Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
METALINK_PARSE_FILE(3)	       libmetalink Manual	  METALINK_PARSE_FILE(3)

NAME
     metalink_parse_file,     metalink_parse_fp,     metalink_parse_fd,     met-
     alink_parse_memory - Parse Metalink file and create metalink_t object.

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, met-
     alink_t **res);

DESCRIPTION
     These functions parse Metalink file data and constructs  metalink_t  struc-
     ture.   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 con-
     structs metalink_t structure.

     metalink_parse_fp() reads data from file stream docfp and construtcts  met-
     alink_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 er-
     ror 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)

libmetalink 0.1.0		    July 2012		  METALINK_PARSE_FILE(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=metalink_parse_file&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help