/* * 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 imagecache page */ #include #include #include "netsurf/types.h" #include "image/image_cache.h" #include "private.h" #include "imagecache.h" /* exported interface documented in about/imagecache.h */ bool fetch_about_imagecache_handler(struct fetch_about_context *ctx) { char buffer[2048]; /* output buffer */ int code = 200; int slen; unsigned int cent_loop = 0; int elen = 0; /* entry length */ nserror res; bool even = false; /* content is going to return ok */ fetch_about_set_http_code(ctx, code); /* content type */ if (fetch_about_send_header(ctx, "Content-Type: text/html")) goto fetch_about_imagecache_handler_aborted; /* page head */ res = fetch_about_ssenddataf(ctx, "\n\n" "Image Cache Status\n" "\n" "\n" "\n" "

Image Cache Status

\n"); if (res != NSERROR_OK) { goto fetch_about_imagecache_handler_aborted; } /* image cache summary */ slen = image_cache_snsummaryf(buffer, sizeof(buffer), "

Configured limit of %a hysteresis of %b

\n" "

Total bitmap size in use %c (in %d)

\n" "

Age %es

\n" "

Peak size %f (in %g)

\n" "

Peak image count %h (size %i)

\n" "

Cache total/hit/miss/fail (counts) %j/%k/%l/%m " "(%pj%%/%pk%%/%pl%%/%pm%%)

\n" "

Cache total/hit/miss/fail (size) %n/%o/%q/%r " "(%pn%%/%po%%/%pq%%/%pr%%)

\n" "

Total images never rendered: %s " "(includes %t that were converted)

\n" "

Total number of excessive conversions: %u " "(from %v images converted more than once)" "

\n" "

Bitmap of size %w had most (%x) conversions

\n" "

Current contents

\n"); if (slen >= (int) (sizeof(buffer))) { goto fetch_about_imagecache_handler_aborted; /* overflow */ } res = fetch_about_senddata(ctx, (const uint8_t *)buffer, slen); if (res != NSERROR_OK) { goto fetch_about_imagecache_handler_aborted; } /* image cache entry table */ res = fetch_about_ssenddataf(ctx, "

\n" "" "Entry" "Content Key" "Redraw Count" "Conversion Count" "Last Redraw" "Bitmap Age" "Bitmap Size" "Source" "\n"); if (res != NSERROR_OK) { goto fetch_about_imagecache_handler_aborted; } slen = 0; do { if (even) { elen = image_cache_snentryf(buffer + slen, sizeof buffer - slen, cent_loop, "" "%e" "%k" "%r" "%c" "%a" "%g" "%s" "%o" "\n"); } else { elen = image_cache_snentryf(buffer + slen, sizeof buffer - slen, cent_loop, "" "%e" "%k" "%r" "%c" "%a" "%g" "%s" "%o" "\n"); } if (elen <= 0) break; /* last option */ if (elen >= (int) (sizeof buffer - slen)) { /* last entry would not fit in buffer, submit buffer */ res = fetch_about_senddata(ctx, (const uint8_t *)buffer, slen); if (res != NSERROR_OK) { goto fetch_about_imagecache_handler_aborted; } slen = 0; } else { /* normal addition */ slen += elen; cent_loop++; even = !even; } } while (elen > 0); slen += snprintf(buffer + slen, sizeof buffer - slen, "

\n\n\n"); res = fetch_about_senddata(ctx, (const uint8_t *)buffer, slen); if (res != NSERROR_OK) { goto fetch_about_imagecache_handler_aborted; } fetch_about_send_finished(ctx); return true; fetch_about_imagecache_handler_aborted: return false; }