diff options
author | George Hazan <george.hazan@gmail.com> | 2014-09-22 14:06:14 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-09-22 14:06:14 +0000 |
commit | fc3a4607ee5cfe9e7cfed8d63e2cb1d549f61d92 (patch) | |
tree | 754549fa0a5a62cbf5fa07b93d74bf4f3ab49061 | |
parent | 772ba179473fa39074278cad7aae84870c9310b8 (diff) |
_tcsncpy -> _tcsncpy_s; strncpy -> strncpy_s
git-svn-id: http://svn.miranda-ng.org/main/trunk@10557 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
22 files changed, 276 insertions, 289 deletions
diff --git a/protocols/JabberG/src/jabber.cpp b/protocols/JabberG/src/jabber.cpp index 3d5fc17fe2..43047a495b 100644 --- a/protocols/JabberG/src/jabber.cpp +++ b/protocols/JabberG/src/jabber.cpp @@ -123,12 +123,12 @@ static int OnModulesLoaded(WPARAM, LPARAM) }
// init fontservice for info frame
- FontIDT fontid = {0};
+ FontIDT fontid = { 0 };
fontid.cbSize = sizeof(fontid);
- _tcsncpy(fontid.group, LPGENT("Jabber"), SIZEOF(fontid.group));
- strncpy(fontid.dbSettingsGroup, GLOBAL_SETTING_MODULE, SIZEOF(fontid.dbSettingsGroup));
- _tcsncpy(fontid.backgroundGroup, _T("Jabber"), SIZEOF(fontid.backgroundGroup));
- _tcsncpy(fontid.backgroundName,_T("Background"), SIZEOF(fontid.backgroundName));
+ _tcsncpy_s(fontid.group, LPGENT("Jabber"), _TRUNCATE);
+ strncpy_s(fontid.dbSettingsGroup, GLOBAL_SETTING_MODULE, _TRUNCATE);
+ _tcsncpy_s(fontid.backgroundGroup, _T("Jabber"), _TRUNCATE);
+ _tcsncpy_s(fontid.backgroundName, _T("Background"), _TRUNCATE);
fontid.flags = FIDF_DEFAULTVALID;
fontid.deffontsettings.charset = DEFAULT_CHARSET;
@@ -137,23 +137,23 @@ static int OnModulesLoaded(WPARAM, LPARAM) lstrcpyn(fontid.deffontsettings.szFace, _T("MS Shell Dlg"), SIZEOF(fontid.deffontsettings.szFace));
fontid.deffontsettings.style = 0;
- _tcsncpy(fontid.name, LPGENT("Frame title"), SIZEOF(fontid.name));
- strncpy(fontid.prefix, "fntFrameTitle", SIZEOF(fontid.prefix));
+ _tcsncpy_s(fontid.name, LPGENT("Frame title"), _TRUNCATE);
+ strncpy_s(fontid.prefix, "fntFrameTitle", _TRUNCATE);
fontid.deffontsettings.style = DBFONTF_BOLD;
FontRegisterT(&fontid);
- _tcsncpy(fontid.name, LPGENT("Frame text"), SIZEOF(fontid.name));
- strncpy(fontid.prefix, "fntFrameClock", SIZEOF(fontid.prefix));
+ _tcsncpy_s(fontid.name, LPGENT("Frame text"), _TRUNCATE);
+ strncpy_s(fontid.prefix, "fntFrameClock", _TRUNCATE);
fontid.deffontsettings.style = 0;
FontRegisterT(&fontid);
ColourIDT colourid = {0};
colourid.cbSize = sizeof(colourid);
- _tcsncpy(colourid.group, _T("Jabber"), SIZEOF(colourid.group));
- strncpy(colourid.dbSettingsGroup, GLOBAL_SETTING_MODULE, SIZEOF(colourid.dbSettingsGroup));
+ _tcsncpy_s(colourid.group, _T("Jabber"), _TRUNCATE);
+ strncpy_s(colourid.dbSettingsGroup, GLOBAL_SETTING_MODULE, _TRUNCATE);
- _tcsncpy(colourid.name, _T("Background"), SIZEOF(colourid.name));
- strncpy(colourid.setting, "clFrameBack", SIZEOF(colourid.setting));
+ _tcsncpy_s(colourid.name, _T("Background"), _TRUNCATE);
+ strncpy_s(colourid.setting, "clFrameBack", _TRUNCATE);
colourid.defcolour = GetSysColor(COLOR_WINDOW);
ColourRegisterT(&colourid);
diff --git a/protocols/JabberG/src/jabber_adhoc.cpp b/protocols/JabberG/src/jabber_adhoc.cpp index 9a2ba33a04..6cb6f13f3c 100644 --- a/protocols/JabberG/src/jabber_adhoc.cpp +++ b/protocols/JabberG/src/jabber_adhoc.cpp @@ -518,7 +518,7 @@ int __cdecl CJabberProto::ContactMenuRunCommands(WPARAM hContact, LPARAM lParam) JABBER_LIST_ITEM *item = NULL;
int selected = 0;
TCHAR jid[JABBER_MAX_JID_LEN];
- _tcsncpy(jid, szJid, SIZEOF(jid));
+ _tcsncpy_s(jid, szJid, SIZEOF(jid));
{
mir_cslock lck(m_csLists);
item = ListGetItemPtr(LIST_ROSTER, jid);
diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index 4f78d7a20a..fff57b2bba 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -504,7 +504,7 @@ int CJabberProto::ByteSendProxyParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, ch // 03-03 address type (3)
// 04-44 dst.addr (41 bytes: 1-byte length, 40-byte SHA1 hash of [sid,srcJID,dstJID])
// 45-46 dst.port (0)
- if (datalen==2 && buffer[0]==5 && buffer[1]==0) {
+ if (datalen == 2 && buffer[0] == 5 && buffer[1] == 0) {
BYTE data[47];
ZeroMemory(data, sizeof(data));
*((DWORD*)data) = 0x03000105;
@@ -521,7 +521,7 @@ int CJabberProto::ByteSendProxyParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, ch char* szAuthString = mir_utf8encodeT(text);
debugLogA("Auth: '%s'", szAuthString);
char* szHash = JabberSha1(szAuthString);
- strncpy((char*)(data+5), szHash, 40);
+ strncpy_s((char*)(data + 5), 40, szHash, _TRUNCATE);
mir_free(szHash);
Netlib_Send(hConn, (char*)data, 47, 0);
jbt->state = JBT_CONNECT;
@@ -538,12 +538,12 @@ int CJabberProto::ByteSendProxyParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, ch // 03-03 address type (1=IPv4 address,3=host address)
// 04-mm bnd.addr server bound address (4-byte IP if IPv4, 1-byte length + n-byte host address string if host address)
// nn-nn+1 bnd.port server bound port
- if (datalen>=5 && buffer[0]==5 && buffer[1]==0 && (buffer[3]==1 || buffer[3]==3 || buffer[3]==0)) {
- if (buffer[3]==1 && datalen>=10)
+ if (datalen >= 5 && buffer[0] == 5 && buffer[1] == 0 && (buffer[3] == 1 || buffer[3] == 3 || buffer[3] == 0)) {
+ if (buffer[3] == 1 && datalen >= 10)
num = 10;
- else if (buffer[3]==3 && datalen>=buffer[4]+7)
+ else if (buffer[3] == 3 && datalen >= buffer[4] + 7)
num = buffer[4] + 7;
- else if (buffer[3]==0 && datalen>=6)
+ else if (buffer[3] == 0 && datalen >= 6)
num = 6;
else {
jbt->state = JBT_SOCKSERR;
@@ -563,8 +563,8 @@ int CJabberProto::ByteSendProxyParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, ch item->jbt = jbt;
m_ThreadInfo->send(
- XmlNodeIq( AddIQ(&CJabberProto::IqResultStreamActivate, JABBER_IQ_TYPE_SET, jbt->streamhostJID, 0, iqId))
- << XQUERY(JABBER_FEAT_BYTESTREAMS) << XATTR(_T("sid"), jbt->sid) << XCHILD(_T("activate"), jbt->dstJID));
+ XmlNodeIq(AddIQ(&CJabberProto::IqResultStreamActivate, JABBER_IQ_TYPE_SET, jbt->streamhostJID, 0, iqId))
+ << XQUERY(JABBER_FEAT_BYTESTREAMS) << XATTR(_T("sid"), jbt->sid) << XCHILD(_T("activate"), jbt->dstJID));
WaitForSingleObject(jbt->hProxyEvent, INFINITE);
@@ -585,7 +585,6 @@ int CJabberProto::ByteSendProxyParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, ch return num;
}
-
void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt)
{
HXML iqNode, queryNode = NULL, n;
@@ -607,62 +606,62 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) to = xmlGetAttrValue(iqNode, _T("to"));
szId = xmlGetAttrValue(iqNode, _T("id"));
- queryNode = xmlGetChild(iqNode , "query");
+ queryNode = xmlGetChild(iqNode, "query");
if (queryNode)
sid = xmlGetAttrValue(queryNode, _T("sid"));
}
- if (szId && from && to && sid && (n = xmlGetChild(queryNode , "streamhost")) != NULL) {
+ if (szId && from && to && sid && (n = xmlGetChild(queryNode, "streamhost")) != NULL) {
jbt->iqId = mir_tstrdup(szId);
jbt->srcJID = mir_tstrdup(from);
jbt->dstJID = mir_tstrdup(to);
jbt->sid = mir_tstrdup(sid);
- if ((buffer=(char*)mir_alloc(JABBER_NETWORK_BUFFER_SIZE))) {
- for (i=1; (n = xmlGetNthChild(queryNode, _T("streamhost"), i)) != NULL; i++) {
+ if ((buffer = (char*)mir_alloc(JABBER_NETWORK_BUFFER_SIZE))) {
+ for (i = 1; (n = xmlGetNthChild(queryNode, _T("streamhost"), i)) != NULL; i++) {
if ((szHost = xmlGetAttrValue(n, _T("host"))) != NULL &&
- (szPort = xmlGetAttrValue(n, _T("port"))) != NULL &&
- (str = xmlGetAttrValue(n, _T("jid"))) != NULL) {
-
- port = (WORD)_ttoi(szPort);
- replaceStrT(jbt->streamhostJID, str);
-
- debugLog(_T("bytestream_recv connecting to %s:%d"), szHost, port);
- NETLIBOPENCONNECTION nloc = { 0 };
- nloc.cbSize = sizeof(nloc);
- nloc.szHost = mir_t2a(szHost);
- nloc.wPort = port;
- hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
- mir_free((void*)nloc.szHost);
-
- if (hConn == NULL) {
- debugLogA("bytestream_recv_connection connection failed (%d), try next streamhost", WSAGetLastError());
- continue;
- }
-
- jbt->hConn = hConn;
-
- data[0] = 5;
- data[1] = 1;
- data[2] = 0;
- Netlib_Send(hConn, data, 3, 0);
-
- jbt->state = JBT_INIT;
- datalen = 0;
- while (jbt->state!=JBT_DONE && jbt->state!=JBT_ERROR && jbt->state!=JBT_SOCKSERR) {
- recvResult = Netlib_Recv(hConn, buffer+datalen, JABBER_NETWORK_BUFFER_SIZE-datalen, 0);
- if (recvResult <= 0) break;
- datalen += recvResult;
- bytesParsed = ByteReceiveParse(hConn, jbt, buffer, datalen);
- if (bytesParsed < datalen)
- memmove(buffer, buffer+bytesParsed, datalen-bytesParsed);
- datalen -= bytesParsed;
- if (jbt->state == JBT_RECVING) validStreamhost = TRUE;
- }
- Netlib_CloseHandle(hConn);
- debugLogA("bytestream_recv_connection closing connection");
+ (szPort = xmlGetAttrValue(n, _T("port"))) != NULL &&
+ (str = xmlGetAttrValue(n, _T("jid"))) != NULL) {
+
+ port = (WORD)_ttoi(szPort);
+ replaceStrT(jbt->streamhostJID, str);
+
+ debugLog(_T("bytestream_recv connecting to %s:%d"), szHost, port);
+ NETLIBOPENCONNECTION nloc = { 0 };
+ nloc.cbSize = sizeof(nloc);
+ nloc.szHost = mir_t2a(szHost);
+ nloc.wPort = port;
+ hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ mir_free((void*)nloc.szHost);
+
+ if (hConn == NULL) {
+ debugLogA("bytestream_recv_connection connection failed (%d), try next streamhost", WSAGetLastError());
+ continue;
+ }
+
+ jbt->hConn = hConn;
+
+ data[0] = 5;
+ data[1] = 1;
+ data[2] = 0;
+ Netlib_Send(hConn, data, 3, 0);
+
+ jbt->state = JBT_INIT;
+ datalen = 0;
+ while (jbt->state != JBT_DONE && jbt->state != JBT_ERROR && jbt->state != JBT_SOCKSERR) {
+ recvResult = Netlib_Recv(hConn, buffer + datalen, JABBER_NETWORK_BUFFER_SIZE - datalen, 0);
+ if (recvResult <= 0) break;
+ datalen += recvResult;
+ bytesParsed = ByteReceiveParse(hConn, jbt, buffer, datalen);
+ if (bytesParsed < datalen)
+ memmove(buffer, buffer + bytesParsed, datalen - bytesParsed);
+ datalen -= bytesParsed;
+ if (jbt->state == JBT_RECVING) validStreamhost = TRUE;
+ }
+ Netlib_CloseHandle(hConn);
+ debugLogA("bytestream_recv_connection closing connection");
}
- if (jbt->state==JBT_ERROR || validStreamhost==TRUE)
+ if (jbt->state == JBT_ERROR || validStreamhost == TRUE)
break;
debugLogA("bytestream_recv_connection stream cannot be established, try next streamhost");
}
@@ -670,14 +669,14 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) }
}
- (this->*jbt->pfnFinal)((jbt->state==JBT_DONE)?TRUE:FALSE, jbt->ft);
+ (this->*jbt->pfnFinal)((jbt->state == JBT_DONE) ? TRUE : FALSE, jbt->ft);
jbt->ft = NULL;
if (!validStreamhost && szId && from) {
debugLogA("bytestream_recv_connection session not completed");
- m_ThreadInfo->send( XmlNodeIq(_T("error"), szId, from)
- << XCHILD(_T("error")) << XATTRI(_T("code"), 404) << XATTR(_T("type"), _T("cancel"))
- << XCHILDNS(_T("item-not-found"), _T("urn:ietf:params:xml:ns:xmpp-stanzas")));
+ m_ThreadInfo->send(XmlNodeIq(_T("error"), szId, from)
+ << XCHILD(_T("error")) << XATTRI(_T("code"), 404) << XATTR(_T("type"), _T("cancel"))
+ << XCHILDNS(_T("item-not-found"), _T("urn:ietf:params:xml:ns:xmpp-stanzas")));
}
delete jbt;
@@ -700,13 +699,13 @@ int CJabberProto::ByteReceiveParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, char // 03-03 address type (3)
// 04-44 dst.addr (41 bytes: 1-byte length, 40-byte SHA1 hash of [sid,srcJID,dstJID])
// 45-46 dst.port (0)
- if (datalen==2 && buffer[0]==5 && buffer[1]==0) {
+ if (datalen == 2 && buffer[0] == 5 && buffer[1] == 0) {
BYTE data[47];
ZeroMemory(data, sizeof(data));
*((DWORD*)data) = 0x03000105;
data[4] = 40;
- TCHAR text[JABBER_MAX_JID_LEN*2];
+ TCHAR text[JABBER_MAX_JID_LEN * 2];
TCHAR *szInitiatorJid = JabberPrepareJid(jbt->srcJID);
TCHAR *szTargetJid = JabberPrepareJid(jbt->dstJID);
mir_sntprintf(text, SIZEOF(text), _T("%s%s%s"), jbt->sid, szInitiatorJid, szTargetJid);
@@ -715,7 +714,7 @@ int CJabberProto::ByteReceiveParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, char char* szAuthString = mir_utf8encodeT(text);
debugLogA("Auth: '%s'", szAuthString);
char* szHash = JabberSha1(szAuthString);
- strncpy((char*)(data+5), szHash, 40);
+ strncpy_s((char*)(data + 5), 40, szHash, _TRUNCATE);
mir_free(szHash);
Netlib_Send(hConn, (char*)data, 47, 0);
jbt->state = JBT_CONNECT;
@@ -732,12 +731,12 @@ int CJabberProto::ByteReceiveParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, char // 03-03 address type (1=IPv4 address,3=host address)
// 04-mm bnd.addr server bound address (4-byte IP if IPv4, 1-byte length + n-byte host address string if host address)
// nn-nn+1 bnd.port server bound port
- if (datalen>=5 && buffer[0]==5 && buffer[1]==0 && (buffer[3]==1 || buffer[3]==3 || buffer[3]==0)) {
- if (buffer[3]==1 && datalen>=10)
+ if (datalen >= 5 && buffer[0] == 5 && buffer[1] == 0 && (buffer[3] == 1 || buffer[3] == 3 || buffer[3] == 0)) {
+ if (buffer[3] == 1 && datalen >= 10)
num = 10;
- else if (buffer[3]==3 && datalen>=buffer[4]+7)
+ else if (buffer[3] == 3 && datalen >= buffer[4] + 7)
num = buffer[4] + 7;
- else if (buffer[3]==0 && datalen>=6)
+ else if (buffer[3] == 0 && datalen >= 6)
num = 6;
else {
jbt->state = JBT_SOCKSERR;
@@ -747,7 +746,7 @@ int CJabberProto::ByteReceiveParse(HANDLE hConn, JABBER_BYTE_TRANSFER *jbt, char m_ThreadInfo->send(
XmlNodeIq(_T("result"), jbt->iqId, jbt->srcJID) << XQUERY(JABBER_FEAT_BYTESTREAMS)
- << XCHILD(_T("streamhost-used")) << XATTR(_T("jid"), jbt->streamhostJID));
+ << XCHILD(_T("streamhost-used")) << XATTR(_T("jid"), jbt->streamhostJID));
}
else jbt->state = JBT_SOCKSERR;
break;
diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp index ad8fad2425..ce817df46c 100644 --- a/protocols/JabberG/src/jabber_caps.cpp +++ b/protocols/JabberG/src/jabber_caps.cpp @@ -216,7 +216,7 @@ JabberCapsBits CJabberProto::GetResourceCapabilites(const TCHAR *jid, BOOL appen if (appendBestResource)
GetClientJID(jid, fullJid, SIZEOF(fullJid));
else
- _tcsncpy(fullJid, jid, SIZEOF(fullJid));
+ _tcsncpy_s(fullJid, jid, SIZEOF(fullJid));
pResourceStatus r(ResourceInfoFromJID(fullJid));
if (r == NULL)
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp index 1594f0e574..d9b5fa568b 100644 --- a/protocols/JabberG/src/jabber_file.cpp +++ b/protocols/JabberG/src/jabber_file.cpp @@ -95,7 +95,7 @@ int CJabberProto::FileReceiveParse(filetransfer *ft, char* buffer, int datalen) 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(str, p, q-p);
+ strncpy_s(str, q - p, p, _TRUNCATE);
str[q-p] = '\0';
debugLogA("FT Got: %s", str);
if (ft->state == FT_CONNECTING) {
@@ -362,7 +362,7 @@ int CJabberProto::FileSendParse(JABBER_SOCKET s, filetransfer *ft, char* buffer, ft->state = FT_ERROR;
break;
}
- strncpy(str, p, q-p);
+ strncpy_s(str, q - p, p, _TRUNCATE);
str[q-p] = '\0';
debugLogA("FT Got: %s", str);
if (ft->state == FT_CONNECTING) {
diff --git a/protocols/JabberG/src/jabber_form.cpp b/protocols/JabberG/src/jabber_form.cpp index 21ef373827..1efd935fa0 100644 --- a/protocols/JabberG/src/jabber_form.cpp +++ b/protocols/JabberG/src/jabber_form.cpp @@ -868,7 +868,7 @@ void CJabberProto::FormCreateDialog(HXML xNode, TCHAR* defTitle, JABBER_FORM_SUB jfi->ppro = this;
jfi->xNode = xi.copyNode(xNode);
if (defTitle)
- _tcsncpy(jfi->defTitle, defTitle, SIZEOF(jfi->defTitle));
+ _tcsncpy_s(jfi->defTitle, defTitle, SIZEOF(jfi->defTitle));
jfi->pfnSubmit = pfnSubmit;
jfi->userdata = userdata;
diff --git a/protocols/JabberG/src/jabber_frame.cpp b/protocols/JabberG/src/jabber_frame.cpp index 8b3ab3f7df..98e0448916 100644 --- a/protocols/JabberG/src/jabber_frame.cpp +++ b/protocols/JabberG/src/jabber_frame.cpp @@ -323,7 +323,7 @@ void CJabberInfoFrame::PaintSkinGlyph(HDC hdc, RECT *rc, char **glyphs, COLORREF rq.rcClipRect = *rc;
for (; *glyphs; ++glyphs) {
- strncpy(rq.szObjectID, *glyphs, sizeof(rq.szObjectID));
+ strncpy_s(rq.szObjectID, *glyphs, _TRUNCATE);
if (!CallService(MS_SKIN_DRAWGLYPH, (WPARAM)&rq, 0))
return;
}
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 7c58fd7c30..316f2f448e 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -1218,7 +1218,7 @@ void CJabberProto::GroupchatProcessInvite(const TCHAR *roomJid, const TCHAR *fro void CJabberProto::AcceptGroupchatInvite(const TCHAR *roomJid, const TCHAR *reason, const TCHAR *password)
{
TCHAR room[256], *server, *p;
- _tcsncpy(room, roomJid, SIZEOF(room));
+ _tcsncpy_s(room, roomJid, SIZEOF(room));
p = _tcstok(room, _T("@"));
server = _tcstok(NULL, _T("@"));
GroupchatJoinRoom(server, p, reason, password);
diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index 10382979fc..5c7c66475e 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -647,7 +647,7 @@ BOOL CJabberProto::OnIqRequestOOB(HXML, CJabberIqInfo *pInfo) if ((q = _tcschr(p, '/')) != NULL) {
TCHAR text[1024];
if (q-p < SIZEOF(text)) {
- _tcsncpy(text, p, q-p);
+ _tcsncpy_s(text, p, q-p);
text[q-p] = '\0';
if ((p = _tcschr(text, ':')) != NULL) {
ft->httpPort = (WORD)_ttoi(p+1);
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index a7ca0a42e8..44cc13f28a 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -143,8 +143,8 @@ void CJabberProto::OnProcessLoginRq(ThreadData* info, DWORD rq) TCHAR room[256], *server, *p;
TCHAR text[128];
- _tcsncpy(text, item->jid, SIZEOF(text));
- _tcsncpy(room, text, SIZEOF(room));
+ _tcsncpy_s(text, item->jid, SIZEOF(text));
+ _tcsncpy_s(room, text, SIZEOF(room));
p = _tcstok(room, _T("@"));
server = _tcstok(NULL, _T("@"));
if (item->nick && item->nick[0] != 0)
@@ -290,7 +290,7 @@ void CJabberProto::OnIqResultBind(HXML iqNode, CJabberIqInfo *pInfo) debugLog(_T("Result Bind: %s confirmed "), m_ThreadInfo->fullJID);
else {
debugLog(_T("Result Bind: %s changed to %s"), m_ThreadInfo->fullJID, szJid);
- _tcsncpy(m_ThreadInfo->fullJID, szJid, SIZEOF(m_ThreadInfo->fullJID));
+ _tcsncpy_s(m_ThreadInfo->fullJID, szJid, SIZEOF(m_ThreadInfo->fullJID));
}
}
if (m_ThreadInfo->bIsSessionAvailable)
@@ -682,7 +682,7 @@ void CJabberProto::OnIqResultGetVcard(HXML iqNode, CJabberIqInfo*) jsr.hdr.firstName = sttGetText(vCardNode, "FN");
jsr.hdr.lastName = _T("");
jsr.hdr.email = sttGetText(vCardNode, "EMAIL");
- _tcsncpy(jsr.jid, jid, SIZEOF(jsr.jid));
+ _tcsncpy_s(jsr.jid, jid, SIZEOF(jsr.jid));
jsr.jid[ SIZEOF(jsr.jid)-1 ] = '\0';
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&jsr);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)id, 0);
@@ -834,7 +834,7 @@ void CJabberProto::OnIqResultGetVcard(HXML iqNode, CJabberIqInfo*) else if ((o=xmlGetChild(n, "EXTADD")) != NULL && xmlGetText(o) != NULL)
mir_sntprintf(text, SIZEOF(text), _T("%s\r\n%s"), xmlGetText(m), xmlGetText(o));
else
- _tcsncpy(text, xmlGetText(m), SIZEOF(text));
+ _tcsncpy_s(text, xmlGetText(m), SIZEOF(text));
text[SIZEOF(text)-1] = '\0';
setTString(hContact, "Street", text);
}
@@ -877,7 +877,7 @@ void CJabberProto::OnIqResultGetVcard(HXML iqNode, CJabberIqInfo*) else if ((o=xmlGetChild(n, "EXTADD")) != NULL && xmlGetText(o) != NULL)
mir_sntprintf(text, SIZEOF(text), _T("%s\r\n%s"), xmlGetText(m), xmlGetText(o));
else
- _tcsncpy(text, xmlGetText(m), SIZEOF(text));
+ _tcsncpy_s(text, xmlGetText(m), SIZEOF(text));
text[SIZEOF(text)-1] = '\0';
setTString(hContact, "CompanyStreet", text);
}
@@ -1162,7 +1162,7 @@ void CJabberProto::OnIqResultSetSearch(HXML iqNode, CJabberIqInfo*) if (!lstrcmp(xmlGetName(itemNode), _T("item"))) {
if ((jid = xmlGetAttrValue(itemNode, _T("jid"))) != NULL) {
- _tcsncpy(jsr.jid, jid, SIZEOF(jsr.jid));
+ _tcsncpy_s(jsr.jid, jid, SIZEOF(jsr.jid));
jsr.jid[SIZEOF(jsr.jid) - 1] = '\0';
jsr.hdr.id = (TCHAR*)jid;
debugLog(_T("Result jid = %s"), jid);
@@ -1238,7 +1238,7 @@ void CJabberProto::OnIqResultExtSearch(HXML iqNode, CJabberIqInfo*) continue;
if (!lstrcmp(fieldName, _T("jid"))) {
- _tcsncpy(jsr.jid, xmlGetText(n), SIZEOF(jsr.jid));
+ _tcsncpy_s(jsr.jid, xmlGetText(n), SIZEOF(jsr.jid));
jsr.jid[SIZEOF(jsr.jid)-1] = '\0';
debugLog(_T("Result jid = %s"), jsr.jid);
}
@@ -1272,7 +1272,7 @@ void CJabberProto::OnIqResultSetPassword(HXML iqNode, CJabberIqInfo *pInfo) return;
if (!lstrcmp(type, _T("result"))) {
- _tcsncpy(m_ThreadInfo->password, m_ThreadInfo->newPassword, SIZEOF(m_ThreadInfo->password));
+ _tcsncpy_s(m_ThreadInfo->password, m_ThreadInfo->newPassword, SIZEOF(m_ThreadInfo->password));
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 c72e46f4d2..2fea681ee1 100644 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -195,7 +195,7 @@ void CJabberProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t c char str[ 256 ];
DBVARIANT dbv;
if (!db_get_utf(hContact, m_szModuleName, "jid", &dbv)) {
- strncpy(str, dbv.pszVal, sizeof str);
+ strncpy_s(str, dbv.pszVal, _TRUNCATE);
str[ sizeof(str)-1 ] = 0;
db_free(&dbv);
}
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index b4e4e156bf..a29a93728f 100644 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -284,10 +284,10 @@ private: ShowWindow(GetDlgItem(m_hwnd, IDC_PROGRESS_REG), SW_SHOW);
ThreadData *thread = new ThreadData(m_regInfo->proto, JABBER_SESSION_REGISTER);
- _tcsncpy(thread->username, m_regInfo->username, SIZEOF(thread->username));
- _tcsncpy(thread->password, m_regInfo->password, SIZEOF(thread->password));
- strncpy(thread->server, m_regInfo->server, SIZEOF(thread->server));
- strncpy(thread->manualHost, m_regInfo->manualHost, SIZEOF(thread->manualHost));
+ _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;
@@ -503,7 +503,7 @@ protected: void OnApply()
{
// clear saved password
- *m_proto->m_savedPassword = 0;
+ m_proto->m_savedPassword = NULL;
if (m_chkSavePassword.GetState() == BST_CHECKED)
m_proto->setTString("Password", ptrT(m_txtPassword.GetText()));
@@ -1734,7 +1734,7 @@ protected: void OnApply()
{
// clear saved password
- *m_proto->m_savedPassword = 0;
+ m_proto->m_savedPassword = NULL;
BOOL bUseHostnameAsResource = FALSE;
TCHAR szCompName[MAX_COMPUTERNAME_LENGTH + 1], szResource[MAX_COMPUTERNAME_LENGTH + 1];
diff --git a/protocols/JabberG/src/jabber_password.cpp b/protocols/JabberG/src/jabber_password.cpp index 8cc8fafdb9..95fd7cd7ea 100644 --- a/protocols/JabberG/src/jabber_password.cpp +++ b/protocols/JabberG/src/jabber_password.cpp @@ -70,7 +70,7 @@ static INT_PTR CALLBACK JabberChangePasswordDlgProc(HWND hwndDlg, UINT msg, WPAR MessageBox(hwndDlg, TranslateT("Current password is incorrect."), TranslateT("Change Password"), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
break;
}
- _tcsncpy(ppro->m_ThreadInfo->newPassword, newPasswd, SIZEOF(ppro->m_ThreadInfo->newPassword));
+ _tcsncpy_s(ppro->m_ThreadInfo->newPassword, newPasswd, SIZEOF(ppro->m_ThreadInfo->newPassword));
XmlNodeIq iq( ppro->AddIQ(&CJabberProto::OnIqResultSetPassword, JABBER_IQ_TYPE_SET, _A2T(ppro->m_ThreadInfo->server)));
HXML q = iq << XQUERY(JABBER_FEAT_REGISTER);
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index e222a40427..86bb347cd4 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -139,8 +139,6 @@ CJabberProto::CJabberProto(const char *aProtoName, const TCHAR *aUserName) : m_pepServices.insert(new CPepMood(this));
m_pepServices.insert(new CPepActivity(this));
- *m_savedPassword = 0;
-
db_set_resident(m_szModuleName, "Status");
db_set_resident(m_szModuleName, DBSETTING_DISPLAY_UID);
@@ -722,7 +720,7 @@ void __cdecl CJabberProto::BasicSearchThread(JABBER_SEARCH_BASIC *jsb) jsr.hdr.lastName = _T("");
jsr.hdr.id = jsb->jid;
- _tcsncpy(jsr.jid, jsb->jid, SIZEOF(jsr.jid));
+ _tcsncpy_s(jsr.jid, jsb->jid, SIZEOF(jsr.jid));
jsr.jid[SIZEOF(jsr.jid)-1] = '\0';
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)jsb->hSearch, (LPARAM)&jsr);
@@ -756,10 +754,10 @@ HANDLE __cdecl CJabberProto::SearchBasic(const TCHAR *szJid) }
mir_sntprintf(jsb->jid, SIZEOF(jsb->jid), _T("%s@%s"), szJid, szServer);
}
- else _tcsncpy(jsb->jid, szJid, SIZEOF(jsb->jid));
+ else _tcsncpy_s(jsb->jid, szJid, SIZEOF(jsb->jid));
mir_free(szServer);
}
- else _tcsncpy(jsb->jid, szJid, SIZEOF(jsb->jid));
+ else _tcsncpy_s(jsb->jid, szJid, SIZEOF(jsb->jid));
debugLog(_T("Adding '%s' without validation"), jsb->jid);
jsb->hSearch = SerialNext();
@@ -1026,7 +1024,7 @@ int __cdecl CJabberProto::SendMsg(MCONTACT hContact, int flags, const char* pszS 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(tempstring, pszSrc + strlen(PGP_PROLOG), nStrippedLength);
+ strncpy_s(tempstring, nStrippedLength, pszSrc + strlen(PGP_PROLOG), _TRUNCATE);
tempstring[nStrippedLength] = 0;
pszSrc = tempstring;
isEncrypted = 1;
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 5ed75fb694..22eccdc0a3 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -703,7 +703,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface //---- jabber_thread.c ----------------------------------------------
- TCHAR m_savedPassword[512];
+ ptrT m_savedPassword;
typedef struct {
bool isPlainAvailable;
diff --git a/protocols/JabberG/src/jabber_search.cpp b/protocols/JabberG/src/jabber_search.cpp index b187e603f4..177bc5e70c 100644 --- a/protocols/JabberG/src/jabber_search.cpp +++ b/protocols/JabberG/src/jabber_search.cpp @@ -259,7 +259,7 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M TCHAR* value = pmUserData->operator [](var);
Results.pszFields[j] = value ? value : (TCHAR *)_T(" ");
if (!_tcsicmp(var,_T("jid")) && value)
- _tcsncpy(Results.jsr.jid, value, SIZEOF(Results.jsr.jid));
+ _tcsncpy_s(Results.jsr.jid, value, SIZEOF(Results.jsr.jid));
}
{
TCHAR * nickfields[]={ _T("nick"), _T("nickname"),
@@ -272,7 +272,7 @@ void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_M if (_tcsicmp(nick, Results.jsr.jid))
mir_sntprintf(buff, SIZEOF(buff), _T("%s (%s)"), nick, Results.jsr.jid);
else
- _tcsncpy(buff, nick, SIZEOF(buff));
+ _tcsncpy_s(buff, nick, SIZEOF(buff));
Results.jsr.hdr.nick = nick ? buff : NULL;
Results.jsr.hdr.flags = PSR_TCHAR;
}
diff --git a/protocols/JabberG/src/jabber_std.cpp b/protocols/JabberG/src/jabber_std.cpp index 1d633787eb..09284f20b8 100644 --- a/protocols/JabberG/src/jabber_std.cpp +++ b/protocols/JabberG/src/jabber_std.cpp @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void CJabberProto::JLoginFailed(int errorCode)
{
- *m_savedPassword = 0;
+ m_savedPassword = NULL;
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, errorCode);
}
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index 8b89ebc57e..81d6d37671 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -131,7 +131,7 @@ INT_PTR __cdecl CJabberProto::JabberGetAvatarInfo(WPARAM wParam, LPARAM lParam) TCHAR tszFileName[MAX_PATH];
GetAvatarFileName(AI->hContact, tszFileName, SIZEOF(tszFileName));
- _tcsncpy(AI->filename, tszFileName, SIZEOF(AI->filename));
+ _tcsncpy_s(AI->filename, tszFileName, SIZEOF(AI->filename));
AI->format = (AI->hContact == NULL) ? PA_FORMAT_PNG : getByte(AI->hContact, "AvatarType", 0);
@@ -469,7 +469,7 @@ INT_PTR __cdecl CJabberProto::JabberServiceParseXmppURI(WPARAM, LPARAM lParam) jsr.hdr.flags = PSR_TCHAR;
jsr.hdr.nick = szJid;
jsr.hdr.id = szJid;
- _tcsncpy(jsr.jid, szJid, SIZEOF(jsr.jid) - 1);
+ _tcsncpy_s(jsr.jid, szJid, SIZEOF(jsr.jid) - 1);
ADDCONTACTSTRUCT acs;
acs.handleType = HANDLE_SEARCHRESULT;
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 12691746bb..70a61cf5fb 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -304,13 +304,13 @@ LBL_FatalError: TCHAR jidStr[512];
mir_sntprintf(jidStr, SIZEOF(jidStr), _T("%s@%S/%s"), info->username, info->server, info->resource);
- _tcsncpy(info->fullJID, jidStr, SIZEOF(info->fullJID)-1);
+ _tcsncpy_s(info->fullJID, jidStr, SIZEOF(info->fullJID)-1);
- if (m_options.SavePassword == FALSE) {
- if (*m_savedPassword) {
- _tcsncpy(info->password, m_savedPassword, SIZEOF(info->password));
- info->password[ SIZEOF(info->password)-1] = '\0';
- }
+ if (m_options.UseDomainLogin) // in the case of NTLM auth we have no need in password
+ info->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, SIZEOF(info->password), m_savedPassword, _TRUNCATE);
else {
mir_sntprintf(jidStr, SIZEOF(jidStr), _T("%s@%S"), info->username, info->server);
@@ -328,23 +328,18 @@ LBL_FatalError: goto LBL_FatalError;
}
- if (param.saveOnlinePassword) lstrcpy(m_savedPassword, param.onlinePassword);
- else *m_savedPassword = 0;
-
- _tcsncpy(info->password, param.onlinePassword, SIZEOF(info->password));
- info->password[ SIZEOF(info->password)-1] = '\0';
+ m_savedPassword = (param.saveOnlinePassword) ? mir_tstrdup(param.onlinePassword) : NULL;
+ _tcsncpy_s(info->password, SIZEOF(info->password), param.onlinePassword, _TRUNCATE);
}
}
else {
- TCHAR *passw = getTStringA(NULL, "Password");
- if (passw == NULL) {
+ ptrT tszPassw(getTStringA(NULL, "Password"));
+ if (tszPassw == NULL) {
JLoginFailed(LOGINERR_BADUSERID);
debugLogA("Thread ended, password is not configured");
goto LBL_FatalError;
}
- _tcsncpy(info->password, passw, SIZEOF(info->password));
- info->password[SIZEOF(info->password)-1] = '\0';
- mir_free(passw);
+ _tcsncpy_s(info->password, SIZEOF(info->password), tszPassw, _TRUNCATE);
}
}
@@ -378,7 +373,7 @@ LBL_FatalError: if (info->manualHost[0] == 0) {
info->xmpp_client_query();
if (info->s == NULL) {
- strncpy(info->manualHost, info->server, SIZEOF(info->manualHost));
+ strncpy_s(info->manualHost, info->server, _TRUNCATE);
info->s = WsConnect(info->manualHost, info->port);
}
}
diff --git a/protocols/JabberG/src/jabber_userinfo.cpp b/protocols/JabberG/src/jabber_userinfo.cpp index aca4c6341f..785b6c6a66 100644 --- a/protocols/JabberG/src/jabber_userinfo.cpp +++ b/protocols/JabberG/src/jabber_userinfo.cpp @@ -661,9 +661,8 @@ static INT_PTR CALLBACK JabberUserPhotoDlgProc(HWND hwndDlg, UINT msg, WPARAM wP switch (LOWORD(wParam)) {
case IDC_SAVE:
static TCHAR szFilter[512];
- DWORD n;
- ptrT jid( photoInfo->ppro->getTStringA(photoInfo->hContact, "jid"));
+ ptrT jid(photoInfo->ppro->getTStringA(photoInfo->hContact, "jid"));
if (jid == NULL)
break;
@@ -672,27 +671,22 @@ static INT_PTR CALLBACK JabberUserPhotoDlgProc(HWND hwndDlg, UINT msg, WPARAM wP if ((item = photoInfo->ppro->ListGetItemPtr(LIST_ROSTER, jid)) == NULL)
break;
- switch ( ProtoGetAvatarFileFormat(item->photoFileName)) {
+ switch (ProtoGetAvatarFileFormat(item->photoFileName)) {
case PA_FORMAT_BMP:
- n = mir_sntprintf(szFilter, SIZEOF(szFilter), _T("BMP %s (*.bmp)"), TranslateT("format"));
- _tcsncpy(szFilter+n+1, _T("*.BMP"), SIZEOF(szFilter)-n-2);
+ mir_sntprintf(szFilter, SIZEOF(szFilter), _T("BMP %s (*.bmp)%c*.BMP"), TranslateT("format"), 0);
break;
case PA_FORMAT_GIF:
- n = mir_sntprintf(szFilter, SIZEOF(szFilter), _T("GIF %s (*.gif)"), TranslateT("format"));
- _tcsncpy(szFilter+n+1, _T("*.GIF"), SIZEOF(szFilter)-n-2);
+ mir_sntprintf(szFilter, SIZEOF(szFilter), _T("GIF %s (*.gif)%c*.GIF"), TranslateT("format"), 0);
break;
case PA_FORMAT_JPEG:
- n = mir_sntprintf(szFilter, SIZEOF(szFilter), _T("JPEG %s (*.jpg;*.jpeg)"), TranslateT("format"));
- _tcsncpy(szFilter+n+1, _T("*.JPG;*.JPEG"), SIZEOF(szFilter)-n-2);
+ mir_sntprintf(szFilter, SIZEOF(szFilter), _T("JPEG %s (*.jpg;*.jpeg)%c*.JPG;*.JPEG"), TranslateT("format"), 0);
break;
default:
- n = mir_sntprintf(szFilter, SIZEOF(szFilter), _T("%s (*.*)"), TranslateT("Unknown format"));
- _tcsncpy(szFilter+n+1, _T("*.*"), SIZEOF(szFilter)-n-2);
+ mir_sntprintf(szFilter, SIZEOF(szFilter), _T("%s (*.*)%c*.*"), TranslateT("Unknown format"), 0);
}
- szFilter[SIZEOF(szFilter)-1] = 0;
TCHAR szFileName[MAX_PATH]; szFileName[0] = '\0';
OPENFILENAME ofn = { 0 };
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index cebc1dcb5a..e87634e657 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -40,7 +40,7 @@ MCONTACT CJabberProto::ChatRoomHContactFromJID(const TCHAR *jid) return NULL;
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- ptrT dbJid( getTStringA(hContact, "ChatRoomID"));
+ ptrT dbJid(getTStringA(hContact, "ChatRoomID"));
if (dbJid == NULL)
if ((dbJid = getTStringA(hContact, "jid")) == NULL)
continue;
@@ -65,7 +65,7 @@ MCONTACT CJabberProto::HContactFromJID(const TCHAR *jid, BOOL bStripResource) for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
bool bIsChat = isChatRoom(hContact);
- ptrT dbJid( getTStringA(hContact, bIsChat ? "ChatRoomID" : "jid"));
+ ptrT dbJid(getTStringA(hContact, bIsChat ? "ChatRoomID" : "jid"));
if (dbJid != NULL) {
int result;
if (item != NULL)
@@ -104,9 +104,9 @@ TCHAR* __stdcall JabberNickFromJID(const TCHAR *jid) p = _tcschr(jid, '/');
if (p != NULL) {
- if ((nick=(TCHAR*)mir_alloc(sizeof(TCHAR)*(int(p-jid)+1))) != NULL) {
- _tcsncpy(nick, jid, p-jid);
- nick[p-jid] = '\0';
+ if ((nick = (TCHAR*)mir_alloc(sizeof(TCHAR)*(int(p - jid) + 1))) != NULL) {
+ _tcsncpy_s(nick, p - jid, jid, _TRUNCATE);
+ nick[p - jid] = '\0';
}
}
else nick = mir_tstrdup(jid);
@@ -128,7 +128,7 @@ pResourceStatus CJabberProto::ResourceInfoFromJID(const TCHAR *jid) if (p == NULL)
return item->getTemp();
- return item->findResource(p+1);
+ return item->findResource(p + 1);
}
TCHAR* JabberPrepareJid(LPCTSTR jid)
@@ -146,10 +146,10 @@ TCHAR* JabberPrepareJid(LPCTSTR jid) void strdel(char* parBuffer, int len)
{
char* p;
- for (p = parBuffer+len; *p != 0; p++)
- p[ -len ] = *p;
+ for (p = parBuffer + len; *p != 0; p++)
+ p[-len] = *p;
- p[ -len ] = '\0';
+ p[-len] = '\0';
}
char* __stdcall JabberUrlDecode(char *str)
@@ -159,26 +159,26 @@ char* __stdcall JabberUrlDecode(char *str) if (str == NULL)
return NULL;
- for (p=q=str; *p!='\0'; p++,q++) {
+ for (p = q = str; *p != '\0'; p++, q++) {
if (*p == '<') {
// skip CDATA
if (!strncmp(p, "<![CDATA[", 9)) {
p += 9;
char *tail = strstr(p, "]]>");
- size_t count = tail ? (tail-p) : strlen(p);
+ size_t count = tail ? (tail - p) : strlen(p);
memmove(q, p, count);
- q += count-1;
- p = (tail ? (tail+3) : (p+count)) - 1;
+ q += count - 1;
+ p = (tail ? (tail + 3) : (p + count)) - 1;
}
else *q = *p;
}
else if (*p == '&') {
- if (!strncmp(p, "&", 5)) { *q = '&'; p += 4; }
+ if (!strncmp(p, "&", 5)) { *q = '&'; p += 4; }
else if (!strncmp(p, "'", 6)) { *q = '\''; p += 5; }
else if (!strncmp(p, ">", 4)) { *q = '>'; p += 3; }
else if (!strncmp(p, "<", 4)) { *q = '<'; p += 3; }
else if (!strncmp(p, """, 6)) { *q = '"'; p += 5; }
- else { *q = *p; }
+ else { *q = *p; }
}
else *q = *p;
}
@@ -192,14 +192,14 @@ void __stdcall JabberUrlDecodeW(WCHAR *str) return;
WCHAR *p, *q;
- for (p=q=str; *p!='\0'; p++,q++) {
+ for (p = q = str; *p != '\0'; p++, q++) {
if (*p == '&') {
- if (!wcsncmp(p, L"&", 5)) { *q = '&'; p += 4; }
+ if (!wcsncmp(p, L"&", 5)) { *q = '&'; p += 4; }
else if (!wcsncmp(p, L"'", 6)) { *q = '\''; p += 5; }
else if (!wcsncmp(p, L">", 4)) { *q = '>'; p += 3; }
else if (!wcsncmp(p, L"<", 4)) { *q = '<'; p += 3; }
else if (!wcsncmp(p, L""", 6)) { *q = '"'; p += 5; }
- else { *q = *p; }
+ else { *q = *p; }
}
else {
*q = *p;
@@ -216,18 +216,18 @@ char* __stdcall JabberUrlEncode(const char *str) if (str == NULL)
return NULL;
- for (c=0,p=(char*)str; *p != '\0'; p++) {
+ for (c = 0, p = (char*)str; *p != '\0'; p++) {
switch (*p) {
- case '&': c += 5; break;
- case '\'': c += 6; break;
- case '>': c += 4; break;
- case '<': c += 4; break;
- case '"': c += 6; break;
- default: c++; break;
+ case '&': c += 5; break;
+ case '\'': c += 6; break;
+ case '>': c += 4; break;
+ case '<': c += 4; break;
+ case '"': c += 6; break;
+ default: c++; break;
}
}
- if ((s=(char*)mir_alloc(c+1)) != NULL) {
- for (p=(char*)str,q=s; *p!='\0'; p++) {
+ if ((s = (char*)mir_alloc(c + 1)) != NULL) {
+ for (p = (char*)str, q = s; *p != '\0'; p++) {
switch (*p) {
case '&': strcpy(q, "&"); q += 5; break;
case '\'': strcpy(q, "'"); q += 6; break;
@@ -236,7 +236,7 @@ char* __stdcall JabberUrlEncode(const char *str) case '"': strcpy(q, """); q += 6; break;
default:
if (*p > 0 && *p < 32) {
- switch(*p) {
+ switch (*p) {
case '\r':
case '\n':
case '\t':
@@ -261,21 +261,20 @@ void __stdcall JabberUtfToTchar(const char *pszValue, size_t cbLen, LPTSTR &dest {
char* pszCopy = NULL;
bool bNeedsFree = false;
- __try
- {
+ __try {
// this code can cause access violation when a stack overflow occurs
- pszCopy = (char*)alloca(cbLen+1);
+ pszCopy = (char*)alloca(cbLen + 1);
}
- __except(EXCEPTION_EXECUTE_HANDLER)
+ __except (EXCEPTION_EXECUTE_HANDLER)
{
bNeedsFree = true;
- pszCopy = (char*)malloc(cbLen+1);
+ pszCopy = (char*)malloc(cbLen + 1);
}
if (pszCopy == NULL)
return;
memcpy(pszCopy, pszValue, cbLen);
- pszCopy[ cbLen ] = 0;
+ pszCopy[cbLen] = 0;
JabberUrlDecode(pszCopy);
@@ -338,16 +337,16 @@ char* __stdcall JabberUnixToDos(const char* str) char* p, *q, *res;
int extra;
- if (str == NULL || str[0]=='\0')
+ if (str == NULL || str[0] == '\0')
return NULL;
extra = 0;
- for (p=(char*)str; *p!='\0'; p++) {
+ for (p = (char*)str; *p != '\0'; p++) {
if (*p == '\n')
extra++;
}
- if ((res=(char*)mir_alloc(strlen(str)+extra+1)) != NULL) {
- for (p=(char*)str,q=res; *p!='\0'; p++,q++) {
+ if ((res = (char*)mir_alloc(strlen(str) + extra + 1)) != NULL) {
+ for (p = (char*)str, q = res; *p != '\0'; p++, q++) {
if (*p == '\n') {
*q = '\r';
q++;
@@ -361,19 +360,19 @@ char* __stdcall JabberUnixToDos(const char* str) WCHAR* __stdcall JabberUnixToDosW(const WCHAR* str)
{
- if (str == NULL || str[0]=='\0')
+ if (str == NULL || str[0] == '\0')
return NULL;
const WCHAR* p;
WCHAR* q, *res;
int extra = 0;
- for (p = str; *p!='\0'; p++)
+ for (p = str; *p != '\0'; p++)
if (*p == '\n')
extra++;
if ((res = (WCHAR*)mir_alloc(sizeof(WCHAR)*(wcslen(str) + extra + 1))) != NULL) {
- for (p = str,q=res; *p!='\0'; p++,q++) {
+ for (p = str, q = res; *p != '\0'; p++, q++) {
if (*p == '\n') {
*q = '\r';
q++;
@@ -391,10 +390,10 @@ void __stdcall JabberHttpUrlDecode(TCHAR *str) unsigned int code;
if (str == NULL) return;
- for (p = q = (TCHAR*)str; *p!='\0'; p++,q++) {
- if (*p=='%' && *(p+1)!='\0' && isxdigit(*(p+1)) && *(p+2)!='\0' && isxdigit(*(p+2))) {
- _stscanf((TCHAR*)p+1, _T("%2x"), &code);
- *q = (unsigned char) code;
+ for (p = q = (TCHAR*)str; *p != '\0'; p++, q++) {
+ if (*p == '%' && *(p + 1) != '\0' && isxdigit(*(p + 1)) && *(p + 2) != '\0' && isxdigit(*(p + 2))) {
+ _stscanf((TCHAR*)p + 1, _T("%2x"), &code);
+ *q = (unsigned char)code;
p += 2;
}
else *q = *p;
@@ -414,52 +413,53 @@ int __stdcall JabberCombineStatus(int status1, int status2) // ID_STATUS_INVISIBLE (valid only for TLEN_PLUGIN)
// ID_STATUS_OFFLINE
// other ID_STATUS in random order (actually return status1)
- if (status1==ID_STATUS_FREECHAT || status2==ID_STATUS_FREECHAT)
+ if (status1 == ID_STATUS_FREECHAT || status2 == ID_STATUS_FREECHAT)
return ID_STATUS_FREECHAT;
- if (status1==ID_STATUS_ONLINE || status2==ID_STATUS_ONLINE)
+ if (status1 == ID_STATUS_ONLINE || status2 == ID_STATUS_ONLINE)
return ID_STATUS_ONLINE;
- if (status1==ID_STATUS_DND || status2==ID_STATUS_DND)
+ if (status1 == ID_STATUS_DND || status2 == ID_STATUS_DND)
return ID_STATUS_DND;
- if (status1==ID_STATUS_AWAY || status2==ID_STATUS_AWAY)
+ if (status1 == ID_STATUS_AWAY || status2 == ID_STATUS_AWAY)
return ID_STATUS_AWAY;
- if (status1==ID_STATUS_NA || status2==ID_STATUS_NA)
+ if (status1 == ID_STATUS_NA || status2 == ID_STATUS_NA)
return ID_STATUS_NA;
- if (status1==ID_STATUS_INVISIBLE || status2==ID_STATUS_INVISIBLE)
+ if (status1 == ID_STATUS_INVISIBLE || status2 == ID_STATUS_INVISIBLE)
return ID_STATUS_INVISIBLE;
- if (status1==ID_STATUS_OFFLINE || status2==ID_STATUS_OFFLINE)
+ if (status1 == ID_STATUS_OFFLINE || status2 == ID_STATUS_OFFLINE)
return ID_STATUS_OFFLINE;
return status1;
}
-struct tagErrorCodeToStr {
+struct tagErrorCodeToStr
+{
int code;
TCHAR *str;
}
static JabberErrorCodeToStrMapping[] = {
- { JABBER_ERROR_REDIRECT, LPGENT("Redirect") },
- { JABBER_ERROR_BAD_REQUEST, LPGENT("Bad request") },
- { JABBER_ERROR_UNAUTHORIZED, LPGENT("Unauthorized") },
- { JABBER_ERROR_PAYMENT_REQUIRED, LPGENT("Payment required") },
- { JABBER_ERROR_FORBIDDEN, LPGENT("Forbidden") },
- { JABBER_ERROR_NOT_FOUND, LPGENT("Not found") },
- { JABBER_ERROR_NOT_ALLOWED, LPGENT("Not allowed") },
- { JABBER_ERROR_NOT_ACCEPTABLE, LPGENT("Not acceptable") },
- { JABBER_ERROR_REGISTRATION_REQUIRED, LPGENT("Registration required") },
- { JABBER_ERROR_REQUEST_TIMEOUT, LPGENT("Request timeout") },
- { JABBER_ERROR_CONFLICT, LPGENT("Conflict") },
- { JABBER_ERROR_INTERNAL_SERVER_ERROR, LPGENT("Internal server error") },
- { JABBER_ERROR_NOT_IMPLEMENTED, LPGENT("Not implemented") },
- { JABBER_ERROR_REMOTE_SERVER_ERROR, LPGENT("Remote server error") },
- { JABBER_ERROR_SERVICE_UNAVAILABLE, LPGENT("Service unavailable") },
- { JABBER_ERROR_REMOTE_SERVER_TIMEOUT, LPGENT("Remote server timeout") },
- { -1, LPGENT("Unknown error") }
+ { JABBER_ERROR_REDIRECT, LPGENT("Redirect") },
+ { JABBER_ERROR_BAD_REQUEST, LPGENT("Bad request") },
+ { JABBER_ERROR_UNAUTHORIZED, LPGENT("Unauthorized") },
+ { JABBER_ERROR_PAYMENT_REQUIRED, LPGENT("Payment required") },
+ { JABBER_ERROR_FORBIDDEN, LPGENT("Forbidden") },
+ { JABBER_ERROR_NOT_FOUND, LPGENT("Not found") },
+ { JABBER_ERROR_NOT_ALLOWED, LPGENT("Not allowed") },
+ { JABBER_ERROR_NOT_ACCEPTABLE, LPGENT("Not acceptable") },
+ { JABBER_ERROR_REGISTRATION_REQUIRED, LPGENT("Registration required") },
+ { JABBER_ERROR_REQUEST_TIMEOUT, LPGENT("Request timeout") },
+ { JABBER_ERROR_CONFLICT, LPGENT("Conflict") },
+ { JABBER_ERROR_INTERNAL_SERVER_ERROR, LPGENT("Internal server error") },
+ { JABBER_ERROR_NOT_IMPLEMENTED, LPGENT("Not implemented") },
+ { JABBER_ERROR_REMOTE_SERVER_ERROR, LPGENT("Remote server error") },
+ { JABBER_ERROR_SERVICE_UNAVAILABLE, LPGENT("Service unavailable") },
+ { JABBER_ERROR_REMOTE_SERVER_TIMEOUT, LPGENT("Remote server timeout") },
+ { -1, LPGENT("Unknown error") }
};
TCHAR* __stdcall JabberErrorStr(int errorCode)
{
int i;
- for (i=0; JabberErrorCodeToStrMapping[i].code!=-1 && JabberErrorCodeToStrMapping[i].code!=errorCode; i++);
+ for (i = 0; JabberErrorCodeToStrMapping[i].code != -1 && JabberErrorCodeToStrMapping[i].code != errorCode; i++);
return JabberErrorCodeToStrMapping[i].str;
}
@@ -482,7 +482,7 @@ TCHAR* __stdcall JabberErrorMsg(HXML errorNode, int* pErrorCode) if (str == NULL)
str = xmlGetText(xmlGetChild(errorNode, _T("text")));
if (str == NULL) {
- for (int i=0; ; i++) {
+ for (int i = 0;; i++) {
HXML c = xmlGetChild(errorNode, i);
if (c == NULL) break;
const TCHAR *attr = xmlGetAttrValue(c, _T("xmlns"));
@@ -518,63 +518,62 @@ void CJabberProto::SendVisibleInvisiblePresence(BOOL invisible) continue;
WORD apparentMode = getWord(hContact, "ApparentMode", 0);
- if (invisible==TRUE && apparentMode==ID_STATUS_OFFLINE)
+ if (invisible == TRUE && apparentMode == ID_STATUS_OFFLINE)
m_ThreadInfo->send(XmlNode(_T("presence")) << XATTR(_T("to"), item->jid) << XATTR(_T("type"), _T("invisible")));
- else if (invisible==FALSE && apparentMode==ID_STATUS_ONLINE)
+ else if (invisible == FALSE && apparentMode == ID_STATUS_ONLINE)
SendPresenceTo(m_iStatus, item->jid, NULL);
-} }
+ }
+}
time_t __stdcall JabberIsoToUnixTime(const TCHAR *stamp)
{
- struct tm timestamp;
TCHAR date[9];
int i, y;
- time_t t;
- if (stamp == NULL) return (time_t) 0;
+ if (stamp == NULL)
+ return 0;
const TCHAR *p = stamp;
// Get the date part
- for (i=0; *p!='\0' && i<8 && isdigit(*p); p++,i++)
+ for (i = 0; *p != '\0' && i < 8 && isdigit(*p); p++, i++)
date[i] = *p;
// Parse year
if (i == 6) {
// 2-digit year (1970-2069)
- y = (date[0]-'0')*10 + (date[1]-'0');
+ y = (date[0] - '0') * 10 + (date[1] - '0');
if (y < 70) y += 100;
}
else if (i == 8) {
// 4-digit year
- y = (date[0]-'0')*1000 + (date[1]-'0')*100 + (date[2]-'0')*10 + date[3]-'0';
+ y = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + date[3] - '0';
y -= 1900;
}
- else
- return (time_t) 0;
+ else return 0;
+
+ struct tm timestamp;
timestamp.tm_year = y;
+
// Parse month
- timestamp.tm_mon = (date[i-4]-'0')*10 + date[i-3]-'0' - 1;
+ timestamp.tm_mon = (date[i - 4] - '0') * 10 + date[i - 3] - '0' - 1;
+
// Parse date
- timestamp.tm_mday = (date[i-2]-'0')*10 + date[i-1]-'0';
+ timestamp.tm_mday = (date[i - 2] - '0') * 10 + date[i - 1] - '0';
// Skip any date/time delimiter
- for (; *p!='\0' && !isdigit(*p); p++);
+ for (; *p != '\0' && !isdigit(*p); p++);
// Parse time
if (_stscanf(p, _T("%d:%d:%d"), ×tamp.tm_hour, ×tamp.tm_min, ×tamp.tm_sec) != 3)
- return (time_t) 0;
+ return (time_t)0;
timestamp.tm_isdst = 0; // DST is already present in _timezone below
- t = mktime(×tamp);
+ time_t t = mktime(×tamp);
_tzset();
t -= _timezone;
-
- if (t >= 0)
- return t;
- else
- return (time_t) 0;
+ return (t >= 0) ? t : 0;
}
void CJabberProto::SendPresenceTo(int status, const TCHAR* to, HXML extra, const TCHAR *msg)
@@ -632,13 +631,13 @@ void CJabberProto::SendPresenceTo(int status, const TCHAR* to, HXML extra, const NotifyFastHook(hExtListInit, (WPARAM)&arrExtCaps, (LPARAM)(IJabberInterface*)this);
// add features enabled through IJabberNetInterface::AddFeatures()
- for (int i=0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++)
+ for (int i = 0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++)
if (m_uEnabledFeatCapsDynamic & m_lstJabberFeatCapPairsDynamic[i]->jcbCap)
arrExtCaps.insert(m_lstJabberFeatCapPairsDynamic[i]->szExt);
if (arrExtCaps.getCount()) {
CMString szExtCaps = arrExtCaps[0];
- for (int i=1; i < arrExtCaps.getCount(); i++) {
+ for (int i = 1; i < arrExtCaps.getCount(); i++) {
szExtCaps.AppendChar(' ');
szExtCaps += arrExtCaps[i];
}
@@ -648,7 +647,7 @@ void CJabberProto::SendPresenceTo(int status, const TCHAR* to, HXML extra, const if (m_options.EnableAvatars) {
HXML x = p << XCHILDNS(_T("x"), _T("vcard-temp:x:update"));
- ptrA hashValue( getStringA("AvatarHash"));
+ ptrA hashValue(getStringA("AvatarHash"));
if (hashValue != NULL) // XEP-0153: vCard-Based Avatars
x << XCHILD(_T("photo"), _A2T(hashValue));
else
@@ -704,10 +703,13 @@ void CJabberProto::SendPresence(int status, bool bSendToAll) {
JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
if (item != NULL) {
- TCHAR text[ 1024 ];
+ TCHAR text[1024];
mir_sntprintf(text, SIZEOF(text), _T("%s/%s"), item->jid, item->nick);
SendPresenceTo(status == ID_STATUS_INVISIBLE ? ID_STATUS_ONLINE : status, text, NULL);
-} } } }
+ }
+ }
+ }
+}
///////////////////////////////////////////////////////////////////////////////
// JabberGetPacketID - converts the xml id attribute into an integer
@@ -716,8 +718,8 @@ int __stdcall JabberGetPacketID(HXML n) {
const TCHAR *str = xmlGetAttrValue(n, _T("id"));
if (str)
- if (!_tcsncmp(str, _T(JABBER_IQID), SIZEOF(JABBER_IQID)-1))
- return _ttoi(str + SIZEOF(JABBER_IQID)-1);
+ if (!_tcsncmp(str, _T(JABBER_IQID), SIZEOF(JABBER_IQID) - 1))
+ return _ttoi(str + SIZEOF(JABBER_IQID) - 1);
return -1;
}
@@ -737,7 +739,7 @@ TCHAR* CJabberProto::GetClientJID(MCONTACT hContact, TCHAR *dest, size_t destLen if (hContact == NULL)
return NULL;
- ptrT jid( getTStringA(hContact, "jid"));
+ ptrT jid(getTStringA(hContact, "jid"));
return GetClientJID(jid, dest, destLen);
}
@@ -758,7 +760,7 @@ TCHAR* CJabberProto::GetClientJID(const TCHAR *jid, TCHAR *dest, size_t destLen) }
if (p == NULL) {
- pResourceStatus r( LI->getBestResource());
+ pResourceStatus r(LI->getBestResource());
if (r != NULL)
mir_sntprintf(dest, destLen, _T("%s/%s"), jid, r->m_tszResourceName);
}
@@ -790,14 +792,14 @@ TCHAR* __stdcall JabberStripJid(const TCHAR *jid, TCHAR *dest, size_t destLen) LPCTSTR __stdcall JabberGetPictureType(HXML node, const char *picBuf)
{
- if (LPCTSTR ptszType = xmlGetText( xmlGetChild(node , "TYPE")))
+ if (LPCTSTR ptszType = xmlGetText(xmlGetChild(node, "TYPE")))
if (!_tcscmp(ptszType, _T("image/jpeg")) ||
- !_tcscmp(ptszType, _T("image/png")) ||
- !_tcscmp(ptszType, _T("image/gif")) ||
- !_tcscmp(ptszType, _T("image/bmp")))
+ !_tcscmp(ptszType, _T("image/png")) ||
+ !_tcscmp(ptszType, _T("image/gif")) ||
+ !_tcscmp(ptszType, _T("image/bmp")))
return ptszType;
- switch( ProtoGetBufferFormat(picBuf)) {
+ switch (ProtoGetBufferFormat(picBuf)) {
case PA_FORMAT_GIF: return _T("image/gif");
case PA_FORMAT_BMP: return _T("image/bmp");
case PA_FORMAT_PNG: return _T("image/png");
@@ -813,36 +815,37 @@ LPCTSTR __stdcall JabberGetPictureType(HXML node, const char *picBuf) TStringPairs::TStringPairs(char* buffer) :
elems(NULL)
{
- TStringPairsElem tempElem[ 100 ];
+ TStringPairsElem tempElem[100];
char* token = strtok(buffer, ",");
- for (numElems=0; token != NULL; numElems++) {
+ for (numElems = 0; token != NULL; numElems++) {
char* p = strchr(token, '='), *p1;
if (p == NULL)
break;
- while(isspace(*token))
+ while (isspace(*token))
token++;
- tempElem[ numElems ].name = rtrim(token);
+ tempElem[numElems].name = rtrim(token);
*p++ = 0;
if ((p1 = strchr(p, '\"')) != NULL) {
*p1 = 0;
- p = p1+1;
+ p = p1 + 1;
}
if ((p1 = strrchr(p, '\"')) != NULL)
*p1 = 0;
- tempElem[ numElems ].value = rtrim(p);
+ tempElem[numElems].value = rtrim(p);
token = strtok(NULL, ",");
}
if (numElems) {
- elems = new TStringPairsElem[ numElems ];
+ elems = new TStringPairsElem[numElems];
memcpy(elems, tempElem, sizeof(tempElem[0]) * numElems);
-} }
+ }
+}
TStringPairs::~TStringPairs()
{
@@ -851,7 +854,7 @@ TStringPairs::~TStringPairs() const char* TStringPairs::operator[](const char* key) const
{
- for (int i=0; i < numElems; i++)
+ for (int i = 0; i < numElems; i++)
if (!strcmp(elems[i].name, key))
return elems[i].value;
@@ -863,10 +866,10 @@ const char* TStringPairs::operator[](const char* key) const void CJabberProto::ComboLoadRecentStrings(HWND hwndDlg, UINT idcCombo, char *param, int recentCount)
{
- for (int i=0; i < recentCount; i++) {
+ for (int i = 0; i < recentCount; i++) {
char setting[MAXMODULELABELLENGTH];
mir_snprintf(setting, sizeof(setting), "%s%d", param, i);
- ptrT tszRecent( getTStringA(setting));
+ ptrT tszRecent(getTStringA(setting));
if (tszRecent != NULL)
SendDlgItemMessage(hwndDlg, idcCombo, CB_ADDSTRING, 0, tszRecent);
}
@@ -891,7 +894,7 @@ void CJabberProto::ComboAddRecentString(HWND hwndDlg, UINT idcCombo, char *param char setting[MAXMODULELABELLENGTH];
mir_snprintf(setting, sizeof(setting), "%s%d", param, id);
setTString(setting, string);
- setByte(param, (id+1)%recentCount);
+ setByte(param, (id + 1) % recentCount);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -935,8 +938,8 @@ static VOID CALLBACK sttRebuildInfoFrameApcProc(void* param) JABBER_LIST_ITEM *item = NULL;
LISTFOREACH(i, ppro, LIST_ROSTER)
{
- if ((item=ppro->ListGetItemPtrFromIndex(i)) != NULL) {
- if (_tcschr(item->jid, '@') == NULL && _tcschr(item->jid, '/') == NULL && item->subscription!=SUB_NONE) {
+ if ((item = ppro->ListGetItemPtrFromIndex(i)) != NULL) {
+ if (_tcschr(item->jid, '@') == NULL && _tcschr(item->jid, '/') == NULL && item->subscription != SUB_NONE) {
MCONTACT hContact = ppro->HContactFromJID(item->jid);
if (hContact == NULL) continue;
@@ -947,7 +950,8 @@ static VOID CALLBACK sttRebuildInfoFrameApcProc(void* param) ppro->m_pInfoFrame->UpdateInfoItem(name, ppro->GetIconHandle(IDI_TRANSPORTL), (TCHAR *)item->jid);
ppro->m_pInfoFrame->SetInfoItemCallback(name, &CJabberProto::InfoFrame_OnTransport);
mir_free(jid_copy);
- } }
+ }
+ }
}
}
ppro->m_pInfoFrame->Update();
@@ -966,16 +970,16 @@ TCHAR* time2str(time_t _time, TCHAR *buf, size_t bufLen) {
struct tm* T = localtime(&_time);
mir_sntprintf(buf, bufLen, _T("%04d-%02d-%02dT%02d:%02d:%02dZ"),
- T->tm_year+1900, T->tm_mon+1, T->tm_mday, T->tm_hour, T->tm_min, T->tm_sec);
+ T->tm_year + 1900, T->tm_mon + 1, T->tm_mday, T->tm_hour, T->tm_min, T->tm_sec);
return buf;
}
time_t str2time(const TCHAR *buf)
{
struct tm T = { 0 };
- if ( _stscanf(buf, _T("%04d-%02d-%02dT%02d:%02d:%02dZ"), &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec) != 6) {
+ if (_stscanf(buf, _T("%04d-%02d-%02dT%02d:%02d:%02dZ"), &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec) != 6) {
int boo;
- if ( _stscanf(buf, _T("%04d-%02d-%02dT%02d:%02d:%02d.%dZ"), &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec, &boo) != 7)
+ if (_stscanf(buf, _T("%04d-%02d-%02dT%02d:%02d:%02d.%dZ"), &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec, &boo) != 7)
return 0;
}
@@ -1007,7 +1011,7 @@ void JabberCopyText(HWND hwnd, const TCHAR *text) OpenClipboard(hwnd);
EmptyClipboard();
- HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(TCHAR)*(lstrlen(text)+1));
+ HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(TCHAR)*(lstrlen(text) + 1));
TCHAR *s = (TCHAR *)GlobalLock(hMem);
lstrcpy(s, text);
GlobalUnlock(hMem);
@@ -1131,7 +1135,7 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param) if (cmpsha == NULL || strnicmp(cmpsha, buffer, sizeof(buffer))) {
TCHAR tszFileName[MAX_PATH];
GetAvatarFileName(AI.hContact, tszFileName, SIZEOF(tszFileName));
- _tcsncpy(AI.filename, tszFileName, SIZEOF(AI.filename));
+ _tcsncpy_s(AI.filename, tszFileName, SIZEOF(AI.filename));
FILE* out = _tfopen(tszFileName, _T("wb"));
if (out != NULL) {
fwrite(res->pData, res->dataLength, 1, out);
@@ -1151,4 +1155,4 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param) delete &avs;
if (hHttpCon)
Netlib_CloseHandle(hHttpCon);
-}
\ No newline at end of file +}
diff --git a/protocols/JabberG/src/jabber_xstatus.cpp b/protocols/JabberG/src/jabber_xstatus.cpp index b678dedbc2..20b4175b2a 100644 --- a/protocols/JabberG/src/jabber_xstatus.cpp +++ b/protocols/JabberG/src/jabber_xstatus.cpp @@ -1354,9 +1354,9 @@ INT_PTR __cdecl CJabberProto::OnGetXStatusEx(WPARAM hContact, LPARAM lParam) return 1;
if (pData->flags & CSSF_UNICODE)
- lstrcpynW(pData->pwszName, g_arrMoods[dwXStatus].szName, (STATUS_TITLE_MAX+1));
+ lstrcpynW(pData->pwszName, g_arrMoods[dwXStatus].szName, (STATUS_TITLE_MAX + 1));
else {
- size_t dwStatusTitleSize = lstrlenW( g_arrMoods[dwXStatus].szName );
+ size_t dwStatusTitleSize = lstrlenW(g_arrMoods[dwXStatus].szName);
if (dwStatusTitleSize > STATUS_TITLE_MAX)
dwStatusTitleSize = STATUS_TITLE_MAX;
@@ -1367,14 +1367,14 @@ INT_PTR __cdecl CJabberProto::OnGetXStatusEx(WPARAM hContact, LPARAM lParam) else {
*pData->ptszName = 0;
if (pData->flags & CSSF_UNICODE) {
- ptrT title( ReadAdvStatusT(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TITLE));
+ ptrT title(ReadAdvStatusT(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TITLE));
if (title)
- _tcsncpy(pData->ptszName, title, STATUS_TITLE_MAX);
+ _tcsncpy_s(pData->ptszName, STATUS_TITLE_MAX, title, _TRUNCATE);
}
else {
- ptrA title( ReadAdvStatusA(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TITLE));
+ ptrA title(ReadAdvStatusA(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TITLE));
if (title)
- strncpy(pData->pszName, title, STATUS_TITLE_MAX);
+ strncpy_s(pData->pszName, STATUS_TITLE_MAX, title, _TRUNCATE);
}
}
}
@@ -1383,14 +1383,14 @@ INT_PTR __cdecl CJabberProto::OnGetXStatusEx(WPARAM hContact, LPARAM lParam) if (pData->flags & CSSF_MASK_MESSAGE) {
*pData->pszMessage = 0;
if (pData->flags & CSSF_UNICODE) {
- ptrT title( ReadAdvStatusT(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TEXT));
+ ptrT title(ReadAdvStatusT(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TEXT));
if (title)
- _tcsncpy(pData->ptszMessage, title, STATUS_TITLE_MAX);
+ _tcsncpy_s(pData->ptszMessage, STATUS_TITLE_MAX, title, _TRUNCATE);
}
else {
- ptrA title( ReadAdvStatusA(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TEXT));
+ ptrA title(ReadAdvStatusA(hContact, ADVSTATUS_MOOD, ADVSTATUS_VAL_TEXT));
if (title)
- strncpy(pData->pszMessage, title, STATUS_TITLE_MAX);
+ strncpy_s(pData->pszMessage, STATUS_TITLE_MAX, title, _TRUNCATE);
}
}
@@ -1481,11 +1481,8 @@ void CJabberProto::WriteAdvStatus(MCONTACT hContact, const char *pszSlot, const mir_snprintf(szSetting, SIZEOF(szSetting), "%s/%s/text", m_szModuleName, pszSlot);
if (pszText)
db_set_ts(hContact, "AdvStatus", szSetting, pszText);
- else {
- // set empty text before db_unset to make resident setting manager happy
- db_set_s(hContact, "AdvStatus", szSetting, "");
+ else
db_unset(hContact, "AdvStatus", szSetting);
- }
}
char* CJabberProto::ReadAdvStatusA(MCONTACT hContact, const char *pszSlot, const char *pszValue)
@@ -1510,13 +1507,13 @@ void g_XstatusIconsInit() TCHAR szFile[MAX_PATH];
GetModuleFileName(hInst, szFile, SIZEOF(szFile));
if (TCHAR *p = _tcsrchr(szFile, '\\'))
- _tcscpy(p+1, _T("..\\Icons\\xstatus_jabber.dll"));
+ _tcscpy(p + 1, _T("..\\Icons\\xstatus_jabber.dll"));
TCHAR szSection[100];
_tcscpy(szSection, _T("Protocols/Jabber/")LPGENT("Moods"));
for (int i = 1; i < SIZEOF(g_arrMoods); i++)
- g_MoodIcons.RegisterIcon(g_arrMoods[i].szTag, szFile, -(200+i), szSection, TranslateTS(g_arrMoods[i].szName));
+ g_MoodIcons.RegisterIcon(g_arrMoods[i].szTag, szFile, -(200 + i), szSection, TranslateTS(g_arrMoods[i].szName));
_tcscpy(szSection, _T("Protocols/Jabber/")LPGENT("Activities"));
for (int k = 0; k < SIZEOF(g_arrActivities); k++) {
|