示例#1
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);
}
示例#2
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);
}
/**
 * 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);;
}
/**
 * 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);
}
示例#5
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();
}