1 /* <!-- copyright */ 2 /* 3 * libmetalink 4 * 5 * Copyright (c) 2008 Tatsuhiro Tsujikawa 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal 9 * in the Software without restriction, including without limitation the rights 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 * THE SOFTWARE. 24 */ 25 /* copyright --> */ 26 #ifndef _D_METALINK_TYPES_H_ 27 #define _D_METALINK_TYPES_H_ 28 29 #include <time.h> 30 31 #include <metalink/metalink_error.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 typedef struct _metalink_resource { 38 /* url, null terminated string */ 39 char* url; 40 /* type of resources, like "http", "ftp", null terminated string */ 41 char* type; 42 /* location, this is 2-characther country code, like "JP", 43 * null terminated string 44 */ 45 char* location; 46 /* preference of this resource, higher value has bigger 47 preference. This is used for metalink 3. To keep compatibility 48 with it, when reading metalink 4, 100000 - priority is assigned 49 to preference. */ 50 int preference; 51 /* priority of this resource, lower value has bigger priority. This 52 is used for metalink 4. */ 53 int priority; 54 /* max connections that a client can establish to this resource */ 55 int maxconnections; 56 } metalink_resource_t; 57 58 metalink_resource_t* metalink_resource_new(void); 59 60 void metalink_resource_delete(metalink_resource_t* resource); 61 62 /* mutators */ 63 metalink_error_t metalink_resource_set_type(metalink_resource_t* resource, const char* type); 64 65 metalink_error_t metalink_resource_set_location(metalink_resource_t* resource, 66 const char* location); 67 68 void metalink_resource_set_preference(metalink_resource_t* resource, 69 int preference); 70 71 void metalink_resource_set_priority(metalink_resource_t* resource, 72 int priority); 73 74 void metalink_resource_set_maxconnections(metalink_resource_t* resource, 75 int maxconnections); 76 77 metalink_error_t metalink_resource_set_url(metalink_resource_t* resource, const char* url); 78 79 typedef struct _metalink_metaurl { 80 /* url, null terminated string */ 81 char* url; 82 /* typef of the media, like "torrent", null terminated string */ 83 char* mediatype; 84 /* name of the metaurl, null terminated string */ 85 char* name; 86 /* priority of this resource */ 87 int priority; 88 } metalink_metaurl_t; 89 90 /* constructor */ 91 metalink_metaurl_t* metalink_metaurl_new(void); 92 93 /* destructor */ 94 void metalink_metaurl_delete(metalink_metaurl_t* metaurl); 95 96 /* mutators */ 97 metalink_error_t metalink_metaurl_set_url(metalink_metaurl_t* metaurl, 98 const char* url); 99 100 metalink_error_t metalink_metaurl_set_mediatype(metalink_metaurl_t* metaurl, 101 const char* mediatype); 102 103 metalink_error_t metalink_metaurl_set_name(metalink_metaurl_t* metaurl, 104 const char* name); 105 106 void metalink_metaurl_set_priority(metalink_metaurl_t* metaurl, 107 int priority); 108 109 typedef struct _metalink_checksum { 110 /* message digest algorithm, for example, sha1, null terminated string */ 111 char* type; 112 /* message digest in a ASCII hexadecimal notation, null terminated string */ 113 char* hash; 114 } metalink_checksum_t; 115 116 metalink_checksum_t* metalink_checksum_new(void); 117 118 void metalink_checksum_delete(metalink_checksum_t* checksum); 119 120 /* mutators */ 121 metalink_error_t metalink_checksum_set_type(metalink_checksum_t* checksum, const char* type); 122 123 metalink_error_t metalink_checksum_set_hash(metalink_checksum_t* checksum, const char* hash); 124 125 /** 126 * hash value of each piece. 127 */ 128 typedef struct _metalink_piece_hash { 129 int piece; 130 /* hash value in a ASCII hexadecimal notation */ 131 char* hash; 132 } metalink_piece_hash_t; 133 134 /* constructor */ 135 metalink_piece_hash_t* metalink_piece_hash_new(void); 136 137 /* destructor */ 138 void metalink_piece_hash_delete(metalink_piece_hash_t* piece_hash); 139 140 /* mutators */ 141 void metalink_piece_hash_set_piece(metalink_piece_hash_t* piece_hash, int piece); 142 143 metalink_error_t metalink_piece_hash_set_hash(metalink_piece_hash_t* piece_hash, const char* hash); 144 145 /** 146 * Piece hash; containing type(hash algorithm) and piece size and 147 * hashes. 148 */ 149 typedef struct _metalink_chunk_checksum { 150 /* message digest algorithm, for example, sha1, null terminated string */ 151 char* type; 152 /* length of piece */ 153 int length; 154 /* list of hash. Iterate until you get NULL */ 155 metalink_piece_hash_t** piece_hashes; 156 } metalink_chunk_checksum_t; 157 158 /* constructor */ 159 metalink_chunk_checksum_t* metalink_chunk_checksum_new(void); 160 161 /* destructor */ 162 void metalink_chunk_checksum_delete(metalink_chunk_checksum_t* chunk_checksum); 163 164 /* mutators */ 165 metalink_error_t metalink_chunk_checksum_set_type(metalink_chunk_checksum_t* chunk_checksum, 166 const char* type); 167 168 void metalink_chunk_checksum_set_length(metalink_chunk_checksum_t* chunk_checksum, 169 int length); 170 171 void metalink_chunk_checksum_set_piece_hashes(metalink_chunk_checksum_t* chunk_checksum, 172 metalink_piece_hash_t** piece_hashes); 173 174 /** 175 * signature of a file 176 */ 177 typedef struct _metalink_signature { 178 /* the type of the signature (eg. application/pgp-signature) */ 179 char* mediatype; 180 /* the content of the signature */ 181 char* signature; 182 } metalink_signature_t; 183 184 /* constructor */ 185 metalink_signature_t* metalink_signature_new(void); 186 187 /* destructor */ 188 void metalink_signature_delete(metalink_signature_t* signature); 189 190 /* mutators */ 191 metalink_error_t metalink_signature_set_mediatype(metalink_signature_t* signature, 192 const char* mediatype); 193 194 metalink_error_t metalink_signature_set_signature(metalink_signature_t* signature, 195 const char* value); 196 197 typedef struct _metalink_file { 198 /* filename, null terminated string */ 199 char* name; 200 /* file description, null terminated string */ 201 char* description; 202 /* file size */ 203 long long int size; 204 /* version, null terminated string */ 205 char* version; 206 /* copyright, null terminated string */ 207 char* copyright; 208 /* identity, null terminated string */ 209 char* identity; 210 /* logo, null terminated string */ 211 char* logo; 212 /* publisher name, null terminated string */ 213 char* publisher_name; 214 /* publisher url, null terminated string */ 215 char* publisher_url; 216 /* list of language, null terminated list of null terminated string */ 217 char** languages; 218 /* first language, for compatibility with metalink 3 */ 219 char* language; 220 /* list of os, null terminated list of null terminated string */ 221 char** oses; 222 /* first os, for compatibility with metalink 3 */ 223 char* os; 224 /* file signature */ 225 metalink_signature_t* signature; 226 /* maximum number of connections for this file */ 227 int maxconnections; 228 /* list of metalink_resource_t */ 229 metalink_resource_t** resources; 230 /* list of metaurls (metalink_resource_t) */ 231 metalink_metaurl_t** metaurls; 232 /* list of metalink_checksum_t. It is possible to include multiple message 233 * digest algorithms 234 */ 235 metalink_checksum_t** checksums; 236 237 /* chunk checksum */ 238 metalink_chunk_checksum_t* chunk_checksum; 239 240 } metalink_file_t; 241 242 /* constructor */ 243 metalink_file_t* metalink_file_new(void); 244 245 /* destructor */ 246 void metalink_file_delete(metalink_file_t* file); 247 248 /* mutators */ 249 metalink_error_t metalink_file_set_name(metalink_file_t* file, const char* name); 250 251 metalink_error_t metalink_file_set_description(metalink_file_t* file, const char* description); 252 253 void metalink_file_set_size(metalink_file_t* file, long long int size); 254 255 metalink_error_t metalink_file_set_version(metalink_file_t* file, const char* version); 256 257 metalink_error_t metalink_file_set_copyright(metalink_file_t* file, const char* copyright); 258 259 metalink_error_t metalink_file_set_identity(metalink_file_t* file, const char* identity); 260 261 metalink_error_t metalink_file_set_logo(metalink_file_t* file, const char* logo); 262 263 metalink_error_t metalink_file_set_publisher_name(metalink_file_t* file, const char* name); 264 265 metalink_error_t metalink_file_set_publisher_url(metalink_file_t* file, const char* url); 266 267 void metalink_file_set_maxconnections(metalink_file_t* file, int maxconnections); 268 269 typedef enum metalink_version_e { 270 METALINK_VERSION_UNKNOWN, 271 METALINK_VERSION_3 = 3, 272 METALINK_VERSION_4 = 4 273 } metalink_version_t; 274 275 typedef struct _metalink { 276 /* put more descriptable information here... */ 277 /* date, publisher or something useful */ 278 279 /* metalink version of this file */ 280 metalink_version_t version; 281 /* generator of this metalink, null terminated string */ 282 char* generator; 283 /* origin of this metalink, null terminated string. In Metalink 284 version 4, this is the content of the origin element. In Metalink 285 version 3, this is the origin attribute of the metalink 286 element. */ 287 char* origin; 288 /* In Metalink version 4, this value is 1 if the dynamic attribute 289 * of the origin element is "true". In Metalink version 3, this 290 * value is 1 if the type attribute of the metalink element is 291 * "dynamic". */ 292 int origin_dynamic; 293 /* timestamp corresponding to the publication of this metalink */ 294 time_t published; 295 /* timestamp corresponding to the last update of this metalink */ 296 time_t updated; 297 298 /* list of metalink_file_t */ 299 metalink_file_t** files; 300 char* identity; 301 char* tags; 302 } metalink_t; 303 304 metalink_error_t metalink_set_identity(metalink_t* metalink, const char* identity); 305 metalink_error_t metalink_set_tags(metalink_t* metalink, const char* tags); 306 metalink_error_t metalink_set_generator(metalink_t* metalink, const char* generator); 307 metalink_error_t metalink_set_origin(metalink_t* metalink, const char* origin); 308 void metalink_set_origin_dynamic(metalink_t* metalink, int origin_dynamic); 309 void metalink_set_published(metalink_t* metalink, time_t published); 310 void metalink_set_updated(metalink_t* metalink, time_t updated); 311 void metalink_set_version(metalink_t* metalink, metalink_version_t version); 312 313 metalink_t* metalink_new(void); 314 315 void metalink_delete(metalink_t* metalink); 316 317 #ifdef __cplusplus 318 } 319 #endif 320 321 #endif /* _D_METALINK_TYPES_H_ */ 322