/* 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. */ /* A memory (refcount) test program * * For usage, see below * */ #include #include #include "xmlrpc.h" /* These are some tests for checking out efficacy of ref-counting values. This program will * not have any ouput unless libxmlrpc is compiled with XMLRPC_DEBUG_REFCOUNT defined. */ #define TEST_DUPPED_VALUE 1 int main(int argc, char **argv) { #if 0 XMLRPC_VALUE xVector1 = XMLRPC_CreateVector("vector_1", xmlrpc_vector_struct); XMLRPC_VALUE xVector2 = XMLRPC_CreateVector("vector_2", xmlrpc_vector_struct); XMLRPC_REQUEST xRequest = XMLRPC_RequestNew(); #endif /* shallow cycle. bad! currently segfaults */ #ifdef TEST_CYCLE_DIRECT XMLRPC_VALUE xVector1 = XMLRPC_CreateVector("vector_1", xmlrpc_vector_struct); XMLRPC_AddValueToVector(xVector1, xVector1); XMLRPC_AddValueToVector(xVector1, xVector1); XMLRPC_CleanupValue(xVector1); #endif /* deep cycle. bad! currently segfaults. */ #ifdef TEST_CYCLE_INDIRECT XMLRPC_VALUE xVector1 = XMLRPC_CreateVector("vector_1", xmlrpc_vector_struct); XMLRPC_VALUE xVector2 = XMLRPC_CreateVector("vector_2", xmlrpc_vector_struct); XMLRPC_AddValueToVector(xVector1, xVector2); XMLRPC_AddValueToVector(xVector2, xVector1); XMLRPC_CleanupValue(xVector1); #endif #ifdef TEST_DUPPED_VALUE XMLRPC_VALUE xVector1 = XMLRPC_CreateVector("vector_1", xmlrpc_vector_struct), xVector2 = NULL; XMLRPC_VALUE xString = XMLRPC_CreateValueString("string", "a string", 0); XMLRPC_AddValueToVector(xVector1, xString); xVector2 = XMLRPC_DupValueNew(xVector1); XMLRPC_SetValueID(xVector2, "vector_1: dupped", 0); XMLRPC_CleanupValue(xVector1); XMLRPC_CleanupValue(xVector2); #endif /* normal usage */ #ifdef TEST_MULTI_REFERENCED_STRING XMLRPC_REQUEST xRequest = XMLRPC_RequestNew(); XMLRPC_VALUE xVector1 = XMLRPC_CreateVector("vector_1", xmlrpc_vector_struct); XMLRPC_VALUE xVector2 = XMLRPC_CreateVector("vector_2", xmlrpc_vector_struct); XMLRPC_VALUE xString = XMLRPC_CreateValueString("string", "a string", 0); XMLRPC_VALUE xString2 = XMLRPC_CopyValue(xString); /* Add various data to the request. */ XMLRPC_AddValueToVector(xVector1, xString); XMLRPC_AddValueToVector(xVector2, xString); XMLRPC_RequestSetData(xRequest, xVector1); XMLRPC_RequestFree(xRequest, 0); XMLRPC_CleanupValue(xVector1); XMLRPC_CleanupValue(xVector2); XMLRPC_CleanupValue(xString2); #endif #ifdef TEST_INTROSPECTION_LOOP int i; XMLRPC_VALUE xResponse; for(i = 0; i < 10; i++) { XMLRPC_SERVER server = XMLRPC_ServerCreate(); XMLRPC_REQUEST request = XMLRPC_RequestNew(); XMLRPC_RequestSetMethodName(request, "system.describeMethods"); XMLRPC_RequestSetRequestType(request, xmlrpc_request_call); xResponse = XMLRPC_ServerCallMethod(server, request, 0); XMLRPC_CleanupValue(xResponse); XMLRPC_RequestFree(request, 1); XMLRPC_ServerDestroy(server); printf(".");fflush(stdout); } printf("\n"); #endif #ifdef XML_TEST static const char* xsm_introspection_xml = "" "" "" "" "value identifier" "value's xmlrpc or user-defined type" "value's textual description " "true if value is optional, else it is required " "a child of this element. n/a for scalar types " "" "" "" "" "" "" "" "" "Dan Libby" "fully describes the methods and types implemented by this XML-RPC server." "1.1" "" "" "" "" "a valid method name" "" "" "" "" "" "" "method name" "method version" "method author" "method purpose" "" "" "parameter list" "return value list" "" "" "" "" "" "a type description" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "Dan Libby" "enumerates the methods implemented by this XML-RPC server." "1.0" "" "" "" "" "name of a method implemented by the server." "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "Dan Libby" "provides documentation string for a single method" "1.0" "" "" "" "name of the method for which documentation is desired" "" "" "help text if defined for the method passed, otherwise an empty string" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "Dan Libby" "provides 1 or more signatures for a single method" "1.0" "" "" "" "name of the method for which documentation is desired" "" "" "" "" "a string indicating the xmlrpc type of a value. one of: string, int, double, base64, datetime, array, struct" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "Dan Libby" "executes multiple methods in sequence and returns the results" "1.0" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "Dan Libby" "returns the version of fault code interop spec that this server is implemented according to. See http://xmlrpc-epi.sourceforge.net/specs/" "1.0" "" "" "" "" "" "" "" "" "" "" "" "version string. this matches the version string found in the spec." "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; XMLRPC_VALUE xDesc = XMLRPC_IntrospectionCreateDescription(xsm_introspection_xml, NULL); XMLRPC_CleanupValue(xDesc); #endif return 0; }