]> git.ipfire.org Git - thirdparty/git.git/blame - http.h
Merge branch 'maint'
[thirdparty/git.git] / http.h
CommitLineData
29508e1e
NH
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
028c2976
MH
9#include "strbuf.h"
10
4f5f998f
JH
11/*
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.
16 */
17#undef USE_CURL_MULTI
18
9cf04301 19#if LIBCURL_VERSION_NUM >= 0x071000
29508e1e
NH
20#define USE_CURL_MULTI
21#define DEFAULT_MAX_REQUESTS 5
22#endif
23
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
30
500ebb01 31#if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
29508e1e
NH
32#define NO_CURL_EASY_DUPHANDLE
33#endif
34
c774b2dc
AH
35#if LIBCURL_VERSION_NUM < 0x070a03
36#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
37#endif
38
c8568e13
NH
39struct slot_results
40{
41 CURLcode curl_result;
42 long http_code;
43};
44
29508e1e
NH
45struct active_request_slot
46{
47 CURL *curl;
48 FILE *local;
49 int in_use;
50 CURLcode curl_result;
51 long http_code;
baa7b67d 52 int *finished;
c8568e13 53 struct slot_results *results;
29508e1e
NH
54 void *callback_data;
55 void (*callback_func)(void *data);
56 struct active_request_slot *next;
57};
58
59struct buffer
60{
028c2976
MH
61 struct strbuf buf;
62 size_t posn;
29508e1e
NH
63};
64
65/* Curl request read/write callbacks */
66extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
67 struct buffer *buffer);
68extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
028c2976 69 size_t nmemb, struct strbuf *buffer);
29508e1e 70extern size_t fwrite_null(const void *ptr, size_t eltsize,
028c2976 71 size_t nmemb, struct strbuf *buffer);
29508e1e
NH
72
73/* Slot lifecycle functions */
74extern struct active_request_slot *get_active_slot(void);
75extern int start_active_slot(struct active_request_slot *slot);
76extern void run_active_slot(struct active_request_slot *slot);
77extern void finish_all_active_slots(void);
53f31389 78extern void release_active_slot(struct active_request_slot *slot);
29508e1e
NH
79
80#ifdef USE_CURL_MULTI
81extern void fill_active_slots(void);
fc57b6aa 82extern void add_fill_function(void *data, int (*fill)(void *));
29508e1e
NH
83extern void step_active_slots(void);
84#endif
85
86extern void http_init(void);
87extern void http_cleanup(void);
88
89extern int data_received;
90extern int active_requests;
91
29508e1e
NH
92extern char curl_errorstr[CURL_ERROR_SIZE];
93
e8dc37e0
MH
94static inline int missing__target(int code, int result)
95{
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)
102 ;
103}
104
105#define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
106
d7e92806
MH
107extern int http_fetch_ref(const char *base, const char *ref, unsigned char *sha1);
108
29508e1e 109#endif /* HTTP_H */