Subversion Repositories Kolibri OS

Rev

Rev 3584 | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
  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.  * High-level resource cache (interface)
  21.  */
  22.  
  23. #ifndef NETSURF_CONTENT_HLCACHE_H_
  24. #define NETSURF_CONTENT_HLCACHE_H_
  25.  
  26. #include "content/content.h"
  27. #include "content/llcache.h"
  28. #include "utils/errors.h"
  29. #include "utils/nsurl.h"
  30.  
  31. /** High-level cache handle */
  32. typedef struct hlcache_handle hlcache_handle;
  33.  
  34. /** Context for retrieving a child object */
  35. typedef struct hlcache_child_context {
  36.         const char *charset;            /**< Charset of parent */
  37.         bool quirks;                    /**< Whether parent is quirky */
  38. } hlcache_child_context;
  39.  
  40. /** High-level cache event */
  41. typedef struct {
  42.         content_msg type;               /**< Event type */
  43.         union content_msg_data data;    /**< Event data */
  44. } hlcache_event;
  45.  
  46. struct hlcache_parameters {
  47.         llcache_query_callback cb; /**< Query handler for llcache */
  48.         void *cb_ctx; /**< Pointer to llcache query handler data */
  49.  
  50.         /** How frequently the background cache clean process is run (ms) */
  51.         unsigned int bg_clean_time;
  52.  
  53.         /** The target upper bound for the cache size */
  54.         size_t limit;
  55.  
  56.         /** The hysteresis allowed round the target size */
  57.         size_t hysteresis;
  58.  
  59. };
  60.  
  61. /**
  62.  * Client callback for high-level cache events
  63.  *
  64.  * \param handle  Handle to object generating event
  65.  * \param event   Event data
  66.  * \param pw      Pointer to client-specific data
  67.  * \return NSERROR_OK on success, appropriate error otherwise.
  68.  */
  69. typedef nserror (*hlcache_handle_callback)(hlcache_handle *handle,
  70.                 const hlcache_event *event, void *pw);
  71.  
  72. /** Flags for high-level cache object retrieval */
  73. enum hlcache_retrieve_flag {
  74.         /* Note: low-level cache retrieval flags occupy the bottom 16 bits of
  75.          * the flags word. High-level cache flags occupy the top 16 bits.
  76.          * To avoid confusion, high-level flags are allocated from bit 31 down.
  77.          */
  78.         /** It's permitted to convert this request into a download */
  79.         HLCACHE_RETRIEVE_MAY_DOWNLOAD = (1 << 31),
  80.         /* Permit content-type sniffing */
  81.         HLCACHE_RETRIEVE_SNIFF_TYPE   = (1 << 30)
  82. };
  83.  
  84. /**
  85.  * Initialise the high-level cache, preparing the llcache also.
  86.  *
  87.  * \param hlcache_parameters Settings to initialise cache with  
  88.  * \return NSERROR_OK on success, appropriate error otherwise.
  89.  */
  90. nserror hlcache_initialise(const struct hlcache_parameters *hlcache_parameters);
  91.  
  92. /**
  93.  * Stop the high-level cache periodic functionality so that the
  94.  * exit sequence can run.
  95.  */
  96. void hlcache_stop(void);
  97.  
  98. /**
  99.  * Finalise the high-level cache, destroying any remaining contents
  100.  */
  101. void hlcache_finalise(void);
  102.  
  103. /**
  104.  * Drive the low-level cache poll loop, and attempt to clean the cache.
  105.  * No guarantee is made about what, if any, cache cleaning will occur.
  106.  *
  107.  * \return NSERROR_OK
  108.  */
  109. nserror hlcache_poll(void);
  110.  
  111. /**
  112.  * Retrieve a high-level cache handle for an object
  113.  *
  114.  * \param url             URL of the object to retrieve handle for
  115.  * \param flags           Object retrieval flags
  116.  * \param referer         Referring URL, or NULL if none
  117.  * \param post            POST data, or NULL for a GET request
  118.  * \param cb              Callback to handle object events
  119.  * \param pw              Pointer to client-specific data for callback
  120.  * \param child           Child retrieval context, or NULL for top-level content
  121.  * \param accepted_types  Bitmap of acceptable content types
  122.  * \param result          Pointer to location to recieve cache handle
  123.  * \return NSERROR_OK on success, appropriate error otherwise
  124.  *
  125.  * Child contents are keyed on the tuple < URL, quirks >.
  126.  * The quirks field is ignored for child contents whose behaviour is not
  127.  * affected by quirks mode.
  128.  *
  129.  * \todo The above rules should be encoded in the handler_map.
  130.  *
  131.  * \todo Is there any way to sensibly reduce the number of parameters here?
  132.  */
  133. nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags,
  134.                 nsurl *referer, llcache_post_data *post,
  135.                 hlcache_handle_callback cb, void *pw,
  136.                 hlcache_child_context *child,
  137.                 content_type accepted_types, hlcache_handle **result);
  138.  
  139. /**
  140.  * Release a high-level cache handle
  141.  *
  142.  * \param handle  Handle to release
  143.  * \return NSERROR_OK on success, appropriate error otherwise
  144.  */
  145. nserror hlcache_handle_release(hlcache_handle *handle);
  146.  
  147. /**
  148.  * Abort a high-level cache fetch
  149.  *
  150.  * \param handle  Handle to abort
  151.  * \return NSERROR_OK on success, appropriate error otherwise
  152.  */
  153. nserror hlcache_handle_abort(hlcache_handle *handle);
  154.  
  155. /**
  156.  * Replace a high-level cache handle's callback
  157.  *
  158.  * \param handle  Handle to replace callback of
  159.  * \param cb      New callback routine
  160.  * \param pw      Private data for callback
  161.  * \return NSERROR_OK on success, appropriate error otherwise
  162.  */
  163. nserror hlcache_handle_replace_callback(hlcache_handle *handle,
  164.                 hlcache_handle_callback cb, void *pw);
  165.  
  166. /**
  167.  * Retrieve a content object from a cache handle
  168.  *
  169.  * \param handle  Cache handle to dereference
  170.  * \return Pointer to content object, or NULL if there is none
  171.  *
  172.  * \todo This may not be correct. Ideally, the client should never need to
  173.  * directly access a content object. It may, therefore, be better to provide a
  174.  * bunch of veneers here that take a hlcache_handle and invoke the
  175.  * corresponding content_ API. If there's no content object associated with the
  176.  * hlcache_handle (e.g. because the source data is still being fetched, so it
  177.  * doesn't exist yet), then these veneers would behave as a NOP. The important
  178.  * thing being that the client need not care about this possibility and can
  179.  * just call the functions with impugnity.
  180.  */
  181. struct content *hlcache_handle_get_content(const hlcache_handle *handle);
  182.  
  183. /**
  184.  * Clone a high level cache handle.
  185.  *
  186.  * \param handle The handle to clone.
  187.  * \param result The cloned handle.
  188.  * \return NSERROR_OK on success, appropriate error otherwise
  189.  *
  190.  */
  191. nserror hlcache_handle_clone(hlcache_handle *handle, hlcache_handle **result);
  192.  
  193. /**
  194.  * Retrieve the URL associated with a high level cache handle
  195.  *
  196.  * \param handle  The handle to inspect
  197.  * \return  Pointer to URL.
  198.  */
  199. nsurl *hlcache_handle_get_url(const hlcache_handle *handle);
  200.  
  201. #endif
  202.