sharing: Use g_auto for variables

This commit is contained in:
Robert Ancell 2018-06-01 11:00:19 +12:00 committed by Georges Basile Stavracas Neto
parent 9a7850a7aa
commit a30f660db9
6 changed files with 137 additions and 220 deletions

View file

@ -28,7 +28,7 @@
static GKeyFile* static GKeyFile*
cc_media_sharing_open_key_file (void) cc_media_sharing_open_key_file (void)
{ {
gchar *path; g_autofree gchar *path = NULL;
GKeyFile *file; GKeyFile *file;
file = g_key_file_new (); file = g_key_file_new ();
@ -39,22 +39,20 @@ cc_media_sharing_open_key_file (void)
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
NULL)) NULL))
{ {
g_free (path); g_autofree gchar *sysconf_path = NULL;
path = g_build_filename (SYSCONFDIR, "rygel.conf", NULL); sysconf_path = g_build_filename (SYSCONFDIR, "rygel.conf", NULL);
g_key_file_load_from_file (file, path, g_key_file_load_from_file (file, sysconf_path,
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
NULL); NULL);
} }
g_free (path);
return file; return file;
} }
void void
cc_media_sharing_get_preferences (gchar ***folders) cc_media_sharing_get_preferences (gchar ***folders)
{ {
GKeyFile *file; g_autoptr(GKeyFile) file = NULL;
file = cc_media_sharing_open_key_file (); file = cc_media_sharing_open_key_file ();
@ -62,7 +60,8 @@ cc_media_sharing_get_preferences (gchar ***folders)
{ {
gsize length; gsize length;
GPtrArray *array; GPtrArray *array;
char **str_list, **orig_list; GStrv str_list;
g_auto(GStrv) orig_list = NULL;
str_list = g_key_file_get_string_list (file, "MediaExport", "uris", str_list = g_key_file_get_string_list (file, "MediaExport", "uris",
&length, NULL); &length, NULL);
@ -91,20 +90,17 @@ cc_media_sharing_get_preferences (gchar ***folders)
g_ptr_array_add (array, NULL); g_ptr_array_add (array, NULL);
*folders = (char **) g_ptr_array_free (array, FALSE); *folders = (char **) g_ptr_array_free (array, FALSE);
g_strfreev (orig_list);
} }
g_key_file_free (file);
} }
void void
cc_media_sharing_set_preferences (gchar **folders) cc_media_sharing_set_preferences (gchar **folders)
{ {
GKeyFile *file; g_autoptr(GKeyFile) file = NULL;
gchar **str_list; gchar **str_list;
gchar *path; g_autofree gchar *path = NULL;
gsize length; gsize length;
gchar *data; g_autofree gchar *data = NULL;
file = cc_media_sharing_open_key_file (); file = cc_media_sharing_open_key_file ();
@ -146,8 +142,4 @@ cc_media_sharing_set_preferences (gchar **folders)
path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL); path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL);
g_file_set_contents (path, data, -1, NULL); g_file_set_contents (path, data, -1, NULL);
g_free (path);
g_key_file_free (file);
} }

View file

@ -30,19 +30,19 @@ static const gchar *service_list[] = { SSHD_SERVICE, NULL };
static gint static gint
enable_ssh_service () enable_ssh_service ()
{ {
GDBusConnection *connection; g_autoptr(GDBusConnection) connection = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
GVariant *temp_variant; g_autoptr(GVariant) start_result = NULL;
g_autoptr(GVariant) enable_result = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!connection) if (!connection)
{ {
g_critical ("Error connecting to D-Bus system bus: %s", error->message); g_critical ("Error connecting to D-Bus system bus: %s", error->message);
g_clear_error (&error);
return 1; return 1;
} }
temp_variant = g_dbus_connection_call_sync (connection, start_result = g_dbus_connection_call_sync (connection,
"org.freedesktop.systemd1", "org.freedesktop.systemd1",
"/org/freedesktop/systemd1", "/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager", "org.freedesktop.systemd1.Manager",
@ -56,98 +56,86 @@ enable_ssh_service ()
NULL, NULL,
&error); &error);
if (!temp_variant) if (!start_result)
{ {
g_critical ("Error starting " SSHD_SERVICE ": %s", error->message); g_critical ("Error starting " SSHD_SERVICE ": %s", error->message);
g_clear_error (&error);
return 1; return 1;
} }
g_variant_unref (temp_variant); enable_result = g_dbus_connection_call_sync (connection,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"EnableUnitFiles",
g_variant_new ("(^asbb)",
service_list,
FALSE, FALSE),
(GVariantType *) "(ba(sss))",
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
temp_variant = g_dbus_connection_call_sync (connection, if (!enable_result)
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"EnableUnitFiles",
g_variant_new ("(^asbb)",
service_list,
FALSE, FALSE),
(GVariantType *) "(ba(sss))",
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (!temp_variant)
{ {
g_critical ("Error enabling " SSHD_SERVICE ": %s", error->message); g_critical ("Error enabling " SSHD_SERVICE ": %s", error->message);
g_clear_error (&error);
return 1; return 1;
} }
g_variant_unref (temp_variant);
return 0; return 0;
} }
static gint static gint
disable_ssh_service () disable_ssh_service ()
{ {
GDBusConnection *connection; g_autoptr(GDBusConnection) connection = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
GVariant *temp_variant; g_autoptr(GVariant) stop_result = NULL;
g_autoptr(GVariant) disable_result = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (!connection) if (!connection)
{ {
g_critical ("Error connecting to D-Bus system bus: %s", error->message); g_critical ("Error connecting to D-Bus system bus: %s", error->message);
g_clear_error (&error);
return 1; return 1;
} }
temp_variant = g_dbus_connection_call_sync (connection, stop_result = g_dbus_connection_call_sync (connection,
"org.freedesktop.systemd1", "org.freedesktop.systemd1",
"/org/freedesktop/systemd1", "/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager", "org.freedesktop.systemd1.Manager",
"StopUnit", "StopUnit",
g_variant_new ("(ss)", SSHD_SERVICE, "replace"), g_variant_new ("(ss)", SSHD_SERVICE, "replace"),
(GVariantType *) "(o)", (GVariantType *) "(o)",
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
NULL, NULL,
&error); &error);
if (!temp_variant) if (!stop_result)
{ {
g_critical ("Error stopping " SSHD_SERVICE ": %s", error->message); g_critical ("Error stopping " SSHD_SERVICE ": %s", error->message);
g_clear_error (&error);
return 1; return 1;
} }
g_variant_unref (temp_variant); disable_result = g_dbus_connection_call_sync (connection,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"DisableUnitFiles",
g_variant_new ("(^asb)", service_list, FALSE,
FALSE),
(GVariantType *) "(a(sss))",
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
temp_variant = g_dbus_connection_call_sync (connection, if (!stop_result)
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"DisableUnitFiles",
g_variant_new ("(^asb)", service_list, FALSE,
FALSE),
(GVariantType *) "(a(sss))",
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (!temp_variant)
{ {
g_critical ("Error disabling " SSHD_SERVICE ": %s", error->message); g_critical ("Error disabling " SSHD_SERVICE ": %s", error->message);
g_clear_error (&error);
return 1; return 1;
} }
g_variant_unref (temp_variant);
return 0; return 0;
} }

View file

@ -32,6 +32,8 @@ typedef struct
GCancellable *cancellable; GCancellable *cancellable;
} CallbackData; } CallbackData;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CallbackData, g_free)
static void static void
set_switch_state (GtkSwitch *gtkswitch, set_switch_state (GtkSwitch *gtkswitch,
gboolean active) gboolean active)
@ -48,12 +50,15 @@ set_switch_state (GtkSwitch *gtkswitch,
static void static void
active_state_ready_callback (GObject *source_object, active_state_ready_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
CallbackData *callback_data) gpointer user_data)
{ {
GVariant *active_variant, *child_variant, *tmp_variant; g_autoptr(CallbackData) callback_data = user_data;
g_autoptr(GVariant) active_variant = NULL;
g_autoptr(GVariant) child_variant = NULL;
g_autoptr(GVariant) tmp_variant = NULL;
const gchar *active_state; const gchar *active_state;
gboolean active; gboolean active;
GError *error = NULL; g_autoptr(GError) error = NULL;
active_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), active_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
result, &error); result, &error);
@ -65,9 +70,6 @@ active_state_ready_callback (GObject *source_object,
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("Error getting remote login state: %s", error->message); g_warning ("Error getting remote login state: %s", error->message);
g_clear_error (&error);
g_free (callback_data);
/* the switch will be remain insensitive, since the current state could /* the switch will be remain insensitive, since the current state could
* not be determined */ * not be determined */
return; return;
@ -79,25 +81,21 @@ active_state_ready_callback (GObject *source_object,
active = g_str_equal (active_state, "active"); active = g_str_equal (active_state, "active");
g_variant_unref (tmp_variant);
g_variant_unref (child_variant);
g_variant_unref (active_variant);
/* set the switch to the correct state */ /* set the switch to the correct state */
if (callback_data->gtkswitch) if (callback_data->gtkswitch)
set_switch_state (callback_data->gtkswitch, active); set_switch_state (callback_data->gtkswitch, active);
g_free (callback_data);
} }
static void static void
path_ready_callback (GObject *source_object, path_ready_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
CallbackData *callback_data) gpointer user_data)
{ {
GVariant *path_variant, *child_variant; g_autoptr(CallbackData) callback_data = user_data;
g_autoptr(GVariant) path_variant = NULL;
g_autoptr(GVariant) child_variant = NULL;
const gchar *object_path; const gchar *object_path;
GError *error = NULL; g_autoptr(GError) error = NULL;
path_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), path_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
result, &error); result, &error);
@ -105,24 +103,15 @@ path_ready_callback (GObject *source_object,
if (!path_variant) if (!path_variant)
{ {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{ return;
g_free (callback_data);
g_clear_error (&error);
return;
}
/* this may fail if systemd or remote login service is not available */ /* this may fail if systemd or remote login service is not available */
g_debug ("Error getting remote login state: %s", error->message); g_debug ("Error getting remote login state: %s", error->message);
g_clear_error (&error);
/* hide the remote login button, since the service is not available */ /* hide the remote login button, since the service is not available */
if (callback_data->button) if (callback_data->button)
gtk_widget_hide (callback_data->button); gtk_widget_hide (callback_data->button);
g_free (callback_data);
return; return;
} }
@ -141,45 +130,36 @@ path_ready_callback (GObject *source_object,
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
callback_data->cancellable, callback_data->cancellable,
(GAsyncReadyCallback) active_state_ready_callback, active_state_ready_callback,
callback_data); callback_data);
g_steal_pointer (&callback_data);
g_variant_unref (child_variant);
g_variant_unref (path_variant);
} }
static void static void
state_ready_callback (GObject *source_object, state_ready_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
CallbackData *callback_data) gpointer user_data)
{ {
GVariant *state_variant, *child_variant; g_autoptr(CallbackData) callback_data = user_data;
g_autoptr(GVariant) state_variant = NULL;
g_autoptr(GVariant) child_variant = NULL;
const gchar *state_string; const gchar *state_string;
GError *error = NULL; g_autoptr(GError) error = NULL;
state_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), state_variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
result, &error); result, &error);
if (!state_variant) if (!state_variant)
{ {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{ return;
g_free (callback_data);
g_clear_error (&error);
return;
}
/* this may fail if systemd or remote login service is not available */ /* this may fail if systemd or remote login service is not available */
g_debug ("Error getting remote login state: %s", error->message); g_debug ("Error getting remote login state: %s", error->message);
g_clear_error (&error);
/* hide the remote login button, since the service is not available */ /* hide the remote login button, since the service is not available */
if (callback_data->button) if (callback_data->button)
gtk_widget_hide (callback_data->button); gtk_widget_hide (callback_data->button);
g_free (callback_data);
return; return;
} }
@ -199,35 +179,30 @@ state_ready_callback (GObject *source_object,
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
callback_data->cancellable, callback_data->cancellable,
(GAsyncReadyCallback) path_ready_callback, path_ready_callback,
callback_data); callback_data);
g_steal_pointer (&callback_data);
} }
else if (g_str_equal (state_string, "disabled")) else if (g_str_equal (state_string, "disabled"))
{ {
/* service is available, but is currently disabled */ /* service is available, but is currently disabled */
set_switch_state (callback_data->gtkswitch, FALSE); set_switch_state (callback_data->gtkswitch, FALSE);
g_free (callback_data);
} }
else else
{ {
/* unknown state */ /* unknown state */
g_warning ("Unknown state %s for %s", state_string, SSHD_SERVICE); g_warning ("Unknown state %s for %s", state_string, SSHD_SERVICE);
g_free (callback_data);
} }
g_variant_unref (child_variant);
g_variant_unref (state_variant);
} }
static void static void
bus_ready_callback (GObject *source_object, bus_ready_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
CallbackData *callback_data) gpointer user_data)
{ {
GDBusConnection *connection; g_autoptr(CallbackData) callback_data = user_data;
GError *error = NULL; g_autoptr(GDBusConnection) connection = NULL;
g_autoptr(GError) error = NULL;
connection = g_bus_get_finish (result, &error); connection = g_bus_get_finish (result, &error);
@ -235,8 +210,6 @@ bus_ready_callback (GObject *source_object,
{ {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("Error getting remote login state: %s", error->message); g_warning ("Error getting remote login state: %s", error->message);
g_clear_error (&error);
g_free (callback_data);
return; return;
} }
@ -251,8 +224,9 @@ bus_ready_callback (GObject *source_object,
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
callback_data->cancellable, callback_data->cancellable,
(GAsyncReadyCallback) state_ready_callback, state_ready_callback,
callback_data); callback_data);
g_steal_pointer (&callback_data);
} }
void void
@ -271,7 +245,7 @@ cc_remote_login_get_enabled (GCancellable *cancellable,
callback_data->cancellable = cancellable; callback_data->cancellable = cancellable;
g_bus_get (G_BUS_TYPE_SYSTEM, callback_data->cancellable, g_bus_get (G_BUS_TYPE_SYSTEM, callback_data->cancellable,
(GAsyncReadyCallback) bus_ready_callback, callback_data); bus_ready_callback, callback_data);
} }
static gint std_err; static gint std_err;
@ -281,7 +255,7 @@ child_watch_func (GPid pid,
gint status, gint status,
gpointer user_data) gpointer user_data)
{ {
CallbackData *callback_data = user_data; g_autoptr(CallbackData) callback_data = user_data;
if (status != 0) if (status != 0)
{ {
g_warning ("Error enabling or disabling remote login service"); g_warning ("Error enabling or disabling remote login service");
@ -292,8 +266,6 @@ child_watch_func (GPid pid,
g_spawn_close_pid (pid); g_spawn_close_pid (pid);
gtk_widget_set_sensitive (GTK_WIDGET (callback_data->gtkswitch), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (callback_data->gtkswitch), TRUE);
g_free (user_data);
} }
void void
@ -302,11 +274,10 @@ cc_remote_login_set_enabled (GCancellable *cancellable,
{ {
gchar *command[] = { "pkexec", LIBEXECDIR "/cc-remote-login-helper", NULL, gchar *command[] = { "pkexec", LIBEXECDIR "/cc-remote-login-helper", NULL,
NULL }; NULL };
GError *error = NULL; g_autoptr(GError) error = NULL;
GPid pid; GPid pid;
CallbackData *callback_data; CallbackData *callback_data;
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (gtkswitch), "set-from-dbus")) == 1) if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (gtkswitch), "set-from-dbus")) == 1)
{ {
g_object_set_data (G_OBJECT (gtkswitch), "set-from-dbus", NULL); g_object_set_data (G_OBJECT (gtkswitch), "set-from-dbus", NULL);
@ -331,8 +302,5 @@ cc_remote_login_set_enabled (GCancellable *cancellable,
g_child_watch_add (pid, child_watch_func, callback_data); g_child_watch_add (pid, child_watch_func, callback_data);
if (error) if (error)
{ g_error ("Error running cc-remote-login-helper: %s", error->message);
g_error ("Error running cc-remote-login-helper: %s", error->message);
g_clear_error (&error);
}
} }

View file

@ -102,10 +102,10 @@ cc_sharing_networks_update_status (CcSharingNetworks *self)
static void static void
cc_sharing_update_networks (CcSharingNetworks *self) cc_sharing_update_networks (CcSharingNetworks *self)
{ {
GVariant *networks; g_autoptr(GVariant) networks = NULL;
char *uuid, *network_name, *carrier_type; char *uuid, *network_name, *carrier_type;
GVariantIter iter; GVariantIter iter;
GError *error = NULL; g_autoptr(GError) error = NULL;
g_list_free_full (self->networks, cc_sharing_network_free); g_list_free_full (self->networks, cc_sharing_network_free);
self->networks = NULL; self->networks = NULL;
@ -115,7 +115,6 @@ cc_sharing_update_networks (CcSharingNetworks *self)
g_dbus_proxy_set_cached_property (G_DBUS_PROXY (self->proxy), g_dbus_proxy_set_cached_property (G_DBUS_PROXY (self->proxy),
"SharingStatus", "SharingStatus",
g_variant_new_uint32 (GSD_SHARING_STATUS_OFFLINE)); g_variant_new_uint32 (GSD_SHARING_STATUS_OFFLINE));
g_error_free (error);
cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox)); cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox));
return; return;
} }
@ -132,8 +131,6 @@ cc_sharing_update_networks (CcSharingNetworks *self)
} }
self->networks = g_list_reverse (self->networks); self->networks = g_list_reverse (self->networks);
cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox)); cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->listbox));
g_variant_unref (networks);
} }
static void static void
@ -141,7 +138,7 @@ cc_sharing_networks_remove_network (GtkWidget *button,
CcSharingNetworks *self) CcSharingNetworks *self)
{ {
GtkWidget *row; GtkWidget *row;
GError *error = NULL; g_autoptr(GError) error = NULL;
gboolean ret; gboolean ret;
const char *uuid; const char *uuid;
@ -153,11 +150,9 @@ cc_sharing_networks_remove_network (GtkWidget *button,
uuid, uuid,
NULL, NULL,
&error); &error);
if (!ret) { if (!ret)
g_warning ("Failed to remove service %s: %s", g_warning ("Failed to remove service %s: %s",
self->service_name, error->message); self->service_name, error->message);
g_error_free (error);
}
cc_sharing_update_networks (self); cc_sharing_update_networks (self);
cc_sharing_update_networks_box (self); cc_sharing_update_networks_box (self);
@ -169,7 +164,7 @@ cc_sharing_networks_enable_network (GtkSwitch *widget,
gpointer user_data) gpointer user_data)
{ {
CcSharingNetworks *self = user_data; CcSharingNetworks *self = user_data;
GError *error = NULL; g_autoptr(GError) error = NULL;
gboolean ret; gboolean ret;
if (state) { if (state) {
@ -190,7 +185,6 @@ cc_sharing_networks_enable_network (GtkSwitch *widget,
} else { } else {
g_warning ("Failed to %s service %s: %s", state ? "enable" : "disable", g_warning ("Failed to %s service %s: %s", state ? "enable" : "disable",
self->service_name, error->message); self->service_name, error->message);
g_error_free (error);
g_signal_handlers_block_by_func (widget, g_signal_handlers_block_by_func (widget,
cc_sharing_networks_enable_network, self); cc_sharing_networks_enable_network, self);
gtk_switch_set_active (widget, !state); gtk_switch_set_active (widget, !state);
@ -321,7 +315,8 @@ cc_sharing_update_networks_box (CcSharingNetworks *self)
{ {
gboolean current_visible; gboolean current_visible;
const char *current_network; const char *current_network;
GList *children, *l; g_autoptr(GList) children = NULL;
GList *l;
children = gtk_container_get_children (GTK_CONTAINER (self->listbox)); children = gtk_container_get_children (GTK_CONTAINER (self->listbox));
for (l = children; l != NULL; l = l->next) { for (l = children; l != NULL; l = l->next) {
@ -331,7 +326,6 @@ cc_sharing_update_networks_box (CcSharingNetworks *self)
row != self->no_network_row) row != self->no_network_row)
gtk_widget_destroy (row); gtk_widget_destroy (row);
} }
g_list_free (children);
current_network = gsd_sharing_get_current_network (self->proxy); current_network = gsd_sharing_get_current_network (self->proxy);

View file

@ -226,7 +226,8 @@ cc_sharing_panel_main_list_box_row_activated (GtkListBox *listbox,
GtkListBoxRow *row, GtkListBoxRow *row,
CcSharingPanel *self) CcSharingPanel *self)
{ {
gchar *widget_name, *found; g_autofree gchar *widget_name = NULL;
gchar *found;
widget_name = g_strdup (gtk_buildable_get_name (GTK_BUILDABLE (row))); widget_name = g_strdup (gtk_buildable_get_name (GTK_BUILDABLE (row)));
@ -239,14 +240,11 @@ cc_sharing_panel_main_list_box_row_activated (GtkListBox *listbox,
found = g_strrstr (widget_name, "button"); found = g_strrstr (widget_name, "button");
if (!found) if (!found)
goto out; return;
memcpy (found, "dialog", 6); memcpy (found, "dialog", 6);
cc_sharing_panel_run_dialog (self, widget_name); cc_sharing_panel_run_dialog (self, widget_name);
out:
g_free (widget_name);
} }
static gboolean static gboolean
@ -364,7 +362,7 @@ cc_sharing_panel_add_folder (GtkListBox *box,
CcSharingPanel *self) CcSharingPanel *self)
{ {
GtkWidget *dialog; GtkWidget *dialog;
gchar *folder = NULL; g_autofree gchar *folder = NULL;
gboolean matching = FALSE; gboolean matching = FALSE;
GList *rows, *l; GList *rows, *l;
@ -418,7 +416,6 @@ cc_sharing_panel_add_folder (GtkListBox *box,
cc_list_box_adjust_scrolling (GTK_LIST_BOX (box)); cc_list_box_adjust_scrolling (GTK_LIST_BOX (box));
bail: bail:
g_free (folder);
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
@ -438,7 +435,7 @@ cc_sharing_panel_media_sharing_dialog_response (GtkDialog *dialog,
gint reponse_id, gint reponse_id,
CcSharingPanel *self) CcSharingPanel *self)
{ {
GPtrArray *folders; g_autoptr(GPtrArray) folders = NULL;
GtkWidget *box; GtkWidget *box;
GList *rows, *l; GList *rows, *l;
@ -459,8 +456,6 @@ cc_sharing_panel_media_sharing_dialog_response (GtkDialog *dialog,
g_ptr_array_add (folders, NULL); g_ptr_array_add (folders, NULL);
cc_media_sharing_set_preferences ((gchar **) folders->pdata); cc_media_sharing_set_preferences ((gchar **) folders->pdata);
g_ptr_array_free (folders, TRUE);
} }
#define ICON_NAME_FOLDER "folder-symbolic" #define ICON_NAME_FOLDER "folder-symbolic"
@ -505,14 +500,14 @@ cc_sharing_panel_new_media_sharing_row (const char *uri_or_path,
{ {
GtkWidget *row, *box, *w; GtkWidget *row, *box, *w;
GUserDirectory dir = G_USER_N_DIRECTORIES; GUserDirectory dir = G_USER_N_DIRECTORIES;
GIcon *icon; g_autoptr(GIcon) icon = NULL;
guint i; guint i;
char *basename, *path; g_autofree gchar *basename = NULL;
GFile *file; g_autofree gchar *path = NULL;
g_autoptr(GFile) file = NULL;
file = g_file_new_for_commandline_arg (uri_or_path); file = g_file_new_for_commandline_arg (uri_or_path);
path = g_file_get_path (file); path = g_file_get_path (file);
g_object_unref (file);
row = gtk_list_box_row_new (); row = gtk_list_box_row_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
@ -534,12 +529,10 @@ cc_sharing_panel_new_media_sharing_row (const char *uri_or_path,
w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU); w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
gtk_widget_set_margin_end (w, 12); gtk_widget_set_margin_end (w, 12);
gtk_container_add (GTK_CONTAINER (box), w); gtk_container_add (GTK_CONTAINER (box), w);
g_object_unref (icon);
/* Label */ /* Label */
basename = g_filename_display_basename (path); basename = g_filename_display_basename (path);
w = gtk_label_new (basename); w = gtk_label_new (basename);
g_free (basename);
gtk_container_add (GTK_CONTAINER (box), w); gtk_container_add (GTK_CONTAINER (box), w);
/* Remove button */ /* Remove button */
@ -554,7 +547,7 @@ cc_sharing_panel_new_media_sharing_row (const char *uri_or_path,
G_CALLBACK (cc_sharing_panel_remove_folder), self); G_CALLBACK (cc_sharing_panel_remove_folder), self);
g_object_set_data (G_OBJECT (w), "row", row); g_object_set_data (G_OBJECT (w), "row", row);
g_object_set_data_full (G_OBJECT (row), "path", path, g_free); g_object_set_data_full (G_OBJECT (row), "path", g_steal_pointer (&path), g_free);
gtk_widget_show_all (row); gtk_widget_show_all (row);
@ -588,9 +581,10 @@ cc_sharing_panel_new_add_media_sharing_row (CcSharingPanel *self)
static void static void
cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self) cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
{ {
gchar **folders, **list; g_auto(GStrv) folders = NULL;
GStrv list;
GtkWidget *box, *networks, *grid, *w; GtkWidget *box, *networks, *grid, *w;
char *path; g_autofree gchar *path = NULL;
path = g_find_program_in_path ("rygel"); path = g_find_program_in_path ("rygel");
if (path == NULL) if (path == NULL)
@ -598,7 +592,6 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
gtk_widget_hide (WID ("media-sharing-button")); gtk_widget_hide (WID ("media-sharing-button"));
return; return;
} }
g_free (path);
g_signal_connect (WID ("media-sharing-dialog"), "response", g_signal_connect (WID ("media-sharing-dialog"), "response",
G_CALLBACK (cc_sharing_panel_media_sharing_dialog_response), G_CALLBACK (cc_sharing_panel_media_sharing_dialog_response),
@ -630,9 +623,6 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
g_signal_connect (G_OBJECT (box), "row-activated", g_signal_connect (G_OBJECT (box), "row-activated",
G_CALLBACK (cc_sharing_panel_add_folder), self); G_CALLBACK (cc_sharing_panel_add_folder), self);
g_strfreev (folders);
networks = cc_sharing_networks_new (self->sharing_proxy, "rygel"); networks = cc_sharing_networks_new (self->sharing_proxy, "rygel");
grid = WID ("grid4"); grid = WID ("grid4");
gtk_grid_attach (GTK_GRID (grid), networks, 0, 4, 2, 1); gtk_grid_attach (GTK_GRID (grid), networks, 0, 4, 2, 1);
@ -676,7 +666,7 @@ cc_sharing_panel_setup_label (CcSharingPanel *self,
GtkWidget *label, GtkWidget *label,
const gchar *hostname) const gchar *hostname)
{ {
gchar *text; g_autofree gchar *text = NULL;
if (label == WID ("personal-file-sharing-label")) if (label == WID ("personal-file-sharing-label"))
text = g_strdup_printf (_("File Sharing allows you to share your Public folder with others on your current network using: <a href=\"dav://%s\">dav://%s</a>"), hostname, hostname); text = g_strdup_printf (_("File Sharing allows you to share your Public folder with others on your current network using: <a href=\"dav://%s\">dav://%s</a>"), hostname, hostname);
@ -688,8 +678,6 @@ cc_sharing_panel_setup_label (CcSharingPanel *self,
g_assert_not_reached (); g_assert_not_reached ();
gtk_label_set_label (GTK_LABEL (label), text); gtk_label_set_label (GTK_LABEL (label), text);
g_free (text);
} }
typedef struct typedef struct
@ -698,13 +686,17 @@ typedef struct
GtkWidget *label; GtkWidget *label;
} GetHostNameData; } GetHostNameData;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetHostNameData, g_free);
static void static void
cc_sharing_panel_get_host_name_fqdn_done (GDBusConnection *connection, cc_sharing_panel_get_host_name_fqdn_done (GObject *object,
GAsyncResult *res, GAsyncResult *res,
GetHostNameData *data) gpointer user_data)
{ {
GError *error = NULL; GDBusConnection *connection = G_DBUS_CONNECTION (object);
GVariant *variant; g_autoptr(GetHostNameData) data = user_data;
g_autoptr(GError) error = NULL;
g_autoptr(GVariant) variant = NULL;
const gchar *fqdn; const gchar *fqdn;
variant = g_dbus_connection_call_finish (connection, res, &error); variant = g_dbus_connection_call_finish (connection, res, &error);
@ -716,36 +708,29 @@ cc_sharing_panel_get_host_name_fqdn_done (GDBusConnection *connection,
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{ {
gchar *hostname; g_autofree gchar *hostname = NULL;
hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry)); hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry));
cc_sharing_panel_setup_label (data->panel, data->label, hostname); cc_sharing_panel_setup_label (data->panel, data->label, hostname);
g_free (hostname);
} }
g_free (data);
g_error_free (error);
return; return;
} }
g_variant_get (variant, "(&s)", &fqdn); g_variant_get (variant, "(&s)", &fqdn);
cc_sharing_panel_setup_label (data->panel, data->label, fqdn); cc_sharing_panel_setup_label (data->panel, data->label, fqdn);
g_variant_unref (variant);
g_object_unref (connection);
g_free (data);
} }
static void static void
cc_sharing_panel_bus_ready (GObject *object, cc_sharing_panel_bus_ready (GObject *object,
GAsyncResult *res, GAsyncResult *res,
GetHostNameData *data) gpointer user_data)
{ {
GDBusConnection *connection; g_autoptr(GDBusConnection) connection = NULL;
GError *error = NULL; g_autoptr(GetHostNameData) data = user_data;
g_autoptr(GError) error = NULL;
connection = g_bus_get_finish (res, &error); connection = g_bus_get_finish (res, &error);
@ -755,17 +740,13 @@ cc_sharing_panel_bus_ready (GObject *object,
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{ {
gchar *hostname; g_autofree gchar *hostname = NULL;
hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry)); hostname = cc_hostname_entry_get_hostname (CC_HOSTNAME_ENTRY (data->panel->hostname_entry));
cc_sharing_panel_setup_label (data->panel, data->label, hostname); cc_sharing_panel_setup_label (data->panel, data->label, hostname);
g_free (hostname);
} }
g_error_free (error);
g_free (data);
return; return;
} }
@ -779,8 +760,9 @@ cc_sharing_panel_bus_ready (GObject *object,
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
data->panel->hostname_cancellable, data->panel->hostname_cancellable,
(GAsyncReadyCallback) cc_sharing_panel_get_host_name_fqdn_done, cc_sharing_panel_get_host_name_fqdn_done,
data); data);
g_steal_pointer (&data);
} }
@ -818,7 +800,7 @@ cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self,
get_hostname_data->label = label; get_hostname_data->label = label;
g_bus_get (G_BUS_TYPE_SYSTEM, g_bus_get (G_BUS_TYPE_SYSTEM,
self->hostname_cancellable, self->hostname_cancellable,
(GAsyncReadyCallback) cc_sharing_panel_bus_ready, cc_sharing_panel_bus_ready,
get_hostname_data); get_hostname_data);
} }
@ -926,7 +908,7 @@ cc_sharing_panel_check_schema_available (CcSharingPanel *self,
const gchar *schema_id) const gchar *schema_id)
{ {
GSettingsSchemaSource *source; GSettingsSchemaSource *source;
GSettingsSchema *schema; g_autoptr(GSettingsSchema) schema = NULL;
source = g_settings_schema_source_get_default (); source = g_settings_schema_source_get_default ();
if (!source) if (!source)
@ -936,7 +918,6 @@ cc_sharing_panel_check_schema_available (CcSharingPanel *self,
if (!schema) if (!schema)
return FALSE; return FALSE;
g_settings_schema_unref (schema);
return TRUE; return TRUE;
} }
@ -1110,13 +1091,12 @@ sharing_proxy_ready (GObject *source,
{ {
CcSharingPanel *self; CcSharingPanel *self;
GDBusProxy *proxy; GDBusProxy *proxy;
GError *error = NULL; g_autoptr(GError) error = NULL;
proxy = G_DBUS_PROXY (gsd_sharing_proxy_new_for_bus_finish (res, &error)); proxy = G_DBUS_PROXY (gsd_sharing_proxy_new_for_bus_finish (res, &error));
if (!proxy) { if (!proxy) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("Failed to get sharing proxy: %s", error->message); g_warning ("Failed to get sharing proxy: %s", error->message);
g_error_free (error);
return; return;
} }

View file

@ -35,17 +35,15 @@
void void
file_share_write_out_password (const char *password) file_share_write_out_password (const char *password)
{ {
char *to_hash; g_autofree gchar *to_hash = NULL;
char *ascii_digest; g_autofree gchar *ascii_digest = NULL;
char *line; g_autofree gchar *line = NULL;
char *filename; g_autofree gchar *filename = NULL;
FILE *file; FILE *file;
to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password); to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash)); ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
g_free (to_hash);
line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest); line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
g_free (ascii_digest);
filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL); filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
@ -54,7 +52,4 @@ file_share_write_out_password (const char *password)
fwrite (line, strlen (line), 1, file); fwrite (line, strlen (line), 1, file);
fclose (file); fclose (file);
} }
g_free (filename);
g_free (line);
} }