Example #1
0
int msgpack_convert_template(zval *return_value, zval *tpl, zval **value)
{
    TSRMLS_FETCH();

    switch (Z_TYPE_P(tpl))
    {
        case IS_ARRAY:
            return msgpack_convert_array(return_value, tpl, value);
            break;
        case IS_STRING:
        case IS_OBJECT:
            return msgpack_convert_object(return_value, tpl, value);
            break;
        default:
            MSGPACK_ERROR("[msgpack] (%s) Template type is unsupported",
                          __FUNCTION__);
            return FAILURE;
    }

    // shouldn't reach
    return FAILURE;
}
Example #2
0
inline int msgpack_convert_long_to_properties(
    HashTable *ht, HashTable **properties, HashPosition *prop_pos,
    uint key_index, zval *val, HashTable *var)
{
    TSRMLS_FETCH();

    if (*properties != NULL)
    {
        char *prop_key;
        uint prop_key_len;
        ulong prop_key_index;
        zval **data = NULL;
        zval *tplval = NULL;
        zval **dataval = NULL;

        for (;; zend_hash_move_forward_ex(*properties, prop_pos))
        {
            if (zend_hash_get_current_key_ex(
                    *properties, &prop_key, &prop_key_len,
                    &prop_key_index, 0, prop_pos) == HASH_KEY_IS_STRING)
            {
                if (var == NULL ||
                    !zend_hash_exists(var, prop_key, prop_key_len))
                {
                    if (zend_hash_find(
                            ht, prop_key, prop_key_len,
                            (void **)&data) == SUCCESS)
                    {
                        switch (Z_TYPE_PP(data))
                        {
                            case IS_ARRAY:
                            {
                                HashTable *dataht;
                                dataht = HASH_OF(val);
                                if (zend_hash_index_find(
                                        dataht, prop_key_index,
                                        (void **)dataval) != SUCCESS)
                                {
                                    MSGPACK_WARNING(
                                        "[msgpack] (%s) "
                                        "can't get data value by index",
                                        __FUNCTION__);
                                    return FAILURE;
                                }

                                ALLOC_INIT_ZVAL(tplval);
                                if (msgpack_convert_array(
                                        tplval, *data, dataval) == SUCCESS)
                                {
                                    zend_hash_move_forward_ex(
                                        *properties, prop_pos);

                                    return zend_symtable_update(
                                        ht, prop_key, prop_key_len,
                                        &tplval, sizeof(tplval), NULL);
                                }
                                // TODO: de we need to call dtor?
                                return FAILURE;
                                break;
                            }
                            case IS_OBJECT:
                            {
                                ALLOC_INIT_ZVAL(tplval);
                                if (msgpack_convert_object(
                                        tplval, *data, &val) == SUCCESS)
                                {
                                    zend_hash_move_forward_ex(
                                        *properties, prop_pos);

                                    return zend_symtable_update(
                                        ht, prop_key, prop_key_len,
                                        &tplval, sizeof(tplval), NULL);
                                }
                                // TODO: de we need to call dtor?
                                return FAILURE;
                                break;
                            }
                            default:
                                zend_hash_move_forward_ex(*properties, prop_pos);
                                return zend_symtable_update(
                                    ht, prop_key, prop_key_len,
                                    &val, sizeof(val), NULL);
                                break;
                        }
                    }
                }
            }
            else
            {
                break;
            }
        }

        *properties = NULL;
    }

    return zend_hash_index_update(ht, key_index, &val, sizeof(val), NULL);
}
Example #3
0
static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object, HashTable **properties, HashPosition *prop_pos, uint key_index, zval *val, HashTable *var) /* {{{ */ {
    zval key_zv;
	HashTable *props = *properties;

    if (props != NULL) {
        zval *data, tplval, *dataval, prop_key_zv;
        zend_string *prop_key;
        ulong prop_key_index;
        const char *class_name, *prop_name;
        size_t prop_len;

        for (;; zend_hash_move_forward_ex(props, prop_pos)) {
            if (zend_hash_get_current_key_ex(props, &prop_key, &prop_key_index, prop_pos) == HASH_KEY_IS_STRING) {
                zend_unmangle_property_name_ex(prop_key, &class_name, &prop_name, &prop_len);
                ZVAL_NEW_STR(&prop_key_zv, prop_key);
                if (var == NULL || !zend_hash_str_exists(var, prop_name, prop_len)) {
                    if ((data = zend_hash_find(ht, prop_key)) != NULL) {
                        switch (Z_TYPE_P(data)) {
                            case IS_ARRAY:
							{
								HashTable *dataht;
								dataht = HASH_OF(val);

								if ((dataval = zend_hash_index_find(dataht, prop_key_index)) == NULL) {
									MSGPACK_WARNING("[msgpack] (%s) "
											"can't get data value by index",
											__FUNCTION__);
									return FAILURE;
								}

								if (msgpack_convert_array(&tplval, data, dataval) == SUCCESS) {
									zend_hash_move_forward_ex(props, prop_pos);
									zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval);
									return SUCCESS;
								}
								return FAILURE;
							}
                            case IS_OBJECT:
							{
								if (msgpack_convert_object(&tplval, data, val) == SUCCESS) {
									zend_hash_move_forward_ex(props, prop_pos);
									zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval);
									return SUCCESS;
								}
								return FAILURE;
							}
                            default:
								zend_hash_move_forward_ex(props, prop_pos);
								zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, val);
							return SUCCESS;
                        }
                    }
                }
            } else {
                break;
            }
        }
        *properties = NULL;
    }
    ZVAL_LONG(&key_zv, key_index);
    zend_std_write_property(object, &key_zv, val, NULL);
    return SUCCESS;
}