Commit 7cd69584 authored by Dan Winship's avatar Dan Winship
Browse files

Merge branch 'libnm-nmobj' (bgo #734228)

parents 50d45ace 66a34803
......@@ -228,16 +228,9 @@ static NmcOutputField nmc_fields_con_active_details_groups[] = {
#define CON_SHOW_DETAIL_GROUP_PROFILE "profile"
#define CON_SHOW_DETAIL_GROUP_ACTIVE "active"
typedef struct {
NmCli *nmc;
int argc;
char **argv;
} ArgsInfo;
/* glib main loop variable - defined in nmcli.c */
extern GMainLoop *loop;
static ArgsInfo args_info;
static guint progress_id = 0; /* ID of event source for displaying progress */
/* for readline TAB completion in editor */
......@@ -1285,7 +1278,7 @@ do_connections_show (NmCli *nmc, gboolean active_only, int argc, char **argv)
nmc->should_wait = FALSE;
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto finish;
......@@ -2009,7 +2002,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
/* create NMClient */
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -2069,7 +2062,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
/* create NMClient */
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -8046,7 +8039,7 @@ do_connection_modify (NmCli *nmc,
/* create NMClient */
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto finish;
......@@ -8254,7 +8247,7 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
/* create NMClient */
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto finish;
......@@ -8347,7 +8340,7 @@ do_connection_reload (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_SUCCESS;
nmc->should_wait = FALSE;
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
return nmc->return_value;
......@@ -8375,7 +8368,7 @@ do_connection_load (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_SUCCESS;
nmc->should_wait = FALSE;
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
return nmc->return_value;
......@@ -8607,21 +8600,6 @@ opt_error:
return nmc->return_value;
}
/* callback called when connections are obtained from the settings service */
static void
get_connections_cb (NMRemoteSettings *settings, gpointer user_data)
{
ArgsInfo *args = (ArgsInfo *) user_data;
/* Get the connection list */
args->nmc->system_connections = nm_remote_settings_list_connections (settings);
parse_cmd (args->nmc, args->argc, args->argv);
if (!args->nmc->should_wait)
quit ();
}
/* Entry point function for connections-related commands: 'nmcli connection' */
NMCResultCode
do_connections (NmCli *nmc, int argc, char **argv)
......@@ -8651,10 +8629,6 @@ do_connections (NmCli *nmc, int argc, char **argv)
nmc->should_wait = TRUE;
args_info.nmc = nmc;
args_info.argc = argc;
args_info.argv = argv;
/* get system settings */
if (!(nmc->system_settings = nm_remote_settings_new (NULL, &error))) {
g_string_printf (nmc->return_text, _("Error: Could not get system settings: %s."), error->message);
......@@ -8665,7 +8639,7 @@ do_connections (NmCli *nmc, int argc, char **argv)
}
/* find out whether settings service is running */
g_object_get (nmc->system_settings, NM_REMOTE_SETTINGS_SERVICE_RUNNING, &nmc->system_settings_running, NULL);
g_object_get (nmc->system_settings, NM_REMOTE_SETTINGS_NM_RUNNING, &nmc->system_settings_running, NULL);
if (!nmc->system_settings_running) {
g_string_printf (nmc->return_text, _("Error: Can't obtain connections: settings service is not running."));
......@@ -8674,13 +8648,13 @@ do_connections (NmCli *nmc, int argc, char **argv)
return nmc->return_value;
}
/* connect to signal "connections-read" - emitted when connections are fetched and ready */
g_signal_connect (nmc->system_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
G_CALLBACK (get_connections_cb), &args_info);
/* Get the connection list */
nmc->system_connections = nm_remote_settings_list_connections (nmc->system_settings);
/* The rest will be done in get_connection_cb() callback.
* We need to wait for signals that connections are read.
*/
parse_cmd (nmc, argc, argv);
if (!nmc->should_wait)
quit ();
return NMC_RESULT_SUCCESS;
}
}
......@@ -1183,7 +1183,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -1231,7 +1231,7 @@ do_devices_show (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -1394,7 +1394,7 @@ do_device_connect (NmCli *nmc, int argc, char **argv)
}
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -1528,7 +1528,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
}
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -1622,7 +1622,7 @@ do_device_delete (NmCli *nmc, int argc, char **argv)
}
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -1765,7 +1765,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -2209,7 +2209,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......@@ -2508,7 +2508,7 @@ do_device_wimax_list (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc);
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
goto error;
......
......@@ -335,7 +335,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
nmc->get_client (nmc); /* create NMClient */
nm_running = nm_client_get_manager_running (nmc->client);
nm_running = nm_client_get_nm_running (nmc->client);
if (nm_running) {
if (!nmc_versions_match (nmc))
return FALSE;
......@@ -478,7 +478,7 @@ show_nm_permissions (NmCli *nmc)
nmc->get_client (nmc); /* create NMClient */
if (!nm_client_get_manager_running (nmc->client)) {
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
return FALSE;
......
......@@ -62,7 +62,7 @@ client_properties_changed (GObject *object,
NMState state;
gboolean wait_startup = GPOINTER_TO_UINT (g_object_get_data (object, WAIT_STARTUP_TAG));
if (!nm_client_get_manager_running (client))
if (!nm_client_get_nm_running (client))
return;
if (wait_startup) {
......@@ -203,7 +203,7 @@ main (int argc, char *argv[])
g_object_set_data (G_OBJECT (client), WAIT_STARTUP_TAG, GUINT_TO_POINTER (wait_startup));
state = nm_client_get_state (client);
if (!nm_client_get_manager_running (client)) {
if (!nm_client_get_nm_running (client)) {
if (exit_no_nm) {
g_object_unref (client);
return 1;
......
......@@ -155,7 +155,7 @@ sort_by_timestamp (gconstpointer a,
static void nmt_edit_connection_list_rebuild (NmtEditConnectionList *list);
static void
rebuild_on_connection_updated (NMRemoteConnection *connection,
rebuild_on_connection_changed (NMRemoteConnection *connection,
gpointer list)
{
nmt_edit_connection_list_rebuild (list);
......@@ -171,7 +171,7 @@ free_connections (NmtEditConnectionList *list)
for (iter = priv->connections; iter; iter = iter->next) {
conn = iter->data;
g_signal_handlers_disconnect_by_func (conn, G_CALLBACK (rebuild_on_connection_updated), list);
g_signal_handlers_disconnect_by_func (conn, G_CALLBACK (rebuild_on_connection_changed), list);
g_object_unref (conn);
}
g_slist_free (priv->connections);
......@@ -202,10 +202,8 @@ nmt_edit_connection_list_rebuild (NmtEditConnectionList *list)
continue;
}
g_signal_connect (conn, NM_REMOTE_CONNECTION_UPDATED,
G_CALLBACK (rebuild_on_connection_updated), list);
g_signal_connect (conn, NM_REMOTE_CONNECTION_REMOVED,
G_CALLBACK (rebuild_on_connection_updated), list);
g_signal_connect (conn, NM_CONNECTION_CHANGED,
G_CALLBACK (rebuild_on_connection_changed), list);
g_object_ref (iter->data);
}
priv->connections = g_slist_sort (priv->connections, sort_by_timestamp);
......@@ -279,9 +277,9 @@ nmt_edit_connection_list_rebuild (NmtEditConnectionList *list)
}
static void
rebuild_on_new_connection (NMRemoteSettings *settings,
NMRemoteConnection *connection,
gpointer list)
rebuild_on_connections_changed (GObject *object,
GParamSpec *pspec,
gpointer list)
{
nmt_edit_connection_list_rebuild (list);
}
......@@ -295,8 +293,8 @@ nmt_edit_connection_list_constructed (GObject *object)
if (priv->extra)
nmt_newt_button_box_add_widget_end (priv->buttons, priv->extra);
g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_NEW_CONNECTION,
G_CALLBACK (rebuild_on_new_connection), list);
g_signal_connect (nm_settings, "notify::" NM_REMOTE_SETTINGS_CONNECTIONS,
G_CALLBACK (rebuild_on_connections_changed), list);
nmt_edit_connection_list_rebuild (list);
......
......@@ -426,6 +426,7 @@ nmt_edit_connection (NMConnection *connection)
typedef struct {
NmtSyncOp op;
gboolean got_callback, got_signal;
NMRemoteConnection *connection;
} ConnectionDeleteData;
static void
......@@ -446,14 +447,17 @@ connection_deleted_callback (NMRemoteConnection *connection,
}
static void
connection_removed_signal (NMRemoteConnection *connection,
connection_removed_signal (NMRemoteSettings *settings,
NMRemoteConnection *connection,
gpointer user_data)
{
ConnectionDeleteData *data = user_data;
data->got_signal = TRUE;
if (data->got_callback && data->got_signal)
nmt_sync_op_complete_boolean (&data->op, TRUE, NULL);
if (connection == data->connection) {
data->got_signal = TRUE;
if (data->got_callback && data->got_signal)
nmt_sync_op_complete_boolean (&data->op, TRUE, NULL);
}
}
void
......@@ -473,8 +477,8 @@ nmt_remove_connection (NMRemoteConnection *connection)
data.got_callback = data.got_signal = FALSE;
nmt_sync_op_init (&data.op);
g_object_ref (connection);
g_signal_connect (connection, NM_REMOTE_CONNECTION_REMOVED,
data.connection = connection;
g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTION_REMOVED,
G_CALLBACK (connection_removed_signal), &data);
nm_remote_connection_delete (connection, connection_deleted_callback, &data);
......@@ -484,8 +488,7 @@ nmt_remove_connection (NMRemoteConnection *connection)
g_error_free (error);
}
g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (connection_removed_signal), &data);
g_object_unref (connection);
g_signal_handlers_disconnect_by_func (nm_settings, G_CALLBACK (connection_removed_signal), &data);
}
NmtNewtForm *
......
......@@ -140,15 +140,6 @@ nmtui_quit (void)
g_main_loop_quit (loop);
}
static void
connections_read (NMRemoteSettings *settings,
gpointer user_data)
{
gboolean *got_connections = user_data;
*got_connections = TRUE;
}
static void
usage (void)
{
......@@ -217,7 +208,6 @@ GOptionEntry entries[] = {
int
main (int argc, char **argv)
{
gboolean got_connections = FALSE;
GOptionContext *opts;
GError *error = NULL;
NmtuiStartupData startup_data;
......@@ -249,7 +239,7 @@ main (int argc, char **argv)
g_error_free (error);
exit (1);
}
if (!nm_client_get_manager_running (nm_client)) {
if (!nm_client_get_nm_running (nm_client)) {
g_printerr ("%s\n", _("NetworkManager is not running."));
exit (1);
}
......@@ -260,11 +250,6 @@ main (int argc, char **argv)
g_error_free (error);
exit (1);
}
g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
G_CALLBACK (connections_read), &got_connections);
/* coverity[loop_condition] */
while (!got_connections)
g_main_context_iteration (NULL, TRUE);
if (sleep_on_startup)
sleep (5);
......
......@@ -27,38 +27,9 @@
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <NetworkManager.h>
/* Global variables */
GMainLoop *loop = NULL; /* Main loop variable - needed for waiting for signal */
int result = EXIT_SUCCESS;
static void
signal_handler (int signo)
{
if (signo == SIGINT || signo == SIGTERM) {
g_message ("Caught signal %d, shutting down...", signo);
g_main_loop_quit (loop);
}
}
static void
setup_signals (void)
{
struct sigaction action;
sigset_t mask;
sigemptyset (&mask);
action.sa_handler = signal_handler;
action.sa_mask = mask;
action.sa_flags = 0;
sigaction (SIGTERM, &action, NULL);
sigaction (SIGINT, &action, NULL);
}
/* Print details of connection */
static void
show_connection (gpointer data, gpointer user_data)
......@@ -89,85 +60,43 @@ show_connection (gpointer data, gpointer user_data)
}
}
/* This callback is called when connections from the settings service are ready.
* Now the connections can be listed.
*/
static void
get_connections_cb (NMRemoteSettings *settings, gpointer user_data)
{
GSList *connections;
connections = nm_remote_settings_list_connections (settings);
printf ("Connections:\n===================\n");
g_slist_foreach (connections, show_connection, NULL);
g_slist_free (connections);
g_object_unref (settings);
/* We are done, exit main loop */
g_main_loop_quit (loop);
}
/* Get system settings and then connect to connections-read signal */
static gboolean
list_connections (gpointer data)
int
main (int argc, char *argv[])
{
NMRemoteSettings *settings;
gboolean settings_running;
GError *error = NULL;
GSList *connections;
#if !GLIB_CHECK_VERSION (2, 35, 0)
/* Initialize GType system */
g_type_init ();
#endif
/* Get system settings */
if (!(settings = nm_remote_settings_new (NULL, &error))) {
g_message ("Error: Could not get system settings: %s.", error->message);
g_error_free (error);
result = EXIT_FAILURE;
g_main_loop_quit (loop);
return FALSE;
return EXIT_FAILURE;
}
/* Find out whether setting service is running */
g_object_get (settings, NM_REMOTE_SETTINGS_SERVICE_RUNNING, &settings_running, NULL);
g_object_get (settings, NM_REMOTE_SETTINGS_NM_RUNNING, &settings_running, NULL);
if (!settings_running) {
g_message ("Error: Can't obtain connections: settings service is not running.");
result = EXIT_FAILURE;
g_main_loop_quit (loop);
return FALSE;
return EXIT_FAILURE;
}
/* Connect to signal "connections-read" - emitted when connections are fetched and ready */
g_signal_connect (settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
G_CALLBACK (get_connections_cb), NULL);
return FALSE;
}
int main (int argc, char *argv[])
{
DBusGConnection *bus;
#if !GLIB_CHECK_VERSION (2, 35, 0)
/* Initialize GType system */
g_type_init ();
#endif
/* Get system bus */
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
/* Now the connections can be listed. */
connections = nm_remote_settings_list_connections (settings);
/* Run list_connections from main loop, because we need to wait for "connections-read"
* signal to have connections ready. The execution will be finished in get_connections_cb()
* callback on the signal.
*/
g_idle_add (list_connections, bus);
printf ("Connections:\n===================\n");
loop = g_main_loop_new (NULL, FALSE); /* Create main loop */
setup_signals (); /* Setup UNIX signals */
g_main_loop_run (loop); /* Run main loop */
g_slist_foreach (connections, show_connection, NULL);
g_main_loop_unref (loop);
dbus_g_connection_unref (bus);
g_slist_free (connections);
g_object_unref (settings);
return result;
return EXIT_SUCCESS;
}
......@@ -679,5 +679,49 @@ nmtst_ip6_config_clone (NMIP6Config *config)
#endif
#ifdef NM_CONNECTION_H
inline static NMConnection *
nmtst_create_minimal_connection (const char *id, const char *uuid, const char *type, NMSettingConnection **out_s_con)
{
NMConnection *con;
NMSetting *s_base = NULL;
NMSettingConnection *s_con;
g_assert (id);
if (uuid)
g_assert (nm_utils_is_uuid (uuid));
else
uuid = nm_utils_uuid_generate ();
if (type) {
GType type_g = nm_connection_lookup_setting_type (type);
g_assert (type_g != G_TYPE_INVALID);
s_base = g_object_new (type_g, NULL);
g_assert (NM_IS_SETTING (s_base));
}
con = nm_connection_new ();
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
g_object_set (s_con,
NM_SETTING_CONNECTION_ID, id,
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_TYPE, type,
NULL);
nm_connection_add_setting (con, NM_SETTING (s_con));
if (s_base)
nm_connection_add_setting (con, s_base);
if (out_s_con)
*out_s_con = s_con;
return con;
}
#endif
#endif /* __NM_TEST_UTILS_H__ */
......@@ -1704,50 +1704,6 @@ nm_client_new_finish (GAsyncResult *result, GError **error)
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
/*
* Validate D-Bus object path.
* The function is copied and adjusted version of
* g_variant_serialiser_is_object_path() from glib.
* FIXME: The function can be replaced by g_variant_is_object_path()
* when we start using GLib >= 2.24
*/
static gboolean
_nm_client_is_object_path (const char *string)
{
gsize i;
if (!g_utf8_validate (string, -1, NULL))
return FALSE;
/* The path must begin with an ASCII '/' (integer 47) character */
if (string[0] != '/')
return FALSE;
for (i = 1; string[i]; i++) {
/* Each element must only contain the ASCII characters
* "[A-Z][a-z][0-9]_"
*/
if (g_ascii_isalnum (string[i]) || string[i] == '_')