diff options
Diffstat (limited to 'content/fetchers.h')
-rw-r--r-- | content/fetchers.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/content/fetchers.h b/content/fetchers.h new file mode 100644 index 000000000..d123de986 --- /dev/null +++ b/content/fetchers.h @@ -0,0 +1,141 @@ +/* + * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * 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 content/fetchers.h + * Interface for fetchers factory. + */ + +#ifndef _NETSURF_DESKTOP_FETCHERS_H_ +#define _NETSURF_DESKTOP_FETCHERS_H_ + +#include "utils/config.h" +#include <libwapcaplet/libwapcaplet.h> + +struct nsurl; +struct fetch_multipart_data; +struct fetch; + +/** + * Fetcher operations API + * + * These are the operations a fetcher must implement. + */ +struct fetcher_operation_table { + /** + * The initialiser for the fetcher. + * + * Called once to initialise the fetcher. + */ + bool (*initialise)(lwc_string *scheme); + + /** + * can this fetcher accept a url. + * + * \param url the URL to check + * \return true if the fetcher can handle the url else false. + */ + bool (*acceptable)(const struct nsurl *url); + + /** + * Setup a fetch + */ + 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); + + /** + * start a fetch. + */ + bool (*start)(void *fetch); + + /** + * abort a fetch. + */ + void (*abort)(void *fetch); + + /** + * free a fetch allocated through the setup method. + */ + void (*free)(void *fetch); + + /** + * poll a fetcher to let it make progress. + */ + void (*poll)(lwc_string *scheme); + + /** + * finalise the fetcher. + */ + void (*finalise)(lwc_string *scheme); +}; + + +/** + * Register a fetcher for a scheme + * + * \param scheme The scheme fetcher is for (caller relinquishes ownership) + * \param ops The operations for the fetcher. + * \return NSERROR_OK or appropriate error code. + */ +nserror fetcher_add(lwc_string *scheme, const struct fetcher_operation_table *ops); + + +/** + * Initialise the fetchers. + * + * @return NSERROR_OK or error code + */ +nserror fetcher_init(void); + + +/** + * Clean up for quit. + * + * Must be called before exiting. + */ +void fetcher_quit(void); + + +/** + * Get the set of file descriptors the fetchers are currently using. + * + * This obtains the file descriptors the fetch system is using to + * obtain data. It will cause the fetchers to make progress, if + * possible, potentially completing fetches before requiring activity + * on file descriptors. + * + * If a set of descriptors is returned (maxfd is not -1) The caller is + * expected to wait on them (with select etc.) and continue to obtain + * the fdset with this call. This will switch the fetchers from polled + * mode to waiting for network activity which is much more efficient. + * + * \note If the caller does not subsequently obtain the fdset again + * the fetchers will fall back to the less efficient polled + * operation. The fallback to polled operation will only occour after + * a timeout which introduces additional delay. + * + * \param read_fd_set[out] The fd set for read. + * \param write_fd_set[out] The fd set for write. + * \param except_fd_set[out] The fd set for exceptions. + * \param maxfd[out] The highest fd number in the set or -1 if no fd available. + * \return NSERROR_OK on success or appropriate error code. + */ +nserror fetcher_fdset(fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, int *maxfd); + +#endif |