コード例 #1
0
ファイル: osip_dialog.c プロジェクト: smx-smx/dsl-n55u
int
osip_dialog_match_as_uac (osip_dialog_t * dlg, osip_message_t * answer)
{
    osip_generic_param_t *tag_param_local;
    osip_generic_param_t *tag_param_remote;
    char *tmp;
    int i;

    osip_call_id_to_str (answer->call_id, &tmp);
    if (0 != strcmp (dlg->call_id, tmp))
    {
        osip_free (tmp);
        return -1;
    }
    osip_free (tmp);

    /* for INCOMING RESPONSE:
       To: remote_uri;remote_tag
       From: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
     */
    i = osip_from_get_tag (answer->from, &tag_param_local);
    if (i != 0)
        return -1;
    if (dlg->local_tag == NULL)
        /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */
        return -1;
    if (0 != strcmp (tag_param_local->gvalue, dlg->local_tag))
        return -1;

    i = osip_to_get_tag (answer->to, &tag_param_remote);
    if (i != 0 && dlg->remote_tag != NULL)	/* no tag in response but tag in dialog */
        return -1;			/* impossible... */
    if (i != 0 && dlg->remote_tag == NULL)	/* no tag in response AND no tag in dialog */
    {
        if (0 ==
                osip_from_compare ((osip_from_t *) dlg->local_uri, (osip_from_t *) answer->from)
                && 0 == osip_from_compare (dlg->remote_uri, answer->to))
            return 0;
        return -1;
    }

    /* we don't have to compare
       remote_uri with from
       && local_uri with to.    ----> we have both tag recognized, it's enough..
     */
    if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag))
        return 0;
    return -1;
}
コード例 #2
0
ファイル: GB_parser.c プロジェクト: github188/Decoder_GB
int GB_handle_RCV_REQACK(GB_CONNECT_STATE *gb_cons, osip_event_t * osip_event)
{
	GB_media_session media_session;	
	int chn = -1;
	osip_uri_param_t *tag = NULL;
	
	SN_MEMSET(&media_session,0,sizeof(media_session));

	if(gb_cons == NULL || osip_event == NULL || osip_event->sip == NULL || osip_event->sip->to == NULL || 
		osip_event->sip->to->url == NULL || osip_event->sip->to->url->username == NULL ||
		osip_event->sip->from == NULL || osip_event->sip->from->url == NULL ||
		osip_event->sip->from->url->username == NULL)
	{
		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d Something is NULL\n",__FUNCTION__,__LINE__);
		return -1;
	}
	
	DeviceID2LocalChn(osip_event->sip->to->url->username,&chn);

	TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d ACK from:%s  to:%s\n",__FUNCTION__,__LINE__,
				osip_event->sip->from->url->username,osip_event->sip->to->url->username);

	if(chn <= 0)
	{
		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  Unknow DeviceID(%s)\n",__FUNCTION__,osip_event->sip->to->url->username);
	}
	else
	{
		osip_from_get_tag(osip_event->sip->from,&tag);

		if(tag == NULL || tag->gvalue == NULL)
		{
			TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  Can't Find Tag!\n",__FUNCTION__);
		}
		else
		{
			media_session.chn = chn - 1;
			media_session.media_session_opt = MEDIA_SESSION_OPT_ACK;
			SN_STRCPY(media_session.TagID,sizeof(media_session.TagID),tag->gvalue);

			write(gb_msg_sock.client_fd, (void *)&media_session, sizeof(media_session));			
		}
	}
	return 0;
}
static int
__osip_dialog_init (osip_dialog_t ** dialog, osip_message_t * invite, osip_message_t * response, osip_from_t * local, osip_to_t * remote, osip_message_t * remote_msg)
{
  int i;
  int pos;
  osip_generic_param_t *tag;

  *dialog = NULL;
  if (response == NULL)
    return OSIP_BADPARAMETER;
  if (response->cseq == NULL || local == NULL || remote == NULL)
    return OSIP_SYNTAXERROR;

  (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t));
  if (*dialog == NULL)
    return OSIP_NOMEM;

  memset (*dialog, 0, sizeof (osip_dialog_t));
  (*dialog)->your_instance = NULL;

  if (MSG_IS_STATUS_2XX (response))
    (*dialog)->state = DIALOG_CONFIRMED;
  else                          /* 1XX */
    (*dialog)->state = DIALOG_EARLY;

  i = osip_call_id_to_str (response->call_id, &((*dialog)->call_id));
  if (i != 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n"));
    osip_dialog_free (*dialog);
    *dialog = NULL;
    return i;
  }

  i = osip_to_get_tag (local, &tag);
  if (i != 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n"));
    osip_dialog_free (*dialog);
    *dialog = NULL;
    return i;
  }

  (*dialog)->local_tag = osip_strdup (tag->gvalue);

  i = osip_from_get_tag (remote, &tag);
  if (i == 0)
    (*dialog)->remote_tag = osip_strdup (tag->gvalue);

  /* VR-2785: remember line value */
  if (invite) {
    osip_uri_param_t *line_param;

    i = osip_uri_param_get_byname (&invite->req_uri->url_params, "line", &line_param);
    if (i == 0 && line_param != NULL && line_param->gvalue != NULL)
      (*dialog)->line_param = osip_strdup (line_param->gvalue);
  }

  osip_list_init (&(*dialog)->route_set);

  pos = 0;
  while (!osip_list_eol (&response->record_routes, pos)) {
    osip_record_route_t *rr;
    osip_record_route_t *rr2;

    rr = (osip_record_route_t *) osip_list_get (&response->record_routes, pos);
    i = osip_record_route_clone (rr, &rr2);
    if (i != 0) {
      OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n"));
      osip_dialog_free (*dialog);
      *dialog = NULL;
      return i;
    }
    if (invite == NULL)
      osip_list_add (&(*dialog)->route_set, rr2, 0);
    else
      osip_list_add (&(*dialog)->route_set, rr2, -1);

    pos++;
  }

  /* local_cseq is set to response->cseq->number for better
     handling of bad UA */
  (*dialog)->local_cseq = osip_atoi (response->cseq->number);

  i = osip_from_clone (remote, &((*dialog)->remote_uri));
  if (i != 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n"));
    osip_dialog_free (*dialog);
    *dialog = NULL;
    return i;
  }

  i = osip_to_clone (local, &((*dialog)->local_uri));
  if (i != 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n"));
    osip_dialog_free (*dialog);
    *dialog = NULL;
    return i;
  }

  {
    osip_contact_t *contact;

    if (!osip_list_eol (&remote_msg->contacts, 0)) {
      contact = osip_list_get (&remote_msg->contacts, 0);
      i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri));
      if (i != 0) {
        OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n"));
        osip_dialog_free (*dialog);
        *dialog = NULL;
        return i;
      }
    }
    else {
      (*dialog)->remote_contact_uri = NULL;
      OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a contact in remote message!\n"));
    }
  }
  (*dialog)->secure = -1;       /* non secure */

  return OSIP_SUCCESS;
}
int
osip_dialog_match_as_uas (osip_dialog_t * dlg, osip_message_t * request)
{
  osip_generic_param_t *tag_param_remote;
  int i;
  char *tmp;

  if (dlg == NULL || dlg->call_id == NULL)
    return OSIP_BADPARAMETER;
  if (request == NULL || request->call_id == NULL || request->from == NULL || request->to == NULL)
    return OSIP_BADPARAMETER;

  osip_call_id_to_str (request->call_id, &tmp);
  if (0 != strcmp (dlg->call_id, tmp)) {
    osip_free (tmp);
    return OSIP_UNDEFINED_ERROR;
  }
  osip_free (tmp);

  /* for INCOMING REQUEST:
     To: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
     From: remote_uri;remote_tag
   */

  if (dlg->local_tag == NULL)
    /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */
    return OSIP_SYNTAXERROR;

#if 0
  /* VR-2785: use line param to distinguish between two registrations by the same user */
  if (dlg->line_param) {
    osip_uri_param_t *line_param;

    i = osip_uri_param_get_byname (&request->req_uri->url_params, "line", &line_param);
    if (i == 0 && strcmp (dlg->line_param, line_param->gvalue))
      return OSIP_UNDEFINED_ERROR;      /* both dlg and req_uri have line params and they do not match */
  }
#endif

  i = osip_from_get_tag (request->from, &tag_param_remote);
  if (i != 0 && dlg->remote_tag != NULL)        /* no tag in request but tag in dialog */
    return OSIP_SYNTAXERROR;    /* impossible... */
  if (i != 0 && dlg->remote_tag == NULL) {      /* no tag in request AND no tag in dialog */
    if (0 == osip_from_compare ((osip_from_t *) dlg->remote_uri, (osip_from_t *) request->from)
        && 0 == osip_from_compare (dlg->local_uri, request->to))
      return OSIP_SUCCESS;
    return OSIP_UNDEFINED_ERROR;
  }

  if (dlg->remote_tag == NULL) {        /* tag in response BUT no tag in dialog */
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a tag in To feilds!\n"));
    if (0 == osip_from_compare ((osip_from_t *) dlg->remote_uri, (osip_from_t *) request->from)
        && 0 == osip_from_compare (dlg->local_uri, request->to))
      return OSIP_SUCCESS;
    return OSIP_UNDEFINED_ERROR;
  }
  /* we don't have to compare
     remote_uri with from
     && local_uri with to.    ----> we have both tag recognized, it's enough..
   */
  if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag))
    return OSIP_SUCCESS;

  return OSIP_UNDEFINED_ERROR;
}
int
osip_dialog_match_as_uac (osip_dialog_t * dlg, osip_message_t * answer)
{
  osip_generic_param_t *tag_param_local;
  osip_generic_param_t *tag_param_remote;
  char *tmp;
  int i;

  if (dlg == NULL || dlg->call_id == NULL)
    return OSIP_BADPARAMETER;
  if (answer == NULL || answer->call_id == NULL || answer->from == NULL || answer->to == NULL)
    return OSIP_BADPARAMETER;

  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Using this method is discouraged. See source code explanations!\n"));
  /*
     When starting a new transaction and when receiving several answers,
     you must be prepared to receive several answers from different sources.
     (because of forking).

     Because some UAs are not compliant (a to tag is missing!), this method
     may match the wrong dialog when a dialog has been created with an empty
     tag in the To header.

     Personnaly, I would recommend to discard 1xx>=101 answers without To tags!
     Just my own feelings.
   */
  osip_call_id_to_str (answer->call_id, &tmp);
  if (0 != strcmp (dlg->call_id, tmp)) {
    osip_free (tmp);
    return OSIP_UNDEFINED_ERROR;
  }
  osip_free (tmp);

  /* for INCOMING RESPONSE:
     To: remote_uri;remote_tag
     From: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
   */
  i = osip_from_get_tag (answer->from, &tag_param_local);
  if (i != 0)
    return OSIP_SYNTAXERROR;
  if (dlg->local_tag == NULL)
    /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */
    return OSIP_SYNTAXERROR;
  if (0 != strcmp (tag_param_local->gvalue, dlg->local_tag))
    return OSIP_UNDEFINED_ERROR;

  i = osip_to_get_tag (answer->to, &tag_param_remote);
  if (i != 0 && dlg->remote_tag != NULL)        /* no tag in response but tag in dialog */
    return OSIP_SYNTAXERROR;    /* impossible... */
  if (i != 0 && dlg->remote_tag == NULL) {      /* no tag in response AND no tag in dialog */
    if (0 == osip_from_compare ((osip_from_t *) dlg->local_uri, (osip_from_t *) answer->from)
        && 0 == osip_from_compare (dlg->remote_uri, answer->to))
      return OSIP_SUCCESS;
    return OSIP_UNDEFINED_ERROR;
  }

  if (dlg->remote_tag == NULL) {        /* tag in response BUT no tag in dialog */
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a tag in To fields!\n"));
    if (0 == osip_from_compare ((osip_from_t *) dlg->local_uri, (osip_from_t *) answer->from)
        && 0 == osip_from_compare (dlg->remote_uri, answer->to))
      return OSIP_SUCCESS;
    return OSIP_UNDEFINED_ERROR;
  }

  /* we don't have to compare
     remote_uri with from
     && local_uri with to.    ----> we have both tag recognized, it's enough..
   */
  if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag))
    return OSIP_SUCCESS;
  return OSIP_UNDEFINED_ERROR;
}
コード例 #6
0
ファイル: GB_parser.c プロジェクト: github188/Decoder_GB
int GB_handle_RCV_REQUEST(GB_CONNECT_STATE *gb_cons, osip_event_t * osip_event)
{
	osip_body_t *mbody = NULL;
	int pos = 0;	
	int code = -1;
	void *Req = NULL;	

	if(gb_cons == NULL || osip_event == NULL || osip_event->sip == NULL || osip_event->sip->sip_method == NULL)
	{
		return -1;
	}
	
	if(strcmp(osip_event->sip->sip_method, GB_SIP_METHOD_MESSAGE) == 0)
	{
		osip_message_get_body(osip_event->sip, pos, &mbody);
		pos++;

		if(mbody == NULL || mbody->body == NULL)
		{
			GB_Send_Reply(gb_cons,osip_event,400);
			return -1;
		}
		
		gb_parser_Req_XML(mbody->body, &code, &Req);

		switch(code)
		{
			case Code_Query_Req:
			{
				GB_Deal_Query_Req(gb_cons, osip_event, (gb_Query_Req_Struct *)Req);
				GB_Free_Query_Req((gb_Query_Req_Struct *)Req);
			}
			break;

			case Code_Control_Req:
			{
				GB_Deal_Control_Req(gb_cons, osip_event, (gb_Control_Req_Struct *) Req);
				GB_Free_Control_Req((gb_Control_Req_Struct *) Req);
			}
			break;

			default:
			{
			}
			break;
		}

		return 0;
	}
	else if(strcmp(osip_event->sip->sip_method, GB_SIP_METHOD_BYE) == 0)
	{
		GB_media_session media_session;	
		int chn = -1;
		osip_uri_param_t *tag = NULL;
		
		SN_MEMSET(&media_session,0,sizeof(media_session));

		if(osip_event->sip->to == NULL || osip_event->sip->to->url == NULL || osip_event->sip->to->url->username == NULL
			|| osip_event->sip->from == NULL || osip_event->sip->from->url == NULL ||
				osip_event->sip->from->url->username == NULL)
		{
			TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d Something is NULL\n",__FUNCTION__,__LINE__);
			return -1;
		}
		
		DeviceID2LocalChn(osip_event->sip->to->url->username,&chn);

		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d BYE from:%s  to:%s\n",__FUNCTION__,__LINE__,
				osip_event->sip->from->url->username,osip_event->sip->to->url->username);

		if(chn <= 0)
		{
			TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  Unknow DeviceID(%s)\n",__FUNCTION__,osip_event->sip->req_uri->username);
		}
		else
		{		
			osip_from_get_tag(osip_event->sip->from,&tag);

			if(tag == NULL || tag->gvalue == NULL)
			{
				TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  Can't Find Tag!\n",__FUNCTION__);
				GB_Send_Reply(gb_cons,osip_event,400);
		
				return 0;
			}
			else
			{
				media_session.chn = chn - 1;
				media_session.media_session_opt = MEDIA_SESSION_OPT_BYE;
				SN_STRCPY(media_session.TagID,sizeof(media_session.TagID),tag->gvalue);

				write(gb_msg_sock.client_fd, (void *)&media_session, sizeof(media_session));				
			}
		}

		GB_Send_Reply(gb_cons,osip_event,200);
		
		return 0;
	}

	
	GB_Send_Reply(gb_cons,osip_event,400);
	return 0;
}
コード例 #7
0
ファイル: GB_parser.c プロジェクト: github188/Decoder_GB
int GB_handle_RCV_REQINVITE(GB_CONNECT_STATE *gb_cons, osip_event_t * osip_event, int *flag)
{
	int ret = -1;
	osip_message_t *rsp = NULL;
	char *result = NULL;
	size_t length;
	int status_code = 200;
	char sdpStr_response[1024] = {0};
	char *pRsp = NULL;
//	struct sipd_media_session sdpInfo;
	GB_media_session media_session;
	int chn = -1;
	PRM_GB_SIPD_CFG gb_cfg;
	osip_uri_param_t *tag = NULL;
	
//	SN_MEMSET(&sdpInfo,0,sizeof(sdpInfo));
	SN_MEMSET(&media_session,0,sizeof(media_session));
	SN_MEMSET(&gb_cfg,0,sizeof(gb_cfg));

	GB_Get_GBCfg(&gb_cfg);

	if(gb_cons == NULL || osip_event == NULL || osip_event->sip == NULL || 
		osip_event->sip->req_uri == NULL || osip_event->sip->req_uri->username == NULL ||
		osip_event->sip->from == NULL || osip_event->sip->from->url == NULL || 
		osip_event->sip->from->url->username == NULL)
	{
		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d Something is NULL\n",__FUNCTION__,__LINE__);
		return -1;
	}
	
	DeviceID2LocalChn(osip_event->sip->req_uri->username,&chn);

	TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d INVITE from:%s  to:%s\n",__FUNCTION__,__LINE__,
			osip_event->sip->from->url->username,osip_event->sip->req_uri->username);
	
	if(chn <= 0)
	{
		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  Unknow DeviceID(%s)\n",__FUNCTION__,osip_event->sip->req_uri->username);
		status_code = 404;  // 没找到
		pRsp = NULL;
	}
	else
	{
		// 流量控制判断等接口调用

		osip_from_get_tag(osip_event->sip->from,&tag);

		if(tag == NULL || tag->gvalue == NULL)
		{
			status_code = 400;  // 错误的请求
			pRsp = NULL;
		}
		else
		{
			media_session.chn = chn - 1;
			media_session.media_session_opt = MEDIA_SESSION_OPT_INVITE;
			SN_STRCPY(media_session.TagID,sizeof(media_session.TagID),tag->gvalue);
						
			write(gb_msg_sock.client_fd, (void *)&media_session, sizeof(media_session));

			snprintf(sdpStr_response,1024,
			"v=0\r\n"\
			"o=34020000001330000001 0 0 IN IP4 %s\r\n"\
			"s=Play\r\n"\
			"c=IN IP4 %s\r\n"\
			"t=0 0\r\n"\
			"m=video %d RTP/AVP 96\r\n"\
			"a=recvonly\r\n"\
			"a=rtpmap:96 PS/90000\r\n"\
			"y=0100000001\r\n"\
			"f=\r\n",
			GB_Get_LocalIP(), GB_Get_LocalIP(),LISTEN_PORT);

			ret = 0;
			if(ret == 0)
			{
				pRsp = sdpStr_response;
			}
			else
			{
				pRsp = NULL;
				status_code = 488;  // 这里不能接受 
			}
		}
	}
	
	ret = gb_build_response_message(&rsp, NULL, status_code,osip_event->sip, GB_MANSCDP_SDP,pRsp,SN_STRLEN(sdpStr_response));

	if(ret < 0)
	{
		osip_message_free (rsp);
		printf("%s  line=%d\n",__FUNCTION__,__LINE__);
		return -1;
	}

	gb_build_response_Contact(rsp, GB_Get_LocalIP(), gb_cfg.local_port, (char *)(gb_cfg.deviceID));

	ret = osip_message_to_str(rsp, &result, &length);

	if (ret == -1) 
	{
		printf("ERROR: failed while printing message!\n");
		osip_message_free (rsp);
		return -1;
	}	
	
	GB_SocketSendData(gb_cons->connfd,inet_ntoa(gb_cons->remoteAddr.sin_addr), ntohs(gb_cons->remoteAddr.sin_port), result, length, 0);
	SN_FREE(result);
	osip_message_free(rsp);

	return 0;
}
コード例 #8
0
ファイル: osip_dialog.c プロジェクト: smx-smx/dsl-n55u
int
osip_dialog_init_as_uas (osip_dialog_t ** dialog, osip_message_t * invite, osip_message_t * response)
{
    int i;
    int pos;
    osip_generic_param_t *tag;

    (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t));
    if (*dialog == NULL)
        return -1;

    (*dialog)->type = CALLEE;
    if (MSG_IS_STATUS_2XX (response))
        (*dialog)->state = DIALOG_CONFIRMED;
    else				/* 1XX */
        (*dialog)->state = DIALOG_EARLY;

    i = osip_call_id_to_str (response->call_id, &((*dialog)->call_id));
    if (i != 0)
        goto diau_error_0;

    i = osip_to_get_tag (response->to, &tag);
    if (i != 0)
        goto diau_error_1;
    (*dialog)->local_tag = osip_strdup (tag->gvalue);

    i = osip_from_get_tag (response->from, &tag);
    if (i != 0)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_WARNING, NULL,
                     "Remote UA is not compliant: missing a tag in response!\n"));
        (*dialog)->remote_tag = NULL;
    }
    else
        (*dialog)->remote_tag = osip_strdup (tag->gvalue);

    (*dialog)->route_set = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
    osip_list_init ((*dialog)->route_set);

    pos = 0;
    while (!osip_list_eol (response->record_routes, pos))
    {
        osip_record_route_t *rr;
        osip_record_route_t *rr2;

        rr = (osip_record_route_t *) osip_list_get (response->record_routes, pos);
        i = osip_record_route_clone (rr, &rr2);
        if (i != 0)
            goto diau_error_2;
        osip_list_add ((*dialog)->route_set, rr2, -1);
        pos++;
    }

    /* local_cseq is set to response->cseq->number for better
       handling of bad UA */
    (*dialog)->local_cseq = osip_atoi (response->cseq->number);
    (*dialog)->remote_cseq = osip_atoi (response->cseq->number);


    i = osip_from_clone (response->from, &((*dialog)->remote_uri));
    if (i != 0)
        goto diau_error_3;

    i = osip_to_clone (response->to, &((*dialog)->local_uri));
    if (i != 0)
        goto diau_error_4;

    {
        osip_contact_t *contact;

        if (!osip_list_eol (invite->contacts, 0))
        {
            contact = osip_list_get (invite->contacts, 0);
            i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri));
            if (i != 0)
                goto diau_error_5;
        }
        else
        {
            (*dialog)->remote_contact_uri = NULL;
            OSIP_TRACE (osip_trace
                        (__FILE__, __LINE__, OSIP_WARNING, NULL,
                         "Remote UA is not compliant: missing a contact in response!\n"));
        }
    }
    (*dialog)->secure = -1;	/* non secure */

    return 0;

diau_error_5:
    osip_from_free ((*dialog)->local_uri);
diau_error_4:
    osip_from_free ((*dialog)->remote_uri);
diau_error_3:
diau_error_2:
    osip_list_special_free ((*dialog)->route_set,
                            (void *(*)(void *)) &osip_record_route_free);
    osip_free ((*dialog)->remote_tag);
    osip_free ((*dialog)->local_tag);
diau_error_1:
    osip_free ((*dialog)->call_id);
diau_error_0:
    OSIP_TRACE (osip_trace
                (__FILE__, __LINE__, OSIP_ERROR, NULL,
                 "Could not establish dialog!\n"));
    osip_free (*dialog);
    *dialog = NULL;
    return -1;
}
コード例 #9
0
ファイル: osip_dialog.c プロジェクト: smx-smx/dsl-n55u
    /* we don't have to compare
       remote_uri with from
       && local_uri with to.    ----> we have both tag recognized, it's enough..
     */
    if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag))
        return 0;

    return -1;
}

int
osip_dialog_init_as_uac (osip_dialog_t ** dialog, osip_message_t * response)
{
    int i;
    int pos;
    osip_generic_param_t *tag;

    *dialog = NULL;
    i = osip_to_get_tag (response->to, &tag);
    if (i != 0)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_WARNING, NULL,
                     "Remote UA is not compliant: missing a tag in response!\n"));
        return -1;
    }

    (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t));
    if (*dialog == NULL)
        return -1;

    (*dialog)->type = CALLER;
    if (MSG_IS_STATUS_2XX (response))
        (*dialog)->state = DIALOG_CONFIRMED;
    else				/* 1XX */
        (*dialog)->state = DIALOG_EARLY;

    i = osip_call_id_to_str (response->call_id, &((*dialog)->call_id));
    if (i != 0)
        goto diau_error_0;

    i = osip_from_get_tag (response->from, &tag);
    if (i != 0)
        goto diau_error_1;
    (*dialog)->local_tag = osip_strdup (tag->gvalue);

    i = osip_to_get_tag (response->to, &tag);
    if (i != 0)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_WARNING, NULL,
                     "Remote UA is not compliant: missing a tag in response!\n"));
        (*dialog)->remote_tag = NULL;
    }
    else
        (*dialog)->remote_tag = osip_strdup (tag->gvalue);

    (*dialog)->route_set = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
    osip_list_init ((*dialog)->route_set);

    pos = 0;
    while (!osip_list_eol (response->record_routes, pos))
    {
        osip_record_route_t *rr;
        osip_record_route_t *rr2;

        rr = (osip_record_route_t *) osip_list_get (response->record_routes, pos);
        i = osip_record_route_clone (rr, &rr2);
        if (i != 0)
            goto diau_error_2;
        osip_list_add ((*dialog)->route_set, rr2, -1);
        pos++;
    }

    (*dialog)->local_cseq = osip_atoi (response->cseq->number);
    (*dialog)->remote_cseq = -1;

    i = osip_to_clone (response->to, &((*dialog)->remote_uri));
    if (i != 0)
        goto diau_error_3;

    i = osip_from_clone (response->from, &((*dialog)->local_uri));
    if (i != 0)
        goto diau_error_4;

    {
        osip_contact_t *contact;

        if (!osip_list_eol (response->contacts, 0))
        {
            contact = osip_list_get (response->contacts, 0);
            i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri));
            if (i != 0)
                goto diau_error_5;
        }
        else
        {
            (*dialog)->remote_contact_uri = NULL;
            OSIP_TRACE (osip_trace
                        (__FILE__, __LINE__, OSIP_WARNING, NULL,
                         "Remote UA is not compliant: missing a contact in response!\n"));
        }
    }
    (*dialog)->secure = -1;	/* non secure */

    return 0;

diau_error_5:
    osip_from_free ((*dialog)->local_uri);
diau_error_4:
    osip_from_free ((*dialog)->remote_uri);
diau_error_3:
diau_error_2:
    osip_list_special_free ((*dialog)->route_set,
                            (void *(*)(void *)) &osip_record_route_free);
    osip_free ((*dialog)->remote_tag);
    osip_free ((*dialog)->local_tag);
diau_error_1:
    osip_free ((*dialog)->call_id);
diau_error_0:
    OSIP_TRACE (osip_trace
                (__FILE__, __LINE__, OSIP_ERROR, NULL,
                 "Could not establish dialog!\n"));
    osip_free (*dialog);
    *dialog = NULL;
    return -1;
}

#if 1 /* SIPIT13 */
int
osip_dialog_init_as_uac_with_remote_request (osip_dialog_t ** dialog, osip_message_t *next_request, int local_cseq)
{
    int i;
    osip_generic_param_t *tag;

    *dialog = NULL;
    i = osip_to_get_tag (next_request->from, &tag);
    if (i != 0)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_WARNING, NULL,
                     "Remote UA is not compliant: missing a tag in next request!\n"));
        return -1;
    }

    (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t));
    if (*dialog == NULL)
        return -1;

    (*dialog)->type = CALLER;
#if 0
    (*dialog)->state = DIALOG_CONFIRMED;
#endif
    (*dialog)->state = DIALOG_EARLY;

    i = osip_call_id_to_str (next_request->call_id, &((*dialog)->call_id));
    if (i != 0)
        goto diau_error_0;

    i = osip_from_get_tag (next_request->to, &tag);
    if (i != 0)
        goto diau_error_1;
    (*dialog)->local_tag = osip_strdup (tag->gvalue);

    i = osip_to_get_tag (next_request->from, &tag);
    if (i != 0)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_WARNING, NULL,
                     "Remote UA is not compliant: missing a tag in next request!\n"));
        (*dialog)->remote_tag = NULL;
    }
    else
        (*dialog)->remote_tag = osip_strdup (tag->gvalue);

    (*dialog)->route_set = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
    osip_list_init ((*dialog)->route_set);

    (*dialog)->local_cseq = local_cseq; /* -1 osip_atoi (xxx->cseq->number); */
    (*dialog)->remote_cseq = osip_atoi (next_request->cseq->number);

    i = osip_to_clone (next_request->from, &((*dialog)->remote_uri));
    if (i != 0)
        goto diau_error_3;

    i = osip_from_clone (next_request->to, &((*dialog)->local_uri));
    if (i != 0)
        goto diau_error_4;

    (*dialog)->secure = -1;	/* non secure */

    return 0;

diau_error_4:
    osip_from_free ((*dialog)->remote_uri);
diau_error_3:
    osip_free ((*dialog)->remote_tag);
    osip_free ((*dialog)->local_tag);
diau_error_1:
    osip_free ((*dialog)->call_id);
diau_error_0:
    OSIP_TRACE (osip_trace
                (__FILE__, __LINE__, OSIP_ERROR, NULL,
                 "Could not establish dialog!\n"));
    osip_free (*dialog);
    *dialog = NULL;
    return -1;
}
コード例 #10
0
ファイル: osip_dialog.c プロジェクト: gabrieldelsaint/UIM
int
osip_dialog_match_as_uas (osip_dialog_t * dlg, osip_message_t * request)
{
  osip_generic_param_t *tag_param_remote;
  int i;
  char *tmp;

  if (dlg == NULL)
    return -1;
  if (request == NULL || request->call_id == NULL ||
      request->from == NULL || request->to == NULL)
    return -1;

  osip_call_id_to_str (request->call_id, &tmp);
  if (0 != strcmp (dlg->call_id, tmp))
    {
      osip_free (tmp);
      return -1;
    }
  osip_free (tmp);

  /* for INCOMING REQUEST:
     To: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
     From: remote_uri;remote_tag
   */

  if (dlg->local_tag == NULL)
    /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */
    return -1;

  i = osip_from_get_tag (request->from, &tag_param_remote);
  if (i != 0 && dlg->remote_tag != NULL)        /* no tag in request but tag in dialog */
    return -1;                  /* impossible... */
  if (i != 0 && dlg->remote_tag == NULL)        /* no tag in request AND no tag in dialog */
    {
      if (0 ==
          osip_from_compare ((osip_from_t *) dlg->remote_uri,
                             (osip_from_t *) request->from)
          && 0 == osip_from_compare (dlg->local_uri, request->to))
        return 0;
      return -1;
    }

  if (dlg->remote_tag == NULL)  /* tag in response BUT no tag in dialog */
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_WARNING, NULL,
                   "Remote UA is not compliant: missing a tag in To feilds!\n"));
      if (0 ==
          osip_from_compare ((osip_from_t *) dlg->remote_uri,
                             (osip_from_t *) request->from)
          && 0 == osip_from_compare (dlg->local_uri, request->to))
        return 0;
      return -1;
    }
  /* we don't have to compare
     remote_uri with from
     && local_uri with to.    ----> we have both tag recognized, it's enough..
   */
  if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag))
    return 0;

  return -1;
}
コード例 #11
0
/*
 * SIP_CALCULATE_BRANCH
 *
 * Calculates a branch parameter according to RFC3261 section 16.11
 *
 * The returned 'id' will be HASHHEXLEN + strlen(magic_cookie)
 * characters (32 + 7) long. The caller must supply at least this
 * amount of space in 'id'.
 *
 * RETURNS
 *	STS_SUCCESS on success
 *	STS_FAILURE on error
 */
int  sip_calculate_branch_id (sip_ticket_t *ticket, char *id) {
/* RFC3261 section 16.11 recommends the following procedure:
 *   The stateless proxy MAY use any technique it likes to guarantee
 *   uniqueness of its branch IDs across transactions.  However, the
 *   following procedure is RECOMMENDED.  The proxy examines the
 *   branch ID in the topmost Via header field of the received
 *   request.  If it begins with the magic cookie, the first
 *   component of the branch ID of the outgoing request is computed
 *   as a hash of the received branch ID.  Otherwise, the first
 *   component of the branch ID is computed as a hash of the topmost
 *   Via, the tag in the To header field, the tag in the From header
 *   field, the Call-ID header field, the CSeq number (but not
 *   method), and the Request-URI from the received request.  One of
 *   these fields will always vary across two different
 *   transactions.
 *
 * The branch value will consist of:
 * - magic cookie "z9hG4bK"
 * - 1st part (unique calculated ID
 * - 2nd part (value for loop detection) <<- not yet used by siproxd
 */
   osip_message_t *sip_msg=ticket->sipmsg;
   static char *magic_cookie="z9hG4bK";
   osip_via_t *via;
   osip_uri_param_t *param=NULL;
   osip_call_id_t *call_id=NULL;
   HASHHEX hashstring;

   hashstring[0]='\0';

   /*
    * Examine topmost via and look for a magic cookie.
    * If it is there, I use THIS branch parameter as input for
    * our hash calculation
    */
   via = osip_list_get (sip_msg->vias, 0);
   if (via == NULL) {
      ERROR("have a SIP message without any via header");
      return STS_FAILURE;
   }

   param=NULL;
   osip_via_param_get_byname(via, "branch", &param);
   if (param && param->gvalue) {
      DEBUGC(DBCLASS_BABBLE, "looking for magic cookie [%s]",param->gvalue);
      if (strncmp(param->gvalue, magic_cookie,
                  strlen(magic_cookie))==0) {
         /* calculate MD5 hash */
         MD5_CTX Md5Ctx;
         HASH HA1;

         MD5Init(&Md5Ctx);
         MD5Update(&Md5Ctx, param->gvalue,
                   strlen(param->gvalue));
         MD5Final(HA1, &Md5Ctx);
         CvtHex(HA1, hashstring);

         DEBUGC(DBCLASS_BABBLE, "existing branch -> branch hash [%s]",
                hashstring);
      }
   }

   /*
    * If I don't have a branch parameter in the existing topmost via,
    * then I need:
    *   - the topmost via
    *   - the tag in the To header field
    *   - the tag in the From header field
    *   - the Call-ID header field
    *   - the CSeq number (but not method)
    *   - the Request-URI from the received request
    */
   if (hashstring[0] == '\0') {
      /* calculate MD5 hash */
      MD5_CTX Md5Ctx;
      HASH HA1;
      char *tmp;

      MD5Init(&Md5Ctx);

      /* topmost via */
      osip_via_to_str(via, &tmp);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
         osip_free(tmp);
      }
     
      /* Tag in To header */
      osip_to_get_tag(sip_msg->to, &param);
      if (param && param->gvalue) {
         MD5Update(&Md5Ctx, param->gvalue, strlen(param->gvalue));
      }

      /* Tag in From header */
      osip_from_get_tag(sip_msg->from, &param);
      if (param && param->gvalue) {
         MD5Update(&Md5Ctx, param->gvalue, strlen(param->gvalue));
      }

      /* Call-ID */
      call_id = osip_message_get_call_id(sip_msg);
      osip_call_id_to_str(call_id, &tmp);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
         osip_free(tmp);
      }

      /* CSeq number (but not method) */
      tmp = osip_cseq_get_number(sip_msg->cseq);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
      }
 
      /* Request URI */
      osip_uri_to_str(sip_msg->req_uri, &tmp);
      if (tmp) {
         MD5Update(&Md5Ctx, tmp, strlen(tmp));
         osip_free(tmp);
      }

      MD5Final(HA1, &Md5Ctx);
      CvtHex(HA1, hashstring);

      DEBUGC(DBCLASS_BABBLE, "non-existing branch -> branch hash [%s]",
             hashstring);
   }

   /* include the magic cookie */
   sprintf(id, "%s%s", magic_cookie, hashstring);

   return STS_SUCCESS;
}