9 static int proc_request(struct client *c);
10 static int proc_flist(struct client *c, char *data, int datasz);
11 static int proc_push(struct client *c, char *data, int datasz);
12 static int proc_pull(struct client *c, char *data, int datasz);
14 const char *repo_path;
16 int handle_client(struct client *c)
21 while((sz = read(c->s, buf, sizeof buf)) > 0) {
22 left = sizeof c->buf - c->bsz;
23 if(sz > left) sz = left;
24 memcpy(c->buf + c->bsz, buf, sz);
28 if(proc_request(c) == -1) {
34 static int proc_request(struct client *c)
40 while(endp < c->buf + c->bsz) {
41 if(*endp == '\n') break;
43 if(endp >= c->buf + c->bsz) {
49 reqdata_len = c->bsz - (reqdata - c->buf);
53 if(strcmp(c->buf, "flist") == 0) {
54 return proc_flist(c, reqdata, reqdata_len);
55 } else if(strcmp(c->buf, "push") == 0) {
56 return proc_push(c, reqdata, reqdata_len);
57 } else if(strcmp(c->buf, "pull") == 0) {
58 return proc_pull(c, reqdata, reqdata_len);
59 } else if(strcmp(c->buf, "dos") == 0) {
60 c->flags |= CLIENT_DOS;
69 void send_string(struct client *c, const char *s)
71 write(c->s, s, strlen(s));
74 void send_ok(struct client *c, int resp_sz)
77 sprintf(buf, "OK %d\n", resp_sz < 0 ? 0 : resp_sz);
81 void send_err(struct client *c)
83 send_string(c, "ERR\n");
86 static struct flist *gen_flist(int contents)
91 if(!(flist = flist_create())) {
95 if(repo_init(repo_path) == -1) {
98 count = repo_num_files();
100 for(i=0; i<count; i++) {
101 flist_add(flist, repo_file(i)->path, contents);
108 static int proc_flist(struct client *c, char *data, int datasz)
112 if(!(flist = gen_flist(0))) {
116 flist_finalize(flist);
118 send_ok(c, flist->final_size);
119 write(c->s, flist->flist, flist->final_size);
121 flist_destroy(flist);
125 static int proc_push(struct client *c, char *data, int datasz)
131 static int proc_pull(struct client *c, char *data, int datasz)