]> git.ipfire.org Git - thirdparty/git.git/blame - http.h
Fix various memory leaks in http-push.c and http-walker.c
[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
9cf04301 11#if LIBCURL_VERSION_NUM >= 0x071000
29508e1e
NH
12#define USE_CURL_MULTI
13#define DEFAULT_MAX_REQUESTS 5
14#endif
15
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
22
500ebb01 23#if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
29508e1e
NH
24#define NO_CURL_EASY_DUPHANDLE
25#endif
26
c774b2dc
AH
27#if LIBCURL_VERSION_NUM < 0x070a03
28#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
29#endif
30
c8568e13
NH
31struct slot_results
32{
33 CURLcode curl_result;
34 long http_code;
35};
36
29508e1e
NH
37struct active_request_slot
38{
39 CURL *curl;
40 FILE *local;
41 int in_use;
42 CURLcode curl_result;
43 long http_code;
baa7b67d 44 int *finished;
c8568e13 45 struct slot_results *results;
29508e1e
NH
46 void *callback_data;
47 void (*callback_func)(void *data);
48 struct active_request_slot *next;
49};
50
51struct buffer
52{
028c2976
MH
53 struct strbuf buf;
54 size_t posn;
29508e1e
NH
55};
56
57/* Curl request read/write callbacks */
58extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
59 struct buffer *buffer);
60extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
028c2976 61 size_t nmemb, struct strbuf *buffer);
29508e1e 62extern size_t fwrite_null(const void *ptr, size_t eltsize,
028c2976 63 size_t nmemb, struct strbuf *buffer);
29508e1e
NH
64
65/* Slot lifecycle functions */
66extern struct active_request_slot *get_active_slot(void);
67extern int start_active_slot(struct active_request_slot *slot);
68extern void run_active_slot(struct active_request_slot *slot);
69extern void finish_all_active_slots(void);
53f31389 70extern void release_active_slot(struct active_request_slot *slot);
29508e1e
NH
71
72#ifdef USE_CURL_MULTI
73extern void fill_active_slots(void);
fc57b6aa 74extern void add_fill_function(void *data, int (*fill)(void *));
29508e1e
NH
75extern void step_active_slots(void);
76#endif
77
78extern void http_init(void);
79extern void http_cleanup(void);
80
81extern int data_received;
82extern int active_requests;
83
29508e1e
NH
84extern char curl_errorstr[CURL_ERROR_SIZE];
85
e8dc37e0
MH
86static inline int missing__target(int code, int result)
87{
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)
94 ;
95}
96
97#define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
98
29508e1e 99#endif /* HTTP_H */