diff options
author | Xan Lopez <xan@gnome.org> | 2009-07-27 14:55:57 +0300 |
---|---|---|
committer | Xan Lopez <xan@gnome.org> | 2009-07-27 14:55:57 +0300 |
commit | 9b05ca319c7dc24b3be067add3a8e1319e89e60a (patch) | |
tree | e36ed2051cb951e1114f08f638dbe7b411036c6b /libsoup | |
parent | 31d83bf9fdbd68378481623e5851e5d7ce2c6f2d (diff) | |
download | libsoup-9b05ca319c7dc24b3be067add3a8e1319e89e60a.tar.gz |
soup-cache: make the 'get-cacheability' function a virtual method
This way subclasses can override the default behaviour and decide, for
example, to serve non-fresh data in some situations.
Diffstat (limited to 'libsoup')
-rw-r--r-- | libsoup/soup-cache.c | 29 | ||||
-rw-r--r-- | libsoup/soup-cache.h | 23 |
2 files changed, 40 insertions, 12 deletions
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c index ef6208a7..2072e9dc 100644 --- a/libsoup/soup-cache.c +++ b/libsoup/soup-cache.c @@ -47,12 +47,6 @@ enum { PROP_CACHE_DIR }; -typedef enum { - SOUP_CACHE_CACHEABLE = (1 << 0), - SOUP_CACHE_UNCACHEABLE = (1 << 1), - SOUP_CACHE_INVALIDATES = (1 << 2) -} SoupCacheability; - #define SOUP_CACHE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_CACHE, SoupCachePrivate)) G_DEFINE_TYPE_WITH_CODE (SoupCache, soup_cache, G_TYPE_OBJECT, @@ -60,7 +54,7 @@ G_DEFINE_TYPE_WITH_CODE (SoupCache, soup_cache, G_TYPE_OBJECT, soup_cache_session_feature_init)) static SoupCacheability -get_cacheability (SoupMessage *msg) +get_cacheability (SoupCache *cache, SoupMessage *msg) { SoupCacheability cacheability; const char *cache_control; @@ -467,7 +461,7 @@ msg_got_headers_cb (SoupMessage *msg, SoupCache *cache) { SoupCacheability cacheable; - cacheable = get_cacheability (msg); + cacheable = soup_cache_get_cacheability (cache, msg); if (cacheable & SOUP_CACHE_CACHEABLE) { SoupCacheEntry *entry; @@ -804,6 +798,8 @@ soup_cache_class_init (SoupCacheClass *cache_class) gobject_class->set_property = soup_cache_set_property; gobject_class->get_property = soup_cache_get_property; + cache_class->get_cacheability = get_cacheability; + g_object_class_install_property(gobject_class, PROP_CACHE_DIR, g_param_spec_string("cache-dir", "Cache directory", @@ -832,3 +828,20 @@ soup_cache_new (const char *cache_dir) NULL); } +/** + * soup_cache_get_cacheability: + * @cache: a #SoupCache + * @msg: a #SoupMessage + * + * Calculates whether the @msg can be cached or not. + * + * Returns: a #SoupCacheability value indicating whether the @msg can be cached or not. + **/ +SoupCacheability +soup_cache_get_cacheability (SoupCache *cache, SoupMessage *msg) +{ + g_return_val_if_fail (SOUP_IS_CACHE (cache), SOUP_CACHE_UNCACHEABLE); + g_return_val_if_fail (SOUP_IS_MESSAGE (msg), SOUP_CACHE_UNCACHEABLE); + + return SOUP_CACHE_GET_CLASS (cache)->get_cacheability (cache, msg); +} diff --git a/libsoup/soup-cache.h b/libsoup/soup-cache.h index be3d7ca6..6854466b 100644 --- a/libsoup/soup-cache.h +++ b/libsoup/soup-cache.h @@ -19,6 +19,12 @@ G_BEGIN_DECLS typedef struct _SoupCachePrivate SoupCachePrivate; +typedef enum { + SOUP_CACHE_CACHEABLE = (1 << 0), + SOUP_CACHE_UNCACHEABLE = (1 << 1), + SOUP_CACHE_INVALIDATES = (1 << 2) +} SoupCacheability; + struct _SoupCache { GObject parent_instance; @@ -28,16 +34,25 @@ struct _SoupCache { typedef struct { GObjectClass parent_class; + /* methods */ + SoupCacheability (*get_cacheability) (SoupCache *cache, SoupMessage *msg); + /* Padding for future expansion */ void (*_libsoup_reserved1) (void); void (*_libsoup_reserved2) (void); void (*_libsoup_reserved3) (void); } SoupCacheClass; -GType soup_cache_get_type (void); -SoupCache *soup_cache_new (const char *cache_dir); -gboolean soup_cache_has_response (SoupCache *cache, SoupSession *session, SoupMessage *msg); -void soup_cache_send_response (SoupCache *cache, SoupSession *session, SoupMessage *msg); +GType soup_cache_get_type (void); +SoupCache* soup_cache_new (const char *cache_dir); +gboolean soup_cache_has_response (SoupCache *cache, + SoupSession *session, + SoupMessage *msg); +void soup_cache_send_response (SoupCache *cache, + SoupSession *session, + SoupMessage *msg); +SoupCacheability soup_cache_get_cacheability (SoupCache *cache, + SoupMessage *msg); G_END_DECLS |