http-push: avoid a needless goto
[git/raj.git] / http.h
blob9bab2c88210650e2aaa271a72eb7192cd2f7331b
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"
12 * We detect based on the cURL version if multi-transfer is
13 * usable in this implementation and define this symbol accordingly.
14 * This is not something Makefile should set nor users should pass
15 * via CFLAGS.
17 #undef USE_CURL_MULTI
19 #if LIBCURL_VERSION_NUM >= 0x071000
20 #define USE_CURL_MULTI
21 #define DEFAULT_MAX_REQUESTS 5
22 #endif
24 #if LIBCURL_VERSION_NUM < 0x070704
25 #define curl_global_cleanup() do { /* nothing */ } while(0)
26 #endif
27 #if LIBCURL_VERSION_NUM < 0x070800
28 #define curl_global_init(a) do { /* nothing */ } while(0)
29 #endif
31 #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
32 #define NO_CURL_EASY_DUPHANDLE
33 #endif
35 #if LIBCURL_VERSION_NUM < 0x070a03
36 #define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
37 #endif
39 struct slot_results
41 CURLcode curl_result;
42 long http_code;
45 struct active_request_slot
47 CURL *curl;
48 FILE *local;
49 int in_use;
50 CURLcode curl_result;
51 long http_code;
52 int *finished;
53 struct slot_results *results;
54 void *callback_data;
55 void (*callback_func)(void *data);
56 struct active_request_slot *next;
59 struct buffer
61 struct strbuf buf;
62 size_t posn;
65 /* Curl request read/write callbacks */
66 extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
67 struct buffer *buffer);
68 extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
69 size_t nmemb, struct strbuf *buffer);
70 extern size_t fwrite_null(const void *ptr, size_t eltsize,
71 size_t nmemb, struct strbuf *buffer);
73 /* Slot lifecycle functions */
74 extern struct active_request_slot *get_active_slot(void);
75 extern int start_active_slot(struct active_request_slot *slot);
76 extern void run_active_slot(struct active_request_slot *slot);
77 extern void finish_all_active_slots(void);
78 extern void release_active_slot(struct active_request_slot *slot);
80 #ifdef USE_CURL_MULTI
81 extern void fill_active_slots(void);
82 extern void add_fill_function(void *data, int (*fill)(void *));
83 extern void step_active_slots(void);
84 #endif
86 extern void http_init(void);
87 extern void http_cleanup(void);
89 extern int data_received;
90 extern int active_requests;
92 extern char curl_errorstr[CURL_ERROR_SIZE];
94 static inline int missing__target(int code, int result)
96 return /* file:// URL -- do we ever use one??? */
97 (result == CURLE_FILE_COULDNT_READ_FILE) ||
98 /* http:// and https:// URL */
99 (code == 404 && result == CURLE_HTTP_RETURNED_ERROR) ||
100 /* ftp:// URL */
101 (code == 550 && result == CURLE_FTP_COULDNT_RETR_FILE)
105 #define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
107 extern int http_fetch_ref(const char *base, const char *ref, unsigned char *sha1);
109 #endif /* HTTP_H */