📄 testosipexdlg.cpp
字号:
// TestOsipExDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestOsipEx.h"
#include "TestOsipExDlg.h"
//OSIP支持
#include <osip2/osip_mt.h>
#include <eXosip/eXosip.h>
#include <eXosip/eXosip_cfg.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//相关类
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;
}
};
int i;
osip_message_t *invite;
jcall call;
void __exit( int r )
{
char line[256];
gets( line );
exit( r );
}
void josua_printf(char* buf)
{
printf( "\n" );
}
CString inf;
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)
{
inf.Format(L"<- (%i %i) INVITE from: %s",
je->cid, je->did,
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
call.build(je);
}
else if (je->type==EXOSIP_CALL_ANSWERED)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_PROCEEDING)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_RINGING)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_REDIRECTED)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_REQUESTFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_SERVERFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_GLOBALFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_CLOSED)
{
inf.Format(L"<- (%i %i) BYE from: %s",
je->cid, je->did, CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_HOLD)
{
inf.Format(L"<- (%i %i) INVITE (On Hold) from: %s",
je->cid, je->did, CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_CALL_OFFHOLD)
{
inf.Format(L"<- (%i %i) INVITE (Off Hold) from: %s",
je->cid, je->did, CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_REGISTRATION_SUCCESS)
{
inf.Format(L"<- (%i) [%i %s] %s for REGISTER %s",
je->rid,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri),
CString(je->req_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_REGISTRATION_FAILURE)
{
inf.Format(L"<- (%i) [%i %s] %s for REGISTER %s",
je->rid,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri),
CString(je->req_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_OPTIONS_NEW)
{
inf.Format(L"<- (%i %i) OPTIONS from: %s",
je->cid, je->did,
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_OPTIONS_ANSWERED)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_OPTIONS_PROCEEDING)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_OPTIONS_REDIRECTED)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_OPTIONS_REQUESTFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_OPTIONS_SERVERFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_OPTIONS_GLOBALFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_INFO_NEW)
{
inf.Format(L"<- (%i %i) INFO from: %s",
je->cid, je->did,
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_INFO_ANSWERED)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_INFO_PROCEEDING)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_INFO_REDIRECTED)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_INFO_REQUESTFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_INFO_SERVERFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_INFO_GLOBALFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s",
je->cid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_SUBSCRIPTION_ANSWERED)
{
inf.Format(L"<- (%i %i) [%i %s] %s for SUBSCRIBE",
je->sid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
inf.Format(L"<- (%i %i) online=%i [status: %i reason:%i]",
je->sid, je->did,
je->online_status,
je->ss_status,
je->ss_reason);
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_SUBSCRIPTION_PROCEEDING)
{
inf.Format(L"<- (%i %i) [%i %s] %s for SUBSCRIBE",
je->sid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_SUBSCRIPTION_REDIRECTED)
{
inf.Format(L"<- (%i %i) [%i %s] %s for SUBSCRIBE",
je->sid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_SUBSCRIPTION_REQUESTFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s for SUBSCRIBE",
je->sid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_SUBSCRIPTION_SERVERFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s for SUBSCRIBE",
je->sid, je->did,
je->status_code,
CString(je->reason_phrase),
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_SUBSCRIPTION_GLOBALFAILURE)
{
inf.Format(L"<- (%i %i) [%i %s] %s for SUBSCRIBE",
je->sid, je->did,
je->status_code,
je->reason_phrase,
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_SUBSCRIPTION_NOTIFY)
{
inf.Format(L"<- (%i %i) NOTIFY from: %s",
je->sid, je->did,
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
inf.Format(L"<- (%i %i) online=%i [status: %i reason:%i]",
je->sid, je->did,
je->online_status,
je->ss_status,
je->ss_reason);
josua_printf(buf);AfxMessageBox(inf);
}
else if (je->type==EXOSIP_IN_SUBSCRIPTION_NEW)
{
inf.Format(L"<- (%i %i) SUBSCRIBE from: %s",
je->nid, je->did,
CString(je->remote_uri));
josua_printf(buf);AfxMessageBox(inf);
// 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')
{
inf.Format(L"(%i %i %i %i) %s", je->cid, je->sid, je->nid, je->did, CString(je->textinfo));
josua_printf(buf);AfxMessageBox(inf);
}
eXosip_event_free(je);
}
if (counter>0)
return 0;
return -1;
}
/////////////////////////////////////////////////////////////////////////////
// CTestOsipExDlg dialog
CTestOsipExDlg::CTestOsipExDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestOsipExDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestOsipExDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestOsipExDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestOsipExDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestOsipExDlg, CDialog)
//{{AFX_MSG_MAP(CTestOsipExDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestOsipExDlg message handlers
BOOL CTestOsipExDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
memset( &call, 0, sizeof(call) );
FILE* logfile = fopen( "logfile.txt", "w");
osip_trace_initialize( (_trace_level)0, logfile );
//osip_trace_initialize( (_trace_level)8, logfile );
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);
i = eXosip_build_initial_invite(&invite,
"sip:127.0.0.1:5060", //被叫对IP
"sip:127.0.0.1:5060", //自己IP
NULL,
"oSIP phone");
if (i!=0)
{
fprintf (stderr, "eXosip_build_initial_invite failed\n");
AfxMessageBox(L"eXosip_build_initial_invite failed");
return TRUE;
}
SetTimer(1,500,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestOsipExDlg::OnButton1()
{
eXosip_lock();
eXosip_initiate_call(invite, NULL, NULL, "10500");
eXosip_unlock();
}
void CTestOsipExDlg::OnButton2()
{
eXosip_lock();
eXosip_answer_call(call.did, 180, 0);
eXosip_unlock();
}
void CTestOsipExDlg::OnButton3()
{
eXosip_lock();
eXosip_answer_call(call.did, 200, 0);
eXosip_unlock();
}
void CTestOsipExDlg::OnButton4()
{
eXosip_lock();
eXosip_terminate_call( call.cid, call.did );
eXosip_unlock();
}
void CTestOsipExDlg::OnTimer(UINT nIDEvent)
{
josua_event_get();
CDialog::OnTimer(nIDEvent);
}
void CTestOsipExDlg::OnButton5()
{
josua_event_get();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -