CVS update: php3/functions
| From: | sas | Date: | Sun, 10 Jan 1999 14:35:01 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-3444@lists.php.net to get a copy of this message | ||
Date: Sunday January 10, 1999 @ 9:35
Author: sas
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv20816
Modified Files:
wddx.c
Log Message:
Allow
$var = "xyz";
wddx_serialize(&$abc, "bar", "foo");
resulting in
<var name='abc'><string>xyz</string></var>
<var name='foo'><string>bar</string></var>
Index: php3/functions/wddx.c
diff -c php3/functions/wddx.c:1.3 php3/functions/wddx.c:1.4
*** php3/functions/wddx.c:1.3 Thu Jan 7 09:17:32 1999
--- php3/functions/wddx.c Sun Jan 10 09:35:00 1999
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: wddx.c,v 1.3 1999/01/07 14:17:32 sas Exp $ */
#include "php.h"
#include "internal_functions.h"
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: wddx.c,v 1.4 1999/01/10 14:35:00 sas Exp $ */
#include "php.h"
#include "internal_functions.h"
***************
*** 222,228 ****
--- 222,301 ----
return _php3_wddx_var(name, str);
}
/* }}} */
+ /* {{{ _php3_wddx_get_parameter_name() */
+
+ /*
+ * This won't work in PHP 3.1
+ */
+
+ static char *_php3_wddx_get_parameter_name(pval *obj)
+ {
+ pval *orig;
+
+ _php3_hash_internal_pointer_reset(GLOBAL(active_symbol_table));
+ while(_php3_hash_get_current_data(GLOBAL(active_symbol_table),
+ (void **) &orig) == SUCCESS) {
+ if(orig == obj) {
+ char *str = NULL;
+ ulong ndx;
+
+ _php3_hash_get_current_key(GLOBAL(active_symbol_table),
+ &str, &ndx);
+ if(str)
+ return str;
+ break;
+ }
+ _php3_hash_move_forward(GLOBAL(active_symbol_table));
+ }
+ return NULL;
+ }
+ /* }}} */
+ /* {{{ _php3_wddx_args_array() */
+
+ static char *_php3_wddx_args_array(HashTable *ht, pval **args, int count)
+ {
+ int i;
+ int len = 0;
+ int freename;
+ char *str = NULL;
+ char *new;
+ char *name;
+ pval *obj;
+
+ for(i = 0; i < count; i++) {
+ /* depending on how the parameter was passed... */
+ obj = args[i];
+ if(ParameterPassedByReference(ht, i+1)) {
+ /* ...we use its variable name */
+ name = _php3_wddx_get_parameter_name(args[i]);
+ freename = 1;
+ } else {
+ /* ...or the content of the variable behind it */
+ i++;
+ if(i >= count) {
+ /* too few arguments */
+ if(str) efree(str);
+ return empty_string;
+ }
+ convert_to_string(args[i]);
+ name = args[i]->value.str.val;
+ freename = 0;
+ }
+ new = _php3_wddx_build(name, obj);
+ len += strlen(new);
+ if(str) {
+ str = erealloc(str, len + 1);
+ strcat(str, new);
+ efree(new);
+ } else {
+ str = new;
+ }
+ if(freename && name) efree(name);
+ }
+ return str;
+ }
/* }}} */
+ /* }}} */
/* {{{ functions needed to unserialize */
/* buffer management and strcat */
***************
*** 336,342 ****
memset(&wddx, 0, sizeof(wddx));
XML_SetUserData(parser, &wddx);
! XML_SetElementHandler(parser, _php3_wddx_start_element, _php3_wddx_end_element),
XML_SetCharacterDataHandler(parser, _php3_wddx_char_data);
XML_Parse(parser, buf, strlen(buf), 1);
XML_ParserFree(parser);
--- 409,416 ----
memset(&wddx, 0, sizeof(wddx));
XML_SetUserData(parser, &wddx);
! XML_SetElementHandler(parser, _php3_wddx_start_element,
! _php3_wddx_end_element),
XML_SetCharacterDataHandler(parser, _php3_wddx_char_data);
XML_Parse(parser, buf, strlen(buf), 1);
XML_ParserFree(parser);
***************
*** 349,375 ****
creates a WDDX conforming representation of its arguments */
PHP_FUNCTION(wddx_serialize)
{
! pval *arg;
int ac = ARG_COUNT(ht);
char *str;
char *new;
! if(ac != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
! if(!(arg->type & IS_HASH)) {
! php3_error(E_WARNING, "_php3_wddx_serialize not called with array as argument");
! RETURN_FALSE;
}
! str = _php3_wddx_struct_or_array(arg->value.ht);
! new = emalloc(strlen(str) + 100);
! sprintf(new, "<wddxPacket version='0.9'><header/><data>%s"
! "</data></wddxPacket>", str);
! efree(str);
! RETURN_STRING(new, 0);
}
/* }}} */
--- 423,456 ----
creates a WDDX conforming representation of its arguments */
PHP_FUNCTION(wddx_serialize)
{
! pval **args;
int ac = ARG_COUNT(ht);
char *str;
char *new;
! if(ac == 0 || (!(args = emalloc(sizeof(*args) * ac))) ||
! getParametersArray(ht, ac, args) == FAILURE) {
WRONG_PARAM_COUNT;
}
! if(ac == 1 && args[0]->type & IS_HASH) {
! str = _php3_wddx_struct_or_array(args[0]->value.ht);
! } else {
! str = _php3_wddx_args_array(ht, args, ac);
}
! efree(args);
!
! if(str) {
! new = emalloc(strlen(str) + 100);
! sprintf(new, "<wddxPacket version='0.9'><header/><data>%s"
! "</data></wddxPacket>", str);
! efree(str);
! RETURN_STRING(new, 0);
! } else {
! RETURN_FALSE;
! }
}
/* }}} */
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net