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
@@ -22,7 +22,7 @@
22
22
  static unsigned int wr_req_count = 0;
23
23
  #define HTTP_PREFIX "HTTP_"
24
24
  #define HTTP_PREFIX_LEN 5
25
-
25
+ extern config_t *Config;
26
26
  /** Private function */
27
27
 
28
28
  /** HTTP header received */
@@ -33,7 +33,7 @@ static unsigned int wr_req_count = 0;
33
33
  */
34
34
 
35
35
 
36
- static inline int wr_req_path_set(wr_req_t *req) {
36
+ int wr_req_path_set(wr_req_t *req) {
37
37
  LOG_FUNCTION
38
38
  // terminate request uri with 'null' character
39
39
 
@@ -62,7 +62,7 @@ static inline int wr_req_path_set(wr_req_t *req) {
62
62
  }
63
63
 
64
64
  // Check Query String length
65
- if(req->req_query_str.len > WR_MAX_REQ_QRY_STR_LEN) {
65
+ if(req->req_query_str.len > Config->Request.max_query_size) {
66
66
  LOG_DEBUG(DEBUG,"query str len = %d", req->req_query_str.len);
67
67
  req->resp_buf_len = sprintf(req->resp_buf,"%s","The request query string is too large.");
68
68
  wr_req_invalid(req->conn, WR_HTTP_STATUS_413);
@@ -87,7 +87,7 @@ static inline int wr_req_path_set(wr_req_t *req) {
87
87
  }
88
88
 
89
89
  // Check request path length
90
- if(req->req_path.len > WR_MAX_REQ_PATH_LEN) {
90
+ if(req->req_path.len > Config->Request.max_path_size) {
91
91
  LOG_DEBUG(DEBUG,"req path len = %d", req->req_path.len);
92
92
  req->resp_buf_len = sprintf(req->resp_buf,"%s","The request path is too large.");
93
93
  wr_req_invalid(req->conn, WR_HTTP_STATUS_413);
@@ -116,49 +116,22 @@ static inline int wr_req_path_set(wr_req_t *req) {
116
116
  return 0;
117
117
  }
118
118
 
119
- /*
120
- static inline void wr_req_header_add(wr_req_t * req) {
121
- int i = 5;
122
-
123
- if(req->scgi->request_headers_len+1 > WR_MAX_REQ_HEADER_LEN) {
124
- req->resp_buf_len = sprintf(req->resp_buf,"%s","The number of request headers is too large.");
125
- wr_req_invalid(req->conn, WR_HTTP_STATUS_413);
126
- return;
127
- }
128
-
129
- for( ; i < req->tmp_header.len ; i++) {
130
- req->tmp_header.str[i] = (req->tmp_header.str[i]=='-' ? '_' : wr_toupper(req->tmp_header.str[i]));
131
- }
132
-
133
- LOG_DEBUG(DEBUG, "%s() header=%s, value=%s", __FUNCTION__, req->tmp_header.str, req->tmp_value.str);
134
-
135
- scgiUEST_HEADER_SET(req->scgi,
136
- req->tmp_header.str, req->tmp_header.len,
137
- req->tmp_value.str, req->tmp_value.len);
138
-
139
-
140
-
141
- wr_string_null(req->tmp_value);
142
- wr_string_null(req->tmp_header);
143
- }
144
- */
145
-
146
- static int wr_req_header_length_check(wr_req_t *req, size_t length, int index){
119
+ int wr_req_header_length_check(wr_req_t *req, size_t length, int index){
147
120
  // Check no. of headers
148
- if(index >= WR_MAX_REQ_HEADER_NO) {
121
+ if(index >= Config->Request.max_header_count) {
149
122
  req->resp_buf_len = sprintf(req->resp_buf, "%s", "The number of request header is too large.");
150
123
  return WR_HTTP_STATUS_413;
151
124
  }
152
125
 
153
126
  // Check field length
154
127
  if(req->scgi->index == index){
155
- if(req->scgi->header_list->field_length + length > WR_MAX_REQ_FIELD_NAME_LEN){
128
+ if(req->scgi->header_list->field_length + length > Config->Request.max_field_size){
156
129
  LOG_DEBUG(DEBUG,"header len = %d", req->scgi->header_list->field_length);
157
130
  req->resp_buf_len = sprintf(req->resp_buf, "%s", "The request field name is too large.");
158
131
  return WR_HTTP_STATUS_413;
159
132
  }
160
133
  }else{
161
- if((length + 5) > WR_MAX_REQ_FIELD_NAME_LEN){
134
+ if((length + 5) > Config->Request.max_field_size){
162
135
  LOG_DEBUG(DEBUG,"header len = %d", length + 5);
163
136
  req->resp_buf_len = sprintf(req->resp_buf, "%s", "The request field name is too large.");
164
137
  return WR_HTTP_STATUS_413;
@@ -169,7 +142,7 @@ static int wr_req_header_length_check(wr_req_t *req, size_t length, int index){
169
142
  }
170
143
 
171
144
  // Check request size
172
- if((req->scgi->header_offset + length) > WR_MAX_REQ_HEADER_LEN) {
145
+ if((req->scgi->header_offset + length) > Config->Request.max_header_size) {
173
146
  req->resp_buf_len = sprintf(req->resp_buf,"%s","The request is too large.");
174
147
  return WR_HTTP_STATUS_413;
175
148
  }
@@ -187,19 +160,19 @@ void wr_req_header_field_cb(ebb_request* request, const char *at, size_t length,
187
160
 
188
161
  scgi_header_field_add(req->scgi, at, length, header_index);
189
162
 
190
- LOG_DEBUG(DEBUG,"field name = %s",req->scgi->header + req->scgi->header_list->field_offset);
163
+ //LOG_DEBUG(DEBUG,"field name = %s",req->scgi->header + req->scgi->header_list->field_offset);
191
164
  }
192
165
 
193
- static int wr_req_header_value_check(wr_req_t *req, size_t length, int index){
166
+ int wr_req_header_value_check(wr_req_t *req, size_t length, int index){
194
167
  // Check value length
195
168
  if(req->scgi->index == index){
196
- if(req->scgi->header_list->value_length + length > WR_MAX_REQ_FIELD_VALUE_LEN){
169
+ if(req->scgi->header_list->value_length + length > Config->Request.max_value_size){
197
170
  LOG_DEBUG(DEBUG,"value len = %d", req->scgi->header_list->value_length);
198
171
  req->resp_buf_len = sprintf(req->resp_buf, "%s", "The request field value is too large.");
199
172
  return WR_HTTP_STATUS_413;
200
173
  }
201
174
  }else{
202
- if(length > WR_MAX_REQ_FIELD_VALUE_LEN){
175
+ if(length > Config->Request.max_value_size){
203
176
  LOG_DEBUG(DEBUG,"value len = %d", length + 5);
204
177
  req->resp_buf_len = sprintf(req->resp_buf, "%s", "The request field value is too large.");
205
178
  return WR_HTTP_STATUS_413;
@@ -207,7 +180,7 @@ static int wr_req_header_value_check(wr_req_t *req, size_t length, int index){
207
180
  }
208
181
 
209
182
  // Check request size
210
- if((req->scgi->header_offset + length) > WR_MAX_REQ_HEADER_LEN) {
183
+ if((req->scgi->header_offset + length) > Config->Request.max_header_size) {
211
184
  req->resp_buf_len = sprintf(req->resp_buf,"%s","The request is too large.");
212
185
  return WR_HTTP_STATUS_413;
213
186
  }
@@ -226,7 +199,7 @@ void wr_req_header_value_cb(ebb_request* request, const char *at, size_t length,
226
199
 
227
200
  scgi_header_value_add(req->scgi, at, length, header_index);
228
201
 
229
- LOG_DEBUG(DEBUG,"field value = %s",req->scgi->header + req->scgi->header_list->value_offset);
202
+ //LOG_DEBUG(DEBUG,"field value = %s",req->scgi->header + req->scgi->header_list->value_offset);
230
203
  }
231
204
 
232
205
  /** HTTP Request path received */
@@ -236,7 +209,7 @@ void wr_req_path_cb(ebb_request* request, const char *at, size_t length) {
236
209
  req->req_path.len += length;
237
210
 
238
211
  // Check request path length
239
- if(req->req_path.len > WR_MAX_REQ_PATH_LEN) {
212
+ if(req->req_path.len > Config->Request.max_path_size) {
240
213
  LOG_DEBUG(DEBUG,"req path len = %d", req->req_path.len);
241
214
  req->resp_buf_len = sprintf(req->resp_buf,"%s","The request path is too large.");
242
215
  wr_req_invalid(req->conn, WR_HTTP_STATUS_413);
@@ -251,7 +224,7 @@ void wr_query_string_cb(ebb_request* request, const char *at, size_t length) {
251
224
  req->req_query_str.len += length;
252
225
 
253
226
  // Check query string size
254
- if(req->req_query_str.len > WR_MAX_REQ_QRY_STR_LEN) {
227
+ if(req->req_query_str.len > Config->Request.max_query_size) {
255
228
  LOG_DEBUG(DEBUG,"query str len = %d", req->req_query_str.len);
256
229
  req->resp_buf_len = sprintf(req->resp_buf,"%s","The request query string is too large.");
257
230
  wr_req_invalid(req->conn, WR_HTTP_STATUS_413);
@@ -264,7 +237,7 @@ void wr_req_uri_cb(ebb_request* request, const char *at, size_t length) {
264
237
  LOG_FUNCTION
265
238
  wr_req_t* req =(wr_req_t*) request->data;
266
239
 
267
- if(req->req_uri.len + length > WR_MAX_REQ_URI_LEN) {
240
+ if(req->req_uri.len + length > Config->Request.max_uri_size) {
268
241
  LOG_DEBUG(DEBUG,"req uri len = %d",__FUNCTION__, req->req_uri.len);
269
242
  req->resp_buf_len = sprintf(req->resp_buf,"%s","The request URI is too large.");
270
243
  wr_req_invalid(req->conn, WR_HTTP_STATUS_414);
@@ -285,7 +258,7 @@ void wr_req_fragment_cb(ebb_request* request, const char *at, size_t length) {
285
258
 
286
259
  // Check request path length
287
260
  LOG_DEBUG(DEBUG,"Fragment length = %d", req->req_fragment.len + length);
288
- if((req->req_fragment.len + length) > WR_MAX_REQ_FRAG_LEN) {
261
+ if((req->req_fragment.len + length) > Config->Request.max_frag_size) {
289
262
  LOG_DEBUG(DEBUG,"req fragment len = %d", length);
290
263
  req->resp_buf_len = sprintf(req->resp_buf, "%s", "The request fragment is too large.");
291
264
  wr_req_invalid(req->conn, WR_HTTP_STATUS_413);
@@ -299,6 +272,22 @@ void wr_req_fragment_cb(ebb_request* request, const char *at, size_t length) {
299
272
  }
300
273
  }
301
274
 
275
+ /** Add req request body */
276
+ int wr_req_body_add(wr_req_t *req, const char *at, size_t length) {
277
+ LOG_FUNCTION
278
+ if(req->upload_file) {
279
+ LOG_DEBUG(DEBUG, "writing into file");
280
+ size_t write = 0;
281
+ while(write < length) {
282
+ write += fwrite( at + write, sizeof(char), length - write, req->upload_file);
283
+ }
284
+ } else {
285
+ LOG_DEBUG(DEBUG, "copying into buffer. len=%d", length);
286
+ scgi_body_add(req->scgi, at, length);
287
+ }
288
+ return 0;
289
+ }
290
+
302
291
  /** Request body received */
303
292
  void wr_req_body_cb(ebb_request* request, const char *at, size_t length) {
304
293
  LOG_FUNCTION
@@ -429,17 +418,17 @@ void wr_headers_complete_cb(ebb_request * request) {
429
418
  /* Add WR_EBB_HTTP_VER header into CGI header list */
430
419
  wr_buffer_t *buf;
431
420
  wr_buffer_new(buf);
432
- wr_buffer_create(buf, WR_TINY_STR_LEN);
433
- buf->len = snprintf(buf->str, WR_TINY_STR_LEN, "HTTP/%d.%d", request->version_major, request->version_minor);
421
+ wr_buffer_create(buf, STR_SIZE16);
422
+ buf->len = snprintf(buf->str, STR_SIZE16, "HTTP/%d.%d", request->version_major, request->version_minor);
434
423
  scgi_header_add(req->scgi, WR_EBB_HTTP_VER, WR_EBB_HTTP_VER_LEN, buf->str, buf->len);
435
424
  wr_buffer_free(buf);
436
425
 
437
426
  /** Check content length */
438
427
  LOG_DEBUG(DEBUG,"Request content len = %d", request->content_length);
439
- if(request->content_length > WR_REQ_BODY_MAX_SIZE) {
428
+ if(request->content_length > Config->Request.max_body_size) {
440
429
  // Open file to write req request body
441
430
  wr_buffer_new(req->upload_file_name);
442
- wr_buffer_create(req->upload_file_name, WR_SHORT_STR_LEN);
431
+ wr_buffer_create(req->upload_file_name, STR_SIZE32);
443
432
  req->upload_file_name->len = sprintf(req->upload_file_name->str,"/tmp/ebb_upload_%d", req->id);
444
433
  req->upload_file = fopen(req->upload_file_name->str,"w+");
445
434
  if(req->upload_file == NULL) {
@@ -475,74 +464,73 @@ void wr_req_complete_cb(ebb_request * request) {
475
464
  WR_QUEUE_INSERT(req->app->q_messages, req, rv)
476
465
  if(rv == 0){
477
466
  wr_wkr_dispatch_req(req);
478
- return;
467
+ }else{
468
+ LOG_ERROR(WARN,"Application pending message queue overflow.", req->id, req->req_uri.str);
469
+ wr_req_invalid(req->conn, WR_HTTP_STATUS_503);
479
470
  }
471
+ return;
480
472
  }
481
473
  LOG_ERROR(WARN,"Failed to dispatch req no %d to any application. Request PATH is %s", req->id, req->req_uri.str);
482
474
  wr_req_invalid(req->conn, WR_HTTP_STATUS_404);
483
475
  }
484
476
 
485
- /********************************************************
486
- * Request Function Definition *
487
- ********************************************************/
488
-
489
477
  /** Create new Request */
490
478
  wr_req_t* wr_req_new(wr_conn_t* conn) {
491
479
  LOG_FUNCTION
492
480
  LOG_DEBUG(DEBUG,"for connection = %d", conn->id);
493
-
481
+
494
482
  wr_req_t *req = wr_malloc(wr_req_t);
495
-
483
+
496
484
  if(req == NULL) {
497
485
  LOG_DEBUG(SEVERE, "Error req is null. Returning ...");
498
486
  return NULL;
499
487
  }
500
-
488
+
501
489
  req->conn = conn;
502
490
  req->id = ++wr_req_count;
503
-
491
+
504
492
  req->app = NULL;
505
493
  req->wkr = NULL;
506
-
494
+
507
495
  req->upload_file = NULL;
508
496
  req->upload_file_name = NULL;
509
497
  // req->uri_hash =
510
498
  req->bytes_sent = 0;
511
499
  req->scgi = scgi_new();
512
-
500
+
513
501
  if(req->scgi == NULL) {
514
502
  free(req);
515
503
  LOG_ERROR(WARN, "Error req->scgi is null. Returning ...");
516
504
  return NULL;
517
505
  }
518
-
506
+
519
507
  req->resp_buf_len =
520
- req->bytes_received =
521
- req->resp_body_len = 0;
508
+ req->bytes_received =
509
+ req->resp_body_len = 0;
522
510
  req->resp_code = 0;
523
-
511
+
524
512
  req->conn_err = req->using_wkr = FALSE;
525
-
513
+
526
514
  #ifdef L_DEBUG
527
515
  /* Adding Connection id and req id */
528
516
  wr_buffer_t *conn_id, *req_id;
529
517
  wr_buffer_new(conn_id);
530
518
  wr_buffer_new(req_id);
531
- wr_buffer_create(conn_id, WR_SHORT_STR_LEN);
532
- wr_buffer_create(req_id, WR_SHORT_STR_LEN);
519
+ wr_buffer_create(conn_id, STR_SIZE32);
520
+ wr_buffer_create(req_id, STR_SIZE32);
533
521
  conn_id->len = snprintf(conn_id->str, conn_id->size, "%d", conn->id);
534
522
  req_id->len = snprintf(req_id->str, req_id->size, "%d", req->id);
535
- scgi_header_add(req->scgi, WR_CONN_ID, strlen(WR_CONN_ID), conn_id->str, conn_id->len);
536
- scgi_header_add(req->scgi, WR_REQ_ID, strlen(WR_REQ_ID), req_id->str, req_id->len);
523
+ scgi_header_add(req->scgi, Config->Request.Header.conn_id.str, Config->Request.Header.conn_id.len, conn_id->str, conn_id->len);
524
+ scgi_header_add(req->scgi, Config->Request.Header.req_id.str, Config->Request.Header.req_id.len, req_id->str, req_id->len);
537
525
  wr_buffer_free(conn_id);
538
526
  wr_buffer_free(req_id);
539
527
  #endif
540
-
528
+
541
529
  wr_string_null(req->req_uri);
542
530
  wr_string_null(req->req_path);
543
531
  wr_string_null(req->req_query_str);
544
532
  wr_string_null(req->req_fragment);
545
-
533
+
546
534
  ebb_request *request = wr_malloc(ebb_request);
547
535
  if(request == NULL) {
548
536
  scgi_free(req->scgi);
@@ -550,12 +538,12 @@ wr_req_t* wr_req_new(wr_conn_t* conn) {
550
538
  LOG_DEBUG(SEVERE, "Error ebb_request is null. Returning ...");
551
539
  return NULL;
552
540
  }
553
-
541
+
554
542
  ebb_request_init(request);
555
-
543
+
556
544
  //TODO: can connection have multiple requests?
557
545
  req->ebb_req = request;
558
-
546
+
559
547
  request->data = req;
560
548
  request->on_path = wr_req_path_cb;
561
549
  request->on_query_string = wr_query_string_cb;
@@ -566,13 +554,18 @@ wr_req_t* wr_req_new(wr_conn_t* conn) {
566
554
  request->on_headers_complete = wr_headers_complete_cb;
567
555
  request->on_body = wr_req_body_cb;
568
556
  request->on_complete = wr_req_complete_cb;
569
-
557
+
570
558
  //TODO: Check for keep alive status & then increment 'responses_to_write'
571
559
  // Else it will be 1
572
-
560
+
573
561
  return req;
574
562
  }
575
563
 
564
+
565
+ /********************************************************
566
+ * Request Function Definition *
567
+ ********************************************************/
568
+
576
569
  /** Destroy req */
577
570
  void wr_req_free(wr_req_t* req) {
578
571
  LOG_FUNCTION
@@ -604,22 +597,6 @@ void wr_req_free(wr_req_t* req) {
604
597
  }
605
598
  }
606
599
 
607
- /** Add req request body */
608
- int wr_req_body_add(wr_req_t *req, const char *at, size_t length) {
609
- LOG_FUNCTION
610
- if(req->upload_file) {
611
- LOG_DEBUG(DEBUG, "writing into file");
612
- size_t write = 0;
613
- while(write < length) {
614
- write += fwrite( at + write, sizeof(char), length - write, req->upload_file);
615
- }
616
- } else {
617
- LOG_DEBUG(DEBUG, "copying into buffer. len=%d", length);
618
- scgi_body_add(req->scgi, at, length);
619
- }
620
- return 0;
621
- }
622
-
623
600
  ebb_request* wr_new_req_cb(ebb_connection *connection) {
624
601
  LOG_FUNCTION
625
602
  // Create new wr_req
@@ -52,12 +52,8 @@ struct wr_req_s {
52
52
  size_t bytes_received;
53
53
  };
54
54
 
55
- /** Create new Request */
56
- wr_req_t* wr_req_new(wr_conn_t*);
57
55
  /** Destroy Request */
58
56
  void wr_req_free(wr_req_t*);
59
- /** Add Request body */
60
- int wr_req_body_add(wr_req_t*, const char*, size_t);
61
57
  /** Invalid request */
62
58
  void wr_req_invalid(wr_conn_t *, wr_resp_status_t);
63
59
  /** Allocates and initializes ab ebb_request */
@@ -19,6 +19,8 @@
19
19
  #include <wr_request.h>
20
20
  #include <string.h>
21
21
 
22
+ extern config_t *Config;
23
+
22
24
  /*********** Private Function ***********/
23
25
  void wr_req_resolver_print(wr_req_resolver_t* resolver) {
24
26
  LOG_FUNCTION
@@ -41,15 +43,19 @@ void wr_req_resolver_print(wr_req_resolver_t* resolver) {
41
43
  }
42
44
 
43
45
  /** Resolve static content */
46
+ /* Do not set req->app if static workers are not there.
47
+ * If req->app does not set, the static content served by the worker of
48
+ * respective application */
44
49
  int wr_req_resolve_static_content(wr_req_t *req){
45
50
  LOG_FUNCTION
46
- char path[WR_FILE_PATH_LEN + WR_MAX_REQ_PATH_LEN];
51
+ char path[STR_SIZE1KB + Config->Request.max_path_size];
47
52
  char *req_path;
48
53
  struct stat buf;
49
54
  int len;
50
55
  wr_str_t decoded_req_path;
51
56
 
52
- if(WR_QUEUE_SIZE(req->app->svr->static_app->q_workers) <= 0){
57
+ // Check static-workers exist or not
58
+ if(req->app->svr->static_app == NULL || WR_QUEUE_SIZE(req->app->svr->static_app->q_workers) <= 0){
53
59
  LOG_ERROR(SEVERE,"Static content server is down.")
54
60
  return -1;
55
61
  }
@@ -77,7 +83,7 @@ int wr_req_resolve_static_content(wr_req_t *req){
77
83
 
78
84
  /* Add WR_FILE_PATH header into SCGI header list */
79
85
  LOG_DEBUG(DEBUG, "File path = %s, lenght = %d", path, strlen(path));
80
- scgi_header_add(req->scgi, WR_HTTP_FILE_PATH, WR_HTTP_FILE_PATH_LEN, path, strlen(path));
86
+ scgi_header_add(req->scgi, Config->Request.Header.file_path.str, Config->Request.Header.file_path.len, path, strlen(path));
81
87
  req->app = req->app->svr->static_app;
82
88
 
83
89
  return 0;
@@ -99,20 +105,20 @@ wr_req_resolver_t* wr_req_resolver_new() {
99
105
  }
100
106
 
101
107
  /** Add Application resolver */
102
- int wr_req_resolver_add(wr_svr_t *server, wr_app_t *app, wr_app_conf_t *conf) {
108
+ int wr_req_resolver_add(wr_svr_t *server, wr_app_t *app) {
103
109
  LOG_FUNCTION
104
110
  short rv = 0;
105
111
 
106
- if(conf->baseuri.str) {
107
- LOG_DEBUG(DEBUG, "Adding resolver baseuri = %s",conf->baseuri.str);
112
+ if(app->conf->baseuri.str) {
113
+ LOG_DEBUG(DEBUG, "Adding resolver baseuri = %s",app->conf->baseuri.str);
108
114
  wr_baseuri_t *baseuri = wr_malloc(wr_baseuri_t);
109
115
  if(baseuri == NULL) {
110
116
  rv = -1;
111
117
  }
112
118
 
113
- baseuri->baseuri_hash = uri_hash(conf->baseuri.str + 1);
119
+ baseuri->baseuri_hash = uri_hash(app->conf->baseuri.str + 1);
114
120
 
115
- if(baseuri->baseuri_hash == WR_DEFAULT_PREFIX_HASH) {
121
+ if(baseuri->baseuri_hash == Config->Request.prefix_hash) {
116
122
  free(baseuri);
117
123
  server->default_app = app;
118
124
  } else {
@@ -129,8 +135,8 @@ int wr_req_resolver_add(wr_svr_t *server, wr_app_t *app, wr_app_conf_t *conf) {
129
135
  * Host name start and end with '*'
130
136
  */
131
137
 
132
- if(conf->host_name_list) {
133
- wr_host_name_t *host = conf->host_name_list;
138
+ if(app->conf->host_name_list) {
139
+ config_host_list_t *host = app->conf->host_name_list;
134
140
  while(host) {
135
141
  LOG_DEBUG(DEBUG, "Adding resolver Host = %s, type=%d",host->name.str, host->type);
136
142
  wr_host_list_t *list = wr_malloc(wr_host_list_t);
@@ -180,7 +186,7 @@ int wr_req_resolver_remove(wr_svr_t *server, wr_app_t *app) {
180
186
  while(baseuri) {
181
187
  if(baseuri->app == app) {
182
188
  LOG_DEBUG(DEBUG,"Removed application %s",baseuri->app->conf->baseuri.str);
183
- // if(baseuri->baseuri_hash == WR_DEFAULT_PREFIX_HASH){
189
+ // if(baseuri->baseuri_hash == Config->Request.prefix_hash){
184
190
  // server->default_app = NULL;
185
191
  // }
186
192
  if(prev_baseuri == NULL) {
@@ -260,25 +266,25 @@ int wr_req_resolve_http_req(wr_svr_t *server, wr_req_t *req) {
260
266
  }
261
267
 
262
268
  while(list) {
263
- if(list->host->type == WR_HOST_TYPE_STATIC &&
269
+ if(list->host->type == HOST_TYPE_STATIC &&
264
270
  list->host->name.len == host_str.len &&
265
271
  strncmp(list->host->name.str, host_str.str, host_str.len)==0) {
266
272
  LOG_DEBUG(DEBUG,"Application resolved with WR_HOST_TYPE_STATIC host %s", list->host->name.str);
267
273
  app = list->app;
268
274
  break;
269
- } else if(list->host->type == WR_HOST_TYPE_WILDCARD_IN_START &&
275
+ } else if(list->host->type == HOST_TYPE_WILDCARD_IN_START &&
270
276
  list->host->name.len < host_str.len &&
271
277
  strncmp(list->host->name.str, host_str.str + host_str.len - list->host->name.len, list->host->name.len)==0) {
272
278
  LOG_DEBUG(DEBUG,"Application resolved with WR_HOST_TYPE_WILDCARD_IN_START host %s", list->host->name.str);
273
279
  app = list->app;
274
280
  break;
275
- } else if(list->host->type == WR_HOST_TYPE_WILDCARD_IN_END &&
281
+ } else if(list->host->type == HOST_TYPE_WILDCARD_IN_END &&
276
282
  list->host->name.len < host_str.len &&
277
283
  strncmp(list->host->name.str, host_str.str, list->host->name.len)==0) {
278
284
  LOG_DEBUG(DEBUG,"Application resolved with WR_HOST_TYPE_WILDCARD_IN_END host %s", list->host->name.str);
279
285
  app = list->app;
280
286
  break;
281
- } else if(list->host->type == WR_HOST_TYPE_WILDCARD_IN_START_END &&
287
+ } else if(list->host->type == HOST_TYPE_WILDCARD_IN_START_END &&
282
288
  list->host->name.len < host_str.len &&
283
289
  strstr(host_str.str, list->host->name.str)!=NULL) {
284
290
  LOG_DEBUG(DEBUG,"Application resolved with WR_HOST_TYPE_WILDCARD_IN_START_END host %s", list->host->name.str);
@@ -31,7 +31,7 @@ typedef struct wr_host_list_s wr_host_list_t;
31
31
  * Host name start and end with '*'
32
32
  */
33
33
  struct wr_host_list_s {
34
- wr_host_name_t *host;
34
+ config_host_list_t *host;
35
35
  wr_app_t *app;
36
36
  wr_host_list_t *next;
37
37
  };
@@ -50,7 +50,7 @@ struct wr_req_resolver_s {
50
50
  };
51
51
 
52
52
  wr_req_resolver_t* wr_req_resolver_new();
53
- int wr_req_resolver_add(wr_svr_t*, wr_app_t*, wr_app_conf_t*);
53
+ int wr_req_resolver_add(wr_svr_t*, wr_app_t*);
54
54
  int wr_req_resolver_remove(wr_svr_t*, wr_app_t*);
55
55
  int wr_req_resolve_http_req(wr_svr_t*, wr_req_t*);
56
56
  void wr_req_resolver_free(wr_req_resolver_t*);