Verify bittorrent .torrent metainfo files.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

163 lignes
3.6KB

  1. #ifndef METAFILE_H
  2. #define METAFILE_H
  3. #include <bencode.h>
  4. /* This file will parse the .torrent file and make accessor functions */
  5. typedef struct {
  6. const char* str;
  7. int len;
  8. } lenstr_t;
  9. typedef struct {
  10. bencode_t path;
  11. long int size;
  12. } fileinfo_t;
  13. typedef struct {
  14. bencode_t filelist;
  15. } fileiter_t;
  16. typedef unsigned char sha1sum_t[20];
  17. /*
  18. typedef struct __attribute__((packed)) sha1sum_t {
  19. unsigned char hash[20];
  20. } sha1sum_t;
  21. */
  22. typedef struct {
  23. char* bytes;
  24. int bytes_size;
  25. sha1sum_t info_hash;
  26. const sha1sum_t* pieces;
  27. int piece_count;
  28. long int piece_length, creation_date;
  29. bencode_t announce, created_by, name, source, comment;
  30. long int is_private;
  31. int is_multi_file;
  32. union {
  33. long int file_size;
  34. bencode_t files;
  35. };
  36. } metainfo_t;
  37. /*
  38. * Returns 0 on success, -1 on error
  39. */
  40. int metainfo_create(metainfo_t* metai, const char* path);
  41. void metainfo_destroy(metainfo_t* metai);
  42. /*
  43. * Get the info_hash of the torrent as a pointer
  44. */
  45. const sha1sum_t* metainfo_infohash(metainfo_t* metai);
  46. /*
  47. * Get the announce url
  48. */
  49. int metainfo_announce(metainfo_t* metai, const char** str, int* len);
  50. /*
  51. * Get the created by string
  52. */
  53. int metainfo_created_by(metainfo_t* metai, const char** str, int* len);
  54. /*
  55. * Get the creation date, as a unix timestamp
  56. */
  57. int metainfo_creation_date(metainfo_t* metai);
  58. /*
  59. * Get the source
  60. */
  61. int metainfo_source(metainfo_t* metai, const char** str, int* len);
  62. /*
  63. * Get the name of the torrent
  64. */
  65. int metainfo_name(metainfo_t* metai, const char** str, int* len);
  66. /*
  67. * Get the comment of the torrent
  68. */
  69. int metainfo_comment(metainfo_t* metai, const char** str, int* len);
  70. /*
  71. * Is this torrent private?
  72. */
  73. int metainfo_is_private(metainfo_t* metai);
  74. /*
  75. * Get the array of pieces
  76. */
  77. int metainfo_pieces(metainfo_t* metai, const sha1sum_t** piece_hash);
  78. /*
  79. * Get the number of pieces, this will return the number
  80. */
  81. long int metainfo_piece_count(metainfo_t* metai);
  82. /*
  83. * Get the index'th piece hash, returns -1 if invalid
  84. */
  85. int metainfo_piece_index(metainfo_t* metai, int index, \
  86. const sha1sum_t** piece_hash);
  87. /*
  88. * Get the size of 1 piece
  89. */
  90. int metainfo_piece_size(metainfo_t* metai);
  91. /*
  92. * Return 1 if the torrent has multiple files, or 0 if has only 1
  93. */
  94. int metainfo_is_multi_file(metainfo_t* metai);
  95. /*
  96. * Return the number of files, if it's a multi file. This is slow
  97. */
  98. long int metainfo_file_count(metainfo_t* metai);
  99. /*
  100. * Get the index'th file information, if it's a multi file
  101. * This is slow and shouldn't be used
  102. */
  103. int metainfo_file_index(metainfo_t* metai, int index, fileinfo_t* finfo);
  104. /*
  105. * Create a file iterator.
  106. * This interface should be used to get the file infos.
  107. * This doesn't need to be freed.
  108. */
  109. int metainfo_fileiter_create(const metainfo_t* metai, fileiter_t* fileiter);
  110. /*
  111. * Get the next fileinfo in a multi file torrent
  112. * Return -1 if there is no more files.
  113. */
  114. int metainfo_file_next(fileiter_t* iter, fileinfo_t* finfo);
  115. /*
  116. * Get the file information, if torrent has only 1 file
  117. */
  118. int metainfo_fileinfo(metainfo_t* metai, fileinfo_t* finfo);
  119. /*
  120. * Copy the file path from a fileinto_t struct into the buffer at 'out_str',
  121. * adding separators according to the current platform.
  122. * if 'out_str' is NULL, return the required bytes to store the name,
  123. * otherwise the number of bytes copied, or -1 if error.
  124. * The count does NOT include the null terminator
  125. */
  126. int metainfo_fileinfo_path(fileinfo_t* len, char* out_str);
  127. /*
  128. * Return the size of the file in bytes, ofc
  129. */
  130. long int metainfo_fileinfo_size(fileinfo_t* finfo);
  131. #endif