ENH: Add example

This commit is contained in:
Andy Cedilnik 2005-02-28 16:26:20 -05:00
parent a5501b11f6
commit 638eb8e68e
5 changed files with 81 additions and 2 deletions

View File

@ -31,7 +31,11 @@ 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_IS_ARRAY_DEFINE)
VA_LIST_ISNOT_ARRAY_DEFINE)
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)
@ -42,6 +46,8 @@ ENDIF(ATTR_UNUSED_VAR)
SET(HAVE_LIBWWW_SSL)
SET(DIRECTORY_SEPARATOR "/")
FIND_PACKAGE(Threads)
INCLUDE_DIRECTORIES(
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
@ -84,4 +90,7 @@ IF(WIN32)
ENDIF(WIN32)
ADD_LIBRARY(cmXMLRPC ${xmlrpc_SRCS})
TARGET_LINK_LIBRARIES(cmXMLRPC ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_CURL_LIBRARIES})
TARGET_LINK_LIBRARIES(cmXMLRPC ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
ADD_EXECUTABLE(xrtest synch_client.c)
TARGET_LINK_LIBRARIES(xrtest cmXMLRPC)

View File

@ -0,0 +1,62 @@
/* A simple synchronous XML-RPC client written in C. */
#include <stdio.h>
#include <xmlrpc.h>
#include <xmlrpc_client.h>
#define NAME "XML-RPC C Test Client"
#define VERSION "0.1"
static void die_if_fault_occurred (xmlrpc_env *env)
{
if (env->fault_occurred) {
fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
env->fault_string, env->fault_code);
exit(1);
}
}
int
main(int const argc,
const char ** const argv ATTR_UNUSED) {
xmlrpc_env env;
xmlrpc_value *result;
char *state_name;
if (argc-1 > 0) {
fprintf(stderr, "No arguments");
exit(0);
}
/* Start up our XML-RPC client library. */
xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
/* Initialize our error-handling environment. */
xmlrpc_env_init(&env);
/* Call the famous server at UserLand. */
result = xmlrpc_client_call(&env, "http://betty.userland.com/RPC2",
"examples.getStateName",
"(i)", (xmlrpc_int32) 41);
die_if_fault_occurred(&env);
/* Get our state name and print it out. */
xmlrpc_parse_value(&env, result, "s", &state_name);
die_if_fault_occurred(&env);
printf("%s\n", state_name);
/* Dispose of our result value. */
xmlrpc_DECREF(result);
/* Clean up our error-handling environment. */
xmlrpc_env_clean(&env);
/* Shutdown our XML-RPC client library. */
xmlrpc_client_cleanup();
return 0;
}

View File

@ -29,6 +29,7 @@
#include <stddef.h>
#include <stdarg.h>
#include <xmlrpc_config.h>
#ifdef HAVE_UNICODE_WCHAR
#include <wchar.h>

View File

@ -142,6 +142,8 @@ setupTransport(xmlrpc_env * const envP,
#if MUST_BUILD_CURL_CLIENT
else if (strcmp(transportName, "curl") == 0)
clientTransportOps = xmlrpc_curl_transport_ops;
else if (strcmp(transportName, "libcurl") == 0)
clientTransportOps = xmlrpc_curl_transport_ops;
#endif
#if MUST_BUILD_LIBWWW_CLIENT
else if (strcmp(transportName, "libwww") == 0)

View File

@ -16,6 +16,9 @@
*/
#include "xmlrpc_amconfig.h"
#ifndef __xmlrpc_config_h__
#define __xmlrpc_config_h__
#define VA_LIST_IS_ARRAY @VA_LIST_IS_ARRAY_DEFINE@
@ -75,3 +78,5 @@ __inline BOOL setenv(const char* name, const char* value, int i)
return (SetEnvironmentVariable(name, value) != 0) ? TRUE : FALSE;
}
#endif
#endif