From 3c441d54dc82d192d3ed657b24fae8cd85eb5400 Mon Sep 17 00:00:00 2001 From: Nishi Date: Fri, 11 Oct 2024 20:13:38 +0000 Subject: [PATCH] wip git-svn-id: file:///raid/svn-personal/rbuild/trunk@11 c68d3453-7f82-0740-9748-1d72386a946b --- Server/Makefile | 2 +- Server/rbs_server.h | 4 +++ Server/rbs_task.h | 10 +++++++ Server/server.c | 23 ++++++++++++++--- Server/task.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 Server/rbs_task.h create mode 100644 Server/task.c diff --git a/Server/Makefile b/Server/Makefile index 807a9f7..8a356d9 100644 --- a/Server/Makefile +++ b/Server/Makefile @@ -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) diff --git a/Server/rbs_server.h b/Server/rbs_server.h index a20fc2e..be3ad2c 100644 --- a/Server/rbs_server.h +++ b/Server/rbs_server.h @@ -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 index 0000000..10c1edf --- /dev/null +++ b/Server/rbs_task.h @@ -0,0 +1,10 @@ +/* $Id$ */ + +#ifndef __RBS_TASK_H__ +#define __RBS_TASK_H__ + +#include + +CMBOOL rbs_task(int sock, const char* section, const char* cmd, const char* arg); + +#endif diff --git a/Server/server.c b/Server/server.c index cddfed4..e765c36 100644 --- a/Server/server.c +++ b/Server/server.c @@ -3,8 +3,10 @@ #include "../config.h" #include "rbs_server.h" + #include "rbs_config.h" #include "rbs_auth.h" +#include "rbs_task.h" #include #include @@ -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 index 0000000..5963445 --- /dev/null +++ b/Server/task.c @@ -0,0 +1,63 @@ +/* $Id$ */ + +#include "rbs_task.h" + +#include "rbs_server.h" +#include "rbs_config.h" + +#include +#include + +#include +#include + +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; +} -- 2.43.0