summaryrefslogtreecommitdiff
path: root/Protocols
diff options
context:
space:
mode:
Diffstat (limited to 'Protocols')
-rw-r--r--Protocols/SIP/Docs/sip_changelog.txt6
-rw-r--r--Protocols/SIP/Docs/sip_version.txt2
-rw-r--r--Protocols/SIP/SIPClient.cpp28
-rw-r--r--Protocols/SIP/SIPClient.h4
-rw-r--r--Protocols/SIP/SIPProto.cpp41
-rw-r--r--Protocols/SIP/SIPProto.h1
-rw-r--r--Protocols/SIP/m_sip.h9
-rw-r--r--Protocols/SIP/sip.cpp8
8 files changed, 71 insertions, 28 deletions
diff --git a/Protocols/SIP/Docs/sip_changelog.txt b/Protocols/SIP/Docs/sip_changelog.txt
index 674f9e3..b8b858f 100644
--- a/Protocols/SIP/Docs/sip_changelog.txt
+++ b/Protocols/SIP/Docs/sip_changelog.txt
@@ -2,6 +2,12 @@ SIP protocol
Changelog:
+. 0.1.3.0
+ * Fix for going online after connecting error
+ * Fix for reconection crash
+ + Added stun server to client API
+ + Added list of hosts to client API
+
. 0.1.2.0
+ Support for clients (Example plugin at http://pescuma.googlecode.com/svn/trunk/Miranda/Plugins/sip_cli )
diff --git a/Protocols/SIP/Docs/sip_version.txt b/Protocols/SIP/Docs/sip_version.txt
index e967521..7a5d348 100644
--- a/Protocols/SIP/Docs/sip_version.txt
+++ b/Protocols/SIP/Docs/sip_version.txt
@@ -1 +1 @@
-SIP protocol 0.1.2.0 \ No newline at end of file
+SIP protocol 0.1.3.0 \ No newline at end of file
diff --git a/Protocols/SIP/SIPClient.cpp b/Protocols/SIP/SIPClient.cpp
index cc831b5..86dc64c 100644
--- a/Protocols/SIP/SIPClient.cpp
+++ b/Protocols/SIP/SIPClient.cpp
@@ -31,12 +31,15 @@ SIPClient::SIPClient(SIP_REGISTRATION *reg)
hasToDestroy = false;
udp.transport_id = -1;
udp.acc_id = -1;
+ udp.host[0] = 0;
udp.port = 0;
tcp.transport_id = -1;
tcp.acc_id = -1;
tcp.port = 0;
+ tcp.host[0] = 0;
tls.transport_id = -1;
tls.acc_id = -1;
+ tls.host[0] = 0;
tls.port = 0;
hNetlibUser = reg->hNetlib;
@@ -221,12 +224,12 @@ void SIPClient::RegisterTransport(pjsip_transport_type_e type, int port, ta *ta)
pjsua_acc_set_user_data(ta->acc_id, this);
- lstrcpyn(host, SipToTchar(info.local_name.host), MAX_REGS(host));
+ lstrcpyn(ta->host, SipToTchar(info.local_name.host), MAX_REGS(ta->host));
ta->port = info.local_name.port;
}
-int SIPClient::Connect(int udp_port, int tcp_port, int tls_port)
+int SIPClient::Connect(SIP_REGISTRATION *reg)
{
Trace(_T("Connecting..."));
@@ -241,6 +244,8 @@ int SIPClient::Connect(int udp_port, int tcp_port, int tls_port)
}
{
+ scoped_mir_free<char> stun;
+
pjsua_config cfg;
pjsua_config_default(&cfg);
#ifndef _DEBUG
@@ -250,6 +255,19 @@ int SIPClient::Connect(int udp_port, int tcp_port, int tls_port)
cfg.cb.on_call_media_state = &static_on_call_media_state;
cfg.cb.on_call_state = &static_on_call_state;
+
+ if (!IsEmpty(reg->stun.host))
+ {
+ TCHAR tmp[1024];
+ mir_sntprintf(tmp, MAX_REGS(tmp), _T("%s:%d"),
+ CleanupSip(reg->stun.host),
+ FirstGtZero(reg->stun.port, PJ_STUN_PORT));
+ stun = TcharToSip(tmp).detach();
+
+ cfg.stun_srv_cnt = 1;
+ cfg.stun_srv[0] = pj_str(stun);
+ }
+
pjsua_logging_config log_cfg;
pjsua_logging_config_default(&log_cfg);
log_cfg.cb = &static_on_log;
@@ -267,9 +285,9 @@ int SIPClient::Connect(int udp_port, int tcp_port, int tls_port)
}
{
- RegisterTransport(PJSIP_TRANSPORT_UDP, udp_port, &udp);
- RegisterTransport(PJSIP_TRANSPORT_TCP, tcp_port, &tcp);
- RegisterTransport(PJSIP_TRANSPORT_TLS, tls_port, &tls);
+ RegisterTransport(PJSIP_TRANSPORT_UDP, reg->udp_port, &udp);
+ RegisterTransport(PJSIP_TRANSPORT_TCP, reg->tcp_port, &tcp);
+ RegisterTransport(PJSIP_TRANSPORT_TLS, reg->tls_port, &tls);
if (udp.port <= 0 && tcp.port <= 0 && tls.port <= 0)
return 1;
diff --git a/Protocols/SIP/SIPClient.h b/Protocols/SIP/SIPClient.h
index 1af9cb6..bbcb3ef 100644
--- a/Protocols/SIP/SIPClient.h
+++ b/Protocols/SIP/SIPClient.h
@@ -31,6 +31,7 @@ public:
struct ta {
pjsua_transport_id transport_id;
pjsua_acc_id acc_id;
+ TCHAR host[256];
int port;
};
@@ -42,7 +43,6 @@ public:
void *callback_param;
char name[512];
- TCHAR host[256];
CRITICAL_SECTION cs;
std::vector<SIPEvent> events;
@@ -61,7 +61,7 @@ public:
int AnswerCall(pjsua_call_id call_id);
int SendDTMF(pjsua_call_id call_id, TCHAR dtmf);
- int Connect(int udp_port, int tcp_port, int tls_port);
+ int Connect(SIP_REGISTRATION *reg);
void Disconnect();
private:
diff --git a/Protocols/SIP/SIPProto.cpp b/Protocols/SIP/SIPProto.cpp
index c0d042a..2f79e16 100644
--- a/Protocols/SIP/SIPProto.cpp
+++ b/Protocols/SIP/SIPProto.cpp
@@ -41,16 +41,6 @@ SIPProto::SIPProto(const char *aProtoName, const TCHAR *aUserName)
memset(awayMessages, 0, sizeof(awayMessages));
- {
- pj_status_t status = pjsua_create();
- if (status != PJ_SUCCESS)
- {
- Error(status, _T("Error creating pjsua"));
- throw "Error creating pjsua";
- }
- hasToDestroy = true;
- }
-
InitializeCriticalSection(&cs);
m_tszUserName = mir_tstrdup(aUserName);
@@ -508,6 +498,19 @@ int SIPProto::Connect()
BroadcastStatus(ID_STATUS_CONNECTING);
+ DestroySIP();
+
+ {
+ pj_status_t status = pjsua_create();
+ if (status != PJ_SUCCESS)
+ {
+ Error(status, _T("Error creating pjsua"));
+ Disconnect();
+ return 1;
+ }
+ hasToDestroy = true;
+ }
+
{
scoped_mir_free<char> stun;
scoped_mir_free<char> dns;
@@ -638,6 +641,7 @@ int SIPProto::Connect()
}
cfg.publish_enabled = (opts.publish ? PJ_TRUE : PJ_FALSE);
+ cfg.mwi_enabled = PJ_TRUE;
if (!opts.sendKeepAlive)
cfg.ka_interval = 0;
@@ -929,6 +933,7 @@ void SIPProto::Disconnect()
DBDeleteContactSetting(hContact, "CList", "StatusMsg");
}
+ m_iDesiredStatus = ID_STATUS_OFFLINE;
BroadcastStatus(ID_STATUS_OFFLINE);
}
@@ -994,15 +999,19 @@ int __cdecl SIPProto::OnOptionsInit(WPARAM wParam, LPARAM lParam)
}
-int __cdecl SIPProto::OnPreShutdown(WPARAM wParam, LPARAM lParam)
+void SIPProto::DestroySIP()
{
- if (hasToDestroy)
- {
- pjsua_destroy();
- hasToDestroy = false;
- }
+ if (!hasToDestroy)
+ return;
+ pjsua_destroy();
+ hasToDestroy = false;
+}
+
+int __cdecl SIPProto::OnPreShutdown(WPARAM wParam, LPARAM lParam)
+{
+ DestroySIP();
return 0;
}
diff --git a/Protocols/SIP/SIPProto.h b/Protocols/SIP/SIPProto.h
index 5d3797f..6efbe59 100644
--- a/Protocols/SIP/SIPProto.h
+++ b/Protocols/SIP/SIPProto.h
@@ -166,6 +166,7 @@ private:
bool SendPresence(int status = 0);
int Connect();
void Disconnect();
+ void DestroySIP();
INT_PTR __cdecl CreateAccMgrUI(WPARAM wParam, LPARAM lParam);
void ConfigureDevices();
diff --git a/Protocols/SIP/m_sip.h b/Protocols/SIP/m_sip.h
index 360912b..e31f813 100644
--- a/Protocols/SIP/m_sip.h
+++ b/Protocols/SIP/m_sip.h
@@ -35,6 +35,11 @@ struct SIP_REGISTRATION
int tcp_port; // UDP port to be used: 0 means TCP, -1 means don't want TCP
int tls_port; // UDP port to be used: 0 means TLS, -1 means don't want TLS
+ struct {
+ const TCHAR *host;
+ int port;
+ } stun;
+
HANDLE hNetlib; // To be used for logs. Can be 0
SIPClientCallback callback;
@@ -45,9 +50,11 @@ struct SIP_REGISTRATION
struct SIP_CLIENT
{
void *data; // Do not touch
- const TCHAR *host;
+ const TCHAR *udp_host;
const int udp_port;
+ const TCHAR *tcp_host;
const int tcp_port;
+ const TCHAR *tls_host;
const int tls_port;
// @param protocol 1 UDP, 2 TCP, 3 TLS
diff --git a/Protocols/SIP/sip.cpp b/Protocols/SIP/sip.cpp
index 138ad78..c68b538 100644
--- a/Protocols/SIP/sip.cpp
+++ b/Protocols/SIP/sip.cpp
@@ -30,7 +30,7 @@ PLUGININFOEX pluginInfo={
#else
"SIP protocol (Ansi)",
#endif
- PLUGIN_MAKE_VERSION(0,1,2,0),
+ PLUGIN_MAKE_VERSION(0,1,3,0),
"Provides support for SIP protocol",
"Ricardo Pescuma Domenecci",
"pescuma@miranda-im.org",
@@ -322,7 +322,7 @@ static INT_PTR ClientRegister(WPARAM wParam, LPARAM lParam)
return NULL;
SIPClient *cli = new SIPClient(reg);
- if (cli->Connect(reg->udp_port, reg->tcp_port, reg->tls_port) != 0)
+ if (cli->Connect(reg) != 0)
{
cli->Disconnect();
delete cli;
@@ -333,9 +333,11 @@ static INT_PTR ClientRegister(WPARAM wParam, LPARAM lParam)
SIP_CLIENT *ret = (SIP_CLIENT *) mir_alloc0(sizeof(SIP_CLIENT) + sizeof(SIPClient *));
ret->data = cli;
- * (TCHAR **) & ret->host = cli->host;
+ * (TCHAR **) & ret->udp_host = cli->udp.host;
* (int *) & ret->udp_port = cli->udp.port;
+ * (TCHAR **) & ret->tcp_host = cli->tcp.host;
* (int *) & ret->tcp_port = cli->tcp.port;
+ * (TCHAR **) & ret->tls_host = cli->tls.host;
* (int *) & ret->tls_port = cli->tls.port;
ret->Call = &ClientCall;
ret->DropCall = &ClientDropCall;