From: Martin Mares Date: Mon, 4 Jun 2007 08:21:35 +0000 (+0200) Subject: First parts of submit command. X-Git-Tag: python-dummy-working~406 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b451c5db7c24116c306eb1ce207641350ef98d8f;p=eval.git First parts of submit command. --- diff --git a/submit/Makefile b/submit/Makefile index b5a7c1d..cf9ee31 100644 --- a/submit/Makefile +++ b/submit/Makefile @@ -9,9 +9,10 @@ CFLAGS+=-Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializer all: submitd connect -submitd: submitd.o commands.o lib/libsh.a lib/libucw.a +submitd: submitd.o commands.o tasks.o lib/libsh.a lib/libucw.a submitd.o: submitd.c submitd.h commands.o: commands.c submitd.h +tasks.o: tasks.c submitd.h connect: connect.o lib/libucw.a connect.o: connect.c diff --git a/submit/PROTOCOL b/submit/PROTOCOL index 7002b5a..cbb5568 100644 --- a/submit/PROTOCOL +++ b/submit/PROTOCOL @@ -25,3 +25,18 @@ Hello request: Hello reply: (only status) + +Submit request: + + !SUBMIT + Ttask + Ssize + (after the request is ACK-ed, the client sends raw data and then server sends a 2nd reply) + +Submit reply: + + (only status) + +Submit reply after data: + + (only status) diff --git a/submit/commands.c b/submit/commands.c index 687e272..e583d66 100644 --- a/submit/commands.c +++ b/submit/commands.c @@ -6,12 +6,9 @@ #include "lib/lib.h" #include "lib/mempool.h" -#include "lib/stkstring.h" #include "sherlock/object.h" #include "sherlock/objread.h" -#include - #include "submitd.h" /*** REQUESTS AND REPLIES ***/ @@ -63,6 +60,8 @@ read_request(struct conn *c) static void write_reply(struct conn *c) { + if (!obj_find_attr(c->reply, '-') && !obj_find_attr(c->reply, '+')) + obj_set_attr(c->reply, '+', "OK"); if (trace_commands) { byte *msg; @@ -79,6 +78,31 @@ write_reply(struct conn *c) bflush(&c->tx_fb); } +static void +err(struct conn *c, byte *msg) +{ + obj_set_attr(c->reply, '-', msg); +} + +/*** SUBMIT ***/ + +static void +cmd_submit(struct conn *c) +{ + byte *tname = obj_find_aval(c->request, 'T'); + if (!tname) + { + err(c, "No task specified"); + return; + } + struct task *task = task_find(tname); + if (!task) + { + err(c, "No such task"); + return; + } +} + /*** COMMAND MUX ***/ static void @@ -87,12 +111,15 @@ execute_command(struct conn *c) byte *cmd = obj_find_aval(c->request, '!'); if (!cmd) { - obj_set_attr(c->reply, '-', "Missing command"); + err(c, "Missing command"); return; } if (trace_commands) log(L_DEBUG, "<< %s", cmd); - obj_set_attr(c->reply, '-', "Unknown command"); + if (!strcasecmp(cmd, "SUBMIT")) + cmd_submit(c); + else + err(c, "Unknown command"); } int @@ -107,21 +134,13 @@ process_command(struct conn *c) /*** INITIAL HANDSHAKE ***/ -static int -user_exists_p(byte *user) -{ - byte *fn = stk_printf("solutions/%s/status", user); - struct stat st; - return !stat(fn, &st) && S_ISREG(st.st_mode); -} - static void execute_init(struct conn *c) { byte *user = obj_find_aval(c->request, 'U'); if (!user) { - obj_set_attr(c->reply, '-', "Missing user"); + err(c, "Missing user"); return; } if (!c->cert_name || @@ -130,18 +149,17 @@ execute_init(struct conn *c) { if (!user_exists_p(user)) { - obj_set_attr(c->reply, '-', "Unknown user"); + err(c, "Unknown user"); return; } log(L_INFO, "Logged in %s", user); } else { - obj_set_attr(c->reply, '-', "Permission denied"); + err(c, "Permission denied"); log(L_ERROR, "Unauthorized attempt to log in as %s", user); return; } - obj_set_attr(c->reply, '+', "OK"); c->user = xstrdup(user); } @@ -152,5 +170,5 @@ process_init(struct conn *c) return 0; execute_init(c); write_reply(c); - return !!obj_find_attr(c->reply, '+'); + return !obj_find_attr(c->reply, '-'); } diff --git a/submit/submitd.c b/submit/submitd.c index 211cc1b..05d2316 100644 --- a/submit/submitd.c +++ b/submit/submitd.c @@ -7,6 +7,7 @@ /* * FIXME: * - competition timeout & per-contestant exceptions + * - open-data problems */ #undef LOCAL_DEBUG @@ -538,6 +539,7 @@ int main(int argc, char **argv) setproctitle_init(argc, argv); cf_def_file = "config"; cf_declare_section("SubmitD", &submitd_conf, 0); + cf_declare_section("Tasks", &tasks_conf, 0); int opt; if ((opt = cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL)) >= 0) diff --git a/submit/submitd.h b/submit/submitd.h index c780f53..9f73326 100644 --- a/submit/submitd.h +++ b/submit/submitd.h @@ -53,4 +53,17 @@ void NONRET client_error(char *msg, ...); int process_init(struct conn *c); int process_command(struct conn *c); +/* tasks.c */ + +struct task { + cnode n; + byte *name; +}; + +extern clist task_list; +extern struct cf_section tasks_conf; + +struct task *task_find(byte *name); +int user_exists_p(byte *user); + #endif diff --git a/submit/tasks.c b/submit/tasks.c new file mode 100644 index 0000000..e420bef --- /dev/null +++ b/submit/tasks.c @@ -0,0 +1,55 @@ +/* + * The Submit Daemon: Tasks + * + * (c) 2007 Martin Mares + */ + +#include "lib/lib.h" +#include "lib/conf.h" +#include "lib/stkstring.h" + +#include + +#include "submitd.h" + +clist task_list; + +static byte * +tasks_conf_init(void) +{ + clist_init(&task_list); + return NULL; +} + +static struct cf_section task_conf = { + CF_TYPE(struct task), + CF_ITEMS { + CF_STRING("Name", PTR_TO(struct task, name)), + CF_END + } +}; + +struct cf_section tasks_conf = { + CF_INIT(tasks_conf_init), + CF_ITEMS { + CF_LIST("Task", &task_list, &task_conf), + CF_END + } +}; + +struct task * +task_find(byte *name) +{ + CLIST_FOR_EACH(struct task *, t, task_list) + if (!strcasecmp(t->name, name)) + return t; + return NULL; +} + +int +user_exists_p(byte *user) +{ + byte *fn = stk_printf("solutions/%s/status", user); + struct stat st; + return !stat(fn, &st) && S_ISREG(st.st_mode); +}