Merge lp:~kalikiana/midori/soupcookiejar into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: André Stösel
Approved revision: 6262
Merged at revision: 6292
Proposed branch: lp:~kalikiana/midori/soupcookiejar
Merge into: lp:midori
Diff against target: 874 lines (+36/-747)
9 files modified
katze/katze-http-cookies-sqlite.c (+0/-292)
katze/katze-http-cookies-sqlite.h (+0/-42)
katze/katze-http-cookies.c (+0/-331)
katze/katze-http-cookies.h (+0/-42)
katze/katze.h (+0/-2)
midori/midori-frontend.c (+0/-5)
midori/midori-privatedata.c (+0/-8)
midori/midori-session.c (+35/-24)
wscript (+1/-1)
To merge this branch: bzr merge lp:~kalikiana/midori/soupcookiejar
Reviewer Review Type Date Requested Status
André Stösel Approve
Review via email: mp+174882@code.launchpad.net

Commit message

Use SoupCookieJarSqlite and drop KatzeHttpCookies(Sqlite)

To post a comment you must log in.
Revision history for this message
André Stösel (ivaldi) wrote :

The cookie handling works fine (like before), but this patch doesn't fix the related bug.

review: Needs Fixing
Revision history for this message
Cris Dywan (kalikiana) wrote :

I apologize for the confusion. I intended for the branch to be the prerequisite step, since it immensely simplifies the relevant code, before tackling the real issue. I'm therefore fixing the 'related branch' now.

Revision history for this message
André Stösel (ivaldi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed file 'katze/katze-http-cookies-sqlite.c'
--- katze/katze-http-cookies-sqlite.c 2012-07-19 19:14:09 +0000
+++ katze/katze-http-cookies-sqlite.c 1970-01-01 00:00:00 +0000
@@ -1,292 +0,0 @@
1/*
2 Copyright (C) 2008-2010 Christian Dywan <christian@twotoasts.de>
3 Copyright (C) 2011 Alexander Butenko <a.butenka@gmail.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 See the file COPYING for the full license text.
11*/
12
13#if HAVE_CONFIG_H
14 #include <config.h>
15#endif
16
17#include "katze-http-cookies-sqlite.h"
18
19#include <stdlib.h>
20#ifdef HAVE_UNISTD_H
21 #include <unistd.h>
22#endif
23#include <glib/gi18n.h>
24#include <libsoup/soup.h>
25#include <gtk/gtk.h>
26#include <glib/gstdio.h>
27#include <sqlite3.h>
28
29#define QUERY_ALL "SELECT id, name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly FROM moz_cookies;"
30#define CREATE_TABLE "CREATE TABLE IF NOT EXISTS moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER)"
31#define QUERY_INSERT "INSERT INTO moz_cookies VALUES(NULL, %Q, %Q, %Q, %Q, %d, NULL, %d, %d);"
32#define QUERY_DELETE "DELETE FROM moz_cookies WHERE name=%Q AND host=%Q;"
33
34enum {
35 COL_ID,
36 COL_NAME,
37 COL_VALUE,
38 COL_HOST,
39 COL_PATH,
40 COL_EXPIRY,
41 COL_LAST_ACCESS,
42 COL_SECURE,
43 COL_HTTP_ONLY,
44 N_COL,
45};
46
47struct _KatzeHttpCookiesSqlite
48{
49 GObject parent_instance;
50 gchar* filename;
51 SoupCookieJar* jar;
52 sqlite3 *db;
53 guint counter;
54};
55
56struct _KatzeHttpCookiesSqliteClass
57{
58 GObjectClass parent_class;
59};
60
61static void
62katze_http_cookies_sqlite_session_feature_iface_init (SoupSessionFeatureInterface *iface,
63 gpointer data);
64
65G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookiesSqlite, katze_http_cookies_sqlite, G_TYPE_OBJECT,
66 G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE,
67 katze_http_cookies_sqlite_session_feature_iface_init));
68
69/* Cookie jar saving into sqlite database
70 Copyright (C) 2008 Diego Escalante Urrelo
71 Copyright (C) 2009 Collabora Ltd.
72 Mostly copied from libSoup 2.30, coding style retained */
73
74/* Follows sqlite3 convention; returns TRUE on error */
75static gboolean
76katze_http_cookies_sqlite_open_db (KatzeHttpCookiesSqlite* http_cookies)
77{
78 char *error = NULL;
79
80 if (sqlite3_open (http_cookies->filename, &http_cookies->db)) {
81 sqlite3_close (http_cookies->db);
82 g_warning ("Can't open %s", http_cookies->filename);
83 return TRUE;
84 }
85
86 if (sqlite3_exec (http_cookies->db, CREATE_TABLE, NULL, NULL, &error)) {
87 g_warning ("Failed to execute query: %s", error);
88 sqlite3_free (error);
89 }
90
91 if (sqlite3_exec (http_cookies->db, "PRAGMA secure_delete = 1;",
92 NULL, NULL, &error)) {
93 g_warning ("Failed to execute query: %s", error);
94 sqlite3_free (error);
95 }
96
97 sqlite3_exec (http_cookies->db,
98 /* Arguably cookies are like a cache, so performance over integrity */
99 "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;"
100 "PRAGMA count_changes = OFF; PRAGMA journal_mode = TRUNCATE;",
101 NULL, NULL, &error);
102
103 return FALSE;
104}
105
106static void
107katze_http_cookies_sqlite_load (KatzeHttpCookiesSqlite* http_cookies)
108{
109 const char *name, *value, *host, *path;
110 sqlite3_stmt* stmt;
111 SoupCookie *cookie = NULL;
112 gint64 expire_time;
113 time_t now;
114 int max_age;
115 gboolean http_only = FALSE, secure = FALSE;
116 char *query;
117 int result;
118
119 if (http_cookies->db == NULL) {
120 if (katze_http_cookies_sqlite_open_db (http_cookies))
121 return;
122 }
123
124 sqlite3_prepare_v2 (http_cookies->db, QUERY_ALL, strlen (QUERY_ALL) + 1, &stmt, NULL);
125 result = sqlite3_step (stmt);
126 if (result != SQLITE_ROW)
127 {
128 if (result == SQLITE_ERROR)
129 g_print (_("Failed to load cookies\n"));
130 sqlite3_reset (stmt);
131 return;
132 }
133
134 while (result == SQLITE_ROW)
135 {
136 now = time (NULL);
137 name = (const char*)sqlite3_column_text (stmt, COL_NAME);
138 value = (const char*)sqlite3_column_text (stmt, COL_VALUE);
139 host = (const char*)sqlite3_column_text (stmt, COL_HOST);
140 path = (const char*)sqlite3_column_text (stmt, COL_PATH);
141 expire_time = sqlite3_column_int64 (stmt,COL_EXPIRY);
142 secure = sqlite3_column_int (stmt, COL_SECURE);
143 http_only = sqlite3_column_int (stmt, COL_HTTP_ONLY);
144
145 if (now >= expire_time)
146 {
147 /* Cookie expired, remove it from database */
148 query = sqlite3_mprintf (QUERY_DELETE, name, host);
149 sqlite3_exec (http_cookies->db, QUERY_DELETE, NULL, NULL, NULL);
150 sqlite3_free (query);
151 result = sqlite3_step (stmt);
152 continue;
153 }
154 max_age = (expire_time - now <= G_MAXINT ? expire_time - now : G_MAXINT);
155 cookie = soup_cookie_new (name, value, host, path, max_age);
156
157 if (secure)
158 soup_cookie_set_secure (cookie, TRUE);
159 if (http_only)
160 soup_cookie_set_http_only (cookie, TRUE);
161
162 soup_cookie_jar_add_cookie (http_cookies->jar, cookie);
163 result = sqlite3_step (stmt);
164 }
165
166 if (stmt)
167 {
168 sqlite3_reset (stmt);
169 sqlite3_clear_bindings (stmt);
170 }
171}
172static void
173katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar* jar,
174 SoupCookie* old_cookie,
175 SoupCookie* new_cookie,
176 KatzeHttpCookiesSqlite* http_cookies)
177{
178 GObject* settings;
179 char *query;
180 time_t expires = 0; /* Avoid warning */
181
182 if (http_cookies->db == NULL) {
183 if (katze_http_cookies_sqlite_open_db (http_cookies))
184 return;
185 }
186
187 if (new_cookie && new_cookie->expires)
188 {
189 gint age;
190
191 expires = soup_date_to_time_t (new_cookie->expires);
192 settings = g_object_get_data (G_OBJECT (jar), "midori-settings");
193 age = katze_object_get_int (settings, "maximum-cookie-age");
194 if (age > 0)
195 {
196 SoupDate* max_date = soup_date_new_from_now (
197 age * SOUP_COOKIE_MAX_AGE_ONE_DAY);
198 if (soup_date_to_time_t (new_cookie->expires)
199 > soup_date_to_time_t (max_date))
200 soup_cookie_set_expires (new_cookie, max_date);
201 }
202 else
203 {
204 /* An age of 0 to SoupCookie means already-expired
205 A user choosing 0 days probably expects 1 hour. */
206 soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR);
207 }
208 }
209
210 if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
211 http_cookies->counter++;
212
213 if (old_cookie) {
214 query = sqlite3_mprintf (QUERY_DELETE,
215 old_cookie->name,
216 old_cookie->domain);
217 sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL);
218 sqlite3_free (query);
219 }
220
221 if (new_cookie && new_cookie->expires) {
222
223 query = sqlite3_mprintf (QUERY_INSERT,
224 new_cookie->name,
225 new_cookie->value,
226 new_cookie->domain,
227 new_cookie->path,
228 expires,
229 new_cookie->secure,
230 new_cookie->http_only);
231 sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL);
232 sqlite3_free (query);
233 }
234}
235
236static void
237katze_http_cookies_sqlite_attach (SoupSessionFeature* feature,
238 SoupSession* session)
239{
240 KatzeHttpCookiesSqlite* http_cookies = (KatzeHttpCookiesSqlite*)feature;
241 const gchar* filename = g_object_get_data (G_OBJECT (feature), "filename");
242 SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
243 g_return_if_fail (jar != NULL);
244 g_return_if_fail (filename != NULL);
245 katze_assign (http_cookies->filename, g_strdup (filename));
246 http_cookies->jar = g_object_ref (jar);
247 katze_http_cookies_sqlite_open_db (http_cookies);
248 katze_http_cookies_sqlite_load (http_cookies);
249 g_signal_connect (jar, "changed",
250 G_CALLBACK (katze_http_cookies_sqlite_jar_changed_cb), feature);
251
252}
253
254static void
255katze_http_cookies_sqlite_detach (SoupSessionFeature* feature,
256 SoupSession* session)
257{
258 KatzeHttpCookiesSqlite* http_cookies = (KatzeHttpCookiesSqlite*)feature;
259 katze_assign (http_cookies->filename, NULL);
260 katze_object_assign (http_cookies->jar, NULL);
261 sqlite3_close (http_cookies->db);
262}
263
264static void
265katze_http_cookies_sqlite_session_feature_iface_init (SoupSessionFeatureInterface *iface,
266 gpointer data)
267{
268 iface->attach = katze_http_cookies_sqlite_attach;
269 iface->detach = katze_http_cookies_sqlite_detach;
270}
271
272static void
273katze_http_cookies_sqlite_finalize (GObject* object)
274{
275 katze_http_cookies_sqlite_detach ((SoupSessionFeature*)object, NULL);
276}
277
278static void
279katze_http_cookies_sqlite_class_init (KatzeHttpCookiesSqliteClass* class)
280{
281 GObjectClass* gobject_class = (GObjectClass*)class;
282 gobject_class->finalize = katze_http_cookies_sqlite_finalize;
283}
284
285static void
286katze_http_cookies_sqlite_init (KatzeHttpCookiesSqlite* http_cookies)
287{
288 http_cookies->filename = NULL;
289 http_cookies->jar = NULL;
290 http_cookies->db = NULL;
291 http_cookies->counter = 0;
292}
2930
=== removed file 'katze/katze-http-cookies-sqlite.h'
--- katze/katze-http-cookies-sqlite.h 2011-10-10 21:22:27 +0000
+++ katze/katze-http-cookies-sqlite.h 1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
1/*
2 Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 See the file COPYING for the full license text.
10*/
11
12#ifndef __KATZE_HTTP_COOKIES_SQLITE_H__
13#define __KATZE_HTTP_COOKIES_SQLITE_H__
14
15#include "katze-utils.h"
16
17#include <glib-object.h>
18
19G_BEGIN_DECLS
20
21#define KATZE_TYPE_HTTP_COOKIES_SQLITE \
22 (katze_http_cookies_sqlite_get_type ())
23#define KATZE_HTTP_COOKIES_SQLITE(obj) \
24 (G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqlite))
25#define KATZE_HTTP_COOKIES_SQLITE_CLASS(klass) \
26 (G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqliteClass))
27#define KATZE_IS_HTTP_COOKIES_SQLITE(obj) \
28 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE))
29#define KATZE_IS_HTTP_COOKIES_SQLITE_CLASS(klass) \
30 (G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_HTTP_COOKIES_SQLITE))
31#define KATZE_HTTP_COOKIES_SQLITE_GET_CLASS(obj) \
32 (G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqliteClass))
33
34typedef struct _KatzeHttpCookiesSqlite KatzeHttpCookiesSqlite;
35typedef struct _KatzeHttpCookiesSqliteClass KatzeHttpCookiesSqliteClass;
36
37GType
38katze_http_cookies_sqlite_get_type (void) G_GNUC_CONST;
39
40G_END_DECLS
41
42#endif /* __KATZE_HTTP_COOKIES_SQLITE_H__ */
430
=== removed file 'katze/katze-http-cookies.c'
--- katze/katze-http-cookies.c 2013-04-16 23:16:24 +0000
+++ katze/katze-http-cookies.c 1970-01-01 00:00:00 +0000
@@ -1,331 +0,0 @@
1/*
2 Copyright (C) 2008-2010 Christian Dywan <christian@twotoasts.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 See the file COPYING for the full license text.
10*/
11
12#if HAVE_CONFIG_H
13 #include <config.h>
14#endif
15
16#include "katze-http-cookies.h"
17#include "midori/midori-core.h"
18
19#include <stdlib.h>
20#ifdef HAVE_UNISTD_H
21 #include <unistd.h>
22#endif
23#include <glib/gi18n.h>
24#include <libsoup/soup.h>
25#include <gtk/gtk.h>
26#include <glib/gstdio.h>
27
28struct _KatzeHttpCookies
29{
30 GObject parent_instance;
31 gchar* filename;
32 SoupCookieJar* jar;
33 guint timeout;
34 guint counter;
35};
36
37struct _KatzeHttpCookiesClass
38{
39 GObjectClass parent_class;
40};
41
42static void
43katze_http_cookies_session_feature_iface_init (SoupSessionFeatureInterface *iface,
44 gpointer data);
45
46G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookies, katze_http_cookies, G_TYPE_OBJECT,
47 G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE,
48 katze_http_cookies_session_feature_iface_init));
49
50/* Cookie jar saving to Mozilla format
51 Copyright (C) 2008 Xan Lopez <xan@gnome.org>
52 Copyright (C) 2008 Dan Winship <danw@gnome.org>
53 Mostly copied from libSoup 2.24, coding style adjusted */
54static SoupCookie*
55parse_cookie (gchar* line,
56 time_t now)
57{
58 gchar** result;
59 SoupCookie *cookie = NULL;
60 gboolean http_only;
61 time_t max_age;
62 gchar* host/*, *is_domain*/, *path, *secure, *expires, *name, *value;
63
64 if (g_str_has_prefix (line, "#HttpOnly_"))
65 {
66 http_only = TRUE;
67 line += strlen ("#HttpOnly_");
68 }
69 else if (*line == '#' || g_ascii_isspace (*line))
70 return cookie;
71 else
72 http_only = FALSE;
73
74 result = g_strsplit (line, "\t", -1);
75 if (g_strv_length (result) != 7)
76 goto out;
77
78 /* Check this first */
79 expires = result[4];
80 max_age = strtoul (expires, NULL, 10) - now;
81 if (max_age <= 0)
82 goto out;
83
84 host = result[0];
85 /* is_domain = result[1]; */
86 path = result[2];
87 secure = result[3];
88
89 name = result[5];
90 value = result[6];
91
92 cookie = soup_cookie_new (name, value, host, path, max_age);
93
94 if (strcmp (secure, "FALSE"))
95 soup_cookie_set_secure (cookie, TRUE);
96 if (http_only)
97 soup_cookie_set_http_only (cookie, TRUE);
98
99 out:
100 g_strfreev (result);
101
102 return cookie;
103}
104
105/* Cookie jar saving to Mozilla format
106 Copyright (C) 2008 Xan Lopez <xan@gnome.org>
107 Copyright (C) 2008 Dan Winship <danw@gnome.org>
108 Mostly copied from libSoup 2.24, coding style adjusted */
109static void
110parse_line (SoupCookieJar* jar,
111 gchar* line,
112 time_t now)
113{
114 SoupCookie* cookie;
115
116 if ((cookie = parse_cookie (line, now)))
117 soup_cookie_jar_add_cookie (jar, cookie);
118}
119
120/* Cookie jar saving to Mozilla format
121 Copyright (C) 2008 Xan Lopez <xan@gnome.org>
122 Copyright (C) 2008 Dan Winship <danw@gnome.org>
123 Mostly copied from libSoup 2.24, coding style adjusted */
124static void
125cookie_jar_load (SoupCookieJar* jar,
126 const gchar* filename)
127{
128 char* contents = NULL;
129 gchar* line;
130 gchar* p;
131 gsize length = 0;
132 time_t now;
133
134 if (!g_file_get_contents (filename, &contents, &length, NULL))
135 return;
136
137 now = time (NULL);
138 line = contents;
139 for (p = contents; *p; p++)
140 {
141 /* \r\n comes out as an extra empty line and gets ignored */
142 if (*p == '\r' || *p == '\n')
143 {
144 *p = '\0';
145 parse_line (jar, line, now);
146 line = p + 1;
147 }
148 }
149 parse_line (jar, line, now);
150
151 g_free (contents);
152}
153
154/* Cookie jar saving to Mozilla format
155 Copyright (C) 2008 Xan Lopez <xan@gnome.org>
156 Copyright (C) 2008 Dan Winship <danw@gnome.org>
157 Copied from libSoup 2.24, coding style preserved */
158static gboolean
159write_cookie (FILE *out, SoupCookie *cookie)
160{
161 if (fprintf (out, "%s%s\t%s\t%s\t%s\t%lu\t%s\t%s\n",
162 cookie->http_only ? "#HttpOnly_" : "",
163 cookie->domain,
164 *cookie->domain == '.' ? "TRUE" : "FALSE",
165 cookie->path,
166 cookie->secure ? "TRUE" : "FALSE",
167 (gulong)soup_date_to_time_t (cookie->expires),
168 cookie->name,
169 cookie->value) < 0)
170 return FALSE;
171 return TRUE;
172}
173
174static gboolean
175katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies)
176{
177 gint fn = 0;
178 FILE* f = NULL;
179 gchar* temporary_filename = NULL;
180 GSList* cookies;
181
182 if (http_cookies->timeout > 0)
183 {
184 g_source_remove (http_cookies->timeout);
185 http_cookies->timeout = 0;
186 }
187
188 temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL);
189 if ((fn = g_mkstemp (temporary_filename)) == -1)
190 goto failed;
191 if (!((f = fdopen (fn, "wb"))))
192 goto failed;
193
194 cookies = soup_cookie_jar_all_cookies (http_cookies->jar);
195 for (; cookies != NULL; cookies = g_slist_next (cookies))
196 {
197 SoupCookie* cookie = cookies->data;
198 if (cookie->expires && !soup_date_is_past (cookie->expires))
199 write_cookie (f, cookie);
200 soup_cookie_free (cookie);
201 }
202 g_slist_free (cookies);
203
204 if (fclose (f) != 0)
205 {
206 f = NULL;
207 goto failed;
208 }
209 f = NULL;
210
211 if (g_rename (temporary_filename, http_cookies->filename) == -1)
212 goto failed;
213 g_free (temporary_filename);
214
215 if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
216 {
217 g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter);
218 http_cookies->counter = 0;
219 }
220 return FALSE;
221
222failed:
223 if (f)
224 fclose (f);
225 g_unlink (temporary_filename);
226 g_free (temporary_filename);
227 if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
228 g_print ("KatzeHttpCookies: Failed to write '%s'\n",
229 http_cookies->filename);
230 return FALSE;
231}
232
233static void
234katze_http_cookies_jar_changed_cb (SoupCookieJar* jar,
235 SoupCookie* old_cookie,
236 SoupCookie* new_cookie,
237 KatzeHttpCookies* http_cookies)
238{
239 GObject* settings;
240
241 if (old_cookie)
242 soup_cookie_set_max_age (old_cookie, 0);
243
244 if (new_cookie)
245 {
246 settings = g_object_get_data (G_OBJECT (jar), "midori-settings");
247 if (new_cookie->expires)
248 {
249 gint age = katze_object_get_int (settings, "maximum-cookie-age");
250 if (age > 0)
251 {
252 SoupDate* max_date = soup_date_new_from_now (
253 age * SOUP_COOKIE_MAX_AGE_ONE_DAY);
254 if (soup_date_to_time_t (new_cookie->expires)
255 > soup_date_to_time_t (max_date))
256 soup_cookie_set_expires (new_cookie, max_date);
257 }
258 else
259 {
260 /* An age of 0 to SoupCookie means already-expired
261 A user choosing 0 days probably expects 1 hour. */
262 soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR);
263 }
264 }
265 }
266
267 if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
268 http_cookies->counter++;
269
270 if (!http_cookies->timeout && (old_cookie || (new_cookie && new_cookie->expires)))
271 http_cookies->timeout = midori_timeout_add_seconds (
272 5, (GSourceFunc)katze_http_cookies_update_jar, http_cookies, NULL);
273}
274
275static void
276katze_http_cookies_attach (SoupSessionFeature* feature,
277 SoupSession* session)
278{
279 KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature;
280 const gchar* filename = g_object_get_data (G_OBJECT (feature), "filename");
281 SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR);
282 g_return_if_fail (jar != NULL);
283 g_return_if_fail (filename != NULL);
284 katze_assign (http_cookies->filename, g_strdup (filename));
285 http_cookies->jar = g_object_ref (jar);
286 cookie_jar_load (http_cookies->jar, http_cookies->filename);
287 g_signal_connect (jar, "changed",
288 G_CALLBACK (katze_http_cookies_jar_changed_cb), feature);
289
290}
291
292static void
293katze_http_cookies_detach (SoupSessionFeature* feature,
294 SoupSession* session)
295{
296 KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature;
297 if (http_cookies->timeout > 0)
298 katze_http_cookies_update_jar (http_cookies);
299 katze_assign (http_cookies->filename, NULL);
300 katze_object_assign (http_cookies->jar, NULL);
301}
302
303static void
304katze_http_cookies_session_feature_iface_init (SoupSessionFeatureInterface *iface,
305 gpointer data)
306{
307 iface->attach = katze_http_cookies_attach;
308 iface->detach = katze_http_cookies_detach;
309}
310
311static void
312katze_http_cookies_finalize (GObject* object)
313{
314 katze_http_cookies_detach ((SoupSessionFeature*)object, NULL);
315}
316
317static void
318katze_http_cookies_class_init (KatzeHttpCookiesClass* class)
319{
320 GObjectClass* gobject_class = (GObjectClass*)class;
321 gobject_class->finalize = katze_http_cookies_finalize;
322}
323
324static void
325katze_http_cookies_init (KatzeHttpCookies* http_cookies)
326{
327 http_cookies->filename = NULL;
328 http_cookies->jar = NULL;
329 http_cookies->timeout = 0;
330 http_cookies->counter = 0;
331}
3320
=== removed file 'katze/katze-http-cookies.h'
--- katze/katze-http-cookies.h 2010-01-17 17:14:48 +0000
+++ katze/katze-http-cookies.h 1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
1/*
2 Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 See the file COPYING for the full license text.
10*/
11
12#ifndef __KATZE_HTTP_COOKIES_H__
13#define __KATZE_HTTP_COOKIES_H__
14
15#include "katze-utils.h"
16
17#include <glib-object.h>
18
19G_BEGIN_DECLS
20
21#define KATZE_TYPE_HTTP_COOKIES \
22 (katze_http_cookies_get_type ())
23#define KATZE_HTTP_COOKIES(obj) \
24 (G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookies))
25#define KATZE_HTTP_COOKIES_CLASS(klass) \
26 (G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookiesClass))
27#define KATZE_IS_HTTP_COOKIES(obj) \
28 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_HTTP_COOKIES))
29#define KATZE_IS_HTTP_COOKIES_CLASS(klass) \
30 (G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_HTTP_COOKIES))
31#define KATZE_HTTP_COOKIES_GET_CLASS(obj) \
32 (G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookiesClass))
33
34typedef struct _KatzeHttpCookies KatzeHttpCookies;
35typedef struct _KatzeHttpCookiesClass KatzeHttpCookiesClass;
36
37GType
38katze_http_cookies_get_type (void) G_GNUC_CONST;
39
40G_END_DECLS
41
42#endif /* __KATZE_HTTP_COOKIES_H__ */
430
=== modified file 'katze/katze.h'
--- katze/katze.h 2013-03-23 01:38:17 +0000
+++ katze/katze.h 2013-07-15 22:44:25 +0000
@@ -13,8 +13,6 @@
13#define __KATZE_H__13#define __KATZE_H__
1414
15#include "katze-http-auth.h"15#include "katze-http-auth.h"
16#include "katze-http-cookies.h"
17#include "katze-http-cookies-sqlite.h"
18#include "katze-throbber.h"16#include "katze-throbber.h"
19#include "katze-utils.h"17#include "katze-utils.h"
20#include "katze-item.h"18#include "katze-item.h"
2119
=== modified file 'midori/midori-frontend.c'
--- midori/midori-frontend.c 2013-06-30 14:58:59 +0000
+++ midori/midori-frontend.c 2013-07-15 22:44:25 +0000
@@ -600,11 +600,6 @@
600 midori_bookmarks_on_quit (bookmarks);600 midori_bookmarks_on_quit (bookmarks);
601 midori_history_on_quit (history, settings);601 midori_history_on_quit (history, settings);
602 midori_private_data_on_quit (settings);602 midori_private_data_on_quit (settings);
603 /* Removing KatzeHttpCookies makes it save outstanding changes */
604#ifndef HAVE_WEBKIT2
605 soup_session_remove_feature_by_type (webkit_get_default_session (),
606 KATZE_TYPE_HTTP_COOKIES);
607#endif
608603
609 MidoriStartup load_on_startup = katze_object_get_int (settings, "load-on-startup");604 MidoriStartup load_on_startup = katze_object_get_int (settings, "load-on-startup");
610 if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES)605 if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES)
611606
=== modified file 'midori/midori-privatedata.c'
--- midori/midori-privatedata.c 2013-06-19 20:23:55 +0000
+++ midori/midori-privatedata.c 2013-07-15 22:44:25 +0000
@@ -239,14 +239,6 @@
239 soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookies->data);239 soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookies->data);
240 }240 }
241 soup_cookies_free (cookies);241 soup_cookies_free (cookies);
242 /* Removing KatzeHttpCookies makes it save outstanding changes */
243 if ((feature = soup_session_get_feature (session, KATZE_TYPE_HTTP_COOKIES)))
244 {
245 g_object_ref (feature);
246 soup_session_remove_feature (session, feature);
247 soup_session_add_feature (session, feature);
248 g_object_unref (feature);
249 }
250242
251 /* Local shared objects/ Flash cookies */243 /* Local shared objects/ Flash cookies */
252 if (midori_web_settings_has_plugin_support ())244 if (midori_web_settings_has_plugin_support ())
253245
=== modified file 'midori/midori-session.c'
--- midori/midori-session.c 2013-07-11 08:40:04 +0000
+++ midori/midori-session.c 2013-07-15 22:44:25 +0000
@@ -17,6 +17,7 @@
17#include "sokoke.h"17#include "sokoke.h"
1818
19#include <glib/gi18n-lib.h>19#include <glib/gi18n-lib.h>
20#include <libsoup/soup-cookie-jar-sqlite.h>
2021
21 #define LIBSOUP_USE_UNSTABLE_REQUEST_API22 #define LIBSOUP_USE_UNSTABLE_REQUEST_API
22 #include <libsoup/soup-cache.h>23 #include <libsoup/soup-cache.h>
@@ -247,6 +248,36 @@
247 return FALSE;248 return FALSE;
248}249}
249250
251static void
252midori_session_cookie_jar_changed_cb (SoupCookieJar* jar,
253 SoupCookie* old_cookie,
254 SoupCookie* new_cookie,
255 MidoriWebSettings* settings)
256{
257 if (new_cookie && new_cookie->expires)
258 {
259 time_t expires = soup_date_to_time_t (new_cookie->expires);
260 gint age = katze_object_get_int (settings, "maximum-cookie-age");
261 if (age > 0)
262 {
263 SoupDate* max_date = soup_date_new_from_now (
264 age * SOUP_COOKIE_MAX_AGE_ONE_DAY);
265 if (soup_date_to_time_t (new_cookie->expires)
266 > soup_date_to_time_t (max_date))
267 soup_cookie_set_expires (new_cookie, max_date);
268 }
269 else
270 {
271 /* An age of 0 to SoupCookie means already-expired
272 A user choosing 0 days probably expects 1 hour. */
273 soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR);
274 }
275 }
276
277 if (midori_debug ("cookies"))
278 g_print ("cookie changed: old %p new %p\n", old_cookie, new_cookie);
279}
280
250gboolean281gboolean
251midori_load_soup_session_full (gpointer settings)282midori_load_soup_session_full (gpointer settings)
252{283{
@@ -265,33 +296,13 @@
265 soup_session_add_feature (session, feature);296 soup_session_add_feature (session, feature);
266 g_object_unref (feature);297 g_object_unref (feature);
267298
268 jar = soup_cookie_jar_new ();299 katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.db"));
269 g_object_set_data (G_OBJECT (jar), "midori-settings", settings);300 jar = soup_cookie_jar_sqlite_new (config_file, FALSE);
270 soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar));301 soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar));
302 g_signal_connect (jar, "changed",
303 G_CALLBACK (midori_session_cookie_jar_changed_cb), settings);
271 g_object_unref (jar);304 g_object_unref (jar);
272305
273 katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.db"));
274 have_new_cookies = g_access (config_file, F_OK) == 0;
275 feature = g_object_new (KATZE_TYPE_HTTP_COOKIES_SQLITE, NULL);
276 g_object_set_data_full (G_OBJECT (feature), "filename",
277 config_file, (GDestroyNotify)g_free);
278 soup_session_add_feature (session, feature);
279 g_object_unref (feature);
280
281 if (!have_new_cookies)
282 {
283 katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.txt"));
284 if (g_access (config_file, F_OK) == 0)
285 {
286 g_message ("Importing cookies from txt to sqlite3");
287 feature_import = g_object_new (KATZE_TYPE_HTTP_COOKIES, NULL);
288 g_object_set_data_full (G_OBJECT (feature_import), "filename",
289 config_file, (GDestroyNotify)g_free);
290 soup_session_add_feature (session, SOUP_SESSION_FEATURE (feature_import));
291 soup_session_remove_feature (session, SOUP_SESSION_FEATURE (feature_import));
292 }
293 }
294
295 katze_assign (config_file, g_build_filename (midori_paths_get_cache_dir (), "web", NULL));306 katze_assign (config_file, g_build_filename (midori_paths_get_cache_dir (), "web", NULL));
296 feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0));307 feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0));
297 soup_session_add_feature (session, feature);308 soup_session_add_feature (session, feature);
298309
=== modified file 'wscript'
--- wscript 2013-07-15 17:07:45 +0000
+++ wscript 2013-07-15 22:44:25 +0000
@@ -278,7 +278,7 @@
278 conf.check_message_custom ('unique', '', 'disabled')278 conf.check_message_custom ('unique', '', 'disabled')
279 conf.define ('HAVE_UNIQUE', [0,1][conf.env['UNIQUE_VERSION'] != 'No'])279 conf.define ('HAVE_UNIQUE', [0,1][conf.env['UNIQUE_VERSION'] != 'No'])
280280
281 check_pkg ('libsoup-2.4', '2.27.90', var='LIBSOUP')281 check_pkg ('libsoup-gnome-2.4', '2.27.90', var='LIBSOUP')
282 if check_version (conf.env['LIBSOUP_VERSION'], 2, 29, 91):282 if check_version (conf.env['LIBSOUP_VERSION'], 2, 29, 91):
283 conf.define ('HAVE_LIBSOUP_2_29_91', 1)283 conf.define ('HAVE_LIBSOUP_2_29_91', 1)
284 if check_version (conf.env['LIBSOUP_VERSION'], 2, 34, 0):284 if check_version (conf.env['LIBSOUP_VERSION'], 2, 34, 0):

Subscribers

People subscribed via source and target branches

to all changes: