Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
static zend_constant *zend_get_special_constant(const char *name, size_t name_len)
{
	zend_constant *c;
	static char haltoff[] = "__COMPILER_HALT_OFFSET__";

	if (!EG(current_execute_data)) {
		return NULL;
	} else if (name_len == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
	          !memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1)) {
		const char *cfilename;
		zend_string *haltname;
		size_t clen;

		cfilename = zend_get_executed_filename();
		clen = strlen(cfilename);
		/* check for __COMPILER_HALT_OFFSET__ */
		haltname = zend_mangle_property_name(haltoff,
			sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
		c = zend_hash_find_ptr(EG(zend_constants), haltname);
		zend_string_free(haltname);
		return c;
	} else {
		return NULL;
	}
}
/* {{{ 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);
}
/* {{{ 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);

}
Ejemplo n.º 7
0
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;
}
zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script, int from_shared_memory)
{
	zend_op_array *op_array;

	op_array = (zend_op_array *) emalloc(sizeof(zend_op_array));
	*op_array = persistent_script->main_op_array;

	if (EXPECTED(from_shared_memory)) {
		zend_hash_init(&ZCG(bind_hash), 10, NULL, NULL, 0);

		ZCG(current_persistent_script) = persistent_script;
		ZCG(arena_mem) = NULL;
		if (EXPECTED(persistent_script->arena_size)) {
#ifdef __SSE2__
			/* Target address must be aligned to 64-byte boundary */
			ZCG(arena_mem) = zend_arena_alloc(&CG(arena), persistent_script->arena_size + 64);
			ZCG(arena_mem) = (void*)(((zend_uintptr_t)ZCG(arena_mem) + 63L) & ~63L);
			fast_memcpy(ZCG(arena_mem), persistent_script->arena_mem, persistent_script->arena_size);
#else
			ZCG(arena_mem) = zend_arena_alloc(&CG(arena), persistent_script->arena_size);
			memcpy(ZCG(arena_mem), persistent_script->arena_mem, persistent_script->arena_size);
#endif
		}

		/* Copy all the necessary stuff from shared memory to regular memory, and protect the shared script */
		if (zend_hash_num_elements(&persistent_script->class_table) > 0) {
			zend_accel_class_hash_copy(CG(class_table), &persistent_script->class_table, (unique_copy_ctor_func_t) zend_class_copy_ctor);
		}
		/* we must first to copy all classes and then prepare functions, since functions may try to bind
		   classes - which depend on pre-bind class entries existent in the class table */
		if (zend_hash_num_elements(&persistent_script->function_table) > 0) {
			zend_accel_function_hash_copy_from_shm(CG(function_table), &persistent_script->function_table);
		}

		/* Register __COMPILER_HALT_OFFSET__ constant */
		if (persistent_script->compiler_halt_offset != 0 &&
		    persistent_script->full_path) {
			zend_string *name;
			char haltoff[] = "__COMPILER_HALT_OFFSET__";

			name = zend_mangle_property_name(haltoff, sizeof(haltoff) - 1, persistent_script->full_path->val, persistent_script->full_path->len, 0);
			if (!zend_hash_exists(EG(zend_constants), name)) {
				zend_register_long_constant(name->val, name->len, persistent_script->compiler_halt_offset, CONST_CS, 0);
			}
			zend_string_release(name);
		}

		zend_hash_destroy(&ZCG(bind_hash));
		ZCG(current_persistent_script) = NULL;
	} else /* if (!from_shared_memory) */ {
		if (zend_hash_num_elements(&persistent_script->function_table) > 0) {
			zend_accel_function_hash_copy(CG(function_table), &persistent_script->function_table);
		}
		if (zend_hash_num_elements(&persistent_script->class_table) > 0) {
			zend_accel_class_hash_copy(CG(class_table), &persistent_script->class_table, NULL);
		}
	}

	if (op_array->early_binding != (uint32_t)-1) {
		zend_string *orig_compiled_filename = CG(compiled_filename);
		CG(compiled_filename) = persistent_script->full_path;
		zend_do_delayed_early_binding(op_array);
		CG(compiled_filename) = orig_compiled_filename;
	}

	if (UNEXPECTED(!from_shared_memory)) {
		free_persistent_script(persistent_script, 0); /* free only hashes */
	}

	return op_array;
}
Ejemplo n.º 9
0
static zend_always_inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, zend_long elements, int objprops)
{
	while (elements-- > 0) {
		zval key, *data, d, *old_data;
		zend_ulong idx;

		ZVAL_UNDEF(&key);

		if (!php_var_unserialize_internal(&key, p, max, NULL)) {
			zval_ptr_dtor(&key);
			return 0;
		}

		data = NULL;
		ZVAL_UNDEF(&d);

		if (!objprops) {
			if (Z_TYPE(key) == IS_LONG) {
				idx = Z_LVAL(key);
numeric_key:
				if (UNEXPECTED((old_data = zend_hash_index_find(ht, idx)) != NULL)) {
					//??? update hash
					var_push_dtor(var_hash, old_data);
					data = zend_hash_index_update(ht, idx, &d);
				} else {
					data = zend_hash_index_add_new(ht, idx, &d);
				}
			} else if (Z_TYPE(key) == IS_STRING) {
				if (UNEXPECTED(ZEND_HANDLE_NUMERIC(Z_STR(key), idx))) {
					goto numeric_key;
				}
				if (UNEXPECTED((old_data = zend_hash_find(ht, Z_STR(key))) != NULL)) {
					//??? update hash
					var_push_dtor(var_hash, old_data);
					data = zend_hash_update(ht, Z_STR(key), &d);
				} else {
					data = zend_hash_add_new(ht, Z_STR(key), &d);
				}
			} else {
				zval_ptr_dtor(&key);
				return 0;
			}
		} else {
			if (EXPECTED(Z_TYPE(key) == IS_STRING)) {
string_key:
				{
					zend_property_info *existing_propinfo;
					zend_string *new_key, *unmangled;
					const char *unmangled_class = NULL; 
					const char *unmangled_prop;
					size_t unmangled_prop_len;

					if (UNEXPECTED(zend_unmangle_property_name_ex(Z_STR(key), &unmangled_class, &unmangled_prop, &unmangled_prop_len) == FAILURE)) {
						zval_ptr_dtor(&key);
						return 0;
					}

					unmangled = zend_string_init(unmangled_prop, unmangled_prop_len, 0);
					if (Z_TYPE_P(rval) == IS_OBJECT
							&& ((existing_propinfo = zend_hash_find_ptr(&Z_OBJCE_P(rval)->properties_info, unmangled)) != NULL) 
							&& (existing_propinfo->flags & ZEND_ACC_PPP_MASK)) {
						if (existing_propinfo->flags & ZEND_ACC_PROTECTED) {
							new_key = zend_mangle_property_name(
								"*", 1, ZSTR_VAL(unmangled), ZSTR_LEN(unmangled), Z_OBJCE_P(rval)->type & ZEND_INTERNAL_CLASS);
							zend_string_release(unmangled);
						} else if (existing_propinfo->flags & ZEND_ACC_PRIVATE) {
							if (unmangled_class != NULL && strcmp(unmangled_class, "*") != 0) {
								new_key = zend_mangle_property_name(
									unmangled_class, strlen(unmangled_class),
									ZSTR_VAL(unmangled), ZSTR_LEN(unmangled),
									Z_OBJCE_P(rval)->type & ZEND_INTERNAL_CLASS);
							} else {
								new_key = zend_mangle_property_name(
									ZSTR_VAL(existing_propinfo->ce->name), ZSTR_LEN(existing_propinfo->ce->name),
									ZSTR_VAL(unmangled), ZSTR_LEN(unmangled),
									Z_OBJCE_P(rval)->type & ZEND_INTERNAL_CLASS);
							}
							zend_string_release(unmangled);
						} else {
							ZEND_ASSERT(existing_propinfo->flags & ZEND_ACC_PUBLIC);
							new_key = unmangled;
						}
						zend_string_release(Z_STR(key));
						ZVAL_STR(&key, new_key);
					} else {
						zend_string_release(unmangled);
					}

					if ((old_data = zend_hash_find(ht, Z_STR(key))) != NULL) {
						if (Z_TYPE_P(old_data) == IS_INDIRECT) {
							old_data = Z_INDIRECT_P(old_data);
						}
						var_push_dtor(var_hash, old_data);
						data = zend_hash_update_ind(ht, Z_STR(key), &d);
					} else {
						data = zend_hash_add_new(ht, Z_STR(key), &d);
					}
				}
			} else if (Z_TYPE(key) == IS_LONG) {
				/* object properties should include no integers */
				convert_to_string(&key);
				goto string_key;
			} else {
				zval_ptr_dtor(&key);
				return 0;
			}
		}

		if (!php_var_unserialize_internal(data, p, max, var_hash)) {
			zval_ptr_dtor(&key);
			return 0;
		}

		var_push_dtor(var_hash, data);
		zval_ptr_dtor(&key);

		if (elements && *(*p-1) != ';' && *(*p-1) != '}') {
			(*p)--;
			return 0;
		}
	}

	return 1;
}
Ejemplo n.º 10
0
zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len) /* {{{ */
{
    return zend_mangle_property_name(ce->name->val, ce->name->len, prop_name, prop_len, 0);
}
Ejemplo n.º 11
0
zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len) /* {{{ */
{
	return zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), prop_name, prop_len, 0);
}