GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  METALINK_PARSE_MEMORY (3)

NAME

metalink_parse_file, metalink_parse_fp, metalink_parse_fd, metalink_parse_memory - Parse Metalink file and create metalink_t object.

CONTENTS

SYNOPSIS

#include <metalink/metalink.h>

metalink_error_t metalink_parse_file(const char *filename, metalink_t **res);
metalink_error_t metalink_parse_fp(FILE *docfp, metalink_t **res);
metalink_error_t metalink_parse_fd(int docfd, metalink_t **res);
metalink_error_t metalink_parse_memory(const char *buf, size_t len, metalink_t **res);

DESCRIPTION

These functions parse Metalink file data and constructs metalink_t structure. You don’t have to allocate memory for metalink_t structure. They take the pointer of metalink_t pointer and allocate memory for that pointer.

metalink_parse_file() parses Metalink file denoted by filename and constructs metalink_t structure.

metalink_parse_fp() reads data from file stream docfp and construtcts metalink_t structure.

metalink_parse_fd() reads data from file descriptor docfd and constructs metalink_t structure.

metalink_parse_memory() parses len bytes of buf and constructs metalink_t structure.

The caller must free the memory allocated for metalink_t structure using metalink_delete(3) if it is no longer used.

RETURN VALUE

All functions return 0 for success. When error occurred, non-zero value error code is returned and metalink_t structure is not allocated. The error codes are described in metalink_error.h.

EXAMPLE

#include <stdio.h>
#include <stdlib.h>
#include <metalink/metalink.h>

int main(int argc, char** argv) { metalink_error_t r; metalink_t* metalink; metalink_file_t* file; metalink_checksum_t** checksums; r = metalink_parse_file("sample.metalink", &metalink);

if(r != 0) { fprintf(stderr, "ERROR: code=%d\n", r); exit(EXIT_FAILURE); }

file = metalink->files[0]; printf("name: %s\n", file->name); printf("size: %lld\n", file->size); printf("os : %s\n", file->os);

if(file->checksums) { checksums = file->checksums; while(*checksums) { printf("hash: %s %s\n", (*checksums)->type, (*checksums)->hash); ++checksums; } } if(file->chunk_checksum) { size_t count = 0; metalink_piece_hash_t** piece_hashes; printf("chunk checksum: size=%d, type=%s\n", file->chunk_checksum->length, file->chunk_checksum->type); printf("first 5 piece hashes...\n"); piece_hashes = file->chunk_checksum->piece_hashes; while(*piece_hashes && count < 5) { printf("piece=%d, hash=%s\n", (*piece_hashes)->piece, (*piece_hashes)->hash); ++piece_hashes; ++count; } printf("...\n"); } if(file->resources) { size_t count = 0; metalink_resource_t** resources; printf("first 5 resources...\n"); resources = file->resources; while(*resources && count < 5) { printf("type=%s, location=%s, preference=%d, url=%s\n", (*resources)->type, (*resources)->location, (*resources)->preference, (*resources)->url); ++resources; ++count; } printf("...\n"); }

/* delete metalink_t */ metalink_delete(metalink);

return EXIT_SUCCESS; }

SEE ALSO

metalink_delete(3), metalink_parse_update(3), metalink_t(3)
Search for    or go to Top of page |  Section 3 |  Main Index


libmetalink 0.1.0 METALINK_PARSE_FILE (3) July 2012

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.