From 6a26d1629f92bd6807f76252842306d4146591d0 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 29 Sep 2017 13:27:56 -0400 Subject: mq_about_request(): Parse query string into hash table --- (limited to 'src') diff --git a/src/about.c b/src/about.c index d130534..41338d3 100644 --- a/src/about.c +++ b/src/about.c @@ -19,20 +19,63 @@ * along with Marquee. If not, see . */ +#include + #include #include "about.h" #include "application.h" +GHashTable * +parse_query_string(gchar *str) +{ + GHashTable *hash_table; + gchar *key; + gchar *val; + + hash_table = g_hash_table_new(g_str_hash, g_str_equal); + + while (*str) { + key = str; + for (; *str && *str != '='; ++str); + if (!*str) { + g_hash_table_insert(hash_table, key, NULL); + break; + } + *str = '\0'; + val = ++str; + for (; *str && *str != '&'; ++str); + if (!*str) { + g_hash_table_insert(hash_table, key, val); + break; + } + *str = '\0'; + g_hash_table_insert(hash_table, key, val); + ++str; + } + + return hash_table; +} + void mq_about_request(WebKitURISchemeRequest *request, MqApplication *application) { const gchar *path; + gchar *query_str; + GHashTable *query; gchar *contents; gsize stream_length; GInputStream *stream; path = webkit_uri_scheme_request_get_path(request); + query_str = strchr(webkit_uri_scheme_request_get_uri(request), '?'); + if (query_str && query_str[1]) { + query_str = g_strdup(query_str + 1); + query = parse_query_string(query_str); + } else { + query = NULL; + } + if (g_strcmp0(path, "marquee") == 0) { /* TODO: Respond with an HTML document with a toggle button. */ mq_application_marquee_mode_activate(application); -- cgit v0.9.1