int geojson_linestring_to_array(zval *line, geo_array **array) { geo_array *tmp; zval **type, **coordinates; if (Z_TYPE_P(line) != IS_ARRAY) { return 0; } if (zend_hash_find(HASH_OF(line), "type", sizeof("type"), (void**) &type) != SUCCESS) { return 0; } if (Z_TYPE_PP(type) != IS_STRING || strcmp(Z_STRVAL_PP(type), "Linestring") != 0) { return 0; } if (zend_hash_find(HASH_OF(line), "coordinates", sizeof("coordinates"), (void**) &coordinates) != SUCCESS) { return 0; } if (Z_TYPE_PP(coordinates) != IS_ARRAY) { return 0; } tmp = geo_hashtable_to_array(*coordinates); if (tmp && array) { *array = tmp; return 1; } return 0; }
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(); }
static char *oauth_provider_get_http_verb() /* {{{ */ { zval *tmp; zend_is_auto_global_str("_SERVER", sizeof("_SERVER")-1); if(Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) != IS_UNDEF) { if((tmp = zend_hash_str_find(HASH_OF(&PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_METHOD", sizeof("REQUEST_METHOD") - 1)) != NULL || (tmp = zend_hash_str_find(HASH_OF(&PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_METHOD", sizeof("HTTP_METHOD") - 1)) != NULL ) { return Z_STRVAL_P(tmp); } } return NULL; }
static PHP_METHOD(midgard_workspace_storage, list_children) { if (zend_parse_parameters_none() == FAILURE) return; guint n_objects; MidgardWorkspaceStorage *self = MIDGARD_WORKSPACE_STORAGE(__php_gobject_ptr(getThis())); MidgardWorkspaceStorage **children = midgard_workspace_storage_list_children(self, &n_objects); array_init(return_value); if (!children) return; const char *g_class_name = G_OBJECT_TYPE_NAME(children[0]); zend_class_entry *ce = zend_fetch_class((char *) g_class_name, strlen(g_class_name), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); int i; for (i = 0; i < n_objects; i++) { zval *zobject; MAKE_STD_ZVAL(zobject); php_midgard_gobject_new_with_gobject(zobject, ce, G_OBJECT(children[i]), TRUE TSRMLS_CC); zend_hash_next_index_insert(HASH_OF(return_value), &zobject, sizeof(zval *), NULL); } }
static int real_php_log_buffer(zval *msg_buffer, char *opt, int opt_len TSRMLS_DC) { php_stream *stream = NULL; HashTable *ht; #if PHP_VERSION_ID >= 70000 zend_ulong num_key; zend_string *str_key; zval *entry; #else zval **log; #endif stream = process_stream(opt,opt_len TSRMLS_CC); if (stream == NULL) { return FAILURE; } #if PHP_VERSION_ID >= 70000 ht = HASH_OF(msg_buffer); ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, entry) { zend_string *s = zval_get_string(entry); php_stream_write(stream, ZSTR_VAL(s), ZSTR_LEN(s)); zend_string_release(s); }
/* {{{ append_multiple_key_values * Internal function which is called from locale_compose * gets the multiple values for the key_name and appends to the loc_name * used for 'variant','extlang','private' * returns 1 if successful , -1 if not found , * 0 if array element is not a string , -2 if buffer-overflow */ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, char* key_name) { zval *ele_value; int i = 0; int isFirstSubtag = 0; int max_value = 0; /* Variant/ Extlang/Private etc. */ if ((ele_value = zend_hash_str_find( hash_arr , key_name , strlen(key_name))) != NULL) { if( Z_TYPE_P(ele_value) == IS_STRING ){ add_prefix( loc_name , key_name); smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); smart_str_appendl(loc_name, Z_STRVAL_P(ele_value) , Z_STRLEN_P(ele_value)); return SUCCESS; } else if(Z_TYPE_P(ele_value) == IS_ARRAY ) { HashTable *arr = HASH_OF(ele_value); zval *data; ZEND_HASH_FOREACH_VAL(arr, data) { if(Z_TYPE_P(data) != IS_STRING) { return FAILURE; } if (isFirstSubtag++ == 0){ add_prefix(loc_name , key_name); } smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); smart_str_appendl(loc_name, Z_STRVAL_P(data) , Z_STRLEN_P(data)); } ZEND_HASH_FOREACH_END(); return SUCCESS; } else { return FAILURE;
/* {{{ pip_sequence_to_hash(PyObject *seq) * Convert a Python sequence to a PHP hash */ zval * pip_sequence_to_hash(PyObject *seq) { zval *hash, *val; PyObject *item; int i = 0; /* Make sure this object implements the sequence protocol */ if (!PySequence_Check(seq)) { return NULL; } /* Initialize our PHP array */ MAKE_STD_ZVAL(hash); if (array_init(hash) != SUCCESS) { return NULL; } /* Iterate over the items in the sequence */ while (item = PySequence_GetItem(seq, i++)) { val = pip_pyobject_to_zval(item); if (zend_hash_next_index_insert(HASH_OF(hash), (void *)&val, sizeof(zval *), NULL) == FAILURE) { php_error(E_ERROR, "Python: Array conversion error"); } Py_DECREF(item); } return hash; }
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); }
/* {{{ pip_mapping_to_hash(PyObject *map) Convert a Python mapping to a PHP hash */ zval * pip_mapping_to_hash(PyObject *map) { zval *hash, *val; PyObject *keys, *key, *item; char *key_name; int i, key_len; if (!PyMapping_Check(map)) { return NULL; } /* Initialize our PHP array */ MAKE_STD_ZVAL(hash); if (array_init(hash) != SUCCESS) { return NULL; } /* Retrieve the list of keys for this mapping */ keys = PyMapping_Keys(map); if (keys == NULL) { return hash; } /* Iterate over the list of keys */ for (i = 0; i < PySequence_Size(keys); i++) { key = PySequence_GetItem(keys, i); if (key) { /* Get the string representation of the key */ if (pip_str(key, &key_name, &key_len) != -1) { /* Extract the item for this key */ item = PyMapping_GetItemString(map, key_name); if (item) { val = pip_pyobject_to_zval(item); /* Add the new item to the associative array */ if (zend_hash_update(HASH_OF(hash), key_name, key_len, (void *)&val, sizeof(zval *), NULL) == FAILURE) { php_error(E_ERROR, "Python: Array conversion error"); } Py_DECREF(item); } else { php_error(E_ERROR, "Python: Could not get item for key"); } } else { php_error(E_ERROR, "Python: Mapping key conversion error"); } Py_DECREF(key); } } Py_DECREF(keys); return hash; }
/* {{{ _php_array_to_envp */ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent TSRMLS_DC) { zval *element; php_process_env_t env; zend_string *string_key; #ifndef PHP_WIN32 char **ep; #endif char *p; uint cnt, l, sizeenv=0; HashTable *target_hash; memset(&env, 0, sizeof(env)); if (!environment) { return env; } cnt = zend_hash_num_elements(Z_ARRVAL_P(environment)); if (cnt < 1) { #ifndef PHP_WIN32 env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent); #endif env.envp = (char *) pecalloc(4, 1, is_persistent); return env; } target_hash = HASH_OF(environment); if (!target_hash) { return env; } /* first, we have to get the size of all the elements in the hash */ ZEND_HASH_FOREACH_STR_KEY_VAL(target_hash, string_key, element) { zend_string *str = zval_get_string(element); uint el_len = str->len; STR_RELEASE(str); if (el_len == 0) { continue; } sizeenv += el_len + 1; if (string_key) { if (string_key->len == 0) { continue; } sizeenv += string_key->len + 1; } } ZEND_HASH_FOREACH_END();
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); }
/** * Construct an instance of the Channel class. If the $args array contains a * "credentials" key mapping to a ChannelCredentials object, a secure channel * will be created with those credentials. * @param string $target The hostname to associate with this channel * @param array $args The arguments to pass to the Channel (optional) */ PHP_METHOD(Channel, __construct) { wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis()); zend_string *target; zval *args_array = NULL; grpc_channel_args args; HashTable *array_hash; zval *creds_obj = NULL; wrapped_grpc_channel_credentials *creds = NULL; /* "Sa" == 1 string, 1 array */ #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sa", &target, &args_array) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, "Channel expects a string and an array", 1); return; } #else ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(target) Z_PARAM_ARRAY(args_array) ZEND_PARSE_PARAMETERS_END(); #endif array_hash = HASH_OF(args_array); if ((creds_obj = zend_hash_str_find(array_hash, "credentials", sizeof("credentials") - 1)) != NULL) { if (Z_TYPE_P(creds_obj) == IS_NULL) { creds = NULL; zend_hash_str_del(array_hash, "credentials", sizeof("credentials") - 1); } else if (Z_OBJ_P(creds_obj)->ce != grpc_ce_channel_credentials) { zend_throw_exception(spl_ce_InvalidArgumentException, "credentials must be a ChannelCredentials object", 1); return; } else { creds = Z_WRAPPED_GRPC_CHANNEL_CREDS_P(creds_obj); zend_hash_str_del(array_hash, "credentials", sizeof("credentials") - 1); } } php_grpc_read_args_array(args_array, &args); if (creds == NULL) { channel->wrapped = grpc_insecure_channel_create(ZSTR_VAL(target), &args, NULL); } else { channel->wrapped = grpc_secure_channel_create(creds->wrapped, ZSTR_VAL(target), &args, NULL); } efree(args.args); }
void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) { HashTable *array_hash; //HashPosition array_pointer; int args_index; zval *data; zend_string *key; //zend_ulong index; array_hash = HASH_OF(args_array); if (!array_hash) { zend_throw_exception(spl_ce_InvalidArgumentException, "array_hash is NULL", 1); return; } args->num_args = zend_hash_num_elements(array_hash); args->args = ecalloc(args->num_args, sizeof(grpc_arg)); args_index = 0; ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, data) { /*for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); (data = zend_hash_get_current_data_ex(array_hash, &array_pointer)) != NULL; zend_hash_move_forward_ex(array_hash, &array_pointer)) { if (zend_hash_get_current_key_ex(array_hash, &key, &index, &array_pointer) != HASH_KEY_IS_STRING) { zend_throw_exception(spl_ce_InvalidArgumentException, "args keys must be strings", 1); return; }*/ if (key == NULL) { zend_throw_exception(spl_ce_InvalidArgumentException, "args keys must be strings", 1); } args->args[args_index].key = ZSTR_VAL(key); switch (Z_TYPE_P(data)) { case IS_LONG: args->args[args_index].value.integer = (int)Z_LVAL_P(data); args->args[args_index].type = GRPC_ARG_INTEGER; break; case IS_STRING: args->args[args_index].value.string = Z_STRVAL_P(data); args->args[args_index].type = GRPC_ARG_STRING; break; default: zend_throw_exception(spl_ce_InvalidArgumentException, "args values must be int or string", 1); return; } args_index++; } ZEND_HASH_FOREACH_END(); }
ZEND_METHOD(Vedis, mget) { zval *keys; zval **val; size_t n; HashPosition pos; VEDIS_PARAM(MGET, 4); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &keys) == FAILURE) { return; } VEDIS_SELF(intern); n = zend_hash_num_elements(HASH_OF(keys)); if (n == 0) { RETURN_FALSE; } VEDIS_ARGS_INIT(n); zend_hash_internal_pointer_reset_ex(HASH_OF(keys), &pos); while (zend_hash_get_current_data_ex(HASH_OF(keys), (void **)&val, &pos) == SUCCESS) { if (Z_TYPE_PP(val) != IS_STRING) { convert_to_string(*val); } VEDIS_ARGS_STRING(Z_STRVAL_PP(val), Z_STRLEN_PP(val)); zend_hash_move_forward_ex(HASH_OF(keys), &pos); } VEDIS_ARGS_EXEC(RETURN_FALSE); VEDIS_RETURN_ARRAY(); }
/* {{{ length int readonly=yes URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337 Since: */ int dom_nodelist_length_read(dom_object *obj, zval *retval) { dom_nnodemap_object *objmap; xmlNodePtr nodep, curnode; int count = 0; HashTable *nodeht; objmap = (dom_nnodemap_object *)obj->ptr; if (objmap != NULL) { if (objmap->ht) { count = xmlHashSize(objmap->ht); } else { if (objmap->nodetype == DOM_NODESET) { nodeht = HASH_OF(&objmap->baseobj_zv); count = zend_hash_num_elements(nodeht); } else { nodep = dom_object_get_node(objmap->baseobj); if (nodep) { if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) { curnode = nodep->children; if (curnode) { count++; while (curnode->next != NULL) { count++; curnode = curnode->next; } } } else { if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { nodep = xmlDocGetRootElement((xmlDoc *) nodep); } else { nodep = nodep->children; } curnode = dom_get_elements_by_tag_name_ns_raw( nodep, (char *) objmap->ns, (char *) objmap->local, &count, -1); } } } } } ZVAL_LONG(retval, count); return SUCCESS; }
php_http_url_t *php_http_url_from_zval(zval *value, unsigned flags TSRMLS_DC) { zval *zcpy; php_http_url_t *purl; switch (Z_TYPE_P(value)) { case IS_ARRAY: case IS_OBJECT: purl = php_http_url_from_struct(HASH_OF(value)); break; default: zcpy = php_http_ztyp(IS_STRING, value); purl = php_http_url_parse(Z_STRVAL_P(zcpy), Z_STRLEN_P(zcpy), flags TSRMLS_CC); zval_ptr_dtor(&zcpy); } return purl; }
static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *val) { zend_ulong idx; zend_string *tmp_key; zval *tmp_val; (void)(idx); ZEND_HASH_FOREACH_KEY_VAL(HASH_OF(val), idx, tmp_key, tmp_val) { if (tmp_key) { php_error_docref(NULL, E_WARNING, "Multiple header key must be numeric index (%s)", ZSTR_VAL(tmp_key)); continue; } if (Z_TYPE_P(tmp_val) != IS_STRING) { php_error_docref(NULL, E_WARNING, "Multiple header values must be string (%s)", ZSTR_VAL(key)); continue; } php_mail_build_headers_elem(s, key, tmp_val); } ZEND_HASH_FOREACH_END(); }
ZEND_METHOD( alinq_class , getArrayItem ) { zval *data_array; zval *copy_array; char *name; int name_len; zval **fooval; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "as",&data_array, &name, &name_len) == FAILURE) { RETURN_NULL(); } if(zend_hash_find(HASH_OF(data_array),name,name_len,(void**)&fooval) == SUCCESS ){ RETVAL_ZVAL(*fooval, 1, 0); }else{ RETVAL_STRING("index_not_found", 1); } return; }
static PHP_METHOD(midgard_query_builder, execute) { RETVAL_FALSE; MidgardConnection *mgd = mgd_handle(TSRMLS_C); CHECK_MGD(mgd); if (zend_parse_parameters_none() == FAILURE) return; _GET_BUILDER_OBJECT; zend_class_entry *ce = php_gobject->user_ce; if (ce == NULL) { php_error(E_WARNING, "Query Builder instance not associated with any class"); return; } guint i, n_objects; GObject **objects = midgard_query_builder_execute(builder, &n_objects); array_init(return_value); if (!objects) return; /* TODO: Should use iterator, instead, and create objects lazily */ /* Initialize zend objects for the same class which was used to initialize Query Builder */ for (i = 0; i < n_objects; i++) { GObject *gobject = objects[i]; zval *zobject; /* TODO: Simplify code below. If possible. */ MAKE_STD_ZVAL(zobject); object_init_ex(zobject, ce); /* Initialize new object for which QB has been created for */ MGD_PHP_SET_GOBJECT(zobject, gobject); // inject our gobject zend_call_method_with_0_params(&zobject, ce, &ce->constructor, "__construct", NULL); /* Call class constructor on given instance */ zend_hash_next_index_insert(HASH_OF(return_value), &zobject, sizeof(zval *), NULL); } if (objects) g_free(objects); }
/** * Returns a list of all the events associated with the EventLoop. * * NOTE: In the case of the default event loop, only events which have * been added using php-libev will be returned as the others are * managed by others. * * @return array */ PHP_METHOD(EventLoop, getEvents) { event_loop_object *obj = (event_loop_object *)zend_object_store_get_object(getThis() TSRMLS_CC); array_init(return_value); event_object *ev = obj->events; while(ev) { assert(ev->this); zval_add_ref(&ev->this); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&ev->this, sizeof(zval *), NULL); ev = ev->next; } return; }
static int parse_point_pair(zval *coordinates, double *lon, double *lat) { HashTable *coords; zval **z_lon, **z_lat; coords = HASH_OF(coordinates); if (coords->nNumOfElements != 2) { return 0; } if (zend_hash_index_find(coords, 0, (void**) &z_lon) != SUCCESS) { return 0; } if (zend_hash_index_find(coords, 1, (void**) &z_lat) != SUCCESS) { return 0; } convert_to_double_ex(z_lon); convert_to_double_ex(z_lat); *lon = Z_DVAL_PP(z_lon); *lat = Z_DVAL_PP(z_lat); return 1; }
static PHP_METHOD(midgard_query_builder, execute) { RETVAL_FALSE; MidgardConnection *mgd = mgd_handle(TSRMLS_C); CHECK_MGD(mgd); if (zend_parse_parameters_none() == FAILURE) return; _GET_BUILDER_OBJECT; zend_class_entry *ce = php_gobject->user_ce; if (ce == NULL) { php_error(E_WARNING, "Query Builder instance not associated with any class"); return; } guint i, n_objects; GObject **objects = midgard_query_builder_execute(builder, &n_objects); array_init(return_value); if (!objects) return; /* TODO: Should use iterator, instead, and create objects lazily */ for (i = 0; i < n_objects; i++) { GObject *gobject = objects[i]; zval *zobject; MAKE_STD_ZVAL(zobject); php_midgard_gobject_new_with_gobject(zobject, ce, gobject, TRUE TSRMLS_CC); zend_hash_next_index_insert(HASH_OF(return_value), &zobject, sizeof(zval *), NULL); } if (objects) g_free(objects); }
static int json_determine_array_type(zval *val) /* {{{ */ { int i; HashTable *myht = HASH_OF(val); i = myht ? zend_hash_num_elements(myht) : 0; if (i > 0) { zend_string *key; zend_ulong index, idx; idx = 0; ZEND_HASH_FOREACH_KEY(myht, index, key) { if (key) { return PHP_JSON_OUTPUT_OBJECT; } else { if (index != idx) { return PHP_JSON_OUTPUT_OBJECT; } } idx++; } ZEND_HASH_FOREACH_END(); }
/* Creates and returns a PHP array object with the data in a * grpc_metadata_array. Returns NULL on failure */ void grpc_parse_metadata_array(grpc_metadata_array *metadata_array, zval *array) { int count = metadata_array->count; grpc_metadata *elements = metadata_array->metadata; int i; zval *data; HashTable *array_hash; zval inner_array; char *str_key; char *str_val; size_t key_len; array_init(array); array_hash = HASH_OF(array); grpc_metadata *elem; for (i = 0; i < count; i++) { elem = &elements[i]; key_len = strlen(elem->key); str_key = ecalloc(key_len + 1, sizeof(char)); memcpy(str_key, elem->key, key_len); str_val = ecalloc(elem->value_length + 1, sizeof(char)); memcpy(str_val, elem->value, elem->value_length); if ((data = zend_hash_str_find(array_hash, str_key, key_len)) != NULL) { if (Z_TYPE_P(data) != IS_ARRAY) { zend_throw_exception(zend_exception_get_default(), "Metadata hash somehow contains wrong types.", 1); efree(str_key); efree(str_val); return; } add_next_index_stringl(data, str_val, elem->value_length); } else { array_init(&inner_array); add_next_index_stringl(&inner_array, str_val, elem->value_length); add_assoc_zval(array, str_key, &inner_array); } } return; }
/* {{{ xslt_make_array() Make an XSLT array (char **) from a zval array (HashTable *) */ extern void xslt_make_array(zval **zarr, char ***carr) { zval **current; HashTable *arr; int idx = 0; arr = HASH_OF(*zarr); if (! arr) { php_error(E_WARNING, "Invalid argument or parameter array to %s", get_active_function_name()); return; } *carr = emalloc((zend_hash_num_elements(arr) * 2) + 1); for (zend_hash_internal_pointer_reset(arr); zend_hash_get_current_data(arr, (void **) ¤t) == SUCCESS; zend_hash_move_forward(arr)) { char *string_key = NULL; ulong num_key; int type; SEPARATE_ZVAL(current); convert_to_string_ex(current); type = zend_hash_get_current_key(arr, &string_key, &num_key, 0); if (type == HASH_KEY_IS_LONG) { php_error(E_WARNING, "Invalid argument or parameter array to %s", get_active_function_name()); return; } (*carr)[idx++] = estrdup(string_key); (*carr)[idx++] = estrndup(Z_STRVAL_PP(current), Z_STRLEN_PP(current)); } (*carr)[idx] = NULL; }
static PHP_METHOD(php_midgard_reflection_class, listSignals) { if (zend_parse_parameters_none() == FAILURE) { return; } _GET_RC_CE; if (ce == NULL) return; array_init(return_value); GType classtype = g_type_from_name(php_class_name_to_g_class_name(ce->name)); if (!classtype) { return; } guint n_ids = 0; guint *ids = g_signal_list_ids(classtype, &n_ids); if (ids == NULL) { return; } size_t i; for (i = 0; i < n_ids; i++) { zval *signalname; MAKE_STD_ZVAL(signalname); ZVAL_STRING(signalname, (char *) g_signal_name(ids[i]), 1); zend_hash_next_index_insert(HASH_OF(return_value), &signalname, sizeof(zval *), NULL); } g_free(ids); }
inline int msgpack_convert_string_to_properties( zval *object, char *key, uint key_len, zval *val, HashTable *var) { zval **data = NULL; HashTable *ht; zend_class_entry *ce; char *prot_name, *priv_name; int prop_name_len; TSRMLS_FETCH(); ht = HASH_OF(object); ce = zend_get_class_entry(object TSRMLS_CC); /* private */ zend_mangle_property_name( &priv_name, &prop_name_len, ce->name, ce->name_length, key, key_len, 1); if (zend_hash_find( ht, priv_name, prop_name_len, (void **)&data) == SUCCESS) { MSGPACK_CONVERT_UPDATE_PROPERTY(ht, priv_name, prop_name_len, val, var); } /* protected */ zend_mangle_property_name( &prot_name, &prop_name_len, "*", 1, key, key_len, 1); if (zend_hash_find( ht, prot_name, prop_name_len, (void **)&data) == SUCCESS) { MSGPACK_CONVERT_UPDATE_PROPERTY(ht, prot_name, prop_name_len, val, var); } /* public */ MSGPACK_CONVERT_UPDATE_PROPERTY(ht, key, key_len, val, var); return FAILURE; }
/* {{{ _php_array_to_envp */ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent TSRMLS_DC) { zval **element; php_process_env_t env; char *string_key, *data; #ifndef PHP_WIN32 char **ep; #endif char *p; uint string_length, cnt, l, sizeenv=0, el_len; ulong num_key; HashTable *target_hash; HashPosition pos; memset(&env, 0, sizeof(env)); if (!environment) { return env; } cnt = zend_hash_num_elements(Z_ARRVAL_P(environment)); if (cnt < 1) { #ifndef PHP_WIN32 env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent); #endif env.envp = (char *) pecalloc(4, 1, is_persistent); return env; } target_hash = HASH_OF(environment); if (!target_hash) { return env; } /* first, we have to get the size of all the elements in the hash */ for (zend_hash_internal_pointer_reset_ex(target_hash, &pos); zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS; zend_hash_move_forward_ex(target_hash, &pos)) { if (Z_TYPE_PP(element) != IS_STRING) { zval tmp; MAKE_COPY_ZVAL(element, &tmp); convert_to_string(&tmp); el_len = Z_STRLEN(tmp); zval_dtor(&tmp); } else { el_len = Z_STRLEN_PP(element); } if (el_len == 0) { continue; } sizeenv += el_len+1; switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) { case HASH_KEY_IS_STRING: if (string_length == 0) { continue; } sizeenv += string_length; break; } } #ifndef PHP_WIN32 ep = env.envarray = (char **) pecalloc(cnt + 1, sizeof(char *), is_persistent); #endif p = env.envp = (char *) pecalloc(sizeenv + 4, 1, is_persistent); for (zend_hash_internal_pointer_reset_ex(target_hash, &pos); zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS; zend_hash_move_forward_ex(target_hash, &pos)) { zval tmp; if (Z_TYPE_PP(element) != IS_STRING) { MAKE_COPY_ZVAL(element, &tmp); convert_to_string(&tmp); } else { tmp = **element; } el_len = Z_STRLEN(tmp); if (el_len == 0) { goto next_element; } data = Z_STRVAL(tmp); switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) { case HASH_KEY_IS_STRING: if (string_length == 0) { goto next_element; } l = string_length + el_len + 1; memcpy(p, string_key, string_length); strncat(p, "=", 1); strncat(p, data, el_len); #ifndef PHP_WIN32 *ep = p; ++ep; #endif p += l; break; case HASH_KEY_IS_LONG: memcpy(p,data,el_len); #ifndef PHP_WIN32 *ep = p; ++ep; #endif p += el_len + 1; break; case HASH_KEY_NON_EXISTENT: break; } next_element: if (Z_TYPE_PP(element) != IS_STRING) { zval_dtor(&tmp); } } assert((uint)(p - env.envp) <= sizeenv); zend_hash_internal_pointer_reset_ex(target_hash, &pos); return env; }
static PHP_MINFO_FUNCTION(json) { php_info_print_table_start(); php_info_print_table_row(2, "json support", "enabled"); php_info_print_table_row(2, "json version", PHP_JSON_VERSION); php_info_print_table_row(2, "json remark", "support for non utf8 charset, like 5.3, modify by [email protected]"); php_info_print_table_end(); } /* }}} */ static void json_escape_string(smart_str *buf, char *s, int len, int options TSRMLS_DC); static int json_determine_array_type(zval **val TSRMLS_DC) /* {{{ */ { int i; HashTable *myht = HASH_OF(*val); i = myht ? zend_hash_num_elements(myht) : 0; if (i > 0) { char *key; ulong index, idx; uint key_len; HashPosition pos; zend_hash_internal_pointer_reset_ex(myht, &pos); idx = 0; for (;; zend_hash_move_forward_ex(myht, &pos)) { i = zend_hash_get_current_key_ex(myht, &key, &key_len, &index, 0, &pos); if (i == HASH_KEY_NON_EXISTENT) { break; }
int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) { zend_class_entry *ce, **pce; TSRMLS_FETCH(); switch (Z_TYPE_P(tpl)) { case IS_STRING: if (zend_lookup_class( Z_STRVAL_P(tpl), Z_STRLEN_P(tpl), &pce TSRMLS_CC) != SUCCESS) { MSGPACK_ERROR("[msgpack] (%s) Class '%s' not found", __FUNCTION__, Z_STRVAL_P(tpl)); return FAILURE; } ce = *pce; break; case IS_OBJECT: ce = zend_get_class_entry(tpl TSRMLS_CC); break; default: MSGPACK_ERROR("[msgpack] (%s) object type is unsupported", __FUNCTION__); return FAILURE; } if (Z_TYPE_PP(value) == IS_OBJECT) { zend_class_entry *vce; vce = zend_get_class_entry(*value TSRMLS_CC); if (strcmp(ce->name, vce->name) == 0) { *return_value = **value; zval_copy_ctor(return_value); zval_ptr_dtor(value); return SUCCESS; } } object_init_ex(return_value, ce); /* Run the constructor if there is one */ if (ce->constructor && (ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { zval *retval_ptr = NULL; zval ***params = NULL; int num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; #if ZEND_MODULE_API_NO >= 20090626 fci.size = sizeof(fci); fci.function_table = EG(function_table); fci.function_name = NULL; fci.symbol_table = NULL; fci.object_ptr = return_value; fci.retval_ptr_ptr = &retval_ptr; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; fcc.initialized = 1; fcc.function_handler = ce->constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); fcc.object_ptr = return_value; #else fci.size = sizeof(fci); fci.function_table = EG(function_table); fci.function_name = NULL; fci.symbol_table = NULL; fci.object_pp = &return_value; fci.retval_ptr_ptr = &retval_ptr; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; fcc.initialized = 1; fcc.function_handler = ce->constructor; fcc.calling_scope = EG(scope); fcc.object_pp = &return_value; #endif if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { if (params) { efree(params); } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } MSGPACK_WARNING( "[msgpack] (%s) Invocation of %s's constructor failed", __FUNCTION__, ce->name); return FAILURE; } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } if (params) { efree(params); } } switch (Z_TYPE_PP(value)) { case IS_ARRAY: { char *key; uint key_len; int key_type; ulong key_index; zval **data; HashPosition pos; HashTable *ht, *ret; HashTable *var = NULL; int num; ht = HASH_OF(*value); ret = HASH_OF(return_value); num = zend_hash_num_elements(ht); if (num <= 0) { zval_ptr_dtor(value); break; } /* string - php_only mode? */ if (ht->nNumOfElements != ht->nNextFreeElement || ht->nNumOfElements != ret->nNumOfElements) { HashTable *properties = NULL; HashPosition prop_pos; ALLOC_HASHTABLE(var); zend_hash_init(var, num, NULL, NULL, 0); zend_hash_internal_pointer_reset_ex(ht, &pos); for (;; zend_hash_move_forward_ex(ht, &pos)) { key_type = zend_hash_get_current_key_ex( ht, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( ht, (void *)&data, &pos) != SUCCESS) { continue; } if (key_type == HASH_KEY_IS_STRING) { zval *val; MSGPACK_CONVERT_COPY_ZVAL(val, data); if (msgpack_convert_string_to_properties( return_value, key, key_len, val, var) != SUCCESS) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) " "illegal offset type, skip this decoding", __FUNCTION__); } } } /* index */ properties = Z_OBJ_HT_P(return_value)->get_properties( return_value TSRMLS_CC); if (HASH_OF(tpl)) { properties = HASH_OF(tpl); } zend_hash_internal_pointer_reset_ex(properties, &prop_pos); zend_hash_internal_pointer_reset_ex(ht, &pos); for (;; zend_hash_move_forward_ex(ht, &pos)) { key_type = zend_hash_get_current_key_ex( ht, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( ht, (void *)&data, &pos) != SUCCESS) { continue; } switch (key_type) { case HASH_KEY_IS_LONG: { zval *val; MSGPACK_CONVERT_COPY_ZVAL(val, data); if (msgpack_convert_long_to_properties( ret, &properties, &prop_pos, key_index, val, var) != SUCCESS) { zval_ptr_dtor(&val); MSGPACK_WARNING( "[msgpack] (%s) " "illegal offset type, skip this decoding", __FUNCTION__); } break; } case HASH_KEY_IS_STRING: break; default: MSGPACK_WARNING( "[msgpack] (%s) key is not string nor array", __FUNCTION__); break; } } zend_hash_destroy(var); FREE_HASHTABLE(var); } else { HashPosition valpos; int (*convert_function)(zval *, zval *, zval **) = NULL; zval **arydata, *aryval; /* index */ zend_hash_internal_pointer_reset_ex(ret, &pos); zend_hash_internal_pointer_reset_ex(ht, &valpos); for (;; zend_hash_move_forward_ex(ret, &pos), zend_hash_move_forward_ex(ht, &valpos)) { key_type = zend_hash_get_current_key_ex( ret, &key, &key_len, &key_index, 0, &pos); if (key_type == HASH_KEY_NON_EXISTANT) { break; } if (zend_hash_get_current_data_ex( ret, (void *)&data, &pos) != SUCCESS) { continue; } switch (Z_TYPE_PP(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; case IS_OBJECT: //case IS_STRING: -- may have default values of // class members, so it's not wise to allow convert_function = msgpack_convert_object; break; default: break; } if (zend_hash_get_current_data_ex( ht, (void *)&arydata, &valpos) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) can't get data value by index", __FUNCTION__); return FAILURE; } MSGPACK_CONVERT_COPY_ZVAL(aryval, arydata); if (convert_function) { zval *rv; ALLOC_INIT_ZVAL(rv); if (convert_function(rv, *data, &aryval) != SUCCESS) { zval_ptr_dtor(&aryval); MSGPACK_WARNING( "[msgpack] (%s) " "convert failure in convert_object", __FUNCTION__); return FAILURE; } zend_symtable_update( ret, key, key_len, &rv, sizeof(rv), NULL); } else { zend_symtable_update( ret, key, key_len, &aryval, sizeof(aryval), NULL); } } } zval_ptr_dtor(value); break; } default: { HashTable *properties = NULL; HashPosition prop_pos; properties = Z_OBJ_HT_P(return_value)->get_properties( return_value TSRMLS_CC); zend_hash_internal_pointer_reset_ex(properties, &prop_pos); if (msgpack_convert_long_to_properties( HASH_OF(return_value), &properties, &prop_pos, 0, *value, NULL) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } break; } } return SUCCESS; }