2011-02-16 02:18:10 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-04-22 00:36:21 +03:00
|
|
|
/**
|
|
|
|
* \file
|
2011-03-17 12:21:02 +03:00
|
|
|
*
|
2014-10-10 16:01:20 +04:00
|
|
|
* URL handling for the "about" scheme.
|
|
|
|
*
|
|
|
|
* Based on the data fetcher by Rob Kendrick
|
2011-03-17 12:21:02 +03:00
|
|
|
* This fetcher provides a simple scheme for the user to access
|
|
|
|
* information from the browser from a known, fixed URL.
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
|
2016-04-22 00:36:21 +03:00
|
|
|
#include <stdlib.h>
|
2011-02-16 02:18:10 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
#include "utils/log.h"
|
2014-04-08 14:40:16 +04:00
|
|
|
#include "testament.h"
|
2016-04-22 00:36:21 +03:00
|
|
|
#include "utils/corestrings.h"
|
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/utils.h"
|
2019-08-06 00:28:52 +03:00
|
|
|
#include "utils/messages.h"
|
2016-04-22 00:36:21 +03:00
|
|
|
#include "utils/ring.h"
|
2014-04-08 14:40:16 +04:00
|
|
|
|
2011-02-16 02:18:10 +03:00
|
|
|
#include "content/fetch.h"
|
2014-06-19 21:27:24 +04:00
|
|
|
#include "content/fetchers.h"
|
2011-02-16 02:18:10 +03:00
|
|
|
#include "content/fetchers/about.h"
|
2016-06-06 16:47:27 +03:00
|
|
|
#include "image/image_cache.h"
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
struct fetch_about_context;
|
|
|
|
|
|
|
|
typedef bool (*fetch_about_handler)(struct fetch_about_context *);
|
|
|
|
|
2019-08-05 17:37:22 +03:00
|
|
|
/**
|
|
|
|
* Context for an about fetch
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
struct fetch_about_context {
|
|
|
|
struct fetch_about_context *r_next, *r_prev;
|
|
|
|
|
|
|
|
struct fetch *fetchh; /**< Handle for this fetch */
|
|
|
|
|
|
|
|
bool aborted; /**< Flag indicating fetch has been aborted */
|
|
|
|
bool locked; /**< Flag indicating entry is already entered */
|
|
|
|
|
2011-09-29 19:31:54 +04:00
|
|
|
nsurl *url; /**< The full url the fetch refers to */
|
2011-02-16 02:18:10 +03:00
|
|
|
|
2019-08-05 17:37:22 +03:00
|
|
|
const struct fetch_multipart_data *multipart; /**< post data */
|
|
|
|
|
2011-02-16 02:18:10 +03:00
|
|
|
fetch_about_handler handler;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct fetch_about_context *ring = NULL;
|
|
|
|
|
2019-08-05 17:37:22 +03:00
|
|
|
/**
|
|
|
|
* handler info for about scheme
|
|
|
|
*/
|
|
|
|
struct about_handlers {
|
|
|
|
const char *name; /**< name to match in url */
|
|
|
|
int name_len;
|
|
|
|
lwc_string *lname; /**< Interned name */
|
|
|
|
fetch_about_handler handler; /**< handler for the url */
|
|
|
|
bool hidden; /**< If entry should be hidden in listing */
|
|
|
|
};
|
|
|
|
|
2019-10-30 21:56:38 +03:00
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
/**
|
|
|
|
* issue fetch callbacks with locking
|
|
|
|
*/
|
|
|
|
static inline bool
|
|
|
|
fetch_about_send_callback(const fetch_msg *msg, struct fetch_about_context *ctx)
|
2011-02-16 02:18:10 +03:00
|
|
|
{
|
|
|
|
ctx->locked = true;
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_send_callback(msg, ctx->fetchh);
|
2011-02-16 02:18:10 +03:00
|
|
|
ctx->locked = false;
|
|
|
|
|
|
|
|
return ctx->aborted;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
static inline bool
|
|
|
|
fetch_about_send_finished(struct fetch_about_context *ctx)
|
|
|
|
{
|
|
|
|
fetch_msg msg;
|
|
|
|
msg.type = FETCH_FINISHED;
|
|
|
|
return fetch_about_send_callback(&msg, ctx);
|
|
|
|
}
|
|
|
|
|
2019-08-05 17:37:22 +03:00
|
|
|
static bool
|
|
|
|
fetch_about_send_header(struct fetch_about_context *ctx, const char *fmt, ...)
|
2011-02-16 02:18:10 +03:00
|
|
|
{
|
|
|
|
char header[64];
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
2011-02-16 02:18:10 +03:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
vsnprintf(header, sizeof header, fmt, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_HEADER;
|
|
|
|
msg.data.header_or_data.buf = (const uint8_t *) header;
|
|
|
|
msg.data.header_or_data.len = strlen(header);
|
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
return fetch_about_send_callback(&msg, ctx);
|
2011-02-16 02:18:10 +03:00
|
|
|
}
|
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
/**
|
|
|
|
* send formatted data on a fetch
|
|
|
|
*/
|
|
|
|
static nserror ssenddataf(struct fetch_about_context *ctx, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
fetch_msg msg;
|
|
|
|
va_list ap;
|
|
|
|
int slen;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
slen = vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (slen >= (int)sizeof(buffer)) {
|
|
|
|
return NSERROR_NOSPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.type = FETCH_DATA;
|
|
|
|
msg.data.header_or_data.buf = (const uint8_t *) buffer;
|
|
|
|
msg.data.header_or_data.len = slen;
|
|
|
|
|
|
|
|
if (fetch_about_send_callback(&msg, ctx)) {
|
|
|
|
return NSERROR_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
nserror res;
|
|
|
|
|
|
|
|
fetch_set_http_code(ctx->fetchh, 500);
|
|
|
|
|
|
|
|
/* content type */
|
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/plain"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
res = ssenddataf(ctx, "Server error 500");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_about_send_finished(ctx);
|
2011-02-16 02:18:10 +03:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to generate about scheme cache page.
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
static bool fetch_about_blank_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
|
|
|
const char buffer[2] = { ' ', '\0' };
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
/* content is going to return ok */
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_set_http_code(ctx->fetchh, 200);
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
/* content type */
|
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/html"))
|
|
|
|
goto fetch_about_blank_handler_aborted;
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_DATA;
|
|
|
|
msg.data.header_or_data.buf = (const uint8_t *) buffer;
|
|
|
|
msg.data.header_or_data.len = strlen(buffer);
|
|
|
|
|
|
|
|
if (fetch_about_send_callback(&msg, ctx))
|
2011-02-16 02:18:10 +03:00
|
|
|
goto fetch_about_blank_handler_aborted;
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_FINISHED;
|
|
|
|
|
|
|
|
fetch_about_send_callback(&msg, ctx);
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_blank_handler_aborted:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
/**
|
|
|
|
* Handler to generate about scheme credits page.
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
static bool fetch_about_credits_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
|
|
|
|
2011-02-24 01:27:55 +03:00
|
|
|
/* content is going to return redirect */
|
|
|
|
fetch_set_http_code(ctx->fetchh, 302);
|
2011-02-16 02:18:10 +03:00
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_REDIRECT;
|
|
|
|
msg.data.redirect = "resource:credits.html";
|
|
|
|
|
|
|
|
fetch_about_send_callback(&msg, ctx);
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-14 04:17:25 +04:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
/**
|
|
|
|
* Handler to generate about scheme licence page.
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
2011-03-13 01:38:00 +03:00
|
|
|
static bool fetch_about_licence_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
|
|
|
|
2011-03-13 01:38:00 +03:00
|
|
|
/* content is going to return redirect */
|
|
|
|
fetch_set_http_code(ctx->fetchh, 302);
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_REDIRECT;
|
|
|
|
msg.data.redirect = "resource:licence.html";
|
|
|
|
|
|
|
|
fetch_about_send_callback(&msg, ctx);
|
2011-03-13 01:38:00 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
2014-10-10 16:01:20 +04:00
|
|
|
/**
|
|
|
|
* Handler to generate about:cache page.
|
2011-10-11 02:41:31 +04:00
|
|
|
*
|
2014-10-10 16:01:20 +04:00
|
|
|
* Shows details of current image cache.
|
2011-10-11 02:41:31 +04:00
|
|
|
*
|
2014-10-10 16:01:20 +04:00
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
2011-10-11 02:41:31 +04:00
|
|
|
*/
|
|
|
|
static bool fetch_about_imagecache_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
2012-03-25 20:42:45 +04:00
|
|
|
char buffer[2048]; /* output buffer */
|
2011-10-11 02:41:31 +04:00
|
|
|
int code = 200;
|
|
|
|
int slen;
|
|
|
|
unsigned int cent_loop = 0;
|
2019-08-08 19:12:42 +03:00
|
|
|
int elen = 0; /* entry length */
|
|
|
|
nserror res;
|
2011-03-13 01:38:00 +03:00
|
|
|
|
2011-10-11 02:41:31 +04:00
|
|
|
/* content is going to return ok */
|
|
|
|
fetch_set_http_code(ctx->fetchh, code);
|
|
|
|
|
|
|
|
/* content type */
|
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/html"))
|
|
|
|
goto fetch_about_imagecache_handler_aborted;
|
|
|
|
|
2011-10-11 11:19:20 +04:00
|
|
|
/* page head */
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<html>\n<head>\n"
|
2011-10-11 02:41:31 +04:00
|
|
|
"<title>NetSurf Browser Image Cache Status</title>\n"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"resource:internal.css\">\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body id =\"cachelist\">\n"
|
|
|
|
"<p class=\"banner\">"
|
|
|
|
"<a href=\"http://www.netsurf-browser.org/\">"
|
|
|
|
"<img src=\"resource:netsurf.png\" alt=\"NetSurf\"></a>"
|
|
|
|
"</p>\n"
|
2019-08-08 19:12:42 +03:00
|
|
|
"<h1>NetSurf Browser Image Cache Status</h1>\n");
|
|
|
|
if (res != NSERROR_OK) {
|
2011-10-11 02:41:31 +04:00
|
|
|
goto fetch_about_imagecache_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2011-10-11 02:41:31 +04:00
|
|
|
|
2011-10-11 11:19:20 +04:00
|
|
|
/* image cache summary */
|
2014-10-10 16:01:20 +04:00
|
|
|
slen = image_cache_snsummaryf(buffer, sizeof(buffer),
|
2012-04-12 17:06:21 +04:00
|
|
|
"<p>Configured limit of %a hysteresis of %b</p>\n"
|
|
|
|
"<p>Total bitmap size in use %c (in %d)</p>\n"
|
|
|
|
"<p>Age %es</p>\n"
|
|
|
|
"<p>Peak size %f (in %g)</p>\n"
|
|
|
|
"<p>Peak image count %h (size %i)</p>\n"
|
2011-10-12 16:34:11 +04:00
|
|
|
"<p>Cache total/hit/miss/fail (counts) %j/%k/%l/%m "
|
2012-04-12 17:06:21 +04:00
|
|
|
"(%pj%%/%pk%%/%pl%%/%pm%%)</p>\n"
|
2011-10-12 16:34:11 +04:00
|
|
|
"<p>Cache total/hit/miss/fail (size) %n/%o/%q/%r "
|
2014-10-10 16:01:20 +04:00
|
|
|
"(%pn%%/%po%%/%pq%%/%pr%%)</p>\n"
|
2011-10-12 16:34:11 +04:00
|
|
|
"<p>Total images never rendered: %s "
|
2012-04-12 17:06:21 +04:00
|
|
|
"(includes %t that were converted)</p>\n"
|
2011-10-12 16:34:11 +04:00
|
|
|
"<p>Total number of excessive conversions: %u "
|
|
|
|
"(from %v images converted more than once)"
|
2012-04-12 17:06:21 +04:00
|
|
|
"</p>\n"
|
|
|
|
"<p>Bitmap of size %w had most (%x) conversions</p>\n"
|
|
|
|
"<h2>Current image cache contents</h2>\n");
|
2019-08-08 19:12:42 +03:00
|
|
|
if (slen >= (int) (sizeof(buffer))) {
|
2011-10-11 11:19:20 +04:00
|
|
|
goto fetch_about_imagecache_handler_aborted; /* overflow */
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2011-10-11 02:41:31 +04:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
/* send image cache summary */
|
|
|
|
msg.type = FETCH_DATA;
|
|
|
|
msg.data.header_or_data.buf = (const uint8_t *) buffer;
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.data.header_or_data.len = slen;
|
2019-08-08 19:12:42 +03:00
|
|
|
if (fetch_about_send_callback(&msg, ctx)) {
|
2011-10-11 02:41:31 +04:00
|
|
|
goto fetch_about_imagecache_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2011-10-11 11:19:20 +04:00
|
|
|
|
|
|
|
/* image cache entry table */
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx, "<p class=\"imagecachelist\">\n"
|
2012-04-12 17:43:57 +04:00
|
|
|
"<strong>"
|
|
|
|
"<span>Entry</span>"
|
|
|
|
"<span>Content Key</span>"
|
|
|
|
"<span>Redraw Count</span>"
|
|
|
|
"<span>Conversion Count</span>"
|
|
|
|
"<span>Last Redraw</span>"
|
|
|
|
"<span>Bitmap Age</span>"
|
|
|
|
"<span>Bitmap Size</span>"
|
|
|
|
"<span>Source</span>"
|
|
|
|
"</strong>\n");
|
2019-08-08 19:12:42 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_imagecache_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
slen = 0;
|
2011-10-11 02:41:31 +04:00
|
|
|
do {
|
2019-08-08 19:12:42 +03:00
|
|
|
elen = image_cache_snentryf(buffer + slen,
|
|
|
|
sizeof buffer - slen,
|
2011-10-11 02:41:31 +04:00
|
|
|
cent_loop,
|
2012-04-12 17:43:57 +04:00
|
|
|
"<a href=\"%U\">"
|
|
|
|
"<span>%e</span>"
|
|
|
|
"<span>%k</span>"
|
|
|
|
"<span>%r</span>"
|
|
|
|
"<span>%c</span>"
|
|
|
|
"<span>%a</span>"
|
|
|
|
"<span>%g</span>"
|
|
|
|
"<span>%s</span>"
|
|
|
|
"<span>%o</span>"
|
|
|
|
"</a>\n");
|
2019-08-08 19:12:42 +03:00
|
|
|
if (elen <= 0)
|
2011-10-11 02:41:31 +04:00
|
|
|
break; /* last option */
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
if (elen >= (int) (sizeof buffer - slen)) {
|
2011-10-11 02:41:31 +04:00
|
|
|
/* last entry would not fit in buffer, submit buffer */
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.data.header_or_data.len = slen;
|
|
|
|
if (fetch_about_send_callback(&msg, ctx))
|
2011-10-11 02:41:31 +04:00
|
|
|
goto fetch_about_imagecache_handler_aborted;
|
|
|
|
slen = 0;
|
|
|
|
} else {
|
|
|
|
/* normal addition */
|
2019-08-08 19:12:42 +03:00
|
|
|
slen += elen;
|
2011-10-11 02:41:31 +04:00
|
|
|
cent_loop++;
|
|
|
|
}
|
2019-08-08 19:12:42 +03:00
|
|
|
} while (elen > 0);
|
2011-10-11 02:41:31 +04:00
|
|
|
|
2014-10-10 16:01:20 +04:00
|
|
|
slen += snprintf(buffer + slen, sizeof buffer - slen,
|
2012-04-12 17:43:57 +04:00
|
|
|
"</p>\n</body>\n</html>\n");
|
2011-10-11 02:41:31 +04:00
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.data.header_or_data.len = slen;
|
|
|
|
if (fetch_about_send_callback(&msg, ctx))
|
2011-10-11 02:41:31 +04:00
|
|
|
goto fetch_about_imagecache_handler_aborted;
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_about_send_finished(ctx);
|
2011-10-11 02:41:31 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_imagecache_handler_aborted:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
/**
|
|
|
|
* Handler to generate about scheme config page
|
2019-08-08 19:12:42 +03:00
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
2019-08-06 00:28:52 +03:00
|
|
|
*/
|
2011-02-21 00:04:53 +03:00
|
|
|
static bool fetch_about_config_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
2011-02-21 00:04:53 +03:00
|
|
|
char buffer[1024];
|
2019-08-08 19:12:42 +03:00
|
|
|
int slen = 0;
|
2011-02-21 00:04:53 +03:00
|
|
|
unsigned int opt_loop = 0;
|
2019-08-08 19:12:42 +03:00
|
|
|
int elen = 0; /* entry length */
|
|
|
|
nserror res;
|
2011-02-21 00:04:53 +03:00
|
|
|
|
|
|
|
/* content is going to return ok */
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_set_http_code(ctx->fetchh, 200);
|
2011-02-21 00:04:53 +03:00
|
|
|
|
|
|
|
/* content type */
|
2019-08-08 19:12:42 +03:00
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/html")) {
|
|
|
|
goto fetch_about_config_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<html>\n<head>\n"
|
|
|
|
"<title>NetSurf Browser Config</title>\n"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"resource:internal.css\">\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body id =\"configlist\">\n"
|
|
|
|
"<p class=\"banner\">"
|
|
|
|
"<a href=\"http://www.netsurf-browser.org/\">"
|
|
|
|
"<img src=\"resource:netsurf.png\""
|
|
|
|
" alt=\"NetSurf\"></a>"
|
|
|
|
"</p>\n"
|
|
|
|
"<h1>NetSurf Browser Config</h1>\n"
|
|
|
|
"<table class=\"config\">\n"
|
|
|
|
"<tr><th>Option</th>"
|
|
|
|
"<th>Type</th>"
|
|
|
|
"<th>Provenance</th>"
|
|
|
|
"<th>Setting</th></tr>\n");
|
|
|
|
if (res != NSERROR_OK) {
|
2011-02-21 00:04:53 +03:00
|
|
|
goto fetch_about_config_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2011-02-21 00:04:53 +03:00
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_DATA;
|
|
|
|
msg.data.header_or_data.buf = (const uint8_t *) buffer;
|
|
|
|
|
2011-02-21 00:04:53 +03:00
|
|
|
do {
|
2019-08-08 19:12:42 +03:00
|
|
|
elen = nsoption_snoptionf(buffer + slen,
|
2013-05-27 03:32:08 +04:00
|
|
|
sizeof buffer - slen,
|
|
|
|
opt_loop,
|
2013-05-29 00:36:10 +04:00
|
|
|
"<tr><th>%k</th><td>%t</td><td>%p</td><td>%V</td></tr>\n");
|
2019-08-08 19:12:42 +03:00
|
|
|
if (elen <= 0)
|
2011-02-21 00:04:53 +03:00
|
|
|
break; /* last option */
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
if (elen >= (int) (sizeof buffer - slen)) {
|
2011-02-21 00:04:53 +03:00
|
|
|
/* last entry would not fit in buffer, submit buffer */
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.data.header_or_data.len = slen;
|
|
|
|
if (fetch_about_send_callback(&msg, ctx))
|
2011-02-21 00:04:53 +03:00
|
|
|
goto fetch_about_config_handler_aborted;
|
|
|
|
slen = 0;
|
|
|
|
} else {
|
|
|
|
/* normal addition */
|
2019-08-08 19:12:42 +03:00
|
|
|
slen += elen;
|
2011-02-21 00:04:53 +03:00
|
|
|
opt_loop++;
|
|
|
|
}
|
2019-08-08 19:12:42 +03:00
|
|
|
} while (elen > 0);
|
2011-02-21 00:04:53 +03:00
|
|
|
|
2014-10-10 16:01:20 +04:00
|
|
|
slen += snprintf(buffer + slen, sizeof buffer - slen,
|
2011-03-18 15:10:15 +03:00
|
|
|
"</table>\n</body>\n</html>\n");
|
2011-02-21 00:04:53 +03:00
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.data.header_or_data.len = slen;
|
|
|
|
if (fetch_about_send_callback(&msg, ctx))
|
2011-02-21 00:04:53 +03:00
|
|
|
goto fetch_about_config_handler_aborted;
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_about_send_finished(ctx);
|
2011-02-21 00:04:53 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_config_handler_aborted:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-11 02:41:31 +04:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
/**
|
|
|
|
* Generate the text of a Choices file which represents the current
|
2014-10-10 16:01:20 +04:00
|
|
|
* in use options.
|
2019-08-08 19:12:42 +03:00
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
2011-02-21 00:04:53 +03:00
|
|
|
*/
|
|
|
|
static bool fetch_about_choices_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
2011-02-21 00:04:53 +03:00
|
|
|
char buffer[1024];
|
|
|
|
int code = 200;
|
|
|
|
int slen;
|
|
|
|
unsigned int opt_loop = 0;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* 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_choices_handler_aborted;
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_DATA;
|
|
|
|
msg.data.header_or_data.buf = (const uint8_t *) buffer;
|
|
|
|
|
2014-10-10 16:01:20 +04:00
|
|
|
slen = snprintf(buffer, sizeof buffer,
|
2011-02-21 00:04:53 +03:00
|
|
|
"# Automatically generated current NetSurf browser Choices\n");
|
|
|
|
|
|
|
|
do {
|
2014-10-10 16:01:20 +04:00
|
|
|
res = nsoption_snoptionf(buffer + slen,
|
|
|
|
sizeof buffer - slen,
|
|
|
|
opt_loop,
|
2011-02-21 00:04:53 +03:00
|
|
|
"%k:%v\n");
|
2014-10-10 16:01:20 +04:00
|
|
|
if (res <= 0)
|
2011-02-21 00:04:53 +03:00
|
|
|
break; /* last option */
|
|
|
|
|
2011-02-21 02:41:50 +03:00
|
|
|
if (res >= (int) (sizeof buffer - slen)) {
|
2011-02-21 00:04:53 +03:00
|
|
|
/* last entry would not fit in buffer, submit buffer */
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.data.header_or_data.len = slen;
|
|
|
|
if (fetch_about_send_callback(&msg, ctx))
|
2011-02-21 00:04:53 +03:00
|
|
|
goto fetch_about_choices_handler_aborted;
|
|
|
|
slen = 0;
|
|
|
|
} else {
|
|
|
|
/* normal addition */
|
|
|
|
slen += res;
|
|
|
|
opt_loop++;
|
|
|
|
}
|
|
|
|
} while (res > 0);
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.data.header_or_data.len = slen;
|
|
|
|
if (fetch_about_send_callback(&msg, ctx))
|
2011-02-21 00:04:53 +03:00
|
|
|
goto fetch_about_choices_handler_aborted;
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_about_send_finished(ctx);
|
2011-02-21 00:04:53 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_choices_handler_aborted:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *leaf;
|
|
|
|
const char *modtype;
|
|
|
|
} modification_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the text of an svn testament which represents the current
|
2011-03-13 14:59:20 +03:00
|
|
|
* build-tree status
|
2019-08-08 19:12:42 +03:00
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
2011-03-13 14:59:20 +03:00
|
|
|
*/
|
|
|
|
static bool fetch_about_testament_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2019-08-08 19:12:42 +03:00
|
|
|
nserror res;
|
2011-03-17 15:12:55 +03:00
|
|
|
static modification_t modifications[] = WT_MODIFICATIONS;
|
2019-08-08 19:12:42 +03:00
|
|
|
int modidx; /* midification index */
|
2011-03-13 14:59:20 +03:00
|
|
|
|
|
|
|
/* content is going to return ok */
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_set_http_code(ctx->fetchh, 200);
|
2011-03-13 14:59:20 +03:00
|
|
|
|
|
|
|
/* content type */
|
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/plain"))
|
|
|
|
goto fetch_about_testament_handler_aborted;
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"# Automatically generated by NetSurf build system\n\n");
|
|
|
|
if (res != NSERROR_OK) {
|
2011-03-13 14:59:20 +03:00
|
|
|
goto fetch_about_testament_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2014-10-10 16:01:20 +04:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx,
|
2012-06-04 19:48:21 +04:00
|
|
|
#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
|
2014-10-10 16:01:20 +04:00
|
|
|
"# The tag used was '" WT_TAGIS "'\n\n"
|
2012-06-04 19:48:21 +04:00
|
|
|
#else
|
2014-10-10 16:01:20 +04:00
|
|
|
"\n"
|
2012-06-04 19:48:21 +04:00
|
|
|
#endif
|
|
|
|
#elif defined(WT_NO_SVN) || defined(WT_NO_GIT)
|
2011-03-18 15:10:15 +03:00
|
|
|
"# This NetSurf was built outside of our revision "
|
|
|
|
"control environment.\n"
|
2014-10-10 16:01:20 +04:00
|
|
|
"# This testament is therefore not very useful.\n\n"
|
2011-03-13 14:59:20 +03:00
|
|
|
#else
|
2012-06-04 19:48:21 +04:00
|
|
|
"# This NetSurf was built from a branch (" WT_BRANCHPATH ").\n\n"
|
2012-10-06 21:12:57 +04:00
|
|
|
#endif
|
|
|
|
#if defined(CI_BUILD)
|
|
|
|
"# This build carries the CI build number '" CI_BUILD "'\n\n"
|
2011-03-13 14:59:20 +03:00
|
|
|
#endif
|
2011-03-17 15:12:55 +03:00
|
|
|
);
|
2019-08-08 19:12:42 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2011-03-13 14:59:20 +03:00
|
|
|
goto fetch_about_testament_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2011-03-13 14:59:20 +03:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
res = 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) {
|
2011-03-13 14:59:20 +03:00
|
|
|
goto fetch_about_testament_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2014-10-10 16:01:20 +04:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx, "Built on %s in %s\n\n", WT_HOSTNAME, WT_ROOT);
|
|
|
|
if (res != NSERROR_OK) {
|
2011-03-13 15:17:18 +03:00
|
|
|
goto fetch_about_testament_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2014-10-10 16:01:20 +04:00
|
|
|
|
2011-03-17 15:12:55 +03:00
|
|
|
if (WT_MODIFIED > 0) {
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx,
|
2011-03-17 15:12:55 +03:00
|
|
|
"Working tree has %d modification%s\n\n",
|
|
|
|
WT_MODIFIED, WT_MODIFIED == 1 ? "" : "s");
|
|
|
|
} else {
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx, "Working tree is not modified.\n");
|
2011-03-17 15:12:55 +03:00
|
|
|
}
|
2019-08-08 19:12:42 +03:00
|
|
|
if (res != NSERROR_OK) {
|
2011-03-13 14:59:20 +03:00
|
|
|
goto fetch_about_testament_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2014-10-10 16:01:20 +04:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
for (modidx = 0; modidx < WT_MODIFIED; ++modidx) {
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
" %s %s\n",
|
|
|
|
modifications[modidx].modtype,
|
|
|
|
modifications[modidx].leaf);
|
|
|
|
if (res != NSERROR_OK) {
|
2011-03-17 15:12:55 +03:00
|
|
|
goto fetch_about_testament_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2011-03-17 15:12:55 +03:00
|
|
|
}
|
2011-11-09 01:51:42 +04:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_about_send_finished(ctx);
|
2011-03-13 14:59:20 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_testament_handler_aborted:
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-21 00:04:53 +03:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to generate about scheme logo page
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
2011-05-14 04:17:25 +04:00
|
|
|
static bool fetch_about_logo_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2011-11-09 01:51:42 +04:00
|
|
|
fetch_msg msg;
|
|
|
|
|
2011-05-14 04:17:25 +04:00
|
|
|
/* content is going to return redirect */
|
|
|
|
fetch_set_http_code(ctx->fetchh, 302);
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
msg.type = FETCH_REDIRECT;
|
|
|
|
msg.data.redirect = "resource:netsurf.png";
|
|
|
|
|
|
|
|
fetch_about_send_callback(&msg, ctx);
|
2011-05-14 04:17:25 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to generate about scheme welcome page
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
2012-07-21 16:12:51 +04:00
|
|
|
static bool fetch_about_welcome_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
|
|
|
fetch_msg msg;
|
|
|
|
|
|
|
|
/* content is going to return redirect */
|
|
|
|
fetch_set_http_code(ctx->fetchh, 302);
|
|
|
|
|
|
|
|
msg.type = FETCH_REDIRECT;
|
|
|
|
msg.data.redirect = "resource:welcome.html";
|
|
|
|
|
|
|
|
fetch_about_send_callback(&msg, ctx);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to generate about scheme maps page
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
2014-10-22 23:39:43 +04:00
|
|
|
static bool fetch_about_maps_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
|
|
|
fetch_msg msg;
|
|
|
|
|
|
|
|
/* content is going to return redirect */
|
|
|
|
fetch_set_http_code(ctx->fetchh, 302);
|
|
|
|
|
|
|
|
msg.type = FETCH_REDIRECT;
|
|
|
|
msg.data.redirect = "resource:maps.html";
|
|
|
|
|
|
|
|
fetch_about_send_callback(&msg, ctx);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
/**
|
|
|
|
* generate the description of the login query
|
2019-08-06 00:28:52 +03:00
|
|
|
*/
|
|
|
|
static nserror
|
2019-08-07 16:09:37 +03:00
|
|
|
get_authentication_description(struct nsurl *url,
|
|
|
|
const char *realm,
|
|
|
|
const char *username,
|
|
|
|
const char *password,
|
|
|
|
char **out_str)
|
2019-08-06 00:28:52 +03:00
|
|
|
{
|
2019-08-06 15:15:24 +03:00
|
|
|
nserror res;
|
2019-08-06 00:28:52 +03:00
|
|
|
char *url_s;
|
|
|
|
size_t url_l;
|
|
|
|
char *str = NULL;
|
|
|
|
const char *key;
|
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = nsurl_get(url, NSURL_HOST, &url_s, &url_l);
|
2019-08-06 00:28:52 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*username == 0) && (*password == 0)) {
|
|
|
|
key = "LoginDescription";
|
|
|
|
} else {
|
|
|
|
key = "LoginAgain";
|
|
|
|
}
|
|
|
|
|
|
|
|
str = messages_get_buff(key, url_s, realm);
|
2019-10-31 00:26:53 +03:00
|
|
|
if (str != NULL) {
|
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"key:%s url:%s realm:%s str:%s",
|
|
|
|
key, url_s, realm, str);
|
2019-08-06 00:28:52 +03:00
|
|
|
*out_str = str;
|
|
|
|
} else {
|
2019-10-31 00:26:53 +03:00
|
|
|
res = NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(url_s);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2019-08-06 00:28:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
free(url_s);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-07 16:09:37 +03:00
|
|
|
* Handler to generate about scheme authentication query page
|
2019-08-08 19:12:42 +03:00
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
2019-08-06 00:28:52 +03:00
|
|
|
*/
|
|
|
|
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 */
|
2019-08-07 16:09:37 +03:00
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/html; charset=utf-8")) {
|
2019-08-06 00:28:52 +03:00
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
2019-08-07 16:09:37 +03:00
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
title = messages_get("LoginTitle");
|
2019-08-06 15:15:24 +03:00
|
|
|
|
|
|
|
res = ssenddataf(ctx,
|
2019-08-06 00:28:52 +03:00
|
|
|
"<html>\n<head>\n"
|
|
|
|
"<title>%s</title>\n"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"resource:internal.css\">\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body id =\"authentication\">\n"
|
|
|
|
"<h1>%s</h1>\n",
|
|
|
|
title, title);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<form method=\"post\""
|
|
|
|
" enctype=\"multipart/form-data\">");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
2019-08-06 12:07:02 +03:00
|
|
|
|
2019-08-07 16:09:37 +03:00
|
|
|
res = get_authentication_description(siteurl,
|
|
|
|
realm,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
&description);
|
2019-08-06 00:28:52 +03:00
|
|
|
if (res == NSERROR_OK) {
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx, "<p>%s</p>", description);
|
2019-08-06 00:28:52 +03:00
|
|
|
free(description);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
}
|
|
|
|
|
2019-08-07 18:05:45 +03:00
|
|
|
res = ssenddataf(ctx, "<table>");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-07 18:05:45 +03:00
|
|
|
"<tr>"
|
|
|
|
"<th><label for=\"name\">%s:</label></th>"
|
|
|
|
"<td><input type=\"text\" id=\"username\" "
|
|
|
|
"name=\"username\" value=\"%s\"></td>"
|
|
|
|
"</tr>",
|
2019-08-06 00:28:52 +03:00
|
|
|
messages_get("Username"), username);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-07 18:05:45 +03:00
|
|
|
"<tr>"
|
|
|
|
"<th><label for=\"password\">%s:</label></th>"
|
|
|
|
"<td><input type=\"password\" id=\"password\" "
|
|
|
|
"name=\"password\" value=\"%s\"></td>"
|
|
|
|
"</tr>",
|
2019-08-06 00:28:52 +03:00
|
|
|
messages_get("Password"), password);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-07 18:05:45 +03:00
|
|
|
res = ssenddataf(ctx, "</table>");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-06 12:51:31 +03:00
|
|
|
"<div id=\"buttons\">"
|
2019-08-06 00:28:52 +03:00
|
|
|
"<input type=\"submit\" id=\"login\" name=\"login\" "
|
2019-08-09 15:20:08 +03:00
|
|
|
"value=\"%s\" class=\"default-action\">"
|
|
|
|
"<input type=\"submit\" id=\"cancel\" name=\"cancel\" "
|
2019-08-06 00:28:52 +03:00
|
|
|
"value=\"%s\">"
|
|
|
|
"</div>",
|
2019-08-09 15:20:08 +03:00
|
|
|
messages_get("Login"),
|
|
|
|
messages_get("Cancel"));
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
|
|
|
res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
url_s = strdup("");
|
|
|
|
}
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-06 00:28:52 +03:00
|
|
|
"<input type=\"hidden\" name=\"siteurl\" value=\"%s\">",
|
|
|
|
url_s);
|
|
|
|
free(url_s);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-06 00:28:52 +03:00
|
|
|
"<input type=\"hidden\" name=\"realm\" value=\"%s\">",
|
|
|
|
realm);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx, "</form></body>\n</html>\n");
|
|
|
|
if (res != NSERROR_OK) {
|
2019-08-06 00:28:52 +03:00
|
|
|
goto fetch_about_query_auth_handler_aborted;
|
2019-08-06 15:15:24 +03:00
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_about_send_finished(ctx);
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 12:06:09 +03:00
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_query_auth_handler_aborted:
|
2019-08-06 12:06:09 +03:00
|
|
|
|
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-07 16:09:37 +03:00
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
/**
|
2019-08-06 15:15:24 +03:00
|
|
|
* Handler to generate about scheme privacy query page
|
2019-08-08 19:12:42 +03:00
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
2019-08-06 00:28:52 +03:00
|
|
|
*/
|
2019-08-06 15:15:24 +03:00
|
|
|
static bool fetch_about_query_privacy_handler(struct fetch_about_context *ctx)
|
2019-08-06 00:28:52 +03:00
|
|
|
{
|
|
|
|
nserror res;
|
|
|
|
char *url_s;
|
|
|
|
size_t url_l;
|
|
|
|
const char *reason = "";
|
|
|
|
const char *title;
|
|
|
|
struct nsurl *siteurl = NULL;
|
2019-08-06 15:15:24 +03:00
|
|
|
char *description = NULL;
|
2019-08-06 00:28:52 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
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 */
|
2019-08-06 15:15:24 +03:00
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/html; charset=utf-8")) {
|
2019-08-06 00:28:52 +03:00
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
2019-08-06 15:15:24 +03:00
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
|
|
|
title = messages_get("PrivacyTitle");
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-06 00:28:52 +03:00
|
|
|
"<html>\n<head>\n"
|
|
|
|
"<title>%s</title>\n"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"resource:internal.css\">\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body id =\"privacy\">\n"
|
|
|
|
"<h1>%s</h1>\n",
|
|
|
|
title, title);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-07 16:09:37 +03:00
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<form method=\"post\""
|
|
|
|
" enctype=\"multipart/form-data\">");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
|
|
|
}
|
|
|
|
|
2019-10-30 01:29:22 +03:00
|
|
|
res = get_query_description(siteurl,
|
|
|
|
"PrivacyDescription",
|
|
|
|
&description);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res == NSERROR_OK) {
|
2019-08-07 16:09:37 +03:00
|
|
|
res = ssenddataf(ctx, "<div><p>%s</p></div>", description);
|
2019-08-06 15:15:24 +03:00
|
|
|
free(description);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
|
|
|
}
|
|
|
|
}
|
2019-08-10 14:51:46 +03:00
|
|
|
res = ssenddataf(ctx, "<div><p>%s</p></div>", reason);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-07 16:09:37 +03:00
|
|
|
"<div id=\"buttons\">"
|
2019-08-06 00:28:52 +03:00
|
|
|
"<input type=\"submit\" id=\"back\" name=\"back\" "
|
2019-08-09 15:20:08 +03:00
|
|
|
"value=\"%s\" class=\"default-action\">"
|
2019-08-06 00:28:52 +03:00
|
|
|
"<input type=\"submit\" id=\"proceed\" name=\"proceed\" "
|
|
|
|
"value=\"%s\">"
|
|
|
|
"</div>",
|
|
|
|
messages_get("Backtosafety"),
|
|
|
|
messages_get("Proceed"));
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
|
|
|
res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
url_s = strdup("");
|
|
|
|
}
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx,
|
2019-08-06 00:28:52 +03:00
|
|
|
"<input type=\"hidden\" name=\"siteurl\" value=\"%s\">",
|
|
|
|
url_s);
|
|
|
|
free(url_s);
|
2019-08-06 15:15:24 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 15:15:24 +03:00
|
|
|
res = ssenddataf(ctx, "</form></body>\n</html>\n");
|
|
|
|
if (res != NSERROR_OK) {
|
2019-08-06 00:28:52 +03:00
|
|
|
goto fetch_about_query_ssl_handler_aborted;
|
2019-08-06 15:15:24 +03:00
|
|
|
}
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_about_send_finished(ctx);
|
2019-08-06 00:28:52 +03:00
|
|
|
|
2019-08-06 12:06:09 +03:00
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_query_ssl_handler_aborted:
|
2019-08-06 12:06:09 +03:00
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
2019-08-06 00:28:52 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-30 01:29:22 +03:00
|
|
|
/**
|
|
|
|
* Handler to generate about scheme timeout query page
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
|
|
|
static bool fetch_about_query_timeout_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 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;
|
|
|
|
}
|
|
|
|
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_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
title = messages_get("TimeoutTitle");
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<html>\n<head>\n"
|
|
|
|
"<title>%s</title>\n"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"resource:internal.css\">\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body id =\"timeout\">\n"
|
|
|
|
"<h1>%s</h1>\n",
|
|
|
|
title, title);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<form method=\"post\""
|
|
|
|
" enctype=\"multipart/form-data\">");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = get_query_description(siteurl,
|
|
|
|
"TimeoutDescription",
|
|
|
|
&description);
|
|
|
|
if (res == NSERROR_OK) {
|
|
|
|
res = ssenddataf(ctx, "<div><p>%s</p></div>", description);
|
|
|
|
free(description);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = ssenddataf(ctx, "<div><p>%s</p></div>", reason);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<div id=\"buttons\">"
|
|
|
|
"<input type=\"submit\" id=\"back\" name=\"back\" "
|
|
|
|
"value=\"%s\" class=\"default-action\">"
|
|
|
|
"<input type=\"submit\" id=\"retry\" name=\"retry\" "
|
|
|
|
"value=\"%s\">"
|
|
|
|
"</div>",
|
|
|
|
messages_get("Backtoprevious"),
|
|
|
|
messages_get("TryAgain"));
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
url_s = strdup("");
|
|
|
|
}
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<input type=\"hidden\" name=\"siteurl\" value=\"%s\">",
|
|
|
|
url_s);
|
|
|
|
free(url_s);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx, "</form></body>\n</html>\n");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_timeout_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_about_send_finished(ctx);
|
|
|
|
|
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_query_timeout_handler_aborted:
|
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-30 21:56:38 +03:00
|
|
|
/**
|
|
|
|
* Handler to generate about scheme fetch error query page
|
|
|
|
*
|
|
|
|
* \param ctx The fetcher context.
|
|
|
|
* \return true if handled false if aborted.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
fetch_about_query_fetcherror_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 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;
|
|
|
|
}
|
|
|
|
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_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
title = messages_get("FetchErrorTitle");
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<html>\n<head>\n"
|
|
|
|
"<title>%s</title>\n"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"resource:internal.css\">\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body id =\"fetcherror\">\n"
|
|
|
|
"<h1>%s</h1>\n",
|
|
|
|
title, title);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<form method=\"post\""
|
|
|
|
" enctype=\"multipart/form-data\">");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = get_query_description(siteurl,
|
|
|
|
"FetchErrorDescription",
|
|
|
|
&description);
|
|
|
|
if (res == NSERROR_OK) {
|
|
|
|
res = ssenddataf(ctx, "<div><p>%s</p></div>", description);
|
|
|
|
free(description);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = ssenddataf(ctx, "<div><p>%s</p></div>", reason);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<div id=\"buttons\">"
|
|
|
|
"<input type=\"submit\" id=\"back\" name=\"back\" "
|
|
|
|
"value=\"%s\" class=\"default-action\">"
|
|
|
|
"<input type=\"submit\" id=\"retry\" name=\"retry\" "
|
|
|
|
"value=\"%s\">"
|
|
|
|
"</div>",
|
|
|
|
messages_get("Backtoprevious"),
|
|
|
|
messages_get("TryAgain"));
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = nsurl_get(siteurl, NSURL_COMPLETE, &url_s, &url_l);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
url_s = strdup("");
|
|
|
|
}
|
|
|
|
res = ssenddataf(ctx,
|
|
|
|
"<input type=\"hidden\" name=\"siteurl\" value=\"%s\">",
|
|
|
|
url_s);
|
|
|
|
free(url_s);
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ssenddataf(ctx, "</form></body>\n</html>\n");
|
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_query_fetcherror_handler_aborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_about_send_finished(ctx);
|
|
|
|
|
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_query_fetcherror_handler_aborted:
|
|
|
|
nsurl_unref(siteurl);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 13:20:04 +03:00
|
|
|
/* Forward declaration because this handler requires the handler table. */
|
|
|
|
static bool fetch_about_about_handler(struct fetch_about_context *ctx);
|
|
|
|
|
2019-08-05 17:37:22 +03:00
|
|
|
/**
|
|
|
|
* List of about paths and their handlers
|
|
|
|
*/
|
2012-07-21 16:12:51 +04:00
|
|
|
struct about_handlers about_handler_list[] = {
|
2019-08-05 17:37:22 +03:00
|
|
|
{
|
|
|
|
"credits",
|
|
|
|
SLEN("credits"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_credits_handler,
|
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"licence",
|
|
|
|
SLEN("licence"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_licence_handler,
|
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"license",
|
|
|
|
SLEN("license"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_licence_handler,
|
|
|
|
true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"welcome",
|
|
|
|
SLEN("welcome"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_welcome_handler,
|
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"maps",
|
|
|
|
SLEN("maps"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_maps_handler,
|
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"config",
|
|
|
|
SLEN("config"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_config_handler,
|
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Choices",
|
|
|
|
SLEN("Choices"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_choices_handler,
|
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"testament",
|
|
|
|
SLEN("testament"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_testament_handler,
|
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"about",
|
|
|
|
SLEN("about"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_about_handler,
|
|
|
|
true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"logo",
|
|
|
|
SLEN("logo"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_logo_handler,
|
|
|
|
true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
/* details about the image cache */
|
|
|
|
"imagecache",
|
|
|
|
SLEN("imagecache"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_imagecache_handler,
|
|
|
|
true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
/* The default blank page */
|
|
|
|
"blank",
|
|
|
|
SLEN("blank"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_blank_handler,
|
|
|
|
true
|
2019-08-06 00:28:52 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"query/auth",
|
|
|
|
SLEN("query/auth"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_query_auth_handler,
|
|
|
|
true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query/ssl",
|
|
|
|
SLEN("query/ssl"),
|
|
|
|
NULL,
|
2019-08-06 15:15:24 +03:00
|
|
|
fetch_about_query_privacy_handler,
|
2019-08-06 00:28:52 +03:00
|
|
|
true
|
2019-10-30 01:29:22 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"query/timeout",
|
|
|
|
SLEN("query/timeout"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_query_timeout_handler,
|
|
|
|
true
|
2019-10-30 21:56:38 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"query/fetcherror",
|
|
|
|
SLEN("query/fetcherror"),
|
|
|
|
NULL,
|
|
|
|
fetch_about_query_fetcherror_handler,
|
|
|
|
true
|
2019-08-05 17:37:22 +03:00
|
|
|
}
|
2011-02-16 02:18:10 +03:00
|
|
|
};
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
#define about_handler_list_len \
|
|
|
|
(sizeof(about_handler_list) / sizeof(struct about_handlers))
|
2011-02-16 02:18:10 +03:00
|
|
|
|
2011-03-17 13:20:04 +03:00
|
|
|
/**
|
2014-10-10 16:01:20 +04:00
|
|
|
* List all the valid about: paths available
|
|
|
|
*
|
2011-03-17 13:20:04 +03:00
|
|
|
* \param ctx The fetch context.
|
|
|
|
* \return true for sucess or false to generate an error.
|
|
|
|
*/
|
|
|
|
static bool fetch_about_about_handler(struct fetch_about_context *ctx)
|
|
|
|
{
|
2019-08-08 19:12:42 +03:00
|
|
|
nserror res;
|
2011-03-17 13:20:04 +03:00
|
|
|
unsigned int abt_loop = 0;
|
|
|
|
|
|
|
|
/* content is going to return ok */
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_set_http_code(ctx->fetchh, 200);
|
2011-03-17 13:20:04 +03:00
|
|
|
|
|
|
|
/* content type */
|
|
|
|
if (fetch_about_send_header(ctx, "Content-Type: text/html"))
|
|
|
|
goto fetch_about_config_handler_aborted;
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx,
|
2011-03-18 15:10:15 +03:00
|
|
|
"<html>\n<head>\n"
|
|
|
|
"<title>NetSurf List of About pages</title>\n"
|
|
|
|
"<link rel=\"stylesheet\" type=\"text/css\" "
|
|
|
|
"href=\"resource:internal.css\">\n"
|
|
|
|
"</head>\n"
|
|
|
|
"<body id =\"aboutlist\">\n"
|
2011-03-17 13:20:04 +03:00
|
|
|
"<p class=\"banner\">"
|
|
|
|
"<a href=\"http://www.netsurf-browser.org/\">"
|
|
|
|
"<img src=\"resource:netsurf.png\" alt=\"NetSurf\"></a>"
|
2011-03-18 15:10:15 +03:00
|
|
|
"</p>\n"
|
|
|
|
"<h1>NetSurf List of About pages</h1>\n"
|
2011-03-17 13:20:04 +03:00
|
|
|
"<ul>\n");
|
2019-08-08 19:12:42 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_config_handler_aborted;
|
|
|
|
}
|
2011-03-17 13:20:04 +03:00
|
|
|
|
|
|
|
for (abt_loop = 0; abt_loop < about_handler_list_len; abt_loop++) {
|
2011-03-17 15:09:48 +03:00
|
|
|
|
2011-03-17 15:26:59 +03:00
|
|
|
/* Skip over hidden entries */
|
2011-03-17 15:24:40 +03:00
|
|
|
if (about_handler_list[abt_loop].hidden)
|
2011-03-17 15:09:48 +03:00
|
|
|
continue;
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx,
|
2014-10-10 16:01:20 +04:00
|
|
|
"<li><a href=\"about:%s\">about:%s</a></li>\n",
|
|
|
|
about_handler_list[abt_loop].name,
|
2011-03-17 13:20:04 +03:00
|
|
|
about_handler_list[abt_loop].name);
|
2019-08-08 19:12:42 +03:00
|
|
|
if (res != NSERROR_OK) {
|
|
|
|
goto fetch_about_config_handler_aborted;
|
2011-03-17 13:20:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
res = ssenddataf(ctx, "</ul>\n</body>\n</html>\n");
|
|
|
|
if (res != NSERROR_OK) {
|
2011-03-17 13:20:04 +03:00
|
|
|
goto fetch_about_config_handler_aborted;
|
2019-08-08 19:12:42 +03:00
|
|
|
}
|
2011-03-17 13:20:04 +03:00
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
fetch_about_send_finished(ctx);
|
2011-03-17 13:20:04 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fetch_about_config_handler_aborted:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
/**
|
|
|
|
* callback to initialise the about scheme fetcher.
|
|
|
|
*/
|
2011-09-27 01:07:19 +04:00
|
|
|
static bool fetch_about_initialise(lwc_string *scheme)
|
2011-02-16 02:18:10 +03:00
|
|
|
{
|
2011-10-10 23:46:46 +04:00
|
|
|
unsigned int abt_loop = 0;
|
|
|
|
lwc_error error;
|
|
|
|
|
|
|
|
for (abt_loop = 0; abt_loop < about_handler_list_len; abt_loop++) {
|
2014-10-10 16:01:20 +04:00
|
|
|
error = lwc_intern_string(about_handler_list[abt_loop].name,
|
|
|
|
about_handler_list[abt_loop].name_len,
|
2011-10-10 23:46:46 +04:00
|
|
|
&about_handler_list[abt_loop].lname);
|
2011-10-11 10:55:20 +04:00
|
|
|
if (error != lwc_error_ok) {
|
|
|
|
while (abt_loop-- != 0) {
|
|
|
|
lwc_string_unref(about_handler_list[abt_loop].lname);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-10 23:46:46 +04:00
|
|
|
}
|
|
|
|
|
2011-02-16 02:18:10 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* callback to finalise the about scheme fetcher.
|
|
|
|
*/
|
2011-09-27 01:07:19 +04:00
|
|
|
static void fetch_about_finalise(lwc_string *scheme)
|
2011-02-16 02:18:10 +03:00
|
|
|
{
|
2011-10-10 23:46:46 +04:00
|
|
|
unsigned int abt_loop = 0;
|
|
|
|
for (abt_loop = 0; abt_loop < about_handler_list_len; abt_loop++) {
|
|
|
|
lwc_string_unref(about_handler_list[abt_loop].lname);
|
|
|
|
}
|
2011-02-16 02:18:10 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
2011-11-27 18:14:36 +04:00
|
|
|
static bool fetch_about_can_fetch(const nsurl *url)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
2019-08-05 17:37:22 +03:00
|
|
|
/**
|
|
|
|
* callback to set up a about scheme fetch.
|
|
|
|
*
|
|
|
|
* \param post_urlenc post data in urlenc format, owned by the llcache object
|
|
|
|
* hence valid the entire lifetime of the fetch.
|
|
|
|
* \param post_multipart post data in multipart format, owned by the llcache
|
|
|
|
* object hence valid the entire lifetime of the fetch.
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
static void *
|
|
|
|
fetch_about_setup(struct fetch *fetchh,
|
2019-08-05 17:37:22 +03:00
|
|
|
nsurl *url,
|
|
|
|
bool only_2xx,
|
|
|
|
bool downgrade_tls,
|
|
|
|
const char *post_urlenc,
|
|
|
|
const struct fetch_multipart_data *post_multipart,
|
|
|
|
const char **headers)
|
2011-02-16 02:18:10 +03:00
|
|
|
{
|
|
|
|
struct fetch_about_context *ctx;
|
|
|
|
unsigned int handler_loop;
|
2011-09-29 19:31:54 +04:00
|
|
|
lwc_string *path;
|
2011-10-10 23:46:46 +04:00
|
|
|
bool match;
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (ctx == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-09-29 19:31:54 +04:00
|
|
|
path = nsurl_get_component(url, NSURL_PATH);
|
2011-02-16 02:18:10 +03:00
|
|
|
|
2014-10-10 16:01:20 +04:00
|
|
|
for (handler_loop = 0;
|
|
|
|
handler_loop < about_handler_list_len;
|
2011-02-16 02:18:10 +03:00
|
|
|
handler_loop++) {
|
|
|
|
ctx->handler = about_handler_list[handler_loop].handler;
|
2014-10-10 16:01:20 +04:00
|
|
|
if (lwc_string_isequal(path,
|
|
|
|
about_handler_list[handler_loop].lname,
|
2011-10-10 23:46:46 +04:00
|
|
|
&match) == lwc_error_ok && match) {
|
2011-02-16 02:18:10 +03:00
|
|
|
break;
|
2014-10-10 16:01:20 +04:00
|
|
|
}
|
2011-02-16 02:18:10 +03:00
|
|
|
}
|
|
|
|
|
2011-10-15 13:47:37 +04:00
|
|
|
if (path != NULL)
|
|
|
|
lwc_string_unref(path);
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
ctx->fetchh = fetchh;
|
2011-09-29 19:31:54 +04:00
|
|
|
ctx->url = nsurl_ref(url);
|
2019-08-05 17:37:22 +03:00
|
|
|
ctx->multipart = post_multipart;
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
RING_INSERT(ring, ctx);
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* callback to free a about scheme fetch
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
static void fetch_about_free(void *ctx)
|
|
|
|
{
|
|
|
|
struct fetch_about_context *c = ctx;
|
2011-09-29 19:31:54 +04:00
|
|
|
nsurl_unref(c->url);
|
2011-02-16 02:18:10 +03:00
|
|
|
RING_REMOVE(ring, c);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* callback to start an about scheme fetch
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
static bool fetch_about_start(void *ctx)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* callback to abort a about fetch
|
|
|
|
*/
|
2011-02-16 02:18:10 +03:00
|
|
|
static void fetch_about_abort(void *ctx)
|
|
|
|
{
|
|
|
|
struct fetch_about_context *c = ctx;
|
|
|
|
|
|
|
|
/* To avoid the poll loop having to deal with the fetch context
|
|
|
|
* disappearing from under it, we simply flag the abort here.
|
|
|
|
* The poll loop itself will perform the appropriate cleanup.
|
|
|
|
*/
|
|
|
|
c->aborted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
/**
|
|
|
|
* callback to poll for additional about fetch contents
|
|
|
|
*/
|
2011-09-27 01:07:19 +04:00
|
|
|
static void fetch_about_poll(lwc_string *scheme)
|
2011-02-16 02:18:10 +03:00
|
|
|
{
|
|
|
|
struct fetch_about_context *c, *next;
|
|
|
|
|
|
|
|
if (ring == NULL) return;
|
|
|
|
|
|
|
|
/* Iterate over ring, processing each pending fetch */
|
|
|
|
c = ring;
|
|
|
|
do {
|
|
|
|
/* Ignore fetches that have been flagged as locked.
|
|
|
|
* This allows safe re-entrant calls to this function.
|
|
|
|
* Re-entrancy can occur if, as a result of a callback,
|
|
|
|
* the interested party causes fetch_poll() to be called
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
if (c->locked == true) {
|
2011-02-24 01:41:17 +03:00
|
|
|
next = c->r_next;
|
2011-02-16 02:18:10 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only process non-aborted fetches */
|
|
|
|
if (c->aborted == false) {
|
|
|
|
/* about fetches can be processed in one go */
|
|
|
|
c->handler(c);
|
|
|
|
}
|
|
|
|
|
2011-02-24 01:41:17 +03:00
|
|
|
/* Compute next fetch item at the last possible moment
|
|
|
|
* as processing this item may have added to the ring
|
|
|
|
*/
|
|
|
|
next = c->r_next;
|
2011-02-16 02:18:10 +03:00
|
|
|
|
|
|
|
fetch_remove_from_queues(c->fetchh);
|
|
|
|
fetch_free(c->fetchh);
|
|
|
|
|
|
|
|
/* Advance to next ring entry, exiting if we've reached
|
|
|
|
* the start of the ring or the ring has become empty
|
|
|
|
*/
|
|
|
|
} while ( (c = next) != ring && ring != NULL);
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:12:42 +03:00
|
|
|
|
2014-06-19 21:27:24 +04:00
|
|
|
nserror fetch_about_register(void)
|
2011-02-16 02:18:10 +03:00
|
|
|
{
|
2014-01-25 00:08:41 +04:00
|
|
|
lwc_string *scheme = lwc_string_ref(corestring_lwc_about);
|
2014-06-19 21:27:24 +04:00
|
|
|
const struct fetcher_operation_table fetcher_ops = {
|
|
|
|
.initialise = fetch_about_initialise,
|
|
|
|
.acceptable = fetch_about_can_fetch,
|
|
|
|
.setup = fetch_about_setup,
|
|
|
|
.start = fetch_about_start,
|
|
|
|
.abort = fetch_about_abort,
|
|
|
|
.free = fetch_about_free,
|
|
|
|
.poll = fetch_about_poll,
|
|
|
|
.finalise = fetch_about_finalise
|
|
|
|
};
|
|
|
|
|
|
|
|
return fetcher_add(scheme, &fetcher_ops);
|
2011-02-16 02:18:10 +03:00
|
|
|
}
|