eXosip使用实例.docx
《eXosip使用实例.docx》由会员分享,可在线阅读,更多相关《eXosip使用实例.docx(20页珍藏版)》请在冰豆网上搜索。
![eXosip使用实例.docx](https://file1.bdocx.com/fileroot1/2022-10/27/fe8e0e75-9b15-4a1f-9f66-62c3633b03f4/fe8e0e75-9b15-4a1f-9f66-62c3633b03f41.gif)
eXosip使用实例
ifeq(1,1)
PWD=$(shellpwd)
LIBCODEPATH=/usr/src
LIBPATH=/usr/local
all:
osip2eXosip2myproj
osip2:
@echo"willmakeosip2";echo;echo
@cd$(LIBCODEPATH)/libosip2-3.6.0;echo-n"pwdis:
";pwd;echo;echo;make;makeinstall;cd$(PWD)
eXosip2:
@echo"willmakeeXosip2";echo;echo
@cd$(LIBCODEPATH)/libeXosip2-3.5.0;echo-n"pwdis:
";pwd;echo;echo;make;makeinstall;cd$(PWD)
ifeq(1,2)
myproj:
@echo"willmakemyproj";echo;echo
-rm-fsipuac
gcc-osipuacsipuac.c-I$(LIBPATH)/include-L$(LIBPATH)/lib-losip2-losipparser2-leXosip2
else
$(warning1111$(CC)$(CPPFLAGS)$(CFLAGS)$(LDFLAGS)$(LIBS))
CC:
=gcc
CFLAGS+=-g-O2
CPPFLAGS+=-I$(LIBPATH)/include
LDFLAGS+=-L$(LIBPATH)/lib
LIBS+=-losip2-losipparser2-leXosip2
myproj:
sipuac.o
gcc-osipuacsipuac.o$(LDFLAGS)$(LIBS)
rm*.o
endif
test:
@echo"hereismakeall"
@if[1-eq2];then\
echo"hereismakeallif";\
echo"pwdis$(shellpwd)";\
echo"willmakeosip2";\
echo;\
cd$(LIBCODEPATH)/libosip2-3.6.0;echo-n"pwdis:
";pwd;echo;echo;make;makeinstall;cd$(PWD);\
echo"pwdis$(shellpwd)";\
echo;\
echo;\
echo"willmakeeXosip2";\
echo;\
cd$(LIBCODEPATH)/libeXosip2-3.5.0;echo-n"pwdis:
";pwd;echo;echo;make;makeinstall;cd$(PWD);\
echo"pwdis$(shellpwd)";\
echo;\
echo;\
echo"willmakemyproj";\
rm-fsipuac;\
gcc-osipuacsipuac.c-I$(LIBPATH)/include-L$(LIBPATH)/lib-losip2-losipparser2-leXosip2;\
else\
echo"hereismakeallelse";\
fi
clean:
@echo"willcleanosip2";echo;echo
@cd$(LIBCODEPATH)/libosip2-3.6.0;echo-n"pwdis:
";pwd;echo;echo;makeclean;cd$(PWD)
@echo"willcleaneXosip2";echo;echo
@cd$(LIBCODEPATH)/libeXosip2-3.5.0;echo-n"pwdis:
";pwd;echo;echo;makeclean;cd$(PWD)
@echo"willcleanmyproj";echo;echo
rm-fsipuac
.PHONY:
allosip2eXosip2myprojtestclean
Endif
///////////////////////////////////////代码
#include
#include
#include
#defineENABLE_TRACE//打开osiplog用的
#include
#include
intreg();
intunreg();
intinvite();
intbye();
inthold();
intunhold();
intquit();
intshow();
#defineCOM_REG"reg"
#defineCOM_UNREG"unreg"
#defineCOM_INVITE"invite"
#defineCOM_BYE"bye"
#defineCOM_HOLD"hold"
#defineCOM_UNHOLD"unhold"
#defineCOM_QUIT"quit"
#defineCOM_SHOW"show"
typedefenum{
REG=0,
UNREG,
INVITE,
BYE,
HOLD,
UNHOLD,
QUIT,
SHOW,
MAX,
}com_type;
typedefint(*COM)();
COMcom[MAX]={reg,unreg,invite,bye,hold,unhold,quit,show};
char*localip="192.168.247.130";
char*serverip="192.168.247.130";
char*username="8001";
char*passwd="8001";
char*realm="\"asterisk\"";//这个字段可以不用
intlocalport=15061;
intserverport=5061;
charreg_from[50]={0};
charregistrar[50]={0};
charcontact[50]={0};
intring_timeout=20;//20秒是振铃超时
intflag=0;
intg_r_id=0;
intg_call_id=0,g_dialog_id=0;
char*g_body=NULL;
intreg()
{
intr_id=0;
osip_message_t*reg_m=NULL;
eXosip_event_t*je=NULL;
eXosip_clear_authentication_info();
if(eXosip_add_authentication_info(username,username,passwd,NULL,NULL/*realm*/))
{
printf("######Add_authentication_infofailed\n");
exit
(1);
}
r_id=eXosip_register_build_initial_register(reg_from,registrar,contact,120,®_m);
if(r_id<0)
{
printf("######Registerfailed!
\n");
exit
(1);
}
printf("######r_idis%d\n",r_id);
g_r_id=r_id;
eXosip_register_send_register(r_id,reg_m);
je=eXosip_event_wait(1,0);
eXosip_lock();
eXosip_default_action(je);
eXosip_unlock();
printf("######willreturnfromreg\n");
return0;
}
intunreg()
{
#if0
inti=0;
osip_message_t*reg_m=NULL;
eXosip_event_t*je=NULL;
eXosip_clear_authentication_info();
if(eXosip_add_authentication_info(username,username,passwd,NULL,NULL/*realm*/))
{
printf("######Add_authentication_infofailed\n");
exit
(1);
}
i=eXosip_register_build_initial_register(reg_from,registrar,contact,0,®_m);
if(i<0)
{
printf("######unregisterfailed!
\n");
exit
(1);
}
eXosip_register_send_register(i,reg_m);
je=eXosip_event_wait(1,0);
eXosip_lock();
eXosip_default_action(je);
eXosip_unlock();
#else
osip_message_t*reg_m=NULL;
eXosip_event_t*je=NULL;
if(eXosip_register_build_register(g_r_id,0,®_m)!
=0)
{
printf("######eXosip_register_build_registerfailed!
\n");
exit
(1);
}
eXosip_register_send_register(g_r_id,reg_m);
je=eXosip_event_wait(1,0);
eXosip_lock();
eXosip_default_action(je);
eXosip_unlock();
#endif
return0;
}
intinvite()
{
inti=0,invite_flg=0;
osip_message_t*invite_m=NULL;
osip_message_t*ack_m=NULL;
eXosip_event_t*je=NULL;
staticcharbody[4096]={0};
chardial[20]={0};
charinv_from[50]={0};
charinv_to[50]={0}