static void _decode_username_password(GTlmNfc* self, const gchar* data) { gsize variant_s_size = 0; guchar* variant_s = g_base64_decode(data, &variant_s_size); GVariantType* v_t = g_variant_type_new("(msms)"); GVariant* v = g_variant_new_from_data(v_t, variant_s, variant_s_size, FALSE, NULL, NULL); if (v == NULL) { g_debug("Couldn't decode Payload data to variant"); g_variant_type_free(v_t); g_free(variant_s); g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0); return; } gchar* username = NULL; gchar* password = NULL; g_variant_get(v, "(msms)", &username, &password); g_signal_emit(self, signals[SIG_RECORD_FOUND], 0, username, password); g_free(username); g_free(password); g_variant_unref(v); g_variant_type_free(v_t); g_free(variant_s); }
GVariant * _secret_session_encode_secret (SecretSession *session, SecretValue *value) { GVariantBuilder *builder; GVariant *result = NULL; GVariantType *type; gboolean ret; g_return_val_if_fail (session != NULL, NULL); g_return_val_if_fail (value != NULL, NULL); type = g_variant_type_new ("(oayays)"); builder = g_variant_builder_new (type); #ifdef WITH_GCRYPT if (session->key) ret = service_encode_aes_secret (session, value, builder); else #endif ret = service_encode_plain_secret (session, value, builder); if (ret) result = g_variant_builder_end (builder); g_variant_builder_unref (builder); g_variant_type_free (type); return result; }
gboolean g_variant_lookup (GVariant *dictionary, const gchar *key, const gchar *format_string, ...) { GVariantType *type; GVariant *value; /* flatten */ g_variant_get_data (dictionary); type = g_variant_type_new (format_string); value = g_variant_lookup_value (dictionary, key, type); g_variant_type_free (type); if (value) { va_list ap; va_start (ap, format_string); g_variant_get_va (value, format_string, NULL, &ap); g_variant_unref (value); va_end (ap); return TRUE; } else return FALSE; }
static void g_simple_action_finalize (GObject *object) { GSimpleAction *simple = G_SIMPLE_ACTION (object); g_free (simple->priv->name); if (simple->priv->parameter_type) g_variant_type_free (simple->priv->parameter_type); if (simple->priv->state) g_variant_unref (simple->priv->state); G_OBJECT_CLASS (g_simple_action_parent_class) ->finalize (object); }
static void perform_closure_free (gpointer data) { PerformClosure *closure = data; g_object_unref (closure->call_cancellable); g_clear_object (&closure->async_cancellable); g_object_unref (closure->connection); if (closure->result) g_variant_unref (closure->result); if (closure->return_type) g_variant_type_free (closure->return_type); g_assert (closure->signal == 0); g_assert (closure->watch == 0); g_slice_free (PerformClosure, closure); }
static void action_info_free (gpointer user_data) { ActionInfo *info = user_data; g_free (info->name); if (info->state) g_variant_unref (info->state); if (info->parameter_type) g_variant_type_free (info->parameter_type); g_slice_free (ActionInfo, info); }
void mpris2_cleanup (void) { hook_dissociate ("playback begin", (HookFunction) update_playback_status); hook_dissociate ("playback pause", (HookFunction) update_playback_status); hook_dissociate ("playback stop", (HookFunction) update_playback_status); hook_dissociate ("playback unpause", (HookFunction) update_playback_status); hook_dissociate ("playlist set playing", (HookFunction) update_metadata); hook_dissociate ("playlist position", (HookFunction) update_metadata); hook_dissociate ("playlist update", (HookFunction) update_metadata); hook_dissociate ("playback ready", (HookFunction) emit_seek); hook_dissociate ("playback seek", (HookFunction) emit_seek); if (update_timer) { g_source_remove (update_timer); update_timer = 0; } g_dbus_connection_close_sync (bus, NULL, NULL); g_object_unref (object_core); g_object_unref (object_player); if (image_file) { aud_art_unref (last_file); image_file = NULL; } str_unref (last_title); str_unref (last_artist); str_unref (last_album); str_unref (last_file); last_title = last_artist = last_album = last_file = NULL; last_length = 0; if (metadata_type) { g_variant_type_free (metadata_type); metadata_type = NULL; } }
static void get_properties_cb_4 (GObject *source_object, GAsyncResult *res, gpointer user_data) { NMBluezDevice *self = NM_BLUEZ_DEVICE (user_data); NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); GError *err = NULL; GVariant *v_properties, *v_dict; GVariantType *v_type; v_properties = g_dbus_proxy_call_finish (priv->proxy, res, &err); if (!v_properties) { nm_log_warn (LOGD_BT, "bluez[%s] error getting device properties: %s", priv->path, err && err->message ? err->message : "(unknown)"); g_error_free (err); g_signal_emit (self, signals[INITIALIZED], 0, FALSE); goto END; } v_type = g_variant_type_new ("(a{sv})"); if (g_variant_is_of_type (v_properties, v_type)) { v_dict = g_variant_get_child_value (v_properties, 0); _set_properties (self, v_dict); g_variant_unref (v_dict); } else { nm_log_warn (LOGD_BT, "bluez[%s] GetProperties returns unexpected result of type %s", priv->path, g_variant_get_type_string (v_properties)); } g_variant_type_free (v_type); g_variant_unref (v_properties); /* Check if any connections match this device */ load_connections (self); priv->initialized = TRUE; g_signal_emit (self, signals[INITIALIZED], 0, TRUE); check_emit_usable (self); END: g_object_unref (self); }
static GVariant * parse_json_with_sig (JsonObject *object, GError **error) { GVariantType *inner_type; GVariant *inner; JsonNode *val; const gchar *sig; val = json_object_get_member (object, "val"); if (val == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "JSON did not contain a 'val' field"); return NULL; } if (!cockpit_json_get_string (object, "sig", NULL, &sig) || !sig) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "JSON did not contain valid 'sig' fields"); return NULL; } if (!g_variant_type_string_is_valid (sig)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "JSON 'sig' field '%s' is invalid", sig); return NULL; } inner_type = g_variant_type_new (sig); inner = parse_json (val, inner_type, error); g_variant_type_free (inner_type); if (!inner) return NULL; return g_variant_new_variant (inner); }
/** * g_dbus_method_invocation_return_value: * @invocation: A #GDBusMethodInvocation. * @parameters: A #GVariant tuple with out parameters for the method or %NULL if not passing any parameters. * * Finishes handling a D-Bus method call by returning @parameters. * If the @parameters GVariant is floating, it is consumed. * * It is an error if @parameters is not of the right format. * * This method will free @invocation, you cannot use it afterwards. * * Since: 2.26 */ void g_dbus_method_invocation_return_value (GDBusMethodInvocation *invocation, GVariant *parameters) { GDBusMessage *reply; GError *error; g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation)); g_return_if_fail ((parameters == NULL) || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE)); if (parameters == NULL) parameters = g_variant_new_tuple (NULL, 0); /* if we have introspection data, check that the signature of @parameters is correct */ if (invocation->method_info != NULL) { GVariantType *type; type = _g_dbus_compute_complete_signature (invocation->method_info->out_args); if (!g_variant_is_of_type (parameters, type)) { gchar *type_string = g_variant_type_dup_string (type); g_warning (_("Type of return value is incorrect, got `%s', expected `%s'"), g_variant_get_type_string (parameters), type_string); g_variant_type_free (type); g_free (type_string); goto out; } g_variant_type_free (type); } if (G_UNLIKELY (_g_dbus_debug_return ())) { _g_dbus_debug_print_lock (); g_print ("========================================================================\n" "GDBus-debug:Return:\n" " >>>> METHOD RETURN\n" " in response to %s.%s()\n" " on object %s\n" " to name %s\n" " reply-serial %d\n", invocation->interface_name, invocation->method_name, invocation->object_path, invocation->sender, g_dbus_message_get_serial (invocation->message)); _g_dbus_debug_print_unlock (); } reply = g_dbus_message_new_method_reply (invocation->message); g_dbus_message_set_body (reply, parameters); error = NULL; if (!g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error)) { g_warning (_("Error sending message: %s"), error->message); g_error_free (error); } g_object_unref (reply); out: g_object_unref (invocation); }
static void g_dbus_method_invocation_return_value_internal (GDBusMethodInvocation *invocation, GVariant *parameters, GUnixFDList *fd_list) { GDBusMessage *reply; GError *error; g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation)); g_return_if_fail ((parameters == NULL) || g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE)); if (parameters == NULL) parameters = g_variant_new_tuple (NULL, 0); /* if we have introspection data, check that the signature of @parameters is correct */ if (invocation->method_info != NULL) { GVariantType *type; type = _g_dbus_compute_complete_signature (invocation->method_info->out_args); if (!g_variant_is_of_type (parameters, type)) { gchar *type_string = g_variant_type_dup_string (type); g_warning ("Type of return value is incorrect: expected '%s', got '%s''", type_string, g_variant_get_type_string (parameters)); g_variant_type_free (type); g_free (type_string); goto out; } g_variant_type_free (type); } /* property_info is only non-NULL if set that way from * GDBusConnection, so this must be the case of async property * handling on either 'Get', 'Set' or 'GetAll'. */ if (invocation->property_info != NULL) { if (g_str_equal (invocation->method_name, "Get")) { GVariant *nested; if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(v)"))) { g_warning ("Type of return value for property 'Get' call should be '(v)' but got '%s'", g_variant_get_type_string (parameters)); goto out; } /* Go deeper and make sure that the value inside of the * variant matches the property type. */ g_variant_get (parameters, "(v)", &nested); if (!g_str_equal (g_variant_get_type_string (nested), invocation->property_info->signature)) { g_warning ("Value returned from property 'Get' call for '%s' should be '%s' but is '%s'", invocation->property_info->name, invocation->property_info->signature, g_variant_get_type_string (nested)); g_variant_unref (nested); goto out; } g_variant_unref (nested); } else if (g_str_equal (invocation->method_name, "GetAll")) { if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) { g_warning ("Type of return value for property 'GetAll' call should be '(a{sv})' but got '%s'", g_variant_get_type_string (parameters)); goto out; } /* Could iterate the list of properties and make sure that all * of them are actually on the interface and with the correct * types, but let's not do that for now... */ } else if (g_str_equal (invocation->method_name, "Set")) { if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE_UNIT)) { g_warning ("Type of return value for property 'Set' call should be '()' but got '%s'", g_variant_get_type_string (parameters)); goto out; } } else g_assert_not_reached (); } if (G_UNLIKELY (_g_dbus_debug_return ())) { _g_dbus_debug_print_lock (); g_print ("========================================================================\n" "GDBus-debug:Return:\n" " >>>> METHOD RETURN\n" " in response to %s.%s()\n" " on object %s\n" " to name %s\n" " reply-serial %d\n", invocation->interface_name, invocation->method_name, invocation->object_path, invocation->sender, g_dbus_message_get_serial (invocation->message)); _g_dbus_debug_print_unlock (); } reply = g_dbus_message_new_method_reply (invocation->message); g_dbus_message_set_body (reply, parameters); #ifdef G_OS_UNIX if (fd_list != NULL) g_dbus_message_set_unix_fd_list (reply, fd_list); #endif error = NULL; if (!g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error)) { g_warning ("Error sending message: %s", error->message); g_error_free (error); } g_object_unref (reply); out: g_object_unref (invocation); }
static void setup_dialog_load_config (SetupDialog *dialog) { GVariant *values; GdkColor defcol; GtkCellRenderer *renderer; values = ibus_config_get_values (dialog->config, dialog->section); /* ibus_config_get_values may return NULL on failure */ if (values == NULL) { GVariantType *child_type = g_variant_type_new ("{sv}"); values = g_variant_new_array (child_type, NULL, 0); g_variant_type_free (child_type); } /* General -> Pre-edit Appearance */ /* foreground color of pre-edit buffer */ _gdk_color_from_uint (PREEDIT_FOREGROUND, &defcol); load_color (values, GTK_TOGGLE_BUTTON (dialog->checkbutton_foreground), GTK_COLOR_BUTTON (dialog->colorbutton_foreground), "preedit_foreground", &defcol); g_signal_connect (dialog->checkbutton_foreground, "toggled", G_CALLBACK (on_foreground_toggled), dialog); /* background color of pre-edit buffer */ _gdk_color_from_uint (PREEDIT_BACKGROUND, &defcol); load_color (values, GTK_TOGGLE_BUTTON (dialog->checkbutton_background), GTK_COLOR_BUTTON (dialog->colorbutton_background), "preedit_background", &defcol); g_signal_connect (dialog->checkbutton_background, "toggled", G_CALLBACK (on_background_toggled), dialog); /* underline of pre-edit buffer */ load_choice (values, GTK_COMBO_BOX (dialog->combobox_underline), "preedit_underline", IBUS_ATTR_UNDERLINE_NONE); /* General -> Other */ /* lookup table orientation */ load_choice (values, GTK_COMBO_BOX (dialog->combobox_orientation), "lookup_table_orientation", IBUS_ORIENTATION_SYSTEM); /* Advanced -> m17n-lib configuration */ dialog->store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); insert_m17n_items (dialog->store, dialog->lang, dialog->name); gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview), GTK_TREE_MODEL (dialog->store)); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (dialog->treeview), -1, "Key", renderer, "text", COLUMN_KEY, NULL); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (dialog->treeview), -1, "Value", renderer, "text", COLUMN_VALUE, NULL); g_object_set (renderer, "editable", TRUE, NULL); g_signal_connect (renderer, "edited", G_CALLBACK (on_edited), dialog); g_signal_connect (dialog->treeview, "query-tooltip", G_CALLBACK (on_query_tooltip), NULL); g_variant_unref (values); }