Nick Hengeveld | 29508e1 | 2005-11-18 11:02:58 -0800 | [diff] [blame] | 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 | |
Nick Hengeveld | c8568e1 | 2006-01-31 11:06:55 -0800 | [diff] [blame] | 25 | struct slot_results |
| 26 | { |
| 27 | CURLcode curl_result; |
| 28 | long http_code; |
| 29 | }; |
| 30 | |
Nick Hengeveld | 29508e1 | 2005-11-18 11:02:58 -0800 | [diff] [blame] | 31 | struct active_request_slot |
| 32 | { |
| 33 | CURL *curl; |
| 34 | FILE *local; |
| 35 | int in_use; |
| 36 | CURLcode curl_result; |
| 37 | long http_code; |
Nick Hengeveld | c8568e1 | 2006-01-31 11:06:55 -0800 | [diff] [blame] | 38 | struct slot_results *results; |
Nick Hengeveld | 29508e1 | 2005-11-18 11:02:58 -0800 | [diff] [blame] | 39 | void *callback_data; |
| 40 | void (*callback_func)(void *data); |
| 41 | struct active_request_slot *next; |
| 42 | }; |
| 43 | |
| 44 | struct buffer |
| 45 | { |
| 46 | size_t posn; |
| 47 | size_t size; |
| 48 | void *buffer; |
| 49 | }; |
| 50 | |
| 51 | /* Curl request read/write callbacks */ |
| 52 | extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, |
| 53 | struct buffer *buffer); |
| 54 | extern size_t fwrite_buffer(const void *ptr, size_t eltsize, |
| 55 | size_t nmemb, struct buffer *buffer); |
| 56 | extern size_t fwrite_null(const void *ptr, size_t eltsize, |
| 57 | size_t nmemb, struct buffer *buffer); |
| 58 | |
| 59 | /* Slot lifecycle functions */ |
| 60 | extern struct active_request_slot *get_active_slot(void); |
| 61 | extern int start_active_slot(struct active_request_slot *slot); |
| 62 | extern void run_active_slot(struct active_request_slot *slot); |
| 63 | extern void finish_all_active_slots(void); |
Mark Wooding | 53f3138 | 2006-02-07 10:07:39 +0000 | [diff] [blame] | 64 | extern void release_active_slot(struct active_request_slot *slot); |
Nick Hengeveld | 29508e1 | 2005-11-18 11:02:58 -0800 | [diff] [blame] | 65 | |
| 66 | #ifdef USE_CURL_MULTI |
| 67 | extern void fill_active_slots(void); |
| 68 | extern void step_active_slots(void); |
| 69 | #endif |
| 70 | |
| 71 | extern void http_init(void); |
| 72 | extern void http_cleanup(void); |
| 73 | |
| 74 | extern int data_received; |
| 75 | extern int active_requests; |
| 76 | |
| 77 | #ifdef USE_CURL_MULTI |
| 78 | extern int max_requests; |
| 79 | extern CURLM *curlm; |
| 80 | #endif |
| 81 | #ifndef NO_CURL_EASY_DUPHANDLE |
| 82 | extern CURL *curl_default; |
| 83 | #endif |
| 84 | extern char curl_errorstr[CURL_ERROR_SIZE]; |
| 85 | |
| 86 | extern int curl_ssl_verify; |
| 87 | extern char *ssl_cert; |
| 88 | #if LIBCURL_VERSION_NUM >= 0x070902 |
| 89 | extern char *ssl_key; |
| 90 | #endif |
| 91 | #if LIBCURL_VERSION_NUM >= 0x070908 |
| 92 | extern char *ssl_capath; |
| 93 | #endif |
| 94 | extern char *ssl_cainfo; |
| 95 | extern long curl_low_speed_limit; |
| 96 | extern long curl_low_speed_time; |
| 97 | |
| 98 | extern struct curl_slist *pragma_header; |
| 99 | extern struct curl_slist *no_range_header; |
| 100 | |
| 101 | extern struct active_request_slot *active_queue_head; |
| 102 | |
| 103 | #endif /* HTTP_H */ |