From: Jens Georg Date: Mon, 2 Apr 2012 16:02:26 +0000 (+0200) Subject: Make internal resource cache version-independant X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ad03dc5b939867da6fc33a8bc59c591ab7ed46c;p=profile%2Fivi%2FGSSDP.git Make internal resource cache version-independant https://bugzilla.gnome.org/show_bug.cgi?id=673150 --- diff --git a/libgssdp/gssdp-resource-browser.c b/libgssdp/gssdp-resource-browser.c index b0c5d20..9441d5b 100644 --- a/libgssdp/gssdp-resource-browser.c +++ b/libgssdp/gssdp-resource-browser.c @@ -126,7 +126,7 @@ gssdp_resource_browser_init (GSSDPResourceBrowser *resource_browser) resource_browser->priv->resources = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, + g_free, resource_free); } @@ -622,13 +622,24 @@ resource_available (GSSDPResourceBrowser *resource_browser, gboolean was_cached; guint timeout; GList *locations; + char *canonical_usn; usn = soup_message_headers_get_one (headers, "USN"); if (!usn) return; /* No USN specified */ + if (resource_browser->priv->version > 0) { + char *version; + + version = g_strrstr (usn, ":"); + canonical_usn = g_strndup (usn, version - usn); + } else { + canonical_usn = g_strdup (usn); + } + /* Get from cache, if possible */ - resource = g_hash_table_lookup (resource_browser->priv->resources, usn); + resource = g_hash_table_lookup (resource_browser->priv->resources, + canonical_usn); if (resource) { /* Remove old timeout */ g_source_destroy (resource->timeout_src); @@ -642,12 +653,18 @@ resource_available (GSSDPResourceBrowser *resource_browser, resource->usn = g_strdup (usn); g_hash_table_insert (resource_browser->priv->resources, - resource->usn, + canonical_usn, resource); was_cached = FALSE; + + /* hash-table takes ownership of this */ + canonical_usn = NULL; } + if (canonical_usn != NULL) + g_free (canonical_usn); + /* Calculate new timeout */ header = soup_message_headers_get_one (headers, "Cache-Control"); if (header) { @@ -777,21 +794,36 @@ resource_unavailable (GSSDPResourceBrowser *resource_browser, SoupMessageHeaders *headers) { const char *usn; + char *canonical_usn; usn = soup_message_headers_get_one (headers, "USN"); if (!usn) return; /* No USN specified */ + if (resource_browser->priv->version > 0) { + char *version; + + version = g_strrstr (usn, ":"); + canonical_usn = g_strndup (usn, version - usn); + } else { + canonical_usn = g_strdup (usn); + } + /* Only process if we were cached */ - if (!g_hash_table_lookup (resource_browser->priv->resources, usn)) - return; + if (!g_hash_table_lookup (resource_browser->priv->resources, + canonical_usn)) + goto out; - g_hash_table_remove (resource_browser->priv->resources, usn); + g_hash_table_remove (resource_browser->priv->resources, + canonical_usn); g_signal_emit (resource_browser, signals[RESOURCE_UNAVAILABLE], 0, usn); + +out: + g_free (canonical_usn); } static gboolean