Merge lp:~kalikiana/midori/soupcookiejar into lp:midori
- soupcookiejar
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
André Stösel | Approve | ||
Review via email:
|
Commit message
Use SoupCookieJarSqlite and drop KatzeHttpCookie
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
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
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
André Stösel (ivaldi) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'katze/katze-http-cookies-sqlite.c' |
2 | --- katze/katze-http-cookies-sqlite.c 2012-07-19 19:14:09 +0000 |
3 | +++ katze/katze-http-cookies-sqlite.c 1970-01-01 00:00:00 +0000 |
4 | @@ -1,292 +0,0 @@ |
5 | -/* |
6 | - Copyright (C) 2008-2010 Christian Dywan <christian@twotoasts.de> |
7 | - Copyright (C) 2011 Alexander Butenko <a.butenka@gmail.com> |
8 | - |
9 | - This library is free software; you can redistribute it and/or |
10 | - modify it under the terms of the GNU Lesser General Public |
11 | - License as published by the Free Software Foundation; either |
12 | - version 2.1 of the License, or (at your option) any later version. |
13 | - |
14 | - See the file COPYING for the full license text. |
15 | -*/ |
16 | - |
17 | -#if HAVE_CONFIG_H |
18 | - #include <config.h> |
19 | -#endif |
20 | - |
21 | -#include "katze-http-cookies-sqlite.h" |
22 | - |
23 | -#include <stdlib.h> |
24 | -#ifdef HAVE_UNISTD_H |
25 | - #include <unistd.h> |
26 | -#endif |
27 | -#include <glib/gi18n.h> |
28 | -#include <libsoup/soup.h> |
29 | -#include <gtk/gtk.h> |
30 | -#include <glib/gstdio.h> |
31 | -#include <sqlite3.h> |
32 | - |
33 | -#define QUERY_ALL "SELECT id, name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly FROM moz_cookies;" |
34 | -#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)" |
35 | -#define QUERY_INSERT "INSERT INTO moz_cookies VALUES(NULL, %Q, %Q, %Q, %Q, %d, NULL, %d, %d);" |
36 | -#define QUERY_DELETE "DELETE FROM moz_cookies WHERE name=%Q AND host=%Q;" |
37 | - |
38 | -enum { |
39 | - COL_ID, |
40 | - COL_NAME, |
41 | - COL_VALUE, |
42 | - COL_HOST, |
43 | - COL_PATH, |
44 | - COL_EXPIRY, |
45 | - COL_LAST_ACCESS, |
46 | - COL_SECURE, |
47 | - COL_HTTP_ONLY, |
48 | - N_COL, |
49 | -}; |
50 | - |
51 | -struct _KatzeHttpCookiesSqlite |
52 | -{ |
53 | - GObject parent_instance; |
54 | - gchar* filename; |
55 | - SoupCookieJar* jar; |
56 | - sqlite3 *db; |
57 | - guint counter; |
58 | -}; |
59 | - |
60 | -struct _KatzeHttpCookiesSqliteClass |
61 | -{ |
62 | - GObjectClass parent_class; |
63 | -}; |
64 | - |
65 | -static void |
66 | -katze_http_cookies_sqlite_session_feature_iface_init (SoupSessionFeatureInterface *iface, |
67 | - gpointer data); |
68 | - |
69 | -G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookiesSqlite, katze_http_cookies_sqlite, G_TYPE_OBJECT, |
70 | - G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, |
71 | - katze_http_cookies_sqlite_session_feature_iface_init)); |
72 | - |
73 | -/* Cookie jar saving into sqlite database |
74 | - Copyright (C) 2008 Diego Escalante Urrelo |
75 | - Copyright (C) 2009 Collabora Ltd. |
76 | - Mostly copied from libSoup 2.30, coding style retained */ |
77 | - |
78 | -/* Follows sqlite3 convention; returns TRUE on error */ |
79 | -static gboolean |
80 | -katze_http_cookies_sqlite_open_db (KatzeHttpCookiesSqlite* http_cookies) |
81 | -{ |
82 | - char *error = NULL; |
83 | - |
84 | - if (sqlite3_open (http_cookies->filename, &http_cookies->db)) { |
85 | - sqlite3_close (http_cookies->db); |
86 | - g_warning ("Can't open %s", http_cookies->filename); |
87 | - return TRUE; |
88 | - } |
89 | - |
90 | - if (sqlite3_exec (http_cookies->db, CREATE_TABLE, NULL, NULL, &error)) { |
91 | - g_warning ("Failed to execute query: %s", error); |
92 | - sqlite3_free (error); |
93 | - } |
94 | - |
95 | - if (sqlite3_exec (http_cookies->db, "PRAGMA secure_delete = 1;", |
96 | - NULL, NULL, &error)) { |
97 | - g_warning ("Failed to execute query: %s", error); |
98 | - sqlite3_free (error); |
99 | - } |
100 | - |
101 | - sqlite3_exec (http_cookies->db, |
102 | - /* Arguably cookies are like a cache, so performance over integrity */ |
103 | - "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" |
104 | - "PRAGMA count_changes = OFF; PRAGMA journal_mode = TRUNCATE;", |
105 | - NULL, NULL, &error); |
106 | - |
107 | - return FALSE; |
108 | -} |
109 | - |
110 | -static void |
111 | -katze_http_cookies_sqlite_load (KatzeHttpCookiesSqlite* http_cookies) |
112 | -{ |
113 | - const char *name, *value, *host, *path; |
114 | - sqlite3_stmt* stmt; |
115 | - SoupCookie *cookie = NULL; |
116 | - gint64 expire_time; |
117 | - time_t now; |
118 | - int max_age; |
119 | - gboolean http_only = FALSE, secure = FALSE; |
120 | - char *query; |
121 | - int result; |
122 | - |
123 | - if (http_cookies->db == NULL) { |
124 | - if (katze_http_cookies_sqlite_open_db (http_cookies)) |
125 | - return; |
126 | - } |
127 | - |
128 | - sqlite3_prepare_v2 (http_cookies->db, QUERY_ALL, strlen (QUERY_ALL) + 1, &stmt, NULL); |
129 | - result = sqlite3_step (stmt); |
130 | - if (result != SQLITE_ROW) |
131 | - { |
132 | - if (result == SQLITE_ERROR) |
133 | - g_print (_("Failed to load cookies\n")); |
134 | - sqlite3_reset (stmt); |
135 | - return; |
136 | - } |
137 | - |
138 | - while (result == SQLITE_ROW) |
139 | - { |
140 | - now = time (NULL); |
141 | - name = (const char*)sqlite3_column_text (stmt, COL_NAME); |
142 | - value = (const char*)sqlite3_column_text (stmt, COL_VALUE); |
143 | - host = (const char*)sqlite3_column_text (stmt, COL_HOST); |
144 | - path = (const char*)sqlite3_column_text (stmt, COL_PATH); |
145 | - expire_time = sqlite3_column_int64 (stmt,COL_EXPIRY); |
146 | - secure = sqlite3_column_int (stmt, COL_SECURE); |
147 | - http_only = sqlite3_column_int (stmt, COL_HTTP_ONLY); |
148 | - |
149 | - if (now >= expire_time) |
150 | - { |
151 | - /* Cookie expired, remove it from database */ |
152 | - query = sqlite3_mprintf (QUERY_DELETE, name, host); |
153 | - sqlite3_exec (http_cookies->db, QUERY_DELETE, NULL, NULL, NULL); |
154 | - sqlite3_free (query); |
155 | - result = sqlite3_step (stmt); |
156 | - continue; |
157 | - } |
158 | - max_age = (expire_time - now <= G_MAXINT ? expire_time - now : G_MAXINT); |
159 | - cookie = soup_cookie_new (name, value, host, path, max_age); |
160 | - |
161 | - if (secure) |
162 | - soup_cookie_set_secure (cookie, TRUE); |
163 | - if (http_only) |
164 | - soup_cookie_set_http_only (cookie, TRUE); |
165 | - |
166 | - soup_cookie_jar_add_cookie (http_cookies->jar, cookie); |
167 | - result = sqlite3_step (stmt); |
168 | - } |
169 | - |
170 | - if (stmt) |
171 | - { |
172 | - sqlite3_reset (stmt); |
173 | - sqlite3_clear_bindings (stmt); |
174 | - } |
175 | -} |
176 | -static void |
177 | -katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar* jar, |
178 | - SoupCookie* old_cookie, |
179 | - SoupCookie* new_cookie, |
180 | - KatzeHttpCookiesSqlite* http_cookies) |
181 | -{ |
182 | - GObject* settings; |
183 | - char *query; |
184 | - time_t expires = 0; /* Avoid warning */ |
185 | - |
186 | - if (http_cookies->db == NULL) { |
187 | - if (katze_http_cookies_sqlite_open_db (http_cookies)) |
188 | - return; |
189 | - } |
190 | - |
191 | - if (new_cookie && new_cookie->expires) |
192 | - { |
193 | - gint age; |
194 | - |
195 | - expires = soup_date_to_time_t (new_cookie->expires); |
196 | - settings = g_object_get_data (G_OBJECT (jar), "midori-settings"); |
197 | - age = katze_object_get_int (settings, "maximum-cookie-age"); |
198 | - if (age > 0) |
199 | - { |
200 | - SoupDate* max_date = soup_date_new_from_now ( |
201 | - age * SOUP_COOKIE_MAX_AGE_ONE_DAY); |
202 | - if (soup_date_to_time_t (new_cookie->expires) |
203 | - > soup_date_to_time_t (max_date)) |
204 | - soup_cookie_set_expires (new_cookie, max_date); |
205 | - } |
206 | - else |
207 | - { |
208 | - /* An age of 0 to SoupCookie means already-expired |
209 | - A user choosing 0 days probably expects 1 hour. */ |
210 | - soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR); |
211 | - } |
212 | - } |
213 | - |
214 | - if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) |
215 | - http_cookies->counter++; |
216 | - |
217 | - if (old_cookie) { |
218 | - query = sqlite3_mprintf (QUERY_DELETE, |
219 | - old_cookie->name, |
220 | - old_cookie->domain); |
221 | - sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL); |
222 | - sqlite3_free (query); |
223 | - } |
224 | - |
225 | - if (new_cookie && new_cookie->expires) { |
226 | - |
227 | - query = sqlite3_mprintf (QUERY_INSERT, |
228 | - new_cookie->name, |
229 | - new_cookie->value, |
230 | - new_cookie->domain, |
231 | - new_cookie->path, |
232 | - expires, |
233 | - new_cookie->secure, |
234 | - new_cookie->http_only); |
235 | - sqlite3_exec (http_cookies->db, query, NULL, NULL, NULL); |
236 | - sqlite3_free (query); |
237 | - } |
238 | -} |
239 | - |
240 | -static void |
241 | -katze_http_cookies_sqlite_attach (SoupSessionFeature* feature, |
242 | - SoupSession* session) |
243 | -{ |
244 | - KatzeHttpCookiesSqlite* http_cookies = (KatzeHttpCookiesSqlite*)feature; |
245 | - const gchar* filename = g_object_get_data (G_OBJECT (feature), "filename"); |
246 | - SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); |
247 | - g_return_if_fail (jar != NULL); |
248 | - g_return_if_fail (filename != NULL); |
249 | - katze_assign (http_cookies->filename, g_strdup (filename)); |
250 | - http_cookies->jar = g_object_ref (jar); |
251 | - katze_http_cookies_sqlite_open_db (http_cookies); |
252 | - katze_http_cookies_sqlite_load (http_cookies); |
253 | - g_signal_connect (jar, "changed", |
254 | - G_CALLBACK (katze_http_cookies_sqlite_jar_changed_cb), feature); |
255 | - |
256 | -} |
257 | - |
258 | -static void |
259 | -katze_http_cookies_sqlite_detach (SoupSessionFeature* feature, |
260 | - SoupSession* session) |
261 | -{ |
262 | - KatzeHttpCookiesSqlite* http_cookies = (KatzeHttpCookiesSqlite*)feature; |
263 | - katze_assign (http_cookies->filename, NULL); |
264 | - katze_object_assign (http_cookies->jar, NULL); |
265 | - sqlite3_close (http_cookies->db); |
266 | -} |
267 | - |
268 | -static void |
269 | -katze_http_cookies_sqlite_session_feature_iface_init (SoupSessionFeatureInterface *iface, |
270 | - gpointer data) |
271 | -{ |
272 | - iface->attach = katze_http_cookies_sqlite_attach; |
273 | - iface->detach = katze_http_cookies_sqlite_detach; |
274 | -} |
275 | - |
276 | -static void |
277 | -katze_http_cookies_sqlite_finalize (GObject* object) |
278 | -{ |
279 | - katze_http_cookies_sqlite_detach ((SoupSessionFeature*)object, NULL); |
280 | -} |
281 | - |
282 | -static void |
283 | -katze_http_cookies_sqlite_class_init (KatzeHttpCookiesSqliteClass* class) |
284 | -{ |
285 | - GObjectClass* gobject_class = (GObjectClass*)class; |
286 | - gobject_class->finalize = katze_http_cookies_sqlite_finalize; |
287 | -} |
288 | - |
289 | -static void |
290 | -katze_http_cookies_sqlite_init (KatzeHttpCookiesSqlite* http_cookies) |
291 | -{ |
292 | - http_cookies->filename = NULL; |
293 | - http_cookies->jar = NULL; |
294 | - http_cookies->db = NULL; |
295 | - http_cookies->counter = 0; |
296 | -} |
297 | |
298 | === removed file 'katze/katze-http-cookies-sqlite.h' |
299 | --- katze/katze-http-cookies-sqlite.h 2011-10-10 21:22:27 +0000 |
300 | +++ katze/katze-http-cookies-sqlite.h 1970-01-01 00:00:00 +0000 |
301 | @@ -1,42 +0,0 @@ |
302 | -/* |
303 | - Copyright (C) 2009 Christian Dywan <christian@twotoasts.de> |
304 | - |
305 | - This library is free software; you can redistribute it and/or |
306 | - modify it under the terms of the GNU Lesser General Public |
307 | - License as published by the Free Software Foundation; either |
308 | - version 2.1 of the License, or (at your option) any later version. |
309 | - |
310 | - See the file COPYING for the full license text. |
311 | -*/ |
312 | - |
313 | -#ifndef __KATZE_HTTP_COOKIES_SQLITE_H__ |
314 | -#define __KATZE_HTTP_COOKIES_SQLITE_H__ |
315 | - |
316 | -#include "katze-utils.h" |
317 | - |
318 | -#include <glib-object.h> |
319 | - |
320 | -G_BEGIN_DECLS |
321 | - |
322 | -#define KATZE_TYPE_HTTP_COOKIES_SQLITE \ |
323 | - (katze_http_cookies_sqlite_get_type ()) |
324 | -#define KATZE_HTTP_COOKIES_SQLITE(obj) \ |
325 | - (G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqlite)) |
326 | -#define KATZE_HTTP_COOKIES_SQLITE_CLASS(klass) \ |
327 | - (G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqliteClass)) |
328 | -#define KATZE_IS_HTTP_COOKIES_SQLITE(obj) \ |
329 | - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE)) |
330 | -#define KATZE_IS_HTTP_COOKIES_SQLITE_CLASS(klass) \ |
331 | - (G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_HTTP_COOKIES_SQLITE)) |
332 | -#define KATZE_HTTP_COOKIES_SQLITE_GET_CLASS(obj) \ |
333 | - (G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_HTTP_COOKIES_SQLITE, KatzeHttpCookiesSqliteClass)) |
334 | - |
335 | -typedef struct _KatzeHttpCookiesSqlite KatzeHttpCookiesSqlite; |
336 | -typedef struct _KatzeHttpCookiesSqliteClass KatzeHttpCookiesSqliteClass; |
337 | - |
338 | -GType |
339 | -katze_http_cookies_sqlite_get_type (void) G_GNUC_CONST; |
340 | - |
341 | -G_END_DECLS |
342 | - |
343 | -#endif /* __KATZE_HTTP_COOKIES_SQLITE_H__ */ |
344 | |
345 | === removed file 'katze/katze-http-cookies.c' |
346 | --- katze/katze-http-cookies.c 2013-04-16 23:16:24 +0000 |
347 | +++ katze/katze-http-cookies.c 1970-01-01 00:00:00 +0000 |
348 | @@ -1,331 +0,0 @@ |
349 | -/* |
350 | - Copyright (C) 2008-2010 Christian Dywan <christian@twotoasts.de> |
351 | - |
352 | - This library is free software; you can redistribute it and/or |
353 | - modify it under the terms of the GNU Lesser General Public |
354 | - License as published by the Free Software Foundation; either |
355 | - version 2.1 of the License, or (at your option) any later version. |
356 | - |
357 | - See the file COPYING for the full license text. |
358 | -*/ |
359 | - |
360 | -#if HAVE_CONFIG_H |
361 | - #include <config.h> |
362 | -#endif |
363 | - |
364 | -#include "katze-http-cookies.h" |
365 | -#include "midori/midori-core.h" |
366 | - |
367 | -#include <stdlib.h> |
368 | -#ifdef HAVE_UNISTD_H |
369 | - #include <unistd.h> |
370 | -#endif |
371 | -#include <glib/gi18n.h> |
372 | -#include <libsoup/soup.h> |
373 | -#include <gtk/gtk.h> |
374 | -#include <glib/gstdio.h> |
375 | - |
376 | -struct _KatzeHttpCookies |
377 | -{ |
378 | - GObject parent_instance; |
379 | - gchar* filename; |
380 | - SoupCookieJar* jar; |
381 | - guint timeout; |
382 | - guint counter; |
383 | -}; |
384 | - |
385 | -struct _KatzeHttpCookiesClass |
386 | -{ |
387 | - GObjectClass parent_class; |
388 | -}; |
389 | - |
390 | -static void |
391 | -katze_http_cookies_session_feature_iface_init (SoupSessionFeatureInterface *iface, |
392 | - gpointer data); |
393 | - |
394 | -G_DEFINE_TYPE_WITH_CODE (KatzeHttpCookies, katze_http_cookies, G_TYPE_OBJECT, |
395 | - G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, |
396 | - katze_http_cookies_session_feature_iface_init)); |
397 | - |
398 | -/* Cookie jar saving to Mozilla format |
399 | - Copyright (C) 2008 Xan Lopez <xan@gnome.org> |
400 | - Copyright (C) 2008 Dan Winship <danw@gnome.org> |
401 | - Mostly copied from libSoup 2.24, coding style adjusted */ |
402 | -static SoupCookie* |
403 | -parse_cookie (gchar* line, |
404 | - time_t now) |
405 | -{ |
406 | - gchar** result; |
407 | - SoupCookie *cookie = NULL; |
408 | - gboolean http_only; |
409 | - time_t max_age; |
410 | - gchar* host/*, *is_domain*/, *path, *secure, *expires, *name, *value; |
411 | - |
412 | - if (g_str_has_prefix (line, "#HttpOnly_")) |
413 | - { |
414 | - http_only = TRUE; |
415 | - line += strlen ("#HttpOnly_"); |
416 | - } |
417 | - else if (*line == '#' || g_ascii_isspace (*line)) |
418 | - return cookie; |
419 | - else |
420 | - http_only = FALSE; |
421 | - |
422 | - result = g_strsplit (line, "\t", -1); |
423 | - if (g_strv_length (result) != 7) |
424 | - goto out; |
425 | - |
426 | - /* Check this first */ |
427 | - expires = result[4]; |
428 | - max_age = strtoul (expires, NULL, 10) - now; |
429 | - if (max_age <= 0) |
430 | - goto out; |
431 | - |
432 | - host = result[0]; |
433 | - /* is_domain = result[1]; */ |
434 | - path = result[2]; |
435 | - secure = result[3]; |
436 | - |
437 | - name = result[5]; |
438 | - value = result[6]; |
439 | - |
440 | - cookie = soup_cookie_new (name, value, host, path, max_age); |
441 | - |
442 | - if (strcmp (secure, "FALSE")) |
443 | - soup_cookie_set_secure (cookie, TRUE); |
444 | - if (http_only) |
445 | - soup_cookie_set_http_only (cookie, TRUE); |
446 | - |
447 | - out: |
448 | - g_strfreev (result); |
449 | - |
450 | - return cookie; |
451 | -} |
452 | - |
453 | -/* Cookie jar saving to Mozilla format |
454 | - Copyright (C) 2008 Xan Lopez <xan@gnome.org> |
455 | - Copyright (C) 2008 Dan Winship <danw@gnome.org> |
456 | - Mostly copied from libSoup 2.24, coding style adjusted */ |
457 | -static void |
458 | -parse_line (SoupCookieJar* jar, |
459 | - gchar* line, |
460 | - time_t now) |
461 | -{ |
462 | - SoupCookie* cookie; |
463 | - |
464 | - if ((cookie = parse_cookie (line, now))) |
465 | - soup_cookie_jar_add_cookie (jar, cookie); |
466 | -} |
467 | - |
468 | -/* Cookie jar saving to Mozilla format |
469 | - Copyright (C) 2008 Xan Lopez <xan@gnome.org> |
470 | - Copyright (C) 2008 Dan Winship <danw@gnome.org> |
471 | - Mostly copied from libSoup 2.24, coding style adjusted */ |
472 | -static void |
473 | -cookie_jar_load (SoupCookieJar* jar, |
474 | - const gchar* filename) |
475 | -{ |
476 | - char* contents = NULL; |
477 | - gchar* line; |
478 | - gchar* p; |
479 | - gsize length = 0; |
480 | - time_t now; |
481 | - |
482 | - if (!g_file_get_contents (filename, &contents, &length, NULL)) |
483 | - return; |
484 | - |
485 | - now = time (NULL); |
486 | - line = contents; |
487 | - for (p = contents; *p; p++) |
488 | - { |
489 | - /* \r\n comes out as an extra empty line and gets ignored */ |
490 | - if (*p == '\r' || *p == '\n') |
491 | - { |
492 | - *p = '\0'; |
493 | - parse_line (jar, line, now); |
494 | - line = p + 1; |
495 | - } |
496 | - } |
497 | - parse_line (jar, line, now); |
498 | - |
499 | - g_free (contents); |
500 | -} |
501 | - |
502 | -/* Cookie jar saving to Mozilla format |
503 | - Copyright (C) 2008 Xan Lopez <xan@gnome.org> |
504 | - Copyright (C) 2008 Dan Winship <danw@gnome.org> |
505 | - Copied from libSoup 2.24, coding style preserved */ |
506 | -static gboolean |
507 | -write_cookie (FILE *out, SoupCookie *cookie) |
508 | -{ |
509 | - if (fprintf (out, "%s%s\t%s\t%s\t%s\t%lu\t%s\t%s\n", |
510 | - cookie->http_only ? "#HttpOnly_" : "", |
511 | - cookie->domain, |
512 | - *cookie->domain == '.' ? "TRUE" : "FALSE", |
513 | - cookie->path, |
514 | - cookie->secure ? "TRUE" : "FALSE", |
515 | - (gulong)soup_date_to_time_t (cookie->expires), |
516 | - cookie->name, |
517 | - cookie->value) < 0) |
518 | - return FALSE; |
519 | - return TRUE; |
520 | -} |
521 | - |
522 | -static gboolean |
523 | -katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies) |
524 | -{ |
525 | - gint fn = 0; |
526 | - FILE* f = NULL; |
527 | - gchar* temporary_filename = NULL; |
528 | - GSList* cookies; |
529 | - |
530 | - if (http_cookies->timeout > 0) |
531 | - { |
532 | - g_source_remove (http_cookies->timeout); |
533 | - http_cookies->timeout = 0; |
534 | - } |
535 | - |
536 | - temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL); |
537 | - if ((fn = g_mkstemp (temporary_filename)) == -1) |
538 | - goto failed; |
539 | - if (!((f = fdopen (fn, "wb")))) |
540 | - goto failed; |
541 | - |
542 | - cookies = soup_cookie_jar_all_cookies (http_cookies->jar); |
543 | - for (; cookies != NULL; cookies = g_slist_next (cookies)) |
544 | - { |
545 | - SoupCookie* cookie = cookies->data; |
546 | - if (cookie->expires && !soup_date_is_past (cookie->expires)) |
547 | - write_cookie (f, cookie); |
548 | - soup_cookie_free (cookie); |
549 | - } |
550 | - g_slist_free (cookies); |
551 | - |
552 | - if (fclose (f) != 0) |
553 | - { |
554 | - f = NULL; |
555 | - goto failed; |
556 | - } |
557 | - f = NULL; |
558 | - |
559 | - if (g_rename (temporary_filename, http_cookies->filename) == -1) |
560 | - goto failed; |
561 | - g_free (temporary_filename); |
562 | - |
563 | - if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) |
564 | - { |
565 | - g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter); |
566 | - http_cookies->counter = 0; |
567 | - } |
568 | - return FALSE; |
569 | - |
570 | -failed: |
571 | - if (f) |
572 | - fclose (f); |
573 | - g_unlink (temporary_filename); |
574 | - g_free (temporary_filename); |
575 | - if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) |
576 | - g_print ("KatzeHttpCookies: Failed to write '%s'\n", |
577 | - http_cookies->filename); |
578 | - return FALSE; |
579 | -} |
580 | - |
581 | -static void |
582 | -katze_http_cookies_jar_changed_cb (SoupCookieJar* jar, |
583 | - SoupCookie* old_cookie, |
584 | - SoupCookie* new_cookie, |
585 | - KatzeHttpCookies* http_cookies) |
586 | -{ |
587 | - GObject* settings; |
588 | - |
589 | - if (old_cookie) |
590 | - soup_cookie_set_max_age (old_cookie, 0); |
591 | - |
592 | - if (new_cookie) |
593 | - { |
594 | - settings = g_object_get_data (G_OBJECT (jar), "midori-settings"); |
595 | - if (new_cookie->expires) |
596 | - { |
597 | - gint age = katze_object_get_int (settings, "maximum-cookie-age"); |
598 | - if (age > 0) |
599 | - { |
600 | - SoupDate* max_date = soup_date_new_from_now ( |
601 | - age * SOUP_COOKIE_MAX_AGE_ONE_DAY); |
602 | - if (soup_date_to_time_t (new_cookie->expires) |
603 | - > soup_date_to_time_t (max_date)) |
604 | - soup_cookie_set_expires (new_cookie, max_date); |
605 | - } |
606 | - else |
607 | - { |
608 | - /* An age of 0 to SoupCookie means already-expired |
609 | - A user choosing 0 days probably expects 1 hour. */ |
610 | - soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR); |
611 | - } |
612 | - } |
613 | - } |
614 | - |
615 | - if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies")) |
616 | - http_cookies->counter++; |
617 | - |
618 | - if (!http_cookies->timeout && (old_cookie || (new_cookie && new_cookie->expires))) |
619 | - http_cookies->timeout = midori_timeout_add_seconds ( |
620 | - 5, (GSourceFunc)katze_http_cookies_update_jar, http_cookies, NULL); |
621 | -} |
622 | - |
623 | -static void |
624 | -katze_http_cookies_attach (SoupSessionFeature* feature, |
625 | - SoupSession* session) |
626 | -{ |
627 | - KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature; |
628 | - const gchar* filename = g_object_get_data (G_OBJECT (feature), "filename"); |
629 | - SoupSessionFeature* jar = soup_session_get_feature (session, SOUP_TYPE_COOKIE_JAR); |
630 | - g_return_if_fail (jar != NULL); |
631 | - g_return_if_fail (filename != NULL); |
632 | - katze_assign (http_cookies->filename, g_strdup (filename)); |
633 | - http_cookies->jar = g_object_ref (jar); |
634 | - cookie_jar_load (http_cookies->jar, http_cookies->filename); |
635 | - g_signal_connect (jar, "changed", |
636 | - G_CALLBACK (katze_http_cookies_jar_changed_cb), feature); |
637 | - |
638 | -} |
639 | - |
640 | -static void |
641 | -katze_http_cookies_detach (SoupSessionFeature* feature, |
642 | - SoupSession* session) |
643 | -{ |
644 | - KatzeHttpCookies* http_cookies = (KatzeHttpCookies*)feature; |
645 | - if (http_cookies->timeout > 0) |
646 | - katze_http_cookies_update_jar (http_cookies); |
647 | - katze_assign (http_cookies->filename, NULL); |
648 | - katze_object_assign (http_cookies->jar, NULL); |
649 | -} |
650 | - |
651 | -static void |
652 | -katze_http_cookies_session_feature_iface_init (SoupSessionFeatureInterface *iface, |
653 | - gpointer data) |
654 | -{ |
655 | - iface->attach = katze_http_cookies_attach; |
656 | - iface->detach = katze_http_cookies_detach; |
657 | -} |
658 | - |
659 | -static void |
660 | -katze_http_cookies_finalize (GObject* object) |
661 | -{ |
662 | - katze_http_cookies_detach ((SoupSessionFeature*)object, NULL); |
663 | -} |
664 | - |
665 | -static void |
666 | -katze_http_cookies_class_init (KatzeHttpCookiesClass* class) |
667 | -{ |
668 | - GObjectClass* gobject_class = (GObjectClass*)class; |
669 | - gobject_class->finalize = katze_http_cookies_finalize; |
670 | -} |
671 | - |
672 | -static void |
673 | -katze_http_cookies_init (KatzeHttpCookies* http_cookies) |
674 | -{ |
675 | - http_cookies->filename = NULL; |
676 | - http_cookies->jar = NULL; |
677 | - http_cookies->timeout = 0; |
678 | - http_cookies->counter = 0; |
679 | -} |
680 | |
681 | === removed file 'katze/katze-http-cookies.h' |
682 | --- katze/katze-http-cookies.h 2010-01-17 17:14:48 +0000 |
683 | +++ katze/katze-http-cookies.h 1970-01-01 00:00:00 +0000 |
684 | @@ -1,42 +0,0 @@ |
685 | -/* |
686 | - Copyright (C) 2009 Christian Dywan <christian@twotoasts.de> |
687 | - |
688 | - This library is free software; you can redistribute it and/or |
689 | - modify it under the terms of the GNU Lesser General Public |
690 | - License as published by the Free Software Foundation; either |
691 | - version 2.1 of the License, or (at your option) any later version. |
692 | - |
693 | - See the file COPYING for the full license text. |
694 | -*/ |
695 | - |
696 | -#ifndef __KATZE_HTTP_COOKIES_H__ |
697 | -#define __KATZE_HTTP_COOKIES_H__ |
698 | - |
699 | -#include "katze-utils.h" |
700 | - |
701 | -#include <glib-object.h> |
702 | - |
703 | -G_BEGIN_DECLS |
704 | - |
705 | -#define KATZE_TYPE_HTTP_COOKIES \ |
706 | - (katze_http_cookies_get_type ()) |
707 | -#define KATZE_HTTP_COOKIES(obj) \ |
708 | - (G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookies)) |
709 | -#define KATZE_HTTP_COOKIES_CLASS(klass) \ |
710 | - (G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookiesClass)) |
711 | -#define KATZE_IS_HTTP_COOKIES(obj) \ |
712 | - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_HTTP_COOKIES)) |
713 | -#define KATZE_IS_HTTP_COOKIES_CLASS(klass) \ |
714 | - (G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_HTTP_COOKIES)) |
715 | -#define KATZE_HTTP_COOKIES_GET_CLASS(obj) \ |
716 | - (G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_HTTP_COOKIES, KatzeHttpCookiesClass)) |
717 | - |
718 | -typedef struct _KatzeHttpCookies KatzeHttpCookies; |
719 | -typedef struct _KatzeHttpCookiesClass KatzeHttpCookiesClass; |
720 | - |
721 | -GType |
722 | -katze_http_cookies_get_type (void) G_GNUC_CONST; |
723 | - |
724 | -G_END_DECLS |
725 | - |
726 | -#endif /* __KATZE_HTTP_COOKIES_H__ */ |
727 | |
728 | === modified file 'katze/katze.h' |
729 | --- katze/katze.h 2013-03-23 01:38:17 +0000 |
730 | +++ katze/katze.h 2013-07-15 22:44:25 +0000 |
731 | @@ -13,8 +13,6 @@ |
732 | #define __KATZE_H__ |
733 | |
734 | #include "katze-http-auth.h" |
735 | -#include "katze-http-cookies.h" |
736 | -#include "katze-http-cookies-sqlite.h" |
737 | #include "katze-throbber.h" |
738 | #include "katze-utils.h" |
739 | #include "katze-item.h" |
740 | |
741 | === modified file 'midori/midori-frontend.c' |
742 | --- midori/midori-frontend.c 2013-06-30 14:58:59 +0000 |
743 | +++ midori/midori-frontend.c 2013-07-15 22:44:25 +0000 |
744 | @@ -600,11 +600,6 @@ |
745 | midori_bookmarks_on_quit (bookmarks); |
746 | midori_history_on_quit (history, settings); |
747 | midori_private_data_on_quit (settings); |
748 | - /* Removing KatzeHttpCookies makes it save outstanding changes */ |
749 | -#ifndef HAVE_WEBKIT2 |
750 | - soup_session_remove_feature_by_type (webkit_get_default_session (), |
751 | - KATZE_TYPE_HTTP_COOKIES); |
752 | -#endif |
753 | |
754 | MidoriStartup load_on_startup = katze_object_get_int (settings, "load-on-startup"); |
755 | if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES) |
756 | |
757 | === modified file 'midori/midori-privatedata.c' |
758 | --- midori/midori-privatedata.c 2013-06-19 20:23:55 +0000 |
759 | +++ midori/midori-privatedata.c 2013-07-15 22:44:25 +0000 |
760 | @@ -239,14 +239,6 @@ |
761 | soup_cookie_jar_delete_cookie ((SoupCookieJar*)jar, cookies->data); |
762 | } |
763 | soup_cookies_free (cookies); |
764 | - /* Removing KatzeHttpCookies makes it save outstanding changes */ |
765 | - if ((feature = soup_session_get_feature (session, KATZE_TYPE_HTTP_COOKIES))) |
766 | - { |
767 | - g_object_ref (feature); |
768 | - soup_session_remove_feature (session, feature); |
769 | - soup_session_add_feature (session, feature); |
770 | - g_object_unref (feature); |
771 | - } |
772 | |
773 | /* Local shared objects/ Flash cookies */ |
774 | if (midori_web_settings_has_plugin_support ()) |
775 | |
776 | === modified file 'midori/midori-session.c' |
777 | --- midori/midori-session.c 2013-07-11 08:40:04 +0000 |
778 | +++ midori/midori-session.c 2013-07-15 22:44:25 +0000 |
779 | @@ -17,6 +17,7 @@ |
780 | #include "sokoke.h" |
781 | |
782 | #include <glib/gi18n-lib.h> |
783 | +#include <libsoup/soup-cookie-jar-sqlite.h> |
784 | |
785 | #define LIBSOUP_USE_UNSTABLE_REQUEST_API |
786 | #include <libsoup/soup-cache.h> |
787 | @@ -247,6 +248,36 @@ |
788 | return FALSE; |
789 | } |
790 | |
791 | +static void |
792 | +midori_session_cookie_jar_changed_cb (SoupCookieJar* jar, |
793 | + SoupCookie* old_cookie, |
794 | + SoupCookie* new_cookie, |
795 | + MidoriWebSettings* settings) |
796 | +{ |
797 | + if (new_cookie && new_cookie->expires) |
798 | + { |
799 | + time_t expires = soup_date_to_time_t (new_cookie->expires); |
800 | + gint age = katze_object_get_int (settings, "maximum-cookie-age"); |
801 | + if (age > 0) |
802 | + { |
803 | + SoupDate* max_date = soup_date_new_from_now ( |
804 | + age * SOUP_COOKIE_MAX_AGE_ONE_DAY); |
805 | + if (soup_date_to_time_t (new_cookie->expires) |
806 | + > soup_date_to_time_t (max_date)) |
807 | + soup_cookie_set_expires (new_cookie, max_date); |
808 | + } |
809 | + else |
810 | + { |
811 | + /* An age of 0 to SoupCookie means already-expired |
812 | + A user choosing 0 days probably expects 1 hour. */ |
813 | + soup_cookie_set_max_age (new_cookie, SOUP_COOKIE_MAX_AGE_ONE_HOUR); |
814 | + } |
815 | + } |
816 | + |
817 | + if (midori_debug ("cookies")) |
818 | + g_print ("cookie changed: old %p new %p\n", old_cookie, new_cookie); |
819 | +} |
820 | + |
821 | gboolean |
822 | midori_load_soup_session_full (gpointer settings) |
823 | { |
824 | @@ -265,33 +296,13 @@ |
825 | soup_session_add_feature (session, feature); |
826 | g_object_unref (feature); |
827 | |
828 | - jar = soup_cookie_jar_new (); |
829 | - g_object_set_data (G_OBJECT (jar), "midori-settings", settings); |
830 | + katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.db")); |
831 | + jar = soup_cookie_jar_sqlite_new (config_file, FALSE); |
832 | soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar)); |
833 | + g_signal_connect (jar, "changed", |
834 | + G_CALLBACK (midori_session_cookie_jar_changed_cb), settings); |
835 | g_object_unref (jar); |
836 | |
837 | - katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.db")); |
838 | - have_new_cookies = g_access (config_file, F_OK) == 0; |
839 | - feature = g_object_new (KATZE_TYPE_HTTP_COOKIES_SQLITE, NULL); |
840 | - g_object_set_data_full (G_OBJECT (feature), "filename", |
841 | - config_file, (GDestroyNotify)g_free); |
842 | - soup_session_add_feature (session, feature); |
843 | - g_object_unref (feature); |
844 | - |
845 | - if (!have_new_cookies) |
846 | - { |
847 | - katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.txt")); |
848 | - if (g_access (config_file, F_OK) == 0) |
849 | - { |
850 | - g_message ("Importing cookies from txt to sqlite3"); |
851 | - feature_import = g_object_new (KATZE_TYPE_HTTP_COOKIES, NULL); |
852 | - g_object_set_data_full (G_OBJECT (feature_import), "filename", |
853 | - config_file, (GDestroyNotify)g_free); |
854 | - soup_session_add_feature (session, SOUP_SESSION_FEATURE (feature_import)); |
855 | - soup_session_remove_feature (session, SOUP_SESSION_FEATURE (feature_import)); |
856 | - } |
857 | - } |
858 | - |
859 | katze_assign (config_file, g_build_filename (midori_paths_get_cache_dir (), "web", NULL)); |
860 | feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0)); |
861 | soup_session_add_feature (session, feature); |
862 | |
863 | === modified file 'wscript' |
864 | --- wscript 2013-07-15 17:07:45 +0000 |
865 | +++ wscript 2013-07-15 22:44:25 +0000 |
866 | @@ -278,7 +278,7 @@ |
867 | conf.check_message_custom ('unique', '', 'disabled') |
868 | conf.define ('HAVE_UNIQUE', [0,1][conf.env['UNIQUE_VERSION'] != 'No']) |
869 | |
870 | - check_pkg ('libsoup-2.4', '2.27.90', var='LIBSOUP') |
871 | + check_pkg ('libsoup-gnome-2.4', '2.27.90', var='LIBSOUP') |
872 | if check_version (conf.env['LIBSOUP_VERSION'], 2, 29, 91): |
873 | conf.define ('HAVE_LIBSOUP_2_29_91', 1) |
874 | if check_version (conf.env['LIBSOUP_VERSION'], 2, 34, 0): |
The cookie handling works fine (like before), but this patch doesn't fix the related bug.