diff options
Diffstat (limited to 'src/tool_metalink.c')
-rw-r--r-- | src/tool_metalink.c | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/src/tool_metalink.c b/src/tool_metalink.c index fce18d5a4..2ad7115db 100644 --- a/src/tool_metalink.c +++ b/src/tool_metalink.c @@ -399,7 +399,7 @@ static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) #endif /* CRYPTO LIBS */ -const digest_params MD5_DIGEST_PARAMS[] = { +const struct digest_params MD5_DIGEST_PARAMS[] = { { CURLX_FUNCTION_CAST(digest_init_func, MD5_Init), CURLX_FUNCTION_CAST(digest_update_func, MD5_Update), @@ -409,7 +409,7 @@ const digest_params MD5_DIGEST_PARAMS[] = { } }; -const digest_params SHA1_DIGEST_PARAMS[] = { +const struct digest_params SHA1_DIGEST_PARAMS[] = { { CURLX_FUNCTION_CAST(digest_init_func, SHA1_Init), CURLX_FUNCTION_CAST(digest_update_func, SHA1_Update), @@ -419,7 +419,7 @@ const digest_params SHA1_DIGEST_PARAMS[] = { } }; -const digest_params SHA256_DIGEST_PARAMS[] = { +const struct digest_params SHA256_DIGEST_PARAMS[] = { { CURLX_FUNCTION_CAST(digest_init_func, SHA256_Init), CURLX_FUNCTION_CAST(digest_update_func, SHA256_Update), @@ -429,15 +429,15 @@ const digest_params SHA256_DIGEST_PARAMS[] = { } }; -static const metalink_digest_def SHA256_DIGEST_DEF[] = { +static const struct metalink_digest_def SHA256_DIGEST_DEF[] = { {"sha-256", SHA256_DIGEST_PARAMS} }; -static const metalink_digest_def SHA1_DIGEST_DEF[] = { +static const struct metalink_digest_def SHA1_DIGEST_DEF[] = { {"sha-1", SHA1_DIGEST_PARAMS} }; -static const metalink_digest_def MD5_DIGEST_DEF[] = { +static const struct metalink_digest_def MD5_DIGEST_DEF[] = { {"md5", MD5_DIGEST_PARAMS} }; @@ -448,7 +448,7 @@ static const metalink_digest_def MD5_DIGEST_DEF[] = { * "Hash Function Textual Names". The latter is widely (and * historically) used in Metalink version 3. */ -static const metalink_digest_alias digest_aliases[] = { +static const struct metalink_digest_alias digest_aliases[] = { {"sha-256", SHA256_DIGEST_DEF}, {"sha256", SHA256_DIGEST_DEF}, {"sha-1", SHA1_DIGEST_DEF}, @@ -457,13 +457,9 @@ static const metalink_digest_alias digest_aliases[] = { {NULL, NULL} }; -static digest_context *digest_init(const digest_params *dparams) +static struct digest_context *digest_init(const struct digest_params *dparams) { - digest_context *ctxt; - - /* Create digest context */ - ctxt = malloc(sizeof(*ctxt)); - + struct digest_context *ctxt = malloc(sizeof(*ctxt)); if(!ctxt) return ctxt; @@ -485,7 +481,7 @@ static digest_context *digest_init(const digest_params *dparams) return ctxt; } -static int digest_update(digest_context *context, +static int digest_update(struct digest_context *context, const unsigned char *data, unsigned int len) { @@ -494,7 +490,7 @@ static int digest_update(digest_context *context, return 0; } -static int digest_final(digest_context *context, unsigned char *result) +static int digest_final(struct digest_context *context, unsigned char *result) { if(result) (*context->digest_hash->digest_final)(result, context->digest_hashctx); @@ -531,11 +527,11 @@ static unsigned char hex_to_uint(const char *s) * Hash algorithm not available. */ static int check_hash(const char *filename, - const metalink_digest_def *digest_def, + const struct metalink_digest_def *digest_def, const unsigned char *digest, FILE *error) { unsigned char *result; - digest_context *dctx; + struct digest_context *dctx; int check_ok, flags, fd; flags = O_RDONLY; @@ -597,7 +593,7 @@ static int check_hash(const char *filename, } int metalink_check_hash(struct GlobalConfig *config, - metalinkfile *mlfile, + struct metalinkfile *mlfile, const char *filename) { int rv; @@ -612,11 +608,11 @@ int metalink_check_hash(struct GlobalConfig *config, return rv; } -static metalink_checksum * -checksum_from_hex_digest(const metalink_digest_def *digest_def, +static struct metalink_checksum * +checksum_from_hex_digest(const struct metalink_digest_def *digest_def, const char *hex_digest) { - metalink_checksum *chksum; + struct metalink_checksum *chksum; unsigned char *digest; size_t i; size_t len = strlen(hex_digest); @@ -627,7 +623,7 @@ checksum_from_hex_digest(const metalink_digest_def *digest_def, for(i = 0; i < len; i += 2) { digest[i/2] = hex_to_uint(hex_digest + i); } - chksum = malloc(sizeof(metalink_checksum)); + chksum = malloc(sizeof(struct metalink_checksum)); if(chksum) { chksum->digest_def = digest_def; chksum->digest = digest; @@ -637,10 +633,9 @@ checksum_from_hex_digest(const metalink_digest_def *digest_def, return chksum; } -static metalink_resource *new_metalink_resource(const char *url) +static struct metalink_resource *new_metalink_resource(const char *url) { - metalink_resource *res; - res = malloc(sizeof(metalink_resource)); + struct metalink_resource *res = malloc(sizeof(struct metalink_resource)); if(res) { res->next = NULL; res->url = strdup(url); @@ -656,7 +651,7 @@ static metalink_resource *new_metalink_resource(const char *url) letter is in [0-9A-Za-z] and the length of the string equals to the result length of digest * 2. */ static int check_hex_digest(const char *hex_digest, - const metalink_digest_def *digest_def) + const struct metalink_digest_def *digest_def) { size_t i; for(i = 0; hex_digest[i]; ++i) { @@ -669,10 +664,9 @@ static int check_hex_digest(const char *hex_digest, return digest_def->dparams->digest_resultlen * 2 == i; } -static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo) +static struct metalinkfile *new_metalinkfile(metalink_file_t *fileinfo) { - metalinkfile *f; - f = (metalinkfile*)malloc(sizeof(metalinkfile)); + struct metalinkfile *f = malloc(sizeof(struct metalinkfile)); if(!f) return NULL; @@ -685,7 +679,7 @@ static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo) f->checksum = NULL; f->resource = NULL; if(fileinfo->checksums) { - const metalink_digest_alias *digest_alias; + const struct metalink_digest_alias *digest_alias; for(digest_alias = digest_aliases; digest_alias->alias_name; ++digest_alias) { metalink_checksum_t **p; @@ -705,11 +699,11 @@ static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo) } if(fileinfo->resources) { metalink_resource_t **p; - metalink_resource root, *tail; + struct metalink_resource root, *tail; root.next = NULL; tail = &root; for(p = fileinfo->resources; *p; ++p) { - metalink_resource *res; + struct metalink_resource *res; /* Filter by type if it is non-NULL. In Metalink v3, type includes the type of the resource. In curl, we are only interested in HTTP, HTTPS and FTP. In addition to them, @@ -798,7 +792,7 @@ int parse_metalink(struct OperationConfig *config, struct OutStruct *outs, url = new_getout(config); if(url) { - metalinkfile *mlfile = new_metalinkfile(*files); + struct metalinkfile *mlfile = new_metalinkfile(*files); if(!mlfile) break; @@ -876,24 +870,23 @@ int check_metalink_content_type(const char *content_type) return check_content_type(content_type, "application/metalink+xml"); } -int count_next_metalink_resource(metalinkfile *mlfile) +int count_next_metalink_resource(struct metalinkfile *mlfile) { int count = 0; - metalink_resource *res; + struct metalink_resource *res; for(res = mlfile->resource; res; res = res->next, ++count); return count; } -static void delete_metalink_checksum(metalink_checksum *chksum) +static void delete_metalink_checksum(struct metalink_checksum *chksum) { - if(chksum == NULL) { + if(!chksum) return; - } Curl_safefree(chksum->digest); Curl_safefree(chksum); } -static void delete_metalink_resource(metalink_resource *res) +static void delete_metalink_resource(struct metalink_resource *res) { if(res == NULL) { return; @@ -902,16 +895,16 @@ static void delete_metalink_resource(metalink_resource *res) Curl_safefree(res); } -void delete_metalinkfile(metalinkfile *mlfile) +void delete_metalinkfile(struct metalinkfile *mlfile) { - metalink_resource *res; + struct metalink_resource *res; if(mlfile == NULL) { return; } Curl_safefree(mlfile->filename); delete_metalink_checksum(mlfile->checksum); for(res = mlfile->resource; res;) { - metalink_resource *next; + struct metalink_resource *next; next = res->next; delete_metalink_resource(res); res = next; @@ -923,7 +916,7 @@ void clean_metalink(struct OperationConfig *config) { if(config) { while(config->metalinkfile_list) { - metalinkfile *mlfile = config->metalinkfile_list; + struct metalinkfile *mlfile = config->metalinkfile_list; config->metalinkfile_list = config->metalinkfile_list->next; delete_metalinkfile(mlfile); } |