a7ff0e822865681b218717f9f178a9a412868847
[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 - 2013, 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 /* returns 1 for success, 0 otherwise (we use OpenSSL *_Init fncs directly) */
27 typedef int (* Curl_digest_init_func)(void *context);
28
29 typedef void (* Curl_digest_update_func)(void *context,
30                                          const unsigned char *data,
31                                          unsigned int len);
32 typedef void (* Curl_digest_final_func)(unsigned char *result, void *context);
33
34 typedef struct {
35   Curl_digest_init_func     digest_init;   /* Initialize context procedure */
36   Curl_digest_update_func   digest_update; /* Update context with data */
37   Curl_digest_final_func    digest_final;  /* Get final result procedure */
38   unsigned int           digest_ctxtsize;  /* Context structure size */
39   unsigned int           digest_resultlen; /* Result length (bytes) */
40 } digest_params;
41
42 typedef struct {
43   const digest_params   *digest_hash;      /* Hash function definition */
44   void                  *digest_hashctx;   /* Hash function context */
45 } digest_context;
46
47 digest_context * Curl_digest_init(const digest_params *dparams);
48 int Curl_digest_update(digest_context *context,
49                        const unsigned char *data,
50                        unsigned int len);
51 int Curl_digest_final(digest_context *context, unsigned char *result);
52
53 typedef struct {
54   const char *hash_name;
55   const digest_params *dparams;
56 } metalink_digest_def;
57
58 typedef struct {
59   const char *alias_name;
60   const metalink_digest_def *digest_def;
61 } metalink_digest_alias;
62
63 typedef struct metalink_checksum {
64   const metalink_digest_def *digest_def;
65   /* raw digest value, not ascii hex digest */
66   unsigned char *digest;
67 } metalink_checksum;
68
69 typedef struct metalink_resource {
70   struct metalink_resource *next;
71   char *url;
72 } metalink_resource;
73
74 typedef struct metalinkfile {
75   struct metalinkfile *next;
76   char *filename;
77   metalink_checksum *checksum;
78   metalink_resource *resource;
79 } metalinkfile;
80
81 #ifdef USE_METALINK
82
83 /*
84  * curl requires libmetalink 0.1.0 or newer
85  */
86 #define CURL_REQ_LIBMETALINK_MAJOR  0
87 #define CURL_REQ_LIBMETALINK_MINOR  1
88 #define CURL_REQ_LIBMETALINK_PATCH  0
89
90 #define CURL_REQ_LIBMETALINK_VERS  ((CURL_REQ_LIBMETALINK_MAJOR * 10000) + \
91                                     (CURL_REQ_LIBMETALINK_MINOR * 100) + \
92                                      CURL_REQ_LIBMETALINK_PATCH)
93
94 extern const digest_params MD5_DIGEST_PARAMS[1];
95 extern const digest_params SHA1_DIGEST_PARAMS[1];
96 extern const digest_params SHA256_DIGEST_PARAMS[1];
97
98 #include <metalink/metalink.h>
99
100 /*
101  * Counts the resource in the metalinkfile.
102  */
103 int count_next_metalink_resource(metalinkfile *mlfile);
104 void clean_metalink(struct Configurable *config);
105
106 /*
107  * Performs final parse operation and extracts information from
108  * Metalink and creates metalinkfile structs.
109  *
110  * This function returns 0 if it succeeds without warnings, or one of
111  * the following negative error codes:
112  *
113  * -1: Parsing failed; or no file is found
114  * -2: Parsing succeeded with some warnings.
115  */
116 int parse_metalink(struct Configurable *config, struct OutStruct *outs,
117                    const char *metalink_url);
118
119 /*
120  * Callback function for CURLOPT_WRITEFUNCTION
121  */
122 size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb,
123                          void *userdata);
124
125 /*
126  * Returns nonzero if content_type includes "application/metalink+xml"
127  * media-type. The check is done in case-insensitive manner.
128  */
129 int check_metalink_content_type(const char *content_type);
130
131 /*
132  * Check checksum of file denoted by filename.
133  *
134  * This function returns 1 if the checksum matches or one of the
135  * following integers:
136  *
137  * 0:
138  *   Checksum didn't match.
139  * -1:
140  *   Could not open file; or could not read data from file.
141  * -2:
142  *   No checksum in Metalink supported, hash algorithm not available, or
143  *   Metalink does not contain checksum.
144  */
145 int metalink_check_hash(struct Configurable *config,
146                         metalinkfile *mlfile,
147                         const char *filename);
148
149 /*
150  * Release resources allocated at global scope.
151  */
152 void metalink_cleanup(void);
153
154 #else /* USE_METALINK */
155
156 #define count_next_metalink_resource(x)  0
157 #define clean_metalink(x)  Curl_nop_stmt
158
159 /* metalink_cleanup() takes no arguments */
160 #define metalink_cleanup() Curl_nop_stmt
161
162 #endif /* USE_METALINK */
163
164 #endif /* HEADER_CURL_TOOL_METALINK_H */