mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-08 20:12:01 +03:00
add about: fetcher
rename fetchers to be more sensible svn path=/trunk/netsurf/; revision=11692
This commit is contained in:
parent
4f47cad962
commit
fa98e3d76a
@ -4,8 +4,9 @@
|
||||
# Included by main makefile -- indicates generic sources for every build.
|
||||
#
|
||||
|
||||
S_CONTENT := content.c dirlist.c fetch.c hlcache.c llcache.c urldb.c \
|
||||
fetchers/fetch_curl.c fetchers/fetch_data.c fetchers/fetch_file.c
|
||||
S_CONTENT := content.c dirlist.c fetch.c hlcache.c llcache.c urldb.c
|
||||
|
||||
S_FETCHERS := curl.c data.c file.c about.c
|
||||
|
||||
S_CSS := css.c dump.c internal.c select.c utils.c
|
||||
|
||||
@ -22,6 +23,7 @@ S_DESKTOP := cookies.c history_global_core.c hotlist.c knockout.c \
|
||||
|
||||
# S_COMMON are sources common to all builds
|
||||
S_COMMON := $(addprefix content/,$(S_CONTENT)) \
|
||||
$(addprefix content/fetchers/,$(S_FETCHERS)) \
|
||||
$(addprefix css/,$(S_CSS)) \
|
||||
$(addprefix render/,$(S_RENDER)) \
|
||||
$(addprefix utils/,$(S_UTILS)) \
|
||||
|
@ -38,9 +38,9 @@
|
||||
|
||||
#include "utils/config.h"
|
||||
#include "content/fetch.h"
|
||||
#include "content/fetchers/fetch_curl.h"
|
||||
#include "content/fetchers/fetch_data.h"
|
||||
#include "content/fetchers/fetch_file.h"
|
||||
#include "content/fetchers/curl.h"
|
||||
#include "content/fetchers/data.h"
|
||||
#include "content/fetchers/file.h"
|
||||
#include "content/urldb.h"
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/options.h"
|
||||
@ -111,6 +111,7 @@ void fetch_init(void)
|
||||
fetch_curl_register();
|
||||
fetch_data_register();
|
||||
fetch_file_register();
|
||||
fetch_about_register();
|
||||
fetch_active = false;
|
||||
}
|
||||
|
||||
|
315
content/fetchers/about.c
Normal file
315
content/fetchers/about.c
Normal file
@ -0,0 +1,315 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* about: URL handling. Based on the data fetcher by Rob Kendrick */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "utils/config.h"
|
||||
#include "content/dirlist.h"
|
||||
#include "content/fetch.h"
|
||||
#include "content/fetchers/about.h"
|
||||
#include "content/urldb.h"
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/options.h"
|
||||
#include "utils/log.h"
|
||||
#include "utils/messages.h"
|
||||
#include "utils/url.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/ring.h"
|
||||
|
||||
struct fetch_about_context;
|
||||
|
||||
typedef bool (*fetch_about_handler)(struct fetch_about_context *);
|
||||
|
||||
/** Context for an about fetch */
|
||||
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 */
|
||||
|
||||
char *url; /**< The full url the fetch refers to */
|
||||
|
||||
fetch_about_handler handler;
|
||||
};
|
||||
|
||||
static struct fetch_about_context *ring = NULL;
|
||||
|
||||
/** issue fetch callbacks with locking */
|
||||
static inline bool fetch_about_send_callback(fetch_msg msg,
|
||||
struct fetch_about_context *ctx, const void *data,
|
||||
unsigned long size, fetch_error_code errorcode)
|
||||
{
|
||||
ctx->locked = true;
|
||||
fetch_send_callback(msg, ctx->fetchh, data, size, errorcode);
|
||||
ctx->locked = false;
|
||||
|
||||
return ctx->aborted;
|
||||
}
|
||||
|
||||
static bool fetch_about_send_header(struct fetch_about_context *ctx,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
char header[64];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
vsnprintf(header, sizeof header, fmt, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
fetch_about_send_callback(FETCH_HEADER, ctx, header, strlen(header),
|
||||
FETCH_ERROR_NO_ERROR);
|
||||
|
||||
return ctx->aborted;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static bool fetch_about_blank_handler(struct fetch_about_context *ctx)
|
||||
{
|
||||
char buffer[2];
|
||||
int code = 200;
|
||||
|
||||
/* 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_blank_handler_aborted;
|
||||
|
||||
buffer[0] = ' ';
|
||||
buffer[1] = 0;
|
||||
if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, strlen(buffer),
|
||||
FETCH_ERROR_NO_ERROR))
|
||||
goto fetch_about_blank_handler_aborted;
|
||||
|
||||
fetch_about_send_callback(FETCH_FINISHED, ctx, 0, 0,
|
||||
FETCH_ERROR_NO_ERROR);
|
||||
|
||||
return true;
|
||||
|
||||
fetch_about_blank_handler_aborted:
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char *authors[] = {
|
||||
"John-Mark Bell", "James Bursa", "Michael Drake",
|
||||
"Rob Kendrick", "Adrian Lees", "Vincent Sanders",
|
||||
"Daniel Silverstone", "Richard Wilson", NULL
|
||||
};
|
||||
|
||||
static bool fetch_about_credits_handler(struct fetch_about_context *ctx)
|
||||
{
|
||||
char buffer[4096];
|
||||
int code = 200;
|
||||
int slen;
|
||||
int auth_loop = 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/html"))
|
||||
goto fetch_about_credits_handler_aborted;
|
||||
|
||||
slen = snprintf(buffer, sizeof buffer,
|
||||
"<html><head><title>NetSurf Browser Credits</title></head>"
|
||||
"<body><h1>NetSurf Browser Credits</h1>"
|
||||
"<p>Authors</p>"
|
||||
"<ul>");
|
||||
|
||||
while (authors[auth_loop] != NULL) {
|
||||
slen += snprintf(buffer + slen, sizeof buffer - slen,
|
||||
"<li>%s</li>", authors[auth_loop]);
|
||||
auth_loop++;
|
||||
}
|
||||
|
||||
slen += snprintf(buffer + slen, sizeof buffer - slen,
|
||||
"</ul></body></html>");
|
||||
|
||||
if (fetch_about_send_callback(FETCH_DATA, ctx, buffer, slen,
|
||||
FETCH_ERROR_NO_ERROR))
|
||||
goto fetch_about_credits_handler_aborted;
|
||||
|
||||
fetch_about_send_callback(FETCH_FINISHED, ctx, 0, 0,
|
||||
FETCH_ERROR_NO_ERROR);
|
||||
|
||||
return true;
|
||||
|
||||
fetch_about_credits_handler_aborted:
|
||||
return false;
|
||||
}
|
||||
|
||||
struct about_handlers {
|
||||
const char *name;
|
||||
fetch_about_handler handler;
|
||||
};
|
||||
|
||||
struct about_handlers about_handler_list[] = {
|
||||
{ "credits", fetch_about_credits_handler },
|
||||
{ "blank", fetch_about_blank_handler } /* The default */
|
||||
};
|
||||
|
||||
#define about_handler_list_len (sizeof(about_handler_list) / sizeof(struct about_handlers))
|
||||
|
||||
/** callback to initialise the about fetcher. */
|
||||
static bool fetch_about_initialise(const char *scheme)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** callback to initialise the about fetcher. */
|
||||
static void fetch_about_finalise(const char *scheme)
|
||||
{
|
||||
}
|
||||
|
||||
/** callback to set up a about fetch context. */
|
||||
static void *
|
||||
fetch_about_setup(struct fetch *fetchh,
|
||||
const char *url,
|
||||
bool only_2xx,
|
||||
const char *post_urlenc,
|
||||
const struct fetch_multipart_data *post_multipart,
|
||||
const char **headers)
|
||||
{
|
||||
struct fetch_about_context *ctx;
|
||||
unsigned int handler_loop;
|
||||
struct url_components urlcomp;
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
url_get_components(url, &urlcomp);
|
||||
|
||||
for (handler_loop = 0;
|
||||
handler_loop < about_handler_list_len;
|
||||
handler_loop++) {
|
||||
ctx->handler = about_handler_list[handler_loop].handler;
|
||||
if (strcmp(about_handler_list[handler_loop].name, urlcomp.path) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
url_destroy_components(&urlcomp);
|
||||
|
||||
ctx->fetchh = fetchh;
|
||||
|
||||
RING_INSERT(ring, ctx);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/** callback to free a about fetch */
|
||||
static void fetch_about_free(void *ctx)
|
||||
{
|
||||
struct fetch_about_context *c = ctx;
|
||||
free(c->url);
|
||||
RING_REMOVE(ring, c);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
/** callback to start a about fetch */
|
||||
static bool fetch_about_start(void *ctx)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** callback to abort a about fetch */
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/** callback to poll for additional about fetch contents */
|
||||
static void fetch_about_poll(const char *scheme)
|
||||
{
|
||||
struct fetch_about_context *c, *next;
|
||||
|
||||
if (ring == NULL) return;
|
||||
|
||||
/* Iterate over ring, processing each pending fetch */
|
||||
c = ring;
|
||||
do {
|
||||
/* Take a copy of the next pointer as we may destroy
|
||||
* the ring item we're currently processing */
|
||||
next = c->r_next;
|
||||
|
||||
/* 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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Only process non-aborted fetches */
|
||||
if (c->aborted == false) {
|
||||
/* about fetches can be processed in one go */
|
||||
c->handler(c);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void fetch_about_register(void)
|
||||
{
|
||||
fetch_add_fetcher("about",
|
||||
fetch_about_initialise,
|
||||
fetch_about_setup,
|
||||
fetch_about_start,
|
||||
fetch_about_abort,
|
||||
fetch_about_free,
|
||||
fetch_about_poll,
|
||||
fetch_about_finalise);
|
||||
}
|
28
content/fetchers/about.h
Normal file
28
content/fetchers/about.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* about: URL method handler
|
||||
*/
|
||||
|
||||
#ifndef NETSURF_CONTENT_FETCHERS_FETCH_ABOUT_H
|
||||
#define NETSURF_CONTENT_FETCHERS_FETCH_ABOUT_H
|
||||
|
||||
void fetch_about_register(void);
|
||||
|
||||
#endif
|
@ -40,7 +40,7 @@
|
||||
#include "utils/config.h"
|
||||
#include <openssl/ssl.h>
|
||||
#include "content/fetch.h"
|
||||
#include "content/fetchers/fetch_curl.h"
|
||||
#include "content/fetchers/curl.h"
|
||||
#include "content/urldb.h"
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/options.h"
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include "utils/config.h"
|
||||
#include "content/fetch.h"
|
||||
#include "content/fetchers/fetch_data.h"
|
||||
#include "content/fetchers/data.h"
|
||||
#include "content/urldb.h"
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/options.h"
|
@ -37,7 +37,7 @@
|
||||
#include "utils/config.h"
|
||||
#include "content/dirlist.h"
|
||||
#include "content/fetch.h"
|
||||
#include "content/fetchers/fetch_file.h"
|
||||
#include "content/fetchers/file.h"
|
||||
#include "content/urldb.h"
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/options.h"
|
Loading…
Reference in New Issue
Block a user