src/tools/wstool.c

Tue, 31 Dec 2019 14:53:13 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 31 Dec 2019 14:53:13 +0100
branch
webdav
changeset 220
2915b6c11aec
parent 175
9823770ba4ee
child 254
4784c14aa639
permissions
-rw-r--r--

add test for webdav_op_propfind_children

173
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "wstool.h"
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <stdio.h>
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdlib.h>
175
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
33 #include <string.h>
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
34
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
35 #include "../server/config/serverconf.h"
173
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "srvctrlsocket.h"
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 static void print_info(char *cmd) {
175
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
40 fprintf(stderr, "usage:\n");
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
41 fprintf(stderr, "%s -t <srvconfigfile>\n", cmd);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
42 fprintf(stderr, "%s -s <socketpath> <command>\n", cmd);
173
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 fprintf(stderr, "Commands: reconfig, shutdown, stat, log\n");
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 int main(int argc, char **argv) {
175
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
47 if(argc > 2) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
48 if(!strcmp(argv[1], "-t")) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
49 return tool_get_tmpdir(argv[2]);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
50 } else if(!strcmp(argv[1], "-s")) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
51 if(argc != 4) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
52 print_info(argv[0]);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
53 return -2;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
54 }
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
55 return tool_srvctrl(argv[2], argv[3]);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
56 }
173
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
175
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
59 print_info(argv[0]);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
60 return -2;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
61 }
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
62
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
63 int tool_get_tmpdir(char *configfile) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
64 ServerConfig *serverconf = load_server_config(configfile);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
65 UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7));
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
66 if(!list) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
67 fprintf(stderr, "Error: No Runtime element in %s\n", configfile);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
68 return -1;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
69 }
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
70 if(ucx_list_size(list) != 1) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
71 fprintf(stderr, "Error: Multiple Runtime elements in %s\n", configfile);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
72 return -1;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
73 }
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
74 ServerConfigObject *runtime = list->data;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
75 sstr_t tmp = cfg_directivelist_get_str(runtime->directives, sstr("Temp"));
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
76 if(!tmp.ptr) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
77 fprintf(stderr, "Error: No Temp directive in Runtime Object\n");
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
78 return -1;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
79 }
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
80
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
81 printf("%.*s\n", (int)tmp.length, tmp.ptr);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
82
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
83 return 0;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
84 }
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
85
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
86 int tool_srvctrl(char *socketfile, char *cmd) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
87 SrvConnection *srv = srvctrl_connet(socketfile);
173
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 if(!srv) {
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 return -1;
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
175
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
92 fprintf(srv->stream, "%s\n", cmd);
173
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 fflush(srv->stream);
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 SrvMsg msg;
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 while(!srvctrl_readmsg(srv, &msg)) {
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 if(msg.type == 0) {
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 fprintf(stdout, "%.*s", (int)msg.length, msg.message);
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 fflush(stdout);
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 } else if(msg.type == 1) {
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 fprintf(stderr, "%.*s", (int)msg.length, msg.message);
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 fflush(stderr);
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 }
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 }
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 srvctrl_close(srv);
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 return 0;
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 }
63b8d52db390 adds new tool for webserver control
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110
175
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
111
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
112
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
113 int log_ereport(int degree, const char *format, ...) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
114 va_list args;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
115 va_start(args, format);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
116 int ret = log_ereport_v(degree, format, args);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
117 va_end(args);
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
118 return ret;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
119 }
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
120
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
121 int log_ereport_v(int degree, const char *format, va_list args) {
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
122 return 0;
9823770ba4ee using wstool in server control scripts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 173
diff changeset
123 }

mercurial