[Telepathy-commits] [telepathy-gabble/master] GabbleJingleFactory: parse Google relay HTTP response in a slightly less copy-happy way
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue Mar 3 11:22:45 PST 2009
---
src/jingle-factory.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/jingle-factory.c b/src/jingle-factory.c
index 93c8387..9b88eae 100644
--- a/src/jingle-factory.c
+++ b/src/jingle-factory.c
@@ -939,23 +939,25 @@ on_http_response (SoupSession *soup,
{
for (i = 0; lines[i] != NULL; i++)
{
- gchar ** fields = g_strsplit (lines[i], "=", 2);
+ gchar *delim = strchr (lines[i], '=');
+ size_t len;
- /* we only want lines of format a=b */
- if ((fields != NULL) &&
- (fields[0] != NULL) && (fields[1] != NULL) &&
- (fields[2] == NULL))
+ if (delim == NULL || delim == lines[i])
{
- gchar *key = g_strdup (fields[0]);
- gchar *val = g_strdup (fields[1]);
- gchar *cr = g_utf8_strchr (val, -1, '\r');
- if (cr != NULL)
- *cr = 0;
+ /* ignore empty keys or lines without '=' */
+ continue;
+ }
+
+ len = strlen (lines[i]);
- g_hash_table_insert (map, key, val);
+ if (lines[i][len - 1] == '\r')
+ {
+ lines[i][len - 1] = '\0';
}
- g_strfreev (fields);
+ *delim = '\0';
+ g_hash_table_insert (map, g_strdup (lines[i]),
+ g_strdup (delim + 1));
}
}
--
1.5.6.5
More information about the telepathy-commits
mailing list