From da7904554c476f4e8451cc54f6f3de882c2f03b6 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 23 Sep 2020 08:48:17 +0100 Subject: split out about scheme testament handler --- content/fetchers/about/Makefile | 4 +- content/fetchers/about/about.c | 104 +---------------------------- content/fetchers/about/atestament.h | 35 ++++++++++ content/fetchers/about/testament.c | 129 ++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 104 deletions(-) create mode 100644 content/fetchers/about/atestament.h create mode 100644 content/fetchers/about/testament.c (limited to 'content/fetchers') diff --git a/content/fetchers/about/Makefile b/content/fetchers/about/Makefile index cca22d3c6..142c53398 100644 --- a/content/fetchers/about/Makefile +++ b/content/fetchers/about/Makefile @@ -1,6 +1,6 @@ # about fetcher sources -S_FETCHER_ABOUT := about.c imagecache.c blank.c certificate.c +S_FETCHER_ABOUT := about.c imagecache.c blank.c certificate.c testament.c # The following files depend on the testament -content/fetchers/about/about.c: testament $(OBJROOT)/testament.h +content/fetchers/about/testament.c: testament $(OBJROOT)/testament.h diff --git a/content/fetchers/about/about.c b/content/fetchers/about/about.c index 2ef470bc2..117bd6689 100644 --- a/content/fetchers/about/about.c +++ b/content/fetchers/about/about.c @@ -35,7 +35,6 @@ #include "netsurf/plot_style.h" #include "utils/log.h" -#include "testament.h" #include "utils/corestrings.h" #include "utils/nscolour.h" #include "utils/nsoption.h" @@ -52,6 +51,7 @@ #include "blank.h" #include "certificate.h" #include "imagecache.h" +#include "atestament.h" #include "about.h" typedef bool (*fetch_about_handler)(struct fetch_about_context *); @@ -216,6 +216,7 @@ nsurl *fetch_about_get_url(struct fetch_about_context *ctx) return ctx->url; } + /** * Generate a 500 server error respnse * @@ -243,8 +244,6 @@ static bool fetch_about_srverror(struct fetch_about_context *ctx) } - - /** * Handler to generate about scheme credits page. * @@ -289,9 +288,6 @@ static bool fetch_about_licence_handler(struct fetch_about_context *ctx) } - - - /** * Handler to generate about scheme config page * @@ -502,102 +498,6 @@ fetch_about_choices_handler_aborted: } -typedef struct { - const char *leaf; - const char *modtype; -} modification_t; - -/** - * Generate the text of an svn testament which represents the current - * build-tree status - * - * \param ctx The fetcher context. - * \return true if handled false if aborted. - */ -static bool fetch_about_testament_handler(struct fetch_about_context *ctx) -{ - nserror res; - static modification_t modifications[] = WT_MODIFICATIONS; - int modidx; /* midification index */ - - /* content is going to return ok */ - fetch_set_http_code(ctx->fetchh, 200); - - /* content type */ - if (fetch_about_send_header(ctx, "Content-Type: text/plain")) - goto fetch_about_testament_handler_aborted; - - res = fetch_about_ssenddataf(ctx, - "# Automatically generated by NetSurf build system\n\n"); - if (res != NSERROR_OK) { - goto fetch_about_testament_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, -#if defined(WT_BRANCHISTRUNK) || defined(WT_BRANCHISMASTER) - "# This is a *DEVELOPMENT* build from the main line.\n\n" -#elif defined(WT_BRANCHISTAG) && (WT_MODIFIED == 0) - "# This is a tagged build of NetSurf\n" -#ifdef WT_TAGIS - "# The tag used was '" WT_TAGIS "'\n\n" -#else - "\n" -#endif -#elif defined(WT_NO_SVN) || defined(WT_NO_GIT) - "# This NetSurf was built outside of our revision " - "control environment.\n" - "# This testament is therefore not very useful.\n\n" -#else - "# This NetSurf was built from a branch (" WT_BRANCHPATH ").\n\n" -#endif -#if defined(CI_BUILD) - "# This build carries the CI build number '" CI_BUILD "'\n\n" -#endif - ); - if (res != NSERROR_OK) { - goto fetch_about_testament_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, - "Built by %s (%s) from %s at revision %s on %s\n\n", - GECOS, USERNAME, WT_BRANCHPATH, WT_REVID, WT_COMPILEDATE); - if (res != NSERROR_OK) { - goto fetch_about_testament_handler_aborted; - } - - res = fetch_about_ssenddataf(ctx, "Built on %s in %s\n\n", WT_HOSTNAME, WT_ROOT); - if (res != NSERROR_OK) { - goto fetch_about_testament_handler_aborted; - } - - if (WT_MODIFIED > 0) { - res = fetch_about_ssenddataf(ctx, - "Working tree has %d modification%s\n\n", - WT_MODIFIED, WT_MODIFIED == 1 ? "" : "s"); - } else { - res = fetch_about_ssenddataf(ctx, "Working tree is not modified.\n"); - } - if (res != NSERROR_OK) { - goto fetch_about_testament_handler_aborted; - } - - for (modidx = 0; modidx < WT_MODIFIED; ++modidx) { - res = fetch_about_ssenddataf(ctx, - " %s %s\n", - modifications[modidx].modtype, - modifications[modidx].leaf); - if (res != NSERROR_OK) { - goto fetch_about_testament_handler_aborted; - } - } - - fetch_about_send_finished(ctx); - - return true; - -fetch_about_testament_handler_aborted: - return false; -} /** diff --git a/content/fetchers/about/atestament.h b/content/fetchers/about/atestament.h new file mode 100644 index 000000000..1851e8f3c --- /dev/null +++ b/content/fetchers/about/atestament.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 testament handler interface + */ + +#ifndef NETSURF_CONTENT_FETCHERS_ABOUT_TESTAMENT_H +#define NETSURF_CONTENT_FETCHERS_ABOUT_TESTAMENT_H + +/** + * Handler to generate about scheme testament page. + * + * \param ctx The fetcher context. + * \return true if handled false if aborted. + */ +bool fetch_about_testament_handler(struct fetch_about_context *ctx); + +#endif diff --git a/content/fetchers/about/testament.c b/content/fetchers/about/testament.c new file mode 100644 index 000000000..ae992ec52 --- /dev/null +++ b/content/fetchers/about/testament.c @@ -0,0 +1,129 @@ +/* + * 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 testament page + */ + +#include +#include + +#include "utils/errors.h" +#include "netsurf/inttypes.h" +#include "testament.h" + +#include "private.h" +#include "atestament.h" + +typedef struct { + const char *leaf; + const char *modtype; +} modification_t; + +/** + * Generate the text of an svn testament which represents the current + * build-tree status + * + * \param ctx The fetcher context. + * \return true if handled false if aborted. + */ +bool fetch_about_testament_handler(struct fetch_about_context *ctx) +{ + nserror res; + static modification_t modifications[] = WT_MODIFICATIONS; + int modidx; /* midification index */ + + /* content is going to return ok */ + fetch_about_set_http_code(ctx, 200); + + /* content type */ + if (fetch_about_send_header(ctx, "Content-Type: text/plain")) + goto fetch_about_testament_handler_aborted; + + res = fetch_about_ssenddataf(ctx, + "# Automatically generated by NetSurf build system\n\n"); + if (res != NSERROR_OK) { + goto fetch_about_testament_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, +#if defined(WT_BRANCHISTRUNK) || defined(WT_BRANCHISMASTER) + "# This is a *DEVELOPMENT* build from the main line.\n\n" +#elif defined(WT_BRANCHISTAG) && (WT_MODIFIED == 0) + "# This is a tagged build of NetSurf\n" +#ifdef WT_TAGIS + "# The tag used was '" WT_TAGIS "'\n\n" +#else + "\n" +#endif +#elif defined(WT_NO_SVN) || defined(WT_NO_GIT) + "# This NetSurf was built outside of our revision " + "control environment.\n" + "# This testament is therefore not very useful.\n\n" +#else + "# This NetSurf was built from a branch (" WT_BRANCHPATH ").\n\n" +#endif +#if defined(CI_BUILD) + "# This build carries the CI build number '" CI_BUILD "'\n\n" +#endif + ); + if (res != NSERROR_OK) { + goto fetch_about_testament_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, + "Built by %s (%s) from %s at revision %s on %s\n\n", + GECOS, USERNAME, WT_BRANCHPATH, WT_REVID, WT_COMPILEDATE); + if (res != NSERROR_OK) { + goto fetch_about_testament_handler_aborted; + } + + res = fetch_about_ssenddataf(ctx, "Built on %s in %s\n\n", WT_HOSTNAME, WT_ROOT); + if (res != NSERROR_OK) { + goto fetch_about_testament_handler_aborted; + } + + if (WT_MODIFIED > 0) { + res = fetch_about_ssenddataf(ctx, + "Working tree has %d modification%s\n\n", + WT_MODIFIED, WT_MODIFIED == 1 ? "" : "s"); + } else { + res = fetch_about_ssenddataf(ctx, "Working tree is not modified.\n"); + } + if (res != NSERROR_OK) { + goto fetch_about_testament_handler_aborted; + } + + for (modidx = 0; modidx < WT_MODIFIED; ++modidx) { + res = fetch_about_ssenddataf(ctx, + " %s %s\n", + modifications[modidx].modtype, + modifications[modidx].leaf); + if (res != NSERROR_OK) { + goto fetch_about_testament_handler_aborted; + } + } + + fetch_about_send_finished(ctx); + + return true; + +fetch_about_testament_handler_aborted: + return false; +} -- cgit v1.2.3