mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
Cleaned up and optimized WDDX serialization - it's about twice
as fast now.
This commit is contained in:
parent
b2873a6cc2
commit
74912b9afb
6
NEWS
6
NEWS
@ -2,12 +2,10 @@ PHP 4.0 NEWS
|
||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
|
||||
?? ??? 200?, Version 4.0.5
|
||||
- Sped up WDDX serialization 2x. (Andrei)
|
||||
- Added a new parameter to mail() which appends aditional command line
|
||||
parameters to the mail program. (Derick)
|
||||
- Added Udm_Clear_Search_Limits mnoGoSearch extension function.
|
||||
- Fixed default search path. (gluke)
|
||||
- Added new Udm_Add_Search_Limit mnoGoSearch extension function.
|
||||
Some bugfixes and example update. (gluke)
|
||||
- Added Udm_Clear_Search_Limits mnoGoSearch extension function. (gluke)
|
||||
- Fixed mnogosearch protos. Fixed mnogosearch functions return values.
|
||||
A bug with capital letters break search has been fixed. (gluke)
|
||||
- Static methods can now be called via call_user_method_* functions, e.g.
|
||||
|
@ -21,6 +21,8 @@
|
||||
#ifndef PHP_WDDX_API_H
|
||||
#define PHP_WDDX_API_H
|
||||
|
||||
#include "ext/standard/php_smart_str.h"
|
||||
|
||||
#define WDDX_ARRAY_S "<array length='%d'>"
|
||||
#define WDDX_ARRAY_E "</array>"
|
||||
#define WDDX_BINARY_S "<binary>"
|
||||
@ -45,23 +47,19 @@
|
||||
#define WDDX_VAR_S "<var name='%s'>"
|
||||
#define WDDX_VAR_E "</var>"
|
||||
|
||||
#define php_wddx_add_chunk(packet, str) { \
|
||||
char *__s = (str); \
|
||||
php_wddx_add_chunk_ex(packet, __s, strlen(__s)); \
|
||||
}
|
||||
#define php_wddx_add_chunk_static(packet, str) \
|
||||
php_wddx_add_chunk_ex(packet, str, sizeof(str)-1);
|
||||
#define php_wddx_add_chunk(packet, str) smart_str_appends(packet, str)
|
||||
#define php_wddx_add_chunk_ex(packet, str, len) smart_str_appendl(packet, str, len)
|
||||
#define php_wddx_add_chunk_static(packet, str) smart_str_appendl(packet, str, sizeof(str)-1)
|
||||
|
||||
typedef struct _wddx_packet wddx_packet;
|
||||
typedef smart_str wddx_packet;
|
||||
|
||||
wddx_packet *php_wddx_constructor(void);
|
||||
void php_wddx_destructor(wddx_packet *packet);
|
||||
#define php_wddx_destructor(packet) smart_str_free(packet)
|
||||
|
||||
void php_wddx_packet_start(wddx_packet *packet, char *comment, int comment_len);
|
||||
void php_wddx_packet_end(wddx_packet *packet);
|
||||
|
||||
void php_wddx_serialize_var(wddx_packet *packet, zval *var, char *name);
|
||||
void php_wddx_add_chunk_ex(wddx_packet *packet, char *str, int length);
|
||||
int php_wddx_deserialize_ex(char *, int, zval *return_value);
|
||||
char *php_wddx_gather(wddx_packet *packet);
|
||||
|
||||
|
249
ext/wddx/wddx.c
249
ext/wddx/wddx.c
@ -40,6 +40,7 @@
|
||||
#include "ext/standard/php_incomplete_class.h"
|
||||
#include "ext/standard/base64.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "ext/standard/php_smart_str.h"
|
||||
|
||||
#define WDDX_BUF_LEN 256
|
||||
#define PHP_CLASS_NAME_VAR "php_class_name"
|
||||
@ -72,11 +73,6 @@
|
||||
|
||||
static int le_wddx;
|
||||
|
||||
struct _wddx_packet {
|
||||
zend_llist *packet_head;
|
||||
int packet_length;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
zval *data;
|
||||
enum {
|
||||
@ -98,13 +94,9 @@ typedef struct {
|
||||
} wddx_stack;
|
||||
|
||||
|
||||
/* {{{ function prototypes */
|
||||
static void php_wddx_process_data(void *user_data, const char *s, int len);
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ module definition structures */
|
||||
|
||||
function_entry wddx_functions[] = {
|
||||
PHP_FE(wddx_serialize_value, NULL)
|
||||
PHP_FE(wddx_serialize_vars, NULL)
|
||||
@ -129,10 +121,8 @@ zend_module_entry wddx_module_entry = {
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ int wddx_stack_init(wddx_stack *stack) */
|
||||
static int wddx_stack_init(wddx_stack *stack)
|
||||
{
|
||||
stack->top = 0;
|
||||
@ -145,10 +135,8 @@ static int wddx_stack_init(wddx_stack *stack)
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ int wddx_stack_push(wddx_stack *stack, void *element, int size) */
|
||||
static int wddx_stack_push(wddx_stack *stack, void *element, int size)
|
||||
{
|
||||
if (stack->top >= stack->max) { /* we need to allocate more memory */
|
||||
@ -162,10 +150,8 @@ static int wddx_stack_push(wddx_stack *stack, void *element, int size)
|
||||
memcpy(stack->elements[stack->top], element, size);
|
||||
return stack->top++;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ int wddx_stack_top(wddx_stack *stack, void **element) */
|
||||
static int wddx_stack_top(wddx_stack *stack, void **element)
|
||||
{
|
||||
if (stack->top > 0) {
|
||||
@ -176,10 +162,8 @@ static int wddx_stack_top(wddx_stack *stack, void **element)
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ int wddx_stack_is_empty(wddx_stack *stack) */
|
||||
static int wddx_stack_is_empty(wddx_stack *stack)
|
||||
{
|
||||
if (stack->top == 0) {
|
||||
@ -188,10 +172,8 @@ static int wddx_stack_is_empty(wddx_stack *stack)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ int wddx_stack_destroy(wddx_stack *stack) */
|
||||
static int wddx_stack_destroy(wddx_stack *stack)
|
||||
{
|
||||
register int i;
|
||||
@ -211,42 +193,22 @@ static int wddx_stack_destroy(wddx_stack *stack)
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ _php_free_packet_chunk */
|
||||
static void _php_free_packet_chunk(void *data)
|
||||
static void release_wddx_packet_rsrc(zend_rsrc_list_entry *rsrc)
|
||||
{
|
||||
char **chunk_ptr = (char **)data;
|
||||
if (*chunk_ptr)
|
||||
efree(*chunk_ptr);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void php_free_wddx_packet(zend_rsrc_list_entry *rsrc)
|
||||
{
|
||||
wddx_packet *packet = (wddx_packet *)rsrc->ptr;
|
||||
php_wddx_destructor(packet);
|
||||
smart_str *str = (smart_str *)rsrc->ptr;
|
||||
smart_str_free(str);
|
||||
efree(str);
|
||||
}
|
||||
|
||||
/* {{{ php_wddx_destructor */
|
||||
void php_wddx_destructor(wddx_packet *packet)
|
||||
{
|
||||
zend_llist_destroy(packet->packet_head);
|
||||
efree(packet->packet_head);
|
||||
efree(packet);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ php_minit_wddx */
|
||||
PHP_MINIT_FUNCTION(wddx)
|
||||
{
|
||||
le_wddx = zend_register_list_destructors_ex(php_free_wddx_packet, NULL, "wddx", module_number);
|
||||
le_wddx = zend_register_list_destructors_ex(release_wddx_packet_rsrc, NULL, "wddx", module_number);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
PHP_MINFO_FUNCTION(wddx)
|
||||
@ -256,43 +218,11 @@ PHP_MINFO_FUNCTION(wddx)
|
||||
php_info_print_table_end();
|
||||
}
|
||||
|
||||
/* {{{ php_wddx_add_chunk_ex */
|
||||
void php_wddx_add_chunk_ex(wddx_packet *packet, char *str, int length)
|
||||
{
|
||||
char *chunk;
|
||||
|
||||
chunk = estrndup(str, length);
|
||||
zend_llist_add_element(packet->packet_head, &chunk);
|
||||
packet->packet_length += length;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ php_wddx_gather */
|
||||
char* php_wddx_gather(wddx_packet *packet)
|
||||
{
|
||||
char **chunk_ptr;
|
||||
char *buf;
|
||||
|
||||
buf = (char *)emalloc(packet->packet_length+1);
|
||||
buf[0] = '\0';
|
||||
for(chunk_ptr = zend_llist_get_first(packet->packet_head);
|
||||
chunk_ptr != NULL;
|
||||
chunk_ptr = zend_llist_get_next(packet->packet_head)) {
|
||||
strcat(buf, *chunk_ptr);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ void php_wddx_packet_start */
|
||||
void php_wddx_packet_start(wddx_packet *packet, char *comment, int comment_len)
|
||||
{
|
||||
php_wddx_add_chunk_static(packet, WDDX_PACKET_S);
|
||||
if (comment)
|
||||
{
|
||||
if (comment) {
|
||||
php_wddx_add_chunk_static(packet, WDDX_HEADER_S);
|
||||
php_wddx_add_chunk_static(packet, WDDX_COMMENT_S);
|
||||
php_wddx_add_chunk_ex(packet, comment, comment_len);
|
||||
@ -302,16 +232,13 @@ void php_wddx_packet_start(wddx_packet *packet, char *comment, int comment_len)
|
||||
php_wddx_add_chunk_static(packet, WDDX_HEADER);
|
||||
php_wddx_add_chunk_static(packet, WDDX_DATA_S);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ int php_wddx_packet_end */
|
||||
void php_wddx_packet_end(wddx_packet *packet)
|
||||
{
|
||||
php_wddx_add_chunk_static(packet, WDDX_DATA_E);
|
||||
php_wddx_add_chunk_static(packet, WDDX_PACKET_E);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
#define FLUSH_BUF() \
|
||||
@ -320,7 +247,6 @@ void php_wddx_packet_end(wddx_packet *packet)
|
||||
l = 0; \
|
||||
}
|
||||
|
||||
/* {{{ void php_wddx_serialize_string(wddx_packet *packet, zval *var) */
|
||||
static void php_wddx_serialize_string(wddx_packet *packet, zval *var)
|
||||
{
|
||||
char *buf,
|
||||
@ -331,12 +257,12 @@ static void php_wddx_serialize_string(wddx_packet *packet, zval *var)
|
||||
|
||||
php_wddx_add_chunk_static(packet, WDDX_STRING_S);
|
||||
|
||||
if (var->value.str.len > 0) {
|
||||
if (Z_STRLEN_P(var) > 0) {
|
||||
l = 0;
|
||||
vend = var->value.str.val + var->value.str.len;
|
||||
buf = (char *)emalloc(var->value.str.len + 1);
|
||||
vend = Z_STRVAL_P(var) + Z_STRLEN_P(var);
|
||||
buf = (char *)emalloc(Z_STRLEN_P(var) + 1);
|
||||
|
||||
for(p = var->value.str.val; p != vend; p++) {
|
||||
for(p = Z_STRVAL_P(var); p != vend; p++) {
|
||||
switch (*p) {
|
||||
case '<':
|
||||
FLUSH_BUF();
|
||||
@ -370,10 +296,8 @@ static void php_wddx_serialize_string(wddx_packet *packet, zval *var)
|
||||
|
||||
php_wddx_add_chunk_static(packet, WDDX_STRING_E);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ void php_wddx_serialize_number(wddx_packet *packet, zval *var) */
|
||||
static void php_wddx_serialize_number(wddx_packet *packet, zval *var)
|
||||
{
|
||||
char tmp_buf[WDDX_BUF_LEN];
|
||||
@ -382,30 +306,25 @@ static void php_wddx_serialize_number(wddx_packet *packet, zval *var)
|
||||
tmp = *var;
|
||||
zval_copy_ctor(&tmp);
|
||||
convert_to_string(&tmp);
|
||||
sprintf(tmp_buf, WDDX_NUMBER, tmp.value.str.val);
|
||||
sprintf(tmp_buf, WDDX_NUMBER, Z_STRVAL(tmp));
|
||||
zval_dtor(&tmp);
|
||||
|
||||
php_wddx_add_chunk(packet, tmp_buf);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ void php_wddx_serialize_boolean(wddx_packet *packet, zval *var) */
|
||||
static void php_wddx_serialize_boolean(wddx_packet *packet, zval *var)
|
||||
{
|
||||
char tmp_buf[WDDX_BUF_LEN];
|
||||
|
||||
sprintf(tmp_buf, WDDX_BOOLEAN, var->value.lval ? "true" : "false");
|
||||
sprintf(tmp_buf, WDDX_BOOLEAN, Z_LVAL_P(var) ? "true" : "false");
|
||||
php_wddx_add_chunk(packet, tmp_buf);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ void php_wddx_serialize_unset(wddx_packet *packet, zval *var) */
|
||||
static void php_wddx_serialize_unset(wddx_packet *packet)
|
||||
{
|
||||
php_wddx_add_chunk_static(packet, WDDX_NULL);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void php_wddx_serialize_object(wddx_packet *packet, zval *obj)
|
||||
{
|
||||
@ -559,7 +478,6 @@ static void php_wddx_serialize_array(wddx_packet *packet, zval *arr)
|
||||
}
|
||||
|
||||
|
||||
/* {{{ void php_wddx_serialize_var(wddx_packet *packet, zval *var, char *name) */
|
||||
void php_wddx_serialize_var(wddx_packet *packet, zval *var, char *name)
|
||||
{
|
||||
char tmp_buf[WDDX_BUF_LEN];
|
||||
@ -569,7 +487,7 @@ void php_wddx_serialize_var(wddx_packet *packet, zval *var, char *name)
|
||||
php_wddx_add_chunk(packet, tmp_buf);
|
||||
}
|
||||
|
||||
switch(var->type) {
|
||||
switch(Z_TYPE_P(var)) {
|
||||
case IS_STRING:
|
||||
php_wddx_serialize_string(packet, var);
|
||||
break;
|
||||
@ -600,24 +518,22 @@ void php_wddx_serialize_var(wddx_packet *packet, zval *var, char *name)
|
||||
php_wddx_add_chunk_static(packet, WDDX_VAR_E);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ void php_wddx_add_var(wddx_packet *packet, zval *name_var) */
|
||||
static void php_wddx_add_var(wddx_packet *packet, zval *name_var)
|
||||
{
|
||||
zval **val;
|
||||
HashTable *target_hash;
|
||||
ELS_FETCH();
|
||||
|
||||
if (name_var->type == IS_STRING)
|
||||
if (Z_TYPE_P(name_var) == IS_STRING)
|
||||
{
|
||||
if (zend_hash_find(EG(active_symbol_table), name_var->value.str.val,
|
||||
name_var->value.str.len+1, (void**)&val) != FAILURE) {
|
||||
php_wddx_serialize_var(packet, *val, name_var->value.str.val);
|
||||
if (zend_hash_find(EG(active_symbol_table), Z_STRVAL_P(name_var),
|
||||
Z_STRLEN_P(name_var)+1, (void**)&val) != FAILURE) {
|
||||
php_wddx_serialize_var(packet, *val, Z_STRVAL_P(name_var));
|
||||
}
|
||||
}
|
||||
else if (name_var->type == IS_ARRAY || name_var->type == IS_OBJECT)
|
||||
else if (Z_TYPE_P(name_var) == IS_ARRAY || Z_TYPE_P(name_var) == IS_OBJECT)
|
||||
{
|
||||
target_hash = HASH_OF(name_var);
|
||||
|
||||
@ -630,10 +546,8 @@ static void php_wddx_add_var(wddx_packet *packet, zval *name_var)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ void php_wddx_push_element(void *user_data, const char *name, const char **atts) */
|
||||
static void php_wddx_push_element(void *user_data, const char *name, const char **atts)
|
||||
{
|
||||
st_entry ent;
|
||||
@ -648,24 +562,24 @@ static void php_wddx_push_element(void *user_data, const char *name, const char
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(name, EL_STRING)) {
|
||||
ent.type = ST_STRING;
|
||||
Z_TYPE(ent) = ST_STRING;
|
||||
SET_STACK_VARNAME;
|
||||
|
||||
ALLOC_ZVAL(ent.data);
|
||||
INIT_PZVAL(ent.data);
|
||||
ent.data->type = IS_STRING;
|
||||
ent.data->value.str.val = empty_string;
|
||||
ent.data->value.str.len = 0;
|
||||
Z_TYPE_P(ent.data) = IS_STRING;
|
||||
Z_STRVAL_P(ent.data) = empty_string;
|
||||
Z_STRLEN_P(ent.data) = 0;
|
||||
wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry));
|
||||
} else if (!strcmp(name, EL_BINARY)) {
|
||||
ent.type = ST_BINARY;
|
||||
Z_TYPE(ent) = ST_BINARY;
|
||||
SET_STACK_VARNAME;
|
||||
|
||||
ALLOC_ZVAL(ent.data);
|
||||
INIT_PZVAL(ent.data);
|
||||
ent.data->type = IS_STRING;
|
||||
ent.data->value.str.val = empty_string;
|
||||
ent.data->value.str.len = 0;
|
||||
Z_TYPE_P(ent.data) = IS_STRING;
|
||||
Z_STRVAL_P(ent.data) = empty_string;
|
||||
Z_STRLEN_P(ent.data) = 0;
|
||||
wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry));
|
||||
} else if (!strcmp(name, EL_CHAR)) {
|
||||
int i;
|
||||
@ -678,24 +592,24 @@ static void php_wddx_push_element(void *user_data, const char *name, const char
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(name, EL_NUMBER)) {
|
||||
ent.type = ST_NUMBER;
|
||||
Z_TYPE(ent) = ST_NUMBER;
|
||||
SET_STACK_VARNAME;
|
||||
|
||||
ALLOC_ZVAL(ent.data);
|
||||
INIT_PZVAL(ent.data);
|
||||
ent.data->type = IS_LONG;
|
||||
Z_TYPE_P(ent.data) = IS_LONG;
|
||||
wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry));
|
||||
} else if (!strcmp(name, EL_BOOLEAN)) {
|
||||
int i;
|
||||
|
||||
for (i=0; atts[i]; i++) {
|
||||
if (!strcmp(atts[i], EL_VALUE) && atts[i+1]) {
|
||||
ent.type = ST_BOOLEAN;
|
||||
Z_TYPE(ent) = ST_BOOLEAN;
|
||||
SET_STACK_VARNAME;
|
||||
|
||||
ALLOC_ZVAL(ent.data);
|
||||
INIT_PZVAL(ent.data);
|
||||
ent.data->type = IS_BOOL;
|
||||
Z_TYPE_P(ent.data) = IS_BOOL;
|
||||
wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry));
|
||||
php_wddx_process_data(user_data, atts[i+1], strlen(atts[i+1]));
|
||||
}
|
||||
@ -738,10 +652,8 @@ static void php_wddx_push_element(void *user_data, const char *name, const char
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ void php_wddx_pop_element(void *user_data, const char *name) */
|
||||
static void php_wddx_pop_element(void *user_data, const char *name)
|
||||
{
|
||||
st_entry *ent1, *ent2;
|
||||
@ -772,7 +684,7 @@ static void php_wddx_pop_element(void *user_data, const char *name)
|
||||
}
|
||||
|
||||
/* Call __wakeup() method on the object. */
|
||||
if (ent1->data->type == IS_OBJECT) {
|
||||
if (Z_TYPE_P(ent1->data) == IS_OBJECT) {
|
||||
zval *fname, *retval = NULL;
|
||||
|
||||
MAKE_STD_ZVAL(fname);
|
||||
@ -789,17 +701,17 @@ static void php_wddx_pop_element(void *user_data, const char *name)
|
||||
if (stack->top > 1) {
|
||||
stack->top--;
|
||||
wddx_stack_top(stack, (void**)&ent2);
|
||||
if (ent2->data->type == IS_ARRAY || ent2->data->type == IS_OBJECT) {
|
||||
if (Z_TYPE_P(ent2->data) == IS_ARRAY || Z_TYPE_P(ent2->data) == IS_OBJECT) {
|
||||
target_hash = HASH_OF(ent2->data);
|
||||
|
||||
if (ent1->varname) {
|
||||
if (!strcmp(ent1->varname, PHP_CLASS_NAME_VAR) &&
|
||||
ent1->data->type == IS_STRING && ent1->data->value.str.len) {
|
||||
Z_TYPE_P(ent1->data) == IS_STRING && Z_STRLEN_P(ent1->data)) {
|
||||
zend_bool incomplete_class = 0;
|
||||
|
||||
zend_str_tolower(ent1->data->value.str.val, ent1->data->value.str.len);
|
||||
if (zend_hash_find(EG(class_table), ent1->data->value.str.val,
|
||||
ent1->data->value.str.len+1, (void **) &ce)==FAILURE) {
|
||||
zend_str_tolower(Z_STRVAL_P(ent1->data), Z_STRLEN_P(ent1->data));
|
||||
if (zend_hash_find(EG(class_table), Z_STRVAL_P(ent1->data),
|
||||
Z_STRLEN_P(ent1->data)+1, (void **) &ce)==FAILURE) {
|
||||
BLS_FETCH();
|
||||
|
||||
incomplete_class = 1;
|
||||
@ -813,12 +725,12 @@ static void php_wddx_pop_element(void *user_data, const char *name)
|
||||
|
||||
/* Merge current hashtable with object's default properties */
|
||||
zend_hash_merge(obj->value.obj.properties,
|
||||
ent2->data->value.ht,
|
||||
Z_ARRVAL_P(ent2->data),
|
||||
(void (*)(void *)) zval_add_ref,
|
||||
(void *) &tmp, sizeof(zval *), 0);
|
||||
|
||||
if (incomplete_class)
|
||||
php_store_class_name(obj, ent1->data->value.str.val, ent1->data->value.str.len);
|
||||
php_store_class_name(obj, Z_STRVAL_P(ent1->data), Z_STRLEN_P(ent1->data));
|
||||
|
||||
/* Clean up old array entry */
|
||||
zval_dtor(ent2->data);
|
||||
@ -848,10 +760,8 @@ static void php_wddx_pop_element(void *user_data, const char *name)
|
||||
else if (!strcmp(name, EL_VAR) && stack->varname)
|
||||
efree(stack->varname);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ void php_wddx_process_data(void *user_data, const char *s, int len) */
|
||||
static void php_wddx_process_data(void *user_data, const char *s, int len)
|
||||
{
|
||||
st_entry *ent;
|
||||
@ -861,19 +771,19 @@ static void php_wddx_process_data(void *user_data, const char *s, int len)
|
||||
|
||||
if (!wddx_stack_is_empty(stack)) {
|
||||
wddx_stack_top(stack, (void**)&ent);
|
||||
switch (ent->type) {
|
||||
switch (Z_TYPE_P(ent)) {
|
||||
case ST_STRING:
|
||||
decoded_value = xml_utf8_decode(s,len,&decoded_len,"ISO-8859-1");
|
||||
|
||||
if (ent->data->value.str.len == 0) {
|
||||
ent->data->value.str.val = estrndup(decoded_value, decoded_len);
|
||||
ent->data->value.str.len = decoded_len;
|
||||
if (Z_STRLEN_P(ent->data) == 0) {
|
||||
Z_STRVAL_P(ent->data) = estrndup(decoded_value, decoded_len);
|
||||
Z_STRLEN_P(ent->data) = decoded_len;
|
||||
} else {
|
||||
ent->data->value.str.val = erealloc(ent->data->value.str.val,
|
||||
ent->data->value.str.len + decoded_len + 1);
|
||||
strncpy(ent->data->value.str.val+ent->data->value.str.len, decoded_value, decoded_len);
|
||||
ent->data->value.str.len += decoded_len;
|
||||
ent->data->value.str.val[ent->data->value.str.len] = '\0';
|
||||
Z_STRVAL_P(ent->data) = erealloc(Z_STRVAL_P(ent->data),
|
||||
Z_STRLEN_P(ent->data) + decoded_len + 1);
|
||||
strncpy(Z_STRVAL_P(ent->data)+Z_STRLEN_P(ent->data), decoded_value, decoded_len);
|
||||
Z_STRLEN_P(ent->data) += decoded_len;
|
||||
Z_STRVAL_P(ent->data)[Z_STRLEN_P(ent->data)] = '\0';
|
||||
}
|
||||
|
||||
efree(decoded_value);
|
||||
@ -891,17 +801,17 @@ static void php_wddx_process_data(void *user_data, const char *s, int len)
|
||||
break;
|
||||
|
||||
case ST_NUMBER:
|
||||
ent->data->type = IS_STRING;
|
||||
ent->data->value.str.len = len;
|
||||
ent->data->value.str.val = estrndup(s, len);
|
||||
Z_TYPE_P(ent->data) = IS_STRING;
|
||||
Z_STRLEN_P(ent->data) = len;
|
||||
Z_STRVAL_P(ent->data) = estrndup(s, len);
|
||||
convert_scalar_to_number(ent->data);
|
||||
break;
|
||||
|
||||
case ST_BOOLEAN:
|
||||
if (!strcmp(s, "true"))
|
||||
ent->data->value.lval = 1;
|
||||
Z_LVAL_P(ent->data) = 1;
|
||||
else if (!strcmp(s, "false"))
|
||||
ent->data->value.lval = 0;
|
||||
Z_LVAL_P(ent->data) = 0;
|
||||
else {
|
||||
stack->top--;
|
||||
zval_dtor(ent->data);
|
||||
@ -917,10 +827,7 @@ static void php_wddx_process_data(void *user_data, const char *s, int len)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ int php_wddx_deserialize_ex(char *value, int vallen, zval *return_value) */
|
||||
int php_wddx_deserialize_ex(char *value, int vallen, zval *return_value)
|
||||
{
|
||||
wddx_stack stack;
|
||||
@ -951,7 +858,6 @@ int php_wddx_deserialize_ex(char *value, int vallen, zval *return_value)
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ proto string wddx_serialize_value(mixed var [, string comment])
|
||||
@ -962,7 +868,6 @@ PHP_FUNCTION(wddx_serialize_value)
|
||||
zval **var,
|
||||
**comment;
|
||||
wddx_packet *packet;
|
||||
char *buf;
|
||||
|
||||
argc = ZEND_NUM_ARGS();
|
||||
if(argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &var, &comment) == FAILURE) {
|
||||
@ -977,17 +882,17 @@ PHP_FUNCTION(wddx_serialize_value)
|
||||
if (argc == 2)
|
||||
{
|
||||
convert_to_string_ex(comment);
|
||||
php_wddx_packet_start(packet, (*comment)->value.str.val, (*comment)->value.str.len);
|
||||
php_wddx_packet_start(packet, Z_STRVAL_PP(comment), Z_STRLEN_PP(comment));
|
||||
}
|
||||
else
|
||||
php_wddx_packet_start(packet, NULL, 0);
|
||||
|
||||
php_wddx_serialize_var(packet, (*var), NULL);
|
||||
php_wddx_packet_end(packet);
|
||||
buf = php_wddx_gather(packet);
|
||||
php_wddx_destructor(packet);
|
||||
|
||||
RETURN_STRING(buf, 0);
|
||||
ZVAL_STRINGL(return_value, packet->c, packet->len, 1);
|
||||
smart_str_free(packet);
|
||||
efree(packet);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -999,7 +904,6 @@ PHP_FUNCTION(wddx_serialize_vars)
|
||||
int argc, i;
|
||||
wddx_packet *packet;
|
||||
zval ***args;
|
||||
char *buf;
|
||||
|
||||
argc = ZEND_NUM_ARGS();
|
||||
/* Allocate arguments array and get the arguments, checking for errors. */
|
||||
@ -1018,33 +922,28 @@ PHP_FUNCTION(wddx_serialize_vars)
|
||||
php_wddx_add_chunk_static(packet, WDDX_STRUCT_S);
|
||||
|
||||
for (i=0; i<argc; i++) {
|
||||
if ((*args[i])->type != IS_ARRAY && (*args[i])->type != IS_OBJECT)
|
||||
if (Z_TYPE_PP(args[i]) != IS_ARRAY && Z_TYPE_PP(args[i]) != IS_OBJECT)
|
||||
convert_to_string_ex(args[i]);
|
||||
php_wddx_add_var(packet, *args[i]);
|
||||
}
|
||||
|
||||
php_wddx_add_chunk_static(packet, WDDX_STRUCT_E);
|
||||
php_wddx_packet_end(packet);
|
||||
buf = php_wddx_gather(packet);
|
||||
php_wddx_destructor(packet);
|
||||
|
||||
efree(args);
|
||||
|
||||
RETURN_STRING(buf, 0);
|
||||
|
||||
ZVAL_STRINGL(return_value, packet->c, packet->len, 1);
|
||||
smart_str_free(packet);
|
||||
efree(packet);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
wddx_packet *php_wddx_constructor(void)
|
||||
{
|
||||
wddx_packet *packet;
|
||||
smart_str *packet;
|
||||
|
||||
packet = emalloc(sizeof(wddx_packet));
|
||||
if(!packet) return NULL;
|
||||
|
||||
packet->packet_head = (zend_llist *)emalloc(sizeof(zend_llist));
|
||||
zend_llist_init(packet->packet_head, sizeof(char *),
|
||||
_php_free_packet_chunk, 0);
|
||||
packet->packet_length = 0;
|
||||
packet = (smart_str *)emalloc(sizeof(smart_str));
|
||||
packet->c = NULL;
|
||||
|
||||
return packet;
|
||||
}
|
||||
@ -1071,9 +970,8 @@ PHP_FUNCTION(wddx_packet_start)
|
||||
|
||||
if (argc == 1) {
|
||||
convert_to_string_ex(comment);
|
||||
php_wddx_packet_start(packet, (*comment)->value.str.val, (*comment)->value.str.len);
|
||||
}
|
||||
else
|
||||
php_wddx_packet_start(packet, Z_STRVAL_PP(comment), Z_STRLEN_PP(comment));
|
||||
} else
|
||||
php_wddx_packet_start(packet, NULL, 0);
|
||||
|
||||
php_wddx_add_chunk_static(packet, WDDX_STRUCT_S);
|
||||
@ -1088,7 +986,6 @@ PHP_FUNCTION(wddx_packet_start)
|
||||
PHP_FUNCTION(wddx_packet_end)
|
||||
{
|
||||
zval **packet_id;
|
||||
char *buf;
|
||||
wddx_packet *packet = NULL;
|
||||
|
||||
if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &packet_id)==FAILURE) {
|
||||
@ -1101,11 +998,9 @@ PHP_FUNCTION(wddx_packet_end)
|
||||
|
||||
php_wddx_packet_end(packet);
|
||||
|
||||
buf = php_wddx_gather(packet);
|
||||
|
||||
zend_list_delete((*packet_id)->value.lval);
|
||||
|
||||
RETURN_STRING(buf, 0);
|
||||
ZVAL_STRINGL(return_value, packet->c, packet->len, 1);
|
||||
|
||||
zend_list_delete(Z_LVAL_PP(packet_id));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -1141,7 +1036,7 @@ PHP_FUNCTION(wddx_add_vars)
|
||||
}
|
||||
|
||||
for (i=1; i<argc; i++) {
|
||||
if ((*args[i])->type != IS_ARRAY && (*args[i])->type != IS_OBJECT)
|
||||
if (Z_TYPE_PP(args[i]) != IS_ARRAY && Z_TYPE_PP(args[i]) != IS_OBJECT)
|
||||
convert_to_string_ex(args[i]);
|
||||
php_wddx_add_var(packet, (*args[i]));
|
||||
}
|
||||
@ -1163,7 +1058,7 @@ PHP_FUNCTION(wddx_deserialize)
|
||||
}
|
||||
|
||||
convert_to_string_ex(packet);
|
||||
if ((*packet)->value.str.len == 0)
|
||||
if (Z_STRLEN_PP(packet) == 0)
|
||||
return;
|
||||
|
||||
php_wddx_deserialize(*packet, return_value);
|
||||
|
Loading…
Reference in New Issue
Block a user