2005-11-19 03:02:58 +08:00
|
|
|
#ifndef HTTP_H
|
|
|
|
#define HTTP_H
|
|
|
|
|
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <curl/easy.h>
|
|
|
|
|
2007-12-10 03:30:59 +08:00
|
|
|
#include "strbuf.h"
|
2008-02-28 04:35:50 +08:00
|
|
|
#include "remote.h"
|
2010-11-25 16:21:04 +08:00
|
|
|
#include "url.h"
|
2007-12-10 03:30:59 +08:00
|
|
|
|
2008-01-22 09:34:43 +08:00
|
|
|
/*
|
|
|
|
* We detect based on the cURL version if multi-transfer is
|
|
|
|
* usable in this implementation and define this symbol accordingly.
|
|
|
|
* This is not something Makefile should set nor users should pass
|
|
|
|
* via CFLAGS.
|
|
|
|
*/
|
|
|
|
#undef USE_CURL_MULTI
|
|
|
|
|
2007-05-02 20:53:23 +08:00
|
|
|
#if LIBCURL_VERSION_NUM >= 0x071000
|
2005-11-19 03:02:58 +08:00
|
|
|
#define USE_CURL_MULTI
|
|
|
|
#define DEFAULT_MAX_REQUESTS 5
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if LIBCURL_VERSION_NUM < 0x070704
|
2010-08-13 06:11:15 +08:00
|
|
|
#define curl_global_cleanup() do { /* nothing */ } while (0)
|
2005-11-19 03:02:58 +08:00
|
|
|
#endif
|
|
|
|
#if LIBCURL_VERSION_NUM < 0x070800
|
2010-08-13 06:11:15 +08:00
|
|
|
#define curl_global_init(a) do { /* nothing */ } while (0)
|
2005-11-19 03:02:58 +08:00
|
|
|
#endif
|
|
|
|
|
2006-12-28 05:59:26 +08:00
|
|
|
#if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)
|
2005-11-19 03:02:58 +08:00
|
|
|
#define NO_CURL_EASY_DUPHANDLE
|
|
|
|
#endif
|
|
|
|
|
2006-09-19 20:20:19 +08:00
|
|
|
#if LIBCURL_VERSION_NUM < 0x070a03
|
|
|
|
#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
|
|
|
|
#endif
|
|
|
|
|
2009-04-02 00:48:24 +08:00
|
|
|
#if LIBCURL_VERSION_NUM < 0x070c03
|
|
|
|
#define NO_CURL_IOCTL
|
|
|
|
#endif
|
|
|
|
|
2011-03-16 15:08:34 +08:00
|
|
|
struct slot_results {
|
2006-02-01 03:06:55 +08:00
|
|
|
CURLcode curl_result;
|
|
|
|
long http_code;
|
|
|
|
};
|
|
|
|
|
2011-03-16 15:08:34 +08:00
|
|
|
struct active_request_slot {
|
2005-11-19 03:02:58 +08:00
|
|
|
CURL *curl;
|
|
|
|
int in_use;
|
|
|
|
CURLcode curl_result;
|
|
|
|
long http_code;
|
2006-03-11 12:18:01 +08:00
|
|
|
int *finished;
|
2006-02-01 03:06:55 +08:00
|
|
|
struct slot_results *results;
|
2005-11-19 03:02:58 +08:00
|
|
|
void *callback_data;
|
|
|
|
void (*callback_func)(void *data);
|
|
|
|
struct active_request_slot *next;
|
|
|
|
};
|
|
|
|
|
2011-03-16 15:08:34 +08:00
|
|
|
struct buffer {
|
2007-12-10 03:30:59 +08:00
|
|
|
struct strbuf buf;
|
|
|
|
size_t posn;
|
2005-11-19 03:02:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Curl request read/write callbacks */
|
2011-05-03 23:47:27 +08:00
|
|
|
extern size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
|
|
|
|
extern size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
|
|
|
|
extern size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
|
2009-04-02 00:48:24 +08:00
|
|
|
#ifndef NO_CURL_IOCTL
|
|
|
|
extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
|
|
|
|
#endif
|
2005-11-19 03:02:58 +08:00
|
|
|
|
|
|
|
/* Slot lifecycle functions */
|
|
|
|
extern struct active_request_slot *get_active_slot(void);
|
|
|
|
extern int start_active_slot(struct active_request_slot *slot);
|
|
|
|
extern void run_active_slot(struct active_request_slot *slot);
|
2009-10-31 08:47:41 +08:00
|
|
|
extern void finish_active_slot(struct active_request_slot *slot);
|
2005-11-19 03:02:58 +08:00
|
|
|
extern void finish_all_active_slots(void);
|
http: fix segfault in handle_curl_result
When we create an http active_request_slot, we can set its
"results" pointer back to local storage. The http code will
fill in the details of how the request went, and we can
access those details even after the slot has been cleaned
up.
Commit 8809703 (http: factor out http error code handling)
switched us from accessing our local results struct directly
to accessing it via the "results" pointer of the slot. That
means we're accessing the slot after it has been marked as
finished, defeating the whole purpose of keeping the results
storage separate.
Most of the time this doesn't matter, as finishing the slot
does not actually clean up the pointer. However, when using
curl's multi interface with the dumb-http revision walker,
we might actually start a new request before handing control
back to the original caller. In that case, we may reuse the
slot, zeroing its results pointer, and leading the original
caller to segfault while looking for its results inside the
slot.
Instead, we need to pass a pointer to our local results
storage to the handle_curl_result function, rather than
relying on the pointer in the slot struct. This matches what
the original code did before the refactoring (which did not
use a separate function, and therefore just accessed the
results struct directly).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-10-12 14:22:49 +08:00
|
|
|
extern int handle_curl_result(struct active_request_slot *slot,
|
|
|
|
struct slot_results *results);
|
2005-11-19 03:02:58 +08:00
|
|
|
|
|
|
|
#ifdef USE_CURL_MULTI
|
|
|
|
extern void fill_active_slots(void);
|
2007-09-11 11:02:34 +08:00
|
|
|
extern void add_fill_function(void *data, int (*fill)(void *));
|
2005-11-19 03:02:58 +08:00
|
|
|
extern void step_active_slots(void);
|
|
|
|
#endif
|
|
|
|
|
2011-12-14 08:11:56 +08:00
|
|
|
extern void http_init(struct remote *remote, const char *url,
|
|
|
|
int proactive_auth);
|
2005-11-19 03:02:58 +08:00
|
|
|
extern void http_cleanup(void);
|
|
|
|
|
|
|
|
extern int active_requests;
|
2009-06-06 16:43:41 +08:00
|
|
|
extern int http_is_verbose;
|
2009-10-31 08:47:41 +08:00
|
|
|
extern size_t http_post_buffer;
|
2005-11-19 03:02:58 +08:00
|
|
|
|
|
|
|
extern char curl_errorstr[CURL_ERROR_SIZE];
|
|
|
|
|
2007-12-11 05:36:09 +08:00
|
|
|
static inline int missing__target(int code, int result)
|
|
|
|
{
|
|
|
|
return /* file:// URL -- do we ever use one??? */
|
|
|
|
(result == CURLE_FILE_COULDNT_READ_FILE) ||
|
|
|
|
/* http:// and https:// URL */
|
|
|
|
(code == 404 && result == CURLE_HTTP_RETURNED_ERROR) ||
|
|
|
|
/* ftp:// URL */
|
|
|
|
(code == 550 && result == CURLE_FTP_COULDNT_RETR_FILE)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
|
|
|
|
|
http*: add helper methods for fetching objects (loose)
The code handling the fetching of loose objects in http-push.c and
http-walker.c have been refactored into new methods and a new struct
(object_http_request) in http.c. They are not meant to be invoked
elsewhere.
The new methods in http.c are
- new_http_object_request
- process_http_object_request
- finish_http_object_request
- abort_http_object_request
- release_http_object_request
and the new struct is http_object_request.
RANGER_HEADER_SIZE and no_pragma_header is no longer made available
outside of http.c, since after the above changes, there are no other
instances of usage outside of http.c.
Remove members of the transfer_request struct in http-push.c and
http-walker.c, including filename, real_sha1 and zret, as they are used
no longer used.
Move the methods append_remote_object_url() and get_remote_object_url()
from http-push.c to http.c. Additionally, get_remote_object_url() is no
longer defined only when USE_CURL_MULTI is defined, since
non-USE_CURL_MULTI code in http.c uses it (namely, in
new_http_object_request()).
Refactor code from http-push.c::start_fetch_loose() and
http-walker.c::start_object_fetch_request() that deals with the details
of coming up with the filename to store the retrieved object, resuming
a previously aborted request, and making a new curl request, into a new
function, new_http_object_request().
Refactor code from http-walker.c::process_object_request() into the
function, process_http_object_request().
Refactor code from http-push.c::finish_request() and
http-walker.c::finish_object_request() into a new function,
finish_http_object_request(). It returns the result of the
move_temp_to_file() invocation.
Add a function, release_http_object_request(), which cleans up object
request data. http-push.c and http-walker.c invoke this function
separately; http-push.c::release_request() and
http-walker.c::release_object_request() do not invoke this function.
Add a function, abort_http_object_request(), which unlink()s the object
file and invokes release_http_object_request(). Update
http-walker.c::abort_object_request() to use this.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-06 16:44:02 +08:00
|
|
|
/* Helpers for modifying and creating URLs */
|
|
|
|
extern void append_remote_object_url(struct strbuf *buf, const char *url,
|
|
|
|
const char *hex,
|
|
|
|
int only_two_digit_prefix);
|
|
|
|
extern char *get_remote_object_url(const char *url, const char *hex,
|
|
|
|
int only_two_digit_prefix);
|
|
|
|
|
2009-06-06 16:43:53 +08:00
|
|
|
/* Options for http_request_*() */
|
|
|
|
#define HTTP_NO_CACHE 1
|
|
|
|
|
|
|
|
/* Return values for http_request_*() */
|
|
|
|
#define HTTP_OK 0
|
|
|
|
#define HTTP_MISSING_TARGET 1
|
|
|
|
#define HTTP_ERROR 2
|
|
|
|
#define HTTP_START_FAILED 3
|
2010-04-02 06:14:35 +08:00
|
|
|
#define HTTP_REAUTH 4
|
|
|
|
#define HTTP_NOAUTH 5
|
2009-06-06 16:43:53 +08:00
|
|
|
|
|
|
|
/*
|
2012-03-28 16:41:54 +08:00
|
|
|
* Requests a URL and stores the result in a strbuf.
|
2009-06-06 16:43:53 +08:00
|
|
|
*
|
|
|
|
* If the result pointer is NULL, a HTTP HEAD request is made instead of GET.
|
|
|
|
*/
|
|
|
|
int http_get_strbuf(const char *url, struct strbuf *result, int options);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prints an error message using error() containing url and curl_errorstr,
|
|
|
|
* and returns ret.
|
|
|
|
*/
|
|
|
|
int http_error(const char *url, int ret);
|
|
|
|
|
Make walker.fetch_ref() take a struct ref.
This simplifies a few things, makes a few things slightly more
complicated, but, more importantly, allows that, when struct ref can
represent a symref, http_fetch_ref() can return one.
Incidentally makes the string that http_fetch_ref() gets include "refs/"
(if appropriate), because that's how the name field of struct ref works.
As far as I can tell, the usage in walker:interpret_target() wouldn't have
worked previously, if it ever would have been used, which it wouldn't
(since the fetch process uses the hash instead of the name of the ref
there).
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-04-27 03:53:09 +08:00
|
|
|
extern int http_fetch_ref(const char *base, struct ref *ref);
|
2007-12-11 07:08:25 +08:00
|
|
|
|
2009-06-06 16:43:59 +08:00
|
|
|
/* Helpers for fetching packs */
|
|
|
|
extern int http_get_info_packs(const char *base_url,
|
|
|
|
struct packed_git **packs_head);
|
|
|
|
|
2011-03-16 15:08:34 +08:00
|
|
|
struct http_pack_request {
|
2009-06-06 16:44:01 +08:00
|
|
|
char *url;
|
|
|
|
struct packed_git *target;
|
|
|
|
struct packed_git **lst;
|
|
|
|
FILE *packfile;
|
|
|
|
char tmpfile[PATH_MAX];
|
|
|
|
struct curl_slist *range_header;
|
|
|
|
struct active_request_slot *slot;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct http_pack_request *new_http_pack_request(
|
|
|
|
struct packed_git *target, const char *base_url);
|
|
|
|
extern int finish_http_pack_request(struct http_pack_request *preq);
|
|
|
|
extern void release_http_pack_request(struct http_pack_request *preq);
|
|
|
|
|
http*: add helper methods for fetching objects (loose)
The code handling the fetching of loose objects in http-push.c and
http-walker.c have been refactored into new methods and a new struct
(object_http_request) in http.c. They are not meant to be invoked
elsewhere.
The new methods in http.c are
- new_http_object_request
- process_http_object_request
- finish_http_object_request
- abort_http_object_request
- release_http_object_request
and the new struct is http_object_request.
RANGER_HEADER_SIZE and no_pragma_header is no longer made available
outside of http.c, since after the above changes, there are no other
instances of usage outside of http.c.
Remove members of the transfer_request struct in http-push.c and
http-walker.c, including filename, real_sha1 and zret, as they are used
no longer used.
Move the methods append_remote_object_url() and get_remote_object_url()
from http-push.c to http.c. Additionally, get_remote_object_url() is no
longer defined only when USE_CURL_MULTI is defined, since
non-USE_CURL_MULTI code in http.c uses it (namely, in
new_http_object_request()).
Refactor code from http-push.c::start_fetch_loose() and
http-walker.c::start_object_fetch_request() that deals with the details
of coming up with the filename to store the retrieved object, resuming
a previously aborted request, and making a new curl request, into a new
function, new_http_object_request().
Refactor code from http-walker.c::process_object_request() into the
function, process_http_object_request().
Refactor code from http-push.c::finish_request() and
http-walker.c::finish_object_request() into a new function,
finish_http_object_request(). It returns the result of the
move_temp_to_file() invocation.
Add a function, release_http_object_request(), which cleans up object
request data. http-push.c and http-walker.c invoke this function
separately; http-push.c::release_request() and
http-walker.c::release_object_request() do not invoke this function.
Add a function, abort_http_object_request(), which unlink()s the object
file and invokes release_http_object_request(). Update
http-walker.c::abort_object_request() to use this.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-06 16:44:02 +08:00
|
|
|
/* Helpers for fetching object */
|
2011-03-16 15:08:34 +08:00
|
|
|
struct http_object_request {
|
http*: add helper methods for fetching objects (loose)
The code handling the fetching of loose objects in http-push.c and
http-walker.c have been refactored into new methods and a new struct
(object_http_request) in http.c. They are not meant to be invoked
elsewhere.
The new methods in http.c are
- new_http_object_request
- process_http_object_request
- finish_http_object_request
- abort_http_object_request
- release_http_object_request
and the new struct is http_object_request.
RANGER_HEADER_SIZE and no_pragma_header is no longer made available
outside of http.c, since after the above changes, there are no other
instances of usage outside of http.c.
Remove members of the transfer_request struct in http-push.c and
http-walker.c, including filename, real_sha1 and zret, as they are used
no longer used.
Move the methods append_remote_object_url() and get_remote_object_url()
from http-push.c to http.c. Additionally, get_remote_object_url() is no
longer defined only when USE_CURL_MULTI is defined, since
non-USE_CURL_MULTI code in http.c uses it (namely, in
new_http_object_request()).
Refactor code from http-push.c::start_fetch_loose() and
http-walker.c::start_object_fetch_request() that deals with the details
of coming up with the filename to store the retrieved object, resuming
a previously aborted request, and making a new curl request, into a new
function, new_http_object_request().
Refactor code from http-walker.c::process_object_request() into the
function, process_http_object_request().
Refactor code from http-push.c::finish_request() and
http-walker.c::finish_object_request() into a new function,
finish_http_object_request(). It returns the result of the
move_temp_to_file() invocation.
Add a function, release_http_object_request(), which cleans up object
request data. http-push.c and http-walker.c invoke this function
separately; http-push.c::release_request() and
http-walker.c::release_object_request() do not invoke this function.
Add a function, abort_http_object_request(), which unlink()s the object
file and invokes release_http_object_request(). Update
http-walker.c::abort_object_request() to use this.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-06 16:44:02 +08:00
|
|
|
char *url;
|
|
|
|
char tmpfile[PATH_MAX];
|
|
|
|
int localfile;
|
|
|
|
CURLcode curl_result;
|
|
|
|
char errorstr[CURL_ERROR_SIZE];
|
|
|
|
long http_code;
|
|
|
|
unsigned char sha1[20];
|
|
|
|
unsigned char real_sha1[20];
|
|
|
|
git_SHA_CTX c;
|
2011-06-11 02:52:15 +08:00
|
|
|
git_zstream stream;
|
http*: add helper methods for fetching objects (loose)
The code handling the fetching of loose objects in http-push.c and
http-walker.c have been refactored into new methods and a new struct
(object_http_request) in http.c. They are not meant to be invoked
elsewhere.
The new methods in http.c are
- new_http_object_request
- process_http_object_request
- finish_http_object_request
- abort_http_object_request
- release_http_object_request
and the new struct is http_object_request.
RANGER_HEADER_SIZE and no_pragma_header is no longer made available
outside of http.c, since after the above changes, there are no other
instances of usage outside of http.c.
Remove members of the transfer_request struct in http-push.c and
http-walker.c, including filename, real_sha1 and zret, as they are used
no longer used.
Move the methods append_remote_object_url() and get_remote_object_url()
from http-push.c to http.c. Additionally, get_remote_object_url() is no
longer defined only when USE_CURL_MULTI is defined, since
non-USE_CURL_MULTI code in http.c uses it (namely, in
new_http_object_request()).
Refactor code from http-push.c::start_fetch_loose() and
http-walker.c::start_object_fetch_request() that deals with the details
of coming up with the filename to store the retrieved object, resuming
a previously aborted request, and making a new curl request, into a new
function, new_http_object_request().
Refactor code from http-walker.c::process_object_request() into the
function, process_http_object_request().
Refactor code from http-push.c::finish_request() and
http-walker.c::finish_object_request() into a new function,
finish_http_object_request(). It returns the result of the
move_temp_to_file() invocation.
Add a function, release_http_object_request(), which cleans up object
request data. http-push.c and http-walker.c invoke this function
separately; http-push.c::release_request() and
http-walker.c::release_object_request() do not invoke this function.
Add a function, abort_http_object_request(), which unlink()s the object
file and invokes release_http_object_request(). Update
http-walker.c::abort_object_request() to use this.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-06 16:44:02 +08:00
|
|
|
int zret;
|
|
|
|
int rename;
|
|
|
|
struct active_request_slot *slot;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct http_object_request *new_http_object_request(
|
|
|
|
const char *base_url, unsigned char *sha1);
|
|
|
|
extern void process_http_object_request(struct http_object_request *freq);
|
|
|
|
extern int finish_http_object_request(struct http_object_request *freq);
|
|
|
|
extern void abort_http_object_request(struct http_object_request *freq);
|
|
|
|
extern void release_http_object_request(struct http_object_request *freq);
|
|
|
|
|
2005-11-19 03:02:58 +08:00
|
|
|
#endif /* HTTP_H */
|