Exemple #1
0
int uac_sendInvite(sessionId * id, const sip_entity* to, const alter_message * alter_m)
{// char * to, char * message, char *meessageType,char *subject
	osip_message_t *invite;
	int i;// optionnal route header
	char to_[100];
	snprintf (to_, 100,"sip:%s@%s", to->username,to->ip);
	char from_[100];
	snprintf (from_, 100,"sip:%s@%s:%s",device_info.ipc_id, device_info.ipc_ip ,device_info.ipc_port );

	i = eXosip_call_build_initial_invite (&invite,to_,from_,NULL,alter_m->subject );

	if (i != 0)
	{
	return -1;
	}
	//osip_message_set_supported (invite, "100rel");
	{
	char localip[128];
	eXosip_guess_localip (AF_INET, localip, 128);

	i=osip_message_set_body (invite, alter_m->body, strlen (alter_m->body));
	i=osip_message_set_content_type (invite, alter_m->content_type);
	}
	eXosip_lock ();
	i = eXosip_call_send_initial_invite (invite);
	eXosip_unlock ();
	//printf("invite->call_id->number:%s size:%d\n",invite->call_id->number,strlen(invite->call_id->number));
	//id->call_id=(char *)malloc(sizeof(char)*(strlen(invite->call_id->number)+1));
	int copynum=0;
	if(sizeof(id->call_id)>(strlen(invite->call_id->number)+1))
	{
		copynum=(strlen(invite->call_id->number)+1);
	}
	else
	{
		copynum=sizeof(id->call_id);
	}
	memcpy(id->call_id,invite->call_id->number,copynum);//strlen(invite->call_id->number)+1);
	//if (i > 0)
	//{
	//eXosip_call_set_reference (i, "ssss");
	//}

	return 0;

}
Exemple #2
0
int csenn_eXosip_invit(sessionId * id, char * to, char * sdpMessage, char * responseSdp)
{
	osip_message_t *invite;
	int i;// optionnal route header
	char to_[100];
	snprintf (to_, 100,"sip:%s", to);
	char from_[100];
		snprintf (from_, 100,
			"sip:%s:%s", device_info.ipc_ip ,device_info.ipc_port );
		//snprintf (tmp, 4096, "");
	/*i = eXosip_call_build_initial_invite (&invite,
			"sip:[email protected]:5060",
			"sip:[email protected]:5060",
			NULL,
			"34020000001320000001:1,34020000001180000002:1" );*/
		i = eXosip_call_build_initial_invite (&invite,
					to_,
					from_,
					NULL,
					"This is a call for a conversation" );
	//i = eXosip_call_build_initial_invite (&invite,"<sip:[email protected]>",	"<sip:[email protected]>",NULL,	"This is a call for a conversation" );
	if (i != 0)
	{
	return -1;
	}
	//osip_message_set_supported (invite, "100rel");
	{
	char tmp[4096];
	char localip[128];
	eXosip_guess_localip (AF_INET, localip, 128);
	localip[128]=device_info.ipc_ip;

	i=osip_message_set_body (invite, sdpMessage, strlen (sdpMessage));
	i=osip_message_set_content_type (invite, "APPLICATION/SDP");
	}
	eXosip_lock ();
	i = eXosip_call_send_initial_invite (invite);

	if (i > 0)
	{
	//eXosip_call_set_reference (i, "ssss");
	}
	eXosip_unlock ();
	int flag1 = 1;
	      while (flag1)
	        {
	    	  eXosip_event_t *je;
	          je = eXosip_event_wait (0, 1000);

	       if (je == NULL)
	        {
	          printf ("No response or the time is over!\n");
	          break;
	        }

	       switch (je->type)
	        {
	        case EXOSIP_CALL_INVITE:
	          printf ("a new invite reveived!\n");
	          break;
	        case EXOSIP_CALL_PROCEEDING:
	          printf ("proceeding!\n");
	          break;
	        case EXOSIP_CALL_RINGING:
	          printf ("ringing!\n");
	          //printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);
	          break;
	        case EXOSIP_CALL_ANSWERED:
	          printf ("ok! connected!\n");
	          printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);
	          id->cid=je->cid;
	          id->did=je->did;
	          osip_body_t *body;
	          osip_message_get_body (je->response, 0, &body);
	          //printf ("I get the msg is: %s\n", body->body);
	          //(*responseSdp)=(char *)malloc (body->length*sizeof(char));
	          if(body!=NULL)
	          snprintf (responseSdp, body->length,"%s", body->body);

	           //response a ack
	          osip_message_t *ack = NULL;
	          eXosip_call_build_ack (je->did, &ack);
	          eXosip_call_send_ack (je->did, ack);
	          flag1 = 0;
	          break;
	        case EXOSIP_CALL_CLOSED:
	          printf ("the other sid closed!\n");
	          break;
	        case EXOSIP_CALL_ACK:
	          printf ("ACK received!\n");
	          break;
	        default:
	          printf ("other response!\n");
	          break;
	        }
	       eXosip_event_free (je);

	        }
	return 0;

}
Exemple #3
0
int
eXosip_reg_init(eXosip_reg_t ** jr, const char *from, const char *proxy,
				const char *contact)
{
	static int r_id = 0;

	*jr = (eXosip_reg_t *) osip_malloc(sizeof(eXosip_reg_t));
	if (*jr == NULL)
		return OSIP_NOMEM;

	if (r_id == 32767)			/* keep it non-negative */
		r_id = 0;

	memset(*jr, '\0', sizeof(eXosip_reg_t));

	(*jr)->r_id = ++r_id;
	(*jr)->r_reg_period = 3600;	/* delay between registration */
	(*jr)->r_aor = osip_strdup(from);	/* sip identity */
	if ((*jr)->r_aor == NULL) {
		osip_free(*jr);
		*jr = NULL;
		return OSIP_NOMEM;
	}
	(*jr)->r_contact = osip_strdup(contact);	/* sip identity */
	(*jr)->r_registrar = osip_strdup(proxy);	/* registrar */
	if ((*jr)->r_registrar == NULL) {
		osip_free((*jr)->r_contact);
		osip_free((*jr)->r_aor);
		osip_free(*jr);
		*jr = NULL;
		return OSIP_NOMEM;
	}

	{
		osip_MD5_CTX Md5Ctx;
		HASH hval;
		HASHHEX key_line;
		char localip[128];
		char firewall_ip[65];
		char firewall_port[10];

		memset(localip, '\0', sizeof(localip));
		memset(firewall_ip, '\0', sizeof(firewall_ip));
		memset(firewall_port, '\0', sizeof(firewall_port));

		eXosip_guess_localip(AF_INET, localip, 128);
		if (eXosip.eXtl != NULL && eXosip.eXtl->tl_get_masquerade_contact != NULL) {
			eXosip.eXtl->tl_get_masquerade_contact(firewall_ip,
												   sizeof(firewall_ip),
												   firewall_port,
												   sizeof(firewall_port));
		}

		osip_MD5Init(&Md5Ctx);
		osip_MD5Update(&Md5Ctx, (unsigned char *) from, strlen(from));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) proxy, strlen(proxy));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) localip, strlen(localip));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) firewall_ip,
					   strlen(firewall_ip));
		osip_MD5Update(&Md5Ctx, (unsigned char *) ":", 1);
		osip_MD5Update(&Md5Ctx, (unsigned char *) firewall_port,
					   strlen(firewall_port));
		osip_MD5Final((unsigned char *) hval, &Md5Ctx);
		CvtHex(hval, key_line);

		osip_strncpy((*jr)->r_line, key_line, sizeof((*jr)->r_line) - 1);
	}

	return OSIP_SUCCESS;
}
Exemple #4
0
int
_eXosip_reg_init (struct eXosip_t *excontext, eXosip_reg_t ** jr, const char *from, const char *proxy, const char *contact)
{
  static int r_id = 0;

  *jr = (eXosip_reg_t *) osip_malloc (sizeof (eXosip_reg_t));
  if (*jr == NULL)
    return OSIP_NOMEM;

  if (r_id == INT_MAX)            /* keep it non-negative */
    r_id = 0;

  memset (*jr, '\0', sizeof (eXosip_reg_t));

  (*jr)->r_id = ++r_id;
  (*jr)->r_reg_period = 3600;   /* delay between registration */
  (*jr)->r_aor = osip_strdup (from);    /* sip identity */
  if ((*jr)->r_aor == NULL) {
    osip_free (*jr);
    *jr = NULL;
    return OSIP_NOMEM;
  }
  (*jr)->r_contact = osip_strdup (contact);     /* sip identity */
  (*jr)->r_registrar = osip_strdup (proxy);     /* registrar */
  if ((*jr)->r_registrar == NULL) {
    osip_free ((*jr)->r_contact);
    osip_free ((*jr)->r_aor);
    osip_free (*jr);
    *jr = NULL;
    return OSIP_NOMEM;
  }

  {
    osip_MD5_CTX Md5Ctx;
    HASH hval;
    HASHHEX key_line;
    char localip[128];
    char firewall_ip[65];
    char firewall_port[10];
    char somerandom[31];

    memset (somerandom, 0, sizeof (somerandom));
    eXosip_generate_random (somerandom, 16);

    memset (localip, '\0', sizeof (localip));
    memset (firewall_ip, '\0', sizeof (firewall_ip));
    memset (firewall_port, '\0', sizeof (firewall_port));

    eXosip_guess_localip (excontext, AF_INET, localip, 128);
    if (excontext->eXtl_transport.tl_get_masquerade_contact != NULL) {
      excontext->eXtl_transport.tl_get_masquerade_contact (excontext, firewall_ip, sizeof (firewall_ip), firewall_port, sizeof (firewall_port));
    }

    osip_MD5Init (&Md5Ctx);
    osip_MD5Update (&Md5Ctx, (unsigned char *) from, (unsigned int) strlen (from));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) proxy, (unsigned int) strlen (proxy));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) localip, (unsigned int) strlen (localip));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) firewall_ip, (unsigned int) strlen (firewall_ip));
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) firewall_port, (unsigned int) strlen (firewall_port));

    /* previously, "line" was common accross several identical restart. */
    /* including random will help to read a correct "expires" parameter */
    /* from 2xx REGISTER answers */
    osip_MD5Update (&Md5Ctx, (unsigned char *) ":", 1);
    osip_MD5Update (&Md5Ctx, (unsigned char *) somerandom, (unsigned int) strlen (somerandom));

    osip_MD5Final ((unsigned char *) hval, &Md5Ctx);
    CvtHex (hval, key_line);

    osip_strncpy ((*jr)->r_line, key_line, sizeof ((*jr)->r_line) - 1);
  }

  return OSIP_SUCCESS;
}
int
sdp_complete_message (int did, sdp_message_t * remote_sdp, osip_message_t * msg)
{
  sdp_media_t *remote_med;
  char *tmp = NULL;
  char buf[4096];
  int pos;

  char localip[128];

  if (remote_sdp == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_WARNING, NULL,
                   "No remote SDP body found for call\n"));
      return -1;
    }
  if (msg == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_WARNING, NULL,
                   "No message to complete\n"));
      return -1;
    }

  eXosip_guess_localip (AF_INET, localip, 128);
  snprintf (buf, 4096,
            "v=0\r\n"
            "o=josua 0 0 IN IP4 %s\r\n"
            "s=conversation\r\n" "c=IN IP4 %s\r\n" "t=0 0\r\n", localip, localip);

  pos = 0;
  while (!osip_list_eol (remote_sdp->m_medias, pos))
    {
      char payloads[128];
      int pos2;

      memset (payloads, '\0', sizeof (payloads));
      remote_med = (sdp_media_t *) osip_list_get (remote_sdp->m_medias, pos);

      if (0 == osip_strcasecmp (remote_med->m_media, "audio"))
        {
          pos2 = 0;
          while (!osip_list_eol (remote_med->m_payloads, pos2))
            {
              tmp = (char *) osip_list_get (remote_med->m_payloads, pos2);
              if (tmp != NULL &&
                  (0 == osip_strcasecmp (tmp, "0")
                   || 0 == osip_strcasecmp (tmp, "8")))
                {
                  strcat (payloads, tmp);
                  strcat (payloads, " ");
                }
              pos2++;
            }
          strcat (buf, "m=");
          strcat (buf, remote_med->m_media);
          if (pos2 == 0 || payloads[0] == '\0')
            {
              strcat (buf, " 0 RTP/AVP \r\n");
              return -1;        /* refuse anyway */
          } else
            {
              strcat (buf, " 10500 RTP/AVP ");
              strcat (buf, payloads);
              strcat (buf, "\r\n");

#if 0
              if (NULL != strstr (payloads, " 0 ")
                  || (payloads[0] == '0' && payloads[1] == ' '))
                strcat (buf, "a=rtpmap:0 PCMU/8000/1\r\n");
              if (NULL != strstr (payloads, " 8 ")
                  || (payloads[0] == '8' && payloads[1] == ' '))
                strcat (buf, "a=rtpmap:8 PCMA/8000/1\r\n");
#else
              if (NULL != strstr (payloads, " 0 ")
                  || (payloads[0] == '0' && payloads[1] == ' '))
                strcat (buf, "a=rtpmap:0 PCMU/8000\r\n");
              if (NULL != strstr (payloads, " 8 ")
                  || (payloads[0] == '8' && payloads[1] == ' '))
                strcat (buf, "a=rtpmap:8 PCMA/8000\r\n");
#endif
            }
      } else
        {
          strcat (buf, "m=");
          strcat (buf, remote_med->m_media);
          strcat (buf, " 0 ");
          strcat (buf, remote_med->m_proto);
          strcat (buf, " \r\n");
        }
      pos++;
    }

  osip_message_set_body (msg, buf, strlen (buf));
  osip_message_set_content_type (msg, "application/sdp");
  return 0;
}
Exemple #6
0
char *
sdp_context_get_answer ( sdp_context_t *ctx,sdp_message_t *remote)
{
	sdp_message_t *answer=NULL;
	char *mtype=NULL, *tmp=NULL;
	char *proto=NULL, *port=NULL, *pt=NULL;
	int i, j, ncodec, m_lines_accepted = 0;
	int err;
	sdp_payload_t payload;
	sdp_handler_t *sdph=ctx->handler;
	sdp_bandwidth_t *sbw=NULL;
	char *relay;

	tmp = sdp_message_c_addr_get (remote, 0, 0);
	if (tmp == NULL)
	  tmp = sdp_message_c_addr_get (remote, -1, 0);
	if (ctx->localip==NULL) {
		/* NULL means guess, otherwise we use the address given as localip */
		ctx->localip=osip_malloc(128);
		eXosip_guess_localip(strchr(tmp,':') ?  AF_INET6 : AF_INET,ctx->localip,128);
	}
	else eXosip_trace(OSIP_INFO1,("Using firewall address in sdp."));

	answer = sdp_context_generate_template (ctx);
	
	/* for each m= line */
	for (i = 0; !sdp_message_endof_media (remote, i); i++)
	{
		sdp_payload_init(&payload);
		mtype = sdp_message_m_media_get (remote, i);
		proto = sdp_message_m_proto_get (remote, i);
		port = sdp_message_m_port_get (remote, i);
		payload.remoteport = osip_atoi (port);
		payload.proto = proto;
		payload.line = i;
		payload.c_addr = sdp_message_c_addr_get (remote, i, 0);
		if (payload.c_addr == NULL)
			payload.c_addr = sdp_message_c_addr_get (remote, -1, 0);
		/*parse relay address if given*/
		relay=sdp_message_a_attr_value_get(remote,i,"relay-addr");
		if (relay){
			payload.relay_host=parse_relay_addr(relay,&payload.relay_port);
		}
		payload.relay_session_id=sdp_message_a_attr_value_get(remote,i,"relay-session-id");
		/* get application specific bandwidth, if any */
		for(j=0;(sbw=sdp_message_bandwidth_get(remote,i,j))!=NULL;j++){
			if (strcasecmp(sbw->b_bwtype,"AS")==0) payload.b_as_bandwidth=atoi(sbw->b_bandwidth);
		}
		payload.a_ptime=_sdp_message_get_a_ptime(remote,i);
		if (keywordcmp ("audio", mtype) == 0)
		{
			if (sdph->accept_audio_codecs != NULL)
			{
				ncodec = 0;
				/* for each payload type */
				for (j = 0;
				     ((pt =
				       sdp_message_m_payload_get (remote, i,
							  j)) != NULL); j++)
				{
					payload.pt = osip_atoi (pt);
					/* get the rtpmap associated to this codec, if any */
					payload.a_rtpmap =
						sdp_message_a_attr_value_get_with_pt
						(remote, i, payload.pt,
						 "rtpmap");
					/* get the fmtp, if any */
					payload.a_fmtp =
						sdp_message_a_attr_value_get_with_pt
						(remote, i, payload.pt,
						 "fmtp");
					
					/* ask the application if this codec is supported */
					err = sdph->accept_audio_codecs (ctx,
									 &payload);
					if (err == 0 && payload.localport > 0)
					{
						ncodec++;
						/* codec accepted */
						if (ncodec == 1)
						{
							/* first codec accepted, setup the line  */
							sdp_message_m_media_add
								(answer,
								 osip_strdup
								 (mtype),
								 int_2char
								 (payload.
								  localport),
								 NULL,
								 osip_strdup
								 (proto));
							/* and accept the remote relay addr if we planned to use our own */
							if (ctx->relay!=NULL && relay){
								add_relay_info(answer,i,relay,payload.relay_session_id);
							}
						}
						/* add the payload, rtpmap, fmtp */
						sdp_message_m_payload_add (answer, i,
								   int_2char
								   (payload.
								    pt));
						if (payload.a_rtpmap != NULL)
						{
							sdp_message_a_attribute_add
								(answer, i,
								 osip_strdup
								 ("rtpmap"),
								 sstrdup_sprintf
								 ("%i %s",
								  payload.pt,
								  payload.
								  a_rtpmap));
						}
						if (payload.a_fmtp != NULL)
						{
							sdp_message_a_attribute_add
								(answer, i,
								 osip_strdup
								 ("fmtp"),
								 sstrdup_sprintf
								 ("%i %s",
								  payload.pt,
								  payload.
								  a_fmtp));
						}
						if (payload.b_as_bandwidth !=
						    0)
						{
							if (sdp_message_bandwidth_get(answer,i,0)==NULL)
								sdp_message_b_bandwidth_add
								(answer, i,
								 osip_strdup
								 ("AS"),
								 sstrdup_sprintf
								 ("%i",
								  payload.
								  b_as_bandwidth));
						}
					}
				}
				if (ncodec == 0)
				{
					/* refuse the line */
					refuse_mline(answer,mtype,proto,i);
					
				}
				else
					m_lines_accepted++;
			}
			else
			{
				/* refuse this line (leave port to 0) */
				refuse_mline(answer,mtype,proto,i);
			}

		}
		else if (keywordcmp ("video", mtype) == 0)
		{
			if (sdph->accept_video_codecs != NULL)
			{
				ncodec = 0;
				/* for each payload type */
				for (j = 0;
				     ((pt =
				       sdp_message_m_payload_get (remote, i,
							  j)) != NULL); j++)
				{
					payload.pt = osip_atoi (pt);
					/* get the rtpmap associated to this codec, if any */
					payload.a_rtpmap =
						sdp_message_a_attr_value_get_with_pt
						(remote, i, payload.pt,
						 "rtpmap");
					/* get the fmtp, if any */
					payload.a_fmtp =
						sdp_message_a_attr_value_get_with_pt
						(remote, i, payload.pt,
						 "fmtp");
					/* ask the application if this codec is supported */
					err = sdph->accept_video_codecs (ctx,
									 &payload);
					if (err == 0 && payload.localport > 0)
					{
						ncodec++;
						/* codec accepted */
						if (ncodec == 1)
						{
							/* first codec accepted, setup the line  */
							sdp_message_m_media_add
								(answer,
								 osip_strdup
								 (mtype),
								 int_2char
								 (payload.localport), NULL,
								 osip_strdup
								 (proto));
							/* and accept the remote relay addr if we planned to use our own */
							if (ctx->relay!=NULL && relay){
								add_relay_info(answer,i,relay,payload.relay_session_id);
							}
						}
						/* add the payload, rtpmap, fmtp */
						sdp_message_m_payload_add (answer, i,
								   int_2char
								   (payload.
								    pt));
						if (payload.a_rtpmap != NULL)
						{
							sdp_message_a_attribute_add
								(answer, i,
								 osip_strdup
								 ("rtpmap"),
								 sstrdup_sprintf
								 ("%i %s",
								  payload.pt,
								  payload.
								  a_rtpmap));
						}
						if (payload.a_fmtp != NULL)
						{
							sdp_message_a_attribute_add
								(answer, i,
								 osip_strdup
								 ("fmtp"),
								 sstrdup_sprintf
								 ("%i %s",
								  payload.pt,
								  payload.
								  a_fmtp));
						}
						if (payload.b_as_bandwidth !=0)
						{
							if (sdp_message_bandwidth_get(answer,i,0)==NULL)
								sdp_message_b_bandwidth_add
								(answer, i,
								 osip_strdup
								 ("AS"),
								 sstrdup_sprintf
								 ("%i",
								  payload.
								  b_as_bandwidth));
						}
					}
				}
				if (ncodec == 0)
				{
					/* refuse the line */
					refuse_mline(answer,mtype,proto,i);
				}
				else
					m_lines_accepted++;
			}
			else
			{
				/* refuse the line */
				refuse_mline(answer,mtype,proto,i);
			}
		}
	}
	if (ctx->answer!=NULL)
		sdp_message_free(ctx->answer);
	ctx->answer = answer;
	if (m_lines_accepted > 0){
		ctx->negoc_status = 200;
		sdp_message_to_str(answer,&tmp);
		if (ctx->answerstr!=NULL)
			osip_free(ctx->answerstr);
		ctx->answerstr=tmp;
		return tmp;
	}else{
		ctx->negoc_status = 415;
		return NULL;
	}
}