desktop-data-model r7264 - in trunk: engine engine-dbus



Author: otaylor
Date: Thu Apr  3 01:33:31 2008
New Revision: 7264
URL: http://svn.gnome.org/viewvc/desktop-data-model?rev=7264&view=rev

Log:
hippo-cookies-linux.c: Add directory watches recursively
  so we actually detect cookies files changing within a
  firefox profile directory ... inotify is *not* recursive,
  and neither are the semantics are gnome_vfs_monitor_add()

hippo-connection.c: The first time that cookies might have
  changed, don't remove leave the SIGNIN state if we don't
  find our auth cookie.


Modified:
   trunk/engine-dbus/hippo-cookies-linux.c
   trunk/engine/hippo-connection.c

Modified: trunk/engine-dbus/hippo-cookies-linux.c
==============================================================================
--- trunk/engine-dbus/hippo-cookies-linux.c	(original)
+++ trunk/engine-dbus/hippo-cookies-linux.c	Thu Apr  3 01:33:31 2008
@@ -10,11 +10,22 @@
     void                   *data;    
 } CookieMonitor;
 
+typedef enum {
+    MONITOR_FILE,
+    MONITOR_DIRECTORY,
+    MONITOR_SUBDIRECTORY
+} MonitorType;
+
 typedef struct {
     char *path;
+    MonitorType monitor_type;
     GnomeVFSMonitorHandle *handle;
 } MonitoredCookieFile;
 
+static void add_monitored_cookie_file    (const char  *path,
+                                          MonitorType  monitor_type);
+static void remove_monitored_cookie_file (const char  *path);
+
 static int cookie_monitors_serial = 0;
 static GSList *cookie_monitors = NULL;
 static GHashTable *monitored_files = NULL;
@@ -44,17 +55,166 @@
 }
 
 static void
+add_subdirectory_monitors(const char *path)
+{
+    GDir *dir = g_dir_open(path, 0, NULL);
+    if (dir == NULL)
+        return;
+
+    while (TRUE) {
+        const char *name = g_dir_read_name(dir);
+        char *fullname;
+        if (name == NULL)
+            return;
+
+        fullname = g_build_filename(path, name, NULL);
+        if (g_file_test(fullname, G_FILE_TEST_IS_DIR))
+            add_monitored_cookie_file(fullname, MONITOR_SUBDIRECTORY);
+            
+    }
+
+    g_dir_close(dir);
+}
+
+static char *
+path_from_info_uri(const char *info_uri)
+{
+    char *local_path;
+    int len;
+    
+    if (info_uri == NULL)
+        return NULL;
+    
+    local_path = gnome_vfs_get_local_path_from_uri(info_uri);
+    if (local_path == NULL) /* Can't convert to a local path */
+        return NULL;
+    
+    len = strlen(local_path);
+    /* If the directory itself is created/deleted, then the path has a trailing
+     * '/' currently; rather than counting on that, we just strip it
+     */
+    if (local_path[len - 1] == '/')
+        local_path[len - 1] = '\0';
+
+    return local_path;
+}
+
+static void
 on_cookie_file_changed(GnomeVFSMonitorHandle *handle,
                        const gchar *monitor_uri,
                        const gchar *info_uri,
                        GnomeVFSMonitorEventType event_type,
                        gpointer user_data)
 {
-    cookie_monitors_notify();
+    MonitoredCookieFile *mcf = user_data;
+
+    switch (mcf->monitor_type) {
+    case MONITOR_DIRECTORY:
+        /* .mozilla/firefox:
+         *    if the directory itself is created, add monitors on all subdirectories,
+         *       and reread cookies
+         *    if a subdirectory is created, add a monitor on it and reread cookies
+         */
+        switch (event_type) {
+        case GNOME_VFS_MONITOR_EVENT_CREATED:
+            {
+                char *local_path = path_from_info_uri(info_uri);
+                if (local_path == NULL)
+                    return;
+                
+                if (strcmp(local_path, mcf->path) == 0) {
+                    add_subdirectory_monitors(local_path);
+                } else if (g_file_test(local_path, G_FILE_TEST_IS_DIR))
+                    add_monitored_cookie_file(local_path, MONITOR_SUBDIRECTORY);
+                
+                cookie_monitors_notify();
+
+                g_free(local_path);
+            }
+            break;
+        case GNOME_VFS_MONITOR_EVENT_DELETED:
+            {
+                /* Deleting or moving aside the directory itself causes problems for
+                 * a number of reasons
+                 *
+                 * - Notify watches on the children don't fire at least in the
+                 *   move-aside case (inotify bug or misfeature?)
+                 * - gnome-vfs gets into a weird state (not fully diagnosed, some
+                 *   combination of gnome-vfs and inotify problems)
+                 * - We don't clean out the child watches, so they won't get added
+                 *   back, but the old ones may won't work.
+                 *
+                 * So, if someone rm -rf's ~/.mozilla, the Online Desktop may not work
+                 * until they log out and log back again. Tough.
+                 */
+                char *local_path = path_from_info_uri(info_uri);
+                if (strcmp(local_path, mcf->path) == 0)
+                    g_warning("Directory of profiles %s removed, future notification may to work", local_path);
+            }
+        case GNOME_VFS_MONITOR_EVENT_CHANGED:
+        case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING:
+        case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING:
+        case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED: 
+            break;
+        }
+    case MONITOR_SUBDIRECTORY:
+        /* .mozilla/firefox/550taoaa.default:
+         *    if a file in the directory called cookies.txt or cookies.sqlite is created
+         *     changed, or delete, reread cookies
+         *    if the directory itself is removed, remove the monitor, and reread cookies
+         */
+        switch (event_type) {
+        case GNOME_VFS_MONITOR_EVENT_CREATED:
+        case GNOME_VFS_MONITOR_EVENT_CHANGED:
+            if (g_str_has_suffix(info_uri, "/cookies.txt") ||
+                g_str_has_suffix(info_uri, "/cookies.sqlite"))
+                cookie_monitors_notify();
+            break;
+        case GNOME_VFS_MONITOR_EVENT_DELETED:
+            {
+                char *local_path = path_from_info_uri(info_uri);
+                if (local_path == NULL)
+                    return;
+                
+                if (strcmp(local_path, mcf->path) == 0) {
+                    remove_monitored_cookie_file(local_path);
+                    cookie_monitors_notify();
+                } else {
+                    if (g_str_has_suffix(info_uri, "/cookies.txt") ||
+                        g_str_has_suffix(info_uri, "/cookies.sqlite"))
+                        cookie_monitors_notify();
+                }
+                
+                g_free(local_path);
+            }
+            break;
+        case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING:
+        case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING:
+        case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED: 
+            break;
+        }
+        break;
+    case MONITOR_FILE:
+        /* .galeon/mozilla/galeon/cookies.txt
+         *    if the file is created, changed, or deleted, reread cookies
+         */
+        switch (event_type) {
+        case GNOME_VFS_MONITOR_EVENT_CREATED:
+        case GNOME_VFS_MONITOR_EVENT_CHANGED:
+        case GNOME_VFS_MONITOR_EVENT_DELETED:
+            cookie_monitors_notify();
+            break;
+        case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING:
+        case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING:
+        case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED: 
+            break;
+        }
+    }
 }
 
 static void
-add_monitored_cookie_file(const char *path)
+add_monitored_cookie_file(const char  *path,
+                          MonitorType  monitor_type)
 {
     MonitoredCookieFile *mcf;
     GnomeVFSResult result;
@@ -76,12 +236,13 @@
     mcf = g_new0(MonitoredCookieFile, 1);
 
     mcf->path = g_strdup(path);
+    mcf->monitor_type = monitor_type;
 
     result = gnome_vfs_monitor_add(&mcf->handle,
                                    mcf->path,
-                                   GNOME_VFS_MONITOR_FILE,
+                                   monitor_type == MONITOR_FILE ? GNOME_VFS_MONITOR_FILE : GNOME_VFS_MONITOR_DIRECTORY,
                                    on_cookie_file_changed,
-                                   NULL);
+                                   mcf);
     if (result != GNOME_VFS_OK) {
         g_warning("Failed to monitor cookie file '%s'", mcf->path);
         g_free(mcf->path);
@@ -90,6 +251,28 @@
     }
     
     g_hash_table_replace(monitored_files, mcf->path, mcf);
+
+    if (monitor_type == MONITOR_DIRECTORY)
+        add_subdirectory_monitors(path);
+}
+
+static void
+remove_monitored_cookie_file(const char *path)
+{
+    MonitoredCookieFile *mcf;
+    
+    if (monitored_files == NULL)
+        return;
+    
+    mcf = g_hash_table_lookup(monitored_files, path);
+    if (mcf == NULL)
+        return;
+
+    g_hash_table_remove(monitored_files, path);
+        
+    gnome_vfs_monitor_cancel(mcf->handle);
+    g_free(mcf->path);
+    g_free(mcf);
 }
 
 GSList*
@@ -111,31 +294,31 @@
                             ".gnome2/epiphany/mozilla/epiphany/cookies.txt",
                             NULL);
     hippo_cookie_locator_add_file(locator, path, HIPPO_BROWSER_EPIPHANY);
-    add_monitored_cookie_file(path);
+    add_monitored_cookie_file(path, MONITOR_FILE);
     g_free(path);
 
     path = g_build_filename(homedir,
                             ".galeon/mozilla/galeon/cookies.txt",
                             NULL);
     hippo_cookie_locator_add_file(locator, path, HIPPO_BROWSER_GALEON);
-    add_monitored_cookie_file(path);
+    add_monitored_cookie_file(path, MONITOR_FILE);
     g_free(path);
 
     path = g_build_filename(homedir,
                             ".mozilla/microb/cookies.txt",
                             NULL);
     hippo_cookie_locator_add_file(locator, path, HIPPO_BROWSER_MAEMO);
-    add_monitored_cookie_file(path);
+    add_monitored_cookie_file(path, MONITOR_FILE);
     g_free(path);
     
     path = g_build_filename(homedir, ".mozilla/firefox", NULL);
     hippo_cookie_locator_add_directory(locator, path, HIPPO_BROWSER_FIREFOX);
-    add_monitored_cookie_file(path);
+    add_monitored_cookie_file(path, MONITOR_DIRECTORY);
     g_free(path);
     
     path = g_build_filename(homedir, ".firefox", NULL);
     hippo_cookie_locator_add_directory(locator, path, HIPPO_BROWSER_FIREFOX);
-    add_monitored_cookie_file(path);
+    add_monitored_cookie_file(path, MONITOR_DIRECTORY);
     g_free(path);
 
     cookies = hippo_cookie_locator_load_cookies(locator, domain, port, name);

Modified: trunk/engine/hippo-connection.c
==============================================================================
--- trunk/engine/hippo-connection.c	(original)
+++ trunk/engine/hippo-connection.c	Thu Apr  3 01:33:31 2008
@@ -921,7 +921,6 @@
 static void
 hippo_connection_run_signin_timeout(HippoConnection *connection)
 {
-    hippo_connection_stop_signin_timeout(connection);
     signin_timeout(connection);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]