Imported Upstream version 7.40.0
[platform/upstream/curl.git] / src / tool_metalink.h
1 #ifndef HEADER_CURL_TOOL_METALINK_H
2 #define HEADER_CURL_TOOL_METALINK_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
12  * This software is licensed as described in the file COPYING, which
13  * you should have received as part of this distribution. The terms
14  * are also available at http://curl.haxx.se/docs/copyright.html.
15  *
16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17  * copies of the Software, and permit persons to whom the Software is
18  * furnished to do so, under the terms of the COPYING file.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  ***************************************************************************/
24 #include "tool_setup.h"
25
26 struct GlobalConfig;
27 struct OperationConfig;
28
29 /* returns 1 for success, 0 otherwise (we use OpenSSL *_Init fncs directly) */
30 typedef int (* Curl_digest_init_func)(void *context);
31
32 typedef void (* Curl_digest_update_func)(void *context,
33                                          const unsigned char *data,
34                                          unsigned int len);
35 typedef void (* Curl_digest_final_func)(unsigned char *result, void *context);
36
37 typedef struct {
38   Curl_digest_init_func     digest_init;   /* Initialize context procedure */
39   Curl_digest_update_func   digest_update; /* Update context with data */
40   Curl_digest_final_func    digest_final;  /* Get final result procedure */
41   unsigned int           digest_ctxtsize;  /* Context structure size */
42   unsigned int           digest_resultlen; /* Result length (bytes) */
43 } digest_params;
44
45 typedef struct {
46   const digest_params   *digest_hash;      /* Hash function definition */
47   void                  *digest_hashctx;   /* Hash function context */
48 } digest_context;
49
50 digest_context * Curl_digest_init(const digest_params *dparams);
51 int Curl_digest_update(digest_context *context,
52                        const unsigned char *data,
53                        unsigned int len);
54 int Curl_digest_final(digest_context *context, unsigned char *result);
55
56 typedef struct {
57   const char *hash_name;
58   const digest_params *dparams;
59 } metalink_digest_def;
60
61 typedef struct {
62   const char *alias_name;
63   const metalink_digest_def *digest_def;
64 } metalink_digest_alias;
65
66 typedef struct metalink_checksum {
67   const metalink_digest_def *digest_def;
68   /* raw digest value, not ascii hex digest */
69   unsigned char *digest;
70 } metalink_checksum;
71
72 typedef struct metalink_resource {
73   struct metalink_resource *next;
74   char *url;
75 } metalink_resource;
76
77 typedef struct metalinkfile {
78   struct metalinkfile *next;
79   char *filename;
80   metalink_checksum *checksum;
81   metalink_resource *resource;
82 } metalinkfile;
83
84 #ifdef USE_METALINK
85
86 /*
87  * curl requires libmetalink 0.1.0 or newer
88  */
89 #define CURL_REQ_LIBMETALINK_MAJOR  0
90 #define CURL_REQ_LIBMETALINK_MINOR  1
91 #define CURL_REQ_LIBMETALINK_PATCH  0
92
93 #define CURL_REQ_LIBMETALINK_VERS  ((CURL_REQ_LIBMETALINK_MAJOR * 10000) + \
94                                     (CURL_REQ_LIBMETALINK_MINOR * 100) + \
95                                      CURL_REQ_LIBMETALINK_PATCH)
96
97 extern const digest_params MD5_DIGEST_PARAMS[1];
98 extern const digest_params SHA1_DIGEST_PARAMS[1];
99 extern const digest_params SHA256_DIGEST_PARAMS[1];
100
101 #include <metalink/metalink.h>
102
103 /*
104  * Counts the resource in the metalinkfile.
105  */
106 int count_next_metalink_resource(metalinkfile *mlfile);
107 void clean_metalink(struct OperationConfig *config);
108
109 /*
110  * Performs final parse operation and extracts information from
111  * Metalink and creates metalinkfile structs.
112  *
113  * This function returns 0 if it succeeds without warnings, or one of
114  * the following negative error codes:
115  *
116  * -1: Parsing failed; or no file is found
117  * -2: Parsing succeeded with some warnings.
118  */
119 int parse_metalink(struct OperationConfig *config, struct OutStruct *outs,
120                    const char *metalink_url);
121
122 /*
123  * Callback function for CURLOPT_WRITEFUNCTION
124  */
125 size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb,
126                          void *userdata);
127
128 /*
129  * Returns nonzero if content_type includes "application/metalink+xml"
130  * media-type. The check is done in case-insensitive manner.
131  */
132 int check_metalink_content_type(const char *content_type);
133
134 /*
135  * Check checksum of file denoted by filename.
136  *
137  * This function returns 1 if the checksum matches or one of the
138  * following integers:
139  *
140  * 0:
141  *   Checksum didn't match.
142  * -1:
143  *   Could not open file; or could not read data from file.
144  * -2:
145  *   No checksum in Metalink supported, hash algorithm not available, or
146  *   Metalink does not contain checksum.
147  */
148 int metalink_check_hash(struct GlobalConfig *config,
149                         metalinkfile *mlfile,
150                         const char *filename);
151
152 /*
153  * Release resources allocated at global scope.
154  */
155 void metalink_cleanup(void);
156
157 #else /* USE_METALINK */
158
159 #define count_next_metalink_resource(x)  0
160 #define clean_metalink(x)  (void)x
161
162 /* metalink_cleanup() takes no arguments */
163 #define metalink_cleanup() Curl_nop_stmt
164
165 #endif /* USE_METALINK */
166
167 #endif /* HEADER_CURL_TOOL_METALINK_H */