mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 01:49:05 +00:00
merged new xmlrpc-c revision 1472 from https://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/trunk
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8545 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <xmlrpc-c/base.h>
|
||||
#include <xmlrpc-c/abyss.h>
|
||||
#include <xmlrpc-c/server.h>
|
||||
@@ -29,12 +32,33 @@ setupSignalHandlers(void) {
|
||||
obviously don't want to die just because a client didn't complete
|
||||
an RPC, so we ignore SIGPIPE.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
struct sigaction mysigaction;
|
||||
|
||||
sigemptyset(&mysigaction.sa_mask);
|
||||
mysigaction.sa_flags = 0;
|
||||
mysigaction.sa_handler = SIG_IGN;
|
||||
sigaction(SIGPIPE, &mysigaction, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
printPeerIpAddr(TSession * const abyssSessionP) {
|
||||
|
||||
struct abyss_unix_chaninfo * channelInfoP;
|
||||
struct sockaddr_in * sockAddrInP;
|
||||
unsigned char * ipAddr; /* 4 byte array */
|
||||
|
||||
SessionGetChannelInfo(abyssSessionP, (void*)&channelInfoP);
|
||||
|
||||
sockAddrInP = (struct sockaddr_in *) &channelInfoP->peerAddr;
|
||||
|
||||
ipAddr = (unsigned char *)&sockAddrInP->sin_addr.s_addr;
|
||||
|
||||
printf("RPC is from IP address %u.%u.%u.%u\n",
|
||||
ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +66,13 @@ setupSignalHandlers(void) {
|
||||
static xmlrpc_value *
|
||||
sample_add(xmlrpc_env * const envP,
|
||||
xmlrpc_value * const paramArrayP,
|
||||
void * const userData ATTR_UNUSED) {
|
||||
void * const serverInfo ATTR_UNUSED,
|
||||
void * const channelInfo) {
|
||||
|
||||
xmlrpc_int x, y, z;
|
||||
|
||||
printPeerIpAddr(channelInfo);
|
||||
|
||||
/* Parse our argument array. */
|
||||
xmlrpc_decompose_value(envP, paramArrayP, "(ii)", &x, &y);
|
||||
if (envP->fault_occurred)
|
||||
@@ -60,6 +87,32 @@ sample_add(xmlrpc_env * const envP,
|
||||
|
||||
|
||||
|
||||
static xmlrpc_server_shutdown_fn requestShutdown;
|
||||
|
||||
static void
|
||||
requestShutdown(xmlrpc_env * const faultP,
|
||||
void * const context,
|
||||
const char * const comment,
|
||||
void * const callInfo) {
|
||||
|
||||
/* You make this run by executing the system method
|
||||
'system.shutdown'. This function is registered in the method
|
||||
registry as the thing to call for that.
|
||||
*/
|
||||
int * const terminationRequestedP = context;
|
||||
TSession * const abyssSessionP = callInfo;
|
||||
|
||||
xmlrpc_env_init(faultP);
|
||||
|
||||
fprintf(stderr, "Termination requested: %s\n", comment);
|
||||
|
||||
printPeerIpAddr(abyssSessionP);
|
||||
|
||||
*terminationRequestedP = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
main(int const argc,
|
||||
const char ** const argv) {
|
||||
@@ -67,6 +120,8 @@ main(int const argc,
|
||||
TServer abyssServer;
|
||||
xmlrpc_registry * registryP;
|
||||
xmlrpc_env env;
|
||||
int terminationRequested; /* A boolean value */
|
||||
const char * error;
|
||||
|
||||
if (argc-1 != 1) {
|
||||
fprintf(stderr, "You must specify 1 argument: The TCP port number "
|
||||
@@ -74,34 +129,42 @@ main(int const argc,
|
||||
"You specified %d.\n", argc-1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
AbyssInit(&error);
|
||||
|
||||
xmlrpc_env_init(&env);
|
||||
|
||||
registryP = xmlrpc_registry_new(&env);
|
||||
|
||||
xmlrpc_registry_add_method(
|
||||
&env, registryP, NULL, "sample.add", &sample_add, NULL);
|
||||
xmlrpc_registry_add_method2(
|
||||
&env, registryP, "sample.add", &sample_add, NULL, NULL, NULL);
|
||||
|
||||
MIMETypeInit();
|
||||
xmlrpc_registry_set_shutdown(registryP,
|
||||
&requestShutdown, &terminationRequested);
|
||||
|
||||
ServerCreate(&abyssServer, "XmlRpcServer", atoi(argv[1]),
|
||||
NULL, NULL);
|
||||
ServerCreate(&abyssServer, "XmlRpcServer", atoi(argv[1]), NULL, NULL);
|
||||
|
||||
xmlrpc_server_abyss_set_handlers(&abyssServer, registryP);
|
||||
xmlrpc_server_abyss_set_handlers2(&abyssServer, "/RPC2", registryP);
|
||||
|
||||
ServerInit(&abyssServer);
|
||||
|
||||
setupSignalHandlers();
|
||||
|
||||
while (1) {
|
||||
terminationRequested = 0;
|
||||
|
||||
while (!terminationRequested) {
|
||||
printf("Waiting for next RPC...\n");
|
||||
|
||||
ServerRunOnce2(&abyssServer, ABYSS_FOREGROUND);
|
||||
ServerRunOnce(&abyssServer);
|
||||
/* This waits for the next connection, accepts it, reads the
|
||||
HTTP POST request, executes the indicated RPC, and closes
|
||||
the connection.
|
||||
*/
|
||||
}
|
||||
|
||||
ServerFree(&abyssServer);
|
||||
|
||||
AbyssTerm();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user