Silence a bunch of -Wunused-but-set-variable warnings
[platform/upstream/glib.git] / gio / gdbusauth.c
index 47905cd..f190469 100644 (file)
@@ -1,6 +1,6 @@
 /* GDBus - GLib D-Bus Library
  *
- * Copyright (C) 2008-2009 Red Hat, Inc.
+ * Copyright (C) 2008-2010 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include "config.h"
 
 #include "gdbusauth.h"
+
 #include "gdbusauthmechanismanon.h"
 #include "gdbusauthmechanismexternal.h"
 #include "gdbusauthmechanismsha1.h"
-
 #include "gdbusauthobserver.h"
 
 #include "gdbuserror.h"
 #include "gioenumtypes.h"
 #include "gcredentials.h"
 #include "gdbusprivate.h"
+#include "giostream.h"
+#include "gdatainputstream.h"
+#include "gdataoutputstream.h"
 
 #ifdef G_OS_UNIX
-#include <gio/gunixconnection.h>
-#include "gunixcredentialsmessage.h"
 #include <sys/types.h>
 #include <sys/socket.h>
+#include "gunixconnection.h"
+#include "gunixcredentialsmessage.h"
 #endif
 
 #include "glibintl.h"
-#include "gioalias.h"
-
-#define DEBUG_ENABLED 1
 
 static void
 debug_print (const gchar *message, ...)
 {
-#if DEBUG_ENABLED
   if (G_UNLIKELY (_g_dbus_debug_authentication ()))
     {
       gchar *s;
@@ -58,6 +57,8 @@ debug_print (const gchar *message, ...)
       va_list var_args;
       guint n;
 
+      _g_dbus_debug_print_lock ();
+
       va_start (var_args, message);
       s = g_strdup_vprintf (message, var_args);
       va_end (var_args);
@@ -75,8 +76,9 @@ debug_print (const gchar *message, ...)
       g_print ("GDBus-debug:Auth: %s\n", str->str);
       g_string_free (str, TRUE);
       g_free (s);
+
+      _g_dbus_debug_print_unlock ();
     }
-#endif
 }
 
 typedef struct
@@ -175,8 +177,8 @@ _g_dbus_auth_class_init (GDBusAuthClass *klass)
   g_object_class_install_property (gobject_class,
                                    PROP_STREAM,
                                    g_param_spec_object ("stream",
-                                                        _("IO Stream"),
-                                                        _("The underlying GIOStream used for I/O"),
+                                                        P_("IO Stream"),
+                                                        P_("The underlying GIOStream used for I/O"),
                                                         G_TYPE_IO_STREAM,
                                                         G_PARAM_READABLE |
                                                         G_PARAM_WRITABLE |
@@ -604,6 +606,8 @@ _g_dbus_auth_run_client (GDBusAuth     *auth,
 
   dis = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (auth->priv->stream)));
   dos = G_DATA_OUTPUT_STREAM (g_data_output_stream_new (g_io_stream_get_output_stream (auth->priv->stream)));
+  g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (dis), FALSE);
+  g_filter_output_stream_set_close_base_stream (G_FILTER_OUTPUT_STREAM (dos), FALSE);
 
   g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
 
@@ -612,7 +616,6 @@ _g_dbus_auth_run_client (GDBusAuth     *auth,
     {
       credentials = g_credentials_new ();
       if (!g_unix_connection_send_credentials (G_UNIX_CONNECTION (auth->priv->stream),
-                                               credentials,
                                                cancellable,
                                                error))
         goto out;
@@ -641,7 +644,7 @@ _g_dbus_auth_run_client (GDBusAuth     *auth,
       debug_print ("CLIENT: didn't send any credentials");
     }
 
-  /* TODO: to reduce rountrips, try to pick an auth mechanism to start with */
+  /* TODO: to reduce roundtrips, try to pick an auth mechanism to start with */
 
   /* Get list of supported authentication mechanisms */
   s = "AUTH\r\n";
@@ -759,6 +762,7 @@ _g_dbus_auth_run_client (GDBusAuth     *auth,
           debug_print ("CLIENT: WaitingForAgreeUnixFD, read=`%s'", line);
           if (g_strcmp0 (line, "AGREE_UNIX_FD") == 0)
             {
+              g_free (line);
               negotiated_capabilities |= G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING;
               s = "BEGIN\r\n";
               debug_print ("CLIENT: writing `%s'", s);
@@ -801,7 +805,7 @@ _g_dbus_auth_run_client (GDBusAuth     *auth,
             {
               gchar *encoded;
               gchar *decoded_data;
-              gsize decoded_data_len;
+              gsize decoded_data_len = 0;
 
               encoded = g_strdup (line + 5);
               g_free (line);
@@ -861,8 +865,8 @@ _g_dbus_auth_run_client (GDBusAuth     *auth,
     g_object_unref (mech);
   g_ptr_array_unref (attempted_auth_mechs);
   g_strfreev (supported_auth_mechs);
-  g_object_ref (dis);
-  g_object_ref (dos);
+  g_object_unref (dis);
+  g_object_unref (dos);
 
   /* ensure return value is NULL if error is set */
   if (error != NULL && *error != NULL)
@@ -970,6 +974,8 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
 
   dis = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (auth->priv->stream)));
   dos = G_DATA_OUTPUT_STREAM (g_data_output_stream_new (g_io_stream_get_output_stream (auth->priv->stream)));
+  g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (dis), FALSE);
+  g_filter_output_stream_set_close_base_stream (G_FILTER_OUTPUT_STREAM (dos), FALSE);
 
   g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
 
@@ -991,6 +997,7 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
     {
       local_error = NULL;
       byte = g_data_input_stream_read_byte (dis, cancellable, &local_error);
+      byte = byte; /* To avoid -Wunused-but-set-variable */
       if (local_error != NULL)
         {
           g_propagate_error (error, local_error);
@@ -1133,15 +1140,15 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
                     {
                     case G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED:
                       if (observer != NULL &&
-                          g_dbus_auth_observer_deny_authenticated_peer (observer,
-                                                                        auth->priv->stream,
-                                                                        credentials))
+                          !g_dbus_auth_observer_authorize_authenticated_peer (observer,
+                                                                              auth->priv->stream,
+                                                                              credentials))
                         {
                           /* disconnect */
                           g_set_error_literal (error,
                                                G_IO_ERROR,
                                                G_IO_ERROR_FAILED,
-                                               _("Cancelled via GDBusAuthObserver::deny-authenticated-peer"));
+                                               _("Cancelled via GDBusAuthObserver::authorize-authenticated-peer"));
                           goto out;
                         }
                       else
@@ -1224,7 +1231,7 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
             {
               gchar *encoded;
               gchar *decoded_data;
-              gsize decoded_data_len;
+              gsize decoded_data_len = 0;
 
               encoded = g_strdup (line + 5);
               g_free (line);
@@ -1278,6 +1285,7 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
             }
           else if (g_strcmp0 (line, "NEGOTIATE_UNIX_FD") == 0)
             {
+              g_free (line);
               if (offered_capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING)
                 {
                   negotiated_capabilities |= G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING;
@@ -1321,9 +1329,9 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
   if (mech != NULL)
     g_object_unref (mech);
   if (dis != NULL)
-    g_object_ref (dis);
-  if (dis != NULL)
-    g_object_ref (dos);
+    g_object_unref (dis);
+  if (dos != NULL)
+    g_object_unref (dos);
 
   /* ensure return value is FALSE if error is set */
   if (error != NULL && *error != NULL)
@@ -1348,6 +1356,3 @@ _g_dbus_auth_run_server (GDBusAuth              *auth,
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
-
-#define __G_DBUS_AUTH_C__
-#include "gioaliasdef.c"