static void add_connection (pam_handle_t *pamh, DBusGProxy *proxy, const char *con_name, const char *con_identity, const char *con_pwd) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSetting8021x *s_8021x; NMSettingIP4Config *s_ip4; char *uuid, *new_con_path = NULL; GHashTable *hash; GError *error = NULL; /* Create a new connection object */ if (debug) { pam_syslog (pamh, LOG_INFO, "Creating new connection object."); } connection = (NMConnection *) nm_connection_new (); /* Build up the 'connection' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the 'connection' setting."); } s_con = (NMSettingConnection *) nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_ID, con_name, NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); /* Build up the 'wired' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the 'wired' setting."); } s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* Build up the '8021x' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the '8021x' setting."); } s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); g_object_set (G_OBJECT (s_8021x), NM_SETTING_802_1X_SYSTEM_CA_CERTS, TRUE, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS, TRUE, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, "*****@*****.**", NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS, TRUE, NM_SETTING_802_1X_IDENTITY, con_identity, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NM_SETTING_802_1X_PASSWORD, con_pwd, NULL); nm_setting_802_1x_add_phase2_altsubject_match(s_8021x, "DNS:radius.example.com"); nm_setting_802_1x_add_eap_method(s_8021x, "peap"); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); /* Build up the 'ipv4' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the 'ipv4' setting."); } s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); /* Call AddConnection with the hash as argument */ if (debug) { pam_syslog (pamh, LOG_INFO, "Calling AddConnection D-BUS method."); } if (!dbus_g_proxy_call (proxy, "AddConnection", &error, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &new_con_path, G_TYPE_INVALID)) { g_print ("Error adding connection: %s %s", dbus_g_error_get_name (error), error->message); pam_syslog (pamh, LOG_ERR, "Error adding connection: %s %s", dbus_g_error_get_name (error), error->message); g_clear_error (&error); } else { g_print ("Added: %s\n", new_con_path); pam_syslog (pamh, LOG_ERR, "Added: %s\n", new_con_path); g_free (new_con_path); } g_hash_table_destroy (hash); g_object_unref (connection); }
void getSongInfos(void) { GHashTable *data_list = NULL; GValue *value; const gchar *data; if(dbus_g_proxy_call (dbus_proxy_shell, "getSongProperties", NULL, G_TYPE_STRING, musicData.playing_uri, G_TYPE_INVALID, dbus_g_type_get_map("GHashTable",G_TYPE_STRING, G_TYPE_VALUE), &data_list, G_TYPE_INVALID)) { g_free (musicData.playing_artist); value = (GValue *) g_hash_table_lookup(data_list, "artist"); if (value != NULL && G_VALUE_HOLDS_STRING(value)) musicData.playing_artist = g_strdup (g_value_get_string(value)); else musicData.playing_artist = NULL; cid_message (" playing_artist <- %s\n", musicData.playing_artist); g_free (musicData.playing_album); value = (GValue *) g_hash_table_lookup(data_list, "album"); if (value != NULL && G_VALUE_HOLDS_STRING(value)) musicData.playing_album = g_strdup (g_value_get_string(value)); else musicData.playing_album = NULL; cid_message (" playing_album <- %s\n", musicData.playing_album); g_free (musicData.playing_title); value = (GValue *) g_hash_table_lookup(data_list, "title"); if (value != NULL && G_VALUE_HOLDS_STRING(value)) musicData.playing_title = g_strdup (g_value_get_string(value)); else musicData.playing_title = NULL; cid_message (" playing_title <- %s\n", musicData.playing_title); value = (GValue *) g_hash_table_lookup(data_list, "track-number"); if (value != NULL && G_VALUE_HOLDS_UINT(value)) musicData.playing_track = g_value_get_uint(value); else musicData.playing_track = 0; cid_message (" playing_track <- %d\n", musicData.playing_track); value = (GValue *) g_hash_table_lookup(data_list, "duration"); if (value != NULL && G_VALUE_HOLDS_UINT(value)) musicData.playing_duration = g_value_get_uint(value); else musicData.playing_duration = 0; cid_message (" playing_duration <- %ds\n", musicData.playing_duration); value = (GValue *) g_hash_table_lookup(data_list, "rb:coverArt-uri"); g_free (musicData.playing_cover); if (value != NULL && G_VALUE_HOLDS_STRING(value)) { GError *erreur = NULL; const gchar *cString = g_value_get_string(value); if (cString != NULL && strncmp (cString, "file://", 7) == 0) { musicData.playing_cover = g_filename_from_uri (cString, NULL, &erreur); if (erreur != NULL) { cid_warning ("Attention : %s\n", erreur->message); g_error_free (erreur); } } else { musicData.playing_cover = g_strdup (cString); } } else { CidDataTable *p_tabFiles = cid_create_datatable(G_TYPE_STRING,"cover","album","albumart", ".folder",".cover","folder","Cover","Folder", G_TYPE_INVALID); gchar *cSongPath = g_filename_from_uri (musicData.playing_uri, NULL, NULL); // on teste d'abord dans le repertoire de la chanson. if (cSongPath != NULL) { gchar *cSongDir = g_path_get_dirname (cSongPath); g_free (cSongPath); musicData.playing_cover = g_strdup_printf ("%s/%s - %s.jpg", cSongDir, musicData.playing_artist, musicData.playing_album); cid_debug (" test de %s\n", musicData.playing_cover); BEGIN_FOREACH_DT(p_tabFiles) if (g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS)) break; g_free (musicData.playing_cover); musicData.playing_cover = g_strdup_printf ("%s/%s.jpg", cSongDir, p_temp->content->string); cid_debug (" test de %s\n", musicData.playing_cover); END_FOREACH_DT if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS)) { cid_debug (" test de %s (.gnome2)\n", musicData.playing_cover); g_free (musicData.playing_cover); musicData.playing_cover = g_strdup_printf("%s/.gnome2/rhythmbox/covers/%s - %s.jpg", g_getenv("HOME"),musicData.playing_artist, musicData.playing_album); } if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS)) { cid_debug (" test de %s (.cache)\n", musicData.playing_cover); g_free (musicData.playing_cover); musicData.playing_cover = g_strdup_printf("%s/.cache/rhythmbox/covers/%s - %s.jpg", g_getenv("HOME"),musicData.playing_artist, musicData.playing_album); } g_free (cSongDir); if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS)) { cid->runtime->iCheckIter = 0; if (musicData.iSidCheckCover == 0 && cid->config->iPlayer != PLAYER_NONE) { cid_debug ("l'image n'existe pas encore => on boucle.\n"); musicData.iSidCheckCover = g_timeout_add (1 SECONDES, (GSourceFunc) _check_cover_is_present, (gpointer) NULL); } } } }
int main (int argc, char *argv[]) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; gboolean images = FALSE; gboolean thisvp = FALSE; gboolean mini_only = FALSE; usleep (200000); g_type_init (); GOptionContext *context; GOptionEntry entries[] = { { "images", 'i', 0, G_OPTION_ARG_NONE, &images, "Use IMAGES in the windowlist", NULL }, { "minimized", 'm', 0, G_OPTION_ARG_NONE, &mini_only, "Show only MINIMIZED windows in the windowlist", NULL }, { "current-viewport", 'c', 0, G_OPTION_ARG_NONE, &thisvp, "Show only windows in CURRENT VIEWPORT in the windowlist", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_summary (context, "Calls the daemon to display just a windowlist"); error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { g_printerr ("Failed to open connection to bus: %s\n", error->message); g_error_free (error); return 1; } proxy = dbus_g_proxy_new_for_name (connection, DESKMENU_SERVICE_DBUS, DESKMENU_PATH_DBUS, DESKMENU_INTERFACE_DBUS); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s", error->message); g_error_free (error); return 1; } if (!dbus_g_proxy_call (proxy, "windowlist", &error, G_TYPE_BOOLEAN, images, G_TYPE_BOOLEAN, thisvp, G_TYPE_BOOLEAN, mini_only, G_TYPE_INVALID, G_TYPE_INVALID)) { g_printerr ("Error: %s\n", error->message); g_error_free (error); return 1; } g_option_context_free (context); g_object_unref (proxy); return 0; }
int main (int argc, char *argv[]) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; gchar *icon = NULL; gboolean images = FALSE; gboolean toggle_file = FALSE; gboolean toggle_wrap = FALSE; usleep (200000); g_type_init (); GOptionContext *context; GOptionEntry entries[] = { { "images", 'i', 0, G_OPTION_ARG_NONE, &images, "Use IMAGES in the viewportlist. Change the viewport icon with '-v <ICON>.'", NULL }, { "viewport-icon", 'v', 0, G_OPTION_ARG_STRING, &icon, "Use ICON/FILENAME as the viewport icon.", "ICON" }, { "wrap", 'w', 0, G_OPTION_ARG_NONE, &toggle_wrap, "Turn on viewport wrap navigation", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_summary (context, "Calls the daemon to display just a viewportlist"); error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { g_printerr ("Failed to open connection to bus: %s\n", error->message); g_error_free (error); return 1; } proxy = dbus_g_proxy_new_for_name (connection, DESKMENU_SERVICE_DBUS, DESKMENU_PATH_DBUS, DESKMENU_INTERFACE_DBUS); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s", error->message); g_error_free (error); return 1; } if (images) { if (icon) { toggle_file = g_regex_match_simple ("/", icon, 0, 0); } else { icon = "user-desktop"; } } if (!dbus_g_proxy_call (proxy, "vplist", &error, G_TYPE_BOOLEAN, toggle_wrap, G_TYPE_BOOLEAN, images, G_TYPE_BOOLEAN, toggle_file, G_TYPE_STRING, icon, G_TYPE_INVALID, G_TYPE_INVALID)) { g_printerr ("Error: %s\n", error->message); g_error_free (error); return 1; } g_option_context_free (context); g_object_unref (proxy); return 0; }
static gboolean __bt_request_callback(DBusGMethodInvocation *context, DBusGProxy *transfer, gpointer user_data) { GValue *value; const char *transfer_name; const char *file_name; int size; int result = BLUETOOTH_ERROR_NONE; GHashTable *hash = NULL; GError *error; if (sending_info == NULL || sending_info->is_canceled == TRUE) { result = BLUETOOTH_ERROR_CANCEL_BY_USER; goto canceled; } dbus_g_method_return(context, ""); __bt_free_transfer_info(sending_info->transfer_info); sending_info->transfer_info = g_malloc0(sizeof(bt_transfer_info_t)); sending_info->transfer_info->proxy = g_object_ref(transfer); dbus_g_proxy_call(transfer, "GetProperties", NULL, G_TYPE_INVALID, dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &hash, G_TYPE_INVALID); if (hash == NULL) goto fail; value = g_hash_table_lookup(hash, "Name"); transfer_name = value ? g_value_get_string(value) : NULL; value = g_hash_table_lookup(hash, "Filename"); file_name = value ? g_value_get_string(value) : NULL; value = g_hash_table_lookup(hash, "Size"); size = value ? g_value_get_uint64(value) : 0; sending_info->transfer_info->transfer_name = g_strdup(transfer_name); sending_info->transfer_info->file_name = g_strdup(file_name); sending_info->transfer_info->size = size; sending_info->result = BLUETOOTH_ERROR_NONE; g_hash_table_destroy(hash); _bt_send_event(BT_OPP_CLIENT_EVENT, BLUETOOTH_EVENT_OPC_TRANSFER_STARTED, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &sending_info->transfer_info->file_name, DBUS_TYPE_UINT64, &sending_info->transfer_info->size, DBUS_TYPE_INT32, &sending_info->request_id, DBUS_TYPE_INVALID); return TRUE; canceled: error = g_error_new(__bt_opc_error_quark(), BT_OBEX_AGENT_ERROR_CANCEL, "CancelledByUser"); dbus_g_method_return_error(context, error); g_error_free(error); return FALSE; fail: result = BLUETOOTH_ERROR_INTERNAL; /* Send the event in only error none case */ _bt_send_event(BT_OPP_CLIENT_EVENT, BLUETOOTH_EVENT_OPC_DISCONNECTED, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &sending_info->address, DBUS_TYPE_INT32, &sending_info->request_id, DBUS_TYPE_INVALID); __bt_free_sending_info(sending_info); sending_info = NULL; __bt_opp_client_agent_deinit(); return TRUE; }
static void add_pidgin_contacts_to_model (GtkTreeStore *store, GtkTreeIter *iter, GtkTreeIter *parent) { GError *error; GArray *contacts_list; GArray *accounts; int i, j; GdkPixbuf *icon; GHashTableIter hiter; GPtrArray *contacts_group; ContactData *dat; GValue val = {0,}; if(proxy == NULL) return; error = NULL; if (!dbus_g_proxy_call (proxy, "PurpleAccountsGetAllActive", &error, G_TYPE_INVALID, DBUS_TYPE_G_INT_ARRAY, &accounts, G_TYPE_INVALID)) { handle_dbus_exception(error); return; } contact_hash = g_hash_table_new (g_str_hash, g_str_equal); for(i = 0; i < accounts->len; i++) { int account = g_array_index(accounts, int, i); error = NULL; if (!dbus_g_proxy_call (proxy, "PurpleFindBuddies", &error, G_TYPE_INT, account, G_TYPE_STRING, NULL, G_TYPE_INVALID, DBUS_TYPE_G_INT_ARRAY, &contacts_list, G_TYPE_INVALID)) { handle_dbus_exception(error); continue; } for(j = 0; j < contacts_list->len ; j++) { int id = g_array_index(contacts_list, int, j); int online; error = NULL; if (!dbus_g_proxy_call (proxy, "PurpleBuddyIsOnline", &error, G_TYPE_INT, id, G_TYPE_INVALID, G_TYPE_INT, &online, G_TYPE_INVALID)) { handle_dbus_exception(error); continue; } if (!online) continue; dat = g_new0 (ContactData, 1); dat->account = account; dat->id = id; error = NULL; if (!dbus_g_proxy_call (proxy, "PurpleBuddyGetName", &error, G_TYPE_INT, id, G_TYPE_INVALID, G_TYPE_STRING, &dat->name, G_TYPE_INVALID)) { handle_dbus_exception(error); g_free(dat); continue; } if (!dbus_g_proxy_call (proxy, "PurpleBuddyGetAlias", &error, G_TYPE_INT, id, G_TYPE_INVALID, G_TYPE_STRING, &dat->alias, G_TYPE_INVALID)) { handle_dbus_exception(error); } contacts_group = g_hash_table_lookup (contact_hash, dat->alias); if (contacts_group == NULL){ GPtrArray *new_group = g_ptr_array_new (); g_ptr_array_add (new_group, dat); g_hash_table_insert (contact_hash, dat->alias, new_group); } else { g_ptr_array_add (contacts_group, dat); } } g_array_free(contacts_list, TRUE); } g_array_free (accounts, TRUE); g_hash_table_iter_init (&hiter, contact_hash); while (g_hash_table_iter_next (&hiter, NULL, (gpointer)&contacts_group)) { gint accounts; dat = g_ptr_array_index (contacts_group, 0); accounts = contacts_group->len; gtk_tree_store_append (store, parent, NULL); gtk_tree_store_set (store, parent, COL_ICON, NULL, COL_ALIAS, dat->alias, -1); gint i; for (i = 0; i < accounts; ++i) { dat = g_ptr_array_index (contacts_group, i); icon = get_buddy_icon(dat->id); if (accounts == 1) { g_value_init(&val, GDK_TYPE_PIXBUF); g_value_set_object (&val, (gpointer)icon); gtk_tree_store_set_value (store, parent, COL_ICON, &val); g_value_unset (&val); break; } gtk_tree_store_append (store, iter, parent); gtk_tree_store_set (store, iter, COL_ICON, icon, COL_ALIAS, dat->alias, -1); } } }
static void get_active_connection_details (DBusGConnection *bus, const char *obj_path) { DBusGProxy *props_proxy; GValue path_value = { 0 }; GValue serv_value = { 0 }; GError *error = NULL; const char *path = NULL, *service = NULL; /* This function gets the backing Connection object that describes the * network configuration that the ActiveConnection object is actually using. * The ActiveConnection object contains the mapping between the configuration * and the actual network interfaces that are using that configuration. */ /* Create a D-Bus object proxy for the active connection object's properties */ props_proxy = dbus_g_proxy_new_for_name (bus, NM_DBUS_SERVICE, obj_path, DBUS_INTERFACE_PROPERTIES); g_assert (props_proxy); /* Get the object path of the Connection details */ if (!dbus_g_proxy_call (props_proxy, "Get", &error, G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION, G_TYPE_STRING, "Connection", G_TYPE_INVALID, G_TYPE_VALUE, &path_value, G_TYPE_INVALID)) { g_warning ("Failed to get active connection Connection property: %s", error->message); g_error_free (error); goto out; } if (!G_VALUE_HOLDS (&path_value, DBUS_TYPE_G_OBJECT_PATH)) { g_warning ("Unexpected type returned getting Connection property: %s", G_VALUE_TYPE_NAME (&path_value)); goto out; } path = g_value_get_boxed (&path_value); if (!path) { g_warning ("Missing connection path!"); goto out; } /* Get the service name of the D-Bus service that provides the Connection */ if (!dbus_g_proxy_call (props_proxy, "Get", &error, G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION, G_TYPE_STRING, "ServiceName", G_TYPE_INVALID, G_TYPE_VALUE, &serv_value, G_TYPE_INVALID)) { g_warning ("Failed to get active connection ServiceName property: %s", error->message); g_error_free (error); goto out; } if (!G_VALUE_HOLDS (&serv_value, G_TYPE_STRING)) { g_warning ("Unexpected type returned getting Connection property: %s", G_VALUE_TYPE_NAME (&serv_value)); goto out; } service = g_value_get_string (&serv_value); if (!service) { g_warning ("Missing connection service name!"); goto out; } /* Print out the actual connection details */ print_connection (bus, service, path); out: g_value_unset (&path_value); g_value_unset (&serv_value); g_object_unref (props_proxy); }
/** * * Method GetData on /org/freedesktop/DeviceKit/Power/Wakeups * * <method name="GetData"> * <arg name="data" type="a(budss)" direction="out"/> (1) * </method> * (1): array | boolean Wheter the proceess on userspace * | uint PID * | double Wakeups value * | string command line * | string details **/ static void xfpm_info_update_wakeups (XfpmInfo *info) { GtkListStore *store; GError *error = NULL; static GType collection_type = G_TYPE_INVALID; static GType struct_type = G_TYPE_INVALID; GPtrArray *array = NULL; gboolean ret; guint i; if ( G_UNLIKELY (collection_type == G_TYPE_INVALID ) ) { struct_type = dbus_g_type_get_struct ("GValueArray", G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_DOUBLE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); collection_type = dbus_g_type_get_collection ("GPtrArray", struct_type); } ret = dbus_g_proxy_call (info->wakeups_proxy, "GetData", &error, G_TYPE_INVALID, collection_type, &array, NULL); if ( !ret ) { g_warning ("GetData Failed on %s : %s", UPOWER_PATH_WAKEUPS, error->message); g_error_free (error); return; } store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (info->wakeups))); gtk_list_store_clear (GTK_LIST_STORE (store)); for ( i = 0; i < array->len; i++ ) { GValue elem = { 0 }; GtkTreeIter iter; gboolean userspace; guint pid; gdouble value; gchar *cmd; gchar *formatted_cmd; gchar *details; gchar *formatted_details; gchar *pid_str; gchar *value_str; const gchar *icon; g_value_init (&elem, struct_type); g_value_set_static_boxed (&elem, g_ptr_array_index (array, i)); dbus_g_type_struct_get (&elem, 0, &userspace, 1, &pid, 2, &value, 3, &cmd, 4, &details, G_MAXUINT); if ( userspace ) { pid_str = g_strdup_printf ("%i", pid); } else { if ( pid < 0xff0 ) { pid_str = g_strdup_printf ("IRQ%i", pid); } else { pid_str = g_strdup("IRQx"); } } value_str = g_strdup_printf ("%.1f", value); icon = userspace ? "application-x-executable" : "applications-system"; formatted_cmd = gpm_stats_format_cmdline (cmd, userspace); formatted_details = gpm_stats_format_details (details); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_WAKEUPS_TYPE, icon, COL_WAKEUPS_PID, pid_str, COL_WAKEUPS_VALUE, value_str, COL_WAKEUPS_CMD, formatted_cmd, COL_WAKEUPS_DETAILS, formatted_details, -1); g_free (cmd); g_free (details); g_free (formatted_cmd); g_free (formatted_details); g_value_unset (&elem); } g_ptr_array_free (array, TRUE); }
static gboolean acquire_name_on_proxy (DBusGProxy *bus_proxy, const char *name) { GError *error; guint result; gboolean res; gboolean ret; ret = FALSE; if (bus_proxy == NULL) { goto out; } error = NULL; res = dbus_g_proxy_call (bus_proxy, "RequestName", &error, G_TYPE_STRING, name, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID); if (! res) { if (error != NULL) { g_warning ("Failed to acquire %s: %s", name, error->message); g_error_free (error); } else { g_warning ("Failed to acquire %s", name); } goto out; } if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { if (error != NULL) { g_warning ("Failed to acquire %s: %s", name, error->message); g_error_free (error); } else { g_warning ("Failed to acquire %s", name); } goto out; } /* register for name lost */ dbus_g_proxy_add_signal (bus_proxy, "NameLost", G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (bus_proxy, "NameLost", G_CALLBACK (on_bus_name_lost), NULL, NULL); ret = TRUE; out: return ret; }
int main (int argc, char **argv) { DBusGConnection *connection; DBusGProxy *remote_object; GMainLoop *mainloop; gchar *path; GError *error = NULL; g_type_init (); connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { write_error ("Couldn't connect to session bus", &error); return EXIT_FAILURE; } remote_object = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE, DBUS_REMOTE, DBUS_REMOTE_CONNECTION_INTERFACE); if (!dbus_g_proxy_call (remote_object, "Connect", &error, G_TYPE_STRING, argv[0], G_TYPE_STRING, "example", G_TYPE_STRING, "Example of a D-Bus client", G_TYPE_STRING, "1.0", G_TYPE_INVALID, G_TYPE_STRING, &path, G_TYPE_INVALID)) { write_error ("Failed to complete Connect", &error); return EXIT_FAILURE; } g_object_unref (remote_object); remote_object = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE, path, DBUS_REMOTE_PLUGIN_INTERFACE); g_free (path); if (!dbus_g_proxy_call (remote_object, "HookCommand", &error, G_TYPE_STRING, "test", G_TYPE_INT, 0, G_TYPE_STRING, "Simple D-BUS example", G_TYPE_INT, 1, G_TYPE_INVALID, G_TYPE_UINT, &command_id, G_TYPE_INVALID)) { write_error ("Failed to complete HookCommand", &error); return EXIT_FAILURE; } g_print ("Command hook id=%d\n", command_id); if (!dbus_g_proxy_call (remote_object, "HookServer", &error, G_TYPE_STRING, "RAW LINE", G_TYPE_INT, 0, G_TYPE_INT, 0, G_TYPE_INVALID, G_TYPE_UINT, &server_id, G_TYPE_INVALID)) { write_error ("Failed to complete HookServer", &error); return EXIT_FAILURE; } g_print ("Server hook id=%d\n", server_id); dbus_g_object_register_marshaller ( g_cclosure_user_marshal_VOID__POINTER_POINTER_UINT_UINT, G_TYPE_NONE, G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); dbus_g_object_register_marshaller ( g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, G_TYPE_INVALID); dbus_g_proxy_add_signal (remote_object, "CommandSignal", G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (remote_object, "CommandSignal", G_CALLBACK (test_command_cb), NULL, NULL); dbus_g_proxy_add_signal (remote_object, "ServerSignal", G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (remote_object, "ServerSignal", G_CALLBACK (test_server_cb), NULL, NULL); dbus_g_proxy_add_signal (remote_object, "UnloadSignal", G_TYPE_INVALID); dbus_g_proxy_connect_signal (remote_object, "UnloadSignal", G_CALLBACK (unload_cb), NULL, NULL); /* Now you can write on the HexChat windows: "/test arg1 arg2 ..." */ mainloop = g_main_loop_new (NULL, FALSE); g_main_loop_run (mainloop); return EXIT_SUCCESS; }
static gboolean try_existing_instance (DBusGConnection *bus, DBusGProxy *proxy, const char *type, gboolean create, gboolean show, const char *uuid) { gboolean has_owner = FALSE; DBusGProxy *instance; GHashTable *args; GValue type_value = { 0, }; GValue create_value = { 0, }; GValue show_value = { 0, }; GValue uuid_value = { 0, }; gboolean success = FALSE; GError *error = NULL; if (!dbus_g_proxy_call (proxy, "NameHasOwner", NULL, G_TYPE_STRING, NM_CE_DBUS_SERVICE_NAME, G_TYPE_INVALID, G_TYPE_BOOLEAN, &has_owner, G_TYPE_INVALID)) return FALSE; if (!has_owner) return FALSE; /* Send arguments to existing process */ instance = dbus_g_proxy_new_for_name (bus, NM_CE_DBUS_SERVICE_NAME, "/", NM_CE_DBUS_SERVICE_NAME); if (!instance) return FALSE; args = g_hash_table_new (g_str_hash, g_str_equal); if (type) { g_value_init (&type_value, G_TYPE_STRING); g_value_set_static_string (&type_value, type); g_hash_table_insert (args, ARG_TYPE, &type_value); } if (create) { g_value_init (&create_value, G_TYPE_BOOLEAN); g_value_set_boolean (&create_value, TRUE); g_hash_table_insert (args, ARG_CREATE, &create_value); } if (show) { g_value_init (&show_value, G_TYPE_BOOLEAN); g_value_set_boolean (&show_value, TRUE); g_hash_table_insert (args, ARG_SHOW, &show_value); } if (uuid) { g_value_init (&uuid_value, G_TYPE_BOOLEAN); g_value_set_static_string (&uuid_value, uuid); g_hash_table_insert (args, ARG_UUID, &uuid_value); } if (dbus_g_proxy_call (instance, "Start", &error, DBUS_TYPE_G_MAP_OF_VARIANT, args, G_TYPE_INVALID, G_TYPE_INVALID)) success = TRUE; else g_warning ("%s: error calling start: %s", __func__, error->message); g_hash_table_destroy (args); g_object_unref (instance); return success; }
int main(int argc, char **argv) { DBusGConnection *bus = NULL; DBusGProxy *bus_proxy = NULL; GError *error = NULL; guint request_name_result = 0; WatchdogService *wservice = NULL; GOptionContext *lOptContext = NULL; int ret = 0; int log = LOG_MASK (LOG_ERR) | LOG_MASK (LOG_INFO); #ifdef DEBUG log = log | LOG_MASK(LOG_DEBUG); #endif openlog ("HM-WATCHDOG", 0x0, LOG_USER); setlogmask(log); g_type_init (); mainloop = g_main_loop_new(NULL, FALSE); lOptContext = g_option_context_new("- Wind River - System Health Monitor Watchdog"); g_option_context_add_main_entries(lOptContext, gOptEntries, NULL); g_option_context_parse(lOptContext, &argc, &argv, NULL); g_option_context_free(lOptContext); bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (!bus) { log_error_message("could not connect to session bus\n", 0); if(error) g_error_free(error); ret = 1; goto res_free; } wservice = w_dbus_register_object(bus, WATCHDOG_TYPE_OBJECT, &dbus_glib_watchdog_service_object_info, WATCHDOG_SERVICE_PATH); bus_proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); #if 0 if (!org_freedesktop_DBus_request_name(driver_proxy, WATCHDOG_SERVICE, 0, &request_name_result, &error)) { g_assert (error != NULL); log_error_message ("failed to get name: %s\n", error->message); g_clear_error (&error); exit (1); } #else if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error, G_TYPE_STRING, WATCHDOG_SERVICE, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { log_error_message("failed to acquire %s\n", WATCHDOG_SERVICE); ret = 1; goto res_free; } #endif g_timeout_add_seconds(TIMEOUT_INTERVAL, w_timeout, wservice); /* signal handlig */ signal(SIGINT, signalHandler); signal(SIGQUIT, signalHandler); signal(SIGABRT, signalHandler); signal(SIGTERM, signalHandler); /* Daemonize if it's the case */ if(gOptDaemonize) daemonize(); log_message("service started\n", 0); g_main_loop_run(mainloop); res_free: if(mainloop) g_main_loop_unref(mainloop); if(wservice) w_dbus_unregister_object(wservice, bus_proxy, bus); if(bus_proxy) g_object_unref(bus_proxy); log_message("watchdog service stopped\n", 0); closelog (); return ret; }
/** * nm_device_new: * @connection: the #DBusGConnection * @path: the DBus object path of the device * * Creates a new #NMDevice. * * Returns: a new device **/ GObject * nm_device_new (DBusGConnection *connection, const char *path) { DBusGProxy *proxy; GError *err = NULL; GValue value = {0,}; GType dtype = 0; NMDevice *device = NULL; g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (path != NULL, NULL); proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, "org.freedesktop.DBus.Properties"); if (!proxy) { g_warning ("%s: couldn't create D-Bus object proxy.", __func__); return NULL; } if (!dbus_g_proxy_call (proxy, "Get", &err, G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE, G_TYPE_STRING, "DeviceType", G_TYPE_INVALID, G_TYPE_VALUE, &value, G_TYPE_INVALID)) { g_warning ("Error in get_property: %s\n", err->message); g_error_free (err); goto out; } switch (g_value_get_uint (&value)) { case NM_DEVICE_TYPE_ETHERNET: dtype = NM_TYPE_DEVICE_ETHERNET; break; case NM_DEVICE_TYPE_WIFI: dtype = NM_TYPE_DEVICE_WIFI; break; case NM_DEVICE_TYPE_GSM: dtype = NM_TYPE_GSM_DEVICE; break; case NM_DEVICE_TYPE_CDMA: dtype = NM_TYPE_CDMA_DEVICE; break; case NM_DEVICE_TYPE_BT: dtype = NM_TYPE_DEVICE_BT; break; default: g_warning ("Unknown device type %d", g_value_get_uint (&value)); break; } if (dtype) { device = (NMDevice *) g_object_new (dtype, NM_OBJECT_DBUS_CONNECTION, connection, NM_OBJECT_DBUS_PATH, path, NULL); } out: g_object_unref (proxy); return G_OBJECT (device); }
static gboolean impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error) { TotemMediaPlayerKeysPlugin *pi = TOTEM_MEDIA_PLAYER_KEYS_PLUGIN (plugin); DBusGConnection *connection; GError *err = NULL; GtkWindow *window; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err); if (connection == NULL) { g_warning ("Error connecting to D-Bus: %s", err->message); return FALSE; } /* Try the mate-settings-daemon version, * then the mate-control-center version of things */ pi->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection, "org.mate.SettingsDaemon", "/org/mate/SettingsDaemon/MediaKeys", "org.mate.SettingsDaemon.MediaKeys", NULL); if (pi->media_player_keys_proxy == NULL) { pi->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection, "org.mate.SettingsDaemon", "/org/mate/SettingsDaemon", "org.mate.SettingsDaemon", &err); } dbus_g_connection_unref (connection); if (err != NULL) { gboolean daemon_not_running; g_warning ("Failed to create dbus proxy for org.mate.SettingsDaemon: %s", err->message); daemon_not_running = (err->code == DBUS_GERROR_NAME_HAS_NO_OWNER); g_error_free (err); /* don't popup error if settings-daemon is not running, * ie when starting totem not under MATE desktop */ return daemon_not_running; } else { g_signal_connect_object (pi->media_player_keys_proxy, "destroy", G_CALLBACK (proxy_destroy), pi, 0); } dbus_g_proxy_call (pi->media_player_keys_proxy, "GrabMediaPlayerKeys", NULL, G_TYPE_STRING, "Totem", G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_INVALID); dbus_g_object_register_marshaller (totem_marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (pi->media_player_keys_proxy, "MediaPlayerKeyPressed", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (pi->media_player_keys_proxy, "MediaPlayerKeyPressed", G_CALLBACK (on_media_player_key_pressed), totem, NULL); window = totem_get_main_window (totem); pi->handler_id = g_signal_connect (G_OBJECT (window), "focus-in-event", G_CALLBACK (on_window_focus_in_event), pi); g_object_unref (G_OBJECT (window)); return TRUE; }
static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { BMObject *object; DBusGConnection *connection; BMClientPrivate *priv; GError *err = NULL; object = (BMObject *) G_OBJECT_CLASS (bm_client_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = BM_CLIENT_GET_PRIVATE (object); connection = bm_object_get_connection (object); priv->client_proxy = dbus_g_proxy_new_for_name (connection, BM_DBUS_SERVICE, bm_object_get_path (object), BM_DBUS_INTERFACE); register_for_property_changed (BM_CLIENT (object)); dbus_g_proxy_add_signal (priv->client_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->client_proxy, "DeviceAdded", G_CALLBACK (client_device_added_proxy), object, NULL); dbus_g_proxy_add_signal (priv->client_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->client_proxy, "DeviceRemoved", G_CALLBACK (client_device_removed_proxy), object, NULL); /* Permissions */ dbus_g_proxy_add_signal (priv->client_proxy, "CheckPermissions", G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->client_proxy, "CheckPermissions", G_CALLBACK (client_recheck_permissions), object, NULL); get_permissions_sync (BM_CLIENT (object)); priv->bus_proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->bus_proxy, "NameOwnerChanged", G_CALLBACK (proxy_name_owner_changed), object, NULL); if (!dbus_g_proxy_call (priv->bus_proxy, "NameHasOwner", &err, G_TYPE_STRING, BM_DBUS_SERVICE, G_TYPE_INVALID, G_TYPE_BOOLEAN, &priv->manager_running, G_TYPE_INVALID)) { g_warning ("Error on NameHasOwner DBUS call: %s", err->message); g_error_free (err); } return G_OBJECT (object); }
static gboolean rhythmbox_next(ThisApplet *applet) { return dbus_g_proxy_call(applet->rhythmbox_player_proxy, "next", NULL, G_TYPE_INVALID, G_TYPE_INVALID); }
/* Recupere les infos de la chanson courante, y compris le chemin de la couverture (la telecharge au besoin). */ static void cd_rhythmbox_getSongInfos (gboolean bGetAll) { GHashTable *data_list = NULL; GValue *value; const gchar *data; if(dbus_g_proxy_call (myData.dbus_proxy_shell, "getSongProperties", NULL, G_TYPE_STRING, myData.cPlayingUri, G_TYPE_INVALID, MP_DBUS_TYPE_SONG_METADATA, &data_list, G_TYPE_INVALID)) { if (bGetAll) { g_free (myData.cArtist); value = (GValue *) g_hash_table_lookup(data_list, "artist"); if (value != NULL && G_VALUE_HOLDS_STRING(value)) myData.cArtist = g_strdup (g_value_get_string(value)); else myData.cArtist = NULL; cd_message (" cArtist <- %s", myData.cArtist); g_free (myData.cAlbum); value = (GValue *) g_hash_table_lookup(data_list, "album"); if (value != NULL && G_VALUE_HOLDS_STRING(value)) myData.cAlbum = g_strdup (g_value_get_string(value)); else myData.cAlbum = NULL; cd_message (" cAlbum <- %s", myData.cAlbum); g_free (myData.cTitle); value = (GValue *) g_hash_table_lookup(data_list, "title"); if (value != NULL && G_VALUE_HOLDS_STRING(value)) myData.cTitle = g_strdup (g_value_get_string(value)); else myData.cTitle = NULL; cd_message (" cTitle <- %s", myData.cTitle); value = (GValue *) g_hash_table_lookup(data_list, "track-number"); if (value != NULL && G_VALUE_HOLDS_UINT(value)) myData.iTrackNumber = g_value_get_uint(value); else myData.iTrackNumber = 0; cd_message (" iTrackNumber <- %d", myData.iTrackNumber); value = (GValue *) g_hash_table_lookup(data_list, "duration"); if (value != NULL && G_VALUE_HOLDS_UINT(value)) myData.iSongLength = g_value_get_uint(value); else myData.iSongLength = 0; cd_message (" iSongLength <- %ds", myData.iSongLength); myData.bCoverNeedsTest = FALSE; } const gchar *cString = NULL; value = (GValue *) g_hash_table_lookup(data_list, "rb:coverArt-uri"); if (value != NULL && G_VALUE_HOLDS_STRING(value)) // RB nous donne une adresse, eventuellement distante. cString = g_value_get_string(value); cd_musicplayer_get_cover_path (cString, ! bGetAll); // la 2eme fois on ne recupere que la couverture et donc on cherche aussi en cache. g_print ("MP : cCoverPath <- %s\n", myData.cCoverPath); g_hash_table_destroy (data_list); } else { cd_warning (" can't get song properties"); g_free (myData.cPlayingUri); myData.cPlayingUri = NULL; g_free (myData.cTitle); myData.cTitle = NULL; g_free (myData.cAlbum); myData.cAlbum = NULL; g_free (myData.cCoverPath); myData.cCoverPath = NULL; } }
static gboolean validate_destination (NstPlugin *plugin, GtkWidget *contact_widget, char **error) { #if 0 GError *e = NULL; char *bdaddr, *device_path; DBusGProxy *device; GHashTable *props; GValue *value; gboolean found = FALSE; char **array; gboolean first_time = TRUE; g_return_val_if_fail (error != NULL, FALSE); if (get_select_device (NULL, &bdaddr) == FALSE) { *error = g_strdup (_("Programming error, could not find the device in the list")); return FALSE; } if (dbus_g_proxy_call (object, "FindDevice", NULL, G_TYPE_STRING, bdaddr, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE) { g_free (bdaddr); return TRUE; } device = dbus_g_proxy_new_for_name (conn, "org.bluez", device_path, "org.bluez.Device"); again: if (dbus_g_proxy_call (device, "GetProperties", NULL, G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID) == FALSE) { goto bail; } value = g_hash_table_lookup (props, "UUIDs"); array = g_value_get_boxed (value); if (array != NULL) { char *uuid; guint i; for (i = 0; array[i] != NULL; i++) { if (g_str_has_suffix (array[i], "-0000-1000-8000-00805f9b34fb") != FALSE) { if (g_str_has_prefix (array[i], "0000") != FALSE) { char *tmp; tmp = g_strndup (array[i] + 4, 4); uuid = g_strdup_printf ("0x%s", tmp); g_free (tmp); } else { char *tmp; tmp = g_strndup (array[i], 8); uuid = g_strdup_printf ("0x%s", tmp); } } else { uuid = g_strdup (array[i]); } if (strcmp (uuid, OBEX_FILETRANS_SVCLASS_ID_STR) == 0 || strcmp (uuid, OBEX_PUSH_SVCLASS_ID_STR) == 0 ){ found = TRUE; g_free (uuid); break; } g_free (uuid); } } else { /* No array, can't really check now, can we */ found = TRUE; } g_hash_table_destroy (props); if (found == TRUE || first_time == FALSE) goto bail; first_time = FALSE; /* If no valid service found the first time around, then request services refresh */ if (! dbus_g_proxy_call (device, "DiscoverServices", &e, G_TYPE_STRING, NULL, G_TYPE_INVALID, dbus_g_type_get_map("GHashTable", G_TYPE_UINT, G_TYPE_STRING), &props, G_TYPE_INVALID)) { goto bail; } goto again; bail: g_object_unref (device); if (found == FALSE) *error = g_strdup_printf (_("Obex Push file transfer unsupported")); return found; #endif return TRUE; }
static int add_connection (DBusGProxy *proxy, char *con_name, char *apn, char *pin, char *username, char *password, int ntype, char *number, char *auth, char *comp, char *aut, char *netid, char *enc, int ecoint, int ecofail, char *uuid, int sbits, char sparity, int stbits, int sbaud) { NMConnection *connection; NMSettingConnection *s_con; NMSettingIP4Config *s_ip4; NMSettingGsm *s_gsm; NMSettingPPP *s_ppp; NMSettingSerial *s_serial; char *new_con_path = NULL; GHashTable *hash; GError *error = NULL; int autoconnect = 1; int uuid_generated = 0; if ((aut != NULL) && (aut[0] != 't')) autoconnect = 0; connection = (NMConnection *)nm_connection_new (); if (connection == NULL){ printf("Unable to allocate new connection... Sorry.\n"); return NMC_RESULT_ERROR_CON_ADD; } s_con = (NMSettingConnection *) nm_setting_connection_new (); if (s_con == NULL){ printf("Failed to allocate new %s setting... Sorry.\n",NM_SETTING_CONNECTION_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_con)); if (uuid == NULL){ uuid = nm_utils_uuid_generate (); uuid_generated = 1; } /*global settings*/ g_object_set (s_con, NM_SETTING_CONNECTION_ID, con_name, NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, (autoconnect == 1) ? TRUE : FALSE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME, NULL); if(uuid_generated == 1) g_free (uuid); /* GSM setting */ s_gsm = (NMSettingGsm *) nm_setting_gsm_new (); if (s_gsm == NULL){ printf("Failed to allocate new %s setting...Sorry.\n",NM_SETTING_GSM_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_gsm)); /*Network type Network preference to force the device to only use specific network technologies. The permitted values are: -1: any, 0: 3G only, 1: GPRS/EDGE only, 2: prefer 3G, and 3: prefer 2G, 4: prefer 4G (LTE), 5: 4G (LTE) only. Note that not all devices allow network preference control. */ g_object_set (s_gsm, NM_SETTING_GSM_NUMBER, (number == NULL) ? "*99#" : number, NM_SETTING_GSM_APN, apn, NM_SETTING_GSM_USERNAME, username, NM_SETTING_GSM_PASSWORD, password, NM_SETTING_GSM_PIN, pin, NM_SETTING_GSM_NETWORK_TYPE, ntype, NM_SETTING_GSM_NETWORK_ID, netid, NULL); /* Serial setting */ s_serial = (NMSettingSerial *) nm_setting_serial_new (); if (s_serial == NULL){ printf("Failed to allocate new %s setting...Sorry.\n",NM_SETTING_SERIAL_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_serial)); g_object_set (s_serial, NM_SETTING_SERIAL_BAUD, sbaud, NM_SETTING_SERIAL_BITS, sbits, NM_SETTING_SERIAL_PARITY, sparity, NM_SETTING_SERIAL_STOPBITS, stbits, NULL); /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); if (s_ip4 == NULL){ printf("Failed to allocate new %s setting... Sorry.\n",NM_SETTING_IP4_CONFIG_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* PPP setting */ s_ppp = (NMSettingPPP *) nm_setting_ppp_new (); if (s_ppp == NULL){ printf("Failed to allocate new %s setting... Sorry.\n", NM_SETTING_PPP_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } g_object_set(s_ppp, NM_SETTING_PPP_REFUSE_EAP, (auth[0] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_PAP, (auth[1] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_CHAP, (auth[2] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_MSCHAP, (auth[3] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_MSCHAPV2, (auth[4] == 't') ? FALSE : TRUE, NM_SETTING_PPP_NOBSDCOMP, (comp[0] == 't') ? FALSE : TRUE, NM_SETTING_PPP_NODEFLATE, (comp[1] == 't') ? FALSE : TRUE, NM_SETTING_PPP_NO_VJ_COMP,(comp[2] == 't') ? FALSE : TRUE, //tcp header compression NM_SETTING_PPP_REQUIRE_MPPE, (strcmp(enc, "ff")==0) ? FALSE : TRUE, NM_SETTING_PPP_MPPE_STATEFUL, (enc[1] == 't') ? TRUE : FALSE, NM_SETTING_PPP_REQUIRE_MPPE_128, (enc[0] == 't') ? TRUE : FALSE, NM_SETTING_PPP_LCP_ECHO_FAILURE, (ecofail > 0) ? ecofail : 0, NM_SETTING_PPP_LCP_ECHO_INTERVAL, (ecoint > 0) ? ecoint: 0, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ppp)); hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); /* Call AddConnection with the hash as argument */ if (!dbus_g_proxy_call (proxy, "AddConnection", &error, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &new_con_path, G_TYPE_INVALID)) { g_print ("Error adding connection: %s %s\n", dbus_g_error_get_name (error), error->message); g_clear_error (&error); g_hash_table_destroy (hash); g_object_unref (connection); return NMC_RESULT_ERROR_CON_ADD; } else { g_print ("\n\tConnection added successfully at: %s \n\tUse: nmcli con list id %s - to see connection detailed info \n\tcon delete id %s - to delete connection\n", new_con_path, con_name, con_name); g_print ("\tTo bring connection up use: nmcli con up id %s.\n",con_name); g_print ("\tTo see connection status use: nmcli con status id %s.\n\n",con_name); g_free (new_con_path); } g_hash_table_destroy (hash); g_object_unref (connection); return 0; }
static gboolean register_client (void) { GError *error; gboolean res; const char *startup_id; const char *app_id; startup_id = g_getenv ("DESKTOP_AUTOSTART_ID"); app_id = "gnome-panel"; error = NULL; res = dbus_g_proxy_call (sm_proxy, "RegisterClient", &error, G_TYPE_STRING, app_id, G_TYPE_STRING, startup_id, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &client_id, G_TYPE_INVALID); if (!res) { g_warning ("Failed to register client: %s", error->message); g_error_free (error); return FALSE; } g_debug ("Client registered with session manager: %s", client_id); client_proxy = dbus_g_proxy_new_for_name (bus_connection, SM_DBUS_NAME, client_id, SM_CLIENT_DBUS_INTERFACE); dbus_g_proxy_add_signal (client_proxy, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_add_signal (client_proxy, "EndSession", G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_add_signal (client_proxy, "CancelEndSession", G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_add_signal (client_proxy, "Stop", G_TYPE_INVALID); dbus_g_proxy_connect_signal (client_proxy, "QueryEndSession", G_CALLBACK (on_client_query_end_session), NULL, NULL); dbus_g_proxy_connect_signal (client_proxy, "EndSession", G_CALLBACK (on_client_end_session), NULL, NULL); dbus_g_proxy_connect_signal (client_proxy, "CancelEndSession", G_CALLBACK (on_client_cancel_end_session), NULL, NULL); dbus_g_proxy_connect_signal (client_proxy, "Stop", G_CALLBACK (on_client_stop), NULL, NULL); return TRUE; }
void _dynamic_Get4 (DBusGProxy* self, const char* param1, const char* param2, GValue* param3, GError** error) { dbus_g_proxy_call (self, "Get", error, G_TYPE_STRING, param1, G_TYPE_STRING, param2, G_TYPE_INVALID, G_TYPE_VALUE, param3, G_TYPE_INVALID); if (*error) { return; } }
static GObject * constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { GObject *object; NMVPNPlugin *plugin; NMVPNPluginPrivate *priv; DBusGConnection *connection; DBusGProxy *proxy; guint request_name_result; GError *err = NULL; object = G_OBJECT_CLASS (nm_vpn_plugin_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_VPN_PLUGIN_GET_PRIVATE (object); if (!priv->dbus_service_name) goto err; connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); if (!connection) goto err; proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!dbus_g_proxy_call (proxy, "RequestName", &err, G_TYPE_STRING, priv->dbus_service_name, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { g_object_unref (proxy); goto err; } g_object_unref (proxy); dbus_g_connection_register_g_object (connection, NM_VPN_DBUS_PLUGIN_PATH, object); plugin = NM_VPN_PLUGIN (object); nm_vpn_plugin_set_connection (plugin, connection); nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_INIT); return object; err: if (err) { g_warning ("Failed to initialize VPN plugin: %s", err->message); g_error_free (err); } if (object) g_object_unref (object); return NULL; }
// Setup dbus server static int thd_dbus_server_proc(gboolean no_daemon) { DBusGConnection *bus; DBusGProxy *bus_proxy; GMainLoop *main_loop; GError *error = NULL; guint result; PrefObject *value_obj; thd_engine = NULL; // Initialize the GType/GObject system g_type_init(); // Create a main loop that will dispatch callbacks g_main_loop = main_loop = g_main_loop_new(NULL, FALSE); if (main_loop == NULL) { thd_log_error("Couldn't create GMainLoop:"); return THD_FATAL_ERROR; } if (dbus_enable) { bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (error != NULL) { thd_log_error("Couldn't connect to session bus: %s:", error->message); return THD_FATAL_ERROR; } // Get a bus proxy instance bus_proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (bus_proxy == NULL) { thd_log_error("Failed to get a proxy for D-Bus:"); return THD_FATAL_ERROR; } thd_log_debug("Registering the well-known name (%s)\n", THD_SERVICE_NAME); // register the well-known name if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error, G_TYPE_STRING, THD_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { thd_log_error("D-Bus.RequestName RPC failed: %s\n", error->message); return THD_FATAL_ERROR; } thd_log_debug("RequestName returned %d.\n", result); if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { thd_log_error("Failed to get the primary well-known name:"); return THD_FATAL_ERROR; } value_obj = (PrefObject*) g_object_new(PREF_TYPE_OBJECT, NULL); if (value_obj == NULL) { thd_log_error("Failed to create one Value instance:"); return THD_FATAL_ERROR; } thd_log_debug("Registering it on the D-Bus.\n"); dbus_g_connection_register_g_object(bus, THD_SERVICE_OBJECT_PATH, G_OBJECT(value_obj)); } if (!no_daemon) { printf("Ready to serve requests: Daemonizing.. %d\n", thd_daemonize); thd_log_info( "thermald ver %s: Ready to serve requests: Daemonizing..\n", TD_DIST_VERSION); if (daemon(0, 1) != 0) { thd_log_error("Failed to daemonize.\n"); return THD_FATAL_ERROR; } } thd_engine = new cthd_engine_default(); if (exclusive_control) thd_engine->set_control_mode(EXCLUSIVE); // Initialize thermald objects thd_engine->set_poll_interval(thd_poll_interval); if (thd_engine->thd_engine_start(ignore_cpuid_check) != THD_SUCCESS) { thd_log_error("THD engine start failed: "); closelog(); exit(1); } // Start service requests on the D-Bus thd_log_debug("Start main loop\n"); g_main_loop_run(main_loop); thd_log_warn("Oops g main loop exit..\n"); return THD_SUCCESS; }
void obexftp_up (void) { GError *err = NULL; GSettings *settings; char *public_dir, *server; gboolean allow_write, require_pairing; settings = g_settings_new (GSETTINGS_SCHEMA); require_pairing =g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING); server = NULL; if (manager_proxy == NULL) { manager_proxy = dbus_g_proxy_new_for_name (connection, "org.openobex", "/org/openobex", "org.openobex.Manager"); if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer", &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "ftp", G_TYPE_BOOLEAN, require_pairing, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) { g_printerr ("Creating Bluetooth ObexFTP server failed: %s\n", err->message); g_error_free (err); g_object_unref (manager_proxy); manager_proxy = NULL; return; } } public_dir = lookup_public_dir (); allow_write =g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ALLOW_WRITE); g_object_unref (settings); if (server_proxy == NULL) { server_proxy = dbus_g_proxy_new_for_name (connection, "org.openobex", server, "org.openobex.Server"); g_free (server); } if (dbus_g_proxy_call (server_proxy, "Start", &err, G_TYPE_STRING, public_dir, G_TYPE_BOOLEAN, allow_write, G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) { if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE && dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) { g_error_free (err); g_message ("already started, ignoring error"); g_free (public_dir); return; } g_printerr ("Starting Bluetooth ObexFTP server failed: %s\n", err->message); g_error_free (err); g_free (public_dir); g_object_unref (server_proxy); server_proxy = NULL; g_object_unref (manager_proxy); manager_proxy = NULL; return; } g_free (public_dir); }
/* activesyncd entry point */ int main (int argc, char** argv) { DBusGConnection* bus = NULL; DBusGProxy* busProxy = NULL; EasSync* EasSyncObj = NULL; EasCommon* EasCommonObj = NULL; EasMail*EasMailObj = NULL; EasTest* EasTestObj = NULL; GMainLoop* loop = NULL; guint result; GError* error = NULL; #if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); #endif dbus_g_thread_init(); #if 0 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL, eas_logger, NULL); #endif g_log_set_default_handler (eas_logger, NULL); signal (SIGABRT, &signalHandler); signal (SIGTERM, &signalHandler); signal (SIGINT, &signalHandler); loop = g_main_loop_new (NULL, FALSE); if (loop == NULL) { g_debug ("Error: Couldn't create GMainLoop"); exit (EXIT_FAILURE); } // Give signalHandler() access to the main loop. g_mainloop = loop; //Creating all the GObjects g_debug ("activesyncd Daemon Started"); g_debug ("Creating eas_sync gobject."); EasSyncObj = eas_sync_new(); if (EasSyncObj == NULL) { g_debug ("Error: Failed to create calendar instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Creating common gobject."); EasCommonObj = g_object_new (EAS_TYPE_COMMON , NULL); if (EasCommonObj == NULL) { g_debug ("Error: Failed to create common instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Creating mail gobject."); EasMailObj = eas_mail_new (); if (EasMailObj == NULL) { g_debug ("Error: Failed to create common instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } EasTestObj = eas_test_new (); if (NULL == EasTestObj) { g_debug ("Failed to make EasTest instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Connecting to the session DBus"); bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (error != NULL) { g_debug ("Error: Connecting to the session DBus (%s)", error->message); g_clear_error (&error); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Registering the well-known name (%s)", EAS_SERVICE_NAME); busProxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (busProxy == NULL) { g_debug ("Error: Failed to get a proxy for D-Bus"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } dbus_g_proxy_set_default_timeout (busProxy, 1000000); /* register the well-known name.*/ g_debug ("D-Bus RequestName RPC "); if (!dbus_g_proxy_call (busProxy, "RequestName", &error, G_TYPE_STRING, EAS_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { g_debug ("Error: D-Bus RequestName RPC failed (%s)", error->message); g_clear_error (&error); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("RequestName returned %d", result); if (result != 1) { g_debug ("Error: Failed to get the primary well-known name"); exit (EXIT_FAILURE); } // Registering sync Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_SYNC_OBJECT_PATH, G_OBJECT (EasSyncObj)); // Registering common Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_COMMON_OBJECT_PATH, G_OBJECT (EasCommonObj)); // Registering mail Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_MAIL_OBJECT_PATH, G_OBJECT (EasMailObj)); dbus_g_connection_register_g_object (bus, EAS_SERVICE_TEST_OBJECT_PATH, G_OBJECT (EasTestObj)); g_debug ("Ready to serve requests"); #ifndef DISABLE_EAS_DAEMON if (daemon (0, 0) != 0) { g_debug ("Failed to daemonize"); } #else g_debug ("Not daemonizing (built with DISABLE_EAS_DAEMON)"); #endif g_main_loop_run (loop); // Clean up g_debug ("Main Cleanup"); g_mainloop = NULL; g_main_loop_unref (loop); // clean up dbus and all its objects if (EasSyncObj) { g_debug ("Unregister and unref EasSyncObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasSyncObj)); g_object_unref(EasSyncObj); } if (EasCommonObj) { g_debug ("Unregister and unref EasCommonObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasCommonObj)); g_object_unref(EasCommonObj); } if (EasMailObj) { g_debug ("Unregister and unref EasMailObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasMailObj)); g_object_unref(EasMailObj); } if (EasTestObj) { g_debug ("Unregister and unref EasTestObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasTestObj)); g_object_unref(EasTestObj); } if (busProxy) { g_debug ("Unref busProxy"); g_object_unref(busProxy); } if(bus) { g_debug ("Flush and unref DBusConnection bus"); dbus_g_connection_flush (bus); dbus_g_connection_unref(bus); } g_debug ("Exiting main()"); return 0; }
gboolean cpufreq_selector_service_register (CPUFreqSelectorService *service, GError **error) { DBusGConnection *connection; DBusGProxy *bus_proxy; gboolean res; guint result; GError *err = NULL; if (service->system_bus) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_ALREADY_REGISTERED, "Service %s already registered", BUS_NAME); return FALSE; } connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); if (!connection) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Couldn't connect to system bus: %s", err->message); g_error_free (err); return FALSE; } bus_proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!bus_proxy) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Could not construct bus_proxy object"); return FALSE; } res = dbus_g_proxy_call (bus_proxy, "RequestName", &err, G_TYPE_STRING, BUS_NAME, G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID); g_object_unref (bus_proxy); if (!res) { if (err) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Failed to acquire %s: %s", BUS_NAME, err->message); g_error_free (err); } else { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Failed to acquire %s", BUS_NAME); } return FALSE; } if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_ALREADY_REGISTERED, "Service %s already registered", BUS_NAME); return FALSE; } service->authority = polkit_authority_get (); service->system_bus = connection; dbus_g_object_type_install_info (CPUFREQ_TYPE_SELECTOR_SERVICE, &dbus_glib_cpufreq_selector_service_object_info); dbus_g_connection_register_g_object (connection, "/org/gnome/cpufreq_selector/selector", G_OBJECT (service)); dbus_g_error_domain_register (CPUFREQ_SELECTOR_SERVICE_ERROR, NULL, CPUFREQ_TYPE_SELECTOR_SERVICE_ERROR); reset_killtimer (); return TRUE; }
/* adapted from PolicyKit */ static gboolean get_caller_info (CsmDBusClient *client, const char *sender, uid_t *calling_uid, pid_t *calling_pid) { gboolean res; GError *error; DBusGConnection *connection; DBusGProxy *bus_proxy; res = FALSE; bus_proxy = NULL; if (sender == NULL) { goto out; } error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { if (error != NULL) { g_warning ("error getting session bus: %s", error->message); g_error_free (error); } goto out; } bus_proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); error = NULL; if (! dbus_g_proxy_call (bus_proxy, "GetConnectionUnixUser", &error, G_TYPE_STRING, sender, G_TYPE_INVALID, G_TYPE_UINT, calling_uid, G_TYPE_INVALID)) { g_debug ("GetConnectionUnixUser() failed: %s", error->message); g_error_free (error); goto out; } error = NULL; if (! dbus_g_proxy_call (bus_proxy, "GetConnectionUnixProcessID", &error, G_TYPE_STRING, sender, G_TYPE_INVALID, G_TYPE_UINT, calling_pid, G_TYPE_INVALID)) { g_debug ("GetConnectionUnixProcessID() failed: %s", error->message); g_error_free (error); goto out; } res = TRUE; g_debug ("uid = %d", *calling_uid); g_debug ("pid = %d", *calling_pid); out: if (bus_proxy != NULL) { g_object_unref (bus_proxy); } return res; }
void hexchat_remote (void) /* TODO: dbus_g_connection_unref (connection) are commented because it makes * dbus to crash. Fixed in dbus >=0.70 ?!? * https://launchpad.net/distros/ubuntu/+source/dbus/+bug/54375 */ { DBusGConnection *connection; DBusGProxy *dbus = NULL; DBusGProxy *remote_object = NULL; gboolean hexchat_running; GError *error = NULL; char *command = NULL; /* GnomeVFS >=2.15 uses D-Bus and threads, so threads should be * initialised before opening for the first time a D-Bus connection */ if (!g_thread_supported ()) { g_thread_init (NULL); } dbus_g_thread_init (); /* if there is nothing to do, return now. */ if (!arg_existing || !(arg_url || arg_command)) { return; } arg_dont_autoconnect = TRUE; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (!connection) { write_error (_("Couldn't connect to session bus"), &error); return; } /* Checks if HexChat is already running */ dbus = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!dbus_g_proxy_call (dbus, "NameHasOwner", &error, G_TYPE_STRING, DBUS_SERVICE, G_TYPE_INVALID, G_TYPE_BOOLEAN, &hexchat_running, G_TYPE_INVALID)) { write_error (_("Failed to complete NameHasOwner"), &error); hexchat_running = FALSE; } g_object_unref (dbus); if (!hexchat_running) { //dbus_g_connection_unref (connection); return; } remote_object = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE, DBUS_REMOTE, DBUS_REMOTE_INTERFACE); if (arg_url) { command = g_strdup_printf ("url %s", arg_url); } else if (arg_command) { command = g_strdup (arg_command); } if (command) { if (!dbus_g_proxy_call (remote_object, "Command", &error, G_TYPE_STRING, command, G_TYPE_INVALID,G_TYPE_INVALID)) { write_error (_("Failed to complete Command"), &error); } g_free (command); } exit (0); }
int moonshot_install_id_card (const char *display_name, const char *user_name, const char *password, const char *realm, char *rules_patterns[], int rules_patterns_length, char *rules_always_confirm[], int rules_always_confirm_length, char *services[], int services_length, const char *ca_cert, const char *subject, const char *subject_alt, const char *server_cert, int force_flat_file_store, MoonshotError **error) { GError *g_error = NULL; DBusGProxy *dbus_proxy; int success = FALSE; int i; const char **rules_patterns_strv, **rules_always_confirm_strv, **services_strv; dbus_proxy = get_dbus_proxy (error); if (*error != NULL) return FALSE; g_return_val_if_fail (DBUS_IS_G_PROXY (dbus_proxy), FALSE); g_return_val_if_fail (rules_patterns_length == rules_always_confirm_length, FALSE); /* Marshall array and struct parameters for DBus */ rules_patterns_strv = g_malloc ((rules_patterns_length + 1) * sizeof (const char *)); rules_always_confirm_strv = g_malloc ((rules_patterns_length + 1) * sizeof (const char *)); services_strv = g_malloc ((services_length + 1) * sizeof (const char *)); for (i = 0; i < rules_patterns_length; i ++) { rules_patterns_strv[i] = rules_patterns[i]; rules_always_confirm_strv[i] = rules_always_confirm[i]; } for (i = 0; i < services_length; i ++) services_strv[i] = services[i]; rules_patterns_strv[rules_patterns_length] = NULL; rules_always_confirm_strv[rules_patterns_length] = NULL; services_strv[services_length] = NULL; dbus_g_proxy_call (dbus_proxy, "InstallIdCard", &g_error, G_TYPE_STRING, display_name, G_TYPE_STRING, user_name, G_TYPE_STRING, password, G_TYPE_STRING, realm, G_TYPE_STRV, rules_patterns_strv, G_TYPE_STRV, rules_always_confirm_strv, G_TYPE_STRV, services_strv, G_TYPE_STRING, ca_cert, G_TYPE_STRING, subject, G_TYPE_STRING, subject_alt, G_TYPE_STRING, server_cert, G_TYPE_INT, force_flat_file_store, G_TYPE_INVALID, G_TYPE_BOOLEAN, &success, G_TYPE_INVALID); g_object_unref (dbus_proxy); g_free(rules_patterns_strv); g_free(rules_always_confirm_strv); g_free(services_strv); if (g_error != NULL) { *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR, g_error->message); return FALSE; } return success; }
static GObject * constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { GObject *object; NMRemoteSettingsPrivate *priv; GError *error = NULL; object = G_OBJECT_CLASS (nm_remote_settings_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); /* D-Bus proxy for clearing connections on NameOwnerChanged */ priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); g_assert (priv->dbus_proxy); dbus_g_object_register_marshaller (_nm_marshal_VOID__STRING_STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged", G_CALLBACK (name_owner_changed), object, NULL); if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", &error, G_TYPE_STRING, NM_DBUS_SERVICE, G_TYPE_INVALID, G_TYPE_BOOLEAN, &priv->service_running, G_TYPE_INVALID)) { g_warning ("%s (NMRemoteSettings) error getting remote settings service status: (%d) %s\n", __func__, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); g_error_free (error); priv->service_running = FALSE; } priv->proxy = dbus_g_proxy_new_for_name (priv->bus, NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS); g_assert (priv->proxy); dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT); dbus_g_proxy_add_signal (priv->proxy, "NewConnection", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "NewConnection", G_CALLBACK (new_connection_cb), object, NULL); priv->fetch_id = g_idle_add (fetch_connections, object); /* D-Bus properties proxy */ priv->props_proxy = dbus_g_proxy_new_for_name (priv->bus, NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, "org.freedesktop.DBus.Properties"); g_assert (priv->props_proxy); /* Monitor properties */ dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->proxy, "PropertiesChanged", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged", G_CALLBACK (properties_changed_cb), object, NULL); /* Get properties */ dbus_g_proxy_begin_call (priv->props_proxy, "GetAll", get_all_cb, object, NULL, G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS, G_TYPE_INVALID); return object; }