about summary refs log tree commit diff stats
path: root/about.c
diff options
context:
space:
mode:
authorMarco Peereboom <marco@conformal.com>2011-11-02 11:38:06 -0500
committerMarco Peereboom <marco@conformal.com>2011-11-02 11:38:06 -0500
commit1e2fb8e373c651d2cca8c1e00ec4a60f8b1752d8 (patch)
tree4349af9818d2a2e6eb38552abcc1ce8bdce0176b /about.c
parentd28c0498460a52333f1d5a0c9d6d8de264f881a6 (diff)
downloadxombrero-1e2fb8e373c651d2cca8c1e00ec4a60f8b1752d8.tar.gz
Move more stuff into about
Diffstat (limited to 'about.c')
-rw-r--r--about.c152
1 files changed, 150 insertions, 2 deletions
diff --git a/about.c b/about.c
index 8d84fa9..65d0ae1 100644
--- a/about.c
+++ b/about.c
@@ -83,8 +83,6 @@
 #define XT_XTP_FL_LIST		(1)
 #define XT_XTP_FL_REMOVE	(2)
 
-int			ca_cmd(struct tab *, struct karg *);
-int			cookie_show_wl(struct tab *, struct karg *);
 int			js_show_wl(struct tab *, struct karg *);
 int			pl_show_wl(struct tab *, struct karg *);
 int			set(struct tab *, struct karg *);
@@ -311,6 +309,99 @@ stats(struct tab *t, struct karg *args)
 	return (0);
 }
 
+void
+show_certs(struct tab *t, gnutls_x509_crt_t *certs,
+    size_t cert_count, char *title)
+{
+	gnutls_datum_t		cinfo;
+	char			*tmp, *body;
+	int			i;
+
+	body = g_strdup("");
+
+	for (i = 0; i < cert_count; i++) {
+		if (gnutls_x509_crt_print(certs[i], GNUTLS_CRT_PRINT_FULL,
+		    &cinfo))
+			return;
+
+		tmp = body;
+		body = g_strdup_printf("%s<h2>Cert #%d</h2><pre>%s</pre>",
+		    body, i, cinfo.data);
+		gnutls_free(cinfo.data);
+		g_free(tmp);
+	}
+
+	tmp = get_html_page(title, body, "", 0);
+	g_free(body);
+
+	load_webkit_string(t, tmp, XT_URI_ABOUT_CERTS);
+	g_free(tmp);
+}
+
+int
+ca_cmd(struct tab *t, struct karg *args)
+{
+	FILE			*f = NULL;
+	int			rv = 1, certs = 0, certs_read;
+	struct stat		sb;
+	gnutls_datum_t		dt;
+	gnutls_x509_crt_t	*c = NULL;
+	char			*certs_buf = NULL, *s;
+
+	if ((f = fopen(ssl_ca_file, "r")) == NULL) {
+		show_oops(t, "Can't open CA file: %s", ssl_ca_file);
+		return (1);
+	}
+
+	if (fstat(fileno(f), &sb) == -1) {
+		show_oops(t, "Can't stat CA file: %s", ssl_ca_file);
+		goto done;
+	}
+
+	certs_buf = g_malloc(sb.st_size + 1);
+	if (fread(certs_buf, 1, sb.st_size, f) != sb.st_size) {
+		show_oops(t, "Can't read CA file: %s", strerror(errno));
+		goto done;
+	}
+	certs_buf[sb.st_size] = '\0';
+
+	s = certs_buf;
+	while ((s = strstr(s, "BEGIN CERTIFICATE"))) {
+		certs++;
+		s += strlen("BEGIN CERTIFICATE");
+	}
+
+	bzero(&dt, sizeof dt);
+	dt.data = (unsigned char *)certs_buf;
+	dt.size = sb.st_size;
+	c = g_malloc(sizeof(gnutls_x509_crt_t) * certs);
+	certs_read = gnutls_x509_crt_list_import(c, (unsigned int *)&certs, &dt,
+	    GNUTLS_X509_FMT_PEM, 0);
+	if (certs_read <= 0) {
+		show_oops(t, "No cert(s) available");
+		goto done;
+	}
+	show_certs(t, c, certs_read, "Certificate Authority Certificates");
+done:
+	if (c)
+		g_free(c);
+	if (certs_buf)
+		g_free(certs_buf);
+	if (f)
+		fclose(f);
+
+	return (rv);
+}
+
+int
+cookie_show_wl(struct tab *t, struct karg *args)
+{
+	args->i = XT_SHOW | XT_WL_PERSISTENT | XT_WL_SESSION;
+	wl_show(t, args, "Cookie White List", &c_wl);
+
+	return (0);
+}
+
 /*
  * cancel, remove, etc. downloads
  */
@@ -466,6 +557,63 @@ clean:
 	g_free(new_favs);
 }
 
+int
+add_favorite(struct tab *t, struct karg *args)
+{
+	char			file[PATH_MAX];
+	FILE			*f;
+	char			*line = NULL;
+	size_t			urilen, linelen;
+	const gchar		*uri, *title;
+
+	if (t == NULL)
+		return (1);
+
+	/* don't allow adding of xtp pages to favorites */
+	if (t->xtp_meaning != XT_XTP_TAB_MEANING_NORMAL) {
+		show_oops(t, "%s: can't add xtp pages to favorites", __func__);
+		return (1);
+	}
+
+	snprintf(file, sizeof file, "%s/%s", work_dir, XT_FAVS_FILE);
+	if ((f = fopen(file, "r+")) == NULL) {
+		show_oops(t, "Can't open favorites file: %s", strerror(errno));
+		return (1);
+	}
+
+	title = get_title(t, FALSE);
+	uri = get_uri(t);
+
+	if (title == NULL || uri == NULL) {
+		show_oops(t, "can't add page to favorites");
+		goto done;
+	}
+
+	urilen = strlen(uri);
+
+	for (;;) {
+		if ((line = fparseln(f, &linelen, NULL, NULL, 0)) == NULL)
+			if (feof(f) || ferror(f))
+				break;
+
+		if (linelen == urilen && !strcmp(line, uri))
+			goto done;
+
+		free(line);
+		line = NULL;
+	}
+
+	fprintf(f, "\n%s\n%s", title, uri);
+done:
+	if (line)
+		free(line);
+	fclose(f);
+
+	update_favorite_tabs(NULL);
+
+	return (0);
+}
+
 void
 xtp_handle_fl(struct tab *t, uint8_t cmd, int arg)
 {