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
@@ -18,13 +18,21 @@
18
18
  */
19
19
 
20
20
  #include <worker.h>
21
- #include <wr_logger.h>
22
21
  #include <netinet/in.h>
23
22
  #include <sys/un.h>
24
23
 
24
+ #define WR_CTL_ACK_TIMEOUT 15.
25
+
25
26
  extern int is_alive;
26
27
 
27
- wkr_ctl_t* wkr_ctl_new() {
28
+ int ctl_msg_process(wkr_t* w);
29
+
30
+ void ctl_ack_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
31
+ LOG_INFO("Control message timeout");
32
+ is_alive = 0;
33
+ };
34
+
35
+ wkr_ctl_t* wkr_ctl_new(wkr_t *w) {
28
36
  LOG_FUNCTION
29
37
  wkr_ctl_t *ctl = wr_malloc(wkr_ctl_t);
30
38
 
@@ -34,8 +42,13 @@ wkr_ctl_t* wkr_ctl_new() {
34
42
 
35
43
  ctl->fd = -1;
36
44
  ctl->msg_size = ctl->bytes_read = 0;
45
+ ctl->w_read.data = ctl->w_write.data = w;
37
46
  ctl->scgi = NULL;
47
+ ctl->error = FALSE;
48
+ ctl->t_ack.data = ctl;
38
49
 
50
+ ev_timer_init (&ctl->t_ack, ctl_ack_timeout_cb, 0., WR_CTL_ACK_TIMEOUT);
51
+
39
52
  return ctl;
40
53
  }
41
54
 
@@ -52,53 +65,60 @@ void wkr_ctl_free(wkr_ctl_t **c) {
52
65
  *c = NULL;
53
66
  }
54
67
 
55
- /** Process control message */
56
- static inline void ctl_msg_process(wkr_t* w) {
68
+ /** Connect to head process **/
69
+ int connect_to_head(wkr_t *w){
57
70
  LOG_FUNCTION
58
71
  wkr_ctl_t *ctl = w->ctl;
59
- char *value;
60
-
61
- scgi_t* ctl_req = ctl->scgi;
62
- ctl->scgi = NULL;
63
-
64
- value = (char*) scgi_header_value_get(ctl_req, "METHOD");
65
- if(value) {
66
- if(strcmp(value,"ADD")==0) {
67
- // Response of ADD method
68
- value = (char*) scgi_header_value_get(ctl_req, "STATUS");
69
- if(value && strcmp(value, "OK")==0) {
70
- LOG_INFO("Worker connected with Head.");
71
- } else {
72
- LOG_ERROR(SEVERE,"Unable to connect with Head.");
73
- sigproc();
74
- }
75
- } else if(strcmp(value,"REMOVE")==0) {
76
- //Request to REMOVE worker
77
- //TODO: need to send acknowledgement for clossing or not
78
- /*scgi_t* ctl_resp = scgi_new();
79
- if(ctl_resp){
80
- scgi_header_add(ctl_resp, "METHOD", strlen("METHOD"), "REMOVE", strlen("REMOVE"));
81
- scgi_header_add(ctl_resp, "STATUS", strlen("STATUS"), "OK", strlen("OK"));
82
- scgi_build(ctl_resp);
83
- send(control.fd, ctl_resp->request_buffer, ctl_resp->request_length, 0);
84
- scgi_free(ctl_resp);
85
- }*/
86
- sigproc();
87
- } else if(strcmp(value,"PING") == 0) {
88
- LOG_INFO("Worker got PING message");
89
- scgi_t* ctl_resp = scgi_new();
90
- if(ctl_resp) {
91
- scgi_header_add(ctl_resp, "COMPONENT", strlen("COMPONENT"), "WORKER", strlen("WORKER"));
92
- scgi_header_add(ctl_resp, "METHOD", strlen("METHOD"), "PING", strlen("PING"));
93
- scgi_header_add(ctl_resp, "STATUS", strlen("STATUS"), "OK", strlen("OK"));
94
- scgi_build(ctl_resp);
95
- ctl->scgi = ctl_resp;
96
- ev_io_start(w->loop, &ctl->w_write);
97
- }
72
+
73
+ if(w->is_uds == FALSE) {
74
+ struct sockaddr_in addr;
75
+
76
+ LOG_DEBUG(DEBUG,"connect_to_head() port = %i", w->listen_port);
77
+
78
+ if ((ctl->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
79
+ LOG_ERROR(WARN,"socket():%s",strerror(errno));
80
+ return FALSE;
81
+ }
82
+ setsocketoption(ctl->fd);
83
+ LOG_DEBUG(DEBUG,"connect_to_head() FD for control.fd is %d",ctl->fd);
84
+
85
+ int iport = atoi(w->tmp->ctl_path.str);
86
+ addr.sin_family = AF_INET; // host byte order
87
+ addr.sin_port = htons(iport); // short, network byte order
88
+ addr.sin_addr.s_addr = htonl(INADDR_ANY); // auto-fill with my IP
89
+ memset(addr.sin_zero, '\0', sizeof addr.sin_zero);
90
+
91
+ if(connect(ctl->fd, (struct sockaddr *)&addr, sizeof addr) < 0) {
92
+ LOG_ERROR(SEVERE,"Connection with controller failed:%s",strerror(errno));
93
+ return FALSE;
94
+ }
95
+ }else{
96
+ LOG_DEBUG(DEBUG,"connect_to_head() path = %s", w->sock_path.str);
97
+ struct sockaddr_un addr;
98
+
99
+ if ((ctl->fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
100
+ LOG_ERROR(WARN,"socket()%s",strerror(errno));
101
+ return FALSE;
102
+ }
103
+
104
+ setsocketoption(ctl->fd);
105
+
106
+ memset(&addr, 0, sizeof(addr));
107
+ addr.sun_family = AF_UNIX;
108
+ strcpy(addr.sun_path, w->tmp->ctl_path.str);
109
+
110
+ int len = sizeof(addr.sun_family)+strlen(addr.sun_path);
111
+ #ifdef __APPLE__
112
+ len ++;
113
+ #endif
114
+
115
+ LOG_DEBUG(DEBUG,"connect_to_head() connecting with socket %s",addr.sun_path);
116
+ if(connect(ctl->fd, (struct sockaddr *)&addr, len) < 0) {
117
+ LOG_ERROR(SEVERE,"Connect with controller fd failed: %s",strerror(errno));
118
+ return FALSE;
98
119
  }
99
- } else {
100
- LOG_ERROR(SEVERE,"METHOD is missing");
101
120
  }
121
+ return TRUE;
102
122
  }
103
123
 
104
124
  /** Send SCGI control message */
@@ -106,26 +126,27 @@ void ctl_write_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
106
126
  LOG_FUNCTION
107
127
  wkr_t* w = (wkr_t*) watcher->data;
108
128
  wkr_ctl_t *ctl = w->ctl;
109
-
129
+
110
130
  if(revents & EV_ERROR) {
111
131
  ev_io_stop(loop, watcher);
112
132
  LOG_ERROR(SEVERE,"Error writing control message :%s",strerror(errno));
113
- sigproc();
133
+ is_alive = 0;
114
134
  return;
115
135
  }
116
136
  if(scgi_send(ctl->scgi, watcher->fd) <= 0){
117
137
  ev_io_stop(loop, watcher);
118
138
  LOG_ERROR(SEVERE,"Error writing control message :%s",strerror(errno));
119
- sigproc();
139
+ is_alive = 0;
120
140
  return;
121
141
  }
122
-
142
+
123
143
  // Check message length
124
144
  if(ctl->scgi->bytes_sent >= ctl->scgi->length) {
125
145
  ev_io_stop(loop, watcher);
126
146
  LOG_DEBUG(DEBUG, "ctl_write_cb() message sent successfully");
127
147
  scgi_free(ctl->scgi);
128
148
  ctl->scgi = NULL;
149
+ if(ctl->error == TRUE) is_alive = 0;
129
150
  }
130
151
  }
131
152
 
@@ -134,7 +155,7 @@ void ctl_read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
134
155
  LOG_FUNCTION
135
156
  wkr_t* w = (wkr_t*) watcher->data;
136
157
  wkr_ctl_t *ctl = w->ctl;
137
-
158
+
138
159
  if(revents & EV_ERROR) {
139
160
  ev_io_stop(loop, watcher);
140
161
  is_alive = 0;
@@ -142,8 +163,8 @@ void ctl_read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
142
163
  return;
143
164
  }
144
165
  int bytesRead = recv(watcher->fd, ctl->msg + ctl->bytes_read,
145
- WR_MSG_SIZE - ctl->bytes_read, 0);
146
-
166
+ STR_SIZE1KB - ctl->bytes_read, 0);
167
+
147
168
  if(bytesRead <= 0) {
148
169
  LOG_ERROR(SEVERE,"Error reading control message :%s",strerror(errno));
149
170
  ev_io_stop(loop, watcher);
@@ -151,7 +172,7 @@ void ctl_read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
151
172
  return;
152
173
  }
153
174
  ctl->bytes_read += bytesRead;
154
-
175
+
155
176
  int i;
156
177
  for(i = 0 ; i < ctl->bytes_read ; i++) {
157
178
  if(ctl->msg[i] == ':') {
@@ -162,9 +183,9 @@ void ctl_read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
162
183
  return;
163
184
  ctl->msg_size = atoi(ctl->msg);
164
185
  ctl->msg_size += (i+2);
165
-
186
+
166
187
  scgi_t* ctl_req = NULL;
167
-
188
+
168
189
  if(ctl->bytes_read >= ctl->msg_size) {
169
190
  ctl_req = scgi_parse(ctl->msg, ctl->msg_size);
170
191
  if(ctl_req == NULL ) {
@@ -178,109 +199,148 @@ void ctl_read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
178
199
  scgi_free(ctl_req);
179
200
  return;
180
201
  }
181
-
202
+
182
203
  ctl->scgi = ctl_req;
183
- ctl_msg_process(w);
184
- scgi_free(ctl_req);
204
+ if(ctl_msg_process(w) == TRUE){
205
+ scgi_free(ctl_req);
206
+ }else{
207
+ scgi_free(ctl_req);
208
+ is_alive = 0;
209
+ }
185
210
  } else {
186
211
  return;
187
212
  }
188
-
213
+
189
214
  ctl->bytes_read = ctl->msg_size = 0;
190
215
  }
191
216
 
192
- /** Send connect acknowledgement on internet socket */
193
- int send_ack_on_internet_socket(wkr_t* w) {
194
- LOG_FUNCTION
195
- LOG_DEBUG(DEBUG,"send_ack_on_internet_socket() port = %i", w->listen_port);
196
- wkr_ctl_t *ctl = w->ctl;
197
-
198
- struct sockaddr_in addr;
199
-
200
- if ((ctl->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
201
- LOG_ERROR(WARN,"socket():%s",strerror(errno));
202
- return -1;
203
- }
204
- setsocketoption(ctl->fd);
205
- LOG_DEBUG(DEBUG,"send_ack_on_internet_socket() FD for control.fd is %d",ctl->fd);
206
- int iport = atoi(w->tmp->ctl_path.str);
207
- addr.sin_family = AF_INET; // host byte order
208
- addr.sin_port = htons(iport); // short, network byte order
209
- addr.sin_addr.s_addr = htonl(INADDR_ANY); // auto-fill with my IP
210
- memset(addr.sin_zero, '\0', sizeof addr.sin_zero);
217
+ /** Start control wathers */
218
+ void start_ctl_watcher(wkr_t *w){
219
+ ev_io_init(&(w->ctl->w_read),ctl_read_cb, w->ctl->fd, EV_READ);
220
+ ev_io_init(&(w->ctl->w_write),ctl_write_cb, w->ctl->fd, EV_WRITE);
221
+ ev_io_start(w->loop,&(w->ctl->w_read));
222
+ }
211
223
 
212
- if(connect(ctl->fd, (struct sockaddr *)&addr, sizeof addr) < 0) {
213
- LOG_ERROR(SEVERE,"Connection with controller failed:%s",strerror(errno));
214
- return -1;
215
- }
216
- char buf[WR_SHORT_STR_LEN];
217
- int len;
224
+ /** Set flag to TRUE to generate error request */
225
+ void get_worker_add_ctl_scgi(wkr_t* w, const int flag){
218
226
  pid_t pid = getpid();
219
-
220
- scgi_t* add_request = scgi_new();
221
- if(add_request == NULL) {
222
- LOG_ERROR(SEVERE,"Cannot create SCGI Request");
223
- return -1;
224
- }
225
-
227
+ char buf[STR_SIZE32];
228
+ int len = sprintf(buf, "%d", pid);
229
+
230
+ scgi_t* scgi = w->ctl->scgi;
231
+
226
232
  // Construct SCGI request
227
- scgi_header_add(add_request, "COMPONENT", strlen("COMPONENT"), "WORKER", strlen("WORKER"));
228
- scgi_header_add(add_request, "METHOD", strlen("METHOD"), "ADD", strlen("ADD"));
229
- scgi_header_add(add_request, "APPLICATION", strlen("APPLICATION"), w->tmp->name.str, w->tmp->name.len);
230
- scgi_header_add(add_request, "UDS", strlen("UDS"), "NO", strlen("NO"));
231
- len = sprintf(buf, "%d", w->listen_port);
232
- scgi_header_add(add_request, "PORT", strlen("PORT"), buf, len);
233
- len = sprintf(buf, "%d", pid);
234
- scgi_header_add(add_request, "PID", strlen("PID"), buf, len);
235
-
236
- scgi_build(add_request);
237
-
238
- ctl->w_read.data = ctl->w_write.data = w;
239
- ctl->bytes_read = 0;
240
- // ctl->bytes_write = 0;
241
- ctl->scgi = add_request;
242
- ev_io_init(&(ctl->w_read),ctl_read_cb, ctl->fd,EV_READ);
243
- ev_io_start(w->loop,&(ctl->w_read));
244
- ev_io_init(&(ctl->w_write),ctl_write_cb, ctl->fd,EV_WRITE);
245
- ev_io_start(w->loop,&(ctl->w_write));
246
-
247
- return 0;
233
+
234
+ scgi_header_add(scgi, "COMPONENT", strlen("COMPONENT"), "WORKER", strlen("WORKER"));
235
+
236
+ if(flag == TRUE){
237
+ scgi_header_add(scgi, "METHOD", strlen("METHOD"), "ERROR", strlen("ERROR"));
238
+ }else{
239
+ scgi_header_add(scgi, "METHOD", strlen("METHOD"), "ADD", strlen("ADD"));
240
+ }
241
+
242
+ scgi_header_add(scgi, "APPLICATION", strlen("APPLICATION"), w->tmp->name.str, w->tmp->name.len);
243
+ scgi_header_add(scgi, "PID", strlen("PID"), buf, len);
244
+
245
+ if(w->is_uds == 1) {
246
+ scgi_header_add(scgi, "UDS", strlen("UDS"), "YES", strlen("YES"));
247
+ scgi_header_add(scgi, "SOCK_PATH", strlen("SOCK_PATH"), w->sock_path.str, w->sock_path.len);
248
+ }else{
249
+ scgi_header_add(scgi, "UDS", strlen("UDS"), "NO", strlen("NO"));
250
+ len = sprintf(buf, "%d", w->listen_port);
251
+ scgi_header_add(scgi, "PORT", strlen("PORT"), buf, len);
252
+ }
253
+
254
+ scgi_build(scgi);
248
255
  }
249
256
 
250
- /** Send connect acknowledgement on unix domain socket */
251
- int send_ack_on_unix_socket(wkr_t* w) {
257
+ /** Process control message */
258
+ int ctl_msg_process(wkr_t* w) {
252
259
  LOG_FUNCTION
253
- LOG_DEBUG(DEBUG,"send_ack_on_unix_socket() path = %s", w->sock_path.str);
254
260
  wkr_ctl_t *ctl = w->ctl;
255
- size_t len;
261
+ char *value;
256
262
 
257
- char buf[WR_SHORT_STR_LEN];
258
- pid_t pid = getpid();
259
- scgi_t* add_request = scgi_new();
260
- if(add_request == NULL) {
261
- LOG_ERROR(SEVERE,"Cannot create SCGI Request");
262
- return -1;
263
- }
263
+ scgi_t* ctl_req = ctl->scgi;
264
+ ctl->scgi = NULL;
264
265
 
265
- // Construct SCGI request
266
- scgi_header_add(add_request, "COMPONENT", strlen("COMPONENT"), "WORKER", strlen("WORKER"));
267
- scgi_header_add(add_request, "METHOD", strlen("METHOD"), "ADD", strlen("ADD"));
268
- scgi_header_add(add_request, "APPLICATION", strlen("APPLICATION"), w->tmp->name.str, w->tmp->name.len);
269
- scgi_header_add(add_request, "UDS", strlen("UDS"), "YES", strlen("YES"));
270
- scgi_header_add(add_request, "SOCK_PATH", strlen("SOCK_PATH"), w->sock_path.str, w->sock_path.len);
271
- len = sprintf(buf, "%d", pid);
272
- scgi_header_add(add_request, "PID", strlen("PID"), buf, len);
266
+ value = (char*) scgi_header_value_get(ctl_req, "METHOD");
267
+ if(value) {
268
+ if(strcmp(value,"ADD")==0) {
269
+ // Response of ADD method
270
+ value = (char*) scgi_header_value_get(ctl_req, "STATUS");
271
+ if(value && strcmp(value, "OK")==0) {
272
+ LOG_INFO("Worker connected with Head.");
273
+ } else {
274
+ LOG_ERROR(SEVERE,"Unable to connect with Head.");
275
+ return FALSE;
276
+ }
277
+ } else if(strcmp(value,"REMOVE")==0) {
278
+ //Request to REMOVE worker
279
+ //TODO: need to send acknowledgement for clossing or not
280
+ /*scgi_t* ctl_resp = scgi_new();
281
+ if(ctl_resp){
282
+ scgi_header_add(ctl_resp, "METHOD", strlen("METHOD"), "REMOVE", strlen("REMOVE"));
283
+ scgi_header_add(ctl_resp, "STATUS", strlen("STATUS"), "OK", strlen("OK"));
284
+ scgi_build(ctl_resp);
285
+ send(control.fd, ctl_resp->request_buffer, ctl_resp->request_length, 0);
286
+ scgi_free(ctl_resp);
287
+ }*/
288
+ return FALSE;
289
+ } else if(strcmp(value,"PING") == 0) {
290
+ LOG_INFO("Worker got PING message");
291
+ scgi_t* ctl_resp = scgi_new();
292
+ if(ctl_resp) {
293
+ scgi_header_add(ctl_resp, "COMPONENT", strlen("COMPONENT"), "WORKER", strlen("WORKER"));
294
+ scgi_header_add(ctl_resp, "METHOD", strlen("METHOD"), "PING", strlen("PING"));
295
+ scgi_header_add(ctl_resp, "STATUS", strlen("STATUS"), "OK", strlen("OK"));
296
+ scgi_build(ctl_resp);
297
+ ctl->scgi = ctl_resp;
298
+ ev_io_start(w->loop, &ctl->w_write);
299
+ }
300
+ }else if(strcmp(value,"ACK") == 0) {
301
+ LOG_INFO("Worker got ACK message");
302
+ return FALSE;
303
+ }else if(strcmp(value,"CONF_REQ") == 0){
304
+ value = (char*) scgi_header_value_get(ctl_req, "STATUS");
305
+ if(value && strcmp(value, "OK") != 0) {
306
+ LOG_ERROR(SEVERE,"Did not receive application configuration.");
307
+ return FALSE;
308
+ }
309
+ //Application configuration received
310
+ application_config_read_cb(w, ctl_req);
311
+ }
312
+ } else {
313
+ LOG_ERROR(SEVERE,"METHOD is missing");
314
+ }
315
+ return TRUE;
316
+ }
273
317
 
274
- scgi_build(add_request);
318
+ /** Create config request message */
319
+ scgi_t* get_config_req_scgi(wkr_t* worker){
275
320
 
276
- ctl->w_read.data = ctl->w_write.data = w;
277
- ctl->bytes_read = 0;
278
- //ctl->bytes_write = 0;
279
- ctl->scgi = add_request;
280
- ev_io_init(&(ctl->w_read),ctl_read_cb, ctl->fd,EV_READ);
281
- ev_io_start(w->loop,&(ctl->w_read));
282
- ev_io_init(&(ctl->w_write),ctl_write_cb, ctl->fd,EV_WRITE);
283
- ev_io_start(w->loop,&(ctl->w_write));
321
+ scgi_t* scgi = scgi_new();
322
+ if(scgi == NULL) {
323
+ LOG_ERROR(SEVERE,"Cannot create SCGI Request");
324
+ is_alive = 0;
325
+ return NULL;
326
+ }
327
+
328
+ // Construct SCGI request
329
+ scgi_header_add(scgi, "COMPONENT", strlen("COMPONENT"), "WORKER", strlen("WORKER"));
330
+ scgi_header_add(scgi, "APPLICATION", strlen("APPLICATION"), worker->tmp->name.str, worker->tmp->name.len);
331
+ scgi_header_add(scgi, "METHOD", strlen("METHOD"), "CONF_REQ", strlen("CONF_REQ"));
332
+ scgi_build(scgi);
333
+
334
+ return scgi;
335
+ }
284
336
 
337
+ /** Send Config request control message */
338
+ int send_config_req_msg(wkr_t* w) {
339
+ LOG_FUNCTION
340
+
341
+ w->ctl->scgi = get_config_req_scgi(w);
342
+ if(w->ctl->scgi == NULL) return -1;
343
+ ev_io_start(w->loop,&(w->ctl->w_write));
344
+
285
345
  return 0;
286
346
  }
@@ -19,7 +19,7 @@
19
19
  #include <worker.h>
20
20
  #include <ruby.h>
21
21
 
22
- #include "wkr_static.h"
22
+ extern config_t *Config;
23
23
 
24
24
  /** for handling of $0, courtesy http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/16221 */
25
25
  static VALUE gProgName = Qnil;
@@ -41,7 +41,7 @@ static http_t *g_http;
41
41
  /** Call 'Ruby' method 'RequestHandler.process' */
42
42
  void http_req_process() {
43
43
  LOG_FUNCTION
44
- if(g_http->is_static){
44
+ if(g_http->stat){
45
45
  static_file_process(g_http);
46
46
  }else{
47
47
  rb_funcall(cRequestHandler, rb_intern("process"),1,rb_req);
@@ -153,7 +153,7 @@ VALUE log_message(VALUE _, VALUE message_type, VALUE severity, VALUE message) {
153
153
  }
154
154
 
155
155
  /** for handling of $0 */
156
- static void setProgName(VALUE name, ID id) {
156
+ void setProgName(VALUE name, ID id) {
157
157
  LOG_FUNCTION
158
158
  gProgName = rb_obj_as_string(name);
159
159
  rb_obj_taint(gProgName);
@@ -181,7 +181,7 @@ void init_ruby_interface(http_t *h) {
181
181
  rb_define_hooked_variable("$0", &gProgName, 0, setProgName);
182
182
  }
183
183
 
184
- static int init_ruby_interpreter(wkr_t *w) {
184
+ int init_ruby_interpreter(wkr_t *w) {
185
185
  LOG_FUNCTION
186
186
  //initializing ruby interpreter ... referred from main.c and ruby.c of ruby-dev
187
187
  //preparing pseudo argc and argv to set ruby_option
@@ -202,13 +202,13 @@ static int init_ruby_interpreter(wkr_t *w) {
202
202
  }
203
203
  strcpy(v[0],"webroar-worker");
204
204
 
205
- v[1] = (char*) malloc(sizeof(char)*(w->tmp->script_path.len+1));
205
+ v[1] = (char*) malloc(sizeof(char)*(Config->Worker.File.app_loader.len +1));
206
206
  if(!v[1]) {
207
207
  LOG_ERROR(WARN,"Memory allocation to pseudo argv failed.");
208
208
  retval = -1;
209
209
  goto err;
210
210
  }
211
- strcpy(v[1], w->tmp->script_path.str);
211
+ strcpy(v[1], Config->Worker.File.app_loader.str);
212
212
 
213
213
  //RUBY_INIT_STACK;
214
214
  ruby_init();
@@ -274,7 +274,7 @@ int load_rack_adapter(wkr_tmp_t *tmp) {
274
274
 
275
275
  rb_gv_set("g_options",g_options);
276
276
 
277
- rb_protect(RUBY_METHOD_FUNC(rb_require), (VALUE)tmp->script_path.str, &state);
277
+ rb_protect(RUBY_METHOD_FUNC(rb_require), (VALUE)Config->Worker.File.app_loader.str, &state);
278
278
  LOG_DEBUG(DEBUG, "state=%d", state);
279
279
  if ( state != 0 ) {
280
280
  LOG_ERROR(FATAL, "Some problem occurred while loading application.");
@@ -297,6 +297,7 @@ http_t* http_new(void *ptr) {
297
297
 
298
298
  h->req = http_req_new();
299
299
  h->resp = http_resp_new();
300
+ h->stat = NULL;
300
301
 
301
302
  if(h->req==NULL || h->resp == NULL) {
302
303
  http_free(&h);
@@ -304,11 +305,11 @@ http_t* http_new(void *ptr) {
304
305
  }
305
306
 
306
307
  if(w->tmp->is_static){
307
- if(static_module_init(w->tmp->root_path.str)!=0){
308
+ h->stat = static_server_new(w);
309
+ if(h->stat == NULL){
308
310
  http_free(&h);
309
311
  return NULL;
310
312
  }
311
- h->is_static = 1;
312
313
  }else{
313
314
  if(init_ruby_interpreter(w)!=0) {
314
315
  http_free(&h);
@@ -321,7 +322,6 @@ http_t* http_new(void *ptr) {
321
322
  return NULL;
322
323
  }
323
324
  rb_req = Data_Wrap_Struct(cReq, 0, 0, h->req);
324
- h->is_static = 0;
325
325
  }
326
326
  g_http = h;
327
327
  return h;
@@ -331,29 +331,15 @@ void http_free(http_t** http) {
331
331
  LOG_FUNCTION
332
332
  http_t *h = *http;
333
333
  if(h) {
334
- if(h->is_static){
335
- static_module_free();
336
- }else{
334
+ if(h->stat == NULL){
337
335
  ruby_finalize();
338
336
  }
339
337
 
340
- if(h->resp)
341
- http_resp_free(&h->resp);
342
- if(h->req)
343
- http_req_free(&h->req);
338
+ if(h->resp) http_resp_free(&h->resp);
339
+ if(h->req) http_req_free(&h->req);
340
+ if(h->stat) static_server_free(h->stat);
344
341
  free(h);
345
342
  }
346
343
  *http = NULL;
347
344
  }
348
345
 
349
- void http_set(http_t* h) {
350
- LOG_FUNCTION
351
- if(h->resp)
352
- http_resp_set(h->resp);
353
- if(h->req)
354
- http_req_set(h->req);
355
- #ifdef L_DEBUG
356
-
357
- h->conn_id = h->req_id = 0;
358
- #endif
359
- }
@@ -19,7 +19,8 @@
19
19
  #ifndef WKR_HTTP_H_
20
20
  #define WKR_HTTP_H_
21
21
 
22
- #include <wkr_http_response.h>
22
+ #include <wkr_static.h>
23
+
23
24
 
24
25
  typedef struct http_s http_t;
25
26
 
@@ -28,16 +29,15 @@ struct http_s {
28
29
  void *wkr;
29
30
  http_req_t *req;
30
31
  http_resp_t *resp;
31
- short is_static;
32
- #ifdef L_DEBUG
32
+ static_server_t *stat;
33
33
 
34
+ #ifdef L_DEBUG
34
35
  wr_u_int conn_id;
35
36
  wr_u_int req_id;
36
37
  #endif
37
38
  };
38
39
 
39
40
  http_t* http_new(void *worker);
40
- void http_set(http_t*);
41
41
  void http_free(http_t**);
42
42
  void http_req_process();
43
43