]> Dogcows Code - chaz/openbox/blobdiff - openbox/session.c
Properly escape strings before writing XML.
[chaz/openbox] / openbox / session.c
index 96d7563faf3f5df622637ec7c884038a7e7849fe..811592ec90cd5fbbfb68531a36ebc5a88e4bf18b 100644 (file)
@@ -33,6 +33,7 @@ GSList *session_desktop_names = NULL;
 void session_startup(gint argc, gchar **argv) {}
 void session_shutdown(gboolean permanent) {}
 GList* session_state_find(struct _ObClient *c) { return NULL; }
+void session_request_logout(gboolean silent) {}
 #else
 
 #include "debug.h"
@@ -100,7 +101,7 @@ void session_startup(gint argc, gchar **argv)
     dir = g_build_filename(parse_xdg_data_home_path(),
                            "openbox", "sessions", NULL);
     if (!parse_mkdir_path(dir, 0700)) {
-        g_message(_("Unable to make directory '%s': %s"),
+        g_message(_("Unable to make directory \"%s\": %s"),
                   dir, g_strerror(errno));
     }
 
@@ -396,14 +397,28 @@ static void sm_save_yourself_2(SmcConn conn, SmPointer data)
     SmcSaveYourselfDone(conn, success);
 }
 
-
 static void sm_save_yourself(SmcConn conn, SmPointer data, gint save_type,
                              Bool shutdown, gint interact_style, Bool fast)
 {
     ObSMSaveData *savedata = NULL;
     gchar *vendor;
 
-    ob_debug_type(OB_DEBUG_SM, "Session save requested\n");
+#ifdef DEBUG
+    {
+        const gchar *sname =
+            (save_type == SmSaveLocal ? "SmSaveLocal" :
+             (save_type == SmSaveGlobal ? "SmSaveGlobal" :
+              (save_type == SmSaveBoth ? "SmSaveBoth" : "INVALID!!")));
+        ob_debug_type(OB_DEBUG_SM, "Session save requested, type %s\n", sname);
+    }
+#endif
+
+    if (save_type == SmSaveGlobal) {
+        /* we have no data to save.  we only store state to get back to where
+           we were, we don't keep open writable files or anything */
+        SmcSaveYourselfDone(conn, TRUE);
+        return;
+    }
 
     vendor = SmcVendor(sm_conn);
     ob_debug_type(OB_DEBUG_SM, "Session manager's vendor: %s\n", vendor);
@@ -448,7 +463,7 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata)
     f = fopen(ob_sm_save_file, "w");
     if (!f) {
         success = FALSE;
-        g_message(_("Unable to save the session to '%s': %s"),
+        g_message(_("Unable to save the session to \"%s\": %s"),
                   ob_sm_save_file, g_strerror(errno));
     } else {
         fprintf(f, "<?xml version=\"1.0\"?>\n\n");
@@ -471,10 +486,14 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata)
 
         if (screen_desktop_names) {
             gint i;
+            gchar *t;
 
             fprintf(f, "<desktopnames>\n");
-            for (i = 0; screen_desktop_names[i]; ++i)
-                fprintf(f, "  <name>%s</name>\n", screen_desktop_names[i]);
+            for (i = 0; screen_desktop_names[i]; ++i){
+                t = g_markup_escape_text(screen_desktop_names[i], -1);
+                fprintf(f, "  <name>%s</name>\n", t);
+                g_free(t);
+            }
             fprintf(f, "</desktopnames>\n");
         }
 
@@ -529,8 +548,11 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata)
 
             if (c->sm_client_id)
                 fprintf(f, "<window id=\"%s\">\n", c->sm_client_id);
-            else
-                fprintf(f, "<window command=\"%s\">\n", c->wm_command);
+            else {
+                t = g_markup_escape_text(c->wm_command, -1);
+                fprintf(f, "<window command=\"%s\">\n", t);
+                g_free(t);
+            }
 
             t = g_markup_escape_text(c->name, -1);
             fprintf(f, "\t<name>%s</name>\n", t);
@@ -580,7 +602,7 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata)
 
         if (fflush(f)) {
             success = FALSE;
-            g_message(_("Error while saving the session to '%s': %s"),
+            g_message(_("Error while saving the session to \"%s\": %s"),
                       ob_sm_save_file, g_strerror(errno));
         }
         fclose(f);
@@ -804,4 +826,20 @@ static void session_load_file(const gchar *path)
     xmlFreeDoc(doc);
 }
 
+void session_request_logout(gboolean silent)
+{
+    if (sm_conn) {
+        SmcRequestSaveYourself(sm_conn,
+                               SmSaveGlobal,
+                               TRUE, /* logout */
+                               (silent ?
+                                SmInteractStyleNone : SmInteractStyleAny),
+                               TRUE,  /* if false, with GSM, it shows the old
+                                         logout prompt */
+                               TRUE); /* global */
+    }
+    else
+        g_message(_("Not connected to a session manager"));
+}
+
 #endif
This page took 0.02778 seconds and 4 git commands to generate.