freeswitch/libs/xmlrpc-c/examples/gen_sample_add_xml.c
Michael Jerris 3abb7730b2 add xmlrpc-c 1.03.14 to in tree libs
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3772 d0543943-73ff-0310-b7d9-9358b9ac24b2
2006-12-21 03:57:49 +00:00

74 lines
1.7 KiB
C

/* This program generates on Standard Output the XML for an XML-RPC
call suitable for the xmlrpc_sample_add_server program.
This is the same XML that the xmlrpc_sample_add_client program sends.
Use this either as an example of how to use the Xmlrpc-c XML-generating
functions or to generate XML that you can use to test an XML-RPC
server.
*/
#include <stdlib.h>
#include <stdio.h>
#include <xmlrpc-c/base.h>
#include "config.h"
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) {
char * const methodName = "sample.add";
xmlrpc_env env;
xmlrpc_value * params;
xmlrpc_mem_block * xmlmemblockP;
if (argc-1 > 0) {
fprintf(stderr, "This program has no arguments\n");
exit(1);
}
/* Initialize our error-handling environment. */
xmlrpc_env_init(&env);
params = xmlrpc_build_value(&env, "(ii)",
(xmlrpc_int32) 5, (xmlrpc_int32) 7);
die_if_fault_occurred(&env);
xmlmemblockP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
xmlrpc_serialize_call(&env, xmlmemblockP, methodName, params);
die_if_fault_occurred(&env);
fwrite(XMLRPC_MEMBLOCK_CONTENTS(char, xmlmemblockP),
sizeof(char),
XMLRPC_MEMBLOCK_SIZE(char, xmlmemblockP),
stdout);
XMLRPC_MEMBLOCK_FREE(char, xmlmemblockP);
/* Dispose of our parameter array. */
xmlrpc_DECREF(params);
/* Clean up our error-handling environment. */
xmlrpc_env_clean(&env);
return 0;
}