分享
 
 
 

一个exOsip的简单例子

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

#include "assert.h"

#include <conio.h>

#include <iostream>

#include <string>

#include "osip2/osip_mt.h"

#include "eXosip/eXosip.h"

#include "eXosip/eXosip_cfg.h"

using namespace std;

char server[200]="@sip.broadz.net";

char identity[200]="sip:";//king@sip.broadz.net";

char registrar[200]="sip:sip.broadz.net:80";

char username[100];//="king";

char password[100];//="";

int j;

int reg_id;

char contact[200]="sip:";//king@sip.broadz.net";

int expires;

bool run = true;

int portbase=10000;

char *destip="sip:2000@sip.broadz.net:80";

int destport=80;

char ipstr[256];

int status,i;

char dummybuffer[1024];

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 ANSWERED] %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);

cout<<"EXOSIP_CALL_PROCEEDING"<<endl;

}

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

cout<<"EXOSIP_CALL_RINGING"<<endl;

}

else if (je->type==EXOSIP_CALL_CANCELLED)

{cout<<"cancer";

}

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

cout<<"EXOSIP_CALL_REDIRECTED"<<endl;

}

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

cout<<"EXOSIP_CALL_REQUESTFAILURE"<<endl;

}

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_SUCCESS %s",

je->rid,

je->status_code,

je->reason_phrase,

je->remote_uri,

je->req_uri);

josua_printf(buf);

cout<<endl;

}

else if (je->type==EXOSIP_REGISTRATION_REFRESHED)

{

}

else if (je->type== EXOSIP_REGISTRATION_TERMINATED)

{

}

else if (je->type==EXOSIP_REGISTRATION_FAILURE)

{

reg_id = eXosip_register_init(identity, registrar, contact);

if(eXosip_add_authentication_info(username, username, password, NULL, NULL))

{

exit(1);

}

eXosip_lock();

j = eXosip_register(reg_id, expires);

eXosip_unlock();

cout<<"REGISTER_FAILURE";

printf( "<- (%i) [%i %s] %s for REGISTER_FAILURE %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;

expires = 3600;

memset( &call, 0, sizeof(call) );

cout<<"Please Enter Your Username:";

cin>>username;

cout<<"Please Enter Your Password:";

cin>>password;

strcat(identity,username);

strcat(identity,server);

strcpy(contact,identity);

cout << "Usage:"<< endl;

cout << "a - answering call"<< endl;

cout << "h - hangup"<< endl;

cout << "z - zhuxiao"<< endl;

cout << "c - call"<< endl;

cout << "q - quit"<< endl;

FILE* logfile = fopen( "logfile.txt", "w");

i = eXosip_init(NULL, NULL, 80);

if (i!=0)

{

fprintf (stderr, "test: could not initialize eXosip\n");

__exit(0);

}

eXosip_sdp_negotiation_remove_audio_payloads();

reg_id = eXosip_register_init(identity, registrar, contact);

j = eXosip_register(reg_id, 3600);

cout<<"init"<<endl;

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

eXosip_set_mode(EVENT_MODE);

osip_message_t *invite;

cout << "oSIP>"<<endl;

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 'z':

cout << "zhuxiao"<< endl;

expires = 0;

reg_id = eXosip_register_init(identity, registrar, contact);

j = eXosip_register(reg_id, 0);

break;

case 'c':

cout << "call"<< endl;

i = eXosip_build_initial_invite(&invite,

destip, //被叫

identity, //主叫

NULL,

"oSIP phone");

if (i!=0)

{

fprintf (stderr, "eXosip_build_initial_invite failed\n");

__exit(0);

}

eXosip_lock();

eXosip_initiate_call(invite, NULL, NULL, "10500");

eXosip_unlock();

break;

case 'q':

eXosip_quit();

cout << "quit"<< endl;

run = false;

break;

}

}

}

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有