Below is a very simple example on how to access SKYRiX services in ANSI-C. C is
not a simple language for processing XML-RPC ...
Download
test.c
Source
// Environment:
// export CLIENT_CFLAGS=`xmlrpc-c-config libwww-client --cflags`
// export CLIENT_LIBS=`xmlrpc-c-config libwww-client --libs`
// Compiling:
// gcc $CLIENT_CFLAGS -o myclient client.c $CLIENT_LIBS
#include <stdio.h>
#include <xmlrpc.h>
#include <xmlrpc_client.h>
#define NAME "OGo C Appointment Client"
#define VERSION "0.42"
#define URL "http://localhost:20000/RPC2"
#define USER "root"
#define PASSWORD "yourpasshere" // password
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 argc, char** argv) {
xmlrpc_env env;
xmlrpc_server_info *server;
xmlrpc_value *appointments, *appointment;
size_t size, i;
char *user, *password;
char *startDate, *endDate, *title;
int first;
/* Start up our XML-RPC client library. */
xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
xmlrpc_env_init(&env);
/* Make a new object to represent our XML-RPC server. */
server = xmlrpc_server_info_new(&env, URL);
die_if_fault_occurred(&env);
/* Set up our authentication information. */
xmlrpc_server_info_set_basic_auth(&env, server, USER, PASSWORD);
die_if_fault_occurred(&env);
/* Ask the server to show us the appointments from August 2002 */
appointments = xmlrpc_client_call_server(&env, server,
"appointment.fetch",
"({s:{s:8,s:8}})",
"qualifier",
"startDate","20020801T00:00:00",
"endDate","20020831T23:59:59"
);
die_if_fault_occurred(&env);
/* Dispose of our server object. */
xmlrpc_server_info_free(server);
/* Loop over the appointments */
size = xmlrpc_array_size(&env, appointments);
die_if_fault_occurred(&env);
first = 1;
for (i = 0; i < size; i++) {
/* get the appointment from the result array */
appointment = xmlrpc_array_get_item(&env, appointments, i);
die_if_fault_occurred(&env);
/* parse the appointment */
xmlrpc_parse_value(&env, appointment, "{s:8,s:8,s:s,*}",
"startDate", &startDate,
"endDate", &endDate,
"title", &title);
die_if_fault_occurred(&env);
if (first) {
printf("Appointment List\n");
printf("================\n\n");
first = 0;
}
else
printf("\n");
printf("Title: %s\nStart: %s End: %s\n", title, startDate, endDate);
}
/* Dispose of our result value. */
xmlrpc_DECREF(appointments);
/* Shut down our XML-RPC client library. */
xmlrpc_env_clean(&env);
xmlrpc_client_cleanup();
return 0;
}
Author
Björn Stierand