void mongo_util_hash_copy_to_p(void *pDest) { zval **p = (zval**)pDest; zval *temp = *p; *p = (zval*)malloc(sizeof(zval)); memcpy(*p, temp, sizeof(zval)); INIT_PZVAL(*p); switch (Z_TYPE_PP(p)) { case IS_STRING: { Z_STRVAL_PP(p) = (char*)malloc(Z_STRLEN_P(temp)+1); memcpy(Z_STRVAL_PP(p), Z_STRVAL_P(temp), Z_STRLEN_P(temp)+1); break; } case IS_ARRAY: { TSRMLS_FETCH(); mongo_util_hash_to_pzval(p, &temp TSRMLS_CC); break; } } }
ZEND_METHOD (Msghdr, __destruct) { int rc; zval **hdr = 0; char *ptr; if (zend_hash_find (Z_OBJPROP_P (getThis ()), "__ptr", sizeof("__ptr"), (void **) &hdr) == FAILURE) return; if ((ptr = Z_STRVAL_PP (hdr)) && (ptr = * (char **) ptr)) { ubuf_free (ptr); } }
/** * 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)); }
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); }
void zephir_concat_ss(zval **result, const char *op1, zend_uint op1_len, const char *op2, zend_uint op2_len, int self_var TSRMLS_DC){ zval result_copy; int use_copy = 0; uint offset = 0, length; length = op1_len + op2_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 *) str_erealloc(Z_STRVAL_PP(result), length + 1); } else { Z_STRVAL_PP(result) = (char *) emalloc(length + 1); } memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len); memcpy(Z_STRVAL_PP(result) + offset + op1_len, op2, op2_len); Z_STRVAL_PP(result)[length] = 0; Z_TYPE_PP(result) = IS_STRING; Z_STRLEN_PP(result) = length; if (use_copy) { zval_dtor(&result_copy); } }
/** * 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 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); }
/* {{{ char *http_request_method_name(http_request_method) */ PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC) { zval **meth; if (HTTP_STD_REQUEST_METHOD(m)) { return http_request_methods[m]; } if (SUCCESS == zend_hash_index_find(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(m), (void **) &meth)) { return Z_STRVAL_PP(meth); } return http_request_methods[0]; }
static SEXP php_zval_to_r(zval **value) /* {{{ */ { SEXP result = NULL_USER_OBJECT; switch (Z_TYPE_PP(value)) { case IS_LONG: PROTECT(result = NEW_INTEGER(1)); INTEGER_DATA(result)[0] = Z_LVAL_PP(value); UNPROTECT(1); break; case IS_DOUBLE: PROTECT(result = NEW_NUMERIC(1)); NUMERIC_DATA(result)[0] = Z_DVAL_PP(value); UNPROTECT(1); break; case IS_STRING: PROTECT(result = NEW_CHARACTER(1)); SET_STRING_ELT(result, 0, COPY_TO_USER_STRING(Z_STRVAL_PP(value))); UNPROTECT(1); break; case IS_BOOL: PROTECT(result = NEW_LOGICAL(1)); LOGICAL_DATA(result)[0] = Z_BVAL_PP(value); UNPROTECT(1); break; case IS_ARRAY: result = php_hash_to_r(Z_ARRVAL_PP(value)); break; default: convert_to_string_ex(value); PROTECT(result = NEW_CHARACTER(1)); SET_STRING_ELT(result, 0, COPY_TO_USER_STRING(Z_STRVAL_PP(value))); UNPROTECT(1); break; } return result; }
void zephir_concat_vv(zval **result, zval *op1, zval *op2, 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); 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 *) str_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)); 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); } }
/* ******************************************************************************************************* * Wrapper function to remove bin(s) from a record. * * @param as_object_p The C client's aerospike object. * @param as_key_p The C client's as_key that identifies the record. * @param bins_p The PHP array of bins to be removed from the record. * @param error_p The as_error to be populated by the function * with the encountered error if any. * @param options_p The user's optional policy options to be used if set, else defaults. * ******************************************************************************************************* */ extern as_status aerospike_record_operations_remove_bin(aerospike* as_object_p, as_key* as_key_p, zval* bins_p, as_error* error_p, zval* options_p) { as_status status = AEROSPIKE_OK; as_record rec; HashTable *bins_array_p = Z_ARRVAL_P(bins_p); HashPosition pointer; zval **bin_names; as_policy_write write_policy; as_record_inita(&rec, zend_hash_num_elements(bins_array_p)); if ((!as_object_p) || (!error_p) || (!as_key_p) || (!bins_array_p)) { status = AEROSPIKE_ERR; goto exit; } set_policy(NULL, &write_policy, NULL, NULL, NULL, NULL, options_p, error_p); if (AEROSPIKE_OK != (status = (error_p->code))) { DEBUG_PHP_EXT_DEBUG("Unable to set policy"); goto exit; } foreach_hashtable(bins_array_p, pointer, bin_names) { if (IS_STRING == Z_TYPE_PP(bin_names)) { if (!(as_record_set_nil(&rec, Z_STRVAL_PP(bin_names)))) { status = AEROSPIKE_ERR; goto exit; } } else { status = AEROSPIKE_ERR; goto exit; } } if (AEROSPIKE_OK != (status = aerospike_key_put(as_object_p, error_p, NULL, as_key_p, &rec))) { goto exit; } exit: as_record_destroy(&rec); return(status); }
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 ); }
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; }
/* {{{ 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; }
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; }
/* {{{ 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; } }
/* {{{ MongoCursor->next */ PHP_METHOD(MongoCursor, next) { zval has_next; mongo_cursor *cursor; cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor); if (!cursor->started_iterating) { MONGO_METHOD(MongoCursor, doQuery)(INTERNAL_FUNCTION_PARAM_PASSTHRU); cursor->started_iterating = 1; } // destroy old current if (cursor->current) { zval_ptr_dtor(&cursor->current); cursor->current = 0; } // check for results MONGO_METHOD(MongoCursor, hasNext)(0, &has_next, NULL, getThis(), 0 TSRMLS_CC); if (!Z_BVAL(has_next)) { // we're out of results RETURN_NULL(); } // we got more results if (cursor->at < cursor->num) { zval **err; MAKE_STD_ZVAL(cursor->current); array_init(cursor->current); cursor->buf.pos = (unsigned char*)bson_to_zval((char*)cursor->buf.pos, Z_ARRVAL_P(cursor->current) TSRMLS_CC); // increment cursor position cursor->at++; // check for err if (cursor->num == 1 && zend_hash_find(Z_ARRVAL_P(cursor->current), "$err", 5, (void**)&err) == SUCCESS) { zend_throw_exception(mongo_ce_CursorException, Z_STRVAL_PP(err), 0 TSRMLS_CC); RETURN_FALSE; } } RETURN_NULL(); }
/* {{{ proto void R::init([array argv]) */ static PHP_METHOD(R, init) { zval *argv = NULL; int argc = 3; HashPosition pos; char **argv_arr; zval **element; int i; char *r_home; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &argv) == FAILURE) { return; } r_home = getenv("R_HOME"); if (!r_home || r_home[0] == '\0') { setenv("R_HOME", PHP_R_DIR, 0); } R_SetErrorHook(php_r_error_handler); R_SetWarningHook(php_r_warning_handler); if (argv) { argc += zend_hash_num_elements(Z_ARRVAL_P(argv)); } argv_arr = safe_emalloc(argc, sizeof(char *), 0); argv_arr[0] = "REmbeddedPHP"; argv_arr[1] = "--gui=none"; argv_arr[2] = "--silent"; if (argv) { i = 3; for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(argv), &pos); zend_hash_get_current_data_ex(Z_ARRVAL_P(argv), (void **) &element, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(argv), &pos) ) { convert_to_string_ex(element); argv_arr[i] = Z_STRVAL_PP(element); /* no copy here, libR does strdup() itself */ i++; } } Rf_initEmbeddedR(argc, argv_arr); efree(argv_arr); }
static void _mqseries_set_authentication_information_record_from_array(zval *array, PMQAIR authentication_information_record, PMQCHAR LDAPUserName) /* {{{ */ { HashTable *ht = Z_ARRVAL_P(array); zval **tmp; MQSERIES_SETOPT_LONG(authentication_information_record, Version); MQSERIES_SETOPT_LONG(authentication_information_record, AuthInfoType); MQSERIES_SETOPT_STRING(authentication_information_record, AuthInfoConnName); MQSERIES_SETOPT_STRING(authentication_information_record, LDAPPassword); MQSERIES_SETOPT_STRING(authentication_information_record, OCSPResponderURL); if (zend_hash_find(ht, "LDAPUserName", sizeof("LDAPUserName"), (void**)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING) { strncpy(LDAPUserName, Z_STRVAL_PP(tmp), sizeof(LDAPUserName)); authentication_information_record->LDAPUserNamePtr = LDAPUserName; authentication_information_record->LDAPUserNameLength = strlen(LDAPUserName); } }
void xdebug_init_debugger(TSRMLS_D) { xdebug_open_log(TSRMLS_C); if (XG(remote_connect_back)) { zval **remote_addr = NULL; XDEBUG_LOG_PRINT(XG(remote_log_file), "I: Checking remote connect back address.\n"); if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "X_HTTP_FORWARDED_FOR", 21, (void**)&remote_addr) == FAILURE) { zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REMOTE_ADDR", 12, (void**)&remote_addr); } if (remote_addr) { XDEBUG_LOG_PRINT(XG(remote_log_file), "I: Remote address found, connecting to %s:%d.\n", Z_STRVAL_PP(remote_addr), XG(remote_port)); XG(context).socket = xdebug_create_socket(Z_STRVAL_PP(remote_addr), XG(remote_port)); } else { XDEBUG_LOG_PRINT(XG(remote_log_file), "W: Remote address not found, connecting to configured address/port: %s:%d. :-|\n", XG(remote_host), XG(remote_port)); XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port)); } } else { XDEBUG_LOG_PRINT(XG(remote_log_file), "I: Connecting to configured address/port: %s:%d.\n", XG(remote_host), XG(remote_port)); XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port)); } if (XG(context).socket >= 0) { XDEBUG_LOG_PRINT(XG(remote_log_file), "I: Connected to client. :-)\n"); XG(remote_enabled) = 0; /* Get handler from mode */ XG(context).handler = xdebug_handler_get(XG(remote_handler)); if (!XG(context).handler) { zend_error(E_WARNING, "The remote debug handler '%s' is not supported.", XG(remote_handler)); XDEBUG_LOG_PRINT(XG(remote_log_file), "E: The remote debug handler '%s' is not supported. :-(\n", XG(remote_handler)); } else if (!XG(context).handler->remote_init(&(XG(context)), XDEBUG_REQ)) { /* The request could not be started, ignore it then */ XDEBUG_LOG_PRINT(XG(remote_log_file), "E: The debug session could not be started. :-(\n"); } else { /* All is well, turn off script time outs */ XG(remote_enabled) = 1; } } else { XDEBUG_LOG_PRINT(XG(remote_log_file), "E: Could not connect to client. :-(\n"); } if (!XG(remote_enabled)) { xdebug_close_log(TSRMLS_C); } }
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); } }
int geojson_point_to_lon_lat(zval *point, double *lon, double *lat) { zval **type, **coordinates; if (zend_hash_find(HASH_OF(point), "type", sizeof("type"), (void**) &type) != SUCCESS) { return 0; } if (Z_TYPE_PP(type) != IS_STRING || strcmp(Z_STRVAL_PP(type), "Point") != 0) { return 0; } if (zend_hash_find(HASH_OF(point), "coordinates", sizeof("coordinates"), (void**) &coordinates) != SUCCESS) { return 0; } if (Z_TYPE_PP(coordinates) != IS_ARRAY) { return 0; } return parse_point_pair(*coordinates, lon, lat); }
PHPAPI void mysqlnd_minfo_print_hash(zval *values) { zval **values_entry; HashPosition pos_values; zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&values_entry, &pos_values) == SUCCESS) { char *string_key; uint string_key_len; ulong num_key; zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values); convert_to_string(*values_entry); php_info_print_table_row(2, string_key, Z_STRVAL_PP(values_entry)); zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values); } }
/*=========================================================================================================== 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 ) ; }
/* {{{ append_key_value * Internal function which is called from locale_compose * gets the value for the key_name and appends to the loc_name * returns 1 if successful , -1 if not found , * 0 if array element is not a string , -2 if buffer-overflow */ static int append_key_value(smart_str* loc_name, HashTable* hash_arr, char* key_name) { zval** ele_value = NULL; if(zend_hash_find(hash_arr , key_name , strlen(key_name) + 1 ,(void **)&ele_value ) == SUCCESS ) { if(Z_TYPE_PP(ele_value)!= IS_STRING ){ /* element value is not a string */ return FAILURE; } if(strcmp(key_name, LOC_LANG_TAG) != 0 && strcmp(key_name, LOC_GRANDFATHERED_LANG_TAG)!=0 ) { /* not lang or grandfathered tag */ smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); } smart_str_appendl(loc_name, Z_STRVAL_PP(ele_value) , Z_STRLEN_PP(ele_value)); return SUCCESS; } return LOC_NOT_FOUND; }
static void release_worker(zval *object) { zend_rsrc_list_entry *p_sock_le; zval **data_source; if (zend_hash_find(Z_OBJPROP_P(object), ZEND_STRS("data_source"), (void **) &data_source) == SUCCESS) { if (zend_hash_find(&EG(persistent_list), Z_STRVAL_PP(data_source), Z_STRLEN_PP(data_source), (void **) &p_sock_le) == SUCCESS) { send_oob2proxy(p_sock_le); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "p_sock_le can not find"); } } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "data_source can not find"); } }
void mongo_util_hash_copy_to_np(void *pDest) { zval **p = (zval**)pDest; zval *temp = *p; ALLOC_ZVAL(*p); memcpy(*p, temp, sizeof(zval)); INIT_PZVAL(*p); switch(Z_TYPE_PP(p)) { case IS_STRING: { Z_STRVAL_PP(p) = estrndup(Z_STRVAL_P(temp), Z_STRLEN_P(temp)); break; } case IS_ARRAY: { TSRMLS_FETCH(); mongo_util_hash_to_zval(p, &temp TSRMLS_CC); break; } } }
/* {{{ 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; }
static const char* phalcon_http_request_getmethod_helper(TSRMLS_D) { zval **value; const char *method = SG(request_info).request_method; if (unlikely(!method)) { zval *_SERVER, key; INIT_ZVAL(key); ZVAL_STRING(&key, "REQUEST_METHOD", 0); phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); value = phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_NA); if (value && Z_TYPE_PP(value) == IS_STRING) { return Z_STRVAL_PP(value); } return ""; } return method; }