From 58c25fb24a28c055026c983b40c99d2d5ffe74a6 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sat, 28 Jun 2003 06:55:47 +0000 Subject: [PATCH] Added missing handling of dateTime Fixed compiler warning involving streams Added a test case for wddx_deserialize() --- ext/wddx/tests/001.phpt | 57 +++++++++++++++++++++++++++++++++++++++ ext/wddx/tests/wddx.xml | 60 +++++++++++++++++++++++++++++++++++++++++ ext/wddx/wddx.c | 36 ++++++++++++++++++++++--- 3 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 ext/wddx/tests/001.phpt create mode 100644 ext/wddx/tests/wddx.xml diff --git a/ext/wddx/tests/001.phpt b/ext/wddx/tests/001.phpt new file mode 100644 index 0000000000..857cc2f304 --- /dev/null +++ b/ext/wddx/tests/001.phpt @@ -0,0 +1,57 @@ +--TEST-- +wddz deserialization test +--FILE-- + +--EXPECT-- +array(11) { + ["aNull"]=> + NULL + ["aString"]=> + string(8) "a string" + ["aNumber"]=> + float(-12.456) + ["aDateTime"]=> + int(897600732) + ["aDateTime2"]=> + string(19) "1930-06-12T04:32:12" + ["aDateTime3"]=> + string(19) "2040-06-12T04:32:12" + ["aBoolean"]=> + bool(true) + ["anArray"]=> + array(2) { + [0]=> + int(10) + [1]=> + string(14) "second element" + } + ["aBinary"]=> + string(11) "binary data" + ["anObject"]=> + array(2) { + ["s"]=> + string(8) "a string" + ["n"]=> + float(-12.456) + } + ["aRecordset"]=> + array(2) { + ["NAME"]=> + array(2) { + [0]=> + string(8) "John Doe" + [1]=> + string(8) "Jane Doe" + } + ["AGE"]=> + array(2) { + [0]=> + int(34) + [1]=> + int(31) + } + } +} diff --git a/ext/wddx/tests/wddx.xml b/ext/wddx/tests/wddx.xml new file mode 100644 index 0000000000..8713159636 --- /dev/null +++ b/ext/wddx/tests/wddx.xml @@ -0,0 +1,60 @@ + + + +
+ + + + + + + a string + + + -12.456 + + + 1998-06-12T04:32:12 + + + 1930-06-12T04:32:12 + + + 2040-06-12T04:32:12 + + + + + + + 10 + second element + + + + YmluYXJ5IGRhdGE= + + + + + a string + + + -12.456 + + + + + + + John Doe + Jane Doe + + + 34 + 31 + + + + + diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c index 1f25a328b3..959b66ad88 100644 --- a/ext/wddx/wddx.c +++ b/ext/wddx/wddx.c @@ -34,6 +34,7 @@ #include "ext/standard/php_smart_str.h" #include "ext/standard/html.h" #include "ext/standard/php_string.h" +#include "ext/standard/php_parsedate.h" #define WDDX_BUF_LEN 256 #define PHP_CLASS_NAME_VAR "php_class_name" @@ -54,6 +55,7 @@ #define EL_VERSION "version" #define EL_RECORDSET "recordset" #define EL_FIELD "field" +#define EL_DATETIME "dateTime" #define php_wddx_deserialize(a,b) \ php_wddx_deserialize_ex((a)->value.str.val, (a)->value.str.len, (b)) @@ -79,7 +81,8 @@ typedef struct { ST_BINARY, ST_STRUCT, ST_RECORDSET, - ST_FIELD + ST_FIELD, + ST_DATETIME } type; char *varname; } st_entry; @@ -860,6 +863,14 @@ static void php_wddx_push_element(void *user_data, const char *name, const char } } + wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry)); + } else if (!strcmp(name, EL_DATETIME)) { + ent.type = ST_DATETIME; + SET_STACK_VARNAME; + + ALLOC_ZVAL(ent.data); + INIT_PZVAL(ent.data); + Z_TYPE_P(ent.data) = IS_LONG; wddx_stack_push((wddx_stack *)stack, &ent, sizeof(st_entry)); } } @@ -884,7 +895,8 @@ static void php_wddx_pop_element(void *user_data, const char *name) if (!strcmp(name, EL_STRING) || !strcmp(name, EL_NUMBER) || !strcmp(name, EL_BOOLEAN) || !strcmp(name, EL_NULL) || !strcmp(name, EL_ARRAY) || !strcmp(name, EL_STRUCT) || - !strcmp(name, EL_RECORDSET) || !strcmp(name, EL_BINARY)) { + !strcmp(name, EL_RECORDSET) || !strcmp(name, EL_BINARY) || + !strcmp(name, EL_DATETIME)) { wddx_stack_top(stack, (void**)&ent1); if (!strcmp(name, EL_BINARY)) { @@ -1048,6 +1060,24 @@ static void php_wddx_process_data(void *user_data, const char *s, int len) } break; + case ST_DATETIME: { + char *tmp; + + tmp = do_alloca(len + 1); + memcpy(tmp, s, len); + tmp[len] = '\0'; + + Z_LVAL_P(ent->data) = php_parse_date(tmp, NULL); + /* date out of range < 1969 or > 2038 */ + if (Z_LVAL_P(ent->data) == -1) { + Z_TYPE_P(ent->data) = IS_STRING; + Z_STRLEN_P(ent->data) = len; + Z_STRVAL_P(ent->data) = estrndup(s, len); + } + free_alloca(tmp); + } + break; + default: break; } @@ -1280,7 +1310,7 @@ PHP_FUNCTION(wddx_deserialize) payload_len = Z_STRLEN_P(packet); } else if (Z_TYPE_P(packet) == IS_RESOURCE) { - stream = php_stream_from_zval(stream, &packet); + php_stream_from_zval(stream, &packet); if (stream) { payload_len = php_stream_copy_to_mem(stream, &payload, PHP_STREAM_COPY_ALL, 0); } -- 2.50.1