merged in updates from SF project. bring php repository up to date with xmlrpc-epi version 0.51

This commit is contained in:
Dan Libby 2002-07-05 04:43:55 +00:00
parent eebae9f9ef
commit 2154e7b55b
26 changed files with 634 additions and 80 deletions

View file

@ -367,6 +367,7 @@ int Q_PushTail(queue *q, void *d)
return True_; return True_;
} }
return False_;
} }

View file

@ -44,6 +44,13 @@ static const char rcsid[] = "#(@) $Id$";
* CREATION DATE * CREATION DATE
* 06/2000 * 06/2000
* HISTORY * HISTORY
* $Log$
* Revision 1.4 2002/02/13 20:58:50 danda
* patch to make source more windows friendly, contributed by Jeff Lawson
*
* Revision 1.3 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 10/15/2000 -- danda -- adding robodoc documentation * 10/15/2000 -- danda -- adding robodoc documentation
* PORTABILITY * PORTABILITY
* Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just * Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just

View file

@ -62,6 +62,7 @@ typedef struct _simplestring {
void simplestring_init(simplestring* string); void simplestring_init(simplestring* string);
void simplestring_clear(simplestring* string); void simplestring_clear(simplestring* string);
void simplestring_free(simplestring* string); void simplestring_free(simplestring* string);
void simplestring_add(simplestring* string, const char* add);
void simplestring_addn(simplestring* string, const char* add, int add_len); void simplestring_addn(simplestring* string, const char* add, int add_len);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -35,6 +35,10 @@
* AUTHOR * AUTHOR
* Dan Libby, aka danda (dan@libby.com) * Dan Libby, aka danda (dan@libby.com)
* HISTORY * HISTORY
* $Log$
* Revision 1.7 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 4/28/2001 -- danda -- adding system.multicall and separating out system methods. * 4/28/2001 -- danda -- adding system.multicall and separating out system methods.
* TODO * TODO
* NOTES * NOTES

View file

@ -43,6 +43,22 @@ static const char rcsid[] = "#(@) $Id$";
* CREATION DATE * CREATION DATE
* 06/2000 * 06/2000
* HISTORY * HISTORY
* $Log$
* Revision 1.9 2002/07/03 20:54:30 danda
* root element should not have a parent. patch from anon SF user
*
* Revision 1.8 2002/05/23 17:46:51 danda
* patch from mukund - fix non utf-8 encoding conversions
*
* Revision 1.7 2002/02/13 20:58:50 danda
* patch to make source more windows friendly, contributed by Jeff Lawson
*
* Revision 1.6 2002/01/08 01:06:55 danda
* enable <?xml version="1.0"?> format for parsers that are very picky.
*
* Revision 1.5 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 10/15/2000 -- danda -- adding robodoc documentation * 10/15/2000 -- danda -- adding robodoc documentation
* TODO * TODO
* Nicer external API. Get rid of macros. Make opaque types, etc. * Nicer external API. Get rid of macros. Make opaque types, etc.
@ -86,7 +102,7 @@ static const char rcsid[] = "#(@) $Id$";
#define XML_DECL_START "<?xml" #define XML_DECL_START "<?xml"
#define XML_DECL_START_LEN sizeof(XML_DECL_START) - 1 #define XML_DECL_START_LEN sizeof(XML_DECL_START) - 1
#define XML_DECL_VERSION "version='1.0'" #define XML_DECL_VERSION "version=\"1.0\""
#define XML_DECL_VERSION_LEN sizeof(XML_DECL_VERSION) - 1 #define XML_DECL_VERSION_LEN sizeof(XML_DECL_VERSION) - 1
#define XML_DECL_ENCODING_ATTR "encoding" #define XML_DECL_ENCODING_ATTR "encoding"
#define XML_DECL_ENCODING_ATTR_LEN sizeof(XML_DECL_ENCODING_ATTR) - 1 #define XML_DECL_ENCODING_ATTR_LEN sizeof(XML_DECL_ENCODING_ATTR) - 1
@ -353,7 +369,6 @@ static void xml_element_serialize(xml_element *el, int (*fptr)(void *data, const
xml_elem_writefunc(fptr, options->encoding, data, 0); xml_elem_writefunc(fptr, options->encoding, data, 0);
xml_elem_writefunc(fptr, ATTR_DELIMITER, data, ATTR_DELIMITER_LEN); xml_elem_writefunc(fptr, ATTR_DELIMITER, data, ATTR_DELIMITER_LEN);
} }
xml_elem_writefunc(fptr, WHITESPACE, data, WHITESPACE_LEN);
xml_elem_writefunc(fptr, XML_DECL_END, data, XML_DECL_END_LEN); xml_elem_writefunc(fptr, XML_DECL_END, data, XML_DECL_END_LEN);
if(options->verbosity != xml_elem_no_white_space) { if(options->verbosity != xml_elem_no_white_space) {
xml_elem_writefunc(fptr, NEWLINE, data, NEWLINE_LEN); xml_elem_writefunc(fptr, NEWLINE, data, NEWLINE_LEN);
@ -591,8 +606,10 @@ static void charHandler(void *userData,
/* Check if we need to decode utf-8 parser output to another encoding */ /* Check if we need to decode utf-8 parser output to another encoding */
if(mydata->needs_enc_conversion && mydata->input_options->encoding) { if(mydata->needs_enc_conversion && mydata->input_options->encoding) {
char* add_text = utf8_decode(s, len, &len, mydata->input_options->encoding); int new_len = 0;
char* add_text = utf8_decode(s, len, &new_len, mydata->input_options->encoding);
if(add_text) { if(add_text) {
len = new_len;
simplestring_addn(&mydata->current->text, add_text, len); simplestring_addn(&mydata->current->text, add_text, len);
free(add_text); free(add_text);
return; return;
@ -700,6 +717,7 @@ xml_element* xml_elem_parse_buf(const char* in_buf, int len, XML_ELEM_INPUT_OPTI
} }
else { else {
xReturn = (xml_element*)Q_Head(&mydata.root->children); xReturn = (xml_element*)Q_Head(&mydata.root->children);
xReturn->parent = NULL;
} }
XML_ParserFree(parser); XML_ParserFree(parser);

View file

@ -5,7 +5,7 @@
*/ */
/************************************************************************ /*-**********************************************************************
* TODO: * * TODO: *
* - [SOAP-ENC:position] read sparse arrays (and write?) * * - [SOAP-ENC:position] read sparse arrays (and write?) *
* - [SOAP-ENC:offset] read partially transmitted arrays (and write?) * * - [SOAP-ENC:offset] read partially transmitted arrays (and write?) *

View file

@ -71,11 +71,30 @@ XMLRPC_VALUE xml_element_to_XMLRPC_REQUEST_worker(XMLRPC_REQUEST request, XMLRPC
current_val = XMLRPC_CreateValueEmpty(); current_val = XMLRPC_CreateValueEmpty();
} }
if (el->name) { if (el->name) {
if (!strcmp(el->name, ELEM_DATA) /* should be ELEM_ARRAY, but there is an extra level. weird */
|| ((!strcmp(el->name, ELEM_PARAMS)) && /* first, deal with the crazy/stupid fault format */
(XMLRPC_RequestGetRequestType(request) == xmlrpc_request_call)) /* this "PARAMS" concept is silly. dave?! */ if (!strcmp(el->name, ELEM_FAULT)) {
|| !strcmp(el->name, ELEM_FAULT)) { /* so is this "FAULT" nonsense. */ xml_element* fault_value = (xml_element*)Q_Head(&el->children);
XMLRPC_SetIsVector(current_val, xmlrpc_vector_struct);
if(fault_value) {
xml_element* fault_struct = (xml_element*)Q_Head(&fault_value->children);
if(fault_struct) {
xml_element* iter = (xml_element*)Q_Head(&fault_struct->children);
while (iter) {
XMLRPC_VALUE xNextVal = XMLRPC_CreateValueEmpty();
xml_element_to_XMLRPC_REQUEST_worker(request, current_val, xNextVal, iter);
XMLRPC_AddValueToVector(current_val, xNextVal);
iter = (xml_element*)Q_Next(&fault_struct->children);
}
}
}
}
else if (!strcmp(el->name, ELEM_DATA) /* should be ELEM_ARRAY, but there is an extra level. weird */
|| (!strcmp(el->name, ELEM_PARAMS) &&
(XMLRPC_RequestGetRequestType(request) == xmlrpc_request_call)) ) { /* this "PARAMS" concept is silly. dave?! */
xml_element* iter = (xml_element*)Q_Head(&el->children); xml_element* iter = (xml_element*)Q_Head(&el->children);
XMLRPC_SetIsVector(current_val, xmlrpc_vector_array); XMLRPC_SetIsVector(current_val, xmlrpc_vector_array);

View file

@ -42,16 +42,31 @@ static const char rcsid[] = "#(@) $Id$";
* CREATION DATE * CREATION DATE
* 9/1999 - 10/2000 * 9/1999 - 10/2000
* HISTORY * HISTORY
* $Log$
* Revision 1.22 2002/03/09 23:15:44 danda
* add fault interrogation funcs
*
* Revision 1.21 2002/03/09 22:27:41 danda
* win32 build patches contributed by Jeff Lawson
*
* Revision 1.20 2002/02/13 20:58:50 danda
* patch to make source more windows friendly, contributed by Jeff Lawson
*
* Revision 1.19 2001/10/12 23:25:54 danda
* default to writing xmlrpc
*
* Revision 1.18 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 10/15/2000 -- danda -- adding robodoc documentation
* 08/2000 -- danda -- PHP C extension that uses XMLRPC
* 08/2000 -- danda -- support for two vocabularies: danda-rpc and xml-rpc
* 09/1999 -- danda -- Initial API, before I even knew of standard XMLRPC vocab. Response only. * 09/1999 -- danda -- Initial API, before I even knew of standard XMLRPC vocab. Response only.
* 06/2000 -- danda -- played with expat-ensor from www.ensor.org. Cool, but some flaws.
* 07/2000 -- danda -- wrote new implementation to be compatible with xmlrpc standard and * 07/2000 -- danda -- wrote new implementation to be compatible with xmlrpc standard and
* incorporated some ideas from ensor, most notably the separation of * incorporated some ideas from ensor, most notably the separation of
* xml dom from xmlrpc api. * xml dom from xmlrpc api.
* 08/2000 -- danda -- support for two vocabularies: danda-rpc and xml-rpc * 06/2000 -- danda -- played with expat-ensor from www.ensor.org. Cool, but some flaws.
* 08/2000 -- danda -- PHP C extension that uses XMLRPC
* 10/15/2000 -- danda -- adding robodoc documentation
* TODO * TODO
* Server method introspection. (Enumerate available methods, describe I/O)
* PORTABILITY * PORTABILITY
* Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just * Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just
* about anything with minor mods. * about anything with minor mods.
@ -116,6 +131,7 @@ static const char rcsid[] = "#(@) $Id$";
#include "xml_element.h" #include "xml_element.h"
#include "xmlrpc_private.h" #include "xmlrpc_private.h"
#include "xmlrpc_introspection_private.h" #include "xmlrpc_introspection_private.h"
#include "system_methods_private.h"
@ -127,7 +143,6 @@ static int date_from_ISO8601 (const char *text, time_t * value) {
struct tm tm; struct tm tm;
int n; int n;
int i; int i;
time_t t;
char buf[18]; char buf[18];
if (strchr (text, '-')) { if (strchr (text, '-')) {
@ -625,7 +640,8 @@ char* XMLRPC_REQUEST_ToXML(XMLRPC_REQUEST request, int* buf_len) {
if (request->output.version == xmlrpc_version_simple) { if (request->output.version == xmlrpc_version_simple) {
root_elem = DANDARPC_REQUEST_to_xml_element (request); root_elem = DANDARPC_REQUEST_to_xml_element (request);
} }
else if (request->output.version == xmlrpc_version_1_0) { else if (request->output.version == xmlrpc_version_1_0 ||
request->output.version == xmlrpc_version_none) {
root_elem = XMLRPC_REQUEST_to_xml_element (request); root_elem = XMLRPC_REQUEST_to_xml_element (request);
} }
else if (request->output.version == xmlrpc_version_soap_1_1) { else if (request->output.version == xmlrpc_version_soap_1_1) {
@ -2382,7 +2398,7 @@ int XMLRPC_ServerRegisterMethod(XMLRPC_SERVER server, const char *name, XMLRPC_C
/*******/ /*******/
inline server_method* find_method(XMLRPC_SERVER server, const char* name) { server_method* find_method(XMLRPC_SERVER server, const char* name) {
server_method* sm; server_method* sm;
q_iter qi = Q_Iter_Head_F(&server->methodlist); q_iter qi = Q_Iter_Head_F(&server->methodlist);
@ -2649,7 +2665,7 @@ XMLRPC_CASE_COMPARISON XMLRPC_SetDefaultIdCaseComparison(XMLRPC_CASE_COMPARISON
/*-****************** /*-******************
* Utility API funcs * * Fault API funcs *
********************/ ********************/
/****f* UTILITY/XMLRPC_UtilityCreateFault /****f* UTILITY/XMLRPC_UtilityCreateFault
@ -2683,6 +2699,7 @@ XMLRPC_CASE_COMPARISON XMLRPC_SetDefaultIdCaseComparison(XMLRPC_CASE_COMPARISON
* simplerpc serialization, meaning that there will be no "<fault>" element in that * simplerpc serialization, meaning that there will be no "<fault>" element in that
* serialization. There will simply be a standard struct with 2 child elements. * serialization. There will simply be a standard struct with 2 child elements.
* imho, the "<fault>" element is unnecessary and/or out of place as part of the standard API. * imho, the "<fault>" element is unnecessary and/or out of place as part of the standard API.
*
* SOURCE * SOURCE
*/ */
XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string) { XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string) {
@ -2749,6 +2766,147 @@ XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string)
/*******/ /*******/
/****f* FAULT/XMLRPC_ValueIsFault
* NAME
* XMLRPC_ValueIsFault
* SYNOPSIS
* int XMLRPC_ValueIsFault (XMLRPC_VALUE value)
* FUNCTION
* Determines if a value encapsulates a fault "object"
* INPUTS
* value any XMLRPC_VALUE
* RESULT
* 1 if it is a fault, else 0
* SEE ALSO
* XMLRPC_ResponseIsFault ()
* SOURCE
*/
int XMLRPC_ValueIsFault (XMLRPC_VALUE value) {
if( XMLRPC_VectorGetValueWithID(value, "faultCode") &&
XMLRPC_VectorGetValueWithID(value, "faultString") ) {
return 1;
}
return 0;
}
/*******/
/****f* FAULT/XMLRPC_ResponseIsFault
* NAME
* XMLRPC_ResponseIsFault
* SYNOPSIS
* int XMLRPC_ResponseIsFault (XMLRPC_REQUEST response)
* FUNCTION
* Determines if a response contains an encapsulated fault "object"
* INPUTS
* value any XMLRPC_REQUEST. typically of type xmlrpc_request_response
* RESULT
* 1 if it contains a fault, else 0
* SEE ALSO
* XMLRPC_ValueIsFault ()
* SOURCE
*/
int XMLRPC_ResponseIsFault(XMLRPC_REQUEST response) {
return XMLRPC_ValueIsFault( XMLRPC_RequestGetData(response) );
}
/*******/
/****f* FAULT/XMLRPC_GetValueFaultCode
* NAME
* XMLRPC_GetValueFaultCode
* SYNOPSIS
* int XMLRPC_GetValueFaultCode (XMLRPC_VALUE value)
* FUNCTION
* returns fault code from a struct, if any
* INPUTS
* value XMLRPC_VALUE of type xmlrpc_vector_struct.
* RESULT
* fault code, else 0.
* BUGS
* impossible to distinguish faultCode == 0 from faultCode not present.
* SEE ALSO
* XMLRPC_GetResponseFaultCode ()
* SOURCE
*/
int XMLRPC_GetValueFaultCode (XMLRPC_VALUE value) {
return XMLRPC_VectorGetIntWithID(value, "faultCode");
}
/*******/
/****f* FAULT/XMLRPC_GetResponseFaultCode
* NAME
* XMLRPC_GetResponseFaultCode
* SYNOPSIS
* int XMLRPC_GetResponseFaultCode(XMLRPC_REQUEST response)
* FUNCTION
* returns fault code from a response, if any
* INPUTS
* response XMLRPC_REQUEST. typically of type xmlrpc_request_response.
* RESULT
* fault code, else 0.
* BUGS
* impossible to distinguish faultCode == 0 from faultCode not present.
* SEE ALSO
* XMLRPC_GetValueFaultCode ()
* SOURCE
*/
int XMLRPC_GetResponseFaultCode(XMLRPC_REQUEST response) {
return XMLRPC_GetValueFaultCode( XMLRPC_RequestGetData(response) );
}
/*******/
/****f* FAULT/XMLRPC_GetValueFaultString
* NAME
* XMLRPC_GetValueFaultString
* SYNOPSIS
* const char* XMLRPC_GetValueFaultString (XMLRPC_VALUE value)
* FUNCTION
* returns fault string from a struct, if any
* INPUTS
* value XMLRPC_VALUE of type xmlrpc_vector_struct.
* RESULT
* fault string, else 0.
* SEE ALSO
* XMLRPC_GetResponseFaultString ()
* SOURCE
*/
const char* XMLRPC_GetValueFaultString (XMLRPC_VALUE value) {
return XMLRPC_VectorGetStringWithID(value, "faultString");
}
/*******/
/****f* FAULT/XMLRPC_GetResponseFaultString
* NAME
* XMLRPC_GetResponseFaultString
* SYNOPSIS
* const char* XMLRPC_GetResponseFaultString (XMLRPC_REQUEST response)
* FUNCTION
* returns fault string from a response, if any
* INPUTS
* response XMLRPC_REQUEST. typically of type xmlrpc_request_response.
* RESULT
* fault string, else 0.
* SEE ALSO
* XMLRPC_GetValueFaultString ()
* SOURCE
*/
const char* XMLRPC_GetResponseFaultString (XMLRPC_REQUEST response) {
return XMLRPC_GetValueFaultString( XMLRPC_RequestGetData(response) );
}
/*******/
/*-******************
* Utility API funcs *
********************/
/****f* UTILITY/XMLRPC_Free /****f* UTILITY/XMLRPC_Free
* NAME * NAME
* XMLRPC_Free * XMLRPC_Free

View file

@ -43,11 +43,11 @@ extern "C" {
/* allow version to be specified via compile line define */ /* allow version to be specified via compile line define */
#ifndef XMLRPC_LIB_VERSION #ifndef XMLRPC_LIB_VERSION
#define XMLRPC_LIB_VERSION "0.50" #define XMLRPC_LIB_VERSION "0.51"
#endif #endif
/* this number, representing the date, must be increased each time the API changes */ /* this number, representing the date, must be increased each time the API changes */
#define XMLRPC_API_NO 20010721 #define XMLRPC_API_NO 20020623
/* this string should be changed with each packaged release */ /* this string should be changed with each packaged release */
#define XMLRPC_VERSION_STR "xmlrpc-epi v. " XMLRPC_LIB_VERSION #define XMLRPC_VERSION_STR "xmlrpc-epi v. " XMLRPC_LIB_VERSION
@ -191,8 +191,8 @@ typedef enum _xmlrpc_error_code {
* SOURCE * SOURCE
*/ */
typedef enum _xmlrpc_version { typedef enum _xmlrpc_version {
xmlrpc_version_none, /* not a recognized vocabulary */ xmlrpc_version_none = 0, /* not a recognized vocabulary */
xmlrpc_version_1_0, /* xmlrpc 1.0 standard vocab */ xmlrpc_version_1_0 = 1, /* xmlrpc 1.0 standard vocab */
xmlrpc_version_simple = 2, /* alt more readable vocab */ xmlrpc_version_simple = 2, /* alt more readable vocab */
xmlrpc_version_danda = 2, /* same as simple. legacy */ xmlrpc_version_danda = 2, /* same as simple. legacy */
xmlrpc_version_soap_1_1 = 3 /* SOAP. version 1.1 */ xmlrpc_version_soap_1_1 = 3 /* SOAP. version 1.1 */
@ -334,6 +334,10 @@ XMLRPC_VALUE XMLRPC_CreateVector(const char* id, XMLRPC_VECTOR_TYPE type);
/* Cleanup values */ /* Cleanup values */
void XMLRPC_CleanupValue(XMLRPC_VALUE value); void XMLRPC_CleanupValue(XMLRPC_VALUE value);
/* Request error */
XMLRPC_VALUE XMLRPC_RequestSetError (XMLRPC_REQUEST request, XMLRPC_VALUE error);
XMLRPC_VALUE XMLRPC_RequestGetError (XMLRPC_REQUEST request);
/* Copy values */ /* Copy values */
XMLRPC_VALUE XMLRPC_CopyValue(XMLRPC_VALUE value); XMLRPC_VALUE XMLRPC_CopyValue(XMLRPC_VALUE value);
XMLRPC_VALUE XMLRPC_DupValueNew(XMLRPC_VALUE xSource); XMLRPC_VALUE XMLRPC_DupValueNew(XMLRPC_VALUE xSource);
@ -393,6 +397,15 @@ XMLRPC_VALUE XMLRPC_ServerCallMethod(XMLRPC_SERVER server, XMLRPC_REQUEST reques
#include "xmlrpc_introspection.h" #include "xmlrpc_introspection.h"
/* Fault interrogation funcs */
int XMLRPC_ValueIsFault (XMLRPC_VALUE value);
int XMLRPC_ResponseIsFault(XMLRPC_REQUEST response);
int XMLRPC_GetValueFaultCode (XMLRPC_VALUE value);
int XMLRPC_GetResponseFaultCode(XMLRPC_REQUEST response);
const char* XMLRPC_GetValueFaultString (XMLRPC_VALUE value);
const char* XMLRPC_GetResponseFaultString (XMLRPC_REQUEST response);
/* Public Utility funcs */ /* Public Utility funcs */
XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string); XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string);
void XMLRPC_Free(void* mem); void XMLRPC_Free(void* mem);

View file

@ -35,6 +35,10 @@
* AUTHOR * AUTHOR
* Dan Libby, aka danda (dan@libby.com) * Dan Libby, aka danda (dan@libby.com)
* HISTORY * HISTORY
* $Log$
* Revision 1.9 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 4/10/2001 -- danda -- initial introspection support * 4/10/2001 -- danda -- initial introspection support
* TODO * TODO
* NOTES * NOTES

View file

@ -160,7 +160,7 @@ typedef struct _server_method {
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
* Functions * Functions
*/ */
extern server_method* find_method(XMLRPC_SERVER server, const char* name); server_method* find_method(XMLRPC_SERVER server, const char* name);
const char* type_to_str(XMLRPC_VALUE_TYPE type, XMLRPC_VECTOR_TYPE vtype); const char* type_to_str(XMLRPC_VALUE_TYPE type, XMLRPC_VECTOR_TYPE vtype);
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------

View file

@ -80,6 +80,7 @@ PHP_FUNCTION(xmlrpc_decode_request);
PHP_FUNCTION(xmlrpc_encode_request); PHP_FUNCTION(xmlrpc_encode_request);
PHP_FUNCTION(xmlrpc_get_type); PHP_FUNCTION(xmlrpc_get_type);
PHP_FUNCTION(xmlrpc_set_type); PHP_FUNCTION(xmlrpc_set_type);
PHP_FUNCTION(xmlrpc_is_fault);
PHP_FUNCTION(xmlrpc_server_create); PHP_FUNCTION(xmlrpc_server_create);
PHP_FUNCTION(xmlrpc_server_destroy); PHP_FUNCTION(xmlrpc_server_destroy);
PHP_FUNCTION(xmlrpc_server_register_method); PHP_FUNCTION(xmlrpc_server_register_method);

View file

@ -68,7 +68,7 @@
#endif #endif
#include "xmlrpc.h" #include "xmlrpc.h"
#define PHP_EXT_VERSION "0.50" #define PHP_EXT_VERSION "0.51"
/* You should tweak config.m4 so this symbol (or some else suitable) /* You should tweak config.m4 so this symbol (or some else suitable)
gets defined. */ gets defined. */
@ -87,6 +87,7 @@ function_entry xmlrpc_functions[] = {
PHP_FE(xmlrpc_encode_request, NULL) PHP_FE(xmlrpc_encode_request, NULL)
PHP_FE(xmlrpc_get_type, NULL) PHP_FE(xmlrpc_get_type, NULL)
PHP_FE(xmlrpc_set_type, first_args_force_ref) PHP_FE(xmlrpc_set_type, first_args_force_ref)
PHP_FE(xmlrpc_is_fault, NULL)
PHP_FE(xmlrpc_server_create, NULL) PHP_FE(xmlrpc_server_create, NULL)
PHP_FE(xmlrpc_server_destroy, NULL) PHP_FE(xmlrpc_server_destroy, NULL)
PHP_FE(xmlrpc_server_register_method, NULL) PHP_FE(xmlrpc_server_register_method, NULL)
@ -176,8 +177,13 @@ typedef struct _xmlrpc_callback_data {
/* value types */ /* value types */
#define OBJECT_TYPE_ATTR "xmlrpc_type" #define OBJECT_TYPE_ATTR "xmlrpc_type"
#define OBJECT_VALUE_ATTR "scalar" #define OBJECT_VALUE_ATTR "scalar"
#define OBJECT_VALUE_TS_ATTR "timestamp"
/* faults */
#define FAULT_CODE "faultCode"
#define FAULT_CODE_LEN (sizeof(FAULT_CODE) - 1)
#define FAULT_STRING "faultString"
#define FAULT_STRING_LEN (sizeof(FAULT_STRING) - 1)
/*********************** /***********************
* forward declarations * * forward declarations *
@ -753,7 +759,7 @@ PHP_FUNCTION(xmlrpc_decode_request)
zval* retval = decode_request_worker(xml, encoding, method); zval* retval = decode_request_worker(xml, encoding, method);
if(retval) { if(retval) {
*return_value = *retval; *return_value = *retval;
zval_copy_ctor(return_value); FREE_ZVAL(retval);
} }
} }
} }
@ -779,7 +785,7 @@ PHP_FUNCTION(xmlrpc_decode)
zval* retval = decode_request_worker(arg1, arg2, NULL); zval* retval = decode_request_worker(arg1, arg2, NULL);
if(retval) { if(retval) {
*return_value = *retval; *return_value = *retval;
FREE_ZVAL(retval); FREE_ZVAL(retval);
} }
} }
} }
@ -1119,14 +1125,6 @@ PHP_FUNCTION(xmlrpc_server_call_method)
out.xmlrpc_out.version = opts->version; out.xmlrpc_out.version = opts->version;
} }
} }
/* automagically determine output serialization type from request type */
if (out.b_auto_version) {
XMLRPC_REQUEST_OUTPUT_OPTIONS opts = XMLRPC_RequestGetOutputOptions(xRequest);
if (opts) {
out.xmlrpc_out.version = opts->version;
}
}
/* set some required request hoojum */ /* set some required request hoojum */
XMLRPC_RequestSetOutputOptions(xResponse, &out.xmlrpc_out); XMLRPC_RequestSetOutputOptions(xResponse, &out.xmlrpc_out);
XMLRPC_RequestSetRequestType(xResponse, xmlrpc_request_response); XMLRPC_RequestSetRequestType(xResponse, xmlrpc_request_response);
@ -1315,7 +1313,7 @@ XMLRPC_VECTOR_TYPE xmlrpc_str_as_vector_type(const char* str)
* note: this only works on strings, and only for date and base64, * note: this only works on strings, and only for date and base64,
* which do not have native php types. black magic lies herein. * which do not have native php types. black magic lies herein.
*/ */
int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE type) int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE newtype)
{ {
int bSuccess = FAILURE; int bSuccess = FAILURE;
@ -1323,8 +1321,8 @@ int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE type)
* base64 and datetime. all other types have corresponding php types * base64 and datetime. all other types have corresponding php types
*/ */
if (Z_TYPE_P(value) == IS_STRING) { if (Z_TYPE_P(value) == IS_STRING) {
if (type == xmlrpc_base64 || type == xmlrpc_datetime) { if (newtype == xmlrpc_base64 || newtype == xmlrpc_datetime) {
const char* typestr = xmlrpc_type_as_str(type, xmlrpc_vector_none); const char* typestr = xmlrpc_type_as_str(newtype, xmlrpc_vector_none);
zval* type; zval* type;
MAKE_STD_ZVAL(type); MAKE_STD_ZVAL(type);
@ -1333,8 +1331,30 @@ int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE type)
Z_STRVAL_P(type) = estrdup(typestr); Z_STRVAL_P(type) = estrdup(typestr);
Z_STRLEN_P(type) = strlen(typestr); Z_STRLEN_P(type) = strlen(typestr);
convert_to_object(value); if(newtype == xmlrpc_datetime) {
bSuccess = zend_hash_update(Z_OBJPROP_P(value), OBJECT_TYPE_ATTR, sizeof(OBJECT_TYPE_ATTR), (void *) &type, sizeof(zval *), NULL); XMLRPC_VALUE v = XMLRPC_CreateValueDateTime_ISO8601(NULL, value->value.str.val);
if(v) {
time_t timestamp = XMLRPC_GetValueDateTime(v);
if(time) {
pval* ztimestamp;
MAKE_STD_ZVAL(ztimestamp);
ztimestamp->type = IS_LONG;
ztimestamp->value.lval = timestamp;
convert_to_object(value);
if(SUCCESS == zend_hash_update(value->value.obj.properties, OBJECT_TYPE_ATTR, sizeof(OBJECT_TYPE_ATTR), (void *) &type, sizeof(zval *), NULL)) {
bSuccess = zend_hash_update(value->value.obj.properties, OBJECT_VALUE_TS_ATTR, sizeof(OBJECT_VALUE_TS_ATTR), (void *) &ztimestamp, sizeof(zval *), NULL);
}
}
XMLRPC_CleanupValue(v);
}
}
else {
convert_to_object(value);
bSuccess = zend_hash_update(Z_OBJPROP_P(value), OBJECT_TYPE_ATTR, sizeof(OBJECT_TYPE_ATTR), (void *) &type, sizeof(zval *), NULL);
}
} }
} }
@ -1457,6 +1477,37 @@ PHP_FUNCTION(xmlrpc_get_type)
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;
if (!(ARG_COUNT(ht) == 1) || getParameters(ht, ARG_COUNT(ht), &arg) == FAILURE) {
WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
}
if (Z_TYPE_P(arg) != IS_ARRAY) {
php_error(E_NOTICE, "%s() expects argument to be an array", get_active_function_name(TSRMLS_CC));
}
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;
}
/* /*
* Local variables: * Local variables:

View file

@ -367,6 +367,7 @@ int Q_PushTail(queue *q, void *d)
return True_; return True_;
} }
return False_;
} }

View file

@ -44,6 +44,13 @@ static const char rcsid[] = "#(@) $Id$";
* CREATION DATE * CREATION DATE
* 06/2000 * 06/2000
* HISTORY * HISTORY
* $Log$
* Revision 1.4 2002/02/13 20:58:50 danda
* patch to make source more windows friendly, contributed by Jeff Lawson
*
* Revision 1.3 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 10/15/2000 -- danda -- adding robodoc documentation * 10/15/2000 -- danda -- adding robodoc documentation
* PORTABILITY * PORTABILITY
* Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just * Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just

View file

@ -62,6 +62,7 @@ typedef struct _simplestring {
void simplestring_init(simplestring* string); void simplestring_init(simplestring* string);
void simplestring_clear(simplestring* string); void simplestring_clear(simplestring* string);
void simplestring_free(simplestring* string); void simplestring_free(simplestring* string);
void simplestring_add(simplestring* string, const char* add);
void simplestring_addn(simplestring* string, const char* add, int add_len); void simplestring_addn(simplestring* string, const char* add, int add_len);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -35,6 +35,10 @@
* AUTHOR * AUTHOR
* Dan Libby, aka danda (dan@libby.com) * Dan Libby, aka danda (dan@libby.com)
* HISTORY * HISTORY
* $Log$
* Revision 1.7 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 4/28/2001 -- danda -- adding system.multicall and separating out system methods. * 4/28/2001 -- danda -- adding system.multicall and separating out system methods.
* TODO * TODO
* NOTES * NOTES

View file

@ -43,6 +43,22 @@ static const char rcsid[] = "#(@) $Id$";
* CREATION DATE * CREATION DATE
* 06/2000 * 06/2000
* HISTORY * HISTORY
* $Log$
* Revision 1.9 2002/07/03 20:54:30 danda
* root element should not have a parent. patch from anon SF user
*
* Revision 1.8 2002/05/23 17:46:51 danda
* patch from mukund - fix non utf-8 encoding conversions
*
* Revision 1.7 2002/02/13 20:58:50 danda
* patch to make source more windows friendly, contributed by Jeff Lawson
*
* Revision 1.6 2002/01/08 01:06:55 danda
* enable <?xml version="1.0"?> format for parsers that are very picky.
*
* Revision 1.5 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 10/15/2000 -- danda -- adding robodoc documentation * 10/15/2000 -- danda -- adding robodoc documentation
* TODO * TODO
* Nicer external API. Get rid of macros. Make opaque types, etc. * Nicer external API. Get rid of macros. Make opaque types, etc.
@ -86,7 +102,7 @@ static const char rcsid[] = "#(@) $Id$";
#define XML_DECL_START "<?xml" #define XML_DECL_START "<?xml"
#define XML_DECL_START_LEN sizeof(XML_DECL_START) - 1 #define XML_DECL_START_LEN sizeof(XML_DECL_START) - 1
#define XML_DECL_VERSION "version='1.0'" #define XML_DECL_VERSION "version=\"1.0\""
#define XML_DECL_VERSION_LEN sizeof(XML_DECL_VERSION) - 1 #define XML_DECL_VERSION_LEN sizeof(XML_DECL_VERSION) - 1
#define XML_DECL_ENCODING_ATTR "encoding" #define XML_DECL_ENCODING_ATTR "encoding"
#define XML_DECL_ENCODING_ATTR_LEN sizeof(XML_DECL_ENCODING_ATTR) - 1 #define XML_DECL_ENCODING_ATTR_LEN sizeof(XML_DECL_ENCODING_ATTR) - 1
@ -353,7 +369,6 @@ static void xml_element_serialize(xml_element *el, int (*fptr)(void *data, const
xml_elem_writefunc(fptr, options->encoding, data, 0); xml_elem_writefunc(fptr, options->encoding, data, 0);
xml_elem_writefunc(fptr, ATTR_DELIMITER, data, ATTR_DELIMITER_LEN); xml_elem_writefunc(fptr, ATTR_DELIMITER, data, ATTR_DELIMITER_LEN);
} }
xml_elem_writefunc(fptr, WHITESPACE, data, WHITESPACE_LEN);
xml_elem_writefunc(fptr, XML_DECL_END, data, XML_DECL_END_LEN); xml_elem_writefunc(fptr, XML_DECL_END, data, XML_DECL_END_LEN);
if(options->verbosity != xml_elem_no_white_space) { if(options->verbosity != xml_elem_no_white_space) {
xml_elem_writefunc(fptr, NEWLINE, data, NEWLINE_LEN); xml_elem_writefunc(fptr, NEWLINE, data, NEWLINE_LEN);
@ -591,8 +606,10 @@ static void charHandler(void *userData,
/* Check if we need to decode utf-8 parser output to another encoding */ /* Check if we need to decode utf-8 parser output to another encoding */
if(mydata->needs_enc_conversion && mydata->input_options->encoding) { if(mydata->needs_enc_conversion && mydata->input_options->encoding) {
char* add_text = utf8_decode(s, len, &len, mydata->input_options->encoding); int new_len = 0;
char* add_text = utf8_decode(s, len, &new_len, mydata->input_options->encoding);
if(add_text) { if(add_text) {
len = new_len;
simplestring_addn(&mydata->current->text, add_text, len); simplestring_addn(&mydata->current->text, add_text, len);
free(add_text); free(add_text);
return; return;
@ -700,6 +717,7 @@ xml_element* xml_elem_parse_buf(const char* in_buf, int len, XML_ELEM_INPUT_OPTI
} }
else { else {
xReturn = (xml_element*)Q_Head(&mydata.root->children); xReturn = (xml_element*)Q_Head(&mydata.root->children);
xReturn->parent = NULL;
} }
XML_ParserFree(parser); XML_ParserFree(parser);

View file

@ -5,7 +5,7 @@
*/ */
/************************************************************************ /*-**********************************************************************
* TODO: * * TODO: *
* - [SOAP-ENC:position] read sparse arrays (and write?) * * - [SOAP-ENC:position] read sparse arrays (and write?) *
* - [SOAP-ENC:offset] read partially transmitted arrays (and write?) * * - [SOAP-ENC:offset] read partially transmitted arrays (and write?) *

View file

@ -71,11 +71,30 @@ XMLRPC_VALUE xml_element_to_XMLRPC_REQUEST_worker(XMLRPC_REQUEST request, XMLRPC
current_val = XMLRPC_CreateValueEmpty(); current_val = XMLRPC_CreateValueEmpty();
} }
if (el->name) { if (el->name) {
if (!strcmp(el->name, ELEM_DATA) /* should be ELEM_ARRAY, but there is an extra level. weird */
|| ((!strcmp(el->name, ELEM_PARAMS)) && /* first, deal with the crazy/stupid fault format */
(XMLRPC_RequestGetRequestType(request) == xmlrpc_request_call)) /* this "PARAMS" concept is silly. dave?! */ if (!strcmp(el->name, ELEM_FAULT)) {
|| !strcmp(el->name, ELEM_FAULT)) { /* so is this "FAULT" nonsense. */ xml_element* fault_value = (xml_element*)Q_Head(&el->children);
XMLRPC_SetIsVector(current_val, xmlrpc_vector_struct);
if(fault_value) {
xml_element* fault_struct = (xml_element*)Q_Head(&fault_value->children);
if(fault_struct) {
xml_element* iter = (xml_element*)Q_Head(&fault_struct->children);
while (iter) {
XMLRPC_VALUE xNextVal = XMLRPC_CreateValueEmpty();
xml_element_to_XMLRPC_REQUEST_worker(request, current_val, xNextVal, iter);
XMLRPC_AddValueToVector(current_val, xNextVal);
iter = (xml_element*)Q_Next(&fault_struct->children);
}
}
}
}
else if (!strcmp(el->name, ELEM_DATA) /* should be ELEM_ARRAY, but there is an extra level. weird */
|| (!strcmp(el->name, ELEM_PARAMS) &&
(XMLRPC_RequestGetRequestType(request) == xmlrpc_request_call)) ) { /* this "PARAMS" concept is silly. dave?! */
xml_element* iter = (xml_element*)Q_Head(&el->children); xml_element* iter = (xml_element*)Q_Head(&el->children);
XMLRPC_SetIsVector(current_val, xmlrpc_vector_array); XMLRPC_SetIsVector(current_val, xmlrpc_vector_array);

View file

@ -42,16 +42,31 @@ static const char rcsid[] = "#(@) $Id$";
* CREATION DATE * CREATION DATE
* 9/1999 - 10/2000 * 9/1999 - 10/2000
* HISTORY * HISTORY
* $Log$
* Revision 1.22 2002/03/09 23:15:44 danda
* add fault interrogation funcs
*
* Revision 1.21 2002/03/09 22:27:41 danda
* win32 build patches contributed by Jeff Lawson
*
* Revision 1.20 2002/02/13 20:58:50 danda
* patch to make source more windows friendly, contributed by Jeff Lawson
*
* Revision 1.19 2001/10/12 23:25:54 danda
* default to writing xmlrpc
*
* Revision 1.18 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 10/15/2000 -- danda -- adding robodoc documentation
* 08/2000 -- danda -- PHP C extension that uses XMLRPC
* 08/2000 -- danda -- support for two vocabularies: danda-rpc and xml-rpc
* 09/1999 -- danda -- Initial API, before I even knew of standard XMLRPC vocab. Response only. * 09/1999 -- danda -- Initial API, before I even knew of standard XMLRPC vocab. Response only.
* 06/2000 -- danda -- played with expat-ensor from www.ensor.org. Cool, but some flaws.
* 07/2000 -- danda -- wrote new implementation to be compatible with xmlrpc standard and * 07/2000 -- danda -- wrote new implementation to be compatible with xmlrpc standard and
* incorporated some ideas from ensor, most notably the separation of * incorporated some ideas from ensor, most notably the separation of
* xml dom from xmlrpc api. * xml dom from xmlrpc api.
* 08/2000 -- danda -- support for two vocabularies: danda-rpc and xml-rpc * 06/2000 -- danda -- played with expat-ensor from www.ensor.org. Cool, but some flaws.
* 08/2000 -- danda -- PHP C extension that uses XMLRPC
* 10/15/2000 -- danda -- adding robodoc documentation
* TODO * TODO
* Server method introspection. (Enumerate available methods, describe I/O)
* PORTABILITY * PORTABILITY
* Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just * Coded on RedHat Linux 6.2. Builds on Solaris x86. Should build on just
* about anything with minor mods. * about anything with minor mods.
@ -116,6 +131,7 @@ static const char rcsid[] = "#(@) $Id$";
#include "xml_element.h" #include "xml_element.h"
#include "xmlrpc_private.h" #include "xmlrpc_private.h"
#include "xmlrpc_introspection_private.h" #include "xmlrpc_introspection_private.h"
#include "system_methods_private.h"
@ -127,7 +143,6 @@ static int date_from_ISO8601 (const char *text, time_t * value) {
struct tm tm; struct tm tm;
int n; int n;
int i; int i;
time_t t;
char buf[18]; char buf[18];
if (strchr (text, '-')) { if (strchr (text, '-')) {
@ -625,7 +640,8 @@ char* XMLRPC_REQUEST_ToXML(XMLRPC_REQUEST request, int* buf_len) {
if (request->output.version == xmlrpc_version_simple) { if (request->output.version == xmlrpc_version_simple) {
root_elem = DANDARPC_REQUEST_to_xml_element (request); root_elem = DANDARPC_REQUEST_to_xml_element (request);
} }
else if (request->output.version == xmlrpc_version_1_0) { else if (request->output.version == xmlrpc_version_1_0 ||
request->output.version == xmlrpc_version_none) {
root_elem = XMLRPC_REQUEST_to_xml_element (request); root_elem = XMLRPC_REQUEST_to_xml_element (request);
} }
else if (request->output.version == xmlrpc_version_soap_1_1) { else if (request->output.version == xmlrpc_version_soap_1_1) {
@ -2382,7 +2398,7 @@ int XMLRPC_ServerRegisterMethod(XMLRPC_SERVER server, const char *name, XMLRPC_C
/*******/ /*******/
inline server_method* find_method(XMLRPC_SERVER server, const char* name) { server_method* find_method(XMLRPC_SERVER server, const char* name) {
server_method* sm; server_method* sm;
q_iter qi = Q_Iter_Head_F(&server->methodlist); q_iter qi = Q_Iter_Head_F(&server->methodlist);
@ -2649,7 +2665,7 @@ XMLRPC_CASE_COMPARISON XMLRPC_SetDefaultIdCaseComparison(XMLRPC_CASE_COMPARISON
/*-****************** /*-******************
* Utility API funcs * * Fault API funcs *
********************/ ********************/
/****f* UTILITY/XMLRPC_UtilityCreateFault /****f* UTILITY/XMLRPC_UtilityCreateFault
@ -2683,6 +2699,7 @@ XMLRPC_CASE_COMPARISON XMLRPC_SetDefaultIdCaseComparison(XMLRPC_CASE_COMPARISON
* simplerpc serialization, meaning that there will be no "<fault>" element in that * simplerpc serialization, meaning that there will be no "<fault>" element in that
* serialization. There will simply be a standard struct with 2 child elements. * serialization. There will simply be a standard struct with 2 child elements.
* imho, the "<fault>" element is unnecessary and/or out of place as part of the standard API. * imho, the "<fault>" element is unnecessary and/or out of place as part of the standard API.
*
* SOURCE * SOURCE
*/ */
XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string) { XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string) {
@ -2749,6 +2766,147 @@ XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string)
/*******/ /*******/
/****f* FAULT/XMLRPC_ValueIsFault
* NAME
* XMLRPC_ValueIsFault
* SYNOPSIS
* int XMLRPC_ValueIsFault (XMLRPC_VALUE value)
* FUNCTION
* Determines if a value encapsulates a fault "object"
* INPUTS
* value any XMLRPC_VALUE
* RESULT
* 1 if it is a fault, else 0
* SEE ALSO
* XMLRPC_ResponseIsFault ()
* SOURCE
*/
int XMLRPC_ValueIsFault (XMLRPC_VALUE value) {
if( XMLRPC_VectorGetValueWithID(value, "faultCode") &&
XMLRPC_VectorGetValueWithID(value, "faultString") ) {
return 1;
}
return 0;
}
/*******/
/****f* FAULT/XMLRPC_ResponseIsFault
* NAME
* XMLRPC_ResponseIsFault
* SYNOPSIS
* int XMLRPC_ResponseIsFault (XMLRPC_REQUEST response)
* FUNCTION
* Determines if a response contains an encapsulated fault "object"
* INPUTS
* value any XMLRPC_REQUEST. typically of type xmlrpc_request_response
* RESULT
* 1 if it contains a fault, else 0
* SEE ALSO
* XMLRPC_ValueIsFault ()
* SOURCE
*/
int XMLRPC_ResponseIsFault(XMLRPC_REQUEST response) {
return XMLRPC_ValueIsFault( XMLRPC_RequestGetData(response) );
}
/*******/
/****f* FAULT/XMLRPC_GetValueFaultCode
* NAME
* XMLRPC_GetValueFaultCode
* SYNOPSIS
* int XMLRPC_GetValueFaultCode (XMLRPC_VALUE value)
* FUNCTION
* returns fault code from a struct, if any
* INPUTS
* value XMLRPC_VALUE of type xmlrpc_vector_struct.
* RESULT
* fault code, else 0.
* BUGS
* impossible to distinguish faultCode == 0 from faultCode not present.
* SEE ALSO
* XMLRPC_GetResponseFaultCode ()
* SOURCE
*/
int XMLRPC_GetValueFaultCode (XMLRPC_VALUE value) {
return XMLRPC_VectorGetIntWithID(value, "faultCode");
}
/*******/
/****f* FAULT/XMLRPC_GetResponseFaultCode
* NAME
* XMLRPC_GetResponseFaultCode
* SYNOPSIS
* int XMLRPC_GetResponseFaultCode(XMLRPC_REQUEST response)
* FUNCTION
* returns fault code from a response, if any
* INPUTS
* response XMLRPC_REQUEST. typically of type xmlrpc_request_response.
* RESULT
* fault code, else 0.
* BUGS
* impossible to distinguish faultCode == 0 from faultCode not present.
* SEE ALSO
* XMLRPC_GetValueFaultCode ()
* SOURCE
*/
int XMLRPC_GetResponseFaultCode(XMLRPC_REQUEST response) {
return XMLRPC_GetValueFaultCode( XMLRPC_RequestGetData(response) );
}
/*******/
/****f* FAULT/XMLRPC_GetValueFaultString
* NAME
* XMLRPC_GetValueFaultString
* SYNOPSIS
* const char* XMLRPC_GetValueFaultString (XMLRPC_VALUE value)
* FUNCTION
* returns fault string from a struct, if any
* INPUTS
* value XMLRPC_VALUE of type xmlrpc_vector_struct.
* RESULT
* fault string, else 0.
* SEE ALSO
* XMLRPC_GetResponseFaultString ()
* SOURCE
*/
const char* XMLRPC_GetValueFaultString (XMLRPC_VALUE value) {
return XMLRPC_VectorGetStringWithID(value, "faultString");
}
/*******/
/****f* FAULT/XMLRPC_GetResponseFaultString
* NAME
* XMLRPC_GetResponseFaultString
* SYNOPSIS
* const char* XMLRPC_GetResponseFaultString (XMLRPC_REQUEST response)
* FUNCTION
* returns fault string from a response, if any
* INPUTS
* response XMLRPC_REQUEST. typically of type xmlrpc_request_response.
* RESULT
* fault string, else 0.
* SEE ALSO
* XMLRPC_GetValueFaultString ()
* SOURCE
*/
const char* XMLRPC_GetResponseFaultString (XMLRPC_REQUEST response) {
return XMLRPC_GetValueFaultString( XMLRPC_RequestGetData(response) );
}
/*******/
/*-******************
* Utility API funcs *
********************/
/****f* UTILITY/XMLRPC_Free /****f* UTILITY/XMLRPC_Free
* NAME * NAME
* XMLRPC_Free * XMLRPC_Free

View file

@ -43,11 +43,11 @@ extern "C" {
/* allow version to be specified via compile line define */ /* allow version to be specified via compile line define */
#ifndef XMLRPC_LIB_VERSION #ifndef XMLRPC_LIB_VERSION
#define XMLRPC_LIB_VERSION "0.50" #define XMLRPC_LIB_VERSION "0.51"
#endif #endif
/* this number, representing the date, must be increased each time the API changes */ /* this number, representing the date, must be increased each time the API changes */
#define XMLRPC_API_NO 20010721 #define XMLRPC_API_NO 20020623
/* this string should be changed with each packaged release */ /* this string should be changed with each packaged release */
#define XMLRPC_VERSION_STR "xmlrpc-epi v. " XMLRPC_LIB_VERSION #define XMLRPC_VERSION_STR "xmlrpc-epi v. " XMLRPC_LIB_VERSION
@ -191,8 +191,8 @@ typedef enum _xmlrpc_error_code {
* SOURCE * SOURCE
*/ */
typedef enum _xmlrpc_version { typedef enum _xmlrpc_version {
xmlrpc_version_none, /* not a recognized vocabulary */ xmlrpc_version_none = 0, /* not a recognized vocabulary */
xmlrpc_version_1_0, /* xmlrpc 1.0 standard vocab */ xmlrpc_version_1_0 = 1, /* xmlrpc 1.0 standard vocab */
xmlrpc_version_simple = 2, /* alt more readable vocab */ xmlrpc_version_simple = 2, /* alt more readable vocab */
xmlrpc_version_danda = 2, /* same as simple. legacy */ xmlrpc_version_danda = 2, /* same as simple. legacy */
xmlrpc_version_soap_1_1 = 3 /* SOAP. version 1.1 */ xmlrpc_version_soap_1_1 = 3 /* SOAP. version 1.1 */
@ -334,6 +334,10 @@ XMLRPC_VALUE XMLRPC_CreateVector(const char* id, XMLRPC_VECTOR_TYPE type);
/* Cleanup values */ /* Cleanup values */
void XMLRPC_CleanupValue(XMLRPC_VALUE value); void XMLRPC_CleanupValue(XMLRPC_VALUE value);
/* Request error */
XMLRPC_VALUE XMLRPC_RequestSetError (XMLRPC_REQUEST request, XMLRPC_VALUE error);
XMLRPC_VALUE XMLRPC_RequestGetError (XMLRPC_REQUEST request);
/* Copy values */ /* Copy values */
XMLRPC_VALUE XMLRPC_CopyValue(XMLRPC_VALUE value); XMLRPC_VALUE XMLRPC_CopyValue(XMLRPC_VALUE value);
XMLRPC_VALUE XMLRPC_DupValueNew(XMLRPC_VALUE xSource); XMLRPC_VALUE XMLRPC_DupValueNew(XMLRPC_VALUE xSource);
@ -393,6 +397,15 @@ XMLRPC_VALUE XMLRPC_ServerCallMethod(XMLRPC_SERVER server, XMLRPC_REQUEST reques
#include "xmlrpc_introspection.h" #include "xmlrpc_introspection.h"
/* Fault interrogation funcs */
int XMLRPC_ValueIsFault (XMLRPC_VALUE value);
int XMLRPC_ResponseIsFault(XMLRPC_REQUEST response);
int XMLRPC_GetValueFaultCode (XMLRPC_VALUE value);
int XMLRPC_GetResponseFaultCode(XMLRPC_REQUEST response);
const char* XMLRPC_GetValueFaultString (XMLRPC_VALUE value);
const char* XMLRPC_GetResponseFaultString (XMLRPC_REQUEST response);
/* Public Utility funcs */ /* Public Utility funcs */
XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string); XMLRPC_VALUE XMLRPC_UtilityCreateFault(int fault_code, const char* fault_string);
void XMLRPC_Free(void* mem); void XMLRPC_Free(void* mem);

View file

@ -35,6 +35,10 @@
* AUTHOR * AUTHOR
* Dan Libby, aka danda (dan@libby.com) * Dan Libby, aka danda (dan@libby.com)
* HISTORY * HISTORY
* $Log$
* Revision 1.9 2001/09/29 21:58:05 danda
* adding cvs log to history section
*
* 4/10/2001 -- danda -- initial introspection support * 4/10/2001 -- danda -- initial introspection support
* TODO * TODO
* NOTES * NOTES

View file

@ -160,7 +160,7 @@ typedef struct _server_method {
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
* Functions * Functions
*/ */
extern server_method* find_method(XMLRPC_SERVER server, const char* name); server_method* find_method(XMLRPC_SERVER server, const char* name);
const char* type_to_str(XMLRPC_VALUE_TYPE type, XMLRPC_VECTOR_TYPE vtype); const char* type_to_str(XMLRPC_VALUE_TYPE type, XMLRPC_VECTOR_TYPE vtype);
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------

View file

@ -80,6 +80,7 @@ PHP_FUNCTION(xmlrpc_decode_request);
PHP_FUNCTION(xmlrpc_encode_request); PHP_FUNCTION(xmlrpc_encode_request);
PHP_FUNCTION(xmlrpc_get_type); PHP_FUNCTION(xmlrpc_get_type);
PHP_FUNCTION(xmlrpc_set_type); PHP_FUNCTION(xmlrpc_set_type);
PHP_FUNCTION(xmlrpc_is_fault);
PHP_FUNCTION(xmlrpc_server_create); PHP_FUNCTION(xmlrpc_server_create);
PHP_FUNCTION(xmlrpc_server_destroy); PHP_FUNCTION(xmlrpc_server_destroy);
PHP_FUNCTION(xmlrpc_server_register_method); PHP_FUNCTION(xmlrpc_server_register_method);

View file

@ -68,7 +68,7 @@
#endif #endif
#include "xmlrpc.h" #include "xmlrpc.h"
#define PHP_EXT_VERSION "0.50" #define PHP_EXT_VERSION "0.51"
/* You should tweak config.m4 so this symbol (or some else suitable) /* You should tweak config.m4 so this symbol (or some else suitable)
gets defined. */ gets defined. */
@ -87,6 +87,7 @@ function_entry xmlrpc_functions[] = {
PHP_FE(xmlrpc_encode_request, NULL) PHP_FE(xmlrpc_encode_request, NULL)
PHP_FE(xmlrpc_get_type, NULL) PHP_FE(xmlrpc_get_type, NULL)
PHP_FE(xmlrpc_set_type, first_args_force_ref) PHP_FE(xmlrpc_set_type, first_args_force_ref)
PHP_FE(xmlrpc_is_fault, NULL)
PHP_FE(xmlrpc_server_create, NULL) PHP_FE(xmlrpc_server_create, NULL)
PHP_FE(xmlrpc_server_destroy, NULL) PHP_FE(xmlrpc_server_destroy, NULL)
PHP_FE(xmlrpc_server_register_method, NULL) PHP_FE(xmlrpc_server_register_method, NULL)
@ -176,8 +177,13 @@ typedef struct _xmlrpc_callback_data {
/* value types */ /* value types */
#define OBJECT_TYPE_ATTR "xmlrpc_type" #define OBJECT_TYPE_ATTR "xmlrpc_type"
#define OBJECT_VALUE_ATTR "scalar" #define OBJECT_VALUE_ATTR "scalar"
#define OBJECT_VALUE_TS_ATTR "timestamp"
/* faults */
#define FAULT_CODE "faultCode"
#define FAULT_CODE_LEN (sizeof(FAULT_CODE) - 1)
#define FAULT_STRING "faultString"
#define FAULT_STRING_LEN (sizeof(FAULT_STRING) - 1)
/*********************** /***********************
* forward declarations * * forward declarations *
@ -753,7 +759,7 @@ PHP_FUNCTION(xmlrpc_decode_request)
zval* retval = decode_request_worker(xml, encoding, method); zval* retval = decode_request_worker(xml, encoding, method);
if(retval) { if(retval) {
*return_value = *retval; *return_value = *retval;
zval_copy_ctor(return_value); FREE_ZVAL(retval);
} }
} }
} }
@ -779,7 +785,7 @@ PHP_FUNCTION(xmlrpc_decode)
zval* retval = decode_request_worker(arg1, arg2, NULL); zval* retval = decode_request_worker(arg1, arg2, NULL);
if(retval) { if(retval) {
*return_value = *retval; *return_value = *retval;
FREE_ZVAL(retval); FREE_ZVAL(retval);
} }
} }
} }
@ -1119,14 +1125,6 @@ PHP_FUNCTION(xmlrpc_server_call_method)
out.xmlrpc_out.version = opts->version; out.xmlrpc_out.version = opts->version;
} }
} }
/* automagically determine output serialization type from request type */
if (out.b_auto_version) {
XMLRPC_REQUEST_OUTPUT_OPTIONS opts = XMLRPC_RequestGetOutputOptions(xRequest);
if (opts) {
out.xmlrpc_out.version = opts->version;
}
}
/* set some required request hoojum */ /* set some required request hoojum */
XMLRPC_RequestSetOutputOptions(xResponse, &out.xmlrpc_out); XMLRPC_RequestSetOutputOptions(xResponse, &out.xmlrpc_out);
XMLRPC_RequestSetRequestType(xResponse, xmlrpc_request_response); XMLRPC_RequestSetRequestType(xResponse, xmlrpc_request_response);
@ -1315,7 +1313,7 @@ XMLRPC_VECTOR_TYPE xmlrpc_str_as_vector_type(const char* str)
* note: this only works on strings, and only for date and base64, * note: this only works on strings, and only for date and base64,
* which do not have native php types. black magic lies herein. * which do not have native php types. black magic lies herein.
*/ */
int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE type) int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE newtype)
{ {
int bSuccess = FAILURE; int bSuccess = FAILURE;
@ -1323,8 +1321,8 @@ int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE type)
* base64 and datetime. all other types have corresponding php types * base64 and datetime. all other types have corresponding php types
*/ */
if (Z_TYPE_P(value) == IS_STRING) { if (Z_TYPE_P(value) == IS_STRING) {
if (type == xmlrpc_base64 || type == xmlrpc_datetime) { if (newtype == xmlrpc_base64 || newtype == xmlrpc_datetime) {
const char* typestr = xmlrpc_type_as_str(type, xmlrpc_vector_none); const char* typestr = xmlrpc_type_as_str(newtype, xmlrpc_vector_none);
zval* type; zval* type;
MAKE_STD_ZVAL(type); MAKE_STD_ZVAL(type);
@ -1333,8 +1331,30 @@ int set_zval_xmlrpc_type(zval* value, XMLRPC_VALUE_TYPE type)
Z_STRVAL_P(type) = estrdup(typestr); Z_STRVAL_P(type) = estrdup(typestr);
Z_STRLEN_P(type) = strlen(typestr); Z_STRLEN_P(type) = strlen(typestr);
convert_to_object(value); if(newtype == xmlrpc_datetime) {
bSuccess = zend_hash_update(Z_OBJPROP_P(value), OBJECT_TYPE_ATTR, sizeof(OBJECT_TYPE_ATTR), (void *) &type, sizeof(zval *), NULL); XMLRPC_VALUE v = XMLRPC_CreateValueDateTime_ISO8601(NULL, value->value.str.val);
if(v) {
time_t timestamp = XMLRPC_GetValueDateTime(v);
if(time) {
pval* ztimestamp;
MAKE_STD_ZVAL(ztimestamp);
ztimestamp->type = IS_LONG;
ztimestamp->value.lval = timestamp;
convert_to_object(value);
if(SUCCESS == zend_hash_update(value->value.obj.properties, OBJECT_TYPE_ATTR, sizeof(OBJECT_TYPE_ATTR), (void *) &type, sizeof(zval *), NULL)) {
bSuccess = zend_hash_update(value->value.obj.properties, OBJECT_VALUE_TS_ATTR, sizeof(OBJECT_VALUE_TS_ATTR), (void *) &ztimestamp, sizeof(zval *), NULL);
}
}
XMLRPC_CleanupValue(v);
}
}
else {
convert_to_object(value);
bSuccess = zend_hash_update(Z_OBJPROP_P(value), OBJECT_TYPE_ATTR, sizeof(OBJECT_TYPE_ATTR), (void *) &type, sizeof(zval *), NULL);
}
} }
} }
@ -1457,6 +1477,37 @@ PHP_FUNCTION(xmlrpc_get_type)
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;
if (!(ARG_COUNT(ht) == 1) || getParameters(ht, ARG_COUNT(ht), &arg) == FAILURE) {
WRONG_PARAM_COUNT; /* prints/logs a warning and returns */
}
if (Z_TYPE_P(arg) != IS_ARRAY) {
php_error(E_NOTICE, "%s() expects argument to be an array", get_active_function_name(TSRMLS_CC));
}
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;
}
/* /*
* Local variables: * Local variables: