Porting of patch applied to ext/xmlrpc.

This commit is contained in:
Ilia Alshanetsky 2003-01-14 21:04:47 +00:00
parent a0b3f822f7
commit e37aee1a34

View file

@ -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,12 +606,13 @@ static zval* XMLRPC_to_PHP(XMLRPC_VALUE el)
}
break;
case xmlrpc_vector:
if(array_init(elem) == SUCCESS) {
array_init(elem);
{
XMLRPC_VALUE xIter = XMLRPC_VectorRewind(el);
while( xIter ) {
zval* val = XMLRPC_to_PHP(xIter);
if(val) {
zval *val = XMLRPC_to_PHP(xIter);
if (val) {
add_zval(elem, XMLRPC_GetValueID(xIter), &val);
}
xIter = XMLRPC_VectorNext(el);
@ -635,32 +632,29 @@ static zval* XMLRPC_to_PHP(XMLRPC_VALUE el)
PHP_FUNCTION(xmlrpc_encode_request)
{
XMLRPC_REQUEST xRequest = NULL;
zval* method, *vals, *out_opts;
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) {
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, (ARG_COUNT(ht) == 3) ? out_opts : 0);
set_output_options(&out, (ZEND_NUM_ARGS() == 3) ? *out_opts : 0);
if(return_value_used) {
xRequest = XMLRPC_RequestNew();
if(xRequest) {
XMLRPC_RequestSetOutputOptions(xRequest, &out.xmlrpc_out);
if(Z_TYPE_P(method) == IS_NULL) {
if (Z_TYPE_PP(method) == IS_NULL) {
XMLRPC_RequestSetRequestType(xRequest, xmlrpc_request_response);
}
else {
XMLRPC_RequestSetMethodName(xRequest, Z_STRVAL_P(method));
} else {
XMLRPC_RequestSetMethodName(xRequest, Z_STRVAL_PP(method));
XMLRPC_RequestSetRequestType(xRequest, xmlrpc_request_call);
}
if(Z_TYPE_P(vals) != IS_NULL) {
XMLRPC_RequestSetData(xRequest, PHP_to_XMLRPC(vals));
if (Z_TYPE_PP(vals) != IS_NULL) {
XMLRPC_RequestSetData(xRequest, PHP_to_XMLRPC(*vals));
}
outBuf = XMLRPC_REQUEST_ToXML(xRequest, 0);
@ -679,17 +673,16 @@ PHP_FUNCTION(xmlrpc_encode_request)
PHP_FUNCTION(xmlrpc_encode)
{
XMLRPC_VALUE xOut = NULL;
zval* arg1;
char* outBuf;
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);
xOut = PHP_to_XMLRPC(*arg1);
/* generate raw xml from xmlrpc data */
outBuf = XMLRPC_VALUE_ToXML(xOut, 0);
@ -739,25 +732,21 @@ 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 (argc < 2 || argc > 3 || (zend_get_parameters_ex(argc, &xml, &method, &encoding) == FAILURE)) {
WRONG_PARAM_COUNT;
}
#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
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);
zval* retval = decode_request_worker(*xml, *encoding, *method);
if(retval) {
*return_value = *retval;
FREE_ZVAL(retval);
@ -771,19 +760,20 @@ 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);
zval* retval = decode_request_worker(*arg1, *arg2, NULL);
if(retval) {
*return_value = *retval;
FREE_ZVAL(retval);
@ -801,20 +791,20 @@ 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(ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
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);
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));
array_init(method_map);
array_init(introspection_map);
if(server) {
/* allocate server data. free'd in destroy_server_data() */
server->method_map = method_map;
server->introspection_map = introspection_map;
server->server_ptr = XMLRPC_ServerCreate();
@ -824,28 +814,26 @@ PHP_FUNCTION(xmlrpc_server_create)
/* 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;
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) {
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));
bSuccess = zend_list_delete(Z_LVAL_PP(arg1));
/* called by hashtable destructor
* destroy_server_data(server);
@ -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,29 +946,28 @@ 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;
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)) {
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;
*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);
add_zval(server->method_map, Z_STRVAL_PP(method_key), &method_name_save);
RETURN_BOOL(1);
}
@ -993,22 +980,20 @@ 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;
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;
*method_name_save = **method_name;
zval_copy_ctor(method_name_save);
/* register our php method */
@ -1016,7 +1001,6 @@ PHP_FUNCTION(xmlrpc_server_register_introspection_callback)
RETURN_BOOL(1);
}
}
RETURN_BOOL(0);
}
@ -1031,42 +1015,29 @@ PHP_FUNCTION(xmlrpc_server_call_method)
XMLRPC_REQUEST xRequest;
STRUCT_XMLRPC_REQUEST_INPUT_OPTIONS input_opts;
xmlrpc_server_data* server;
zval *rawxml, *caller_params, *handle, *output_opts;
zval **rawxml, **caller_params, **handle, **output_opts = NULL;
int type;
php_output_options out;
int argc =ZEND_NUM_ARGS();
/* 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) {
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, NULL);
}
else {
WRONG_PARAM_COUNT;
}
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);
/* generate an XMLRPC_REQUEST from the raw xml input */
xRequest = XMLRPC_REQUEST_FromXML(Z_STRVAL_P(rawxml), Z_STRLEN_P(rawxml), &input_opts);
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;
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);
@ -1081,7 +1052,7 @@ PHP_FUNCTION(xmlrpc_server_call_method)
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.caller_params = *caller_params;
data.php_executed = 0;
data.server = server;
@ -1099,24 +1070,19 @@ PHP_FUNCTION(xmlrpc_server_call_method)
* or somesuch.
*/
xAnswer = XMLRPC_ServerCallMethod(server->server_ptr, xRequest, &data);
if(xAnswer) {
if(out.b_php_out) {
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) {
if(!out.b_php_out) {
} 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;
char *outBuf = 0;
int buf_len = 0;
/* automagically determine output serialization type from request type */
@ -1141,9 +1107,7 @@ PHP_FUNCTION(xmlrpc_server_call_method)
/* cleanup after ourselves. what a sty! */
XMLRPC_RequestFree(xResponse, 0);
}
}
/* or as native php types? */
else {
} else { /* or as native php types? */
*return_value = *data.return_data;
zval_copy_ctor(return_value);
}
@ -1168,19 +1132,18 @@ PHP_FUNCTION(xmlrpc_server_call_method)
Adds introspection documentation */
PHP_FUNCTION(xmlrpc_server_add_introspection_data)
{
zval *handle, *desc;
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);
XMLRPC_VALUE xDesc = PHP_to_XMLRPC(*desc);
if (xDesc) {
int retval = XMLRPC_ServerAddIntrospectionData(server->server_ptr, xDesc);
XMLRPC_CleanupValue(xDesc);
@ -1195,17 +1158,17 @@ 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);
XMLRPC_VALUE xVal = XMLRPC_IntrospectionCreateDescription(Z_STRVAL_PP(arg1), &err);
if(xVal) {
retval = XMLRPC_to_PHP(xVal);
@ -1215,18 +1178,16 @@ PHP_FUNCTION(xmlrpc_parse_method_descriptions)
}
/* dust, sweep, and mop */
XMLRPC_CleanupValue(xVal);
}
else {
} 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",
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 {
zend_error(E_WARNING, "Invalid xml structure. Unable to create introspection data");
} 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,26 +1397,21 @@ 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;
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_NUM_ARGS() != 2 || (zend_get_parameters_ex(2, &arg, &type) == FAILURE)) {
WRONG_PARAM_COUNT;
}
#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
convert_to_string(type);
vtype = xmlrpc_str_as_type(Z_STRVAL_P(type));
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) {
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));
zend_error(E_WARNING,"invalid type '%s' passed to xmlrpc_set_type()", Z_STRVAL_PP(type));
}
RETURN_FALSE;
}
@ -1464,17 +1420,17 @@ PHP_FUNCTION(xmlrpc_set_type)
Gets xmlrpc type for a PHP value. Especially useful for base64 and datetime strings */
PHP_FUNCTION(xmlrpc_get_type)
{
zval* arg;
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);
type = get_zval_xmlrpc_type(*arg, 0);
if (type == xmlrpc_vector) {
vtype = determine_vector_type(Z_ARRVAL_P(arg));
vtype = determine_vector_type(Z_ARRVAL_PP(arg));
}
RETURN_STRING((char*) xmlrpc_type_as_str(type, vtype), 1);
@ -1484,25 +1440,23 @@ PHP_FUNCTION(xmlrpc_get_type)
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));
}
else {
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_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)
{
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;
}
}