diff options
Diffstat (limited to 'protocols/JabberG')
-rw-r--r-- | protocols/JabberG/src/jabber.h | 10 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_adhoc.cpp | 7 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_bookmarks.cpp | 6 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_byte.cpp | 6 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_captcha.cpp | 10 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_chat.cpp | 67 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_ft.cpp | 35 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_ibb.cpp | 10 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iq.h | 3 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iq_handlers.cpp | 6 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iqid.cpp | 12 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_privacy.h | 13 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_rc.h | 10 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_secur.cpp | 114 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_util.cpp | 134 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_vcard.cpp | 2 |
16 files changed, 134 insertions, 311 deletions
diff --git a/protocols/JabberG/src/jabber.h b/protocols/JabberG/src/jabber.h index 5085fa9807..b91a720edd 100644 --- a/protocols/JabberG/src/jabber.h +++ b/protocols/JabberG/src/jabber.h @@ -701,10 +701,8 @@ struct CJabberAdhocStartupParams }
~CJabberAdhocStartupParams()
{
- if (m_szJid)
- mir_free(m_szJid);
- if (m_szNode)
- mir_free(m_szNode);
+ mir_free(m_szJid);
+ mir_free(m_szNode);
}
};
@@ -753,9 +751,6 @@ int __stdcall JabberCombineStatus(int status1, int status2); TCHAR* __stdcall JabberErrorStr(int errorCode);
TCHAR* __stdcall JabberErrorMsg(HXML errorNode, int* errorCode = NULL);
void __stdcall JabberUtfToTchar(const char* str, size_t cbLen, LPTSTR& dest);
-char* __stdcall JabberBase64Encode(const char* buffer, int bufferLen);
-char* __stdcall JabberBase64Decode(const char* buffer, int *resultLen);
-char* __stdcall JabberBase64DecodeW(const WCHAR* buffer, int *resultLen);
time_t __stdcall JabberIsoToUnixTime(const TCHAR *stamp);
void __stdcall JabberStringAppend(char* *str, int *sizeAlloced, const char* fmt, ...);
TCHAR* __stdcall JabberStripJid(const TCHAR *jid, TCHAR* dest, size_t destLen);
@@ -768,7 +763,6 @@ TCHAR* time2str(time_t _time, TCHAR *buf, size_t bufLen); time_t str2time(const TCHAR*);
#define JabberUnixToDosT JabberUnixToDosW
-#define JabberBase64DecodeT JabberBase64DecodeW
const TCHAR *JabberStrIStr(const TCHAR *str, const TCHAR *substr);
void JabberCopyText(HWND hwnd, TCHAR *text);
diff --git a/protocols/JabberG/src/jabber_adhoc.cpp b/protocols/JabberG/src/jabber_adhoc.cpp index b28221f607..222a34e044 100644 --- a/protocols/JabberG/src/jabber_adhoc.cpp +++ b/protocols/JabberG/src/jabber_adhoc.cpp @@ -361,15 +361,12 @@ int CJabberProto::AdHoc_AddCommandRadio(HWND hFrame, TCHAR * labelStr, int id, i static INT_PTR CALLBACK JabberAdHoc_CommandDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
JabberAdHocData* dat = (JabberAdHocData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- switch (msg)
- {
+ switch (msg) {
case WM_INITDIALOG:
{
CJabberAdhocStartupParams* pStartupParams = (CJabberAdhocStartupParams *)lParam;
- dat=(JabberAdHocData *)mir_alloc(sizeof(JabberAdHocData));
- memset(dat,0,sizeof(JabberAdHocData));
+ dat=(JabberAdHocData *)mir_calloc(sizeof(JabberAdHocData));
- //hmmm, useless code? if (dat->ResponderJID) mir_free(dat->ResponderJID);
dat->ResponderJID = mir_tstrdup(pStartupParams->m_szJid);
dat->proto = pStartupParams->m_pProto;
diff --git a/protocols/JabberG/src/jabber_bookmarks.cpp b/protocols/JabberG/src/jabber_bookmarks.cpp index f7cb896d58..2c2a9807e9 100644 --- a/protocols/JabberG/src/jabber_bookmarks.cpp +++ b/protocols/JabberG/src/jabber_bookmarks.cpp @@ -362,11 +362,7 @@ void CJabberDlgBookmarks::OpenBookmark() }
}
}
- else {
- char *szUrl = mir_t2a(item->jid);
- CallService(MS_UTILS_OPENURL, 1, (LPARAM)szUrl);
- mir_free(szUrl);
- }
+ else CallService(MS_UTILS_OPENURL, OUF_TCHAR, (LPARAM)item->jid);
}
INT_PTR CJabberDlgBookmarks::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index c34bf5494f..16d9c835ac 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -457,8 +457,7 @@ void CJabberProto::ByteSendViaProxy(JABBER_BYTE_TRANSFER *jbt) szHost = jbt->szProxyHost;
port = (WORD)_ttoi(szPort);
- if (jbt->streamhostJID) mir_free(jbt->streamhostJID);
- jbt->streamhostJID = mir_tstrdup(jbt->szProxyJid);
+ replaceStrT(jbt->streamhostJID, jbt->szProxyJid);
NETLIBOPENCONNECTION nloc = { 0 };
nloc.cbSize = sizeof(nloc);
@@ -638,8 +637,7 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) (str = xmlGetAttrValue(n, _T("jid"))) != NULL) {
port = (WORD)_ttoi(szPort);
- if (jbt->streamhostJID) mir_free(jbt->streamhostJID);
- jbt->streamhostJID = mir_tstrdup(str);
+ replaceStrT(jbt->streamhostJID, str);
Log("bytestream_recv connecting to %S:%d", szHost, port);
NETLIBOPENCONNECTION nloc = { 0 };
diff --git a/protocols/JabberG/src/jabber_captcha.cpp b/protocols/JabberG/src/jabber_captcha.cpp index dcb9d8c3b6..ce4018ca66 100644 --- a/protocols/JabberG/src/jabber_captcha.cpp +++ b/protocols/JabberG/src/jabber_captcha.cpp @@ -111,9 +111,6 @@ INT_PTR CALLBACK JabberCaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info)
{
- CAPTCHA_FORM_PARAMS param;
- TCHAR *CaptchaPath = 0;
-
HXML x = xmlGetChildByTag(node, "x", "xmlns", JABBER_FEAT_DATA_FORMS);
if (x == NULL)
return false;
@@ -123,6 +120,8 @@ bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info) return false;
if ((y = xmlGetChild(y, "value")) == NULL)
return false;
+
+ CAPTCHA_FORM_PARAMS param;
param.fromjid = xmlGetText(y);
if ((y = xmlGetChildByTag(x, _T("field"), _T("var"), _T("sid"))) == NULL)
@@ -142,6 +141,7 @@ bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info) if (o == NULL || xmlGetText(o) == NULL)
return false;
+ TCHAR *CaptchaPath = 0;
GetCaptchaImage(parentNode, CaptchaPath);
param.bmp = (HBITMAP) CallService(MS_UTILS_LOADBITMAPT, 0, (LPARAM)CaptchaPath);
DeleteFile(CaptchaPath);
@@ -162,8 +162,8 @@ bool CJabberProto::ProcessCaptcha(HXML node, HXML parentNode, ThreadData* info) bool CJabberProto::GetCaptchaImage(HXML node, TCHAR*& CaptchaPath)
{
HXML o = xmlGetChild(node , "data");
- int bufferLen;
- char* buffer = JabberBase64DecodeT(xmlGetText(o), &bufferLen);
+ unsigned bufferLen;
+ ptrA buffer((char*)mir_base64_decode( _T2A(xmlGetText(o)), &bufferLen));
if (buffer == NULL)
return false;
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 84cae898da..5018d5f3be 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -1016,9 +1016,10 @@ static INT_PTR CALLBACK sttUserInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam g_ReleaseIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_BTN_AFFILIATION, BM_SETIMAGE, IMAGE_ICON, 0));
g_ReleaseIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_BTN_ROLE, BM_SETIMAGE, IMAGE_ICON, 0));
TUserInfoData *dat = (TUserInfoData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- if ( !dat)break;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
- mir_free(dat);
+ if (dat) {
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
+ mir_free(dat);
+ }
break;
}
return FALSE;
@@ -1026,13 +1027,9 @@ static INT_PTR CALLBACK sttUserInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* gch)
{
- JABBER_RESOURCE_STATUS *me = NULL, *him = NULL;
- for (int i=0; i < item->resourceCount; i++) {
- JABBER_RESOURCE_STATUS& p = item->pResources[i];
- if ( !lstrcmp(p.resourceName, item->nick )) me = &p;
- if ( !lstrcmp(p.resourceName, gch->ptszUID)) him = &p;
- }
-
+ JABBER_RESOURCE_STATUS
+ *me = item->findResource(item->nick),
+ *him = item->findResource(gch->ptszUID);
if (him == NULL || me == NULL)
return;
@@ -1043,8 +1040,7 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* TCHAR szBuffer[1024];
TCHAR szTitle[256];
- if ((gch->dwData >= CLISTMENUIDMIN) && (gch->dwData <= CLISTMENUIDMAX))
- {
+ if ((gch->dwData >= CLISTMENUIDMIN) && (gch->dwData <= CLISTMENUIDMAX)) {
if (him->szRealJid && *him->szRealJid)
if (HANDLE hContact = ppro->HContactFromJID(him->szRealJid))
CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(gch->dwData, MPCF_CONTACTMENU), (LPARAM)hContact);
@@ -1053,7 +1049,6 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* switch(gch->dwData) {
case IDM_SLAP:
- {
if (ppro->m_bJabberOnline) {
DBVARIANT dbv = {0};
TCHAR *szMessage = ppro->getTString("GcMsgSlap", &dbv) ?
@@ -1076,36 +1071,35 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* db_free(&dbv);
}
break;
- }
+
case IDM_VCARD:
- {
- HANDLE hContact;
- JABBER_SEARCH_RESULT jsr = {0};
- mir_sntprintf(jsr.jid, SIZEOF(jsr.jid), _T("%s/%s"), item->jid, him->resourceName);
- jsr.hdr.cbSize = sizeof(JABBER_SEARCH_RESULT);
+ {
+ JABBER_SEARCH_RESULT jsr = {0};
+ mir_sntprintf(jsr.jid, SIZEOF(jsr.jid), _T("%s/%s"), item->jid, him->resourceName);
+ jsr.hdr.cbSize = sizeof(JABBER_SEARCH_RESULT);
- JABBER_LIST_ITEM *item = ppro->ListAdd(LIST_VCARD_TEMP, jsr.jid);
- ppro->ListAddResource(LIST_VCARD_TEMP, jsr.jid, him->status, him->statusMessage, him->priority);
+ JABBER_LIST_ITEM *item = ppro->ListAdd(LIST_VCARD_TEMP, jsr.jid);
+ ppro->ListAddResource(LIST_VCARD_TEMP, jsr.jid, him->status, him->statusMessage, him->priority);
- hContact = (HANDLE)CallProtoService(ppro->m_szModuleName, PS_ADDTOLIST, PALF_TEMPORARY, (LPARAM)&jsr);
- CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0);
+ HANDLE hContact = (HANDLE)CallProtoService(ppro->m_szModuleName, PS_ADDTOLIST, PALF_TEMPORARY, (LPARAM)&jsr);
+ CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0);
+ }
break;
- }
+
case IDM_INFO:
- {
- TUserInfoData *dat = (TUserInfoData *)mir_alloc(sizeof(TUserInfoData));
- dat->me = me;
- dat->him = him;
- dat->item = item;
- dat->ppro = ppro;
- HWND hwndInfo = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_GROUPCHAT_INFO), NULL, sttUserInfoDlgProc, (LPARAM)dat);
- ShowWindow(hwndInfo, SW_SHOW);
+ {
+ TUserInfoData *dat = (TUserInfoData *)mir_alloc(sizeof(TUserInfoData));
+ dat->me = me;
+ dat->him = him;
+ dat->item = item;
+ dat->ppro = ppro;
+ HWND hwndInfo = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_GROUPCHAT_INFO), NULL, sttUserInfoDlgProc, (LPARAM)dat);
+ ShowWindow(hwndInfo, SW_SHOW);
+ }
break;
- }
+
case IDM_KICK:
- {
- if ((GetTickCount() - dwLastBanKickTime) > BAN_KICK_INTERVAL)
- {
+ if ((GetTickCount() - dwLastBanKickTime) > BAN_KICK_INTERVAL) {
dwLastBanKickTime = GetTickCount();
mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s: "), me->resourceName);
mir_sntprintf(szTitle, SIZEOF(szTitle), _T("%s %s"), TranslateT("Reason to kick"), him->resourceName);
@@ -1120,7 +1114,6 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* }
dwLastBanKickTime = GetTickCount();
break;
- }
case IDM_SET_VISITOR:
if (him->role != ROLE_VISITOR)
diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp index 23778a4a88..d94d944caf 100644 --- a/protocols/JabberG/src/jabber_ft.cpp +++ b/protocols/JabberG/src/jabber_ft.cpp @@ -94,7 +94,7 @@ void CJabberProto::FtInitiate(TCHAR* jid, filetransfer *ft) sid[8] = '\0';
if (ft->sid != NULL) mir_free(ft->sid);
ft->sid = mir_tstrdup(sid);
- filename = ft->std.ptszFiles[ ft->std.currentFileNumber ];
+ filename = ft->std.ptszFiles[ft->std.currentFileNumber];
if ((p = _tcsrchr(filename, '\\')) != NULL)
filename = p+1;
@@ -105,7 +105,7 @@ void CJabberProto::FtInitiate(TCHAR* jid, filetransfer *ft) HXML si = iq << XCHILDNS(_T("si"), JABBER_FEAT_SI) << XATTR(_T("id"), sid)
<< XATTR(_T("mime-type"), _T("binary/octet-stream")) << XATTR(_T("profile"), JABBER_FEAT_SI_FT);
si << XCHILDNS(_T("file"), JABBER_FEAT_SI_FT) << XATTR(_T("name"), filename)
- << XATTRI64(_T("size"), ft->fileSize[ ft->std.currentFileNumber ]) << XCHILD(_T("desc"), ft->szDescription);
+ << XATTRI64(_T("size"), ft->fileSize[ft->std.currentFileNumber]) << XCHILD(_T("desc"), ft->szDescription);
HXML field = si << XCHILDNS(_T("feature"), JABBER_FEAT_FEATURE_NEG)
<< XCHILDNS(_T("x"), JABBER_FEAT_DATA_FORMS) << XATTR(_T("type"), _T("form"))
@@ -179,9 +179,9 @@ BOOL CJabberProto::FtSend(HANDLE hConn, filetransfer *ft) char* buffer;
int numRead;
- Log("Sending [%s]", ft->std.ptszFiles[ ft->std.currentFileNumber ]);
- _tstati64(ft->std.ptszFiles[ ft->std.currentFileNumber ], &statbuf); // file size in statbuf.st_size
- if ((fd = _topen(ft->std.ptszFiles[ ft->std.currentFileNumber ], _O_BINARY|_O_RDONLY)) < 0) {
+ Log("Sending [%s]", ft->std.ptszFiles[ft->std.currentFileNumber]);
+ _tstati64(ft->std.ptszFiles[ft->std.currentFileNumber], &statbuf); // file size in statbuf.st_size
+ if ((fd = _topen(ft->std.ptszFiles[ft->std.currentFileNumber], _O_BINARY|_O_RDONLY)) < 0) {
Log("File cannot be opened");
return FALSE;
}
@@ -209,14 +209,13 @@ BOOL CJabberProto::FtSend(HANDLE hConn, filetransfer *ft) BOOL CJabberProto::FtIbbSend(int blocksize, filetransfer *ft)
{
- struct _stati64 statbuf;
- int fd;
- char* buffer;
- int numRead;
+ Log("Sending [%s]", ft->std.ptszFiles[ft->std.currentFileNumber]);
- Log("Sending [%s]", ft->std.ptszFiles[ ft->std.currentFileNumber ]);
- _tstati64(ft->std.ptszFiles[ ft->std.currentFileNumber ], &statbuf); // file size in statbuf.st_size
- if ((fd = _topen(ft->std.ptszFiles[ ft->std.currentFileNumber ], _O_BINARY|_O_RDONLY)) < 0) {
+ struct _stati64 statbuf;
+ _tstati64(ft->std.ptszFiles[ft->std.currentFileNumber], &statbuf); // file size in statbuf.st_size
+
+ int fd = _topen(ft->std.ptszFiles[ft->std.currentFileNumber], _O_BINARY|_O_RDONLY);
+ if (fd < 0) {
Log("File cannot be opened");
return FALSE;
}
@@ -225,8 +224,10 @@ BOOL CJabberProto::FtIbbSend(int blocksize, filetransfer *ft) ft->std.currentFileSize = statbuf.st_size;
ft->std.currentFileProgress = 0;
- if ((buffer=(char*)mir_alloc(blocksize)) != NULL) {
- while ((numRead=_read(fd, buffer, blocksize)) > 0) {
+ ptrA buffer((char*)mir_alloc(blocksize));
+ if (buffer != NULL) {
+ int numRead;
+ while ((numRead = _read(fd, buffer, blocksize)) > 0) {
int iqId = SerialNext();
XmlNode msg(_T("message"));
xmlAddAttr(msg, _T("to"), ft->jibb->dstJID);
@@ -235,7 +236,7 @@ BOOL CJabberProto::FtIbbSend(int blocksize, filetransfer *ft) // let others send data too
Sleep(2);
- char *encoded = JabberBase64Encode(buffer, numRead);
+ char *encoded = mir_base64_encode((PBYTE)(char*)buffer, numRead);
msg << XCHILD(_T("data"), _A2T(encoded)) << XATTR(_T("xmlns"), JABBER_FEAT_IBB)
<< XATTR(_T("sid"), ft->jibb->sid) << XATTRI(_T("seq"), ft->jibb->wPacketId);
@@ -251,7 +252,6 @@ BOOL CJabberProto::FtIbbSend(int blocksize, filetransfer *ft) if (ft->jibb->state == JIBB_ERROR || ft->jibb->bStreamClosed || m_ThreadInfo->send(msg) == SOCKET_ERROR) {
Log("JabberFtIbbSend unsuccessful exit");
- mir_free(buffer);
_close(fd);
return FALSE;
}
@@ -262,7 +262,6 @@ BOOL CJabberProto::FtIbbSend(int blocksize, filetransfer *ft) ft->std.totalProgress += numRead;
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&ft->std);
}
- mir_free(buffer);
}
_close(fd);
return TRUE;
@@ -277,7 +276,7 @@ void CJabberProto::FtSendFinal(BOOL success, filetransfer *ft) else {
if (ft->std.currentFileNumber < ft->std.totalFiles-1) {
ft->std.currentFileNumber++;
- replaceStrT(ft->std.tszCurrentFile, ft->std.ptszFiles[ ft->std.currentFileNumber ]);
+ replaceStrT(ft->std.tszCurrentFile, ft->std.ptszFiles[ft->std.currentFileNumber]);
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0);
FtInitiate(ft->jid, ft);
return;
diff --git a/protocols/JabberG/src/jabber_ibb.cpp b/protocols/JabberG/src/jabber_ibb.cpp index a6cf22333b..55f3ba1851 100644 --- a/protocols/JabberG/src/jabber_ibb.cpp +++ b/protocols/JabberG/src/jabber_ibb.cpp @@ -179,16 +179,12 @@ BOOL CJabberProto::OnIbbRecvdData(const TCHAR *data, const TCHAR *sid, const TCH item->jibb->wPacketId++;
- int length = 0;
- char *decodedData = JabberBase64DecodeT(data, &length);
- if ( !decodedData)
+ unsigned length;
+ ptrA decodedData((char*)mir_base64_decode( _T2A(data), &length));
+ if (decodedData == NULL)
return FALSE;
(this->*item->jibb->pfnRecv)(NULL, item->ft, decodedData, length);
-
item->jibb->dwTransferredSize += (DWORD)length;
-
- mir_free(decodedData);
-
return TRUE;
}
diff --git a/protocols/JabberG/src/jabber_iq.h b/protocols/JabberG/src/jabber_iq.h index 9cd3937d0a..0042a9a006 100644 --- a/protocols/JabberG/src/jabber_iq.h +++ b/protocols/JabberG/src/jabber_iq.h @@ -104,8 +104,7 @@ public: }
~CJabberIqInfo()
{
- if (m_szReceiver)
- mir_free(m_szReceiver);
+ mir_free(m_szReceiver);
}
void SetReceiver(const TCHAR *szReceiver)
{
diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index 6c88eb0e4b..dfacdd5bba 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -492,7 +492,7 @@ BOOL CJabberProto::OnIqRequestAvatar(HXML, CJabberIqInfo *pInfo) return TRUE;
long bytes = _filelength(_fileno(in));
- char* buffer = (char*)mir_alloc(bytes*4/3 + bytes + 1000);
+ ptrA buffer((char*)mir_alloc(bytes*4/3 + bytes + 1000));
if (buffer == NULL) {
fclose(in);
return TRUE;
@@ -501,10 +501,8 @@ BOOL CJabberProto::OnIqRequestAvatar(HXML, CJabberIqInfo *pInfo) fread(buffer, bytes, 1, in);
fclose(in);
- char* str = JabberBase64Encode(buffer, bytes);
+ ptrA str( mir_base64_encode((PBYTE)(char*)buffer, bytes));
m_ThreadInfo->send( XmlNodeIq(_T("result"), pInfo) << XQUERY(JABBER_FEAT_AVATAR) << XCHILD(_T("query"), _A2T(str)) << XATTR(_T("mimetype"), szMimeType));
- mir_free(str);
- mir_free(buffer);
return TRUE;
}
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 6bd2a40761..b45bdfe821 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -614,11 +614,12 @@ void CJabberProto::OnIqResultGetVcardPhoto(const TCHAR *jid, HXML n, HANDLE hCon return;
HXML o = xmlGetChild(n, "BINVAL");
- if (o == NULL || xmlGetText(o) == NULL)
+ LPCTSTR ptszBinval = xmlGetText(o);
+ if (o == NULL || ptszBinval == NULL)
return;
- int bufferLen;
- ptrA buffer( JabberBase64DecodeT(xmlGetText(o), &bufferLen));
+ unsigned bufferLen;
+ ptrA buffer((char*)mir_base64_decode( _T2A(ptszBinval), &bufferLen));
if (buffer == NULL)
return;
@@ -1442,8 +1443,8 @@ void CJabberProto::OnIqResultGetServerAvatar(HXML iqNode) void CJabberProto::OnIqResultGotAvatar(HANDLE hContact, HXML n, const TCHAR *mimeType)
{
- int resultLen = 0;
- ptrA body( JabberBase64DecodeT( xmlGetText(n), &resultLen));
+ unsigned resultLen;
+ ptrA body((char*)mir_base64_decode( _T2A(xmlGetText(n)), &resultLen));
int pictureType;
if (mimeType != NULL) {
@@ -1454,7 +1455,6 @@ void CJabberProto::OnIqResultGotAvatar(HANDLE hContact, HXML n, const TCHAR *mim else {
LBL_ErrFormat:
Log("Invalid mime type specified for picture: %S", mimeType);
- mir_free(body);
return;
} }
else if ((pictureType = JabberGetPictureType(body)) == PA_FORMAT_UNKNOWN)
diff --git a/protocols/JabberG/src/jabber_privacy.h b/protocols/JabberG/src/jabber_privacy.h index aafc779bc9..ef29ce53d2 100644 --- a/protocols/JabberG/src/jabber_privacy.h +++ b/protocols/JabberG/src/jabber_privacy.h @@ -69,9 +69,7 @@ public: };
~CPrivacyListRule()
{
- if (m_szValue)
- mir_free(m_szValue);
-
+ mir_free(m_szValue);
if (m_pNext)
delete m_pNext;
};
@@ -166,8 +164,7 @@ public: };
~CPrivacyList()
{
- if (m_szListName)
- mir_free(m_szListName);
+ mir_free(m_szListName);
RemoveAllRules();
if (m_pNext)
delete m_pNext;
@@ -341,10 +338,8 @@ public: };
~CPrivacyListManager()
{
- if (m_szActiveListName)
- mir_free(m_szActiveListName);
- if (m_szDefaultListName)
- mir_free(m_szDefaultListName);
+ mir_free(m_szActiveListName);
+ mir_free(m_szDefaultListName);
RemoveAllLists();
DeleteCriticalSection(&m_cs);
};
diff --git a/protocols/JabberG/src/jabber_rc.h b/protocols/JabberG/src/jabber_rc.h index 9660b36834..fae38a0bf0 100644 --- a/protocols/JabberG/src/jabber_rc.h +++ b/protocols/JabberG/src/jabber_rc.h @@ -119,12 +119,10 @@ public: }
~CJabberAdhocNode()
{
- if (m_szJid)
- mir_free(m_szJid);
- if (m_szNode)
- mir_free(m_szNode);
- if (m_szName)
- mir_free(m_szName);
+ mir_free(m_szJid);
+ mir_free(m_szNode);
+ mir_free(m_szName);
+
if (m_pNext)
delete m_pNext;
}
diff --git a/protocols/JabberG/src/jabber_secur.cpp b/protocols/JabberG/src/jabber_secur.cpp index 5cc728a360..251e875fd3 100644 --- a/protocols/JabberG/src/jabber_secur.cpp +++ b/protocols/JabberG/src/jabber_secur.cpp @@ -166,8 +166,8 @@ char* TMD5Auth::getChallenge(const TCHAR *challenge) iCallCount++;
- int resultLen;
- char* text = JabberBase64DecodeT(challenge, &resultLen);
+ unsigned resultLen;
+ ptrA text((char*)mir_base64_decode( _T2A(challenge), &resultLen));
TStringPairs pairs(text);
const char *realm = pairs["realm"], *nonce = pairs["nonce"];
@@ -179,29 +179,29 @@ char* TMD5Auth::getChallenge(const TCHAR *challenge) CallService(MS_UTILS_GETRANDOM, sizeof(digest), (LPARAM)digest);
sprintf(cnonce, "%08x%08x%08x%08x", htonl(digest[0]), htonl(digest[1]), htonl(digest[2]), htonl(digest[3]));
- char *uname = mir_utf8encodeT(info->username),
- *passw = mir_utf8encodeT(info->password),
- *serv = mir_utf8encode(info->server);
+ ptrA uname( mir_utf8encodeT(info->username)),
+ passw( mir_utf8encodeT(info->password)),
+ serv( mir_utf8encode(info->server));
mir_md5_init(&ctx);
- mir_md5_append(&ctx, (BYTE*)uname, (int)strlen(uname));
- mir_md5_append(&ctx, (BYTE*)":", 1);
- mir_md5_append(&ctx, (BYTE*)realm, (int)strlen(realm));
- mir_md5_append(&ctx, (BYTE*)":", 1);
- mir_md5_append(&ctx, (BYTE*)passw, (int)strlen(passw));
+ mir_md5_append(&ctx, (BYTE*)(char*)uname, (int)strlen(uname));
+ mir_md5_append(&ctx, (BYTE*)":", 1);
+ mir_md5_append(&ctx, (BYTE*)realm, (int)strlen(realm));
+ mir_md5_append(&ctx, (BYTE*)":", 1);
+ mir_md5_append(&ctx, (BYTE*)(char*)passw, (int)strlen(passw));
mir_md5_finish(&ctx, (BYTE*)hash1);
mir_md5_init(&ctx);
- mir_md5_append(&ctx, (BYTE*)hash1, 16);
- mir_md5_append(&ctx, (BYTE*)":", 1);
+ mir_md5_append(&ctx, (BYTE*)hash1, 16);
+ mir_md5_append(&ctx, (BYTE*)":", 1);
mir_md5_append(&ctx, (BYTE*)nonce, (int)strlen(nonce));
- mir_md5_append(&ctx, (BYTE*)":", 1);
+ mir_md5_append(&ctx, (BYTE*)":", 1);
mir_md5_append(&ctx, (BYTE*)cnonce, (int)strlen(cnonce));
mir_md5_finish(&ctx, (BYTE*)hash1);
mir_md5_init(&ctx);
mir_md5_append(&ctx, (BYTE*)"AUTHENTICATE:xmpp/", 18);
- mir_md5_append(&ctx, (BYTE*)serv, (int)strlen(serv));
+ mir_md5_append(&ctx, (BYTE*)(char*)serv, (int)strlen(serv));
mir_md5_finish(&ctx, (BYTE*)hash2);
mir_md5_init(&ctx);
@@ -217,19 +217,14 @@ char* TMD5Auth::getChallenge(const TCHAR *challenge) mir_md5_append(&ctx, (BYTE*)tmpBuf, (int)strlen(tmpBuf));
mir_md5_finish(&ctx, (BYTE*)digest);
- char* buf = (char*)alloca(8000);
+ char *buf = (char*)alloca(8000);
int cbLen = mir_snprintf(buf, 8000,
"username=\"%s\",realm=\"%s\",nonce=\"%s\",cnonce=\"%s\",nc=%08d,"
"qop=auth,digest-uri=\"xmpp/%s\",charset=utf-8,response=%08x%08x%08x%08x",
uname, realm, nonce, cnonce, iCallCount, serv,
htonl(digest[0]), htonl(digest[1]), htonl(digest[2]), htonl(digest[3]));
- mir_free(uname);
- mir_free(passw);
- mir_free(serv);
- mir_free(text);
-
- return JabberBase64Encode(buf, cbLen);
+ return mir_base64_encode((PBYTE)buf, cbLen);
}
@@ -307,44 +302,46 @@ void TScramAuth::Hi(mir_sha1_byte_t* res , char* passw, size_t passwLen, char* s char* TScramAuth::getChallenge(const TCHAR *challenge)
{
- int chlLen;
- char *chl = JabberBase64DecodeT(challenge, &chlLen);
+ unsigned chlLen;
+ ptrA chl((char*)mir_base64_decode( _T2A(challenge), &chlLen));
+
+ char *r = strstr(chl, "r=");
+ if ( !r)
+ return NULL;
- char *r = strstr(chl, "r="); if ( !r) { mir_free(chl); return NULL; }
char *e = strchr(r, ','); if (e) *e = 0;
- char *snonce = mir_strdup(r + 2);
+ ptrA snonce( mir_strdup(r + 2));
if (e) *e = ',';
size_t cnlen = strlen(cnonce);
- if (strncmp(cnonce, snonce, cnlen)) { mir_free(chl); mir_free(snonce); return NULL; }
+ if (strncmp(cnonce, snonce, cnlen))
+ return NULL;
- char *s = strstr(chl, "s="); if ( !s) { mir_free(chl); mir_free(snonce); return NULL; }
+ char *s = strstr(chl, "s=");
+ if (!s)
+ return NULL;
e = strchr(s, ','); if (e) *e = 0;
- int saltLen;
- char *salt = JabberBase64Decode(s + 2, &saltLen);
+
+ unsigned saltLen;
+ ptrA salt((char*)mir_base64_decode(s + 2, &saltLen));
if (e) *e = ',';
+ if (saltLen > 16)
+ return NULL;
- if (saltLen > 16) {
- mir_free(salt);
- mir_free(snonce);
- mir_free(chl);
+ char *in = strstr(chl, "i=");
+ if (!in)
return NULL;
- }
- char *in = strstr(chl, "i="); if ( !in) return NULL;
e = strchr(in, ','); if (e) *e = 0;
int ind = atoi(in + 2);
if (e) *e = ',';
- char *passw = mir_utf8encodeT(info->password);
+ ptrA passw( mir_utf8encodeT(info->password));
size_t passwLen = strlen(passw);
mir_sha1_byte_t saltedPassw[ MIR_SHA1_HASH_SIZE ];
Hi(saltedPassw, passw, passwLen, salt, saltLen, ind);
- mir_free(salt);
- mir_free(passw);
-
mir_sha1_byte_t clientKey[ MIR_SHA1_HASH_SIZE ];
hmac_sha1(clientKey, saltedPassw, sizeof(saltedPassw), (mir_sha1_byte_t*)"Client Key", 10);
@@ -371,46 +368,33 @@ char* TScramAuth::getChallenge(const TCHAR *challenge) mir_sha1_byte_t srvSig[ MIR_SHA1_HASH_SIZE ];
hmac_sha1(srvSig, serverKey, sizeof(serverKey), (mir_sha1_byte_t*)authmsg, authmsgLen);
- serverSignature = JabberBase64Encode((char*)srvSig, sizeof(srvSig));
+ serverSignature = mir_base64_encode((PBYTE)srvSig, sizeof(srvSig));
char buf[4096];
- char *encproof = JabberBase64Encode((char*)clientProof, sizeof(clientProof));
+ ptrA encproof( mir_base64_encode((PBYTE)clientProof, sizeof(clientProof)));
int cbLen = mir_snprintf(buf, sizeof(buf), "c=biws,r=%s,p=%s", snonce, encproof);
-
- mir_free(encproof);
- mir_free(snonce);
- mir_free(chl);
-
- return JabberBase64Encode(buf, cbLen);
+ return mir_base64_encode((PBYTE)buf, cbLen);
}
char* TScramAuth::getInitialRequest()
{
- char *uname = mir_utf8encodeT(info->username),
- *serv = mir_utf8encode(info->server);
+ ptrA uname( mir_utf8encodeT(info->username)), serv( mir_utf8encode(info->server));
unsigned char nonce[24];
CallService(MS_UTILS_GETRANDOM, sizeof(nonce), (LPARAM)nonce);
- cnonce = JabberBase64Encode((char*)nonce, sizeof(nonce));
+ cnonce = mir_base64_encode((PBYTE)nonce, sizeof(nonce));
char buf[4096];
int cbLen = mir_snprintf(buf, sizeof(buf), "n,,n=%s@%s,r=%s", uname, serv, cnonce);
msg1 = mir_strdup(buf + 3);
-
- mir_free(serv);
- mir_free(uname);
-
- return JabberBase64Encode(buf, cbLen);
+ return mir_base64_encode((PBYTE)buf, cbLen);
}
bool TScramAuth::validateLogin(const TCHAR *challenge)
{
- int chlLen;
- char* chl = JabberBase64DecodeT(challenge, &chlLen);
- bool res = chl && strncmp(chl + 2, serverSignature, chlLen - 2) == 0;
- mir_free(chl);
-
- return res;
+ unsigned chlLen;
+ ptrA chl((char*)mir_base64_decode( _T2A(challenge), &chlLen));
+ return chl && strncmp((char*)chl + 2, serverSignature, chlLen - 2) == 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -429,8 +413,7 @@ TPlainAuth::~TPlainAuth() char* TPlainAuth::getInitialRequest()
{
- char *uname = mir_utf8encodeT(info->username),
- *passw = mir_utf8encodeT(info->password);
+ ptrA uname( mir_utf8encodeT(info->username)), passw( mir_utf8encodeT(info->password));
size_t size = 2 * strlen(uname) + strlen(passw) + strlen(info->server) + 4;
char *toEncode = (char*)alloca(size);
@@ -439,10 +422,7 @@ char* TPlainAuth::getInitialRequest() else
size = mir_snprintf(toEncode, size, "%c%s%c%s", 0, uname, 0, passw);
- mir_free(uname);
- mir_free(passw);
-
- return JabberBase64Encode(toEncode, (int)size);
+ return mir_base64_encode((PBYTE)toEncode, (int)size);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 9814cd302c..2abab23957 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -93,7 +93,7 @@ HANDLE CJabberProto::ChatRoomHContactFromJID(const TCHAR *jid) HANDLE CJabberProto::HContactFromJID(const TCHAR *jid , BOOL bStripResource)
{
if (jid == NULL)
- return (HANDLE)NULL;
+ return NULL;
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_CHATROOM, jid);
@@ -330,32 +330,27 @@ void __stdcall JabberUtfToTchar(const char* pszValue, size_t cbLen, LPTSTR& dest JabberUrlDecode(pszCopy);
-
mir_utf8decode(pszCopy, &dest);
-
if (bNeedsFree)
free(pszCopy);
}
char* __stdcall JabberSha1(char* str)
{
- mir_sha1_ctx sha;
- mir_sha1_byte_t digest[20];
- char* result;
- int i;
-
if (str == NULL)
return NULL;
+ mir_sha1_byte_t digest[20];
+ mir_sha1_ctx sha;
mir_sha1_init(&sha);
mir_sha1_append(&sha, (mir_sha1_byte_t*)str, (int)strlen(str));
mir_sha1_finish(&sha, digest);
- if ((result=(char*)mir_alloc(41)) == NULL)
- return NULL;
- for (i=0; i<20; i++)
- sprintf(result+(i<<1), "%02x", digest[i]);
+ char *result = (char*)mir_alloc(41);
+ if (result)
+ for (int i=0; i < 20; i++)
+ sprintf(result+(i<<1), "%02x", digest[i]);
return result;
}
@@ -601,121 +596,6 @@ void CJabberProto::SendVisibleInvisiblePresence(BOOL invisible) SendPresenceTo(m_iStatus, item->jid, NULL);
} }
-/////////////////////////////////////////////////////////////////////////////////////////
-// JabberBase64Encode
-
-static char b64table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-char* __stdcall JabberBase64Encode(const char* buffer, int bufferLen)
-{
- if (buffer == NULL || bufferLen<=0)
- return NULL;
-
- char* res = (char*)mir_alloc((((bufferLen+2)*4)/3) + 1);
- if (res == NULL)
- return NULL;
-
- unsigned char igroup[3];
- char *r = res;
- const char* peob = buffer + bufferLen;
- for (const char* p = buffer; p < peob;) {
- igroup[ 0 ] = igroup[ 1 ] = igroup[ 2 ] = 0;
- int n;
- for (n=0; n<3; n++) {
- if (p >= peob) break;
- igroup[n] = (unsigned char) *p;
- p++;
- }
-
- if (n > 0) {
- r[0] = b64table[ igroup[0]>>2 ];
- r[1] = b64table[ ((igroup[0]&3)<<4) | (igroup[1]>>4) ];
- r[2] = b64table[ ((igroup[1]&0xf)<<2) | (igroup[2]>>6) ];
- r[3] = b64table[ igroup[2]&0x3f ];
-
- if (n < 3) {
- r[3] = '=';
- if (n < 2)
- r[2] = '=';
- }
- r += 4;
- } }
-
- *r = '\0';
-
- return res;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// JabberBase64Decode
-
-static unsigned char b64rtable[256];
-
-char* __stdcall JabberBase64DecodeW(const WCHAR* str, int *resultLen)
-{
- char *stra = mir_u2a(str);
- char *res = JabberBase64Decode(stra, resultLen);
- mir_free(stra);
- return res;
-}
-
-char* __stdcall JabberBase64Decode(const char* str, int *resultLen)
-{
- char* res;
- unsigned char* r, igroup[4], a[4];
- int n, num, count;
-
- if (str == NULL || resultLen == NULL) return NULL;
- if ((res=(char*)mir_alloc(((strlen(str)+3)/4)*3)) == NULL) return NULL;
-
- for (n=0; n<256; n++)
- b64rtable[n] = (unsigned char) 0x80;
- for (n=0; n<26; n++)
- b64rtable['A'+n] = n;
- for (n=0; n<26; n++)
- b64rtable['a'+n] = n + 26;
- for (n=0; n<10; n++)
- b64rtable['0'+n] = n + 52;
- b64rtable['+'] = 62;
- b64rtable['/'] = 63;
- b64rtable['='] = 0;
- count = 0;
- for (r=(unsigned char*)res; *str != '\0';) {
- for (n=0; n<4; n++) {
- if (BYTE(*str) == '\r' || BYTE(*str) == '\n') {
- n--; str++;
- continue;
- }
-
- if (BYTE(*str)=='\0') {
- if (n == 0)
- goto LBL_Exit;
- mir_free(res);
- return NULL;
- }
-
- if (b64rtable[BYTE(*str)]==0x80) {
- mir_free(res);
- return NULL;
- }
-
- a[n] = BYTE(*str);
- igroup[n] = b64rtable[BYTE(*str)];
- str++;
- }
- r[0] = igroup[0]<<2 | igroup[1]>>4;
- r[1] = igroup[1]<<4 | igroup[2]>>2;
- r[2] = igroup[2]<<6 | igroup[3];
- r += 3;
- num = (a[2]=='='?1:(a[3]=='='?2:3));
- count += num;
- if (num < 3) break;
- }
-LBL_Exit:
- *resultLen = count;
- return res;
-}
-
time_t __stdcall JabberIsoToUnixTime(const TCHAR *stamp)
{
struct tm timestamp;
diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp index 39dc3a6799..566c276bf2 100644 --- a/protocols/JabberG/src/jabber_vcard.cpp +++ b/protocols/JabberG/src/jabber_vcard.cpp @@ -1155,7 +1155,7 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, TCHAR* szPhotoFileName) if ((hFile=CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) {
if ((buffer=(char*)mir_alloc(st.st_size)) != NULL) {
if (ReadFile(hFile, buffer, st.st_size, &nRead, NULL)) {
- if ((str=JabberBase64Encode(buffer, nRead)) != NULL) {
+ if ((str=mir_base64_encode((PBYTE)buffer, nRead)) != NULL) {
n = v << XCHILD(_T("PHOTO"));
TCHAR *szFileType;
switch(JabberGetPictureType(buffer)) {
|