http.hon commit builtin-tag.c: remove cruft (fd74cb0)
   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/*
  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
  19#if LIBCURL_VERSION_NUM >= 0x071000
  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
  31#if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
  32#define NO_CURL_EASY_DUPHANDLE
  33#endif
  34
  35#if LIBCURL_VERSION_NUM < 0x070a03
  36#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
  37#endif
  38
  39struct slot_results
  40{
  41        CURLcode curl_result;
  42        long http_code;
  43};
  44
  45struct active_request_slot
  46{
  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;
  57};
  58
  59struct buffer
  60{
  61        struct strbuf buf;
  62        size_t posn;
  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,
  69                            size_t nmemb, struct strbuf *buffer);
  70extern size_t fwrite_null(const void *ptr, size_t eltsize,
  71                          size_t nmemb, struct strbuf *buffer);
  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);
  78extern void release_active_slot(struct active_request_slot *slot);
  79
  80#ifdef USE_CURL_MULTI
  81extern void fill_active_slots(void);
  82extern void add_fill_function(void *data, int (*fill)(void *));
  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
  92extern char curl_errorstr[CURL_ERROR_SIZE];
  93
  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
 107extern int http_fetch_ref(const char *base, const char *ref, unsigned char *sha1);
 108
 109#endif /* HTTP_H */