#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include <unistd.h>
#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);
if(proc_request(c) == -1) {
return -1;
}
+
+ if(sz == 0) return -1;
return 0;
}
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;
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));
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;
count = repo_num_files();
for(i=0; i<count; i++) {
- flist_add(flist, repo_file(i)->path, 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, repo_file(i)->path, pathbuf, contents);
}
repo_cleanup();
+ free(pathbuf);
return flist;
}