2012-04-26 09:59:52 -04:00
|
|
|
#ifndef HEADER_CURL_TOOL_METALINK_H
|
|
|
|
#define HEADER_CURL_TOOL_METALINK_H
|
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2020-04-13 17:46:18 -04:00
|
|
|
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2012-04-26 09:59:52 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2012-04-26 09:59:52 -04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
#include "tool_setup.h"
|
2019-07-20 13:14:00 -04:00
|
|
|
#include "tool_sdecls.h"
|
2012-04-26 09:59:52 -04:00
|
|
|
|
2014-03-01 15:11:28 -05:00
|
|
|
struct GlobalConfig;
|
|
|
|
struct OperationConfig;
|
|
|
|
|
2012-11-13 07:09:43 -05:00
|
|
|
/* returns 1 for success, 0 otherwise (we use OpenSSL *_Init fncs directly) */
|
2020-04-13 17:46:18 -04:00
|
|
|
typedef int (*digest_init_func)(void *context);
|
2012-11-13 07:09:43 -05:00
|
|
|
|
2020-04-13 17:46:18 -04:00
|
|
|
typedef void (*digest_update_func)(void *context,
|
|
|
|
const unsigned char *data,
|
|
|
|
unsigned int len);
|
|
|
|
typedef void (*digest_final_func)(unsigned char *result, void *context);
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
|
|
|
|
typedef struct {
|
2020-04-13 17:46:18 -04:00
|
|
|
digest_init_func digest_init; /* Initialize context procedure */
|
|
|
|
digest_update_func digest_update; /* Update context with data */
|
|
|
|
digest_final_func digest_final; /* Get final result procedure */
|
|
|
|
unsigned int digest_ctxtsize; /* Context structure size */
|
|
|
|
unsigned int digest_resultlen; /* Result length (bytes) */
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
} digest_params;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const digest_params *digest_hash; /* Hash function definition */
|
|
|
|
void *digest_hashctx; /* Hash function context */
|
|
|
|
} digest_context;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *hash_name;
|
|
|
|
const digest_params *dparams;
|
|
|
|
} metalink_digest_def;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *alias_name;
|
|
|
|
const metalink_digest_def *digest_def;
|
|
|
|
} metalink_digest_alias;
|
|
|
|
|
2012-06-16 09:58:06 -04:00
|
|
|
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
|
|
|
|
|
2012-06-30 08:17:44 -04:00
|
|
|
/*
|
|
|
|
* curl requires libmetalink 0.1.0 or newer
|
|
|
|
*/
|
|
|
|
#define CURL_REQ_LIBMETALINK_MAJOR 0
|
|
|
|
#define CURL_REQ_LIBMETALINK_MINOR 1
|
|
|
|
#define CURL_REQ_LIBMETALINK_PATCH 0
|
|
|
|
|
|
|
|
#define CURL_REQ_LIBMETALINK_VERS ((CURL_REQ_LIBMETALINK_MAJOR * 10000) + \
|
|
|
|
(CURL_REQ_LIBMETALINK_MINOR * 100) + \
|
|
|
|
CURL_REQ_LIBMETALINK_PATCH)
|
|
|
|
|
2012-06-16 09:58:06 -04:00
|
|
|
extern const digest_params MD5_DIGEST_PARAMS[1];
|
|
|
|
extern const digest_params SHA1_DIGEST_PARAMS[1];
|
|
|
|
extern const digest_params SHA256_DIGEST_PARAMS[1];
|
|
|
|
|
2012-06-30 08:07:38 -04:00
|
|
|
#include <metalink/metalink.h>
|
2012-06-20 11:51:06 -04:00
|
|
|
|
2012-06-16 09:58:06 -04:00
|
|
|
/*
|
|
|
|
* Counts the resource in the metalinkfile.
|
|
|
|
*/
|
|
|
|
int count_next_metalink_resource(metalinkfile *mlfile);
|
2019-09-11 10:32:11 -04:00
|
|
|
|
|
|
|
void delete_metalinkfile(metalinkfile *mlfile);
|
2014-02-23 07:59:59 -05:00
|
|
|
void clean_metalink(struct OperationConfig *config);
|
2012-06-16 09:58:06 -04:00
|
|
|
|
2012-06-27 11:20:20 -04:00
|
|
|
/*
|
|
|
|
* Performs final parse operation and extracts information from
|
|
|
|
* Metalink and creates metalinkfile structs.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds without warnings, or one of
|
|
|
|
* the following negative error codes:
|
|
|
|
*
|
|
|
|
* -1: Parsing failed; or no file is found
|
|
|
|
* -2: Parsing succeeded with some warnings.
|
|
|
|
*/
|
2014-02-23 07:59:59 -05:00
|
|
|
int parse_metalink(struct OperationConfig *config, struct OutStruct *outs,
|
2012-06-26 09:55:16 -04:00
|
|
|
const char *metalink_url);
|
2012-06-20 11:51:06 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback function for CURLOPT_WRITEFUNCTION
|
|
|
|
*/
|
|
|
|
size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb,
|
|
|
|
void *userdata);
|
2012-06-16 09:58:06 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
/*
|
|
|
|
* Check checksum of file denoted by filename.
|
|
|
|
*
|
|
|
|
* This function returns 1 if the checksum matches or one of the
|
|
|
|
* following integers:
|
|
|
|
*
|
|
|
|
* 0:
|
|
|
|
* Checksum didn't match.
|
|
|
|
* -1:
|
|
|
|
* Could not open file; or could not read data from file.
|
|
|
|
* -2:
|
2012-10-30 09:21:54 -04:00
|
|
|
* No checksum in Metalink supported, hash algorithm not available, or
|
|
|
|
* Metalink does not contain checksum.
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
*/
|
2014-03-01 08:00:31 -05:00
|
|
|
int metalink_check_hash(struct GlobalConfig *config,
|
2012-05-25 06:24:32 -04:00
|
|
|
metalinkfile *mlfile,
|
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as
md5, sha-1, sha-256, etc. To deal with these checksums, I created
abstraction layer based on lib/curl_md5.h and
lib/md5.c. Basically, they are almost the same but I changed the
code so that it is not hash type dependent. Currently,
GNUTLS(nettle or gcrypt) and OpenSSL functions are supported.
Checksum checking is done by reopening download file. If there
is an I/O error, the current implementation just prints error
message and does not try next resource.
In this patch, the supported hash types are: md5, sha-1 and sha-256.
2012-05-21 12:40:11 -04:00
|
|
|
const char *filename);
|
|
|
|
|
2012-10-31 05:43:36 -04:00
|
|
|
/*
|
|
|
|
* Release resources allocated at global scope.
|
|
|
|
*/
|
|
|
|
void metalink_cleanup(void);
|
|
|
|
|
2012-06-08 08:21:29 -04:00
|
|
|
#else /* USE_METALINK */
|
|
|
|
|
|
|
|
#define count_next_metalink_resource(x) 0
|
2019-09-11 10:32:11 -04:00
|
|
|
#define delete_metalinkfile(x) (void)x
|
2014-02-09 14:08:13 -05:00
|
|
|
#define clean_metalink(x) (void)x
|
2013-02-15 05:19:59 -05:00
|
|
|
|
|
|
|
/* metalink_cleanup() takes no arguments */
|
2013-02-15 07:45:28 -05:00
|
|
|
#define metalink_cleanup() Curl_nop_stmt
|
2012-06-08 08:21:29 -04:00
|
|
|
|
|
|
|
#endif /* USE_METALINK */
|
|
|
|
|
2012-04-26 09:59:52 -04:00
|
|
|
#endif /* HEADER_CURL_TOOL_METALINK_H */
|