|
13 | 13 | #include "fpm_atomic.h"
|
14 | 14 | #include "fpm_conf.h"
|
15 | 15 | #include "fpm_php.h"
|
16 |
| -#include <ext/standard/html.h> |
| 16 | +#include "ext/standard/html.h" |
| 17 | +#include "ext/json/php_json.h" |
17 | 18 |
|
18 | 19 | static char *fpm_status_uri = NULL;
|
19 | 20 | static char *fpm_status_ping_uri = NULL;
|
@@ -140,7 +141,8 @@ int fpm_status_handle_request(void) /* {{{ */
|
140 | 141 | struct fpm_scoreboard_proc_s *proc;
|
141 | 142 | char *buffer, *time_format, time_buffer[64];
|
142 | 143 | time_t now_epoch;
|
143 |
| - int full, encode, has_start_time; |
| 144 | + int full, has_start_time; |
| 145 | + bool encode_html, encode_json; |
144 | 146 | char *short_syntax, *short_post;
|
145 | 147 | char *full_pre, *full_syntax, *full_post, *full_separator;
|
146 | 148 | zend_string *_GET_str;
|
@@ -175,7 +177,8 @@ int fpm_status_handle_request(void) /* {{{ */
|
175 | 177 | full = (fpm_php_get_string_from_table(_GET_str, "full") != NULL);
|
176 | 178 | short_syntax = short_post = NULL;
|
177 | 179 | full_separator = full_pre = full_syntax = full_post = NULL;
|
178 |
| - encode = 0; |
| 180 | + encode_html = false; |
| 181 | + encode_json = false; |
179 | 182 | has_start_time = 1;
|
180 | 183 |
|
181 | 184 | scoreboard_p = fpm_scoreboard_get();
|
@@ -218,7 +221,7 @@ int fpm_status_handle_request(void) /* {{{ */
|
218 | 221 | if (fpm_php_get_string_from_table(_GET_str, "html")) {
|
219 | 222 | sapi_add_header_ex(ZEND_STRL("Content-Type: text/html"), 1, 1);
|
220 | 223 | time_format = "%d/%b/%Y:%H:%M:%S %z";
|
221 |
| - encode = 1; |
| 224 | + encode_html = true; |
222 | 225 |
|
223 | 226 | short_syntax =
|
224 | 227 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
|
@@ -287,7 +290,7 @@ int fpm_status_handle_request(void) /* {{{ */
|
287 | 290 | } else if (fpm_php_get_string_from_table(_GET_str, "xml")) {
|
288 | 291 | sapi_add_header_ex(ZEND_STRL("Content-Type: text/xml"), 1, 1);
|
289 | 292 | time_format = "%s";
|
290 |
| - encode = 1; |
| 293 | + encode_html = true; |
291 | 294 |
|
292 | 295 | short_syntax =
|
293 | 296 | "<?xml version=\"1.0\" ?>\n"
|
@@ -336,6 +339,8 @@ int fpm_status_handle_request(void) /* {{{ */
|
336 | 339 | sapi_add_header_ex(ZEND_STRL("Content-Type: application/json"), 1, 1);
|
337 | 340 | time_format = "%s";
|
338 | 341 |
|
| 342 | + encode_json = true; |
| 343 | + |
339 | 344 | short_syntax =
|
340 | 345 | "{"
|
341 | 346 | "\"pool\":\"%s\","
|
@@ -549,11 +554,24 @@ int fpm_status_handle_request(void) /* {{{ */
|
549 | 554 | query_string = NULL;
|
550 | 555 | tmp_query_string = NULL;
|
551 | 556 | if (proc->query_string[0] != '\0') {
|
552 |
| - if (!encode) { |
553 |
| - query_string = proc->query_string; |
| 557 | + if (encode_html) { |
| 558 | + tmp_query_string = php_escape_html_entities_ex( |
| 559 | + (const unsigned char *) proc->query_string, |
| 560 | + strlen(proc->query_string), 1, ENT_HTML_IGNORE_ERRORS & ENT_COMPAT, |
| 561 | + NULL, /* double_encode */ 1, /* quiet */ 0); |
| 562 | + } else if (encode_json) { |
| 563 | + tmp_query_string = php_json_encode_string(proc->query_string, |
| 564 | + strlen(proc->query_string), PHP_JSON_INVALID_UTF8_IGNORE); |
554 | 565 | } else {
|
555 |
| - tmp_query_string = php_escape_html_entities_ex((const unsigned char *) proc->query_string, strlen(proc->query_string), 1, ENT_HTML_IGNORE_ERRORS & ENT_COMPAT, NULL, /* double_encode */ 1, /* quiet */ 0); |
| 566 | + query_string = proc->query_string; |
| 567 | + } |
| 568 | + if (tmp_query_string) { |
556 | 569 | query_string = ZSTR_VAL(tmp_query_string);
|
| 570 | + /* remove quotes around the string */ |
| 571 | + if (encode_json && ZSTR_LEN(tmp_query_string) >= 2) { |
| 572 | + query_string[ZSTR_LEN(tmp_query_string) - 1] = '\0'; |
| 573 | + ++query_string; |
| 574 | + } |
557 | 575 | }
|
558 | 576 | }
|
559 | 577 |
|
|
0 commit comments