Bucket *f = (Bucket *) a;
Bucket *s = (Bucket *) b;
- return strcasecmp(((zend_module_entry *)f->xData)->name,
- ((zend_module_entry *)s->xData)->name);
+ return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name,
+ ((zend_module_entry *)Z_PTR(s->val))->name);
}
/* }}} */
static void print_modules(TSRMLS_D) /* {{{ */
{
HashTable sorted_registry;
- zend_module_entry tmp;
zend_hash_init(&sorted_registry, 50, NULL, NULL, 1);
- zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
+//??? zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
+ zend_hash_copy(&sorted_registry, &module_registry, NULL);
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
zend_hash_apply(&sorted_registry, (apply_func_t) print_module_info TSRMLS_CC);
zend_hash_destroy(&sorted_registry);
/* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */
#define INI_DEFAULT(name,value)\
- Z_SET_REFCOUNT(tmp, 0);\
- Z_UNSET_ISREF(tmp); \
- ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0);\
- zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL);\
+ ZVAL_STR(&tmp, STR_INIT(value, sizeof(value)-1, 1));\
+ zend_hash_str_update(configuration_hash, name, sizeof(name)-1, &tmp);\
static void sapi_cli_ini_defaults(HashTable *configuration_hash)
{
static void cli_register_file_handles(TSRMLS_D) /* {{{ */
{
- zval *zin, *zout, *zerr;
+ zval zin, zout, zerr;
php_stream *s_in, *s_out, *s_err;
php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL;
zend_constant ic, oc, ec;
- MAKE_STD_ZVAL(zin);
- MAKE_STD_ZVAL(zout);
- MAKE_STD_ZVAL(zerr);
-
s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in);
s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out);
s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err);
if (s_in==NULL || s_out==NULL || s_err==NULL) {
- FREE_ZVAL(zin);
- FREE_ZVAL(zout);
- FREE_ZVAL(zerr);
if (s_in) php_stream_close(s_in);
if (s_out) php_stream_close(s_out);
if (s_err) php_stream_close(s_err);
s_in_process = s_in;
- php_stream_to_zval(s_in, zin);
- php_stream_to_zval(s_out, zout);
- php_stream_to_zval(s_err, zerr);
+ php_stream_to_zval(s_in, &zin);
+ php_stream_to_zval(s_out, &zout);
+ php_stream_to_zval(s_err, &zerr);
- ic.value = *zin;
+ ZVAL_COPY_VALUE(&ic.value, &zin);
ic.flags = CONST_CS;
- ic.name = zend_strndup(ZEND_STRL("STDIN"));
- ic.name_len = sizeof("STDIN");
+ ic.name = STR_INIT("STDIN", sizeof("STDIN")-1, 1);
ic.module_number = 0;
zend_register_constant(&ic TSRMLS_CC);
- oc.value = *zout;
+ ZVAL_COPY_VALUE(&oc.value, &zout);
oc.flags = CONST_CS;
- oc.name = zend_strndup(ZEND_STRL("STDOUT"));
- oc.name_len = sizeof("STDOUT");
+ oc.name = STR_INIT("STDOUT", sizeof("STDOUT")-1, 1);
oc.module_number = 0;
zend_register_constant(&oc TSRMLS_CC);
- ec.value = *zerr;
+ ZVAL_COPY_VALUE(&ec.value, &zerr);
ec.flags = CONST_CS;
- ec.name = zend_strndup(ZEND_STRL("STDERR"));
- ec.name_len = sizeof("STDERR");
+ ec.name = STR_INIT("STDERR", sizeof("STDERR")-1, 1);
ec.module_number = 0;
zend_register_constant(&ec TSRMLS_CC);
-
- FREE_ZVAL(zin);
- FREE_ZVAL(zout);
- FREE_ZVAL(zerr);
}
/* }}} */
int lineno = 0;
const char *param_error=NULL;
int hide_argv = 0;
+ zend_string *key;
zend_try {
CG(in_compilation) = 0; /* not initialized but needed for several options */
- EG(uninitialized_zval_ptr) = NULL;
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (c) {
}
}
- zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
+ key = STR_INIT("_SERVER", sizeof("_SERVER")-1, 0);
+ zend_is_auto_global(key TSRMLS_CC);
+ STR_RELEASE(key);
PG(during_request_startup) = 0;
switch (behavior) {
{
char *input;
size_t len, index = 0;
- zval *argn, *argi;
+ zval argn, argi;
cli_register_file_handles(TSRMLS_C);
if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1 TSRMLS_CC) == FAILURE) {
exit_status=254;
}
- ALLOC_ZVAL(argi);
- Z_TYPE_P(argi) = IS_LONG;
- Z_LVAL_P(argi) = index;
- INIT_PZVAL(argi);
- zend_hash_update(&EG(symbol_table), "argi", sizeof("argi"), &argi, sizeof(zval *), NULL);
+ ZVAL_LONG(&argi, index);
+ zend_hash_str_update(&EG(symbol_table).ht, "argi", sizeof("argi")-1, &argi);
while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) {
len = strlen(input);
while (len-- && (input[len]=='\n' || input[len]=='\r')) {
input[len] = '\0';
}
- ALLOC_ZVAL(argn);
- Z_TYPE_P(argn) = IS_STRING;
- Z_STRLEN_P(argn) = ++len;
- Z_STRVAL_P(argn) = estrndup(input, len);
- INIT_PZVAL(argn);
- zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn, sizeof(zval *), NULL);
- Z_LVAL_P(argi) = ++index;
+ ZVAL_STRINGL(&argn, input, len);
+ zend_hash_str_update(&EG(symbol_table).ht, "argn", sizeof("argn")-1, &argn);
+ Z_LVAL(argi) = ++index;
if (exec_run) {
if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1 TSRMLS_CC) == FAILURE) {
exit_status=254;
}
#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() /* {{{ */
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);
}
}
{
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) {
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);
}
}
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) /* {{{ */
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 {
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;
}
{
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);
}
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;
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;
}
} /* }}} */
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();
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>";
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;
}
/* }}} */
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)) {
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 {
}
} /* }}} */
-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) /* {{{ */
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);
#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);
}
}
}