diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 22 |
1 files changed, 18 insertions, 4 deletions
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "xs_mime.h" | 9 | #include "xs_mime.h" |
| 10 | #include "xs_time.h" | 10 | #include "xs_time.h" |
| 11 | #include "xs_openssl.h" | 11 | #include "xs_openssl.h" |
| 12 | #include "xs_fcgi.h" | ||
| 12 | 13 | ||
| 13 | #include "snac.h" | 14 | #include "snac.h" |
| 14 | 15 | ||
| @@ -24,6 +25,8 @@ | |||
| 24 | #include <poll.h> | 25 | #include <poll.h> |
| 25 | #endif | 26 | #endif |
| 26 | 27 | ||
| 28 | int use_fcgi = 0; | ||
| 29 | |||
| 27 | int srv_running = 0; | 30 | int srv_running = 0; |
| 28 | 31 | ||
| 29 | /* nodeinfo 2.0 template */ | 32 | /* nodeinfo 2.0 template */ |
| @@ -199,8 +202,12 @@ void httpd_connection(FILE *f) | |||
| 199 | xs *etag = NULL; | 202 | xs *etag = NULL; |
| 200 | int p_size = 0; | 203 | int p_size = 0; |
| 201 | char *p; | 204 | char *p; |
| 205 | int fcgi_id; | ||
| 202 | 206 | ||
| 203 | req = xs_httpd_request(f, &payload, &p_size); | 207 | if (use_fcgi) |
| 208 | req = xs_fcgi_request(f, &payload, &p_size, &fcgi_id); | ||
| 209 | else | ||
| 210 | req = xs_httpd_request(f, &payload, &p_size); | ||
| 204 | 211 | ||
| 205 | if (req == NULL) { | 212 | if (req == NULL) { |
| 206 | /* probably because a timeout */ | 213 | /* probably because a timeout */ |
| @@ -330,7 +337,10 @@ void httpd_connection(FILE *f) | |||
| 330 | headers = xs_dict_append(headers, "access-control-allow-origin", "*"); | 337 | headers = xs_dict_append(headers, "access-control-allow-origin", "*"); |
| 331 | headers = xs_dict_append(headers, "access-control-allow-headers", "*"); | 338 | headers = xs_dict_append(headers, "access-control-allow-headers", "*"); |
| 332 | 339 | ||
| 333 | xs_httpd_response(f, status, headers, body, b_size); | 340 | if (use_fcgi) |
| 341 | xs_fcgi_response(f, status, headers, body, b_size, fcgi_id); | ||
| 342 | else | ||
| 343 | xs_httpd_response(f, status, headers, body, b_size); | ||
| 334 | 344 | ||
| 335 | fclose(f); | 345 | fclose(f); |
| 336 | 346 | ||
| @@ -550,6 +560,8 @@ void httpd(void) | |||
| 550 | char sem_name[24]; | 560 | char sem_name[24]; |
| 551 | sem_t anon_job_sem; | 561 | sem_t anon_job_sem; |
| 552 | 562 | ||
| 563 | use_fcgi = xs_type(xs_dict_get(srv_config, "fastcgi")) == XSTYPE_TRUE; | ||
| 564 | |||
| 553 | address = xs_dict_get(srv_config, "address"); | 565 | address = xs_dict_get(srv_config, "address"); |
| 554 | port = xs_number_str(xs_dict_get(srv_config, "port")); | 566 | port = xs_number_str(xs_dict_get(srv_config, "port")); |
| 555 | 567 | ||
| @@ -564,7 +576,8 @@ void httpd(void) | |||
| 564 | signal(SIGTERM, term_handler); | 576 | signal(SIGTERM, term_handler); |
| 565 | signal(SIGINT, term_handler); | 577 | signal(SIGINT, term_handler); |
| 566 | 578 | ||
| 567 | srv_log(xs_fmt("httpd start %s:%s %s", address, port, USER_AGENT)); | 579 | srv_log(xs_fmt("httpd%s start %s:%s %s", use_fcgi ? " (FastCGI)" : "", |
| 580 | address, port, USER_AGENT)); | ||
| 568 | 581 | ||
| 569 | /* show the number of usable file descriptors */ | 582 | /* show the number of usable file descriptors */ |
| 570 | struct rlimit r; | 583 | struct rlimit r; |
| @@ -651,5 +664,6 @@ void httpd(void) | |||
| 651 | 664 | ||
| 652 | xs *uptime = xs_str_time_diff(time(NULL) - start_time); | 665 | xs *uptime = xs_str_time_diff(time(NULL) - start_time); |
| 653 | 666 | ||
| 654 | srv_log(xs_fmt("httpd stop %s:%s (run time: %s)", address, port, uptime)); | 667 | srv_log(xs_fmt("httpd%s stop %s:%s (run time: %s)", use_fcgi ? " (FastCGI)" : "", |
| 668 | address, port, uptime)); | ||
| 655 | } | 669 | } |