webroar 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +48 -1
- data/README +11 -14
- data/Rakefile +1 -1
- data/conf/mime_type.yml +172 -166
- data/conf/server_internal_config.yml +30 -8
- data/doc/user-guide.html +294 -153
- data/doc/user-guide.txt +9 -13
- data/lib/command_runner.rb +1 -0
- data/lib/dependencies.rb +18 -15
- data/lib/installer.rb +115 -50
- data/src/admin_panel/app/controllers/admin_controller.rb +1 -15
- data/src/admin_panel/app/controllers/application_controller.rb +2 -2
- data/src/admin_panel/app/controllers/application_specification_controller.rb +2 -1
- data/src/admin_panel/app/controllers/headers_controller.rb +73 -0
- data/src/admin_panel/app/controllers/mail_specification_controller.rb +10 -0
- data/src/admin_panel/app/controllers/server_specification_controller.rb +14 -0
- data/src/admin_panel/app/helpers/admin_helper.rb +0 -85
- data/src/admin_panel/app/models/app.rb +1 -1
- data/src/admin_panel/app/models/application_specification.rb +33 -25
- data/src/admin_panel/app/models/headers.rb +116 -0
- data/src/admin_panel/app/models/mail_specification.rb +20 -5
- data/src/admin_panel/app/models/server_specification.rb +2 -7
- data/src/admin_panel/app/views/admin/configuration.html.erb +10 -5
- data/src/admin_panel/app/views/exceptions/_exception_list_partial.html.erb +4 -4
- data/src/admin_panel/app/views/graph/_graph_page.html.erb +3 -0
- data/src/admin_panel/app/views/headers/_add_expires_text_box.html.erb +35 -0
- data/src/admin_panel/app/views/headers/_expires_by_type_form.html.erb +65 -0
- data/src/admin_panel/app/views/headers/_headers_table.html.erb +113 -0
- data/src/admin_panel/app/views/mail_specification/_current_spec.html.erb +168 -0
- data/src/admin_panel/app/views/{admin → server_specification}/_add_div.html.erb +1 -1
- data/src/admin_panel/config/initializers/application_constants.rb +6 -0
- data/src/admin_panel/lib/control.rb +6 -3
- data/src/admin_panel/lib/scgi.rb +74 -21
- data/src/admin_panel/lib/yaml_writer.rb +51 -17
- data/src/admin_panel/public/javascripts/application.js +20 -1
- data/src/head/wr_access_log.c +2 -2
- data/src/head/wr_application.c +294 -236
- data/src/head/wr_application.h +8 -8
- data/src/head/wr_configurator.c +451 -517
- data/src/head/wr_configurator.h +10 -115
- data/src/head/wr_connection.c +26 -25
- data/src/head/wr_connection.h +2 -3
- data/src/head/wr_controller.c +110 -93
- data/src/head/wr_controller.h +6 -6
- data/src/head/wr_main.c +31 -24
- data/src/head/wr_request.c +70 -93
- data/src/head/wr_request.h +0 -4
- data/src/head/wr_resolver.c +21 -15
- data/src/head/wr_resolver.h +2 -2
- data/src/head/wr_server.c +36 -26
- data/src/head/wr_server.h +5 -5
- data/src/head/wr_worker.c +551 -512
- data/src/head/wr_worker.h +33 -20
- data/src/helper/wr_config.c +316 -0
- data/src/helper/wr_config.h +235 -0
- data/src/helper/wr_helper.h +1 -5
- data/src/helper/wr_logger.c +4 -4
- data/src/helper/wr_scgi.c +3 -4
- data/src/helper/wr_scgi.h +2 -0
- data/src/helper/wr_string.h +2 -2
- data/src/helper/wr_util.c +3 -1
- data/src/helper/wr_util.h +0 -0
- data/src/helper/wr_yaml_parser.c +30 -0
- data/src/helper/wr_yaml_parser.h +1 -0
- data/src/ruby_lib/exception_tracker/instrumentation/action_controller.rb +2 -1
- data/src/ruby_lib/mailer/smtpmail.rb +7 -4
- data/src/ruby_lib/profiler/instrumentation/action_controller.rb +2 -1
- data/src/ruby_lib/profiler/instrumentation/active_record.rb +3 -0
- data/src/ruby_lib/rack/adapter/rails.rb +14 -7
- data/src/ruby_lib/ruby_interface/client.rb +1 -1
- data/src/ruby_lib/ruby_interface/version.rb +2 -2
- data/src/ruby_lib/webroar_app_loader.rb +4 -2
- data/src/worker/wkr_controller.c +200 -140
- data/src/worker/wkr_http.c +14 -28
- data/src/worker/wkr_http.h +4 -4
- data/src/worker/wkr_http_request.c +12 -11
- data/src/worker/wkr_http_request.h +7 -8
- data/src/worker/wkr_http_response.c +10 -14
- data/src/worker/wkr_http_response.h +0 -1
- data/src/worker/wkr_main.c +74 -140
- data/src/worker/wkr_static.c +295 -108
- data/src/worker/wkr_static.h +20 -7
- data/src/worker/worker.c +245 -70
- data/src/worker/worker.h +46 -34
- data/tasks/compile.rake +128 -175
- data/tasks/test.rake +345 -469
- data/test/spec/webroar_command_spec.rb +23 -0
- metadata +173 -43
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/README +0 -34
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/Rakefile +0 -13
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/init.rb +0 -5
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/lib/action_mailer_tls.rb +0 -16
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb +0 -123
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/test/tls_test.rb +0 -42
- data/src/head/wr_config.h +0 -165
- data/src/ruby_lib/mailer/action_mailer_tls.rb +0 -16
- data/src/ruby_lib/mailer/smtp_tls.rb +0 -123
data/src/head/wr_worker.h
CHANGED
@@ -25,24 +25,39 @@
|
|
25
25
|
|
26
26
|
/** Worker states */
|
27
27
|
typedef enum{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
28
|
+
WKR_STATE_CONNECTING = 100,
|
29
|
+
WKR_STATE_ACTIVE = 200,
|
30
|
+
WKR_STATE_INACTIVE = 201,
|
31
|
+
WKR_STATE_PINGING = 202,
|
32
|
+
WKR_STATE_EXPIRED = 203,
|
33
|
+
WKR_STATE_ERROR = 401,
|
34
|
+
WKR_STATE_TIMEDOUT = 402,
|
35
|
+
WKR_STATE_ERROR_ACK = 403,
|
36
|
+
WKR_STATE_HANGUP = 404,
|
37
|
+
WKR_STATE_DISCONNECTING = 501
|
38
38
|
}wr_wkr_state_t;
|
39
39
|
|
40
|
+
/** Worker actions */
|
41
|
+
typedef enum{
|
42
|
+
WKR_ACTION_ADD,
|
43
|
+
WKR_ACTION_ADD_TIMEOUT,
|
44
|
+
WKR_ACTION_ADD_ERROR,
|
45
|
+
WKR_ACTION_REMOVE,
|
46
|
+
WKR_ACTION_PING,
|
47
|
+
WKR_ACTION_PING_TIMEOUT,
|
48
|
+
WKR_ACTION_PING_REPLAY,
|
49
|
+
WKR_ACTION_REQ_PROCESSED,
|
50
|
+
WKR_ACTION_REQ_PROCESSING,
|
51
|
+
WKR_ACTION_ERROR
|
52
|
+
}wr_wkr_action_t;
|
53
|
+
|
54
|
+
|
40
55
|
/** Worker structure */
|
41
56
|
struct wr_wkr_s {
|
42
|
-
wr_u_short
|
43
|
-
|
44
|
-
wr_u_short
|
45
|
-
struct ev_loop
|
57
|
+
wr_u_short id; /**< Worker index/id */
|
58
|
+
wr_wkr_state_t state; /**< Worker state */
|
59
|
+
wr_u_short pid; /**< Worker id */
|
60
|
+
struct ev_loop *loop;
|
46
61
|
|
47
62
|
int fd; /**< Socket fd */
|
48
63
|
ev_io watcher; /**< watcher */
|
@@ -50,29 +65,27 @@ struct wr_wkr_s {
|
|
50
65
|
ev_timer t_wait; /**< idle watcher for worker */
|
51
66
|
wr_u_short trials_done; /**< Number of time we want to send PING before killing */
|
52
67
|
|
53
|
-
wr_ctl_t
|
68
|
+
wr_ctl_t *ctl; /**< Pointer to control structure */
|
54
69
|
wr_req_t *req;
|
55
70
|
wr_app_t *app; /**< Application pointer*/
|
56
71
|
};
|
57
72
|
|
58
|
-
/** Create new worker */
|
59
|
-
wr_wkr_t* wr_wkr_new(wr_ctl_t*);
|
60
73
|
/** Destroy worker */
|
61
74
|
void wr_wkr_free(wr_wkr_t*);
|
62
75
|
/** Remove worker */
|
63
76
|
int wr_wkr_remove(wr_wkr_t*, int);
|
64
77
|
/** Create the Worker */
|
65
|
-
int wr_wkr_create(wr_svr_t*,
|
78
|
+
int wr_wkr_create(wr_svr_t*, config_application_list_t*);
|
66
79
|
/** Dispatch the request to Worker process */
|
67
80
|
void wr_wkr_dispatch_req(wr_req_t*);
|
68
|
-
/** Handle connect request from Worker */
|
69
|
-
//int wr_wkr_connect(wr_ctl_msg_t*, wr_ctl_t*);
|
70
81
|
/** This would get called when worker reply to PING */
|
71
82
|
//void wr_wkr_ping_reply(wr_wkr_t*);
|
72
83
|
/** Worker add callback */
|
73
84
|
void wr_wkr_add_cb(wr_ctl_t*, const wr_ctl_msg_t*);
|
74
85
|
/** Worker remove callback */
|
75
86
|
void wr_wkr_remove_cb(wr_ctl_t*, const wr_ctl_msg_t*);
|
87
|
+
/** Worker Add error callback */
|
88
|
+
void wr_wkr_add_error_cb(wr_ctl_t*, const wr_ctl_msg_t*);
|
76
89
|
/** Worker ping callback */
|
77
90
|
void wr_wkr_ping_cb(wr_ctl_t*, const wr_ctl_msg_t*);
|
78
91
|
|
@@ -0,0 +1,316 @@
|
|
1
|
+
/* WebROaR - Ruby Application Server - http://webroar.in/
|
2
|
+
* Copyright (C) 2009 Goonj LLC
|
3
|
+
*
|
4
|
+
* This file is part of WebROaR.
|
5
|
+
*
|
6
|
+
* WebROaR is free software: you can redistribute it and/or modify
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
9
|
+
* (at your option) any later version.
|
10
|
+
*
|
11
|
+
* WebROaR is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
* GNU General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public License
|
17
|
+
* along with WebROaR. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
19
|
+
|
20
|
+
/*****************************************************************
|
21
|
+
* Set Configuration parameters
|
22
|
+
*****************************************************************/
|
23
|
+
|
24
|
+
#include <wr_config.h>
|
25
|
+
#include <sys/socket.h>
|
26
|
+
|
27
|
+
#define SERVER_NAME "WebROaR"
|
28
|
+
#define SERVER_VERSION "0.4.0"
|
29
|
+
|
30
|
+
#define FILE_PATH "FILE_PATH"
|
31
|
+
#define CONN_ID "CONNECTION_ID"
|
32
|
+
#define REQ_ID "REQ_ID"
|
33
|
+
#define RESP_CODE "RESP_CODE"
|
34
|
+
#define RESP_CONTENT_LEN "RESP_CONTENT_LEN"
|
35
|
+
|
36
|
+
int wr_config_server_init(config_t *Config, const char* root_path){
|
37
|
+
wr_string_new(Config->Server.Dir.root, root_path, strlen(root_path));
|
38
|
+
|
39
|
+
Config->Server.Control.conn_pool = 5;
|
40
|
+
wr_string_new(Config->Server.Control.sock_path, "/tmp/webroar_controller_sock", strlen("/tmp/webroar_controller_sock"));
|
41
|
+
|
42
|
+
wr_string_new(Config->Server.File.sock, "/tmp/webroar.sock", strlen("/tmp/webroar.sock"));
|
43
|
+
wr_string_new(Config->Server.File.pid, "/var/run/webroar.pid", strlen("/var/run/webroar.pid"));
|
44
|
+
wr_string_new(Config->Server.File.high_rss, "/var/run/high_rss.pid", strlen("/var/run/high_rss.pid"));
|
45
|
+
wr_string_new(Config->Server.File.log, "webroar.log", strlen("webroar.log"));
|
46
|
+
wr_string_dump(Config->Server.File.config, Config->Server.Dir.root);
|
47
|
+
wr_string_append(Config->Server.File.config, "/conf/config.yml", strlen("/conf/config.yml"));
|
48
|
+
wr_string_dump(Config->Server.File.internal_config, Config->Server.Dir.root);
|
49
|
+
wr_string_append(Config->Server.File.internal_config, "/conf/server_internal_config.yml", strlen("/conf/server_internal_config.yml"));
|
50
|
+
wr_string_dump(Config->Server.File.worker_bin, Config->Server.Dir.root);
|
51
|
+
wr_string_append(Config->Server.File.worker_bin, "/bin/webroar-worker", strlen("/bin/webroar-worker"));
|
52
|
+
|
53
|
+
wr_string_dump(Config->Server.Dir.admin_panel, Config->Server.Dir.root);
|
54
|
+
wr_string_append(Config->Server.Dir.admin_panel, "/admin_panel", strlen("/admin_panel"));
|
55
|
+
|
56
|
+
Config->Server.Worker.max = 20;
|
57
|
+
Config->Server.Worker.pending = 10;
|
58
|
+
Config->Server.Worker.add_trials = 3;
|
59
|
+
Config->Server.Worker.add_wait = 1800;
|
60
|
+
Config->Server.Worker.add_timeout = 25;
|
61
|
+
Config->Server.Worker.kill_timeout= 10;
|
62
|
+
Config->Server.Worker.idle_time = 60;
|
63
|
+
Config->Server.Worker.ping_timeout= 15;
|
64
|
+
Config->Server.Worker.ping_trials = 2;
|
65
|
+
|
66
|
+
#ifdef HAVE_GNUTLS
|
67
|
+
Config->Server.SSL.port = 443;
|
68
|
+
wr_string_null(Config->Server.SSL.certificate);
|
69
|
+
wr_string_null(Config->Server.SSL.key);
|
70
|
+
#endif
|
71
|
+
|
72
|
+
wr_string_new(Config->Server.name, SERVER_NAME, strlen(SERVER_NAME));
|
73
|
+
wr_string_new(Config->Server.version, SERVER_VERSION, strlen(SERVER_VERSION));
|
74
|
+
|
75
|
+
Config->Server.port = 3000;
|
76
|
+
Config->Server.log_level = SEVERE;
|
77
|
+
// using 'AF_UNIX' macro to identify UDS support.
|
78
|
+
#ifdef AF_UNIX
|
79
|
+
Config->Server.flag = SERVER_UDS_SUPPORT;
|
80
|
+
#else
|
81
|
+
Config->Server.flag = 0;
|
82
|
+
#endif
|
83
|
+
Config->Server.flag |= SERVER_KEEP_ALIVE;
|
84
|
+
Config->Server.stack_trace = 50;
|
85
|
+
|
86
|
+
return TRUE;
|
87
|
+
}
|
88
|
+
|
89
|
+
int wr_config_application_init(config_t *Config){
|
90
|
+
Config->Application.Default.max_workers = 4;
|
91
|
+
Config->Application.Default.min_workers = 8;
|
92
|
+
wr_string_new(Config->Application.Default.env, "production", strlen("production"));
|
93
|
+
|
94
|
+
wr_string_new(Config->Application.Admin_panel.name, "Admin Panel", strlen("Admin Panel"));
|
95
|
+
wr_string_new(Config->Application.Admin_panel.base_uri, "/admin-panel", strlen("/admin-panel"));
|
96
|
+
|
97
|
+
wr_string_new(Config->Application.Static_server.name, "static-worker", strlen("static-worker"));
|
98
|
+
Config->Application.Static_server.min_workers = 4;
|
99
|
+
Config->Application.Static_server.max_workers = 8;
|
100
|
+
|
101
|
+
wr_string_new(Config->Application.analytics_on, "enabled", strlen("enabled"));
|
102
|
+
Config->Application.msg_queue_size = 2048;
|
103
|
+
Config->Application.max_req_ratio = 1;
|
104
|
+
Config->Application.min_req_ratio = 3;
|
105
|
+
Config->Application.high_load = 2;
|
106
|
+
Config->Application.low_load = 600;
|
107
|
+
Config->Application.max_hosts = 16;
|
108
|
+
|
109
|
+
Config->Application.list = NULL;
|
110
|
+
|
111
|
+
return TRUE;
|
112
|
+
}
|
113
|
+
|
114
|
+
int wr_config_worker_init(config_t *Config, const char *root_path){
|
115
|
+
|
116
|
+
wr_u_short root_path_len = strlen(root_path);
|
117
|
+
|
118
|
+
wr_string_new(Config->Worker.File.config, root_path, root_path_len);
|
119
|
+
wr_string_append(Config->Worker.File.config, "/conf/config.yml", strlen("/conf/config.yml"));
|
120
|
+
wr_string_new(Config->Worker.File.mime_type, root_path, root_path_len);
|
121
|
+
wr_string_append(Config->Worker.File.mime_type, "/conf/mime_type.yml", strlen("/conf/mime_type.yml"));
|
122
|
+
wr_string_new(Config->Worker.File.internal_config, root_path, root_path_len);
|
123
|
+
wr_string_append(Config->Worker.File.internal_config, "/conf/server_internal_config.yml", strlen("/conf/server_internal_config.yml"));
|
124
|
+
wr_string_new(Config->Worker.File.app_loader, root_path, root_path_len);
|
125
|
+
wr_string_append(Config->Worker.File.app_loader, "/src/ruby_lib/webroar_app_loader.rb", strlen("/src/ruby_lib/webroar_app_loader.rb"));
|
126
|
+
|
127
|
+
wr_string_new(Config->Worker.Header.file_path, FILE_PATH, strlen(FILE_PATH));
|
128
|
+
wr_string_new(Config->Worker.Header.conn_id, CONN_ID, strlen(CONN_ID));
|
129
|
+
wr_string_new(Config->Worker.Header.req_id, REQ_ID, strlen(REQ_ID));
|
130
|
+
wr_string_new(Config->Worker.Header.resp_code, RESP_CODE, strlen(RESP_CODE));
|
131
|
+
wr_string_new(Config->Worker.Header.resp_content_len, RESP_CONTENT_LEN, strlen(RESP_CONTENT_LEN));
|
132
|
+
|
133
|
+
wr_string_new(Config->Worker.Server.name, SERVER_NAME, strlen(SERVER_NAME));
|
134
|
+
wr_string_new(Config->Worker.Server.version, SERVER_VERSION, strlen(SERVER_VERSION));
|
135
|
+
|
136
|
+
wr_string_new(Config->Worker.static_server, "static-worker", strlen("static-worker"));
|
137
|
+
wr_string_new(Config->Worker.sock_path, "/tmp/webroar_worker_sock", strlen("/tmp/webroar_worker_sock"));
|
138
|
+
Config->Worker.stack_tace = 50;
|
139
|
+
Config->Worker.max_body_size = 65536;
|
140
|
+
|
141
|
+
Config->Worker.Compress.lower_limit = 10240; //10KB
|
142
|
+
Config->Worker.Compress.upper_limit = 1024*1024; //1MB
|
143
|
+
|
144
|
+
return TRUE;
|
145
|
+
}
|
146
|
+
|
147
|
+
int wr_config_request_init(config_t *Config){
|
148
|
+
Config->Request.prefix_hash = 5381;
|
149
|
+
Config->Request.conn_pool = 10;
|
150
|
+
Config->Request.max_body_size = 65536;
|
151
|
+
Config->Request.max_uri_size = 12288;
|
152
|
+
Config->Request.max_path_size = 1024;
|
153
|
+
Config->Request.max_frag_size = 1024;
|
154
|
+
Config->Request.max_query_size = 1024;
|
155
|
+
Config->Request.max_field_size = 256;
|
156
|
+
Config->Request.max_value_size = 81920;
|
157
|
+
Config->Request.max_header_size = 112640;
|
158
|
+
Config->Request.max_header_count= 40;
|
159
|
+
|
160
|
+
#ifdef L_DEBUG
|
161
|
+
wr_string_new(Config->Request.Header.conn_id, CONN_ID, strlen(CONN_ID));
|
162
|
+
wr_string_new(Config->Request.Header.req_id, REQ_ID, strlen(REQ_ID));
|
163
|
+
#endif
|
164
|
+
wr_string_new(Config->Request.Header.file_path, FILE_PATH, strlen(FILE_PATH));
|
165
|
+
wr_string_new(Config->Request.Header.resp_code, RESP_CODE, strlen(RESP_CODE));
|
166
|
+
wr_string_new(Config->Request.Header.resp_content_len, RESP_CONTENT_LEN, strlen(RESP_CONTENT_LEN));
|
167
|
+
|
168
|
+
return TRUE;
|
169
|
+
}
|
170
|
+
|
171
|
+
config_t* wr_worker_config_init(const char* root_path){
|
172
|
+
config_t *Config;
|
173
|
+
if(root_path == NULL) return NULL;
|
174
|
+
Config = wr_malloc(config_t);
|
175
|
+
|
176
|
+
if(Config){
|
177
|
+
if(!wr_config_worker_init(Config, root_path)){
|
178
|
+
free(Config);
|
179
|
+
return NULL;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
return Config;
|
184
|
+
}
|
185
|
+
|
186
|
+
config_t* wr_server_config_init(const char *root_path){
|
187
|
+
config_t *Config;
|
188
|
+
wr_u_short retval = TRUE;
|
189
|
+
|
190
|
+
if(root_path == NULL) return NULL;
|
191
|
+
Config = wr_malloc(config_t);
|
192
|
+
|
193
|
+
|
194
|
+
if(Config){
|
195
|
+
if(!wr_config_server_init(Config, root_path)) retval = FALSE;
|
196
|
+
if(!wr_config_request_init(Config)) retval = FALSE;
|
197
|
+
if(! wr_config_application_init(Config)) retval = FALSE;
|
198
|
+
}
|
199
|
+
|
200
|
+
if(retval == FALSE){
|
201
|
+
free(Config);
|
202
|
+
return NULL;
|
203
|
+
}
|
204
|
+
|
205
|
+
return Config;
|
206
|
+
}
|
207
|
+
|
208
|
+
void wr_config_server_free(config_t *Config){
|
209
|
+
wr_string_free(Config->Server.Control.sock_path);
|
210
|
+
wr_string_free(Config->Server.File.sock);
|
211
|
+
wr_string_free(Config->Server.File.pid);
|
212
|
+
wr_string_free(Config->Server.File.high_rss);
|
213
|
+
wr_string_free(Config->Server.File.log);
|
214
|
+
wr_string_free(Config->Server.File.config);
|
215
|
+
wr_string_free(Config->Server.File.internal_config);
|
216
|
+
wr_string_free(Config->Server.File.worker_bin);
|
217
|
+
wr_string_free(Config->Server.Dir.admin_panel);
|
218
|
+
wr_string_free(Config->Server.Dir.root);
|
219
|
+
#ifdef HAVE_GNUTLS
|
220
|
+
wr_string_free(Config->Server.SSL.certificate);
|
221
|
+
wr_string_free(Config->Server.SSL.key);
|
222
|
+
#endif
|
223
|
+
wr_string_free(Config->Server.name);
|
224
|
+
wr_string_free(Config->Server.version);
|
225
|
+
}
|
226
|
+
|
227
|
+
void wr_config_request_free(config_t *Config){
|
228
|
+
#ifdef L_DEBUG
|
229
|
+
wr_string_free(Config->Request.Header.conn_id);
|
230
|
+
wr_string_free(Config->Request.Header.req_id);
|
231
|
+
#endif
|
232
|
+
wr_string_free(Config->Request.Header.file_path);
|
233
|
+
wr_string_free(Config->Request.Header.resp_code);
|
234
|
+
wr_string_free(Config->Request.Header.resp_content_len);
|
235
|
+
}
|
236
|
+
|
237
|
+
void wr_config_application_free(config_t *Config){
|
238
|
+
wr_string_free(Config->Application.Default.env);
|
239
|
+
wr_string_free(Config->Application.Admin_panel.name);
|
240
|
+
wr_string_free(Config->Application.Admin_panel.base_uri);
|
241
|
+
wr_string_free(Config->Application.Static_server.name);
|
242
|
+
wr_string_free(Config->Application.analytics_on);
|
243
|
+
wr_application_list_free(Config->Application.list);
|
244
|
+
}
|
245
|
+
|
246
|
+
void wr_config_worker_free(config_t *Config){
|
247
|
+
wr_string_free(Config->Worker.File.config);
|
248
|
+
wr_string_free(Config->Worker.File.mime_type);
|
249
|
+
wr_string_free(Config->Worker.File.internal_config);
|
250
|
+
wr_string_free(Config->Worker.File.app_loader);
|
251
|
+
wr_string_free(Config->Worker.Header.file_path);
|
252
|
+
wr_string_free(Config->Worker.Header.conn_id);
|
253
|
+
wr_string_free(Config->Worker.Header.req_id);
|
254
|
+
wr_string_free(Config->Worker.Header.resp_code);
|
255
|
+
wr_string_free(Config->Worker.Header.resp_content_len);
|
256
|
+
wr_string_free(Config->Worker.Server.name);
|
257
|
+
wr_string_free(Config->Worker.Server.version);
|
258
|
+
wr_string_free(Config->Worker.static_server);
|
259
|
+
wr_string_free(Config->Worker.sock_path);
|
260
|
+
}
|
261
|
+
|
262
|
+
void wr_host_list_free(config_host_list_t *list) {
|
263
|
+
config_host_list_t *next;
|
264
|
+
while(list) {
|
265
|
+
next = list->next;
|
266
|
+
wr_string_free(list->name);
|
267
|
+
free(list);
|
268
|
+
list = next;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
/** Destroy application configuration */
|
273
|
+
void wr_application_list_free(config_application_list_t* list){
|
274
|
+
LOG_FUNCTION
|
275
|
+
config_application_list_t* next;
|
276
|
+
|
277
|
+
// Iterate applications and destroy each application
|
278
|
+
while(list) {
|
279
|
+
next = list->next;
|
280
|
+
wr_string_free(list->name);
|
281
|
+
wr_string_free(list->baseuri);
|
282
|
+
wr_string_free(list->path);
|
283
|
+
scgi_free(list->scgi);
|
284
|
+
wr_host_list_free(list->host_name_list);
|
285
|
+
wr_application_list_free(list->new);
|
286
|
+
free(list);
|
287
|
+
list = next;
|
288
|
+
}
|
289
|
+
}
|
290
|
+
|
291
|
+
void wr_server_config_free(config_t *Config){
|
292
|
+
if(Config == NULL) return;
|
293
|
+
wr_config_server_free(Config);
|
294
|
+
wr_config_request_free(Config);
|
295
|
+
wr_config_application_free(Config);
|
296
|
+
free(Config);
|
297
|
+
}
|
298
|
+
|
299
|
+
void wr_worker_config_free(config_t *Config){
|
300
|
+
if(Config == NULL) return;
|
301
|
+
wr_config_worker_free(Config);
|
302
|
+
free(Config);
|
303
|
+
}
|
304
|
+
|
305
|
+
void wr_set_numeric_value(node_t *root, const char *path, void *value, wr_u_short flag){
|
306
|
+
char *str = wr_validate_string(get_node_value(root, path));
|
307
|
+
long *lvalue = (long*) value;
|
308
|
+
if(str) {
|
309
|
+
wr_u_long val = atoi(str);
|
310
|
+
if(val > 0){
|
311
|
+
*lvalue = val;
|
312
|
+
}else if(flag && strcmp(str,"0") == 0){
|
313
|
+
*lvalue = 0;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
}
|
@@ -0,0 +1,235 @@
|
|
1
|
+
/* WebROaR - Ruby Application Server - http://webroar.in/
|
2
|
+
* Copyright (C) 2009 Goonj LLC
|
3
|
+
*
|
4
|
+
* This file is part of WebROaR.
|
5
|
+
*
|
6
|
+
* WebROaR is free software: you can redistribute it and/or modify
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
9
|
+
* (at your option) any later version.
|
10
|
+
*
|
11
|
+
* WebROaR is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
* GNU General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public License
|
17
|
+
* along with WebROaR. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
19
|
+
#ifndef WR_CONFIG_H_
|
20
|
+
#define WR_CONFIG_H_
|
21
|
+
|
22
|
+
#include<wr_string.h>
|
23
|
+
#include<wr_macro.h>
|
24
|
+
#include<wr_logger.h>
|
25
|
+
#include<wr_scgi.h>
|
26
|
+
#include<wr_yaml_parser.h>
|
27
|
+
|
28
|
+
#define TRUE 1
|
29
|
+
#define FALSE 0
|
30
|
+
|
31
|
+
#define STR_SIZE16 16
|
32
|
+
#define STR_SIZE32 32
|
33
|
+
#define STR_SIZE64 64
|
34
|
+
#define STR_SIZE128 128
|
35
|
+
#define STR_SIZE256 256
|
36
|
+
#define STR_SIZE512 512
|
37
|
+
#define STR_SIZE1KB 1024
|
38
|
+
#define STR_SIZE10KB 10240
|
39
|
+
|
40
|
+
#define SERVER_ACCESS_LOG 1
|
41
|
+
#define SERVER_SSL_SUPPORT 2
|
42
|
+
#define SERVER_UDS_SUPPORT 4
|
43
|
+
#define SERVER_KEEP_ALIVE 8
|
44
|
+
|
45
|
+
typedef struct config_server_s{
|
46
|
+
|
47
|
+
struct control{
|
48
|
+
wr_str_t sock_path;
|
49
|
+
wr_u_short conn_pool;
|
50
|
+
}Control;
|
51
|
+
|
52
|
+
struct file{
|
53
|
+
wr_str_t log;
|
54
|
+
wr_str_t pid;
|
55
|
+
wr_str_t config;
|
56
|
+
wr_str_t sock;
|
57
|
+
wr_str_t high_rss;
|
58
|
+
wr_str_t worker_bin;
|
59
|
+
wr_str_t internal_config;
|
60
|
+
}File;
|
61
|
+
|
62
|
+
struct dir{
|
63
|
+
wr_str_t admin_panel;
|
64
|
+
wr_str_t root;
|
65
|
+
}Dir;
|
66
|
+
|
67
|
+
struct worker{
|
68
|
+
wr_u_short max;
|
69
|
+
wr_u_short pending;
|
70
|
+
wr_u_short add_trials;
|
71
|
+
wr_u_short add_wait;
|
72
|
+
wr_u_short add_timeout;
|
73
|
+
wr_u_short kill_timeout;
|
74
|
+
wr_u_short idle_time;
|
75
|
+
wr_u_short ping_timeout;
|
76
|
+
wr_u_short ping_trials;
|
77
|
+
}Worker;
|
78
|
+
|
79
|
+
#ifdef HAVE_GNUTLS
|
80
|
+
struct ssl{
|
81
|
+
wr_u_int port;
|
82
|
+
wr_str_t certificate;
|
83
|
+
wr_str_t key;
|
84
|
+
}SSL;
|
85
|
+
#endif
|
86
|
+
|
87
|
+
wr_str_t name;
|
88
|
+
wr_str_t version;
|
89
|
+
wr_u_int port;
|
90
|
+
|
91
|
+
LOG_SEVERITY log_level;
|
92
|
+
wr_u_short flag; // To store different bit level flags like access_log, ssl_support, uds support
|
93
|
+
wr_u_short stack_trace;
|
94
|
+
|
95
|
+
}config_server_t;
|
96
|
+
|
97
|
+
|
98
|
+
typedef struct config_request_s{
|
99
|
+
wr_u_short prefix_hash;
|
100
|
+
wr_u_short conn_pool;
|
101
|
+
wr_u_long max_body_size;
|
102
|
+
wr_u_int max_uri_size;
|
103
|
+
wr_u_short max_path_size;
|
104
|
+
wr_u_short max_frag_size;
|
105
|
+
wr_u_short max_query_size;
|
106
|
+
wr_u_short max_field_size;
|
107
|
+
wr_u_long max_value_size;
|
108
|
+
wr_u_long max_header_size;
|
109
|
+
wr_u_short max_header_count;
|
110
|
+
|
111
|
+
struct header{
|
112
|
+
#ifdef L_DEBUG
|
113
|
+
wr_str_t conn_id;
|
114
|
+
wr_str_t req_id;
|
115
|
+
#endif
|
116
|
+
wr_str_t file_path;
|
117
|
+
wr_str_t resp_code;
|
118
|
+
wr_str_t resp_content_len;
|
119
|
+
}Header;
|
120
|
+
|
121
|
+
}config_request_t;
|
122
|
+
|
123
|
+
typedef enum config_host_type_s{
|
124
|
+
HOST_TPE_INVALID = 0,
|
125
|
+
HOST_TYPE_STATIC = 1,
|
126
|
+
HOST_TYPE_WILDCARD_IN_START = 2,
|
127
|
+
HOST_TYPE_WILDCARD_IN_END = 4,
|
128
|
+
HOST_TYPE_WILDCARD_IN_START_END = 8,
|
129
|
+
}config_host_type_t;
|
130
|
+
|
131
|
+
typedef struct config_host_list_s config_host_list_t;
|
132
|
+
struct config_host_list_s {
|
133
|
+
wr_str_t name;
|
134
|
+
config_host_type_t type;
|
135
|
+
config_host_list_t *next;
|
136
|
+
};
|
137
|
+
|
138
|
+
typedef struct config_application_list_s config_application_list_t;
|
139
|
+
struct config_application_list_s {
|
140
|
+
wr_str_t name; /**< Application name */
|
141
|
+
wr_str_t baseuri; /**< Application baseuri */
|
142
|
+
wr_str_t path; /**< Application path */
|
143
|
+
wr_u_short min_worker; /**< Minimum number of workers required */
|
144
|
+
wr_u_short max_worker; /**< Maximum number of workers */
|
145
|
+
LOG_SEVERITY log_level; /**< Logging level */
|
146
|
+
|
147
|
+
scgi_t *scgi;
|
148
|
+
config_host_list_t *host_name_list;
|
149
|
+
config_application_list_t *new;
|
150
|
+
config_application_list_t *next;
|
151
|
+
};
|
152
|
+
|
153
|
+
|
154
|
+
typedef struct config_application_s{
|
155
|
+
|
156
|
+
struct application_default{
|
157
|
+
wr_u_short max_workers;
|
158
|
+
wr_u_short min_workers;
|
159
|
+
wr_str_t env;
|
160
|
+
}Default;
|
161
|
+
|
162
|
+
struct admin_panel{
|
163
|
+
wr_str_t name;
|
164
|
+
wr_str_t base_uri;
|
165
|
+
}Admin_panel;
|
166
|
+
|
167
|
+
struct static_server{
|
168
|
+
wr_str_t name;
|
169
|
+
wr_u_short min_workers;
|
170
|
+
wr_u_short max_workers;
|
171
|
+
}Static_server;
|
172
|
+
|
173
|
+
wr_str_t analytics_on;
|
174
|
+
wr_u_int msg_queue_size;
|
175
|
+
wr_u_short max_req_ratio;
|
176
|
+
wr_u_short min_req_ratio;
|
177
|
+
wr_u_short high_load;
|
178
|
+
wr_u_short low_load;
|
179
|
+
wr_u_short max_hosts;
|
180
|
+
|
181
|
+
config_application_list_t *list;
|
182
|
+
|
183
|
+
}config_application_t;
|
184
|
+
|
185
|
+
typedef struct config_worker_s{
|
186
|
+
|
187
|
+
struct worker_file{
|
188
|
+
wr_str_t config;
|
189
|
+
wr_str_t mime_type;
|
190
|
+
wr_str_t internal_config;
|
191
|
+
wr_str_t app_loader;
|
192
|
+
}File;
|
193
|
+
|
194
|
+
struct worker_header{
|
195
|
+
wr_str_t file_path;
|
196
|
+
wr_str_t conn_id;
|
197
|
+
wr_str_t req_id;
|
198
|
+
wr_str_t resp_code;
|
199
|
+
wr_str_t resp_content_len;
|
200
|
+
}Header;
|
201
|
+
|
202
|
+
struct server{
|
203
|
+
wr_str_t name;
|
204
|
+
wr_str_t version;
|
205
|
+
}Server;
|
206
|
+
|
207
|
+
struct compress{
|
208
|
+
wr_u_long lower_limit;
|
209
|
+
wr_u_long upper_limit;
|
210
|
+
}Compress;
|
211
|
+
|
212
|
+
wr_str_t static_server;
|
213
|
+
wr_str_t sock_path;
|
214
|
+
wr_u_short stack_tace;
|
215
|
+
wr_u_long max_body_size;
|
216
|
+
|
217
|
+
}config_worker_t;
|
218
|
+
|
219
|
+
typedef struct config_s{
|
220
|
+
config_server_t Server;
|
221
|
+
config_request_t Request;
|
222
|
+
config_worker_t Worker;
|
223
|
+
config_application_t Application;
|
224
|
+
}config_t;
|
225
|
+
|
226
|
+
config_t* wr_server_config_init(const char* root_path);
|
227
|
+
config_t* wr_worker_config_init(const char* root_path);
|
228
|
+
|
229
|
+
void wr_server_config_free(config_t *Config);
|
230
|
+
void wr_worker_config_free(config_t *Config);
|
231
|
+
void wr_application_list_free(config_application_list_t* list);
|
232
|
+
|
233
|
+
void wr_set_numeric_value(node_t *root, const char *path, void *value, wr_u_short flag);
|
234
|
+
|
235
|
+
#endif /*WR_CONFIG_H_*/
|
data/src/helper/wr_helper.h
CHANGED
@@ -20,13 +20,9 @@
|
|
20
20
|
#ifndef WR_HELPER_H_
|
21
21
|
#define WR_HELPER_H_
|
22
22
|
|
23
|
-
#include <
|
24
|
-
#include <wr_string.h>
|
23
|
+
#include <wr_config.h>
|
25
24
|
#include <wr_queue.h>
|
26
25
|
#include <wr_util.h>
|
27
|
-
#include <wr_scgi.h>
|
28
|
-
#include <wr_logger.h>
|
29
|
-
#include <wr_yaml_parser.h>
|
30
26
|
#include <wr_msg_queue_client.h>
|
31
27
|
|
32
28
|
#endif /*WR_HELPER_H_*/
|
data/src/helper/wr_logger.c
CHANGED
@@ -28,8 +28,8 @@
|
|
28
28
|
#include<time.h>
|
29
29
|
#include<errno.h>
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
char* get_date_time();
|
32
|
+
char* get_log_file_path();
|
33
33
|
|
34
34
|
//this macro should included in common utility
|
35
35
|
#define null_check(ptr) if (ptr == NULL) \
|
@@ -51,11 +51,11 @@ void close_logger() {
|
|
51
51
|
fclose(stderr);
|
52
52
|
}
|
53
53
|
|
54
|
-
|
54
|
+
char* get_log_file_path() {
|
55
55
|
return log_file_path;
|
56
56
|
}
|
57
57
|
|
58
|
-
|
58
|
+
char* get_date_time() {
|
59
59
|
struct tm *now=NULL;
|
60
60
|
time_t time_value=0;
|
61
61
|
char *str;
|