1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <string.h>
#include <stdio.h>
#include "websocksy.h"
#include "config.h"
#include "plugin.h"
static enum /*_config_file_section*/ {
cfg_main,
cfg_backend
} config_section = cfg_main;
int config_parse_file(ws_config* config, char* filename){
return 1;
}
int config_parse_arguments(ws_config* config, int argc, char** argv){
size_t u;
char* option = NULL, *value = NULL;
//if exactly one argument, treat it as config file
if(argc == 1){
return config_parse_file(config, argv[0]);
}
if(argc % 2){
return 1;
}
for(u = 0; u < argc; u += 2){
if(argv[u][0] != '-'){
return 1;
}
switch(argv[u][1]){
case 'p':
config->port = argv[u + 1];
break;
case 'l':
config->host = argv[u + 1];
break;
case 'b':
//clean up the previously registered backend
if(config->backend.cleanup){
config->backend.cleanup();
}
//load the backend plugin
if(plugin_backend_load(PLUGINS, argv[u + 1], &(config->backend))){
return 1;
}
if(config->backend.init() != WEBSOCKSY_API_VERSION){
fprintf(stderr, "Loaded backend %s was built for a different API version\n", argv[u + 1]);
return 1;
}
break;
case 'c':
if(!strchr(argv[u + 1], '=')){
return 1;
}
if(!config->backend.config){
continue;
}
option = strdup(argv[u + 1]);
value = strchr(option, '=');
*value = 0;
value++;
config->backend.config(option, value);
free(option);
option = NULL;
value = NULL;
break;
}
}
return 0;
}
|