From cc18b5f21e5c81c87e547b496eb4cf083aafb513 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 13 Mar 2011 11:59:20 +0000 Subject: Initial testament functionality svn path=/trunk/netsurf/; revision=12020 --- content/fetchers/about.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'content') diff --git a/content/fetchers/about.c b/content/fetchers/about.c index 4d6b13ce0..1f441d485 100644 --- a/content/fetchers/about.c +++ b/content/fetchers/about.c @@ -46,6 +46,7 @@ #include "utils/url.h" #include "utils/utils.h" #include "utils/ring.h" +#include "utils/testament.h" struct fetch_about_context; @@ -279,6 +280,88 @@ fetch_about_choices_handler_aborted: return false; } +/** Generate the text of an svn testament which represents the current + * build-tree status + */ +typedef struct { const char *leaf; const char modtype; } modification_t; +static bool fetch_about_testament_handler(struct fetch_about_context *ctx) +{ + static modification_t modifications[] = WT_MODIFICATIONS; + char buffer[1024]; + int code = 200; + int slen; + int i; + + + /* content is going to return ok */ + fetch_set_http_code(ctx->fetchh, code); + + /* content type */ + if (fetch_about_send_header(ctx, "Content-Type: text/plain")) + goto fetch_about_testament_handler_aborted; + + slen = snprintf(buffer, sizeof buffer, + "# Automatically generated by NetSurf build system\n\n"); + + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen, + FETCH_ERROR_NO_ERROR)) + goto fetch_about_testament_handler_aborted; + + slen = snprintf(buffer, sizeof buffer, +#if defined(WT_BRANCHISTRUNK) + "# This is a *DEVELOPMENT* build from the trunk.\n\n" +#elif defined(WT_BRANCHISRELEASE) + "# This is a release build of NetSurf\n\n" +#else + "# This NetSurf was built from a branch.\n\n" +#endif + ); + + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen, + FETCH_ERROR_NO_ERROR)) + goto fetch_about_testament_handler_aborted; + + + slen = snprintf(buffer, sizeof buffer, + "Built by %s (%s) from %s at revision %s\n\n", + GECOS, USERNAME, WT_BRANCHPATH, WT_REVID); + + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen, + FETCH_ERROR_NO_ERROR)) + goto fetch_about_testament_handler_aborted; + + if (WT_MODIFIED > 0) { + slen = snprintf(buffer, sizeof buffer, + "Working tree has %d modification%s\n\n", + WT_MODIFIED, WT_MODIFIED == 1 ? "" : "s"); + } else { + slen = snprintf(buffer, sizeof buffer, + "Working tree is not modified.\n"); + } + + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen, + FETCH_ERROR_NO_ERROR)) + goto fetch_about_testament_handler_aborted; + + for (i = 0; i < WT_MODIFIED; ++i) { + slen = snprintf(buffer, sizeof buffer, + " %c %s\n", + modifications[i].modtype, + modifications[i].leaf); + if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen, + FETCH_ERROR_NO_ERROR)) + goto fetch_about_testament_handler_aborted; + + } + + fetch_about_send_callback(FETCH_FINISHED, ctx, 0, 0, + FETCH_ERROR_NO_ERROR); + + return true; + +fetch_about_testament_handler_aborted: + return false; +} struct about_handlers { const char *name; @@ -290,6 +373,7 @@ struct about_handlers about_handler_list[] = { { "licence", fetch_about_licence_handler }, { "config", fetch_about_config_handler }, { "Choices", fetch_about_choices_handler }, + { "testament", fetch_about_testament_handler }, { "blank", fetch_about_blank_handler } /* The default */ }; -- cgit v1.2.3