Esempio n. 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;

}
Esempio n. 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;

}
Esempio n. 3
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);
}