diff options
Diffstat (limited to 'ext/standard/var.c')
| -rw-r--r-- | ext/standard/var.c | 244 |
1 files changed, 1 insertions, 243 deletions
diff --git a/ext/standard/var.c b/ext/standard/var.c index 5b11a5247f..5e865cf29c 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -362,249 +362,7 @@ PHPAPI void php_var_serialize(smart_str *buf, zval **struc, HashTable *var_hash } /* }}} */ -/* {{{ php_var_unserialize */ -PHPAPI int php_var_unserialize(zval **rval, const char **p, const char *max, HashTable *var_hash TSRMLS_DC) -{ - const char *q; - char *str; - int i; - char cur; - ulong id; - HashTable *myht; - zval **rval_ref; - - if (var_hash && **p != 'R') { /* references aren't counted by serializer! */ - zend_hash_next_index_insert(var_hash, rval, sizeof(*rval), NULL); - } - - switch (cur = **p) { - case 'R': - if (*((*p) + 1) != ':') { - return 0; - } - q = *p; - while (**p && **p != ';') { - (*p)++; - } - if (**p != ';') { - return 0; - } - (*p)++; - id = atol(q + 2)-1; /* count starts with 1 */ - if (!var_hash) { - return 0; - } - if (zend_hash_index_find(var_hash, id, (void *)&rval_ref) != SUCCESS) { - return 0; - } - zval_ptr_dtor(rval); - *rval = *rval_ref; - (*rval)->refcount++; - (*rval)->is_ref = 1; - return 1; - - case 'N': - if (*((*p) + 1) != ';') { - return 0; - } - (*p)++; - INIT_PZVAL(*rval); - ZVAL_NULL(*rval); - (*p)++; - return 1; - - case 'b': /* bool */ - case 'i': - if (*((*p) + 1) != ':') { - return 0; - } - q = *p; - while (**p && **p != ';') { - (*p)++; - } - if (**p != ';') { - return 0; - } - (*p)++; - INIT_PZVAL(*rval); - if (cur == 'b') { - ZVAL_BOOL(*rval, atol(q + 2)); - } else { - ZVAL_LONG(*rval, atol(q + 2)); - } - return 1; - - case 'd': - if (*((*p) + 1) != ':') { - return 0; - } - q = *p; - while (**p && **p != ';') { - (*p)++; - } - if (**p != ';') { - return 0; - } - (*p)++; - INIT_PZVAL(*rval); - ZVAL_DOUBLE(*rval, atof(q + 2)); - return 1; - - case 's': - if (*((*p) + 1) != ':') { - return 0; - } - (*p) += 2; - q = *p; - while (**p && **p != ':') { - (*p)++; - } - if (**p != ':') { - return 0; - } - i = atoi(q); - if (i < 0 || (*p + 3 + i) > max || *((*p) + 1) != '\"' || - *((*p) + 2 + i) != '\"' || *((*p) + 3 + i) != ';') { - return 0; - } - (*p) += 2; - - if (i == 0) { - str = empty_string; - } else { - str = estrndup(*p, i); - } - (*p) += i + 2; - INIT_PZVAL(*rval); - ZVAL_STRINGL(*rval, str, i, 0); - return 1; - - case 'a': - case 'o': - case 'O': { - zend_bool incomplete_class = 0; - char *class_name = NULL; - size_t name_len = 0; - int pi; - - INIT_PZVAL(*rval); - - if (cur == 'a') { - Z_TYPE_PP(rval) = IS_ARRAY; - ALLOC_HASHTABLE(Z_ARRVAL_PP(rval)); - myht = Z_ARRVAL_PP(rval); - } else { - zend_class_entry *ce; - - if (cur == 'O') { /* php4 serialized - we get the class-name */ - if (*((*p) + 1) != ':') { - return 0; - } - (*p) += 2; - q = *p; - while (**p && **p != ':') { - (*p)++; - } - if (**p != ':') { - return 0; - } - name_len = i = atoi(q); - if (i < 0 || (*p + 3 + i) > max || *((*p) + 1) != '\"' || - *((*p) + 2 + i) != '\"' || *((*p) + 3 + i) != ':') { - return 0; - } - (*p) += 2; - class_name = emalloc(i + 1); - for(pi=0;pi<i;pi++) { - class_name[pi] = tolower((*p)[pi]); - } - class_name[i] = 0; - (*p) += i; - - if (zend_hash_find(EG(class_table), class_name, i+1, (void **) &ce)==FAILURE) { - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } - } else { /* old php 3.0 data 'o' */ - ce = &zend_standard_class_def; - } - - object_init_ex(*rval, ce); - myht = Z_OBJPROP_PP(rval); - - if (incomplete_class) - php_store_class_name(*rval, class_name, name_len); - - if (class_name) - efree(class_name); - } - - (*p) += 2; - i = atoi(*p); - - if (cur == 'a') { /* object_init_ex will init the HashTable for objects! */ - zend_hash_init(myht, i + 1, NULL, ZVAL_PTR_DTOR, 0); - } - - while (**p && **p != ':') { - (*p)++; - } - if (**p != ':' || *((*p) + 1) != '{') { - return 0; - } - for ((*p) += 2; **p && **p != '}' && i > 0; i--) { - zval *key; - zval *data; - - ALLOC_INIT_ZVAL(key); - ALLOC_INIT_ZVAL(data); - - if (!php_var_unserialize(&key, p, max, NULL TSRMLS_CC)) { - zval_dtor(key); - FREE_ZVAL(key); - FREE_ZVAL(data); - return 0; - } - if (!php_var_unserialize(&data, p, max, var_hash TSRMLS_CC)) { - zval_dtor(key); - FREE_ZVAL(key); - zval_dtor(data); - FREE_ZVAL(data); - return 0; - } - switch (Z_TYPE_P(key)) { - case IS_LONG: - zend_hash_index_update(myht, Z_LVAL_P(key), &data, sizeof(data), NULL); - break; - case IS_STRING: - zend_hash_update(myht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); - break; - } - zval_dtor(key); - FREE_ZVAL(key); - } - - if (Z_TYPE_PP(rval) == IS_OBJECT) { - zval *retval_ptr = NULL; - zval fname; - - INIT_PZVAL(&fname); - ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0); - call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); - - if (retval_ptr) - zval_ptr_dtor(&retval_ptr); - } - - return *((*p)++) == '}'; - } - } - - return 0; -} - -/* }}} */ /* {{{ proto string serialize(mixed variable) Returns a string representation of variable (which can later be unserialized) */ PHP_FUNCTION(serialize) @@ -635,7 +393,7 @@ PHP_FUNCTION(serialize) PHP_FUNCTION(unserialize) { zval **buf; - php_serialize_data_t var_hash; + php_unserialize_data_t var_hash; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buf) == FAILURE) { WRONG_PARAM_COUNT; |
