diff options
Diffstat (limited to 'sapi/cli/php_cli_server.c')
-rw-r--r-- | sapi/cli/php_cli_server.c | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 2c68fa17a4..35d06329d7 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -366,9 +366,9 @@ int php_cli_server_get_system_time(char *buf) { } #endif -static void char_ptr_dtor_p(char **p) /* {{{ */ -{ - pefree(*p, 1); +static void char_ptr_dtor_p(zval *zv) /* {{{ */ +{ + pefree(Z_PTR_P(zv), 1); } /* }}} */ static char *get_last_error() /* {{{ */ @@ -449,11 +449,11 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int static void append_essential_headers(smart_str* buffer, php_cli_server_client *client, int persistent) /* {{{ */ { { - char **val; - if (SUCCESS == zend_hash_find(&client->request.headers, "host", sizeof("host"), (void**)&val)) { + char *val; + if (SUCCESS == (val = zend_hash_str_find_ptr(&client->request.headers, "host", sizeof("host")-1))) { smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent); smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent); - smart_str_appends_ex(buffer, *val, persistent); + smart_str_appends_ex(buffer, val, persistent); smart_str_appendl_ex(buffer, "\r\n", 2, persistent); } } @@ -476,9 +476,8 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ { php_cli_server_client *client; HashTable *headers; - char *key; - uint key_len; - char **value_pointer; + zend_string *key; + char *value; HashPosition pos; if (zend_parse_parameters_none() == FAILURE) { @@ -491,9 +490,10 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ array_init_size(return_value, zend_hash_num_elements(headers)); zend_hash_internal_pointer_reset_ex(headers, &pos); - while (zend_hash_get_current_data_ex(headers, (void **)&value_pointer, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(headers, &key, &key_len, NULL, 0, &pos); - add_assoc_string_ex(return_value, key, key_len, *value_pointer, 1); + while ((value = zend_hash_get_current_data_ptr_ex(headers, &pos)) != NULL) { + zend_hash_get_current_key_ex(headers, &key, NULL, 0, &pos); +//??? + add_assoc_string_ex(return_value, key->val, key->len, value, 1); zend_hash_move_forward_ex(headers, &pos); } } @@ -679,11 +679,11 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers TSRMLS static char *sapi_cli_server_read_cookies(TSRMLS_D) /* {{{ */ { php_cli_server_client *client = SG(server_context); - char **val; - if (FAILURE == zend_hash_find(&client->request.headers, "cookie", sizeof("cookie"), (void**)&val)) { + char *val; + if (NULL == (val = zend_hash_str_find_ptr(&client->request.headers, "cookie", sizeof("cookie")-1))) { return NULL; } - return *val; + return val; } /* }}} */ static int sapi_cli_server_read_post(char *buf, uint count_bytes TSRMLS_DC) /* {{{ */ @@ -710,11 +710,11 @@ static void sapi_cli_server_register_variable(zval *track_vars_array, const char static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { zval *track_vars_array = va_arg(args, zval *); - if (hash_key->nKeyLength) { + if (hash_key->key) { char *real_key, *key; uint i; - key = estrndup(hash_key->arKey, hash_key->nKeyLength); - for(i=0; i<hash_key->nKeyLength; i++) { + key = estrndup(hash_key->key->val, hash_key->key->len); + for(i=0; i<hash_key->key->len; i++) { if (key[i] == '-') { key[i] = '_'; } else { @@ -1411,7 +1411,7 @@ static int php_cli_server_request_ctor(php_cli_server_request *req) /* {{{ */ req->path_info_len = 0; req->query_string = NULL; req->query_string_len = 0; - zend_hash_init(&req->headers, 0, NULL, (void(*)(void*))char_ptr_dtor_p, 1); + zend_hash_init(&req->headers, 0, NULL, char_ptr_dtor_p, 1); zend_hash_init(&req->headers_original_case, 0, NULL, NULL, 1); req->content = NULL; req->content_len = 0; @@ -1682,8 +1682,8 @@ static int php_cli_server_client_read_request_on_header_value(php_http_parser *p } { char *header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len); - zend_hash_add(&client->request.headers, header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL); - zend_hash_add(&client->request.headers_original_case, client->current_header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL); + zend_hash_str_add_ptr(&client->request.headers, header_name, client->current_header_name_len, value); + zend_hash_str_add_ptr(&client->request.headers_original_case, client->current_header_name, client->current_header_name_len, value); efree(header_name); } @@ -1833,7 +1833,7 @@ static size_t php_cli_server_client_send_through(php_cli_server_client *client, static void php_cli_server_client_populate_request_info(const php_cli_server_client *client, sapi_request_info *request_info) /* {{{ */ { - char **val; + char *val; request_info->request_method = php_http_method_str(client->request.request_method); request_info->proto_num = client->request.protocol_version; @@ -1842,8 +1842,8 @@ static void php_cli_server_client_populate_request_info(const php_cli_server_cli request_info->query_string = client->request.query_string; request_info->content_length = client->request.content_len; request_info->auth_user = request_info->auth_password = request_info->auth_digest = NULL; - if (SUCCESS == zend_hash_find(&client->request.headers, "content-type", sizeof("content-type"), (void**)&val)) { - request_info->content_type = *val; + if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "content-type", sizeof("content-type")-1))) { + request_info->content_type = val; } } /* }}} */ @@ -1903,8 +1903,7 @@ static void php_cli_server_close_connection(php_cli_server *server, php_cli_serv static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server_client *client, int status TSRMLS_DC) /* {{{ */ { - char *escaped_request_uri = NULL; - size_t escaped_request_uri_len; + zend_string *escaped_request_uri = NULL; const char *status_string = get_status_string(status); const char *content_template = get_template_string(status); char *errstr = get_last_error(); @@ -1913,7 +1912,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_content_sender_ctor(&client->content_sender); client->content_sender_initialized = 1; - escaped_request_uri = php_escape_html_entities_ex((unsigned char *)client->request.request_uri, client->request.request_uri_len, &escaped_request_uri_len, 0, ENT_QUOTES, NULL, 0 TSRMLS_CC); + escaped_request_uri = php_escape_html_entities_ex((unsigned char *)client->request.request_uri, client->request.request_uri_len, 0, ENT_QUOTES, NULL, 0 TSRMLS_CC); { static const char prologue_template[] = "<!doctype html><html><head><title>%d %s</title>"; @@ -1941,7 +1940,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } { - php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(strlen(content_template) + escaped_request_uri_len + 3 + strlen(status_string) + 1); + php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(strlen(content_template) + escaped_request_uri->len + 3 + strlen(status_string) + 1); if (!chunk) { goto fail; } @@ -2078,10 +2077,10 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv /* }}} */ static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */ - char **auth; + char *auth; php_cli_server_client_populate_request_info(client, &SG(request_info)); - if (SUCCESS == zend_hash_find(&client->request.headers, "authorization", sizeof("authorization"), (void**)&auth)) { - php_handle_auth_data(*auth TSRMLS_CC); + if (NULL != (auth = zend_hash_str_find_ptr(&client->request.headers, "authorization", sizeof("authorization")-1))) { + php_handle_auth_data(auth TSRMLS_CC); } SG(sapi_headers).http_response_code = 200; if (FAILURE == php_request_startup(TSRMLS_C)) { @@ -2123,10 +2122,10 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server zfd.opened_path = NULL; zend_try { - zval *retval = NULL; + zval retval; if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, &retval, 1, &zfd)) { - if (retval) { - decline = Z_TYPE_P(retval) == IS_BOOL && !Z_LVAL_P(retval); + if (Z_TYPE(retval) != IS_UNDEF) { + decline = Z_TYPE(retval) == IS_BOOL && !Z_LVAL(retval); zval_ptr_dtor(&retval); } } else { @@ -2218,12 +2217,14 @@ static void php_cli_server_dtor(php_cli_server *server TSRMLS_DC) /* {{{ */ } } /* }}} */ -static void php_cli_server_client_dtor_wrapper(php_cli_server_client **p) /* {{{ */ +static void php_cli_server_client_dtor_wrapper(zval *zv) /* {{{ */ { - closesocket((*p)->sock); - php_cli_server_poller_remove(&(*p)->server->poller, POLLIN | POLLOUT, (*p)->sock); - php_cli_server_client_dtor(*p); - pefree(*p, 1); + php_cli_server_client *p = Z_PTR_P(zv); + + closesocket(p->sock); + php_cli_server_poller_remove(&p->server->poller, POLLIN | POLLOUT, p->sock); + php_cli_server_client_dtor(p); + pefree(p, 1); } /* }}} */ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const char *document_root, const char *router TSRMLS_DC) /* {{{ */ @@ -2294,7 +2295,7 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c server->host = host; server->port = port; - zend_hash_init(&server->clients, 0, NULL, (void(*)(void*))php_cli_server_client_dtor_wrapper, 1); + zend_hash_init(&server->clients, 0, NULL, php_cli_server_client_dtor_wrapper, 1); { size_t document_root_len = strlen(document_root); @@ -2438,16 +2439,16 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, int fd, i #ifdef DEBUG php_cli_server_logf("%s Accepted" TSRMLS_CC, client->addr_str); #endif - zend_hash_index_update(&server->clients, client_sock, &client, sizeof(client), NULL); + zend_hash_index_update_ptr(&server->clients, client_sock, client); php_cli_server_recv_event_read_request(server, client TSRMLS_CC); } else { - php_cli_server_client **client; - if (SUCCESS == zend_hash_index_find(&server->clients, fd, (void **)&client)) { + php_cli_server_client *client; + if (NULL != (client = zend_hash_index_find_ptr(&server->clients, fd))) { if (event & POLLIN) { - params->rhandler(server, *client TSRMLS_CC); + params->rhandler(server, client TSRMLS_CC); } if (event & POLLOUT) { - params->whandler(server, *client TSRMLS_CC); + params->whandler(server, client TSRMLS_CC); } } } |