Spice Session

Spice Session — handles connection details, and active channels

Stability Level

Stable, unless otherwise indicated

Synopsis

#include <spice-client.h>

                    SpiceSession;
                    SpiceSessionClass;
SpiceSession *      spice_session_new                   (void);
gboolean            spice_session_connect               (SpiceSession *session);
gboolean            spice_session_open_fd               (SpiceSession *session,
                                                         int fd);
void                spice_session_disconnect            (SpiceSession *session);
GList *             spice_session_get_channels          (SpiceSession *session);
gboolean            spice_session_get_read_only         (SpiceSession *session);
gboolean            spice_session_has_channel_type      (SpiceSession *session,
                                                         gint type);
SpiceURI *          spice_session_get_proxy_uri         (SpiceSession *session);
gboolean            spice_session_is_for_migration      (SpiceSession *session);

enum                SpiceSessionMigration;
enum                SpiceSessionVerify;
GOptionGroup *      spice_get_option_group              (void);
void                spice_set_session_option            (SpiceSession *session);

enum                SpiceClientError;
#define             SPICE_CLIENT_ERROR
GQuark              spice_client_error_quark            (void);

Object Hierarchy

  GObject
   +----SpiceSession
  GEnum
   +----SpiceSessionMigration
  GFlags
   +----SpiceSessionVerify

Properties

  "ca"                       GByteArray*           : Read / Write
  "ca-file"                  gchar*                : Read / Write
  "cache-size"               gint                  : Read / Write
  "cert-subject"             gchar*                : Read / Write
  "ciphers"                  gchar*                : Read / Write
  "client-sockets"           gboolean              : Read / Write
  "color-depth"              gint                  : Read / Write
  "disable-effects"          GStrv                 : Read / Write
  "enable-audio"             gboolean              : Read / Write / Construct
  "enable-smartcard"         gboolean              : Read / Write
  "enable-usbredir"          gboolean              : Read / Write / Construct
  "glz-window-size"          gint                  : Read / Write
  "host"                     gchar*                : Read / Write / Construct
  "inhibit-keyboard-grab"    gboolean              : Read / Write
  "migration-state"          SpiceSessionMigration  : Read
  "name"                     gchar*                : Read
  "password"                 gchar*                : Read / Write
  "port"                     gchar*                : Read / Write
  "preferred-compression"    SpiceImageCompress    : Read / Write
  "protocol"                 gint                  : Read / Write / Construct
  "proxy"                    gchar*                : Read / Write
  "pubkey"                   GByteArray*           : Read / Write
  "read-only"                gboolean              : Read / Write / Construct
  "secure-channels"          GStrv                 : Read / Write
  "share-dir-ro"             gboolean              : Read / Write / Construct
  "shared-dir"               gchar*                : Read / Write / Construct
  "smartcard-certificates"   GStrv                 : Read / Write
  "smartcard-db"             gchar*                : Read / Write
  "tls-port"                 gchar*                : Read / Write
  "unix-path"                gchar*                : Read / Write / Construct
  "uri"                      gchar*                : Read / Write
  "username"                 gchar*                : Read / Write
  "uuid"                     gpointer              : Read
  "verify"                   SpiceSessionVerify    : Read / Write / Construct

Signals

  "channel-destroy"                                : Run First
  "channel-new"                                    : Run First
  "mm-time-reset"                                  : Run First

Description

The SpiceSession class handles all the SpiceChannel connections. It's also the class that contains connections informations, such as "host" and "port".

You can simply set the property "uri" to something like "spice://127.0.0.1?port=5930" to configure your connection details.

You may want to connect to "channel-new" signal, to be informed of the availability of channels and to interact with them.

For example, when the SpiceInputsChannel is available and get the event SPICE_CHANNEL_OPENED, you can send key events with spice_inputs_key_press(). When the SpiceMainChannel is available, you can start sharing the clipboard... .

Once SpiceSession properties set, you can call spice_session_connect() to start connecting and communicating with a Spice server.

Details

SpiceSession

typedef struct _SpiceSession SpiceSession;

The SpiceSession struct is opaque and should not be accessed directly.


SpiceSessionClass

typedef struct {
    GObjectClass parent_class;

    /* signals */
    void (*channel_new)(SpiceSession *session, SpiceChannel *channel);
    void (*channel_destroy)(SpiceSession *session, SpiceChannel *channel);
} SpiceSessionClass;

Class structure for SpiceSession.

GObjectClass parent_class;

Parent class.

channel_new ()

Signal class handler for the "channel_new" signal.

channel_destroy ()

Signal class handler for the "channel_destroy" signal.

spice_session_new ()

SpiceSession *      spice_session_new                   (void);

Creates a new Spice session.

Returns :

a new SpiceSession

spice_session_connect ()

gboolean            spice_session_connect               (SpiceSession *session);

Open the session using the "host" and "port".

session :

a SpiceSession

Returns :

FALSE if the session state is invalid for connection request. TRUE if the connection is initiated. To know whether the connection is established, you must watch for channels creation ("channel-new") and the channels state ("channel-event").

spice_session_open_fd ()

gboolean            spice_session_open_fd               (SpiceSession *session,
                                                         int fd);

Open the session using the provided fd socket file descriptor. This is useful if you create the fd yourself, for example to setup a SSH tunnel.

Note however that additional sockets will be needed by all the channels created for session so users of this API should hook into SpiceChannel::open-fd signal for each channel they are interested in, and create and pass a new socket to the channel using spice_channel_open_fd, in the signal callback.

If fd is -1, a valid fd will be requested later via the SpiceChannel::open-fd signal. Typically, you would want to just pass -1 as fd this call since you will have to hook to SpiceChannel::open-fd signal anyway.

session :

a SpiceSession

fd :

a file descriptor (socket) or -1

Returns :

TRUE on success.

spice_session_disconnect ()

void                spice_session_disconnect            (SpiceSession *session);

Disconnect the session, and destroy all channels.

session :

a SpiceSession

spice_session_get_channels ()

GList *             spice_session_get_channels          (SpiceSession *session);

Get the list of current channels associated with this session.

session :

a SpiceSession

Returns :

a GList of unowned SpiceChannel channels. [element-type SpiceChannel][transfer container]

spice_session_get_read_only ()

gboolean            spice_session_get_read_only         (SpiceSession *session);

Checks whether the session is read-only.

session :

a SpiceSession

Returns :

whether the session is in read-only mode.

spice_session_has_channel_type ()

gboolean            spice_session_has_channel_type      (SpiceSession *session,
                                                         gint type);

See if there is a type channel in the channels associated with this session.

session :

a SpiceSession

type :

a "channel-type"

Returns :

TRUE if a type channel is available otherwise FALSE.

spice_session_get_proxy_uri ()

SpiceURI *          spice_session_get_proxy_uri         (SpiceSession *session);

Gets the session proxy uri.

session :

a SpiceSession

Returns :

the session proxy SpiceURI or NULL. [transfer none]

Since 0.24


spice_session_is_for_migration ()

gboolean            spice_session_is_for_migration      (SpiceSession *session);

During seamless migration, channels may be created to establish a connection with the target, but they are temporary and should only handle migration steps. In order to avoid other interactions with the client, channels should check this value.

session :

a Spice session

Returns :

TRUE if the session is a copy created during migration

Since 0.27


enum SpiceSessionMigration

typedef enum {
    SPICE_SESSION_MIGRATION_NONE,
    SPICE_SESSION_MIGRATION_SWITCHING,
    SPICE_SESSION_MIGRATION_MIGRATING,
    SPICE_SESSION_MIGRATION_CONNECTING,
} SpiceSessionMigration;

Session migration state.

SPICE_SESSION_MIGRATION_NONE

no migration going on

SPICE_SESSION_MIGRATION_SWITCHING

the session is switching host (destroy and reconnect)

SPICE_SESSION_MIGRATION_MIGRATING

the session is migrating seamlessly (reconnect)

SPICE_SESSION_MIGRATION_CONNECTING

the migration is connecting to destination (Since: 0.27)

enum SpiceSessionVerify

typedef enum {
    SPICE_SESSION_VERIFY_PUBKEY   = (1 << 0),
    SPICE_SESSION_VERIFY_HOSTNAME = (1 << 1),
    SPICE_SESSION_VERIFY_SUBJECT  = (1 << 2),
} SpiceSessionVerify;

Peer certificate verification parameters flags.

SPICE_SESSION_VERIFY_PUBKEY

verify certificate public key matching

SPICE_SESSION_VERIFY_HOSTNAME

verify certificate hostname matching

SPICE_SESSION_VERIFY_SUBJECT

verify certificate subject matching

spice_get_option_group ()

GOptionGroup *      spice_get_option_group              (void);

Gets commandline options.

Bindings for other languages are available since 0.32

Returns :

a GOptionGroup for the commandline arguments specific to Spice. You have to call spice_set_session_option() after to set the options on a SpiceSession. [transfer full]

spice_set_session_option ()

void                spice_set_session_option            (SpiceSession *session);

Set various properties on session, according to the commandline arguments given to spice_get_option_group() option group.

session :

a SpiceSession to set option upon

enum SpiceClientError

typedef enum {
    SPICE_CLIENT_ERROR_FAILED,
    SPICE_CLIENT_ERROR_USB_DEVICE_REJECTED,
    SPICE_CLIENT_ERROR_USB_DEVICE_LOST,
    SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
    SPICE_CLIENT_ERROR_AUTH_NEEDS_USERNAME,
    SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME,
    SPICE_CLIENT_ERROR_USB_SERVICE,
} SpiceClientError;

Error codes returned by spice-client API.

SPICE_CLIENT_ERROR_FAILED

generic error code

SPICE_CLIENT_ERROR_USB_DEVICE_REJECTED

device redirection rejected by host

SPICE_CLIENT_ERROR_USB_DEVICE_LOST

device disconnected (fatal IO error)

SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD

password is required

SPICE_CLIENT_ERROR_AUTH_NEEDS_USERNAME

username is required

SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD_AND_USERNAME

password and username are required

SPICE_CLIENT_ERROR_USB_SERVICE

USB service error

SPICE_CLIENT_ERROR

#define SPICE_CLIENT_ERROR spice_client_error_quark()

Error domain for spice client errors.


spice_client_error_quark ()

GQuark              spice_client_error_quark            (void);

Gets a GQuark representing the string "spice-client-error-quark"

Returns :

the GQuark representing the string.

Property Details

The "ca" property

  "ca"                       GByteArray*           : Read / Write

CA certificates in PEM format. The text data can contain several CA certificates identified by:

-----BEGIN CERTIFICATE----- ... (CA certificate in base64 encoding) ... -----END CERTIFICATE-----

Since 0.15


The "ca-file" property

  "ca-file"                  gchar*                : Read / Write

File holding the CA certificates for the host the client is connecting to

Default value: NULL


The "cache-size" property

  "cache-size"               gint                  : Read / Write

Images cache size. If 0, don't set.

Allowed values: >= 0

Default value: 0

Since 0.9


The "cert-subject" property

  "cert-subject"             gchar*                : Read / Write

Certificate subject to check.

Default value: NULL


The "ciphers" property

  "ciphers"                  gchar*                : Read / Write

SSL cipher list.

Default value: NULL


The "client-sockets" property

  "client-sockets"           gboolean              : Read / Write

Sockets are provided by the client.

Default value: FALSE


The "color-depth" property

  "color-depth"              gint                  : Read / Write

Display color depth to set on new display channels. If 0, don't set.

Allowed values: [0,32]

Default value: 0

Since 0.7


The "disable-effects" property

  "disable-effects"          GStrv                 : Read / Write

A string array of effects to disable. The settings will be applied on new display channels. The following effets can be disabled "wallpaper", "font-smooth", "animation", and "all", which will disable all the effects. If NULL, don't apply changes.

Since 0.7


The "enable-audio" property

  "enable-audio"             gboolean              : Read / Write / Construct

If set to TRUE, the audio channels will be enabled for playback and recording.

Default value: TRUE

Since 0.8


The "enable-smartcard" property

  "enable-smartcard"         gboolean              : Read / Write

If set to TRUE, the smartcard channel will be enabled and smartcard events will be forwarded to the guest

Default value: FALSE

Since 0.7


The "enable-usbredir" property

  "enable-usbredir"          gboolean              : Read / Write / Construct

If set to TRUE, the usbredir channel will be enabled and USB devices can be redirected to the guest

Default value: TRUE

Since 0.8


The "glz-window-size" property

  "glz-window-size"          gint                  : Read / Write

Glz window size. If 0, don't set.

Allowed values: [0,134217728]

Default value: 0

Since 0.9


The "host" property

  "host"                     gchar*                : Read / Write / Construct

URL of the SPICE host to connect to

Default value: "localhost"


The "inhibit-keyboard-grab" property

  "inhibit-keyboard-grab"    gboolean              : Read / Write

Request that SpiceDisplays don't grab the keyboard.

Default value: FALSE


The "migration-state" property

  "migration-state"          SpiceSessionMigration  : Read

SpiceSessionMigration bit field indicating if a migration is in progress

Default value: SPICE_SESSION_MIGRATION_NONE


The "name" property

  "name"                     gchar*                : Read

Spice server name.

Default value: NULL

Since 0.11


The "password" property

  "password"                 gchar*                : Read / Write

TLS password to use

Default value: NULL


The "port" property

  "port"                     gchar*                : Read / Write

Port to connect to for unencrypted sessions

Default value: NULL


The "preferred-compression" property

  "preferred-compression"    SpiceImageCompress    : Read / Write

The image compression algorithm the client prefers to use. It is reported to the server.

Default value: SPICE_IMAGE_COMPRESSION_INVALID

Since 0.29


The "protocol" property

  "protocol"                 gint                  : Read / Write / Construct

Version of the SPICE protocol to use

Allowed values: [1,2]

Default value: 2


The "proxy" property

  "proxy"                    gchar*                : Read / Write

URI to the proxy server to use when doing network connection. of the form [protocol://]<host>[:port]

Default value: NULL

Since 0.17


The "pubkey" property

  "pubkey"                   GByteArray*           : Read / Write

Public key to check.


The "read-only" property

  "read-only"                gboolean              : Read / Write / Construct

Whether this connection is read-only mode.

Default value: FALSE

Since 0.8


The "secure-channels" property

  "secure-channels"          GStrv                 : Read / Write

A string array of channel types to be secured.

Since 0.20


The "share-dir-ro" property

  "share-dir-ro"             gboolean              : Read / Write / Construct

Whether to share the directory read-only.

Default value: FALSE

Since 0.28


The "shared-dir" property

  "shared-dir"               gchar*                : Read / Write / Construct

Location of the shared directory

Default value: NULL

Since 0.24


The "smartcard-certificates" property

  "smartcard-certificates"   GStrv                 : Read / Write

This property is used when one wants to simulate a smartcard with no hardware smartcard reader. If it's set to a NULL-terminated string array containing the names of 3 valid certificates, these will be used to simulate a smartcard in the guest See also spice_smartcard_manager_insert_card()

Since 0.7


The "smartcard-db" property

  "smartcard-db"             gchar*                : Read / Write

Path to the NSS certificate database containing the certificates to use to simulate a software smartcard

Default value: NULL

Since 0.7


The "tls-port" property

  "tls-port"                 gchar*                : Read / Write

Port to connect to for TLS sessions

Default value: NULL


The "unix-path" property

  "unix-path"                gchar*                : Read / Write / Construct

Path of the Unix socket to connect to

Default value: NULL

Since 0.28


The "uri" property

  "uri"                      gchar*                : Read / Write

URI of the SPICE host to connect to. The URI is of the form spice://hostname?port=XXX or spice://hostname?tls_port=XXX

Default value: NULL


The "username" property

  "username"                 gchar*                : Read / Write

Username to use

Default value: NULL


The "uuid" property

  "uuid"                     gpointer              : Read

Spice server uuid.

Since 0.11


The "verify" property

  "verify"                   SpiceSessionVerify    : Read / Write / Construct

SpiceSessionVerify bit field indicating which parts of the peer certificate should be checked

Default value: SPICE_SESSION_VERIFY_HOSTNAME

Signal Details

The "channel-destroy" signal

void                user_function                      (SpiceSession *session,
                                                        SpiceChannel *channel,
                                                        gpointer      user_data)      : Run First

The "channel-destroy" signal is emitted each time a SpiceChannel is destroyed.

session :

the session that emitted the signal

channel :

the destroyed SpiceChannel

user_data :

user data set when the signal handler was connected.

The "channel-new" signal

void                user_function                      (SpiceSession *session,
                                                        SpiceChannel *channel,
                                                        gpointer      user_data)      : Run First

The "channel-new" signal is emitted each time a SpiceChannel is created.

session :

the session that emitted the signal

channel :

the new SpiceChannel

user_data :

user data set when the signal handler was connected.

The "mm-time-reset" signal

void                user_function                      (SpiceSession *session,
                                                        gpointer      user_data)      : Run First

The "mm-time-reset" is emitted when we identify discontinuity in mm-time

Since 0.20

session :

the session that emitted the signal

user_data :

user data set when the signal handler was connected.

See Also

SpiceChannel, and the GTK widget SpiceDisplay