Initial import of ephy (rev# 7126) from svn
[ephy-soc.git] / embed / .svn / text-base / ephy-cookie-manager.c.svn-base
blob08c3afad1b602b2e44c0f7ebe41f717b91d9a3e9
1 /*
2  *  Copyright © 2000-2003 Marco Pesenti Gritti
3  *  Copyright © 2003 Christian Persch
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  *  $Id$
20  */
22 #include "config.h"
24 #include "ephy-cookie-manager.h"
26 GType
27 ephy_cookie_get_type (void)
29         static GType type = 0;
31         if (G_UNLIKELY (type == 0))
32         {
33                 type = g_boxed_type_register_static ("EphyCookie",
34                                                      (GBoxedCopyFunc) ephy_cookie_copy,
35                                                      (GBoxedFreeFunc) ephy_cookie_free);
36         }
38         return type;
41 /**
42  * ephy_cookie_new:
43  *
44  * Return value: a new #EphyCookie.
45  **/
46 EphyCookie *
47 ephy_cookie_new (void)
49         return g_new0 (EphyCookie, 1);
52 /**
53  * ephy_cookie_copy:
54  * @cookie: a #EphyCookie
55  *
56  * Return value: a copy of @cookie.
57  **/
58 EphyCookie *
59 ephy_cookie_copy (const EphyCookie *cookie)
61         EphyCookie *copy = g_new0 (EphyCookie, 1);
63         copy->name = g_strdup (cookie->name);
64         copy->value = g_strdup (cookie->value);
65         copy->domain = g_strdup (cookie->domain);
66         copy->path = g_strdup (cookie->path);
67         copy->expires = cookie->expires;
68         copy->real_expires = cookie->real_expires;
69         copy->is_secure = cookie->is_secure;
70         copy->is_session = cookie->is_session;
72         return copy;
75 /**
76  * ephy_cookie_free:
77  * @cookie: a #EphyCookie
78  * 
79  * Frees @cookie.
80  **/
81 void
82 ephy_cookie_free (EphyCookie *cookie)
84         if (cookie != NULL)
85         {
86                 g_free (cookie->name);
87                 g_free (cookie->value);
88                 g_free (cookie->domain);
89                 g_free (cookie->path);
91                 g_free (cookie);
92         }
95 /* EphyCookieManager */
97 static void ephy_cookie_manager_base_init (gpointer base_iface);
99 GType
100 ephy_cookie_manager_get_type (void)
102        static GType type = 0;
104         if (G_UNLIKELY (type == 0))
105         {
106                 const GTypeInfo our_info =
107                 {
108                         sizeof (EphyCookieManagerIface),
109                         ephy_cookie_manager_base_init,
110                         NULL,
111                 };
112                 
113                 type = g_type_register_static (G_TYPE_INTERFACE,
114                                                "EphyCookieManager",
115                                                &our_info,
116                                                (GTypeFlags) 0);
117         }
119         return type;
122 static void
123 ephy_cookie_manager_base_init (gpointer base_iface)
125         static gboolean initialised = FALSE;
127         if (initialised == FALSE)
128         {
129         /**
130          * EphyCookieManager::cookie-added
131          * @manager: the #EphyCookieManager
132          * @cookie: the added #EphyCookie
133          *
134          * The cookie-added signal is emitted when a cookie has been added.
135          **/
136         g_signal_new ("cookie-added",
137                       EPHY_TYPE_COOKIE_MANAGER,
138                       G_SIGNAL_RUN_FIRST,
139                       G_STRUCT_OFFSET (EphyCookieManagerIface, added),
140                       NULL, NULL,
141                       g_cclosure_marshal_VOID__BOXED,
142                       G_TYPE_NONE,
143                       1,
144                       EPHY_TYPE_COOKIE | G_SIGNAL_TYPE_STATIC_SCOPE);
146         /**
147          * EphyCookieManager::cookie-changed
148          * @manager: the #EphyCookieManager
149          * @cookie: the changed #EphyCookie
150          *
151          * The cookie-changed signal is emitted when a cookie has been changed.
152          **/
153         g_signal_new ("cookie-changed",
154                       EPHY_TYPE_COOKIE_MANAGER,
155                       G_SIGNAL_RUN_FIRST,
156                       G_STRUCT_OFFSET (EphyCookieManagerIface, changed),
157                       NULL, NULL,
158                       g_cclosure_marshal_VOID__BOXED,
159                       G_TYPE_NONE,
160                       1,
161                       EPHY_TYPE_COOKIE | G_SIGNAL_TYPE_STATIC_SCOPE);
163         /**
164          * EphyCookieManager::cookie-deleted
165          * @manager: the #EphyCookieManager
166          * @cookie: the deleted #EphyCookie
167          *
168          * The cookie-deleted signal is emitted when a cookie has been deleted.
169          **/
170         g_signal_new ("cookie-deleted",
171                       EPHY_TYPE_COOKIE_MANAGER,
172                       G_SIGNAL_RUN_FIRST,
173                       G_STRUCT_OFFSET (EphyCookieManagerIface, deleted),
174                       NULL, NULL,
175                       g_cclosure_marshal_VOID__BOXED,
176                       G_TYPE_NONE,
177                       1,
178                       EPHY_TYPE_COOKIE | G_SIGNAL_TYPE_STATIC_SCOPE);
180         /**
181          * EphyCookieManager::cookie-rejected
182          * @manager: the #EphyCookieManager
183          * @address: the address of the page that wanted to set the cookie
184          *
185          * The cookie-rejected signal is emitted when a cookie has been rejected.
186          **/
187         g_signal_new ("cookie-rejected",
188                       EPHY_TYPE_COOKIE_MANAGER,
189                       G_SIGNAL_RUN_FIRST,
190                       G_STRUCT_OFFSET (EphyCookieManagerIface, rejected),
191                       NULL, NULL,
192                       g_cclosure_marshal_VOID__STRING,
193                       G_TYPE_NONE,
194                       1,
195                       G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
197         /**
198          * EphyCookieManager::cookies-cleared
199          * @manager: the #EphyCookieManager
200          *
201          * The cookies-cleared signal is emitted when the cookie database has
202          * been cleared.
203          **/
204         g_signal_new ("cookies-cleared",
205                       EPHY_TYPE_COOKIE_MANAGER,
206                       G_SIGNAL_RUN_FIRST,
207                       G_STRUCT_OFFSET (EphyCookieManagerIface, cleared),
208                       NULL, NULL,
209                       g_cclosure_marshal_VOID__VOID,
210                       G_TYPE_NONE,
211                       0);
213         initialised = TRUE;
214         }
218  * ephy_cookie_manager_list_cookies:
219  * @manager: the #EphyCookieManager
220  * 
221  * Lists all cookies in the cookies database.
222  * 
223  * Return value: the cookies list
224  **/
225 GList *
226 ephy_cookie_manager_list_cookies (EphyCookieManager *manager)
228         EphyCookieManagerIface *iface = EPHY_COOKIE_MANAGER_GET_IFACE (manager);
229         return iface->list (manager);
233  * ephy_cookie_manager_remove_cookie:
234  * @manager: the #EphyCookieManager
235  * @cookie: a #EphyCookie
236  * 
237  * Removes @cookie from the cookies database. You must free @cookie yourself.
238  **/
239 void
240 ephy_cookie_manager_remove_cookie (EphyCookieManager *manager,
241                                    const EphyCookie *cookie)
243         EphyCookieManagerIface *iface = EPHY_COOKIE_MANAGER_GET_IFACE (manager);
244         iface->remove (manager, cookie);
248  * ephy_cookie_manager_clear:
249  * @manager: the #EphyCookieManager
250  * 
251  * Clears the cookies database.
252  **/
253 void
254 ephy_cookie_manager_clear (EphyCookieManager *manager)
256         EphyCookieManagerIface *iface = EPHY_COOKIE_MANAGER_GET_IFACE (manager);
257         iface->clear (manager);