41#include <libwapcaplet/libwapcaplet.h>
56#include "content/fetchers/about/about.h"
64#define MAX_FETCHERS 10
71#define SCHEDULE_TIME 10
74#define FDSET_TIMEOUT 1000
137 scheme, &match) == lwc_error_ok) &&
152 "Attempting to start fetch %p, fetcher %p, url %s",
fetch,
176 struct fetch *queueitem;
185 if (countbyhost <
nsoption_int(max_fetchers_per_host)) {
192 if (lwc_string_isequal(queueitem->
host,
194 lwc_error_ok && same_host ==
true) {
195 queueitem = queueitem->
r_next;
198 queueitem = queueitem->
r_next;
240 "queue_ring %i, fetch_ring %i",
245 while ((all_queued != 0) &&
251 "%d queued, %d fetching",
256 NSLOG(
fetch, DEBUG,
"Fetch ring is now %d elements.", all_active);
257 NSLOG(
fetch, DEBUG,
"Queue ring is now %d elements.", all_queued);
259 return (all_active > 0);
311 ret = fetch_about_register();
342 "Fetcher for scheme %s still has %d active users at quit.",
386 fd_set *write_fd_set,
387 fd_set *except_fd_set,
408 FD_ZERO(read_fd_set);
409 FD_ZERO(write_fd_set);
410 FD_ZERO(except_fd_set);
419 write_fd_set, except_fd_set);
420 if (fetcher_maxfd > maxfd)
421 maxfd = fetcher_maxfd;
454 const char *post_urlenc,
458 const char *headers[],
459 struct fetch **fetch_out)
471 assert(scheme != NULL);
475 lwc_string_unref(scheme);
496 only_2xx, downgrade_tls,
497 post_urlenc, post_multipart,
558 "During the fetch of %s, the fetcher did not finish.",
565 "Freeing fetch %p, fetcher %p",
577 if (f->
host != NULL) {
578 lwc_string_unref(f->
host);
592 lwc_string_unref(scheme);
625 for (; list != NULL; list = list->
next) {
637 if (clone->
name == NULL) {
646 if (clone->
value == NULL) {
689 while (list != NULL) {
690 if (strcmp(list->
name,
name) == 0) {
705 for (; list != NULL; list =
next) {
711 "Freeing rawfile: %s", list->
rawfile);
729 newdata = calloc(1,
sizeof(*newdata));
731 if (newdata == NULL) {
736 if (newdata->
name == NULL) {
742 if (newdata->
value == NULL) {
748 newdata->
next = *list;
773 "Fetch %p, fetcher %p can be freed",
788 NSLOG(
fetch, DEBUG,
"Fetch ring is now %d elements.", all_active);
789 NSLOG(
fetch, DEBUG,
"Queue ring is now %d elements.", all_queued);
796 NSLOG(
fetch, DEBUG,
"Setting HTTP code to %ld", http_code);
805 assert(
fetch && data);
static void fetch_unref_fetcher(int fetcherd)
nserror fetch_multipart_data_new_kv(struct fetch_multipart_data **list, const char *name, const char *value)
Create an entry for a fetch_multipart_data.
static struct fetch * fetch_ring
Ring of active fetches.
void fetch_set_http_code(struct fetch *fetch, long http_code)
set the http code of a fetch
void fetcher_quit(void)
Clean up for quit.
static void dump_rings(void)
static struct fetch * queue_ring
Ring of queued fetches.
bool fetch_can_fetch(const nsurl *url)
Check if a URL's scheme can be fetched.
static bool fetch_dispatch_jobs(void)
Dispatch as many jobs as we have room to dispatch.
static bool fetch_dispatch_job(struct fetch *fetch)
Dispatch a single job.
void fetch_set_cookie(struct fetch *fetch, const char *data)
set cookie data on a fetch
static void fetch_ref_fetcher(int fetcherd)
const char * fetch_multipart_data_find(const struct fetch_multipart_data *list, const char *name)
Find an entry in a fetch_multipart_data.
static scheme_fetcher fetchers[MAX_FETCHERS]
long fetch_http_code(struct fetch *fetch)
Get the HTTP response code.
nserror fetch_start(nsurl *url, nsurl *referer, fetch_callback callback, void *p, bool only_2xx, const char *post_urlenc, const struct fetch_multipart_data *post_multipart, bool verifiable, bool downgrade_tls, const char *headers[], struct fetch **fetch_out)
Start fetching data for the given URL.
void fetch_abort(struct fetch *f)
Abort a fetch.
nserror fetcher_add(lwc_string *scheme, const struct fetcher_operation_table *ops)
Register a fetcher for a scheme.
struct scheme_fetcher_s scheme_fetcher
Information about a fetcher for a given scheme.
nserror fetch_fdset(fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, int *maxfd_out)
Get the set of file descriptors the fetchers are currently using.
static int get_fetcher_for_scheme(lwc_string *scheme)
Find a suitable fetcher for a scheme.
#define MAX_FETCHERS
The maximum number of fetchers that can be added.
void fetch_send_callback(const fetch_msg *msg, struct fetch *fetch)
send message to fetch
void fetch_free(struct fetch *f)
Free a fetch structure and associated resources.
static void fetcher_poll(void *unused)
#define FDSET_TIMEOUT
The fdset timeout in ms.
static bool fetch_choose_and_dispatch(void)
Choose and dispatch a single job.
struct fetch_multipart_data * fetch_multipart_data_clone(const struct fetch_multipart_data *list)
Clone a linked list of fetch_multipart_data.
void fetch_remove_from_queues(struct fetch *fetch)
remove a queued fetch
void fetch_change_callback(struct fetch *fetch, fetch_callback callback, void *p)
Change the callback function for a fetch.
void fetch_multipart_data_destroy(struct fetch_multipart_data *list)
Free a linked list of fetch_multipart_data.
#define SCHEDULE_TIME
The time in ms between polling the fetchers.
nserror fetcher_init(void)
Initialise all registered fetchers.
Fetching of data from a URL (interface).
#define FETCH__INTERNAL_ABORTED
This message is actually an internal message used to indicate that a fetch was aborted.
#define FETCH_MIN_FINISHED_MSG
Minimum finished message type.
void(* fetch_callback)(const fetch_msg *msg, void *p)
fetch_msg_type
Fetcher message types.
nserror fetch_file_register(void)
Register file scheme handler.
file scheme fetcher handler interface.
Useful interned string pointers (interface).
nserror fetch_curl_register(void)
Register curl scheme handler.
Fetching of data from a URL (Registration).
nserror fetch_data_register(void)
Register data scheme handler.
data scheme fetch handler interface.
nserror
Enumeration of error codes.
@ NSERROR_INIT_FAILED
Initialisation failed.
@ NSERROR_BAD_URL
Bad URL.
@ NSERROR_NO_FETCH_HANDLER
No fetch handler for URL scheme.
@ NSERROR_NOMEM
Memory exhaustion.
nserror fetch_javascript_register(void)
Register javascript scheme fetcher with fetcher factory.
javascript scheme handler
Interface for fetchers factory.
static nserror fetch(nsurl *url, enum backing_store_flags bsflags, uint8_t **data_out, size_t *datalen_out)
Retrieve an object from the backing store.
struct netsurf_table * guit
The global interface table.
Interface to core interface table.
Interface to platform-specific miscellaneous browser operation table.
#define NSLOG(catname, level, logmsg, args...)
Localised message support (interface).
NetSurf URL handling (interface).
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
nsurl * nsurl_ref(nsurl *url)
Increment the reference count to a NetSurf URL object.
lwc_string * nsurl_get_component(const nsurl *url, nsurl_component part)
Get part of a URL as a lwc_string, from a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
nserror fetch_resource_register(void)
Register the resource scheme.
resource URL scheme handler interface.
#define RING_GETSIZE(ringtype, ring, sizevar)
Measure the size of a ring and put it in the supplied variable.
#define RING_REMOVE(ring, element)
Remove the given element from the specified ring.
#define RING_INSERT(ring, element)
Insert the given item into the specified ring.
#define RING_COUNTBYLWCHOST(ringtype, ring, sizevar, lwc_hostname)
Count the number of elements in the ring which match the provided lwc_hostname.
Interface to utility string handling.
union fetch_msg::@118 data
Fetch POST multipart data.
char * rawfile
Raw filename if file is true.
struct fetch_multipart_data * next
Next in linked list.
Information for a single fetch.
fetch_callback callback
Callback function.
void * p
Private data for callback.
nsurl * referer
Referer URL.
long http_code
HTTP response code, or 0.
void * fetcher_handle
The handle for the fetcher.
fetch_msg_type last_msg
The last message sent for this fetch.
bool fetch_is_active
This fetch is active.
lwc_string * host
Host part of URL, interned.
struct fetch * r_next
Next active fetch in fetch_ring.
int fetcherd
Fetcher descriptor for this fetch.
bool verifiable
Transaction is verifiable.
struct fetch * r_prev
Previous active fetch in fetch_ring.
bool(* start)(void *fetch)
start a fetch.
void(* free)(void *fetch)
free a fetch allocated through the setup method.
void *(* setup)(struct fetch *parent_fetch, struct nsurl *url, bool only_2xx, bool downgrade_tls, const char *post_urlenc, const struct fetch_multipart_data *post_multipart, const char **headers)
Setup a fetch.
void(* finalise)(lwc_string *scheme)
Finalise the fetcher.
int(* fdset)(lwc_string *scheme, fd_set *read_set, fd_set *write_set, fd_set *error_set)
update an fdset with the FDs needed to poll cleanly
void(* abort)(void *fetch)
abort a fetch.
bool(* initialise)(lwc_string *scheme)
The initialiser for the fetcher.
void(* poll)(lwc_string *scheme)
poll a fetcher to let it make progress.
bool(* acceptable)(const struct nsurl *url)
Can this fetcher accept a url.
nserror(* schedule)(int t, void(*callback)(void *p), void *p)
Schedule a callback.
struct gui_misc_table * misc
Browser table.
Information about a fetcher for a given scheme.
int refcount
When zero the fetcher is no longer in use.
lwc_string * scheme
The scheme.
struct fetcher_operation_table ops
The fetchers operations.
Interface to time operations.
bool urldb_set_cookie(const char *header, nsurl *url, nsurl *referer)
Parse Set-Cookie header and insert cookie(s) into database.
Unified URL information database internal interface.
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.