exosip

exosip针对UA是对osip进行扩展,oSIP不提供不论什么高速产生请求消息和响应消息的方法,全部请求消息和响应消息的形成必须调用一组sip message api来手动组装完毕,所以作者在osip上基础上开发了exosip,用exosip开发软电话非常方便,仅需几个API就能够完毕.exosip中附带一个样例:josua,只是josua相对复杂了点,以下给出一个最简单的样例供大家參考,由于样例实在太简单所以没有给出凝视,用到exosip的API的參数请參看exosip源码,看懂这个样例再研究josua就非常easy了.我使用的是osip 2.0.9+exosip 0.77.

#include "assert.h"
#include <conio.h>
#include <iostream>
#include <osip2/osip_mt.h>
#include <eXosip/eXosip.h>
#include <eXosip/eXosip_cfg.h>

using namespace std;

class jcall;

class jcall {
public:
 int cid;
 int did;
 
 char reason_phrase[50];
 int  status_code;
 
 char textinfo[256];
 char req_uri[256];
 char local_uri[256];
 char remote_uri[256];
 char subject[256];
 
 char remote_sdp_audio_ip[50];
 int  remote_sdp_audio_port;
 int  payload;
 char payload_name[50];
 
 int state;
 
 jcall() {}
 
 int build(eXosip_event_t *je)
 {
  jcall *ca = this;
  
  ca->cid = je->cid;
  ca->did = je->did;
  
  if (ca->did<1 && ca->cid<1)
  {
   assert(0);
   return -1; /* not enough information for this event?? */
  }
  
  osip_strncpy(ca->textinfo,   je->textinfo, 255);
  osip_strncpy(ca->req_uri,    je->req_uri, 255);
  osip_strncpy(ca->local_uri,  je->local_uri, 255);
  osip_strncpy(ca->remote_uri, je->remote_uri, 255);
  osip_strncpy(ca->subject,    je->subject, 255);
  
  if (ca->remote_sdp_audio_ip[0]==‘/0‘)
  {
   osip_strncpy(ca->remote_sdp_audio_ip, je->remote_sdp_audio_ip, 49);
   ca->remote_sdp_audio_port = je->remote_sdp_audio_port;
   ca->payload = je->payload;
   osip_strncpy(ca->payload_name, je->payload_name, 49);
   
  }
  
  if (je->reason_phrase[0]!=‘/0‘)
  {
   osip_strncpy(ca->reason_phrase, je->reason_phrase, 49);
   ca->status_code = je->status_code;
  }
  
  ca->state = je->type;
  return 0;
 }
 
};

jcall call;

void __exit( int r )
{
 char line[256];
 gets( line );
 exit( r );
}

void josua_printf(char* buf)
{
 printf( "/n" );
}

int josua_event_get()
{
 int counter =0;
 /* use events to print some info */
 eXosip_event_t *je;
 for (;;)
 {
  char buf[100];
  je = eXosip_event_wait(0,50);
  if (je==NULL)
   break;
  counter++;
  if (je->type==EXOSIP_CALL_NEW)
  {
   printf( "<- (%i %i) INVITE from: %s",
    je->cid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
   call.build(je);
  }
  else if (je->type==EXOSIP_CALL_ANSWERED)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_PROCEEDING)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_RINGING)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_REDIRECTED)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_REQUESTFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_SERVERFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_GLOBALFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_CLOSED)
  {
   printf( "<- (%i %i) BYE from: %s",
    je->cid, je->did, je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_HOLD)
  {
   printf( "<- (%i %i) INVITE (On Hold) from: %s",
    je->cid, je->did, je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_OFFHOLD)
  {
   printf( "<- (%i %i) INVITE (Off Hold) from: %s",
    je->cid, je->did, je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_REGISTRATION_SUCCESS)
  {
   printf( "<- (%i) [%i %s] %s for REGISTER %s",
    je->rid,
    je->status_code,
    je->reason_phrase,
    je->remote_uri,
    je->req_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_REGISTRATION_FAILURE)
  {
   printf( "<- (%i) [%i %s] %s for REGISTER %s",
    je->rid,
    je->status_code,
    je->reason_phrase,
    je->remote_uri,
    je->req_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_NEW)
  {
   printf( "<- (%i %i) OPTIONS from: %s",
    je->cid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_OPTIONS_ANSWERED)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_PROCEEDING)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_OPTIONS_REDIRECTED)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_REQUESTFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_SERVERFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_GLOBALFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_NEW)
  {
   printf( "<- (%i %i) INFO from: %s",
    je->cid, je->did,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_ANSWERED)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_PROCEEDING)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_REDIRECTED)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_REQUESTFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_SERVERFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_GLOBALFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s",
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  
  else if (je->type==EXOSIP_SUBSCRIPTION_ANSWERED)
  {
   printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
   
   printf( "<- (%i %i) online=%i [status: %i reason:%i]",
    je->sid, je->did,
    je->online_status,
    je->ss_status,
    je->ss_reason);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_PROCEEDING)
  {
   printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_REDIRECTED)
  {
   printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_REQUESTFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_SERVERFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_GLOBALFAILURE)
  {
   printf( "<- (%i %i) [%i %s] %s for SUBSCRIBE",
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_NOTIFY)
  {
   printf( "<- (%i %i) NOTIFY from: %s",
    je->sid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
   printf( "<- (%i %i) online=%i [status: %i reason:%i]",
    je->sid, je->did,
    je->online_status,
    je->ss_status,
    je->ss_reason);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_IN_SUBSCRIPTION_NEW)
  {
   printf( "<- (%i %i) SUBSCRIBE from: %s",
    je->nid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
   /* search for the user to see if he has been
   previously accepted or not! */
   
   eXosip_notify(je->did, EXOSIP_SUBCRSTATE_PENDING, EXOSIP_NOTIFY_AWAY);
  }
  else if (je->textinfo[0]!=‘/0‘)
  {
   printf( "(%i %i %i %i) %s", je->cid, je->sid, je->nid, je->did, je->textinfo);
   josua_printf(buf);
  }
  
  
  eXosip_event_free(je);
    }
 if (counter>0)
  return 0;
 return -1;
}

int main(int argc, char* argv[])
{
 int i;
 memset( &call, 0, sizeof(call) );
 
 cout << "Usage:"<< endl;
 cout << "a - answering call"<< endl;
 cout << "h - hangup"<< endl;
 cout << "r - ringing"<< endl;
 cout << "c - call"<< endl;
 cout << "q - quit"<< endl;
 
 FILE* logfile = fopen( "logfile.txt", "w");
 // osip_trace_initialize( (_trace_level)0, logfile );
 // osip_trace_initialize( (_trace_level)8, stdout );
 i = eXosip_init(stdin, stdout, 5060);
 if (i!=0)
    {
  fprintf (stderr, "test: could not initialize eXosip/n");
  __exit(0);
  
    }
 
 
 eXosip_sdp_negotiation_remove_audio_payloads();
 eXosip_sdp_negotiation_add_codec(osip_strdup("0"),
  NULL,
  osip_strdup("RTP/AVP"),
  NULL, NULL, NULL,
  NULL,NULL,
  osip_strdup("0 PCMU/8000"));
 
 eXosip_sdp_negotiation_add_codec(osip_strdup("8"),
  NULL,
  osip_strdup("RTP/AVP"),
  NULL, NULL, NULL,
  NULL,NULL,
  osip_strdup("8 PCMA/8000"));
   
 /* register callbacks? */
 eXosip_set_mode(EVENT_MODE);
 
 osip_message_t *invite;
 i = eXosip_build_initial_invite(&invite,
  "sip:192.168.197.5:5060",       //被叫对IP
  "sip:192.168.197.254:5060",     //自己IP
  NULL,
  "oSIP phone");
 if (i!=0)
 {
  fprintf (stderr, "eXosip_build_initial_invite failed/n");
  __exit(0);
 }
 
 
 cout << "oSIP>";
 bool run = true;
 while( run )
 {
  josua_event_get();
  
  if ( _kbhit() )
  {
   switch ( _getch() )
   {
   case ‘a‘:
    cout << "answer"<< endl;
    eXosip_lock();
    eXosip_answer_call(call.did, 200, 0);
    eXosip_unlock();
    break;
    
   case ‘h‘:
    cout << "hangup"<< endl;
    eXosip_lock();
    eXosip_terminate_call( call.cid, call.did );
    eXosip_unlock();
    break;
    
   case ‘r‘:
    cout << "ringing"<< endl;
    eXosip_lock();
    eXosip_answer_call(call.did, 180, 0);
    eXosip_unlock();
    break;
    
   case ‘c‘:
    cout << "call"<< endl;
    eXosip_lock();
    eXosip_initiate_call(invite, NULL, NULL, "10500");
    eXosip_unlock();
    break;
    
   case ‘q‘:
    cout << "quit"<< endl;
    run = false;
    break;
    
   default :
    cout << "/noSIP>";
   }
  }
 }
 
 
 return 0;
}

时间: 2024-10-23 20:14:57

exosip的相关文章

osip及eXosip的编译方法

在最新版本的osip2.exosip2中不支持在VC6.0下编译osip.exosip协议栈的方法 说明: 1.以下文章中的osip版本为3.1.0 2.eXosip版本为3.1.0 3.编译环境为:Windows XP 专业版本+VS 2005 4.实例程序下载:http://download.csdn.net/source/617797 5.osip.exosip.openssl的开发包下载,开发包包括:osip2.dll.osipparser2.dll.exosip2.dll.libeay

linux下编译eXosip、osip,以及UAC和UAS的例子

从网站上看到了这样的一篇博文 :Windows下编译eXosip.osip,以及UAC和UAS的例子 (链接:http://www.cnblogs.com/dyllove98/archive/2013/06/25/3155427.html) 觉得对学习sip的初学者,包括我,都是很有帮助的.但是那是在window下的编译,我在这里稍微改了一下,让它支持在linux下编译测试运行通过. 我们这里使用库的版本:libosip2-3.6.0.tar,libeXosip2-3.6.0.tar,大家可以自

exosip 和 pjsip 简介

 oSIP oSIP的开发开始于2000年7月,第一个版本在2001年5月发 布,到现在已经发展到3.x了.它采用ANSI C编写,而且结 构简单小巧,所以速度特别快,它并不提供高层的SIP会话 控制API,它主要提供一些解析SIP/SDP消息的API和事务处理 的状态机,oSIP的作者还开发了基于oSIP的UA lib:exosip和 proxy server lib:partysip. oSIP支持的功能: exosip针对UA是对osip进行扩展,oSIP不提供任何快速产生请求消息和响应消

eXosip的register注册

转载于:http://blog.sina.com.cn/s/blog_4868f98601018ioh.html 这个测试程序是从eXosip原有的测试程序改造的.原程序是tools 目录下的 sip_reg.c 本程序主要改造了这几个地方: 1) eXosip_event_wait() 函数的超时时间,从原来的1ms 修改为50ms 2) 对于初次注册时,服务器返回401的情况.  调用函数 eXosip_add_authentication_info()发送鉴权信息. 其余的内容基本没改,在

Osip2和eXosip协议栈的简析

Osip2是一个开放源代码的sip协议栈,是开源代码中不多使用C语言写的协议栈之一,它具有短小简洁的特点,专注于sip底层解析使得它的效率比较高. eXosip是Osip2的一个扩展协议集,它部分封装了Osip2协议栈,使得它更容易被使用. 一.介绍 Osip2是一个开放源代码的sip协议栈,是开源代码中不多使用C语言写的协议栈之一,它具有短小简洁的特点,专注于sip底层解析使得它的效率比较高.但缺点也很明显,首先就是可用性差,没有很好的api封装,使得上层应用在调用协议栈时很破碎:其次,只做到

SIP开发环境的搭建(转)

IP开发环境的搭建(转) 要在windows或者linux平台下开发基于SIP的软电话,需要以下软件 服务器端软件: 注册多个客户端到服务器上,可以进行通话测试 SIP客户端软件:主要用于测试,可以对别人已经完成的客户端进行抓包,以比对自己程序的发包数据 SIP协议栈:基于某个现成的SIP协议栈来开发会加快开发进度 RTP栈:传输语言或者视频数据的协议栈 抓包测试工具:调试网络程序最有效的办法 以下介绍这些软件主要以开源软件为主 一 服务器端软件 1. Asterisk:Linux系统下开源的I

几种开源SIP协议栈对比OPAL,VOCAL,sipX,ReSIProcate,oSIP

随着VoIP和NGN技术的发展,H.323时代即将过渡到SIP时代,在H.323的开源协议栈中,Openh323占统治地位,它把一个复杂而又先进 的H.323协议栈展现在普通程序员的眼前,为H.323普及立下了汗马功劳.而然当在SIP时代,则出现了群雄割据的状况,SIP相对于H.323简 单,灵活,于是各种协议栈层出不穷,下面将详细对比最具有代表性的5个开源项目:OPAL,VOCAL,sipX,ReSIProcate,oSIP OPAL是Open Phone Abstraction Librar

libeXosip2(2-1) -- eXosip2 configuration API

eXosip2 configuration API General purpose API. Data Structures struct   eXosip_dns_cache struct   eXosip_tls_credentials_s struct   eXosip_tls_ctx_s Macros #define  EXOSIP_OPT_UDP_KEEP_ALIVE   (EXOSIP_OPT_BASE_OPTION+1) #define  EXOSIP_OPT_UDP_LEARN_

libeXosip2(2-3) -- eXosip2 event API

eXosip2 event API General purpose API. Data Structures struct   eXosip_event Enumerations enum   eXosip_event_type { EXOSIP_REGISTRATION_SUCCESS, EXOSIP_REGISTRATION_FAILURE, EXOSIP_CALL_INVITE, EXOSIP_CALL_REINVITE, EXOSIP_CALL_NOANSWER, EXOSIP_CALL