コード例 #1
0
static
void binary_serialize_spec(zval* zthis, PHPOutputTransport& transport, HashTable* spec) {
    HashPosition key_ptr;
    zval* val_ptr;

    for (zend_hash_internal_pointer_reset_ex(spec, &key_ptr);
            (val_ptr = zend_hash_get_current_data_ex(spec, &key_ptr)) != nullptr;
            zend_hash_move_forward_ex(spec, &key_ptr)) {

        zend_ulong fieldno;
        if (zend_hash_get_current_key_ex(spec, nullptr, &fieldno, &key_ptr) != HASH_KEY_IS_LONG) {
            throw_tprotocolexception("Bad keytype in TSPEC (expected 'long')", INVALID_DATA);
            return;
        }
        HashTable* fieldspec = Z_ARRVAL_P(val_ptr);

        // field name
        val_ptr = zend_hash_str_find(fieldspec, "var", sizeof("var")-1);
        char* varname = Z_STRVAL_P(val_ptr);

        // thrift type
        val_ptr = zend_hash_str_find(fieldspec, "type", sizeof("type")-1);
        if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr);
        int8_t ttype = Z_LVAL_P(val_ptr);

        zval rv;
        zval* prop = zend_read_property(Z_OBJCE_P(zthis), zthis, varname, strlen(varname), false, &rv);
        if (Z_TYPE_P(prop) != IS_NULL) {
            transport.writeI8(ttype);
            transport.writeI16(fieldno);
            binary_serialize(ttype, transport, prop, fieldspec);
        }
    }
    transport.writeI8(T_STOP); // struct end
}
コード例 #2
0
ファイル: php_variables.c プロジェクト: Crell/php-src
static zend_bool php_auto_globals_create_server(zend_string *name)
{
	if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) {
		php_register_server_variables();

		if (PG(register_argc_argv)) {
			if (SG(request_info).argc) {
				zval *argc, *argv;

				if ((argc = zend_hash_str_find(&EG(symbol_table), "argc", sizeof("argc")-1)) != NULL &&
					(argv = zend_hash_str_find(&EG(symbol_table), "argv", sizeof("argv")-1)) != NULL) {
					Z_ADDREF_P(argv);
					zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv")-1, argv);
					zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc")-1, argc);
				}
			} else {
				php_build_argv(SG(request_info).query_string, &PG(http_globals)[TRACK_VARS_SERVER]);
			}
		}

	} else {
		zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
		array_init(&PG(http_globals)[TRACK_VARS_SERVER]);
	}

	zend_hash_update(&EG(symbol_table), name, &PG(http_globals)[TRACK_VARS_SERVER]);
	Z_ADDREF(PG(http_globals)[TRACK_VARS_SERVER]);

	return 0; /* don't rearm */
}
コード例 #3
0
ファイル: yaf_route_simple.c プロジェクト: recoye/php-yaf
/** {{{ zend_string * yaf_route_simple_assemble(zval *info, zval *query)
 */
zend_string * yaf_route_simple_assemble(yaf_route_t *this_ptr, zval *info, zval *query) {
	smart_str tvalue = {0};
	zval *nmodule, *ncontroller, *naction;

	smart_str_appendc(&tvalue, '?');

	nmodule = zend_read_property(yaf_route_simple_ce,
			this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_MODULE), 1, NULL);
	ncontroller = zend_read_property(yaf_route_simple_ce,
			this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_CONTROLLER), 1, NULL);
	naction = zend_read_property(yaf_route_simple_ce,
			this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_ACTION), 1, NULL);

	do {
		zval *tmp;

		if ((tmp = zend_hash_str_find(Z_ARRVAL_P(info), ZEND_STRL(YAF_ROUTE_ASSEMBLE_MOUDLE_FORMAT))) != NULL) {
			smart_str_appendl(&tvalue, Z_STRVAL_P(nmodule), Z_STRLEN_P(nmodule));
			smart_str_appendc(&tvalue, '=');
			smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
			smart_str_appendc(&tvalue, '&');
		} 

		if ((tmp = zend_hash_str_find(Z_ARRVAL_P(info), ZEND_STRL(YAF_ROUTE_ASSEMBLE_CONTROLLER_FORMAT))) == NULL) {
			yaf_trigger_error(YAF_ERR_TYPE_ERROR, "%s", "You need to specify the controller by ':c'");
			break;
		}

		smart_str_appendl(&tvalue, Z_STRVAL_P(ncontroller), Z_STRLEN_P(ncontroller));
		smart_str_appendc(&tvalue, '=');
		smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
		smart_str_appendc(&tvalue, '&');

		if ((tmp = zend_hash_str_find(Z_ARRVAL_P(info), ZEND_STRL(YAF_ROUTE_ASSEMBLE_ACTION_FORMAT))) == NULL) {
			yaf_trigger_error(YAF_ERR_TYPE_ERROR, "%s", "You need to specify the action by ':a'");
			break;
		}

		smart_str_appendl(&tvalue, Z_STRVAL_P(naction), Z_STRLEN_P(naction));
		smart_str_appendc(&tvalue, '=');
		smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));

		if (query && IS_ARRAY == Z_TYPE_P(query)) {
			zend_string *key;

            ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(query), key, tmp) {
				if (IS_STRING == Z_TYPE_P(tmp) && key) {
					smart_str_appendc(&tvalue, '&');
					smart_str_appendl(&tvalue, ZSTR_VAL(key), ZSTR_LEN(key));
					smart_str_appendc(&tvalue, '=');
					smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
				}
			} ZEND_HASH_FOREACH_END();
		}

		smart_str_0(&tvalue);
		return tvalue.s;
	} while (0);
コード例 #4
0
ファイル: zend_exceptions.c プロジェクト: 18913574260/php-src
static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* {{{ */
{
	zval *file, *tmp;

	smart_str_appendc(str, '#');
	smart_str_append_long(str, num);
	smart_str_appendc(str, ' ');

	file = zend_hash_str_find(ht, "file", sizeof("file")-1);
	if (file) {
		if (Z_TYPE_P(file) != IS_STRING) {
			zend_error(E_WARNING, "Function name is no string");
			smart_str_appends(str, "[unknown function]");
		} else{
			zend_long line;
			tmp = zend_hash_str_find(ht, "line", sizeof("line")-1);
			if (tmp) {
				if (Z_TYPE_P(tmp) == IS_LONG) {
					line = Z_LVAL_P(tmp);
				} else {
					zend_error(E_WARNING, "Line is no long");
					line = 0;
				}
			} else {
				line = 0;
			}
			smart_str_append(str, Z_STR_P(file));
			smart_str_appendc(str, '(');
			smart_str_append_long(str, line);
			smart_str_appends(str, "): ");
		}
	} else {
		smart_str_appends(str, "[internal function]: ");
	}
	TRACE_APPEND_KEY("class");
	TRACE_APPEND_KEY("type");
	TRACE_APPEND_KEY("function");
	smart_str_appendc(str, '(');
	tmp = zend_hash_str_find(ht, "args", sizeof("args")-1);
	if (tmp) {
		if (Z_TYPE_P(tmp) == IS_ARRAY) {
			size_t last_len = ZSTR_LEN(str->s);
			zval *arg;

			ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmp), arg) {
				_build_trace_args(arg, str);
			} ZEND_HASH_FOREACH_END();

			if (last_len != ZSTR_LEN(str->s)) {
				ZSTR_LEN(str->s) -= 2; /* remove last ', ' */
			}
		} else {
コード例 #5
0
ファイル: user_filters.c プロジェクト: LTD-Beget/php-src
/* {{{ php_stream_bucket_attach */
static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
{
	zval *zbrigade, *zobject;
	zval *pzbucket, *pzdata;
	php_stream_bucket_brigade *brigade;
	php_stream_bucket *bucket;

	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_RESOURCE(zbrigade)
		Z_PARAM_OBJECT(zobject)
	ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

	if (NULL == (pzbucket = zend_hash_str_find(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
		php_error_docref(NULL, E_WARNING, "Object has no bucket property");
		RETURN_FALSE;
	}

	if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource(
					Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) {
		RETURN_FALSE;
	}

	if ((bucket = (php_stream_bucket *)zend_fetch_resource_ex(pzbucket, PHP_STREAM_BUCKET_RES_NAME, le_bucket)) == NULL) {
		RETURN_FALSE;
	}

	if (NULL != (pzdata = zend_hash_str_find(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) {
		if (!bucket->own_buf) {
			bucket = php_stream_bucket_make_writeable(bucket);
		}
		if (bucket->buflen != Z_STRLEN_P(pzdata)) {
			bucket->buf = perealloc(bucket->buf, Z_STRLEN_P(pzdata), bucket->is_persistent);
			bucket->buflen = Z_STRLEN_P(pzdata);
		}
		memcpy(bucket->buf, Z_STRVAL_P(pzdata), bucket->buflen);
	}

	if (append) {
		php_stream_bucket_append(brigade, bucket);
	} else {
		php_stream_bucket_prepend(brigade, bucket);
	}
	/* This is a hack necessary to accommodate situations where bucket is appended to the stream
 	 * multiple times. See bug35916.phpt for reference.
	 */
	if (bucket->refcount == 1) {
		bucket->refcount++;
	}
}
コード例 #6
0
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;
}
コード例 #7
0
ファイル: locale_methods.c プロジェクト: 0xhacking/php-src
/* {{{ 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;
コード例 #8
0
ファイル: zend_constants.c プロジェクト: Llewellynvdm/php-src
ZEND_API zval *zend_get_constant(zend_string *name)
{
    zval *zv;
	zend_constant *c;
	ALLOCA_FLAG(use_heap)

	zv = zend_hash_find(EG(zend_constants), name);
	if (zv == NULL) {
		char *lcname = do_alloca(ZSTR_LEN(name) + 1, use_heap);
		zend_str_tolower_copy(lcname, ZSTR_VAL(name), ZSTR_LEN(name));
		zv = zend_hash_str_find(EG(zend_constants), lcname, ZSTR_LEN(name));
		if (zv != NULL) {
			c = Z_PTR_P(zv);
			if (c->flags & CONST_CS) {
				c = NULL;
			}
		} else {
			c = zend_get_special_constant(ZSTR_VAL(name), ZSTR_LEN(name));
		}
		free_alloca(lcname, use_heap);
		return c ? &c->value : NULL;
	} else {
		return &((zend_constant*)Z_PTR_P(zv))->value;
	}
}
コード例 #9
0
ファイル: zend_constants.c プロジェクト: VBart/php-src
static inline zend_constant *zend_get_constant_impl(zend_string *name)
{
    zval *zv;
	zend_constant *c;
	ALLOCA_FLAG(use_heap)

	zv = zend_hash_find(EG(zend_constants), name);
	if (zv == NULL) {
		char *lcname = do_alloca(ZSTR_LEN(name) + 1, use_heap);
		zend_str_tolower_copy(lcname, ZSTR_VAL(name), ZSTR_LEN(name));
		zv = zend_hash_str_find(EG(zend_constants), lcname, ZSTR_LEN(name));
		if (zv != NULL) {
			c = Z_PTR_P(zv);
			if (ZEND_CONSTANT_FLAGS(c) & CONST_CS) {
				c = NULL;
			}
		} else {
			c = zend_get_special_constant(ZSTR_VAL(name), ZSTR_LEN(name));
		}
		free_alloca(lcname, use_heap);
		return c;
	} else {
		return (zend_constant *) Z_PTR_P(zv);
	}
}
コード例 #10
0
ファイル: dateformat_format.c プロジェクト: avsej/php-src
/* {{{
 * Internal function which fetches an element from the passed array for the key_name passed
*/
static int32_t internal_get_arr_ele(IntlDateFormatter_object *dfo,
		HashTable* hash_arr, char* key_name, intl_error *err)
{
	zval	*ele_value	= NULL;
	int32_t	result		= 0;
	char	*message;

	if (U_FAILURE(err->code)) {
		return result;
	}

	if ((ele_value = zend_hash_str_find(hash_arr, key_name, strlen(key_name))) != NULL) {
		if(Z_TYPE_P(ele_value) != IS_LONG) {
			spprintf(&message, 0, "datefmt_format: parameter array contains "
					"a non-integer element for key '%s'", key_name);
			intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message, 1);
			efree(message);
		} else {
			if (Z_LVAL_P(ele_value) > INT32_MAX ||
					Z_LVAL_P(ele_value) < INT32_MIN) {
				spprintf(&message, 0, "datefmt_format: value " ZEND_LONG_FMT " is out of "
						"bounds for a 32-bit integer in key '%s'",
						Z_LVAL_P(ele_value), key_name);
				intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message, 1);
				efree(message);
			} else {
				result = Z_LVAL_P(ele_value);
			}
		}
	}

	return result;
}
コード例 #11
0
ファイル: conversions.c プロジェクト: AmesianX/php-src
/* Generic Aggregated conversions */
static void from_zval_write_aggregation(const zval *container,
										char *structure,
										const field_descriptor *descriptors,
										ser_context *ctx)
{
	const field_descriptor	*descr;
	zval					*elem;

	if (Z_TYPE_P(container) != IS_ARRAY) {
		do_from_zval_err(ctx, "%s", "expected an array here");
	}

	for (descr = descriptors; descr->name != NULL && !ctx->err.has_error; descr++) {
		if ((elem = zend_hash_str_find(Z_ARRVAL_P(container),
				descr->name, descr->name_size - 1)) != NULL) {

			if (descr->from_zval == NULL) {
				do_from_zval_err(ctx, "No information on how to convert value "
						"of key '%s'", descr->name);
				break;
			}

			zend_llist_add_element(&ctx->keys, (void*)&descr->name);
			descr->from_zval(elem, ((char*)structure) + descr->field_offset, ctx);
			zend_llist_remove_tail(&ctx->keys);

		} else if (descr->required) {
			do_from_zval_err(ctx, "The key '%s' is required", descr->name);
			break;
		}
	}
}
コード例 #12
0
/* {{{ php_runkit_sandbox_parent_read_property
	read_property handler */
static zval *php_runkit_sandbox_parent_read_property(zval *object, zval *member, int type
	, const zend_literal *key)
{
	php_runkit_sandbox_parent_object *objval = PHP_RUNKIT_SANDBOX_PARENT_FETCHBOX(object);
	zval tmp_member;
	zval retval;
	int prop_found = 0;

	if (!objval) {
		return EG(uninitialized_zval_ptr);
	}
	if (!objval->self->parent_access || !objval->self->parent_read) {
		php_error_docref(NULL, E_WARNING, "Access to read parent's symbol table is disallowed");
		return EG(uninitialized_zval_ptr);
	}

	PHP_RUNKIT_ZVAL_CONVERT_TO_STRING_IF_NEEDED(member, tmp_member);

	PHP_RUNKIT_SANDBOX_PARENT_BEGIN(objval)
		zval **value;

		if ((value = zend_hash_str_find(php_runkit_sandbox_parent_resolve_symbol_table(objval), Z_STRVAL_P(member), Z_STRLEN_P(member) + 1)) != NULL) {
			retval = **value;
			prop_found = 1;
		}
	PHP_RUNKIT_SANDBOX_PARENT_END(objval)

	if (member == &tmp_member) {
		zval_dtor(member);
	}

	return php_runkit_sandbox_return_property_value(prop_found, &retval);
}
コード例 #13
0
ファイル: info.c プロジェクト: aerospike/aerospike-client-php
/* Check if a node* pointer is in a php array of host pairs
 * The hosts array will have been validated at this point, so we don't check bounds
 * on any of the individual elements */
static inline bool node_in_hosts_list(const as_node* node, HashTable* hosts_ary) {
	zval* z_host_pair = NULL;
	char host_buffer[AS_HOSTNAME_SIZE] = {0};
	zval* hostname = NULL;
	zval* port = NULL;
	HashTable* host_pair = NULL;

	ZEND_HASH_FOREACH_VAL(hosts_ary, z_host_pair) {
		host_pair = Z_ARRVAL_P(z_host_pair);
		hostname = zend_hash_str_find(host_pair, "addr", strlen("addr"));
		port = zend_hash_str_find(host_pair, "port", strlen("port"));

		snprintf(host_buffer, AS_HOSTNAME_SIZE, "%s:%ld", Z_STRVAL_P(hostname), Z_LVAL_P(port));
		if (!strcmp(host_buffer, as_node_get_address_string((as_node*)node))) {
			return true;
		}
	}ZEND_HASH_FOREACH_END();
コード例 #14
0
ファイル: info.c プロジェクト: aerospike/aerospike-client-php
/*
 * True if the argument is an array of host entries, else false
 * should look like ["hosts"=>[[addr, port]]]
 */
static bool is_valid_hosts_list(HashTable* outer_hosts_ary) {
	HashTable* host_pair = NULL;
	zval* hostname = NULL;
	zval* port = NULL;
	zval* z_host_pair = NULL;

	HashTable* hosts_ary = NULL;
	zval* z_hosts_ary = NULL;
	z_hosts_ary = zend_hash_str_find(outer_hosts_ary, "hosts", strlen("hosts"));
	if (!z_hosts_ary || Z_TYPE_P(z_hosts_ary) != IS_ARRAY) {
		return false;
	}
	hosts_ary = Z_ARRVAL_P(z_hosts_ary);

	/* Each entry should be of the form: ["addr"=> "192.168.1.1", "port"=>4500] *
	 *  return false if one does not match the expected format
	 */
	ZEND_HASH_FOREACH_VAL(hosts_ary, z_host_pair) {
		if (!z_host_pair || Z_TYPE_P(z_host_pair) != IS_ARRAY) {
			return false;
		}
		host_pair = Z_ARRVAL_P(z_host_pair);

		if (zend_hash_num_elements(host_pair) != 2) {
			return false;
		}

		hostname = zend_hash_str_find(host_pair, "addr", strlen("addr"));
		port = zend_hash_str_find(host_pair, "port", strlen("port"));

		if (!hostname || !port) {
			return false;
		}

		if (Z_TYPE_P(hostname) != IS_STRING) {
			return false;
		}

		if (Z_TYPE_P(port) != IS_LONG) {
			return false;
		}
	}ZEND_HASH_FOREACH_END();

	return true;
}
コード例 #15
0
ファイル: zend_ts_hash.c プロジェクト: AxiosCros/php-src
ZEND_API zval *zend_ts_hash_str_find(TsHashTable *ht, const char *key, size_t len)
{
	zval *retval;

	begin_read(ht);
	retval = zend_hash_str_find(TS_HASH(ht), key, len);
	end_read(ht);

	return retval;
}
コード例 #16
0
ファイル: user_filters.c プロジェクト: chosen1/php-src
/* {{{ php_stream_bucket_attach */
static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
{
	zval *zbrigade, *zobject;
	zval *pzbucket, *pzdata;
	php_stream_bucket_brigade *brigade;
	php_stream_bucket *bucket;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "zo", &zbrigade, &zobject) == FAILURE) {
		RETURN_FALSE;
	}

	if (NULL == (pzbucket = zend_hash_str_find(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
		php_error_docref(NULL, E_WARNING, "Object has no bucket property");
		RETURN_FALSE;
	}

	ZEND_FETCH_RESOURCE(brigade, php_stream_bucket_brigade *, zbrigade, -1, PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade);
	ZEND_FETCH_RESOURCE(bucket, php_stream_bucket *, pzbucket, -1, PHP_STREAM_BUCKET_RES_NAME, le_bucket);

	if (NULL != (pzdata = zend_hash_str_find(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) {
		if (!bucket->own_buf) {
			bucket = php_stream_bucket_make_writeable(bucket);
		}
		if ((int)bucket->buflen != Z_STRLEN_P(pzdata)) {
			bucket->buf = perealloc(bucket->buf, Z_STRLEN_P(pzdata), bucket->is_persistent);
			bucket->buflen = Z_STRLEN_P(pzdata);
		}
		memcpy(bucket->buf, Z_STRVAL_P(pzdata), bucket->buflen);
	}

	if (append) {
		php_stream_bucket_append(brigade, bucket);
	} else {
		php_stream_bucket_prepend(brigade, bucket);
	}
	/* This is a hack necessary to accommodate situations where bucket is appended to the stream
 	 * multiple times. See bug35916.phpt for reference.
	 */
	if (bucket->refcount == 1) {
		bucket->refcount++;
	}
}
コード例 #17
0
ファイル: php_ini.c プロジェクト: Tyrael/php-src
/* {{{ cfg_get_string
 */
PHPAPI int cfg_get_string(const char *varname, char **result)
{
	zval *tmp;

	if ((tmp = zend_hash_str_find(&configuration_hash, varname, strlen(varname))) == NULL) {
		*result = NULL;
		return FAILURE;
	}
	*result = Z_STRVAL_P(tmp);
	return SUCCESS;
}
コード例 #18
0
ファイル: spl_heap.c プロジェクト: ECEDBUC/php-src
static zval *spl_pqueue_extract_helper(zval *value, int flags) /* {{{ */
{
	if ((flags & SPL_PQUEUE_EXTR_BOTH) == SPL_PQUEUE_EXTR_BOTH) {
		return value;
	} else if ((flags & SPL_PQUEUE_EXTR_BOTH) > 0) {
		if ((flags & SPL_PQUEUE_EXTR_DATA) == SPL_PQUEUE_EXTR_DATA) {
			zval *data;
			if ((data = zend_hash_str_find(Z_ARRVAL_P(value), "data", sizeof("data") - 1)) != NULL) {
				return data;
			}
		} else {
			zval *priority;
			if ((priority = zend_hash_str_find(Z_ARRVAL_P(value), "priority", sizeof("priority") - 1)) != NULL) {
				return priority;
			}
		}
	}

	return NULL;
}
コード例 #19
0
ファイル: timecop_php7.c プロジェクト: dreamsxin/php-timecop
static int update_request_time(long unixtime)
{
	zval *server_vars, *request_time, tmp;

	server_vars = zend_hash_str_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER")-1);
	if (server_vars != NULL && Z_TYPE_P(server_vars) == IS_ARRAY) {
		request_time = zend_hash_str_find(Z_ARRVAL_P(server_vars), "REQUEST_TIME", sizeof("REQUEST_TIME")-1);
		if (request_time != NULL) {
			if (Z_TYPE(TIMECOP_G(orig_request_time)) == IS_NULL) {
				ZVAL_COPY_VALUE(&TIMECOP_G(orig_request_time), request_time);
			}
		}
		ZVAL_LONG(&tmp, unixtime);
		zend_hash_str_update(Z_ARRVAL_P(server_vars),
							 "REQUEST_TIME", sizeof("REQUEST_TIME")-1,
							 &tmp);
	}

	return SUCCESS;
}
コード例 #20
0
ファイル: php_thrift_protocol7.cpp プロジェクト: apupier/fn
static
void binary_deserialize_spec(zval* zthis, PHPInputTransport& transport, HashTable* spec) {
  // SET and LIST have 'elem' => array('type', [optional] 'class')
  // MAP has 'val' => array('type', [optiona] 'class')
  zend_class_entry* ce = Z_OBJCE_P(zthis);
  while (true) {
    int8_t ttype = transport.readI8();
    if (ttype == T_STOP) {
      validate_thrift_object(zthis);
      return;
    }

    int16_t fieldno = transport.readI16();
    zval* val_ptr = zend_hash_index_find(spec, fieldno);
    if (val_ptr != nullptr) {
      HashTable* fieldspec = Z_ARRVAL_P(val_ptr);
      // pull the field name
      val_ptr = zend_hash_str_find(fieldspec, "var", sizeof("var")-1);
      char* varname = Z_STRVAL_P(val_ptr);

      // and the type
      val_ptr = zend_hash_str_find(fieldspec, "type", sizeof("type")-1);
      if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr);
      int8_t expected_ttype = Z_LVAL_P(val_ptr);

      if (ttypes_are_compatible(ttype, expected_ttype)) {
        zval rv;
        ZVAL_UNDEF(&rv);

        binary_deserialize(ttype, transport, &rv, fieldspec);
        zend_update_property(ce, zthis, varname, strlen(varname), &rv);

        zval_ptr_dtor(&rv);
      } else {
        skip_element(ttype, transport);
      }
    } else {
      skip_element(ttype, transport);
    }
  }
}
コード例 #21
0
ファイル: multicast.c プロジェクト: LTD-Beget/php-src
static int php_get_if_index_from_array(const HashTable *ht, const char *key,
	php_socket *sock, unsigned int *if_index)
{
	zval *val;

	if ((val = zend_hash_str_find(ht, key, strlen(key))) == NULL) {
		*if_index = 0; /* default: 0 */
		return SUCCESS;
	}

	return php_get_if_index_from_zval(val, if_index);
}
コード例 #22
0
static int oauth_provider_add_required_param(HashTable *ht, char *required_param) /* {{{ */
{
	zval zparam, *dest_entry;

	if((dest_entry = zend_hash_str_find(ht, required_param, strlen(required_param))) == NULL) {
		ZVAL_NULL(&zparam);
		if(zend_hash_str_add(ht, required_param, strlen(required_param), &zparam) == NULL) {
			return FAILURE;
		}
	}
	return SUCCESS;
}
コード例 #23
0
static char *oauth_provider_get_current_uri()
{
	zval *host, *port, *uri, *proto, *https;

	zend_is_auto_global_str("_SERVER", sizeof("_SERVER")-1);

	host = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_HOST", sizeof("HTTP_HOST") - 1);
	port = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "SERVER_PORT", sizeof("SERVER_PORT") - 1);
	uri = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI") - 1);
	proto = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_X_FORWARDED_PROTO", sizeof("HTTP_X_FORWARDED_PROTO") - 1);
	https = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTPS", sizeof("HTTPS") - 1);

	if (host && port && uri)
	{
		char *tmp,*hostname,*colon_in_hostname;

		spprintf(&hostname, 0, "%s", Z_STRVAL_P(host));
		colon_in_hostname=strrchr(hostname,':');
		if(colon_in_hostname && ((https && Z_LVAL_P(port)==443) || (!https && Z_LVAL_P(port)==80)))
		{
			*colon_in_hostname=0;
		}
		if(proto && Z_STRLEN_P(proto))
		{
			spprintf(&tmp, 0, "%s://%s%s", Z_STRVAL_P(proto), hostname, Z_STRVAL_P(uri));
		}
		else if(https && Z_STRLEN_P(https)>0 && strcasecmp(Z_STRVAL_P(https),"off")!=0)
		{
			spprintf(&tmp, 0, "https://%s%s", hostname, Z_STRVAL_P(uri));
		}
		else
		{
			spprintf(&tmp, 0, "http://%s%s", hostname, Z_STRVAL_P(uri));
		}
		efree(hostname);
		return tmp;
	}

	return NULL;
}
コード例 #24
0
ファイル: php_ini.c プロジェクト: Tyrael/php-src
/* {{{ cfg_get_double
 */
PHPAPI int cfg_get_double(const char *varname, double *result)
{
	zval *tmp, var;

	if ((tmp = zend_hash_str_find(&configuration_hash, varname, strlen(varname))) == NULL) {
		*result = (double) 0;
		return FAILURE;
	}
	ZVAL_DUP(&var, tmp);
	convert_to_double(&var);
	*result = Z_DVAL(var);
	return SUCCESS;
}
コード例 #25
0
ファイル: incomplete_class.c プロジェクト: Jille/php-src
/* {{{ php_lookup_class_name
 */
PHPAPI zend_string *php_lookup_class_name(zval *object)
{
	zval *val;
	HashTable *object_properties;

	object_properties = Z_OBJPROP_P(object);

	if ((val = zend_hash_str_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1)) != NULL) {
		return zend_string_copy(Z_STR_P(val));
	}

	return NULL;
}
コード例 #26
0
ファイル: channel.c プロジェクト: stanley-cheung/grpc-php7
/**
 * 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);
}
コード例 #27
0
ファイル: timecop_php7.c プロジェクト: dreamsxin/php-timecop
static int restore_request_time()
{
	zval *server_vars, *request_time, orig_request_time;

	server_vars = zend_hash_str_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER")-1);
	if (Z_TYPE(TIMECOP_G(orig_request_time)) != IS_NULL &&
		server_vars != NULL && Z_TYPE_P(server_vars) == IS_ARRAY) {
		zend_hash_str_update(Z_ARRVAL_P(server_vars),
							 "REQUEST_TIME", sizeof("REQUEST_TIME")-1,
							 &TIMECOP_G(orig_request_time));
		ZVAL_NULL(&TIMECOP_G(orig_request_time));
	}

	return SUCCESS;
}
コード例 #28
0
ファイル: url_scanner_ex.c プロジェクト: LTD-Beget/php-src
static int check_http_host(char *target)
{
	zval *host, *tmp;
	zend_string *host_tmp;
	char *colon;

	if ((tmp  = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER"))) &&
		(host = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("HTTP_HOST"))) &&
		Z_TYPE_P(host) == IS_STRING) {
		host_tmp = zend_string_init(Z_STRVAL_P(host), Z_STRLEN_P(host), 0);
		/* HTTP_HOST could be 'localhost:8888' etc. */
		colon = strchr(ZSTR_VAL(host_tmp), ':');
		if (colon) {
			ZSTR_LEN(host_tmp) = colon - ZSTR_VAL(host_tmp);
			ZSTR_VAL(host_tmp)[ZSTR_LEN(host_tmp)] = '\0';
		}
		if (!strcasecmp(ZSTR_VAL(host_tmp), target)) {
			zend_string_release(host_tmp);
			return SUCCESS;
		}
		zend_string_release(host_tmp);
	}
	return FAILURE;
}
コード例 #29
0
ファイル: php_thrift_protocol7.cpp プロジェクト: apupier/fn
//is used to validate objects before serialization and after deserialization. For now, only required fields are validated.
static
void validate_thrift_object(zval* object) {
    zend_class_entry* object_class_entry = Z_OBJCE_P(object);
    zval* is_validate = zend_read_static_property(object_class_entry, "isValidate", sizeof("isValidate")-1, false);
    zval* spec = zend_read_static_property(object_class_entry, "_TSPEC", sizeof("_TSPEC")-1, false);
    HashPosition key_ptr;
    zval* val_ptr;

    if (Z_TYPE_INFO_P(is_validate) == IS_TRUE) {
        for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(spec), &key_ptr);
           (val_ptr = zend_hash_get_current_data_ex(Z_ARRVAL_P(spec), &key_ptr)) != nullptr;
           zend_hash_move_forward_ex(Z_ARRVAL_P(spec), &key_ptr)) {

            zend_ulong fieldno;
            if (zend_hash_get_current_key_ex(Z_ARRVAL_P(spec), nullptr, &fieldno, &key_ptr) != HASH_KEY_IS_LONG) {
              throw_tprotocolexception("Bad keytype in TSPEC (expected 'long')", INVALID_DATA);
              return;
            }
            HashTable* fieldspec = Z_ARRVAL_P(val_ptr);

            // field name
            zval* zvarname = zend_hash_str_find(fieldspec, "var", sizeof("var")-1);
            char* varname = Z_STRVAL_P(zvarname);

            zval* is_required = zend_hash_str_find(fieldspec, "isRequired", sizeof("isRequired")-1);
            zval rv;
            zval* prop = zend_read_property(object_class_entry, object, varname, strlen(varname), false, &rv);

            if (Z_TYPE_INFO_P(is_required) == IS_TRUE && Z_TYPE_P(prop) == IS_NULL) {
                char errbuf[128];
                snprintf(errbuf, 128, "Required field %s.%s is unset!", ZSTR_VAL(object_class_entry->name), varname);
                throw_tprotocolexception(errbuf, INVALID_DATA);
            }
        }
    }
}
コード例 #30
0
ファイル: com_com.c プロジェクト: AmesianX/php-src
/* map an ID to a name */
HRESULT php_com_get_id_of_name(php_com_dotnet_object *obj, char *name,
		size_t namelen, DISPID *dispid)
{
	OLECHAR *olename;
	HRESULT hr;
	zval *tmp;

	if (namelen == -1) {
		namelen = strlen(name);
	}

	if (obj->id_of_name_cache && NULL != (tmp = zend_hash_str_find(obj->id_of_name_cache, name, namelen))) {
		*dispid = (DISPID)Z_LVAL_P(tmp);
		return S_OK;
	}
	
	olename = php_com_string_to_olestring(name, namelen, obj->code_page);

	if (obj->typeinfo) {
		hr = ITypeInfo_GetIDsOfNames(obj->typeinfo, &olename, 1, dispid);
		if (FAILED(hr)) {
			hr = IDispatch_GetIDsOfNames(V_DISPATCH(&obj->v), &IID_NULL, &olename, 1, LOCALE_SYSTEM_DEFAULT, dispid);
			if (SUCCEEDED(hr)) {
				/* fall back on IDispatch direct */
				ITypeInfo_Release(obj->typeinfo);
				obj->typeinfo = NULL;
			}
		}
	} else {
		hr = IDispatch_GetIDsOfNames(V_DISPATCH(&obj->v), &IID_NULL, &olename, 1, LOCALE_SYSTEM_DEFAULT, dispid);
	}
	efree(olename);

	if (SUCCEEDED(hr)) {
		zval tmp;

		/* cache the mapping */
		if (!obj->id_of_name_cache) {
			ALLOC_HASHTABLE(obj->id_of_name_cache);
			zend_hash_init(obj->id_of_name_cache, 2, NULL, NULL, 0);
		}
		ZVAL_LONG(&tmp, *dispid);
		zend_hash_str_update(obj->id_of_name_cache, name, namelen, &tmp);
	}
	
	return hr;
}