osip和mysql_osip2/eXosip2调试笔记

osip和mysql_osip2/eXosip2调试笔记软件版本:libosip2-3.3.0.tar.gzlibeXosip2-3.3.0.tar.gz./configure–prefix=/opt/sip/target–disable-staticmakemakeinstall测试代码:代码来源:http://blog.csdn.net/bat603/archive/2006/11/15/1386277.aspx1、UAS…

大家好,又见面了,我是你们的朋友全栈君。

软件版本: libosip2-3.3.0.tar.gz libeXosip2-3.3.0.tar.gz ./configure –prefix=/opt/sip/target –disable-static make make install 测试代码: 代码来源:http://blog.csdn.net/bat603/archive/2006/11/15/1386277.aspx 1、UAS //*******************U

软件版本:

libosip2-3.3.0.tar.gz

libeXosip2-3.3.0.tar.gz

./configure –prefix=/opt/sip/target –disable-static

make

make install

测试代码:

代码来源:http://blog.csdn.net/bat603/archive/2006/11/15/1386277.aspx

1、UAS

//*******************UAS**************************************************//

#include #include #include #include #include #include #include int

main (int argc, char *argv[])

{

eXosip_event_t *je = NULL;

osip_message_t *ack = NULL;

osip_message_t *invite = NULL;

osip_message_t *answer = NULL;

sdp_message_t *remote_sdp = NULL;

int call_id, dialog_id;

int i,j;

int id;

char *sour_call = “sip:133@192.168.0.133”;

char *dest_call = “sip:140@192.168.0.140:5060”;

char command;

char tmp[4096];

char localip[128];

int pos = 0;

//初始化sip

i = eXosip_init ();

if (i != 0)

{

printf (“Can’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, “eXosip_listen_addr error!/nCouldn’t initialize transport layer!/n”);

}

for(;;)

{

//侦听是否有消息到来

je = eXosip_event_wait (0,50);

//协议栈带有此语句,具体作用未知

eXosip_lock ();

eXosip_default_action (je);

eXosip_automatic_refresh ();

eXosip_unlock ();

if (je == NULL)//没有接收到消息

continue;

// printf (“the cid is %s, did is %s/n”, je->did, je->cid);

switch (je->type)

{

case EXOSIP_MESSAGE_NEW://新的消息到来

printf (” EXOSIP_MESSAGE_NEW!/n”);

if (MSG_IS_MESSAGE (je->request))//如果接受到的消息类型是MESSAGE

{

{

osip_body_t *body;

osip_message_get_body (je->request, 0, &body);

printf (“I get the msg is: %s/n”, body->body);

//printf (“the cid is %s, did is %s/n”, je->did, je->cid);

}

//按照规则,需要回复200 OK信息

eXosip_message_build_answer (je->tid, 200,&answer);

eXosip_message_send_answer (je->tid, 200,answer);

}

break;

case EXOSIP_CALL_INVITE:

//得到接收到消息的具体信息

printf (“Received a INVITE msg from %s:%s, UserName is %s, password is %s/n”,je->request->req_uri->host,

je->request->req_uri->port, je->request->req_uri->username, je->request->req_uri->password);

//得到消息体,认为该消息就是SDP格式.

remote_sdp = eXosip_get_remote_sdp (je->did);

call_id = je->cid;

dialog_id = je->did;

eXosip_lock ();

eXosip_call_send_answer (je->tid, 180, NULL);

i = eXosip_call_build_answer (je->tid, 200, &answer);

if (i != 0)

{

printf (“This request msg is invalid!Cann’t response!/n”);

eXosip_call_send_answer (je->tid, 400, NULL);

}

else

{

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”);

//设置回复的SDP消息体,下一步计划分析消息体

//没有分析消息体,直接回复原来的消息,这一块做的不好。

osip_message_set_body (answer, tmp, strlen(tmp));

osip_message_set_content_type (answer, “application/sdp”);

eXosip_call_send_answer (je->tid, 200, answer);

printf (“send 200 over!/n”);

}

eXosip_unlock ();

//显示出在sdp消息体中的 attribute 的内容,里面计划存放我们的信息

printf (“the INFO is :/n”);

while (!osip_list_eol (remote_sdp->a_attributes, pos))

{

sdp_attribute_t *at;

at = (sdp_attribute_t *) osip_list_get (remote_sdp->a_attributes, pos);

printf (“%s : %s/n”, at->a_att_field, at->a_att_value);//这里解释了为什么在SDP消息体中属性a里面存放必须是两列

pos ++;

}

break;

case EXOSIP_CALL_ACK:

printf (“ACK recieved!/n”);

// printf (“the cid is %s, did is %s/n”, je->did, je->cid);

break;

case EXOSIP_CALL_CLOSED:

printf (“the remote hold the session!/n”);

// eXosip_call_build_ack(dialog_id, &ack);

//eXosip_call_send_ack(dialog_id, ack);

i = eXosip_call_build_answer (je->tid, 200, &answer);

if (i != 0)

{

printf (“This request msg is invalid!Cann’t response!/n”);

eXosip_call_send_answer (je->tid, 400, NULL);

}

else

{

eXosip_call_send_answer (je->tid, 200, answer);

printf (“bye send 200 over!/n”);

}

break;

case EXOSIP_CALL_MESSAGE_NEW://至于该类型和EXOSIP_MESSAGE_NEW的区别,源代码这么解释的

/*

/* request related events within calls (except INVITE) */

EXOSIP_CALL_MESSAGE_NEW, /**< announce new incoming request. */

/* response received for request outside calls */

EXOSIP_MESSAGE_NEW, /**< announce new incoming request. */

我也不是很明白,理解是: EXOSIP_CALL_MESSAGE_NEW是一个呼叫中的新的消息到来,比如ring trying都算,所以在接受到后必须判断

该消息类型,EXOSIP_MESSAGE_NEW而是表示不是呼叫内的消息到来。

该解释有不妥地方,仅供参考。

*/

printf(” EXOSIP_CALL_MESSAGE_NEW/n”);

if (MSG_IS_INFO(je->request))//如果传输的是INFO方法

{

eXosip_lock ();

i = eXosip_call_build_answer (je->tid, 200, &answer);

if (i == 0)

{

eXosip_call_send_answer (je->tid, 200, answer);

}

eXosip_unlock ();

{

osip_body_t *body;

osip_message_get_body (je->request, 0, &body);

printf (“the body is %s/n”, body->body);

}

}

break;

default:

printf (“Could not parse the msg!/n”);

}

}

}

>> gcc uastest.c -o uastest -L/opt/sip/target/lib/ -I/opt/sip/target/include/ -leXosip2

问题及其解决:

编译问题:

uastest.c: In function `main’:

uastest.c:118: incompatible type for argument 1 of `osip_list_eol’

uastest.c:122: incompatible type for argument 1 of `osip_list_get’

解决方法:

The osip_list_* interface has been changed in latest versions of

osip and osip_list_t in structures are not pointer any more.

I think Updating is just a matter of adding “&” in front of

remote_sdp->m_medias and to other list accessed.

运行问题:

[root@localhost linphonenew]# ./uastest

./uastest: error while loading shared libraries: libosipparser2.so.4: cannot open shared object file: No such file or directory

解决方法:

#libosipparser2相关库文件复制到usr、lib目录下面

cp /opt/sip/target/lib/libosipp* /usr/lib

2、uac

#include #include #include #include #include #include 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:140@192.168.0.140”;

char *registerer = “sip:192.168.0.133:5060”;

char *source_call = “sip:140@192.168.0.140”;

char *dest_call = “sip:133@192.168.0.133: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);

}

>> gcc uastest.c -o uastest -L/opt/sip/target/lib/ -I/opt/sip/target/include/ -leXosip2

3/ 单机测试指导

本机ip:192.168.3.168

uac修改:

line23-26改为:

char *identity=”sip:140@192.168.3.168″; //UAC1,端口是5060

char *registar=”sip:133@192.168.3.168:5061″; //UAS,端口是5061

char *source_call=”sip:140@192.168.3.168″;

char *dest_call=”sip:133@192.168.3.168:5061″;

uas修改:

line44改为: i = eXosip_listen_addr (IPPROTO_UDP, NULL, 5061, AF_INET, 0);

其他:

http://hi.baidu.com/yangkaiii/blog/item/e2946f44ecdeaa86b3b7dc5d.html

http://hi.baidu.com/yangkaiii/blog/item/e46a59dde1ad5e305882dd5c.html

4/ 呼叫彩E

本机ip:192.168.3.168

彩E:192.168.3.167

line80到85改为:

snprintf (tmp, 4096,

“v=0/r/n”

“o=- 6 2 IN IP4 192.168.3.46/r/n”

“s=CounterPath X-Lite 3.0/r/n”

“c=IN IP4 192.168.3.46/r/n”

“t=0 0/r/n”

“m=audio 52386 RTP/AVP 107 0 8 101/r/n”

“a=alt:1 1 : 0+Y3WBhV SIknnQeS 192.168.3.46 52386/r/n”

“a=fmtp:101 0-15/r/n”

“a=rtpmap:107 BV32/16000/r/n”

“a=rtpmap:101 telephone-event/8000/r/n”

“a=sendrecv/r/n”);

line26:

char *dest_call=”sip:111@192.168.3.167:5060″;

注意:111的用户名不能就是该彩E的账号,不能随便换成其他的121之类,否则得到busy之类的应答信息。

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/149500.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • linux1521端口不通,Linux开放1521端口允许网络连接Oracle Listene「建议收藏」

    linux1521端口不通,Linux开放1521端口允许网络连接Oracle Listene「建议收藏」症状:1.TCP/IP连接是通的。可以用ping命令测试。2.服务器上OracleListener已经启动。lsnrctlstatus查看listener状态lsnrctlstart启动Oraclelistener3.客户端得到的错误信息通常是:ORA-12170:TNS:连接超时这时,我们基本可以肯定是服务器没有开放1521端口(假设你用默认设置)解决方法:1.假…

  • 关于input type=“file”的及其files对象的深层探究

    关于input type=“file”的及其files对象的深层探究我们都知道,html5中有个inputtype=file元素。用该元素可以实现页面上传文件的功能但一般的做法只是简单的在表单中操作,我来研究一下深层东西想要了解它,就要知道它的内置对象,files页面上写一个input,然后选俩个图片,打印这个input对象$(“input[name=’file1′]”).change(function(e){console.log…

  • 【机器学习】一文读懂正则化与LASSO回归,Ridge回归

    【机器学习】一文读懂正则化与LASSO回归,Ridge回归该文已经收录到专题机器学习进阶之路当中,欢迎大家关注。1.过拟合当样本特征很多,样本数相对较少时,模型容易陷入过拟合。为了缓解过拟合问题,有两种方法:方法一:减少特征数量(人工选择重要特征来保留,会丢弃部分信息)。方法二:正则化(减少特征参数的数量级)。2.正则化(Regularization)正则化是结构风险(损失函数+正则化项)最小化策略的体…

  • nginx设置ip访问就跳转域名_php页面跳转方法

    nginx设置ip访问就跳转域名_php页面跳转方法目的:将所有wangqiao123.comabc.wangqiao123.com域名自动跳转到www.wangqiao123.comserver{listen80;server_namewangqiao123.comabc.wangqiao123.com;…

  • Ubuntu下使用SSH 命令用于登录远程桌面

    Ubuntu下使用SSH 命令用于登录远程桌面问题描述基础:ssh命令连接step1:SSH程序的安装step2:服务器启动ssh服务step3:查询服务器的ip地址step4:在本地主机端ssh远程登录服务器step5:退出远程登录进阶:利用公钥省去口令输入step1生成密钥对step2复制公钥至服务器参考资料问题描述做DL的经常需要在一台电脑(本地主机)上写代码,另一台电脑(服务器…

    2022年10月21日
  • 怎样把文件保存在回收站而不丢失

    怎样把文件保存在回收站而不丢失

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号