X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=reposerve;a=blobdiff_plain;f=server%2Fsrc%2Fclient.c;h=e7f4d3c12163bdd65a3033b34abbb349d1a91aad;hp=bec2f11b4ea5a110231c9a5eca71d4f0b2e93874;hb=ec7b115817aa06ede0c2bf933ccdeeb893fdd831;hpb=779888af6bc05f2395e0c9fc0c53067e0674cb27 diff --git a/server/src/client.c b/server/src/client.c index bec2f11..e7f4d3c 100644 --- a/server/src/client.c +++ b/server/src/client.c @@ -1,12 +1,14 @@ #include #include #include +#include #include #include "client.h" #include "proto.h" #include "repo.h" static int proc_request(struct client *c); +static void print_invalid(const char *s); static int proc_flist(struct client *c, char *data, int datasz); static int proc_push(struct client *c, char *data, int datasz); static int proc_pull(struct client *c, char *data, int datasz); @@ -28,6 +30,8 @@ int handle_client(struct client *c) if(proc_request(c) == -1) { return -1; } + + if(sz == 0) return -1; return 0; } @@ -38,7 +42,12 @@ static int proc_request(struct client *c) int reqdata_len; while(endp < c->buf + c->bsz) { + if(*endp == '\r' && endp[1] == '\n') { + *endp++ = 0; + break; + } if(*endp == '\n') break; + endp++; } if(endp >= c->buf + c->bsz) { return 0; @@ -62,10 +71,27 @@ static int proc_request(struct client *c) return 0; } + print_invalid(c->buf); send_err(c); return 0; } +static void print_invalid(const char *s) +{ + int i; + printf("Recv invalid request: \""); + for(i=0; i<60; i++) { + if(!*s) break; + if(isprint(*s)) { + putchar(*s); + } else { + printf("\\x%x", (unsigned int)*s); + } + s++; + } + puts("\""); +} + void send_string(struct client *c, const char *s) { write(c->s, s, strlen(s)); @@ -85,8 +111,10 @@ void send_err(struct client *c) static struct flist *gen_flist(int contents) { - int i, count; + int i, count, len; struct flist *flist; + char *pathbuf = 0; + int pathbuf_sz = 0; if(!(flist = flist_create())) { return 0; @@ -98,10 +126,22 @@ static struct flist *gen_flist(int contents) count = repo_num_files(); for(i=0; ipath, contents); + len = strlen(repo_path) + strlen(repo_file(i)->path) + 1; + if(len > pathbuf_sz) { + free(pathbuf); + if(!(pathbuf = malloc(len + 1))) { + fprintf(stderr, "gen_flist: failed to allocate path buffer (%d bytes)\n", len + 1); + repo_cleanup(); + flist_destroy(flist); + return 0; + } + } + sprintf(pathbuf, "%s/%s", repo_path, repo_file(i)->path); + flist_add(flist, pathbuf, contents); } repo_cleanup(); + free(pathbuf); return flist; }