2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2003-06-30 16:44:03 +04:00
|
|
|
*/
|
|
|
|
|
2003-09-18 03:27:33 +04:00
|
|
|
/** \file
|
|
|
|
* Fetching of data from a URL (interface).
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETSURF_DESKTOP_FETCH_H_
|
|
|
|
#define _NETSURF_DESKTOP_FETCH_H_
|
|
|
|
|
2003-08-29 16:57:14 +04:00
|
|
|
#include <stdbool.h>
|
2011-09-27 01:07:19 +04:00
|
|
|
|
|
|
|
#include <libwapcaplet/libwapcaplet.h>
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2011-09-27 15:07:32 +04:00
|
|
|
#include "utils/nsurl.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
struct content;
|
|
|
|
struct fetch;
|
2011-11-09 01:51:42 +04:00
|
|
|
struct ssl_cert_info;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FETCH_PROGRESS,
|
|
|
|
FETCH_HEADER,
|
|
|
|
FETCH_DATA,
|
|
|
|
FETCH_FINISHED,
|
|
|
|
FETCH_ERROR,
|
|
|
|
FETCH_REDIRECT,
|
|
|
|
FETCH_NOTMODIFIED,
|
|
|
|
FETCH_AUTH,
|
2013-01-05 03:13:23 +04:00
|
|
|
FETCH_CERT_ERR,
|
|
|
|
FETCH_SSL_ERR
|
2011-11-09 01:51:42 +04:00
|
|
|
} fetch_msg_type;
|
|
|
|
|
|
|
|
typedef struct fetch_msg {
|
|
|
|
fetch_msg_type type;
|
|
|
|
|
|
|
|
union {
|
|
|
|
const char *progress;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const uint8_t *buf;
|
|
|
|
size_t len;
|
|
|
|
} header_or_data;
|
|
|
|
|
|
|
|
const char *error;
|
|
|
|
|
|
|
|
/** \todo Use nsurl */
|
|
|
|
const char *redirect;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *realm;
|
|
|
|
} auth;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const struct ssl_cert_info *certs;
|
|
|
|
size_t num_certs;
|
|
|
|
} cert_err;
|
|
|
|
} data;
|
|
|
|
} fetch_msg;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
/** Fetch POST multipart data */
|
|
|
|
struct fetch_multipart_data {
|
|
|
|
bool file; /**< Item is a file */
|
|
|
|
char *name; /**< Name of item */
|
|
|
|
char *value; /**< Item value */
|
2014-01-04 23:34:04 +04:00
|
|
|
char *rawfile; /**< Raw filename if file is true */
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
struct fetch_multipart_data *next; /**< Next in linked list */
|
|
|
|
};
|
2006-02-06 03:10:09 +03:00
|
|
|
|
2006-02-23 18:06:54 +03:00
|
|
|
struct ssl_cert_info {
|
|
|
|
long version; /**< Certificate version */
|
|
|
|
char not_before[32]; /**< Valid from date */
|
|
|
|
char not_after[32]; /**< Valid to date */
|
|
|
|
int sig_type; /**< Signature type */
|
|
|
|
long serial; /**< Serial number */
|
|
|
|
char issuer[256]; /**< Issuer details */
|
|
|
|
char subject[256]; /**< Subject details */
|
|
|
|
int cert_type; /**< Certificate type */
|
|
|
|
};
|
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
extern bool fetch_active;
|
2007-06-10 21:46:44 +04:00
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
typedef void (*fetch_callback)(const fetch_msg *msg, void *p);
|
2007-06-10 21:46:44 +04:00
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
void fetch_init(void);
|
2011-09-27 15:07:32 +04:00
|
|
|
struct fetch * fetch_start(nsurl *url, nsurl *referer,
|
2009-07-10 04:26:37 +04:00
|
|
|
fetch_callback callback,
|
|
|
|
void *p, bool only_2xx, const char *post_urlenc,
|
2010-04-10 21:13:53 +04:00
|
|
|
const struct fetch_multipart_data *post_multipart,
|
2013-01-05 03:13:23 +04:00
|
|
|
bool verifiable, bool downgrade_tls,
|
2010-04-10 21:13:53 +04:00
|
|
|
const char *headers[]);
|
2003-02-09 15:58:15 +03:00
|
|
|
void fetch_abort(struct fetch *f);
|
|
|
|
void fetch_poll(void);
|
|
|
|
void fetch_quit(void);
|
2003-03-15 18:53:20 +03:00
|
|
|
const char *fetch_filetype(const char *unix_path);
|
2004-03-22 00:32:15 +03:00
|
|
|
char *fetch_mimetype(const char *ro_path);
|
2011-09-27 18:42:45 +04:00
|
|
|
bool fetch_can_fetch(const nsurl *url);
|
2004-06-28 03:24:11 +04:00
|
|
|
void fetch_change_callback(struct fetch *fetch,
|
2007-06-10 21:46:44 +04:00
|
|
|
fetch_callback callback,
|
|
|
|
void *p);
|
2007-01-13 03:19:02 +03:00
|
|
|
long fetch_http_code(struct fetch *fetch);
|
2009-02-16 23:24:54 +03:00
|
|
|
bool fetch_get_verifiable(struct fetch *fetch);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
void fetch_multipart_data_destroy(struct fetch_multipart_data *list);
|
|
|
|
struct fetch_multipart_data *fetch_multipart_data_clone(
|
|
|
|
const struct fetch_multipart_data *list);
|
|
|
|
|
2007-06-10 21:46:44 +04:00
|
|
|
/* API for fetchers themselves */
|
|
|
|
|
2013-01-05 03:13:23 +04:00
|
|
|
typedef bool (*fetcher_initialise)(lwc_string *scheme);
|
|
|
|
typedef bool (*fetcher_can_fetch)(const nsurl *url);
|
|
|
|
typedef void *(*fetcher_setup_fetch)(struct fetch *parent_fetch, nsurl *url,
|
|
|
|
bool only_2xx, bool downgrade_tls, const char *post_urlenc,
|
|
|
|
const struct fetch_multipart_data *post_multipart,
|
|
|
|
const char **headers);
|
|
|
|
typedef bool (*fetcher_start_fetch)(void *fetch);
|
|
|
|
typedef void (*fetcher_abort_fetch)(void *fetch);
|
|
|
|
typedef void (*fetcher_free_fetch)(void *fetch);
|
|
|
|
typedef void (*fetcher_poll_fetcher)(lwc_string *scheme);
|
|
|
|
typedef void (*fetcher_finalise)(lwc_string *scheme);
|
2007-06-10 21:46:44 +04:00
|
|
|
|
2011-09-27 01:23:47 +04:00
|
|
|
/** Register a fetcher for a scheme
|
|
|
|
*
|
|
|
|
* \param scheme scheme fetcher is for (caller relinquishes ownership)
|
|
|
|
* \param initialiser fetcher initialiser
|
2011-11-27 18:14:36 +04:00
|
|
|
* \param can_fetch fetcher can fetch function
|
2011-09-27 01:23:47 +04:00
|
|
|
* \param setup_fetch fetcher fetch setup function
|
|
|
|
* \param start_fetch fetcher fetch start function
|
|
|
|
* \param abort_fetch fetcher fetch abort function
|
|
|
|
* \param free_fetch fetcher fetch free function
|
|
|
|
* \param poll_fetcher fetcher poll function
|
|
|
|
* \param finaliser fetcher finaliser
|
|
|
|
* \return true iff success
|
|
|
|
*/
|
2011-09-27 01:07:19 +04:00
|
|
|
bool fetch_add_fetcher(lwc_string *scheme,
|
2007-06-10 21:46:44 +04:00
|
|
|
fetcher_initialise initialiser,
|
2011-11-27 18:14:36 +04:00
|
|
|
fetcher_can_fetch can_fetch,
|
2007-06-10 21:46:44 +04:00
|
|
|
fetcher_setup_fetch setup_fetch,
|
|
|
|
fetcher_start_fetch start_fetch,
|
|
|
|
fetcher_abort_fetch abort_fetch,
|
|
|
|
fetcher_free_fetch free_fetch,
|
|
|
|
fetcher_poll_fetcher poll_fetcher,
|
|
|
|
fetcher_finalise finaliser);
|
|
|
|
|
2011-11-09 01:51:42 +04:00
|
|
|
void fetch_send_callback(const fetch_msg *msg, struct fetch *fetch);
|
2007-07-04 22:44:13 +04:00
|
|
|
void fetch_remove_from_queues(struct fetch *fetch);
|
|
|
|
void fetch_free(struct fetch *f);
|
2007-06-10 21:46:44 +04:00
|
|
|
void fetch_set_http_code(struct fetch *fetch, long http_code);
|
|
|
|
const char *fetch_get_referer_to_send(struct fetch *fetch);
|
2008-01-30 22:56:41 +03:00
|
|
|
void fetch_set_cookie(struct fetch *fetch, const char *data);
|
2011-11-09 01:51:42 +04:00
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
#endif
|