diff options
author | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-07-07 07:35:41 +0000 |
---|---|---|
committer | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-07-07 07:35:41 +0000 |
commit | 675c4d3aa28f6589b759062b7c9b151de0b64255 (patch) | |
tree | 8cac30050debf7791e33837ebefd1b757f873291 | |
parent | a5a2935911aae732e11d584f8adca39543429155 (diff) |
fix list parsing (strange status messages, etc)
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@256 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r-- | MySpace/NetMessage.cpp | 59 | ||||
-rw-r--r-- | MySpace/server_con.cpp | 6 | ||||
-rw-r--r-- | MySpace/version.h | 2 |
3 files changed, 27 insertions, 40 deletions
diff --git a/MySpace/NetMessage.cpp b/MySpace/NetMessage.cpp index b158654..4db627a 100644 --- a/MySpace/NetMessage.cpp +++ b/MySpace/NetMessage.cpp @@ -2,7 +2,7 @@ #include "NetMessage.h"
#include <cstdlib>
-NMString::NMString(): text(0), len(0) {
+NMString::NMString(): text(0), len(-1) {
}
NMString::NMString(const NMString &other) {
@@ -32,10 +32,10 @@ const bool NMString::operator==(const char *str) const { NMString &NMString::operator=(const NMString &other) {
int olen = strlen(other.text);
if(olen > len) {
- if(text) delete[] text;
- len = olen;
- text = new char[len + 1];
+ delete[] text;
+ text = new char[olen + 1];
}
+ len = olen;
mir_snprintf(text, len + 1, "%s", other.text);
return *this;
@@ -202,14 +202,15 @@ int Dictionary::parse(char *data, int size) { first = false;
pos += 1;
} else {
- *(data + pos + tl) = 0;
-
- il = strcspn(data + pos, "=");
- *(data + pos + il) = 0;
- key = unescape_inplace(data + pos);
- value = unescape_inplace(data + pos + il + 1);
- KeyValue kv = KeyValue(NMString(key), NMString(value));
- add(kv);
+ if(pos + tl < size) {
+ *(data + pos + tl) = 0;
+ il = strcspn(data + pos, "=");
+ *(data + pos + il) = 0;
+ key = unescape_inplace(data + pos);
+ value = unescape_inplace(data + pos + il + 1);
+ KeyValue kv = KeyValue(NMString(key), NMString(value));
+ add(kv);
+ }
pos += tl + 1;
}
@@ -285,34 +286,20 @@ char *Dictionary::escape(char *val) { int read_pos = 0, write_pos = 0;
while(read_pos < len) {
if(val[read_pos] == '\'') {
- buff[write_pos++] = '&';
- buff[write_pos++] = '#';
- buff[write_pos++] = '3';
- buff[write_pos++] = '9';
- buff[write_pos++] = ';';
+ strncpy(buff + write_pos, "'", 5);
+ write_pos += 5;
read_pos++;
} else if(val[read_pos] == '`') {
- buff[write_pos++] = '&';
- buff[write_pos++] = '#';
- buff[write_pos++] = '3';
- buff[write_pos++] = '9';
- buff[write_pos++] = ';';
+ strncpy(buff + write_pos, "'", 5);
+ write_pos += 5;
read_pos++;
} else if(val[read_pos] == '#') {
- buff[write_pos++] = '&';
- buff[write_pos++] = '#';
- buff[write_pos++] = '0';
- buff[write_pos++] = '3';
- buff[write_pos++] = '5';
- buff[write_pos++] = ';';
+ strncpy(buff + write_pos, "#", 6);
+ write_pos += 6;
read_pos++;
} else if(val[read_pos] == '\"') {
- buff[write_pos++] = '&';
- buff[write_pos++] = 'q';
- buff[write_pos++] = 'u';
- buff[write_pos++] = 'o';
- buff[write_pos++] = 't';
- buff[write_pos++] = ';';
+ strncpy(buff + write_pos, """, 6);
+ write_pos += 6;
read_pos++;
} else {
buff[write_pos++] = val[read_pos++];
@@ -425,7 +412,7 @@ Dictionary NetMessage::get_dict(char *key) { Dictionary d;
char t[4096];
if(get_string(key, t, 4096)) {
- d.parse(t, strlen(t));
+ d.parse(t, strlen(t) + 1);
}
return d;
}
@@ -434,7 +421,7 @@ PipedStringList NetMessage::get_list(char *key) { PipedStringList l;
char t[4096];
if(get_string(key, t, 4096)) {
- l.parse(t, strlen(t));
+ l.parse(t, strlen(t) + 1);
}
return l;
}
diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp index e81db37..eff0c90 100644 --- a/MySpace/server_con.cpp +++ b/MySpace/server_con.cpp @@ -42,7 +42,6 @@ bool WriteData(char *fn, int fn_size, char *data, int data_size) { mir_snprintf(szTempFileName, MAX_PATH, "%s%s", szTempPath, fn);
mir_snprintf(fn, fn_size, "%s", szTempFileName);
- // prepend dir to filename & create dir?
HANDLE hSaveFile = CreateFileA(fn, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hSaveFile == INVALID_HANDLE_VALUE) return false;
@@ -265,8 +264,8 @@ void ParseStatusMessage(HANDLE hContact, PipedStringList &l) { DBWriteContactSettingDword(hContact, MODULE, "IdleTS", 0);
}
char smsg[512];
- l.get_string(3, smsg, 512);
- DBWriteContactSettingStringUtf(hContact, MODULE, "StatusMsg", smsg);
+ if(l.get_string(3, smsg, 512))
+ DBWriteContactSettingStringUtf(hContact, MODULE, "StatusMsg", smsg);
}
void __cdecl ServerThreadFunc(void*) {
@@ -348,6 +347,7 @@ void __cdecl ServerThreadFunc(void*) { //PUShowMessage("Not first packet", SM_NOTIFY);
}
+ *(end - 1) = 0;
NetMessage msg;
msg.parse(pbuff, end - pbuff);
if(msg.exists(NMString("error"))) {
diff --git a/MySpace/version.h b/MySpace/version.h index 208e491..7cec9f5 100644 --- a/MySpace/version.h +++ b/MySpace/version.h @@ -5,7 +5,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 0
#define __RELEASE_NUM 2
-#define __BUILD_NUM 3
+#define __BUILD_NUM 5
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
#define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM
|