1999-04-17 08:37:12 +08:00
|
|
|
|
/*
|
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
|
| PHP version 4.0 |
|
1999-04-17 08:37:12 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
|
| Copyright (c) 1997, 1998, 1999 The PHP Group |
|
1999-04-17 08:37:12 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
|
| This source file is subject to version 2.0 of the PHP license, |
|
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
|
| http://www.php.net/license/2_0.txt. |
|
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 08:37:12 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
| Authors: Jani Lehtim<EFBFBD>ki <jkl@njet.net> |
|
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ includes
|
|
|
|
|
*/
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include "php.h"
|
|
|
|
|
#include "php3_string.h"
|
|
|
|
|
#include "php3_var.h"
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ php3api_var_dump
|
|
|
|
|
xmae*/
|
|
|
|
|
|
1999-04-25 02:39:41 +08:00
|
|
|
|
void php3api_var_dump(pval **struc, int level)
|
1999-04-17 08:37:12 +08:00
|
|
|
|
{
|
|
|
|
|
ulong index;
|
|
|
|
|
char *key;
|
|
|
|
|
int i, c = 0;
|
1999-04-25 02:39:41 +08:00
|
|
|
|
pval **data;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
char buf[512];
|
|
|
|
|
|
1999-04-25 02:39:41 +08:00
|
|
|
|
switch ((*struc)->type) {
|
1999-07-01 17:26:05 +08:00
|
|
|
|
case IS_BOOL:
|
|
|
|
|
i = sprintf(buf, "%*cbool(%s)\n", level, ' ', ((*struc)->value.lval?"true":"false"));
|
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
|
|
|
|
break;
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
case IS_LONG:
|
1999-04-25 02:39:41 +08:00
|
|
|
|
i = sprintf(buf, "%*cint(%ld)\n", level, ' ', (*struc)->value.lval);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IS_DOUBLE:
|
1999-04-25 02:39:41 +08:00
|
|
|
|
i = sprintf(buf, "%*cfloat(%g)\n", level, ' ', (*struc)->value.dval);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IS_STRING:
|
1999-04-25 02:39:41 +08:00
|
|
|
|
i = sprintf(buf, "%*cstring(%d) \"", level, ' ', (*struc)->value.str.len);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
1999-04-25 02:39:41 +08:00
|
|
|
|
PHPWRITE((*struc)->value.str.val, (*struc)->value.str.len);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
strcpy(buf, "\"\n");
|
|
|
|
|
PHPWRITE(buf, strlen(buf));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IS_ARRAY:
|
1999-08-03 03:17:14 +08:00
|
|
|
|
i = sprintf(buf, "%*carray(%d) {\n", level, ' ', zend_hash_num_elements((*struc)->value.ht));
|
1999-04-17 08:37:12 +08:00
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
|
|
|
|
goto head_done;
|
|
|
|
|
|
|
|
|
|
case IS_OBJECT:
|
1999-08-03 03:17:14 +08:00
|
|
|
|
i = sprintf(buf, "%*cobject(%d) {\n", level, ' ', zend_hash_num_elements((*struc)->value.ht));
|
1999-04-17 08:37:12 +08:00
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
|
|
|
|
head_done:
|
|
|
|
|
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_internal_pointer_reset((*struc)->value.ht);
|
|
|
|
|
for (;; zend_hash_move_forward((*struc)->value.ht)) {
|
|
|
|
|
if ((i = zend_hash_get_current_key((*struc)->value.ht, &key, &index)) == HASH_KEY_NON_EXISTANT)
|
1999-04-17 08:37:12 +08:00
|
|
|
|
break;
|
|
|
|
|
if (c > 0) {
|
|
|
|
|
strcpy(buf, "\n");
|
|
|
|
|
PHPWRITE(buf, strlen(buf));
|
|
|
|
|
}
|
|
|
|
|
c++;
|
1999-08-03 03:17:14 +08:00
|
|
|
|
if (zend_hash_get_current_data((*struc)->value.ht, (void **) (&data)) != SUCCESS || !data || (data == struc))
|
1999-04-17 08:37:12 +08:00
|
|
|
|
continue;
|
|
|
|
|
switch (i) {
|
|
|
|
|
case HASH_KEY_IS_LONG:{
|
1999-04-25 02:39:41 +08:00
|
|
|
|
pval *d = emalloc(sizeof(pval));
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
1999-04-25 02:39:41 +08:00
|
|
|
|
d->type = IS_LONG;
|
|
|
|
|
d->value.lval = index;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
php3api_var_dump(&d, level + 2);
|
1999-04-25 02:39:41 +08:00
|
|
|
|
efree(d);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case HASH_KEY_IS_STRING:{
|
1999-04-25 02:39:41 +08:00
|
|
|
|
pval *d = emalloc(sizeof(pval));
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
1999-04-25 02:39:41 +08:00
|
|
|
|
d->type = IS_STRING;
|
|
|
|
|
d->value.str.val = key;
|
|
|
|
|
d->value.str.len = strlen(key);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
php3api_var_dump(&d, level + 2);
|
|
|
|
|
efree(key);
|
1999-04-25 02:39:41 +08:00
|
|
|
|
efree(d);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
php3api_var_dump(data, level + 2);
|
|
|
|
|
}
|
|
|
|
|
i = sprintf(buf, "%*c}\n", level, ' ');
|
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
i = sprintf(buf, "%*ci:0\n", level, ' ');
|
|
|
|
|
PHPWRITE(&buf[1], i - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ php3api_var_dump */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(var_dump)
|
|
|
|
|
{
|
|
|
|
|
pval *struc;
|
|
|
|
|
|
|
|
|
|
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &struc) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-04-25 02:39:41 +08:00
|
|
|
|
php3api_var_dump(&struc, 1);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ php3api_var_dump */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define STR_CAT(P,S,I) {\
|
|
|
|
|
pval *__p = (P);\
|
|
|
|
|
ulong __i = __p->value.str.len;\
|
|
|
|
|
__p->value.str.len += (I);\
|
|
|
|
|
if (__p->value.str.val) {\
|
|
|
|
|
__p->value.str.val = (char *)erealloc(__p->value.str.val, __p->value.str.len + 1);\
|
|
|
|
|
} else {\
|
|
|
|
|
__p->value.str.val = emalloc(__p->value.str.len + 1);\
|
|
|
|
|
*__p->value.str.val = 0;\
|
|
|
|
|
}\
|
|
|
|
|
strcat(__p->value.str.val + __i, (S));\
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ php3api_var_dump */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
void php3api_var_serialize(pval *buf, pval **struc)
|
1999-04-17 08:37:12 +08:00
|
|
|
|
{
|
|
|
|
|
char s[256];
|
|
|
|
|
ulong slen;
|
|
|
|
|
int i, ch;
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
switch ((*struc)->type) {
|
1999-07-01 17:26:05 +08:00
|
|
|
|
case IS_BOOL:
|
|
|
|
|
slen = sprintf(s, "b:%ld;", (*struc)->value.lval);
|
|
|
|
|
STR_CAT(buf, s, slen);
|
|
|
|
|
return;
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
case IS_LONG:
|
1999-04-25 20:41:18 +08:00
|
|
|
|
slen = sprintf(s, "i:%ld;", (*struc)->value.lval);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
STR_CAT(buf, s, slen);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case IS_DOUBLE:
|
1999-04-25 20:41:18 +08:00
|
|
|
|
slen = sprintf(s, "d:%g;", (*struc)->value.dval);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
STR_CAT(buf, s, slen);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case IS_STRING:{
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
i = buf->value.str.len;
|
1999-04-25 20:41:18 +08:00
|
|
|
|
slen = sprintf(s, "s:%d:\"", (*struc)->value.str.len);
|
|
|
|
|
STR_CAT(buf, s, slen + (*struc)->value.str.len + 2);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
p = buf->value.str.val + i + slen;
|
1999-04-25 20:41:18 +08:00
|
|
|
|
if ((*struc)->value.str.len > 0) {
|
|
|
|
|
memcpy(p, (*struc)->value.str.val, (*struc)->value.str.len);
|
|
|
|
|
p += (*struc)->value.str.len;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
}
|
|
|
|
|
*p++ = '\"';
|
|
|
|
|
*p++ = ';';
|
|
|
|
|
*p = 0;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case IS_ARRAY:
|
|
|
|
|
ch = 'a';
|
1999-08-03 03:17:14 +08:00
|
|
|
|
i = zend_hash_num_elements((*struc)->value.ht);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
slen = sprintf(s, "%c:%d:{", ch, i);
|
|
|
|
|
STR_CAT(buf, s, slen);
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
char *key;
|
1999-06-11 23:54:06 +08:00
|
|
|
|
pval **data,*d;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
ulong index;
|
|
|
|
|
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_internal_pointer_reset((*struc)->value.ht);
|
|
|
|
|
for (;; zend_hash_move_forward((*struc)->value.ht)) {
|
|
|
|
|
if ((i = zend_hash_get_current_key((*struc)->value.ht, &key, &index)) == HASH_KEY_NON_EXISTANT) {
|
1999-04-17 08:37:12 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
1999-08-03 03:17:14 +08:00
|
|
|
|
if (zend_hash_get_current_data((*struc)->value.ht, (void **) (&data)) !=
|
1999-06-11 23:54:06 +08:00
|
|
|
|
SUCCESS || !data || ((*data) == (*struc))) {
|
1999-04-25 20:41:18 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
switch (i) {
|
|
|
|
|
case HASH_KEY_IS_LONG:
|
1999-04-25 20:41:18 +08:00
|
|
|
|
d = emalloc(sizeof(pval));
|
|
|
|
|
d->type = IS_LONG;
|
|
|
|
|
d->value.lval = index;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
php3api_var_serialize(buf, &d);
|
1999-04-25 20:41:18 +08:00
|
|
|
|
efree(d);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
break;
|
|
|
|
|
case HASH_KEY_IS_STRING:
|
1999-04-25 20:41:18 +08:00
|
|
|
|
d = emalloc(sizeof(pval));
|
|
|
|
|
d->type = IS_STRING;
|
|
|
|
|
d->value.str.val = key;
|
|
|
|
|
d->value.str.len = strlen(key);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
php3api_var_serialize(buf, &d);
|
|
|
|
|
efree(key);
|
1999-04-25 20:41:18 +08:00
|
|
|
|
efree(d);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
php3api_var_serialize(buf, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
STR_CAT(buf, "}", 1);
|
|
|
|
|
return;
|
|
|
|
|
|
1999-06-10 23:34:20 +08:00
|
|
|
|
case IS_OBJECT:
|
|
|
|
|
i = zend_hash_num_elements((*struc)->value.obj.properties);
|
|
|
|
|
slen = sprintf(s, "o:%d:{", i);
|
|
|
|
|
STR_CAT(buf, s, slen);
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
char *key;
|
1999-06-11 23:54:06 +08:00
|
|
|
|
pval **data,*d;
|
1999-06-10 23:34:20 +08:00
|
|
|
|
ulong index;
|
|
|
|
|
|
|
|
|
|
zend_hash_internal_pointer_reset((*struc)->value.obj.properties);
|
1999-08-03 03:17:14 +08:00
|
|
|
|
for (;; zend_hash_move_forward((*struc)->value.obj.properties)) {
|
|
|
|
|
if ((i = zend_hash_get_current_key((*struc)->value.obj.properties, &key, &index)) == HASH_KEY_NON_EXISTANT) {
|
1999-06-10 23:34:20 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
1999-08-03 03:17:14 +08:00
|
|
|
|
if (zend_hash_get_current_data((*struc)->value.obj.properties, (void **)
|
1999-06-11 23:54:06 +08:00
|
|
|
|
(&data)) != SUCCESS || !data || ((*data) == (*struc))) {
|
1999-06-10 23:34:20 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
|
case HASH_KEY_IS_LONG:
|
|
|
|
|
d = emalloc(sizeof(pval));
|
|
|
|
|
d->type = IS_LONG;
|
|
|
|
|
d->value.lval = index;
|
|
|
|
|
php3api_var_serialize(buf, &d);
|
|
|
|
|
efree(d);
|
|
|
|
|
break;
|
|
|
|
|
case HASH_KEY_IS_STRING:
|
|
|
|
|
d = emalloc(sizeof(pval));
|
|
|
|
|
d->type = IS_STRING;
|
|
|
|
|
d->value.str.val = key;
|
|
|
|
|
d->value.str.len = strlen(key);
|
|
|
|
|
php3api_var_serialize(buf, &d);
|
|
|
|
|
efree(key);
|
|
|
|
|
efree(d);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
php3api_var_serialize(buf, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
STR_CAT(buf, "}", 1);
|
|
|
|
|
break;
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
default:
|
|
|
|
|
STR_CAT(buf, "i:0;", 4);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ php3api_var_dump */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
1999-07-01 13:47:06 +08:00
|
|
|
|
int php3api_var_unserialize(pval **rval, const char **p, const char *max)
|
1999-04-17 08:37:12 +08:00
|
|
|
|
{
|
1999-07-01 13:47:06 +08:00
|
|
|
|
const char *q;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
char *str;
|
|
|
|
|
int i;
|
1999-07-01 17:26:05 +08:00
|
|
|
|
char cur;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
1999-07-01 17:26:05 +08:00
|
|
|
|
switch (cur = **p) {
|
|
|
|
|
case 'b': /* bool */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
case 'i':
|
|
|
|
|
if (*((*p) + 1) != ':') {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
q = *p;
|
|
|
|
|
while (**p && **p != ';') {
|
|
|
|
|
(*p)++;
|
|
|
|
|
}
|
|
|
|
|
if (**p != ';') {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
(*p)++;
|
1999-07-01 17:26:05 +08:00
|
|
|
|
if (cur == 'b') {
|
|
|
|
|
(*rval)->type = IS_BOOL;
|
|
|
|
|
} else {
|
|
|
|
|
(*rval)->type = IS_LONG;
|
|
|
|
|
}
|
1999-07-10 04:45:55 +08:00
|
|
|
|
INIT_PZVAL(*rval);
|
1999-04-25 20:41:18 +08:00
|
|
|
|
(*rval)->value.lval = atol(q + 2);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
|
if (*((*p) + 1) != ':') {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
q = *p;
|
|
|
|
|
while (**p && **p != ';') {
|
|
|
|
|
(*p)++;
|
|
|
|
|
}
|
|
|
|
|
if (**p != ';') {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
(*p)++;
|
1999-04-25 20:41:18 +08:00
|
|
|
|
(*rval)->type = IS_DOUBLE;
|
1999-07-10 04:45:55 +08:00
|
|
|
|
INIT_PZVAL(*rval);
|
1999-04-25 20:41:18 +08:00
|
|
|
|
(*rval)->value.dval = atof(q + 2);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
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;
|
|
|
|
|
str = emalloc(i + 1);
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
memcpy(str, *p, i);
|
|
|
|
|
}
|
|
|
|
|
str[i] = 0;
|
|
|
|
|
(*p) += i + 2;
|
1999-04-25 20:41:18 +08:00
|
|
|
|
(*rval)->type = IS_STRING;
|
|
|
|
|
(*rval)->value.str.val = str;
|
|
|
|
|
(*rval)->value.str.len = i;
|
1999-07-10 04:45:55 +08:00
|
|
|
|
INIT_PZVAL(*rval);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case 'a':
|
1999-04-25 20:41:18 +08:00
|
|
|
|
(*rval)->type = IS_ARRAY;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
1999-07-10 04:45:55 +08:00
|
|
|
|
INIT_PZVAL(*rval);
|
1999-06-10 23:34:20 +08:00
|
|
|
|
(*p) += 2;
|
|
|
|
|
i = atoi(*p);
|
|
|
|
|
(*rval)->value.ht = (HashTable *) emalloc(sizeof(HashTable));
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_init((*rval)->value.ht, i + 1, NULL, PVAL_PTR_DTOR, 0);
|
1999-06-10 23:34:20 +08:00
|
|
|
|
while (**p && **p != ':') {
|
|
|
|
|
(*p)++;
|
|
|
|
|
}
|
|
|
|
|
if (**p != ':' || *((*p) + 1) != '{') {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
for ((*p) += 2; **p && **p != '}' && i > 0; i--) {
|
|
|
|
|
pval *key = emalloc(sizeof(pval));
|
|
|
|
|
pval *data = emalloc(sizeof(pval));
|
|
|
|
|
|
|
|
|
|
if (!php3api_var_unserialize(&key, p, max)) {
|
|
|
|
|
efree(key);
|
|
|
|
|
efree(data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!php3api_var_unserialize(&data, p, max)) {
|
|
|
|
|
pval_destructor(key);
|
|
|
|
|
efree(key);
|
|
|
|
|
efree(data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
switch (key->type) {
|
|
|
|
|
case IS_LONG:
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_index_update((*rval)->value.ht, key->value.lval, &data, sizeof(data), NULL);
|
1999-06-10 23:34:20 +08:00
|
|
|
|
break;
|
|
|
|
|
case IS_STRING:
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_add((*rval)->value.ht, key->value.str.val, key->value.str.len + 1, &data, sizeof(data), NULL);
|
1999-06-10 23:34:20 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pval_destructor(key);
|
|
|
|
|
efree(key);
|
|
|
|
|
}
|
|
|
|
|
return *((*p)++) == '}';
|
1999-04-17 08:37:12 +08:00
|
|
|
|
case 'o':
|
1999-04-25 20:41:18 +08:00
|
|
|
|
(*rval)->type = IS_OBJECT;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
1999-07-10 04:45:55 +08:00
|
|
|
|
INIT_PZVAL(*rval);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
(*p) += 2;
|
|
|
|
|
i = atoi(*p);
|
1999-06-10 23:34:20 +08:00
|
|
|
|
(*rval)->value.obj.properties = (HashTable *) emalloc(sizeof(HashTable));
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_init((*rval)->value.obj.properties, i + 1, NULL, PVAL_PTR_DTOR, 0);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
while (**p && **p != ':') {
|
|
|
|
|
(*p)++;
|
|
|
|
|
}
|
|
|
|
|
if (**p != ':' || *((*p) + 1) != '{') {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
for ((*p) += 2; **p && **p != '}' && i > 0; i--) {
|
1999-04-25 20:41:18 +08:00
|
|
|
|
pval *key = emalloc(sizeof(pval));
|
|
|
|
|
pval *data = emalloc(sizeof(pval));
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
|
|
if (!php3api_var_unserialize(&key, p, max)) {
|
1999-04-25 20:41:18 +08:00
|
|
|
|
efree(key);
|
|
|
|
|
efree(data);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!php3api_var_unserialize(&data, p, max)) {
|
1999-05-29 05:27:19 +08:00
|
|
|
|
pval_destructor(key);
|
1999-04-25 20:41:18 +08:00
|
|
|
|
efree(key);
|
|
|
|
|
efree(data);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
1999-04-25 20:41:18 +08:00
|
|
|
|
switch (key->type) {
|
1999-04-17 08:37:12 +08:00
|
|
|
|
case IS_LONG:
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_index_update((*rval)->value.obj.properties, key->value.lval, &data, sizeof(data), NULL);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
break;
|
|
|
|
|
case IS_STRING:
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_add((*rval)->value.obj.properties, key->value.str.val, key->value.str.len + 1, &data, sizeof(data), NULL);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
1999-04-25 20:41:18 +08:00
|
|
|
|
pval_destructor(key);
|
|
|
|
|
efree(key);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
}
|
|
|
|
|
return *((*p)++) == '}';
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ proto string serialize(mixed variable)
|
|
|
|
|
Returns a string representation of variable (which can later be unserialized) */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
PHP_FUNCTION(serialize)
|
1999-04-25 20:41:18 +08:00
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
{
|
|
|
|
|
pval *struc;
|
|
|
|
|
|
|
|
|
|
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &struc) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
|
return_value->value.str.val = NULL;
|
|
|
|
|
return_value->value.str.len = 0;
|
1999-04-25 20:41:18 +08:00
|
|
|
|
php3api_var_serialize(return_value, &struc);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-25 20:41:18 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ proto mixed unserialize(string variable_representation)
|
|
|
|
|
Takes a string representation of variable and recreates it */
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(unserialize)
|
|
|
|
|
{
|
|
|
|
|
pval *buf;
|
|
|
|
|
|
|
|
|
|
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &buf) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
if (buf->type == IS_STRING) {
|
1999-07-01 13:47:06 +08:00
|
|
|
|
const char *p = buf->value.str.val;
|
1999-04-25 20:41:18 +08:00
|
|
|
|
if (!php3api_var_unserialize(&return_value, &p, p + buf->value.str.len)) {
|
1999-04-17 08:37:12 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-16 01:06:22 +08:00
|
|
|
|
/* }}} */
|
1999-04-25 20:41:18 +08:00
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* tab-width: 4
|
|
|
|
|
* c-basic-offset: 4
|
|
|
|
|
* End:
|
|
|
|
|
*/
|