diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-09-29 13:27:56 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-09-29 13:27:56 (EDT) |
commit | 6a26d1629f92bd6807f76252842306d4146591d0 (patch) | |
tree | f40dc2c3110ae95f9e445b78824d16d8cf99c8de | |
parent | 6a8b4936b258497f7a6de772e6ccb9ea0194c0b1 (diff) | |
download | marquee-6a26d1629f92bd6807f76252842306d4146591d0.zip marquee-6a26d1629f92bd6807f76252842306d4146591d0.tar.gz marquee-6a26d1629f92bd6807f76252842306d4146591d0.tar.bz2 |
mq_about_request(): Parse query string into hash table
-rw-r--r-- | src/about.c | 43 |
1 files changed, 43 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. */ +#include <string.h> + #include <webkit2/webkit2.h> #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); |