]> mj.ucw.cz Git - moe.git/commitdiff
First parts of submit command.
authorMartin Mares <mj@ucw.cz>
Mon, 4 Jun 2007 08:21:35 +0000 (10:21 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 4 Jun 2007 08:21:35 +0000 (10:21 +0200)
submit/Makefile
submit/PROTOCOL
submit/commands.c
submit/submitd.c
submit/submitd.h
submit/tasks.c [new file with mode: 0644]

index b5a7c1d02db86c495865b6578fa482ce191c45d9..cf9ee31473e8d49cbba3bb94bb98b783c904cfde 100644 (file)
@@ -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
 
index 7002b5aefbdbf459fb39f55cb219ad7cbb37d1d4..cbb55682910a83223e51f3351ef724326aca57cc 100644 (file)
@@ -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)
index 687e2721add4d520eeebe16fd3c4c9602211aa6e..e583d66a518ec97d477cc8afd6b1ce348372f129 100644 (file)
@@ -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 <sys/stat.h>
-
 #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, '-');
 }
index 211cc1b12a4b5ba104dbd2531e61b1c933112efc..05d23166f369206b8005d77d2b66338f5e423028 100644 (file)
@@ -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)
index c780f53a058d7f1bf1c0a7adaf1db15ce619c9a3..9f73326730460e904645c65ef7ea10c3310a39b9 100644 (file)
@@ -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 (file)
index 0000000..e420bef
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  The Submit Daemon: Tasks
+ *
+ *  (c) 2007 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+#include "lib/conf.h"
+#include "lib/stkstring.h"
+
+#include <sys/stat.h>
+
+#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);
+}