eXosip使用实例.doc_第1页
eXosip使用实例.doc_第2页
eXosip使用实例.doc_第3页
eXosip使用实例.doc_第4页
eXosip使用实例.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

ifeq (1,1)PWD=$(shell pwd)LIBCODEPATH=/usr/srcLIBPATH=/usr/localall: osip2 eXosip2 myprojosip2:echo will make osip2;echo;echocd $(LIBCODEPATH)/libosip2-3.6.0;echo -n pwd is: ;pwd;echo;echo;make;make install;cd $(PWD)eXosip2:echo will make eXosip2;echo;echocd $(LIBCODEPATH)/libeXosip2-3.5.0;echo -n pwd is: ;pwd;echo;echo;make;make install;cd $(PWD)ifeq (1,2)myproj:echo will make myproj;echo;echo-rm -f sipuacgcc -o sipuac sipuac.c -I$(LIBPATH)/include -L$(LIBPATH)/lib -losip2 -losipparser2 -leXosip2else$(warning 1111 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBS)CC := gccCFLAGS += -g -O2CPPFLAGS += -I$(LIBPATH)/includeLDFLAGS += -L$(LIBPATH)/libLIBS += -losip2 -losipparser2 -leXosip2myproj: sipuac.ogcc -o sipuac sipuac.o $(LDFLAGS) $(LIBS)rm *.oendiftest:echo here is make allif 1 -eq 2 ;then echo here is make all if ;echo pwd is $(shell pwd) ;echo will make osip2 ;echo ;cd $(LIBCODEPATH)/libosip2-3.6.0;echo -n pwd is: ;pwd;echo;echo;make;make install;cd $(PWD) ;echo pwd is $(shell pwd) ;echo ;echo ;echo will make eXosip2 ;echo ;cd $(LIBCODEPATH)/libeXosip2-3.5.0;echo -n pwd is: ;pwd;echo;echo;make;make install;cd $(PWD) ;echo pwd is $(shell pwd) ;echo ;echo ;echo will make myproj ;rm -f sipuac ;gcc -o sipuac sipuac.c -I$(LIBPATH)/include -L$(LIBPATH)/lib -losip2 -losipparser2 -leXosip2 ;else echo here is make all else ;ficlean:echo will clean osip2;echo;echocd $(LIBCODEPATH)/libosip2-3.6.0;echo -n pwd is: ;pwd;echo;echo;make clean;cd $(PWD)echo will clean eXosip2;echo;echocd $(LIBCODEPATH)/libeXosip2-3.5.0;echo -n pwd is: ;pwd;echo;echo;make clean;cd $(PWD)echo will clean myproj;echo;echorm -f sipuac.PHONY: all osip2 eXosip2 myproj test cleanEndif/代码#include #include #include #define ENABLE_TRACE /打开osip log用的#include #include int reg();int unreg();int invite();int bye();int hold();int unhold();int quit();int show();#define COM_REGreg#define COM_UNREGunreg#define COM_INVITEinvite#define COM_BYEbye#define COM_HOLDhold#define COM_UNHOLDunhold#define COM_QUITquit#define COM_SHOWshowtypedef enumREG = 0,UNREG,INVITE,BYE,HOLD,UNHOLD,QUIT,SHOW,MAX,com_type;typedef int (*COM)();COM comMAX = 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;/这个字段可以不用int localport = 15061;int serverport = 5061;char reg_from50 = 0;char registrar50 = 0;char contact50 = 0;int ring_timeout = 20;/20秒是振铃超时int flag = 0;int g_r_id = 0;int g_call_id = 0,g_dialog_id = 0;char * g_body = NULL;int reg()int r_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_info failedn);exit(1);r_id = eXosip_register_build_initial_register(reg_from,registrar,contact,120,®_m);if(r_id 0)printf(# Register failed!n);exit(1);printf(# r_id is %dn,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(# will return from regn);return 0;int unreg()#if 0int i = 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_info failedn);exit(1);i = eXosip_register_build_initial_register(reg_from,registrar,contact,0,®_m);if(i type) case EXOSIP_CALL_INVITE: printf(# A new invite received!n);break;case EXOSIP_CALL_PROCEEDING: /收到100tryprintf(# Proceeding!n);break;case EXOSIP_CALL_RINGING: printf(# Ringing!n);break;case EXOSIP_CALL_ANSWERED: printf(# OK! Connected! did = %d cid = %dn,je-did,je-cid);g_call_id = je-cid;g_dialog_id = je-did;eXosip_lock();eXosip_call_build_ack(je-did,&ack_m);eXosip_call_send_ack(je-did,ack_m);eXosip_unlock();invite_flg = 0; break;case EXOSIP_CALL_CLOSED: /a BYE was received for this callprintf(# the other sid closed!n);break;case EXOSIP_CALL_ACK: printf(# ACK received!n);break;default:printf(# other msg!n);if(je-response & (je-response-status_code = 486)osip_header_t* retryafter = NULL;osip_message_get_retry_after(je-response, 0, &retryafter);printf(# * %s *n, retryafter-hvalue?retryafter-hvalue:null);invite_flg = 0;/eXosip_event_free(je);break; /end switcheXosip_event_free(je); /end whilereturn 0;int bye()int i = 0;eXosip_event_t * je = NULL;eXosip_lock();i = eXosip_call_terminate(g_call_id,g_dialog_id);if(i type) case EXOSIP_CALL_INVITE: printf(# A new invite received!n);break;case EXOSIP_CALL_PROCEEDING: /收到100tryprintf(# Proceeding!n);break;case EXOSIP_CALL_RINGING: printf(# Ringing!n);break;case EXOSIP_CALL_ANSWERED: printf(# OK! Connected! did = %d cid = %dn,je-did,je-cid);/g_call_id = je-cid;/g_dialog_id = je-did;eXosip_lock();eXosip_call_build_ack(je-did,&ack_m);eXosip_call_send_ack(je-did,ack_m);eXosip_unlock();invite_flg = 0; break;case EXOSIP_CALL_CLOSED: /a BYE was received for this callprintf(# the other sid closed!n);break;case EXOSIP_CALL_ACK: printf(# ACK received!n);break;default:printf(# other msg!n);if(je-response & (je-response-status_code = 486)osip_header_t* retryafter = NULL;osip_message_get_retry_after(je-response, 0, &retryafter);printf(# * %s *n, retryafter-hvalue?retryafter-hvalue:null);invite_flg = 0;/eXosip_event_free(je);break; /end switcheXosip_event_free(je); /end whilereturn 0;int unhold()int invite_flg = 1;osip_message_t * invite_m = NULL;eXosip_event_t * je = NULL;osip_message_t * ack_m = NULL;static char body4096 = 0;if(eXosip_call_build_request(g_dialog_id, INVITE, &invite_m) != 0)printf(# eXosip_call_build_request failed!n);return -1;memset(body,0,4096);snprintf(body,4096,v=0rno=wangpeng 0 2 IN IP4 %srns=xxxxrnc=IN IP4 %srnt=0 0rnm=audio 12000 RTP/AVP 0 8rna=rtpmap:8 PCMA/8000rna=rtpmap:0 PCMU/8000rna=ptime:20rna=sendrecv,localip,localip);osip_message_set_body(invite_m,body,strlen(body);osip_message_set_content_type(invite_m,application/sdp);eXosip_lock();eXosip_call_send_request(g_dialog_id, invite_m);eXosip_unlock();while(invite_flg)printf(will eXosip_event_wait unholdn);je = eXosip_event_wait(ring_timeout,0);printf(after eXosip_event_wait unholdn);if(je != NULL);/printEventType(je);elseprintf(No response or the time is over!n);return -2;eXosip_lock();eXosip_default_action(je);eXosip_automatic_refresh();eXosip_unlock();switch(je-type) case EXOSIP_CALL_INVITE: printf(# A new invite received!n);break;case EXOSIP_CALL_PROCEEDING: /收到100tryprintf(# Proceeding!n);break;case EXOSIP_CALL_RINGING: printf(# Ringing!n);break;case EXOSIP_CALL_ANSWERED: printf(# OK! Connected! did = %d cid = %dn,je-did,je-cid);/g_call_id = je-cid;/g_dialog_id = je-did;eXosip_lock();eXosip_call_build_ack(je-did,&ack_m);eXosip_call_send_ack(je-did,ack_m);eXosip_unlock();invite_flg = 0; break;case EXOSIP_CALL_CLOSED: /a BYE was received for this callprintf(# the other sid closed!n);break;case EXOSIP_CALL_ACK: printf(# ACK received!n);break;default:printf(# other msg!n);if(je-response & (je-response-status_code = 486)osip_header_t* retryafter = NULL;osip_message_get_retry_after(je-response, 0, &retryafter);printf(# * %s *n, retryafter-hvalue?retryafter-hvalue:null);invite_flg = 0;/eXosip_event_free(je);break; /end switcheXosip_event_free(je); /end whilereturn 0;int quit()eXosip_quit();printf(# Exit the setup!n);flag = 0;return 0;int show()/if(je != NULL)/printf(# tid = %d,did = %d,cid = %d n,je-tid,je-did,je-cid);printf(this function not implementn);return 0;void test()char local20 = 0;eXosip_guess_localip(AF_INET,local,19);printf(local ip is %snn,local);exit(0);int main(int argc,char *argv)int i = 0;eXosip_event_t * je = NULL;char command10 = 0;sprintf(reg_from,sip:%s%s:%d,username,serverip,serverport);sprintf(registrar,sip:%s:%d,serverip,serverport);sprintf(contact,sip:%s%s:%d,username,localip,localport);printf(%s注册n,COM_REG);printf(%s注销n,COM_UNREG);printf(%s发起呼叫n,COM_INVITE);printf(%s挂断n,COM_BYE);printf(%s保持n,COM_HOLD);printf(%s去保持n,COM_UNHOLD);printf(%s退出程序n,COM_QUIT);printf(%s显示各种idn,COM_SHOW);TRACE_INITIALIZE(8, NULL); /打开osip log用的i = eXosip_init();if(i != 0)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论