diff options
Diffstat (limited to 'protocols/JabberG/src/jabber_util.cpp')
-rw-r--r-- | protocols/JabberG/src/jabber_util.cpp | 260 |
1 files changed, 132 insertions, 128 deletions
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 +}
|