int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){
	osip_message_t *sip=NULL;

	if(op->cid == -1)
	{
		/* we are not currently in communication with the destination */
		if (from)
			sal_op_set_from(op,from);
		if (to)
			sal_op_set_to(op,to);

		sal_exosip_fix_route(op);
		eXosip_lock();
		eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op),
			sal_op_get_from(op),sal_op_get_route(op));
		if (sip!=NULL){
			sal_exosip_add_custom_headers(sip,op->base.custom_headers);
			msg_add_current_date(sip);
			osip_message_set_content_type(sip,content_type);
			if (msg) osip_message_set_body(sip,msg,strlen(msg));
			sal_add_other(op->base.root,op,sip);
			eXosip_message_send_request(sip);
		}else{
			ms_error("Could not build MESSAGE request !");
		}
		eXosip_unlock();
	}
	else
	{
		/* we are currently in communication with the destination */
		eXosip_lock();
		//First we generate an INFO message to get the current call_id and a good cseq
		eXosip_call_build_request(op->did,"MESSAGE",&sip);
		if(sip == NULL)
		{
			ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?");
			eXosip_unlock();
			return -1;
		}
		sal_exosip_add_custom_headers(sip,op->base.custom_headers);
		msg_add_current_date(sip);
		osip_message_set_content_type(sip,content_type);
		if (msg) osip_message_set_body(sip,msg,strlen(msg));
		eXosip_call_send_request(op->did,sip);
		eXosip_unlock();
	}
	return 0;
}
static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status)
{
	char buf[1000];
	char *contact_info;

	osip_from_t *from=NULL;
	from=osip_message_get_from(notify);
	osip_uri_to_str(from->url,&contact_info);

	mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style);

	osip_message_set_body(notify, buf, strlen(buf));
	osip_message_set_content_type(notify,
		presence_style ? "application/xpidf+xml" : "application/pidf+xml");

	osip_free(contact_info);
}
Ejemplo n.º 3
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;

}
Ejemplo n.º 4
0
int
eXosip_build_publish (struct eXosip_t *excontext, osip_message_t ** message, const char *to, const char *from, const char *route, const char *event, const char *expires, const char *ctype, const char *body)
{
  int i;

  *message = NULL;

  if (to == NULL || to[0] == '\0')
    return OSIP_BADPARAMETER;
  if (from == NULL || from[0] == '\0')
    return OSIP_BADPARAMETER;
  if (event == NULL || event[0] == '\0')
    return OSIP_BADPARAMETER;
  if (ctype == NULL || ctype[0] == '\0') {
    if (body != NULL && body[0] != '\0')
      return OSIP_BADPARAMETER;
  }
  else {
    if (body == NULL || body[0] == '\0')
      return OSIP_BADPARAMETER;
  }

  i = _eXosip_generating_publish (excontext, message, to, from, route);
  if (i != 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot send message (cannot build PUBLISH)! "));
    return i;
  }

  if (body != NULL && body[0] != '\0' && ctype != NULL && ctype[0] != '\0') {
    osip_message_set_content_type (*message, ctype);
    osip_message_set_body (*message, body, strlen (body));
    /*
       osip_message_set_header (*message, "Content-Disposition",
       "render;handling=required");
     */
  }
  if (expires != NULL && expires[0] != '\0')
    osip_message_set_expires (*message, expires);
  else
    osip_message_set_expires (*message, "3600");

  osip_message_set_header (*message, "Event", event);

  return OSIP_SUCCESS;
}
Ejemplo n.º 5
0
int uac_send_message(const sessionId Id, const alter_message * alter_m)
{
	osip_message_t *message;
	int i;
	eXosip_lock ();
	i = eXosip_call_build_request (Id.did,alter_m->method_type/*"MESSAGE" or "INFO"*/, &message);
	if (i == 0)
	{
		if(alter_m->content_type!=NULL)
		osip_message_set_content_type (message, alter_m->content_type/*"Application/MANSRTSP"*/);
		if(alter_m->subject!=NULL)
		osip_message_set_subject(message,alter_m->subject);
		osip_message_set_body (message, alter_m->body, strlen (alter_m->body));
		i = eXosip_call_send_request (Id.did, message);
	}
	eXosip_unlock ();

	return i;
}
Ejemplo n.º 6
0
int uac_send_noSessionMessage(const sip_entity* to_, const alter_message * alter_m)
{//,char * to, char * from, char * route,char * content,char * subject
	osip_message_t *message;
	char from[4+CHARLEN+1+15+1+4+1];
	char to[4+CHARLEN+1+15+1+4+1];
	snprintf(from,sizeof(from),"sip:%s@%s:%s",device_info.ipc_id,device_info.ipc_ip,device_info.ipc_port);
	snprintf(to,sizeof(to),"sip:%s@%s:%d",to_->username,to_->ip,to_->port);
	eXosip_lock ();
	eXosip_message_build_request (&message, alter_m->method_type, to,from, alter_m->route);

	if(alter_m->subject!=NULL)
	osip_message_set_subject(message,alter_m->subject);
	osip_message_set_body(message,alter_m->body,strlen(alter_m->body));
	osip_message_set_content_type(message,alter_m->content_type);
	eXosip_message_send_request(message);

	eXosip_unlock ();
	return 1;
	}
Ejemplo n.º 7
0
void call_accept(Call *call)
{
	sdp_context_t *ctx;
	PayloadType *payload;
	char *hellofile;
	static int call_count=0;	
	char record_file[250];
	osip_message_t *msg=NULL;
	sprintf(record_file,"/tmp/sipomatic%i.wav",call_count);

	ctx=call->sdpc;
	payload=rtp_profile_get_payload(call->profile,call->audio.pt);
	if (strcmp(payload->mime_type,"telephone-event")==0){
		/* telephone-event is not enough to accept a call */
		ms_message("Cannot accept call with only telephone-event.\n");
		eXosip_call_send_answer(call->did,415,NULL);
		call->state=CALL_STATE_FINISHED;
		return;
	}
	if (payload->clock_rate==16000){
		hellofile=call->root->file_path16000hz;
	}else hellofile=call->root->file_path8000hz;
	eXosip_call_build_answer(call->tid,200,&msg);
	osip_message_set_content_type(msg,"application/sdp");
	osip_message_set_body(msg,call->sdpc->answerstr,strlen(call->sdpc->answerstr));
	eXosip_call_send_answer(call->tid,200,msg);
	call->audio_stream=audio_stream_new(call->audio.localport,call->audio.localport+1,call->root->ipv6);
	audio_stream_start_with_files(call->audio_stream, call->profile,
				call->audio.remaddr,call->audio.remoteport,call->audio.remoteport+1,
				 call->audio.pt,20,hellofile,record_file);
	call_count++;
#ifdef VIDEO_ENABLED
	if (call->video.remoteport!=0){
		video_stream_send_only_start(call->video_stream,call->profile,
			call->video.remaddr,call->video.remoteport,call->video.remoteport+1,call->video.pt, 60, 
			ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get()));
	}
#endif
	call->time=time(NULL);
	call->state=CALL_STATE_RUNNING;
	ms_filter_set_notify_callback(call->audio_stream->soundread,endoffile_cb,(void*)call);
}
Ejemplo n.º 8
0
int uac_send_info(const sessionId Id)
{
	osip_message_t *info;
	char info_body[1000];
	int i;
	eXosip_lock ();
	i = eXosip_call_build_info (Id.did, &info);
	if (i == 0)
	{
		snprintf (info_body, 999, "Signal=sss\r\nDuration=250\r\n");
		osip_message_set_content_type (info, "Application/MANSRTSP");
		osip_message_set_body (info, info_body, strlen (info_body));
		i = eXosip_call_send_request (Id.did, info);
	}
	else
	{
		printf("eXosip_call_build_info error\n");
		return 0;
	}
	eXosip_unlock ();

	//成功时返回的i可能是0,如果是0则需要修改,后续在测试修改
	return i;
}
Ejemplo n.º 9
0
int uac_register()
{
		int expires=3600;		/* 注册存活时间 */
		int ret = 0;			/* 注册返回值 */
		eXosip_event_t *je  = NULL;	/* 监听到的消息指针 */
		osip_message_t *reg = NULL;	/* 注册的消息体指针 */
		char from[100];/*sip:主叫用户名@被叫IP地址*/
		char proxy[100];/*sip:被叫IP地址:被叫IP端口*/

		memset(from, 0, 100);
		memset(proxy, 0, 100);
		sprintf(from, "sip:%s@%s", device_info.ipc_id, device_info.server_ip);
		sprintf(proxy, "sip:%s:%s", device_info.server_ip, device_info.server_port);

	/*------step 1-----------发送不带认证信息的注册请求-----------------------*/
	retry:
		eXosip_lock();
		g_register_id = eXosip_register_build_initial_register(from, proxy, NULL, expires, &reg);
		char mac[12];
		memset(mac,0,12);
		memcpy(mac,RegisterCon->self_MACaddr.macaddr,sizeof(RegisterCon->self_MACaddr.macaddr));
		//mac[12]='\n';
		//getNetInfo(NULL,mac);//printf("mac:%02x %02x %02x %02x %02x %02x",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);

		codeToChar(mac,sizeof(mac));
		char mac_subject[20];
		sprintf(mac_subject,"MAC:%s\r\n",mac);
		osip_message_set_subject(reg,mac_subject);
		osip_message_set_authorization(reg, "Capability algorithm=\"H:MD5\"");
		if (0 > g_register_id)
		{
			eXosip_lock();
			printf("eXosip_register_build_initial_register error!\r\n");
			return -1;
		}
		printf("eXosip_register_build_initial_register success!\r\n");

		ret = eXosip_register_send_register(g_register_id, reg);
		eXosip_unlock();
		if (0 != ret)
		{
			printf("eXosip_register_send_register no authorization error!\r\n");
			return -1;
		}
		printf("eXosip_register_send_register no authorization success!\r\n");

		printf("g_register_id=%d\r\n", g_register_id);

		for (;;)
		{
			je = eXosip_event_wait(10, 500);/*侦听消息的到来*/

			if (NULL == je)/*没有接收到消息*/
			{
				continue;
			}
			if (EXOSIP_REGISTRATION_FAILURE == je->type)/*注册失败*/
			{
				printf("<EXOSIP_REGISTRATION_FAILURE>\r\n");
				printf("je->rid=%d\r\n", je->rid);
				/*-------step 2---------收到服务器返回的注册失败/401未认证状态------------*/
				if ((NULL != je->response)&&(401 == je->response->status_code))
				{
					AuthActive * auth_active_packet_data=NULL;
					osip_body_t *body;

					osip_header_t * subject;
					osip_message_get_subject(je->response,0,&subject);
					if(subject==NULL)
					{
						printf("no subject\n");
						return 0;
					}
					//printf("subject->hvalue:%s\n",subject->hvalue);
					char mac[12];
					memset(mac, 0, 12);
					memcpy(mac,subject->hvalue,4);
					if(!strcmp(mac,"MAC:"))
					{
						memcpy(mac,subject->hvalue+4,12);
						decodeFromChar(mac,12);
						memcpy(RegisterCon->peer_MACaddr.macaddr,mac,6);
					}
					else
					{
						printf("subject not match\n");
						return 0;
					}

					osip_message_get_body (je->response, 0, &body);
					if(!auth_active_packet_data)
					{
						free(auth_active_packet_data);
						auth_active_packet_data=NULL;
					}
					if((sizeof(AuthActive)*2)>(body->length))
					{
						printf("body->length is not enough");
						return 0;
					}
					auth_active_packet_data=(AuthActive *)malloc (sizeof(AuthActive)*2);//;body->length*sizeof(char));
					memset(auth_active_packet_data,0,sizeof(AuthActive)*2);
					memcpy(auth_active_packet_data,body->body, sizeof(AuthActive)*2);
					decodeFromChar((char*)auth_active_packet_data,sizeof(AuthActive)*2);
					if(!HandleWAPIProtocolAuthActive(RegisterCon,auth_active_packet_data))
					{
						printf("HandleWAPIProtocolAuthActive error\n");
						return 0;
					}

					/*
					//printf("message:%s\n",message);
					if(0/*when receive 401Unauthorized package,send ACK and Regester/)
					{
						osip_message_t *ack = NULL;
						int call_id=atoi(reg->call_id->number);
						printf("je->did:%d\n",je->did);
						ret=eXosip_call_build_ack(je->rid,&ack);
						ret=eXosip_call_send_ack(atoi(je->rid),ack);
					}
					*/

					reg = NULL;
					/*----------step 3-------------发送携带认证信息的注册请求----------------------*/
					eXosip_lock();
					int return_num;

					return_num=eXosip_clear_authentication_info();/*清除认证信息*/
					printf("return_num:%d\n",return_num);
					return_num=eXosip_add_authentication_info(device_info.ipc_id, device_info.ipc_id, device_info.ipc_pwd, "MD5", NULL);/*添加主叫用户的认证信息*/
					printf("return_num:%d\n",return_num);
					printf("je->rid:%d expires:%d return num:%d\n",je->rid,expires,eXosip_register_build_register(je->rid, expires, &reg));

					//if(auth_request_packet_data!=NULL)
					//{

						//free(auth_request_packet_data);
						//auth_request_packet_data=NULL;
					//}

					auth_request_packet_data=(AccessAuthRequ*)malloc(sizeof(AccessAuthRequ)*2);

					memset(auth_request_packet_data,0, sizeof(AccessAuthRequ)*2);

					if(ProcessWAPIProtocolAccessAuthRequest(RegisterCon,auth_active_packet_data,auth_request_packet_data)<1)
					{
						printf("ProcessWAPIProtocolAccessAuthRequest error\n");
						return 0;
					}
					codeToChar((char*)auth_request_packet_data,sizeof(AccessAuthRequ)*2);

					//printf("length:%d",(sizeof(AuthActive)*2));
					//printf("length:%d",(sizeof(AccessAuthRequ)*2));
					//printf("length:%d",(sizeof(CertificateAuthRequ)*2));
					//printf("length:%d",sizeof(CertificateAuthResp)*2);
					//printf("length:%d",sizeof(AccessAuthResp)*2);
					printf("111\n");
					if(reg==NULL)
					{
						printf("reg==NULL\n");
					}
					osip_message_set_body(reg,(char*)auth_request_packet_data,sizeof(AccessAuthRequ)*2);printf("222\n");
					printf("333\n");
					printf("je->rid:%d\n",je->rid);printf("444\n");
					ret = eXosip_register_send_register(je->rid, reg);
					eXosip_unlock();
					decodeFromChar((char *)auth_request_packet_data,sizeof(AccessAuthRequ)*2);
					if (0 != ret)
					{
						printf("eXosip_register_send_register authorization error!\r\n");
						return -1;
					}
					printf("eXosip_register_send_register authorization success!\r\n");
					eXosip_event_free (je);
					//free(auth_active_packet_data);
printf("end\n");
				}
				else/*真正的注册失败*/
				{
					printf("EXOSIP_REGISTRATION_FAILURE error!\r\n");
					eXosip_event_free (je);
					return -1;
					//goto retry;/*重新注册*/
				}
			}
			else if (EXOSIP_REGISTRATION_SUCCESS == je->type)
			{printf("recieve EXOSIP_REGISTRATION_SUCCESS\n");
				/*---------step 6-------------收到服务器返回的注册成功--------------------------------*/

				AccessAuthResp * access_auth_resp_data;
				osip_body_t *body;
				osip_message_get_body (je->response, 0, &body);
				if(body==NULL)
				{
					printf("body==NULL\n");
					return 0;
				}
				if( body->length<sizeof(AccessAuthResp)*2)
				{
					printf("message length is too short:%d\n",body->length);
					return 0;
				}
				access_auth_resp_data=(AccessAuthResp *)malloc (body->length*sizeof(char));
				memcpy(access_auth_resp_data,body->body, body->length);

				decodeFromChar((char*)access_auth_resp_data,sizeof(AccessAuthResp)*2);

				if(auth_request_packet_data==NULL)
				{
					printf("auth_request_packet_data = NULL\n");
				}
				if(HandleWAPIProtocolAccessAuthResp(RegisterCon,auth_request_packet_data,access_auth_resp_data)<1)
				{
					printf("HandleWAPIProtocolAccessAuthResp error\n");
					return 0;
				}

				g_register_id = je->rid;/*保存注册成功的注册ID*/
				printf("g_register_id=%d\r\n", g_register_id);
				printf("<EXOSIP_REGISTRATION_SUCCESS>\r\n");
				/*
				//send key agreement package  发送密钥协商包
				osip_message_t * inforequest;
				ret=eXosip_message_build_request(&inforequest,"MESSAGE",proxy,from,NULL);
				ret=osip_message_set_body(inforequest,"sssss",6);
				ret=eXosip_message_send_request(inforequest);

				*/
				eXosip_event_free (je);
				free(auth_request_packet_data);
				free(access_auth_resp_data);
				return 1;
				break;
			}
		}

		return 0;
}
Ejemplo n.º 10
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;

}
Ejemplo n.º 11
0
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;
}
Ejemplo n.º 12
0
static int
msg_osip_body_parse(osip_message_t * sip, const char *start_of_buf,
					const char **next_body, size_t length)
{
	const char *start_of_body;
	const char *end_of_body;
	const char *end_of_buf;
	char *tmp;
	int i;

	char *sep_boundary;
	size_t len_sep_boundary;
	osip_generic_param_t *ct_param;

	if (sip->content_type == NULL
		|| sip->content_type->type == NULL || sip->content_type->subtype == NULL)
		return OSIP_SUCCESS;	/* no body is attached */

	if (0 != osip_strcasecmp(sip->content_type->type, "multipart")) {
		size_t osip_body_len;

		if (start_of_buf[0] == '\0')
			return OSIP_SYNTAXERROR;	/* final CRLF is missing */
		/* get rid of the first CRLF */
		if ('\r' == start_of_buf[0]) {
			if ('\n' == start_of_buf[1])
				start_of_body = start_of_buf + 2;
			else
				start_of_body = start_of_buf + 1;
		} else if ('\n' == start_of_buf[0])
			start_of_body = start_of_buf + 1;
		else
			return OSIP_SYNTAXERROR;	/* message does not end with CRLFCRLF, CRCR or LFLF */

		/* update length (without CRLFCRLF */
		length = length - (start_of_body - start_of_buf);	/* fixed 24 08 2004 */
		if (length <= 0)
			return OSIP_SYNTAXERROR;

		if (sip->content_length != NULL)
			osip_body_len = osip_atoi(sip->content_length->value);
		else {
			/* if content_length does not exist, set it. */
			char tmp[16];

			/* case where content-length is missing but the
			   body only contains non-binary data */
			if (0 == osip_strcasecmp(sip->content_type->type, "application")
				&& 0 == osip_strcasecmp(sip->content_type->subtype, "sdp")) {
				osip_body_len = strlen(start_of_body);
				sprintf(tmp, "%i", osip_body_len);
				i = osip_message_set_content_length(sip, tmp);
				if (i != 0)
					return i;
			} else
				return OSIP_SYNTAXERROR;	/* Content-type may be non binary data */
		}

		if (length < osip_body_len) {
			OSIP_TRACE(osip_trace
					   (__FILE__, __LINE__, OSIP_ERROR, NULL,
						"Message was not receieved enterely. length=%i osip_body_len=%i\n",
						length, osip_body_len));
			return OSIP_SYNTAXERROR;
		}

		end_of_body = start_of_body + osip_body_len;
		tmp = osip_malloc(end_of_body - start_of_body + 2);
		if (tmp == NULL)
			return OSIP_NOMEM;
		memcpy(tmp, start_of_body, end_of_body - start_of_body);
		tmp[end_of_body - start_of_body] = '\0';

		i = osip_message_set_body(sip, tmp, end_of_body - start_of_body);
		osip_free(tmp);
		if (i != 0)
			return i;
		return OSIP_SUCCESS;
	}

	/* find the boundary */
	i = osip_generic_param_get_byname(&sip->content_type->gen_params,
									  "boundary", &ct_param);
	if (i != 0)
		return i;

	if (ct_param == NULL)
		return OSIP_SYNTAXERROR;
	if (ct_param->gvalue == NULL)
		return OSIP_SYNTAXERROR;	/* No boundary but multiple headers??? */

	{
		const char *boundary_prefix = "\n--";

		size_t len = strlen(ct_param->gvalue);

		sep_boundary = (char *) osip_malloc(len + 4);
		if (sep_boundary == NULL)
			return OSIP_NOMEM;
		strcpy(sep_boundary, boundary_prefix);
		if (ct_param->gvalue[0] == '"' && ct_param->gvalue[len - 1] == '"')
			strncat(sep_boundary, ct_param->gvalue + 1, len - 2);
		else
			strncat(sep_boundary, ct_param->gvalue, len);
	}

	len_sep_boundary = strlen(sep_boundary);

	*next_body = NULL;
	start_of_body = start_of_buf;

	end_of_buf = start_of_buf + length;

	for (;;) {
		size_t body_len = 0;

		i = __osip_find_next_occurence(sep_boundary, start_of_body,
									   &start_of_body, end_of_buf);
		if (i != 0) {
			osip_free(sep_boundary);
			return i;
		}

		i = __osip_find_next_occurence(sep_boundary,
									   start_of_body + len_sep_boundary,
									   &end_of_body, end_of_buf);
		if (i != 0) {
			osip_free(sep_boundary);
			return i;
		}

		/* this is the real beginning of body */
		start_of_body = start_of_body + len_sep_boundary + 1;
		if ('\n' == start_of_body[0] || '\r' == start_of_body[0])
			start_of_body++;

		body_len = end_of_body - start_of_body;

		/* Skip CR before end boundary. */
		if (*(end_of_body - 1) == '\r')
			body_len--;

		tmp = osip_malloc(body_len + 2);
		if (tmp == NULL) {
			osip_free(sep_boundary);
			return OSIP_NOMEM;
		}
		memcpy(tmp, start_of_body, body_len);
		tmp[body_len] = '\0';

		i = osip_message_set_body_mime(sip, tmp, body_len);
		osip_free(tmp);
		if (i != 0) {
			osip_free(sep_boundary);
			return i;
		}

		if (strncmp(end_of_body + len_sep_boundary, "--", 2) == 0) {	/* end of all bodies */
			*next_body = end_of_body;
			osip_free(sep_boundary);
			return OSIP_SUCCESS;
		}

		/* continue on the next body */
		start_of_body = end_of_body;
	}
	/* Unreachable code */
	/* osip_free (sep_boundary); */
	return OSIP_SYNTAXERROR;
}
Ejemplo n.º 13
0
int
main (int argc, char *argv[])
{
  eXosip_event_t *je;
  osip_message_t *reg = NULL;
  osip_message_t *invite = NULL;
  osip_message_t *ack = NULL;
  osip_message_t *info = NULL;
  osip_message_t *message = NULL;

  int call_id, dialog_id;
  int i,flag;
  int flag1 = 1;
  int id;
 
  char *identity = "sip:[email protected]";
  char *registerer = "sip:192.168.44.100:5060";
  char *source_call = "sip:[email protected]";
  char *dest_call = "sip:[email protected]:5060";
 
  char command;
  char tmp[4096];
  char localip[128];

  printf("r     向服务器注册\n\n");
  printf("c     取消注册\n\n");
  printf("i     发起呼叫请求\n\n");
  printf("h     挂断\n\n");
  printf("q     退出程序\n\n");
  printf("s     执行方法INFO\n\n");
  printf("m     执行方法MESSAGE\n\n");
  //初始化
  i = eXosip_init ();
  if (i != 0)
    {
      printf ("Couldn't initialize eXosip!\n");
      return -1;
    }
  else
    {
      printf ("eXosip_init successfully!\n");
    }

  i = eXosip_listen_addr (IPPROTO_UDP, NULL, 5060, AF_INET, 0);
  if (i != 0)
    {
      eXosip_quit ();
      fprintf (stderr, "Couldn't initialize transport layer!\n");
      return -1;
    }
  flag = 1;
  while (flag)
    {
      printf ("please input the comand:\n");
      
      scanf ("%c", &command);
      getchar ();
      
      switch (command)
    {
    case 'r':
      printf ("This modal isn't commpleted!\n");
      break;
    case 'i':/* INVITE */
      i = eXosip_call_build_initial_invite (&invite, dest_call, source_call, NULL, "This si a call for a conversation");
      if (i != 0)
        {
          printf ("Intial INVITE failed!\n");
          break;
        }
        //符合SDP格式,其中属性a是自定义格式,也就是说可以存放自己的信息,但是只能是两列,比如帐户信息
        //但是经测试,格式:v o t必不可少,原因未知,估计是协议栈在传输时需要检查的
      snprintf (tmp, 4096,
            "v=0\r\n"
            "o=anonymous 0 0 IN IP4 0.0.0.0\r\n"
            "t=1 10\r\n"
            "a=username:rainfish\r\n"
            "a=password:123\r\n");
      osip_message_set_body (invite, tmp, strlen(tmp));
      osip_message_set_content_type (invite, "application/sdp");
      
      eXosip_lock ();
      i = eXosip_call_send_initial_invite (invite);
      eXosip_unlock ();
      flag1 = 1;
      while (flag1)
        {
          je = eXosip_event_wait (0, 200);
          
          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");
          // call_id = je->cid;
          // dialog_id = je->did;
          printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);
          break;
        case EXOSIP_CALL_ANSWERED:
          printf ("ok! connected!\n");
          call_id = je->cid;
          dialog_id = je->did;
          printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);

          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);
         
        }
      break;
    case 'h':
      printf ("Holded !\n");
      
      eXosip_lock ();
      eXosip_call_terminate (call_id, dialog_id);
      eXosip_unlock ();
      break;
    case 'c':
      printf ("This modal isn't commpleted!\n");
      break;
    case 's':
    //传输INFO方法
      eXosip_call_build_info (dialog_id, &info);
      snprintf (tmp , 4096,
            "hello,rainfish");
      osip_message_set_body (info, tmp, strlen(tmp));
      //格式可以任意设定,text/plain代表文本信息
      osip_message_set_content_type (info, "text/plain");
      eXosip_call_send_request (dialog_id, info);
      break;
    case 'm':
    //传输MESSAGE方法,也就是即时消息,和INFO方法相比,我认为主要区别,是MESSAGE不用建立连接,直接传输信息,而INFO必须
    //在建立INVITE的基础上传输。
      printf ("the mothed :MESSAGE\n");
      eXosip_message_build_request (&message, "MESSAGE", dest_call, source_call, NULL);
      snprintf (tmp, 4096,
            "hellor rainfish");
      osip_message_set_body (message, tmp, strlen(tmp));
      //假设格式是xml
      osip_message_set_content_type (message, "text/xml");
      eXosip_message_send_request (message);
      break;
    case 'q':
      eXosip_quit ();
      printf ("Exit the setup!\n");
      flag = 0;
      break;
    }
    }
  return (0);
}
Ejemplo n.º 14
0
static char *
generating_no_sdp_answer(eXosip_call_t *jc, eXosip_dialog_t *jd,
			 osip_message_t *orig_request, char *local_sdp_port, char *local_video_port)
{
  sdp_message_t *local_sdp = NULL;
  char *local_body = NULL;
  char *size;
  int i;
  
  jc->c_ack_sdp = 1;
  if(osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &local_sdp, local_sdp_port, local_video_port) != 0)
    return NULL;
  
  if (local_sdp!=NULL)
    {
      int pos=0;
      while (!sdp_message_endof_media (local_sdp, pos))
	{
	  int k = 0;
	  char *tmp = sdp_message_m_media_get (local_sdp, pos);
	  if (0 == strncmp (tmp, "audio", 5))
	    {
	      char *payload = NULL;
	      do {
		payload = sdp_message_m_payload_get (local_sdp, pos, k);
		if (payload == NULL)
		  {
		  }
		else if (0==strncmp("110",payload,3))
		  {
		    sdp_message_a_attribute_add (local_sdp,
						 pos,
						 osip_strdup ("AS"),
						 osip_strdup ("110 20"));
		  }
		else if (0==strncmp("111",payload,3))
		  {
		    sdp_message_a_attribute_add (local_sdp,
						 pos,
						 osip_strdup ("AS"),
						 osip_strdup ("111 20"));
		  }
		k++;
	      } while (payload != NULL);
	    }
	  pos++;
	}
    }
  
  i = sdp_message_to_str(local_sdp, &local_body);
  
  if (local_body!=NULL)
    {
      size= (char *)osip_malloc(7*sizeof(char));
#ifdef __APPLE_CC__
      sprintf(size,"%li",strlen(local_body));
#else
      sprintf(size,"%i",strlen(local_body));
#endif
      osip_message_set_content_length(orig_request, size);
      osip_free(size);
  
      osip_message_set_body(orig_request, local_body, strlen(local_body));
      osip_message_set_content_type(orig_request, "application/sdp");
    }
  else
    osip_message_set_content_length(orig_request, "0");
  
  osip_negotiation_ctx_set_local_sdp(jc->c_ctx, local_sdp);
  
  OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO3,NULL,"200 OK w/ SDP (RESPONSE TO INVITE w/ NO SDP)=\n%s\n", local_body));
  
  return local_body;
}
Ejemplo n.º 15
0
int
eXosip_answer_invite_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, char *local_sdp_port, char *ctct, char *local_video_port,
			 char *public_sdp_port,  char *public_video_port)
{
  osip_event_t *evt_answer;
  osip_message_t *response;
  int i;
  char *size;
  char *body = NULL;
  osip_transaction_t *tr;
  tr = eXosip_find_last_inc_invite(jc, jd);

  if (tr==NULL || tr->orig_request==NULL)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: cannot find transaction to answer\n"));
      return -1;
    }

  if (jd!=NULL && jd->d_dialog==NULL)
    {  /* element previously removed */
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: cannot answer this closed transaction\n"));
      return -1;
    }

  /* is the transaction already answered? */
  if (tr->state==IST_COMPLETED
      || tr->state==IST_CONFIRMED
      || tr->state==IST_TERMINATED)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: transaction already answered\n"));
      return -1;
    }

  /* WE SHOULD LOOK FOR A SDP PACKET!! */
  if(NULL != osip_list_get(&tr->orig_request->bodies,0))
    {
      body = generating_sdp_answer(tr->orig_request, jc->c_ctx);
      if (body==NULL)
	code = 488; /* bad sdp */
    }
  else
    {
      if(local_sdp_port==NULL && local_video_port == NULL)
	code = 488; /* session description in the request is not acceptable. */
      else
	/* body is NULL (contains no SDP), generate a response to INVITE w/ no SDP */
	body = generating_no_sdp_answer(jc, jd, tr->orig_request, public_sdp_port ? public_sdp_port : local_sdp_port
					, public_video_port ? public_video_port : local_video_port);
    }
  
  if (jd==NULL)
    i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
  else
    i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);

  if (i!=0)
    {
      OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n"));
      code = 500; /* ? which code to use? */
      osip_free(body); /* not used */
      return -1;
    }

  if (code==488)
    {
      osip_message_set_content_length(response, "0");
      /*  TODO: send message to transaction layer */
      osip_free(body);
      evt_answer = osip_new_outgoing_sipmessage(response);
      evt_answer->transactionid = tr->transactionid;
      osip_transaction_add_event(tr, evt_answer);
	  __eXosip_wakeup();
      return 0;
    }

  if ( ! body ) {
    fprintf(stderr, "%s,%d: body is NULL\n", __FILE__, __LINE__);
    return -1;
  }

  i = osip_message_set_body(response, body, strlen(body));
  if (i!=0) {
    goto g2atii_error_1;
  }
  size = (char *) osip_malloc(6*sizeof(char));
#ifdef __APPLE_CC__
  sprintf(size,"%li",strlen(body));
#else
  sprintf(size,"%i",strlen(body));
#endif
  i = osip_message_set_content_length(response, size);
  osip_free(size);
  if (i!=0) goto g2atii_error_1;
  i = osip_message_set_content_type(response, "application/sdp");
  if (i!=0) goto g2atii_error_1;

  /* request that estabish a dialog: */
  /* 12.1.1 UAS Behavior */
  {
    i = complete_answer_that_establish_a_dialog2(response, tr->orig_request, ctct);
    if (i!=0) goto g2atii_error_1;; /* ?? */
  }

  osip_free(body);
  /* THIS RESPONSE MUST BE SENT RELIABILY until the final ACK is received !! */
  /* this response must be stored at the upper layer!!! (it will be destroyed*/
  /* right after being sent! */

  if (jd==NULL)
    {
      i = eXosip_dialog_init_as_uas(&jd, owsip_transaction_account_get (tr), tr->orig_request, response);
      if (i!=0)
	{
     OSIP_TRACE (osip_trace
		 (__FILE__, __LINE__, OSIP_ERROR, NULL,
	     "eXosip: cannot create dialog!\n"));
	  return -1;
	}
      ADD_ELEMENT(jc->c_dialogs, jd);
    }

  eXosip_dialog_set_200ok(jd, response);
  evt_answer = osip_new_outgoing_sipmessage(response);
  evt_answer->transactionid = tr->transactionid;

  osip_transaction_add_event(tr, evt_answer);

  osip_dialog_set_state(jd->d_dialog, DIALOG_CONFIRMED);
  __eXosip_wakeup();
  return 0;

 g2atii_error_1:
  osip_free(body);
  osip_message_free(response);
  return -1;
}
Ejemplo n.º 16
0
int
eXosip_answer_invite_2xx_with_body(eXosip_call_t *jc, eXosip_dialog_t *jd, int code,const char*bodytype, const char*body)
{
  osip_event_t *evt_answer;
  osip_message_t *response;
  int i;
  char *size;
  osip_transaction_t *tr;
  tr = eXosip_find_last_inc_invite(jc, jd);

  if (tr==NULL || tr->orig_request==NULL)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: cannot find transaction to answer\n"));
      return -1;
    }

  if (jd!=NULL && jd->d_dialog==NULL)
    {  /* element previously removed */
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: cannot answer this closed transaction\n"));
      return -1;
    }

  /* is the transaction already answered? */
  if (tr->state==IST_COMPLETED
      || tr->state==IST_CONFIRMED
      || tr->state==IST_TERMINATED)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: transaction already answered\n"));
      return -1;
    }
  
  if (jd==NULL)
    i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
  else
    i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);

  if (i!=0)
    {
      OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n"));
      code = 500; /* ? which code to use? */
      return -1;
    }

  if (code==488)
    {
      osip_message_set_content_length(response, "0");
      /*  TODO: send message to transaction layer */
      evt_answer = osip_new_outgoing_sipmessage(response);
      evt_answer->transactionid = tr->transactionid;
      osip_transaction_add_event(tr, evt_answer);
  __eXosip_wakeup();
      return 0;
    }

  if ( ! body ) {
    fprintf(stderr, "%s,%d: body is NULL\n", __FILE__, __LINE__);
    return -1;
  }


  i = osip_message_set_body(response, body, strlen(body));
  if (i!=0) {
    goto g2atii_error_1;
  }
  size = (char *) osip_malloc(6*sizeof(char));
  sprintf(size,"%i",strlen(body));
  i = osip_message_set_content_length(response, size);
  osip_free(size);
  if (i!=0) goto g2atii_error_1;
  i = owsip_message_set_header(response, "content-type", bodytype);
  if (i!=0) goto g2atii_error_1;

  /* request that estabish a dialog: */
  /* 12.1.1 UAS Behavior */
    i = complete_answer_that_establish_a_dialog(response, tr->orig_request);
    if (i!=0) goto g2atii_error_1; /* ?? */
  /* THIS RESPONSE MUST BE SENT RELIABILY until the final ACK is received !! */
  /* this response must be stored at the upper layer!!! (it will be destroyed*/
  /* right after being sent! */

  if (jd==NULL)
    {
      i = eXosip_dialog_init_as_uas(&jd, owsip_transaction_account_get (tr), tr->orig_request, response);
      if (i!=0)
	{
     OSIP_TRACE (osip_trace
		 (__FILE__, __LINE__, OSIP_ERROR, NULL,
	     "eXosip: cannot create dialog!\n"));
	  return -1;
	}
      ADD_ELEMENT(jc->c_dialogs, jd);
    }

  eXosip_dialog_set_200ok(jd, response);
  evt_answer = osip_new_outgoing_sipmessage(response);
  evt_answer->transactionid = tr->transactionid;

  osip_transaction_add_event(tr, evt_answer);

  osip_dialog_set_state(jd->d_dialog, DIALOG_CONFIRMED);
  __eXosip_wakeup();
  return 0;

 g2atii_error_1:
  osip_message_free(response);
  return -1;
}
Ejemplo n.º 17
0
int
eXosip_answer_options_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code)
{
  osip_event_t *evt_answer;
  osip_transaction_t *tr;
  osip_message_t *response;
  sdp_message_t *sdp;
  char *body;
  char size[10];
  int i;

  tr = eXosip_find_last_inc_options(jc, jd);
  if (tr==NULL)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: cannot find transaction to answer"));
      return -1;
    }
  osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &sdp, "10400", NULL);
  if (sdp==NULL)
    {
      return -1;
    }
  if (jd!=NULL)
    {
      i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
    }
  else
    {
      i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
    }
  if (i!=0)
    {
      OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for options\n"));
      sdp_message_free(sdp); /* not used */
      return -1;
    }
  i = sdp_message_to_str(sdp, &body);
  sdp_message_free(sdp);
  if ( ( i!=0 ) || ( ! body ) ) {
    osip_message_free(response);
    return -1;
  }
  
  i = osip_message_set_body(response, body, strlen(body));
  if (i!=0) {
    osip_message_free(response);
    return -1;
  }
#ifdef __APPLE_CC__
  snprintf(size, 9,"%li",strlen(body));
#else
  snprintf(size, 9,"%i",strlen(body));
#endif
  i = osip_message_set_content_length(response, size);
  if (i!=0) {
    osip_free(body);
    osip_message_free(response);
    return -1;
  }
  osip_free(body);
  i = osip_message_set_content_type(response, "application/sdp");
  if (i!=0) {
    osip_message_free(response);
    return -1;
  }

  evt_answer = osip_new_outgoing_sipmessage(response);
  evt_answer->transactionid = tr->transactionid;

  osip_transaction_add_event(tr, evt_answer);
  __eXosip_wakeup();
  return 0;
}
Ejemplo n.º 18
0
int uas_invite(sipua_uas_t *sipuas, const char *to, sipua_call_t* call_info, char* sdp_body, int sdp_bytes)
{
	eXosipua_t *jua = (eXosipua_t*)sipuas;
    
	osip_message_t *invite;
	char sdp_size[8];

	char* proxy = NULL;

	int ret;

	char *from = call_info->user_prof->regname;

	/*
	OSIP_TRACE (osip_trace(__FILE__, __LINE__, OSIP_INFO2, NULL, "To: |%s|\n", to));
	*/
	if (0!=jua_check_url(from))
	{
		jua_log(("uas_call: illigal sip id!\n"));
		return UA_FAIL;

	}

   if (0!=jua_check_url(to))
	{
		jua_log(("uas_invite: illigal sip destination\n"));
		return UA_FAIL;
	}

	if(jua->sipuas.proxy[0]!='\0')
   {
		proxy = uas_check_route(jua->sipuas.proxy);
   }
#if 0
	else
   {
      proxy = uas_check_route(call_info->user_prof->registrar);
   }
#endif

	sprintf(sdp_size,"%i", sdp_bytes);

   printf("uas_invite: [%s] from %s to %s, proxy[%s]\n", call_info->subject, from, to, proxy);
	printf("\n-------Initiate SDP [%d bytes]--------\n", sdp_bytes);
	printf("Callid[%s]\n", call_info->setid.id);
	printf("----------------------------------------\n");
	printf("%s", sdp_body);
	printf("----------------------------------------\n");

	if (eXosip_build_initial_invite(&invite, to, from, proxy, call_info->subject) != 0)
		return UA_FAIL;

	/* sdp content of the call */
	osip_message_set_content_type(invite, "application/sdp");
   osip_message_set_content_length(invite, sdp_size);
	osip_message_set_body(invite, sdp_body, sdp_bytes);
   
	eXosip_lock();
   
	ret = eXosip_initiate_call(invite, call_info, NULL/*negotiation_reference*/, NULL/*local_audio_port*/);

	eXosip_unlock();
	
   if(proxy)
      osip_free(proxy);
   
	/*When to free it ???
	osip_message_free(invite);
	*/

	return ret;
}
int
_eXosip_insubscription_auto_send_notify (int did,
                                         int subscription_status,
                                         int subscription_reason)
{
  osip_message_t *notify;
  int i;
  char xml[4096];
  char *entity;
  eXosip_call_t *jc;
  eXosip_dialog_t *jd;

  if (did <= 0)
    return OSIP_BADPARAMETER;

  i = eXosip_insubscription_build_notify (did, subscription_status,
                                          subscription_reason, &notify);
  if (i != 0)
    {
      return i;
    }

  /* build dialog xml state */
  memset (xml, 0, sizeof (xml));

  i = osip_uri_to_str (notify->from->url, &entity);
  if (i != 0 || entity == NULL)
    {
      osip_message_free (notify);
      return i;
    }
  snprintf (xml, sizeof (xml),
            "<?xml version=\"1.0\"?>" "\r\n"
            "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\"" "\r\n"
            "	version=\"2\" state=\"full\"" "\r\n"
            "	entity=\"%s\">" "\r\n", entity);
  osip_free (entity);

  /* loop over all jc/jd */
  for (jc = eXosip.j_calls; jc != NULL; jc = jc->next)
    {
      for (jd = jc->c_dialogs; jd != NULL; jd = jd->next)
        {
          if (jd->d_dialog == NULL)     /* finished call */
            {
          } else
            {
              char tmp_dialog[2048];
              char direction[20];
              char dlg_state[20];
              char *remote_uri = NULL;

              if (jd->d_dialog->type == CALLER)
                strcpy (direction, "initiator");
              else
                strcpy (direction, "recipient");
              if (jd->d_dialog->state == DIALOG_CONFIRMED)
                strcpy (dlg_state, "confirmed");
              else
                strcpy (dlg_state, "early");

              if (jd->d_dialog->remote_uri != NULL
                  && jd->d_dialog->remote_uri->url != NULL)
                {
                  osip_uri_to_str (jd->d_dialog->remote_uri->url, &remote_uri);
                }
              if (remote_uri != NULL)
                {
                  /* add dialog info */
                  snprintf (tmp_dialog, sizeof (tmp_dialog),
                            "	<dialog id=\"%s\" call-id=\"%s\"" "\r\n"
                            "		local-tag=\"%s\" remote-tag=\"%s\""
                            "\r\n" "		direction=\"%s\">"
                            "\r\n"
                            "		<state>%s</state>"
                            "\r\n"
                            "		<remote>"
                            "\r\n"
                            "			<identity>%s</identity>"
                            "\r\n"
                            "		</remote>"
                            "\r\n"
                            "	</dialog>"
                            "\r\n",
                            jd->
                            d_dialog->
                            call_id,
                            jd->
                            d_dialog->
                            call_id,
                            jd->
                            d_dialog->
                            local_tag,
                            jd->
                            d_dialog->
                            remote_tag, direction, dlg_state, remote_uri);
                  strcat (xml, tmp_dialog);
                }
            }
        }
    }
  strcat (xml, "</dialog-info>" "\r\n");
  osip_message_set_content_type (notify, "application/dialog-info+xml");
  osip_message_set_body (notify, xml, strlen (xml));

  return eXosip_insubscription_send_request (did, notify);
}