static void
testSetHandlers(TServer * const abyssServerP) {

    xmlrpc_env env;
    xmlrpc_registry * registryP;

    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);
    TEST_NO_FAULT(&env);
    TEST(registryP != NULL);

    xmlrpc_server_abyss_set_handler(&env, abyssServerP, "/RPC3", registryP);
    TEST_NO_FAULT(&env);

    xmlrpc_server_abyss_set_handlers2(abyssServerP, "/RPC4", registryP);

    xmlrpc_registry_free(registryP);

    {
        xmlrpc_registry * registryP;
        registryP = xmlrpc_registry_new(&env);
        xmlrpc_server_abyss_set_handlers(abyssServerP, registryP);
        xmlrpc_registry_free(registryP);
    }
    xmlrpc_env_clean(&env);
}
Example #2
0
void
rcd_rpc_init(void)
{
    xmlrpc_env env;

    rc_debug (RC_DEBUG_LEVEL_MESSAGE, "Initializing RPC system");

    xmlrpc_env_init(&env);
    registry = xmlrpc_registry_new(&env);

    if (env.fault_occurred) {
        rc_debug (RC_DEBUG_LEVEL_ERROR, 
                  "Unable to initialize the XML-RPC server registry: %s (%d)",
                  env.fault_string, env.fault_code);
        exit (-1);
    }

    rcd_shutdown_add_handler ((RCDShutdownFn) xmlrpc_registry_free, registry);

    /* The xmlrpc-c limit for XML size is 512k.  Bump it up to 10 megs */
    xmlrpc_limit_set (XMLRPC_XML_SIZE_LIMIT_ID, 10*1024*1024);

    /* Create a hash which will be used for registering RPC methods */
    method_info_hash = g_hash_table_new (g_str_hash, g_str_equal);

    /* Register the basic RPC calls (ping, querying for modules, etc.) */
    rcd_rpc_system_register_methods();

    /* Register a shutdown function for the soup server (if it's started) */
    rcd_shutdown_add_handler (soup_shutdown_cb, NULL);
} /* rcd_rpc_init */
inline XmlRpcGenSrv::XmlRpcGenSrv (int) {

    XmlRpcEnv env;

    mRegistry = xmlrpc_registry_new (env);
    env.throwIfFaultOccurred();        
}
void launch(int port, struct ExperimentServer handlers){
    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;

    weblab_handlers.is_up_and_running = handlers.is_up_and_running;
    weblab_handlers.start_experiment  = handlers.start_experiment;
    weblab_handlers.send_command      = handlers.send_command;
    weblab_handlers.send_file         = handlers.send_file;
    weblab_handlers.dispose           = handlers.dispose;

    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);

    xmlrpc_registry_add_method( &env, registryP, NULL, "Util.test_me", &weblab_xmlrpc_test_me, NULL);
    xmlrpc_registry_add_method( &env, registryP, NULL, "Util.is_up_and_running", &weblab_xmlrpc_is_up_and_running, NULL);
    xmlrpc_registry_add_method( &env, registryP, NULL, "Util.start_experiment", &weblab_xmlrpc_start_experiment, NULL);
    xmlrpc_registry_add_method( &env, registryP, NULL, "Util.send_command", &weblab_xmlrpc_send_command_to_device, NULL);
    xmlrpc_registry_add_method( &env, registryP, NULL, "Util.send_file", &weblab_xmlrpc_send_file_to_device, NULL);
    xmlrpc_registry_add_method( &env, registryP, NULL, "Util.dispose", &weblab_xmlrpc_dispose, NULL);

    serverparm.config_file_name = NULL;
    serverparm.registryP        = registryP;
    serverparm.port_number      = port;
    serverparm.log_file_name    = "xmlrpc_log";

    printf("Running XML-RPC server on port %i...\n", port);

    xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));
}
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;
}
static void
testObject(void) {

    xmlrpc_env env;
    xmlrpc_server_abyss_parms parms;
    xmlrpc_server_abyss_t * serverP;
    xmlrpc_registry * registryP;
    xmlrpc_server_abyss_sig * oldHandlersP;

    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);
    TEST_NO_FAULT(&env);

    parms.config_file_name = NULL;
    parms.registryP = registryP;

    serverP = NULL;

    xmlrpc_server_abyss_create(&env, &parms, XMLRPC_APSIZE(registryP),
                               &serverP);

    TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);  /* Global init not done */

    xmlrpc_server_abyss_global_init(&env);
    TEST_NO_FAULT(&env);

    xmlrpc_server_abyss_create(&env, &parms, XMLRPC_APSIZE(registryP),
                               &serverP);

    TEST_NO_FAULT(&env);
    TEST(serverP != NULL);

    xmlrpc_server_abyss_terminate(&env, serverP);
    TEST_NO_FAULT(&env);

    xmlrpc_server_abyss_reset_terminate(&env, serverP);
    TEST_NO_FAULT(&env);

    xmlrpc_server_abyss_setup_sig(&env, serverP, &oldHandlersP);
    TEST_NO_FAULT(&env);

    xmlrpc_server_abyss_use_sigchld(serverP);
    
    xmlrpc_server_abyss_restore_sig(oldHandlersP);
    TEST_NO_FAULT(&env);

    xmlrpc_server_abyss_destroy(serverP);
    
    xmlrpc_registry_free(registryP);

    xmlrpc_server_abyss_global_term();

    xmlrpc_server_abyss_setup_sig(&env, serverP, &oldHandlersP);
    TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR); /* Not globally initialized */

    xmlrpc_env_clean(&env);
}
/**************************************
* XmlHandler
*	Constructor
*************************************/
XmlHandler::XmlHandler()
{
	xmlrpc_env env;

	//Build the enviroment
	xmlrpc_env_init(&env);

	//Creamos el registro
	registry = xmlrpc_registry_new(&env);
}
int
xr_createServer (char *path, int port, char *logfile)
{
	
    if (svr) {
	perror ("createServer:  Server already allocated");
	return (ERR);
    }
    if (! (svr = (ServerP) calloc ((size_t) 1, sizeof (Server)))) {
	perror ("createServer:  Cannot allocate server");
	return (ERR);
    }


    /* Initialize the structure.
    */
    strcpy (svr->path, (path ? path : ""));
    strcpy (svr->logfile, (logfile ? logfile : ""));
    svr->port = port;


    /* Initialize XML-RPC interface.
    */
    xmlrpc_env_init (&svr->env);             
    bzero (svr->url, SZ_PATH);
    sprintf (svr->url, "http://localhost:%d/RPC2", port);


    /* Create the service registry and initialize server params.
    */
    svr->registry = xmlrpc_registry_new (&svr->env);


    /* Set the default shutdown method.
    xmlrpc_registry_set_shutdown (svr->registry, &xr_requestShutdown,
	&shutdown);
    */


    /* In the "modern" form of the Abyss API, we supply parameters in memory
    ** like a normal API.  We select the modern form by setting
    ** config_file_name to NULL: 
    */
    svr->serverparm.config_file_name 	= NULL;
    svr->serverparm.registryP        	= svr->registry;
    svr->serverparm.port_number      	= svr->port;
    if (svr->logfile[0])
        svr->serverparm.log_file_name	= svr->logfile;

    svr->trace = 0;


    return (OK);
}
int 
main(int           const argc, 
     const char ** const argv) {

    struct xmlrpc_method_info3 const methodInfo = {
        /* .methodName     = */ "sample.add",
        /* .methodFunction = */ &sample_add,
    };
    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;

    if (argc-1 != 1) {
        fprintf(stderr, "You must specify 1 argument:  The TCP port "
                "number on which the server will accept connections "
                "for RPCs (8080 is a common choice).  "
                "You specified %d arguments.\n",  argc-1);
        exit(1);
    }
    
    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);
    if (env.fault_occurred) {
        printf("xmlrpc_registry_new() failed.  %s\n", env.fault_string);
        exit(1);
    }

    xmlrpc_registry_add_method3(&env, registryP, &methodInfo);
    if (env.fault_occurred) {
        printf("xmlrpc_registry_add_method3() failed.  %s\n",
               env.fault_string);
        exit(1);
    }

    serverparm.config_file_name = NULL;   /* Select the modern normal API */
    serverparm.registryP        = registryP;
    serverparm.port_number      = atoi(argv[1]);
    serverparm.log_file_name    = "/tmp/xmlrpc_log";

    printf("Running XML-RPC server...\n");

    xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));
    if (env.fault_occurred) {
        printf("xmlrpc_server_abyss() failed.  %s\n", env.fault_string);
        exit(1);
    }
    /* xmlrpc_server_abyss() never returns unless it fails */

    return 0;
}
Example #10
0
static void run_rpc_server(xmlrpc_env *env, unsigned int port)
{
	xmlrpc_server_abyss_parms serverparm;
	xmlrpc_registry * registryP;
	memset(&serverparm, 0, sizeof(serverparm));

	registryP = xmlrpc_registry_new(env);

	xmlrpc_registry_add_method(env, registryP, NULL, "add_flow_destination", &add_flow_destination, NULL);
	xmlrpc_registry_add_method(env, registryP, NULL, "add_flow_source", &add_flow_source, NULL);
	xmlrpc_registry_add_method(env, registryP, NULL, "start_flows", &start_flows, NULL);
	xmlrpc_registry_add_method(env, registryP, NULL, "get_reports", &method_get_reports, NULL);
	xmlrpc_registry_add_method(env, registryP, NULL, "stop_flow", &method_stop_flow, NULL);
	xmlrpc_registry_add_method(env, registryP, NULL, "get_version", &method_get_version, NULL);
	xmlrpc_registry_add_method(env, registryP, NULL, "get_status", &method_get_status, NULL);

	/* In the modern form of the Abyss API, we supply parameters in memory
	   like a normal API.  We select the modern form by setting
	   config_file_name to NULL:
	*/
	serverparm.config_file_name	= NULL;
	serverparm.registryP		= registryP;
	serverparm.socket_bound		= 1;
	serverparm.log_file_name        = NULL; /*"/tmp/xmlrpc_log";*/

	/* Increase HTTP keep-alive duration. Using defaults the amount of
	 * sockets in TIME_WAIT state would become too high.
	 */
	serverparm.keepalive_timeout = 60;
	serverparm.keepalive_max_conn = 1000;

	/* Disable introspection */
	serverparm.dont_advertise = 1;

	logging_log(LOG_NOTICE, "Running XML-RPC server on port %u", port);
	printf("Running XML-RPC server...\n");

	serverparm.socket_handle = bind_rpc_server(rpc_bind_addr, port);
	xmlrpc_server_abyss(env, &serverparm, XMLRPC_APSIZE(socket_handle));

	if (env->fault_occurred) {
		logging_log(LOG_ALERT, "XML-RPC Fault: %s (%d)\n",
			env->fault_string, env->fault_code);
	}
	/* xmlrpc_server_abyss() never returns */
}
Example #11
0
int 
main(int           const argc, 
     const char ** const argv) {

    struct xmlrpc_method_info3 const methodInfo = {
        /* .methodName     = */ "calculate_modexp",
        /* .methodFunction = */ &calculate_modexp,
    };
    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;
 
    if (argc-1 != 1) {
        fprintf(stderr, "You must specify 1 argument:  The TCP port "
                "number on which the server will accept connections "
                "for RPCs (8080 is a common choice).  "
                "You specified %d arguments.\n",  argc-1);
        exit(1);
    }
    
    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);

    xmlrpc_registry_add_method3(&env, registryP, &methodInfo);

    /* In the modern form of the Abyss API, we supply parameters in memory
       like a normal API.  We select the modern form by setting
       config_file_name to NULL: 
    */
    serverparm.config_file_name = NULL;
    serverparm.registryP        = registryP;
    serverparm.port_number      = atoi(argv[1]);
    serverparm.log_file_name    = "/tmp/xmlrpc_log";

    printf("Running XML-RPC server...\n");

    xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));

    /* xmlrpc_server_abyss() never returns */

    return 0;
}
Example #12
0
/**************************************
* XmlHandler
*	Constructor
*************************************/
XmlHandler::XmlHandler(XmlHandlerCmd *cmd,void *user_data)
{
	xmlrpc_env env;

	//Build the enviroment
	xmlrpc_env_init(&env);

	//Creamos el registro
	registry = xmlrpc_registry_new(&env);

	//Append commands
        while (cmd && cmd->name)
	{
		//Append methods
		AddMethod(cmd->name,cmd->func,user_data);
		//Next
		cmd++;
	}
}
Example #13
0
void init_rpc_server(struct xmlrpc_method_info3 const * methodInfo, int portnum ){
    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_server_abyss_t * serverP;
    xmlrpc_registry * registryP;
    xmlrpc_env env;
    xmlrpc_server_abyss_sig * oldHandlersP;

    xmlrpc_env_init(&env);

    xmlrpc_server_abyss_global_init(&env);
    dieIfFailed((const char*)"xmlrpc_server_abyss_global_init", &env);

    registryP = xmlrpc_registry_new(&env);
    dieIfFailed((const char*)"xmlrpc_registry_new", &env);

    xmlrpc_registry_add_method3(&env, registryP, methodInfo);
    dieIfFailed((const char*)"xmlrpc_registry_add_method3", &env);
    
    serverparm.config_file_name = NULL;
    serverparm.registryP        = registryP;
    serverparm.port_number      = portnum;

    xmlrpc_server_abyss_create(&env, &serverparm, XMLRPC_APSIZE(port_number), &serverP);
    dieIfFailed((const char*)"xmlrpc_server_abyss_create", &env);

    xmlrpc_server_abyss_setup_sig(&env, serverP, &oldHandlersP);
    dieIfFailed((const char*)"xmlrpc_server_abyss_setup_sig", &env);

    setupSigtermHandler(serverP);

    printf("Running XML-RPC server...\n");

    xmlrpc_server_abyss_run_server(&env, serverP);
    dieIfFailed((const char*)"xmlrpc_server_abyss_run_server", &env);

    restoreSigtermHandler();
    xmlrpc_server_abyss_restore_sig(oldHandlersP);
    xmlrpc_server_abyss_destroy(serverP);
    xmlrpc_registry_free(registryP);
    xmlrpc_server_abyss_global_term();
    xmlrpc_env_clean(&env);
}
int __cdecl wmain( int argc, wchar_t * argv[])
{
	xmlrpc_server_httpsys_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;

	xmlrpc_env_init(&env);

	registryP = xmlrpc_registry_new(&env);

    xmlrpc_registry_add_method(
        &env, registryP, NULL, "sample.add", &sample_add, NULL);

    wprintf(L"Starting XML-RPC server...\n");

	//Sets the port number we are listening on
	serverparm.portNum=8080;

	//if this is set, we will use the authorization function
	serverparm.authfn=NULL;
	//serverparm.authfn=&handleAuthorization;

	//set the logging level and log file
	serverparm.logLevel=2;
	serverparm.logFile="C:\\httpsysserverlog.txt";

	//set the use of SSL
	serverparm.useSSL=0;

    serverparm.registryP = registryP;

    xmlrpc_server_httpsys(&env, &serverparm, XMLRPC_HSSIZE(authfn));

	wprintf(L"Stopping XML-RPC server...\n");

	xmlrpc_registry_free(registryP);
	xmlrpc_env_clean(&env);

    return 0;
}
Example #15
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;
}
Example #16
0
//--------------------------------------------------------------------------------------
DWORD WINAPI ServerThread(LPVOID lpParam)
{
    struct xmlrpc_method_info3 const methodInfo = 
    {
        /* .methodName     = */ "vertex_callback",
        /* .methodFunction = */ &vertex_callback,
    };

    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry *registryP;
    xmlrpc_env env;

    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);

    xmlrpc_registry_add_method3(&env, registryP, &methodInfo);

    /* In the modern form of the Abyss API, we supply parameters in memory
       like a normal API.  We select the modern form by setting
       config_file_name to NULL: 
    */
    serverparm.config_file_name = NULL;
    serverparm.registryP = registryP;
    serverparm.port_number = XMLRPC_SERVER_PORT;
    serverparm.log_file_name = "./" LOG_NAME;

    DbgMsg(
        __FILE__, __LINE__, 
        __FUNCTION__"(): Running XML-RPC server at port %d...\n", 
        serverparm.port_number
    );

    xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));

    /* xmlrpc_server_abyss() never returns */ 
    return 0;
}
Example #17
0
int main(int argc, char **argv)
{
	xmlrpc_server_abyss_parms serverparm;
	xmlrpc_registry * registryP;
	xmlrpc_env env;
	int ii;
	int c;
	int dmn = 0;
        char *config_file = NULL;
        
	while ( ( c = getopt_long( argc, argv, short_opts, long_opts, NULL ) ) != -1 )
        {
		switch( c ) {
                        case 'd':
                                dmn = 1;
                                break;
                        case 'c':
                                config_file = strdup( optarg );
                                break;
                        case '?':
                        default:
                                fprintf(stderr, "unknown option\n");
                                fprintf(stderr, "%s", usage_txt);
                                exit(1);
                }
                
        }
        if ( dmn && (0 != daemon( 0, 0 ) )) {
                SYSLOG_FAULT("Failed to daemonize");
                return 1;
	}

	if ( zw_api_init( "/dev/ttyUSB0", &hzr_ctx.zw_ctx ) ) {
		SYSLOG_FAULT("zWave API Init failed");
		return 1;
	}

        sleep(3);
        zw_list_nodes();

        if ( config_file )
        	xmlconfig_load( config_file );
        
	xmlrpc_env_init(&env);
	dieOnFault("init", &env);

	registryP = xmlrpc_registry_new(&env);
	dieOnFault("init_registry", &env);

	for ( ii = 0; ii < ( sizeof( methodInfo ) / sizeof( struct xmlrpc_method_info3 ) ); ii++ )
	{
		xmlrpc_registry_add_method3(&env, registryP, &methodInfo[ii]);
		dieOnFault("add_method", &env);
	}

	serverparm.config_file_name = NULL;
	serverparm.registryP = registryP;
	serverparm.port_number = 8080;
	serverparm.log_file_name = "/tmp/xmlrpc_log";

	printf("Starting XML-RPC server...\n");

	xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(registryP));

	if ( config_file ) free( config_file );
	return 0;
}
Example #18
0
static void xmlrpc_process(int rank)
{
	/* install handler to catch termination of child processes */
	if (signal(SIGCHLD, xmlrpc_sigchld)==SIG_ERR) {
		LM_ERR("failed to install signal handler for SIGCHLD\n");
		goto error;
	}

	/* Server Abyss init */

	xmlrpc_env_init(&env);

	#ifdef XMLRPC_OLD_VERSION
	xmlrpc_server_abyss_init_registry();
	registryP= xmlrpc_server_abyss_registry();
	#else
	registryP = xmlrpc_registry_new(&env);    
	#endif

	DateInit();
	MIMETypeInit();

	if (!ServerCreate(&srv, "XmlRpcServer", port, "", log_file)) {
		LM_ERR("failed to create XMLRPC server\n");
		goto error;
	}

	#ifdef XMLRPC_OLD_VERSION
	if (!ServerAddHandler(&srv, xmlrpc_server_abyss_rpc2_handler)) {
		LM_ERR("failed to add handler to server\n");
		goto error;
	}

	ServerDefaultHandler(&srv, xmlrpc_server_abyss_default_handler);

	#else

	xmlrpc_server_abyss_set_handlers2(&srv, "/RPC2", registryP);

	#endif

	ServerInit(&srv);

	if( init_mi_child() != 0 ) {
		LM_CRIT("failed to init the mi process\n");
		goto error;
	}

	if ( xr_writer_init(read_buf_size) != 0 ) {
		LM_ERR("failed to init the reply writer\n");
		goto error;
	}
	#ifdef XMLRPC_OLD_VERSION
	xmlrpc_env_init(&env);
	#endif

	if ( rpl_opt == 1 ) {
		xr_response = xmlrpc_build_value(&env, "()");
		if ( env.fault_occurred ){
			LM_ERR("failed to create an empty array: %s\n", env.fault_string);
			goto cleanup;
		}
	}

	if ( set_default_method(&env,registryP) != 0 ) {
		LM_ERR("failed to set up the default method!\n");
		goto cleanup;
	}

	/* Run server abyss */
	LM_INFO("starting xmlrpc server\n");

	ServerRun(&srv);

	LM_CRIT("Server terminated!!!\n");

cleanup:
	xmlrpc_env_clean(&env);
	if ( xr_response ) xmlrpc_DECREF(xr_response);
error:
	exit(-1);
}
/**
 * Thread process created to run a  listener for the methods being called.
 */
static void *
xr_rpcListener (Server *svr)
{
    xmlrpc_server_abyss_parms serverparm;
    

    /*  Initialize the environment and install the default dispatcher method.
    */
    xmlrpc_env_init (&svr->env);	/* initialize XML-RPC interface */

    if (SRVR_DEBUG)
	fprintf (stderr, "GLOBAL_ABYSS_SERVER rpcListener ....\n");
    svr->registry = xmlrpc_registry_new (&svr->env);
    xmlrpc_registry_set_default_method (&svr->env, 
	(svr->serverparm.registryP = svr->registry), 
        (xmlrpc_default_method) &xr_defaultMethod, svr);

    serverparm.config_file_name   = NULL;
    serverparm.registryP          = svr->serverparm.registryP;
    serverparm.port_number        = svr->serverparm.port_number;
    serverparm.log_file_name      = svr->serverparm.log_file_name;
    serverparm.keepalive_timeout  = 0;
    serverparm.keepalive_max_conn = 0;
    /*
    serverparm.keepalive_timeout  = 30;
    serverparm.keepalive_max_conn = 128;
    */


    /*  Never returns .....
    */
#ifndef OLD_METHOD
    xmlrpc_server_abyss (&svr->env, &serverparm, XMLRPC_APSIZE(log_file_name));

#else
  {
    xmlrpc_server_abyss_t   *serverP;
    xmlrpc_server_abyss_sig *oldHandlersP;

    xmlrpc_server_abyss_create (&svr->env, &serverparm, 
	XMLRPC_APSIZE(log_file_name), &serverP);
    xmlrpc_server_abyss_setup_sig (&svr->env, serverP, &oldHandlersP);

    printf ("Starting XML-RPC server...\n");

    xmlrpc_server_abyss_run_server (&svr->env,  &serverP);

    xmlrpc_server_abyss_restore_sig (oldHandlersP);
    free (oldHandlersP);
    xmlrpc_server_abyss_destroy (serverP);
    xmlrpc_server_abyss_global_term ();
  }
#endif


    /*  Should never get here.
     */
    if (svr->env.fault_occurred) {
        fprintf (stderr, "xmlrpc_server_abyss terminates.....\n");
        exit (1);
    } else
	return ((void *) OK);
}
/**
 * Thread process created to run a  listener for the methods being called.
 */
static void *
xr_rpcListener (Server *svr)
{
    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_server_abyss_t    *serverP;
    xmlrpc_server_abyss_sig  *oldHandlersP;


    xmlrpc_env_init (&svr->env);

    if (SRVR_DEBUG)
	fprintf (stderr, "NEW_ABYSS_SERVER rpcListener ....\n");
    xmlrpc_server_abyss_global_init (&svr->env);
    xr_dieIfFailed ("xmlrpc_server_abyss_global_init", svr->env);
    
    svr->registry = xmlrpc_registry_new (&svr->env);
    xr_dieIfFailed ("xmlrpc_registry_new", svr->env);

    xmlrpc_registry_set_default_method (&svr->env, 
        (svr->serverparm.registryP = svr->registry), 
        (xmlrpc_default_method) &xr_defaultMethod, svr);

    serverparm.config_file_name   = NULL;
    serverparm.registryP          = svr->serverparm.registryP;
    serverparm.port_number        = svr->serverparm.port_number;
    serverparm.log_file_name      = svr->serverparm.log_file_name;
    /*
    serverparm.keepalive_timeout  = 15;
    serverparm.keepalive_max_conn = 4;

    xmlrpc_server_abyss_create (&svr->env, &serverparm, 
				XMLRPC_APSIZE(keepalive_max_conn), &serverP);
    */
    xmlrpc_server_abyss_create (&svr->env, &serverparm, 
				XMLRPC_APSIZE(log_file_name), &serverP);
    xr_dieIfFailed ("xmlrpc_server_abyss_create", svr->env);
    
    xmlrpc_server_abyss_setup_sig (&svr->env, serverP, &oldHandlersP);
    xr_dieIfFailed ("xmlrpc_server_abyss_setup_sig", svr->env);

    xr_setupSigtermHandler (serverP);

    /*  Launch the server.
     */  
    xmlrpc_server_abyss_run_server (&svr->env, serverP);
    xr_dieIfFailed ("xmlrpc_server_abyss_run_server", svr->env);


    /*  We should never get here ....
     */  
    fprintf (stderr, "Server has terminated\n");

    xr_restoreSigtermHandler ();
    xmlrpc_server_abyss_restore_sig (oldHandlersP);
    xmlrpc_server_abyss_destroy (serverP);
    xmlrpc_registry_free (svr->registry);
    xmlrpc_server_abyss_global_term ();
    xmlrpc_env_clean (&svr->env);

    return ((void *) ERR);;
}
Example #21
0
int main(int argc, char ** argv){	
	signal(SIGINT, stop_notifier);
    signal(SIGTERM, stop_notifier);

	notify_log("Info", "Strated scheduler");

	//load in config
	if (ini_parse("/etc/network-sensor-server/config.ini", handler, &config) < 0) {
        notify_log("Error", "Can't load 'config.ini'\n");
        return 1;
    }

	//make deamon
    if(argc == 2)
        deamonise();

    /*                  */
    /* -- RPC server -- */
    /*                  */

    struct xmlrpc_method_info3 const add_alarm_method = {
        "add_alarm.request",
        &add_alarm,
    };

    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;
    xmlrpc_server_abyss_t * serverP;
    xmlrpc_server_abyss_sig * oldHandlersP;

    xmlrpc_env_init(&env);
    xmlrpc_server_abyss_global_init(&env);

    registryP = xmlrpc_registry_new(&env);
    if (env.fault_occurred) {
        notify_log("Error", "xmlrpc_registry_new() failed.  %s", env.fault_string);
        exit(1);
    }

    //add methods
    xmlrpc_registry_add_method3(&env, registryP, &add_alarm_method);
    if (env.fault_occurred) {
        notify_log("Error", "xmlrpc_registry_add_method3() add_alarm failed.  %s", env.fault_string);
        exit(1);
    }

    serverparm.config_file_name = NULL;   /* Select the modern normal API */
    serverparm.registryP        = registryP;
    serverparm.port_number      = config.notifier_rpc_port;
    serverparm.runfirst         = NULL;
    serverparm.runfirst_arg     = NULL;
    serverparm.log_file_name    = "/var/log/network-sensor-server/xmlrpc_log";

    xmlrpc_server_abyss_create(&env, &serverparm, XMLRPC_APSIZE(log_file_name), &serverP);

    notify_log("Info", "Started XML-RPC server");

    xmlrpc_server_abyss_run_server(&env, serverP);

    if (env.fault_occurred) {
        printf("xmlrpc_server_abyss() failed.  %s\n", env.fault_string);
        exit(1);
    }

    notify_log("Info", "Stopping XML-RPC server");

    xmlrpc_server_abyss_destroy(serverP);
    xmlrpc_server_abyss_global_term();
}
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);
}