⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlrpc.c

📁 PHP v6.0 For Linux 运行环境:Win9X/ WinME/ WinNT/ Win2K/ WinXP
💻 C
📖 第 1 页 / 共 5 页
字号:
/*  This file is part of libXMLRPC - a C library for xml-encoded function calls.  Author: Dan Libby (dan@libby.com)  Epinions.com may be contacted at feedback@epinions-inc.com*//*    Copyright 2000 Epinions, Inc.   Subject to the following 3 conditions, Epinions, Inc.  permits you, free   of charge, to (a) use, copy, distribute, modify, perform and display this   software and associated documentation files (the "Software"), and (b)   permit others to whom the Software is furnished to do so as well.    1) The above copyright notice and this permission notice shall be included   without modification in all copies or substantial portions of the   Software.    2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF   ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY   IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR   PURPOSE OR NONINFRINGEMENT.    3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,   SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT   OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING   NEGLIGENCE), EVEN IF EPINIONS, INC.  IS AWARE OF THE POSSIBILITY OF SUCH   DAMAGES.    */static const char rcsid[] = "#(@) $Id: xmlrpc.c,v 1.8 2005/03/28 00:07:24 edink Exp $";/****h* ABOUT/xmlrpc * NAME *   XMLRPC_VALUE * AUTHOR *   Dan Libby, aka danda  (dan@libby.com) * CREATION DATE *   9/1999 - 10/2000 * HISTORY *   $Log: xmlrpc.c,v $ *   Revision 1.8  2005/03/28 00:07:24  edink *   Reshufle includes to make it compile on windows * *   Revision 1.7  2005/03/26 03:13:58  sniper *   - Made it possible to build ext/xmlrpc with libxml2 * *   Revision 1.6  2004/04/27 17:33:59  iliaa *   Removed C++ style comments. * *   Revision 1.5  2003/12/16 21:00:21  sniper *   Fix some compile warnings (patch by Joe Orton) * *   Revision 1.4  2002/07/05 04:43:53  danda *   merged in updates from SF project.  bring php repository up to date with xmlrpc-epi version 0.51 * *   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. *   07/2000 -- danda -- wrote new implementation to be compatible with xmlrpc standard and *                       incorporated some ideas from ensor, most notably the separation of *                       xml dom from xmlrpc api. *   06/2000 -- danda -- played with expat-ensor from www.ensor.org.  Cool, but some flaws. * TODO * PORTABILITY *   Coded on RedHat Linux 6.2.  Builds on Solaris x86.  Should build on just *   about anything with minor mods. * NOTES *   Welcome to XMLRPC.  For more info on the specification and history, see *   http://www.xmlrpc.org. * *   This code aims to be a full-featured C implementation of XMLRPC.  It does not *   have any networking code.  Rather, it is intended to be plugged into apps *   or libraries with existing networking facilities, eg PHP, apache, perl, mozilla,  *   home-brew application servers, etc. * *   Usage Paradigm: *     The user of this library will typically be implementing either an XMLRPC server, *     an XMLRPC client, or both.  The client will use the library to build an in-memory *     representation of a request, and then serialize (encode) that request into XML. The *     client will then send the XML to the server via external mechanism.  The server will *     de-serialize the XML back into an binary representation, call the appropriate registered *     method -- thereby generating a response.  The response will be serialized into XML and *     sent back to the client.  The client will de-serialize it into memory, and can *     iterate through the results via API. * *     Both the request and the response may consist of arbitrarily long, arbitrarily nested *     values.  The values may be one of several types, as defined by XMLRPC_VALUE_TYPE. * *   Features and Architecture: *     - The XML parsing (xml_element.c) is completely independent of the XMLRPC api. In fact, *       it can be used as a standalone dom implementation. *     - Because of this, the same XMLRPC data can be serialized into multiple xml vocabularies. *       It is simply a matter of writing a transport.  So far, two transports have been defined. *       The default xmlrpc vocab (xml_to_xmlrpc.c), and simple-rpc (xml_to_dandarpc.c) which is  *       proprietary, but imho more readable, and nice for proprietary legacy reasons. *     - Various output options, including: xml escaping via CDATA or entity, case folding, *       vocab version, and character encoding. *     - One to One mapping between C structures and actual values, unlike ensor which forces *       one to understand the arcana of the xmlrpc vocab. *     - support for mixed indexed/keyed vector types, making it more compatible with  *       languages such as PHP. *     - quite speedy compared to implementations written in interpreted languages. Also, uses *       intelligent string handling, so not many strlen() calls, etc. *     - comprehensive API for manipulation of values *******/#include "ext/xml/expat_compat.h"#ifdef _WIN32#include "xmlrpc_win32.h"#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <time.h>#include <ctype.h>#include "queue.h"#include "xmlrpc.h"#include "base64.h"#include "xml_to_xmlrpc.h"#include "xml_to_dandarpc.h"#include "xml_to_soap.h"#include "xml_element.h"#include "xmlrpc_private.h"#include "xmlrpc_introspection_private.h"#include "system_methods_private.h"/*-********************** Begin Time Functions ************************/static int date_from_ISO8601 (const char *text, time_t * value) {   struct tm tm;   int n;   int i;	char buf[18];	if (strchr (text, '-')) {		char *p = (char *) text, *p2 = buf;		while (p && *p) {			if (*p != '-') {				*p2 = *p;				p2++;			}			p++;		}		text = buf;	}   tm.tm_isdst = -1;   if(strlen(text) < 17) {      return -1;   }   n = 1000;   tm.tm_year = 0;   for(i = 0; i < 4; i++) {      tm.tm_year += (text[i]-'0')*n;      n /= 10;   }   n = 10;   tm.tm_mon = 0;   for(i = 0; i < 2; i++) {      tm.tm_mon += (text[i+4]-'0')*n;      n /= 10;   }   tm.tm_mon --;   n = 10;   tm.tm_mday = 0;   for(i = 0; i < 2; i++) {      tm.tm_mday += (text[i+6]-'0')*n;      n /= 10;   }   n = 10;   tm.tm_hour = 0;   for(i = 0; i < 2; i++) {      tm.tm_hour += (text[i+9]-'0')*n;      n /= 10;   }   n = 10;   tm.tm_min = 0;   for(i = 0; i < 2; i++) {      tm.tm_min += (text[i+12]-'0')*n;      n /= 10;   }   n = 10;   tm.tm_sec = 0;   for(i = 0; i < 2; i++) {      tm.tm_sec += (text[i+15]-'0')*n;      n /= 10;   }   tm.tm_year -= 1900;   *value = mktime(&tm);   return 0;}static int date_to_ISO8601 (time_t value, char *buf, int length) {   struct tm *tm;   tm = localtime(&value);#if 0  /* TODO: soap seems to favor this method. xmlrpc the latter. */	return strftime (buf, length, "%Y-%m-%dT%H:%M:%SZ", tm);#else   return strftime(buf, length, "%Y%m%dT%H:%M:%S", tm);#endif}/*-******************** End Time Functions **********************//*-**************************** Begin XMLRPC_REQUEST funcs ******************************//****f* REQUEST/XMLRPC_RequestNew * NAME *   XMLRPC_RequestNew * SYNOPSIS *   XMLRPC_REQUEST XMLRPC_RequestNew() * FUNCTION *   Creates a new XMLRPC_Request data struct * INPUTS *   none * SEE ALSO *   XMLRPC_RequestFree () * SOURCE */XMLRPC_REQUEST XMLRPC_RequestNew() {   XMLRPC_REQUEST xRequest = calloc(1, sizeof(STRUCT_XMLRPC_REQUEST));   if(xRequest) {      simplestring_init(&xRequest->methodName);   }   return xRequest;}/*******//****f* REQUEST/XMLRPC_RequestFree * NAME *   XMLRPC_RequestFree * SYNOPSIS *   void XMLRPC_RequestFree(XMLRPC_REQUEST request, int bFreeIO) * FUNCTION *   Free XMLRPC Request and all sub-values * INPUTS *   request -- previously allocated request struct *   bFreeIO -- 1 = also free request value data, if any, 0 = ignore. * SEE ALSO *   XMLRPC_RequestNew () *   XMLRPC_CleanupValue () * SOURCE */void XMLRPC_RequestFree(XMLRPC_REQUEST request, int bFreeIO) {   if(request) {      simplestring_free(&request->methodName);      if(request->io && bFreeIO) {         XMLRPC_CleanupValue(request->io);      }      if(request->error) {         XMLRPC_CleanupValue(request->error);      }      my_free(request);   }}/*******//* Set Method Name to call *//****f* REQUEST/XMLRPC_RequestSetMethodName * NAME *   XMLRPC_RequestSetMethodName * SYNOPSIS *   const char* XMLRPC_RequestSetMethodName(XMLRPC_REQUEST request, const char* methodName) * FUNCTION *   Set name of method to call with this request. * INPUTS *   request -- previously allocated request struct *   methodName -- name of method * SEE ALSO *   XMLRPC_RequestNew () *   XMLRPC_RequestGetMethodName () *   XMLRPC_RequestFree () * SOURCE */const char* XMLRPC_RequestSetMethodName(XMLRPC_REQUEST request, const char* methodName) {   if(request) {      simplestring_clear(&request->methodName);      simplestring_add(&request->methodName, methodName);      return request->methodName.str;   }   return NULL;}/*******//****f* REQUEST/XMLRPC_RequestGetMethodName * NAME *   XMLRPC_RequestGetMethodName * SYNOPSIS *   const char* XMLRPC_RequestGetMethodName(XMLRPC_REQUEST request) * FUNCTION *   Get name of method called by this request * INPUTS *   request -- previously allocated request struct * SEE ALSO *   XMLRPC_RequestNew () *   XMLRPC_RequestSetMethodName () *   XMLRPC_RequestFree () * SOURCE */const char* XMLRPC_RequestGetMethodName(XMLRPC_REQUEST request) {   return request ? request->methodName.str : NULL;}/*******//****f* REQUEST/XMLRPC_RequestSetRequestType * NAME *   XMLRPC_RequestSetRequestType * SYNOPSIS *   XMLRPC_REQUEST_TYPE XMLRPC_RequestSetRequestType(XMLRPC_REQUEST request, XMLRPC_REQUEST_TYPE type) * FUNCTION *   A request struct may be allocated by a caller or by xmlrpc *   in response to a request.  This allows setting the *   request type. * INPUTS *   request -- previously allocated request struct *   type    -- request type [xmlrpc_method_call | xmlrpc_method_response] * SEE ALSO *   XMLRPC_RequestNew () *   XMLRPC_RequestGetRequestType () *   XMLRPC_RequestFree () *   XMLRPC_REQUEST_TYPE * SOURCE */XMLRPC_REQUEST_TYPE XMLRPC_RequestSetRequestType (XMLRPC_REQUEST request,																  XMLRPC_REQUEST_TYPE type) {   if(request) {      request->request_type = type;      return request->request_type;   }   return xmlrpc_request_none;}/*******//****f* REQUEST/XMLRPC_RequestGetRequestType * NAME *   XMLRPC_RequestGetRequestType * SYNOPSIS *   XMLRPC_REQUEST_TYPE XMLRPC_RequestGetRequestType(XMLRPC_REQUEST request) * FUNCTION *   A request struct may be allocated by a caller or by xmlrpc *   in response to a request.  This allows setting the *   request type. * INPUTS *   request -- previously allocated request struct * RESULT *   type    -- request type [xmlrpc_method_call | xmlrpc_method_response] * SEE ALSO *   XMLRPC_RequestNew () *   XMLRPC_RequestSetRequestType () *   XMLRPC_RequestFree () *   XMLRPC_REQUEST_TYPE * SOURCE */XMLRPC_REQUEST_TYPE XMLRPC_RequestGetRequestType(XMLRPC_REQUEST request) {   return request ? request->request_type : xmlrpc_request_none;}/*******//****f* REQUEST/XMLRPC_RequestSetData * NAME *   XMLRPC_RequestSetData * SYNOPSIS *   XMLRPC_VALUE XMLRPC_RequestSetData(XMLRPC_REQUEST request, XMLRPC_VALUE data) * FUNCTION *   Associates a block of xmlrpc data with the request.  The *   data is *not* copied.  A pointer is kept.  The caller *   should be careful not to doubly free the data value, *   which may optionally be free'd by XMLRPC_RequestFree(). * INPUTS *   request -- previously allocated request struct *   data    -- previously allocated data struct * RESULT *   XMLRPC_VALUE -- pointer to value stored, or NULL * SEE ALSO *   XMLRPC_RequestNew () *   XMLRPC_RequestGetData () *   XMLRPC_RequestFree () *   XMLRPC_REQUEST *   XMLRPC_VALUE * SOURCE */XMLRPC_VALUE XMLRPC_RequestSetData(XMLRPC_REQUEST request, XMLRPC_VALUE data) {   if(request && data) {		if (request->io) {			XMLRPC_CleanupValue (request->io);		}      request->io = XMLRPC_CopyValue(data);      return request->io;   }   return NULL;}/*******//****f* REQUEST/XMLRPC_RequestGetData * NAME *   XMLRPC_RequestGetData * SYNOPSIS *   XMLRPC_VALUE XMLRPC_RequestGetData(XMLRPC_REQUEST request) * FUNCTION *   Returns data associated with request, if any. * INPUTS *   request -- previously allocated request struct * RESULT *   XMLRPC_VALUE -- pointer to value stored, or NULL * SEE ALSO *   XMLRPC_RequestNew () *   XMLRPC_RequestSetData () *   XMLRPC_RequestFree () *   XMLRPC_REQUEST *   XMLRPC_VALUE * SOURCE */XMLRPC_VALUE XMLRPC_RequestGetData(XMLRPC_REQUEST request) {   return request ? request->io : NULL;}/*******//****f* REQUEST/XMLRPC_RequestSetError * NAME *   XMLRPC_RequestSetError * SYNOPSIS *   XMLRPC_VALUE XMLRPC_RequestSetError(XMLRPC_REQUEST request, XMLRPC_VALUE error) * FUNCTION *   Associates a block of xmlrpc data, representing an error *   condition, with the request.  * INPUTS *   request -- previously allocated request struct *   error   -- previously allocated error code or struct * RESULT *   XMLRPC_VALUE -- pointer to value stored, or NULL * NOTES *   This is a private function for usage by internals only. * SEE ALSO *   XMLRPC_RequestGetError () * SOURCE */XMLRPC_VALUE XMLRPC_RequestSetError (XMLRPC_REQUEST request, XMLRPC_VALUE error) {	if (request && error) {		if (request->error) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -