This will allow us to efficiently support file upload through SAPI in the future.
* Fixes
}
-static char *sapi_cgi_read_post(SLS_D)
+static int sapi_cgi_read_post(char *buffer, uint count_bytes SLS_DC)
{
uint read_bytes=0, tmp_read_bytes;
- char *result = (char *) emalloc(SG(request_info).content_length+1);
- while (read_bytes < SG(request_info).content_length) {
- tmp_read_bytes = read(0, result+read_bytes, SG(request_info).content_length-read_bytes);
+ count_bytes = MIN(count_bytes, SG(request_info).content_length-SG(read_post_bytes));
+ while (read_bytes < count_bytes) {
+ tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes);
if (tmp_read_bytes<=0) {
break;
}
read_bytes += tmp_read_bytes;
}
- result[read_bytes]=0;
- return result;
+ return read_bytes;
}
ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini)
{
- syntax_highlighter_ini->highlight_comment = INI_STR("highlight_comment");
- syntax_highlighter_ini->highlight_default = INI_STR("highlight_default");
- syntax_highlighter_ini->highlight_html = INI_STR("highlight_html");
- syntax_highlighter_ini->highlight_keyword = INI_STR("highlight_keyword");
- syntax_highlighter_ini->highlight_string = INI_STR("highlight_string");
+ syntax_highlighter_ini->highlight_comment = INI_STR("highlight.comment");
+ syntax_highlighter_ini->highlight_default = INI_STR("highlight.default");
+ syntax_highlighter_ini->highlight_html = INI_STR("highlight.html");
+ syntax_highlighter_ini->highlight_keyword = INI_STR("highlight.keyword");
+ syntax_highlighter_ini->highlight_string = INI_STR("highlight.string");
}
{
char *res = NULL, *var, *val;
pval *array_ptr;
+ int free_buffer;
ELS_FETCH();
PLS_FETCH();
SLS_FETCH();
break;
}
- if (arg == PARSE_POST) {
+ if (arg == PARSE_POST) { /* POST data */
res = php3_getpost(array_ptr PLS_CC);
- } else if (arg == PARSE_GET) { /* Get data */
+ free_buffer = 0;
+ } else if (arg == PARSE_GET) { /* GET data */
var = SG(request_info).query_string;
if (var && *var) {
res = (char *) estrdup(var);
+ free_buffer = 1;
+ } else {
+ free_buffer = 0;
}
} else if (arg == PARSE_COOKIE) { /* Cookie data */
var = SG(request_info).cookie_data;
if (var && *var) {
res = (char *) estrdup(var);
+ free_buffer = 1;
+ } else {
+ free_buffer = 0;
}
} else if (arg == PARSE_STRING) { /* String data */
res = str;
+ free_buffer = 1;
}
if (!res) {
return;
var = strtok(NULL, PG(arg_separator));
}
}
- efree(res);
+ if (free_buffer) {
+ efree(res);
+ }
}
}
+#undef SAPI_POST_BLOCK_SIZE
+#define SAPI_POST_BLOCK_SIZE 2
+
+static void sapi_read_post_data(SLS_D)
+{
+ int read_bytes, total_read_bytes=0;
+ int allocated_bytes=SAPI_POST_BLOCK_SIZE+1;
+
+ SG(request_info).post_data = emalloc(allocated_bytes);
+
+ for (;;) {
+ read_bytes = sapi_module.read_post(SG(request_info).post_data+total_read_bytes, SAPI_POST_BLOCK_SIZE SLS_CC);
+ if (read_bytes<=0) {
+ break;
+ }
+ total_read_bytes += read_bytes;
+ if (read_bytes < SAPI_POST_BLOCK_SIZE) {
+ break;
+ }
+ if (total_read_bytes+SAPI_POST_BLOCK_SIZE >= allocated_bytes) {
+ allocated_bytes = total_read_bytes+SAPI_POST_BLOCK_SIZE+1;
+ SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes);
+ }
+ }
+ SG(request_info).post_data[total_read_bytes] = 0; /* terminating NULL */
+}
+
+
SAPI_API void sapi_activate(SLS_D)
{
zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0);
SG(sapi_headers).send_default_content_type = 1;
SG(sapi_headers).http_response_code = 200;
SG(headers_sent) = 0;
+ SG(read_post_bytes) = 0;
if (SG(server_context)) {
- SG(request_info).post_data = sapi_module.read_post(SLS_C);
+ sapi_read_post_data(SLS_C);
SG(request_info).cookie_data = sapi_module.read_cookies(SLS_C);
}
}
#include "zend.h"
#include "zend_llist.h"
+#define SAPI_POST_BLOCK_SIZE 4000
#if WIN32||WINNT
# ifdef SAPI_EXPORTS
void *server_context;
sapi_request_info request_info;
sapi_headers_struct sapi_headers;
+ uint read_post_bytes;
unsigned char headers_sent;
} sapi_globals_struct;
int (*send_headers)(sapi_headers_struct *sapi_headers SLS_DC);
void (*send_header)(sapi_header_struct *sapi_header, void *server_context);
- char *(*read_post)(SLS_D);
+ int (*read_post)(char *buffer, uint count_bytes SLS_DC);
char *(*read_cookies)(SLS_D);
};