From 5be409c981e54efd335f311f082bc6a3dc18fadf Mon Sep 17 00:00:00 2001 From: sje Date: Mon, 2 Jul 2007 04:28:46 +0000 Subject: fix for nick formatting git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@238 4f64403b-2f21-0410-a795-97e2b3489a10 --- MySpace/formatting.cpp | 37 +++++++++++++++++++++++++++++++++++-- MySpace/formatting.h | 7 +++++-- MySpace/nick_dialog.cpp | 4 ++-- MySpace/proto.cpp | 2 +- MySpace/server_con.cpp | 12 ++++++------ MySpace/version.h | 2 +- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/MySpace/formatting.cpp b/MySpace/formatting.cpp index 891f75e..e66d0f6 100644 --- a/MySpace/formatting.cpp +++ b/MySpace/formatting.cpp @@ -1,7 +1,7 @@ #include "common.h" #include "formatting.h" -void entitize(char *buff, int size) { +void entitize_msg(char *buff, int size) { char *tmp = new char[size]; int in = 0, out = 0; @@ -23,7 +23,7 @@ void entitize(char *buff, int size) { buff[size - 1] = 0; } -void unentitize(char *buff) { +void unentitize_msg(char *buff) { int in = 0, out = 0; while(buff[in]) { if(buff[in] == '&') { @@ -45,6 +45,39 @@ void unentitize(char *buff) { buff[out] = 0; } +void entitize_nick(char *buff, int size) { + char *tmp = new char[size]; + + int in = 0, out = 0; + while(buff[in] && out < size) { + switch(buff[in]) { + case '\'': in++; strncpy(tmp + out, "'", size - out); out += 5; break; + default: + tmp[out++] = buff[in++]; + } + } + tmp[out] = 0; + + strncpy(buff, tmp, size); + delete tmp; + buff[size - 1] = 0; +} + +void unentitize_nick(char *buff) { + int in = 0, out = 0; + while(buff[in]) { + if(buff[in] == '&') { + if(strncmp(buff + in, "'", 5) == 0) { + buff[out++] = '\''; in += 5; + } else + buff[out++] = buff[in++]; + } else + buff[out++] = buff[in++]; + } + buff[out] = 0; +} + + void strip_tags(char *buff) { int in = 0, out = 0; while(buff[in]) { diff --git a/MySpace/formatting.h b/MySpace/formatting.h index b7342d2..02b2dec 100644 --- a/MySpace/formatting.h +++ b/MySpace/formatting.h @@ -1,8 +1,11 @@ #ifndef _FORMATTING_INC #define _FORMATTING_INC -void entitize(char *buff, int size); -void unentitize(char *buff); +void entitize_msg(char *buff, int size); +void unentitize_msg(char *buff); + +void entitize_nick(char *buff, int size); +void unentitize_nick(char *buff); void strip_tags(char *buff); diff --git a/MySpace/nick_dialog.cpp b/MySpace/nick_dialog.cpp index eb711b3..83d7402 100644 --- a/MySpace/nick_dialog.cpp +++ b/MySpace/nick_dialog.cpp @@ -27,7 +27,7 @@ void CheckAvailable(HWND hwndDlg, TCHAR *nick) { strncpy(an, nick, 256); #endif char body[512]; - entitize(an, 256); + entitize_nick(an, 256); mir_snprintf(body, 512, "UserName=%s", an); msg.add_string("body", body); @@ -51,7 +51,7 @@ void SetNick(HWND hwndDlg, TCHAR *nick) { strncpy(an, nick, 256); #endif char body[512]; - entitize(an, 256); + entitize_nick(an, 256); mir_snprintf(body, 512, "UserName=%s", an); msg.add_string("body", body); diff --git a/MySpace/proto.cpp b/MySpace/proto.cpp index fbd45ed..80b6ea0 100644 --- a/MySpace/proto.cpp +++ b/MySpace/proto.cpp @@ -158,7 +158,7 @@ int ProtoSendMessage(WPARAM wParam, LPARAM lParam) { } msg_utf[MAX_MESSAGE_SIZE-1] = 0; - entitize(msg_utf, MAX_MESSAGE_SIZE); + entitize_msg(msg_utf, MAX_MESSAGE_SIZE); encode_smileys(msg_utf, MAX_MESSAGE_SIZE); mir_snprintf(msg_fmt, MAX_MESSAGE_SIZE, "

%s

", msg_utf); diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp index 5c3ef1c..0da2449 100644 --- a/MySpace/server_con.cpp +++ b/MySpace/server_con.cpp @@ -434,7 +434,7 @@ void __cdecl ServerThreadFunc(void*) { if(msg.get_string("msg", text, MAX_MESSAGE_SIZE)) { strip_tags(text); decode_smileys(text); - unentitize(text); + unentitize_msg(text); PROTORECVEVENT pre = {0}; pre.flags = PREF_UTF; @@ -467,10 +467,10 @@ void __cdecl ServerThreadFunc(void*) { MYPROTOSEARCHRESULT mpsr = {sizeof(mpsr)}; if(body.get_string("UserName", nick, 256)) { - unentitize(nick); + unentitize_nick(nick); mpsr.psr.nick = nick; } else if(body.get_string("DisplayName", nick, 256)) { - unentitize(nick); + unentitize_nick(nick); mpsr.psr.nick = nick; } if(body.get_string("Email", email, 256)) @@ -495,10 +495,10 @@ void __cdecl ServerThreadFunc(void*) { MYPROTOSEARCHRESULT mpsr = {sizeof(mpsr)}; if(body.get_string("DisplayName", nick, 256)) { - unentitize(nick); + unentitize_nick(nick); mpsr.psr.nick = nick; } else if(body.get_string("UserName", nick, 256)) { - unentitize(nick); + unentitize_nick(nick); mpsr.psr.nick = nick; } @@ -529,7 +529,7 @@ void __cdecl ServerThreadFunc(void*) { int uid = body.get_int("ContactID"); if(uid != 0) { if(body.get_string("NickName", nick, 256)) { - unentitize(nick); + unentitize_nick(nick); DBWriteContactSettingStringUtf(0, MODULE, "Nick", nick); } } diff --git a/MySpace/version.h b/MySpace/version.h index fcb5ed7..775d2aa 100644 --- a/MySpace/version.h +++ b/MySpace/version.h @@ -5,7 +5,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 0 #define __RELEASE_NUM 1 -#define __BUILD_NUM 8 +#define __BUILD_NUM 9 #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM #define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM -- cgit v1.2.3