X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=http-backend.c;h=14c90c2e84afd9997e1a6453f0065b3f59b32e57;hb=385cc9d8c44eb5be9d57e630129752a72c0a08c8;hp=f729488fc5f787c0f4997aacdd1bb14732d717f7;hpb=ad336054068074ed614d0bb54bb169e5263499d7;p=git.git diff --git a/http-backend.c b/http-backend.c index f729488fc..14c90c2e8 100644 --- a/http-backend.c +++ b/http-backend.c @@ -6,6 +6,7 @@ #include "exec_cmd.h" #include "run-command.h" #include "string-list.h" +#include "url.h" static const char content_type[] = "Content-Type"; static const char content_length[] = "Content-Length"; @@ -25,60 +26,6 @@ static struct rpc_service rpc_service[] = { { "receive-pack", "receivepack", -1 }, }; -static int decode_char(const char *q) -{ - int i; - unsigned char val = 0; - for (i = 0; i < 2; i++) { - unsigned char c = *q++; - val <<= 4; - if (c >= '0' && c <= '9') - val += c - '0'; - else if (c >= 'a' && c <= 'f') - val += c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val += c - 'A' + 10; - else - return -1; - } - return val; -} - -static char *decode_parameter(const char **query, int is_name) -{ - const char *q = *query; - struct strbuf out; - - strbuf_init(&out, 16); - do { - unsigned char c = *q; - - if (!c) - break; - if (c == '&' || (is_name && c == '=')) { - q++; - break; - } - - if (c == '%') { - int val = decode_char(q + 1); - if (0 <= val) { - strbuf_addch(&out, val); - q += 3; - continue; - } - } - - if (c == '+') - strbuf_addch(&out, ' '); - else - strbuf_addch(&out, c); - q++; - } while (1); - *query = q; - return strbuf_detach(&out, NULL); -} - static struct string_list *get_parameters(void) { if (!query_params) { @@ -86,13 +33,13 @@ static struct string_list *get_parameters(void) query_params = xcalloc(1, sizeof(*query_params)); while (query && *query) { - char *name = decode_parameter(&query, 1); - char *value = decode_parameter(&query, 0); + char *name = url_decode_parameter_name(&query); + char *value = url_decode_parameter_value(&query); struct string_list_item *i; - i = string_list_lookup(name, query_params); + i = string_list_lookup(query_params, name); if (!i) - i = string_list_insert(name, query_params); + i = string_list_insert(query_params, name); else free(i->util); i->util = value; @@ -104,7 +51,7 @@ static struct string_list *get_parameters(void) static const char *get_parameter(const char *name) { struct string_list_item *i; - i = string_list_lookup(name, get_parameters()); + i = string_list_lookup(get_parameters(), name); return i ? i->util : NULL; } @@ -538,15 +485,17 @@ static void service_rpc(char *service_name) static NORETURN void die_webcgi(const char *err, va_list params) { - char buffer[1000]; + static int dead; - http_status(500, "Internal Server Error"); - hdr_nocache(); - end_headers(); + if (!dead) { + dead = 1; + http_status(500, "Internal Server Error"); + hdr_nocache(); + end_headers(); - vsnprintf(buffer, sizeof(buffer), err, params); - fprintf(stderr, "fatal: %s\n", buffer); - exit(0); + vreportf("fatal: ", err, params); + } + exit(0); /* we successfully reported a failure ;-) */ } static char* getdir(void) @@ -648,6 +597,9 @@ int main(int argc, char **argv) setup_path(); if (!enter_repo(dir, 0)) not_found("Not a git repository: '%s'", dir); + if (!getenv("GIT_HTTP_EXPORT_ALL") && + access("git-daemon-export-ok", F_OK) ) + not_found("Repository not exported: '%s'", dir); git_config(http_config, NULL); cmd->imp(cmd_arg);