summaryrefslogtreecommitdiff
path: root/protocols/MSN/src/msn_misc.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-06-19 15:20:36 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-06-19 15:20:36 +0000
commit6593f9613819dbc42ffff76a4d7a6d5156b46eae (patch)
treea3fc0bec71e6e2a034620dc4cc68a28ac5a32189 /protocols/MSN/src/msn_misc.cpp
parent0137f837ddf36dfd6e7de6decdc763a62b4fdb2c (diff)
oops, one another creepy piece of junk
git-svn-id: http://svn.miranda-ng.org/main/trunk@17012 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MSN/src/msn_misc.cpp')
-rw-r--r--protocols/MSN/src/msn_misc.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp
index d60db4f4c4..3ac3245410 100644
--- a/protocols/MSN/src/msn_misc.cpp
+++ b/protocols/MSN/src/msn_misc.cpp
@@ -712,33 +712,30 @@ int ThreadData::sendPacket(const char* cmd, const char* fmt, ...)
int ThreadData::sendPacketPayload(const char* cmd, const char *param, const char* fmt, ...)
{
- int thisTrid = 0;
- bool bTopHdr;
-
if (this == NULL) return 0;
- size_t strsize = 512;
- char* str = (char*)mir_alloc(strsize);
-
va_list vararg;
va_start(vararg, fmt);
- thisTrid = InterlockedIncrement(&mTrid);
- int regSz = proto->msnRegistration ? (int)mir_strlen(proto->msnRegistration)+16 : 0;
- int paramStart = mir_snprintf(str, strsize, "%s %d %s ", cmd, thisTrid, param), strSz;
- if (bTopHdr=*fmt=='\b') fmt++;
- while ((strSz = mir_vsnprintf(str + paramStart, strsize - paramStart - regSz - 10, fmt, vararg)) == -1)
- str = (char*)mir_realloc(str, strsize += 512);
- if (strSz && !bTopHdr) strSz+=2;
- paramStart+=mir_snprintf(str+paramStart, strsize - paramStart , "%d\r\n", strSz+regSz);
- if (proto->msnRegistration) paramStart+=mir_snprintf(str+paramStart, strsize - paramStart, "Registration: %s\r\n", proto->msnRegistration);
- if (strSz && !bTopHdr) paramStart+=mir_snprintf(str+paramStart, strsize - paramStart, "\r\n");
- mir_vsnprintf(str + paramStart, strsize - paramStart, fmt, vararg);
- str[strsize - 3] = 0;
+ bool bTopHdr = fmt[0] == '\b';
+ int thisTrid = InterlockedIncrement(&mTrid);
+
+ CMStringA str, payLoad;
+ if (bTopHdr)
+ fmt++;
+
+ if (proto->msnRegistration)
+ payLoad.AppendFormat("Registration: %s\r\n", proto->msnRegistration);
+ if (!bTopHdr)
+ payLoad.Append("\r\n");
+ payLoad.AppendFormatV(fmt, vararg);
va_end(vararg);
- int result = send(str, mir_strlen(str));
- mir_free(str);
+ str.AppendFormat("%s %d %s ", cmd, thisTrid, param);
+ str.AppendFormat("%d\r\n", payLoad.GetLength());
+ str += payLoad;
+
+ int result = send(str, str.GetLength());
return (result > 0) ? thisTrid : -1;
}