⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osip.c

📁 嵌入式产品中的osip的源代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
osip_ict_execute (osip_t * osip){  osip_transaction_t *transaction;  osip_event_t *se;  int more_event;  int tr;  tr = 0;  while (!osip_list_eol (osip->osip_ict_transactions, tr))    {      transaction = osip_list_get (osip->osip_ict_transactions, tr);      tr++;      more_event = 1;      do	{	  se = (osip_event_t *) osip_fifo_tryget (transaction->transactionff);	  if (se == NULL)	/* no more event for this transaction */	    more_event = 0;	  else	    osip_transaction_execute (transaction, se);	}      while (more_event == 1);    }  return 0;}intosip_ist_execute (osip_t * osip){  osip_transaction_t *transaction;  osip_event_t *se;  int more_event;  int tr;  tr = 0;  while (!osip_list_eol (osip->osip_ist_transactions, tr))    {      transaction = osip_list_get (osip->osip_ist_transactions, tr);      tr++;      more_event = 1;      do	{	  se = (osip_event_t *) osip_fifo_tryget (transaction->transactionff);	  if (se == NULL)	/* no more event for this transaction */	    more_event = 0;	  else	    osip_transaction_execute (transaction, se);	}      while (more_event == 1);    }  return 0;}intosip_nict_execute (osip_t * osip){  osip_transaction_t *transaction;  osip_event_t *se;  int more_event;  int tr;  tr = 0;  while (!osip_list_eol (osip->osip_nict_transactions, tr))    {      transaction = osip_list_get (osip->osip_nict_transactions, tr);      tr++;      more_event = 1;      do	{	  se = (osip_event_t *) osip_fifo_tryget (transaction->transactionff);	  if (se == NULL)	/* no more event for this transaction */	    more_event = 0;	  else	    osip_transaction_execute (transaction, se);	}      while (more_event == 1);    }  return 0;}intosip_nist_execute (osip_t * osip){  osip_transaction_t *transaction;  osip_event_t *se;  int more_event;  int tr;  tr = 0;  while (!osip_list_eol (osip->osip_nist_transactions, tr))    {      transaction = osip_list_get (osip->osip_nist_transactions, tr);      tr++;      more_event = 1;      do	{	  se = (osip_event_t *) osip_fifo_tryget (transaction->transactionff);	  if (se == NULL)	/* no more event for this transaction */	    more_event = 0;	  else	    osip_transaction_execute (transaction, se);	}      while (more_event == 1);    }  return 0;}voidosip_timers_gettimeout (osip_t * osip, struct timeval *lower_tv){  struct timeval now;  osip_transaction_t *tr;  int pos = 0;  gettimeofday (&now, NULL);  lower_tv->tv_sec = now.tv_sec + 3600 * 24 * 265;	/* wake up evry year :-) */  lower_tv->tv_usec = now.tv_usec;#ifdef OSIP_MT  osip_mutex_lock (ict_fastmutex);#endif  /* handle ict timers */  while (!osip_list_eol (osip->osip_ict_transactions, pos))    {      tr =	(osip_transaction_t *) osip_list_get (osip->osip_ict_transactions,					      pos);      if (1 <= osip_fifo_size (tr->transactionff))	{	  OSIP_TRACE (osip_trace		      (__FILE__, __LINE__, OSIP_INFO4, NULL,		       "1 Pending event already in transaction !\n"));	  lower_tv->tv_sec = 0;	  lower_tv->tv_usec = 0;#ifdef OSIP_MT	  osip_mutex_unlock (ict_fastmutex);#endif	  return;	}      else	{	  if (tr->state == ICT_CALLING)	    min_timercmp (lower_tv, &tr->ict_context->timer_b_start);	  if (tr->state == ICT_CALLING)	    min_timercmp (lower_tv, &tr->ict_context->timer_a_start);	  if (tr->state == ICT_COMPLETED)	    min_timercmp (lower_tv, &tr->ict_context->timer_d_start);	  if (timercmp (&now, lower_tv, >))	    {	      lower_tv->tv_sec = 0;	      lower_tv->tv_usec = 0;#ifdef OSIP_MT	      osip_mutex_unlock (ict_fastmutex);#endif	      return;	    }	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (ict_fastmutex);#endif#ifdef OSIP_MT  osip_mutex_lock (ist_fastmutex);#endif  /* handle ist timers */  while (!osip_list_eol (osip->osip_ist_transactions, pos))    {      tr =	(osip_transaction_t *) osip_list_get (osip->osip_ist_transactions,					      pos);      if (tr->state == IST_CONFIRMED)	min_timercmp (lower_tv, &tr->ist_context->timer_i_start);      if (tr->state == IST_COMPLETED)	min_timercmp (lower_tv, &tr->ist_context->timer_h_start);      if (tr->state == IST_COMPLETED)	min_timercmp (lower_tv, &tr->ist_context->timer_g_start);      if (timercmp (&now, lower_tv, >))	{	  lower_tv->tv_sec = 0;	  lower_tv->tv_usec = 0;#ifdef OSIP_MT	  osip_mutex_unlock (ist_fastmutex);#endif	  return;	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (ist_fastmutex);#endif#ifdef OSIP_MT  osip_mutex_lock (nict_fastmutex);#endif  /* handle nict timers */  while (!osip_list_eol (osip->osip_nict_transactions, pos))    {      tr =	(osip_transaction_t *) osip_list_get (osip->osip_nict_transactions,					      pos);      if (tr->state == NICT_COMPLETED)	min_timercmp (lower_tv, &tr->nict_context->timer_k_start);      if (tr->state == NICT_PROCEEDING || tr->state == NICT_TRYING)	min_timercmp (lower_tv, &tr->nict_context->timer_f_start);      if (tr->state == NICT_PROCEEDING || tr->state == NICT_TRYING)	min_timercmp (lower_tv, &tr->nict_context->timer_e_start);      if (timercmp (&now, lower_tv, >))	{	  lower_tv->tv_sec = 0;	  lower_tv->tv_usec = 0;#ifdef OSIP_MT	  osip_mutex_unlock (nict_fastmutex);#endif	  return;	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (nict_fastmutex);#endif#ifdef OSIP_MT  osip_mutex_lock (nist_fastmutex);#endif  /* handle nist timers */  while (!osip_list_eol (osip->osip_nist_transactions, pos))    {      tr =	(osip_transaction_t *) osip_list_get (osip->osip_nist_transactions,					      pos);      if (tr->state == NIST_COMPLETED)	min_timercmp (lower_tv, &tr->nist_context->timer_j_start);      if (timercmp (&now, lower_tv, >))	{	  lower_tv->tv_sec = 0;	  lower_tv->tv_usec = 0;#ifdef OSIP_MT	  osip_mutex_unlock (nist_fastmutex);#endif	  return;	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (nist_fastmutex);#endif  lower_tv->tv_sec = lower_tv->tv_sec - now.tv_sec;  lower_tv->tv_usec = lower_tv->tv_usec - now.tv_usec;  /* just make sure the value is correct! */  if (lower_tv->tv_usec < 0)    {      lower_tv->tv_usec = lower_tv->tv_usec + 1000000;      lower_tv->tv_sec--;    }  if (lower_tv->tv_sec < 0)    {      lower_tv->tv_sec = 0;      lower_tv->tv_usec = 0;    }  if (lower_tv->tv_usec > 1000000)    {      lower_tv->tv_usec = lower_tv->tv_usec - 1000000;      lower_tv->tv_sec++;    }  return;}voidosip_timers_ict_execute (osip_t * osip){  osip_transaction_t *tr;  int pos = 0;#ifdef OSIP_MT  osip_mutex_lock (ict_fastmutex);#endif  /* handle ict timers */  while (!osip_list_eol (osip->osip_ict_transactions, pos))    {      osip_event_t *evt;      tr =	(osip_transaction_t *) osip_list_get (osip->osip_ict_transactions,					      pos);      if (1 <= osip_fifo_size (tr->transactionff))	{	  OSIP_TRACE (osip_trace		      (__FILE__, __LINE__, OSIP_INFO4, NULL,		       "1 Pending event already in transaction !\n"));	}      else	{	  evt = __osip_ict_need_timer_b_event (tr->ict_context, tr->state,					       tr->transactionid);	  if (evt != NULL)	    osip_fifo_add (tr->transactionff, evt);	  else	    {	      evt = __osip_ict_need_timer_a_event (tr->ict_context, tr->state,						   tr->transactionid);	      if (evt != NULL)		osip_fifo_add (tr->transactionff, evt);	      else		{		  evt =		    __osip_ict_need_timer_d_event (tr->ict_context, tr->state,						   tr->transactionid);		  if (evt != NULL)		    osip_fifo_add (tr->transactionff, evt);		}	    }	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (ict_fastmutex);#endif}voidosip_timers_ist_execute (osip_t * osip){  osip_transaction_t *tr;  int pos = 0;#ifdef OSIP_MT  osip_mutex_lock (ist_fastmutex);#endif  /* handle ist timers */  while (!osip_list_eol (osip->osip_ist_transactions, pos))    {      osip_event_t *evt;      tr =	(osip_transaction_t *) osip_list_get (osip->osip_ist_transactions,					      pos);      evt = __osip_ist_need_timer_i_event (tr->ist_context, tr->state,					   tr->transactionid);      if (evt != NULL)	osip_fifo_add (tr->transactionff, evt);      else	{	  evt = __osip_ist_need_timer_h_event (tr->ist_context, tr->state,					       tr->transactionid);	  if (evt != NULL)	    osip_fifo_add (tr->transactionff, evt);	  else	    {	      evt = __osip_ist_need_timer_g_event (tr->ist_context, tr->state,						   tr->transactionid);	      if (evt != NULL)		osip_fifo_add (tr->transactionff, evt);	    }	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (ist_fastmutex);#endif}voidosip_timers_nict_execute (osip_t * osip){  osip_transaction_t *tr;  int pos = 0;#ifdef OSIP_MT  osip_mutex_lock (nict_fastmutex);#endif  /* handle nict timers */  while (!osip_list_eol (osip->osip_nict_transactions, pos))    {      osip_event_t *evt;      tr =	(osip_transaction_t *) osip_list_get (osip->osip_nict_transactions,					      pos);      evt = __osip_nict_need_timer_k_event (tr->nict_context, tr->state,					    tr->transactionid);      if (evt != NULL)	osip_fifo_add (tr->transactionff, evt);      else	{	  evt = __osip_nict_need_timer_f_event (tr->nict_context, tr->state,						tr->transactionid);	  if (evt != NULL)	    osip_fifo_add (tr->transactionff, evt);	  else	    {	      evt =		__osip_nict_need_timer_e_event (tr->nict_context, tr->state,						tr->transactionid);	      if (evt != NULL)		osip_fifo_add (tr->transactionff, evt);	    }	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (nict_fastmutex);#endif}voidosip_timers_nist_execute (osip_t * osip){  osip_transaction_t *tr;  int pos = 0;#ifdef OSIP_MT  osip_mutex_lock (nist_fastmutex);#endif  /* handle nist timers */  while (!osip_list_eol (osip->osip_nist_transactions, pos))    {      osip_event_t *evt;      tr =	(osip_transaction_t *) osip_list_get (osip->osip_nist_transactions,					      pos);      evt = __osip_nist_need_timer_j_event (tr->nist_context, tr->state,					    tr->transactionid);      if (evt != NULL)	osip_fifo_add (tr->transactionff, evt);      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (nist_fastmutex);#endif}voidosip_set_cb_send_message (osip_t * cf,			  int (*cb) (osip_transaction_t *, osip_message_t *,				     char *, int, int)){  cf->cb_send_message = cb;}void__osip_message_callback (int type, osip_transaction_t * tr,			 osip_message_t * msg){  osip_t *config = tr->config;  if (type >= OSIP_MESSAGE_CALLBACK_COUNT)    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_BUG, NULL,		   "invalid callback type %d\n", type));      return;    }  if (config->msg_callbacks[type] == NULL)    return;  config->msg_callbacks[type] (type, tr, msg);}void__osip_kill_transaction_callback (int type, osip_transaction_t * tr){  osip_t *config = tr->config;  if (type >= OSIP_KILL_CALLBACK_COUNT)    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_BUG, NULL,		   "invalid callback type %d\n", type));      return;    }  if (config->kill_callbacks[type] == NULL)    return;  config->kill_callbacks[type] (type, tr);}void__osip_transport_error_callback (int type, osip_transaction_t * tr, int error){  osip_t *config = tr->config;  if (type >= OSIP_TRANSPORT_ERROR_CALLBACK_COUNT)    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_BUG, NULL,		   "invalid callback type %d\n", type));      return;    }  if (config->tp_error_callbacks[type] == NULL)    return;  config->tp_error_callbacks[type] (type, tr, error);}intosip_set_message_callback (osip_t * config, int type, osip_message_cb_t cb){  if (type >= OSIP_MESSAGE_CALLBACK_COUNT)    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_ERROR, NULL,		   "invalid callback type %d\n", type));      return -1;    }  config->msg_callbacks[type] = cb;  return 0;}intosip_set_kill_transaction_callback (osip_t * config, int type,				    osip_kill_transaction_cb_t cb){  if (type >= OSIP_KILL_CALLBACK_COUNT)    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_ERROR, NULL,		   "invalid callback type %d\n", type));      return -1;    }  config->kill_callbacks[type] = cb;  return 0;}intosip_set_transport_error_callback (osip_t * config, int type,				   osip_transport_error_cb_t cb){  if (type >= OSIP_TRANSPORT_ERROR_CALLBACK_COUNT)    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_ERROR, NULL,		   "invalid callback type %d\n", type));      return -1;    }  config->tp_error_callbacks[type] = cb;  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -