Example #1
0
int main(int argc, char *argv[])
{
  int retval = 0;
  int i;

  su_init();

  for (i = 1; argv[i]; i++) {
    if (strcmp(argv[i], "-v") == 0)
      tstflags |= tst_verbatim;
    else if (strcmp(argv[i], "-a") == 0)
      tstflags |= tst_abort;
    else
      usage(1);
  }

  retval |= test_sockaddr();
  retval |= test_sendrecv();
  retval |= test_select();
  retval |= test_md5(); fflush(stdout);

  su_deinit();

  return retval;
}
static int deinit_test(root_test_t *rt)
{
  BEGIN();

  TEST_VOID(su_root_destroy(rt->rt_root)); rt->rt_root = NULL;
  TEST_VOID(su_root_destroy(NULL));

  su_deinit();

  END();
}
Example #3
0
void pr_deinit(proxy_t *pr)
{
  if (pr->pr_addrinfo)
    su_freeaddrinfo(pr->pr_addrinfo), pr->pr_addrinfo = NULL;

  if (pr->pr_root)
    su_root_destroy(pr->pr_root), pr->pr_root = NULL;

  su_home_deinit(pr->pr_home);

  su_deinit();
}
static apt_bool_t mrcp_sofia_task_run(apt_task_t *task)
{
	mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task);

	if(sofia_agent->nua) {
		/* Run event loop */
		su_root_run(sofia_agent->root);
		
		/* Destroy allocated resources */
		nua_destroy(sofia_agent->nua);
		sofia_agent->nua = NULL;
	}
	su_root_destroy(sofia_agent->root);
	sofia_agent->root = NULL;
	su_deinit();

	apt_task_child_terminate(task);
	return TRUE;
}
Example #5
0
int main(int argc, char *argv[])
{
  proxy_t pr[1] = {{{ SU_HOME_INIT(pr) }}};
  int error;

  error = pr_init(pr);
  if (error == 0) {
    if ((error = pr_config(pr, argc, argv)) > 1)
      usage();
  }

  if (error == 0)
    error = pr_run(pr);

  pr_deinit(pr);

  su_deinit();

  exit(error);
}
static apt_bool_t mrcp_sofia_task_run(apt_task_t *task)
{
    mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task);

    /* Initialize Sofia-SIP library and create event loop */
    su_init();
    sofia_agent->root = su_root_create(NULL);

    /* Create a user agent instance. The stack will call the 'event_callback()'
     * callback when events such as succesful registration to network,
     * an incoming call, etc, occur.
     */
    sofia_agent->nua = nua_create(
                           sofia_agent->root,         /* Event loop */
                           mrcp_sofia_event_callback, /* Callback for processing events */
                           sofia_agent,               /* Additional data to pass to callback */
                           NUTAG_URL(sofia_agent->sip_bind_str), /* Address to bind to */
                           TAG_END());                /* Last tag should always finish the sequence */
    if(sofia_agent->nua) {
        nua_set_params(
            sofia_agent->nua,
            NUTAG_AUTOANSWER(0),
            NUTAG_APPL_METHOD("OPTIONS"),
            SIPTAG_USER_AGENT_STR(sofia_agent->config->user_agent_name),
            TAG_END());

        /* Run event loop */
        su_root_run(sofia_agent->root);

        /* Destroy allocated resources */
        nua_destroy(sofia_agent->nua);
        sofia_agent->nua = NULL;
    }
    su_root_destroy(sofia_agent->root);
    sofia_agent->root = NULL;
    su_deinit();

    apt_task_child_terminate(task);
    return TRUE;
}
/** Main function for clone thread.
 *
 * @internal
 */
static void *su_pthread_port_clone_main(void *varg)
{
  struct clone_args *arg = (struct clone_args *)varg;
  su_task_r task;
  int zap = 1;

#if SU_HAVE_WINSOCK
  su_init();
#endif

  task->sut_port = arg->create();

  if (task->sut_port) {
    task->sut_root = su_salloc(su_port_home(task->sut_port),
			       sizeof *task->sut_root);
    if (task->sut_root) {

      task->sut_root->sur_threading = 1;	/* By default */

      SU_TASK_COPY(task->sut_root->sur_parent, su_root_task(arg->parent),
		   su_pthread_port_clone_main);
      SU_TASK_COPY(task->sut_root->sur_task, task,
		   su_pthread_port_clone_main);

      if (su_msg_create(arg->clone,
			task,
			su_root_task(arg->parent),
			su_pthread_port_clone_break,
			0) == 0) {
	task->sut_root->sur_magic = arg->magic;
	task->sut_root->sur_deinit = arg->deinit;

	su_root_set_max_defer(task->sut_root, 
			      su_root_get_max_defer(arg->parent));

	if (arg->init(task->sut_root, arg->magic) == 0) {
	  su_pthread_port_return_to_parent(arg, 0), arg = NULL;

	  su_root_run(task->sut_root); /* Do the work */

	  /* Cleanup */
	  if (task->sut_port->sup_waiting_parent) {
	    struct su_pthread_port_waiting_parent *mom;

	    mom = task->sut_port->sup_waiting_parent;
	    pthread_mutex_lock(mom->mutex);
	    mom->waiting = 0;
	    pthread_cond_signal(mom->cv);
	    pthread_mutex_unlock(mom->mutex);

	    pthread_mutex_lock(mom->deinit);
	    su_port_getmsgs(task->sut_port);
	    pthread_mutex_unlock(mom->deinit);
	  }
	  else
	    zap = 0;
	}
	else
	  su_msg_destroy(arg->clone);

	su_root_destroy(task->sut_root);
      }
    }

    task->sut_port->sup_base->sup_vtable->
      su_port_decref(task->sut_port, zap,
		     "su_pthread_port_clone_main");
  }

#if SU_HAVE_WINSOCK
  su_deinit();
#endif

  if (arg)
    su_pthread_port_return_to_parent(arg, -1);

  return NULL;			/* Exit from thread */
}
/*
 * test su_timer functionality:
 *
 * Create a timer, executing print_stamp() in every 20 ms
 */
int main(int argc, char *argv[])
{
  su_root_t *root;
  su_timer_t *t, *t1, *t_end;
  su_timer_t **timers;
  su_duration_t interval = 60;
  char *argv0 = argv[0];
  char *s;
  int use_t1 = 0;
  su_time_t now, started;
  intptr_t i, N = 500;
  GSource *source;

  struct timing timing[1] = {{ 0 }};
  struct tester tester[1] = {{ 0 }};

  while (argv[1] && argv[1][0] == '-') {
    char *o = argv[1] + 1;
    while (*o) {
      if (*o == '1')
	o++, use_t1 = 1;
      else if (*o == 'r')
	o++, timing->t_run = 1;
      else if (*o == 'N') {
	if (o[1])
	  N = strtoul(o + 1, &o, 0);
	else if (argv[2])
	  N = strtoul(argv++[2], &o, 0);
	break;
      }
      else
	break;

    }
    if (*o)
      usage(argv0);
    argv++;
  }

  if (argv[1]) {
    interval = strtoul(argv[1], &s, 10);

    if (interval == 0 || s == argv[1])
      usage(argv0);
  }

  su_init(); atexit(su_deinit);

  tester->root = root = su_glib_root_create(tester);

  source = su_root_gsource(tester->root);
  g_source_attach(source, NULL /*g_main_context_default ()*/);

  su_msg_create(intr_msg,
		su_root_task(root),
		su_root_task(root),
		test_break, 0);

  signal(SIGINT, intr_handler);
#if HAVE_SIGPIPE
  signal(SIGPIPE, intr_handler);
  signal(SIGQUIT, intr_handler);
  signal(SIGHUP, intr_handler);
#endif

  t = su_timer_create(su_root_task(root), interval);
  t1 = su_timer_create(su_root_task(root), 1);
  t_end = su_timer_create(su_root_task(root), 20 * interval);

  if (t == NULL || t1 == NULL || t_end == NULL)
    su_perror("su_timer_create"), exit(1);

  tester->t = t, tester->t1 = t1;

  timing->t_prev = su_now();

  if (timing->t_run)
    su_timer_run(t, print_stamp, timing);
  else
    su_timer_set(t, print_stamp, timing);

  if (use_t1)
    su_timer_set(t1, print_X, NULL);

  su_timer_set(t_end, end_test, NULL);

  su_root_run(root);

  su_msg_destroy(intr_msg);

  su_timer_destroy(t);
  su_timer_destroy(t1);

  if (timing->t_times != 10) {
    fprintf(stderr, "%s: t expired %d times (expecting 10)\n",
	    argv0, timing->t_times);
    return 1;
  }

  /* Insert timers in order */
  timers = calloc(N, sizeof *timers);
  if (!timers) { perror("calloc"); exit(1); }

  now = started = su_now();

  for (i = 0; i < N; i++) {
    t = su_timer_create(su_root_task(root), 1000);
    if (!t) { perror("su_timer_create"); exit(1); }
    if (++now.tv_usec == 0) ++now.tv_sec;
    su_timer_set_at(t, increment, (void *)i, now);
    timers[i] = t;
  }

  tester->sentinel = (void*)(i - 1);

  su_root_run(root);

  printf("Processing %u timers took %f millisec (%f expected)\n",
	 (unsigned)i, su_time_diff(su_now(), started) * 1000, (double)i / 1000);

  for (i = 0; i < N; i++) {
    su_timer_destroy(timers[i]);
  }

  su_root_destroy(root);

  su_deinit();

  return 0;
}
Example #9
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;
}
Example #10
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() ;

        
    }
Example #11
0
int main(int argc, char *argv[])
{
  char buffer[SU_ADDRSIZE];
  su_localinfo_t hints[1] = {{ LI_CANONNAME }};
  su_localinfo_t *li, *res = NULL;
  int error;
  int ifindex = 0;

  if (argv[1] && strcmp(argv[1], "--help") == 0)
    usage(0);

  for (;;) {
    switch(getopt(argc, argv, "iImdn46gslh")) {

    case 'I': ifindex = 1; break;
    case 'i': hints->li_flags |= LI_IFNAME; ifindex = 1; break;
    case 'm': hints->li_flags |= LI_V4MAPPED; break;
    case '4': hints->li_family = AF_INET; break;
#if SU_HAVE_IN6
    case '6': hints->li_family = AF_INET6; break;
#endif
    case 'd': hints->li_flags |= LI_NAMEREQD; break;
    case 'n': hints->li_flags |= LI_NUMERIC; break;
    case 'g': hints->li_scope |= LI_SCOPE_GLOBAL; break;
    case 's': hints->li_scope |= LI_SCOPE_SITE; break;
    case 'l': hints->li_scope |= LI_SCOPE_LINK; break;
    case 'h': hints->li_scope |= LI_SCOPE_HOST; break;

    case -1:
      goto main;

    default:
      usage(1);
    }
  }

 main:
  if (optind < argc)
    hints->li_canonname = argv[optind++];

  if (optind < argc)
    usage(1);

  su_init();

  if ((error = su_getlocalinfo(hints, &res)) == 0) {
    for (li = res; li; li = li->li_next) {
      if (li->li_flags & LI_NUMERIC) {
        fputs(li->li_canonname, stdout);
      }
      else {
        su_inet_ntop(li->li_family, SU_ADDR(li->li_addr),
		     buffer, sizeof(buffer));
        printf("%s maddr=[%s]", li->li_canonname, buffer);
      }
      if (li->li_scope & LI_SCOPE_GLOBAL)
	fputs(" scope=global", stdout);
      else if (li->li_scope & LI_SCOPE_SITE)
	fputs(" scope=site", stdout);
      else if (li->li_scope & LI_SCOPE_LINK)
	fputs(" scope=link", stdout);
      else if (li->li_scope & LI_SCOPE_HOST)
	fputs(" scope=host", stdout);
      if (ifindex) {
	if (li->li_ifname)
	  printf(" if[%d]=%s", li->li_index, li->li_ifname);
	else
	  printf(" if[%d]", li->li_index);
      }
      puts("");
    }
    su_freelocalinfo(res);
  }
  else {
    fprintf(stderr, "localinfo: %s\n", su_gli_strerror(error));
    error = 1;
  }

  su_deinit();

  return error;
}
Example #12
0
static int luasofia_su_deinit(lua_State *L)
{
    su_deinit();
    return 0;
}