Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. /** \file
  20.  * Fetching of data from a URL (interface).
  21.  */
  22.  
  23. #ifndef _NETSURF_DESKTOP_FETCH_H_
  24. #define _NETSURF_DESKTOP_FETCH_H_
  25.  
  26. #include <stdbool.h>
  27.  
  28. #include <libwapcaplet/libwapcaplet.h>
  29.  
  30. #include "utils/config.h"
  31. #include "utils/nsurl.h"
  32.  
  33. struct content;
  34. struct fetch;
  35. struct ssl_cert_info;
  36.  
  37. typedef enum {
  38.         FETCH_PROGRESS,
  39.         FETCH_HEADER,
  40.         FETCH_DATA,
  41.         FETCH_FINISHED,
  42.         FETCH_ERROR,
  43.         FETCH_REDIRECT,
  44.         FETCH_NOTMODIFIED,
  45.         FETCH_AUTH,
  46.         FETCH_CERT_ERR,
  47.         FETCH_SSL_ERR
  48. } fetch_msg_type;
  49.  
  50. typedef struct fetch_msg {
  51.         fetch_msg_type type;
  52.  
  53.         union {
  54.                 const char *progress;
  55.  
  56.                 struct {
  57.                         const uint8_t *buf;
  58.                         size_t len;
  59.                 } header_or_data;
  60.  
  61.                 const char *error;
  62.  
  63.                 /** \todo Use nsurl */
  64.                 const char *redirect;
  65.  
  66.                 struct {
  67.                         const char *realm;
  68.                 } auth;
  69.  
  70.                 struct {
  71.                         const struct ssl_cert_info *certs;
  72.                         size_t num_certs;
  73.                 } cert_err;
  74.         } data;
  75. } fetch_msg;
  76.  
  77. /** Fetch POST multipart data */
  78. struct fetch_multipart_data {
  79.         bool file;                      /**< Item is a file */
  80.         char *name;                     /**< Name of item */
  81.         char *value;                    /**< Item value */
  82.  
  83.         struct fetch_multipart_data *next;      /**< Next in linked list */
  84. };
  85.  
  86. struct ssl_cert_info {
  87.         long version;           /**< Certificate version */
  88.         char not_before[32];    /**< Valid from date */
  89.         char not_after[32];     /**< Valid to date */
  90.         int sig_type;           /**< Signature type */
  91.         long serial;            /**< Serial number */
  92.         char issuer[256];       /**< Issuer details */
  93.         char subject[256];      /**< Subject details */
  94.         int cert_type;          /**< Certificate type */
  95. };
  96.  
  97. extern bool fetch_active;
  98.  
  99. typedef void (*fetch_callback)(const fetch_msg *msg, void *p);
  100.  
  101.  
  102. void fetch_init(void);
  103. struct fetch * fetch_start(nsurl *url, nsurl *referer,
  104.                 fetch_callback callback,
  105.                 void *p, bool only_2xx, const char *post_urlenc,
  106.                 const struct fetch_multipart_data *post_multipart,
  107.                 bool verifiable, bool downgrade_tls,
  108.                 const char *headers[]);
  109. void fetch_abort(struct fetch *f);
  110. void fetch_poll(void);
  111. void fetch_quit(void);
  112. const char *fetch_filetype(const char *unix_path);
  113. char *fetch_mimetype(const char *ro_path);
  114. bool fetch_can_fetch(const nsurl *url);
  115. void fetch_change_callback(struct fetch *fetch,
  116.                            fetch_callback callback,
  117.                            void *p);
  118. long fetch_http_code(struct fetch *fetch);
  119. bool fetch_get_verifiable(struct fetch *fetch);
  120.  
  121. void fetch_multipart_data_destroy(struct fetch_multipart_data *list);
  122. struct fetch_multipart_data *fetch_multipart_data_clone(
  123.                 const struct fetch_multipart_data *list);
  124.  
  125. /* API for fetchers themselves */
  126.  
  127. typedef bool (*fetcher_initialise)(lwc_string *scheme);
  128. typedef bool (*fetcher_can_fetch)(const nsurl *url);
  129. typedef void *(*fetcher_setup_fetch)(struct fetch *parent_fetch, nsurl *url,
  130.                 bool only_2xx, bool downgrade_tls, const char *post_urlenc,
  131.                 const struct fetch_multipart_data *post_multipart,
  132.                 const char **headers);
  133. typedef bool (*fetcher_start_fetch)(void *fetch);
  134. typedef void (*fetcher_abort_fetch)(void *fetch);
  135. typedef void (*fetcher_free_fetch)(void *fetch);
  136. typedef void (*fetcher_poll_fetcher)(lwc_string *scheme);
  137. typedef void (*fetcher_finalise)(lwc_string *scheme);
  138.  
  139. /** Register a fetcher for a scheme
  140.  *
  141.  * \param scheme        scheme fetcher is for (caller relinquishes ownership)
  142.  * \param initialiser   fetcher initialiser
  143.  * \param can_fetch     fetcher can fetch function
  144.  * \param setup_fetch   fetcher fetch setup function
  145.  * \param start_fetch   fetcher fetch start function
  146.  * \param abort_fetch   fetcher fetch abort function
  147.  * \param free_fetch    fetcher fetch free function
  148.  * \param poll_fetcher  fetcher poll function
  149.  * \param finaliser     fetcher finaliser
  150.  * \return true iff success
  151.  */
  152. bool fetch_add_fetcher(lwc_string *scheme,
  153.                        fetcher_initialise initialiser,
  154.                        fetcher_can_fetch can_fetch,
  155.                        fetcher_setup_fetch setup_fetch,
  156.                        fetcher_start_fetch start_fetch,
  157.                        fetcher_abort_fetch abort_fetch,
  158.                        fetcher_free_fetch free_fetch,
  159.                        fetcher_poll_fetcher poll_fetcher,
  160.                        fetcher_finalise finaliser);
  161.  
  162. void fetch_send_callback(const fetch_msg *msg, struct fetch *fetch);
  163. void fetch_remove_from_queues(struct fetch *fetch);
  164. void fetch_free(struct fetch *f);
  165. void fetch_set_http_code(struct fetch *fetch, long http_code);
  166. const char *fetch_get_referer_to_send(struct fetch *fetch);
  167. void fetch_set_cookie(struct fetch *fetch, const char *data);
  168.  
  169. #endif
  170.