Esempio n. 1
0
/* {{{ 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++;
	}
}
Esempio n. 2
0
static inline int msgpack_convert_string_to_properties(zval *object, zend_string *key, zval *val, HashTable *var)/* {{{ */ {
    zend_class_entry *ce = Z_OBJCE_P(object);
    HashTable *propers = Z_OBJPROP_P(object);
    zend_string *prot_name, *priv_name;
    zval pub_name;
    int return_code;

    ZVAL_STR(&pub_name, key);
    priv_name = zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(key), ZSTR_LEN(key), 1);
    prot_name = zend_mangle_property_name("*", 1, ZSTR_VAL(key), ZSTR_LEN(key), 1);

    if (zend_hash_find(propers, priv_name) != NULL) {
        zend_update_property_ex(ce, object, key, val);
        return_code = SUCCESS;
    } else if (zend_hash_find(propers, prot_name) != NULL) {
        zend_update_property_ex(ce, object, key, val);
        return_code = SUCCESS;
    } else {
        zend_std_write_property(object, &pub_name, val, NULL);
        return_code = FAILURE;
    }
    zend_hash_add(var, Z_STR(pub_name), val);

    zend_string_release(priv_name);
    zend_string_release(prot_name);

    return return_code;
}
Esempio n. 3
0
static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements)
{
	zval retval;
	zval fname;
	HashTable *ht;

	if (Z_TYPE_P(rval) != IS_OBJECT) {
		return 0;
	}

	ht = Z_OBJPROP_P(rval);
	zend_hash_extend(ht, zend_hash_num_elements(ht) + elements, (ht->u.flags & HASH_FLAG_PACKED));
	if (!process_nested_data(UNSERIALIZE_PASSTHRU, ht, elements, 1)) {
		return 0;
	}

	ZVAL_DEREF(rval);
	if (Z_OBJCE_P(rval) != PHP_IC_ENTRY &&
		zend_hash_str_exists(&Z_OBJCE_P(rval)->function_table, "__wakeup", sizeof("__wakeup")-1)) {
		ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1);
		BG(serialize_lock)++;
		call_user_function_ex(CG(function_table), rval, &fname, &retval, 0, 0, 1, NULL);
		BG(serialize_lock)--;
		zval_dtor(&fname);
		zval_dtor(&retval);
	}

	if (EG(exception)) {
		return 0;
	}

	return finish_nested_data(UNSERIALIZE_PASSTHRU);

}
/* {{{ proto ProtocolBuffers\EnumDescriptor ProtocolBuffersDescriptorBuilder::build()
*/
PHP_METHOD(protocolbuffers_enum_descriptor_builder, build)
{
	zval *result, *container, **fields, **entry, *key, *value;
	char *property;
	int property_len;
	HashPosition pos;

	MAKE_STD_ZVAL(result);
	object_init_ex(result, php_protocol_buffers_enum_descriptor_class_entry);

	MAKE_STD_ZVAL(container);
	array_init(container);

	zend_mangle_property_name(&property, &property_len, (char*)"*", 1, (char*)ZEND_STRS("values"), 0);
	if (zend_hash_find(Z_OBJPROP_P(getThis()), property, property_len, (void **)&fields) == SUCCESS) {
		zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(fields), &pos);
		while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(fields), (void **)&entry, &pos) == SUCCESS) {
			zval *tmp = NULL;

			MAKE_STD_ZVAL(tmp);

			php_protocolbuffers_read_protected_property(*entry, ZEND_STRS("name"), &key TSRMLS_CC);
			php_protocolbuffers_read_protected_property(*entry, ZEND_STRS("value"), &value TSRMLS_CC);

			ZVAL_ZVAL(tmp, value, 1, 0);
			zend_hash_update(Z_ARRVAL_P(container), Z_STRVAL_P(key), Z_STRLEN_P(key), &tmp, sizeof(zval), NULL);
			zend_hash_move_forward_ex(Z_ARRVAL_PP(fields), &pos);
		}
	}
	efree(property);

	php_protocolbuffers_set_protected_property(result, ZEND_STRS("values"), container TSRMLS_CC);
	RETURN_ZVAL(result, 0, 1);
}
Esempio n. 5
0
File: berg.c Progetto: henryzxj/berg
/* {{{ proto ProtocolBuffers_DescriptorBuilder ProtocolBuffers_DescriptorBuilder::__construct()
*/
PHP_METHOD(berg_buffers, __construct)
{
	zval *instance = getThis();
	zval fields,options,extension_ranges,*tmp;
	array_init(&fields);
	add_next_index_double(&fields,42.00);
	add_next_index_long(&fields,42);
	php_var_dump(&fields,1);
	zend_update_property(Z_OBJCE_P(instance),instance,ZEND_STRL("fields"),&fields);
	zval_ptr_dtor(&fields);

//	array_init(&options);
//	zend_update_property(berg_buffers_class_entry,instance,ZEND_STRL("options"),&options);
//	zval_ptr_dtor(&options);
//
//	array_init(&extension_ranges);
//	zend_update_property(berg_buffers_class_entry,instance,ZEND_STRL("extension_ranges"),&extension_ranges);
//	zval_ptr_dtor(&extension_ranges);

	zend_string *key = zend_string_init(ZEND_STRL("fields"),0);
	if((tmp=zend_hash_find(Z_OBJPROP_P(instance), key))!=NULL){
		php_var_dump(tmp,1);
	}
	zend_string_release(key);
	//>gdb
	//(gdb) p fields1->u2
	//$1 = {var_flags = 4294967295, next = 4294967295, cache_slot = 4294967295, lineno = 4294967295, num_args = 4294967295, fe_pos = 4294967295, fe_iter_idx = 4294967295}
	//(gdb) p fields1->value->arr->nNumUsed
	//$4 = 1
	//(gdb) p fields1->value->arr->nTableSize
	//$5 = 4294956704
	//(gdb) p fields1->value->arr->nNumOfElements
	//$6 = 0
}
Esempio n. 6
0
	SharedValue KPHPObject::Get(const char *name)
	{
		zval** zPropertyPtr;
		unsigned int nameLength = strlen(name);
		TSRMLS_FETCH();

		// First try to get the property via the read_property handler.
		if (this->PropertyExists(name TSRMLS_CC) && Z_OBJ_HANDLER_P(object, read_property))
		{
			zval zname;
			ZVAL_STRINGL(&zname, name, nameLength, 0);

			// Use the read_property handler in the class.
			zval* zProperty = Z_OBJ_HANDLER_P(object, read_property)(
				object, &zname, 2 TSRMLS_CC);

			return PHPUtils::ToKrollValue(zProperty TSRMLS_CC);

		} // Next just try reading it from the properties hash.
		else if (zend_hash_find(Z_OBJPROP_P(object),
			name, nameLength + 1, (void**) &zPropertyPtr) != FAILURE)
		{
			return PHPUtils::ToKrollValue(*zPropertyPtr TSRMLS_CC);

		} // Check if the method exists on the object
		else if (this->MethodExists(name TSRMLS_CC))
		{
			return Value::NewMethod(new KPHPMethod(object, name));
		}
		else
		{
			return Value::Undefined;
		}
	}
/* {{{ proto void ProtocolBuffersDescriptorBuilder::addValue(ProtocolBuffers\EnumValueDescriptor $value[, bool $force = false])
*/
PHP_METHOD(protocolbuffers_enum_descriptor_builder, addValue)
{
	zval *instance = getThis();
	zval *value, **fields, *name;
	zend_bool force = 0;
	char *property;
	int property_len;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"O|b", &value, php_protocol_buffers_enum_value_descriptor_class_entry, &force) == FAILURE) {
		return;
	}

	zend_mangle_property_name(&property, &property_len, (char*)"*", 1, (char*)ZEND_STRS("values"), 0);
	if (zend_hash_find(Z_OBJPROP_P(instance), property, property_len, (void **)&fields) == SUCCESS) {
		if (php_protocolbuffers_read_protected_property(value, ZEND_STRS("name"), &name TSRMLS_CC)) {
			if (zend_hash_exists(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name))) {
				if (force < 1) {
					zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "name `%s` has already registered.", Z_STRVAL_P(name));
				}
				efree(property);
				return;
			}
		}

		Z_ADDREF_P(value);
		zend_hash_update(Z_ARRVAL_PP(fields), Z_STRVAL_P(name), Z_STRLEN_P(name)+1, &value, sizeof(zval), NULL);
	}
	efree(property);

}
/* {{{ proto ProtocolBuffers\EnumDescriptor ProtocolBuffersDescriptorBuilder::build()
*/
PHP_METHOD(protocolbuffers_enum_descriptor_builder, build)
{
	zval *result, *container, *fields, *entry, *key, *value;
	char *property;
	int property_len;
	HashPosition pos;

//	MAKE_STD_ZVAL(result);
	object_init_ex(result, php_protocol_buffers_enum_descriptor_class_entry);

//	MAKE_STD_ZVAL(container);
	array_init(container);

	zend_string *property_key = zend_mangle_property_name((char*)"*", 1, ZEND_STRL("values"), 0);
	if ((fields=zend_hash_find(Z_OBJPROP_P(getThis()), property_key)) != NULL) {
		zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(fields), &pos);
		while ((entry=zend_hash_get_current_data_ex(Z_ARRVAL_P(fields), &pos)) != NULL) {
			zval *tmp = NULL;

//			MAKE_STD_ZVAL(tmp);

			php_protocolbuffers_read_protected_property(entry, ZEND_STRL("name"), &key TSRMLS_CC);
			php_protocolbuffers_read_protected_property(entry, ZEND_STRL("value"), &value TSRMLS_CC);

			ZVAL_ZVAL(tmp, value, 1, 0);
			zend_string *key_name = zend_string_init(Z_STRVAL_P(key),Z_STRLEN_P(key),0);
			zend_hash_update(Z_ARRVAL_P(container), key_name, tmp);
			zend_hash_move_forward_ex(Z_ARRVAL_P(fields), &pos);
		}
	}
	efree(property);

	php_protocolbuffers_set_protected_property(result, ZEND_STRL("values"), container TSRMLS_CC);
	RETURN_ZVAL(result, 0, 1);
}
/* {{{ proto void ProtocolBuffersDescriptorBuilder::addValue(ProtocolBuffers\EnumValueDescriptor $value[, bool $force = false])
*/
PHP_METHOD(protocolbuffers_enum_descriptor_builder, addValue)
{
	zval *instance = getThis();
	zval *value, *fields, *name;
	zend_bool force = 0;
//	char *property;
	int property_len;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"O|b", &value, php_protocol_buffers_enum_value_descriptor_class_entry, &force) == FAILURE) {
		return;
	}

	zend_string *property_key = zend_mangle_property_name((char*)"*", 1, (char*)ZEND_STRL("values"), 0);
	if ((fields=zend_hash_find(Z_OBJPROP_P(instance), property_key)) != NULL) {
		if (php_protocolbuffers_read_protected_property(value, ZEND_STRL("name"), &name TSRMLS_CC)) {
			zend_string *name_key = zend_string_init(Z_STRVAL_P(name), Z_STRLEN_P(name),0);
			if (zend_hash_exists(Z_ARRVAL_P(fields), name_key)) {
				if (force < 1) {
					zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "name `%s` has already registered.", Z_STRVAL_P(name));
				}
				zend_string_release(property_key);
				zend_string_release(name_key);
				return;
			}
		}

		Z_ADDREF_P(value);
		zend_string *name_key = zend_string_init(Z_STRVAL_P(name), Z_STRLEN_P(name)+1,0);
		zend_hash_update(Z_ARRVAL_P(fields), name_key, value);
		zend_string_release(name_key);
	}
	zend_string_release(property_key);

}
Esempio n. 10
0
static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements)
{
	zval retval;
	zval fname;

	if (Z_TYPE_P(rval) != IS_OBJECT) {
		return 0;
	}

	//??? TODO: resize before
	if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_P(rval), elements, 1)) {
		return 0;
	}

	ZVAL_DEREF(rval);
	if (Z_OBJCE_P(rval) != PHP_IC_ENTRY &&
		zend_hash_str_exists(&Z_OBJCE_P(rval)->function_table, "__wakeup", sizeof("__wakeup")-1)) {
		ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1);
		BG(serialize_lock)++;
		call_user_function_ex(CG(function_table), rval, &fname, &retval, 0, 0, 1, NULL);
		BG(serialize_lock)--;
		zval_dtor(&fname);
		zval_dtor(&retval);
	}

	if (EG(exception)) {
		return 0;
	}

	return finish_nested_data(UNSERIALIZE_PASSTHRU);

}
Esempio n. 11
0
/* {{{ php_store_class_name
 */
PHPAPI void php_store_class_name(zval *object, const char *name, size_t len)
{
	zval val;


	ZVAL_STRINGL(&val, name, len);
	zend_hash_str_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1, &val);
}
Esempio n. 12
0
File: php_xio.c Progetto: tniuli/xio
ZEND_METHOD (Msg, __construct2)
{
	zval *hdr = 0;

	ALLOC_ZVAL (hdr);
	object_init_ex (hdr, msghdr_ce);

	if (zend_hash_update (Z_OBJPROP_P (getThis ()), "hdr", sizeof ("hdr"), &hdr, sizeof (hdr), 0) == FAILURE)
		BUG_ON (1);
}
Esempio n. 13
0
/* {{{ 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++;
	}
}
Esempio n. 14
0
ZEND_METHOD(YConsistent,consistent_end){
	zval *object = getThis();
	zval **conhash_prop;
	if(zend_hash_find(Z_OBJPROP_P(object),"conhash",sizeof("conhash"),(void **)&conhash_prop) == FAILURE){
		RETURN_NULL();
	}
	if(zend_list_delete(Z_LVAL_PP(conhash_prop)) == FAILURE){
		RETURN_FALSE;
	}
	RETURN_TRUE;
}
Esempio n. 15
0
/**
 * @zobject: swoole_client object
 */
static int php_swoole_client_close(zval *zobject, int fd TSRMLS_DC)
{
	zval *zcallback = NULL;
	zval *retval;
	zval **args[1];
	swClient *cli;
	zval **zres;

	if (zend_hash_find(Z_OBJPROP_P(zobject), SW_STRL("_client"), (void **) &zres) == SUCCESS)
	{
		ZEND_FETCH_RESOURCE_NO_RETURN(cli, swClient*, zres, -1, SW_RES_CLIENT_NAME, le_swoole_client);
	}
Esempio n. 16
0
File: php_xio.c Progetto: tniuli/xio
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);
	}
}
Esempio n. 17
0
/* {{{ 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;
}
/* {{{ proto void ProtocolBuffersPHPMessageOptions::setSinglePropertyName(string $name)
*/
PHP_METHOD(protocolbuffers_php_message_options, setSinglePropertyName)
{
	zval *instance = getThis();
	zval **target;
	char *value;
	long value_len;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"s", &value, &value_len) == FAILURE) {
		return;
	}


	if (zend_hash_find(Z_OBJPROP_P(instance), "single_property_name", sizeof("single_property_name"), (void **)&target) == SUCCESS) {
		zval *tmp;

		MAKE_STD_ZVAL(tmp);
		ZVAL_STRING(tmp, value, 1);

		zend_hash_update(Z_OBJPROP_P(instance), "single_property_name", sizeof("single_property_name"), (void **)&tmp, sizeof(zval*), NULL);
	}
}
Esempio n. 19
0
ZEND_METHOD(YConsistent,add_server){
	char *host;
	int host_len,port,weight;
	zval *object = getThis();
	zval **conhash_prop;
	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"sll",&host,&host_len,&port,&weight) == FAILURE){
		return;
	}
	if(zend_hash_find(Z_OBJPROP_P(object),"conhash",sizeof("conhash"),(void **)&conhash_prop) == FAILURE){
		RETURN_NULL();
	} 
	conhash *con = zend_list_find(Z_LVAL_PP(conhash_prop),&le_conhash);
	conhash_add_server(host,port,weight,con);
}
Esempio n. 20
0
ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
{
	switch (Z_TYPE_P(expr)) {
		case IS_ARRAY:
			ZEND_PUTS("Array (");
			if (Z_REFCOUNTED_P(expr)) {
				if (Z_IS_RECURSIVE_P(expr)) {
					ZEND_PUTS(" *RECURSION*");
					return;
				}
				Z_PROTECT_RECURSION_P(expr);
			}
			print_flat_hash(Z_ARRVAL_P(expr));
			ZEND_PUTS(")");
			if (Z_REFCOUNTED_P(expr)) {
				Z_UNPROTECT_RECURSION_P(expr);
			}
			break;
		case IS_OBJECT:
		{
			HashTable *properties = NULL;
			zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
			zend_printf("%s Object (", ZSTR_VAL(class_name));
			zend_string_release(class_name);

			if (Z_IS_RECURSIVE_P(expr)) {
				ZEND_PUTS(" *RECURSION*");
				return;
			}

			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
				properties = Z_OBJPROP_P(expr);
			}
			if (properties) {
				Z_PROTECT_RECURSION_P(expr);
				print_flat_hash(properties);
				Z_UNPROTECT_RECURSION_P(expr);
			}
			ZEND_PUTS(")");
			break;
		}
		case IS_REFERENCE:
			zend_print_flat_zval_r(Z_REFVAL_P(expr));
			break;
		default:
			zend_print_variable(expr);
			break;
	}
}
/* {{{ proto void ProtocolBuffersPHPMessageOptions::setProcessUnknownFields(boolean $use)
*/
PHP_METHOD(protocolbuffers_php_message_options, setProcessUnknownFields)
{
	zval *instance = getThis();
	zval **target;
	long value;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"l", &value) == FAILURE) {
		return;
	}

	if (zend_hash_find(Z_OBJPROP_P(instance), "process_unknown_fields", sizeof("process_unknown_fields"), (void **)&target) == SUCCESS) {
		ZVAL_BOOL(*target, value);
	}
}
Esempio n. 22
0
ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
{
	switch (Z_TYPE_P(expr)) {
		case IS_ARRAY:
			ZEND_PUTS("Array (");
			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
				ZEND_PUTS(" *RECURSION*");
				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
				return;
			}
			print_flat_hash(Z_ARRVAL_P(expr));
			ZEND_PUTS(")");
			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
			}
			break;
		case IS_OBJECT:
		{
			HashTable *properties = NULL;
			zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
			zend_printf("%s Object (", ZSTR_VAL(class_name));
			zend_string_release(class_name);

			if (Z_OBJ_APPLY_COUNT_P(expr) > 0) {
				ZEND_PUTS(" *RECURSION*");
				return;
			}

			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
				properties = Z_OBJPROP_P(expr);
			}
			if (properties) {
				Z_OBJ_INC_APPLY_COUNT_P(expr);
				print_flat_hash(properties);
				Z_OBJ_DEC_APPLY_COUNT_P(expr);
			}
			ZEND_PUTS(")");
			break;
		}
		case IS_REFERENCE:
			zend_print_flat_zval_r(Z_REFVAL_P(expr));
			break;
		default:
			zend_print_variable(expr);
			break;
	}
}
/* {{{ proto void ProtocolBuffersPHPMessageOptions::setUseSingleProperty(boolean $use)
*/
PHP_METHOD(protocolbuffers_php_message_options, setUseSingleProperty)
{

	zval *instance = getThis();
	zval **target;
	long value;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"l", &value) == FAILURE) {
		return;
	}

	if (zend_hash_find(Z_OBJPROP_P(instance), "use_single_property", sizeof("use_single_property"), (void **)&target) == SUCCESS) {
		ZVAL_BOOL(*target, value);
	}
}
Esempio n. 24
0
PHP_METHOD(pdo_connect_pool_PDOStatement, __call) {
    zval *z_args;
    zval *object;
    zval *pass_data;
    zval **zres, **source_zval;

    char *cmd;
    int cmd_len;

    if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa", &object, pdo_connect_pool_PDOStatement_class_entry_ptr, &cmd, &cmd_len, &z_args) == FAILURE) {
        RETURN_FALSE;
    }

    cpClient *cli;
    if (zend_hash_find(Z_OBJPROP_P(getThis()), ZEND_STRS("cli"), (void **) &zres) == SUCCESS) {
        ZEND_FETCH_RESOURCE(cli, cpClient*, zres, -1, CP_RES_CLIENT_NAME, le_cli_connect_pool);
    } else {
Esempio n. 25
0
ZEND_METHOD(YConsistent,find_server){
	char *key;
	char *return_key;
	int key_len;
	zval *object = getThis();
	zval **conhash_prop;
	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s",&key,&key_len) == FAILURE){
		return;
	}
	if(zend_hash_find(Z_OBJPROP_P(object),"conhash",sizeof("conhash"),(void **)&conhash_prop) == FAILURE){
		RETURN_NULL();
	}
	conhash *con = zend_list_find(Z_LVAL_PP(conhash_prop),&le_conhash);
	cnode *node = conhash_find_server(key,key_len,con);
	array_init(return_value);
	add_assoc_string(return_value,"host",node->server.host,1);
	add_assoc_long(return_value,"port",node->server.port);
}
Esempio n. 26
0
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");
    }
}
Esempio n. 27
0
static void release_worker(zval *object)
{
    zend_rsrc_list_entry *p_sock_le;
    zval **pool_port;
    if (zend_hash_find(Z_OBJPROP_P(object), ZEND_STRS("pool_port"), (void **) &pool_port) == SUCCESS)
    {
        char str[100] = {0};
        CON_FORMART_KEY(str, (int) Z_LVAL_PP(pool_port));
        if (zend_hash_find(&EG(persistent_list), str, strlen(str), (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, "pool_port can not find");
    }
}
Esempio n. 28
0
/* {{{ pip_pyobject_to_zobject(PyObject *obj)
   Convert Python object to a PHP (Zend) object */
zval *
pip_pyobject_to_zobject(PyObject *obj)
{
	pval *ret;
	zval *handle;
	TSRMLS_FETCH();

	/* Create a PHP Python object */
	MAKE_STD_ZVAL(ret);
	object_init_ex(ret, &python_class_entry);
	ret->is_ref = 1;
	ret->refcount = 1;

	/* Assign the current PyObject to the new PHP Python object */
	ALLOC_ZVAL(handle);
	ZVAL_RESOURCE(handle, zend_list_insert(obj, le_pyobject));
	zval_copy_ctor(handle);
	INIT_PZVAL(handle);
	zend_hash_index_update(Z_OBJPROP_P(ret), 0, &handle, sizeof(zval *), NULL);

	return ret;
}
Esempio n. 29
0
static void php_bencode_encode_array(smart_str *buf, zval *val) /* {{{ */
{
	int num_elements = 0;
	char mode;
	HashTable *ht;
	
	if (Z_TYPE_P(val) == IS_ARRAY) {
		ht = Z_ARRVAL_P(val);
	} else {
		ht = Z_OBJPROP_P(val);
		mode = PHP_BENCODE_TYPE_DICTIONARY;
	}
	if (ht && ZEND_HASH_GET_APPLY_COUNT(ht) > 1) {
		zend_error(E_WARNING, "recursion detected");
		return;
	}
	num_elements = ht ? zend_hash_num_elements(ht) : 0;
	if (Z_TYPE_P(val) == IS_ARRAY) {
		if (num_elements > 0) {
			zend_string *key;
			zend_ulong index, idx;

			idx = 0;
			mode = PHP_BENCODE_TYPE_LIST;
			ZEND_HASH_FOREACH_KEY(ht, index, key) {
				if (key) {
					mode = PHP_BENCODE_TYPE_DICTIONARY;
					break;
				} else {
					if (index != idx) {
						mode = PHP_BENCODE_TYPE_DICTIONARY;
						break;
					}
				}
				idx++;
			} ZEND_HASH_FOREACH_END();
		}else{
Esempio n. 30
0
static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements)
{
	HashTable *ht;
	zend_bool has_wakeup;

	if (Z_TYPE_P(rval) != IS_OBJECT) {
		return 0;
	}

	has_wakeup = Z_OBJCE_P(rval) != PHP_IC_ENTRY
		&& zend_hash_str_exists(&Z_OBJCE_P(rval)->function_table, "__wakeup", sizeof("__wakeup")-1);

	ht = Z_OBJPROP_P(rval);
	if (elements >= (zend_long)(HT_MAX_SIZE - zend_hash_num_elements(ht))) {
		return 0;
	}

	zend_hash_extend(ht, zend_hash_num_elements(ht) + elements, (ht->u.flags & HASH_FLAG_PACKED));
	if (!process_nested_data(UNSERIALIZE_PASSTHRU, ht, elements, 1)) {
		if (has_wakeup) {
			ZVAL_DEREF(rval);
			GC_FLAGS(Z_OBJ_P(rval)) |= IS_OBJ_DESTRUCTOR_CALLED;
		}
		return 0;
	}

	ZVAL_DEREF(rval);
	if (has_wakeup) {
		/* Delay __wakeup call until end of serialization */
		zval *wakeup_var = var_tmp_var(var_hash);
		ZVAL_COPY(wakeup_var, rval);
		Z_EXTRA_P(wakeup_var) = VAR_WAKEUP_FLAG;
	}

	return finish_nested_data(UNSERIALIZE_PASSTHRU);
}