aboutsummaryrefslogtreecommitdiff
path: root/src/tool_metalink.h
blob: c2568a31eaba74d1afd8a94459abe75c0a0193ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef HEADER_CURL_TOOL_METALINK_H
#define HEADER_CURL_TOOL_METALINK_H
/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at http://curl.haxx.se/docs/copyright.html.
 *
 * 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"

typedef void (* Curl_digest_init_func)(void *context);
typedef void (* Curl_digest_update_func)(void *context,
                                         const unsigned char *data,
                                         unsigned int len);
typedef void (* Curl_digest_final_func)(unsigned char *result, void *context);

typedef struct {
  Curl_digest_init_func     digest_init;   /* Initialize context procedure */
  Curl_digest_update_func   digest_update; /* Update context with data */
  Curl_digest_final_func    digest_final;  /* Get final result procedure */
  unsigned int           digest_ctxtsize;  /* Context structure size */
  unsigned int           digest_resultlen; /* Result length (bytes) */
} digest_params;

typedef struct {
  const digest_params   *digest_hash;      /* Hash function definition */
  void                  *digest_hashctx;   /* Hash function context */
} digest_context;

digest_context * Curl_digest_init(const digest_params *dparams);
int Curl_digest_update(digest_context *context,
                       const unsigned char *data,
                       unsigned int len);
int Curl_digest_final(digest_context *context, unsigned char *result);

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;

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];

#include <metalink/metalink_parser.h>

/*
 * 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, struct OutStruct *outs);

/*
 * Callback function for CURLOPT_WRITEFUNCTION
 */
size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb,
                         void *userdata);

/*
 * 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.
 *
 * 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:
 *   No checksum in Metalink supported; or Metalink does not contain
 *   checksum.
 */
int metalink_check_hash(struct Configurable *config,
                        metalinkfile *mlfile,
                        const char *filename);

#else /* USE_METALINK */

#define count_next_metalink_resource(x)  0
#define clean_metalink(x)  Curl_nop_stmt

#endif /* USE_METALINK */

#endif /* HEADER_CURL_TOOL_METALINK_H */