int main(int argc, char *argv[])
{
  root_test_t rt[1] = {{{ SU_HOME_INIT(rt) }}};
  int retval = 0;
  int i;

  rt->rt_family = AF_INET;

  for (i = 1; argv[i]; i++) {
    if (strcmp(argv[i], "-v") == 0)
      rt->rt_flags |= tst_verbatim;
    else if (strcmp(argv[i], "-a") == 0)
      rt->rt_flags |= tst_abort;
#if SU_HAVE_IN6
    else if (strcmp(argv[i], "-6") == 0)
      rt->rt_family = AF_INET6;
#endif
    else
      usage(1);
  }

  retval |= init_test(rt);
  retval |= register_test(rt);
  retval |= clone_test(rt);
  su_root_threading(rt->rt_root, 0);
  retval |= clone_test(rt);
  retval |= deinit_test(rt);

  return retval;
}
static void
farsight_netsocket_stun_init (FarsightNetsocketStun *object)
{
    FarsightNetsocketStun *self = FARSIGHT_NETSOCKET_STUN (object);
    GSource *gsource;

    /* create a su event loop and connect it to glib */
    su_init();
    self->root = su_root_source_create(self);
    su_root_threading(self->root, 1);
    gsource = su_root_gsource(self->root);
    g_source_attach(gsource, NULL);

    self->dispose_run = FALSE;
}
예제 #3
0
static int luasofia_su_root_threading(lua_State *L)
{
    int enable = 0;

    luasofia_su_root_t *lroot = NULL;
   
    /* get enable param */
    enable = lua_toboolean(L, -1);

    /* get and check first argument (should be a root) */
    lroot = (luasofia_su_root_t*)luaL_checkudata(L, -2, SU_ROOT_MTABLE);

    enable = su_root_threading(lroot->root, enable);

    lua_pushboolean(L, enable);
    return 1;
}
예제 #4
0
nua_t *s2_nua_setup(char const *label,
		    tag_type_t tag, tag_value_t value, ...)
{
  ta_list ta;

  s2_setup(label);

  s2 = su_home_new(sizeof *s2);

  s2_dns_setup(s2base->root);

  s2_setup_logs(0);
  s2_sip_setup("example.org", NULL, TAG_END());
  assert(s2sip->contact);

  s2_dns_domain("example.org", 1,
		"s2", 1, s2sip->udp.contact->m_url,
		"s2", 1, s2sip->tcp.contact->m_url,
		NULL);

  /* enable/disable multithreading */
  su_root_threading(s2base->root, s2_nua_thread);

  ta_start(ta, tag, value);
  s2->nua =
    nua_create(s2base->root,
	       s2_nua_callback,
	       s2,
	       SIPTAG_FROM_STR("Alice <sip:[email protected]>"),
	       /* NUTAG_PROXY((url_string_t *)s2sip->contact->m_url), */
	       /* Use internal DNS server */
	       NUTAG_PROXY("sip:example.org"),
	       /* Force sresolv to use localhost and s2dns as DNS server */
#if HAVE_WIN32
	       SRESTAG_RESOLV_CONF("NUL"),
#else
	       SRESTAG_RESOLV_CONF("/dev/null"),
#endif
	       ta_tags(ta));
  ta_end(ta);

  return s2->nua;
}
예제 #5
0
int sofsip_loop(int ac, char *av[], const int input_fd, const int output_fd)
{
  cli_t cli[1] = {{{{sizeof(cli)}}}};
  int res = 0;
  global_cli_p = cli;

#ifndef _WIN32
  /* see: http://www.opengroup.org/onlinepubs/007908799/xsh/sigaction.html */
  struct sigaction sigact;
  memset(&sigact, 0, sizeof(sigact));
  sigact.sa_handler = sofsip_signal_handler;
  sigaction(SIGINT, &sigact, NULL); /* ctrl-c */
  sigaction(SIGABRT, &sigact, NULL);
  sigaction(SIGTERM, &sigact, NULL);
#endif

  cli->cli_input_fd = input_fd;
  cli->cli_output_fd = output_fd;

  /* step: initialize sofia su OS abstraction layer */
  su_init();
  su_home_init(cli->cli_home);

  /* step: initialize glib and gstreamer */
#if HAVE_GLIB
  g_type_init();
#if HAVE_GST
  {
    //guint major, minor, micro, nano;
    //gst_init (NULL, NULL);
    //gst_version (&major, &minor, &micro, &nano);
    //g_message ("This program is linked against GStreamer %d.%d.%d\n", major, minor, micro);
  }
#endif
#endif

  /* step: create a su event loop and connect it mainloop */
  sofsip_mainloop_create(cli);
  assert(cli->cli_root);

  /* Disable threading by command line switch? */
  su_root_threading(cli->cli_root, 0);

  /* step: parse command line arguments and initialize app event loop */
  res = sofsip_init(cli, ac, av);
  assert(res == 0);

  /* step: create ssc signaling and media subsystem instance */
  cli->cli_ssc = ssc_create(cli->cli_home, cli->cli_root, cli->cli_conf, cli->cli_input_fd, cli->cli_output_fd);

  if (res != -1 && cli->cli_ssc) {

    cli->cli_ssc->ssc_exit_cb = sofsip_shutdown_cb;
    cli->cli_ssc->ssc_auth_req_cb = sofsip_auth_req_cb;
    cli->cli_ssc->ssc_event_cb = sofsip_event_cb;
  
    ssc_input_install_handler(SOFSIP_PROMPT, sofsip_handle_input_cb);

    /* enter the main loop */
    sofsip_mainloop_run(cli);

    ssc_destroy(cli->cli_ssc), cli->cli_ssc = NULL;
  }
  
  sofsip_deinit(cli);
  ssc_input_clear_history();

  sofsip_mainloop_destroy(cli);
  su_home_deinit(cli->cli_home);
  su_deinit();

  return 0;
}
예제 #6
0
    void DrachtioController::run() {
        
        if( m_bDaemonize ) {
            daemonize() ;
        }

		/* now we can initialize logging */
		m_logger.reset( this->createLogger() );
		this->logConfig() ;

        DR_LOG(log_debug) << "Main thread id: " << boost::this_thread::get_id() << endl ;

       /* open stats connection */
        string adminAddress ;
        unsigned int adminPort = m_Config->getAdminPort( adminAddress ) ;
        if( 0 != adminPort ) {
            m_pClientController.reset( new ClientController( this, adminAddress, adminPort )) ;
        }

        string url ;
        m_Config->getSipUrl( url ) ;
        DR_LOG(log_notice) << "starting sip stack on " << url << endl ;
        
        int rv = su_init() ;
        if( rv < 0 ) {
            DR_LOG(log_error) << "Error calling su_init: " << rv << endl ;
            return ;
        }
        ::atexit(su_deinit);
        
        m_root = su_root_create( NULL ) ;
        if( NULL == m_root ) {
            DR_LOG(log_error) << "Error calling su_root_create: " << endl ;
            return  ;
        }
        m_home = su_home_create() ;
        if( NULL == m_home ) {
            DR_LOG(log_error) << "Error calling su_home_create" << endl ;
        }
        su_log_redirect(NULL, __sofiasip_logger_func, NULL);
        
        /* for now set logging to full debug */
        su_log_set_level(NULL, m_Config->getSofiaLogLevel() ) ;
        setenv("TPORT_LOG", "1", 1) ;
        
        /* this causes su_clone_start to start a new thread */
        su_root_threading( m_root, 0 ) ;
        rv = su_clone_start( m_root, m_clone, this, clone_init, clone_destroy ) ;
        if( rv < 0 ) {
           DR_LOG(log_error) << "Error calling su_clone_start" << endl ;
           return  ;
        }
        
        /* enable extended headers */
        if (sip_update_default_mclass(sip_extend_mclass(NULL)) < 0) {
            DR_LOG(log_error) << "Error calling sip_update_default_mclass" << endl ;
            return  ;
        }
 
         /* create our agent */
        char str[URL_MAXLEN] ;
        memset(str, 0, URL_MAXLEN) ;
        strncpy( str, url.c_str(), url.length() ) ;
        
		m_nta = nta_agent_create( m_root,
                                 URL_STRING_MAKE(str),               /* our contact address */
                                 NULL,         /* no callback function */
                                 NULL,                  /* therefore no context */
                                 TAG_NULL(),
                                 TAG_END() ) ;
        
        if( NULL == m_nta ) {
            DR_LOG(log_error) << "Error calling nta_agent_create" << endl ;
            return ;
        }
        
        m_defaultLeg = nta_leg_tcreate(m_nta, defaultLegCallback, this,
                                      NTATAG_NO_DIALOG(1),
                                      TAG_END());
        if( NULL == m_defaultLeg ) {
            DR_LOG(log_error) << "Error creating default leg" << endl ;
            return ;
        }
        
        
        /* save my contact url, via, etc */
        m_my_contact = nta_agent_contact( m_nta ) ;
        ostringstream s ;
        s << "SIP/2.0/UDP " <<  m_my_contact->m_url[0].url_host ;
        if( m_my_contact->m_url[0].url_port ) s << ":" <<  m_my_contact->m_url[0].url_port  ;
        m_my_via.assign( s.str().c_str(), s.str().length() ) ;
        DR_LOG(log_debug) << "My via header: " << m_my_via << endl ;

        m_pDialogController = boost::make_shared<SipDialogController>( this, &m_clone ) ;
              
        /* sofia event loop */
        DR_LOG(log_notice) << "Starting sofia event loop in main thread: " <<  boost::this_thread::get_id() << endl ;

        /* start a timer */
        m_timer = su_timer_create( su_root_task(m_root), 30000) ;
        su_timer_set_for_ever(m_timer, watchdogTimerHandler, this) ;
 
        su_root_run( m_root ) ;
        DR_LOG(log_notice) << "Sofia event loop ended" << endl ;
        
        su_root_destroy( m_root ) ;
        m_root = NULL ;
        su_home_unref( m_home ) ;
        su_deinit() ;

        m_Config.reset();
        this->deinitializeLogging() ;

        
    }