http.hon commit git-rebase -i: clean-up error check codepath. (ab11903)
   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
   9#include "strbuf.h"
  10
  11#if LIBCURL_VERSION_NUM >= 0x071000
  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
  23#if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
  24#define NO_CURL_EASY_DUPHANDLE
  25#endif
  26
  27#if LIBCURL_VERSION_NUM < 0x070a03
  28#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
  29#endif
  30
  31struct slot_results
  32{
  33        CURLcode curl_result;
  34        long http_code;
  35};
  36
  37struct active_request_slot
  38{
  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;
  49};
  50
  51struct buffer
  52{
  53        struct strbuf buf;
  54        size_t posn;
  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,
  61                            size_t nmemb, struct strbuf *buffer);
  62extern size_t fwrite_null(const void *ptr, size_t eltsize,
  63                          size_t nmemb, struct strbuf *buffer);
  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);
  70extern void release_active_slot(struct active_request_slot *slot);
  71
  72#ifdef USE_CURL_MULTI
  73extern void fill_active_slots(void);
  74extern void add_fill_function(void *data, int (*fill)(void *));
  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
  84extern char curl_errorstr[CURL_ERROR_SIZE];
  85
  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
  99extern int http_fetch_ref(const char *base, const char *ref, unsigned char *sha1);
 100
 101#endif /* HTTP_H */