From 424bb3587748eb59c0d56613e88ef4511ad4dcbf Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 16 Jun 2012 22:58:06 +0900 Subject: curl: Refactored metalink_checksum When creating metalink_checksum from metalink_checksum_t, first check hex digest is valid for the given hash function. We do this check in the order of digest_aliases so that first good match will be chosen (strongest hash function available). As a result, the metalinkfile now only contains at most one metalink_checksum because other entries are just redundant. --- src/tool_metalink.h | 77 ++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'src/tool_metalink.h') diff --git a/src/tool_metalink.h b/src/tool_metalink.h index 3ce1fe2f9..36b4b02c7 100644 --- a/src/tool_metalink.h +++ b/src/tool_metalink.h @@ -23,41 +23,6 @@ ***************************************************************************/ #include "tool_setup.h" -typedef struct metalink_checksum { - struct metalink_checksum *next; - char *hash_name; - /* Hex-encoded hash value */ - char *hash_value; -} metalink_checksum; - -typedef struct metalink_resource { - struct metalink_resource *next; - char *url; -} metalink_resource; - -typedef struct metalinkfile { - struct metalinkfile *next; - char *filename; - metalink_checksum *checksum; - metalink_resource *resource; -} metalinkfile; - -#ifdef USE_METALINK - -/* - * Counts the resource in the metalinkfile. - */ -int count_next_metalink_resource(metalinkfile *mlfile); -void clean_metalink(struct Configurable *config); - -int parse_metalink(struct Configurable *config, const char *infile); - -/* - * Returns nonzero if content_type includes "application/metalink+xml" - * media-type. The check is done in case-insensitive manner. - */ -int check_metalink_content_type(const char *content_type); - typedef void (* Curl_digest_init_func)(void *context); typedef void (* Curl_digest_update_func)(void *context, const unsigned char *data, @@ -77,10 +42,6 @@ typedef struct { void *digest_hashctx; /* Hash function context */ } digest_context; -extern const digest_params MD5_DIGEST_PARAMS[1]; -extern const digest_params SHA1_DIGEST_PARAMS[1]; -extern const digest_params SHA256_DIGEST_PARAMS[1]; - digest_context * Curl_digest_init(const digest_params *dparams); int Curl_digest_update(digest_context *context, const unsigned char *data, @@ -97,6 +58,44 @@ typedef struct { const metalink_digest_def *digest_def; } metalink_digest_alias; +typedef struct metalink_checksum { + const metalink_digest_def *digest_def; + /* raw digest value, not ascii hex digest */ + unsigned char *digest; +} metalink_checksum; + +typedef struct metalink_resource { + struct metalink_resource *next; + char *url; +} metalink_resource; + +typedef struct metalinkfile { + struct metalinkfile *next; + char *filename; + metalink_checksum *checksum; + metalink_resource *resource; +} metalinkfile; + +#ifdef USE_METALINK + +extern const digest_params MD5_DIGEST_PARAMS[1]; +extern const digest_params SHA1_DIGEST_PARAMS[1]; +extern const digest_params SHA256_DIGEST_PARAMS[1]; + +/* + * Counts the resource in the metalinkfile. + */ +int count_next_metalink_resource(metalinkfile *mlfile); +void clean_metalink(struct Configurable *config); + +int parse_metalink(struct Configurable *config, const char *infile); + +/* + * Returns nonzero if content_type includes "application/metalink+xml" + * media-type. The check is done in case-insensitive manner. + */ +int check_metalink_content_type(const char *content_type); + /* * Check checksum of file denoted by filename. * -- cgit v1.2.1