Beispiel #1
0
void processSipMsg()
{
	int port;
	char host[256];
	char msg[MESSAGE_MAX_LENGTH];
	int msgLen;
	osip_event_t *sipevent;
	osip_transaction_t *transaction = NULL;
	struct sockaddr_in sa;
	int status;

	if((msgLen = networkMsgRecv(sipSock,msg,MESSAGE_MAX_LENGTH,&sa)) > 0){
		printf("processSipMsg: RECEIVED MSG\n");
		printf("%s\n",msg);
		sipevent = osip_parse(msg,msgLen);
		if((sipevent==NULL)||(sipevent->sip==NULL)){
			printf("Could not parse SIP message\n");
			osip_event_free(sipevent);
			return;
		}
	}
	osip_message_fix_last_via_header(sipevent->sip,(char *)inet_ntoa(sa.sin_addr),ntohs(sa.sin_port));
	if((status = osip_find_transaction_and_add_event(osip,sipevent)) != 0){
		printf("New transaction!\n");
		if(MSG_IS_REQUEST(sipevent->sip)){
			printf("Got New Request\n");;
		}else if(MSG_IS_RESPONSE(sipevent->sip)){
			printf("Bad Message:%s\n",msg);
			osip_event_free(sipevent);
		}else{
			printf("Unsupported message:%s\n",msg);
			osip_event_free(sipevent);
		}
	}
}
Beispiel #2
0
PPL_DECLARE (int) psp_core_event_add_sip_message (osip_event_t * evt)
{
  osip_transaction_t *transaction;
  osip_message_t *answer1xx;
  int i;

  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==NULL
	  || evt->sip->cseq->method==NULL || evt->sip->sip_method==NULL)
	{
	  osip_event_free (evt);
	  return -1;
	}
      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"));
	  osip_event_free (evt);
	  return -1;
	}
    }

  i = psp_core_find_osip_transaction_and_add_event (evt);
  if (i == 0)
    {
      psp_osip_wakeup (core->psp_osip);
      return 0;			/*evt consumed */
    }
  if (MSG_IS_REQUEST (evt->sip))
    {
      if (MSG_IS_ACK (evt->sip))
	{			/* continue as it is a new transaction... */
	  osip_route_t *route;

	  /* If a route header is present, then plugins will give
	     the correct location. */
	  osip_message_get_route (evt->sip, 0, &route);
	  if (route == NULL)
	    {
	      OSIP_TRACE (osip_trace
			  (__FILE__, __LINE__, OSIP_INFO1, NULL,
			   "core module: This is a late ACK to discard!\n"));
	      /* It can be a ACK for 200 ok, but those ACK SHOULD
	         never go through this proxy! (and should be sent to the
	         contact header of the 200ok */
#ifdef SUPPORT_FOR_BROKEN_UA
	      /* if this ACK has a request-uri that is not us,
		 forward the message there. How should I modify this
		 message?? */
	      
	      if (evt!=NULL
		  && evt->sip!=NULL
		  && evt->sip!=NULL
		  && evt->sip->req_uri!=NULL)
		{
		  if (psp_core_is_responsible_for_this_domain(evt->sip->req_uri)!=0)
		    {
		      int port = 5060;
		      if (evt->sip->req_uri->port != NULL)
			port = osip_atoi (evt->sip->req_uri->port);
		      psp_core_cb_snd_message(NULL, evt->sip,
					      evt->sip->req_uri->host,
					      port, -1);
 		    }
		}
#endif
	      osip_event_free (evt);
	      return 0;
	    }

	  OSIP_TRACE (osip_trace
		      (__FILE__, __LINE__, OSIP_INFO1, NULL,
		       "core module: This is a ACK for INVITE!\n"));
	  psp_core_event_add_sfp_inc_ack (evt->sip);
	  osip_free (evt);
	  return 0;
	}

      /* we can create the transaction and send a 1xx */
      transaction = osip_create_transaction (core->psp_osip->osip, evt);
      if (transaction == NULL)
	{
	  OSIP_TRACE (osip_trace
		      (__FILE__, __LINE__, OSIP_INFO3, NULL,
		       "core module: Could not create a transaction for this request!\n"));
	  osip_event_free (evt);
	  return -1;
	}

      /* now, all retransmissions will be handled by oSIP. */

      /* From rfc3261: (Section: 16.2)
         "Thus, a stateful proxy SHOULD NOT generate 100 (Trying) responses
         to non-INVITE requests." */
      if (MSG_IS_INVITE (evt->sip))
	{
	  i = osip_msg_build_response (&answer1xx, 100, evt->sip);
	  if (i != 0)
	    {
	      OSIP_TRACE (osip_trace
			  (__FILE__, __LINE__, OSIP_ERROR, NULL,
			   "sfp module: could not create a 100 Trying for this transaction. (discard it and let the transaction die itself)!\n"));
	      osip_event_free (evt);
	      return -1;
	    }

	  osip_transaction_add_event (transaction, evt);

	  evt = osip_new_outgoing_sipmessage (answer1xx);
	  evt->transactionid = transaction->transactionid;
	  osip_transaction_add_event (transaction, evt);
	}
      else
	osip_transaction_add_event (transaction, evt);

      psp_osip_wakeup (core->psp_osip);
      return 0;
    }
  else
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_INFO3, NULL,
		   "sfp module: No module seems to be able to forward this response!\n"));
      /* this is probably a late answer? */
      /* let's forward it! */
      i = psp_core_handle_late_answer (evt->sip);
      if (i != 0)
	{
	  osip_event_free (evt);
	  return -1;
	}
      osip_event_free (evt);
    }
  return 0;
}