Back to index

lightdm  1.3.2
Classes | Enumerations | Functions | Variables
vnc-server.c File Reference
#include <gio/gio.h>
#include "vnc-server.h"

Go to the source code of this file.

Classes

struct  VNCServerPrivate

Enumerations

enum  { NEW_CONNECTION, LAST_SIGNAL }

Functions

 G_DEFINE_TYPE (VNCServer, vnc_server, G_TYPE_OBJECT)
VNCServervnc_server_new (void)
void vnc_server_set_port (VNCServer *server, guint port)
guint vnc_server_get_port (VNCServer *server)
static gboolean read_cb (GSocket *socket, GIOCondition condition, VNCServer *server)
static GSocket * open_tcp_socket (GSocketFamily family, guint port, GError **error)
gboolean vnc_server_start (VNCServer *server)
static void vnc_server_init (VNCServer *server)
static void vnc_server_finalize (GObject *object)
static void vnc_server_class_init (VNCServerClass *klass)

Variables

static guint signals [LAST_SIGNAL] = { 0 }

Class Documentation

struct VNCServerPrivate

Definition at line 22 of file vnc-server.c.

Class Members
guint port
GSocket * socket
GSocket * socket6

Enumeration Type Documentation

anonymous enum
Enumerator:
NEW_CONNECTION 
LAST_SIGNAL 

Definition at line 16 of file vnc-server.c.


Function Documentation

G_DEFINE_TYPE ( VNCServer  ,
vnc_server  ,
G_TYPE_OBJECT   
)
static GSocket* open_tcp_socket ( GSocketFamily  family,
guint  port,
GError **  error 
) [static]

Definition at line 81 of file vnc-server.c.

{
    GSocket *socket;
    GSocketAddress *address;
  
    socket = g_socket_new (family, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, error);
    if (!socket)
        return NULL;

    address = g_inet_socket_address_new (g_inet_address_new_any (family), port);
    if (!g_socket_bind (socket, address, TRUE, error) ||
        !g_socket_listen (socket, error))
    {
        g_object_unref (socket);
        return NULL;
    }

    return socket;
}

Here is the caller graph for this function:

static gboolean read_cb ( GSocket *  socket,
GIOCondition  condition,
VNCServer server 
) [static]

Definition at line 54 of file vnc-server.c.

{
    GError *error = NULL;
    GSocket *client_socket;

    client_socket = g_socket_accept (socket, NULL, &error);
    if (error)
        g_warning ("Failed to get connection from from VNC socket: %s", error->message);
    g_clear_error (&error);

    if (client_socket)
    {
        GInetSocketAddress *address;
        gchar *hostname;

        address = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (client_socket, NULL));
        hostname = g_inet_address_to_string (g_inet_socket_address_get_address (address));
        g_debug ("Got VNC connection from %s:%d", hostname, g_inet_socket_address_get_port (address));
        g_free (hostname);

        g_signal_emit (server, signals[NEW_CONNECTION], 0, client_socket);
    }

    return TRUE;
}

Here is the caller graph for this function:

static void vnc_server_class_init ( VNCServerClass klass) [static]

Definition at line 162 of file vnc-server.c.

{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    object_class->finalize = vnc_server_finalize;  

    g_type_class_add_private (klass, sizeof (VNCServerPrivate));

    signals[NEW_CONNECTION] =
        g_signal_new ("new-connection",
                      G_TYPE_FROM_CLASS (klass),
                      G_SIGNAL_RUN_LAST,
                      G_STRUCT_OFFSET (VNCServerClass, new_connection),
                      NULL, NULL,
                      g_cclosure_marshal_VOID__OBJECT,
                      G_TYPE_NONE, 1, G_TYPE_SOCKET);
}

Here is the call graph for this function:

static void vnc_server_finalize ( GObject *  object) [static]

Definition at line 147 of file vnc-server.c.

{
    VNCServer *self;

    self = VNC_SERVER (object);
  
    if (self->priv->socket)
        g_object_unref (self->priv->socket);
    if (self->priv->socket6)
        g_object_unref (self->priv->socket6);
  
    G_OBJECT_CLASS (vnc_server_parent_class)->finalize (object);  
}

Here is the caller graph for this function:

guint vnc_server_get_port ( VNCServer server)

Definition at line 47 of file vnc-server.c.

{
    g_return_val_if_fail (server != NULL, 0);
    return server->priv->port;
}

Here is the caller graph for this function:

static void vnc_server_init ( VNCServer server) [static]

Definition at line 140 of file vnc-server.c.

{
    server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, VNC_SERVER_TYPE, VNCServerPrivate);
    server->priv->port = 5900;
}

Definition at line 34 of file vnc-server.c.

{
    return g_object_new (VNC_SERVER_TYPE, NULL);
}

Here is the caller graph for this function:

void vnc_server_set_port ( VNCServer server,
guint  port 
)

Definition at line 40 of file vnc-server.c.

{
    g_return_if_fail (server != NULL);
    server->priv->port = port;
}

Here is the caller graph for this function:

gboolean vnc_server_start ( VNCServer server)

Definition at line 102 of file vnc-server.c.

{
    GSource *source;
    GError *error = NULL;

    g_return_val_if_fail (server != NULL, FALSE);
  
    server->priv->socket = open_tcp_socket (G_SOCKET_FAMILY_IPV4, server->priv->port, &error);
    if (error)
        g_warning ("Failed to create IPv4 VNC socket: %s", error->message);
    g_clear_error (&error);
  
    if (server->priv->socket)
    {
        source = g_socket_create_source (server->priv->socket, G_IO_IN, NULL);
        g_source_set_callback (source, (GSourceFunc) read_cb, server, NULL);
        g_source_attach (source, NULL);
    }
    
    server->priv->socket6 = open_tcp_socket (G_SOCKET_FAMILY_IPV6, server->priv->port, &error);
    if (error)
        g_warning ("Failed to create IPv6 VNC socket: %s", error->message);
    g_clear_error (&error);

    if (server->priv->socket6)
    {
        source = g_socket_create_source (server->priv->socket6, G_IO_IN, NULL);
        g_source_set_callback (source, (GSourceFunc) read_cb, server, NULL);
        g_source_attach (source, NULL);
    }

    if (!server->priv->socket && !server->priv->socket6)
        return FALSE;

    return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

guint signals[LAST_SIGNAL] = { 0 } [static]

Definition at line 20 of file vnc-server.c.