void zephir_concat_vvs(zval **result, zval *op1, zval *op2, const char *op3, zend_uint op3_len, int self_var TSRMLS_DC){ zval result_copy, op1_copy, op2_copy; int use_copy = 0, use_copy1 = 0, use_copy2 = 0; uint offset = 0, length; if (Z_TYPE_P(op1) != IS_STRING) { zend_make_printable_zval(op1, &op1_copy, &use_copy1); if (use_copy1) { op1 = &op1_copy; } } if (Z_TYPE_P(op2) != IS_STRING) { zend_make_printable_zval(op2, &op2_copy, &use_copy2); if (use_copy2) { op2 = &op2_copy; } } length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2) + op3_len; if (self_var) { if (Z_TYPE_PP(result) != IS_STRING) { zend_make_printable_zval(*result, &result_copy, &use_copy); if (use_copy) { ZEPHIR_CPY_WRT_CTOR(*result, (&result_copy)); } } offset = Z_STRLEN_PP(result); length += offset; Z_STRVAL_PP(result) = (char *) erealloc(Z_STRVAL_PP(result), length + 1); } else { Z_STRVAL_PP(result) = (char *) emalloc(length + 1); } memcpy(Z_STRVAL_PP(result) + offset, Z_STRVAL_P(op1), Z_STRLEN_P(op1)); memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2)); memcpy(Z_STRVAL_PP(result) + offset + Z_STRLEN_P(op1) + Z_STRLEN_P(op2), op3, op3_len); Z_STRVAL_PP(result)[length] = 0; Z_TYPE_PP(result) = IS_STRING; Z_STRLEN_PP(result) = length; if (use_copy1) { zval_dtor(op1); } if (use_copy2) { zval_dtor(op2); } if (use_copy) { zval_dtor(&result_copy); } }
static int accel_file_in_cache(INTERNAL_FUNCTION_PARAMETERS) { zval **zfilename; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, &zfilename) == FAILURE || Z_TYPE_PP(zfilename) != IS_STRING || Z_STRLEN_PP(zfilename) == 0) { return 0; } return filename_is_in_cache(Z_STRVAL_PP(zfilename), Z_STRLEN_PP(zfilename) TSRMLS_CC); }
/** * Checks a plain text password and its hash version to check if the password matches * * @param string $password * @param string $passwordHash * @param int $maxPasswordLength * @return boolean */ PHP_METHOD(Phalcon_Security, checkHash){ zval **password, **password_hash, **max_pass_length = NULL, *hash; zval* params[2]; int check = 0; phalcon_fetch_params_ex(2, 1, &password, &password_hash, &max_pass_length); PHALCON_ENSURE_IS_STRING(password); if (max_pass_length) { PHALCON_ENSURE_IS_LONG(max_pass_length); if (Z_LVAL_PP(max_pass_length) > 0 && Z_STRLEN_PP(password) > Z_LVAL_PP(max_pass_length)) { RETURN_FALSE; } } params[0] = *password; params[1] = *password_hash; ALLOC_INIT_ZVAL(hash); phalcon_call_func_params_w(hash, SL("crypt"), 2, params TSRMLS_CC); if (UNEXPECTED(EG(exception) != NULL)) { zval_ptr_dtor(&hash); RETURN_NULL(); } if (UNEXPECTED(Z_TYPE_P(hash) != IS_STRING)) { convert_to_string(hash); } if (Z_STRLEN_P(hash) == Z_STRLEN_PP(password_hash)) { int n = Z_STRLEN_P(hash); char *h1 = Z_STRVAL_P(hash); char *h2 = Z_STRVAL_PP(password_hash); while (n) { check |= ((unsigned int)*h1) ^ ((unsigned int)*h2); ++h1; ++h2; --n; } zval_ptr_dtor(&hash); RETURN_BOOL(check == 0); } zval_ptr_dtor(&hash); RETURN_FALSE; }
static int websocket_handshake(http_client *client) { //HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: %s\r\nSec-WebSocket-Version: %s\r\nKeepAlive: off\r\nContent-Length: 0\r\nServer: ZWebSocket\r\n TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); zval *header = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("header"), 1 TSRMLS_CC); HashTable *ht = Z_ARRVAL_P(header); zval **pData; if(zend_hash_find(ht, ZEND_STRS("sec-websocket-key") , (void **) &pData) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "header no sec-websocket-key"); return SW_ERR; } convert_to_string(*pData); // swTrace("key: %s len:%d\n", Z_STRVAL_PP(pData), Z_STRLEN_PP(pData)); swString *buf = swString_new(256); swString_append_ptr(buf, ZEND_STRL("HTTP/1.1 101 Switching Protocols\r\n")); swString_append_ptr(buf, ZEND_STRL("Upgrade: websocket\r\nConnection: Upgrade\r\n")); swString *shaBuf = swString_new(Z_STRLEN_PP(pData)+36); swString_append_ptr(shaBuf, Z_STRVAL_PP(pData), Z_STRLEN_PP(pData)); swString_append_ptr(shaBuf, ZEND_STRL(SW_WEBSOCKET_GUID)); char data_str[20]; // bzero(data_str, sizeof(data_str)); // swTrace("sha1 start:%s\n", shaBuf->str); sha1(shaBuf->str, (unsigned char *) data_str); char encoded_value[50]; bzero(encoded_value, sizeof(encoded_value)); // swTrace("base64_encode start:%d\n", sizeof(data_str)); swBase64_encode((unsigned char *) data_str, 20, encoded_value); // swTrace("base64_encode end:%s %d %d\n", encoded_value, encoded_len, strlen(encoded_value)); char _buf[128]; int n = 0; n = snprintf(_buf, strlen(encoded_value)+25, "Sec-WebSocket-Accept: %s\r\n", encoded_value); // efree(data_str); // efree(encoded_value); swString_free(shaBuf); // swTrace("accept value: %s\n", _buf); swString_append_ptr(buf, _buf, n); swString_append_ptr(buf, ZEND_STRL("Sec-WebSocket-Version: 13\r\n")); swString_append_ptr(buf, ZEND_STRL("Server: swoole-websocket\r\n\r\n")); swTrace("websocket header len:%zd\n%s \n", buf->length, buf->str); int ret = swServer_tcp_send(SwooleG.serv, client->fd, buf->str, buf->length); swString_free(buf); // swTrace("handshake send: %d lenght: %d\n", client->fd, ret); return ret; }
/** {{{ int yaf_application_is_module_name(char *name, int len TSRMLS_DC) * 判断名称是否是已经注册了的module的名称 */ int yaf_application_is_module_name(char *name, int len TSRMLS_DC) { zval *modules, **ppzval; HashTable *ht; yaf_application_t *app; /* 获取类的实例,$app = self::$_app */ app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC); if (!app || Z_TYPE_P(app) != IS_OBJECT) { return 0; } /* $modules = $this->_modules */ modules = zend_read_property(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_MODULES), 1 TSRMLS_CC); if (!modules || Z_TYPE_P(modules) != IS_ARRAY) { return 0; } /* 检测name是否在$this->_modules数组中,在就返回1,不在返回0 */ ht = Z_ARRVAL_P(modules); zend_hash_internal_pointer_reset(ht); while (zend_hash_get_current_data(ht, (void **)&ppzval) == SUCCESS) { if (Z_TYPE_PP(ppzval) == IS_STRING && Z_STRLEN_PP(ppzval) == len && strncasecmp(Z_STRVAL_PP(ppzval), name, len) == 0) { return 1; } zend_hash_move_forward(ht); } return 0; }
/** {{{ int yaf_application_is_module_name(char *name, int len TSRMLS_DC) */ int yaf_application_is_module_name(char *name, int len TSRMLS_DC) { zval *modules, **ppzval; HashTable *ht; yaf_application_t *app; app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC); if (Z_TYPE_P(app) != IS_OBJECT) { return 0; } modules = zend_read_property(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_MODULES), 1 TSRMLS_CC); if (Z_TYPE_P(modules) != IS_ARRAY) { return 0; } ht = Z_ARRVAL_P(modules); zend_hash_internal_pointer_reset(ht); while (zend_hash_get_current_data(ht, (void **)&ppzval) == SUCCESS) { if (Z_STRLEN_PP(ppzval) == len && strncasecmp(Z_STRVAL_PP(ppzval), name, len) == 0) { return 1; } zend_hash_move_forward(ht); } return 0; }
/** * Reads meta-data from files * * @param string $key * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ zval **key, *meta_data_dir, *virtual_key; zval *path, *data = NULL; phalcon_fetch_params_ex(1, 0, &key); PHALCON_ENSURE_IS_STRING(key); PHALCON_MM_GROW(); meta_data_dir = phalcon_fetch_nproperty_this(this_ptr, SL("_metaDataDir"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path_ex(virtual_key, Z_STRVAL_PP(key), Z_STRLEN_PP(key), '_' TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { RETURN_MM_ON_FAILURE(phalcon_require_ret(&data, Z_STRVAL_P(path) TSRMLS_CC)); RETVAL_ZVAL(data, 1, 1); } PHALCON_MM_RESTORE(); }
zval* air_arr_del_index_el(zval *arr) { HashTable *ht = Z_ARRVAL_P(arr); zval *tmp; MAKE_STD_ZVAL(tmp); array_init(tmp); for( zend_hash_internal_pointer_reset(ht); zend_hash_has_more_elements(ht) == SUCCESS; zend_hash_move_forward(ht) ){ int type; ulong idx; char *key; uint key_len; zval **tmp_data; type = zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, NULL); if(type == HASH_KEY_IS_STRING){ if(zend_hash_get_current_data(ht, (void**)&tmp_data) != FAILURE) { add_assoc_stringl_ex(tmp, key, key_len, Z_STRVAL_PP(tmp_data), Z_STRLEN_PP(tmp_data), 1); } } } return tmp; }
/* {{{ php_tmpl_parse_check_memory */ inline void php_tmpl_parse_check_memory(t_template* tmpl, HashPosition *dup_tag_pos, t_tmpl_tag* tag, uint tag_mod, zval** iteration, zval** dest, uint* offset) { zval **dup_ztag; t_tmpl_tag *dup_tag; if(NULL == *dup_tag_pos || !zend_hash_num_elements(Z_ARRVAL_P(tmpl->dup_tag))) return; /* The next line has been added to avoid skiping of duplicate tags in some circumstances. This is sort of a dirty fix and needs to be optimized for speed. */ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmpl->dup_tag), dup_tag_pos); do { if(FAILURE == zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpl->dup_tag), (void*)&dup_ztag, dup_tag_pos)) break; dup_tag = Z_TMPL_TAG(dup_ztag); if(*offset > dup_tag->loff) continue; if(TMPL_TAG == tag_mod) { if(dup_tag->ctx != tag->ctx && dup_tag->loff < tag->loff) continue; if(dup_tag->ctx != tag->ctx || dup_tag->loff >= tag->loff) break; } else { if(dup_tag->ctx != tag && dup_tag->loff < tag->roff) continue; if(dup_tag->ctx != tag || dup_tag->loff > tag->roff) break; } TMPL_PARSE_DEST_ADD(*offset, dup_tag->loff - *offset); *offset = dup_tag->roff; if(FAILURE == zend_hash_find(Z_ARRVAL_PP(iteration), ZV(dup_tag->name), ZL(dup_tag->name)+1, (void*)&dup_ztag)) continue; TMPL_PARSE_DEST_ADD(Z_STRVAL_PP(dup_ztag)-Z_STRVAL_P(tmpl->original), Z_STRLEN_PP(dup_ztag)); } while(SUCCESS == zend_hash_move_forward_ex(Z_ARRVAL_P(tmpl->dup_tag), dup_tag_pos)); }
static void accel_file_in_cache(int type, INTERNAL_FUNCTION_PARAMETERS) { char *filename; int filename_len; #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO zval **zfilename; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zfilename) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(zfilename); filename = Z_STRVAL_PP(zfilename); filename_len = Z_STRLEN_PP(zfilename); #elif ZEND_EXTENSION_API_NO == PHP_5_3_X_API_NO if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { return; } #else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { return; } #endif if(filename_len > 0) { if(filename_is_in_cache(filename, filename_len TSRMLS_CC)) { RETURN_TRUE; } } php_stat(filename, filename_len, type, return_value TSRMLS_CC); }
/** * Writes the meta-data to files * * @param string $key * @param array $data */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ zval **key, **data, *meta_data_dir, *virtual_key; zval *path, *php_export, *status; smart_str exp = { NULL, 0, 0 }; phalcon_fetch_params_ex(2, 0, &key, &data); PHALCON_MM_GROW(); meta_data_dir = phalcon_fetch_nproperty_this(this_ptr, SL("_metaDataDir"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path_ex(virtual_key, Z_STRVAL_PP(key), Z_STRLEN_PP(key), '_' TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); smart_str_appends(&exp, "<?php return "); php_var_export_ex(data, 0, &exp TSRMLS_CC); smart_str_appendc(&exp, ';'); smart_str_0(&exp); PHALCON_INIT_VAR(php_export); ZVAL_STRINGL(php_export, exp.c, exp.len, 0); PHALCON_INIT_VAR(status); phalcon_file_put_contents(status, path, php_export TSRMLS_CC); if (PHALCON_IS_FALSE(status)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Meta-Data directory cannot be written"); return; } PHALCON_MM_RESTORE(); }
/** * This function allocates a persistent zval and copy the string with pestrndup (persistent). */ void MAKE_PZVAL_STR(zval** zdata, zval * zstr) { *zdata = pemalloc(sizeof(zval), 1); Z_TYPE_PP(zdata) = Z_TYPE_P(zstr); Z_STRVAL_PP(zdata) = pestrndup(Z_STRVAL_P(zstr), Z_STRLEN_P(zstr), 1); Z_STRLEN_PP(zdata) = Z_STRLEN_P(zstr); }
/** {{{ int yaf_response_alter_header(yaf_response_t *response, char *name, uint name_len, char *value, long value_len, int flag TSRMLS_DC) */ int yaf_response_alter_header(yaf_response_t *response, char *name, uint name_len, char *value, long value_len, uint rep TSRMLS_DC) { zval *z_headers, **ppzval; char *oheader; if (!name_len) { return 1; } z_headers = zend_read_property(yaf_response_ce, response, ZEND_STRL(YAF_RESPONSE_PROPERTY_NAME_HEADER), 1 TSRMLS_CC); if (zend_hash_find(Z_ARRVAL_P(z_headers), name, name_len + 1, (void **)&ppzval) == FAILURE) { add_assoc_stringl_ex(z_headers, name, name_len + 1, value, value_len, 1); return 1; } oheader = Z_STRVAL_PP(ppzval); if (rep) { ZVAL_STRINGL(*ppzval, value, value_len, 1); } else { Z_STRLEN_PP(ppzval) = spprintf(&Z_STRVAL_PP(ppzval), 0, "%s, %s", oheader, value); } efree(oheader); return 1; }
ZEND_METHOD(Vedis, msetnx) { zval **val, *members; int key_len; HashPosition pos; size_t n; VEDIS_PARAM(MSETNX, 6); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &members) == FAILURE) { return; } VEDIS_SELF(intern); n = zend_hash_num_elements(HASH_OF(members)); if (n == 0) { RETURN_FALSE; } VEDIS_ARGS_INIT(n * 2); zend_hash_internal_pointer_reset_ex(HASH_OF(members), &pos); while (zend_hash_get_current_data_ex(HASH_OF(members), (void **)&val, &pos) == SUCCESS) { char *str_key; uint str_key_len; long num_key; int flags; flags = zend_hash_get_current_key_ex(HASH_OF(members), &str_key, &str_key_len, &num_key, 0, &pos); if (flags == HASH_KEY_NON_EXISTANT) { break; } if (Z_TYPE_PP(val) != IS_STRING) { convert_to_string(*val); } if (flags == HASH_KEY_IS_STRING) { VEDIS_ARGS_STRING(str_key, str_key_len - 1); } else { smart_str buf = {0}; smart_str_append_long(&buf, num_key); smart_str_0(&buf); VEDIS_ARGS_STRING(buf.c, buf.len); smart_str_free(&buf); } VEDIS_ARGS_STRING(Z_STRVAL_PP(val), Z_STRLEN_PP(val)); zend_hash_move_forward_ex(HASH_OF(members), &pos); } VEDIS_ARGS_EXEC(RETURN_FALSE); VEDIS_RETURN_BOOL(); }
/** * This functions is given an array of strings and returns the length of * the longest one. If there are other kind of items, it returns -1 */ int array_max_strlen( const HashTable* array ) { zval **entry; /* pointer to array entry */ HashPosition pos; /* hash iterator */ int max_length = 0; zend_hash_internal_pointer_reset_ex(array, &pos); while (zend_hash_get_current_data_ex(array, (void **)&entry, &pos) == SUCCESS) { if (Z_TYPE_PP(entry) != IS_STRING) { return -1; } if (Z_STRLEN_PP(entry) > max_length) { max_length = Z_STRLEN_PP(entry); } zend_hash_move_forward_ex(array, &pos); } return max_length; }
static int passwd_callback(char *buf, int num, int verify, void *data) /* {{{ */ { stream *stream = (stream *)data; zval **val = NULL; char *passphrase = NULL; /* TODO: could expand this to make a callback into Lua user-space */ GET_VER_OPT_STRING("passphrase", passphrase); if (passphrase) { if (Z_STRLEN_PP(val) < num - 1) { memcpy(buf, Z_STRVAL_PP(val), Z_STRLEN_PP(val)+1); return Z_STRLEN_PP(val); } } return 0; }
RedisArray* ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC) { int i, host_len, id; int count = zend_hash_num_elements(hosts); char *host, *p; short port; zval **zpData, z_cons, z_ret; RedisSock *redis_sock = NULL; /* function calls on the Redis object */ ZVAL_STRING(&z_cons, "__construct", 0); /* init connections */ for(i = 0; i < count; ++i) { if(FAILURE == zend_hash_quick_find(hosts, NULL, 0, i, (void**)&zpData)) { efree(ra); return NULL; } ra->hosts[i] = estrdup(Z_STRVAL_PP(zpData)); /* default values */ host = Z_STRVAL_PP(zpData); host_len = Z_STRLEN_PP(zpData); port = 6379; if((p = strchr(host, ':'))) { /* found port */ host_len = p - host; port = (short)atoi(p+1); } /* create Redis object */ MAKE_STD_ZVAL(ra->redis[i]); object_init_ex(ra->redis[i], redis_ce); INIT_PZVAL(ra->redis[i]); call_user_function(&redis_ce->function_table, &ra->redis[i], &z_cons, &z_ret, 0, NULL TSRMLS_CC); /* create socket */ redis_sock = redis_sock_create(host, host_len, port, 0, 0, NULL, retry_interval); /* TODO: persistence? */ /* connect */ redis_sock_server_open(redis_sock, 1 TSRMLS_CC); /* attach */ #if PHP_VERSION_ID >= 50400 id = zend_list_insert(redis_sock, le_redis_sock TSRMLS_CC); #else id = zend_list_insert(redis_sock, le_redis_sock); #endif add_property_resource(ra->redis[i], "socket", id); } return ra; }
PHP_METHOD(MIME, load) { zval *array, *arg, retval; /* Fetch allowHEAD */ MAKE_STD_ZVAL(array); array_init_size(array, 2); add_next_index_stringl(array, "Pancake\\Config", sizeof("Pancake\\Config") - 1, 1); add_next_index_stringl(array, "get", 3, 1); MAKE_STD_ZVAL(arg); Z_TYPE_P(arg) = IS_STRING; Z_STRLEN_P(arg) = 4; Z_STRVAL_P(arg) = estrndup("mime", 4); call_user_function(CG(function_table), NULL, array, &retval, 1, &arg TSRMLS_CC); if(Z_TYPE(retval) != IS_ARRAY) { zend_error(E_ERROR, "Bad MIME type array - Please check Pancake MIME type configuration"); } ALLOC_HASHTABLE(PANCAKE_GLOBALS(mimeTable)); zend_hash_init(PANCAKE_GLOBALS(mimeTable), 0, NULL, ZVAL_PTR_DTOR, 0); zval **data, **ext; char *key; for(zend_hash_internal_pointer_reset(Z_ARRVAL(retval)); zend_hash_get_current_data(Z_ARRVAL(retval), (void**) &data) == SUCCESS && zend_hash_get_current_key(Z_ARRVAL(retval), &key, NULL, 0) == HASH_KEY_IS_STRING; zend_hash_move_forward(Z_ARRVAL(retval))) { for(zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data)); zend_hash_get_current_data(Z_ARRVAL_PP(data), (void**) &ext) == SUCCESS; zend_hash_move_forward(Z_ARRVAL_PP(data))) { zval *zkey; MAKE_STD_ZVAL(zkey); Z_TYPE_P(zkey) = IS_STRING; Z_STRLEN_P(zkey) = strlen(key); Z_STRVAL_P(zkey) = estrndup(key, Z_STRLEN_P(zkey)); zend_hash_add(PANCAKE_GLOBALS(mimeTable), Z_STRVAL_PP(ext), Z_STRLEN_PP(ext), (void*) &zkey, sizeof(zval*), NULL); } } MAKE_STD_ZVAL(PANCAKE_GLOBALS(defaultMimeType)); Z_TYPE_P(PANCAKE_GLOBALS(defaultMimeType)) = IS_STRING; Z_STRLEN_P(PANCAKE_GLOBALS(defaultMimeType)) = sizeof("application/octet-stream") - 1; Z_STRVAL_P(PANCAKE_GLOBALS(defaultMimeType)) = estrndup("application/octet-stream", sizeof("application/octet-stream") - 1); free: zval_dtor(&retval); zval_ptr_dtor(&array); zval_ptr_dtor(&arg); }
/*=========================================================================================================== NAME string_append - Fast string concatenation. PROTOTYPE string_append ( &$value, ... ) ; DESCRIPTION Appends series of values to the specified string. PARAMETERS $value (string) - String where to append values. $... (mixed) - Any argument that can be converted to a string and appended to $value. NOTE This code is theorically faster than the inline string-catenation operator, except that calling a PHP_FUNCTION() has a cost. When catenating 100 000 times a set of value takes 170ms using the catenation operator, it takes 615ms for string_append(), 535 of them being consumed just by calling the PHP_FUNCTION(). *===========================================================================================================*/ THRAK_API zend_bool internal_string_append ( zval * z_string, int argc, zval ** argv, char ** result, int * result_length ) { char * data, * p ; int size = Z_STRLEN_P ( z_string ) ; int i ; // Compute the size needed to hold all the appended strings for ( i = 0 ; i < argc ; i ++ ) { if ( Z_ISREF_P ( argv [i] ) ) SEPARATE_ZVAL ( & argv [i] ) ; convert_to_string ( argv [i] ) ; size += Z_STRLEN_P ( argv [i] ) ; } // Allocate enough memory for it (just reallocate existing data, this will avoid to copy the appended variable // initial value) data = p = erealloc ( Z_STRVAL_P ( z_string ), size + 1 ) ; if ( data == NULL ) return ( 0 ) ; // Point at the end of initial value p += Z_STRLEN_P ( z_string ) ; for ( i = 0 ; i < argc ; i ++, argv ++ ) { memcpy ( p, Z_STRVAL_PP ( argv ), Z_STRLEN_PP ( argv ) ) ; p += Z_STRLEN_PP ( argv ) ; } /* Useless but makes me happy */ * p = 0 ; // Give the resulting string to the caller * result = data ; * result_length = size ; return ( 1 ) ; }
/* {{{ php_tmpl_set */ int php_tmpl_set(t_template* tmpl, zval* path, zval** data) { zval **iteration, *cp_data, **ztag; t_tmpl_tag *tag; char *p; if(FAILURE == zend_hash_find(Z_ARRVAL_P(tmpl->tags), ZV(path), ZL(path)+1, (void*)&ztag)) { /* php_error(E_NOTICE, "Can't set value for tag/context \"%s\" which doesn't exist", ZV(path)); */ return FAILURE; } tag = Z_TMPL_TAG(ztag); if(TMPL_TAG == tag->typ) { if((iteration = (zval**)php_tmpl_get_iteration(tmpl, path, TMPL_ITERATION_CURRENT)) == NULL) { return FAILURE; } } else { for(p = ZV(path)+ZL(path); p >= ZV(path) && *p != '/'; p--); *(p > ZV(path) ? p++ : ++p) = 0; ZL(path) = strlen(ZV(path)); if((iteration = (zval**)php_tmpl_get_iteration(tmpl, path, TMPL_ITERATION_CURRENT)) == NULL) { return FAILURE; } } convert_to_string_ex(data); MAKE_STD_ZVAL(cp_data); ZVAL_STRINGL(cp_data, Z_STRVAL_PP(data), Z_STRLEN_PP(data), 1); if(SUCCESS == zend_hash_find(Z_ARRVAL_PP(iteration), ZV(tag->name), ZL(tag->name)+1, (void*)&ztag)) { if(IS_ARRAY == Z_TYPE_PP(ztag)) { /* MEMORY LEAK CAUSED BY THE NEXT LINE !!! */ zend_hash_del(Z_ARRVAL_PP(iteration), ZV(tag->name), ZL(tag->name)+1); } else { tmpl->size -= (Z_STRLEN_PP(ztag) * tag->tag_num); } } zend_hash_update(Z_ARRVAL_PP(iteration), ZV(tag->name), ZL(tag->name)+1, (void*)&cp_data, sizeof(zval**), NULL); tmpl->size += (ZL(cp_data) * tag->tag_num); return SUCCESS; }
/** * Parses a raw doc block returning the annotations found * * @param string $docBlock * @param string $file * @param int $line * @return array */ PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock) { zval **doc_block, **file = NULL, **line = NULL; phalcon_fetch_params_ex(3, 0, &doc_block, &file, &line); PHALCON_ENSURE_IS_STRING(doc_block); PHALCON_ENSURE_IS_STRING(file); PHALCON_ENSURE_IS_LONG(line); RETURN_ON_FAILURE(phannot_parse_annotations(return_value, Z_STRVAL_PP(doc_block), Z_STRLEN_PP(doc_block), Z_STRVAL_PP(file), Z_LVAL_PP(line) TSRMLS_CC)); }
/* {{{ proto int owsrequest.loadParams() Initializes the OWSRequest object from the cgi environment variables REQUEST_METHOD, QUERY_STRING and HTTP_COOKIE. Returns the number of name/value pairs collected. */ PHP_METHOD(OWSRequestObj, loadParams) { zval *zobj = getThis(); zval **val; php_owsrequest_object *php_owsrequest; void *thread_context; #ifdef ZTS thread_context = (void*)TSRMLS_C; #else thread_context = NULL; #endif //PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { //PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } //PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_owsrequest = (php_owsrequest_object *) zend_object_store_get_object(zobj TSRMLS_CC); if ( (STRING_EQUAL(sapi_module.name,"cli")) || (STRING_EQUAL(sapi_module.name,"cgi")) || (STRING_EQUAL(sapi_module.name,"cgi-fcgi")) ) { cgirequestObj_loadParams(php_owsrequest->cgirequest, NULL, NULL, 0, thread_context); } else { // check if we have input data for GET method if (SG(request_info).request_method && STRING_EQUAL(SG(request_info).request_method, "GET")) { zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); if ( PG(http_globals)[TRACK_VARS_SERVER] && (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "QUERY_STRING", sizeof("QUERY_STRING"), (void **) &val) == SUCCESS) && (Z_TYPE_PP(val) == IS_STRING) && (Z_STRLEN_PP(val) > 0) ) { cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv, NULL, 0, thread_context); } } else { cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, thread_context); } } RETURN_LONG(php_owsrequest->cgirequest->NumParams); }
static void SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) { swig_object_wrapper *value=NULL; /* * First test for Null pointers. Return those as PHP native NULL */ if (!ptr ) { ZVAL_NULL(z); return; } if (type->clientdata) { if (! (*(int *)(type->clientdata))) zend_error(E_ERROR, "Type: %s failed to register with zend",type->name); value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); value->ptr=ptr; value->newobject=newobject; if (newobject <= 1) { /* Just register the pointer as a resource. */ ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata)); } else { /* * Wrap the resource in an object, the resource will be accessible * via the "_cPtr" member. This is currently only used by * directorin typemaps. */ value->newobject = 0; zval *resource; MAKE_STD_ZVAL(resource); ZEND_REGISTER_RESOURCE(resource, value, *(int *)(type->clientdata)); zend_class_entry **ce = NULL; zval *classname; MAKE_STD_ZVAL(classname); /* _p_Foo -> Foo */ ZVAL_STRING(classname, (char*)type->name+3, 1); /* class names are stored in lowercase */ php_strtolower(Z_STRVAL_PP(&classname), Z_STRLEN_PP(&classname)); if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &ce TSRMLS_CC) != SUCCESS) { /* class does not exist */ object_init(z); } else { object_init_ex(z, *ce); } Z_SET_REFCOUNT_P(z, 1); Z_SET_ISREF_P(z); zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval), NULL); FREE_ZVAL(classname); } return; } zend_error(E_ERROR, "Type: %s not registered with zend",type->name); }
static void init_function_monitor_hash(xdebug_hash *internal, HashTable *functions_to_monitor) { HashPosition pos; zval **val; zend_hash_internal_pointer_reset_ex(functions_to_monitor, &pos); while (zend_hash_get_current_data_ex(functions_to_monitor, (void **) &val, &pos) != FAILURE) { if (Z_TYPE_PP(val) == IS_STRING) { xdebug_hash_add(internal, Z_STRVAL_PP(val), Z_STRLEN_PP(val), xdstrdup(Z_STRVAL_PP(val))); } zend_hash_move_forward_ex(functions_to_monitor, &pos); } }
void cpServer_init_common(zval *conf) { zval **v; //daemonize,守护进程化 if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("daemonize"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.daemonize = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("recycle_num"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.recycle_num = (int) Z_LVAL_PP(v); } //error_file if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("log_file"), (void **) &v) == SUCCESS) { memcpy(CPGC.log_file, Z_STRVAL_PP(v), Z_STRLEN_PP(v)); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_read_len"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.max_read_len = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("port"), (void **) &v) == SUCCESS) {//todo check null convert_to_long(*v); CPGC.port = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("idel_time"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.idel_time = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("ser_fail_hits"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.ser_fail_hits = (int) Z_LVAL_PP(v); } if (zend_hash_find(Z_ARRVAL_P(conf), ZEND_STRS("max_fail_num"), (void **) &v) == SUCCESS) { convert_to_long(*v); CPGC.max_fail_num = (int) Z_LVAL_PP(v); } }
zval * activerecord_model_magic_set( zval * model, char * name, int name_len, zval * value ) { zval ** alias, * retval = NULL; if( zend_hash_find( Z_ARRVAL_P(zend_read_static_property(activerecord_model_ce, "alias_attribute", 15, 0 TSRMLS_CC)), name, name_len, (void**)&alias ) == SUCCESS ) { efree( name ); emalloc( name, sizeof( Z_STRVAL_PP(alias) ) ); strncpy( name, Z_STRVAL_PP(alias), Z_STRLEN_PP(alias) ); name_len = Z_STRLEN_PP(alias); } else { char *method_name; emalloc( method_name, sizeof(name)+4 ); strcpy( method_name, "set_" ); strcat( method_name, name ); if( activerecord_model_array_search( zend_read_property( activerecord_model_ce, this_ptr, "setters", 7, 0 TSRMLS_CC ), method_name) ) { zend_call_method( &this_ptr, activerecord_model_ce, NULL, method_name, sizeof(method_name), &retval, 0, NULL, NULL TSRMLS_CC ); efree( name ); RETURN_ZVAL( retval, 0, 0 ); } } if( zend_hash_find( Z_ARRVAL_P(zend_read_property(activerecord_model_ce, model, "attributes", 10, 0 TSRMLS_CC)), name, name_len ) == SUCCESS ) { retval = activerecord_model_assign_attribute( model, name, name_len, value ); } efree( name ); if( retval == NULL ); // throw new exception RETURN_ZVAL( retval, 0, 0 ); }
/* {{{ convert_to_gmp * Convert zval to be gmp number */ static int convert_to_gmp(mpz_t * *gmpnumber, zval **val, int base TSRMLS_DC) { int ret = 0; int skip_lead = 0; *gmpnumber = emalloc(sizeof(mpz_t)); switch (Z_TYPE_PP(val)) { case IS_LONG: case IS_BOOL: case IS_CONSTANT: { convert_to_long_ex(val); mpz_init_set_si(**gmpnumber, Z_LVAL_PP(val)); } break; case IS_STRING: { char *numstr = Z_STRVAL_PP(val); if (Z_STRLEN_PP(val) > 2) { if (numstr[0] == '0') { if (numstr[1] == 'x' || numstr[1] == 'X') { base = 16; skip_lead = 1; } else if (base != 16 && (numstr[1] == 'b' || numstr[1] == 'B')) { base = 2; skip_lead = 1; } } } ret = mpz_init_set_str(**gmpnumber, (skip_lead ? &numstr[2] : numstr), base); } break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING,"Unable to convert variable to GMP - wrong type"); efree(*gmpnumber); return FAILURE; } if (ret) { FREE_GMP_NUM(*gmpnumber); return FAILURE; } return SUCCESS; }
/* {{{ suhosin_server_encode */ static void suhosin_server_strip(HashTable *arr, char *key, int klen) { zval **tzval; unsigned char *s, *t; if (zend_hash_find(arr, key, klen, (void **) &tzval) == SUCCESS && Z_TYPE_PP(tzval) == IS_STRING) { s = t = (unsigned char *)Z_STRVAL_PP(tzval); for (; *t; t++) { if (suhosin_is_dangerous_char[*t]) { *t = '?'; } } Z_STRLEN_PP(tzval) = t-s; } }
char *owsrequest_getenv(const char *name, void *thread_context) { zval **val, **ppzval; zval *cookie_result, *key; HashTable *cookies; char *string_key = NULL, *cookie_tmp; ulong num_key; int numElements, i = 0; TSRMLS_FETCH_FROM_CTX(thread_context); if (STRING_EQUAL(name, "HTTP_COOKIE")) { cookies = PG(http_globals)[TRACK_VARS_COOKIE]->value.ht; numElements = zend_hash_num_elements(cookies); MAKE_STD_ZVAL(cookie_result); ZVAL_STRING(cookie_result, "",1); for(zend_hash_internal_pointer_reset(cookies); zend_hash_has_more_elements(cookies) == SUCCESS; zend_hash_move_forward(cookies), ++i) { zend_hash_get_current_data(cookies, (void **)&ppzval); zend_hash_get_current_key(cookies, &string_key, &num_key, 1); cookie_tmp = malloc((strlen(string_key)+Z_STRLEN_PP(ppzval)+3) * sizeof(char)); sprintf(cookie_tmp, "%s=%s;",string_key,Z_STRVAL_PP(ppzval)); MAKE_STD_ZVAL(key); ZVAL_STRING(key, cookie_tmp,1); add_string_to_string(cookie_result,cookie_result, key); zval_dtor(key); free(cookie_tmp); } return Z_STRVAL_P(cookie_result); } else { zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); if ( PG(http_globals)[TRACK_VARS_SERVER] && (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, name, strlen(name)+1, (void **) &val) == SUCCESS) && (Z_TYPE_PP(val) == IS_STRING)) { return Z_STRVAL_PP(val); } } return NULL; }
FOREACH_KEYVAL(pos, param, key, entry) { if (key.type == HASH_KEY_IS_STRING) { if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(key.str, key.len-1, &xkey, &xlen, oe, ie)) { http_error_ex(HE_WARNING, HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", key.len-1, key.str, ie, oe); return FAILURE; } } if (Z_TYPE_PP(entry) == IS_STRING) { if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry), &xlate_str, &xlate_len, oe, ie)) { if (key.type == HASH_KEY_IS_STRING) { efree(xkey); } http_error_ex(HE_WARNING, HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", Z_STRLEN_PP(entry), Z_STRVAL_PP(entry), ie, oe); return FAILURE; } if (key.type == HASH_KEY_IS_STRING) { add_assoc_stringl_ex(array, xkey, xlen+1, xlate_str, xlate_len, 0); } else { add_index_stringl(array, key.num, xlate_str, xlate_len, 0); } } else if (Z_TYPE_PP(entry) == IS_ARRAY) { zval *subarray; MAKE_STD_ZVAL(subarray); array_init(subarray); if (key.type == HASH_KEY_IS_STRING) { add_assoc_zval_ex(array, xkey, xlen+1, subarray); } else { add_index_zval(array, key.num, subarray); } if (SUCCESS != http_querystring_xlate(subarray, *entry, ie, oe)) { if (key.type == HASH_KEY_IS_STRING) { efree(xkey); } return FAILURE; } } if (key.type == HASH_KEY_IS_STRING) { efree(xkey); } }