Commit 3615950f authored by Brad King's avatar Brad King
Browse files

ENH: Remove Utilities/cmxmlrpc source tree

We never build this source tree anymore, so remove it.
parent 8f5af617
MACRO(TRY_COMPILE_FROM_SOURCE SOURCE VAR)
IF("${VAR}" MATCHES "^${VAR}$" OR "${VAR}" MATCHES "UNKNOWN")
SET(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
IF(CMAKE_REQUIRED_LIBRARIES)
SET(TRY_COMPILE_FROM_SOURCE_ADD_LIBRARIES
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
ENDIF(CMAKE_REQUIRED_LIBRARIES)
SET(src "")
FOREACH(def ${EXTRA_DEFINES})
SET(src "${src}#define ${def} 1\n")
ENDFOREACH(def)
FOREACH(inc ${HEADER_INCLUDES})
SET(src "${src}#include <${inc}>\n")
ENDFOREACH(inc)
SET(src "${src}\nint main() { ${SOURCE} ; return 0; }")
FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src2.c"
"${src}\n")
EXEC_PROGRAM("${CMAKE_COMMAND}"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp"
ARGS -E copy src2.c src.c)
MESSAGE(STATUS "Performing Test ${VAR}")
TRY_COMPILE(${VAR}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
CMAKE_FLAGS
"${TRY_COMPILE_FROM_SOURCE_ADD_LIBRARIES}"
OUTPUT_VARIABLE OUTPUT)
IF(${VAR})
SET(${VAR} 1 CACHE INTERNAL "Test ${FUNCTION}")
MESSAGE(STATUS "Performing Test ${VAR} - Success")
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Performing C SOURCE FILE Test ${VAR} succeded with the following output:\n"
"${OUTPUT}\n"
"Source file was:\n${src}\n")
ELSE(${VAR})
MESSAGE(STATUS "Performing Test ${VAR} - Failed")
SET(${VAR} "" CACHE INTERNAL "Test ${FUNCTION}")
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Performing C SOURCE FILE Test ${VAR} failed with the following output:\n"
"${OUTPUT}\n"
"Source file was:\n${src}\n")
ENDIF(${VAR})
ENDIF("${VAR}" MATCHES "^${VAR}$" OR "${VAR}" MATCHES "UNKNOWN")
ENDMACRO(TRY_COMPILE_FROM_SOURCE)
PROJECT(XMLRPC)
INCLUDE_REGULAR_EXPRESSION("^.*$")
# Disable warnings on Borland to avoid changing 3rd party code.
IF(BORLAND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
ENDIF(BORLAND)
# Include all the necessary files for macros
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
# Check if header file exists and add it to the list.
SET(CURRENT_INCLUDES)
INCLUDE (CheckIncludeFiles)
MACRO(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
CHECK_INCLUDE_FILES("${CURRENT_INCLUDES};${FILE}" ${VARIABLE})
IF(${VARIABLE})
SET(CURRENT_INCLUDES ${CURRENT_INCLUDES} ${FILE})
ENDIF(${VARIABLE})
ENDMACRO(CHECK_INCLUDE_FILE_CONCAT)
CHECK_INCLUDE_FILE_CONCAT("stdio.h" HAVE_STDIO_H)
CHECK_INCLUDE_FILE_CONCAT("stdarg.h" HAVE_STDARG_H)
CHECK_INCLUDE_FILE_CONCAT("sys/filio.h" HAVE_SYS_FILIO_H)
CHECK_INCLUDE_FILE_CONCAT("sys/ioctl.h" HAVE_SYS_IOCTL_H)
CHECK_INCLUDE_FILE_CONCAT("wchar.h" HAVE_WCHAR_H)
IF(HAVE_WCHAR_H)
OPTION(HAVE_UNICODE_WCHAR "Enable Unicode Support" YES)
MARK_AS_ADVANCED(HAVE_UNICODE_WCHAR)
ELSE(HAVE_WCHAR_H)
SET(HAVE_UNICODE_WCHAR 0)
ENDIF(HAVE_WCHAR_H)
INCLUDE (CheckSymbolExists)
CHECK_SYMBOL_EXISTS(asprintf "${CURRENT_INCLUDES}" HAVE_ASPRINTF)
CHECK_SYMBOL_EXISTS(setgroups "${CURRENT_INCLUDES}" HAVE_SETGROUPS)
INCLUDE (CheckTypeSize)
CHECK_TYPE_SIZE(size_t SIZEOF_SIZE_T)
INCLUDE (TryCompileFromSource)
SET(HEADER_INCLUDES "${CURRENT_INCLUDES}")
TRY_COMPILE_FROM_SOURCE("va_list list1, list2; list1 = list2"
VA_LIST_ISNOT_ARRAY_DEFINE)
TRY_COMPILE_FROM_SOURCE("va_list list1, list2; va_copy(list1, list2);"
HAS_VA_COPY)
SET(VA_LIST_IS_ARRAY_DEFINE 0)
IF(NOT VA_LIST_ISNOT_ARRAY_DEFINE)
SET(VA_LIST_IS_ARRAY_DEFINE 1)
ENDIF(NOT VA_LIST_ISNOT_ARRAY_DEFINE)
TRY_COMPILE_FROM_SOURCE("int x __attribute__((__unused__))"
ATTR_UNUSED_VAR)
SET(ATTR_UNUSED)
IF(ATTR_UNUSED_VAR)
SET(ATTR_UNUSED "__attribute__((__unused__))")
ENDIF(ATTR_UNUSED_VAR)
SET(HAVE_LIBWWW_SSL)
SET(DIRECTORY_SEPARATOR "/")
SET(HAVE_PTHREADS 0)
IF(CMAKE_BUILD_XMLRPC_WITH_THREADS)
FIND_PACKAGE(Threads)
IF(WIN32 OR CMAKE_USE_PTHREADS_INIT)
SET(HAVE_PTHREADS 1)
ENDIF(WIN32 OR CMAKE_USE_PTHREADS_INIT)
ENDIF(CMAKE_BUILD_XMLRPC_WITH_THREADS)
INCLUDE_DIRECTORIES(
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
${CMAKE_EXPAT_INCLUDES}
${CMAKE_CURL_INCLUDES}
)
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/xmlrpc_config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/xmlrpc_config.h"
)
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/xmlrpc_amconfig.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/xmlrpc_amconfig.h"
)
SET(xmlrpc_SRCS
#XmlRpcCpp.cpp
xmlrpc_array.c
xmlrpc_authcookie.c
xmlrpc_base64.c
xmlrpc_client.c
xmlrpc_data.c
xmlrpc_expat.c
xmlrpc_parse.c
xmlrpc_registry.c
xmlrpc_serialize.c
xmlrpc_curl_transport.c
#xmlrpc_server_abyss.c
xmlrpc_struct.c
xmlrpc_strutil.c
xmlrpc_support.c
casprintf.c
)
IF(HAVE_UNICODE_WCHAR)
SET(xmlrpc_SRCS
${xmlrpc_SRCS}
xmlrpc_utf8.c
)
ENDIF(HAVE_UNICODE_WCHAR)
IF(WIN32)
SET(xmlrpc_SRCS ${xmlrpc_SRCS}
win32_pthreads.c
)
ENDIF(WIN32)
ADD_LIBRARY(cmXMLRPC ${xmlrpc_SRCS})
TARGET_LINK_LIBRARIES(cmXMLRPC ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_CURL_LIBRARIES})
IF(HAVE_PTHREADS)
TARGET_LINK_LIBRARIES(cmXMLRPC ${CMAKE_THREAD_LIBS_INIT})
ENDIF(HAVE_PTHREADS)
ADD_EXECUTABLE(xrtest synch_client.c)
TARGET_LINK_LIBRARIES(xrtest cmXMLRPC ${CMAKE_DL_LIBS})
# comment out test since it doesn pass and Andy doesn;t seem to be fixing it,
# for now assume that XMLRPC is not production quality code - Ken
# ADD_TEST(Test-XMLRPC ${EXECUTABLE_OUTPUT_PATH}/xrtest)
// Copyright (C) 2001 by Eric Kidd. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. The name of the author may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
#include "XmlRpcCpp.h"
//=========================================================================
// XmlRpcFault Methods
//=========================================================================
XmlRpcFault::XmlRpcFault (const XmlRpcFault &fault) {
xmlrpc_env_init(&mFault);
xmlrpc_env_set_fault(&mFault,
fault.mFault.fault_code,
fault.mFault.fault_string);
}
XmlRpcFault::XmlRpcFault (const int faultCode, const string faultString) {
xmlrpc_env_init(&mFault);
xmlrpc_env_set_fault(&mFault, faultCode,
const_cast<char*>(faultString.c_str()));
}
XmlRpcFault::XmlRpcFault (const xmlrpc_env *env) {
if (!env->fault_string)
throw XmlRpcFault(XMLRPC_INTERNAL_ERROR,
"Tried to create empty fault");
xmlrpc_env_init(&mFault);
xmlrpc_env_set_fault(&mFault, env->fault_code,
const_cast<char*>(env->fault_string));
}
XmlRpcFault::~XmlRpcFault (void) {
xmlrpc_env_clean(&mFault);
}
string XmlRpcFault::getFaultString (void) const {
XMLRPC_ASSERT(mFault.fault_occurred);
return string(mFault.fault_string);
}
//=========================================================================
// XmlRpcEnv Methods
//=========================================================================
XmlRpcEnv::XmlRpcEnv (const XmlRpcEnv &env) {
xmlrpc_env_init(&mEnv);
if (env.hasFaultOccurred())
xmlrpc_env_set_fault(&mEnv,
env.mEnv.fault_code,
env.mEnv.fault_string);
}
XmlRpcFault XmlRpcEnv::getFault (void) const {
return XmlRpcFault(&mEnv);
}
void XmlRpcEnv::throwMe (void) const {
throw XmlRpcFault(&mEnv);
}
//=========================================================================
// XmlRpcValue Methods
//=========================================================================
// If the user doesn't tell us what kind of value to create, use
// a false boolean value as the default.
XmlRpcValue::XmlRpcValue (void) {
XmlRpcEnv env;
mValue = xmlrpc_build_value(env, "b", (xmlrpc_bool) 0);
env.throwIfFaultOccurred();
}
XmlRpcValue XmlRpcValue::makeInt (const XmlRpcValue::int32 i) {
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_build_value(env, "i", i);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeBool (const bool b) {
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_build_value(env, "b", (xmlrpc_bool) b);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeDouble (const double d) {
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_build_value(env, "d", d);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeDateTime (const string& dateTime) {
XmlRpcEnv env;
xmlrpc_value *value;
const char *data = dateTime.c_str(); // Make sure we're not using wchar_t.
value = xmlrpc_build_value(env, "8", data);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeString (const string& str) {
XmlRpcEnv env;
const char *data = str.data(); // Make sure we're not using wchar_t.
size_t size = str.size();
xmlrpc_value *value = xmlrpc_build_value(env, "s#", data, size);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeString (const char *const str) {
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_build_value(env, "s", str);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeString (const char *const str, size_t len) {
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_build_value(env, "s#", str, len);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeArray (void) {
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_build_value(env, "()");
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeStruct (void) {
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_struct_new(env);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue XmlRpcValue::makeBase64 (const unsigned char *const data,
size_t len)
{
XmlRpcEnv env;
xmlrpc_value *value = xmlrpc_build_value(env, "6", data, len);
env.throwIfFaultOccurred();
return XmlRpcValue(value, CONSUME_REFERENCE);
}
XmlRpcValue::int32 XmlRpcValue::getInt (void) const {
XmlRpcEnv env;
XmlRpcValue::int32 result;
xmlrpc_parse_value(env, mValue, "i", &result);
env.throwIfFaultOccurred();
return result;
}
bool XmlRpcValue::getBool (void) const {
XmlRpcEnv env;
xmlrpc_bool result;
xmlrpc_parse_value(env, mValue, "b", &result);
env.throwIfFaultOccurred();
return result;
}
double XmlRpcValue::getDouble (void) const {
XmlRpcEnv env;
double result;
xmlrpc_parse_value(env, mValue, "d", &result);
env.throwIfFaultOccurred();
return result;
}
string XmlRpcValue::getRawDateTime (void) const {
XmlRpcEnv env;
char *result;
xmlrpc_parse_value(env, mValue, "8", &result);
env.throwIfFaultOccurred();
return string(result);
}
string XmlRpcValue::getString (void) const {
XmlRpcEnv env;
char *result;
size_t result_len;
xmlrpc_parse_value(env, mValue, "s#", &result, &result_len);
env.throwIfFaultOccurred();
return string(result, result_len);
}
XmlRpcValue XmlRpcValue::getArray (void) const {
XmlRpcEnv env;
xmlrpc_value *result;
xmlrpc_parse_value(env, mValue, "A", &result);
env.throwIfFaultOccurred();
return XmlRpcValue(result);
}
XmlRpcValue XmlRpcValue::getStruct (void) const {
XmlRpcEnv env;
xmlrpc_value *result;
xmlrpc_parse_value(env, mValue, "S", &result);
env.throwIfFaultOccurred();
return XmlRpcValue(result);
}
void XmlRpcValue::getBase64 (const unsigned char *& out_data,
size_t& out_len) const
{
XmlRpcEnv env;
xmlrpc_parse_value(env, mValue, "6", &out_data, &out_len);
env.throwIfFaultOccurred();
}
size_t XmlRpcValue::arraySize (void) const {
XmlRpcEnv env;
size_t result = xmlrpc_array_size(env, mValue);
env.throwIfFaultOccurred();
return result;
}
void XmlRpcValue::arrayAppendItem (const XmlRpcValue& value) {
XmlRpcEnv env;
xmlrpc_array_append_item(env, mValue, value.borrowReference());
env.throwIfFaultOccurred();
}
XmlRpcValue XmlRpcValue::arrayGetItem (int index) const {
XmlRpcEnv env;
xmlrpc_value *result = xmlrpc_array_get_item(env, mValue, index);
env.throwIfFaultOccurred();
return XmlRpcValue(result);
}
size_t XmlRpcValue::structSize (void) const {
XmlRpcEnv env;
size_t result = xmlrpc_struct_size(env, mValue);
env.throwIfFaultOccurred();
return result;
}
bool XmlRpcValue::structHasKey (const string& key) const {
XmlRpcEnv env;
const char *keystr = key.data();
size_t keylen = key.size();
bool result = xmlrpc_struct_has_key_n(env, mValue,
const_cast<char*>(keystr), keylen);
env.throwIfFaultOccurred();
return result;
}
XmlRpcValue XmlRpcValue::structGetValue (const string& key) const {
XmlRpcEnv env;
const char *keystr = key.data();
size_t keylen = key.size();
xmlrpc_value *result =
xmlrpc_struct_get_value_n(env, mValue,
const_cast<char*>(keystr), keylen);
env.throwIfFaultOccurred();
return XmlRpcValue(result);
}
void XmlRpcValue::structSetValue (const string& key, const XmlRpcValue& value)
{
XmlRpcEnv env;
const char *keystr = key.data();
size_t keylen = key.size();
xmlrpc_struct_set_value_n(env, mValue, (char*) keystr, keylen,
value.borrowReference());
env.throwIfFaultOccurred();
}
void XmlRpcValue::structGetKeyAndValue (const int index,
string& out_key,
XmlRpcValue& out_value) const
{
XmlRpcEnv env;
xmlrpc_value *key, *value;
xmlrpc_struct_get_key_and_value(env, mValue, index, &key, &value);
env.throwIfFaultOccurred();
out_key = XmlRpcValue(key).getString();
out_value = XmlRpcValue(value);
}
XmlRpcGenSrv& XmlRpcGenSrv::addMethod (const string& name,
xmlrpc_method method,
void *data)
{
XmlRpcEnv env;
xmlrpc_registry_add_method (env, mRegistry, NULL,
name.c_str (),
method, data);
env.throwIfFaultOccurred ();
return (*this);
}
XmlRpcGenSrv& XmlRpcGenSrv::addMethod (const string& name,
xmlrpc_method method,
void* data,
const string& signature,
const string& help)
{
XmlRpcEnv env;
xmlrpc_registry_add_method_w_doc (env, mRegistry, NULL,
name.c_str (),
method, data,
signature.c_str (),
help.c_str ());
env.throwIfFaultOccurred ();
return (*this);
}
xmlrpc_mem_block* XmlRpcGenSrv::alloc (XmlRpcEnv& env, const string& body) const
{
xmlrpc_mem_block* result = NULL;
char* contents;
result = xmlrpc_mem_block_new (env, body.length ());
env.throwIfFaultOccurred ();
contents = XMLRPC_TYPED_MEM_BLOCK_CONTENTS(char, result);
memcpy (contents, body.c_str (), body.length ());
return result;
}
string XmlRpcGenSrv::handle (const string& body) const
{
XmlRpcEnv env;
string result;
xmlrpc_mem_block* input = NULL, * output = NULL;
char* input_data, * output_data;
size_t input_size, output_size;
if (body.length () > xmlrpc_limit_get (XMLRPC_XML_SIZE_LIMIT_ID))
throw XmlRpcFault (XMLRPC_LIMIT_EXCEEDED_ERROR, "XML-RPC request too large");
input = alloc (env, body);
input_data = XMLRPC_TYPED_MEM_BLOCK_CONTENTS(char, input);
input_size = XMLRPC_TYPED_MEM_BLOCK_SIZE(char, input);
output = xmlrpc_registry_process_call (env, mRegistry, NULL,
input_data, input_size);
if (output)
{
output_data = XMLRPC_TYPED_MEM_BLOCK_CONTENTS(char, output);
output_size = XMLRPC_TYPED_MEM_BLOCK_SIZE(char, output);
result.assign (output_data, output_size);
xmlrpc_mem_block_free (output);
}
xmlrpc_mem_block_free (input);
if (!result.length ())
throw XmlRpcFault (env);
return result;
}
// -*- C++ -*- <-- an Emacs control
// Copyright information is at the bottom of the file.
//=========================================================================
// XML-RPC C++ API
//=========================================================================
#ifndef _XMLRPCCPP_H_
#define _XMLRPCCPP_H_ 1
// The C++ standard says we should either include <string.h> (which gets
// us the wrong header), or say 'using namespace std;' (which doesn't
// work with our version of g++). So this header name is technically wrong.
// Tell me what your compiler does; I can provide some autoconf magic to the
// Right Thing on most platforms.
//
// 2004.12.22 Bryan: This looks like a problem with whatever g++ he was
// using, so if anything, the special case should be for that. In any case,
// we've already added using namespace std to other files, without knowing
// there was an issue, so I'm just going to do the "using namespace"
// unconditionally and see who complains. If there are complaints, we can
// improve the documentation here.
//
// Formerly, the "using namespace std" was under
// "#if defined(__GNUC__) && (__GNUC__ >= 3)".
#include <string>
using namespace std;
#include <xmlrpc_config.h>
#include <xmlrpc.h>
#include <xmlrpc_client.h>
#include <xmlrpc_server.h>