From 2a0e0fd2b429af5e8ec151ae3e4fe67c4e4f13ef Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Tue, 9 Oct 2012 15:11:09 +0000 Subject: [PATCH] refactor url handling. there are still some left to be done, will come to it later. SVN revision: 77653 --- src/bin/termio.c | 20 +++++++++----------- src/bin/termiolink.c | 22 ++++++---------------- src/bin/utils.c | 20 +++++++++++++++++++- src/bin/utils.h | 3 +++ 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/bin/termio.c b/src/bin/termio.c index f218f5f2..7fcc5468 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -112,19 +112,17 @@ _activate_link(Evas_Object *obj) if (!config) return; if (!sd->link.string) return; if (link_is_url(sd->link.string)) - url = EINA_TRUE; - else if ((!strncasecmp(sd->link.string, "file://", 7)) || - (!strncasecmp(sd->link.string, "/", 1))) { - path = sd->link.string; - if (!strncasecmp(sd->link.string, "file://", 7)) path = path + 7; - } - else - { - const char *at = strchr(sd->link.string, '@'); - if (at && (strchr(at + 1, '.'))) - email = EINA_TRUE; + if (!strncasecmp(sd->link.string, "file://", 7)) + // TODO: decode string: %XX -> char + path = sd->link.string + sizeof("file://") - 1; + else + url = EINA_TRUE; } + else if (sd->link.string[0] == '/') + path = sd->link.string; + else if (link_is_email(sd->link.string)) + email = EINA_TRUE; s = eina_str_escape(sd->link.string); if (!s) return; diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c index 86a6628b..4fd1302b 100644 --- a/src/bin/termiolink.c +++ b/src/bin/termiolink.c @@ -1,6 +1,7 @@ #include "private.h" #include #include "termio.h" +#include "utils.h" static Eina_Bool coord_back(int *x, int *y, int w, int h __UNUSED__) @@ -56,10 +57,7 @@ _termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r if (!s) break; if (goback) { - if ((!strncasecmp(s, "http://", 7))|| - (!strncasecmp(s, "https://", 8)) || - (!strncasecmp(s, "file://", 7)) || - (!strncasecmp(s, "ftp://", 6))) + if (link_is_protocol(s)) { goback = EINA_FALSE; coord_back(&x1, &y1, w, h); @@ -87,7 +85,7 @@ _termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r else if (s[0] == '<') endmatch = '>'; if ((!strncasecmp((s + 1), "www.", 4)) || (!strncasecmp((s + 1), "ftp.", 4)) || - (!strncasecmp((s + 1), "/", 1))) + (s[1] == '/')) { goback = EINA_FALSE; coord_forward(&x1, &y1, w, h); @@ -160,17 +158,9 @@ _termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r } if ((!isspace(s[0])) && (len > 1)) { - const char *at = strchr(s, '@'); - - if ((at && (strchr(at + 1, '.'))) || - (!strncasecmp(s, "http://", 7))|| - (!strncasecmp(s, "https://", 8)) || - (!strncasecmp(s, "ftp://", 6)) || - (!strncasecmp(s, "file://", 7)) || - (!strncasecmp(s, "www.", 4)) || - (!strncasecmp(s, "ftp.", 4)) || - (!strncasecmp(s, "/", 1)) - ) + if (link_is_email(s) || + link_is_url(s) || + (s[0] == '/')) { if (x1r) *x1r = x1; if (y1r) *y1r = y1; diff --git a/src/bin/utils.c b/src/bin/utils.c index 601931ad..5a39d22f 100644 --- a/src/bin/utils.c +++ b/src/bin/utils.c @@ -52,13 +52,31 @@ theme_auto_reload_enable(Evas_Object *edje) } Eina_Bool -link_is_url(const char *str) +link_is_protocol(const char *str) { if ((!strncasecmp(str, "http://", 7))|| (!strncasecmp(str, "https://", 8)) || (!strncasecmp(str, "ftp://", 6)) || + (!strncasecmp(str, "file://", 7))) + return EINA_TRUE; + return EINA_FALSE; +} + +Eina_Bool +link_is_url(const char *str) +{ + if (link_is_protocol(str) || (!strncasecmp(str, "www.", 4)) || (!strncasecmp(str, "ftp.", 4))) return EINA_TRUE; return EINA_FALSE; } + +Eina_Bool +link_is_email(const char *str) +{ + const char *at = strchr(str, '@'); + if (at && strchr(at + 1, '.')) + return EINA_TRUE; + return EINA_FALSE; +} diff --git a/src/bin/utils.h b/src/bin/utils.h index 7ad93c10..52e9dbfd 100644 --- a/src/bin/utils.h +++ b/src/bin/utils.h @@ -7,6 +7,9 @@ Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group); void theme_reload(Evas_Object *edje); void theme_auto_reload_enable(Evas_Object *edje); + +Eina_Bool link_is_protocol(const char *str); Eina_Bool link_is_url(const char *str); +Eina_Bool link_is_email(const char *str); #endif