[PATCH 10/25] Convert VncConnection into a proper GObject type
- From: "Daniel P. Berrange" <berrange redhat com>
- To: gtk-vnc-list gnome org
- Cc: "Daniel P. Berrange" <berrange redhat com>
- Subject: [PATCH 10/25] Convert VncConnection into a proper GObject type
- Date: Sat, 21 Nov 2009 13:27:59 +0000
---
src/vncbaseframebuffer.h | 2 +-
src/vncconnection.c | 1312 +++++++++++++++++++++++++++-------------------
src/vncconnection.h | 28 +-
src/vncconnectionblt.h | 29 +-
src/vncdisplay.c | 2 +-
5 files changed, 824 insertions(+), 549 deletions(-)
diff --git a/src/vncbaseframebuffer.h b/src/vncbaseframebuffer.h
index 529a347..173e806 100644
--- a/src/vncbaseframebuffer.h
+++ b/src/vncbaseframebuffer.h
@@ -32,7 +32,7 @@ G_BEGIN_DECLS
#define VNC_BASE_FRAMEBUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VNC_TYPE_BASE_FRAMEBUFFER, VncBaseFramebufferClass))
#define VNC_IS_BASE_FRAMEBUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VNC_TYPE_BASE_FRAMEBUFFER))
#define VNC_IS_BASE_FRAMEBUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VNC_TYPE_BASE_FRAMEBUFFER))
-#define VNC_BASE_FRAMEBUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VNC_TYPE_BASE_FRAMEBUFFER, VncBAseFramebufferClass))
+#define VNC_BASE_FRAMEBUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VNC_TYPE_BASE_FRAMEBUFFER, VncBaseFramebufferClass))
typedef struct _VncBaseFramebuffer VncBaseFramebuffer;
diff --git a/src/vncconnection.c b/src/vncconnection.c
index 91eb284..bbe862e 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -100,7 +100,11 @@ struct g_condition_wait_source
gpointer data;
};
-struct _VncConnection
+#define VNC_CONNECTION_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), VNC_TYPE_CONNECTION, VncConnectionPrivate))
+
+
+struct _VncConnectionPrivate
{
GIOChannel *channel;
int fd;
@@ -178,6 +182,8 @@ struct _VncConnection
const guint8 const *keycode_map;
};
+G_DEFINE_TYPE(VncConnection, vnc_connection, G_TYPE_OBJECT);
+
#define nibhi(a) (((a) >> 4) & 0x0F)
#define niblo(a) ((a) & 0x0F)
@@ -296,51 +302,97 @@ static gboolean g_condition_wait(g_condition_wait_func func, gpointer data)
return TRUE;
}
+
+enum {
+ PROP_0,
+ PROP_FRAMEBUFFER,
+};
+
+
+static void vnc_connection_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ VncConnection *conn = VNC_CONNECTION(object);
+ VncConnectionPrivate *priv = conn->priv;
+
+ switch (prop_id) {
+ case PROP_FRAMEBUFFER:
+ g_value_set_object(value, priv->fb);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+static void vnc_connection_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ VncConnection *conn = VNC_CONNECTION(object);
+
+ switch (prop_id) {
+ case PROP_FRAMEBUFFER:
+ vnc_connection_set_framebuffer(conn, g_value_get_object(value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+
static gboolean vnc_connection_use_compression(VncConnection *conn)
{
- return conn->compressed_buffer != NULL;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->compressed_buffer != NULL;
}
static int vnc_connection_zread(VncConnection *conn, void *buffer, size_t size)
{
+ VncConnectionPrivate *priv = conn->priv;
char *ptr = buffer;
size_t offset = 0;
while (offset < size) {
/* if data is available in the uncompressed buffer, then
* copy */
- if (conn->uncompressed_length) {
- size_t len = MIN(conn->uncompressed_length,
+ if (priv->uncompressed_length) {
+ size_t len = MIN(priv->uncompressed_length,
size - offset);
memcpy(ptr + offset,
- conn->uncompressed_buffer,
+ priv->uncompressed_buffer,
len);
- conn->uncompressed_length -= len;
- if (conn->uncompressed_length)
- memmove(conn->uncompressed_buffer,
- conn->uncompressed_buffer + len,
- conn->uncompressed_length);
+ priv->uncompressed_length -= len;
+ if (priv->uncompressed_length)
+ memmove(priv->uncompressed_buffer,
+ priv->uncompressed_buffer + len,
+ priv->uncompressed_length);
offset += len;
} else {
int err;
- conn->strm->next_in = conn->compressed_buffer;
- conn->strm->avail_in = conn->compressed_length;
- conn->strm->next_out = conn->uncompressed_buffer;
- conn->strm->avail_out = sizeof(conn->uncompressed_buffer);
+ priv->strm->next_in = priv->compressed_buffer;
+ priv->strm->avail_in = priv->compressed_length;
+ priv->strm->next_out = priv->uncompressed_buffer;
+ priv->strm->avail_out = sizeof(priv->uncompressed_buffer);
/* inflate as much as possible */
- err = inflate(conn->strm, Z_SYNC_FLUSH);
+ err = inflate(priv->strm, Z_SYNC_FLUSH);
if (err != Z_OK) {
errno = EIO;
return -1;
}
- conn->uncompressed_length = (guint8 *)conn->strm->next_out - conn->uncompressed_buffer;
- conn->compressed_length -= (guint8 *)conn->strm->next_in - conn->compressed_buffer;
- conn->compressed_buffer = conn->strm->next_in;
+ priv->uncompressed_length = (guint8 *)priv->strm->next_out - priv->uncompressed_buffer;
+ priv->compressed_length -= (guint8 *)priv->strm->next_in - priv->compressed_buffer;
+ priv->compressed_buffer = priv->strm->next_in;
}
}
@@ -356,11 +408,12 @@ static int vnc_connection_zread(VncConnection *conn, void *buffer, size_t size)
*/
static int vnc_connection_read_wire(VncConnection *conn, void *data, size_t len)
{
+ VncConnectionPrivate *priv = conn->priv;
int ret;
reread:
- if (conn->tls_session) {
- ret = gnutls_read(conn->tls_session, data, len);
+ if (priv->tls_session) {
+ ret = gnutls_read(priv->tls_session, data, len);
if (ret < 0) {
if (ret == GNUTLS_E_AGAIN)
errno = EAGAIN;
@@ -369,31 +422,31 @@ static int vnc_connection_read_wire(VncConnection *conn, void *data, size_t len)
ret = -1;
}
} else
- ret = recv (conn->fd, data, len, 0);
+ ret = recv (priv->fd, data, len, 0);
if (ret == -1) {
switch (errno) {
case EWOULDBLOCK:
- if (conn->wait_interruptable) {
- if (!g_io_wait_interruptable(&conn->wait,
- conn->channel, G_IO_IN)) {
- GVNC_DEBUG("Read blocking interrupted %d", conn->has_error);
+ if (priv->wait_interruptable) {
+ if (!g_io_wait_interruptable(&priv->wait,
+ priv->channel, G_IO_IN)) {
+ GVNC_DEBUG("Read blocking interrupted %d", priv->has_error);
return -EAGAIN;
}
} else
- g_io_wait(conn->channel, G_IO_IN);
+ g_io_wait(priv->channel, G_IO_IN);
case EINTR:
goto reread;
default:
GVNC_DEBUG("Closing the connection: vnc_connection_read() - errno=%d", errno);
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return -errno;
}
}
if (ret == 0) {
GVNC_DEBUG("Closing the connection: vnc_connection_read() - ret=0");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return -EPIPE;
}
//GVNC_DEBUG("Read wire %p %d -> %d", data, len, ret);
@@ -409,10 +462,12 @@ static int vnc_connection_read_wire(VncConnection *conn, void *data, size_t len)
*/
static int vnc_connection_read_sasl(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
size_t want;
- //GVNC_DEBUG("Read SASL %p size %d offset %d", conn->saslDecoded,
- // conn->saslDecodedLength, conn->saslDecodedOffset);
- if (conn->saslDecoded == NULL) {
+
+ //GVNC_DEBUG("Read SASL %p size %d offset %d", priv->saslDecoded,
+ // priv->saslDecodedLength, priv->saslDecodedOffset);
+ if (priv->saslDecoded == NULL) {
char encoded[8192];
int encodedLen = sizeof(encoded);
int err, ret;
@@ -422,30 +477,30 @@ static int vnc_connection_read_sasl(VncConnection *conn)
return ret;
}
- err = sasl_decode(conn->saslconn, encoded, ret,
- &conn->saslDecoded, &conn->saslDecodedLength);
+ err = sasl_decode(priv->saslconn, encoded, ret,
+ &priv->saslDecoded, &priv->saslDecodedLength);
if (err != SASL_OK) {
GVNC_DEBUG("Failed to decode SASL data %s",
sasl_errstring(err, NULL, NULL));
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return -EINVAL;
}
- conn->saslDecodedOffset = 0;
+ priv->saslDecodedOffset = 0;
}
- want = conn->saslDecodedLength - conn->saslDecodedOffset;
- if (want > sizeof(conn->read_buffer))
- want = sizeof(conn->read_buffer);
+ want = priv->saslDecodedLength - priv->saslDecodedOffset;
+ if (want > sizeof(priv->read_buffer))
+ want = sizeof(priv->read_buffer);
- memcpy(conn->read_buffer,
- conn->saslDecoded + conn->saslDecodedOffset,
+ memcpy(priv->read_buffer,
+ priv->saslDecoded + priv->saslDecodedOffset,
want);
- conn->saslDecodedOffset += want;
- if (conn->saslDecodedOffset == conn->saslDecodedLength) {
- conn->saslDecodedLength = conn->saslDecodedOffset = 0;
- conn->saslDecoded = NULL;
+ priv->saslDecodedOffset += want;
+ if (priv->saslDecodedOffset == priv->saslDecodedLength) {
+ priv->saslDecodedLength = priv->saslDecodedOffset = 0;
+ priv->saslDecoded = NULL;
}
- //GVNC_DEBUG("Done read write %d - %d", want, conn->has_error);
+ //GVNC_DEBUG("Done read write %d - %d", want, priv->has_error);
return want;
}
#endif
@@ -457,8 +512,10 @@ static int vnc_connection_read_sasl(VncConnection *conn)
*/
static int vnc_connection_read_plain(VncConnection *conn)
{
- //GVNC_DEBUG("Read plain %d", sizeof(conn->read_buffer));
- return vnc_connection_read_wire(conn, conn->read_buffer, sizeof(conn->read_buffer));
+ VncConnectionPrivate *priv = conn->priv;
+
+ //GVNC_DEBUG("Read plain %d", sizeof(priv->read_buffer));
+ return vnc_connection_read_wire(conn, priv->read_buffer, sizeof(priv->read_buffer));
}
/*
@@ -466,9 +523,11 @@ static int vnc_connection_read_plain(VncConnection *conn)
*/
static int vnc_connection_read_buf(VncConnection *conn)
{
- //GVNC_DEBUG("Start read %d", conn->has_error);
+ VncConnectionPrivate *priv = conn->priv;
+
+ //GVNC_DEBUG("Start read %d", priv->has_error);
#if HAVE_SASL
- if (conn->saslconn)
+ if (priv->saslconn)
return vnc_connection_read_sasl(conn);
else
#endif
@@ -480,10 +539,11 @@ static int vnc_connection_read_buf(VncConnection *conn)
*/
static int vnc_connection_read(VncConnection *conn, void *data, size_t len)
{
+ VncConnectionPrivate *priv = conn->priv;
char *ptr = data;
size_t offset = 0;
- if (conn->has_error) return -EINVAL;
+ if (priv->has_error) return -EINVAL;
while (offset < len) {
size_t tmp;
@@ -494,25 +554,25 @@ static int vnc_connection_read(VncConnection *conn, void *data, size_t len)
int ret = vnc_connection_zread(conn, ptr + offset, len);
if (ret == -1) {
GVNC_DEBUG("Closing the connection: vnc_connection_read() - zread() failed");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return -errno;
}
offset += ret;
continue;
- } else if (conn->read_offset == conn->read_size) {
+ } else if (priv->read_offset == priv->read_size) {
int ret = vnc_connection_read_buf(conn);
if (ret < 0)
return ret;
- conn->read_offset = 0;
- conn->read_size = ret;
+ priv->read_offset = 0;
+ priv->read_size = ret;
}
- tmp = MIN(conn->read_size - conn->read_offset, len - offset);
+ tmp = MIN(priv->read_size - priv->read_offset, len - offset);
- memcpy(ptr + offset, conn->read_buffer + conn->read_offset, tmp);
+ memcpy(ptr + offset, priv->read_buffer + priv->read_offset, tmp);
- conn->read_offset += tmp;
+ priv->read_offset += tmp;
offset += tmp;
}
@@ -527,14 +587,15 @@ static void vnc_connection_flush_wire(VncConnection *conn,
const void *data,
size_t datalen)
{
+ VncConnectionPrivate *priv = conn->priv;
const char *ptr = data;
size_t offset = 0;
//GVNC_DEBUG("Flush write %p %d", data, datalen);
while (offset < datalen) {
int ret;
- if (conn->tls_session) {
- ret = gnutls_write(conn->tls_session,
+ if (priv->tls_session) {
+ ret = gnutls_write(priv->tls_session,
ptr+offset,
datalen-offset);
if (ret < 0) {
@@ -545,24 +606,24 @@ static void vnc_connection_flush_wire(VncConnection *conn,
ret = -1;
}
} else
- ret = send (conn->fd,
+ ret = send (priv->fd,
ptr+offset,
datalen-offset, 0);
if (ret == -1) {
switch (errno) {
case EWOULDBLOCK:
- g_io_wait(conn->channel, G_IO_OUT);
+ g_io_wait(priv->channel, G_IO_OUT);
case EINTR:
continue;
default:
GVNC_DEBUG("Closing the connection: vnc_connection_flush %d", errno);
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return;
}
}
if (ret == 0) {
GVNC_DEBUG("Closing the connection: vnc_connection_flush");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return;
}
offset += ret;
@@ -577,21 +638,22 @@ static void vnc_connection_flush_wire(VncConnection *conn,
*/
static void vnc_connection_flush_sasl(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
const char *output;
unsigned int outputlen;
int err;
- err = sasl_encode(conn->saslconn,
- conn->write_buffer,
- conn->write_offset,
+ err = sasl_encode(priv->saslconn,
+ priv->write_buffer,
+ priv->write_offset,
&output, &outputlen);
if (err != SASL_OK) {
GVNC_DEBUG("Failed to encode SASL data %s",
sasl_errstring(err, NULL, NULL));
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return;
}
- //GVNC_DEBUG("Flush SASL %d: %p %d", conn->write_offset, output, outputlen);
+ //GVNC_DEBUG("Flush SASL %d: %p %d", priv->write_offset, output, outputlen);
vnc_connection_flush_wire(conn, output, outputlen);
}
#endif
@@ -601,10 +663,12 @@ static void vnc_connection_flush_sasl(VncConnection *conn)
*/
static void vnc_connection_flush_plain(VncConnection *conn)
{
- //GVNC_DEBUG("Flush plain %d", conn->write_offset);
+ VncConnectionPrivate *priv = conn->priv;
+
+ //GVNC_DEBUG("Flush plain %d", priv->write_offset);
vnc_connection_flush_wire(conn,
- conn->write_buffer,
- conn->write_offset);
+ priv->write_buffer,
+ priv->write_offset);
}
@@ -613,33 +677,36 @@ static void vnc_connection_flush_plain(VncConnection *conn)
*/
static void vnc_connection_flush(VncConnection *conn)
{
- //GVNC_DEBUG("STart write %d", conn->has_error);
+ VncConnectionPrivate *priv = conn->priv;
+
+ //GVNC_DEBUG("STart write %d", priv->has_error);
#if HAVE_SASL
- if (conn->saslconn)
+ if (priv->saslconn)
vnc_connection_flush_sasl(conn);
else
#endif
vnc_connection_flush_plain(conn);
- conn->write_offset = 0;
+ priv->write_offset = 0;
}
static void vnc_connection_write(VncConnection *conn, const void *data, size_t len)
{
+ VncConnectionPrivate *priv = conn->priv;
const char *ptr = data;
size_t offset = 0;
while (offset < len) {
ssize_t tmp;
- if (conn->write_offset == sizeof(conn->write_buffer)) {
+ if (priv->write_offset == sizeof(priv->write_buffer)) {
vnc_connection_flush(conn);
}
- tmp = MIN(sizeof(conn->write_buffer), len - offset);
+ tmp = MIN(sizeof(priv->write_buffer), len - offset);
- memcpy(conn->write_buffer+conn->write_offset, ptr + offset, tmp);
+ memcpy(priv->write_buffer+priv->write_offset, ptr + offset, tmp);
- conn->write_offset += tmp;
+ priv->write_offset += tmp;
offset += tmp;
}
}
@@ -649,10 +716,11 @@ static ssize_t vnc_connection_tls_push(gnutls_transport_ptr_t transport,
const void *data,
size_t len) {
VncConnection *conn = transport;
+ VncConnectionPrivate *priv = conn->priv;
int ret;
retry:
- ret = write(conn->fd, data, len);
+ ret = write(priv->fd, data, len);
if (ret < 0) {
if (errno == EINTR)
goto retry;
@@ -666,10 +734,11 @@ static ssize_t vnc_connection_tls_pull(gnutls_transport_ptr_t transport,
void *data,
size_t len) {
VncConnection *conn = transport;
+ VncConnectionPrivate *priv = conn->priv;
int ret;
retry:
- ret = read(conn->fd, data, len);
+ ret = read(priv->fd, data, len);
if (ret < 0) {
if (errno == EINTR)
goto retry;
@@ -680,7 +749,9 @@ static ssize_t vnc_connection_tls_pull(gnutls_transport_ptr_t transport,
static size_t vnc_connection_pixel_size(VncConnection *conn)
{
- return conn->fmt.bits_per_pixel / 8;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->fmt.bits_per_pixel / 8;
}
static void vnc_connection_read_pixel(VncConnection *conn, guint8 *pixel)
@@ -697,11 +768,12 @@ static guint8 vnc_connection_read_u8(VncConnection *conn)
static int vnc_connection_read_u8_interruptable(VncConnection *conn, guint8 *value)
{
+ VncConnectionPrivate *priv = conn->priv;
int ret;
- conn->wait_interruptable = 1;
+ priv->wait_interruptable = 1;
ret = vnc_connection_read(conn, value, sizeof(*value));
- conn->wait_interruptable = 0;
+ priv->wait_interruptable = 0;
return ret;
}
@@ -801,6 +873,7 @@ static gnutls_anon_client_credentials vnc_connection_tls_initialize_anon_cred(vo
static gnutls_certificate_credentials_t vnc_connection_tls_initialize_cert_cred(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
gnutls_certificate_credentials_t x509_cred;
int ret;
@@ -808,9 +881,9 @@ static gnutls_certificate_credentials_t vnc_connection_tls_initialize_cert_cred(
GVNC_DEBUG("Cannot allocate credentials %s", gnutls_strerror(ret));
return NULL;
}
- if (conn->cred_x509_cacert) {
+ if (priv->cred_x509_cacert) {
if ((ret = gnutls_certificate_set_x509_trust_file(x509_cred,
- conn->cred_x509_cacert,
+ priv->cred_x509_cacert,
GNUTLS_X509_FMT_PEM)) < 0) {
GVNC_DEBUG("Cannot load CA certificate %s", gnutls_strerror(ret));
return NULL;
@@ -820,10 +893,10 @@ static gnutls_certificate_credentials_t vnc_connection_tls_initialize_cert_cred(
return NULL;
}
- if (conn->cred_x509_cert && conn->cred_x509_key) {
+ if (priv->cred_x509_cert && priv->cred_x509_key) {
if ((ret = gnutls_certificate_set_x509_key_file (x509_cred,
- conn->cred_x509_cert,
- conn->cred_x509_key,
+ priv->cred_x509_cert,
+ priv->cred_x509_key,
GNUTLS_X509_FMT_PEM)) < 0) {
GVNC_DEBUG("Cannot load certificate & key %s", gnutls_strerror(ret));
return NULL;
@@ -832,9 +905,9 @@ static gnutls_certificate_credentials_t vnc_connection_tls_initialize_cert_cred(
GVNC_DEBUG("No client cert or key provided");
}
- if (conn->cred_x509_cacrl) {
+ if (priv->cred_x509_cacrl) {
if ((ret = gnutls_certificate_set_x509_crl_file(x509_cred,
- conn->cred_x509_cacrl,
+ priv->cred_x509_cacrl,
GNUTLS_X509_FMT_PEM)) < 0) {
GVNC_DEBUG("Cannot load CRL %s", gnutls_strerror(ret));
return NULL;
@@ -850,6 +923,7 @@ static gnutls_certificate_credentials_t vnc_connection_tls_initialize_cert_cred(
static int vnc_connection_validate_certificate(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
int ret;
unsigned int status;
const gnutls_datum_t *certs;
@@ -857,7 +931,7 @@ static int vnc_connection_validate_certificate(VncConnection *conn)
time_t now;
GVNC_DEBUG("Validating");
- if ((ret = gnutls_certificate_verify_peers2 (conn->tls_session, &status)) < 0) {
+ if ((ret = gnutls_certificate_verify_peers2 (priv->tls_session, &status)) < 0) {
GVNC_DEBUG("Verify failed %s", gnutls_strerror(ret));
return FALSE;
}
@@ -884,10 +958,10 @@ static int vnc_connection_validate_certificate(VncConnection *conn)
GVNC_DEBUG("Certificate is valid.");
}
- if (gnutls_certificate_type_get(conn->tls_session) != GNUTLS_CRT_X509)
+ if (gnutls_certificate_type_get(priv->tls_session) != GNUTLS_CRT_X509)
return FALSE;
- if (!(certs = gnutls_certificate_get_peers(conn->tls_session, &nCerts)))
+ if (!(certs = gnutls_certificate_get_peers(priv->tls_session, &nCerts)))
return FALSE;
for (i = 0 ; i < nCerts ; i++) {
@@ -920,14 +994,14 @@ static int vnc_connection_validate_certificate(VncConnection *conn)
}
if (i == 0) {
- if (!conn->host) {
+ if (!priv->host) {
GVNC_DEBUG ("No hostname provided for certificate verification");
gnutls_x509_crt_deinit (cert);
return FALSE;
}
- if (!gnutls_x509_crt_check_hostname (cert, conn->host)) {
+ if (!gnutls_x509_crt_check_hostname (cert, priv->host)) {
GVNC_DEBUG ("The certificate's owner does not match hostname '%s'",
- conn->host);
+ priv->host);
gnutls_x509_crt_deinit (cert);
return FALSE;
}
@@ -969,12 +1043,15 @@ static void vnc_connection_read_pixel_format(VncConnection *conn, VncPixelFormat
gboolean vnc_connection_has_error(VncConnection *conn)
{
- return conn->has_error;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->has_error;
}
gboolean vnc_connection_set_pixel_format(VncConnection *conn,
const VncPixelFormat *fmt)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 pad[3] = {0};
vnc_connection_write_u8(conn, 0);
@@ -996,8 +1073,8 @@ gboolean vnc_connection_set_pixel_format(VncConnection *conn,
vnc_connection_write(conn, pad, 3);
vnc_connection_flush(conn);
- if (&conn->fmt != fmt)
- memcpy(&conn->fmt, fmt, sizeof(*fmt));
+ if (&priv->fmt != fmt)
+ memcpy(&priv->fmt, fmt, sizeof(*fmt));
return !vnc_connection_has_error(conn);
}
@@ -1005,11 +1082,14 @@ gboolean vnc_connection_set_pixel_format(VncConnection *conn,
const VncPixelFormat *vnc_connection_get_pixel_format(VncConnection *conn)
{
- return &conn->fmt;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return &priv->fmt;
}
gboolean vnc_connection_set_encodings(VncConnection *conn, int n_encoding, gint32 *encoding)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 pad[1] = {0};
int i, skip_zrle=0;
@@ -1026,16 +1106,16 @@ gboolean vnc_connection_set_encodings(VncConnection *conn, int n_encoding, gint3
* So we kill off ZRLE encoding for problematic pixel formats
*/
for (i = 0; i < n_encoding; i++)
- if (conn->fmt.depth == 32 &&
- (conn->fmt.red_max > 255 ||
- conn->fmt.blue_max > 255 ||
- conn->fmt.green_max > 255) &&
+ if (priv->fmt.depth == 32 &&
+ (priv->fmt.red_max > 255 ||
+ priv->fmt.blue_max > 255 ||
+ priv->fmt.green_max > 255) &&
encoding[i] == GVNC_ENCODING_ZRLE) {
GVNC_DEBUG("Dropping ZRLE encoding for broken pixel format");
skip_zrle++;
}
- conn->has_ext_key_event = FALSE;
+ priv->has_ext_key_event = FALSE;
vnc_connection_write_u8(conn, 2);
vnc_connection_write(conn, pad, 1);
vnc_connection_write_u16(conn, n_encoding - skip_zrle);
@@ -1066,20 +1146,21 @@ gboolean vnc_connection_framebuffer_update_request(VncConnection *conn,
static void vnc_connection_buffered_write(VncConnection *conn, const void *data, size_t size)
{
+ VncConnectionPrivate *priv = conn->priv;
size_t left;
- left = conn->xmit_buffer_capacity - conn->xmit_buffer_size;
+ left = priv->xmit_buffer_capacity - priv->xmit_buffer_size;
if (left < size) {
- conn->xmit_buffer_capacity += size + 4095;
- conn->xmit_buffer_capacity &= ~4095;
+ priv->xmit_buffer_capacity += size + 4095;
+ priv->xmit_buffer_capacity &= ~4095;
- conn->xmit_buffer = g_realloc(conn->xmit_buffer, conn->xmit_buffer_capacity);
+ priv->xmit_buffer = g_realloc(priv->xmit_buffer, priv->xmit_buffer_capacity);
}
- memcpy(&conn->xmit_buffer[conn->xmit_buffer_size],
+ memcpy(&priv->xmit_buffer[priv->xmit_buffer_size],
data, size);
- conn->xmit_buffer_size += size;
+ priv->xmit_buffer_size += size;
}
static void vnc_connection_buffered_write_u8(VncConnection *conn, guint8 value)
@@ -1101,17 +1182,20 @@ static void vnc_connection_buffered_write_u32(VncConnection *conn, guint32 value
static void vnc_connection_buffered_flush(VncConnection *conn)
{
- g_io_wakeup(&conn->wait);
+ VncConnectionPrivate *priv = conn->priv;
+
+ g_io_wakeup(&priv->wait);
}
gboolean vnc_connection_key_event(VncConnection *conn, guint8 down_flag,
guint32 key, guint16 scancode)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 pad[2] = {0};
- GVNC_DEBUG("Key event %d %d %d %d", key, scancode, down_flag, conn->has_ext_key_event);
- if (conn->has_ext_key_event) {
- scancode = x_keycode_to_pc_keycode(conn->keycode_map, scancode);
+ GVNC_DEBUG("Key event %d %d %d %d", key, scancode, down_flag, priv->has_ext_key_event);
+ if (priv->has_ext_key_event) {
+ scancode = x_keycode_to_pc_keycode(priv->keycode_map, scancode);
vnc_connection_buffered_write_u8(conn, 255);
vnc_connection_buffered_write_u8(conn, 0);
@@ -1156,10 +1240,11 @@ gboolean vnc_connection_client_cut_text(VncConnection *conn,
static inline guint8 *vnc_connection_get_local(VncConnection *conn, int x, int y)
{
- const VncPixelFormat *local = vnc_framebuffer_get_local_format(conn->fb);
- int rowstride = vnc_framebuffer_get_rowstride(conn->fb);
+ VncConnectionPrivate *priv = conn->priv;
+ const VncPixelFormat *local = vnc_framebuffer_get_local_format(priv->fb);
+ int rowstride = vnc_framebuffer_get_rowstride(priv->fb);
- return vnc_framebuffer_get_buffer(conn->fb) +
+ return vnc_framebuffer_get_buffer(priv->fb) +
(y * rowstride) +
(x * (local->bits_per_pixel / 8));
}
@@ -1173,7 +1258,9 @@ static guint8 vnc_connection_swap_rfb_8(VncConnection *conn G_GNUC_UNUSED, guint
/* VNC server RFB format -> local host native format */
static guint16 vnc_connection_swap_rfb_16(VncConnection *conn, guint16 pixel)
{
- if (conn->fbSwapRemote)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->fbSwapRemote)
return (((pixel >> 8) & 0xFF) << 0) |
(((pixel >> 0) & 0xFF) << 8);
else
@@ -1183,7 +1270,9 @@ static guint16 vnc_connection_swap_rfb_16(VncConnection *conn, guint16 pixel)
/* VNC server RFB format -> local host native format */
static guint32 vnc_connection_swap_rfb_32(VncConnection *conn, guint32 pixel)
{
- if (conn->fbSwapRemote)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->fbSwapRemote)
return (((pixel >> 24) & 0xFF) << 0) |
(((pixel >> 16) & 0xFF) << 8) |
(((pixel >> 8) & 0xFF) << 16) |
@@ -1271,31 +1360,33 @@ static void vnc_connection_raw_update(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
+
/* optimize for perfect match between server/client
FWIW, in the local case, we ought to be doing a write
directly from the source framebuffer and a read directly
into the client framebuffer
*/
- if (vnc_framebuffer_perfect_format_match(conn->fb)) {
+ if (vnc_framebuffer_perfect_format_match(priv->fb)) {
int i;
- int rowstride = vnc_framebuffer_get_rowstride(conn->fb);
- guint8 *dst = vnc_framebuffer_get_buffer(conn->fb);
+ int rowstride = vnc_framebuffer_get_rowstride(priv->fb);
+ guint8 *dst = vnc_framebuffer_get_buffer(priv->fb);
- dst += (y * rowstride) + (x * (conn->fmt.bits_per_pixel/8));
+ dst += (y * rowstride) + (x * (priv->fmt.bits_per_pixel/8));
for (i = 0; i < height; i++) {
vnc_connection_read(conn, dst,
- width * (conn->fmt.bits_per_pixel/8));
+ width * (priv->fmt.bits_per_pixel/8));
dst += rowstride;
}
} else {
guint8 *dst;
int i;
- dst = g_malloc(width * (conn->fmt.bits_per_pixel / 8));
+ dst = g_malloc(width * (priv->fmt.bits_per_pixel / 8));
for (i = 0; i < height; i++) {
- vnc_connection_read(conn, dst, width * (conn->fmt.bits_per_pixel / 8));
- vnc_framebuffer_blt(conn->fb, dst, 0, x, y + i, width, 1);
+ vnc_connection_read(conn, dst, width * (priv->fmt.bits_per_pixel / 8));
+ vnc_framebuffer_blt(priv->fb, dst, 0, x, y + i, width, 1);
}
g_free(dst);
}
@@ -1305,12 +1396,13 @@ static void vnc_connection_copyrect_update(VncConnection *conn,
guint16 dst_x, guint16 dst_y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
int src_x, src_y;
src_x = vnc_connection_read_u16(conn);
src_y = vnc_connection_read_u16(conn);
- vnc_framebuffer_copyrect(conn->fb,
+ vnc_framebuffer_copyrect(priv->fb,
src_x, src_y,
dst_x, dst_y,
width, height);
@@ -1322,6 +1414,7 @@ static void vnc_connection_hextile_rect(VncConnection *conn,
guint16 width, guint16 height,
guint8 *fg, guint8 *bg)
{
+ VncConnectionPrivate *priv = conn->priv;
int i;
if (flags & 0x01) {
@@ -1335,7 +1428,7 @@ static void vnc_connection_hextile_rect(VncConnection *conn,
if (flags & 0x04)
vnc_connection_read_pixel(conn, fg);
- vnc_framebuffer_fill(conn->fb, bg, x, y, width, height);
+ vnc_framebuffer_fill(priv->fb, bg, x, y, width, height);
/* AnySubrects */
if (flags & 0x08) {
@@ -1351,7 +1444,7 @@ static void vnc_connection_hextile_rect(VncConnection *conn,
xy = vnc_connection_read_u8(conn);
wh = vnc_connection_read_u8(conn);
- vnc_framebuffer_fill(conn->fb, fg,
+ vnc_framebuffer_fill(priv->fb, fg,
x + nibhi(xy), y + niblo(xy),
nibhi(wh) + 1, niblo(wh) + 1);
}
@@ -1388,13 +1481,14 @@ static void vnc_connection_rre_update(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 bg[4];
guint32 num;
guint32 i;
num = vnc_connection_read_u32(conn);
vnc_connection_read_pixel(conn, bg);
- vnc_framebuffer_fill(conn->fb, bg, x, y, width, height);
+ vnc_framebuffer_fill(priv->fb, bg, x, y, width, height);
for (i = 0; i < num; i++) {
guint8 fg[4];
@@ -1406,7 +1500,7 @@ static void vnc_connection_rre_update(VncConnection *conn,
sub_w = vnc_connection_read_u16(conn);
sub_h = vnc_connection_read_u16(conn);
- vnc_framebuffer_fill(conn->fb, fg,
+ vnc_framebuffer_fill(priv->fb, fg,
x + sub_x, y + sub_y, sub_w, sub_h);
}
}
@@ -1415,17 +1509,18 @@ static void vnc_connection_rre_update(VncConnection *conn,
* values. */
static void vnc_connection_read_cpixel(VncConnection *conn, guint8 *pixel)
{
+ VncConnectionPrivate *priv = conn->priv;
int bpp = vnc_connection_pixel_size(conn);
memset(pixel, 0, bpp);
- if (bpp == 4 && conn->fmt.true_color_flag) {
- int fitsInMSB = ((conn->fmt.red_shift > 7) &&
- (conn->fmt.green_shift > 7) &&
- (conn->fmt.blue_shift > 7));
- int fitsInLSB = (((conn->fmt.red_max << conn->fmt.red_shift) < (1 << 24)) &&
- ((conn->fmt.green_max << conn->fmt.green_shift) < (1 << 24)) &&
- ((conn->fmt.blue_max << conn->fmt.blue_shift) < (1 << 24)));
+ if (bpp == 4 && priv->fmt.true_color_flag) {
+ int fitsInMSB = ((priv->fmt.red_shift > 7) &&
+ (priv->fmt.green_shift > 7) &&
+ (priv->fmt.blue_shift > 7));
+ int fitsInLSB = (((priv->fmt.red_max << priv->fmt.red_shift) < (1 << 24)) &&
+ ((priv->fmt.green_max << priv->fmt.green_shift) < (1 << 24)) &&
+ ((priv->fmt.blue_max << priv->fmt.blue_shift) < (1 << 24)));
/*
* We need to analyse the shifts to see if they fit in 3 bytes,
@@ -1435,8 +1530,8 @@ static void vnc_connection_read_cpixel(VncConnection *conn, guint8 *pixel)
*/
if (fitsInMSB || fitsInLSB) {
bpp = 3;
- if (conn->fmt.depth == 24 &&
- conn->fmt.byte_order == G_BIG_ENDIAN)
+ if (priv->fmt.depth == 24 &&
+ priv->fmt.byte_order == G_BIG_ENDIAN)
pixel++;
}
}
@@ -1448,6 +1543,7 @@ static void vnc_connection_zrle_update_tile_blit(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 blit_data[4 * 64 * 64];
int i, bpp;
@@ -1456,26 +1552,27 @@ static void vnc_connection_zrle_update_tile_blit(VncConnection *conn,
for (i = 0; i < width * height; i++)
vnc_connection_read_cpixel(conn, blit_data + (i * bpp));
- vnc_framebuffer_blt(conn->fb, blit_data, width * bpp, x, y, width, height);
+ vnc_framebuffer_blt(priv->fb, blit_data, width * bpp, x, y, width, height);
}
static guint8 vnc_connection_read_zrle_pi(VncConnection *conn, int palette_size)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 pi = 0;
- if (conn->zrle_pi_bits == 0) {
- conn->zrle_pi = vnc_connection_read_u8(conn);
- conn->zrle_pi_bits = 8;
+ if (priv->zrle_pi_bits == 0) {
+ priv->zrle_pi = vnc_connection_read_u8(conn);
+ priv->zrle_pi_bits = 8;
}
if ( palette_size == 2) {
- pi = (conn->zrle_pi >> (conn->zrle_pi_bits - 1)) & 1;
- conn->zrle_pi_bits -= 1;
+ pi = (priv->zrle_pi >> (priv->zrle_pi_bits - 1)) & 1;
+ priv->zrle_pi_bits -= 1;
} else if ((palette_size == 3) || (palette_size == 4)) {
- pi = (conn->zrle_pi >> (conn->zrle_pi_bits - 2)) & 3;
- conn->zrle_pi_bits -= 2;
+ pi = (priv->zrle_pi >> (priv->zrle_pi_bits - 2)) & 3;
+ priv->zrle_pi_bits -= 2;
} else if ((palette_size >=5) && (palette_size <=16)){
- pi = (conn->zrle_pi >> (conn->zrle_pi_bits - 4)) & 15;
- conn->zrle_pi_bits -= 4;
+ pi = (priv->zrle_pi >> (priv->zrle_pi_bits - 4)) & 15;
+ priv->zrle_pi_bits -= 4;
}
return pi;
@@ -1486,6 +1583,7 @@ static void vnc_connection_zrle_update_tile_palette(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 palette[128][4];
int i, j;
@@ -1494,12 +1592,12 @@ static void vnc_connection_zrle_update_tile_palette(VncConnection *conn,
for (j = 0; j < height; j++) {
/* discard any padding bits */
- conn->zrle_pi_bits = 0;
+ priv->zrle_pi_bits = 0;
for (i = 0; i < width; i++) {
int ind = vnc_connection_read_zrle_pi(conn, palette_size);
- vnc_framebuffer_set_pixel_at(conn->fb, palette[ind & 0x7F],
+ vnc_framebuffer_set_pixel_at(priv->fb, palette[ind & 0x7F],
x + i, y + j);
}
}
@@ -1522,6 +1620,7 @@ static void vnc_connection_zrle_update_tile_rle(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
int i, j, rl = 0;
guint8 pixel[4];
@@ -1531,7 +1630,7 @@ static void vnc_connection_zrle_update_tile_rle(VncConnection *conn,
vnc_connection_read_cpixel(conn, pixel);
rl = vnc_connection_read_zrle_rl(conn);
}
- vnc_framebuffer_set_pixel_at(conn->fb, pixel, x + i, y + j);
+ vnc_framebuffer_set_pixel_at(priv->fb, pixel, x + i, y + j);
rl -= 1;
}
}
@@ -1542,6 +1641,7 @@ static void vnc_connection_zrle_update_tile_prle(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
int i, j, rl = 0;
guint8 palette[128][4];
guint8 pi = 0;
@@ -1560,7 +1660,7 @@ static void vnc_connection_zrle_update_tile_prle(VncConnection *conn,
rl = 1;
}
- vnc_framebuffer_set_pixel_at(conn->fb, palette[pi], x + i, y + j);
+ vnc_framebuffer_set_pixel_at(priv->fb, palette[pi], x + i, y + j);
rl -= 1;
}
}
@@ -1569,6 +1669,7 @@ static void vnc_connection_zrle_update_tile_prle(VncConnection *conn,
static void vnc_connection_zrle_update_tile(VncConnection *conn, guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 subencoding = vnc_connection_read_u8(conn);
guint8 pixel[4];
@@ -1578,7 +1679,7 @@ static void vnc_connection_zrle_update_tile(VncConnection *conn, guint16 x, guin
} else if (subencoding == 1) {
/* Solid tile of a single color */
vnc_connection_read_cpixel(conn, pixel);
- vnc_framebuffer_fill(conn->fb, pixel, x, y, width, height);
+ vnc_framebuffer_fill(priv->fb, pixel, x, y, width, height);
} else if ((subencoding >= 2) && (subencoding <= 16)) {
/* Packed palette types */
vnc_connection_zrle_update_tile_palette(conn, subencoding,
@@ -1601,6 +1702,7 @@ static void vnc_connection_zrle_update(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint32 length;
guint32 offset;
guint16 i, j;
@@ -1611,10 +1713,10 @@ static void vnc_connection_zrle_update(VncConnection *conn,
vnc_connection_read(conn, zlib_data, length);
/* setup subsequent calls to vnc_connection_read*() to use the compressed data */
- conn->uncompressed_length = 0;
- conn->compressed_length = length;
- conn->compressed_buffer = zlib_data;
- conn->strm = &conn->streams[0];
+ priv->uncompressed_length = 0;
+ priv->compressed_length = length;
+ priv->compressed_buffer = zlib_data;
+ priv->strm = &priv->streams[0];
offset = 0;
for (j = 0; j < height; j += 64) {
@@ -1627,10 +1729,10 @@ static void vnc_connection_zrle_update(VncConnection *conn,
}
}
- conn->strm = NULL;
- conn->uncompressed_length = 0;
- conn->compressed_length = 0;
- conn->compressed_buffer = NULL;
+ priv->strm = NULL;
+ priv->uncompressed_length = 0;
+ priv->compressed_length = 0;
+ priv->compressed_buffer = NULL;
g_free(zlib_data);
}
@@ -1658,21 +1760,25 @@ static guint32 vnc_connection_read_cint(VncConnection *conn)
static int vnc_connection_tpixel_size(VncConnection *conn)
{
- if (conn->fmt.depth == 24)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->fmt.depth == 24)
return 3;
- return conn->fmt.bits_per_pixel / 8;
+ return priv->fmt.bits_per_pixel / 8;
}
static void vnc_connection_read_tpixel(VncConnection *conn, guint8 *pixel)
{
- if (conn->fmt.depth == 24) {
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->fmt.depth == 24) {
uint32_t val;
vnc_connection_read(conn, pixel, 3);
- val = (pixel[0] << conn->fmt.red_shift)
- | (pixel[1] << conn->fmt.green_shift)
- | (pixel[2] << conn->fmt.blue_shift);
+ val = (pixel[0] << priv->fmt.red_shift)
+ | (pixel[1] << priv->fmt.green_shift)
+ | (pixel[2] << priv->fmt.blue_shift);
- if (conn->fmt.byte_order != G_BYTE_ORDER)
+ if (priv->fmt.byte_order != G_BYTE_ORDER)
val = (((val >> 0) & 0xFF) << 24) |
(((val >> 8) & 0xFF) << 16) |
(((val >> 16) & 0xFF) << 8) |
@@ -1687,13 +1793,14 @@ static void vnc_connection_tight_update_copy(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 pixel[4];
int i, j;
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
vnc_connection_read_tpixel(conn, pixel);
- vnc_framebuffer_set_pixel_at(conn->fb, pixel, x + i, y + j);
+ vnc_framebuffer_set_pixel_at(priv->fb, pixel, x + i, y + j);
}
}
}
@@ -1715,6 +1822,7 @@ static void vnc_connection_tight_update_palette(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
int i, j;
for (j = 0; j < height; j++) {
@@ -1724,7 +1832,7 @@ static void vnc_connection_tight_update_palette(VncConnection *conn,
guint8 ind;
ind = vnc_connection_tight_get_pi(conn, &ra, i, palette_size);
- vnc_framebuffer_set_pixel_at(conn->fb, &palette[ind * 4], x + i, y + j);
+ vnc_framebuffer_set_pixel_at(priv->fb, &palette[ind * 4], x + i, y + j);
}
}
}
@@ -1733,13 +1841,17 @@ static void vnc_connection_tight_compute_predicted(VncConnection *conn, guint8 *
guint8 *lp, guint8 *cp,
guint8 *llp)
{
- conn->tight_compute_predicted(conn, ppixel, lp, cp, llp);
+ VncConnectionPrivate *priv = conn->priv;
+
+ priv->tight_compute_predicted(conn, ppixel, lp, cp, llp);
}
static void vnc_connection_tight_sum_pixel(VncConnection *conn,
guint8 *lhs, guint8 *rhs)
{
- conn->tight_sum_pixel(conn, lhs, rhs);
+ VncConnectionPrivate *priv = conn->priv;
+
+ priv->tight_sum_pixel(conn, lhs, rhs);
}
static void vnc_connection_tight_update_gradient(VncConnection *conn,
@@ -1750,6 +1862,7 @@ static void vnc_connection_tight_update_gradient(VncConnection *conn,
guint8 zero_pixel[4];
guint8 *last_row, *row;
int bpp;
+ VncConnectionPrivate *priv = conn->priv;
bpp = vnc_connection_pixel_size(conn);
last_row = g_malloc(width * bpp);
@@ -1787,7 +1900,7 @@ static void vnc_connection_tight_update_gradient(VncConnection *conn,
}
/* write out row of pixel data */
- vnc_framebuffer_blt(conn->fb, row, width * bpp, x, y + j, width, 1);
+ vnc_framebuffer_blt(priv->fb, row, width * bpp, x, y + j, width, 1);
/* swap last row and current row */
tmp_row = last_row;
@@ -1803,18 +1916,21 @@ static void jpeg_draw(void *opaque, int x, int y, int w, int h,
guint8 *data, int stride)
{
VncConnection *conn = opaque;
+ VncConnectionPrivate *priv = conn->priv;
- vnc_framebuffer_rgb24_blt(conn->fb, data, stride, x, y, w, h);
+ vnc_framebuffer_rgb24_blt(priv->fb, data, stride, x, y, w, h);
}
static void vnc_connection_tight_update_jpeg(VncConnection *conn, guint16 x, guint16 y,
guint16 width, guint16 height,
guint8 *data, size_t length)
{
- if (conn->ops.render_jpeg == NULL)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->ops.render_jpeg == NULL)
return;
- conn->ops.render_jpeg(conn->ops_data, jpeg_draw, conn,
+ priv->ops.render_jpeg(priv->ops_data, jpeg_draw, conn,
x, y, width, height, data, length);
}
@@ -1822,6 +1938,7 @@ static void vnc_connection_tight_update(VncConnection *conn,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 ccontrol;
guint8 pixel[4];
int i;
@@ -1830,8 +1947,8 @@ static void vnc_connection_tight_update(VncConnection *conn,
for (i = 0; i < 4; i++) {
if (ccontrol & (1 << i)) {
- inflateEnd(&conn->streams[i + 1]);
- inflateInit(&conn->streams[i + 1]);
+ inflateEnd(&priv->streams[i + 1]);
+ inflateInit(&priv->streams[i + 1]);
}
}
@@ -1849,7 +1966,7 @@ static void vnc_connection_tight_update(VncConnection *conn,
if (ccontrol & 0x04)
filter_id = vnc_connection_read_u8(conn);
- conn->strm = &conn->streams[(ccontrol & 0x03) + 1];
+ priv->strm = &priv->streams[(ccontrol & 0x03) + 1];
if (filter_id == 1) {
palette_size = vnc_connection_read_u8(conn);
@@ -1872,9 +1989,9 @@ static void vnc_connection_tight_update(VncConnection *conn,
vnc_connection_read(conn, zlib_data, zlib_length);
- conn->uncompressed_length = 0;
- conn->compressed_length = zlib_length;
- conn->compressed_buffer = zlib_data;
+ priv->uncompressed_length = 0;
+ priv->compressed_length = zlib_length;
+ priv->compressed_buffer = zlib_data;
}
switch (filter_id) {
@@ -1891,24 +2008,24 @@ static void vnc_connection_tight_update(VncConnection *conn,
break;
default: /* error */
GVNC_DEBUG("Closing the connection: vnc_connection_tight_update() - filter_id unknown");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
break;
}
if (data_size >= 12) {
- conn->uncompressed_length = 0;
- conn->compressed_length = 0;
- conn->compressed_buffer = NULL;
+ priv->uncompressed_length = 0;
+ priv->compressed_length = 0;
+ priv->compressed_buffer = NULL;
g_free(zlib_data);
}
- conn->strm = NULL;
+ priv->strm = NULL;
} else if (ccontrol == 8) {
/* fill */
/* FIXME check each width; endianness */
vnc_connection_read_tpixel(conn, pixel);
- vnc_framebuffer_fill(conn->fb, pixel, x, y, width, height);
+ vnc_framebuffer_fill(priv->fb, pixel, x, y, width, height);
} else if (ccontrol == 9) {
/* jpeg */
guint32 length;
@@ -1923,18 +2040,20 @@ static void vnc_connection_tight_update(VncConnection *conn,
} else {
/* error */
GVNC_DEBUG("Closing the connection: vnc_connection_tight_update() - ccontrol unknown");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
}
static void vnc_connection_update(VncConnection *conn, int x, int y, int width, int height)
{
- if (conn->has_error || !conn->ops.update)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->has_error || !priv->ops.update)
return;
GVNC_DEBUG("Notify update area (%dx%d) at location %d,%d", width, height, x, y);
- if (!conn->ops.update(conn->ops_data, x, y, width, height)) {
+ if (!priv->ops.update(priv->ops_data, x, y, width, height)) {
GVNC_DEBUG("Closing the connection: vnc_connection_update");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
}
@@ -1942,72 +2061,84 @@ static void vnc_connection_set_color_map_entry(VncConnection *conn, guint16 colo
guint16 red, guint16 green,
guint16 blue)
{
- if (conn->has_error || !conn->ops.set_color_map_entry)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->has_error || !priv->ops.set_color_map_entry)
return;
- if (!conn->ops.set_color_map_entry(conn->ops_data, color,
+ if (!priv->ops.set_color_map_entry(priv->ops_data, color,
red, green, blue)) {
GVNC_DEBUG("Closing the connection: vnc_connection_set_color_map_entry");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
}
static void vnc_connection_bell(VncConnection *conn)
{
- if (conn->has_error || !conn->ops.bell)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->has_error || !priv->ops.bell)
return;
GVNC_DEBUG("Server beep");
- if (!conn->ops.bell(conn->ops_data)) {
+ if (!priv->ops.bell(priv->ops_data)) {
GVNC_DEBUG("Closing the connection: vnc_connection_bell");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
}
static void vnc_connection_server_cut_text(VncConnection *conn, const void *data,
size_t len)
{
- if (conn->has_error || !conn->ops.server_cut_text)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->has_error || !priv->ops.server_cut_text)
return;
- if (!conn->ops.server_cut_text(conn->ops_data, data, len)) {
+ if (!priv->ops.server_cut_text(priv->ops_data, data, len)) {
GVNC_DEBUG("Closing the connection: vnc_connection_server_cut_text");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
}
static void vnc_connection_resize(VncConnection *conn, int width, int height)
{
- if (conn->has_error)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->has_error)
return;
- conn->width = width;
- conn->height = height;
+ priv->width = width;
+ priv->height = height;
- if (!conn->ops.resize)
+ if (!priv->ops.resize)
return;
- if (!conn->ops.resize(conn->ops_data, width, height)) {
+ if (!priv->ops.resize(priv->ops_data, width, height)) {
GVNC_DEBUG("Closing the connection: vnc_connection_resize");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
}
static void vnc_connection_pixel_format(VncConnection *conn)
{
- if (conn->has_error || !conn->ops.pixel_format)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->has_error || !priv->ops.pixel_format)
return;
- if (!conn->ops.pixel_format(conn->ops_data, &conn->fmt))
- conn->has_error = TRUE;
+ if (!priv->ops.pixel_format(priv->ops_data, &priv->fmt))
+ priv->has_error = TRUE;
}
static void vnc_connection_pointer_type_change(VncConnection *conn, int absolute)
{
- if (conn->has_error || !conn->ops.pointer_type_change)
+ VncConnectionPrivate *priv = conn->priv;
+
+ if (priv->has_error || !priv->ops.pointer_type_change)
return;
- if (!conn->ops.pointer_type_change(conn->ops_data, absolute)) {
+ if (!priv->ops.pointer_type_change(priv->ops_data, absolute)) {
GVNC_DEBUG("Closing the connection: vnc_connection_pointer_type_change");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
}
@@ -2015,18 +2146,21 @@ static void vnc_connection_rich_cursor_blt(VncConnection *conn, guint8 *pixbuf,
guint8 *image, guint8 *mask,
int pitch, guint16 width, guint16 height)
{
- conn->rich_cursor_blt(conn, pixbuf, image, mask, pitch, width, height);
+ VncConnectionPrivate *priv = conn->priv;
+
+ priv->rich_cursor_blt(conn, pixbuf, image, mask, pitch, width, height);
}
static void vnc_connection_rich_cursor(VncConnection *conn, int x, int y, int width, int height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 *pixbuf = NULL;
if (width && height) {
guint8 *image, *mask;
int imagelen, masklen;
- imagelen = width * height * (conn->fmt.bits_per_pixel / 8);
+ imagelen = width * height * (priv->fmt.bits_per_pixel / 8);
masklen = ((width + 7)/8) * height;
image = g_malloc(imagelen);
@@ -2037,18 +2171,18 @@ static void vnc_connection_rich_cursor(VncConnection *conn, int x, int y, int wi
vnc_connection_read(conn, mask, masklen);
vnc_connection_rich_cursor_blt(conn, pixbuf, image, mask,
- width * (conn->fmt.bits_per_pixel/8),
+ width * (priv->fmt.bits_per_pixel/8),
width, height);
g_free(image);
g_free(mask);
}
- if (conn->has_error || !conn->ops.local_cursor)
+ if (priv->has_error || !priv->ops.local_cursor)
return;
- if (!conn->ops.local_cursor(conn->ops_data, x, y, width, height, pixbuf)) {
+ if (!priv->ops.local_cursor(priv->ops_data, x, y, width, height, pixbuf)) {
GVNC_DEBUG("Closing the connection: vnc_connection_rich_cursor() - !ops.local_cursor()");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
g_free(pixbuf);
@@ -2056,6 +2190,7 @@ static void vnc_connection_rich_cursor(VncConnection *conn, int x, int y, int wi
static void vnc_connection_xcursor(VncConnection *conn, int x, int y, int width, int height)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 *pixbuf = NULL;
if (width && height) {
@@ -2092,11 +2227,11 @@ static void vnc_connection_xcursor(VncConnection *conn, int x, int y, int width,
g_free(mask);
}
- if (conn->has_error || !conn->ops.local_cursor)
+ if (priv->has_error || !priv->ops.local_cursor)
return;
- if (!conn->ops.local_cursor(conn->ops_data, x, y, width, height, pixbuf)) {
+ if (!priv->ops.local_cursor(priv->ops_data, x, y, width, height, pixbuf)) {
GVNC_DEBUG("Closing the connection: vnc_connection_xcursor() - !ops.local_cursor()");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
}
g_free(pixbuf);
@@ -2104,14 +2239,18 @@ static void vnc_connection_xcursor(VncConnection *conn, int x, int y, int width,
static void vnc_connection_ext_key_event(VncConnection *conn)
{
- conn->has_ext_key_event = TRUE;
- conn->keycode_map = x_keycode_to_pc_keycode_map();
+ VncConnectionPrivate *priv = conn->priv;
+
+ priv->has_ext_key_event = TRUE;
+ priv->keycode_map = x_keycode_to_pc_keycode_map();
}
static void vnc_connection_framebuffer_update(VncConnection *conn, gint32 etype,
guint16 x, guint16 y,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("FramebufferUpdate type=%d area (%dx%d) at location %d,%d",
etype, width, height, x, y);
@@ -2148,7 +2287,7 @@ static void vnc_connection_framebuffer_update(VncConnection *conn, gint32 etype,
vnc_connection_pointer_type_change(conn, x);
break;
case GVNC_ENCODING_WMVi:
- vnc_connection_read_pixel_format(conn, &conn->fmt);
+ vnc_connection_read_pixel_format(conn, &priv->fmt);
vnc_connection_pixel_format(conn);
break;
case GVNC_ENCODING_RICH_CURSOR:
@@ -2162,13 +2301,14 @@ static void vnc_connection_framebuffer_update(VncConnection *conn, gint32 etype,
break;
default:
GVNC_DEBUG("Received an unknown encoding type: %d", etype);
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
break;
}
}
gboolean vnc_connection_server_message(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 msg;
int ret;
@@ -2176,10 +2316,10 @@ gboolean vnc_connection_server_message(VncConnection *conn)
handle has_error appropriately */
do {
- if (conn->xmit_buffer_size) {
- vnc_connection_write(conn, conn->xmit_buffer, conn->xmit_buffer_size);
+ if (priv->xmit_buffer_size) {
+ vnc_connection_write(conn, priv->xmit_buffer, priv->xmit_buffer_size);
vnc_connection_flush(conn);
- conn->xmit_buffer_size = 0;
+ priv->xmit_buffer_size = 0;
}
} while ((ret = vnc_connection_read_u8_interruptable(conn, &msg)) == -EAGAIN);
@@ -2243,14 +2383,14 @@ gboolean vnc_connection_server_message(VncConnection *conn)
n_text = vnc_connection_read_u32(conn);
if (n_text > (32 << 20)) {
GVNC_DEBUG("Closing the connection: vnc_connection_server_message() - cutText > allowed");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
break;
}
data = g_new(char, n_text + 1);
if (data == NULL) {
GVNC_DEBUG("Closing the connection: vnc_connection_server_message() - cutText - !data");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
break;
}
@@ -2262,7 +2402,7 @@ gboolean vnc_connection_server_message(VncConnection *conn)
} break;
default:
GVNC_DEBUG("Received an unknown message: %u", msg);
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
break;
}
@@ -2271,28 +2411,35 @@ gboolean vnc_connection_server_message(VncConnection *conn)
gboolean vnc_connection_wants_credential_password(VncConnection *conn)
{
- return conn->want_cred_password;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->want_cred_password;
}
gboolean vnc_connection_wants_credential_username(VncConnection *conn)
{
- return conn->want_cred_username;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->want_cred_username;
}
gboolean vnc_connection_wants_credential_x509(VncConnection *conn)
{
- return conn->want_cred_x509;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->want_cred_x509;
}
static gboolean vnc_connection_has_credentials(gpointer data)
{
VncConnection *conn = data;
+ VncConnectionPrivate *priv = conn->priv;
- if (conn->has_error)
+ if (priv->has_error)
return TRUE;
- if (vnc_connection_wants_credential_username(conn) && !conn->cred_username)
+ if (vnc_connection_wants_credential_username(conn) && !priv->cred_username)
return FALSE;
- if (vnc_connection_wants_credential_password(conn) && !conn->cred_password)
+ if (vnc_connection_wants_credential_password(conn) && !priv->cred_password)
return FALSE;
/*
* For x509 we require a minimum of the CA cert.
@@ -2302,22 +2449,24 @@ static gboolean vnc_connection_has_credentials(gpointer data)
* alone though - we'll merely find out when TLS
* negotiation takes place.
*/
- if (vnc_connection_wants_credential_x509(conn) && !conn->cred_x509_cacert)
+ if (vnc_connection_wants_credential_x509(conn) && !priv->cred_x509_cacert)
return FALSE;
return TRUE;
}
static gboolean vnc_connection_gather_credentials(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
+
if (!vnc_connection_has_credentials(conn)) {
GVNC_DEBUG("Requesting missing credentials");
- if (conn->has_error || !conn->ops.auth_cred) {
- conn->has_error = TRUE;
+ if (priv->has_error || !priv->ops.auth_cred) {
+ priv->has_error = TRUE;
return FALSE;
}
- if (!conn->ops.auth_cred(conn->ops_data))
- conn->has_error = TRUE;
- if (conn->has_error)
+ if (!priv->ops.auth_cred(priv->ops_data))
+ priv->has_error = TRUE;
+ if (priv->has_error)
return FALSE;
GVNC_DEBUG("Waiting for missing credentials");
g_condition_wait(vnc_connection_has_credentials, conn);
@@ -2329,7 +2478,9 @@ static gboolean vnc_connection_gather_credentials(VncConnection *conn)
static gboolean vnc_connection_check_auth_result(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
guint32 result;
+
GVNC_DEBUG("Checking auth result");
result = vnc_connection_read_u32(conn);
if (!result) {
@@ -2337,7 +2488,7 @@ static gboolean vnc_connection_check_auth_result(VncConnection *conn)
return TRUE;
}
- if (conn->minor >= 8) {
+ if (priv->minor >= 8) {
guint32 len;
char reason[1024];
len = vnc_connection_read_u32(conn);
@@ -2346,35 +2497,36 @@ static gboolean vnc_connection_check_auth_result(VncConnection *conn)
vnc_connection_read(conn, reason, len);
reason[len] = '\0';
GVNC_DEBUG("Fail %s", reason);
- if (!conn->has_error && conn->ops.auth_failure)
- conn->ops.auth_failure(conn->ops_data, reason);
+ if (!priv->has_error && priv->ops.auth_failure)
+ priv->ops.auth_failure(priv->ops_data, reason);
} else {
GVNC_DEBUG("Fail auth no result");
- if (!conn->has_error && conn->ops.auth_failure)
- conn->ops.auth_failure(conn->ops_data, NULL);
+ if (!priv->has_error && priv->ops.auth_failure)
+ priv->ops.auth_failure(priv->ops_data, NULL);
}
return FALSE;
}
static gboolean vnc_connection_perform_auth_vnc(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
guint8 challenge[16];
guint8 key[8];
GVNC_DEBUG("Do Challenge");
- conn->want_cred_password = TRUE;
- conn->want_cred_username = FALSE;
- conn->want_cred_x509 = FALSE;
+ priv->want_cred_password = TRUE;
+ priv->want_cred_username = FALSE;
+ priv->want_cred_x509 = FALSE;
if (!vnc_connection_gather_credentials(conn))
return FALSE;
- if (!conn->cred_password)
+ if (!priv->cred_password)
return FALSE;
vnc_connection_read(conn, challenge, 16);
memset(key, 0, 8);
- strncpy((char*)key, (char*)conn->cred_password, 8);
+ strncpy((char*)key, (char*)priv->cred_password, 8);
deskey(key, EN0);
des(challenge, challenge);
@@ -2391,7 +2543,8 @@ static gboolean vnc_connection_perform_auth_vnc(VncConnection *conn)
* Key has to be 8 bytes, length a multiple of 8 bytes.
*/
static void
-vncEncryptBytes2(unsigned char *where, const int length, unsigned char *key) {
+vncEncryptBytes2(unsigned char *where, const int length, unsigned char *key)
+{
int i, j;
deskey(key, EN0);
for (i = 0; i< 8; i++)
@@ -2406,6 +2559,7 @@ vncEncryptBytes2(unsigned char *where, const int length, unsigned char *key) {
static gboolean vnc_connection_perform_auth_mslogon(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
struct vnc_dh *dh;
guchar gen[8], mod[8], resp[8], pub[8], key[8];
gcry_mpi_t genmpi, modmpi, respmpi, pubmpi, keympi;
@@ -2413,9 +2567,9 @@ static gboolean vnc_connection_perform_auth_mslogon(VncConnection *conn)
guint passwordLen, usernameLen;
GVNC_DEBUG("Do Challenge");
- conn->want_cred_password = TRUE;
- conn->want_cred_username = TRUE;
- conn->want_cred_x509 = FALSE;
+ priv->want_cred_password = TRUE;
+ priv->want_cred_username = TRUE;
+ priv->want_cred_x509 = FALSE;
if (!vnc_connection_gather_credentials(conn))
return FALSE;
@@ -2437,8 +2591,8 @@ static gboolean vnc_connection_perform_auth_mslogon(VncConnection *conn)
keympi = vnc_dh_gen_key(dh, respmpi);
vnc_mpi_to_bytes(keympi, key);
- passwordLen = strlen(conn->cred_password);
- usernameLen = strlen(conn->cred_username);
+ passwordLen = strlen(priv->cred_password);
+ usernameLen = strlen(priv->cred_username);
if (passwordLen > sizeof(password))
passwordLen = sizeof(password);
if (usernameLen > sizeof(username))
@@ -2446,8 +2600,8 @@ static gboolean vnc_connection_perform_auth_mslogon(VncConnection *conn)
memset(password, 0, sizeof password);
memset(username, 0, sizeof username);
- memcpy(password, conn->cred_password, passwordLen);
- memcpy(username, conn->cred_username, usernameLen);
+ memcpy(password, priv->cred_password, passwordLen);
+ memcpy(username, priv->cred_username, usernameLen);
vncEncryptBytes2(username, sizeof(username), key);
vncEncryptBytes2(password, sizeof(password), key);
@@ -2496,21 +2650,22 @@ static gboolean
vnc_connection_gather_sasl_credentials(VncConnection *conn,
sasl_interact_t *interact)
{
+ VncConnectionPrivate *priv = conn->priv;
int ninteract;
- conn->want_cred_password = FALSE;
- conn->want_cred_username = FALSE;
- conn->want_cred_x509 = FALSE;
+ priv->want_cred_password = FALSE;
+ priv->want_cred_username = FALSE;
+ priv->want_cred_x509 = FALSE;
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++) {
switch (interact[ninteract].id) {
case SASL_CB_AUTHNAME:
case SASL_CB_USER:
- conn->want_cred_username = TRUE;
+ priv->want_cred_username = TRUE;
break;
case SASL_CB_PASS:
- conn->want_cred_password = TRUE;
+ priv->want_cred_password = TRUE;
break;
default:
@@ -2521,8 +2676,8 @@ vnc_connection_gather_sasl_credentials(VncConnection *conn,
}
}
- if ((conn->want_cred_password ||
- conn->want_cred_username) &&
+ if ((priv->want_cred_password ||
+ priv->want_cred_username) &&
!vnc_connection_gather_credentials(conn)) {
GVNC_DEBUG("%s", "cannot gather sasl credentials");
return FALSE;
@@ -2532,15 +2687,15 @@ vnc_connection_gather_sasl_credentials(VncConnection *conn,
switch (interact[ninteract].id) {
case SASL_CB_AUTHNAME:
case SASL_CB_USER:
- interact[ninteract].result = conn->cred_username;
- interact[ninteract].len = strlen(conn->cred_username);
- GVNC_DEBUG("Gather Username %s", conn->cred_username);
+ interact[ninteract].result = priv->cred_username;
+ interact[ninteract].len = strlen(priv->cred_username);
+ GVNC_DEBUG("Gather Username %s", priv->cred_username);
break;
case SASL_CB_PASS:
- interact[ninteract].result = conn->cred_password;
- interact[ninteract].len = strlen(conn->cred_password);
- //GVNC_DEBUG("Gather Password %s", conn->cred_password);
+ interact[ninteract].result = priv->cred_password;
+ interact[ninteract].len = strlen(priv->cred_password);
+ //GVNC_DEBUG("Gather Password %s", priv->cred_password);
break;
}
}
@@ -2592,6 +2747,7 @@ vnc_connection_gather_sasl_credentials(VncConnection *conn,
*/
static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
sasl_conn_t *saslconn = NULL;
sasl_security_properties_t secprops;
const char *clientout;
@@ -2626,7 +2782,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
/* Get local address in form IPADDR:PORT */
salen = sizeof(sa);
- if (getsockname(conn->fd, (struct sockaddr*)&sa, &salen) < 0) {
+ if (getsockname(priv->fd, (struct sockaddr*)&sa, &salen) < 0) {
GVNC_DEBUG("failed to get sock address %d (%s)",
errno, strerror(errno));
goto error;
@@ -2638,7 +2794,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
/* Get remote address in form IPADDR:PORT */
salen = sizeof(sa);
- if (getpeername(conn->fd, (struct sockaddr*)&sa, &salen) < 0) {
+ if (getpeername(priv->fd, (struct sockaddr*)&sa, &salen) < 0) {
GVNC_DEBUG("failed to get peer address %d (%s)",
errno, strerror(errno));
g_free(localAddr);
@@ -2651,11 +2807,11 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
goto error;
}
- GVNC_DEBUG("Client SASL new host:'%s' local:'%s' remote:'%s'", conn->host, localAddr, remoteAddr);
+ GVNC_DEBUG("Client SASL new host:'%s' local:'%s' remote:'%s'", priv->host, localAddr, remoteAddr);
/* Setup a handle for being a client */
err = sasl_client_new("vnc",
- conn->host,
+ priv->host,
localAddr,
remoteAddr,
saslcb,
@@ -2671,10 +2827,10 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
}
/* Initialize some connection props we care about */
- if (conn->tls_session) {
+ if (priv->tls_session) {
gnutls_cipher_algorithm_t cipher;
- cipher = gnutls_cipher_get(conn->tls_session);
+ cipher = gnutls_cipher_get(priv->tls_session);
if (!(ssf = (sasl_ssf_t)gnutls_cipher_get_key_size(cipher))) {
GVNC_DEBUG("%s", "invalid cipher size for TLS session");
goto error;
@@ -2692,11 +2848,11 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
memset (&secprops, 0, sizeof secprops);
/* If we've got TLS, we don't care about SSF */
- secprops.min_ssf = conn->tls_session ? 0 : 56; /* Equiv to DES supported by all Kerberos */
- secprops.max_ssf = conn->tls_session ? 0 : 100000; /* Very strong ! AES == 256 */
+ secprops.min_ssf = priv->tls_session ? 0 : 56; /* Equiv to DES supported by all Kerberos */
+ secprops.max_ssf = priv->tls_session ? 0 : 100000; /* Very strong ! AES == 256 */
secprops.maxbufsize = 100000;
/* If we're not TLS, then forbid any anonymous or trivially crackable auth */
- secprops.security_flags = conn->tls_session ? 0 :
+ secprops.security_flags = priv->tls_session ? 0 :
SASL_SEC_NOANONYMOUS | SASL_SEC_NOPLAINTEXT;
err = sasl_setprop(saslconn, SASL_SEC_PROPS, &secprops);
@@ -2708,7 +2864,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
/* Get the supported mechanisms from the server */
mechlistlen = vnc_connection_read_u32(conn);
- if (conn->has_error)
+ if (priv->has_error)
goto error;
if (mechlistlen > SASL_MAX_MECHLIST_LEN) {
GVNC_DEBUG("mechlistlen %d too long", mechlistlen);
@@ -2718,7 +2874,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
mechlist = g_malloc(mechlistlen+1);
vnc_connection_read(conn, mechlist, mechlistlen);
mechlist[mechlistlen] = '\0';
- if (conn->has_error) {
+ if (priv->has_error) {
g_free(mechlist);
mechlist = NULL;
goto error;
@@ -2784,14 +2940,14 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
vnc_connection_write_u32(conn, 0);
}
vnc_connection_flush(conn);
- if (conn->has_error)
+ if (priv->has_error)
goto error;
GVNC_DEBUG("%s", "Getting sever start negotiation reply");
/* Read the 'START' message reply from server */
serverinlen = vnc_connection_read_u32(conn);
- if (conn->has_error)
+ if (priv->has_error)
goto error;
if (serverinlen > SASL_MAX_DATA_LEN) {
GVNC_DEBUG("SASL negotiation data too long: %d bytes",
@@ -2809,7 +2965,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
serverin = NULL;
}
complete = vnc_connection_read_u8(conn);
- if (conn->has_error)
+ if (priv->has_error)
goto error;
GVNC_DEBUG("Client start result complete: %d. Data %d bytes %p '%s'",
@@ -2863,13 +3019,13 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
vnc_connection_write_u32(conn, 0);
}
vnc_connection_flush(conn);
- if (conn->has_error)
+ if (priv->has_error)
goto error;
GVNC_DEBUG("Server step with %d bytes %p", clientoutlen, clientout);
serverinlen = vnc_connection_read_u32(conn);
- if (conn->has_error)
+ if (priv->has_error)
goto error;
if (serverinlen > SASL_MAX_DATA_LEN) {
GVNC_DEBUG("SASL negotiation data too long: %d bytes",
@@ -2887,7 +3043,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
serverin = NULL;
}
complete = vnc_connection_read_u8(conn);
- if (conn->has_error)
+ if (priv->has_error)
goto error;
GVNC_DEBUG("Client step result complete: %d. Data %d bytes %p '%s'",
@@ -2902,7 +3058,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
}
/* Check for suitable SSF if non-TLS */
- if (!conn->tls_session) {
+ if (!priv->tls_session) {
err = sasl_getprop(saslconn, SASL_SSF, &val);
if (err != SASL_OK) {
GVNC_DEBUG("cannot query SASL ssf on connection %d (%s)",
@@ -2922,11 +3078,11 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
/* This must come *after* check-auth-result, because the former
* is defined to be sent unencrypted, and setting saslconn turns
* on the SSF layer encryption processing */
- conn->saslconn = saslconn;
+ priv->saslconn = saslconn;
return ret;
error:
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
if (saslconn)
sasl_dispose(&saslconn);
return FALSE;
@@ -2936,6 +3092,7 @@ static gboolean vnc_connection_perform_auth_sasl(VncConnection *conn)
static gboolean vnc_connection_start_tls(VncConnection *conn, int anonTLS)
{
+ VncConnectionPrivate *priv = conn->priv;
static const int cert_type_priority[] = { GNUTLS_CRT_X509, 0 };
static const int protocol_priority[]= { GNUTLS_TLS1_1, GNUTLS_TLS1_0, GNUTLS_SSL3, 0 };
static const int kx_priority[] = {GNUTLS_KX_DHE_DSS, GNUTLS_KX_RSA, GNUTLS_KX_DHE_RSA, GNUTLS_KX_SRP, 0};
@@ -2945,90 +3102,90 @@ static gboolean vnc_connection_start_tls(VncConnection *conn, int anonTLS)
GVNC_DEBUG("Do TLS handshake");
if (vnc_connection_tls_initialize() < 0) {
GVNC_DEBUG("Failed to init TLS");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return FALSE;
}
- if (conn->tls_session == NULL) {
- if (gnutls_init(&conn->tls_session, GNUTLS_CLIENT) < 0) {
- conn->has_error = TRUE;
+ if (priv->tls_session == NULL) {
+ if (gnutls_init(&priv->tls_session, GNUTLS_CLIENT) < 0) {
+ priv->has_error = TRUE;
return FALSE;
}
- if (gnutls_set_default_priority(conn->tls_session) < 0) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ if (gnutls_set_default_priority(priv->tls_session) < 0) {
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
- if (gnutls_kx_set_priority(conn->tls_session, anonTLS ? kx_anon : kx_priority) < 0) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ if (gnutls_kx_set_priority(priv->tls_session, anonTLS ? kx_anon : kx_priority) < 0) {
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
- if (gnutls_certificate_type_set_priority(conn->tls_session, cert_type_priority) < 0) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ if (gnutls_certificate_type_set_priority(priv->tls_session, cert_type_priority) < 0) {
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
- if (gnutls_protocol_set_priority(conn->tls_session, protocol_priority) < 0) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ if (gnutls_protocol_set_priority(priv->tls_session, protocol_priority) < 0) {
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
if (anonTLS) {
gnutls_anon_client_credentials anon_cred = vnc_connection_tls_initialize_anon_cred();
if (!anon_cred) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
- if (gnutls_credentials_set(conn->tls_session, GNUTLS_CRD_ANON, anon_cred) < 0) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ if (gnutls_credentials_set(priv->tls_session, GNUTLS_CRD_ANON, anon_cred) < 0) {
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
} else {
- conn->want_cred_password = FALSE;
- conn->want_cred_username = FALSE;
- conn->want_cred_x509 = TRUE;
+ priv->want_cred_password = FALSE;
+ priv->want_cred_username = FALSE;
+ priv->want_cred_x509 = TRUE;
if (!vnc_connection_gather_credentials(conn))
return FALSE;
gnutls_certificate_credentials_t x509_cred = vnc_connection_tls_initialize_cert_cred(conn);
if (!x509_cred) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
- if (gnutls_credentials_set(conn->tls_session, GNUTLS_CRD_CERTIFICATE, x509_cred) < 0) {
- gnutls_deinit(conn->tls_session);
- conn->has_error = TRUE;
+ if (gnutls_credentials_set(priv->tls_session, GNUTLS_CRD_CERTIFICATE, x509_cred) < 0) {
+ gnutls_deinit(priv->tls_session);
+ priv->has_error = TRUE;
return FALSE;
}
}
- gnutls_transport_set_ptr(conn->tls_session, (gnutls_transport_ptr_t)conn);
- gnutls_transport_set_push_function(conn->tls_session, vnc_connection_tls_push);
- gnutls_transport_set_pull_function(conn->tls_session, vnc_connection_tls_pull);
+ gnutls_transport_set_ptr(priv->tls_session, (gnutls_transport_ptr_t)conn);
+ gnutls_transport_set_push_function(priv->tls_session, vnc_connection_tls_push);
+ gnutls_transport_set_pull_function(priv->tls_session, vnc_connection_tls_pull);
}
retry:
- if ((ret = gnutls_handshake(conn->tls_session)) < 0) {
+ if ((ret = gnutls_handshake(priv->tls_session)) < 0) {
if (!gnutls_error_is_fatal(ret)) {
GVNC_DEBUG("Handshake was blocking");
- if (!gnutls_record_get_direction(conn->tls_session))
- g_io_wait(conn->channel, G_IO_IN);
+ if (!gnutls_record_get_direction(priv->tls_session))
+ g_io_wait(priv->channel, G_IO_IN);
else
- g_io_wait(conn->channel, G_IO_OUT);
+ g_io_wait(priv->channel, G_IO_OUT);
goto retry;
}
GVNC_DEBUG("Handshake failed %s", gnutls_strerror(ret));
- gnutls_deinit(conn->tls_session);
- conn->tls_session = NULL;
- conn->has_error = TRUE;
+ gnutls_deinit(priv->tls_session);
+ priv->tls_session = NULL;
+ priv->has_error = TRUE;
return FALSE;
}
@@ -3039,7 +3196,7 @@ static gboolean vnc_connection_start_tls(VncConnection *conn, int anonTLS)
} else {
if (!vnc_connection_validate_certificate(conn)) {
GVNC_DEBUG("Certificate validation failed");
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return FALSE;
}
return TRUE;
@@ -3049,10 +3206,11 @@ static gboolean vnc_connection_start_tls(VncConnection *conn, int anonTLS)
static gboolean vnc_connection_has_auth_subtype(gpointer data)
{
VncConnection *conn = data;
+ VncConnectionPrivate *priv = conn->priv;
- if (conn->has_error)
+ if (priv->has_error)
return TRUE;
- if (conn->auth_subtype == GVNC_AUTH_INVALID)
+ if (priv->auth_subtype == GVNC_AUTH_INVALID)
return FALSE;
return TRUE;
}
@@ -3060,6 +3218,7 @@ static gboolean vnc_connection_has_auth_subtype(gpointer data)
static gboolean vnc_connection_perform_auth_tls(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
unsigned int nauth, i;
unsigned int auth[20];
@@ -3082,7 +3241,7 @@ static gboolean vnc_connection_perform_auth_tls(VncConnection *conn)
if (nauth > sizeof(auth)) {
GVNC_DEBUG("Too many (%d) auth types", nauth);
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return FALSE;
}
for (i = 0 ; i < nauth ; i++) {
@@ -3093,27 +3252,27 @@ static gboolean vnc_connection_perform_auth_tls(VncConnection *conn)
GVNC_DEBUG("Possible sub-auth %d", auth[i]);
}
- if (conn->has_error || !conn->ops.auth_subtype)
+ if (priv->has_error || !priv->ops.auth_subtype)
return FALSE;
- if (!conn->ops.auth_subtype(conn->ops_data, nauth, auth))
- conn->has_error = TRUE;
- if (conn->has_error)
+ if (!priv->ops.auth_subtype(priv->ops_data, nauth, auth))
+ priv->has_error = TRUE;
+ if (priv->has_error)
return FALSE;
GVNC_DEBUG("Waiting for auth subtype");
g_condition_wait(vnc_connection_has_auth_subtype, conn);
- if (conn->has_error)
+ if (priv->has_error)
return FALSE;
- GVNC_DEBUG("Choose auth %d", conn->auth_subtype);
+ GVNC_DEBUG("Choose auth %d", priv->auth_subtype);
- vnc_connection_write_u8(conn, conn->auth_subtype);
+ vnc_connection_write_u8(conn, priv->auth_subtype);
vnc_connection_flush(conn);
- switch (conn->auth_subtype) {
+ switch (priv->auth_subtype) {
case GVNC_AUTH_NONE:
- if (conn->minor == 8)
+ if (priv->minor == 8)
return vnc_connection_check_auth_result(conn);
return TRUE;
case GVNC_AUTH_VNC:
@@ -3131,6 +3290,7 @@ static gboolean vnc_connection_perform_auth_tls(VncConnection *conn)
static gboolean vnc_connection_perform_auth_vencrypt(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
int major, minor, status, anonTLS;
unsigned int nauth, i;
unsigned int auth[20];
@@ -3167,40 +3327,40 @@ static gboolean vnc_connection_perform_auth_vencrypt(VncConnection *conn)
GVNC_DEBUG("Possible auth %d", auth[i]);
}
- if (conn->has_error || !conn->ops.auth_subtype)
+ if (priv->has_error || !priv->ops.auth_subtype)
return FALSE;
- if (!conn->ops.auth_subtype(conn->ops_data, nauth, auth))
- conn->has_error = TRUE;
- if (conn->has_error)
+ if (!priv->ops.auth_subtype(priv->ops_data, nauth, auth))
+ priv->has_error = TRUE;
+ if (priv->has_error)
return FALSE;
GVNC_DEBUG("Waiting for auth subtype");
g_condition_wait(vnc_connection_has_auth_subtype, conn);
- if (conn->has_error)
+ if (priv->has_error)
return FALSE;
- GVNC_DEBUG("Choose auth %d", conn->auth_subtype);
+ GVNC_DEBUG("Choose auth %d", priv->auth_subtype);
if (!vnc_connection_gather_credentials(conn))
return FALSE;
#if !DEBUG
- if (conn->auth_subtype == GVNC_AUTH_VENCRYPT_PLAIN) {
+ if (priv->auth_subtype == GVNC_AUTH_VENCRYPT_PLAIN) {
GVNC_DEBUG("Cowardly refusing to transmit plain text password");
return FALSE;
}
#endif
- vnc_connection_write_u32(conn, conn->auth_subtype);
+ vnc_connection_write_u32(conn, priv->auth_subtype);
vnc_connection_flush(conn);
status = vnc_connection_read_u8(conn);
if (status != 1) {
- GVNC_DEBUG("Server refused VeNCrypt auth %d %d", conn->auth_subtype, status);
+ GVNC_DEBUG("Server refused VeNCrypt auth %d %d", priv->auth_subtype, status);
return FALSE;
}
- switch (conn->auth_subtype) {
+ switch (priv->auth_subtype) {
case GVNC_AUTH_VENCRYPT_TLSNONE:
case GVNC_AUTH_VENCRYPT_TLSPLAIN:
case GVNC_AUTH_VENCRYPT_TLSVNC:
@@ -3215,9 +3375,9 @@ static gboolean vnc_connection_perform_auth_vencrypt(VncConnection *conn)
GVNC_DEBUG("Could not start TLS");
return FALSE;
}
- GVNC_DEBUG("Completed TLS setup, do subauth %d", conn->auth_subtype);
+ GVNC_DEBUG("Completed TLS setup, do subauth %d", priv->auth_subtype);
- switch (conn->auth_subtype) {
+ switch (priv->auth_subtype) {
/* Plain certificate based auth */
case GVNC_AUTH_VENCRYPT_TLSNONE:
case GVNC_AUTH_VENCRYPT_X509NONE:
@@ -3239,7 +3399,7 @@ static gboolean vnc_connection_perform_auth_vencrypt(VncConnection *conn)
#endif
default:
- GVNC_DEBUG("Unknown auth subtype %d", conn->auth_subtype);
+ GVNC_DEBUG("Unknown auth subtype %d", priv->auth_subtype);
return FALSE;
}
}
@@ -3247,20 +3407,22 @@ static gboolean vnc_connection_perform_auth_vencrypt(VncConnection *conn)
static gboolean vnc_connection_has_auth_type(gpointer data)
{
VncConnection *conn = data;
+ VncConnectionPrivate *priv = conn->priv;
- if (conn->has_error)
+ if (priv->has_error)
return TRUE;
- if (conn->auth_type == GVNC_AUTH_INVALID)
+ if (priv->auth_type == GVNC_AUTH_INVALID)
return FALSE;
return TRUE;
}
static gboolean vnc_connection_perform_auth(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
unsigned int nauth, i;
unsigned int auth[10];
- if (conn->minor <= 6) {
+ if (priv->minor <= 6) {
nauth = 1;
auth[0] = vnc_connection_read_u32(conn);
} else {
@@ -3272,7 +3434,7 @@ static gboolean vnc_connection_perform_auth(VncConnection *conn)
return vnc_connection_check_auth_result(conn);
if (nauth > sizeof(auth)) {
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return FALSE;
}
for (i = 0 ; i < nauth ; i++)
@@ -3283,38 +3445,38 @@ static gboolean vnc_connection_perform_auth(VncConnection *conn)
GVNC_DEBUG("Possible auth %u", auth[i]);
}
- if (conn->has_error || !conn->ops.auth_type)
+ if (priv->has_error || !priv->ops.auth_type)
return FALSE;
- if (!conn->ops.auth_type(conn->ops_data, nauth, auth))
- conn->has_error = TRUE;
- if (conn->has_error)
+ if (!priv->ops.auth_type(priv->ops_data, nauth, auth))
+ priv->has_error = TRUE;
+ if (priv->has_error)
return FALSE;
GVNC_DEBUG("Waiting for auth type");
g_condition_wait(vnc_connection_has_auth_type, conn);
- if (conn->has_error)
+ if (priv->has_error)
return FALSE;
- GVNC_DEBUG("Choose auth %u", conn->auth_type);
+ GVNC_DEBUG("Choose auth %u", priv->auth_type);
if (!vnc_connection_gather_credentials(conn))
return FALSE;
- if (conn->minor > 6) {
- vnc_connection_write_u8(conn, conn->auth_type);
+ if (priv->minor > 6) {
+ vnc_connection_write_u8(conn, priv->auth_type);
vnc_connection_flush(conn);
}
- switch (conn->auth_type) {
+ switch (priv->auth_type) {
case GVNC_AUTH_NONE:
- if (conn->minor == 8)
+ if (priv->minor == 8)
return vnc_connection_check_auth_result(conn);
return TRUE;
case GVNC_AUTH_VNC:
return vnc_connection_perform_auth_vnc(conn);
case GVNC_AUTH_TLS:
- if (conn->minor < 7)
+ if (priv->minor < 7)
return FALSE;
return vnc_connection_perform_auth_tls(conn);
@@ -3330,9 +3492,9 @@ static gboolean vnc_connection_perform_auth(VncConnection *conn)
return vnc_connection_perform_auth_mslogon(conn);
default:
- if (conn->ops.auth_unsupported)
- conn->ops.auth_unsupported (conn->ops_data, conn->auth_type);
- conn->has_error = TRUE;
+ if (priv->ops.auth_unsupported)
+ priv->ops.auth_unsupported (priv->ops_data, priv->auth_type);
+ priv->has_error = TRUE;
return FALSE;
}
@@ -3340,126 +3502,171 @@ static gboolean vnc_connection_perform_auth(VncConnection *conn)
return TRUE;
}
-VncConnection *vnc_connection_new(const struct vnc_connection_ops *ops, gpointer ops_data)
+static void vnc_connection_finalize (GObject *object)
{
- VncConnection *conn = g_malloc0(sizeof(*conn));
+ VncConnection *conn = VNC_CONNECTION(object);
+ VncConnectionPrivate *priv = conn->priv;
- conn->fd = -1;
+ if (vnc_connection_is_open(conn))
+ vnc_connection_close(conn);
- memcpy(&conn->ops, ops, sizeof(*ops));
- conn->ops_data = ops_data;
- conn->auth_type = GVNC_AUTH_INVALID;
- conn->auth_subtype = GVNC_AUTH_INVALID;
+ if (priv->fb)
+ g_object_unref(G_OBJECT(priv->fb));
- return conn;
+ G_OBJECT_CLASS(vnc_connection_parent_class)->finalize (object);
}
-void vnc_connection_free(VncConnection *conn)
+static void vnc_connection_class_init(VncConnectionClass *klass)
{
- if (!conn)
- return;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- if (vnc_connection_is_open(conn))
- vnc_connection_close(conn);
+ object_class->finalize = vnc_connection_finalize;
+ object_class->get_property = vnc_connection_get_property;
+ object_class->set_property = vnc_connection_set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_FRAMEBUFFER,
+ g_param_spec_object("framebuffer",
+ "The desktop framebuffer",
+ "The desktop framebuffer instance",
+ VNC_TYPE_FRAMEBUFFER,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_type_class_add_private(klass, sizeof(VncConnectionPrivate));
+}
+
+
+void vnc_connection_init(VncConnection *fb)
+{
+ VncConnectionPrivate *priv;
+
+ priv = fb->priv = VNC_CONNECTION_GET_PRIVATE(fb);
+
+ memset(priv, 0, sizeof(*priv));
+
+ priv->fd = -1;
+ priv->auth_type = GVNC_AUTH_INVALID;
+ priv->auth_subtype = GVNC_AUTH_INVALID;
+}
+
+
+VncConnection *vnc_connection_new(const struct vnc_connection_ops *ops, gpointer ops_data)
+{
+ VncConnection *conn;
+ VncConnectionPrivate *priv;
- if (conn->fb)
- g_object_unref(G_OBJECT(conn->fb));
+ conn = VNC_CONNECTION(g_object_new(VNC_TYPE_CONNECTION,
+ NULL));
- g_free(conn);
- conn = NULL;
+ priv = conn->priv;
+
+ /* XXX kill this */
+ memcpy(&priv->ops, ops, sizeof(*ops));
+ priv->ops_data = ops_data;
+
+ return conn;
}
void vnc_connection_close(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
int i;
- if (conn->tls_session) {
- gnutls_bye(conn->tls_session, GNUTLS_SHUT_RDWR);
- conn->tls_session = NULL;
+ if (priv->tls_session) {
+ gnutls_bye(priv->tls_session, GNUTLS_SHUT_RDWR);
+ priv->tls_session = NULL;
}
#if HAVE_SASL
- if (conn->saslconn)
- sasl_dispose (&conn->saslconn);
+ if (priv->saslconn)
+ sasl_dispose (&priv->saslconn);
#endif
- if (conn->channel) {
- g_io_channel_unref(conn->channel);
- conn->channel = NULL;
+ if (priv->channel) {
+ g_io_channel_unref(priv->channel);
+ priv->channel = NULL;
}
- if (conn->fd != -1) {
- close(conn->fd);
- conn->fd = -1;
+ if (priv->fd != -1) {
+ close(priv->fd);
+ priv->fd = -1;
}
- if (conn->host) {
- g_free(conn->host);
- conn->host = NULL;
+ if (priv->host) {
+ g_free(priv->host);
+ priv->host = NULL;
}
- if (conn->port) {
- g_free(conn->port);
- conn->port = NULL;
+ if (priv->port) {
+ g_free(priv->port);
+ priv->port = NULL;
}
- if (conn->name) {
- g_free(conn->name);
- conn->name = NULL;
+ if (priv->name) {
+ g_free(priv->name);
+ priv->name = NULL;
}
- g_free (conn->xmit_buffer);
+ g_free (priv->xmit_buffer);
- if (conn->cred_username) {
- g_free(conn->cred_username);
- conn->cred_username = NULL;
+ if (priv->cred_username) {
+ g_free(priv->cred_username);
+ priv->cred_username = NULL;
}
- if (conn->cred_password) {
- g_free(conn->cred_password);
- conn->cred_password = NULL;
+ if (priv->cred_password) {
+ g_free(priv->cred_password);
+ priv->cred_password = NULL;
}
- if (conn->cred_x509_cacert) {
- g_free(conn->cred_x509_cacert);
- conn->cred_x509_cacert = NULL;
+ if (priv->cred_x509_cacert) {
+ g_free(priv->cred_x509_cacert);
+ priv->cred_x509_cacert = NULL;
}
- if (conn->cred_x509_cacrl) {
- g_free(conn->cred_x509_cacrl);
- conn->cred_x509_cacrl = NULL;
+ if (priv->cred_x509_cacrl) {
+ g_free(priv->cred_x509_cacrl);
+ priv->cred_x509_cacrl = NULL;
}
- if (conn->cred_x509_cert) {
- g_free(conn->cred_x509_cert);
- conn->cred_x509_cert = NULL;
+ if (priv->cred_x509_cert) {
+ g_free(priv->cred_x509_cert);
+ priv->cred_x509_cert = NULL;
}
- if (conn->cred_x509_key) {
- g_free(conn->cred_x509_key);
- conn->cred_x509_key = NULL;
+ if (priv->cred_x509_key) {
+ g_free(priv->cred_x509_key);
+ priv->cred_x509_key = NULL;
}
for (i = 0; i < 5; i++)
- inflateEnd(&conn->streams[i]);
+ inflateEnd(&priv->streams[i]);
- conn->auth_type = GVNC_AUTH_INVALID;
- conn->auth_subtype = GVNC_AUTH_INVALID;
+ priv->auth_type = GVNC_AUTH_INVALID;
+ priv->auth_subtype = GVNC_AUTH_INVALID;
- conn->has_error = 0;
+ priv->has_error = 0;
}
void vnc_connection_shutdown(VncConnection *conn)
{
- close(conn->fd);
- conn->fd = -1;
- conn->has_error = 1;
+ VncConnectionPrivate *priv = conn->priv;
+
+ close(priv->fd);
+ priv->fd = -1;
+ priv->has_error = 1;
GVNC_DEBUG("Waking up couroutine to shutdown gracefully");
- g_io_wakeup(&conn->wait);
+ g_io_wakeup(&priv->wait);
}
gboolean vnc_connection_is_open(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
+
if (!conn)
return FALSE;
- if (conn->fd != -1)
+ if (priv->fd != -1)
return TRUE;
- if (conn->host)
+ if (priv->host)
return TRUE;
return FALSE;
}
@@ -3467,53 +3674,64 @@ gboolean vnc_connection_is_open(VncConnection *conn)
gboolean vnc_connection_is_initialized(VncConnection *conn)
{
+ VncConnectionPrivate *priv = conn->priv;
+
if (!vnc_connection_is_open(conn))
return FALSE;
- if (conn->name)
+ if (priv->name)
return TRUE;
return FALSE;
}
-static gboolean vnc_connection_before_version (VncConnection *conn, int major, int minor) {
- return (conn->major < major) || (conn->major == major && conn->minor < minor);
+
+static gboolean vnc_connection_before_version (VncConnection *conn, int major, int minor)
+{
+ VncConnectionPrivate *priv = conn->priv;
+
+ return (priv->major < major) || (priv->major == major && priv->minor < minor);
}
-static gboolean vnc_connection_after_version (VncConnection *conn, int major, int minor) {
+
+
+static gboolean vnc_connection_after_version (VncConnection *conn, int major, int minor)
+{
return !vnc_connection_before_version (conn, major, minor+1);
}
+
gboolean vnc_connection_initialize(VncConnection *conn, gboolean shared_flag)
{
+ VncConnectionPrivate *priv = conn->priv;
int ret, i;
char version[13];
guint32 n_name;
- conn->absolute = 1;
+ priv->absolute = 1;
vnc_connection_read(conn, version, 12);
version[12] = 0;
- ret = sscanf(version, "RFB %03d.%03d\n", &conn->major, &conn->minor);
+ ret = sscanf(version, "RFB %03d.%03d\n", &priv->major, &priv->minor);
if (ret != 2) {
GVNC_DEBUG("Error while getting server version");
goto fail;
}
- GVNC_DEBUG("Server version: %d.%d", conn->major, conn->minor);
+ GVNC_DEBUG("Server version: %d.%d", priv->major, priv->minor);
if (vnc_connection_before_version(conn, 3, 3)) {
- GVNC_DEBUG("Server version is not supported (%d.%d)", conn->major, conn->minor);
+ GVNC_DEBUG("Server version is not supported (%d.%d)", priv->major, priv->minor);
goto fail;
} else if (vnc_connection_before_version(conn, 3, 7)) {
- conn->minor = 3;
+ priv->minor = 3;
} else if (vnc_connection_after_version(conn, 3, 8)) {
- conn->major = 3;
- conn->minor = 8;
+ priv->major = 3;
+ priv->minor = 8;
}
- snprintf(version, 12, "RFB %03d.%03d\n", conn->major, conn->minor);
+ snprintf(version, 12, "RFB %03d.%03d\n", priv->major, priv->minor);
vnc_connection_write(conn, version, 12);
vnc_connection_flush(conn);
- GVNC_DEBUG("Using version: %d.%d", conn->major, conn->minor);
+ GVNC_DEBUG("Using version: %d.%d", priv->major, priv->minor);
if (!vnc_connection_perform_auth(conn)) {
GVNC_DEBUG("Auth failed");
@@ -3522,44 +3740,44 @@ gboolean vnc_connection_initialize(VncConnection *conn, gboolean shared_flag)
vnc_connection_write_u8(conn, shared_flag); /* shared flag */
vnc_connection_flush(conn);
- conn->width = vnc_connection_read_u16(conn);
- conn->height = vnc_connection_read_u16(conn);
+ priv->width = vnc_connection_read_u16(conn);
+ priv->height = vnc_connection_read_u16(conn);
if (vnc_connection_has_error(conn))
return FALSE;
- vnc_connection_read_pixel_format(conn, &conn->fmt);
+ vnc_connection_read_pixel_format(conn, &priv->fmt);
n_name = vnc_connection_read_u32(conn);
if (n_name > 4096)
goto fail;
- conn->name = g_new(char, n_name + 1);
+ priv->name = g_new(char, n_name + 1);
- vnc_connection_read(conn, conn->name, n_name);
- conn->name[n_name] = 0;
- GVNC_DEBUG("Display name '%s'", conn->name);
+ vnc_connection_read(conn, priv->name, n_name);
+ priv->name[n_name] = 0;
+ GVNC_DEBUG("Display name '%s'", priv->name);
if (vnc_connection_has_error(conn))
return FALSE;
- if (!conn->ops.get_preferred_pixel_format)
+ if (!priv->ops.get_preferred_pixel_format)
goto fail;
- if (conn->ops.get_preferred_pixel_format(conn->ops_data, &conn->fmt))
- vnc_connection_set_pixel_format(conn, &conn->fmt);
+ if (priv->ops.get_preferred_pixel_format(priv->ops_data, &priv->fmt))
+ vnc_connection_set_pixel_format(conn, &priv->fmt);
else
goto fail;
- memset(&conn->strm, 0, sizeof(conn->strm));
+ memset(&priv->strm, 0, sizeof(priv->strm));
/* FIXME what level? */
for (i = 0; i < 5; i++)
- inflateInit(&conn->streams[i]);
- conn->strm = NULL;
+ inflateInit(&priv->streams[i]);
+ priv->strm = NULL;
- vnc_connection_resize(conn, conn->width, conn->height);
+ vnc_connection_resize(conn, priv->width, priv->height);
return !vnc_connection_has_error(conn);
fail:
- conn->has_error = 1;
+ priv->has_error = 1;
return !vnc_connection_has_error(conn);
}
@@ -3595,6 +3813,8 @@ static gboolean vnc_connection_set_nonblock(int fd)
gboolean vnc_connection_open_fd(VncConnection *conn, int fd)
{
+ VncConnectionPrivate *priv = conn->priv;
+
if (vnc_connection_is_open(conn)) {
GVNC_DEBUG ("Error: already connected?");
return FALSE;
@@ -3605,7 +3825,7 @@ gboolean vnc_connection_open_fd(VncConnection *conn, int fd)
if (!vnc_connection_set_nonblock(fd))
return FALSE;
- if (!(conn->channel =
+ if (!(priv->channel =
#ifdef WIN32
g_io_channel_win32_new_socket(_get_osfhandle(fd))
#else
@@ -3615,20 +3835,21 @@ gboolean vnc_connection_open_fd(VncConnection *conn, int fd)
GVNC_DEBUG ("Failed to g_io_channel_unix_new()");
return FALSE;
}
- conn->fd = fd;
+ priv->fd = fd;
return !vnc_connection_has_error(conn);
}
gboolean vnc_connection_open_host(VncConnection *conn, const char *host, const char *port)
{
+ VncConnectionPrivate *priv = conn->priv;
struct addrinfo *ai, *runp, hints;
int ret;
if (vnc_connection_is_open(conn))
return FALSE;
- conn->host = g_strdup(host);
- conn->port = g_strdup(port);
+ priv->host = g_strdup(host);
+ priv->port = g_strdup(port);
GVNC_DEBUG("Resolving host %s %s", host, port);
memset (&hints, '\0', sizeof (hints));
@@ -3673,8 +3894,8 @@ gboolean vnc_connection_open_host(VncConnection *conn, const char *host, const c
as explained in connect(2) man page */
if ((connect(fd, runp->ai_addr, runp->ai_addrlen) == 0) ||
errno == EISCONN) {
- conn->channel = chan;
- conn->fd = fd;
+ priv->channel = chan;
+ priv->fd = fd;
freeaddrinfo(ai);
return !vnc_connection_has_error(conn);
}
@@ -3700,9 +3921,11 @@ gboolean vnc_connection_open_host(VncConnection *conn, const char *host, const c
gboolean vnc_connection_set_auth_type(VncConnection *conn, unsigned int type)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Thinking about auth type %u", type);
- if (conn->auth_type != GVNC_AUTH_INVALID) {
- conn->has_error = TRUE;
+ if (priv->auth_type != GVNC_AUTH_INVALID) {
+ priv->has_error = TRUE;
return !vnc_connection_has_error(conn);
}
if (type != GVNC_AUTH_NONE &&
@@ -3712,43 +3935,47 @@ gboolean vnc_connection_set_auth_type(VncConnection *conn, unsigned int type)
type != GVNC_AUTH_VENCRYPT &&
type != GVNC_AUTH_SASL) {
GVNC_DEBUG("Unsupported auth type %u", type);
- if (conn->ops.auth_unsupported)
- conn->ops.auth_unsupported (conn->ops_data, type);
+ if (priv->ops.auth_unsupported)
+ priv->ops.auth_unsupported (priv->ops_data, type);
- conn->has_error = TRUE;
+ priv->has_error = TRUE;
return !vnc_connection_has_error(conn);
}
GVNC_DEBUG("Decided on auth type %u", type);
- conn->auth_type = type;
- conn->auth_subtype = GVNC_AUTH_INVALID;
+ priv->auth_type = type;
+ priv->auth_subtype = GVNC_AUTH_INVALID;
return !vnc_connection_has_error(conn);
}
gboolean vnc_connection_set_auth_subtype(VncConnection *conn, unsigned int type)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Requested auth subtype %d", type);
- if (conn->auth_type != GVNC_AUTH_VENCRYPT &&
- conn->auth_type != GVNC_AUTH_TLS) {
- conn->has_error = TRUE;
+ if (priv->auth_type != GVNC_AUTH_VENCRYPT &&
+ priv->auth_type != GVNC_AUTH_TLS) {
+ priv->has_error = TRUE;
return !vnc_connection_has_error(conn);
}
- if (conn->auth_subtype != GVNC_AUTH_INVALID) {
- conn->has_error = TRUE;
+ if (priv->auth_subtype != GVNC_AUTH_INVALID) {
+ priv->has_error = TRUE;
return !vnc_connection_has_error(conn);
}
- conn->auth_subtype = type;
+ priv->auth_subtype = type;
return !vnc_connection_has_error(conn);
}
gboolean vnc_connection_set_credential_password(VncConnection *conn, const char *password)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Set password credential %s", password);
- if (conn->cred_password)
- g_free(conn->cred_password);
- if (!(conn->cred_password = g_strdup(password))) {
- conn->has_error = TRUE;
+ if (priv->cred_password)
+ g_free(priv->cred_password);
+ if (!(priv->cred_password = g_strdup(password))) {
+ priv->has_error = TRUE;
return FALSE;
}
return TRUE;
@@ -3756,11 +3983,13 @@ gboolean vnc_connection_set_credential_password(VncConnection *conn, const char
gboolean vnc_connection_set_credential_username(VncConnection *conn, const char *username)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Set username credential %s", username);
- if (conn->cred_username)
- g_free(conn->cred_username);
- if (!(conn->cred_username = g_strdup(username))) {
- conn->has_error = TRUE;
+ if (priv->cred_username)
+ g_free(priv->cred_username);
+ if (!(priv->cred_username = g_strdup(username))) {
+ priv->has_error = TRUE;
return FALSE;
}
return TRUE;
@@ -3768,11 +3997,13 @@ gboolean vnc_connection_set_credential_username(VncConnection *conn, const char
gboolean vnc_connection_set_credential_x509_cacert(VncConnection *conn, const char *file)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Set x509 cacert %s", file);
- if (conn->cred_x509_cacert)
- g_free(conn->cred_x509_cacert);
- if (!(conn->cred_x509_cacert = g_strdup(file))) {
- conn->has_error = TRUE;
+ if (priv->cred_x509_cacert)
+ g_free(priv->cred_x509_cacert);
+ if (!(priv->cred_x509_cacert = g_strdup(file))) {
+ priv->has_error = TRUE;
return FALSE;
}
return TRUE;
@@ -3780,11 +4011,13 @@ gboolean vnc_connection_set_credential_x509_cacert(VncConnection *conn, const ch
gboolean vnc_connection_set_credential_x509_cacrl(VncConnection *conn, const char *file)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Set x509 cacrl %s", file);
- if (conn->cred_x509_cacrl)
- g_free(conn->cred_x509_cacrl);
- if (!(conn->cred_x509_cacrl = g_strdup(file))) {
- conn->has_error = TRUE;
+ if (priv->cred_x509_cacrl)
+ g_free(priv->cred_x509_cacrl);
+ if (!(priv->cred_x509_cacrl = g_strdup(file))) {
+ priv->has_error = TRUE;
return FALSE;
}
return TRUE;
@@ -3792,11 +4025,13 @@ gboolean vnc_connection_set_credential_x509_cacrl(VncConnection *conn, const cha
gboolean vnc_connection_set_credential_x509_key(VncConnection *conn, const char *file)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Set x509 key %s", file);
- if (conn->cred_x509_key)
- g_free(conn->cred_x509_key);
- if (!(conn->cred_x509_key = g_strdup(file))) {
- conn->has_error = TRUE;
+ if (priv->cred_x509_key)
+ g_free(priv->cred_x509_key);
+ if (!(priv->cred_x509_key = g_strdup(file))) {
+ priv->has_error = TRUE;
return FALSE;
}
return TRUE;
@@ -3804,11 +4039,13 @@ gboolean vnc_connection_set_credential_x509_key(VncConnection *conn, const char
gboolean vnc_connection_set_credential_x509_cert(VncConnection *conn, const char *file)
{
+ VncConnectionPrivate *priv = conn->priv;
+
GVNC_DEBUG("Set x509 cert %s", file);
- if (conn->cred_x509_cert)
- g_free(conn->cred_x509_cert);
- if (!(conn->cred_x509_cert = g_strdup(file))) {
- conn->has_error = TRUE;
+ if (priv->cred_x509_cert)
+ g_free(priv->cred_x509_cert);
+ if (!(priv->cred_x509_cert = g_strdup(file))) {
+ priv->has_error = TRUE;
return FALSE;
}
return TRUE;
@@ -3817,47 +4054,56 @@ gboolean vnc_connection_set_credential_x509_cert(VncConnection *conn, const char
gboolean vnc_connection_set_framebuffer(VncConnection *conn, VncFramebuffer *fb)
{
+ VncConnectionPrivate *priv = conn->priv;
const VncPixelFormat *remote;
int i;
- if (conn->fb)
- g_object_unref(G_OBJECT(conn->fb));
- conn->fb = fb;
- g_object_ref(G_OBJECT(conn->fb));
+ if (priv->fb)
+ g_object_unref(G_OBJECT(priv->fb));
+ priv->fb = fb;
+ g_object_ref(G_OBJECT(priv->fb));
- remote = vnc_framebuffer_get_remote_format(conn->fb);
+ remote = vnc_framebuffer_get_remote_format(priv->fb);
- conn->fbSwapRemote = remote->byte_order != G_BYTE_ORDER;
+ priv->fbSwapRemote = remote->byte_order != G_BYTE_ORDER;
- i = conn->fmt.bits_per_pixel / 8;
+ i = priv->fmt.bits_per_pixel / 8;
if (i == 4) i = 3;
- conn->rich_cursor_blt = vnc_connection_rich_cursor_blt_table[i - 1];
- conn->tight_compute_predicted = vnc_connection_tight_compute_predicted_table[i - 1];
- conn->tight_sum_pixel = vnc_connection_tight_sum_pixel_table[i - 1];
+ priv->rich_cursor_blt = vnc_connection_rich_cursor_blt_table[i - 1];
+ priv->tight_compute_predicted = vnc_connection_tight_compute_predicted_table[i - 1];
+ priv->tight_sum_pixel = vnc_connection_tight_sum_pixel_table[i - 1];
return !vnc_connection_has_error(conn);
}
const char *vnc_connection_get_name(VncConnection *conn)
{
- return conn->name;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->name;
}
int vnc_connection_get_width(VncConnection *conn)
{
- return conn->width;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->width;
}
int vnc_connection_get_height(VncConnection *conn)
{
- return conn->height;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->height;
}
gboolean vnc_connection_using_raw_keycodes(VncConnection *conn)
{
- return conn->has_ext_key_event;
+ VncConnectionPrivate *priv = conn->priv;
+
+ return priv->has_ext_key_event;
}
/*
diff --git a/src/vncconnection.h b/src/vncconnection.h
index 9f7b281..aba1e7c 100644
--- a/src/vncconnection.h
+++ b/src/vncconnection.h
@@ -25,7 +25,31 @@
#include "vncframebuffer.h"
+G_BEGIN_DECLS
+
+#define VNC_TYPE_CONNECTION (vnc_connection_get_type ())
+#define VNC_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VNC_TYPE_CONNECTION, VncConnection))
+#define VNC_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VNC_TYPE_CONNECTION, VncConnectionClass))
+#define VNC_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VNC_TYPE_CONNECTION))
+#define VNC_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VNC_TYPE_CONNECTION))
+#define VNC_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VNC_TYPE_CONNECTION, VncConnectionClass))
+
+
typedef struct _VncConnection VncConnection;
+typedef struct _VncConnectionPrivate VncConnectionPrivate;
+typedef struct _VncConnectionClass VncConnectionClass;
+
+struct _VncConnection
+{
+ GObject parent;
+
+ VncConnectionPrivate *priv;
+};
+
+struct _VncConnectionClass
+{
+ GObjectClass parent_class;
+};
typedef void (rgb24_render_func)(void *, int, int, int, int, guint8 *, int);
@@ -109,9 +133,9 @@ typedef enum {
GVNC_AUTH_VENCRYPT_TLSSASL = 264,
} VncConnectionAuthVencrypt;
+GType vnc_connection_get_type(void) G_GNUC_CONST;
VncConnection *vnc_connection_new(const struct vnc_connection_ops *ops, gpointer ops_data);
-void vnc_connection_free(VncConnection *conn);
void vnc_connection_close(VncConnection *conn);
void vnc_connection_shutdown(VncConnection *conn);
@@ -172,6 +196,8 @@ int vnc_connection_get_height(VncConnection *conn);
/* HACK this is temporary */
gboolean vnc_connection_using_raw_keycodes(VncConnection *conn);
+G_END_DECLS
+
#endif
/*
* Local variables:
diff --git a/src/vncconnectionblt.h b/src/vncconnectionblt.h
index 031fcf2..c894bdc 100644
--- a/src/vncconnectionblt.h
+++ b/src/vncconnectionblt.h
@@ -32,7 +32,7 @@
#define TIGHT_SUM_PIXEL SPLICE(vnc_connection_tight_sum_pixel_, SUFFIX())
#define SWAP_RFB(conn, pixel) SPLICE(vnc_connection_swap_rfb_, SRC)(conn, pixel)
#define SWAP_IMG(conn, pixel) SPLICE(vnc_connection_swap_img_, DST)(conn, pixel)
-#define COMPONENT(color, pixel) ((SWAP_RFB(conn, pixel) >> conn->fmt.SPLICE(color, _shift) & conn->fmt.SPLICE(color, _max)))
+#define COMPONENT(color, pixel) ((SWAP_RFB(conn, pixel) >> priv->fmt.SPLICE(color, _shift) & priv->fmt.SPLICE(color, _max)))
/* We need to convert to a GdkPixbuf which is always 32-bit */
@@ -41,6 +41,7 @@ static void RICH_CURSOR_BLIT(VncConnection *conn, guint8 *pixbuf,
guint8 *image, guint8 *mask, int pitch,
guint16 width, guint16 height)
{
+ VncConnectionPrivate *priv = conn->priv;
int x1, y1;
guint32 *dst = (guint32 *)pixbuf;
guint8 *src = image;
@@ -69,11 +70,11 @@ static void RICH_CURSOR_BLIT(VncConnection *conn, guint8 *pixbuf,
#endif
/* Then this adjusts for remote having less bpp than 32 */
- for (n = 255 ; n > conn->fmt.red_max ; n>>= 1)
+ for (n = 255 ; n > priv->fmt.red_max ; n>>= 1)
rs++;
- for (n = 255 ; n > conn->fmt.green_max ; n>>= 1)
+ for (n = 255 ; n > priv->fmt.green_max ; n>>= 1)
gs++;
- for (n = 255 ; n > conn->fmt.blue_max ; n>>= 1)
+ for (n = 255 ; n > priv->fmt.blue_max ; n>>= 1)
bs++;
for (y1 = 0; y1 < height; y1++) {
@@ -103,29 +104,31 @@ static void TIGHT_COMPUTE_PREDICTED(VncConnection *conn, src_pixel_t *ppixel,
src_pixel_t *lp, src_pixel_t *cp,
src_pixel_t *llp)
{
+ VncConnectionPrivate *priv = conn->priv;
ssrc_pixel_t red, green, blue;
red = COMPONENT(red, *lp) + COMPONENT(red, *cp) - COMPONENT(red, *llp);
red = MAX(red, 0);
- red = MIN(red, conn->fmt.red_max);
+ red = MIN(red, priv->fmt.red_max);
green = COMPONENT(green, *lp) + COMPONENT(green, *cp) - COMPONENT(green, *llp);
green = MAX(green, 0);
- green = MIN(green, conn->fmt.green_max);
+ green = MIN(green, priv->fmt.green_max);
blue = COMPONENT(blue, *lp) + COMPONENT(blue, *cp) - COMPONENT(blue, *llp);
blue = MAX(blue, 0);
- blue = MIN(blue, conn->fmt.blue_max);
+ blue = MIN(blue, priv->fmt.blue_max);
*ppixel = SWAP_RFB(conn,
- (red << conn->fmt.red_shift) |
- (green << conn->fmt.green_shift) |
- (blue << conn->fmt.blue_shift));
+ (red << priv->fmt.red_shift) |
+ (green << priv->fmt.green_shift) |
+ (blue << priv->fmt.blue_shift));
}
static void TIGHT_SUM_PIXEL(VncConnection *conn,
src_pixel_t *lhs, src_pixel_t *rhs)
{
+ VncConnectionPrivate *priv = conn->priv;
src_pixel_t red, green, blue;
red = COMPONENT(red, *lhs) + COMPONENT(red, *rhs);
@@ -133,9 +136,9 @@ static void TIGHT_SUM_PIXEL(VncConnection *conn,
blue = COMPONENT(blue, *lhs) + COMPONENT(blue, *rhs);
*lhs = SWAP_RFB(conn,
- ((red & conn->fmt.red_max) << conn->fmt.red_shift) |
- ((green & conn->fmt.green_max) << conn->fmt.green_shift) |
- ((blue & conn->fmt.blue_max) << conn->fmt.blue_shift));
+ ((red & priv->fmt.red_max) << priv->fmt.red_shift) |
+ ((green & priv->fmt.green_max) << priv->fmt.green_shift) |
+ ((blue & priv->fmt.blue_max) << priv->fmt.blue_shift));
}
#endif
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index 4eb10af..165f67a 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -1619,7 +1619,7 @@ static void vnc_display_finalize (GObject *obj)
if (vnc_connection_is_open(priv->conn)) {
g_warning("VNC widget finalized before the connection finished shutting down\n");
}
- vnc_connection_free(priv->conn);
+ g_object_unref(G_OBJECT(priv->conn));
display->priv->conn = NULL;
if (priv->fb) {
--
1.6.5.2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]