summaryrefslogtreecommitdiff
path: root/MySpace/NetMessage.cpp
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-07 07:35:41 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-07-07 07:35:41 +0000
commit675c4d3aa28f6589b759062b7c9b151de0b64255 (patch)
tree8cac30050debf7791e33837ebefd1b757f873291 /MySpace/NetMessage.cpp
parenta5a2935911aae732e11d584f8adca39543429155 (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
Diffstat (limited to 'MySpace/NetMessage.cpp')
-rw-r--r--MySpace/NetMessage.cpp59
1 files changed, 23 insertions, 36 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, "&#39;", 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, "&#39;", 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, "&#035;", 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, "&quot;", 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;
}