static void add_pan_connection (NmaBtDevice *self) { NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); NMConnection *connection; NMSetting *setting, *bt_setting, *ip_setting; char *id, *uuid; /* The connection */ connection = nm_connection_new (); /* The connection settings */ setting = nm_setting_connection_new (); id = g_strdup_printf (_("%s Network"), priv->alias ? priv->alias : priv->bdaddr); uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (setting), NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL); g_free (id); g_free (uuid); nm_setting_connection_add_permission ((NMSettingConnection *) setting, "user", g_get_user_name (), NULL); nm_connection_add_setting (connection, setting); /* The Bluetooth settings */ bt_setting = nm_setting_bluetooth_new (); g_object_set (G_OBJECT (bt_setting), NM_SETTING_BLUETOOTH_BDADDR, priv->bdaddr_array, NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_PANU, NULL); nm_connection_add_setting (connection, bt_setting); /* IPv4 */ ip_setting = nm_setting_ip4_config_new (); g_object_set (G_OBJECT (ip_setting), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NM_SETTING_IP4_CONFIG_MAY_FAIL, FALSE, NULL); nm_connection_add_setting (connection, ip_setting); /* IPv6 */ ip_setting = nm_setting_ip6_config_new (); g_object_set (G_OBJECT (ip_setting), NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, NULL); nm_connection_add_setting (connection, ip_setting); /* Add the connection to the settings service */ nm_remote_settings_add_connection (priv->settings, connection, pan_add_cb, self); }
static void wizard_done_cb (NMAMobileWizard *wizard, gboolean canceled, NMAMobileWizardAccessMethod *method, gpointer user_data) { NmaBtDevice *self = NMA_BT_DEVICE (user_data); NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); NMConnection *connection = NULL; NMSetting *s_bt; g_return_if_fail (wizard == priv->wizard); g_message ("%s: mobile wizard done", __func__); if (canceled || !method) { dun_error (self, __func__, NULL, _("Mobile wizard was canceled")); return; } if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) connection = dun_new_cdma (method); else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) connection = dun_new_gsm (method); else { dun_error (self, __func__, NULL, _("Unknown phone device type (not GSM or CDMA)")); return; } nma_mobile_wizard_destroy (priv->wizard); priv->wizard = NULL; g_assert (connection); /* The Bluetooth settings */ s_bt = nm_setting_bluetooth_new (); g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_BDADDR, priv->bdaddr_array, NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_DUN, NULL); nm_connection_add_setting (connection, s_bt); g_message ("%s: adding new setting", __func__); /* Add the connection to the settings service */ nm_remote_settings_add_connection (priv->settings, connection, dun_add_cb, self); g_message ("%s: waiting for add connection result...", __func__); }
static void apply_edits (NetConnectionEditor *editor) { update_connection (editor); if (editor->is_new_connection) { nm_remote_settings_add_connection (editor->settings, editor->orig_connection, added_connection_cb, editor); } else { nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (editor->orig_connection), updated_connection_cb, editor); } }
static gboolean add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; char *uuid; gboolean success; /* Create a new connection object */ connection = nm_connection_new (); /* Build 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 */ s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* Build 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)); /* Ask the settings service to add the new connection; we'll quit the * mainloop and exit when the callback is called. */ success = nm_remote_settings_add_connection (settings, connection, added_cb, loop); if (!success) g_print ("Error adding connection\n"); g_object_unref (connection); return success; }
static void save_connection_and_exit (NmtNewtButton *button, gpointer user_data) { NmtEditor *editor = user_data; NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE (editor); NmtSyncOp op; GError *error = NULL; if (!nm_connection_replace_settings_from_connection (priv->orig_connection, priv->edit_connection, &error)) { nmt_newt_message_dialog (_("Error saving connection: %s"), error->message); g_error_free (error); return; } nmt_sync_op_init (&op); if (NM_IS_REMOTE_CONNECTION (priv->orig_connection)) { nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (priv->orig_connection), connection_updated, &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { nmt_newt_message_dialog (_("Unable to save connection: %s"), error->message); g_error_free (error); return; } /* Clear secrets so they don't lay around in memory; they'll get * requested again anyway next time the connection is edited. */ nm_connection_clear_secrets (priv->orig_connection); } else { nm_remote_settings_add_connection (nm_settings, priv->orig_connection, connection_added, &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { nmt_newt_message_dialog (_("Unable to add new connection: %s"), error->message); g_error_free (error); return; } } nmt_newt_form_quit (NMT_NEWT_FORM (editor)); }
static void test_add_connection (void) { gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; char *uuid; gboolean success; time_t start, now; gboolean done = FALSE; connection = nm_connection_new (); s_con = (NMSettingConnection *) nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, TEST_CON_ID, NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); success = nm_remote_settings_add_connection (settings, connection, add_cb, &done); g_assert (success == TRUE); start = time (NULL); do { now = time (NULL); g_main_context_iteration (NULL, FALSE); } while ((done == FALSE) && (now - start < 5)); g_assert (done == TRUE); g_assert (remote != NULL); /* Make sure the connection is the same as what we added */ g_assert (nm_connection_compare (connection, NM_CONNECTION (remote), NM_SETTING_COMPARE_FLAG_EXACT) == TRUE); }