summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/JabberG/src/jabber.h51
-rw-r--r--protocols/JabberG/src/jabber_captcha.cpp6
-rw-r--r--protocols/JabberG/src/jabber_disco.cpp8
-rw-r--r--protocols/JabberG/src/jabber_file.cpp71
-rw-r--r--protocols/JabberG/src/jabber_iqid.cpp44
-rw-r--r--protocols/JabberG/src/jabber_misc.cpp2
-rw-r--r--protocols/JabberG/src/jabber_opt.cpp29
-rw-r--r--protocols/JabberG/src/jabber_password.cpp8
-rw-r--r--protocols/JabberG/src/jabber_proto.cpp17
-rw-r--r--protocols/JabberG/src/jabber_proto.h21
-rw-r--r--protocols/JabberG/src/jabber_secur.cpp34
-rw-r--r--protocols/JabberG/src/jabber_secur.h2
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp342
13 files changed, 293 insertions, 342 deletions
diff --git a/protocols/JabberG/src/jabber.h b/protocols/JabberG/src/jabber.h
index 9c5e921603..7e20519a89 100644
--- a/protocols/JabberG/src/jabber.h
+++ b/protocols/JabberG/src/jabber.h
@@ -315,12 +315,6 @@ struct CJabberHttpAuthParams
*******************************************************************/
typedef HANDLE JABBER_SOCKET;
-enum JABBER_SESSION_TYPE
-{
- JABBER_SESSION_NORMAL,
- JABBER_SESSION_REGISTER
-};
-
#define CAPS_BOOKMARK 0x0001
#define CAPS_BOOKMARKS_LOADED 0x8000
@@ -333,19 +327,30 @@ enum JABBER_SESSION_TYPE
#define JABBER_LOGIN_SERVERINFO 0x0004
#define JABBER_LOGIN_BOOKMARKS_AJ 0x0008
+struct JABBER_CONN_DATA : public MZeroedObject
+{
+ TCHAR username[512];
+ TCHAR password[512];
+ char server[128];
+ char manualHost[128];
+ int port;
+ BOOL useSSL;
+
+ HWND reg_hwndDlg;
+};
+
struct ThreadData
{
- ThreadData(CJabberProto* _ppro, JABBER_SESSION_TYPE parType);
+ ThreadData(CJabberProto *_pro, JABBER_CONN_DATA *_connData);
~ThreadData();
- HANDLE hThread;
- JABBER_SESSION_TYPE type;
+ ptrA szStreamId;
+ char* buffer;
// network support
JABBER_SOCKET s;
- BOOL useSSL;
HANDLE iomutex; // protects i/o operations
- CJabberProto* proto;
+ CJabberProto *proto;
// XEP-0138 (Compression support)
BOOL useZlib;
@@ -366,22 +371,18 @@ struct ThreadData
MCONTACT resolveContact;
// features & registration
- HWND reg_hwndDlg;
- BOOL reg_done, bIsSessionAvailable;
- BOOL bBookmarksLoaded;
+ bool bIsReg;
+ bool reg_done, bIsSessionAvailable;
+ bool bBookmarksLoaded;
DWORD dwLoginRqs;
// connection & login data
- TCHAR username[512];
- TCHAR password[512];
- char server[128];
- char manualHost[128];
+ JABBER_CONN_DATA conn;
TCHAR resource[128];
TCHAR fullJID[JABBER_MAX_JID_LEN];
- WORD port;
ptrT tszNewPassword;
- class TJabberAuth* auth;
+ class TJabberAuth *auth;
JabberCapsBits jabberServerCaps;
void close(void);
@@ -403,16 +404,6 @@ struct JABBER_MODEMSGS
TCHAR *szFreechat;
};
-struct JABBER_REG_ACCOUNT
-{
- TCHAR username[512];
- TCHAR password[512];
- char server[128];
- char manualHost[128];
- WORD port;
- BOOL useSSL;
-};
-
typedef enum { FT_SI, FT_OOB, FT_BYTESTREAM, FT_IBB } JABBER_FT_TYPE;
typedef enum { FT_CONNECTING, FT_INITIALIZING, FT_RECEIVING, FT_DONE, FT_ERROR, FT_DENIED } JABBER_FILE_STATE;
diff --git a/protocols/JabberG/src/jabber_captcha.cpp b/protocols/JabberG/src/jabber_captcha.cpp
index c9a0c50860..4884cfee6a 100644
--- a/protocols/JabberG/src/jabber_captcha.cpp
+++ b/protocols/JabberG/src/jabber_captcha.cpp
@@ -110,7 +110,7 @@ INT_PTR CALLBACK JabberCaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam,
return FALSE;
}
-bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info)
+bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData *info)
{
HXML x = xmlGetChildByTag(node, "x", "xmlns", JABBER_FEAT_DATA_FORMS);
if (x == NULL)
@@ -166,7 +166,7 @@ bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info)
return true;
}
-void CJabberProto::sendCaptchaResult(TCHAR* buf, ThreadData* info, LPCTSTR from, LPCTSTR challenge, LPCTSTR fromjid, LPCTSTR sid)
+void CJabberProto::sendCaptchaResult(TCHAR* buf, ThreadData *info, LPCTSTR from, LPCTSTR challenge, LPCTSTR fromjid, LPCTSTR sid)
{
XmlNodeIq iq(_T("set"), SerialNext());
HXML query= iq <<XATTR(_T("to"), from) << XCHILD(_T("captcha")) << XATTR(_T("xmlns"), _T("urn:xmpp:captcha")) << XCHILD (_T("x")) << XATTR(_T("xmlns"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("submit"));
@@ -178,7 +178,7 @@ void CJabberProto::sendCaptchaResult(TCHAR* buf, ThreadData* info, LPCTSTR from,
info -> send (iq);
}
-void CJabberProto::sendCaptchaError(ThreadData* info, LPCTSTR from, LPCTSTR to, LPCTSTR challenge)
+void CJabberProto::sendCaptchaError(ThreadData *info, LPCTSTR from, LPCTSTR to, LPCTSTR challenge)
{
XmlNode message(_T("message"));
HXML query= message << XATTR(_T("type"), _T("error")) << XATTR(_T("to"), from) << XATTR(_T("id"), challenge) << XATTR(_T("from"), to)
diff --git a/protocols/JabberG/src/jabber_disco.cpp b/protocols/JabberG/src/jabber_disco.cpp
index d3030a3b7e..7fbb073683 100644
--- a/protocols/JabberG/src/jabber_disco.cpp
+++ b/protocols/JabberG/src/jabber_disco.cpp
@@ -416,7 +416,7 @@ void CJabberProto::PerformBrowse(HWND hwndDlg)
} }
else if (!lstrcmp(szJid, _T(SD_FAKEJID_CONFERENCES))) {
sttBrowseMode = SD_BROWSE_CONFERENCES;
- TCHAR *szServerJid = mir_a2t(m_ThreadInfo->server);
+ TCHAR *szServerJid = mir_a2t(m_ThreadInfo->conn.server);
CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootItems, JABBER_IQ_TYPE_GET, szServerJid);
pInfo->m_pUserData = (void*)JABBER_FEAT_MUC;
pInfo->SetTimeout(30000);
@@ -427,7 +427,7 @@ void CJabberProto::PerformBrowse(HWND hwndDlg)
}
else if (!lstrcmp(szJid, _T(SD_FAKEJID_AGENTS))) {
sttBrowseMode = SD_BROWSE_AGENTS;
- TCHAR *szServerJid = mir_a2t(m_ThreadInfo->server);
+ TCHAR *szServerJid = mir_a2t(m_ThreadInfo->conn.server);
CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootItems, JABBER_IQ_TYPE_GET, szServerJid);
pInfo->m_pUserData = (void*)_T("jabber:iq:gateway");
pInfo->SetTimeout(30000);
@@ -639,7 +639,7 @@ void CJabberDlgDiscovery::OnInitDialog()
m_focusEditAfterBrowse = false;
}
else {
- SetDlgItemTextA(m_hwnd, IDC_COMBO_JID, m_proto->m_ThreadInfo->server);
+ SetDlgItemTextA(m_hwnd, IDC_COMBO_JID, m_proto->m_ThreadInfo->conn.server);
SetDlgItemText(m_hwnd, IDC_COMBO_NODE, _T(""));
m_focusEditAfterBrowse = true;
}
@@ -790,7 +790,7 @@ void CJabberDlgDiscovery::btnViewAsList_OnClick(CCtrlButton *)
void CJabberDlgDiscovery::btnGoHome_OnClick(CCtrlButton *)
{
- SetDlgItemTextA(m_hwnd, IDC_COMBO_JID, m_proto->m_ThreadInfo->server);
+ SetDlgItemTextA(m_hwnd, IDC_COMBO_JID, m_proto->m_ThreadInfo->conn.server);
SetDlgItemText(m_hwnd, IDC_COMBO_NODE, _T(""));
PostMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_BUTTON_BROWSE, 0), 0);
}
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index d9b5fa568b..f394d8ff8e 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void __cdecl CJabberProto::FileReceiveThread(filetransfer *ft)
{
- ThreadData info(this, JABBER_SESSION_NORMAL);
+ ThreadData info(this, NULL);
debugLogA("Thread started: type=file_receive server='%s' port='%d'", ft->httpHostName, ft->httpPort);
@@ -73,7 +73,7 @@ void __cdecl CJabberProto::FileReceiveThread(filetransfer *ft)
ft->s = NULL;
- if (ft->state==FT_DONE || (ft->state==FT_RECEIVING && ft->std.currentFileSize < 0))
+ if (ft->state == FT_DONE || (ft->state == FT_RECEIVING && ft->std.currentFileSize < 0))
ft->complete();
debugLogA("Thread ended: type=file_receive server='%s'", ft->httpHostName);
@@ -91,16 +91,16 @@ int CJabberProto::FileReceiveParse(filetransfer *ft, char* buffer, int datalen)
p = buffer;
num = 0;
while (true) {
- if (ft->state==FT_CONNECTING || ft->state==FT_INITIALIZING) {
- for (q=p; q+1<eob && (*q!='\r' || *(q+1)!='\n'); q++);
- if (q+1 < eob) {
- if ((str=(char*)mir_alloc(q-p+1)) != NULL) {
+ if (ft->state == FT_CONNECTING || ft->state == FT_INITIALIZING) {
+ for (q = p; q + 1 < eob && (*q != '\r' || *(q + 1) != '\n'); q++);
+ if (q + 1 < eob) {
+ if ((str = (char*)mir_alloc(q - p + 1)) != NULL) {
strncpy_s(str, q - p, p, _TRUNCATE);
- str[q-p] = '\0';
+ str[q - p] = '\0';
debugLogA("FT Got: %s", str);
if (ft->state == FT_CONNECTING) {
// looking for "HTTP/1.1 200 OK"
- if (sscanf(str, "HTTP/%*d.%*d %d %*s", &code)==1 && code==200) {
+ if (sscanf(str, "HTTP/%*d.%*d %d %*s", &code) == 1 && code == 200) {
ft->state = FT_INITIALIZING;
ft->std.currentFileSize = -1;
debugLogA("Change to FT_INITIALIZING");
@@ -124,15 +124,16 @@ int CJabberProto::FileReceiveParse(filetransfer *ft, char* buffer, int datalen)
ft->std.currentFileProgress = 0;
debugLogA("Change to FT_RECEIVING");
}
- else if ((s=strchr(str, ':')) != NULL) {
+ else if ((s = strchr(str, ':')) != NULL) {
*s = '\0';
if (!strcmp(str, "Content-Length"))
- ft->std.totalBytes = ft->std.currentFileSize = _atoi64(s+1);
- } }
+ ft->std.totalBytes = ft->std.currentFileSize = _atoi64(s + 1);
+ }
+ }
mir_free(str);
q += 2;
- num += (q-p);
+ num += (q - p);
p = q;
}
else {
@@ -146,7 +147,7 @@ int CJabberProto::FileReceiveParse(filetransfer *ft, char* buffer, int datalen)
}
else if (ft->state == FT_RECEIVING) {
int bufferSize, writeSize;
- __int64 remainingBytes;
+ __int64 remainingBytes;
if (ft->std.currentFileSize < 0 || ft->std.currentFileProgress < ft->std.currentFileSize) {
bufferSize = eob - p;
@@ -199,7 +200,7 @@ void JabberFileServerConnection(JABBER_SOCKET hConnection, DWORD /*dwRemoteIP*/,
ft->s = hConnection;
ppro->debugLogA("Set ft->s to %d (saving %d)", hConnection, slisten);
- char* buffer = (char*)mir_alloc(JABBER_NETWORK_BUFFER_SIZE+1);
+ char* buffer = (char*)mir_alloc(JABBER_NETWORK_BUFFER_SIZE + 1);
if (buffer == NULL) {
ppro->debugLogA("Cannot allocate network buffer, file server connection closed.");
Netlib_CloseHandle(hConnection);
@@ -211,10 +212,10 @@ void JabberFileServerConnection(JABBER_SOCKET hConnection, DWORD /*dwRemoteIP*/,
ppro->debugLogA("Entering recv loop for this file connection... (ft->s is hConnection)");
int datalen = 0;
- while (ft->state!=FT_DONE && ft->state!=FT_ERROR) {
+ while (ft->state != FT_DONE && ft->state != FT_ERROR) {
int recvResult, bytesParsed;
- recvResult = Netlib_Recv(hConnection, buffer+datalen, JABBER_NETWORK_BUFFER_SIZE-datalen, 0);
+ recvResult = Netlib_Recv(hConnection, buffer + datalen, JABBER_NETWORK_BUFFER_SIZE - datalen, 0);
if (recvResult <= 0)
break;
datalen += recvResult;
@@ -224,7 +225,7 @@ void JabberFileServerConnection(JABBER_SOCKET hConnection, DWORD /*dwRemoteIP*/,
bytesParsed = ppro->FileSendParse(hConnection, ft, buffer, datalen);
if (bytesParsed < datalen)
- memmove(buffer, buffer+bytesParsed, datalen-bytesParsed);
+ memmove(buffer, buffer + bytesParsed, datalen - bytesParsed);
datalen -= bytesParsed;
}
@@ -241,10 +242,10 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft)
{
debugLogA("Thread started: type=file_send");
- ThreadData info(this, JABBER_SESSION_NORMAL);
+ ThreadData info(this, NULL);
ft->type = FT_OOB;
- NETLIBBIND nlb = {0};
+ NETLIBBIND nlb = { 0 };
nlb.cbSize = sizeof(NETLIBBIND);
nlb.pfnNewConnectionV2 = JabberFileServerConnection;
nlb.pExtra = this;
@@ -271,7 +272,7 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft)
TCHAR *ptszResource = ListGetBestClientResourceNamePtr(ft->jid);
if (ptszResource != NULL) {
ft->state = FT_CONNECTING;
- for (int i=0; i < ft->std.totalFiles && ft->state != FT_ERROR && ft->state != FT_DENIED; i++) {
+ for (int i = 0; i < ft->std.totalFiles && ft->state != FT_ERROR && ft->state != FT_DENIED; i++) {
ft->std.currentFileNumber = i;
ft->state = FT_CONNECTING;
if (ft->httpPath) mir_free(ft->httpPath);
@@ -283,7 +284,7 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft)
else
p = ft->std.ptszFiles[i];
- char *pFileName = mir_urlEncode( ptrA( mir_utf8encodeT(p)));
+ char *pFileName = mir_urlEncode(ptrA(mir_utf8encodeT(p)));
if (pFileName != NULL) {
ft->szId = JabberId2string(SerialNext());
@@ -354,23 +355,23 @@ int CJabberProto::FileSendParse(JABBER_SOCKET s, filetransfer *ft, char* buffer,
eob = buffer + datalen;
p = buffer;
num = 0;
- while (ft->state==FT_CONNECTING || ft->state==FT_INITIALIZING) {
- for (q=p; q+1<eob && (*q!='\r' || *(q+1)!='\n'); q++);
- if (q+1 >= eob)
+ while (ft->state == FT_CONNECTING || ft->state == FT_INITIALIZING) {
+ for (q = p; q + 1 < eob && (*q != '\r' || *(q + 1) != '\n'); q++);
+ if (q + 1 >= eob)
break;
- if ((str=(char*)mir_alloc(q-p+1)) == NULL) {
+ if ((str = (char*)mir_alloc(q - p + 1)) == NULL) {
ft->state = FT_ERROR;
break;
}
strncpy_s(str, q - p, p, _TRUNCATE);
- str[q-p] = '\0';
+ str[q - p] = '\0';
debugLogA("FT Got: %s", str);
if (ft->state == FT_CONNECTING) {
// looking for "GET filename.ext HTTP/1.1"
if (!strncmp(str, "GET ", 4)) {
- for (t=str+4; *t!='\0' && *t!=' '; t++);
+ for (t = str + 4; *t != '\0' && *t != ' '; t++);
*t = '\0';
- for (t=str+4; *t!='\0' && *t=='/'; t++);
+ for (t = str + 4; *t != '\0' && *t == '/'; t++);
ft->httpPath = mir_a2t(t);
JabberHttpUrlDecode(ft->httpPath);
ft->state = FT_INITIALIZING;
@@ -385,7 +386,7 @@ int CJabberProto::FileSendParse(JABBER_SOCKET s, filetransfer *ft, char* buffer,
num += 2;
currentFile = ft->std.currentFileNumber;
- TCHAR *t = _tcsrchr(ft->std.ptszFiles[ currentFile ], '\\');
+ TCHAR *t = _tcsrchr(ft->std.ptszFiles[currentFile], '\\');
if (t != NULL)
t++;
else
@@ -399,9 +400,9 @@ int CJabberProto::FileSendParse(JABBER_SOCKET s, filetransfer *ft, char* buffer,
ft->state = FT_ERROR;
break;
}
- debugLog(_T("Sending [%s]"), ft->std.ptszFiles[ currentFile ]);
- _tstati64(ft->std.ptszFiles[ currentFile ], &statbuf); // file size in statbuf.st_size
- if ((fileId = _topen(ft->std.ptszFiles[currentFile], _O_BINARY|_O_RDONLY)) < 0) {
+ debugLog(_T("Sending [%s]"), ft->std.ptszFiles[currentFile]);
+ _tstati64(ft->std.ptszFiles[currentFile], &statbuf); // file size in statbuf.st_size
+ if ((fileId = _topen(ft->std.ptszFiles[currentFile], _O_BINARY | _O_RDONLY)) < 0) {
debugLogA("File cannot be opened");
ft->state = FT_ERROR;
mir_free(ft->httpPath);
@@ -409,7 +410,7 @@ int CJabberProto::FileSendParse(JABBER_SOCKET s, filetransfer *ft, char* buffer,
break;
}
- char fileBuffer[ 2048 ];
+ char fileBuffer[2048];
int bytes = mir_snprintf(fileBuffer, sizeof(fileBuffer), "HTTP/1.1 200 OK\r\nContent-Length: %I64u\r\n\r\n", statbuf.st_size);
WsSend(s, fileBuffer, bytes, MSG_DUMPASTEXT);
@@ -480,7 +481,7 @@ filetransfer::~filetransfer()
mir_free(std.tszCurrentFile);
if (std.ptszFiles) {
- for (int i=0; i < std.totalFiles; i++)
+ for (int i = 0; i < std.totalFiles; i++)
mir_free(std.ptszFiles[i]);
mir_free(std.ptszFiles);
} }
@@ -505,7 +506,7 @@ int filetransfer::create()
if (fileId != -1)
return fileId;
- TCHAR filefull[ MAX_PATH ];
+ TCHAR filefull[MAX_PATH];
mir_sntprintf(filefull, SIZEOF(filefull), _T("%s\\%s"), std.tszWorkingDir, std.tszCurrentFile);
replaceStrT(std.tszCurrentFile, filefull);
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index a6dce6f2f9..84232b04e0 100644
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -117,7 +117,7 @@ void CJabberProto::OnIqResultNotes(HXML iqNode, CJabberIqInfo *pInfo)
}
}
-void CJabberProto::OnProcessLoginRq(ThreadData* info, DWORD rq)
+void CJabberProto::OnProcessLoginRq(ThreadData *info, DWORD rq)
{
if (info == NULL)
return;
@@ -180,23 +180,23 @@ void CJabberProto::OnLoggedIn()
<< XCHILDNS(_T("storage"), JABBER_FEAT_MIRANDA_NOTES));
m_ThreadInfo->send(
- XmlNodeIq( AddIQ(&CJabberProto::OnIqResultDiscoBookmarks, JABBER_IQ_TYPE_GET))
+ XmlNodeIq(AddIQ(&CJabberProto::OnIqResultDiscoBookmarks, JABBER_IQ_TYPE_GET))
<< XQUERY(JABBER_FEAT_PRIVATE_STORAGE) << XCHILDNS(_T("storage"), _T("storage:bookmarks")));
m_bPepSupported = false;
m_ThreadInfo->jabberServerCaps = JABBER_RESOURCE_CAPS_NONE;
m_ThreadInfo->send(
- XmlNodeIq( AddIQ(&CJabberProto::OnIqResultServerDiscoInfo, JABBER_IQ_TYPE_GET, _A2T(m_ThreadInfo->server)))
+ XmlNodeIq(AddIQ(&CJabberProto::OnIqResultServerDiscoInfo, JABBER_IQ_TYPE_GET, _A2T(m_ThreadInfo->conn.server)))
<< XQUERY(JABBER_FEAT_DISCO_INFO));
QueryPrivacyLists(m_ThreadInfo);
- ptrA szServerName( getStringA("LastLoggedServer"));
- if (szServerName == NULL || strcmp(m_ThreadInfo->server, szServerName))
+ ptrA szServerName(getStringA("LastLoggedServer"));
+ if (szServerName == NULL || strcmp(m_ThreadInfo->conn.server, szServerName))
SendGetVcard(m_szJabberJID);
- setString("LastLoggedServer", m_ThreadInfo->server);
+ setString("LastLoggedServer", m_ThreadInfo->conn.server);
m_pepServices.ResetPublishAll();
}
@@ -208,25 +208,25 @@ void CJabberProto::OnIqResultGetAuth(HXML iqNode, CJabberIqInfo *pInfo)
HXML queryNode;
const TCHAR *type;
- if ((type=xmlGetAttrValue(iqNode, _T("type"))) == NULL) return;
- if ((queryNode=xmlGetChild(iqNode , "query")) == NULL) return;
+ if ((type = xmlGetAttrValue(iqNode, _T("type"))) == NULL) return;
+ if ((queryNode = xmlGetChild(iqNode, "query")) == NULL) return;
if (!lstrcmp(type, _T("result"))) {
- XmlNodeIq iq( AddIQ(&CJabberProto::OnIqResultSetAuth, JABBER_IQ_TYPE_SET));
+ XmlNodeIq iq(AddIQ(&CJabberProto::OnIqResultSetAuth, JABBER_IQ_TYPE_SET));
HXML query = iq << XQUERY(_T("jabber:iq:auth"));
- query << XCHILD(_T("username"), m_ThreadInfo->username);
- if (xmlGetChild(queryNode, "digest") != NULL && m_szStreamId) {
- char* str = mir_utf8encodeT(m_ThreadInfo->password);
+ query << XCHILD(_T("username"), m_ThreadInfo->conn.username);
+ if (xmlGetChild(queryNode, "digest") != NULL && m_ThreadInfo->szStreamId) {
+ char* str = mir_utf8encodeT(m_ThreadInfo->conn.password);
char text[200];
- mir_snprintf(text, SIZEOF(text), "%s%s", m_szStreamId, str);
+ mir_snprintf(text, SIZEOF(text), "%s%s", m_ThreadInfo->szStreamId, str);
mir_free(str);
- if ((str=JabberSha1(text)) != NULL) {
+ if ((str = JabberSha1(text)) != NULL) {
query << XCHILD(_T("digest"), _A2T(str));
mir_free(str);
}
}
else if (xmlGetChild(queryNode, "password") != NULL)
- query << XCHILD(_T("password"), m_ThreadInfo->password);
+ query << XCHILD(_T("password"), m_ThreadInfo->conn.password);
else {
debugLogA("No known authentication mechanism accepted by the server.");
m_ThreadInfo->send("</stream:stream>");
@@ -239,10 +239,10 @@ void CJabberProto::OnIqResultGetAuth(HXML iqNode, CJabberIqInfo *pInfo)
m_ThreadInfo->send(iq);
}
else if (!lstrcmp(type, _T("error"))) {
- m_ThreadInfo->send("</stream:stream>");
+ m_ThreadInfo->send("</stream:stream>");
TCHAR text[128];
- mir_sntprintf(text, SIZEOF(text), TranslateT("Authentication failed for %s."), m_ThreadInfo->username);
+ mir_sntprintf(text, SIZEOF(text), TranslateT("Authentication failed for %s."), m_ThreadInfo->conn.username);
MsgPopup(NULL, text, TranslateT("Jabber Authentication"));
JLoginFailed(LOGINERR_WRONGPASSWORD);
m_ThreadInfo = NULL; // To disallow auto reconnect
@@ -255,12 +255,12 @@ void CJabberProto::OnIqResultSetAuth(HXML iqNode, CJabberIqInfo *pInfo)
// RECVED: authentication result
// ACTION: if successfully logged in, continue by requesting roster list and set my initial status
debugLogA("<iq/> iqIdSetAuth");
- if ((type=xmlGetAttrValue(iqNode, _T("type"))) == NULL) return;
+ if ((type = xmlGetAttrValue(iqNode, _T("type"))) == NULL) return;
if (!lstrcmp(type, _T("result"))) {
- ptrT tszNick( getTStringA("Nick"));
+ ptrT tszNick(getTStringA("Nick"));
if (tszNick == NULL)
- setTString("Nick", m_ThreadInfo->username);
+ setTString("Nick", m_ThreadInfo->conn.username);
OnLoggedIn();
}
@@ -269,7 +269,7 @@ void CJabberProto::OnIqResultSetAuth(HXML iqNode, CJabberIqInfo *pInfo)
TCHAR text[128];
m_ThreadInfo->send("</stream:stream>");
- mir_sntprintf(text, SIZEOF(text), TranslateT("Authentication failed for %s."), m_ThreadInfo->username);
+ mir_sntprintf(text, SIZEOF(text), TranslateT("Authentication failed for %s."), m_ThreadInfo->conn.username);
MsgPopup(NULL, text, TranslateT("Jabber Authentication"));
JLoginFailed(LOGINERR_WRONGPASSWORD);
m_ThreadInfo = NULL; // To disallow auto reconnect
@@ -1262,7 +1262,7 @@ void CJabberProto::OnIqResultSetPassword(HXML iqNode, CJabberIqInfo *pInfo)
return;
if (!lstrcmp(type, _T("result"))) {
- _tcsncpy_s(m_ThreadInfo->password, m_ThreadInfo->tszNewPassword, _TRUNCATE);
+ _tcsncpy_s(m_ThreadInfo->conn.password, m_ThreadInfo->tszNewPassword, _TRUNCATE);
MessageBox(NULL, TranslateT("Password is successfully changed. Don't forget to update your password in the Jabber protocol option."), TranslateT("Change Password"), MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND);
}
else if (!lstrcmp(type, _T("error")))
diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp
index 2fea681ee1..d5a0fc137e 100644
--- a/protocols/JabberG/src/jabber_misc.cpp
+++ b/protocols/JabberG/src/jabber_misc.cpp
@@ -204,7 +204,7 @@ void CJabberProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t c
}
else if (m_ThreadInfo != NULL) {
mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%s@%S avatar%s"),
- m_ThreadInfo->username, m_ThreadInfo->server, szFileType);
+ m_ThreadInfo->conn.username, m_ThreadInfo->conn.server, szFileType);
}
else {
ptrA res1( getStringA("LoginName")), res2( getStringA("LoginServer"));
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp
index a29a93728f..ce8ea900d9 100644
--- a/protocols/JabberG/src/jabber_opt.cpp
+++ b/protocols/JabberG/src/jabber_opt.cpp
@@ -228,7 +228,7 @@ class CJabberDlgRegister: public CJabberDlgBase
{
typedef CJabberDlgBase CSuper;
public:
- CJabberDlgRegister(CJabberProto *proto, HWND hwndParent, ThreadData *regInfo):
+ CJabberDlgRegister(CJabberProto *proto, HWND hwndParent, JABBER_CONN_DATA *regInfo):
CJabberDlgBase(proto, IDD_OPT_REGISTER, hwndParent, false),
m_bProcessStarted(false),
m_regInfo(regInfo),
@@ -270,7 +270,7 @@ protected:
private:
bool m_bProcessStarted;
- ThreadData *m_regInfo;
+ JABBER_CONN_DATA *m_regInfo;
CCtrlButton m_btnOk;
@@ -283,15 +283,8 @@ private:
ShowWindow(GetDlgItem(m_hwnd, IDC_PROGRESS_REG), SW_SHOW);
- ThreadData *thread = new ThreadData(m_regInfo->proto, JABBER_SESSION_REGISTER);
- _tcsncpy_s(thread->username, m_regInfo->username, _TRUNCATE);
- _tcsncpy_s(thread->password, m_regInfo->password, _TRUNCATE);
- strncpy_s(thread->server, m_regInfo->server, _TRUNCATE);
- strncpy_s(thread->manualHost, m_regInfo->manualHost, _TRUNCATE);
- thread->port = m_regInfo->port;
- thread->useSSL = m_regInfo->useSSL;
- thread->reg_hwndDlg = m_hwnd;
- m_proto->ForkThread((CJabberProto::MyThreadFunc)&CJabberProto::ServerThread, thread);
+ m_regInfo->reg_hwndDlg = m_hwnd;
+ m_proto->ForkThread((CJabberProto::MyThreadFunc)&CJabberProto::ServerThread, m_regInfo);
m_btnOk.SetText(TranslateT("Cancel"));
m_bProcessStarted = true;
@@ -578,7 +571,7 @@ private:
pshn.hdr.hwndFrom = m_hwnd;
SendMessage(m_hwnd, WM_NOTIFY, 0, (LPARAM)&pshn);
- ThreadData regInfo(m_proto, JABBER_SESSION_NORMAL);
+ JABBER_CONN_DATA regInfo;
m_txtUsername.GetText(regInfo.username, SIZEOF(regInfo.username));
m_txtPassword.GetText(regInfo.password, SIZEOF(regInfo.password));
m_cbServer.GetTextA(regInfo.server, SIZEOF(regInfo.server));
@@ -591,7 +584,7 @@ private:
regInfo.manualHost[0] = '\0';
}
- if (regInfo.username[0] && regInfo.password[0] && regInfo.server[0] && regInfo.port>0 && ((m_chkManualHost.GetState() != BST_CHECKED) || regInfo.manualHost[0])) {
+ if (regInfo.username[0] && regInfo.password[0] && regInfo.server[0] && regInfo.port > 0 && ((m_chkManualHost.GetState() != BST_CHECKED) || regInfo.manualHost[0])) {
CJabberDlgRegister dlg(m_proto, m_hwnd, &regInfo);
dlg.DoModal();
}
@@ -697,7 +690,7 @@ private:
void CheckRegistration()
{
- ThreadData regInfo(m_proto, JABBER_SESSION_NORMAL);
+ JABBER_CONN_DATA regInfo;
m_txtUsername.GetText(regInfo.username, SIZEOF(regInfo.username));
m_txtPassword.GetText(regInfo.password, SIZEOF(regInfo.password));
m_cbServer.GetTextA(regInfo.server, SIZEOF(regInfo.server));
@@ -710,7 +703,7 @@ private:
regInfo.manualHost[0] = '\0';
}
- if (regInfo.username[0] && regInfo.password[0] && regInfo.server[0] && regInfo.port>0 && ((m_chkManualHost.GetState() != BST_CHECKED) || regInfo.manualHost[0]))
+ if (regInfo.username[0] && regInfo.password[0] && regInfo.server[0] && regInfo.port > 0 && ((m_chkManualHost.GetState() != BST_CHECKED) || regInfo.manualHost[0]))
EnableWindow(GetDlgItem(m_hwnd, IDC_BUTTON_REGISTER), TRUE);
else
EnableWindow(GetDlgItem(m_hwnd, IDC_BUTTON_REGISTER), FALSE);
@@ -1866,7 +1859,7 @@ private:
pshn.hdr.hwndFrom = m_hwnd;
SendMessage(m_hwnd, WM_NOTIFY, 0, (LPARAM)&pshn);
- ThreadData regInfo(m_proto, JABBER_SESSION_NORMAL);
+ JABBER_CONN_DATA regInfo;
m_txtUsername.GetText(regInfo.username, SIZEOF(regInfo.username));
m_txtPassword.GetText(regInfo.password, SIZEOF(regInfo.password));
m_cbServer.GetTextA(regInfo.server, SIZEOF(regInfo.server));
@@ -1949,11 +1942,11 @@ void CJabberDlgAccMgrUI::CheckRegistration()
return;
}
- ThreadData regInfo(m_proto, JABBER_SESSION_NORMAL);
+ JABBER_CONN_DATA regInfo;
m_txtUsername.GetText(regInfo.username, SIZEOF(regInfo.username));
m_txtPassword.GetText(regInfo.password, SIZEOF(regInfo.password));
m_cbServer.GetTextA(regInfo.server, SIZEOF(regInfo.server));
- regInfo.port = (WORD)m_txtPort.GetInt();
+ regInfo.port = m_txtPort.GetInt();
if (m_chkManualHost.GetState() == BST_CHECKED)
m_txtManualHost.GetTextA(regInfo.manualHost, SIZEOF(regInfo.manualHost));
else
diff --git a/protocols/JabberG/src/jabber_password.cpp b/protocols/JabberG/src/jabber_password.cpp
index a994f8bb7a..ffd4bd58d3 100644
--- a/protocols/JabberG/src/jabber_password.cpp
+++ b/protocols/JabberG/src/jabber_password.cpp
@@ -50,7 +50,7 @@ static INT_PTR CALLBACK JabberChangePasswordDlgProc(HWND hwndDlg, UINT msg, WPAR
TranslateDialogDefault(hwndDlg);
if (ppro->m_bJabberOnline && ppro->m_ThreadInfo != NULL) {
TCHAR text[1024];
- mir_sntprintf(text, SIZEOF(text), TranslateT("Set New Password for %s@%S"), ppro->m_ThreadInfo->username, ppro->m_ThreadInfo->server);
+ mir_sntprintf(text, SIZEOF(text), TranslateT("Set New Password for %s@%S"), ppro->m_ThreadInfo->conn.username, ppro->m_ThreadInfo->conn.server);
SetWindowText(hwndDlg, text);
}
return TRUE;
@@ -66,15 +66,15 @@ static INT_PTR CALLBACK JabberChangePasswordDlgProc(HWND hwndDlg, UINT msg, WPAR
break;
}
GetDlgItemText(hwndDlg, IDC_OLDPASSWD, text, SIZEOF(text));
- if (_tcscmp(text, ppro->m_ThreadInfo->password)) {
+ if (_tcscmp(text, ppro->m_ThreadInfo->conn.password)) {
MessageBox(hwndDlg, TranslateT("Current password is incorrect."), TranslateT("Change Password"), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
break;
}
ppro->m_ThreadInfo->tszNewPassword = mir_tstrdup(newPasswd);
- XmlNodeIq iq( ppro->AddIQ(&CJabberProto::OnIqResultSetPassword, JABBER_IQ_TYPE_SET, _A2T(ppro->m_ThreadInfo->server)));
+ XmlNodeIq iq(ppro->AddIQ(&CJabberProto::OnIqResultSetPassword, JABBER_IQ_TYPE_SET, _A2T(ppro->m_ThreadInfo->conn.server)));
HXML q = iq << XQUERY(JABBER_FEAT_REGISTER);
- q << XCHILD(_T("username"), ppro->m_ThreadInfo->username);
+ q << XCHILD(_T("username"), ppro->m_ThreadInfo->conn.username);
q << XCHILD(_T("password"), newPasswd);
ppro->m_ThreadInfo->send(iq);
}
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 47bda82b1c..ca211ac890 100644
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -181,8 +181,6 @@ CJabberProto::~CJabberProto()
mir_free(m_transportProtoTableStartIndex);
- mir_free(m_szStreamId);
-
for (int i=0; i < m_lstTransports.getCount(); i++)
mir_free(m_lstTransports[i]);
@@ -731,7 +729,7 @@ HANDLE __cdecl CJabberProto::SearchBasic(const TCHAR *szJid)
return 0;
if (_tcschr(szJid, '@') == NULL) {
- TCHAR *szServer = mir_a2t(m_ThreadInfo->server);
+ TCHAR *szServer = mir_a2t(m_ThreadInfo->conn.server);
const TCHAR *p = _tcsstr(szJid, szServer);
if (p == NULL) {
bool numericjid = true;
@@ -902,7 +900,6 @@ HANDLE __cdecl CJabberProto::SendFile(MCONTACT hContact, const TCHAR *szDescript
if (jid == NULL)
return 0;
- int i, j;
struct _stati64 statbuf;
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid);
if (item == NULL)
@@ -946,6 +943,8 @@ HANDLE __cdecl CJabberProto::SendFile(MCONTACT hContact, const TCHAR *szDescript
ft->std.ptszFiles = (TCHAR**)mir_calloc(sizeof(TCHAR*)* ft->std.totalFiles);
ft->fileSize = (unsigned __int64*)mir_calloc(sizeof(unsigned __int64)* ft->std.totalFiles);
+
+ int i, j;
for (i = j = 0; i < ft->std.totalFiles; i++) {
if (_tstati64(ppszFiles[i], &statbuf))
debugLog(_T("'%s' is an invalid filename"), ppszFiles[i]);
@@ -1015,8 +1014,8 @@ int __cdecl CJabberProto::SendMsg(MCONTACT hContact, int flags, const char* pszS
int isEncrypted, id = SerialNext();
if (!strncmp(pszSrc, PGP_PROLOG, strlen(PGP_PROLOG))) {
- const char* szEnd = strstr(pszSrc, PGP_EPILOG);
- char* tempstring = (char*)alloca(strlen(pszSrc) + 1);
+ const char *szEnd = strstr(pszSrc, PGP_EPILOG);
+ char *tempstring = (char*)alloca(strlen(pszSrc) + 1);
size_t nStrippedLength = strlen(pszSrc) - strlen(PGP_PROLOG) - (szEnd ? strlen(szEnd) : 0);
strncpy_s(tempstring, nStrippedLength, pszSrc + strlen(PGP_PROLOG), _TRUNCATE);
tempstring[nStrippedLength] = 0;
@@ -1071,7 +1070,8 @@ int __cdecl CJabberProto::SendMsg(MCONTACT hContact, int flags, const char* pszS
// if message sent to groupchat
!lstrcmp(msgType, _T("groupchat")) ||
// if message delivery check disabled in settings
- !m_options.MsgAck || !getByte(hContact, "MsgAck", TRUE)) {
+ !m_options.MsgAck || !getByte(hContact, "MsgAck", TRUE))
+ {
if (!lstrcmp(msgType, _T("groupchat")))
xmlAddAttr(m, _T("to"), szClientJid);
else {
@@ -1172,9 +1172,8 @@ int __cdecl CJabberProto::SetStatus(int iNewStatus)
}
else if (!m_ThreadInfo && !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) {
m_iStatus = ID_STATUS_CONNECTING;
- ThreadData* thread = new ThreadData(this, JABBER_SESSION_NORMAL);
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
- thread->hThread = ForkThreadEx((MyThreadFunc)&CJabberProto::ServerThread, thread, 0);
+ ForkThread((MyThreadFunc)&CJabberProto::ServerThread, NULL);
RebuildInfoFrame();
}
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index 522f3546da..5303bc5c5a 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -160,7 +160,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
HANDLE m_hThreadHandle;
TCHAR *m_szJabberJID;
- char *m_szStreamId;
BOOL m_bJabberOnline; // XMPP connection initialized and we can send XMPP packets
int m_nJabberSearchID;
time_t m_tmJabberLoggedInTime;
@@ -333,8 +332,8 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
//---- jabber_captcha.cpp ------------------------------------------------------------
- void sendCaptchaResult(TCHAR* buf, ThreadData* info, LPCTSTR from, LPCTSTR challenge, LPCTSTR fromjid, LPCTSTR sid);
- void sendCaptchaError(ThreadData* info, LPCTSTR from, LPCTSTR to, LPCTSTR challenge);
+ void sendCaptchaResult(TCHAR* buf, ThreadData *info, LPCTSTR from, LPCTSTR challenge, LPCTSTR fromjid, LPCTSTR sid);
+ void sendCaptchaError(ThreadData *info, LPCTSTR from, LPCTSTR to, LPCTSTR challenge);
//---- jabber_chat.cpp ---------------------------------------------------------------
@@ -491,7 +490,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void OnIqResultSetSearch(HXML iqNode, CJabberIqInfo *pInfo);
void OnIqResultSetVcard(HXML iqNode, CJabberIqInfo *pInfo);
void OnIqResultVersion(HXML node, CJabberIqInfo *pInfo);
- void OnProcessLoginRq(ThreadData* info, DWORD rq);
+ void OnProcessLoginRq(ThreadData *info, DWORD rq);
void OnLoggedIn(void);
//---- jabber_iq_handlers.cpp -------------------------------------------------------
@@ -719,7 +718,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
AUTHMECHS m_AuthMechs;
- void __cdecl ServerThread(ThreadData* info);
+ void __cdecl ServerThread(JABBER_CONN_DATA *info);
void OnProcessFailure(HXML node, ThreadData *info);
void OnProcessError(HXML node, ThreadData *info);
@@ -738,17 +737,17 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void UpdateJidDbSettings(const TCHAR *jid);
MCONTACT CreateTemporaryContact(const TCHAR *szJid, JABBER_LIST_ITEM* chatItem);
- void PerformRegistration(ThreadData* info);
- void PerformIqAuth(ThreadData* info);
- void PerformAuthentication(ThreadData* info);
- void OnProcessFeatures(HXML node, ThreadData* info);
+ void PerformRegistration(ThreadData *info);
+ void PerformIqAuth(ThreadData *info);
+ void PerformAuthentication(ThreadData *info);
+ void OnProcessFeatures(HXML node, ThreadData *info);
void xmlStreamInitialize(char *which);
- void xmlStreamInitializeNow(ThreadData* info);
+ void xmlStreamInitializeNow(ThreadData *info);
BOOL OnProcessJingle(HXML node);
void OnProcessIq(HXML node);
- void OnProcessRegIq(HXML node, ThreadData* info);
+ void OnProcessRegIq(HXML node, ThreadData *info);
void OnPingReply(HXML node, CJabberIqInfo *pInfo);
bool ProcessCaptcha(HXML node, HXML parentNode, ThreadData *info);
diff --git a/protocols/JabberG/src/jabber_secur.cpp b/protocols/JabberG/src/jabber_secur.cpp
index cc3c76bee7..b0cf0ac342 100644
--- a/protocols/JabberG/src/jabber_secur.cpp
+++ b/protocols/JabberG/src/jabber_secur.cpp
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/////////////////////////////////////////////////////////////////////////////////////////
// ntlm auth - LanServer based authorization
-TNtlmAuth::TNtlmAuth(ThreadData* info, const char* mechanism, const TCHAR *hostname) :
+TNtlmAuth::TNtlmAuth(ThreadData *info, const char* mechanism, const TCHAR *hostname) :
TJabberAuth(info)
{
szName = mechanism;
@@ -84,7 +84,7 @@ bool TNtlmAuth::getSpn(TCHAR* szSpn, size_t dwSpnLen)
mir_free(szFullUserNameU);
}
else {
- const char* connectHost = info->manualHost[0] ? info->manualHost : info->server;
+ const char* connectHost = info->conn.manualHost[0] ? info->conn.manualHost : info->conn.server;
unsigned long ip = inet_addr(connectHost);
PHOSTENT host = (ip == INADDR_NONE) ? NULL : gethostbyaddr((char*)&ip, 4, AF_INET);
@@ -107,8 +107,8 @@ char* TNtlmAuth::getInitialRequest()
// This generates login method advertisement packet
char* result;
- if (info->password[0] != 0)
- result = Netlib_NtlmCreateResponse2(hProvider, "", info->username, info->password, &complete);
+ if (info->conn.password[0] != 0)
+ result = Netlib_NtlmCreateResponse2(hProvider, "", info->conn.username, info->conn.password, &complete);
else
result = Netlib_NtlmCreateResponse2(hProvider, "", NULL, NULL, &complete);
@@ -121,8 +121,8 @@ char* TNtlmAuth::getChallenge(const TCHAR *challenge)
return NULL;
char *text = (!lstrcmp(challenge, _T("="))) ? mir_strdup("") : mir_t2a(challenge), *result;
- if (info->password[0] != 0)
- result = Netlib_NtlmCreateResponse2(hProvider, text, info->username, info->password, &complete);
+ if (info->conn.password[0] != 0)
+ result = Netlib_NtlmCreateResponse2(hProvider, text, info->conn.username, info->conn.password, &complete);
else
result = Netlib_NtlmCreateResponse2(hProvider, text, NULL, NULL, &complete);
@@ -133,7 +133,7 @@ char* TNtlmAuth::getChallenge(const TCHAR *challenge)
/////////////////////////////////////////////////////////////////////////////////////////
// md5 auth - digest-based authorization
-TMD5Auth::TMD5Auth(ThreadData* info) :
+TMD5Auth::TMD5Auth(ThreadData *info) :
TJabberAuth(info),
iCallCount(0)
{
@@ -164,9 +164,9 @@ char* TMD5Auth::getChallenge(const TCHAR *challenge)
CallService(MS_UTILS_GETRANDOM, sizeof(digest), (LPARAM)digest);
mir_snprintf(cnonce, SIZEOF(cnonce), "%08x%08x%08x%08x", htonl(digest[0]), htonl(digest[1]), htonl(digest[2]), htonl(digest[3]));
- ptrA uname( mir_utf8encodeT(info->username)),
- passw( mir_utf8encodeT(info->password)),
- serv( mir_utf8encode(info->server));
+ ptrA uname(mir_utf8encodeT(info->conn.username)),
+ passw(mir_utf8encodeT(info->conn.password)),
+ serv(mir_utf8encode(info->conn.server));
mir_md5_init(&ctx);
mir_md5_append(&ctx, (BYTE*)(char*)uname, (int)strlen(uname));
@@ -215,7 +215,7 @@ char* TMD5Auth::getChallenge(const TCHAR *challenge)
/////////////////////////////////////////////////////////////////////////////////////////
// SCRAM-SHA-1 authorization
-TScramAuth::TScramAuth(ThreadData* info) :
+TScramAuth::TScramAuth(ThreadData *info) :
TJabberAuth(info)
{
szName = "SCRAM-SHA-1";
@@ -269,7 +269,7 @@ char* TScramAuth::getChallenge(const TCHAR *challenge)
if (snonce == NULL || salt == NULL || ind == -1)
return NULL;
- ptrA passw(mir_utf8encodeT(info->password));
+ ptrA passw(mir_utf8encodeT(info->conn.password));
size_t passwLen = strlen(passw);
BYTE saltedPassw[MIR_SHA1_HASH_SIZE];
@@ -311,7 +311,7 @@ char* TScramAuth::getChallenge(const TCHAR *challenge)
char* TScramAuth::getInitialRequest()
{
- ptrA uname(mir_utf8encodeT(info->username));
+ ptrA uname(mir_utf8encodeT(info->conn.username));
unsigned char nonce[24];
CallService(MS_UTILS_GETRANDOM, sizeof(nonce), (LPARAM)nonce);
@@ -333,7 +333,7 @@ bool TScramAuth::validateLogin(const TCHAR *challenge)
/////////////////////////////////////////////////////////////////////////////////////////
// plain auth - the most simple one
-TPlainAuth::TPlainAuth(ThreadData* info, bool old) :
+TPlainAuth::TPlainAuth(ThreadData *info, bool old) :
TJabberAuth(info)
{
szName = "PLAIN";
@@ -346,12 +346,12 @@ TPlainAuth::~TPlainAuth()
char* TPlainAuth::getInitialRequest()
{
- ptrA uname(mir_utf8encodeT(info->username)), passw(mir_utf8encodeT(info->password));
+ ptrA uname(mir_utf8encodeT(info->conn.username)), passw(mir_utf8encodeT(info->conn.password));
- size_t size = 2 * strlen(uname) + strlen(passw) + strlen(info->server) + 4;
+ size_t size = 2 * strlen(uname) + strlen(passw) + strlen(info->conn.server) + 4;
char *toEncode = (char*)alloca(size);
if (bOld)
- size = mir_snprintf(toEncode, size, "%s@%s%c%s%c%s", uname, info->server, 0, uname, 0, passw);
+ size = mir_snprintf(toEncode, size, "%s@%s%c%s%c%s", uname, info->conn.server, 0, uname, 0, passw);
else
size = mir_snprintf(toEncode, size, "%c%s%c%s", 0, uname, 0, passw);
diff --git a/protocols/JabberG/src/jabber_secur.h b/protocols/JabberG/src/jabber_secur.h
index fadcf42fc3..6666c11d4e 100644
--- a/protocols/JabberG/src/jabber_secur.h
+++ b/protocols/JabberG/src/jabber_secur.h
@@ -32,7 +32,7 @@ class TJabberAuth
protected: bool bIsValid;
const char* szName;
unsigned complete;
- ThreadData* info;
+ ThreadData *info;
public:
TJabberAuth(ThreadData*);
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index 8ea9ab3839..0120ad9e4d 100644
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -144,11 +144,11 @@ static int CompareDNS(const DNS_SRV_DATAA* dns1, const DNS_SRV_DATAA* dns2)
void ThreadData::xmpp_client_query(void)
{
- if (inet_addr(server) != INADDR_NONE)
+ if (inet_addr(conn.server) != INADDR_NONE)
return;
char temp[256];
- mir_snprintf(temp, SIZEOF(temp), "_xmpp-client._tcp.%s", server);
+ mir_snprintf(temp, SIZEOF(temp), "_xmpp-client._tcp.%s", conn.server);
DNS_RECORDA *results = NULL;
DNS_STATUS status = DnsQuery_A(temp, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD *)&results, NULL);
@@ -161,14 +161,14 @@ void ThreadData::xmpp_client_query(void)
}
for (int i = 0; i < dnsList.getCount(); i++) {
- WORD dnsPort = port == 0 || port == 5222 ? dnsList[i]->wPort : port;
+ WORD dnsPort = (conn.port == 0 || conn.port == 5222) ? dnsList[i]->wPort : conn.port;
char* dnsHost = dnsList[i]->pNameTarget;
- proto->debugLogA("%s%s resolved to %s:%d", "_xmpp-client._tcp.", server, dnsHost, dnsPort);
+ proto->debugLogA("%s%s resolved to %s:%d", "_xmpp-client._tcp.", conn.server, dnsHost, dnsPort);
s = proto->WsConnect(dnsHost, dnsPort);
if (s) {
- mir_snprintf(manualHost, SIZEOF(manualHost), "%s", dnsHost);
- port = dnsPort;
+ strncpy_s(conn.manualHost, dnsHost, _TRUNCATE);
+ conn.port = dnsPort;
break;
} }
DnsRecordListFree(results, DnsFreeRecordList);
@@ -184,7 +184,7 @@ void CJabberProto::xmlStreamInitialize(char *szWhich)
m_szXmlStreamToBeInitialized = _strdup(szWhich);
}
-void CJabberProto::xmlStreamInitializeNow(ThreadData* info)
+void CJabberProto::xmlStreamInitializeNow(ThreadData *info)
{
debugLogA("Stream is initializing %s",
m_szXmlStreamToBeInitialized ? m_szXmlStreamToBeInitialized : "after connect");
@@ -195,7 +195,7 @@ void CJabberProto::xmlStreamInitializeNow(ThreadData* info)
HXML n = xi.createNode(_T("xml"), NULL, 1) << XATTR(_T("version"), _T("1.0")) << XATTR(_T("encoding"), _T("UTF-8"));
- HXML stream = n << XCHILDNS(_T("stream:stream"), _T("jabber:client")) << XATTR(_T("to"), _A2T(info->server))
+ HXML stream = n << XCHILDNS(_T("stream:stream"), _T("jabber:client")) << XATTR(_T("to"), _A2T(info->conn.server))
<< XATTR(_T("xmlns:stream"), _T("http://etherx.jabber.org/streams"));
if (m_tszSelectedLang)
@@ -218,72 +218,60 @@ void CJabberProto::xmlStreamInitializeNow(ThreadData* info)
xi.destroyNode(n);
}
-void CJabberProto::ServerThread(ThreadData* info)
+void CJabberProto::ServerThread(JABBER_CONN_DATA *param)
{
- char* buffer;
- int datalen;
- int oldStatus;
- ptrA szValue;
ptrT tszValue;
- debugLogA("Thread started: type=%d", info->type);
+ ThreadData info(this, param);
- info->resolveID = -1;
- info->auth = NULL;
+ debugLogA("Thread started: type=%d", info.bIsReg);
if (m_options.ManualConnect == TRUE) {
ptrA szManualHost(getStringA("ManualHost"));
if (szManualHost != NULL)
- strncpy_s(info->manualHost, SIZEOF(info->manualHost), szManualHost, _TRUNCATE);
+ strncpy_s(info.conn.manualHost, szManualHost, _TRUNCATE);
- info->port = getWord("ManualPort", JABBER_DEFAULT_PORT);
+ info.conn.port = getWord("ManualPort", JABBER_DEFAULT_PORT);
}
- else info->port = getWord("Port", JABBER_DEFAULT_PORT);
+ else info.conn.port = getWord("Port", JABBER_DEFAULT_PORT);
- info->useSSL = m_options.UseSSL;
+ info.conn.useSSL = m_options.UseSSL;
- if (info->type == JABBER_SESSION_NORMAL) {
+ if (!info.bIsReg) {
// Normal server connection, we will fetch all connection parameters
// e.g. username, password, etc. from the database.
if (m_ThreadInfo != NULL) {
- // Will not start another connection thread if a thread is already running.
- // Make APC call to the main thread. This will immediately wake the thread up
- // in case it is asleep in the reconnect loop so that it will immediately
- // reconnect.
- QueueUserAPC(JabberDummyApcFunc, m_ThreadInfo->hThread, 0);
debugLogA("Thread ended, another normal thread is running");
-LBL_Exit:
- delete info;
return;
}
- m_ThreadInfo = info;
- replaceStr(m_szStreamId, NULL);
+ m_ThreadInfo = &info;
if ((tszValue = getTStringA("LoginName")) != NULL)
- _tcsncpy_s(info->username, tszValue, _TRUNCATE);
+ _tcsncpy_s(info.conn.username, tszValue, _TRUNCATE);
- if (*rtrimt(info->username) == '\0') {
- DWORD dwSize = SIZEOF(info->username);
- if (GetUserName(info->username, &dwSize))
- setTString("LoginName", info->username);
+ if (*rtrimt(info.conn.username) == '\0') {
+ DWORD dwSize = SIZEOF(info.conn.username);
+ if (GetUserName(info.conn.username, &dwSize))
+ setTString("LoginName", info.conn.username);
else
- info->username[0] = 0;
+ info.conn.username[0] = 0;
}
- if (*rtrimt(info->username) == '\0') {
+ if (*rtrimt(info.conn.username) == '\0') {
debugLogA("Thread ended, login name is not configured");
JLoginFailed(LOGINERR_BADUSERID);
+
LBL_FatalError:
- m_ThreadInfo = NULL;
- oldStatus = m_iStatus;
+ int oldStatus = m_iStatus;
m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
- goto LBL_Exit;
+ return;
}
- if ((szValue = getStringA("LoginServer")) != NULL)
- strncpy_s(info->server, SIZEOF(info->server), szValue, _TRUNCATE);
+ ptrA szValue(getStringA("LoginServer"));
+ if (szValue != NULL)
+ strncpy_s(info.conn.server, szValue, _TRUNCATE);
else {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
debugLogA("Thread ended, login server is not configured");
@@ -291,28 +279,28 @@ LBL_FatalError:
}
if (m_options.HostNameAsResource) {
- DWORD dwCompNameLen = SIZEOF(info->resource) - 1;
- if (!GetComputerName(info->resource, &dwCompNameLen))
- _tcscpy(info->resource, _T("Miranda"));
+ DWORD dwCompNameLen = SIZEOF(info.resource) - 1;
+ if (!GetComputerName(info.resource, &dwCompNameLen))
+ _tcscpy(info.resource, _T("Miranda"));
}
else {
if ((tszValue = getTStringA("Resource")) != NULL)
- _tcsncpy_s(info->resource, tszValue, _TRUNCATE);
+ _tcsncpy_s(info.resource, tszValue, _TRUNCATE);
else
- _tcscpy(info->resource, _T("Miranda"));
+ _tcscpy(info.resource, _T("Miranda"));
}
TCHAR jidStr[512];
- mir_sntprintf(jidStr, SIZEOF(jidStr), _T("%s@%S/%s"), info->username, info->server, info->resource);
- _tcsncpy_s(info->fullJID, jidStr, _TRUNCATE);
+ mir_sntprintf(jidStr, SIZEOF(jidStr), _T("%s@%S/%s"), info.conn.username, info.conn.server, info.resource);
+ _tcsncpy_s(info.fullJID, jidStr, _TRUNCATE);
if (m_options.UseDomainLogin) // in the case of NTLM auth we have no need in password
- info->password[0] = 0;
+ info.conn.password[0] = 0;
else if (!m_options.SavePassword) { // we have to enter a password manually. have we done it before?
if (m_savedPassword != NULL)
- _tcsncpy_s(info->password, m_savedPassword, _TRUNCATE);
+ _tcsncpy_s(info.conn.password, m_savedPassword, _TRUNCATE);
else {
- mir_sntprintf(jidStr, SIZEOF(jidStr), _T("%s@%S"), info->username, info->server);
+ mir_sntprintf(jidStr, SIZEOF(jidStr), _T("%s@%S"), info.conn.username, info.conn.server);
JabberPasswordDlgParam param;
param.pro = this;
@@ -329,7 +317,7 @@ LBL_FatalError:
}
m_savedPassword = (param.saveOnlinePassword) ? mir_tstrdup(param.onlinePassword) : NULL;
- _tcsncpy_s(info->password, param.onlinePassword, _TRUNCATE);
+ _tcsncpy_s(info.conn.password, param.onlinePassword, _TRUNCATE);
}
}
else {
@@ -339,99 +327,88 @@ LBL_FatalError:
debugLogA("Thread ended, password is not configured");
goto LBL_FatalError;
}
- _tcsncpy_s(info->password, tszPassw, _TRUNCATE);
+ _tcsncpy_s(info.conn.password, tszPassw, _TRUNCATE);
}
}
- else if (info->type == JABBER_SESSION_REGISTER) {
+ else {
// Register new user connection, all connection parameters are already filled-in.
// Multiple thread allowed, although not possible :)
// thinking again.. multiple thread should not be allowed
- info->reg_done = FALSE;
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 25, (LPARAM)TranslateT("Connecting..."));
+ info.reg_done = false;
+ SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 25, (LPARAM)TranslateT("Connecting..."));
iqIdRegGetReg = -1;
iqIdRegSetReg = -1;
}
- else {
- debugLogA("Thread ended, invalid session type");
- goto LBL_FatalError;
- }
int jabberNetworkBufferSize = 2048;
- if ((buffer = (char*)mir_alloc(jabberNetworkBufferSize + 1)) == NULL) { // +1 is for '\0' when debug logging this buffer
+ if ((info.buffer = (char*)mir_alloc(jabberNetworkBufferSize + 1)) == NULL) { // +1 is for '\0' when debug logging this buffer
debugLogA("Cannot allocate network buffer, thread ended");
- if (info->type == JABBER_SESSION_NORMAL) {
+ if (info.bIsReg)
+ SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Not enough memory"));
+ else
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
- }
- else if (info->type == JABBER_SESSION_REGISTER) {
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Not enough memory"));
- }
+
debugLogA("Thread ended, network buffer cannot be allocated");
goto LBL_FatalError;
}
- if (info->manualHost[0] == 0) {
- info->xmpp_client_query();
- if (info->s == NULL) {
- strncpy_s(info->manualHost, info->server, _TRUNCATE);
- info->s = WsConnect(info->manualHost, info->port);
+ if (info.conn.manualHost[0] == 0) {
+ info.xmpp_client_query();
+ if (info.s == NULL) {
+ strncpy_s(info.conn.manualHost, info.conn.server, _TRUNCATE);
+ info.s = WsConnect(info.conn.manualHost, info.conn.port);
}
}
- else
- info->s = WsConnect(info->manualHost, info->port);
+ else info.s = WsConnect(info.conn.manualHost, info.conn.port);
- debugLogA("Thread type=%d server='%s' port='%d'", info->type, info->manualHost, info->port);
- if (info->s == NULL) {
+ debugLogA("Thread type=%d server='%s' port='%d'", info.bIsReg, info.conn.manualHost, info.conn.port);
+ if (info.s == NULL) {
debugLogA("Connection failed (%d)", WSAGetLastError());
- if (info->type == JABBER_SESSION_NORMAL) {
- if (m_ThreadInfo == info) {
+ if (!info.bIsReg) {
+ if (m_ThreadInfo == &info)
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
- } }
- else if (info->type == JABBER_SESSION_REGISTER)
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Cannot connect to the server"));
+ }
+ else SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Cannot connect to the server"));
debugLogA("Thread ended, connection failed");
- mir_free(buffer);
goto LBL_FatalError;
}
// Determine local IP
- if (info->useSSL) {
+ if (info.conn.useSSL) {
debugLogA("Intializing SSL connection");
- if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)info->s, 0)) {
+ if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)info.s, 0)) {
debugLogA("SSL intialization failed");
- if (info->type == JABBER_SESSION_NORMAL) {
+ if (!info.bIsReg)
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
- }
- else if (info->type == JABBER_SESSION_REGISTER) {
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Cannot connect to the server"));
- }
- mir_free(buffer);
- info->close();
+ else
+ SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Cannot connect to the server"));
+
+ info.close();
debugLogA("Thread ended, SSL connection failed");
goto LBL_FatalError;
} }
// User may change status to OFFLINE while we are connecting above
- if (m_iDesiredStatus != ID_STATUS_OFFLINE || info->type == JABBER_SESSION_REGISTER) {
-
- if (info->type == JABBER_SESSION_NORMAL) {
- size_t len = _tcslen(info->username) + strlen(info->server) + 1;
+ if (m_iDesiredStatus != ID_STATUS_OFFLINE || info.bIsReg) {
+ if (!info.bIsReg) {
+ size_t len = _tcslen(info.conn.username) + strlen(info.conn.server) + 1;
m_szJabberJID = (TCHAR*)mir_alloc(sizeof(TCHAR)*(len + 1));
- mir_sntprintf(m_szJabberJID, len + 1, _T("%s@%S"), info->username, info->server);
+ mir_sntprintf(m_szJabberJID, len + 1, _T("%s@%S"), info.conn.username, info.conn.server);
m_bSendKeepAlive = m_options.KeepAlive != 0;
setTString("jid", m_szJabberJID); // store jid in database
}
- xmlStreamInitializeNow(info);
+ xmlStreamInitializeNow(&info);
const TCHAR *tag = _T("stream:stream");
debugLogA("Entering main recv loop");
- datalen = 0;
+ int datalen = 0;
// cache values
DWORD dwConnectionKeepAliveInterval = m_options.ConnectionKeepAliveInterval;
for (;;) {
- if (!info->useZlib || info->zRecvReady) {
+ if (!info.useZlib || info.zRecvReady) {
DWORD dwIdle = GetTickCount() - m_lastTicks;
if (dwIdle >= dwConnectionKeepAliveInterval)
dwIdle = dwConnectionKeepAliveInterval - 10; // now!
@@ -439,7 +416,7 @@ LBL_FatalError:
NETLIBSELECT nls = { 0 };
nls.cbSize = sizeof(NETLIBSELECT);
nls.dwTimeout = dwConnectionKeepAliveInterval - dwIdle;
- nls.hReadConns[0] = info->s;
+ nls.hReadConns[0] = info.s;
int nSelRes = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls);
if (nSelRes == -1) // error
break;
@@ -447,43 +424,39 @@ LBL_FatalError:
if (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_PING) {
CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnPingReply, JABBER_IQ_TYPE_GET, NULL, 0, -1, this);
pInfo->SetTimeout(m_options.ConnectionKeepAliveTimeout);
- info->send(XmlNodeIq(pInfo) << XATTR(_T("from"), m_ThreadInfo->fullJID) << XCHILDNS(_T("ping"), JABBER_FEAT_PING));
+ info.send(XmlNodeIq(pInfo) << XATTR(_T("from"), m_ThreadInfo->fullJID) << XCHILDNS(_T("ping"), JABBER_FEAT_PING));
}
- else info->send(" \t ");
+ else info.send(" \t ");
continue;
} }
- int recvResult = info->recv(buffer + datalen, jabberNetworkBufferSize - datalen);
+ int recvResult = info.recv(info.buffer + datalen, jabberNetworkBufferSize - datalen);
debugLogA("recvResult = %d", recvResult);
if (recvResult <= 0)
break;
datalen += recvResult;
recvRest:
- buffer[datalen] = '\0';
+ info.buffer[datalen] = '\0';
- TCHAR *str;
- str = mir_utf8decodeW(buffer);
+ ptrT str(mir_utf8decodeW(info.buffer));
int bytesParsed = 0;
XmlNode root(str, &bytesParsed, tag);
if (root && tag) {
- char *p = strstr(buffer, "stream:stream");
+ char *p = strstr(info.buffer, "stream:stream");
if (p) p = strchr(p, '>');
if (p)
- bytesParsed = p - buffer + 1;
+ bytesParsed = p - info.buffer + 1;
else {
root = XmlNode();
bytesParsed = 0;
}
-
- mir_free(str);
-
}
else {
- if (root) str[bytesParsed] = 0;
+ if (root)
+ str[bytesParsed] = 0;
bytesParsed = (root) ? mir_utf8lenW(str) : 0;
- mir_free(str);
}
debugLogA("bytesParsed = %d", bytesParsed);
@@ -494,38 +467,38 @@ recvRest:
HXML n = xmlGetChild(root, i);
if (!n)
break;
- OnProcessProtocol(n, info);
+ OnProcessProtocol(n, &info);
}
}
- else OnProcessProtocol(root, info);
+ else OnProcessProtocol(root, &info);
if (bytesParsed > 0) {
if (bytesParsed < datalen)
- memmove(buffer, buffer + bytesParsed, datalen - bytesParsed);
+ memmove(info.buffer, info.buffer + bytesParsed, datalen - bytesParsed);
datalen -= bytesParsed;
}
else if (datalen >= jabberNetworkBufferSize) {
//jabberNetworkBufferSize += 65536;
jabberNetworkBufferSize *= 2;
debugLogA("Increasing network buffer size to %d", jabberNetworkBufferSize);
- if ((buffer = (char*)mir_realloc(buffer, jabberNetworkBufferSize + 1)) == NULL) {
+ if ((info.buffer = (char*)mir_realloc(info.buffer, jabberNetworkBufferSize + 1)) == NULL) {
debugLogA("Cannot reallocate more network buffer, go offline now");
break;
} }
else debugLogA("Unknown state: bytesParsed=%d, datalen=%d, jabberNetworkBufferSize=%d", bytesParsed, datalen, jabberNetworkBufferSize);
if (m_szXmlStreamToBeInitialized) {
- xmlStreamInitializeNow(info);
+ xmlStreamInitializeNow(&info);
tag = _T("stream:stream");
}
if (root && datalen)
goto recvRest;
}
- if (info->type == JABBER_SESSION_NORMAL) {
+ if (!info.bIsReg) {
m_iqManager.ExpireAll();
m_bJabberOnline = FALSE;
- info->zlibUninit();
+ info.zlibUninit();
EnableMenuItems(FALSE);
RebuildInfoFrame();
if (m_hwndJabberChangePassword) {
@@ -547,7 +520,7 @@ recvRest:
WindowNotify(WM_JABBER_CHECK_ONLINE);
// Set status to offline
- oldStatus = m_iStatus;
+ int oldStatus = m_iStatus;
m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
@@ -562,45 +535,36 @@ recvRest:
WindowNotify(WM_JABBER_REFRESH_VCARD);
}
- else if (info->type == JABBER_SESSION_REGISTER && !info->reg_done)
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Connection lost"));
+ else if (info.bIsReg && !info.reg_done)
+ SendMessage(info.conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Error: Connection lost"));
}
- else if (info->type == JABBER_SESSION_NORMAL) {
- oldStatus = m_iStatus;
+ else if (!info.bIsReg) {
+ int oldStatus = m_iStatus;
m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
}
- debugLogA("Thread ended: type=%d server='%s'", info->type, info->server);
+ debugLogA("Thread ended: type=%d server='%s'", info.bIsReg, info.conn.server);
- if (info->type == JABBER_SESSION_NORMAL && m_ThreadInfo == info) {
- mir_free(m_szStreamId);
- m_szStreamId = NULL;
- m_ThreadInfo = NULL;
- }
-
- info->close();
- mir_free(buffer);
+ info.close();
debugLogA("Exiting ServerThread");
- goto LBL_Exit;
}
-void CJabberProto::PerformRegistration(ThreadData* info)
+void CJabberProto::PerformRegistration(ThreadData *info)
{
iqIdRegGetReg = SerialNext();
info->send(XmlNodeIq(_T("get"), iqIdRegGetReg, NULL) << XQUERY(JABBER_FEAT_REGISTER));
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 50, (LPARAM)TranslateT("Requesting registration instruction..."));
+ SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 50, (LPARAM)TranslateT("Requesting registration instruction..."));
}
-void CJabberProto::PerformIqAuth(ThreadData* info)
+void CJabberProto::PerformIqAuth(ThreadData *info)
{
- if (info->type == JABBER_SESSION_NORMAL) {
+ if (!info->bIsReg) {
info->send(XmlNodeIq(AddIQ(&CJabberProto::OnIqResultGetAuth, JABBER_IQ_TYPE_GET))
- << XQUERY(_T("jabber:iq:auth")) << XCHILD(_T("username"), info->username));
+ << XQUERY(_T("jabber:iq:auth")) << XCHILD(_T("username"), info->conn.username));
}
- else if (info->type == JABBER_SESSION_REGISTER)
- PerformRegistration(info);
+ else PerformRegistration(info);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -610,13 +574,11 @@ void CJabberProto::OnProcessStreamOpening(HXML node, ThreadData *info)
if (lstrcmp(xmlGetName(node), _T("stream:stream")))
return;
- if (info->type == JABBER_SESSION_NORMAL) {
+ if (!info->bIsReg) {
const TCHAR *sid = xmlGetAttrValue(node, _T("id"));
- if (sid != NULL) {
- char* pszSid = mir_t2a(sid);
- replaceStr(info->proto->m_szStreamId, pszSid);
- mir_free(pszSid);
- } }
+ if (sid != NULL)
+ info->szStreamId = mir_t2a(sid);
+ }
// old server - disable SASL then
if (xmlGetAttrValue(node, _T("version")) == NULL)
@@ -626,7 +588,7 @@ void CJabberProto::OnProcessStreamOpening(HXML node, ThreadData *info)
info->proto->PerformIqAuth(info);
}
-void CJabberProto::PerformAuthentication(ThreadData* info)
+void CJabberProto::PerformAuthentication(ThreadData *info)
{
TJabberAuth* auth = NULL;
char* request = NULL;
@@ -694,7 +656,7 @@ void CJabberProto::PerformAuthentication(ThreadData* info)
}
TCHAR text[1024];
- mir_sntprintf(text, SIZEOF(text), TranslateT("Authentication failed for %s@%S."), info->username, info->server);
+ mir_sntprintf(text, SIZEOF(text), TranslateT("Authentication failed for %s@%S."), info->conn.username, info->conn.server);
MsgPopup(NULL, text, TranslateT("Jabber Authentication"));
JLoginFailed(LOGINERR_WRONGPASSWORD);
info->send("</stream:stream>");
@@ -712,7 +674,7 @@ void CJabberProto::PerformAuthentication(ThreadData* info)
/////////////////////////////////////////////////////////////////////////////////////////
-void CJabberProto::OnProcessFeatures(HXML node, ThreadData* info)
+void CJabberProto::OnProcessFeatures(HXML node, ThreadData *info)
{
bool isRegisterAvailable = false;
bool areMechanismsDefined = false;
@@ -723,7 +685,7 @@ void CJabberProto::OnProcessFeatures(HXML node, ThreadData* info)
break;
if (!_tcscmp(xmlGetName(n), _T("starttls"))) {
- if (!info->useSSL && m_options.UseTLS) {
+ if (!info->conn.useSSL && m_options.UseTLS) {
debugLogA("Requesting TLS");
info->send(XmlNode(xmlGetName(n)) << XATTR(_T("xmlns"), _T("urn:ietf:params:xml:ns:xmpp-tls")));
return;
@@ -784,12 +746,10 @@ void CJabberProto::OnProcessFeatures(HXML node, ThreadData* info)
}
if (areMechanismsDefined) {
- if (info->type == JABBER_SESSION_NORMAL)
- PerformAuthentication(info);
- else if (info->type == JABBER_SESSION_REGISTER)
+ if (info->bIsReg)
PerformRegistration(info);
else
- info->send("</stream:stream>");
+ PerformAuthentication(info);
return;
}
@@ -810,7 +770,7 @@ void CJabberProto::OnProcessFeatures(HXML node, ThreadData* info)
PerformIqAuth(info);
}
-void CJabberProto::OnProcessFailure(HXML node, ThreadData* info)
+void CJabberProto::OnProcessFailure(HXML node, ThreadData *info)
{
const TCHAR *type;
//failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"
@@ -820,7 +780,7 @@ void CJabberProto::OnProcessFailure(HXML node, ThreadData* info)
}
}
-void CJabberProto::OnProcessError(HXML node, ThreadData* info)
+void CJabberProto::OnProcessError(HXML node, ThreadData *info)
{
TCHAR *buff;
int i;
@@ -856,7 +816,7 @@ void CJabberProto::OnProcessError(HXML node, ThreadData* info)
info->send("</stream:stream>");
}
-void CJabberProto::OnProcessSuccess(HXML node, ThreadData* info)
+void CJabberProto::OnProcessSuccess(HXML node, ThreadData *info)
{
const TCHAR *type;
// int iqId;
@@ -874,14 +834,14 @@ void CJabberProto::OnProcessSuccess(HXML node, ThreadData* info)
debugLogA("Success: Logged-in.");
ptrT tszNick(getTStringA("Nick"));
if (tszNick == NULL)
- setTString("Nick", info->username);
+ setTString("Nick", info->conn.username);
xmlStreamInitialize("after successful sasl");
}
else debugLog(_T("Success: unknown action %s."), type);
}
-void CJabberProto::OnProcessChallenge(HXML node, ThreadData* info)
+void CJabberProto::OnProcessChallenge(HXML node, ThreadData *info)
{
if (info->auth == NULL) {
debugLogA("No previous auth have been made, exiting...");
@@ -896,7 +856,7 @@ void CJabberProto::OnProcessChallenge(HXML node, ThreadData* info)
mir_free(challenge);
}
-void CJabberProto::OnProcessProtocol(HXML node, ThreadData* info)
+void CJabberProto::OnProcessProtocol(HXML node, ThreadData *info)
{
OnConsoleProcessXml(node, JCPF_IN);
@@ -916,7 +876,7 @@ void CJabberProto::OnProcessProtocol(HXML node, ThreadData* info)
OnProcessError(node, info);
else if (!lstrcmp(xmlGetName(node), _T("challenge")))
OnProcessChallenge(node, info);
- else if (info->type == JABBER_SESSION_NORMAL) {
+ else if (!info->bIsReg) {
if (!lstrcmp(xmlGetName(node), _T("message")))
OnProcessMessage(node, info);
else if (!lstrcmp(xmlGetName(node), _T("presence")))
@@ -926,7 +886,7 @@ void CJabberProto::OnProcessProtocol(HXML node, ThreadData* info)
else
debugLogA("Invalid top-level tag (only <message/> <presence/> and <iq/> allowed)");
}
- else if (info->type == JABBER_SESSION_REGISTER) {
+ else {
if (!lstrcmp(xmlGetName(node), _T("iq")))
OnProcessRegIq(node, info);
else
@@ -934,7 +894,7 @@ void CJabberProto::OnProcessProtocol(HXML node, ThreadData* info)
}
}
-void CJabberProto::OnProcessProceed(HXML node, ThreadData* info)
+void CJabberProto::OnProcessProceed(HXML node, ThreadData *info)
{
const TCHAR *type;
if ((type = xmlGetAttrValue(node, _T("xmlns"))) != NULL && !lstrcmp(type, _T("error")))
@@ -943,13 +903,13 @@ void CJabberProto::OnProcessProceed(HXML node, ThreadData* info)
if (!lstrcmp(type, _T("urn:ietf:params:xml:ns:xmpp-tls"))) {
debugLogA("Starting TLS...");
- char* gtlk = strstr(info->manualHost, "google.com");
- bool isHosted = gtlk && !gtlk[10] && stricmp(info->server, "gmail.com") &&
- stricmp(info->server, "googlemail.com");
+ char* gtlk = strstr(info->conn.manualHost, "google.com");
+ bool isHosted = gtlk && !gtlk[10] && stricmp(info->conn.server, "gmail.com") &&
+ stricmp(info->conn.server, "googlemail.com");
NETLIBSSL ssl = { 0 };
ssl.cbSize = sizeof(ssl);
- ssl.host = isHosted ? info->manualHost : info->server;
+ ssl.host = isHosted ? info->conn.manualHost : info->conn.server;
if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)info->s, (LPARAM)&ssl)) {
debugLogA("SSL initialization failed");
info->send("</stream:stream>");
@@ -960,7 +920,7 @@ void CJabberProto::OnProcessProceed(HXML node, ThreadData* info)
}
}
-void CJabberProto::OnProcessCompressed(HXML node, ThreadData* info)
+void CJabberProto::OnProcessCompressed(HXML node, ThreadData *info)
{
debugLogA("Compression confirmed");
@@ -1065,7 +1025,7 @@ MCONTACT CJabberProto::CreateTemporaryContact(const TCHAR *szJid, JABBER_LIST_IT
return hContact;
}
-void CJabberProto::OnProcessMessage(HXML node, ThreadData* info)
+void CJabberProto::OnProcessMessage(HXML node, ThreadData *info)
{
HXML xNode, n;
@@ -1524,7 +1484,7 @@ void CJabberProto::UpdateJidDbSettings(const TCHAR *jid)
MenuUpdateSrmmIcon(item);
}
-void CJabberProto::OnProcessPresence(HXML node, ThreadData* info)
+void CJabberProto::OnProcessPresence(HXML node, ThreadData *info)
{
if (!node || !xmlGetName(node) || _tcscmp(xmlGetName(node), _T("presence")))
return;
@@ -1878,9 +1838,8 @@ void CJabberProto::OnProcessIq(HXML node)
}
}
-void CJabberProto::OnProcessRegIq(HXML node, ThreadData* info)
+void CJabberProto::OnProcessRegIq(HXML node, ThreadData *info)
{
- HXML errorNode;
const TCHAR *type;
if (!xmlGetName(node) || _tcscmp(xmlGetName(node), _T("iq"))) return;
@@ -1889,7 +1848,6 @@ void CJabberProto::OnProcessRegIq(HXML node, ThreadData* info)
int id = JabberGetPacketID(node);
if (!_tcscmp(type, _T("result"))) {
-
// RECVED: result of the request for registration mechanism
// ACTION: send account registration information
if (id == iqIdRegGetReg) {
@@ -1897,25 +1855,24 @@ void CJabberProto::OnProcessRegIq(HXML node, ThreadData* info)
XmlNodeIq iq(_T("set"), iqIdRegSetReg);
HXML query = iq << XQUERY(JABBER_FEAT_REGISTER);
- query << XCHILD(_T("password"), info->password);
- query << XCHILD(_T("username"), info->username);
+ query << XCHILD(_T("password"), info->conn.password);
+ query << XCHILD(_T("username"), info->conn.username);
info->send(iq);
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 75, (LPARAM)TranslateT("Sending registration information..."));
+ SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 75, (LPARAM)TranslateT("Sending registration information..."));
}
// RECVED: result of the registration process
// ACTION: account registration successful
else if (id == iqIdRegSetReg) {
info->send("</stream:stream>");
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Registration successful"));
+ SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Registration successful"));
info->reg_done = TRUE;
}
}
else if (!_tcscmp(type, _T("error"))) {
- errorNode = xmlGetChild(node, "error");
- TCHAR *str = JabberErrorMsg(errorNode);
- SendMessage(info->reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)str);
+ TCHAR *str = JabberErrorMsg(xmlGetChild(node, "error"));
+ SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)str);
mir_free(str);
info->reg_done = TRUE;
info->send("</stream:stream>");
@@ -1925,20 +1882,31 @@ void CJabberProto::OnProcessRegIq(HXML node, ThreadData* info)
/////////////////////////////////////////////////////////////////////////////////////////
// ThreadData constructor & destructor
-ThreadData::ThreadData(CJabberProto* aproto, JABBER_SESSION_TYPE parType)
+ThreadData::ThreadData(CJabberProto *_pro, JABBER_CONN_DATA *param)
{
memset(this, 0, sizeof(*this));
- type = parType;
- proto = aproto;
+
+ resolveID = -1;
+ proto = _pro;
iomutex = CreateMutex(NULL, FALSE, NULL);
+
+ if (param != NULL) {
+ bIsReg = true;
+ memcpy(&conn, param, sizeof(conn));
+ }
}
ThreadData::~ThreadData()
{
- if (auth) delete auth;
+ if (!bIsReg && proto->m_ThreadInfo == this)
+ proto->m_ThreadInfo = NULL;
+
+ delete auth;
+
mir_free(zRecvData);
+ mir_free(buffer);
+
CloseHandle(iomutex);
- CloseHandle(hThread);
}
void ThreadData::close(void)