Avoid redundant declaration of missing_target()
[git/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
9cf04301 9#if LIBCURL_VERSION_NUM >= 0x071000
29508e1e
NH
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
500ebb01 21#if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
29508e1e
NH
22#define NO_CURL_EASY_DUPHANDLE
23#endif
24
c774b2dc
AH
25#if LIBCURL_VERSION_NUM < 0x070a03
26#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
27#endif
28
c8568e13
NH
29struct slot_results
30{
31 CURLcode curl_result;
32 long http_code;
33};
34
29508e1e
NH
35struct active_request_slot
36{
37 CURL *curl;
38 FILE *local;
39 int in_use;
40 CURLcode curl_result;
41 long http_code;
baa7b67d 42 int *finished;
c8568e13 43 struct slot_results *results;
29508e1e
NH
44 void *callback_data;
45 void (*callback_func)(void *data);
46 struct active_request_slot *next;
47};
48
49struct buffer
50{
51 size_t posn;
52 size_t size;
53 void *buffer;
54};
55
56/* Curl request read/write callbacks */
57extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
58 struct buffer *buffer);
59extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
60 size_t nmemb, struct buffer *buffer);
61extern size_t fwrite_null(const void *ptr, size_t eltsize,
62 size_t nmemb, struct buffer *buffer);
63
64/* Slot lifecycle functions */
65extern struct active_request_slot *get_active_slot(void);
66extern int start_active_slot(struct active_request_slot *slot);
67extern void run_active_slot(struct active_request_slot *slot);
68extern void finish_all_active_slots(void);
53f31389 69extern void release_active_slot(struct active_request_slot *slot);
29508e1e
NH
70
71#ifdef USE_CURL_MULTI
72extern void fill_active_slots(void);
fc57b6aa 73extern void add_fill_function(void *data, int (*fill)(void *));
29508e1e
NH
74extern void step_active_slots(void);
75#endif
76
77extern void http_init(void);
78extern void http_cleanup(void);
79
80extern int data_received;
81extern int active_requests;
82
29508e1e
NH
83extern char curl_errorstr[CURL_ERROR_SIZE];
84
e8dc37e0
MH
85static inline int missing__target(int code, int result)
86{
87 return /* file:// URL -- do we ever use one??? */
88 (result == CURLE_FILE_COULDNT_READ_FILE) ||
89 /* http:// and https:// URL */
90 (code == 404 && result == CURLE_HTTP_RETURNED_ERROR) ||
91 /* ftp:// URL */
92 (code == 550 && result == CURLE_FTP_COULDNT_RETR_FILE)
93 ;
94}
95
96#define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
97
29508e1e 98#endif /* HTTP_H */