NetSurf
Data Structures | Macros | Typedefs | Functions | Variables
resource.c File Reference

resource scheme URL handling. More...

#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdarg.h>
#include <libwapcaplet/libwapcaplet.h>
#include "netsurf/inttypes.h"
#include "utils/nsurl.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/time.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/ring.h"
#include "netsurf/fetch.h"
#include "desktop/gui_internal.h"
#include "content/fetch.h"
#include "content/fetchers.h"
#include "content/fetchers/resource.h"
Include dependency graph for resource.c:

Go to the source code of this file.

Data Structures

struct  fetch_resource_map_entry
 map of resource scheme paths to redirect urls More...
 
struct  fetch_resource_context
 Context for an resource fetch. More...
 

Macros

#define DIRECT_ETAG_VALUE   123456
 

Typedefs

typedef bool(* fetch_resource_handler) (struct fetch_resource_context *)
 

Functions

static bool fetch_resource_send_callback (const fetch_msg *msg, struct fetch_resource_context *ctx)
 issue fetch callbacks with locking More...
 
static bool fetch_resource_send_header (struct fetch_resource_context *ctx, const char *fmt,...)
 
static bool fetch_resource_redirect_handler (struct fetch_resource_context *ctx)
 resource handler that results in a redirect to another url. More...
 
static bool fetch_resource_data_handler (struct fetch_resource_context *ctx)
 
static bool fetch_resource_notfound_handler (struct fetch_resource_context *ctx)
 
static bool fetch_resource_initialise (lwc_string *scheme)
 callback to initialise the resource fetcher. More...
 
static void fetch_resource_finalise (lwc_string *scheme)
 callback to finalise the resource fetcher. More...
 
static bool fetch_resource_can_fetch (const nsurl *url)
 
static void * fetch_resource_setup (struct fetch *fetchh, nsurl *url, bool only_2xx, bool downgrade_tls, const char *post_urlenc, const struct fetch_multipart_data *post_multipart, const char **headers)
 set up a resource fetch context. More...
 
static void fetch_resource_free (void *ctx)
 callback to free a resource fetch More...
 
static bool fetch_resource_start (void *ctx)
 callback to start a resource fetch More...
 
static void fetch_resource_abort (void *ctx)
 callback to abort a resource fetch More...
 
static void fetch_resource_poll (lwc_string *scheme)
 callback to poll for additional resource fetch contents More...
 
nserror fetch_resource_register (void)
 Register the resource scheme. More...
 

Variables

static const char * fetch_resource_paths []
 Valid resource paths. More...
 
static struct fetch_resource_map_entry fetch_resource_map [NOF_ELEMENTS(fetch_resource_paths)]
 
static struct fetch_resource_contextring = NULL
 
static uint32_t fetch_resource_path_count
 

Detailed Description

resource scheme URL handling.

Based on the data fetcher by Rob Kendrick

Definition in file resource.c.

Macro Definition Documentation

◆ DIRECT_ETAG_VALUE

#define DIRECT_ETAG_VALUE   123456

Definition at line 47 of file resource.c.

Typedef Documentation

◆ fetch_resource_handler

typedef bool(* fetch_resource_handler) (struct fetch_resource_context *)

Definition at line 83 of file resource.c.

Function Documentation

◆ fetch_resource_abort()

static void fetch_resource_abort ( void *  ctx)
static

callback to abort a resource fetch

Definition at line 429 of file resource.c.

References fetch_resource_context::aborted.

Referenced by fetch_resource_register().

Here is the caller graph for this function:

◆ fetch_resource_can_fetch()

static bool fetch_resource_can_fetch ( const nsurl url)
static

Definition at line 329 of file resource.c.

Referenced by fetch_resource_register().

Here is the caller graph for this function:

◆ fetch_resource_data_handler()

static bool fetch_resource_data_handler ( struct fetch_resource_context ctx)
static

Definition at line 161 of file resource.c.

References fetch_resource_context::aborted, fetch_msg::buf, fetch_msg::data, fetch_resource_map_entry::data, fetch_resource_map_entry::data_len, DIRECT_ETAG_VALUE, fetch_resource_context::entry, fetch_resource_context::etag, netsurf_table::fetch, FETCH_DATA, FETCH_FINISHED, FETCH_NOTMODIFIED, fetch_resource_send_callback(), fetch_resource_send_header(), fetch_set_http_code(), fetch_resource_context::fetchh, gui_fetch_table::filetype, guit, fetch_msg::header_or_data, fetch_msg::len, fetch_resource_map_entry::path, PRId64, PRIsizet, and fetch_msg::type.

Referenced by fetch_resource_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_finalise()

static void fetch_resource_finalise ( lwc_string *  scheme)
static

callback to finalise the resource fetcher.

Definition at line 315 of file resource.c.

References fetch_resource_map_entry::data, netsurf_table::fetch, fetch_resource_map, fetch_resource_path_count, guit, nsurl_unref(), path(), fetch_resource_map_entry::redirect_url, and gui_fetch_table::release_resource_data.

Referenced by fetch_resource_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_free()

static void fetch_resource_free ( void *  ctx)
static

callback to free a resource fetch

Definition at line 414 of file resource.c.

References nsurl_unref(), and fetch_resource_context::url.

Referenced by fetch_resource_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_initialise()

static bool fetch_resource_initialise ( lwc_string *  scheme)
static

callback to initialise the resource fetcher.

Todo:
should this exit with an error condition?

Definition at line 269 of file resource.c.

References fetch_resource_map_entry::data, fetch_resource_map_entry::data_len, netsurf_table::fetch, fetch_resource_map, fetch_resource_path_count, fetch_resource_paths, gui_fetch_table::get_resource_data, gui_fetch_table::get_resource_url, guit, NOF_ELEMENTS, NSERROR_OK, NSLOG, nsurl_unref(), fetch_resource_map_entry::path, path(), and fetch_resource_map_entry::redirect_url.

Referenced by fetch_resource_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_notfound_handler()

static bool fetch_resource_notfound_handler ( struct fetch_resource_context ctx)
static

Definition at line 220 of file resource.c.

References fetch_msg::buf, buffer, fetch_msg::data, FETCH_DATA, FETCH_FINISHED, fetch_resource_send_callback(), fetch_resource_send_header(), fetch_set_http_code(), fetch_resource_context::fetchh, fetch_msg::header_or_data, fetch_msg::len, messages_get(), nsurl_access(), fetch_msg::type, and fetch_resource_context::url.

Referenced by fetch_resource_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_poll()

static void fetch_resource_poll ( lwc_string *  scheme)
static

callback to poll for additional resource fetch contents

Definition at line 442 of file resource.c.

References fetch_resource_context::aborted, fetch_free(), fetch_remove_from_queues(), fetch_resource_context::fetchh, fetch_resource_context::handler, fetch_resource_context::locked, ring, RING_INSERT, and RING_REMOVE.

Referenced by fetch_resource_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_redirect_handler()

static bool fetch_resource_redirect_handler ( struct fetch_resource_context ctx)
static

resource handler that results in a redirect to another url.

Definition at line 146 of file resource.c.

References fetch_msg::data, fetch_resource_context::entry, FETCH_REDIRECT, fetch_resource_send_callback(), fetch_set_http_code(), fetch_resource_context::fetchh, nsurl_access(), fetch_msg::redirect, fetch_resource_map_entry::redirect_url, and fetch_msg::type.

Referenced by fetch_resource_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_register()

nserror fetch_resource_register ( void  )

Register the resource scheme.

should only be called from the fetch initialise

Returns
NSERROR_OK on successful registration or error code on failure.

Definition at line 479 of file resource.c.

References fetch_resource_abort(), fetch_resource_can_fetch(), fetch_resource_finalise(), fetch_resource_free(), fetch_resource_initialise(), fetch_resource_poll(), fetch_resource_setup(), fetch_resource_start(), fetcher_add(), and fetcher_operation_table::initialise.

Referenced by fetcher_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_send_callback()

static bool fetch_resource_send_callback ( const fetch_msg msg,
struct fetch_resource_context ctx 
)
inlinestatic

issue fetch callbacks with locking

Definition at line 108 of file resource.c.

References fetch_resource_context::aborted, fetch_send_callback(), fetch_resource_context::fetchh, and fetch_resource_context::locked.

Referenced by fetch_resource_data_handler(), fetch_resource_notfound_handler(), fetch_resource_redirect_handler(), and fetch_resource_send_header().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_send_header()

static bool fetch_resource_send_header ( struct fetch_resource_context ctx,
const char *  fmt,
  ... 
)
static

Definition at line 118 of file resource.c.

References fetch_msg::buf, fetch_msg::data, FETCH_HEADER, fetch_resource_send_callback(), fetch_msg::header_or_data, fetch_msg::len, and fetch_msg::type.

Referenced by fetch_resource_data_handler(), and fetch_resource_notfound_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_setup()

static void * fetch_resource_setup ( struct fetch fetchh,
nsurl url,
bool  only_2xx,
bool  downgrade_tls,
const char *  post_urlenc,
const struct fetch_multipart_data post_multipart,
const char **  headers 
)
static

set up a resource fetch context.

Definition at line 338 of file resource.c.

References fetch_resource_map_entry::data, fetch_resource_context::entry, fetch_resource_context::etag, fetch_resource_data_handler(), fetch_resource_map, fetch_resource_notfound_handler(), fetch_resource_path_count, fetch_resource_redirect_handler(), fetch_resource_context::fetchh, fetch_resource_context::handler, nsc_snptimet(), NSERROR_OK, NSLOG, nsurl_get_component(), NSURL_PATH, nsurl_ref(), path(), ring, RING_INSERT, SLEN, and fetch_resource_context::url.

Referenced by fetch_resource_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_resource_start()

static bool fetch_resource_start ( void *  ctx)
static

callback to start a resource fetch

Definition at line 423 of file resource.c.

Referenced by fetch_resource_register().

Here is the caller graph for this function:

Variable Documentation

◆ fetch_resource_map

struct fetch_resource_map_entry fetch_resource_map[NOF_ELEMENTS(fetch_resource_paths)]
static

◆ fetch_resource_path_count

uint32_t fetch_resource_path_count
static

◆ fetch_resource_paths

const char* fetch_resource_paths[]
static
Initial value:
= {
"adblock.css",
"default.css",
"internal.css",
"quirks.css",
"user.css",
"credits.html",
"licence.html",
"welcome.html",
"favicon.ico",
"default.ico",
"netsurf.png",
"icons/arrow-l.png",
"icons/content.png",
"icons/directory.png",
"icons/directory2.png",
"icons/hotlist-add.png",
"icons/hotlist-rmv.png",
"icons/search.png"
}

Valid resource paths.

Definition at line 50 of file resource.c.

Referenced by fetch_resource_initialise().

◆ ring

struct fetch_resource_context* ring = NULL
static

Definition at line 103 of file resource.c.

Referenced by fetch_resource_poll(), and fetch_resource_setup().