viking

webkit based web browser for Enlightenment
Log | Files | Refs | LICENSE

commit 47a79d107e822fca35a2e22179f1cc7a44f9efe9
parent 2c0259e01eb5bf82233970a7a3f321e5f15cb7e6
Author: Kyle Milz <kmilz@ucalgary.ca>
Date:   Fri, 19 Oct 2012 16:16:42 -0600

use uri_sanitize everywhere.

Diffstat:
Msrc/commands.c | 88++++++++-----------------------------------------------------------------------
Msrc/main.c | 46----------------------------------------------
Msrc/utilities.c | 65++++++++++++++++++++++++++++++++++++-----------------------------
Msrc/utilities.h | 4+++-
4 files changed, 48 insertions(+), 155 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -339,95 +339,25 @@ number(const Arg *arg, void *data) return TRUE; } -static char defaultsearch[MAX_SETTING_SIZE] = "d"; - Eina_Bool open_arg(const Arg *arg, void *data) { - // char *argv[64]; - char *s = arg->s, *p = NULL, *new; - Arg a = { .i = NavigationReload }; - int len; - char *search_uri, *search_term; + Arg a = { .i = NavigationReload }; Window_Data *ad = data; - /* - if (embed) { - argv[0] = *args; - argv[1] = "-e"; - argv[2] = winid; - argv[3] = arg->s; - argv[4] = NULL; - } else { - argv[0] = *args; - argv[1] = arg->s; - argv[2] = NULL; - } - */ - - if (!arg->s) - navigate(&a, data); - else if (arg->i == TargetCurrent) { - while(*s == ' ') /* strip leading whitespace */ - ++s; - p = (s + strlen(s) - 1); - while(*p == ' ') /* strip trailing whitespace */ - --p; - *(p + 1) = '\0'; - len = strlen(s); - new = NULL; - /* check for external handlers - if (open_handler(s)) - return TRUE; - */ - /* check for search engines */ - p = strchr(s, ' '); - if (p) { /* check for search engines */ - *p = '\0'; - search_uri = find_uri_for_searchengine(s); - if (search_uri != NULL) { - search_term = soup_uri_encode(p+1, "&"); - new = strdup_printf(search_uri, search_term); - free(search_term); - } - *p = ' '; - } - if (!new) { - if (len > 3 && strstr(s, "://")) { /* valid url? */ - p = new = malloc(len + 1); - while(*s != '\0') { /* strip whitespaces */ - if (*s != ' ') - *(p++) = *s; - ++s; - } - *p = '\0'; - } else if (strcspn(s, "/") == 0 || strcspn(s, "./") == 0) { /* prepend "file://" */ - new = malloc(sizeof("file://") + len); - strcpy(new, "file://"); - memcpy(&new[sizeof("file://") - 1], s, len + 1); - } else if (p || !strchr(s, '.')) { /* whitespaces or no dot? */ - search_uri = find_uri_for_searchengine(defaultsearch); - if (search_uri != NULL) { - search_term = soup_uri_encode(s, "&"); - new = strdup_printf(search_uri, search_term); - free(search_term); - } - } else { /* prepend "http://" */ - new = malloc(sizeof("http://") + len); - strcpy(new, "http://"); - memcpy(&new[sizeof("http://") - 1], s, len + 1); - } - } - // webkit_web_view_load_uri(webview, new); - ewk_view_url_set(ad->cur_buf->view, new); - free(new); - } else { + if (!arg->s) { + navigate(&a, data); + } + else if (arg->i == TargetCurrent) { + ewk_view_url_set(ad->cur_buf->view, uri_sanitize(arg->s)); + } + else { buffer_add(SwitchToBuffer, ad, NULL, NULL); a.i = TargetCurrent; a.s = arg->s; open_arg(&a, ad); } - return TRUE; + return EINA_TRUE; } Eina_Bool diff --git a/src/main.c b/src/main.c @@ -98,41 +98,6 @@ static const Ecore_Getopt options = { } }; -const char* -uri_sanitize(const char *uri) -{ - char *fixed_uri; - char *schema; - char *tmp; - - if (!uri || !*uri) return NULL; - - tmp = strstr(uri, "://"); - if (!tmp || (tmp == uri) || (tmp > (uri + 15))) { - char *new_uri = NULL; - if (ecore_file_exists(uri)) { - schema = "file"; - new_uri = ecore_file_realpath(uri); - } - else - schema = "http"; - - if (asprintf(&fixed_uri, "%s://%s", schema, new_uri ? new_uri : uri) > 0) { - free(new_uri); - return fixed_uri; - } - free(new_uri); - } - else { - Eina_Strbuf *search_url = eina_strbuf_new(); - eina_strbuf_append(search_url, "http://google.com/search?q="); - eina_strbuf_append(search_url, uri); - return eina_strbuf_string_get(search_url); - } - - return NULL; -} - static Eina_Bool session_restore(App_Data *ad) { @@ -315,15 +280,6 @@ setup_main_callbacks(App_Data *ad, const char *cookie_path) } -/* search engines */ -static Searchengine searchengines[] = { - { "d", "https://duckduckgo.com/?q=%s&t=Vimprobable" }, - { "i", "http://ixquick.com/do/metasearch.pl?query=%s" }, - { "w", "https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Special%%3ASearch&search=%s&go=Go" }, - { "wd", "https://secure.wikimedia.org/wikipedia/de/w/index.php?title=Special%%3ASearch&search=%s&go=Go" }, - { "dd", "https://duckduckgo.com/html/?q=%s&t=Vimprobable" }, -}; - static Eina_Bool _client_add(void *data, int type, Ecore_Con_Event_Server_Add *ev) { @@ -480,8 +436,6 @@ elm_main(int argc, char *argv[]) if (!session_save_timer) ERR("Could not register session save timer"); - make_searchengines_list(searchengines, LENGTH(searchengines)); - elm_theme_overlay_add(NULL, "./default.edj"); setup_modkeys(ad); diff --git a/src/utilities.c b/src/utilities.c @@ -20,8 +20,6 @@ #include "jsmn.h" -static Eina_List *dynamic_searchengines = NULL; - void parse(const char *buf); void add_modkeys(char key); int get_modkey(char key); @@ -357,33 +355,6 @@ count_list(Listelement *elementlist) return n; } -void make_searchengines_list(Searchengine *searchengines, int length) -{ - int i; - for (i = 0; i < length; i++, searchengines++) { - dynamic_searchengines = eina_list_prepend(dynamic_searchengines, searchengines); - } -} - -/* find a searchengine with a given handle and return its URI or NULL if - * nothing is found. - * The returned string is internal and must not be freed or modified. */ -char *find_uri_for_searchengine(const char *handle) -{ - Eina_List *l; - - if (dynamic_searchengines != NULL) { - for (l = dynamic_searchengines; l; l = eina_list_next(l)) { - Searchengine *s = (Searchengine*)l->data; - if (!strcmp(s->handle, handle)) { - return s->uri; - } - } - } - - return NULL; -} - Eina_Bool process_line(const char *line, Window_Data *wd) { @@ -829,3 +800,39 @@ make_bf_list(Evas_Object *label, Buffer_Data *bd) elm_object_text_set(label, eina_strbuf_string_steal(buf)); } +const char* +uri_sanitize(const char *uri) +{ + char *fixed_uri; + char *schema; + char *tmp; + + if (!uri || !*uri) return NULL; + + /* TODO: strip whitespace, different search engines */ + tmp = strstr(uri, "://"); + if (!tmp || (tmp == uri) || (tmp > (uri + 15))) { + char *new_uri = NULL; + if (ecore_file_exists(uri)) { + schema = "file"; + new_uri = ecore_file_realpath(uri); + } + else + schema = "http"; + + if (asprintf(&fixed_uri, "%s://%s", schema, new_uri ? new_uri : uri) > 0) { + free(new_uri); + return fixed_uri; + } + free(new_uri); + } + else { + Eina_Strbuf *search_url = eina_strbuf_new(); + eina_strbuf_append(search_url, "http://google.com/search?q="); + eina_strbuf_append(search_url, uri); + return eina_strbuf_string_get(search_url); + } + + return NULL; +} + diff --git a/src/utilities.h b/src/utilities.h @@ -40,8 +40,10 @@ void make_buffer_number(Evas_Object *label, Buffer_Data *bd); void make_favicon(Evas_Object *icon, Buffer_Data *bd); void make_url(Evas_Object *label, Buffer_Data *bd); void make_bf_list(Evas_Object *label, Buffer_Data *bd); - void gui_count_update(Window_Data*); void gui_modkey_update(Window_Data*); void gui_zoom_update(Window_Data*); void gui_scroll_update(Window_Data*); + +const char* uri_sanitize(const char*); +