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