summaryrefslogtreecommitdiff
path: root/gweb
diff options
context:
space:
mode:
authorMohamed Abbas <mabbas@linux.intel.com>2010-12-28 14:35:46 -0800
committerMarcel Holtmann <marcel@holtmann.org>2010-12-30 12:29:14 -0800
commit07be2d2c1b6a96535535108092bde5d4a1f714c7 (patch)
tree1081afd0a90f9bdfdb923319bd6f9349f4f644aa /gweb
parentbf33c6d46988ac775e5ae499baab136bacc33ce2 (diff)
downloadconnman-07be2d2c1b6a96535535108092bde5d4a1f714c7.tar.gz
connman-07be2d2c1b6a96535535108092bde5d4a1f714c7.tar.bz2
connman-07be2d2c1b6a96535535108092bde5d4a1f714c7.zip
Handling multiple message-header fields with the same name.
Append all multiple message-header fields with the same name and remove any white space in front of fiels value.
Diffstat (limited to 'gweb')
-rw-r--r--gweb/gweb.c119
1 files changed, 79 insertions, 40 deletions
diff --git a/gweb/gweb.c b/gweb/gweb.c
index c6a76cc5..2f464458 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -653,6 +653,81 @@ static int handle_body(struct web_session *session,
return err;
}
+static void handle_multi_line(struct web_session *session)
+{
+ gsize count;
+ char *str;
+ gchar *value;
+
+ str = session->current_header->str;
+
+ if (str[0] != ' ' && str[0] != '\t')
+ return;
+
+ while (str[0] == ' ' || str[0] == '\t')
+ str++;
+
+ count = str - session->current_header->str;
+ if (count > 0) {
+ g_string_erase(session->current_header, 0, count);
+ g_string_insert_c(session->current_header, 0, ' ');
+ }
+
+ value = g_hash_table_lookup(session->result.headers,
+ session->result.last_key);
+ if (value != NULL) {
+ g_string_insert(session->current_header, 0, value);
+
+ str = session->current_header->str;
+
+ g_hash_table_replace(session->result.headers,
+ g_strdup(session->result.last_key),
+ g_strdup(str));
+ }
+}
+
+static void add_header_field(struct web_session *session)
+{
+ gsize count;
+ guint8 *pos;
+ char *str;
+ gchar *value;
+ gchar *key;
+
+ str = session->current_header->str;
+
+ pos = memchr(str, ':', session->current_header->len);
+ if (pos != NULL) {
+ *pos = '\0';
+ pos++;
+
+ key = g_strdup(str);
+
+ /* remove preceding white spaces */
+ while (*pos == ' ')
+ pos++;
+
+ count = (char *) pos - str;
+
+ g_string_erase(session->current_header, 0, count);
+
+ value = g_hash_table_lookup(session->result.headers, key);
+ if (value != NULL) {
+ g_string_insert_c(session->current_header, 0, ' ');
+ g_string_insert_c(session->current_header, 0, ';');
+
+ g_string_insert(session->current_header, 0, value);
+ }
+
+ str = session->current_header->str;
+ g_hash_table_replace(session->result.headers, key,
+ g_strdup(str));
+
+ g_free(session->result.last_key);
+ session->result.last_key = g_strdup(key);
+ }
+}
+
static gboolean received_data(GIOChannel *channel, GIOCondition cond,
gpointer user_data)
{
@@ -759,46 +834,10 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
debug(session->web, "[header] %s", str);
/* handle multi-line header */
- if (str[0] == ' ' || str[0] == '\t') {
- gchar *value;
-
- while (str[0] == ' ' || str[0] == '\t')
- str++;
-
- count = str - session->current_header->str;
- if (count > 0) {
- g_string_erase(session->current_header,
- 0, count);
- g_string_insert_c(session->current_header,
- 0, ' ');
- }
-
- value = g_hash_table_lookup(session->result.headers,
- session->result.last_key);
- if (value != NULL) {
- g_string_insert(session->current_header,
- 0, value);
-
- str = session->current_header->str;
-
- g_hash_table_replace(session->result.headers,
- g_strdup(session->result.last_key),
- g_strdup(str));
- }
- } else {
- pos = memchr(str, ':', session->current_header->len);
- if (pos != NULL) {
- *pos = '\0';
- pos++;
-
- g_hash_table_replace(session->result.headers,
- g_strdup(str),
- g_strdup((char *)pos));
-
- g_free(session->result.last_key);
- session->result.last_key = g_strdup(str);
- }
- }
+ if (str[0] == ' ' || str[0] == '\t')
+ handle_multi_line(session);
+ else
+ add_header_field(session);
g_string_truncate(session->current_header, 0);
}