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;
}
exosip的更多相关文章
- linux下编译eXosip、osip,以及UAC和UAS的例子
从网站上看到了这样的一篇博文 :Windows下编译eXosip.osip,以及UAC和UAS的例子 (链接:http://www.cnblogs.com/dyllove98/archive/2013 ...
- Windows下编译eXosip、osip,以及UAC和UAS的例子
今天开始了SIP开源库的学习,我选择了osip和eXosip,但是这两个库的编译使用有些麻烦,源码下来之后编译会出现很多问题,网上也没有找到完整的编译介绍,只能一步一步的找办法解决,最后终于编译成功! ...
- osip及eXosip的编译方法
osip及eXosip的编译方法 在最新版本的osip2.exosip2中不支持在VC6.0下编译osip.exosip协议栈的方法 说明: 1.以下文章中的osip版本为3.1.0 2.eXosip ...
- [置顶] 我的GB28181标准开发里程碑——基于eXosip的IPC端与SPVMN注册成功
昨天编译搭建好eXosip的开发环境后,今天完成了SIP注册功能,里程碑一战啊!加油加油,成功就在眼前! 今天基于eXosip做了一个IPC客户端,成功与公安部的SPVMN视频监控联网调测软件自测工具 ...
- eXosip sip
eXosip是对osip的封装,是对sip协议的使用更简单.osip是gnu开源的sip协议实现. 介绍: http://savannah.nongnu.org/projects/exosip 下载地 ...
- 利用exosip DNS CACHE自定义SIP服务器地址和端口
文章标题可能表述不清,罢了,我这里描述一个场景: 当使用exosip开发UA时,服务器地址是域名example.com和端口形式,但存在两个限制: 1.example.com没有DNS记录.没有NAP ...
- Osip2和eXosip协议栈的简析
Osip2是一个开放源代码的sip协议栈,是开源代码中不多使用C语言写的协议栈之一,它具有短小简洁的特点,专注于sip底层解析使得它的效率比较高. eXosip是Osip2的一个扩展协议集,它部分封装 ...
- exosip/osip 杂项
exosip 对比osip osip2和eXosip2协议 exosip 和 pjsip 简介 如果要实现嵌入式设备上的SIP电话或者其它,PJSIP是我所见的Coding和Design最为优秀的了, ...
- exosip 和 pjsip 简介
oSIP oSIP的开发开始于2000年7月,第一个版本在2001年5月发 布,到现在已经发展到3.x了.它采用ANSI C编写,而且结 构简单小巧,所以速度特别快,它并不提供高层的SIP会话 控制 ...
随机推荐
- poj 4052(ac自动机)
题意:自己百度吧!! 分析:就是通过它的fail指针来找出它的子串就行了,这题其实不难的.这好像还是金华邀请赛的题哦! 代码实现: #include<cstdio> #include< ...
- 15、自定义Content Provider
自定义Content Provider的步骤 1. 编写一个类,该类必须继承自ContentProvider类. 实现ContentProvider类中所有的抽象方法. 定义Content ...
- HNU 13108-Just Another Knapsack Problem (ac自动机上的dp)
题意: 给你一个母串,多个模式串及其价值,求用模式串拼接成母串(不重叠不遗漏),能获得的最大价值. 分析: ac自动机中,在字典树上查找时,用dp,dp[i]拼成母串以i为结尾的子串,获得的最大价值, ...
- HDU 1025-Constructing Roads In JGShining's Kingdom(最长不降子序列,线段树优化)
分析: 最长不降子序列,n很大o(n^2)肯定超,想到了小明序列那个题用线段树维护前面的最大值即可 该题也可用二分搜索来做. 注意问题输出时的坑,路复数后加s #include <map> ...
- Survival(ZOJ 2297状压dp)
题意:有n个怪,已知杀死第i个怪耗费的血和杀死怪恢复的血,和杀死boss耗的血,血量不能超过100,若过程中血小于0,则失败,问 是否能杀死boss(boss最后出现). 分析:就是求杀死n个怪后剩余 ...
- 《Python 学习手册4th》 第十五章 文档
''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容 (每天看42页内容,可以保证月底看完此书) “重点 ...
- 解决duilib使用zip换肤卡顿的问题:修改duilib并使用资源文件换肤
转载请说明原出处,谢谢~~ 今天在做单子是,客户要求做换肤功能,为此我专门写了一个换肤函数,并且把各种皮肤资源压缩为各个zip文件来换肤.但是客户反映程序运行缓慢,我测试后发现的确明显可以看出慢了不少 ...
- restsharp发送服务端请求回传session
今天工作遇到这样一个场景,我需要获取一个游戏目录列表,这个列表接口在线上已经存在,但是这个接口需要登录认证后才能获取到,所以实现这个功能我打算分两部来做: 1.首先调登录接口,以写上session 2 ...
- 第二百五十八天 how can I 坚持
装虚拟机了.CentOs,32位,这电脑装4台能不能带起来啊. 早上,流鼻血了,不知道咋回事.太干了... 明天得早起会,得利索着点,不能托托拉拉的. 还有,今天又忘带钥匙了.悲剧. 睡觉.hadoo ...
- Delimiter must not be alphanumeric or backslash 问题及解决
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in 正则表达 ...