int 
main(int           const argc, 
     const char ** const argv) {

    struct xmlrpc_method_info3 const methodInfo = {
        .methodName     = "sample.add",
        .methodFunction = &sample_add,
        .serverInfo = NULL
    };
    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 "
                "on which to listen for XML-RPC calls.  "
                "You specified %d.\n",  argc-1);
        exit(1);
    }

    AbyssInit(&error);
    
    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);

    xmlrpc_registry_add_method3(&env, registryP, &methodInfo);

    xmlrpc_registry_set_shutdown(registryP,
                                 &requestShutdown, &terminationRequested);

    ServerCreate(&abyssServer, "XmlRpcServer", atoi(argv[1]), NULL, NULL);
    
    xmlrpc_server_abyss_set_handlers2(&abyssServer, "/RPC2", registryP);

    ServerInit(&abyssServer);

    setupSignalHandlers();

    terminationRequested = 0;

    while (!terminationRequested) {
        printf("Waiting for next RPC...\n");

        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;
}
Beispiel #2
0
int xmlrpcsrv_init() {


	// Init the XMLRPC-C library
	
	xmlrpc_env env;
	xmlrpc_env_init(&env);
	xmlrpcsrv_registry = xmlrpc_registry_new(&env);

	if (env.fault_occurred) {
		xmlrpc_env_clean(&env);
		return POM_ERR;
	}

	xmlrpc_env_clean(&env);

	xmlrpccmd_register_all();

	xmlrpc_registry_set_shutdown(xmlrpcsrv_registry, xmlrpcsrv_shutdown, NULL);

	return POM_OK;
}
static void *
xr_rpcListener (Server *svr)
{
    struct xmlrpc_method_info3 const methodInfo[] = {
       /* .methodName   	.methodFunction  	*/ 
	{ "svrping", 		&test_ping,		},
	/*
	{ "sys.abort", 		&xr_requestAbort,	},
	{ "sys.shutdown", 	&xr_requestShutdown,	}
	*/
    };
    register int i = 0;
    TServer abyssServer;
    xmlrpc_registry * registryP;
    xmlrpc_env env;
    const char * error;

    extern void xr_serverRunOnce ();
    extern int  xr_requestAbort ();


    AbyssInit (&error);				/* initialize		*/
    xmlrpc_env_init (&env);
    registryP = xmlrpc_registry_new (&env);


    if (SRVR_DEBUG)
	fprintf (stderr, "single_run_server rpcListener ....\n");

    /*  Setup a test ping method and install the special shutdown handlers.
     */
    for (i=0; i < 1; i++)
    	xmlrpc_registry_add_method3 (&env, registryP, &methodInfo[i]);

    /*  Set default shutdown method.
     */
    xmlrpc_registry_set_shutdown (registryP, &xr_requestShutdown, &svr_done);
    xr_addServerMethod ("sys.abort", xr_requestAbort, NULL);


    /*  Set the default method we'll use to dispatch calls.
     */
    svr->serverparm.enable_shutdown = (xmlrpc_bool) 1;
    xmlrpc_registry_set_default_method (&svr->env, 
        (svr->serverparm.registryP = svr->registry = registryP), 
        (xmlrpc_default_method) &xr_defaultMethod, svr);


    /*  Create the server instance.
     */
    ServerCreate (&abyssServer, "XmlRpcServer", 
	svr->serverparm.port_number, NULL, NULL);

    xmlrpc_server_abyss_set_handlers2 (&abyssServer, "/RPC2",
	svr->serverparm.registryP);

    ServerInit (&abyssServer);

#ifdef XR_SIGPIPE_IGN
    xr_setupSigpipeHandlers ();
#endif


    while (! svr_done ) {
        /*  This waits for the next connection, accepts it, reads the
         *  HTTP POST request, executes the indicated RPC, and closes
         *  the connection.
        ServerRunOnce (&abyssServer);
         */
 	//	ServerRunOnce(&abyssServer);
       (void) xr_serverRunOnce (&abyssServer);
    }

    ServerFree (&abyssServer);			/* shut down		*/
    AbyssTerm ();

    return ((void *) ERR);
}
int
xr_addServerMethod (char *name, void *method, void *userData)
{
    char *arg_signature, *ret_signature;


    if (DEBUG)
	fprintf (stderr, "addMethod: '%s'\n", name);

    /* Create a method in the server.  We also use this to let the 
    ** user set the default and shutdown methods.
    */
    if (strcmp (name, "default") == 0) {

	/* Set the default method.
	*/
	xmlrpc_registry_set_default_method (&svr->env, svr->registry, 
	    (xmlrpc_default_method) &method, NULL);

    } else if (strcmp (name, "shutdown") == 0) {
	int shutdown;

        xmlrpc_registry_set_shutdown (svr->registry, method, &shutdown);

    } else {

	/*  All we really do at this stage is register the method with
	**  the interface registry.  When a method is called, the default
	**  method is responsible for parsing the arguments and invoking
	**  the client code using the standard prototype.
	*/ 
	MethodP	m = calloc (1, sizeof (Method));

	if (svr->method_head == (MethodP) NULL) {
	    /* Initialize the list of methods;
	    */
	    svr->method_head = svr->method_tail = m;

	} else {
	    /* Add the mthod to the tail of the list.
	    */
	    svr->method_tail->next = svr->method_tail = m;
	}

	/* Save information about the method.  We force the argument 
	** signature to always be an array to simply the process of getting
	** the parameters in the method.  On return, we use the signature
	** provided by the user and rely on the implementation to extract
	** the results appropriately.
	**
	*/
	arg_signature = ret_signature = "not_currently_used";
	strcpy (m->name, name);
	strcpy (m->ret_signature, ret_signature);
        if (arg_signature[0] != '(') {
            sprintf (m->arg_signature, "(%s)", arg_signature);
        } else 
            strcpy (m->arg_signature, arg_signature);


	m->methodFunc = method;
	m->serverInfo = userData;

	svr->num_methods++;
    }

    return (OK);
}