webroar 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG +48 -1
  2. data/README +11 -14
  3. data/Rakefile +1 -1
  4. data/conf/mime_type.yml +172 -166
  5. data/conf/server_internal_config.yml +30 -8
  6. data/doc/user-guide.html +294 -153
  7. data/doc/user-guide.txt +9 -13
  8. data/lib/command_runner.rb +1 -0
  9. data/lib/dependencies.rb +18 -15
  10. data/lib/installer.rb +115 -50
  11. data/src/admin_panel/app/controllers/admin_controller.rb +1 -15
  12. data/src/admin_panel/app/controllers/application_controller.rb +2 -2
  13. data/src/admin_panel/app/controllers/application_specification_controller.rb +2 -1
  14. data/src/admin_panel/app/controllers/headers_controller.rb +73 -0
  15. data/src/admin_panel/app/controllers/mail_specification_controller.rb +10 -0
  16. data/src/admin_panel/app/controllers/server_specification_controller.rb +14 -0
  17. data/src/admin_panel/app/helpers/admin_helper.rb +0 -85
  18. data/src/admin_panel/app/models/app.rb +1 -1
  19. data/src/admin_panel/app/models/application_specification.rb +33 -25
  20. data/src/admin_panel/app/models/headers.rb +116 -0
  21. data/src/admin_panel/app/models/mail_specification.rb +20 -5
  22. data/src/admin_panel/app/models/server_specification.rb +2 -7
  23. data/src/admin_panel/app/views/admin/configuration.html.erb +10 -5
  24. data/src/admin_panel/app/views/exceptions/_exception_list_partial.html.erb +4 -4
  25. data/src/admin_panel/app/views/graph/_graph_page.html.erb +3 -0
  26. data/src/admin_panel/app/views/headers/_add_expires_text_box.html.erb +35 -0
  27. data/src/admin_panel/app/views/headers/_expires_by_type_form.html.erb +65 -0
  28. data/src/admin_panel/app/views/headers/_headers_table.html.erb +113 -0
  29. data/src/admin_panel/app/views/mail_specification/_current_spec.html.erb +168 -0
  30. data/src/admin_panel/app/views/{admin → server_specification}/_add_div.html.erb +1 -1
  31. data/src/admin_panel/config/initializers/application_constants.rb +6 -0
  32. data/src/admin_panel/lib/control.rb +6 -3
  33. data/src/admin_panel/lib/scgi.rb +74 -21
  34. data/src/admin_panel/lib/yaml_writer.rb +51 -17
  35. data/src/admin_panel/public/javascripts/application.js +20 -1
  36. data/src/head/wr_access_log.c +2 -2
  37. data/src/head/wr_application.c +294 -236
  38. data/src/head/wr_application.h +8 -8
  39. data/src/head/wr_configurator.c +451 -517
  40. data/src/head/wr_configurator.h +10 -115
  41. data/src/head/wr_connection.c +26 -25
  42. data/src/head/wr_connection.h +2 -3
  43. data/src/head/wr_controller.c +110 -93
  44. data/src/head/wr_controller.h +6 -6
  45. data/src/head/wr_main.c +31 -24
  46. data/src/head/wr_request.c +70 -93
  47. data/src/head/wr_request.h +0 -4
  48. data/src/head/wr_resolver.c +21 -15
  49. data/src/head/wr_resolver.h +2 -2
  50. data/src/head/wr_server.c +36 -26
  51. data/src/head/wr_server.h +5 -5
  52. data/src/head/wr_worker.c +551 -512
  53. data/src/head/wr_worker.h +33 -20
  54. data/src/helper/wr_config.c +316 -0
  55. data/src/helper/wr_config.h +235 -0
  56. data/src/helper/wr_helper.h +1 -5
  57. data/src/helper/wr_logger.c +4 -4
  58. data/src/helper/wr_scgi.c +3 -4
  59. data/src/helper/wr_scgi.h +2 -0
  60. data/src/helper/wr_string.h +2 -2
  61. data/src/helper/wr_util.c +3 -1
  62. data/src/helper/wr_util.h +0 -0
  63. data/src/helper/wr_yaml_parser.c +30 -0
  64. data/src/helper/wr_yaml_parser.h +1 -0
  65. data/src/ruby_lib/exception_tracker/instrumentation/action_controller.rb +2 -1
  66. data/src/ruby_lib/mailer/smtpmail.rb +7 -4
  67. data/src/ruby_lib/profiler/instrumentation/action_controller.rb +2 -1
  68. data/src/ruby_lib/profiler/instrumentation/active_record.rb +3 -0
  69. data/src/ruby_lib/rack/adapter/rails.rb +14 -7
  70. data/src/ruby_lib/ruby_interface/client.rb +1 -1
  71. data/src/ruby_lib/ruby_interface/version.rb +2 -2
  72. data/src/ruby_lib/webroar_app_loader.rb +4 -2
  73. data/src/worker/wkr_controller.c +200 -140
  74. data/src/worker/wkr_http.c +14 -28
  75. data/src/worker/wkr_http.h +4 -4
  76. data/src/worker/wkr_http_request.c +12 -11
  77. data/src/worker/wkr_http_request.h +7 -8
  78. data/src/worker/wkr_http_response.c +10 -14
  79. data/src/worker/wkr_http_response.h +0 -1
  80. data/src/worker/wkr_main.c +74 -140
  81. data/src/worker/wkr_static.c +295 -108
  82. data/src/worker/wkr_static.h +20 -7
  83. data/src/worker/worker.c +245 -70
  84. data/src/worker/worker.h +46 -34
  85. data/tasks/compile.rake +128 -175
  86. data/tasks/test.rake +345 -469
  87. data/test/spec/webroar_command_spec.rb +23 -0
  88. metadata +173 -43
  89. data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/README +0 -34
  90. data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/Rakefile +0 -13
  91. data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/init.rb +0 -5
  92. data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/lib/action_mailer_tls.rb +0 -16
  93. data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb +0 -123
  94. data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/test/tls_test.rb +0 -42
  95. data/src/head/wr_config.h +0 -165
  96. data/src/ruby_lib/mailer/action_mailer_tls.rb +0 -16
  97. data/src/ruby_lib/mailer/smtp_tls.rb +0 -123
@@ -19,7 +19,13 @@
19
19
  #ifndef WKR_STATIC_H_
20
20
  #define WKR_STATIC_H_
21
21
 
22
- #include <wkr_http.h>
22
+ #include <wkr_http_response.h>
23
+ #if defined(W_ZLIB) && defined(W_REGEX)
24
+ #include <regex.h>
25
+ #endif
26
+
27
+ #define MAP_SIZE 36
28
+ #define DEFAULT_CONTENT_TYPE "javascript|css|xml|text"
23
29
 
24
30
  typedef struct static_file_s{
25
31
  char ext[10];
@@ -28,13 +34,20 @@ typedef struct static_file_s{
28
34
  struct static_file_s *next;
29
35
  }static_file_t;
30
36
 
31
- /* Initialize extension and mime-type map */
32
- int static_module_init(char *root_path);
37
+ typedef struct static_server_s{
38
+ struct stat buf;
39
+ const char *path, *encoding, *user_agent, *modify;
40
+ wr_buffer_t *buffer; // Buffer to
41
+ static_file_t *map[MAP_SIZE + 1];
42
+ #if defined(W_ZLIB) && defined(W_REGEX)
43
+ regex_t *r_user_agent, *r_content_type;
44
+ #endif
45
+ }static_server_t;
33
46
 
34
- /* Free extension and mime-type map */
35
- void static_module_free();
47
+ static_server_t * static_server_new(void *worker);
48
+ void static_server_free(static_server_t *stat);
36
49
 
37
50
  /* Serve the static file content */
38
- void static_file_process(http_t *h);
51
+ void static_file_process(void *http);
39
52
 
40
- #endif /*WKR_STATIC_H_*/
53
+ #endif /*WKR_STATIC_H_*/
data/src/worker/worker.c CHANGED
@@ -33,6 +33,15 @@
33
33
  #include <netinet/in.h>
34
34
  #include <sys/un.h>
35
35
  #include <ev.c>
36
+ #include <pwd.h>
37
+
38
+ #ifdef __linux__
39
+ #include <sys/prctl.h>
40
+ #endif
41
+
42
+ extern config_t *Config;
43
+
44
+ void load_application(wkr_t* w);
36
45
 
37
46
  wkr_tmp_t* wkr_tmp_new() {
38
47
  LOG_FUNCTION
@@ -46,23 +55,23 @@ wkr_tmp_t* wkr_tmp_new() {
46
55
  wr_string_null(tmp->type);
47
56
  wr_string_null(tmp->name);
48
57
  wr_string_null(tmp->resolver);
49
- wr_string_null(tmp->ruby_path);
50
- wr_string_null(tmp->script_path);
51
58
  wr_string_null(tmp->root_path);
52
59
  wr_string_null(tmp->ctl_path);
53
60
  wr_string_null(tmp->log_file);
54
61
 
55
- // tmp->path = tmp->env = tmp->type = tmp->name =
56
- // tmp->resolver = tmp->ruby_path = tmp->script_path =
57
- // tmp->root_path = tmp->ctl_path = tmp->log_file = NULL;
58
-
59
62
  tmp->profiler = 'n';
60
63
  tmp->gid = tmp->uid = 0;
61
64
  // HTTP1.1 assumes persistent connection by default
62
65
  tmp->keep_alive = TRUE;
63
66
  tmp->is_uds = FALSE;
64
67
  tmp->is_static = 0;
65
-
68
+ #ifdef W_ZLIB
69
+ tmp->lower_limit = tmp->upper_limit = 0;
70
+ #ifdef W_REGEX
71
+ wr_string_null(tmp->r_user_agent);
72
+ wr_string_null(tmp->r_content_type);
73
+ #endif
74
+ #endif
66
75
  return tmp;
67
76
  }
68
77
 
@@ -75,23 +84,13 @@ void wkr_tmp_free(wkr_tmp_t** t) {
75
84
  wr_string_free(tmp->type);
76
85
  wr_string_free(tmp->name);
77
86
  wr_string_free(tmp->resolver);
78
- wr_string_free(tmp->ruby_path);
79
- wr_string_free(tmp->script_path);
80
87
  wr_string_free(tmp->root_path);
81
88
  wr_string_free(tmp->ctl_path);
82
89
  wr_string_free(tmp->log_file);
83
-
84
- // if(tmp->path) free(tmp->path);
85
- // if(tmp->env) free(tmp->env);
86
- // if(tmp->type) free(tmp->type);
87
- // if(tmp->name) free(tmp->name);
88
- // if(tmp->resolver) free(tmp->resolver);
89
- // if(tmp->ruby_path) free(tmp->ruby_path);
90
- // if(tmp->script_path) free(tmp->script_path);
91
- // if(tmp->root_path) free(tmp->root_path);
92
- // if(tmp->ctl_path) free(tmp->ctl_path);
93
- // if(tmp->log_file) free(tmp->log_file);
94
-
90
+ #if defined(W_ZLIB) && defined(W_REGEX)
91
+ wr_string_free(tmp->r_content_type);
92
+ wr_string_free(tmp->r_user_agent);
93
+ #endif
95
94
  free(tmp);
96
95
  }
97
96
  *t = NULL;
@@ -114,38 +113,25 @@ wkr_t* worker_new(struct ev_loop *loop, wkr_tmp_t *tmp) {
114
113
  w->tmp = tmp;
115
114
  assert(w->tmp!=NULL);
116
115
 
117
- w->ctl = wkr_ctl_new();
116
+ w->env_var = NULL;
117
+
118
+ w->ctl = wkr_ctl_new(w);
118
119
  assert(w->ctl!=NULL);
119
-
120
- // Connect to head controller UDS socket before user previliges get lowered.
121
- if(tmp->is_uds) {
122
- struct sockaddr_un addr;
123
-
124
- if ((w->ctl->fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
125
- LOG_ERROR(WARN,"socket()%s",strerror(errno));
126
- worker_free(&w);
127
- return NULL;
128
- }
129
-
130
- setsocketoption(w->ctl->fd);
131
-
132
- memset(&addr, 0, sizeof(addr));
133
- addr.sun_family = AF_UNIX;
134
- strcpy(addr.sun_path, tmp->ctl_path.str);
135
-
136
- int len = sizeof(addr.sun_family)+strlen(addr.sun_path);
137
- #ifdef __APPLE__
138
- len ++;
139
- #endif
140
-
141
- LOG_DEBUG(DEBUG,"send_ack_on_unix_socket() connecting with socket %s",addr.sun_path);
142
- if(connect(w->ctl->fd, (struct sockaddr *)&addr, len) < 0) {
143
- LOG_ERROR(SEVERE,"Connect with controller fd failed: %s",strerror(errno));
144
- worker_free(&w);
145
- return NULL;
146
- }
120
+ if(connect_to_head(w) == FALSE){
121
+ worker_free(&w);
122
+ return NULL;
123
+ }
124
+ start_ctl_watcher(w);
125
+ /* if(w->tmp->is_static){
126
+ w->ctl->scgi = scgi_new();
127
+ load_application(w);
128
+ } else */ if(send_config_req_msg(w) < 0){
129
+ worker_free(&w);
130
+ return NULL;
147
131
  }
148
132
 
133
+ // Connect to head controller UDS socket before user previliges get lowered.
134
+
149
135
  return w;
150
136
  }
151
137
 
@@ -157,7 +143,6 @@ void worker_free(wkr_t **wrk) {
157
143
  close(w->req_fd);
158
144
  if(w->listen_fd > 0)
159
145
  close(w->listen_fd);
160
- // if(w->sock_path){
161
146
  if(w->sock_path.str) {
162
147
  // Set root privilege to remove socket file.
163
148
  // if(setegid(0)!=0){
@@ -168,8 +153,6 @@ void worker_free(wkr_t **wrk) {
168
153
  // }
169
154
  unlink(w->sock_path.str);
170
155
  wr_string_free(w->sock_path);
171
- // unlink(w->sock_path);
172
- // free(w->sock_path);
173
156
  }
174
157
  ev_io_stop(w->loop, &(w->w_accept));
175
158
  ev_io_stop(w->loop, &(w->ctl->w_read));
@@ -180,13 +163,14 @@ void worker_free(wkr_t **wrk) {
180
163
  if(w->ctl)
181
164
  wkr_ctl_free(&w->ctl);
182
165
 
166
+ wr_string_list_free(w->env_var);
183
167
  free(w);
184
168
  }
185
169
  *wrk=NULL;
186
170
  }
187
171
 
188
172
  /** Conenct worker on internet socket */
189
- static inline int connect_internet_socket(wkr_t* w) {
173
+ int listen_internet_socket(wkr_t* w) {
190
174
  LOG_FUNCTION
191
175
  struct sockaddr_in addr;
192
176
  if ((w->listen_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
@@ -223,8 +207,7 @@ static inline int connect_internet_socket(wkr_t* w) {
223
207
  return 0;
224
208
  }
225
209
 
226
- /** Connect worker on unix domain socket */
227
- static inline int connect_unix_socket(wkr_t* w) {
210
+ int listen_unix_socket(wkr_t* w) {
228
211
  LOG_FUNCTION
229
212
  struct sockaddr_un addr;
230
213
 
@@ -241,19 +224,14 @@ static inline int connect_unix_socket(wkr_t* w) {
241
224
  memset(&addr, 0, sizeof(addr));
242
225
  /* Preparing socket path unique to this worker*/
243
226
  w->sock_path.str = (char*) malloc(sizeof(char)*50);
244
- w->sock_path.len = sprintf(w->sock_path.str, "%s_%d",WR_WKR_SOCK_PATH,getpid());
227
+ w->sock_path.len = sprintf(w->sock_path.str, "%s_%d", Config->Worker.sock_path.str, getpid());
245
228
 
246
- // w->sock_path = wr_malloc_CHAR(50);
247
- // sprintf(w->sock_path, "%s_%d",WR_WKR_SOCK_PATH,getpid());
248
-
249
- // LOG_DEBUG(DEBUG,"connect_unix_socket() socket name is %s",w->sock_path);
250
229
  LOG_DEBUG(DEBUG,"connect_unix_socket() socket name is %s",w->sock_path.str);
251
230
 
252
231
  addr.sun_family = AF_UNIX;
253
232
  //strcpy(addr.sun_path,w->sock_path);
254
233
  strcpy(addr.sun_path,w->sock_path.str);
255
234
  unlink(addr.sun_path);
256
- // LOG_DEBUG(DEBUG,"connect_unix_socket() Binding worker at socket path %s",w->sock_path);
257
235
  LOG_DEBUG(DEBUG,"connect_unix_socket() Binding worker at socket path %s",w->sock_path.str);
258
236
 
259
237
  int len = sizeof(addr.sun_family) + strlen(addr.sun_path);
@@ -277,20 +255,20 @@ static inline int connect_unix_socket(wkr_t* w) {
277
255
 
278
256
 
279
257
  /** Connect worket to Head */
280
- int worker_connect(wkr_t* w) {
258
+ int worker_listen(wkr_t* w) {
281
259
  LOG_FUNCTION
260
+ int retval;
282
261
  if(w->is_uds == 1) {
283
- if(connect_unix_socket(w) >= 0)
284
- return send_ack_on_unix_socket(w);
285
- } else {
286
- if(connect_internet_socket(w) >=0)
287
- return send_ack_on_internet_socket(w);
262
+ return listen_unix_socket(w);
263
+ }else{
264
+ return listen_internet_socket(w);
288
265
  }
289
- return -1;
266
+
267
+ // if(retval >= 0 ) return send_ack_ctl_msg(w);
290
268
  }
291
269
 
292
270
  /** This function accept connection from Head. */
293
- static void request_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
271
+ void request_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
294
272
  LOG_FUNCTION
295
273
  wkr_t *w = (wkr_t*) watcher->data;
296
274
 
@@ -332,5 +310,202 @@ void worker_accept_requests(wkr_t* w) {
332
310
  w->w_accept.data = w;
333
311
  ev_io_init(&(w->w_accept), request_accept_cb, w->listen_fd, EV_READ);
334
312
  ev_io_start(w->loop,&(w->w_accept));
313
+ //wkr_tmp_free(&w->tmp);
314
+ }
315
+
316
+ int drop_privileges(wkr_t *w, scgi_t *scgi) {
317
+ char *str;
318
+
319
+ str = (char*) scgi_header_value_get(scgi, "USER");
320
+
321
+ if(str && strlen(str) > 0) {
322
+ struct passwd *user_info=NULL;
323
+ user_info = getpwnam(str);
324
+ // Check for user existence
325
+ if(user_info) {
326
+ w->tmp->uid = user_info->pw_uid;
327
+ w->tmp->gid = user_info->pw_gid;
328
+ } else {
329
+ scgi_body_add(w->ctl->scgi, "Application run_as_user is invalid. Application not started.", strlen("Application run_as_user is invalid. Application not started."));
330
+ LOG_ERROR(SEVERE,"Application run_as_user is invalid. Application not started.");
331
+ return FALSE;
332
+ }
333
+ } else {
334
+ scgi_body_add(w->ctl->scgi, "Application run_as_user is missing. Application not started.", strlen("Application run_as_user is missing. Application not started."));
335
+ LOG_ERROR(SEVERE,"Application run_as_user is missing. Application not started.");
336
+ return FALSE;
337
+ }
338
+
339
+ change_log_file_owner(w->tmp->uid, w->tmp->gid);
340
+ //setting read, effective, saved group and user id
341
+ if(setgid(w->tmp->gid)!=0) {
342
+ scgi_body_add(w->ctl->scgi, "setegid() failed", strlen("setegid() failed"));
343
+ LOG_ERROR(SEVERE,"setegid() failed");
344
+ return FALSE;
345
+ }
346
+ if(setuid(w->tmp->uid)!=0) {
347
+ scgi_body_add(w->ctl->scgi, "seteuid() failed", strlen("seteuid() failed"));
348
+ LOG_ERROR(SEVERE,"seteuid() failed");
349
+ return FALSE;
350
+ }
351
+
352
+ LOG_DEBUG(DEBUG,"Passed userid=%d and groupid=%d",
353
+ w->tmp->uid, w->tmp->gid);
354
+ LOG_DEBUG(DEBUG,"effective userid=%d and groupid=%d",geteuid(),getegid());
355
+ #ifdef __linux__
356
+ int rv = prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
357
+ LOG_DEBUG(DEBUG,"prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) = %d", rv);
358
+ if (rv < 0) {
359
+ LOG_ERROR(SEVERE,"error setting prctl(PR_SET_DUMPABLE, 1, 0, 0, 0), errno = %d, desc = %s", errno, strerror(errno));
360
+ }
361
+ #endif
362
+ return TRUE;
363
+ }
364
+
365
+ void manipulate_environment_variable(wkr_t* w, scgi_t *scgi) {
366
+ LOG_FUNCTION
367
+ char *var, *str;
368
+ int rv = 0;
369
+
370
+ str = (char*) scgi_header_value_get(scgi, "ENV_VAR");
371
+ w->env_var = wr_string_list_new();
372
+ if(str){
373
+ var = strtok(str,"#");
374
+ while(var){
375
+ LOG_DEBUG(DEBUG,"Environment variable string = %s", var);
376
+ wr_string_list_add(w->env_var, var, strlen(var));
377
+ // TODO: see the security concerns
378
+ rv = putenv(w->env_var->rear->str.str);
379
+ if (rv != 0) {
380
+ LOG_ERROR(WARN, "putenv() failed, errno = %d, description = %s", errno, strerror(errno));
381
+ }
382
+ var = strtok(NULL,"#");
383
+ }
384
+ }
385
+ }
386
+
387
+ void load_application(wkr_t* w){
388
+ LOG_FUNCTION
389
+
390
+ w->ctl->scgi = scgi_new();
391
+ if(w->ctl->scgi == NULL) {
392
+ LOG_ERROR(SEVERE,"Cannot create SCGI Request");
393
+ sigproc();
394
+ return;
395
+ }
396
+
397
+ w->http = http_new(w);
398
+ if(w->http == NULL) {
399
+ scgi_body_add(w->ctl->scgi, "unable to load application.", strlen("unable to load application."));
400
+ LOG_ERROR(SEVERE,"unable to load application.");
401
+ }else if(worker_listen(w) < 0) {
402
+ scgi_body_add(w->ctl->scgi, "Error Initializing Workers.", strlen("Error Initializing Workers."));
403
+ LOG_ERROR(WARN,"Error Initializing Workers.");
404
+ }else{
405
+ worker_accept_requests(w);
406
+ LOG_INFO("Worker ready for serving requests.");
407
+ init_idle_watcher(w);
408
+
409
+ LOG_INFO("Successfully loaded rack application=%s with environment=%s",
410
+ w->tmp->path.str, w->tmp->env.str);
411
+ }
412
+
413
+ //loading adapter according to application type
414
+ LOG_DEBUG(DEBUG,"webroar_root = %s", w->tmp->root_path.str);
415
+ LOG_DEBUG(DEBUG,"path = %s, name = %s, type = %s, environment = %s, baseuri = %s, analytics = %c",
416
+ w->tmp->path.str, w->tmp->name.str, w->tmp->type.str,
417
+ w->tmp->env.str, w->tmp->resolver.str, w->tmp->profiler);
418
+
419
+ // Send error or ok acknowledgement message
420
+ if(w->ctl->scgi->body_length > 0){
421
+ // Send error response
422
+ w->ctl->error = TRUE;
423
+ get_worker_add_ctl_scgi(w, TRUE);
424
+ ev_io_start(w->loop,&(w->ctl->w_write));
425
+ ev_timer_again(w->loop, &w->ctl->t_ack);
426
+ }else{
427
+ // Send acknowledgement message
428
+ get_worker_add_ctl_scgi(w, FALSE);
429
+ ev_io_start(w->loop,&(w->ctl->w_write));
430
+ }
335
431
  wkr_tmp_free(&w->tmp);
336
432
  }
433
+
434
+ void application_config_read_cb(wkr_t* w, scgi_t *scgi){
435
+ LOG_FUNCTION
436
+ char *str;
437
+ /*w->ctl->scgi = scgi_new();
438
+
439
+ if(w->ctl->scgi == NULL) {
440
+ LOG_ERROR(SEVERE,"Cannot create SCGI Request");
441
+ sigproc();
442
+ return;
443
+ } */
444
+
445
+ if(w->tmp->is_static){
446
+
447
+ #ifdef W_ZLIB
448
+ str = (char*) scgi_header_value_get(scgi, "LOWER_LIMIT");
449
+ if(str){
450
+ w->tmp->lower_limit = atol(str);
451
+ }
452
+
453
+ str = (char*) scgi_header_value_get(scgi, "UPPER_LIMIT");
454
+ if(str){
455
+ w->tmp->upper_limit = atol(str);
456
+ }
457
+
458
+ #ifdef W_REGEX
459
+ str = (char*) scgi_header_value_get(scgi, "CONTENT_TYPE");
460
+ if(str){
461
+ wr_string_new(w->tmp->r_content_type, str, strlen(str));
462
+ }else {
463
+ wr_string_new(w->tmp->r_content_type, DEFAULT_CONTENT_TYPE, strlen(DEFAULT_CONTENT_TYPE));
464
+ }
465
+
466
+
467
+ str = (char*) scgi_header_value_get(scgi, "USER_AGENT");
468
+ if(str){
469
+ wr_string_new(w->tmp->r_user_agent, str, strlen(str));
470
+ }
471
+ #endif
472
+
473
+ #endif
474
+ }else{
475
+ if(drop_privileges(w, scgi) == FALSE) {
476
+ wkr_tmp_free(&w->tmp);
477
+ sigproc();
478
+ return;
479
+ }
480
+
481
+ manipulate_environment_variable(w, scgi);
482
+ str = (char*) scgi_header_value_get(scgi, "PATH");
483
+ if(str){
484
+ wr_string_new(w->tmp->path, str, strlen(str));
485
+ }
486
+
487
+ str = (char*) scgi_header_value_get(scgi, "ENV");
488
+ if(str){
489
+ wr_string_new(w->tmp->env, str, strlen(str));
490
+ }
491
+
492
+ str = (char*) scgi_header_value_get(scgi, "TYPE");
493
+ if(str){
494
+ wr_string_new(w->tmp->type, str, strlen(str));
495
+ }
496
+
497
+ str = (char*) scgi_header_value_get(scgi, "BASE_URI");
498
+ if(str){
499
+ wr_string_new(w->tmp->resolver, str, strlen(str));
500
+ }
501
+
502
+ str = (char*) scgi_header_value_get(scgi, "ANALYTICS");
503
+ if(str && strcmp(str,"enabled")==0){
504
+ w->tmp->profiler = 'y';
505
+ }else{
506
+ w->tmp->profiler = 'n';
507
+ }
508
+ }
509
+
510
+ load_application(w);
511
+ }
data/src/worker/worker.h CHANGED
@@ -23,7 +23,7 @@
23
23
  #ifndef WORKER_H_
24
24
  #define WORKER_H_
25
25
 
26
- #include <wkr_static.h>
26
+ #include <wkr_http.h>
27
27
 
28
28
  typedef struct wkr_s wkr_t;
29
29
  typedef struct wkr_tmp_s wkr_tmp_t;
@@ -31,22 +31,28 @@ typedef struct wkr_ctl_s wkr_ctl_t;
31
31
 
32
32
  /****** Worket temporary structure ****/
33
33
  struct wkr_tmp_s {
34
- wr_str_t path; /**< Application path */
35
- wr_str_t env; /**< Application environment */
36
- wr_str_t type; /**< Application type */
37
- wr_str_t name; /**< Application name */
38
- wr_str_t resolver; /**< Application baseuri */
39
- wr_str_t ruby_path; /**< Ruby library path */
40
- wr_str_t script_path; /**< webroar.rb script path */
41
- wr_str_t root_path; /**< WebROaR root path */
42
- char profiler; /**< Analytics flag */
43
- wr_str_t ctl_path; /**< Server control path/port */
44
- wr_str_t log_file; /**< Log file name */
45
- short gid; /**< Process group id */
46
- short uid; /**< Process user id */
47
- short keep_alive; /**< HTTP connection keep alive flag */
48
- short is_uds;
49
- short is_static; /**< Worker to serve static files only */
34
+ wr_str_t path; /**< Application path */
35
+ wr_str_t env; /**< Application environment */
36
+ wr_str_t type; /**< Application type */
37
+ wr_str_t name; /**< Application name */
38
+ wr_str_t resolver; /**< Application baseuri */
39
+ wr_str_t root_path; /**< WebROaR root path */
40
+ char profiler; /**< Analytics flag */
41
+ wr_str_t ctl_path; /**< Server control path/port */
42
+ wr_str_t log_file; /**< Log file name */
43
+ short gid; /**< Process group id */
44
+ short uid; /**< Process user id */
45
+ short keep_alive; /**< HTTP connection keep alive flag */
46
+ short is_uds;
47
+ short is_static; /**< Worker to serve static files only */
48
+ #ifdef W_ZLIB
49
+ wr_u_long lower_limit; /**< Content-Length lower than the value would not be encoded */
50
+ wr_u_long upper_limit; /**< Content-Length larger than the value would not be encoded */
51
+ #ifdef W_REGEX
52
+ wr_str_t r_user_agent; /**< Regex value to validate User-Agent */
53
+ wr_str_t r_content_type; /**< Regex value to validate Content-Type */
54
+ #endif
55
+ #endif
50
56
  };
51
57
 
52
58
  wkr_tmp_t* wkr_tmp_new();
@@ -56,44 +62,50 @@ void wkr_tmp_free(wkr_tmp_t**);
56
62
  struct wkr_ctl_s {
57
63
  int fd;
58
64
  ev_io w_read;
59
- char msg[WR_MSG_SIZE];
65
+ char msg[STR_SIZE1KB];
60
66
  size_t msg_size;
61
67
  size_t bytes_read;
62
68
  ev_io w_write;
69
+ ev_timer t_ack;
63
70
  //size_t bytes_write;
64
71
  scgi_t* scgi;
72
+ int error;
65
73
  };
66
74
 
67
- wkr_ctl_t* wkr_ctl_new();
75
+ wkr_ctl_t* wkr_ctl_new(wkr_t *w);
68
76
  void wkr_ctl_free(wkr_ctl_t**);
69
- int send_ack_on_internet_socket(wkr_t* w);
70
- int send_ack_on_unix_socket(wkr_t* w);
77
+ int connect_to_head(wkr_t *w);
78
+ void start_ctl_watcher(wkr_t *w);
79
+ // Flag to create error response.
80
+ void get_worker_add_ctl_scgi(wkr_t* w, const int flag);
81
+ int send_config_req_msg(wkr_t* w);
82
+ void application_config_read_cb(wkr_t* w, scgi_t *scgi);
71
83
 
72
84
  /********** Worker structure *********/
73
85
  struct wkr_s {
74
86
  /** Listen request from Head */
75
- int listen_fd;
76
- int listen_port;
77
- wr_str_t sock_path;
78
- ev_io w_accept;
87
+ int listen_fd;
88
+ int listen_port;
89
+ wr_str_t sock_path;
90
+ ev_io w_accept;
79
91
  struct ev_loop *loop;
80
92
 
81
93
  /** Request */
82
- int req_fd; /**< Socket fd */
83
- ev_io w_req; /**< watcher */
84
- short is_uds;
94
+ int req_fd; /**< Socket fd */
95
+ ev_io w_req; /**< watcher */
96
+ short is_uds;
85
97
 
86
- wkr_ctl_t *ctl;
87
- wkr_tmp_t *tmp;
88
- http_t *http;
98
+ wkr_ctl_t *ctl;
99
+ wkr_tmp_t *tmp;
100
+ http_t *http;
101
+
102
+ wr_str_list_t *env_var; /**< Environment variable array */
89
103
  };
90
104
 
91
105
  wkr_t* worker_new(struct ev_loop *, wkr_tmp_t*);
92
106
  void worker_free(wkr_t**);
93
- void worker_accept_requests(wkr_t*);
94
- int worker_connect(wkr_t*);
107
+ void init_idle_watcher(wkr_t *w);
95
108
  void start_idle_watcher();
96
- void stop_idle_watcher();
97
109
  void sigproc();
98
110
 
99
111
  #endif /*WORKER_H_*/