[libsoup] Bug 677923 - Add soup_cookie_jar_set_cookie_with_first_party() alternative that takes a SoupCookie i
- From: Christophe Dumez <cdumez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Bug 677923 - Add soup_cookie_jar_set_cookie_with_first_party() alternative that takes a SoupCookie i
- Date: Tue, 12 Jun 2012 16:58:59 +0000 (UTC)
commit 786cb47cd55fed9529b8defe009790b4d8471859
Author: Christophe Dumez <christophe dumez intel com>
Date: Tue Jun 12 11:00:37 2012 +0300
Bug 677923 - Add soup_cookie_jar_set_cookie_with_first_party() alternative that takes a SoupCookie in argument
Currently, the only way to add a cookie while checking first_party is to use
soup_cookie_jar_set_cookie_with_first_party(). However, this function takes an
unparsed cookie in argument.
In the event the client has already parsed the cookie (e.g. to do some
pre-processing), it would be useful to have an alternative to
soup_cookie_jar_set_cookie_with_first_party() which takes a parsed SoupCookie
in argument. This would be more efficient.
docs/reference/libsoup-2.4-sections.txt | 1 +
libsoup/soup-cookie-jar.c | 57 +++++++++++++++++++++++-------
libsoup/soup-cookie-jar.h | 3 ++
3 files changed, 47 insertions(+), 14 deletions(-)
---
diff --git a/docs/reference/libsoup-2.4-sections.txt b/docs/reference/libsoup-2.4-sections.txt
index 0e62e36..959c643 100644
--- a/docs/reference/libsoup-2.4-sections.txt
+++ b/docs/reference/libsoup-2.4-sections.txt
@@ -883,6 +883,7 @@ soup_cookie_jar_set_cookie
soup_cookie_jar_set_cookie_with_first_party
<SUBSECTION>
soup_cookie_jar_add_cookie
+soup_cookie_jar_add_cookie_with_first_party
soup_cookie_jar_delete_cookie
soup_cookie_jar_all_cookies
<SUBSECTION>
diff --git a/libsoup/soup-cookie-jar.c b/libsoup/soup-cookie-jar.c
index 6925b32..6077717 100644
--- a/libsoup/soup-cookie-jar.c
+++ b/libsoup/soup-cookie-jar.c
@@ -527,6 +527,47 @@ soup_cookie_jar_add_cookie (SoupCookieJar *jar, SoupCookie *cookie)
}
/**
+ * soup_cookie_jar_add_cookie_with_first_party:
+ * @jar: a #SoupCookieJar
+ * @first_party: the URI for the main document
+ * @cookie: a #SoupCookie
+ *
+ * Adds @cookie to @jar, emitting the 'changed' signal if we are modifying
+ * an existing cookie or adding a valid new cookie ('valid' means
+ * that the cookie's expire date is not in the past).
+ *
+ * @first_party will be used to reject cookies coming from third party
+ * resources in case such a security policy is set in the @jar.
+ *
+ * @cookie will be 'stolen' by the jar, so don't free it afterwards.
+ *
+ * Since: 2.40
+ **/
+void
+soup_cookie_jar_add_cookie_with_first_party (SoupCookieJar *jar, SoupURI *first_party, SoupCookie *cookie)
+{
+ SoupCookieJarPrivate *priv;
+
+ g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
+ g_return_if_fail (first_party != NULL);
+ g_return_if_fail (cookie != NULL);
+
+ priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
+ if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER) {
+ soup_cookie_free (cookie);
+ return;
+ }
+
+ if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS ||
+ soup_cookie_domain_matches (cookie, first_party->host)) {
+ /* will steal or free soup_cookie */
+ soup_cookie_jar_add_cookie (jar, cookie);
+ } else {
+ soup_cookie_free (cookie);
+ }
+}
+
+/**
* soup_cookie_jar_set_cookie:
* @jar: a #SoupCookieJar
* @uri: the URI setting the cookie
@@ -591,7 +632,6 @@ soup_cookie_jar_set_cookie_with_first_party (SoupCookieJar *jar,
const char *cookie)
{
SoupCookie *soup_cookie;
- SoupCookieJarPrivate *priv;
g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
g_return_if_fail (uri != NULL);
@@ -601,20 +641,9 @@ soup_cookie_jar_set_cookie_with_first_party (SoupCookieJar *jar,
if (!uri->host)
return;
- priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
- if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
- return;
-
soup_cookie = soup_cookie_parse (cookie, uri);
- if (soup_cookie) {
- if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS ||
- soup_cookie_domain_matches (soup_cookie, first_party->host)) {
- /* will steal or free soup_cookie */
- soup_cookie_jar_add_cookie (jar, soup_cookie);
- } else {
- soup_cookie_free (soup_cookie);
- }
- }
+ if (soup_cookie)
+ soup_cookie_jar_add_cookie_with_first_party (jar, first_party, soup_cookie);
}
static void
diff --git a/libsoup/soup-cookie-jar.h b/libsoup/soup-cookie-jar.h
index fc39ff8..7ef0506 100644
--- a/libsoup/soup-cookie-jar.h
+++ b/libsoup/soup-cookie-jar.h
@@ -67,6 +67,9 @@ void soup_cookie_jar_set_cookie_with_first_party (SoupCooki
const char *cookie);
void soup_cookie_jar_add_cookie (SoupCookieJar *jar,
SoupCookie *cookie);
+void soup_cookie_jar_add_cookie_with_first_party (SoupCookieJar *jar,
+ SoupURI *first_party,
+ SoupCookie *cookie);
void soup_cookie_jar_delete_cookie (SoupCookieJar *jar,
SoupCookie *cookie);
GSList * soup_cookie_jar_all_cookies (SoupCookieJar *jar);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]