src/tools/wstool.c

branch
srvctrl
changeset 175
9823770ba4ee
parent 173
63b8d52db390
child 254
4784c14aa639
--- a/src/tools/wstool.c	Sun Feb 19 11:56:39 2017 +0100
+++ b/src/tools/wstool.c	Mon Mar 06 15:43:28 2017 +0100
@@ -30,26 +30,66 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+
+#include "../server/config/serverconf.h"
 
 #include "srvctrlsocket.h"
 
 static void print_info(char *cmd) {
-    fprintf(stderr, "usage: %s -s <socketpath> <command>\n\n");
+    fprintf(stderr, "usage:\n");
+    fprintf(stderr, "%s -t <srvconfigfile>\n", cmd);
+    fprintf(stderr, "%s -s <socketpath> <command>\n", cmd);
     fprintf(stderr, "Commands: reconfig, shutdown, stat, log\n");
 }
 
 int main(int argc, char **argv) {
-    if(argc < 3) {
-        print_info(argv[0]);
-        return -2;
+    if(argc > 2) {
+        if(!strcmp(argv[1], "-t")) {
+            return tool_get_tmpdir(argv[2]);
+        } else if(!strcmp(argv[1], "-s")) {
+            if(argc != 4) {
+                print_info(argv[0]);
+                return -2;
+            }
+            return tool_srvctrl(argv[2], argv[3]);
+        }
     }
     
-    SrvConnection *srv = srvctrl_connet(argv[1]);
+    print_info(argv[0]);
+    return -2;
+}
+
+int tool_get_tmpdir(char *configfile) {
+    ServerConfig *serverconf = load_server_config(configfile);
+    UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7));
+    if(!list) {
+        fprintf(stderr, "Error: No Runtime element in %s\n", configfile);
+        return -1;
+    }
+    if(ucx_list_size(list) != 1) {
+        fprintf(stderr, "Error: Multiple Runtime elements in %s\n", configfile);
+        return -1;
+    }
+    ServerConfigObject *runtime = list->data;
+    sstr_t tmp = cfg_directivelist_get_str(runtime->directives, sstr("Temp"));
+    if(!tmp.ptr) {
+        fprintf(stderr, "Error: No Temp directive in Runtime Object\n");
+        return -1;
+    }
+    
+    printf("%.*s\n", (int)tmp.length, tmp.ptr);
+    
+    return 0;
+}
+
+int tool_srvctrl(char *socketfile, char *cmd) {
+    SrvConnection *srv = srvctrl_connet(socketfile);
     if(!srv) {
         return -1;
     }
     
-    fprintf(srv->stream, "%s\n", argv[2]);
+    fprintf(srv->stream, "%s\n", cmd);
     fflush(srv->stream);
     
     SrvMsg msg;
@@ -68,3 +108,16 @@
     return 0;
 }
 
+
+
+int log_ereport(int degree, const char *format, ...) {
+    va_list args;
+    va_start(args, format);
+    int ret = log_ereport_v(degree, format, args);
+    va_end(args);
+    return ret;
+}
+
+int log_ereport_v(int degree, const char *format, va_list args) { 
+    return 0;
+}

mercurial