static void entry_activated_cb(GtkEntry *entry, gpointer user_data) { /* GtkWidget **array_widget = user_data; GtkWidget *window = array_widget[0]; GtkWidget *label = array_widget[1]; */ GtkWidget *label = GTK_WIDGET(user_data); const static gchar *text; char input[32] = {0}; text = gtk_entry_get_text(entry); g_strlcpy(input, text, 32); INFO("Activated %s!\n", input); if ( !dbus_g_proxy_call(proxy, "say", &error, G_TYPE_STRING, &input, G_TYPE_INVALID, G_TYPE_STRING, &res, G_TYPE_INVALID)) { if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) DEBUG ("Caught remote method exception %s: %s", dbus_g_error_get_name (error), error->message); else DEBUG ("Error: %s\n", error->message); g_error_free (error); exit(1); } gtk_label_set_text(GTK_LABEL(label), res); INFO("Result is: %s\n", res); g_free(res); gtk_entry_set_text(entry, ""); }
void seahorse_util_handle_error (GError* err, const char* desc, ...) { gchar *t = NULL; va_list ap; if(!err) return; va_start(ap, desc); if (desc) t = g_strdup_vprintf (desc, ap); va_end(ap); /* Never show an error for 'cancelled' */ if (err->code == DBUS_GERROR_REMOTE_EXCEPTION && err->domain == DBUS_GERROR && strstr (dbus_g_error_get_name (err), "Cancelled")) g_free(t); return; seahorse_util_show_error (NULL, t, err->message ? err->message : ""); g_free(t); g_clear_error (&err); }
/** * gpk_ignore_session_error: * * Returns true if the error is a remote exception where we cancelled **/ gboolean gpk_ignore_session_error (GError *error) { gboolean ret = FALSE; const gchar *name; if (error == NULL) goto out; if (error->domain != DBUS_GERROR) goto out; if (error->code != DBUS_GERROR_REMOTE_EXCEPTION) goto out; /* use one of our local codes */ name = dbus_g_error_get_name (error); if (name == NULL) goto out; if (g_str_has_prefix (name, "org.freedesktop.PackageKit.Modify.Cancelled")) { ret = TRUE; goto out; } /* DBus-glib hates us */ if (g_str_has_prefix (name, "Org.freedesktop.PackageKit.Modify.Cancelled")) { ret = TRUE; goto out; } out: return ret; }
int main(int argc, char **argv) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; char **name_list; char **name_list_ptr; char *name; g_type_init(); if (argc < 3) { g_printerr("Usage: %s ADDR KEYNUM\n", argv[0]); exit(1); } error = NULL; connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if(connection == NULL) { g_printerr("Fialed to open connection to bus: %s\n", error->message); g_error_free(error); exit(1); } /* Create a proxy object for the tictactoe */ proxy = dbus_g_proxy_new_for_name(connection, argv[1], "/com/lp/tictactoe", "com.lp.tictactoe"); /* Call keypad method, wait for reply */ error = NULL; if(!dbus_g_proxy_call(proxy, "keypad", &error, G_TYPE_UINT, atoi(argv[2]), G_TYPE_INVALID, G_TYPE_INVALID)) { /* Just do demonstrate remote exceptions versus regular GError */ if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message); } else { g_printerr("Error: %s\n", error->message); } g_error_free(error); exit(1); } g_object_unref(proxy); return 0; }
int main (int argc, char **argv) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; char **name_list; char **name_list_ptr; g_type_init (); 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); exit (1); } /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */ proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); /* Call ListNames method, wait for reply */ error = NULL; if (!dbus_g_proxy_call (proxy, "ListNames", &error, G_TYPE_INVALID, G_TYPE_STRV, &name_list, G_TYPE_INVALID)) { /* Just do demonstrate remote exceptions versus regular GError */ if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) g_printerr ("Caught remote method exception %s: %s", dbus_g_error_get_name (error), error->message); else g_printerr ("Error: %s\n", error->message); g_error_free (error); exit (1); } /* Print the results */ g_print ("Names on the message bus:\n"); for (name_list_ptr = name_list; *name_list_ptr; name_list_ptr++) { g_print (" %s\n", *name_list_ptr); } g_strfreev (name_list); g_object_unref (proxy); return 0; }
/** * Determine whether D-BUS error name for a remote exception matches * the given name. This function is intended to be invoked on a * GError returned from an invocation of a remote method, e.g. via * dbus_g_proxy_end_call. It will silently return FALSE for errors * which are not remote D-BUS exceptions (i.e. with a domain other * than DBUS_GERROR or a code other than * DBUS_GERROR_REMOTE_EXCEPTION). * * @param error the GError given from the remote method * @param name the D-BUS error name * @param msg the D-BUS error detailed message * @returns TRUE iff the remote error has the given name */ gboolean dbus_g_error_has_name (GError *error, const char *name) { g_return_val_if_fail (error != NULL, FALSE); if (error->domain != DBUS_GERROR || error->code != DBUS_GERROR_REMOTE_EXCEPTION) return FALSE; return !strcmp (dbus_g_error_get_name (error), name); }
static void emit_error_helper (NMSupplicantInterface *self, GError *err) { const char *name = NULL; if (err->domain == DBUS_GERROR && err->code == DBUS_GERROR_REMOTE_EXCEPTION) name = dbus_g_error_get_name (err); g_signal_emit (self, signals[CONNECTION_ERROR], 0, name, err->message); }
static void handle_dbus_call_error(const char *call, GError **_error) { GError *error = *_error; const char *message = error->message; if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) message = dbus_g_error_get_name(error); g_warning("Error calling '%s': %s", call, message); g_clear_error(_error); }
int main(int argc, char *argv[]) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; char **name_list; char **name_list_ptr; g_type_init(); error = NULL; #if 0 connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); #else connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); #endif if (!connection) { g_printerr("Failed to open connection to bus: %s\n", error->message); g_error_free(error); exit(1); } proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); error = NULL; if (!dbus_g_proxy_call(proxy, "ListNames", &error, G_TYPE_INVALID, G_TYPE_STRV, &name_list, G_TYPE_INVALID)) { if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { g_printerr("Caught remote method exception %s: %s\n", dbus_g_error_get_name(error), error->message); } else { g_printerr("Error: %s\n", error->message); } g_error_free(error); exit(1); } g_print("Names on the message bus: \n"); for (name_list_ptr = name_list; *name_list_ptr; name_list_ptr++) { g_print(" %s\n", *name_list_ptr); } g_strfreev(name_list); g_object_unref(proxy); exit(0); }
static void notification_error (const char *title, const char *detail, SeahorseApplet *sapplet, GError *err) { /* Never show an error for 'cancelled' */ if (err->code == DBUS_GERROR_REMOTE_EXCEPTION && err->domain == DBUS_GERROR && strstr (dbus_g_error_get_name (err), "Cancelled")) return; seahorse_notification_display(title, detail, FALSE, NULL, GTK_WIDGET (sapplet)); }
gint call_mms_dbus(SharingEntryMedia *media) { GError *error = NULL; DBusGConnection *connection; g_type_init(); connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (!connection) { g_printerr("Failed to open connection to system bus: %s\n", error->message); ULOG_DEBUG_L("Failed to open connection to system bus: %s\n", error->message); g_clear_error(&error); return EXIT_FAILURE; } DBusGProxy *proxy; gint retval = 0; const gchar *local_file; const gchar *desc; const gchar *title; local_file = sharing_entry_media_get_localpath(media); desc = sharing_entry_media_get_desc(media); title = sharing_entry_media_get_title(media); proxy = dbus_g_proxy_new_for_name(connection, MMS_DBUS_NAME, MMS_DBUS_PATH, MMS_DBUS_IFACE); if (!dbus_g_proxy_call(proxy, MMS_SHARE_SIG, &error, G_TYPE_STRING, local_file, G_TYPE_STRING, title, G_TYPE_STRING, desc, G_TYPE_INVALID)) { if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message); ULOG_DEBUG_L("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message); } else { g_printerr("Failed to call method: %s\n", error->message); ULOG_DEBUG_L("Failed to call method: %s\n", error->message); } g_clear_error(&error); } g_object_unref(proxy); return retval; }
/* * Print appropriate warnings when dbus raised error * on queries */ static void handle_dbus_exception(GError *error) { if (error == NULL) { g_warning("[Pidgin] unable to parse result"); return; } else if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { g_warning ("[Pidgin] caught remote method exception %s: %s", dbus_g_error_get_name (error), error->message); } g_error_free (error); }
static int gnome_sessionmanager_control(DBusGConnection *connection, int enable) { GError *error; DBusGProxy *proxy; gboolean ret; /* Create a proxy object */ proxy = dbus_g_proxy_new_for_name(connection, SM_SERVICE, SM_PATH, SM_INTERFACE); if (!proxy) { LOGDBG("Failed to get a proxy for " SM_SERVICE); return 0; } error = NULL; if (enable) { ret = dbus_g_proxy_call(proxy, "Uninhibit", &error, G_TYPE_UINT, cookie, G_TYPE_INVALID, G_TYPE_INVALID); } else { ret = dbus_g_proxy_call(proxy, "Inhibit", &error, G_TYPE_STRING, GS_APPLICATION_NAME, G_TYPE_UINT, 0, G_TYPE_STRING, GS_REASON_FOR_INHIBIT, G_TYPE_UINT, 12, G_TYPE_INVALID, G_TYPE_UINT, &cookie, G_TYPE_INVALID); } g_object_unref(proxy); if (!ret) { /* Check if it's a remote exception or a regular GError */ if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { LOGMSG(MSG_RemoteMethodException, dbus_g_error_get_name(error), error->message); } else { LOGMSG(MSG_GError, error->message); } g_error_free(error); return 0; } LOGMSG(enable ? MSG_GNOMEScreensaverEnabled : MSG_GNOMEScreensaverDisabled); return 1; }
void _mdu_error_fixup (GError *error) { const char *name; gboolean matched; if (error == NULL) return; if (error->domain != DBUS_GERROR || error->code != DBUS_GERROR_REMOTE_EXCEPTION) return; name = dbus_g_error_get_name (error); if (name == NULL) return; matched = TRUE; if (strcmp (name, "org.freedesktop.UDisks.Error.Failed") == 0) error->code = MDU_ERROR_FAILED; else if (strcmp (name, "org.freedesktop.UDisks.Error.Busy") == 0) error->code = MDU_ERROR_BUSY; else if (strcmp (name, "org.freedesktop.UDisks.Error.Cancelled") == 0) error->code = MDU_ERROR_CANCELLED; else if (strcmp (name, "org.freedesktop.UDisks.Error.Inhibited") == 0) error->code = MDU_ERROR_INHIBITED; else if (strcmp (name, "org.freedesktop.UDisks.Error.InvalidOption") == 0) error->code = MDU_ERROR_INVALID_OPTION; else if (strcmp (name, "org.freedesktop.UDisks.Error.NotSupported") == 0) error->code = MDU_ERROR_NOT_SUPPORTED; else if (strcmp (name, "org.freedesktop.UDisks.Error.AtaSmartWouldWakeup") == 0) error->code = MDU_ERROR_ATA_SMART_WOULD_WAKEUP; else if (strcmp (name, "org.freedesktop.UDisks.Error.PermissionDenied") == 0) error->code = MDU_ERROR_PERMISSION_DENIED; else if (strcmp (name, "org.freedesktop.UDisks.Error.FilesystemDriverMissing") == 0) error->code = MDU_ERROR_FILESYSTEM_DRIVER_MISSING; else if (strcmp (name, "org.freedesktop.UDisks.Error.FilesystemToolsMissing") == 0) error->code = MDU_ERROR_FILESYSTEM_TOOLS_MISSING; else matched = FALSE; if (matched) error->domain = MDU_ERROR; }
static NMDeviceStateReason translate_mm_error (GError *error) { NMDeviceStateReason reason; if (dbus_g_error_has_name (error, MM_MODEM_CONNECT_ERROR_NO_CARRIER)) reason = NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER; else if (dbus_g_error_has_name (error, MM_MODEM_CONNECT_ERROR_NO_DIALTONE)) reason = NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE; else if (dbus_g_error_has_name (error, MM_MODEM_CONNECT_ERROR_BUSY)) reason = NM_DEVICE_STATE_REASON_MODEM_BUSY; else if (dbus_g_error_has_name (error, MM_MODEM_CONNECT_ERROR_NO_ANSWER)) reason = NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_NETWORK_NOT_ALLOWED)) reason = NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_NETWORK_TIMEOUT)) reason = NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_NO_NETWORK)) reason = NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_NOT_INSERTED)) reason = NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_PIN)) reason = NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_PUK)) reason = NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_WRONG)) reason = NM_DEVICE_STATE_REASON_GSM_SIM_WRONG; else { /* unable to map the ModemManager error to a NM_DEVICE_STATE_REASON */ nm_log_dbg (LOGD_MB, "unmapped dbus error detected: '%s'", dbus_g_error_get_name (error)); reason = NM_DEVICE_STATE_REASON_UNKNOWN; } /* FIXME: We have only GSM error messages here, and we have no idea which activation state failed. Reasons like: NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED, NM_DEVICE_STATE_REASON_GSM_APN_FAILED, NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED, NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED are not used. */ return reason; }
/* * Print appropriate warnings when dbus raised error * on queries */ static void _handle_dbus_exception (GError *error, gboolean empty_list_messages) { if (error == NULL) { g_warning("[Gajim] unable to parse result"); return; } else if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { g_warning ("[Gajim] caught remote method exception %s: %s", dbus_g_error_get_name (error), error->message); } else if(empty_list_messages) { /* empty list and error goes here */ g_warning ("[Gajim] empty result set: %d %d %s\n", error->domain, error->code, error->message); } g_error_free (error); }
static int mce_control(DBusGConnection *connection, int enable) { GError *error; DBusGProxy *proxy; gboolean ret = 1; /* Create a proxy object */ proxy = dbus_g_proxy_new_for_name(connection, MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF); if (!proxy) { LOGDBG("Failed to get a proxy for " SM_SERVICE); return 0; } error = NULL; if (enable) { ret = dbus_g_proxy_call(proxy, MCE_CANCEL_PREVENT_BLANK_REQ, &error, G_TYPE_INVALID, G_TYPE_INVALID); } else { ret = dbus_g_proxy_call(proxy, MCE_PREVENT_BLANK_REQ, &error, G_TYPE_INVALID, G_TYPE_INVALID); } g_object_unref(proxy); if (!ret) { /* Check if it's a remote exception or a regular GError */ if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { LOGMSG(MSG_RemoteMethodException, dbus_g_error_get_name(error), error->message); } else { LOGMSG(MSG_GError, error->message); } g_error_free(error); return 0; } LOGMSG(enable ? MSG_MCEScreensaverEnabled : MSG_MCEScreensaverDisabled); return 1; }
static void handle_reply (DBusGProxy * proxy, char * OUT_out, GError * error, gpointer entry) { if (error) { gchar* msg = g_strdup_printf (_("Error contacting the mirror service: %s:%d:%s%c%s"), g_quark_to_string (error->domain), error->code, error->message, g_error_matches (error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) ? ':' : '\0', g_error_matches (error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) ? dbus_g_error_get_name (error) : ""); gtk_label_set_text (GTK_LABEL (error_label), msg); g_free (msg); /* FIXME: free the error? */ } else { gtk_label_set(GTK_LABEL(error_label), ""); gtk_entry_set_text(GTK_ENTRY(entry), OUT_out); } gtk_widget_set_sensitive (entry, TRUE); }
static char * dbus_gerror_fqn (GError const *error) { char const *fqn; switch (error->code) { case DBUS_GERROR_FAILED: fqn = DBUS_ERROR_FAILED; break; case DBUS_GERROR_NO_MEMORY: fqn = DBUS_ERROR_NO_MEMORY; break; case DBUS_GERROR_SERVICE_UNKNOWN: fqn = DBUS_ERROR_SERVICE_UNKNOWN; break; case DBUS_GERROR_NAME_HAS_NO_OWNER: fqn = DBUS_ERROR_NAME_HAS_NO_OWNER; break; case DBUS_GERROR_NO_REPLY: fqn = DBUS_ERROR_NO_REPLY; break; case DBUS_GERROR_IO_ERROR: fqn = DBUS_ERROR_IO_ERROR; break; case DBUS_GERROR_BAD_ADDRESS: fqn = DBUS_ERROR_BAD_ADDRESS; break; case DBUS_GERROR_NOT_SUPPORTED: fqn = DBUS_ERROR_NOT_SUPPORTED; break; case DBUS_GERROR_LIMITS_EXCEEDED: fqn = DBUS_ERROR_LIMITS_EXCEEDED; break; case DBUS_GERROR_ACCESS_DENIED: fqn = DBUS_ERROR_ACCESS_DENIED; break; case DBUS_GERROR_AUTH_FAILED: fqn = DBUS_ERROR_AUTH_FAILED; break; case DBUS_GERROR_NO_SERVER: fqn = DBUS_ERROR_NO_SERVER; break; case DBUS_GERROR_TIMEOUT: fqn = DBUS_ERROR_TIMEOUT; break; case DBUS_GERROR_NO_NETWORK: fqn = DBUS_ERROR_NO_NETWORK; break; case DBUS_GERROR_ADDRESS_IN_USE: fqn = DBUS_ERROR_ADDRESS_IN_USE; break; case DBUS_GERROR_DISCONNECTED: fqn = DBUS_ERROR_DISCONNECTED; break; case DBUS_GERROR_INVALID_ARGS: fqn = DBUS_ERROR_INVALID_ARGS; break; case DBUS_GERROR_FILE_NOT_FOUND: fqn = DBUS_ERROR_FILE_NOT_FOUND; break; case DBUS_GERROR_FILE_EXISTS: fqn = DBUS_ERROR_FILE_EXISTS; break; case DBUS_GERROR_UNKNOWN_METHOD: fqn = DBUS_ERROR_UNKNOWN_METHOD; break; case DBUS_GERROR_TIMED_OUT: fqn = DBUS_ERROR_TIMED_OUT; break; case DBUS_GERROR_MATCH_RULE_NOT_FOUND: fqn = DBUS_ERROR_MATCH_RULE_NOT_FOUND; break; case DBUS_GERROR_MATCH_RULE_INVALID: fqn = DBUS_ERROR_MATCH_RULE_INVALID; break; case DBUS_GERROR_SPAWN_EXEC_FAILED: fqn = DBUS_ERROR_SPAWN_EXEC_FAILED; break; case DBUS_GERROR_SPAWN_FORK_FAILED: fqn = DBUS_ERROR_SPAWN_FORK_FAILED; break; case DBUS_GERROR_SPAWN_CHILD_EXITED: fqn = DBUS_ERROR_SPAWN_CHILD_EXITED; break; case DBUS_GERROR_SPAWN_CHILD_SIGNALED: fqn = DBUS_ERROR_SPAWN_CHILD_SIGNALED; break; case DBUS_GERROR_SPAWN_FAILED: fqn = DBUS_ERROR_SPAWN_FAILED; break; case DBUS_GERROR_UNIX_PROCESS_ID_UNKNOWN: fqn = DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN; break; case DBUS_GERROR_INVALID_SIGNATURE: fqn = DBUS_ERROR_INVALID_SIGNATURE; break; case DBUS_GERROR_INVALID_FILE_CONTENT: fqn = DBUS_ERROR_INVALID_FILE_CONTENT; break; case DBUS_GERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN: fqn = DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN; break; case DBUS_GERROR_REMOTE_EXCEPTION: fqn = dbus_g_error_get_name ((GError *)error); break; default: return NULL; } return g_strdup (fqn); }
static void assistant_prepare (GtkAssistant *ass, GtkWidget *page, EnrollData *data) { const char *name; name = g_object_get_data (G_OBJECT (page), "name"); if (name == NULL) return; if (g_str_equal (name, "enroll")) { DBusGProxy *p; GError *error = NULL; GtkBuilder *dialog = data->dialog; char *path; guint i; GValue value = { 0, }; if (!dbus_g_proxy_call (data->device, "Claim", &error, G_TYPE_STRING, "", G_TYPE_INVALID, G_TYPE_INVALID)) { GtkWidget *d; char *msg; /* translators: * The variable is the name of the device, for example: * "Could you not access "Digital Persona U.are.U 4000/4000B" device */ msg = g_strdup_printf (_("Could not access '%s' device"), data->name); d = get_error_dialog (msg, dbus_g_error_get_name (error), GTK_WINDOW (data->ass)); g_error_free (error); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (d); g_free (msg); enroll_data_destroy (data); return; } data->state = STATE_CLAIMED; p = dbus_g_proxy_new_from_proxy (data->device, "org.freedesktop.DBus.Properties", NULL); if (!dbus_g_proxy_call (p, "Get", NULL, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_STRING, "num-enroll-stages", G_TYPE_INVALID, G_TYPE_VALUE, &value, G_TYPE_INVALID) || g_value_get_int (&value) < 1) { GtkWidget *d; char *msg; /* translators: * The variable is the name of the device, for example: * "Could you not access "Digital Persona U.are.U 4000/4000B" device */ msg = g_strdup_printf (_("Could not access '%s' device"), data->name); d = get_error_dialog (msg, "net.reactivated.Fprint.Error.Internal", GTK_WINDOW (data->ass)); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (d); g_free (msg); enroll_data_destroy (data); g_object_unref (p); return; } g_object_unref (p); data->num_enroll_stages = g_value_get_int (&value); /* Hide the extra "bulbs" if not needed */ for (i = MAX_ENROLL_STAGES; i > data->num_enroll_stages; i--) { char *name; name = g_strdup_printf ("image%d", i); gtk_widget_hide (WID (name)); g_free (name); } /* And set the right image */ { char *filename; filename = g_strdup_printf ("%s.png", data->finger); path = g_build_filename (MATECC_PIXMAP_DIR, filename, NULL); g_free (filename); } for (i = 1; i <= data->num_enroll_stages; i++) { char *name; name = g_strdup_printf ("image%d", i); gtk_image_set_from_file (GTK_IMAGE (WID (name)), path); g_free (name); } g_free (path); dbus_g_proxy_add_signal(data->device, "EnrollStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL); dbus_g_proxy_connect_signal(data->device, "EnrollStatus", G_CALLBACK(enroll_result), data, NULL); if (!dbus_g_proxy_call(data->device, "EnrollStart", &error, G_TYPE_STRING, data->finger, G_TYPE_INVALID, G_TYPE_INVALID)) { GtkWidget *d; char *msg; /* translators: * The variable is the name of the device, for example: * "Could you not access "Digital Persona U.are.U 4000/4000B" device */ msg = g_strdup_printf (_("Could not start finger capture on '%s' device"), data->name); d = get_error_dialog (msg, dbus_g_error_get_name (error), GTK_WINDOW (data->ass)); g_error_free (error); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (d); g_free (msg); enroll_data_destroy (data); return; } data->state = STATE_ENROLLING;; } else { if (data->state == STATE_ENROLLING) { dbus_g_proxy_call(data->device, "EnrollStop", NULL, G_TYPE_INVALID, G_TYPE_INVALID); data->state = STATE_CLAIMED; } if (data->state == STATE_CLAIMED) { dbus_g_proxy_call(data->device, "Release", NULL, G_TYPE_INVALID, G_TYPE_INVALID); data->state = STATE_NONE; } } }
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); }
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; }
void gnome_screensaver_control(int enable) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; gboolean ret; #ifdef GLIB_CHECK_VERSION #if !GLIB_CHECK_VERSION(2,35,0) g_type_init(); #endif #endif #ifdef HAVE_MCE_DBUS_NAMES error = NULL; connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (!connection) { LOGMSG(MSG_OpenBusConnectionError, error ? error->message : "<null>"); g_error_free(error); } else if (mce_control(connection, enable)) { return; } #endif /* Get a connection to the session bus */ error = NULL; connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (!connection) { LOGMSG(MSG_OpenBusConnectionError, error ? error->message : "<null>"); g_error_free(error); return; } /* try session manager interface first */ if (gnome_sessionmanager_control(connection, enable)) return; /* Create a proxy object */ proxy = dbus_g_proxy_new_for_name(connection, GS_SERVICE, GS_PATH, GS_INTERFACE); if (!proxy) { LOGDBG("Failed to get a proxy for " GS_SERVICE); return; } error = NULL; /* Enable the screensaver */ if (enable) { /* First call the GNOME screensaver 2.15 API method */ ret = dbus_g_proxy_call(proxy, "UnInhibit", &error, G_TYPE_UINT, cookie, G_TYPE_INVALID, G_TYPE_INVALID); /* If this fails, try the GNOME screensaver 2.14 API */ if (!ret && error->domain == DBUS_GERROR && error->code == DBUS_GERROR_UNKNOWN_METHOD) { LOGMSG(MSG_GnomeAPI215Failed); g_error_free(error); error = NULL; ret = dbus_g_proxy_call(proxy, "AllowActivation", &error, G_TYPE_INVALID, G_TYPE_INVALID); } } /* Disable the screensaver */ else { /* First call the GNOME screensaver 2.15 API method */ ret = dbus_g_proxy_call(proxy, "Inhibit", &error, G_TYPE_STRING, GS_APPLICATION_NAME, G_TYPE_STRING, GS_REASON_FOR_INHIBIT, G_TYPE_INVALID, G_TYPE_UINT, &cookie, G_TYPE_INVALID); /* If this fails, try the GNOME screensaver 2.14 API */ if (!ret && error->domain == DBUS_GERROR && error->code == DBUS_GERROR_UNKNOWN_METHOD) { LOGMSG(MSG_GnomeAPI215Failed); g_error_free(error); error = NULL; ret = dbus_g_proxy_call(proxy, "InhibitActivation", &error, G_TYPE_STRING, GS_REASON_FOR_INHIBIT, G_TYPE_INVALID, G_TYPE_INVALID); } } if (!ret) { /* Check if it's a remote exception or a regular GError */ if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) { LOGMSG(MSG_RemoteMethodException, dbus_g_error_get_name(error), error->message); } else { LOGMSG(MSG_GError, error->message); } g_error_free(error); } else { LOGMSG(enable ? MSG_GNOMEScreensaverEnabled : MSG_GNOMEScreensaverDisabled); } g_object_unref(proxy); }