about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJosh Rickmar <jrick@devio.us>2012-08-01 15:32:10 -0400
committerJosh Rickmar <jrick@devio.us>2012-08-01 15:32:10 -0400
commit9ca900cd5e075fd66de3ac87948b15cae589663b (patch)
treebd82b8c9609cbf920c2397b8dec8cba951421aa5
parentb7e09d8dfea47b72af1675bee23b5f33238b26fe (diff)
downloadxombrero-9ca900cd5e075fd66de3ac87948b15cae589663b.tar.gz
Add a :https command
-rw-r--r--about.c28
-rw-r--r--whitelist.c87
-rw-r--r--xombrero.128
-rw-r--r--xombrero.c13
-rw-r--r--xombrero.h4
5 files changed, 149 insertions, 11 deletions
diff --git a/about.c b/about.c
index 10e2bd4..560a795 100644
--- a/about.c
+++ b/about.c
@@ -75,6 +75,7 @@
 
 int			js_show_wl(struct tab *, struct karg *);
 int			pl_show_wl(struct tab *, struct karg *);
+int			https_show_wl(struct tab *, struct karg *);
 int			xtp_page_set(struct tab *, struct karg *);
 int			xtp_page_rt(struct tab *, struct karg *);
 int			marco(struct tab *, struct karg *);
@@ -101,6 +102,7 @@ struct about_type about_list[] = {
 	{ XT_URI_ABOUT_MARCO,		marco },
 	{ XT_URI_ABOUT_STARTPAGE,	startpage },
 	{ XT_URI_ABOUT_PLUGINWL,	pl_show_wl },
+	{ XT_URI_ABOUT_HTTPS,		https_show_wl },
 	{ XT_URI_ABOUT_WEBKIT,		about_webkit },
 	{ XT_URI_ABOUT_SEARCH,		xtp_page_sl },
 	{ XT_URI_ABOUT_RUNTIME,		xtp_page_rt },
@@ -455,6 +457,32 @@ pl_cmd(struct tab *t, struct karg *args)
 	return (0);
 }
 
+int
+https_show_wl(struct tab *t, struct karg *args)
+{
+	args->i = XT_SHOW | XT_WL_PERSISTENT | XT_WL_SESSION;
+	wl_show(t, args, "HTTPS Force List", &force_https);
+
+	return (0);
+}
+
+int
+https_cmd(struct tab *t, struct karg *args)
+{
+	if (args->i & XT_SHOW)
+		wl_show(t, args, "HTTPS Force List", &force_https);
+	else if (args->i & XT_SAVE) {
+		args->i |= XT_WL_RELOAD;
+		wl_save(t, args, XT_WL_HTTPS);
+	} else if (args->i & XT_WL_TOGGLE) {
+		args->i |= XT_WL_RELOAD;
+		toggle_force_https(t, args);
+	} else if (args->i & XT_DELETE)
+		show_oops(t, "https delete' currently unimplemented");
+
+	return (0);
+}
+
 /*
  * cancel, remove, etc. downloads
  */
diff --git a/whitelist.c b/whitelist.c
index 9367a97..819fb7a 100644
--- a/whitelist.c
+++ b/whitelist.c
@@ -56,7 +56,6 @@ struct domain *
 wl_find(const gchar *s, struct domain_list *wl)
 {
 	struct domain		*d = NULL, dfind;
-	char			*match_fqdn;
 	int			i;
 
 	if (s == NULL || wl == NULL)
@@ -64,17 +63,19 @@ wl_find(const gchar *s, struct domain_list *wl)
 	if (strlen(s) < 2)
 		return (NULL);
 
-	for (i = strlen(s) - 1; i >= 0; i--) {
-		if (i == 0 || (i == 1 && s[0] == '.') || s[i] == '.') {
+	for (i = strlen(s) - 1; i >= 0; --i) {
+		if (i == 0 || (s[i] == '.')) {
 			dfind.d = (gchar *)&s[i];
 			d = RB_FIND(domain_list, wl, &dfind);
 			if (d)
 				goto done;
-			dfind.d = g_strdup_printf(".%s", s);
-			d = RB_FIND(domain_list, wl, &dfind);
-			g_free(dfind.d);
-			if (d)
-				goto done;
+			if (i == 0 && s[i] != '.') {
+				dfind.d = g_strdup_printf(".%s", s);
+				d = RB_FIND(domain_list, wl, &dfind);
+				g_free(dfind.d);
+				if (d)
+					goto done;
+			}
 		}
 	}
 
@@ -111,6 +112,9 @@ wl_save(struct tab *t, struct karg *args, int list)
 	case XT_WL_PLUGIN:
 		lst_str = "Plugin";
 		break;
+	case XT_WL_HTTPS:
+		lst_str = "HTTPS";
+		break;
 	default:
 		show_oops(t, "Invalid list id: %d", list);
 		return (1);
@@ -134,6 +138,9 @@ wl_save(struct tab *t, struct karg *args, int list)
 	case XT_WL_PLUGIN:
 		lt = g_strdup_printf("pl_wl=%s", dom);
 		break;
+	case XT_WL_HTTPS:
+		lt = g_strdup_printf("force_https=%s", dom);
+		break;
 	default:
 		/* can't happen */
 		show_oops(t, "Invalid list id: %d", list);
@@ -199,6 +206,14 @@ wl_save(struct tab *t, struct karg *args, int list)
 		}
 		toggle_pl(t, &a);
 		break;
+	case XT_WL_HTTPS:
+		d = wl_find(dom, &force_https);
+		if (!d) {
+			settings_add("force_https", dom);
+			d = wl_find(dom, &force_https);
+		}
+		toggle_force_https(t, &a);
+		break;
 	default:
 		abort(); /* can't happen */
 	}
@@ -260,8 +275,10 @@ wl_show(struct tab *t, struct karg *args, char *title, struct domain_list *wl)
 		load_webkit_string(t, tmp, XT_URI_ABOUT_JSWL);
 	else if (wl == &c_wl)
 		load_webkit_string(t, tmp, XT_URI_ABOUT_COOKIEWL);
-	else
+	else if (wl == &pl_wl)
 		load_webkit_string(t, tmp, XT_URI_ABOUT_PLUGINWL);
+	else if (wl == &force_https)
+		load_webkit_string(t, tmp, XT_URI_ABOUT_HTTPS);
 	g_free(tmp);
 	return (0);
 }
@@ -487,3 +504,55 @@ done:
 	return (0);
 }
 
+int
+toggle_force_https(struct tab *t, struct karg *args)
+{
+	int			es;
+	const gchar		*uri;
+	struct domain		*d;
+	char			*dom = NULL;
+
+	if (args == NULL)
+		return (1);
+
+	uri = get_uri(t);
+	dom = find_domain(uri, args->i);
+
+	if (uri == NULL || dom == NULL ||
+	    webkit_web_view_get_load_status(t->wv) == WEBKIT_LOAD_FAILED) {
+		show_oops(t, "Can't toggle domain in https force list");
+		goto done;
+	}
+	d = wl_find(dom, &force_https);
+
+	if (d == NULL)
+		es = 0;
+	else
+		es = 1;
+
+	if (args->i & XT_WL_TOGGLE)
+		es = !es;
+	else if ((args->i & XT_WL_ENABLE) && es != 1)
+		es = 1;
+	else if ((args->i & XT_WL_DISABLE) && es != 0)
+		es = 0;
+
+	uri = get_uri(t);
+	dom = find_domain(uri, args->i);
+
+	if (es) {
+		args->i |= !XT_WL_PERSISTENT;
+		wl_add(dom, &force_https, args->i);
+	} else {
+		d = wl_find(dom, &force_https);
+		if (d)
+			RB_REMOVE(domain_list, &force_https, d);
+	}
+
+	if (args->i & XT_WL_RELOAD)
+		webkit_web_view_reload(t->wv);
+done:
+	if (dom)
+		g_free(dom);
+	return (0);
+}
diff --git a/xombrero.1 b/xombrero.1
index 66cbcd3..d22eb07 100644
--- a/xombrero.1
+++ b/xombrero.1
@@ -518,6 +518,30 @@ Show global history.
 Show help page.
 .It Cm home
 Go to home URL.
+.It Cm https
+The
+.Cm https
+command is used to manitulate the items in the HTTPS force list.
+Used by itself it expands to
+.Cm https show all .
+.It Cm https save, save fqdn
+Saves the FQDN to the persistant force HTTPS list.
+For example,
+the www.peereboom.us domain would result in saving www.peereboom.us.
+.It Cm https save domain
+Saves the top level domain name to the persistent whitelist.
+For example,
+the www.peereboom.us domain would result in saving .peereboom.us.
+.It Cm https show all
+Show all persistent ans session entries in the HTTPS force list.
+.It Cm https show persistent
+Shows all persistent entries in the HTTPS force list.
+.It Cm https show session
+Shows all session entries in the HTTPS force list.
+.It Cm https toggle, https toggle fqdn
+Toggle this FQDN in the HTTPS force list.
+.It Cm https toggle domain
+Toggle the top level domain in the HTTPS force list.
 .It Cm js
 The
 .Cm js
@@ -527,7 +551,7 @@ Used by itself it expands to
 .It Cm js save, save fqdn
 Saves the FQDN to the persistent whitelist.
 For example,
-the www.peereboom.us domain would result in saving .www.peereboom.us.
+the www.peereboom.us domain would result in saving www.peereboom.us.
 .It Cm js save domain
 Saves the top level domain name to the persistent whitelist.
 For example,
@@ -557,7 +581,7 @@ Used by itself it expands to
 .It Cm plugin save, save fqdn
 Saves the FQDN to the persistent whitelist.
 For example,
-the www.peereboom.us domain would result in saving .www.peereboom.us.
+the www.peereboom.us domain would result in saving www.peereboom.us.
 .It Cm plugin save domain
 Saves the top level domain name to the persistent whitelist.
 For example,
diff --git a/xombrero.c b/xombrero.c
index ea60b7f..7b80c96 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -3326,6 +3326,19 @@ struct cmd {
 	{ "domain",		2,	pl_cmd,			XT_WL_TOGGLE | XT_WL_TOPLEVEL,			0 },
 	{ "fqdn",		2,	pl_cmd,			XT_WL_TOGGLE | XT_WL_FQDN,			0 },
 
+	/* https command */
+	{ "https",		0,	https_cmd,		XT_SHOW | XT_WL_PERSISTENT | XT_WL_SESSION,	0 },
+	{ "save",		1,	https_cmd,		XT_SAVE | XT_WL_FQDN,				0 },
+	{ "domain",		2,	https_cmd,		XT_SAVE | XT_WL_TOPLEVEL,			0 },
+	{ "fqdn",		2,	https_cmd,		XT_SAVE | XT_WL_FQDN,				0 },
+	{ "show",		1,	https_cmd,		XT_SHOW | XT_WL_PERSISTENT | XT_WL_SESSION,	0 },
+	{ "all",		2,	https_cmd,		XT_SHOW | XT_WL_PERSISTENT | XT_WL_SESSION,	0 },
+	{ "persistent",		2,	https_cmd,		XT_SHOW | XT_WL_PERSISTENT,			0 },
+	{ "session",		2,	https_cmd,		XT_SHOW | XT_WL_SESSION,			0 },
+	{ "toggle",		1,	https_cmd,		XT_WL_TOGGLE | XT_WL_FQDN,			0 },
+	{ "domain",		2,	https_cmd,		XT_WL_TOGGLE | XT_WL_TOPLEVEL,			0 },
+	{ "fqdn",		2,	https_cmd,		XT_WL_TOGGLE | XT_WL_FQDN,			0 },
+
 	/* toplevel (domain) command */
 	{ "toplevel",		0,	toplevel_cmd,		XT_WL_TOGGLE | XT_WL_TOPLEVEL | XT_WL_RELOAD,	0 },
 	{ "toggle",		1,	toplevel_cmd,		XT_WL_TOGGLE | XT_WL_TOPLEVEL | XT_WL_RELOAD,	0 },
diff --git a/xombrero.h b/xombrero.h
index 6b27fd6..d5da4d9 100644
--- a/xombrero.h
+++ b/xombrero.h
@@ -443,6 +443,7 @@ char			*tld_get_suffix(const char *);
 #define XT_URI_ABOUT_HISTORY	("history")
 #define XT_URI_ABOUT_JSWL	("jswl")
 #define XT_URI_ABOUT_PLUGINWL	("plwl")
+#define XT_URI_ABOUT_HTTPS	("https")
 #define XT_URI_ABOUT_SET	("set")
 #define XT_URI_ABOUT_STATS	("stats")
 #define XT_URI_ABOUT_MARCO	("marco")
@@ -487,6 +488,7 @@ size_t			about_list_size(void);
 int			cookie_cmd(struct tab *, struct karg *);
 int			js_cmd(struct tab *, struct karg *);
 int			pl_cmd(struct tab *, struct karg *);
+int			https_cmd(struct tab *, struct karg *);
 void			startpage_add(const char *, ...);
 
 /*
@@ -522,6 +524,7 @@ void			startpage_add(const char *, ...);
 #define XT_WL_JAVASCRIPT	(1)
 #define XT_WL_COOKIE		(2)
 #define XT_WL_PLUGIN		(3)
+#define XT_WL_HTTPS		(4)
 
 struct domain {
 	RB_ENTRY(domain)	entry;
@@ -557,6 +560,7 @@ int		wl_save(struct tab *, struct karg *, int);
 int		toggle_cwl(struct tab *, struct karg *);
 int		toggle_js(struct tab *, struct karg *);
 int		toggle_pl(struct tab *, struct karg *);
+int		toggle_force_https(struct tab *, struct karg *);
 
 /* input autofocus */
 void		input_autofocus(struct tab *);