summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-05-29 21:34:40 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-05-29 21:34:40 +0000
commit33d765917eabeb4b664c1b0681d52185920def72 (patch)
tree2c9e2a65aca18a034daada72599fc6531adae7e1 /protocols
parenta66281d8453edde56145e032e8d38db91580ba08 (diff)
no more mir_strncat in GG
git-svn-id: http://svn.miranda-ng.org/main/trunk@13901 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Gadu-Gadu/src/filetransfer.cpp5
-rw-r--r--protocols/Gadu-Gadu/src/gg_proto.cpp24
-rw-r--r--protocols/Gadu-Gadu/src/oauth.cpp18
-rw-r--r--protocols/Gadu-Gadu/src/services.cpp27
4 files changed, 31 insertions, 43 deletions
diff --git a/protocols/Gadu-Gadu/src/filetransfer.cpp b/protocols/Gadu-Gadu/src/filetransfer.cpp
index f0330f7f66..53e3668e3c 100644
--- a/protocols/Gadu-Gadu/src/filetransfer.cpp
+++ b/protocols/Gadu-Gadu/src/filetransfer.cpp
@@ -662,9 +662,8 @@ HANDLE GGPROTO::dccfileallow(HANDLE hTransfer, const PROTOCHAR* szPath)
{
struct gg_dcc *dcc = (struct gg_dcc *) hTransfer;
char fileName[MAX_PATH], *path = mir_t2a(szPath);
- strncpy(fileName, path, sizeof(fileName));
- mir_strncat(fileName, (char*)dcc->file_info.filename, sizeof(fileName) - mir_strlen(fileName));
- dcc->folder = _strdup((char *) path);
+ mir_snprintf(fileName, _countof(fileName), "%s%s", path, dcc->file_info.filename);
+ dcc->folder = _strdup((char*)path);
dcc->tick = 0;
mir_free(path);
diff --git a/protocols/Gadu-Gadu/src/gg_proto.cpp b/protocols/Gadu-Gadu/src/gg_proto.cpp
index 979b77de51..a61ec36c60 100644
--- a/protocols/Gadu-Gadu/src/gg_proto.cpp
+++ b/protocols/Gadu-Gadu/src/gg_proto.cpp
@@ -303,10 +303,6 @@ HANDLE GGPROTO::SearchBasic(const PROTOCHAR *id)
HANDLE GGPROTO::SearchByName(const PROTOCHAR *nick, const PROTOCHAR *firstName, const PROTOCHAR *lastName)
{
- gg_pubdir50_t req;
- unsigned long crc;
- char data[512] = "\0";
-
// Check if connected and if there's a search data
if (!isonline())
return 0;
@@ -314,8 +310,8 @@ HANDLE GGPROTO::SearchByName(const PROTOCHAR *nick, const PROTOCHAR *firstName,
if (!nick && !firstName && !lastName)
return 0;
- if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH)))
- {
+ gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);
+ if (req == NULL) {
#ifdef DEBUGMODE
debugLogA("SearchByName(): ForkThread 12 GGPROTO::searchthread");
#endif
@@ -324,33 +320,33 @@ HANDLE GGPROTO::SearchByName(const PROTOCHAR *nick, const PROTOCHAR *firstName,
}
// Add nick,firstName,lastName and search it
+ CMStringA szQuery;
if (nick)
{
T2Utf nick_utf8(nick);
gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nick_utf8);
- mir_strncat(data, nick_utf8, sizeof(data) - mir_strlen(data));
+ szQuery.Append(nick_utf8);
}
- mir_strncat(data, ".", sizeof(data) - mir_strlen(data));
+ szQuery.AppendChar('.');
if (firstName)
{
T2Utf firstName_utf8(firstName);
gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8);
- mir_strncat(data, firstName_utf8, sizeof(data) - mir_strlen(data));
+ szQuery.Append(firstName_utf8);
}
- mir_strncat(data, ".", sizeof(data) - mir_strlen(data));
+ szQuery.AppendChar('.');
if (lastName)
{
T2Utf lastName_utf8(lastName);
gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8);
- mir_strncat(data, lastName_utf8, sizeof(data) - mir_strlen(data));
+ szQuery.Append(lastName_utf8);
}
- mir_strncat(data, ".", sizeof(data) - mir_strlen(data));
+ szQuery.AppendChar('.');
// Count crc & check if the data was equal if yes do same search with shift
- crc = crc_get(data);
-
+ unsigned long crc = crc_get(szQuery.GetBuffer());
if (crc == last_crc && next_uin)
gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin));
else
diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp
index 7990753277..14fc85d6ce 100644
--- a/protocols/Gadu-Gadu/src/oauth.cpp
+++ b/protocols/Gadu-Gadu/src/oauth.cpp
@@ -219,19 +219,15 @@ int oauth_sign_request(LIST<OAUTHPARAMETER> &params, const char *httpmethod, con
return 0;
}
-char *oauth_generate_nonce()
+char* oauth_generate_nonce()
{
- char timestamp[22], randnum[16];
- mir_snprintf(timestamp, SIZEOF(timestamp), "%ld", time(NULL));
+ char randnum[16];
CallService(MS_UTILS_GETRANDOM, (WPARAM)sizeof(randnum), (LPARAM)randnum);
- int strSizeB = int(mir_strlen(timestamp) + sizeof(randnum));
- ptrA str((char *)mir_calloc(strSizeB + 1));
- mir_strcpy(str, timestamp);
- mir_strncat(str, randnum, sizeof(randnum));
+ CMStringA str(FORMAT, "%ld%s", time(NULL), randnum);
BYTE digest[16];
- mir_md5_hash((BYTE*)(char*)str, strSizeB, digest);
+ mir_md5_hash((BYTE*)str.GetString(), str.GetLength(), digest);
return bin2hex(digest, sizeof(digest), (char *)mir_alloc(32 + 1));
}
@@ -240,7 +236,7 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD
const char *token, const char *token_secret)
{
int i, size;
- char *res, timestamp[22], *nonce;
+ char *res, timestamp[22];
if (httpmethod == NULL || url == NULL) return NULL;
@@ -254,9 +250,7 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD
};
mir_snprintf(timestamp, SIZEOF(timestamp), "%ld", time(NULL));
oauth_setparam(oauth_parameters, "oauth_timestamp", timestamp);
- nonce = oauth_generate_nonce();
- oauth_setparam(oauth_parameters, "oauth_nonce", nonce);
- mir_free(nonce);
+ oauth_setparam(oauth_parameters, "oauth_nonce", ptrA(oauth_generate_nonce()));
if (token != NULL && *token)
oauth_setparam(oauth_parameters, "oauth_token", token);
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp
index d0f442d872..5b1a2537f9 100644
--- a/protocols/Gadu-Gadu/src/services.cpp
+++ b/protocols/Gadu-Gadu/src/services.cpp
@@ -27,23 +27,22 @@
char *gg_status2db(int status, const char *suffix)
{
char *prefix;
- static char str[64];
-
switch(status) {
- case ID_STATUS_AWAY: prefix = "Away"; break;
- case ID_STATUS_NA: prefix = "Na"; break;
- case ID_STATUS_DND: prefix = "Dnd"; break;
- case ID_STATUS_OCCUPIED: prefix = "Occupied"; break;
- case ID_STATUS_FREECHAT: prefix = "FreeChat"; break;
- case ID_STATUS_ONLINE: prefix = "On"; break;
- case ID_STATUS_OFFLINE: prefix = "Off"; break;
- case ID_STATUS_INVISIBLE: prefix = "Inv"; break;
- case ID_STATUS_ONTHEPHONE: prefix = "Otp"; break;
- case ID_STATUS_OUTTOLUNCH: prefix = "Otl"; break;
+ case ID_STATUS_AWAY: prefix = "Away"; break;
+ case ID_STATUS_NA: prefix = "Na"; break;
+ case ID_STATUS_DND: prefix = "Dnd"; break;
+ case ID_STATUS_OCCUPIED: prefix = "Occupied"; break;
+ case ID_STATUS_FREECHAT: prefix = "FreeChat"; break;
+ case ID_STATUS_ONLINE: prefix = "On"; break;
+ case ID_STATUS_OFFLINE: prefix = "Off"; break;
+ case ID_STATUS_INVISIBLE: prefix = "Inv"; break;
+ case ID_STATUS_ONTHEPHONE: prefix = "Otp"; break;
+ case ID_STATUS_OUTTOLUNCH: prefix = "Otl"; break;
default: return NULL;
}
- strncpy(str, prefix, sizeof(str));
- mir_strncat(str, suffix, sizeof(str) - mir_strlen(str));
+
+ static char str[64];
+ mir_snprintf(str, _countof(str), "%s%s", prefix, suffix);
return str;
}