-
Notifications
You must be signed in to change notification settings - Fork 4
/
wr_config.c
316 lines (267 loc) · 11.6 KB
/
wr_config.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/* WebROaR - Ruby Application Server - http://webroar.in/
* Copyright (C) 2009 Goonj LLC
*
* This file is part of WebROaR.
*
* WebROaR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebROaR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WebROaR. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************
* Set Configuration parameters
*****************************************************************/
#include <wr_config.h>
#include <sys/socket.h>
#define SERVER_NAME "WebROaR"
#define SERVER_VERSION "0.5.0"
#define FILE_PATH "FILE_PATH"
#define CONN_ID "CONNECTION_ID"
#define REQ_ID "REQ_ID"
#define RESP_CODE "RESP_CODE"
#define RESP_CONTENT_LEN "RESP_CONTENT_LEN"
int wr_config_server_init(config_t *Config, const char* root_path){
wr_string_new(Config->Server.Dir.root, root_path, strlen(root_path));
Config->Server.Control.conn_pool = 5;
wr_string_new(Config->Server.Control.sock_path, "/tmp/webroar_controller_sock", strlen("/tmp/webroar_controller_sock"));
wr_string_new(Config->Server.File.sock, "/tmp/webroar.sock", strlen("/tmp/webroar.sock"));
wr_string_new(Config->Server.File.pid, "/var/run/webroar.pid", strlen("/var/run/webroar.pid"));
wr_string_new(Config->Server.File.high_rss, "/var/run/high_rss.pid", strlen("/var/run/high_rss.pid"));
wr_string_new(Config->Server.File.log, "webroar.log", strlen("webroar.log"));
wr_string_dump(Config->Server.File.config, Config->Server.Dir.root);
wr_string_append(Config->Server.File.config, "/conf/config.yml", strlen("/conf/config.yml"));
wr_string_dump(Config->Server.File.internal_config, Config->Server.Dir.root);
wr_string_append(Config->Server.File.internal_config, "/conf/server_internal_config.yml", strlen("/conf/server_internal_config.yml"));
wr_string_dump(Config->Server.File.worker_bin, Config->Server.Dir.root);
wr_string_append(Config->Server.File.worker_bin, "/bin/webroar-worker", strlen("/bin/webroar-worker"));
wr_string_dump(Config->Server.Dir.admin_panel, Config->Server.Dir.root);
wr_string_append(Config->Server.Dir.admin_panel, "/admin_panel", strlen("/admin_panel"));
Config->Server.Worker.max = 20;
Config->Server.Worker.pending = 10;
Config->Server.Worker.add_trials = 3;
Config->Server.Worker.add_wait = 1800;
Config->Server.Worker.add_timeout = 25;
Config->Server.Worker.kill_timeout= 10;
Config->Server.Worker.idle_time = 60;
Config->Server.Worker.ping_timeout= 15;
Config->Server.Worker.ping_trials = 2;
#ifdef HAVE_GNUTLS
Config->Server.SSL.port = 443;
wr_string_null(Config->Server.SSL.certificate);
wr_string_null(Config->Server.SSL.key);
#endif
wr_string_new(Config->Server.name, SERVER_NAME, strlen(SERVER_NAME));
wr_string_new(Config->Server.version, SERVER_VERSION, strlen(SERVER_VERSION));
Config->Server.port = 3000;
Config->Server.log_level = SEVERE;
// using 'AF_UNIX' macro to identify UDS support.
#ifdef AF_UNIX
Config->Server.flag = SERVER_UDS_SUPPORT;
#else
Config->Server.flag = 0;
#endif
Config->Server.flag |= SERVER_KEEP_ALIVE;
Config->Server.stack_trace = 50;
return TRUE;
}
int wr_config_application_init(config_t *Config){
Config->Application.Default.max_workers = 4;
Config->Application.Default.min_workers = 8;
wr_string_new(Config->Application.Default.env, "production", strlen("production"));
wr_string_new(Config->Application.Admin_panel.name, "Admin Panel", strlen("Admin Panel"));
wr_string_new(Config->Application.Admin_panel.base_uri, "/admin-panel", strlen("/admin-panel"));
wr_string_new(Config->Application.Static_server.name, "static-worker", strlen("static-worker"));
Config->Application.Static_server.min_workers = 4;
Config->Application.Static_server.max_workers = 8;
wr_string_new(Config->Application.analytics_on, "enabled", strlen("enabled"));
Config->Application.msg_queue_size = 2048;
Config->Application.max_req_ratio = 1;
Config->Application.min_req_ratio = 3;
Config->Application.high_load = 2;
Config->Application.low_load = 600;
Config->Application.max_hosts = 16;
Config->Application.list = NULL;
return TRUE;
}
int wr_config_worker_init(config_t *Config, const char *root_path){
wr_u_short root_path_len = strlen(root_path);
wr_string_new(Config->Worker.File.config, root_path, root_path_len);
wr_string_append(Config->Worker.File.config, "/conf/config.yml", strlen("/conf/config.yml"));
wr_string_new(Config->Worker.File.mime_type, root_path, root_path_len);
wr_string_append(Config->Worker.File.mime_type, "/conf/mime_type.yml", strlen("/conf/mime_type.yml"));
wr_string_new(Config->Worker.File.internal_config, root_path, root_path_len);
wr_string_append(Config->Worker.File.internal_config, "/conf/server_internal_config.yml", strlen("/conf/server_internal_config.yml"));
wr_string_new(Config->Worker.File.app_loader, root_path, root_path_len);
wr_string_append(Config->Worker.File.app_loader, "/src/ruby_lib/webroar_app_loader.rb", strlen("/src/ruby_lib/webroar_app_loader.rb"));
wr_string_new(Config->Worker.Header.file_path, FILE_PATH, strlen(FILE_PATH));
wr_string_new(Config->Worker.Header.conn_id, CONN_ID, strlen(CONN_ID));
wr_string_new(Config->Worker.Header.req_id, REQ_ID, strlen(REQ_ID));
wr_string_new(Config->Worker.Header.resp_code, RESP_CODE, strlen(RESP_CODE));
wr_string_new(Config->Worker.Header.resp_content_len, RESP_CONTENT_LEN, strlen(RESP_CONTENT_LEN));
wr_string_new(Config->Worker.Server.name, SERVER_NAME, strlen(SERVER_NAME));
wr_string_new(Config->Worker.Server.version, SERVER_VERSION, strlen(SERVER_VERSION));
wr_string_new(Config->Worker.static_server, "static-worker", strlen("static-worker"));
wr_string_new(Config->Worker.sock_path, "/tmp/webroar_worker_sock", strlen("/tmp/webroar_worker_sock"));
Config->Worker.stack_tace = 50;
Config->Worker.max_body_size = 65536;
Config->Worker.Compress.lower_limit = 10240; //10KB
Config->Worker.Compress.upper_limit = 1024*1024; //1MB
return TRUE;
}
int wr_config_request_init(config_t *Config){
Config->Request.prefix_hash = 5381;
Config->Request.conn_pool = 10;
Config->Request.max_body_size = 65536;
Config->Request.max_uri_size = 12288;
Config->Request.max_path_size = 1024;
Config->Request.max_frag_size = 1024;
Config->Request.max_query_size = 1024;
Config->Request.max_field_size = 256;
Config->Request.max_value_size = 81920;
Config->Request.max_header_size = 112640;
Config->Request.max_header_count= 40;
#ifdef L_DEBUG
wr_string_new(Config->Request.Header.conn_id, CONN_ID, strlen(CONN_ID));
wr_string_new(Config->Request.Header.req_id, REQ_ID, strlen(REQ_ID));
#endif
wr_string_new(Config->Request.Header.file_path, FILE_PATH, strlen(FILE_PATH));
wr_string_new(Config->Request.Header.resp_code, RESP_CODE, strlen(RESP_CODE));
wr_string_new(Config->Request.Header.resp_content_len, RESP_CONTENT_LEN, strlen(RESP_CONTENT_LEN));
return TRUE;
}
config_t* wr_worker_config_init(const char* root_path){
config_t *Config;
if(root_path == NULL) return NULL;
Config = wr_malloc(config_t);
if(Config){
if(!wr_config_worker_init(Config, root_path)){
free(Config);
return NULL;
}
}
return Config;
}
config_t* wr_server_config_init(const char *root_path){
config_t *Config;
wr_u_short retval = TRUE;
if(root_path == NULL) return NULL;
Config = wr_malloc(config_t);
if(Config){
if(!wr_config_server_init(Config, root_path)) retval = FALSE;
if(!wr_config_request_init(Config)) retval = FALSE;
if(! wr_config_application_init(Config)) retval = FALSE;
}
if(retval == FALSE){
free(Config);
return NULL;
}
return Config;
}
void wr_config_server_free(config_t *Config){
wr_string_free(Config->Server.Control.sock_path);
wr_string_free(Config->Server.File.sock);
wr_string_free(Config->Server.File.pid);
wr_string_free(Config->Server.File.high_rss);
wr_string_free(Config->Server.File.log);
wr_string_free(Config->Server.File.config);
wr_string_free(Config->Server.File.internal_config);
wr_string_free(Config->Server.File.worker_bin);
wr_string_free(Config->Server.Dir.admin_panel);
wr_string_free(Config->Server.Dir.root);
#ifdef HAVE_GNUTLS
wr_string_free(Config->Server.SSL.certificate);
wr_string_free(Config->Server.SSL.key);
#endif
wr_string_free(Config->Server.name);
wr_string_free(Config->Server.version);
}
void wr_config_request_free(config_t *Config){
#ifdef L_DEBUG
wr_string_free(Config->Request.Header.conn_id);
wr_string_free(Config->Request.Header.req_id);
#endif
wr_string_free(Config->Request.Header.file_path);
wr_string_free(Config->Request.Header.resp_code);
wr_string_free(Config->Request.Header.resp_content_len);
}
void wr_config_application_free(config_t *Config){
wr_string_free(Config->Application.Default.env);
wr_string_free(Config->Application.Admin_panel.name);
wr_string_free(Config->Application.Admin_panel.base_uri);
wr_string_free(Config->Application.Static_server.name);
wr_string_free(Config->Application.analytics_on);
wr_application_list_free(Config->Application.list);
}
void wr_config_worker_free(config_t *Config){
wr_string_free(Config->Worker.File.config);
wr_string_free(Config->Worker.File.mime_type);
wr_string_free(Config->Worker.File.internal_config);
wr_string_free(Config->Worker.File.app_loader);
wr_string_free(Config->Worker.Header.file_path);
wr_string_free(Config->Worker.Header.conn_id);
wr_string_free(Config->Worker.Header.req_id);
wr_string_free(Config->Worker.Header.resp_code);
wr_string_free(Config->Worker.Header.resp_content_len);
wr_string_free(Config->Worker.Server.name);
wr_string_free(Config->Worker.Server.version);
wr_string_free(Config->Worker.static_server);
wr_string_free(Config->Worker.sock_path);
}
void wr_host_list_free(config_host_list_t *list) {
config_host_list_t *next;
while(list) {
next = list->next;
wr_string_free(list->name);
free(list);
list = next;
}
}
/** Destroy application configuration */
void wr_application_list_free(config_application_list_t* list){
LOG_FUNCTION
config_application_list_t* next;
// Iterate applications and destroy each application
while(list) {
next = list->next;
wr_string_free(list->name);
wr_string_free(list->baseuri);
wr_string_free(list->path);
scgi_free(list->scgi);
wr_host_list_free(list->host_name_list);
wr_application_list_free(list->new);
free(list);
list = next;
}
}
void wr_server_config_free(config_t *Config){
if(Config == NULL) return;
wr_config_server_free(Config);
wr_config_request_free(Config);
wr_config_application_free(Config);
free(Config);
}
void wr_worker_config_free(config_t *Config){
if(Config == NULL) return;
wr_config_worker_free(Config);
free(Config);
}
void wr_set_numeric_value(node_t *root, const char *path, void *value, wr_u_short flag){
char *str = yaml_validate_string(yaml_get_value(root, path));
long *lvalue = (long*) value;
if(str) {
wr_u_long val = atoi(str);
if(val > 0){
*lvalue = val;
}else if(flag && strcmp(str,"0") == 0){
*lvalue = 0;
}
}
}