Re(-re)*fix trim_common_tail()
[git/mingw/4msysgit/wingit-dll.git] / http.h
blobaeba9301f8fe1a1d4e2f9819257579375be648aa
1 #ifndef HTTP_H
2 #define HTTP_H
4 #include "cache.h"
6 #include <curl/curl.h>
7 #include <curl/easy.h>
9 #include "strbuf.h"
11 #if LIBCURL_VERSION_NUM >= 0x071000
12 #define USE_CURL_MULTI
13 #define DEFAULT_MAX_REQUESTS 5
14 #endif
16 #if LIBCURL_VERSION_NUM < 0x070704
17 #define curl_global_cleanup() do { /* nothing */ } while(0)
18 #endif
19 #if LIBCURL_VERSION_NUM < 0x070800
20 #define curl_global_init(a) do { /* nothing */ } while(0)
21 #endif
23 #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
24 #define NO_CURL_EASY_DUPHANDLE
25 #endif
27 #if LIBCURL_VERSION_NUM < 0x070a03
28 #define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
29 #endif
31 struct slot_results
33 CURLcode curl_result;
34 long http_code;
37 struct active_request_slot
39 CURL *curl;
40 FILE *local;
41 int in_use;
42 CURLcode curl_result;
43 long http_code;
44 int *finished;
45 struct slot_results *results;
46 void *callback_data;
47 void (*callback_func)(void *data);
48 struct active_request_slot *next;
51 struct buffer
53 struct strbuf buf;
54 size_t posn;
57 /* Curl request read/write callbacks */
58 extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
59 struct buffer *buffer);
60 extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
61 size_t nmemb, struct strbuf *buffer);
62 extern size_t fwrite_null(const void *ptr, size_t eltsize,
63 size_t nmemb, struct strbuf *buffer);
65 /* Slot lifecycle functions */
66 extern struct active_request_slot *get_active_slot(void);
67 extern int start_active_slot(struct active_request_slot *slot);
68 extern void run_active_slot(struct active_request_slot *slot);
69 extern void finish_all_active_slots(void);
70 extern void release_active_slot(struct active_request_slot *slot);
72 #ifdef USE_CURL_MULTI
73 extern void fill_active_slots(void);
74 extern void add_fill_function(void *data, int (*fill)(void *));
75 extern void step_active_slots(void);
76 #endif
78 extern void http_init(void);
79 extern void http_cleanup(void);
81 extern int data_received;
82 extern int active_requests;
84 extern char curl_errorstr[CURL_ERROR_SIZE];
86 static inline int missing__target(int code, int result)
88 return /* file:// URL -- do we ever use one??? */
89 (result == CURLE_FILE_COULDNT_READ_FILE) ||
90 /* http:// and https:// URL */
91 (code == 404 && result == CURLE_HTTP_RETURNED_ERROR) ||
92 /* ftp:// URL */
93 (code == 550 && result == CURLE_FTP_COULDNT_RETR_FILE)
97 #define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
99 extern int http_fetch_ref(const char *base, const char *ref, unsigned char *sha1);
101 #endif /* HTTP_H */