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

📄 osip.c

📁 嵌入式产品中的osip的源代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
  osip_mutex_lock (nict_fastmutex);#endif  while (!osip_list_eol (osip->osip_nict_transactions, pos))    {      tmp = osip_list_get (osip->osip_nict_transactions, pos);      if (tmp->transactionid == nict->transactionid)	{	  osip_list_remove (osip->osip_nict_transactions, pos);#ifdef OSIP_MT	  osip_mutex_unlock (nict_fastmutex);#endif	  return 0;	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (nict_fastmutex);#endif  return -1;}int__osip_remove_nist_transaction (osip_t * osip, osip_transaction_t * nist){  int pos = 0;  osip_transaction_t *tmp;#ifdef OSIP_MT  osip_mutex_lock (nist_fastmutex);#endif  while (!osip_list_eol (osip->osip_nist_transactions, pos))    {      tmp = osip_list_get (osip->osip_nist_transactions, pos);      if (tmp->transactionid == nist->transactionid)	{	  osip_list_remove (osip->osip_nist_transactions, pos);#ifdef OSIP_MT	  osip_mutex_unlock (nist_fastmutex);#endif	  return 0;	}      pos++;    }#ifdef OSIP_MT  osip_mutex_unlock (nist_fastmutex);#endif  return -1;}#if 0/* this method is made obsolete because it contains bugs and is also   too much limited.   any call to this method should be replace this way:   //osip_distribute(osip, evt);   osip_transaction_t *transaction = osip_find_transaction_and_add_event(osip, evt);   if (i!=0) // in case it's a new request     {        if (evt is an ACK)            evt could be an ACK for INVITE (not handled by oSIP)        else if ( evt is a 200 for INVITE)           evt could be a retransmission of a 200 for INVITE (not handled by oSIP)        else if (evt is a new request)  == not a ACK and not a response	  {           transaction = osip_create_transaction(osip, evt);           if (transaction==NULL)             printf("failed to create a transaction\");          }    }    else    {    // here, the message as been taken by the stack.    }*//* finds the transaction context and add the sipevent in its fifo. *//* USED ONLY BY THE TRANSPORT LAYER.                               *//* INPUT : osip_t *osip | osip. contains the list of tr. context*//* INPUT : osip_event_t* sipevent | event to dispatch.               */osip_transaction_t *osip_distribute_event (osip_t * osip, osip_event_t * evt){  osip_transaction_t *transaction = NULL;  int i;  osip_fsm_type_t ctx_type;  if (EVT_IS_INCOMINGMSG (evt))    {      /* event is for ict */      if (MSG_IS_REQUEST (evt->sip))	{	  if (0 == strcmp (evt->sip->cseq->method, "INVITE")	      || 0 == strcmp (evt->sip->cseq->method, "ACK"))	    {#ifdef OSIP_MT	      osip_mutex_lock (ist_fastmutex);#endif	      transaction =		osip_transaction_find (osip->osip_ist_transactions, evt);#ifdef OSIP_MT	      osip_mutex_unlock (ist_fastmutex);#endif	    }	  else	    {#ifdef OSIP_MT	      osip_mutex_lock (nist_fastmutex);#endif	      transaction =		osip_transaction_find (osip->osip_nist_transactions, evt);#ifdef OSIP_MT	      osip_mutex_unlock (nist_fastmutex);#endif	    }	}      else	{	  if (0 == strcmp (evt->sip->cseq->method, "INVITE")	      || 0 == strcmp (evt->sip->cseq->method, "ACK"))	    {#ifdef OSIP_MT	      osip_mutex_lock (ict_fastmutex);#endif	      transaction =		osip_transaction_find (osip->osip_ict_transactions, evt);#ifdef OSIP_MT	      osip_mutex_unlock (ict_fastmutex);#endif	    }	  else	    {#ifdef OSIP_MT	      osip_mutex_lock (nict_fastmutex);#endif	      transaction =		osip_transaction_find (osip->osip_nict_transactions, evt);#ifdef OSIP_MT	      osip_mutex_unlock (nict_fastmutex);#endif	    }	}      if (transaction == NULL)	{	  if (EVT_IS_RCV_STATUS_1XX (evt)	      || EVT_IS_RCV_STATUS_2XX (evt)	      || EVT_IS_RCV_STATUS_3456XX (evt) || EVT_IS_RCV_ACK (evt))	    {			/* event MUST be ignored! */	      /* EXCEPT FOR 2XX THAT MUST BE GIVEN TO THE CORE LAYER!!! */	      /* TODO */	      OSIP_TRACE (osip_trace			  (__FILE__, __LINE__, OSIP_WARNING, NULL,			   "transaction does not yet exist... %x callid:%s\n",			   evt, evt->sip->call_id->number));	      osip_message_free (evt->sip);	      osip_free (evt);	/* transaction thread will not delete it */	      return NULL;	    }	  /* we create a new context for this incoming request */	  if (0 == strcmp (evt->sip->cseq->method, "INVITE"))	    ctx_type = IST;	  else	    ctx_type = NIST;	  i = osip_transaction_init (&transaction, ctx_type, osip, evt->sip);	  if (i == -1)	    {	      osip_message_free (evt->sip);	      osip_free (evt);	/* transaction thread will not delete it */	      return NULL;	    }	}      evt->transactionid = transaction->transactionid;      evt->transactionid = transaction->transactionid;      osip_fifo_add (transaction->transactionff, evt);      return transaction;    }  else    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_BUG, NULL,		   "wrong event type %x\n", evt));      return NULL;    }}#endifintosip_find_transaction_and_add_event (osip_t * osip, osip_event_t * evt){  osip_transaction_t *transaction = __osip_find_transaction (osip, evt, 1);  if (transaction == NULL)    return -1;  return 0;}#ifndef OSIP_MTosip_transaction_t *osip_find_transaction (osip_t * osip, osip_event_t * evt){  return __osip_find_transaction (osip, evt, 0);}#endifosip_transaction_t *__osip_find_transaction (osip_t * osip, osip_event_t * evt, int consume){  osip_transaction_t *transaction = NULL;  osip_list_t *transactions = NULL;#ifdef OSIP_MT  struct osip_mutex *mut = NULL;#endif  if (evt == NULL || evt->sip == NULL || evt->sip->cseq == NULL)    return NULL;  if (EVT_IS_INCOMINGMSG (evt))    {      if (MSG_IS_REQUEST (evt->sip))	{	  if (0 == strcmp (evt->sip->cseq->method, "INVITE")	      || 0 == strcmp (evt->sip->cseq->method, "ACK"))	    {	      transactions = osip->osip_ist_transactions;#ifdef OSIP_MT	      mut = ist_fastmutex;#endif	    }	  else	    {	      transactions = osip->osip_nist_transactions;#ifdef OSIP_MT	      mut = nist_fastmutex;#endif	    }	}      else	{	  if (0 == strcmp (evt->sip->cseq->method, "INVITE")	      || 0 == strcmp (evt->sip->cseq->method, "ACK"))	    {	      transactions = osip->osip_ict_transactions;#ifdef OSIP_MT	      mut = ict_fastmutex;#endif	    }	  else	    {	      transactions = osip->osip_nict_transactions;#ifdef OSIP_MT	      mut = nict_fastmutex;#endif	    }	}    }  else if (EVT_IS_OUTGOINGMSG (evt))    {      if (MSG_IS_RESPONSE (evt->sip))	{	  if (0 == strcmp (evt->sip->cseq->method, "INVITE")	      || 0 == strcmp (evt->sip->cseq->method, "ACK"))	    {	      transactions = osip->osip_ist_transactions;#ifdef OSIP_MT	      mut = ist_fastmutex;#endif	    }	  else	    {	      transactions = osip->osip_nist_transactions;#ifdef OSIP_MT	      mut = nist_fastmutex;#endif	    }	}      else	{	  if (0 == strcmp (evt->sip->cseq->method, "INVITE")	      || 0 == strcmp (evt->sip->cseq->method, "ACK"))	    {	      transactions = osip->osip_ict_transactions;#ifdef OSIP_MT	      mut = ict_fastmutex;#endif	    }	  else	    {	      transactions = osip->osip_nict_transactions;#ifdef OSIP_MT	      mut = nict_fastmutex;#endif	    }	}    }  if (transactions == NULL)    return NULL;		/* not a message??? */#ifdef OSIP_MT  osip_mutex_lock (mut);#endif  transaction = osip_transaction_find (transactions, evt);  if (consume == 1)    {				/* we add the event before releasing the mutex!! */      if (transaction != NULL)	{	  osip_transaction_add_event (transaction, evt);#ifdef OSIP_MT	  osip_mutex_unlock (mut);#endif	  return transaction;	}    }#ifdef OSIP_MT  osip_mutex_unlock (mut);#endif  return transaction;}osip_transaction_t *osip_create_transaction (osip_t * osip, osip_event_t * evt){  osip_transaction_t *transaction;  int i;  osip_fsm_type_t ctx_type;  if (evt == NULL)    return NULL;  if (evt->sip == NULL)    return NULL;  /* make sure the request's method reflect the cseq value. */  if (MSG_IS_REQUEST (evt->sip))    {      /* delete request where cseq method does not match         the method in request-line */      if (evt->sip->cseq == NULL	  || evt->sip->cseq->method == NULL || evt->sip->sip_method == NULL)	{	  return NULL;	}      if (0 != strcmp (evt->sip->cseq->method, evt->sip->sip_method))	{	  OSIP_TRACE (osip_trace		      (__FILE__, __LINE__, OSIP_WARNING, NULL,		       "core module: Discard invalid message with method!=cseq!\n"));	  return NULL;	}    }  if (MSG_IS_ACK (evt->sip))	/* ACK never create transactions */    return NULL;  if (EVT_IS_INCOMINGREQ (evt))    {      /* we create a new context for this incoming request */      if (0 == strcmp (evt->sip->cseq->method, "INVITE"))	ctx_type = IST;      else	ctx_type = NIST;    }  else if (EVT_IS_OUTGOINGREQ (evt))    {      if (0 == strcmp (evt->sip->cseq->method, "INVITE"))	ctx_type = ICT;      else	ctx_type = NICT;    }  else    {      OSIP_TRACE (osip_trace		  (__FILE__, __LINE__, OSIP_ERROR, NULL,		   "Cannot build a transction for this message!\n"));      return NULL;    }  i = osip_transaction_init (&transaction, ctx_type, osip, evt->sip);  if (i == -1)    {      return NULL;    }  evt->transactionid = transaction->transactionid;  return transaction;}osip_transaction_t *osip_transaction_find (osip_list_t * transactions, osip_event_t * evt){  int pos = 0;  osip_transaction_t *transaction;  if (EVT_IS_INCOMINGREQ (evt))    {      while (!osip_list_eol (transactions, pos))	{	  transaction =	    (osip_transaction_t *) osip_list_get (transactions, pos);	  if (0 ==	      __osip_transaction_matching_request_osip_to_xist_17_2_3	      (transaction, evt->sip))	    return transaction;	  pos++;	}    }  else if (EVT_IS_INCOMINGRESP (evt))    {      while (!osip_list_eol (transactions, pos))	{	  transaction =	    (osip_transaction_t *) osip_list_get (transactions, pos);	  if (0 ==	      __osip_transaction_matching_response_osip_to_xict_17_1_3	      (transaction, evt->sip))	    return transaction;	  pos++;	}    }  else				/* handle OUTGOING message */    {				/* THE TRANSACTION ID MUST BE SET */      while (!osip_list_eol (transactions, pos))	{	  transaction =	    (osip_transaction_t *) osip_list_get (transactions, pos);	  if (transaction->transactionid == evt->transactionid)	    return transaction;	  pos++;	}    }  return NULL;}static int ref_count = 0;#ifdef OSIP_MTstatic struct osip_mutex *ref_mutex = NULL;#endifstatic intincrease_ref_count (void){#ifdef OSIP_MT  if (ref_count == 0)    ref_mutex = osip_mutex_init ();  /* Here we should assert() that the mutex was really generated. */  osip_mutex_lock (ref_mutex);#endif  if (ref_count == 0)    __osip_global_init ();  ref_count++;#ifdef OSIP_MT  osip_mutex_unlock (ref_mutex);#endif  return 0;}static voiddecrease_ref_count (void){#ifdef OSIP_MT  osip_mutex_lock (ref_mutex);#endif  /* assert (ref_count > 0); */  ref_count--;  if (ref_count == 0)    {#ifdef OSIP_MT      osip_mutex_unlock (ref_mutex);      osip_mutex_destroy (ref_mutex);#endif      __osip_global_free ();      return;    }#ifdef OSIP_MT  osip_mutex_unlock (ref_mutex);#endif}intosip_init (osip_t ** osip){  if (increase_ref_count () != 0)    return -1;  *osip = (osip_t *) osip_malloc (sizeof (osip_t));  if (*osip == NULL)    return -1;			/* allocation failed */  memset (*osip, 0, sizeof (osip_t));  (*osip)->osip_ict_transactions =    (osip_list_t *) osip_malloc (sizeof (osip_list_t));  osip_list_init ((*osip)->osip_ict_transactions);  (*osip)->osip_ist_transactions =    (osip_list_t *) osip_malloc (sizeof (osip_list_t));  osip_list_init ((*osip)->osip_ist_transactions);  (*osip)->osip_nict_transactions =    (osip_list_t *) osip_malloc (sizeof (osip_list_t));  osip_list_init ((*osip)->osip_nict_transactions);  (*osip)->osip_nist_transactions =    (osip_list_t *) osip_malloc (sizeof (osip_list_t));  osip_list_init ((*osip)->osip_nist_transactions);#ifdef OSIP_RETRANSMIT_2XX  (*osip)->ixt_retransmissions =    (osip_list_t *) osip_malloc (sizeof (osip_list_t));  osip_list_init ((*osip)->ixt_retransmissions);#else  (*osip)->ixt_retransmissions = NULL;#endif  return 0;}voidosip_release (osip_t * osip){  osip_free (osip->osip_ict_transactions);  osip_free (osip->osip_ist_transactions);  osip_free (osip->osip_nict_transactions);  osip_free (osip->osip_nist_transactions);#ifdef OSIP_RETRANSMIT_2XX  osip_free (osip->ixt_retransmissions);#endif  osip_free (osip);  decrease_ref_count ();}voidosip_set_application_context (osip_t * osip, void *pointer){  osip->application_context = pointer;}void *osip_get_application_context (osip_t * osip){  if (osip == NULL)    return NULL;  return osip->application_context;}int

⌨️ 快捷键说明

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