]> Nishi Git Mirror - rbuild.git/commitdiff
wip
authorNishi <nishi@nishi.boats>
Fri, 11 Oct 2024 20:13:38 +0000 (20:13 +0000)
committerNishi <nishi@nishi.boats>
Fri, 11 Oct 2024 20:13:38 +0000 (20:13 +0000)
git-svn-id: file:///raid/svn-personal/rbuild/trunk@11 c68d3453-7f82-0740-9748-1d72386a946b

Server/Makefile
Server/rbs_server.h
Server/rbs_task.h [new file with mode: 0644]
Server/server.c
Server/task.c [new file with mode: 0644]

index 807a9f7942e4735478193b2c94a8bba822a8a88b..8a356d9506e4393462f6e5e300f512601393a708 100644 (file)
@@ -5,7 +5,7 @@ include $(PWD)/Platform/$(PLATFORM).mk
 .PHONY: all clean
 .SUFFIXES: .c .o
 
-OBJS = main.o server.o auth.o config.o
+OBJS = main.o server.o auth.o config.o task.o
 OBJS += ../Common/common.a
 
 all: rbuild-server$(EXEC)
index a20fc2e7e9e0c651eccd9205f525cb1ea2d53675..be3ad2ce1124b1ddd2e136f391c81f6bcd9e2bca 100644 (file)
@@ -7,5 +7,9 @@
 
 CMBOOL rbs_server_init(void);
 CMBOOL rbs_server_loop(void);
+int rbs_write(int sock, unsigned char* data, unsigned int size);
+int rbs_read(int sock, unsigned char* data, unsigned int size);
+char* rbs_readline(int sock);
+void rbs_close(int sock);
 
 #endif
diff --git a/Server/rbs_task.h b/Server/rbs_task.h
new file mode 100644 (file)
index 0000000..10c1edf
--- /dev/null
@@ -0,0 +1,10 @@
+/* $Id$ */
+
+#ifndef __RBS_TASK_H__
+#define __RBS_TASK_H__
+
+#include <cm_bool.h>
+
+CMBOOL rbs_task(int sock, const char* section, const char* cmd, const char* arg);
+
+#endif
index cddfed4377c5216c02bdfcc7e7514927cf0a6f29..e765c36bb2a71455f9aaf88205effc2d0f0bb4b3 100644 (file)
@@ -3,8 +3,10 @@
 #include "../config.h"
 
 #include "rbs_server.h"
+
 #include "rbs_config.h"
 #include "rbs_auth.h"
+#include "rbs_task.h"
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -72,12 +74,21 @@ CMBOOL rbs_server_init(void) {
        }
 }
 
-void rbs_write(int sock, unsigned char* data, unsigned int size) {
+int rbs_write(int sock, unsigned char* data, unsigned int size) {
        if(run_inetd) {
-               fwrite(data, 1, size, stdout);
+               int n = fwrite(data, 1, size, stdout);
                fflush(stdout);
+               return n;
+       } else {
+               return send(sock, data, size, 0);
+       }
+}
+
+int rbs_read(int sock, unsigned char* data, unsigned int size) {
+       if(run_inetd) {
+               return fread(data, 1, size, stdin);
        } else {
-               send(sock, data, size, 0);
+               return recv(sock, data, size, 0);
        }
 }
 
@@ -197,6 +208,12 @@ void rbs_server_handler(void* sockptr) {
                                        free(line);
                                        break;
                                }
+                       } else if(strcmp(cmd, "CC") == 0 && arg != NULL && authed) {
+                               if(!rbs_task(sock, section, cmd, arg)) {
+                                       rbs_write(sock, "FAIL\n", 5);
+                                       free(line);
+                                       break;
+                               }
                        } else {
                                free(line);
                                break;
diff --git a/Server/task.c b/Server/task.c
new file mode 100644 (file)
index 0000000..5963445
--- /dev/null
@@ -0,0 +1,63 @@
+/* $Id$ */
+
+#include "rbs_task.h"
+
+#include "rbs_server.h"
+#include "rbs_config.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include <cm_string.h>
+#include <cm_bool.h>
+
+void rbs_push(char*** stack, const char* str) {
+       char** oldstack = *stack;
+       int i;
+       for(i = 0; oldstack[i] != NULL; i++)
+               ;
+       *stack = malloc(sizeof(**stack) * (i + 2));
+       for(i = 0; oldstack[i] != NULL; i++) {
+               (*stack)[i] = oldstack[i];
+       }
+       free(oldstack);
+       (*stack)[i] = cm_strdup(str);
+       (*stack)[i + 1] = NULL;
+}
+
+void rbs_stack_free(char** stack) {
+       int i;
+       for(i = 0; stack[i] != NULL; i++) free(stack[i]);
+       free(stack);
+}
+
+char** rbs_parse_args(const char* arg) {
+       char* str = cm_strdup(arg);
+       char** stack = malloc(sizeof(*stack));
+       int i;
+       int incr = 0;
+       stack[0] = NULL;
+       for(i = 0;; i++) {
+               if(str[i] == 0 || str[i] == ' ') {
+                       char oldc = str[i];
+                       char* got = str + incr;
+                       str[i] = 0;
+
+                       rbs_push(&stack, got);
+
+                       incr = i + 1;
+                       if(oldc == 0) break;
+               }
+       }
+       free(str);
+       for(i = 0; stack[i] != NULL; i++) {
+               printf("[%s]\n", stack[i]);
+       }
+       return stack;
+}
+
+CMBOOL rbs_task(int sock, const char* section, const char* cmd, const char* arg) {
+       char** args = rbs_parse_args(arg);
+       rbs_stack_free(args);
+       return CMFALSE;
+}