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;
}
Example #2
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;
	}
Example #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);
}