summaryrefslogtreecommitdiff
path: root/ext/rpc
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2003-01-14 21:04:47 +0000
committerIlia Alshanetsky <iliaa@php.net>2003-01-14 21:04:47 +0000
commite37aee1a34f8af77cce71468e70b2e268664f1bd (patch)
tree8b3f9bf99a12afb20b90366da74b14a643539612 /ext/rpc
parenta0b3f822f7809d4a2c3a88580134c8ed011b835c (diff)
downloadphp-git-e37aee1a34f8af77cce71468e70b2e268664f1bd.tar.gz
Porting of patch applied to ext/xmlrpc.
Diffstat (limited to 'ext/rpc')
-rw-r--r--ext/rpc/xmlrpc/xmlrpc-epi-php.c754
1 files changed, 354 insertions, 400 deletions
diff --git a/ext/rpc/xmlrpc/xmlrpc-epi-php.c b/ext/rpc/xmlrpc/xmlrpc-epi-php.c
index f3316bbd81..611f7cf7d6 100644
--- a/ext/rpc/xmlrpc/xmlrpc-epi-php.c
+++ b/ext/rpc/xmlrpc/xmlrpc-epi-php.c
@@ -307,11 +307,7 @@ static int add_zval(zval* list, const char* id, zval** val)
return 0;
}
-#if ZEND_MODULE_API_NO >= 20001222
#define my_zend_hash_get_current_key(ht, my_key, num_index) zend_hash_get_current_key(ht, my_key, num_index, 0)
-#else
-#define my_zend_hash_get_current_key(ht, my_key, num_index) zend_hash_get_current_key(ht, my_key, num_index)
-#endif
/*************************
@@ -610,18 +606,19 @@ static zval* XMLRPC_to_PHP(XMLRPC_VALUE el)
}
break;
case xmlrpc_vector:
- if(array_init(elem) == SUCCESS) {
- XMLRPC_VALUE xIter = XMLRPC_VectorRewind(el);
-
- while( xIter ) {
- zval* val = XMLRPC_to_PHP(xIter);
- if(val) {
- add_zval(elem, XMLRPC_GetValueID(xIter), &val);
- }
- xIter = XMLRPC_VectorNext(el);
- }
- }
- break;
+ array_init(elem);
+ {
+ XMLRPC_VALUE xIter = XMLRPC_VectorRewind(el);
+
+ while( xIter ) {
+ zval *val = XMLRPC_to_PHP(xIter);
+ if (val) {
+ add_zval(elem, XMLRPC_GetValueID(xIter), &val);
+ }
+ xIter = XMLRPC_VectorNext(el);
+ }
+ }
+ break;
default:
break;
}
@@ -634,43 +631,40 @@ static zval* XMLRPC_to_PHP(XMLRPC_VALUE el)
Generates XML for a method request */
PHP_FUNCTION(xmlrpc_encode_request)
{
- XMLRPC_REQUEST xRequest = NULL;
- zval* method, *vals, *out_opts;
- char* outBuf;
- php_output_options out;
-
- if( !(ARG_COUNT(ht) == 2 || ARG_COUNT(ht) == 3) ||
- getParameters(ht, ARG_COUNT(ht), &method, &vals, &out_opts) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ XMLRPC_REQUEST xRequest = NULL;
+ zval **method, **vals, **out_opts;
+ char* outBuf;
+ php_output_options out;
- set_output_options(&out, (ARG_COUNT(ht) == 3) ? out_opts : 0);
+ if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 || (zend_get_parameters_ex(ZEND_NUM_ARGS(), &method, &vals, &out_opts) == FAILURE)) {
+ WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
+ }
+ set_output_options(&out, (ZEND_NUM_ARGS() == 3) ? *out_opts : 0);
- if(return_value_used) {
- xRequest = XMLRPC_RequestNew();
+ if(return_value_used) {
+ xRequest = XMLRPC_RequestNew();
- if(xRequest) {
- XMLRPC_RequestSetOutputOptions(xRequest, &out.xmlrpc_out);
- if(Z_TYPE_P(method) == IS_NULL) {
- XMLRPC_RequestSetRequestType(xRequest, xmlrpc_request_response);
- }
- else {
- XMLRPC_RequestSetMethodName(xRequest, Z_STRVAL_P(method));
- XMLRPC_RequestSetRequestType(xRequest, xmlrpc_request_call);
- }
- if(Z_TYPE_P(vals) != IS_NULL) {
- XMLRPC_RequestSetData(xRequest, PHP_to_XMLRPC(vals));
- }
+ if(xRequest) {
+ XMLRPC_RequestSetOutputOptions(xRequest, &out.xmlrpc_out);
+ if (Z_TYPE_PP(method) == IS_NULL) {
+ XMLRPC_RequestSetRequestType(xRequest, xmlrpc_request_response);
+ } else {
+ XMLRPC_RequestSetMethodName(xRequest, Z_STRVAL_PP(method));
+ XMLRPC_RequestSetRequestType(xRequest, xmlrpc_request_call);
+ }
+ if (Z_TYPE_PP(vals) != IS_NULL) {
+ XMLRPC_RequestSetData(xRequest, PHP_to_XMLRPC(*vals));
+ }
- outBuf = XMLRPC_REQUEST_ToXML(xRequest, 0);
- if(outBuf) {
- RETVAL_STRING(outBuf, 1);
- free(outBuf);
- }
- XMLRPC_RequestFree(xRequest, 1);
- }
- }
+ outBuf = XMLRPC_REQUEST_ToXML(xRequest, 0);
+ if(outBuf) {
+ RETVAL_STRING(outBuf, 1);
+ free(outBuf);
+ }
+ XMLRPC_RequestFree(xRequest, 1);
+ }
+ }
}
/* }}} */
@@ -678,31 +672,30 @@ PHP_FUNCTION(xmlrpc_encode_request)
Generates XML for a PHP value */
PHP_FUNCTION(xmlrpc_encode)
{
- XMLRPC_VALUE xOut = NULL;
- zval* arg1;
- char* outBuf;
+ XMLRPC_VALUE xOut = NULL;
+ zval **arg1;
+ char *outBuf;
- if( !(ARG_COUNT(ht) == 1) ||
- getParameters(ht, ARG_COUNT(ht), &arg1) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &arg1) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- if( return_value_used ) {
- /* convert native php type to xmlrpc type */
- xOut = PHP_to_XMLRPC(arg1);
+ if( return_value_used ) {
+ /* convert native php type to xmlrpc type */
+ xOut = PHP_to_XMLRPC(*arg1);
- /* generate raw xml from xmlrpc data */
- outBuf = XMLRPC_VALUE_ToXML(xOut, 0);
+ /* generate raw xml from xmlrpc data */
+ outBuf = XMLRPC_VALUE_ToXML(xOut, 0);
- if(xOut) {
- if(outBuf) {
- RETVAL_STRING(outBuf, 1);
- free(outBuf);
- }
- /* cleanup */
- XMLRPC_CleanupValue(xOut);
- }
- }
+ if(xOut) {
+ if(outBuf) {
+ RETVAL_STRING(outBuf, 1);
+ free(outBuf);
+ }
+ /* cleanup */
+ XMLRPC_CleanupValue(xOut);
+ }
+ }
}
/* }}} */
@@ -739,30 +732,26 @@ zval* decode_request_worker (zval* xml_in, zval* encoding_in, zval* method_name_
Decodes XML into native PHP types */
PHP_FUNCTION(xmlrpc_decode_request)
{
- zval* xml, *method, *encoding = NULL;
+ zval **xml, **method, **encoding = NULL;
+ int argc = ZEND_NUM_ARGS();
- if( !(ARG_COUNT(ht) == 2 || ARG_COUNT(ht) == 3) || getParameters(ht, ARG_COUNT(ht), &xml, &method, &encoding) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
-#if ZEND_MODULE_API_NO < 20010901
- if (!ParameterPassedByReference(ht,2)) {
- zend_error(E_WARNING,"second argument to xmlrpc_decode_request() passed by value, expecting reference");
- }
-#endif
+ if (argc < 2 || argc > 3 || (zend_get_parameters_ex(argc, &xml, &method, &encoding) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- convert_to_string(xml);
- convert_to_string(method);
- if(ARG_COUNT(ht) == 3) {
- convert_to_string(encoding);
- }
+ convert_to_string_ex(xml);
+ convert_to_string_ex(method);
+ if(argc == 3) {
+ convert_to_string_ex(encoding);
+ }
- if(return_value_used) {
- zval* retval = decode_request_worker(xml, encoding, method);
- if(retval) {
- *return_value = *retval;
- FREE_ZVAL(retval);
- }
- }
+ if(return_value_used) {
+ zval* retval = decode_request_worker(*xml, *encoding, *method);
+ if(retval) {
+ *return_value = *retval;
+ FREE_ZVAL(retval);
+ }
+ }
}
/* }}} */
@@ -771,24 +760,25 @@ PHP_FUNCTION(xmlrpc_decode_request)
Decodes XML into native PHP types */
PHP_FUNCTION(xmlrpc_decode)
{
- zval* arg1, *arg2 = NULL;
+ zval **arg1, **arg2 = NULL;
+ int argc = ZEND_NUM_ARGS();
- if( !(ARG_COUNT(ht) == 1 || ARG_COUNT(ht) == 2) || getParameters(ht, ARG_COUNT(ht), &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (argc < 1 || argc > 2 || (zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- convert_to_string(arg1);
- if(ARG_COUNT(ht) == 2) {
- convert_to_string(arg2);
- }
+ convert_to_string_ex(arg1);
+ if(argc == 2) {
+ convert_to_string_ex(arg2);
+ }
- if(return_value_used) {
- zval* retval = decode_request_worker(arg1, arg2, NULL);
- if(retval) {
- *return_value = *retval;
- FREE_ZVAL(retval);
- }
- }
+ if(return_value_used) {
+ zval* retval = decode_request_worker(*arg1, *arg2, NULL);
+ if(retval) {
+ *return_value = *retval;
+ FREE_ZVAL(retval);
+ }
+ }
}
/* }}} */
@@ -801,58 +791,56 @@ PHP_FUNCTION(xmlrpc_decode)
Creates an xmlrpc server */
PHP_FUNCTION(xmlrpc_server_create)
{
- if(ARG_COUNT(ht) != 0) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
-
- if(return_value_used) {
- zval *method_map, *introspection_map;
- MAKE_STD_ZVAL(method_map);
- MAKE_STD_ZVAL(introspection_map);
-
- if(array_init(method_map) == SUCCESS && array_init(introspection_map) == SUCCESS) {
- /* allocate server data. free'd in destroy_server_data() */
- xmlrpc_server_data *server = emalloc(sizeof(xmlrpc_server_data));
-
- if(server) {
- server->method_map = method_map;
- server->introspection_map = introspection_map;
- server->server_ptr = XMLRPC_ServerCreate();
-
- XMLRPC_ServerRegisterIntrospectionCallback(server->server_ptr, php_xmlrpc_introspection_callback);
+ if(ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT;
+ }
- /* store for later use */
- ZEND_REGISTER_RESOURCE(return_value,server, le_xmlrpc_server);
- }
- }
- }
+ if(return_value_used) {
+ zval *method_map, *introspection_map;
+ xmlrpc_server_data *server = emalloc(sizeof(xmlrpc_server_data));
+ MAKE_STD_ZVAL(method_map);
+ MAKE_STD_ZVAL(introspection_map);
+
+ array_init(method_map);
+ array_init(introspection_map);
+
+ /* allocate server data. free'd in destroy_server_data() */
+ server->method_map = method_map;
+ server->introspection_map = introspection_map;
+ server->server_ptr = XMLRPC_ServerCreate();
+
+ XMLRPC_ServerRegisterIntrospectionCallback(server->server_ptr, php_xmlrpc_introspection_callback);
+
+ /* store for later use */
+ ZEND_REGISTER_RESOURCE(return_value,server, le_xmlrpc_server);
+ }
}
/* {{{ proto void xmlrpc_server_destroy(handle server)
Destroys server resources */
PHP_FUNCTION(xmlrpc_server_destroy)
{
- zval* arg1;
- int bSuccess = FAILURE;
+ zval **arg1;
+ int bSuccess = FAILURE;
- if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &arg1) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- if(Z_TYPE_P(arg1) == IS_RESOURCE) {
- int type;
+ if(Z_TYPE_PP(arg1) == IS_RESOURCE) {
+ int type;
- xmlrpc_server_data *server = zend_list_find(Z_LVAL_P(arg1), &type);
+ xmlrpc_server_data *server = zend_list_find(Z_LVAL_PP(arg1), &type);
- if(server && type == le_xmlrpc_server) {
- bSuccess = zend_list_delete(Z_LVAL_P(arg1));
+ if(server && type == le_xmlrpc_server) {
+ bSuccess = zend_list_delete(Z_LVAL_PP(arg1));
- /* called by hashtable destructor
- * destroy_server_data(server);
- */
- }
- }
- RETVAL_LONG(bSuccess == SUCCESS);
+ /* called by hashtable destructor
+ * destroy_server_data(server);
+ */
+ }
+ }
+ RETVAL_LONG(bSuccess == SUCCESS);
}
@@ -922,25 +910,25 @@ static void php_xmlrpc_introspection_callback(XMLRPC_SERVER server, void* data)
if(xData) {
if(!XMLRPC_ServerAddIntrospectionData(server, xData)) {
- zend_error(E_WARNING, "Unable to add introspection data returned from %s(), improper element structure", Z_STRVAL_PP(php_function));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to add introspection data returned from %s(), improper element structure", Z_STRVAL_PP(php_function));
}
XMLRPC_CleanupValue(xData);
}
else {
/* could not create description */
if(err.xml_elem_error.parser_code) {
- zend_error(E_WARNING, "xml parse error: [line %i, column %i, message: %s] Unable to add introspection data returned from %s()",
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "xml parse error: [line %i, column %i, message: %s] Unable to add introspection data returned from %s()",
err.xml_elem_error.column, err.xml_elem_error.line, err.xml_elem_error.parser_error, Z_STRVAL_PP(php_function));
}
else {
- zend_error(E_WARNING, "Unable to add introspection data returned from %s()",
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to add introspection data returned from %s()",
Z_STRVAL_PP(php_function));
}
}
}
else {
/* user func failed */
- zend_error(E_WARNING, "Error calling user introspection callback: %s()", Z_STRVAL_PP(php_function));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error calling user introspection callback: %s()", Z_STRVAL_PP(php_function));
}
}
else {
@@ -958,34 +946,33 @@ static void php_xmlrpc_introspection_callback(XMLRPC_SERVER server, void* data)
Register a PHP function to handle method matching method_name */
PHP_FUNCTION(xmlrpc_server_register_method)
{
- zval* method_key, *method_name, *handle, *method_name_save;
- int type;
- xmlrpc_server_data* server;
+ zval **method_key, **method_name, **handle, *method_name_save;
+ int type;
+ xmlrpc_server_data* server;
- /* get some params. should be 3 */
- if( !(ARG_COUNT(ht) == 3) || getParameters(ht, ARG_COUNT(ht), &handle, &method_key, &method_name) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 3 || (zend_get_parameters_ex(3, &handle, &method_key, &method_name) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- server = zend_list_find(Z_LVAL_P(handle), &type);
+ server = zend_list_find(Z_LVAL_PP(handle), &type);
- if(type == le_xmlrpc_server) {
- /* register with C engine. every method just calls our standard callback,
- * and it then dispatches to php as necessary
- */
- if(XMLRPC_ServerRegisterMethod(server->server_ptr, Z_STRVAL_P(method_key), php_xmlrpc_callback)) {
- /* save for later use */
- MAKE_STD_ZVAL(method_name_save);
- *method_name_save = *method_name;
- zval_copy_ctor(method_name_save);
+ if(type == le_xmlrpc_server) {
+ /* register with C engine. every method just calls our standard callback,
+ * and it then dispatches to php as necessary
+ */
+ if(XMLRPC_ServerRegisterMethod(server->server_ptr, Z_STRVAL_PP(method_key), php_xmlrpc_callback)) {
+ /* save for later use */
+ MAKE_STD_ZVAL(method_name_save);
+ *method_name_save = **method_name;
+ zval_copy_ctor(method_name_save);
- /* register our php method */
- add_zval(server->method_map, Z_STRVAL_P(method_key), &method_name_save);
+ /* register our php method */
+ add_zval(server->method_map, Z_STRVAL_PP(method_key), &method_name_save);
- RETURN_BOOL(1);
- }
- }
- RETURN_BOOL(0);
+ RETURN_BOOL(1);
+ }
+ }
+ RETURN_BOOL(0);
}
@@ -993,31 +980,28 @@ PHP_FUNCTION(xmlrpc_server_register_method)
Register a PHP function to generate documentation */
PHP_FUNCTION(xmlrpc_server_register_introspection_callback)
{
- zval* method_name, *handle, *method_name_save;
- int type;
- xmlrpc_server_data* server;
+ zval **method_name, **handle, *method_name_save;
+ int type;
+ xmlrpc_server_data* server;
- /* get some params. should be 2 */
- if( !(ARG_COUNT(ht) == 2) || getParameters(ht, ARG_COUNT(ht), &handle, &method_name) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 2 || (zend_get_parameters_ex(2, &handle, &method_name) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- server = zend_list_find(Z_LVAL_P(handle), &type);
+ server = zend_list_find(Z_LVAL_PP(handle), &type);
- if(type == le_xmlrpc_server) {
- {
- /* save for later use */
- MAKE_STD_ZVAL(method_name_save);
- *method_name_save = *method_name;
- zval_copy_ctor(method_name_save);
+ if(type == le_xmlrpc_server) {
+ /* save for later use */
+ MAKE_STD_ZVAL(method_name_save);
+ *method_name_save = **method_name;
+ zval_copy_ctor(method_name_save);
- /* register our php method */
- add_zval(server->introspection_map, NULL, &method_name_save);
+ /* register our php method */
+ add_zval(server->introspection_map, NULL, &method_name_save);
- RETURN_BOOL(1);
- }
- }
- RETURN_BOOL(0);
+ RETURN_BOOL(1);
+ }
+ RETURN_BOOL(0);
}
@@ -1027,97 +1011,79 @@ PHP_FUNCTION(xmlrpc_server_register_introspection_callback)
Parses XML requests and call methods */
PHP_FUNCTION(xmlrpc_server_call_method)
{
- xmlrpc_callback_data data = {0};
- XMLRPC_REQUEST xRequest;
- STRUCT_XMLRPC_REQUEST_INPUT_OPTIONS input_opts;
- xmlrpc_server_data* server;
- zval *rawxml, *caller_params, *handle, *output_opts;
- int type;
- php_output_options out;
-
- /* get params. 3 or 4 params ok */
- if(ARG_COUNT(ht) == 4) {
- if(getParameters(ht, ARG_COUNT(ht), &handle, &rawxml, &caller_params, &output_opts) != SUCCESS) {
- WRONG_PARAM_COUNT;
- }
-
- /* user output options */
- set_output_options(&out, output_opts);
- }
- else if(ARG_COUNT(ht) == 3) {
- if(getParameters(ht, ARG_COUNT(ht), &handle, &rawxml, &caller_params) != SUCCESS) {
- WRONG_PARAM_COUNT;
- }
- /* user output options */
- set_output_options(&out, NULL);
- }
- else {
- WRONG_PARAM_COUNT;
- }
+ xmlrpc_callback_data data = {0};
+ XMLRPC_REQUEST xRequest;
+ STRUCT_XMLRPC_REQUEST_INPUT_OPTIONS input_opts;
+ xmlrpc_server_data* server;
+ zval **rawxml, **caller_params, **handle, **output_opts = NULL;
+ int type;
+ php_output_options out;
+ int argc =ZEND_NUM_ARGS();
+
+ if (argc < 3 || argc > 4 || (zend_get_parameters_ex(argc, &handle, &rawxml, &caller_params, &output_opts) != SUCCESS)) {
+ WRONG_PARAM_COUNT;
+ }
+ /* user output options */
+ set_output_options(&out, *output_opts);
- server = zend_list_find(Z_LVAL_P(handle), &type);
+ server = zend_list_find(Z_LVAL_PP(handle), &type);
- if(type == le_xmlrpc_server) {
- /* HACK: use output encoding for now */
- input_opts.xml_elem_opts.encoding = utf8_get_encoding_id_from_string(out.xmlrpc_out.xml_elem_opts.encoding);
+ if(type == le_xmlrpc_server) {
+ /* HACK: use output encoding for now */
+ input_opts.xml_elem_opts.encoding = utf8_get_encoding_id_from_string(out.xmlrpc_out.xml_elem_opts.encoding);
- /* generate an XMLRPC_REQUEST from the raw xml input */
- xRequest = XMLRPC_REQUEST_FromXML(Z_STRVAL_P(rawxml), Z_STRLEN_P(rawxml), &input_opts);
+ /* generate an XMLRPC_REQUEST from the raw xml input */
+ xRequest = XMLRPC_REQUEST_FromXML(Z_STRVAL_PP(rawxml), Z_STRLEN_PP(rawxml), &input_opts);
- if(xRequest) {
- const char* methodname = XMLRPC_RequestGetMethodName(xRequest);
- zval** php_function;
- XMLRPC_VALUE xAnswer = NULL;
- MAKE_STD_ZVAL(data.xmlrpc_method); /* init. very important. spent a frustrating day finding this out. */
- MAKE_STD_ZVAL(data.return_data);
- Z_TYPE_P(data.return_data) = IS_NULL; /* in case value is never init'd, we don't dtor to think it is a string or something */
- Z_TYPE_P(data.xmlrpc_method) = IS_NULL;
+ if(xRequest) {
+ const char* methodname = XMLRPC_RequestGetMethodName(xRequest);
+ zval **php_function;
+ XMLRPC_VALUE xAnswer = NULL;
+ MAKE_STD_ZVAL(data.xmlrpc_method); /* init. very important. spent a frustrating day finding this out. */
+ MAKE_STD_ZVAL(data.return_data);
+ Z_TYPE_P(data.return_data) = IS_NULL; /* in case value is never init'd, we don't dtor to think it is a string or something */
+ Z_TYPE_P(data.xmlrpc_method) = IS_NULL;
- if (!methodname) {
- methodname = "";
- }
+ if (!methodname) {
+ methodname = "";
+ }
- /* setup some data to pass to the callback function */
- Z_STRVAL_P(data.xmlrpc_method) = estrdup(methodname);
- Z_STRLEN_P(data.xmlrpc_method) = strlen(methodname);
- Z_TYPE_P(data.xmlrpc_method) = IS_STRING;
- data.caller_params = caller_params;
- data.php_executed = 0;
- data.server = server;
-
- /* check if the called method has been previous registered */
- if(zend_hash_find(Z_ARRVAL_P(server->method_map),
+ /* setup some data to pass to the callback function */
+ Z_STRVAL_P(data.xmlrpc_method) = estrdup(methodname);
+ Z_STRLEN_P(data.xmlrpc_method) = strlen(methodname);
+ Z_TYPE_P(data.xmlrpc_method) = IS_STRING;
+ data.caller_params = *caller_params;
+ data.php_executed = 0;
+ data.server = server;
+
+ /* check if the called method has been previous registered */
+ if(zend_hash_find(Z_ARRVAL_P(server->method_map),
Z_STRVAL_P(data.xmlrpc_method),
Z_STRLEN_P(data.xmlrpc_method) + 1,
(void**)&php_function) == SUCCESS) {
- data.php_function = *php_function;
- }
+ data.php_function = *php_function;
+ }
- /* We could just call the php method directly ourselves at this point, but we do this
- * with a C callback in case the xmlrpc library ever implements some cool usage stats,
- * or somesuch.
- */
- xAnswer = XMLRPC_ServerCallMethod(server->server_ptr, xRequest, &data);
- if(xAnswer) {
- if(out.b_php_out) {
- zval_dtor(data.return_data);
- FREE_ZVAL(data.return_data);
- data.return_data = XMLRPC_to_PHP(xAnswer);
- }
- }
- else if(data.php_executed) {
- if(!out.b_php_out) {
- xAnswer = PHP_to_XMLRPC(data.return_data);
- }
- }
+ /* We could just call the php method directly ourselves at this point, but we do this
+ * with a C callback in case the xmlrpc library ever implements some cool usage stats,
+ * or somesuch.
+ */
+ xAnswer = XMLRPC_ServerCallMethod(server->server_ptr, xRequest, &data);
+ if(xAnswer && out.b_php_out) {
+ zval_dtor(data.return_data);
+ FREE_ZVAL(data.return_data);
+ data.return_data = XMLRPC_to_PHP(xAnswer);
+ } else if(data.php_executed && !out.b_php_out) {
+ xAnswer = PHP_to_XMLRPC(data.return_data);
+ }
- /* should we return data as xml? */
- if(!out.b_php_out) {
- XMLRPC_REQUEST xResponse = XMLRPC_RequestNew();
- if(xResponse) {
- char* outBuf = 0;
- int buf_len = 0;
+ /* should we return data as xml? */
+ if(!out.b_php_out) {
+ XMLRPC_REQUEST xResponse = XMLRPC_RequestNew();
+ if(xResponse) {
+ char *outBuf = 0;
+ int buf_len = 0;
/* automagically determine output serialization type from request type */
if (out.b_auto_version) {
@@ -1126,41 +1092,39 @@ PHP_FUNCTION(xmlrpc_server_call_method)
out.xmlrpc_out.version = opts->version;
}
}
- /* set some required request hoojum */
- XMLRPC_RequestSetOutputOptions(xResponse, &out.xmlrpc_out);
- XMLRPC_RequestSetRequestType(xResponse, xmlrpc_request_response);
- XMLRPC_RequestSetData(xResponse, xAnswer);
- XMLRPC_RequestSetMethodName(xResponse, methodname);
-
- /* generate xml */
- outBuf = XMLRPC_REQUEST_ToXML(xResponse, &buf_len);
- if(outBuf) {
- RETVAL_STRINGL(outBuf, buf_len, 1);
- free(outBuf);
- }
- /* cleanup after ourselves. what a sty! */
- XMLRPC_RequestFree(xResponse, 0);
- }
- }
- /* or as native php types? */
- else {
- *return_value = *data.return_data;
- zval_copy_ctor(return_value);
- }
+ /* set some required request hoojum */
+ XMLRPC_RequestSetOutputOptions(xResponse, &out.xmlrpc_out);
+ XMLRPC_RequestSetRequestType(xResponse, xmlrpc_request_response);
+ XMLRPC_RequestSetData(xResponse, xAnswer);
+ XMLRPC_RequestSetMethodName(xResponse, methodname);
+
+ /* generate xml */
+ outBuf = XMLRPC_REQUEST_ToXML(xResponse, &buf_len);
+ if(outBuf) {
+ RETVAL_STRINGL(outBuf, buf_len, 1);
+ free(outBuf);
+ }
+ /* cleanup after ourselves. what a sty! */
+ XMLRPC_RequestFree(xResponse, 0);
+ }
+ } else { /* or as native php types? */
+ *return_value = *data.return_data;
+ zval_copy_ctor(return_value);
+ }
- /* cleanup after ourselves. what a sty! */
- zval_dtor(data.xmlrpc_method);
- FREE_ZVAL(data.xmlrpc_method);
- zval_dtor(data.return_data);
- FREE_ZVAL(data.return_data);
+ /* cleanup after ourselves. what a sty! */
+ zval_dtor(data.xmlrpc_method);
+ FREE_ZVAL(data.xmlrpc_method);
+ zval_dtor(data.return_data);
+ FREE_ZVAL(data.return_data);
- if(xAnswer) {
- XMLRPC_CleanupValue(xAnswer);
- }
+ if(xAnswer) {
+ XMLRPC_CleanupValue(xAnswer);
+ }
- XMLRPC_RequestFree(xRequest, 1);
- }
- }
+ XMLRPC_RequestFree(xRequest, 1);
+ }
+ }
}
@@ -1168,26 +1132,25 @@ PHP_FUNCTION(xmlrpc_server_call_method)
Adds introspection documentation */
PHP_FUNCTION(xmlrpc_server_add_introspection_data)
{
- zval *handle, *desc;
- int type;
- xmlrpc_server_data* server;
+ zval **handle, **desc;
+ int type;
+ xmlrpc_server_data* server;
- /* get some params. should be 2 */
- if ( !(ARG_COUNT(ht) == 2) || getParameters(ht, ARG_COUNT(ht), &handle, &desc) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 2 || (zend_get_parameters_ex(2, &handle, &desc) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- server = zend_list_find(Z_LVAL_P(handle), &type);
+ server = zend_list_find(Z_LVAL_PP(handle), &type);
- if (type == le_xmlrpc_server) {
- XMLRPC_VALUE xDesc = PHP_to_XMLRPC(desc);
- if (xDesc) {
- int retval = XMLRPC_ServerAddIntrospectionData(server->server_ptr, xDesc);
- XMLRPC_CleanupValue(xDesc);
- RETURN_LONG(retval);
- }
- }
- RETURN_LONG(0);
+ if (type == le_xmlrpc_server) {
+ XMLRPC_VALUE xDesc = PHP_to_XMLRPC(*desc);
+ if (xDesc) {
+ int retval = XMLRPC_ServerAddIntrospectionData(server->server_ptr, xDesc);
+ XMLRPC_CleanupValue(xDesc);
+ RETURN_LONG(retval);
+ }
+ }
+ RETURN_LONG(0);
}
@@ -1195,40 +1158,38 @@ PHP_FUNCTION(xmlrpc_server_add_introspection_data)
Decodes XML into a list of method descriptions */
PHP_FUNCTION(xmlrpc_parse_method_descriptions)
{
- zval* arg1, *retval;
+ zval **arg1, *retval;
- if( !(ARG_COUNT(ht) == 1) || getParameters(ht, ARG_COUNT(ht), &arg1) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &arg1) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- convert_to_string(arg1);
+ convert_to_string_ex(arg1);
- if(return_value_used) {
- STRUCT_XMLRPC_ERROR err = {0};
- XMLRPC_VALUE xVal = XMLRPC_IntrospectionCreateDescription(Z_STRVAL_P(arg1), &err);
- if(xVal) {
- retval = XMLRPC_to_PHP(xVal);
+ if(return_value_used) {
+ STRUCT_XMLRPC_ERROR err = {0};
+ XMLRPC_VALUE xVal = XMLRPC_IntrospectionCreateDescription(Z_STRVAL_PP(arg1), &err);
+ if(xVal) {
+ retval = XMLRPC_to_PHP(xVal);
- if(retval) {
- *return_value = *retval;
- zval_copy_ctor(return_value);
- }
- /* dust, sweep, and mop */
- XMLRPC_CleanupValue(xVal);
- }
- else {
- /* could not create description */
- if(err.xml_elem_error.parser_code) {
- zend_error(E_WARNING, "xml parse error: [line %i, column %i, message: %s] Unable to create introspection data",
- err.xml_elem_error.column, err.xml_elem_error.line, err.xml_elem_error.parser_error);
- }
- else {
- zend_error(E_WARNING, "Invalid xml structure. Unable to create introspection data");
- }
+ if(retval) {
+ *return_value = *retval;
+ zval_copy_ctor(return_value);
+ }
+ /* dust, sweep, and mop */
+ XMLRPC_CleanupValue(xVal);
+ } else {
+ /* could not create description */
+ if(err.xml_elem_error.parser_code) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "xml parse error: [line %i, column %i, message: %s] Unable to create introspection data",
+ err.xml_elem_error.column, err.xml_elem_error.line, err.xml_elem_error.parser_error);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid xml structure. Unable to create introspection data");
+ }
- zend_error(E_WARNING, "xml parse error. no method description created");
- }
- }
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "xml parse error. no method description created");
+ }
+ }
}
@@ -1436,78 +1397,71 @@ XMLRPC_VALUE_TYPE get_zval_xmlrpc_type(zval* value, zval** newvalue)
Sets xmlrpc type, base64 or datetime, for a PHP string value */
PHP_FUNCTION(xmlrpc_set_type)
{
- zval* arg, *type;
- XMLRPC_VALUE_TYPE vtype;
+ zval **arg, **type;
+ XMLRPC_VALUE_TYPE vtype;
- if (!(ARG_COUNT(ht) == 2) || getParameters(ht, ARG_COUNT(ht), &arg, &type) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
-#if ZEND_MODULE_API_NO < 20010901
- if (!ParameterPassedByReference(ht,1)) {
- zend_error(E_WARNING,"first argument to xmlrpc_set_type() passed by value, expecting reference");
- }
-#endif
+ if (ZEND_NUM_ARGS() != 2 || (zend_get_parameters_ex(2, &arg, &type) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- convert_to_string(type);
- vtype = xmlrpc_str_as_type(Z_STRVAL_P(type));
- if (vtype != xmlrpc_none) {
- if (set_zval_xmlrpc_type(arg, vtype) == SUCCESS) {
- RETURN_TRUE;
- }
- } else {
- zend_error(E_WARNING,"invalid type '%s' passed to xmlrpc_set_type()", Z_STRVAL_P(type));
- }
- RETURN_FALSE;
+ convert_to_string_ex(type);
+ vtype = xmlrpc_str_as_type(Z_STRVAL_PP(type));
+ if (vtype != xmlrpc_none) {
+ if (set_zval_xmlrpc_type(*arg, vtype) == SUCCESS) {
+ RETURN_TRUE;
+ }
+ } else {
+ zend_error(E_WARNING,"invalid type '%s' passed to xmlrpc_set_type()", Z_STRVAL_PP(type));
+ }
+ RETURN_FALSE;
}
/* {{{ proto string xmlrpc_get_type(mixed value)
Gets xmlrpc type for a PHP value. Especially useful for base64 and datetime strings */
PHP_FUNCTION(xmlrpc_get_type)
{
- zval* arg;
- XMLRPC_VALUE_TYPE type;
- XMLRPC_VECTOR_TYPE vtype = xmlrpc_vector_none;
+ zval **arg;
+ XMLRPC_VALUE_TYPE type;
+ XMLRPC_VECTOR_TYPE vtype = xmlrpc_vector_none;
- if (!(ARG_COUNT(ht) == 1) || getParameters(ht, ARG_COUNT(ht), &arg) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &arg) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- type = get_zval_xmlrpc_type(arg, 0);
- if (type == xmlrpc_vector) {
- vtype = determine_vector_type(Z_ARRVAL_P(arg));
- }
+ type = get_zval_xmlrpc_type(*arg, 0);
+ if (type == xmlrpc_vector) {
+ vtype = determine_vector_type(Z_ARRVAL_PP(arg));
+ }
- RETURN_STRING((char*) xmlrpc_type_as_str(type, vtype), 1);
+ RETURN_STRING((char*) xmlrpc_type_as_str(type, vtype), 1);
}
/* {{{ proto string xmlrpc_is_fault(array)
Determines if an array value represents an XMLRPC fault. */
PHP_FUNCTION(xmlrpc_is_fault)
{
- zval* arg, **val;
+ zval **arg, **val;
- if (!(ARG_COUNT(ht) == 1) || getParameters(ht, ARG_COUNT(ht), &arg) == FAILURE) {
- WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
- }
+ if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &arg) == FAILURE)) {
+ WRONG_PARAM_COUNT;
+ }
- if (Z_TYPE_P(arg) != IS_ARRAY) {
- php_error(E_NOTICE, "%s(): Array argument expected", get_active_function_name(TSRMLS_C));
+ if (Z_TYPE_PP(arg) != IS_ARRAY) {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array argument expected");
+ } else {
+ /* The "correct" way to do this would be to call the xmlrpc
+ * library XMLRPC_ValueIsFault() func. However, doing that
+ * would require us to create an xmlrpc value from the php
+ * array, which is rather expensive, especially if it was
+ * a big array. Thus, we resort to this not so clever hackery.
+ */
+ if (zend_hash_find(Z_ARRVAL_PP(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS &&
+ zend_hash_find(Z_ARRVAL_PP(arg), FAULT_STRING, FAULT_STRING_LEN + 1, (void**) &val) == SUCCESS) {
+ RETURN_TRUE;
+ }
}
- else {
- /* The "correct" way to do this would be to call the xmlrpc
- * library XMLRPC_ValueIsFault() func. However, doing that
- * would require us to create an xmlrpc value from the php
- * array, which is rather expensive, especially if it was
- * a big array. Thus, we resort to this not so clever hackery.
- */
- if( zend_hash_find(Z_ARRVAL_P(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS &&
- zend_hash_find(Z_ARRVAL_P(arg), FAULT_STRING, FAULT_STRING_LEN + 1, (void**) &val) == SUCCESS)
- {
- RETURN_TRUE;
- }
- }
- RETURN_FALSE;
+ RETURN_FALSE;
}