Check checksum of downloaded file if checksum is available
[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 - 2012, 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 #include <metalink/metalink_parser.h>
27
28 #include "tool_cfgable.h"
29
30 struct metalinkfile {
31   struct metalinkfile *next;
32   metalink_file_t *file;
33 };
34
35 struct metalink {
36   struct metalink *next;
37   metalink_t* metalink;
38 };
39
40 struct metalinkfile *new_metalinkfile(metalink_file_t *metalinkfile);
41
42 struct metalink *new_metalink(metalink_t *metalink);
43
44 /*
45  * Counts the resource in the metalinkfile.
46  */
47 int count_next_metalink_resource(struct metalinkfile *mlfile);
48
49 void clean_metalink(struct Configurable *config);
50
51 int parse_metalink(struct Configurable *config, const char *infile);
52
53 /*
54  * Returns nonzero if content_type includes "application/metalink+xml"
55  * media-type. The check is done in case-insensitive manner.
56  */
57 int check_metalink_content_type(const char *content_type);
58
59 typedef void (* Curl_digest_init_func)(void *context);
60 typedef void (* Curl_digest_update_func)(void *context,
61                                          const unsigned char *data,
62                                          unsigned int len);
63 typedef void (* Curl_digest_final_func)(unsigned char *result, void *context);
64
65 typedef struct {
66   Curl_digest_init_func     digest_init;   /* Initialize context procedure */
67   Curl_digest_update_func   digest_update; /* Update context with data */
68   Curl_digest_final_func    digest_final;  /* Get final result procedure */
69   unsigned int           digest_ctxtsize;  /* Context structure size */
70   unsigned int           digest_resultlen; /* Result length (bytes) */
71 } digest_params;
72
73 typedef struct {
74   const digest_params   *digest_hash;      /* Hash function definition */
75   void                  *digest_hashctx;   /* Hash function context */
76 } digest_context;
77
78 extern const digest_params MD5_DIGEST_PARAMS[1];
79 extern const digest_params SHA1_DIGEST_PARAMS[1];
80 extern const digest_params SHA256_DIGEST_PARAMS[1];
81
82 digest_context * Curl_digest_init(const digest_params *dparams);
83 int Curl_digest_update(digest_context *context,
84                        const unsigned char *data,
85                        unsigned int len);
86 int Curl_digest_final(digest_context *context, unsigned char *result);
87
88 typedef struct {
89   const char *hash_name;
90   const digest_params *dparams;
91 } metalink_digest_def;
92
93 typedef struct {
94   const char *alias_name;
95   const metalink_digest_def *digest_def;
96 } metalink_digest_alias;
97
98 /*
99  * Check checksum of file denoted by filename.
100  *
101  * This function returns 1 if the checksum matches or one of the
102  * following integers:
103  *
104  * 0:
105  *   Checksum didn't match.
106  * -1:
107  *   Could not open file; or could not read data from file.
108  * -2:
109  *   No checksum in Metalink supported; or Metalink does not contain
110  *   checksum.
111  */
112 int metalink_check_hash(struct Configurable *config,
113                         struct metalinkfile *mlfile,
114                         const char *filename);
115
116 #endif /* HEADER_CURL_TOOL_METALINK_H */