split out about scheme query private handler

This commit is contained in:
Vincent Sanders 2020-09-27 14:20:14 +01:00
parent ff3b948ac0
commit b1844cbf2a
7 changed files with 338 additions and 179 deletions

View File

@ -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

View File

@ -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;
}
/**

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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