1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright (C) 2008 Red Hat, Inc.
15 #include "soup-cookie.h"
16 #include "soup-cookie-jar.h"
17 #include "soup-date.h"
18 #include "soup-enum-types.h"
19 #include "soup-marshal.h"
20 #include "soup-message.h"
21 #include "soup-session-feature.h"
26 * SECTION:soup-cookie-jar
27 * @short_description: Automatic cookie handling for #SoupSession
29 * A #SoupCookieJar stores #SoupCookie<!-- -->s and arrange for them
30 * to be sent with the appropriate #SoupMessage<!-- -->s.
31 * #SoupCookieJar implements #SoupSessionFeature, so you can add a
32 * cookie jar to a session with soup_session_add_feature() or
33 * soup_session_add_feature_by_type().
35 * Note that the base #SoupCookieJar class does not support any form
36 * of long-term cookie persistence.
39 static void soup_cookie_jar_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer interface_data);
41 G_DEFINE_TYPE_WITH_CODE (SoupCookieJar, soup_cookie_jar, G_TYPE_OBJECT,
42 G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE,
43 soup_cookie_jar_session_feature_init))
50 static guint signals[LAST_SIGNAL] = { 0 };
62 gboolean constructed, read_only;
63 GHashTable *domains, *serials;
65 SoupCookieJarAcceptPolicy accept_policy;
66 } SoupCookieJarPrivate;
67 #define SOUP_COOKIE_JAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_COOKIE_JAR, SoupCookieJarPrivate))
70 soup_cookie_jar_init (SoupCookieJar *jar)
72 SoupCookieJarPrivate *priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
74 priv->domains = g_hash_table_new_full (soup_str_case_hash,
77 priv->serials = g_hash_table_new (NULL, NULL);
78 priv->accept_policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
82 soup_cookie_jar_constructed (GObject *object)
84 SoupCookieJarPrivate *priv = SOUP_COOKIE_JAR_GET_PRIVATE (object);
86 priv->constructed = TRUE;
90 soup_cookie_jar_finalize (GObject *object)
92 SoupCookieJarPrivate *priv = SOUP_COOKIE_JAR_GET_PRIVATE (object);
96 g_hash_table_iter_init (&iter, priv->domains);
97 while (g_hash_table_iter_next (&iter, &key, &value))
98 soup_cookies_free (value);
99 g_hash_table_destroy (priv->domains);
100 g_hash_table_destroy (priv->serials);
102 G_OBJECT_CLASS (soup_cookie_jar_parent_class)->finalize (object);
106 soup_cookie_jar_set_property (GObject *object, guint prop_id,
107 const GValue *value, GParamSpec *pspec)
109 SoupCookieJarPrivate *priv =
110 SOUP_COOKIE_JAR_GET_PRIVATE (object);
114 priv->read_only = g_value_get_boolean (value);
116 case PROP_ACCEPT_POLICY:
117 priv->accept_policy = g_value_get_enum (value);
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
126 soup_cookie_jar_get_property (GObject *object, guint prop_id,
127 GValue *value, GParamSpec *pspec)
129 SoupCookieJarPrivate *priv =
130 SOUP_COOKIE_JAR_GET_PRIVATE (object);
134 g_value_set_boolean (value, priv->read_only);
136 case PROP_ACCEPT_POLICY:
137 g_value_set_enum (value, priv->accept_policy);
140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
146 soup_cookie_jar_real_is_persistent (SoupCookieJar *jar)
152 soup_cookie_jar_class_init (SoupCookieJarClass *jar_class)
154 GObjectClass *object_class = G_OBJECT_CLASS (jar_class);
156 g_type_class_add_private (jar_class, sizeof (SoupCookieJarPrivate));
158 object_class->constructed = soup_cookie_jar_constructed;
159 object_class->finalize = soup_cookie_jar_finalize;
160 object_class->set_property = soup_cookie_jar_set_property;
161 object_class->get_property = soup_cookie_jar_get_property;
163 jar_class->is_persistent = soup_cookie_jar_real_is_persistent;
166 * SoupCookieJar::changed:
167 * @jar: the #SoupCookieJar
168 * @old_cookie: the old #SoupCookie value
169 * @new_cookie: the new #SoupCookie value
171 * Emitted when @jar changes. If a cookie has been added,
172 * @new_cookie will contain the newly-added cookie and
173 * @old_cookie will be %NULL. If a cookie has been deleted,
174 * @old_cookie will contain the to-be-deleted cookie and
175 * @new_cookie will be %NULL. If a cookie has been changed,
176 * @old_cookie will contain its old value, and @new_cookie its
180 g_signal_new ("changed",
181 G_OBJECT_CLASS_TYPE (object_class),
183 G_STRUCT_OFFSET (SoupCookieJarClass, changed),
185 _soup_marshal_NONE__BOXED_BOXED,
187 SOUP_TYPE_COOKIE | G_SIGNAL_TYPE_STATIC_SCOPE,
188 SOUP_TYPE_COOKIE | G_SIGNAL_TYPE_STATIC_SCOPE);
191 * SOUP_COOKIE_JAR_READ_ONLY:
193 * Alias for the #SoupCookieJar:read-only property. (Whether
194 * or not the cookie jar is read-only.)
196 g_object_class_install_property (
197 object_class, PROP_READ_ONLY,
198 g_param_spec_boolean (SOUP_COOKIE_JAR_READ_ONLY,
200 "Whether or not the cookie jar is read-only",
202 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
205 * SOUP_COOKIE_JAR_ACCEPT_POLICY:
207 * Alias for the #SoupCookieJar:accept-policy property.
212 * SoupCookieJar:accept-policy:
214 * The policy the jar should follow to accept or reject cookies
218 g_object_class_install_property (
219 object_class, PROP_ACCEPT_POLICY,
220 g_param_spec_enum (SOUP_COOKIE_JAR_ACCEPT_POLICY,
222 "The policy the jar should follow to accept or reject cookies",
223 SOUP_TYPE_COOKIE_JAR_ACCEPT_POLICY,
224 SOUP_COOKIE_JAR_ACCEPT_ALWAYS,
229 * soup_cookie_jar_new:
231 * Creates a new #SoupCookieJar. The base #SoupCookieJar class does
232 * not support persistent storage of cookies; use a subclass for that.
234 * Returns: a new #SoupCookieJar
239 soup_cookie_jar_new (void)
241 return g_object_new (SOUP_TYPE_COOKIE_JAR, NULL);
245 * soup_cookie_jar_save:
246 * @jar: a #SoupCookieJar
248 * This function exists for backward compatibility, but does not do
249 * anything any more; cookie jars are saved automatically when they
253 soup_cookie_jar_save (SoupCookieJar *jar)
255 /* Does nothing, obsolete */
259 soup_cookie_jar_changed (SoupCookieJar *jar,
260 SoupCookie *old, SoupCookie *new)
262 SoupCookieJarPrivate *priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
264 if (old && old != new)
265 g_hash_table_remove (priv->serials, old);
268 g_hash_table_insert (priv->serials, new, GUINT_TO_POINTER (priv->serial));
271 if (priv->read_only || !priv->constructed)
274 g_signal_emit (jar, signals[CHANGED], 0, old, new);
278 compare_cookies (gconstpointer a, gconstpointer b, gpointer jar)
280 SoupCookie *ca = (SoupCookie *)a;
281 SoupCookie *cb = (SoupCookie *)b;
282 SoupCookieJarPrivate *priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
284 guint aserial, bserial;
286 /* "Cookies with longer path fields are listed before cookies
287 * with shorter path field."
289 alen = ca->path ? strlen (ca->path) : 0;
290 blen = cb->path ? strlen (cb->path) : 0;
294 /* "Among cookies that have equal length path fields, cookies
295 * with earlier creation dates are listed before cookies with
296 * later creation dates."
298 aserial = GPOINTER_TO_UINT (g_hash_table_lookup (priv->serials, ca));
299 bserial = GPOINTER_TO_UINT (g_hash_table_lookup (priv->serials, cb));
300 return aserial - bserial;
304 get_cookies (SoupCookieJar *jar, SoupURI *uri, gboolean for_http, gboolean copy_cookies)
306 SoupCookieJarPrivate *priv;
307 GSList *cookies, *domain_cookies;
308 char *domain, *cur, *next_domain;
309 GSList *new_head, *cookies_to_remove = NULL, *p;
311 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
316 /* The logic here is a little weird, but the plan is that if
317 * uri->host is "www.foo.com", we will end up looking up
318 * cookies for ".www.foo.com", "www.foo.com", ".foo.com", and
319 * ".com", in that order. (Logic stolen from Mozilla.)
322 domain = cur = g_strdup_printf (".%s", uri->host);
323 next_domain = domain + 1;
325 new_head = domain_cookies = g_hash_table_lookup (priv->domains, cur);
326 while (domain_cookies) {
327 GSList *next = domain_cookies->next;
328 SoupCookie *cookie = domain_cookies->data;
330 if (cookie->expires && soup_date_is_past (cookie->expires)) {
331 cookies_to_remove = g_slist_append (cookies_to_remove,
333 new_head = g_slist_delete_link (new_head, domain_cookies);
334 g_hash_table_insert (priv->domains,
337 } else if (soup_cookie_applies_to_uri (cookie, uri) &&
338 (for_http || !cookie->http_only))
339 cookies = g_slist_append (cookies, copy_cookies ? soup_cookie_copy (cookie) : cookie);
341 domain_cookies = next;
345 next_domain = strchr (cur + 1, '.');
349 for (p = cookies_to_remove; p; p = p->next) {
350 SoupCookie *cookie = p->data;
352 soup_cookie_jar_changed (jar, cookie, NULL);
353 soup_cookie_free (cookie);
355 g_slist_free (cookies_to_remove);
357 return g_slist_sort_with_data (cookies, compare_cookies, jar);
361 * soup_cookie_jar_get_cookies:
362 * @jar: a #SoupCookieJar
364 * @for_http: whether or not the return value is being passed directly
365 * to an HTTP operation
367 * Retrieves (in Cookie-header form) the list of cookies that would
368 * be sent with a request to @uri.
370 * If @for_http is %TRUE, the return value will include cookies marked
371 * "HttpOnly" (that is, cookies that the server wishes to keep hidden
372 * from client-side scripting operations such as the JavaScript
373 * document.cookies property). Since #SoupCookieJar sets the Cookie
374 * header itself when making the actual HTTP request, you should
375 * almost certainly be setting @for_http to %FALSE if you are calling
378 * Return value: the cookies, in string form, or %NULL if there are no
384 soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
389 g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
390 g_return_val_if_fail (uri != NULL, NULL);
392 cookies = get_cookies (jar, uri, for_http, FALSE);
395 char *result = soup_cookies_to_cookie_header (cookies);
396 g_slist_free (cookies);
408 * soup_cookie_jar_get_cookie_list:
409 * @jar: a #SoupCookieJar
411 * @for_http: whether or not the return value is being passed directly
412 * to an HTTP operation
414 * Retrieves the list of cookies that would be sent with a request to @uri
415 * as a #GSList of #SoupCookie objects.
417 * If @for_http is %TRUE, the return value will include cookies marked
418 * "HttpOnly" (that is, cookies that the server wishes to keep hidden
419 * from client-side scripting operations such as the JavaScript
420 * document.cookies property). Since #SoupCookieJar sets the Cookie
421 * header itself when making the actual HTTP request, you should
422 * almost certainly be setting @for_http to %FALSE if you are calling
425 * Return value: (transfer full) (element-type Soup.Cookie): a #GSList
426 * with the cookies in the @jar that would be sent with a request to @uri.
431 soup_cookie_jar_get_cookie_list (SoupCookieJar *jar, SoupURI *uri, gboolean for_http)
433 g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
434 g_return_val_if_fail (uri != NULL, NULL);
436 return get_cookies (jar, uri, for_http, TRUE);
440 * soup_cookie_jar_add_cookie:
441 * @jar: a #SoupCookieJar
442 * @cookie: a #SoupCookie
444 * Adds @cookie to @jar, emitting the 'changed' signal if we are modifying
445 * an existing cookie or adding a valid new cookie ('valid' means
446 * that the cookie's expire date is not in the past).
448 * @cookie will be 'stolen' by the jar, so don't free it afterwards.
453 soup_cookie_jar_add_cookie (SoupCookieJar *jar, SoupCookie *cookie)
455 SoupCookieJarPrivate *priv;
456 GSList *old_cookies, *oc, *last = NULL;
457 SoupCookie *old_cookie;
459 g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
460 g_return_if_fail (cookie != NULL);
462 /* Never accept cookies for public domains. */
463 if (!g_hostname_is_ip_address (cookie->domain) &&
464 soup_tld_domain_is_public_suffix (cookie->domain)) {
465 soup_cookie_free (cookie);
469 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
470 old_cookies = g_hash_table_lookup (priv->domains, cookie->domain);
471 for (oc = old_cookies; oc; oc = oc->next) {
472 old_cookie = oc->data;
473 if (!strcmp (cookie->name, old_cookie->name) &&
474 !g_strcmp0 (cookie->path, old_cookie->path)) {
475 if (cookie->expires && soup_date_is_past (cookie->expires)) {
476 /* The new cookie has an expired date,
477 * this is the way the the server has
478 * of telling us that we have to
481 old_cookies = g_slist_delete_link (old_cookies, oc);
482 g_hash_table_insert (priv->domains,
483 g_strdup (cookie->domain),
485 soup_cookie_jar_changed (jar, old_cookie, NULL);
486 soup_cookie_free (old_cookie);
487 soup_cookie_free (cookie);
490 soup_cookie_jar_changed (jar, old_cookie, cookie);
491 soup_cookie_free (old_cookie);
499 /* The new cookie is... a new cookie */
500 if (cookie->expires && soup_date_is_past (cookie->expires)) {
501 soup_cookie_free (cookie);
506 last->next = g_slist_append (NULL, cookie);
508 old_cookies = g_slist_append (NULL, cookie);
509 g_hash_table_insert (priv->domains, g_strdup (cookie->domain),
513 soup_cookie_jar_changed (jar, NULL, cookie);
517 * soup_cookie_jar_add_cookie_with_first_party:
518 * @jar: a #SoupCookieJar
519 * @first_party: the URI for the main document
520 * @cookie: a #SoupCookie
522 * Adds @cookie to @jar, emitting the 'changed' signal if we are modifying
523 * an existing cookie or adding a valid new cookie ('valid' means
524 * that the cookie's expire date is not in the past).
526 * @first_party will be used to reject cookies coming from third party
527 * resources in case such a security policy is set in the @jar.
529 * @cookie will be 'stolen' by the jar, so don't free it afterwards.
534 soup_cookie_jar_add_cookie_with_first_party (SoupCookieJar *jar, SoupURI *first_party, SoupCookie *cookie)
536 SoupCookieJarPrivate *priv;
538 g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
539 g_return_if_fail (first_party != NULL);
540 g_return_if_fail (cookie != NULL);
542 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
543 if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER) {
544 soup_cookie_free (cookie);
548 if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS ||
549 soup_cookie_domain_matches (cookie, first_party->host)) {
550 /* will steal or free soup_cookie */
551 soup_cookie_jar_add_cookie (jar, cookie);
553 soup_cookie_free (cookie);
558 * soup_cookie_jar_set_cookie:
559 * @jar: a #SoupCookieJar
560 * @uri: the URI setting the cookie
561 * @cookie: the stringified cookie to set
563 * Adds @cookie to @jar, exactly as though it had appeared in a
564 * Set-Cookie header returned from a request to @uri.
566 * Keep in mind that if the #SoupCookieJarAcceptPolicy
567 * %SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY is set you'll need to use
568 * soup_cookie_jar_set_cookie_with_first_party(), otherwise the jar
569 * will have no way of knowing if the cookie is being set by a third
575 soup_cookie_jar_set_cookie (SoupCookieJar *jar, SoupURI *uri,
578 SoupCookie *soup_cookie;
579 SoupCookieJarPrivate *priv;
581 g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
582 g_return_if_fail (uri != NULL);
583 g_return_if_fail (cookie != NULL);
588 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
589 if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
592 g_return_if_fail (priv->accept_policy != SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
594 soup_cookie = soup_cookie_parse (cookie, uri);
596 /* will steal or free soup_cookie */
597 soup_cookie_jar_add_cookie (jar, soup_cookie);
602 * soup_cookie_jar_set_cookie_with_first_party:
603 * @jar: a #SoupCookieJar
604 * @uri: the URI setting the cookie
605 * @first_party: the URI for the main document
606 * @cookie: the stringified cookie to set
608 * Adds @cookie to @jar, exactly as though it had appeared in a
609 * Set-Cookie header returned from a request to @uri. @first_party
610 * will be used to reject cookies coming from third party resources in
611 * case such a security policy is set in the @jar.
616 soup_cookie_jar_set_cookie_with_first_party (SoupCookieJar *jar,
618 SoupURI *first_party,
621 SoupCookie *soup_cookie;
623 g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
624 g_return_if_fail (uri != NULL);
625 g_return_if_fail (first_party != NULL);
626 g_return_if_fail (cookie != NULL);
631 soup_cookie = soup_cookie_parse (cookie, uri);
633 soup_cookie_jar_add_cookie_with_first_party (jar, first_party, soup_cookie);
637 process_set_cookie_header (SoupMessage *msg, gpointer user_data)
639 SoupCookieJar *jar = user_data;
640 SoupCookieJarPrivate *priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
641 GSList *new_cookies, *nc;
643 if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
646 new_cookies = soup_cookies_from_response (msg);
647 for (nc = new_cookies; nc; nc = nc->next) {
648 SoupURI *first_party = soup_message_get_first_party (msg);
650 if ((priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY &&
651 first_party != NULL && first_party->host &&
652 soup_cookie_domain_matches (nc->data, first_party->host)) ||
653 priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS)
654 soup_cookie_jar_add_cookie (jar, nc->data);
656 soup_cookie_free (nc->data);
658 g_slist_free (new_cookies);
662 soup_cookie_jar_request_queued (SoupSessionFeature *feature,
663 SoupSession *session,
666 soup_message_add_header_handler (msg, "got-headers",
668 G_CALLBACK (process_set_cookie_header),
673 soup_cookie_jar_request_started (SoupSessionFeature *feature,
674 SoupSession *session,
678 SoupCookieJar *jar = SOUP_COOKIE_JAR (feature);
681 cookies = soup_cookie_jar_get_cookies (jar, soup_message_get_uri (msg), TRUE);
683 soup_message_headers_replace (msg->request_headers,
687 soup_message_headers_remove (msg->request_headers, "Cookie");
691 soup_cookie_jar_request_unqueued (SoupSessionFeature *feature,
692 SoupSession *session,
695 g_signal_handlers_disconnect_by_func (msg, process_set_cookie_header, feature);
699 soup_cookie_jar_session_feature_init (SoupSessionFeatureInterface *feature_interface,
700 gpointer interface_data)
702 feature_interface->request_queued = soup_cookie_jar_request_queued;
703 feature_interface->request_started = soup_cookie_jar_request_started;
704 feature_interface->request_unqueued = soup_cookie_jar_request_unqueued;
708 * soup_cookie_jar_all_cookies:
709 * @jar: a #SoupCookieJar
711 * Constructs a #GSList with every cookie inside the @jar.
712 * The cookies in the list are a copy of the original, so
713 * you have to free them when you are done with them.
715 * Return value: (transfer full) (element-type Soup.Cookie): a #GSList
716 * with all the cookies in the @jar.
721 soup_cookie_jar_all_cookies (SoupCookieJar *jar)
723 SoupCookieJarPrivate *priv;
728 g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
730 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
732 g_hash_table_iter_init (&iter, priv->domains);
734 while (g_hash_table_iter_next (&iter, &key, &value)) {
735 GSList *p, *cookies = value;
736 for (p = cookies; p; p = p->next)
737 l = g_slist_prepend (l, soup_cookie_copy (p->data));
744 * soup_cookie_jar_delete_cookie:
745 * @jar: a #SoupCookieJar
746 * @cookie: a #SoupCookie
748 * Deletes @cookie from @jar, emitting the 'changed' signal.
753 soup_cookie_jar_delete_cookie (SoupCookieJar *jar,
756 SoupCookieJarPrivate *priv;
760 g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
761 g_return_if_fail (cookie != NULL);
763 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
765 domain = g_strdup (cookie->domain);
767 cookies = g_hash_table_lookup (priv->domains, domain);
771 for (p = cookies; p; p = p->next ) {
772 SoupCookie *c = (SoupCookie*)p->data;
773 if (soup_cookie_equal (cookie, c)) {
774 cookies = g_slist_delete_link (cookies, p);
775 g_hash_table_insert (priv->domains,
778 soup_cookie_jar_changed (jar, c, NULL);
779 soup_cookie_free (c);
786 * SoupCookieJarAcceptPolicy:
787 * @SOUP_COOKIE_JAR_ACCEPT_ALWAYS: accept all cookies unconditionally.
788 * @SOUP_COOKIE_JAR_ACCEPT_NEVER: reject all cookies unconditionally.
789 * @SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY: accept all cookies set by
790 * the main document loaded in the application using libsoup. An
791 * example of the most common case, web browsers, would be: If
792 * http://www.example.com is the page loaded, accept all cookies set
793 * by example.com, but if a resource from http://www.third-party.com
794 * is loaded from that page reject any cookie that it could try to
795 * set. For libsoup to be able to tell apart first party cookies from
796 * the rest, the application must call soup_message_set_first_party()
797 * on each outgoing #SoupMessage, setting the #SoupURI of the main
798 * document. If no first party is set in a message when this policy is
799 * in effect, cookies will be assumed to be third party by default.
805 * soup_cookie_jar_get_accept_policy:
806 * @jar: a #SoupCookieJar
808 * Gets @jar's #SoupCookieJarAcceptPolicy
810 * Returns: the #SoupCookieJarAcceptPolicy set in the @jar
814 SoupCookieJarAcceptPolicy
815 soup_cookie_jar_get_accept_policy (SoupCookieJar *jar)
817 SoupCookieJarPrivate *priv;
819 g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), SOUP_COOKIE_JAR_ACCEPT_ALWAYS);
821 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
822 return priv->accept_policy;
826 * soup_cookie_jar_set_accept_policy:
827 * @jar: a #SoupCookieJar
828 * @policy: a #SoupCookieJarAcceptPolicy
830 * Sets @policy as the cookie acceptance policy for @jar.
835 soup_cookie_jar_set_accept_policy (SoupCookieJar *jar,
836 SoupCookieJarAcceptPolicy policy)
838 SoupCookieJarPrivate *priv;
840 g_return_if_fail (SOUP_IS_COOKIE_JAR (jar));
842 priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
844 if (priv->accept_policy != policy) {
845 priv->accept_policy = policy;
846 g_object_notify (G_OBJECT (jar), SOUP_COOKIE_JAR_ACCEPT_POLICY);
851 * soup_cookie_jar_is_persistent:
852 * @jar: a #SoupCookieJar
854 * Gets whether @jar stores cookies persistenly.
856 * Returns: %TRUE if @jar storage is persistent or %FALSE otherwise.
861 soup_cookie_jar_is_persistent (SoupCookieJar *jar)
863 g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), FALSE);
865 return SOUP_COOKIE_JAR_GET_CLASS (jar)->is_persistent (jar);