From 746affa7821662be32df3e2bdff4e52ad8dde270 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 27 Sep 2020 23:10:17 +0100 Subject: split out about scheme query auth handler --- content/fetchers/about/Makefile | 1 + content/fetchers/about/about.c | 216 +------------------------------ content/fetchers/about/query_auth.c | 246 ++++++++++++++++++++++++++++++++++++ content/fetchers/about/query_auth.h | 35 +++++ 4 files changed, 284 insertions(+), 214 deletions(-) create mode 100644 content/fetchers/about/query_auth.c create mode 100644 content/fetchers/about/query_auth.h diff --git a/content/fetchers/about/Makefile b/content/fetchers/about/Makefile index 4b3df3eca..ea6a2d4b6 100644 --- a/content/fetchers/about/Makefile +++ b/content/fetchers/about/Makefile @@ -8,6 +8,7 @@ S_FETCHER_ABOUT := \ config.c \ imagecache.c \ query.c \ + query_auth.c \ query_privacy.c \ testament.c diff --git a/content/fetchers/about/about.c b/content/fetchers/about/about.c index 38ad57527..9f1b3e9cc 100644 --- a/content/fetchers/about/about.c +++ b/content/fetchers/about/about.c @@ -48,13 +48,14 @@ #include "desktop/system_colour.h" #include "private.h" -#include "query.h" #include "about.h" #include "blank.h" #include "certificate.h" #include "config.h" #include "choices.h" #include "imagecache.h" +#include "query.h" +#include "query_auth.h" #include "query_privacy.h" #include "atestament.h" @@ -384,219 +385,6 @@ static bool fetch_about_welcome_handler(struct fetch_about_context *ctx) } -/** - * generate the description of the login query - */ -static nserror -get_authentication_description(struct nsurl *url, - const char *realm, - const char *username, - const char *password, - char **out_str) -{ - nserror res; - char *url_s; - size_t url_l; - char *str = NULL; - const char *key; - - res = nsurl_get(url, NSURL_HOST, &url_s, &url_l); - if (res != NSERROR_OK) { - return res; - } - - if ((*username == 0) && (*password == 0)) { - key = "LoginDescription"; - } else { - key = "LoginAgain"; - } - - str = messages_get_buff(key, url_s, realm); - if (str != NULL) { - NSLOG(netsurf, INFO, - "key:%s url:%s realm:%s str:%s", - key, url_s, realm, str); - *out_str = str; - } else { - res = NSERROR_NOMEM; - } - - free(url_s); - - return res; -} - - - - -/** - * Handler to generate about scheme authentication query page - * - * \param ctx The fetcher context. - * \return true if handled false if aborted. - */ -static bool fetch_about_query_auth_handler(struct fetch_about_context *ctx) -{ - nserror res; - char *url_s; - size_t url_l; - const char *realm = ""; - const char *username = ""; - const char *password = ""; - const char *title; - char *description = NULL; - struct nsurl *siteurl = 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, "realm") == 0) { - realm = curmd->value; - } else if (strcmp(curmd->name, "username") == 0) { - username = curmd->value; - } else if (strcmp(curmd->name, "password") == 0) { - password = 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_auth_handler_aborted; - } - - title = messages_get("LoginTitle"); - res = fetch_about_ssenddataf(ctx, - "\n\n" - "%s\n" - "\n" - "\n" - "\n" - "

%s

\n", - title, title); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, - "
"); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = get_authentication_description(siteurl, - realm, - username, - password, - &description); - if (res == NSERROR_OK) { - res = fetch_about_ssenddataf(ctx, "

%s

", description); - free(description); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - } - - res = fetch_about_ssenddataf(ctx, ""); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, - "" - "" - "" - "", - messages_get("Username"), username); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, - "" - "" - "" - "", - messages_get("Password"), password); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, "
"); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, - "
" - "" - "" - "
", - messages_get("Login"), - messages_get("Cancel")); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l); - if (res != NSERROR_OK) { - url_s = strdup(""); - } - res = fetch_about_ssenddataf(ctx, - "", - url_s); - free(url_s); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, - "", - realm); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, "
\n\n"); - if (res != NSERROR_OK) { - goto fetch_about_query_auth_handler_aborted; - } - - fetch_about_send_finished(ctx); - - nsurl_unref(siteurl); - - return true; - -fetch_about_query_auth_handler_aborted: - - nsurl_unref(siteurl); - - return false; -} - - - - /** * Handler to generate about scheme timeout query page * diff --git a/content/fetchers/about/query_auth.c b/content/fetchers/about/query_auth.c new file mode 100644 index 000000000..1ed2e80ee --- /dev/null +++ b/content/fetchers/about/query_auth.c @@ -0,0 +1,246 @@ +/* + * Copyright 2020 Vincent Sanders + * + * 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 . + */ + +/** + * \file + * content generator for the about scheme query privacy page + */ + +#include +#include +#include +#include +#include +#include + +#include "utils/errors.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "content/fetch.h" + +#include "private.h" +#include "query_auth.h" + + +/** + * generate the description of the login query + */ +static nserror +get_authentication_description(struct nsurl *url, + const char *realm, + const char *username, + const char *password, + char **out_str) +{ + nserror res; + char *url_s; + size_t url_l; + char *str = NULL; + const char *key; + + res = nsurl_get(url, NSURL_HOST, &url_s, &url_l); + if (res != NSERROR_OK) { + return res; + } + + if ((*username == 0) && (*password == 0)) { + key = "LoginDescription"; + } else { + key = "LoginAgain"; + } + + str = messages_get_buff(key, url_s, realm); + if (str != NULL) { + NSLOG(netsurf, INFO, + "key:%s url:%s realm:%s str:%s", + key, url_s, realm, str); + *out_str = str; + } else { + res = NSERROR_NOMEM; + } + + free(url_s); + + return res; +} + + +/** + * Handler to generate about scheme authentication query page + * + * \param ctx The fetcher context. + * \return true if handled false if aborted. + */ +bool fetch_about_query_auth_handler(struct fetch_about_context *ctx) +{ + nserror res; + char *url_s; + size_t url_l; + const char *realm = ""; + const char *username = ""; + const char *password = ""; + const char *title; + char *description = NULL; + struct nsurl *siteurl = 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, "realm") == 0) { + realm = curmd->value; + } else if (strcmp(curmd->name, "username") == 0) { + username = curmd->value; + } else if (strcmp(curmd->name, "password") == 0) { + password = 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_auth_handler_aborted; + } + + title = messages_get("LoginTitle"); + res = fetch_about_ssenddataf(ctx, + "\n\n" + "%s\n" + "\n" + "\n" + "\n" + "

%s

\n", + title, title); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, + "
"); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = get_authentication_description(siteurl, + realm, + username, + password, + &description); + if (res == NSERROR_OK) { + res = fetch_about_ssenddataf(ctx, "

%s

", description); + free(description); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + } + + res = fetch_about_ssenddataf(ctx, ""); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, + "" + "" + "" + "", + messages_get("Username"), username); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, + "" + "" + "" + "", + messages_get("Password"), password); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, "
"); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, + "
" + "" + "" + "
", + messages_get("Login"), + messages_get("Cancel")); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l); + if (res != NSERROR_OK) { + url_s = strdup(""); + } + res = fetch_about_ssenddataf(ctx, + "", + url_s); + free(url_s); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, + "", + realm); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, "
\n\n"); + if (res != NSERROR_OK) { + goto fetch_about_query_auth_handler_aborted; + } + + fetch_about_send_finished(ctx); + + nsurl_unref(siteurl); + + return true; + +fetch_about_query_auth_handler_aborted: + + nsurl_unref(siteurl); + + return false; +} diff --git a/content/fetchers/about/query_auth.h b/content/fetchers/about/query_auth.h new file mode 100644 index 000000000..1c7f658e1 --- /dev/null +++ b/content/fetchers/about/query_auth.h @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Vincent Sanders + * + * 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 . + */ + +/** + * \file + * about scheme query auth handler interface + */ + +#ifndef NETSURF_CONTENT_FETCHERS_ABOUT_QUERY_AUTH_H +#define NETSURF_CONTENT_FETCHERS_ABOUT_QUERY_AUTH_H + +/** + * Handler to generate about scheme query auth page. + * + * \param ctx The fetcher context. + * \return true if handled false if aborted. + */ +bool fetch_about_query_auth_handler(struct fetch_about_context *ctx); + +#endif -- cgit v1.2.3