static gboolean lookup_internal (const gchar *name, GSocketConnectable **connectable) { const gchar *env; gboolean ret = FALSE; GSocketAddress *address; g_assert (name != NULL); g_assert (connectable != NULL); if (internal_addresses) { ret = g_hash_table_lookup_extended (internal_addresses, name, NULL, (gpointer *)connectable); } if (!ret && g_str_equal (name, "ssh-agent")) { *connectable = NULL; env = g_getenv ("SSH_AUTH_SOCK"); if (env != NULL && env[0] != '\0') { address = g_unix_socket_address_new (env); *connectable = G_SOCKET_CONNECTABLE (address); cockpit_channel_internal_address ("ssh-agent", address); } ret = TRUE; } return ret; }
static void cockpit_channel_class_init (CockpitChannelClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GSocketAddress *address; GInetAddress *inet; const gchar *port; gobject_class->constructed = cockpit_channel_constructed; gobject_class->get_property = cockpit_channel_get_property; gobject_class->set_property = cockpit_channel_set_property; gobject_class->dispose = cockpit_channel_dispose; gobject_class->finalize = cockpit_channel_finalize; klass->prepare = cockpit_channel_real_prepare; klass->close = cockpit_channel_real_close; /** * CockpitChannel:transport: * * The transport to send and receive messages over. */ g_object_class_install_property (gobject_class, PROP_TRANSPORT, g_param_spec_object ("transport", "transport", "transport", COCKPIT_TYPE_TRANSPORT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel:channel: * * The numeric channel to receive and send messages on. */ g_object_class_install_property (gobject_class, PROP_ID, g_param_spec_string ("id", "id", "id", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel:options: * * The JSON options used to open this channel. The exact contents are * dependent on the derived channel class ... but this must at the * very least contain a 'payload' field describing what kind of channel * this should be. */ g_object_class_install_property (gobject_class, PROP_OPTIONS, g_param_spec_boxed ("options", "options", "options", JSON_TYPE_OBJECT, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel:capabilities: * * The capabilties that this channel supports. */ g_object_class_install_property (gobject_class, PROP_CAPABILITIES, g_param_spec_boxed ("capabilities", "Capabilities", "Channel Capabilities", G_TYPE_STRV, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)); /** * CockpitChannel::closed: * * Emitted when the channel closes. This is similar to CockpitTransport::closed * but only applies to the individual channel. * * The channel will also be closed when the transport closes. */ cockpit_channel_sig_closed = g_signal_new ("closed", COCKPIT_TYPE_CHANNEL, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (CockpitChannelClass, closed), NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_STRING); g_type_class_add_private (klass, sizeof (CockpitChannelPrivate)); /* * If we're running under a test server, register that server's HTTP address * as an internal address, available for use in cockpit channels. */ port = g_getenv ("COCKPIT_TEST_SERVER_PORT"); if (port) { inet = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4); address = g_inet_socket_address_new (inet, atoi (port)); cockpit_channel_internal_address ("test-server", address); g_object_unref (address); g_object_unref (inet); } }