1#ifndef HTTP_H
2#define HTTP_H
3
4#include "cache.h"
5
6#include <curl/curl.h>
7#include <curl/easy.h>
8
9#if LIBCURL_VERSION_NUM >= 0x070908
10#define USE_CURL_MULTI
11#define DEFAULT_MAX_REQUESTS 5
12#endif
13
14#if LIBCURL_VERSION_NUM < 0x070704
15#define curl_global_cleanup() do { /* nothing */ } while(0)
16#endif
17#if LIBCURL_VERSION_NUM < 0x070800
18#define curl_global_init(a) do { /* nothing */ } while(0)
19#endif
20
21#if LIBCURL_VERSION_NUM < 0x070c04
22#define NO_CURL_EASY_DUPHANDLE
23#endif
24
25struct active_request_slot
26{
27 CURL *curl;
28 FILE *local;
29 int in_use;
30 CURLcode curl_result;
31 long http_code;
32 void *callback_data;
33 void (*callback_func)(void *data);
34 struct active_request_slot *next;
35};
36
37struct buffer
38{
39 size_t posn;
40 size_t size;
41 void *buffer;
42};
43
44/* Curl request read/write callbacks */
45extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
46 struct buffer *buffer);
47extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
48 size_t nmemb, struct buffer *buffer);
49extern size_t fwrite_null(const void *ptr, size_t eltsize,
50 size_t nmemb, struct buffer *buffer);
51
52/* Slot lifecycle functions */
53extern struct active_request_slot *get_active_slot(void);
54extern int start_active_slot(struct active_request_slot *slot);
55extern void run_active_slot(struct active_request_slot *slot);
56extern void finish_all_active_slots(void);
57
58#ifdef USE_CURL_MULTI
59extern void fill_active_slots(void);
60extern void step_active_slots(void);
61#endif
62
63extern void http_init(void);
64extern void http_cleanup(void);
65
66extern int data_received;
67extern int active_requests;
68
69#ifdef USE_CURL_MULTI
70extern int max_requests;
71extern CURLM *curlm;
72#endif
73#ifndef NO_CURL_EASY_DUPHANDLE
74extern CURL *curl_default;
75#endif
76extern char curl_errorstr[CURL_ERROR_SIZE];
77
78extern int curl_ssl_verify;
79extern char *ssl_cert;
80#if LIBCURL_VERSION_NUM >= 0x070902
81extern char *ssl_key;
82#endif
83#if LIBCURL_VERSION_NUM >= 0x070908
84extern char *ssl_capath;
85#endif
86extern char *ssl_cainfo;
87extern long curl_low_speed_limit;
88extern long curl_low_speed_time;
89
90extern struct curl_slist *pragma_header;
91extern struct curl_slist *no_range_header;
92
93extern struct active_request_slot *active_queue_head;
94
95#endif /* HTTP_H */