summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2020-09-27 14:20:14 +0100
committerVincent Sanders <vince@kyllikki.org>2020-09-27 23:09:56 +0100
commitb1844cbf2a997ccf999286472ffc4d2c4bf79c1e (patch)
tree7bcced07b6e6f64898184179a6778527200eacd1 /content
parentff3b948ac0ee0142535bea9a6ebde57b7056c2eb (diff)
downloadnetsurf-b1844cbf2a997ccf999286472ffc4d2c4bf79c1e.tar.gz
netsurf-b1844cbf2a997ccf999286472ffc4d2c4bf79c1e.tar.bz2
split out about scheme query private handler
Diffstat (limited to 'content')
-rw-r--r--content/fetchers/about/Makefile2
-rw-r--r--content/fetchers/about/about.c192
-rw-r--r--content/fetchers/about/private.h18
-rw-r--r--content/fetchers/about/query.c60
-rw-r--r--content/fetchers/about/query.h36
-rw-r--r--content/fetchers/about/query_privacy.c174
-rw-r--r--content/fetchers/about/query_privacy.h35
7 files changed, 338 insertions, 179 deletions
diff --git a/content/fetchers/about/Makefile b/content/fetchers/about/Makefile
index 52eaece3d..4b3df3eca 100644
--- a/content/fetchers/about/Makefile
+++ b/content/fetchers/about/Makefile
@@ -7,6 +7,8 @@ S_FETCHER_ABOUT := \
choices.c \
config.c \
imagecache.c \
+ query.c \
+ query_privacy.c \
testament.c
# The following files depend on the testament
diff --git a/content/fetchers/about/about.c b/content/fetchers/about/about.c
index 1bc382b57..38ad57527 100644
--- a/content/fetchers/about/about.c
+++ b/content/fetchers/about/about.c
@@ -48,13 +48,15 @@
#include "desktop/system_colour.h"
#include "private.h"
+#include "query.h"
+#include "about.h"
#include "blank.h"
#include "certificate.h"
-#include "imagecache.h"
-#include "atestament.h"
#include "config.h"
#include "choices.h"
-#include "about.h"
+#include "imagecache.h"
+#include "query_privacy.h"
+#include "atestament.h"
typedef bool (*fetch_about_handler)(struct fetch_about_context *);
@@ -219,13 +221,16 @@ nsurl *fetch_about_get_url(struct fetch_about_context *ctx)
}
-/**
- * Generate a 500 server error respnse
- *
- * \param ctx The fetcher context.
- * \return true if handled false if aborted.
- */
-static bool fetch_about_srverror(struct fetch_about_context *ctx)
+/* exported interface documented in about/private.h */
+const struct fetch_multipart_data *
+fetch_about_get_multipart(struct fetch_about_context *ctx)
+{
+ return ctx->multipart;
+}
+
+
+/* exported interface documented in about/private.h */
+bool fetch_about_srverror(struct fetch_about_context *ctx)
{
nserror res;
@@ -422,37 +427,6 @@ get_authentication_description(struct nsurl *url,
}
-/**
- * generate a generic query description
- */
-static nserror
-get_query_description(struct nsurl *url,
- const char *key,
- char **out_str)
-{
- nserror res;
- char *url_s;
- size_t url_l;
- char *str = NULL;
-
- /* get the host in question */
- res = nsurl_get(url, NSURL_HOST, &url_s, &url_l);
- if (res != NSERROR_OK) {
- return res;
- }
-
- /* obtain the description with the url substituted */
- str = messages_get_buff(key, url_s);
- if (str == NULL) {
- res = NSERROR_NOMEM;
- } else {
- *out_str = str;
- }
-
- free(url_s);
-
- return res;
-}
/**
@@ -621,142 +595,6 @@ fetch_about_query_auth_handler_aborted:
}
-/**
- * Handler to generate about scheme privacy query page
- *
- * \param ctx The fetcher context.
- * \return true if handled false if aborted.
- */
-static bool fetch_about_query_privacy_handler(struct fetch_about_context *ctx)
-{
- nserror res;
- char *url_s;
- size_t url_l;
- const char *reason = "";
- const char *title;
- struct nsurl *siteurl = NULL;
- char *description = NULL;
- const char *chainurl = NULL;
- const struct fetch_multipart_data *curmd; /* mutipart data iterator */
-
- /* extract parameters from multipart post data */
- curmd = ctx->multipart;
- while (curmd != NULL) {
- if (strcmp(curmd->name, "siteurl") == 0) {
- res = nsurl_create(curmd->value, &siteurl);
- if (res != NSERROR_OK) {
- return fetch_about_srverror(ctx);
- }
- } else if (strcmp(curmd->name, "reason") == 0) {
- reason = curmd->value;
- } else if (strcmp(curmd->name, "chainurl") == 0) {
- chainurl = curmd->value;
- }
- curmd = curmd->next;
- }
-
- if (siteurl == NULL) {
- return fetch_about_srverror(ctx);
- }
-
- /* content is going to return ok */
- fetch_set_http_code(ctx->fetchh, 200);
-
- /* content type */
- if (fetch_about_send_header(ctx, "Content-Type: text/html; charset=utf-8")) {
- goto fetch_about_query_ssl_handler_aborted;
- }
-
- title = messages_get("PrivacyTitle");
- res = fetch_about_ssenddataf(ctx,
- "<html>\n<head>\n"
- "<title>%s</title>\n"
- "<link rel=\"stylesheet\" type=\"text/css\" "
- "href=\"resource:internal.css\">\n"
- "</head>\n"
- "<body class=\"ns-even-bg ns-even-fg ns-border\" id =\"privacy\">\n"
- "<h1 class=\"ns-border ns-odd-fg-bad\">%s</h1>\n",
- title, title);
- if (res != NSERROR_OK) {
- goto fetch_about_query_ssl_handler_aborted;
- }
-
- res = fetch_about_ssenddataf(ctx,
- "<form method=\"post\""
- " enctype=\"multipart/form-data\">");
- if (res != NSERROR_OK) {
- goto fetch_about_query_ssl_handler_aborted;
- }
-
- res = get_query_description(siteurl,
- "PrivacyDescription",
- &description);
- if (res == NSERROR_OK) {
- res = fetch_about_ssenddataf(ctx, "<div><p>%s</p></div>", description);
- free(description);
- if (res != NSERROR_OK) {
- goto fetch_about_query_ssl_handler_aborted;
- }
- }
-
- if (chainurl == NULL) {
- res = fetch_about_ssenddataf(ctx,
- "<div><p>%s</p></div>"
- "<div><p>%s</p></div>",
- reason,
- messages_get("ViewCertificatesNotPossible"));
- } else {
- res = fetch_about_ssenddataf(ctx,
- "<div><p>%s</p></div>"
- "<div><p><a href=\"%s\" target=\"_blank\">%s</a></p></div>",
- reason,
- chainurl,
- messages_get("ViewCertificates"));
- }
- if (res != NSERROR_OK) {
- goto fetch_about_query_ssl_handler_aborted;
- }
- res = fetch_about_ssenddataf(ctx,
- "<div id=\"buttons\">"
- "<input type=\"submit\" id=\"back\" name=\"back\" "
- "value=\"%s\" class=\"default-action\">"
- "<input type=\"submit\" id=\"proceed\" name=\"proceed\" "
- "value=\"%s\">"
- "</div>",
- messages_get("Backtosafety"),
- messages_get("Proceed"));
- if (res != NSERROR_OK) {
- goto fetch_about_query_ssl_handler_aborted;
- }
-
- res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l);
- if (res != NSERROR_OK) {
- url_s = strdup("");
- }
- res = fetch_about_ssenddataf(ctx,
- "<input type=\"hidden\" name=\"siteurl\" value=\"%s\">",
- url_s);
- free(url_s);
- if (res != NSERROR_OK) {
- goto fetch_about_query_ssl_handler_aborted;
- }
-
- res = fetch_about_ssenddataf(ctx, "</form></body>\n</html>\n");
- if (res != NSERROR_OK) {
- goto fetch_about_query_ssl_handler_aborted;
- }
-
- fetch_about_send_finished(ctx);
-
- nsurl_unref(siteurl);
-
- return true;
-
-fetch_about_query_ssl_handler_aborted:
- nsurl_unref(siteurl);
-
- return false;
-}
/**
diff --git a/content/fetchers/about/private.h b/content/fetchers/about/private.h
index 808a91e79..fcf9b1987 100644
--- a/content/fetchers/about/private.h
+++ b/content/fetchers/about/private.h
@@ -25,6 +25,7 @@
#define NETSURF_CONTENT_FETCHERS_ABOUT_PRIVATE_H
struct fetch_about_context;
+struct fetch_multipart_data;
/**
* set http response code on about response
@@ -43,8 +44,7 @@ bool fetch_about_send_header(struct fetch_about_context *ctx, const char *fmt, .
/**
* send data on the about response
*/
-nserror
-fetch_about_senddata(struct fetch_about_context *ctx, const uint8_t *data, size_t data_len);
+nserror fetch_about_senddata(struct fetch_about_context *ctx, const uint8_t *data, size_t data_len);
/**
* send formatted data on the about response
@@ -57,7 +57,21 @@ nserror fetch_about_ssenddataf(struct fetch_about_context *ctx, const char *fmt,
bool fetch_about_send_finished(struct fetch_about_context *ctx);
/**
+ * Generate a 500 server error respnse
+ *
+ * \param ctx The fetcher context.
+ * \return true if handled false if aborted.
+ */
+bool fetch_about_srverror(struct fetch_about_context *ctx);
+
+/**
+ * get the fetch url
*/
struct nsurl *fetch_about_get_url(struct fetch_about_context *ctx);
+/**
+ * get multipart fetch data
+ */
+const struct fetch_multipart_data *fetch_about_get_multipart(struct fetch_about_context *ctx);
+
#endif
diff --git a/content/fetchers/about/query.c b/content/fetchers/about/query.c
new file mode 100644
index 000000000..7c4e9f442
--- /dev/null
+++ b/content/fetchers/about/query.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * content generator for the about scheme query privacy page
+ */
+
+#include <stdlib.h>
+
+#include "utils/errors.h"
+#include "utils/nsurl.h"
+#include "utils/messages.h"
+
+#include "query.h"
+
+/* exported interface documented in about/query.h */
+nserror
+get_query_description(struct nsurl *url,
+ const char *key,
+ char **out_str)
+{
+ nserror res;
+ char *url_s;
+ size_t url_l;
+ char *str = NULL;
+
+ /* get the host in question */
+ res = nsurl_get(url, NSURL_HOST, &url_s, &url_l);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ /* obtain the description with the url substituted */
+ str = messages_get_buff(key, url_s);
+ if (str == NULL) {
+ res = NSERROR_NOMEM;
+ } else {
+ *out_str = str;
+ }
+
+ free(url_s);
+
+ return res;
+}
diff --git a/content/fetchers/about/query.h b/content/fetchers/about/query.h
new file mode 100644
index 000000000..889a9ecdd
--- /dev/null
+++ b/content/fetchers/about/query.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * about scheme query handlers support interface
+ */
+
+#ifndef NETSURF_CONTENT_FETCHERS_ABOUT_QUERY_H
+#define NETSURF_CONTENT_FETCHERS_ABOUT_QUERY_H
+
+/**
+ * generate a generic query description
+ *
+ * \param url The site url
+ * \param key message key
+ * \param out_str pointer to buffer with output
+ */
+nserror get_query_description(struct nsurl *url, const char *key, char **out_str);
+
+#endif
diff --git a/content/fetchers/about/query_privacy.c b/content/fetchers/about/query_privacy.c
new file mode 100644
index 000000000..030672bab
--- /dev/null
+++ b/content/fetchers/about/query_privacy.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * content generator for the about scheme query privacy page
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "utils/errors.h"
+#include "utils/messages.h"
+#include "content/fetch.h"
+
+#include "private.h"
+#include "query.h"
+#include "query_privacy.h"
+
+/**
+ * Handler to generate about scheme privacy query page
+ *
+ * \param ctx The fetcher context.
+ * \return true if handled false if aborted.
+ */
+bool fetch_about_query_privacy_handler(struct fetch_about_context *ctx)
+{
+ nserror res;
+ char *url_s;
+ size_t url_l;
+ const char *reason = "";
+ const char *title;
+ struct nsurl *siteurl = NULL;
+ char *description = NULL;
+ const char *chainurl = NULL;
+ const struct fetch_multipart_data *curmd; /* mutipart data iterator */
+
+ /* extract parameters from multipart post data */
+ curmd = fetch_about_get_multipart(ctx);
+ while (curmd != NULL) {
+ if (strcmp(curmd->name, "siteurl") == 0) {
+ res = nsurl_create(curmd->value, &siteurl);
+ if (res != NSERROR_OK) {
+ return fetch_about_srverror(ctx);
+ }
+ } else if (strcmp(curmd->name, "reason") == 0) {
+ reason = curmd->value;
+ } else if (strcmp(curmd->name, "chainurl") == 0) {
+ chainurl = curmd->value;
+ }
+ curmd = curmd->next;
+ }
+
+ if (siteurl == NULL) {
+ return fetch_about_srverror(ctx);
+ }
+
+ /* content is going to return ok */
+ fetch_about_set_http_code(ctx, 200);
+
+ /* content type */
+ if (fetch_about_send_header(ctx, "Content-Type: text/html; charset=utf-8")) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+
+ title = messages_get("PrivacyTitle");
+ res = fetch_about_ssenddataf(ctx,
+ "<html>\n<head>\n"
+ "<title>%s</title>\n"
+ "<link rel=\"stylesheet\" type=\"text/css\" "
+ "href=\"resource:internal.css\">\n"
+ "</head>\n"
+ "<body class=\"ns-even-bg ns-even-fg ns-border\" id =\"privacy\">\n"
+ "<h1 class=\"ns-border ns-odd-fg-bad\">%s</h1>\n",
+ title, title);
+ if (res != NSERROR_OK) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+
+ res = fetch_about_ssenddataf(ctx,
+ "<form method=\"post\""
+ " enctype=\"multipart/form-data\">");
+ if (res != NSERROR_OK) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+
+ res = get_query_description(siteurl,
+ "PrivacyDescription",
+ &description);
+ if (res == NSERROR_OK) {
+ res = fetch_about_ssenddataf(ctx, "<div><p>%s</p></div>", description);
+ free(description);
+ if (res != NSERROR_OK) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+ }
+
+ if (chainurl == NULL) {
+ res = fetch_about_ssenddataf(ctx,
+ "<div><p>%s</p></div>"
+ "<div><p>%s</p></div>",
+ reason,
+ messages_get("ViewCertificatesNotPossible"));
+ } else {
+ res = fetch_about_ssenddataf(ctx,
+ "<div><p>%s</p></div>"
+ "<div><p><a href=\"%s\" target=\"_blank\">%s</a></p></div>",
+ reason,
+ chainurl,
+ messages_get("ViewCertificates"));
+ }
+ if (res != NSERROR_OK) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+ res = fetch_about_ssenddataf(ctx,
+ "<div id=\"buttons\">"
+ "<input type=\"submit\" id=\"back\" name=\"back\" "
+ "value=\"%s\" class=\"default-action\">"
+ "<input type=\"submit\" id=\"proceed\" name=\"proceed\" "
+ "value=\"%s\">"
+ "</div>",
+ messages_get("Backtosafety"),
+ messages_get("Proceed"));
+ if (res != NSERROR_OK) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+
+ res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l);
+ if (res != NSERROR_OK) {
+ url_s = strdup("");
+ }
+ res = fetch_about_ssenddataf(ctx,
+ "<input type=\"hidden\" name=\"siteurl\" value=\"%s\">",
+ url_s);
+ free(url_s);
+ if (res != NSERROR_OK) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+
+ res = fetch_about_ssenddataf(ctx, "</form></body>\n</html>\n");
+ if (res != NSERROR_OK) {
+ goto fetch_about_query_ssl_handler_aborted;
+ }
+
+ fetch_about_send_finished(ctx);
+
+ nsurl_unref(siteurl);
+
+ return true;
+
+fetch_about_query_ssl_handler_aborted:
+ nsurl_unref(siteurl);
+
+ return false;
+}
diff --git a/content/fetchers/about/query_privacy.h b/content/fetchers/about/query_privacy.h
new file mode 100644
index 000000000..38ddbe889
--- /dev/null
+++ b/content/fetchers/about/query_privacy.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf.
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * about scheme query privacy handler interface
+ */
+
+#ifndef NETSURF_CONTENT_FETCHERS_ABOUT_QUERY_PRIVACY_H
+#define NETSURF_CONTENT_FETCHERS_ABOUT_QUERY_PRIVACY_H
+
+/**
+ * Handler to generate about scheme query privacy page.
+ *
+ * \param ctx The fetcher context.
+ * \return true if handled false if aborted.
+ */
+bool fetch_about_query_privacy_handler(struct fetch_about_context *ctx);
+
+#endif