#include "cache.h"
#include "commit.h"
#include "pack.h"
#include "fetch.h"
#include "http.h"
#ifndef NO_EXPAT
#include <expat.h>
/* Definitions for DAV requests */
#define DAV_PROPFIND "PROPFIND"
#define DAV_PROPFIND_RESP ".multistatus.response"
#define DAV_PROPFIND_NAME ".multistatus.response.href"
#define DAV_PROPFIND_COLLECTION ".multistatus.response.propstat.prop.resourcetype.collection"
#define PROPFIND_ALL_REQUEST "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<D:propfind xmlns:D=\"DAV:\">\n<D:allprop/>\n</D:propfind>"
/* Definitions for processing XML DAV responses */
#ifndef XML_STATUS_OK
enum XML_Status {
XML_STATUS_OK = 1,
XML_STATUS_ERROR = 0
};
#define XML_STATUS_OK 1
#define XML_STATUS_ERROR 0
#endif
/* Flags that control remote_ls processing */
#define PROCESS_FILES (1u << 0)
#define PROCESS_DIRS (1u << 1)
#define RECURSIVE (1u << 2)
/* Flags that remote_ls passes to callback functions */
#define IS_DIR (1u << 0)
#endif
#define PREV_BUF_SIZE 4096
#define RANGE_HEADER_SIZE 30
static int got_alternates = -1;
static int corrupt_object_found = 0;
static struct curl_slist *no_pragma_header;
struct alt_base
{
char *base;
int path_len;
int got_indices;
struct packed_git *packs;
struct alt_base *next;
};
static struct alt_base *alt = NULL;
enum object_request_state {
WAITING,
ABORTED,
ACTIVE,
COMPLETE,
};
struct object_request
{
unsigned char sha1[20];
struct alt_base *repo;
char *url;
char filename[PATH_MAX];
char tmpfile[PATH_MAX];
int local;
enum object_request_state state;
CURLcode curl_result;
char errorstr[CURL_ERROR_SIZE];
long http_code;
unsigned char real_sha1[20];
SHA_CTX c;
z_stream stream;
int zret;
int rename;
struct active_request_slot *slot;
struct object_request *next;
};
struct alternates_request {
char *base;
char *url;
struct buffer *buffer;
struct active_request_slot *slot;
int http_specific;
};
#ifndef NO_EXPAT
struct xml_ctx
{
char *name;
int len;
char *cdata;
void (*userFunc)(struct xml_ctx *ctx, int tag_closed);
void *userData;
};
struct remote_ls_ctx
{
struct alt_base *repo;
char *path;
void (*userFunc)(struct remote_ls_ctx *ls);
void *userData;
int flags;
char *dentry_name;
int dentry_flags;
int rc;
struct remote_ls_ctx *parent;
};
#endif
static struct object_request *object_queue_head = NULL;
static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
void *data)
{
unsigned char expn[4096];
size_t size = eltsize * nmemb;
int posn = 0;
struct object_request *obj_req = (struct object_request *)data;
do {
ssize_t retval = write(obj_req->local,
ptr + posn, size - posn);
if (retval < 0)
return posn;
posn += retval;
} while (posn < size);
obj_req->stream.avail_in = size;
obj_req->stream.next_in = ptr;
do {
obj_req->stream.next_out = expn;
obj_req->stream.avail_out = sizeof(expn);
obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH);
SHA1_Update(&obj_req->c, expn,
sizeof(expn) - obj_req->stream.avail_out);
} while (obj_req->stream.avail_in && obj_req->zret == Z_OK);
data_received++;
return size;
}
static void fetch_alternates(char *base);
static void process_object_response(void *callback_data);
static void
|