diff options
Diffstat (limited to 'xorg/server/module/rdpClientCon.c')
-rw-r--r-- | xorg/server/module/rdpClientCon.c | 491 |
1 files changed, 488 insertions, 3 deletions
diff --git a/xorg/server/module/rdpClientCon.c b/xorg/server/module/rdpClientCon.c index 3edd1e0c..5e89b81a 100644 --- a/xorg/server/module/rdpClientCon.c +++ b/xorg/server/module/rdpClientCon.c @@ -43,6 +43,14 @@ Client connection to xrdp #define LTOUI32(_in) ((unsigned int)(_in)) +#define USE_MAX_OS_BYTES 1 +#define MAX_OS_BYTES (16 * 1024 * 1024) + +static int +rdpClientConSendPending(rdpPtr dev, rdpClientCon *clientCon); +static int +rdpClientConSendMsg(rdpPtr dev, rdpClientCon *clientCon); + /******************************************************************************/ static int rdpClientConGotConnection(ScreenPtr pScreen, rdpPtr dev) @@ -219,13 +227,13 @@ rdpClientConInit(rdpPtr dev) if (dev->listen_sck == 0) { unlink(dev->uds_data); - dev->listen_sck = g_tcp_local_socket_stream(); - if (g_tcp_local_bind(dev->listen_sck, dev->uds_data) != 0) + dev->listen_sck = g_sck_local_socket_stream(); + if (g_sck_local_bind(dev->listen_sck, dev->uds_data) != 0) { LLOGLN(0, ("rdpClientConInit: g_tcp_local_bind failed")); return 1; } - g_tcp_listen(dev->listen_sck); + g_sck_listen(dev->listen_sck); AddEnabledDevice(dev->listen_sck); } return 0; @@ -243,3 +251,480 @@ rdpClientConDeinit(rdpPtr dev) } return 0; } + +/*****************************************************************************/ +static int +rdpClientConDisconnect(rdpPtr dev, rdpClientCon *clientCon) +{ + return 0; +} + +/******************************************************************************/ +int +rdpClientConBeginUpdate(rdpPtr dev, rdpClientCon *clientCon) +{ + LLOGLN(10, ("rdpClientConBeginUpdate:")); + + if (clientCon->connected) + { + if (clientCon->begin) + { + return 0; + } + init_stream(clientCon->out_s, 0); + s_push_layer(clientCon->out_s, iso_hdr, 8); + out_uint16_le(clientCon->out_s, 1); /* begin update */ + out_uint16_le(clientCon->out_s, 4); /* size */ + clientCon->begin = TRUE; + clientCon->count = 1; + } + + return 0; +} + +/******************************************************************************/ +int +rdpClientConEndUpdate(rdpPtr dev, rdpClientCon *clientCon) +{ + LLOGLN(10, ("rdpClientConEndUpdate")); + + if (clientCon->connected && clientCon->begin) + { + if (dev->do_dirty_ons) + { + /* in this mode, end update is only called in check dirty */ + rdpClientConSendPending(dev, clientCon); + } + else + { + rdpClientConScheduleDeferredUpdate(dev); + } + } + + return 0; +} + +/******************************************************************************/ +int +rdpClientConPreCheck(rdpPtr dev, rdpClientCon *clientCon, int in_size) +{ + int rv; + + rv = 0; + if (clientCon->begin == FALSE) + { + rdpClientConBeginUpdate(dev, clientCon); + } + + if ((clientCon->out_s->p - clientCon->out_s->data) > + (clientCon->out_s->size - (in_size + 20))) + { + s_mark_end(clientCon->out_s); + if (rdpClientConSendMsg(dev, clientCon) != 0) + { + LLOGLN(0, ("rdpClientConPreCheck: rdpup_send_msg failed")); + rv = 1; + } + clientCon->count = 0; + init_stream(clientCon->out_s, 0); + s_push_layer(clientCon->out_s, iso_hdr, 8); + } + + return rv; +} + +/******************************************************************************/ +int +rdpClientConDeleteOsSurface(rdpPtr dev, rdpClientCon *clientCon, int rdpindex) +{ + LLOGLN(10, ("rdpClientConDeleteOsSurface: rdpindex %d", rdpindex)); + + if (clientCon->connected) + { + LLOGLN(10, ("rdpClientConDeleteOsSurface: rdpindex %d", rdpindex)); + rdpClientConPreCheck(dev, clientCon, 8); + out_uint16_le(clientCon->out_s, 22); + out_uint16_le(clientCon->out_s, 8); + clientCon->count++; + out_uint32_le(clientCon->out_s, rdpindex); + } + + return 0; +} + +/*****************************************************************************/ +/* returns -1 on error */ +int +rdpClientConAddOsBitmap(rdpPtr dev, rdpClientCon *clientCon, + PixmapPtr pixmap, rdpPixmapPtr priv) +{ + int index; + int rv; + int oldest; + int oldest_index; + int this_bytes; + + LLOGLN(10, ("rdpClientConAddOsBitmap:")); + if (clientCon->connected == FALSE) + { + LLOGLN(10, ("rdpClientConAddOsBitmap: test error 1")); + return -1; + } + + if (clientCon->osBitmaps == NULL) + { + LLOGLN(10, ("rdpClientConAddOsBitmap: test error 2")); + return -1; + } + + this_bytes = pixmap->devKind * pixmap->drawable.height; + if (this_bytes > MAX_OS_BYTES) + { + LLOGLN(10, ("rdpClientConAddOsBitmap: error, too big this_bytes %d " + "width %d height %d", this_bytes, + pixmap->drawable.height, pixmap->drawable.height)); + return -1; + } + + oldest = 0x7fffffff; + oldest_index = -1; + rv = -1; + index = 0; + + while (index < clientCon->maxOsBitmaps) + { + if (clientCon->osBitmaps[index].used == FALSE) + { + clientCon->osBitmaps[index].used = TRUE; + clientCon->osBitmaps[index].pixmap = pixmap; + clientCon->osBitmaps[index].priv = priv; + clientCon->osBitmaps[index].stamp = clientCon->osBitmapStamp; + clientCon->osBitmapStamp++; + clientCon->osBitmapNumUsed++; + rv = index; + break; + } + else + { + if (clientCon->osBitmaps[index].stamp < oldest) + { + oldest = clientCon->osBitmaps[index].stamp; + oldest_index = index; + } + } + index++; + } + + if (rv == -1) + { + if (oldest_index == -1) + { + LLOGLN(0, ("rdpClientConAddOsBitmap: error")); + } + else + { + LLOGLN(10, ("rdpClientConAddOsBitmap: too many pixmaps removing " + "oldest_index %d", oldest_index)); + rdpClientConRemoveOsBitmap(dev, clientCon, oldest_index); + rdpClientConDeleteOsSurface(dev, clientCon, oldest_index); + clientCon->osBitmaps[oldest_index].used = TRUE; + clientCon->osBitmaps[oldest_index].pixmap = pixmap; + clientCon->osBitmaps[oldest_index].priv = priv; + clientCon->osBitmaps[oldest_index].stamp = clientCon->osBitmapStamp; + clientCon->osBitmapStamp++; + clientCon->osBitmapNumUsed++; + rv = oldest_index; + } + } + + if (rv < 0) + { + LLOGLN(10, ("rdpClientConAddOsBitmap: test error 3")); + return rv; + } + + clientCon->osBitmapAllocSize += this_bytes; + LLOGLN(10, ("rdpClientConAddOsBitmap: this_bytes %d " + "clientCon->osBitmapAllocSize %d", + this_bytes, clientCon->osBitmapAllocSize)); +#if USE_MAX_OS_BYTES + while (clientCon->osBitmapAllocSize > MAX_OS_BYTES) + { + LLOGLN(10, ("rdpClientConAddOsBitmap: must delete " + "clientCon->osBitmapNumUsed %d", + clientCon->osBitmapNumUsed)); + /* find oldest */ + oldest = 0x7fffffff; + oldest_index = -1; + index = 0; + while (index < clientCon->maxOsBitmaps) + { + if (clientCon->osBitmaps[index].used && + (clientCon->osBitmaps[index].stamp < oldest)) + { + oldest = clientCon->osBitmaps[index].stamp; + oldest_index = index; + } + index++; + } + if (oldest_index == -1) + { + LLOGLN(0, ("rdpClientConAddOsBitmap: error 1")); + break; + } + if (oldest_index == rv) + { + LLOGLN(0, ("rdpClientConAddOsBitmap: error 2")); + break; + } + rdpClientConRemoveOsBitmap(dev, clientCon, oldest_index); + rdpClientConDeleteOsSurface(dev, clientCon, oldest_index); + } +#endif + LLOGLN(10, ("rdpClientConAddOsBitmap: new bitmap index %d", rv)); + LLOGLN(10, ("rdpClientConAddOsBitmap: clientCon->osBitmapNumUsed %d " + "clientCon->osBitmapStamp 0x%8.8x", + clientCon->osBitmapNumUsed, clientCon->osBitmapStamp)); + return rv; +} + +/*****************************************************************************/ +int +rdpClientConRemoveOsBitmap(rdpPtr dev, rdpClientCon *clientCon, int rdpindex) +{ + PixmapPtr pixmap; + rdpPixmapPtr priv; + int this_bytes; + + if (clientCon->osBitmaps == NULL) + { + LLOGLN(10, ("rdpClientConRemoveOsBitmap: test error 1")); + return 1; + } + + LLOGLN(10, ("rdpClientConRemoveOsBitmap: index %d stamp %d", + rdpindex, clientCon->osBitmaps[rdpindex].stamp)); + + if ((rdpindex < 0) && (rdpindex >= clientCon->maxOsBitmaps)) + { + LLOGLN(10, ("rdpClientConRemoveOsBitmap: test error 2")); + return 1; + } + + if (clientCon->osBitmaps[rdpindex].used) + { + pixmap = clientCon->osBitmaps[rdpindex].pixmap; + priv = clientCon->osBitmaps[rdpindex].priv; + rdpDrawItemRemoveAll(dev, priv); + this_bytes = pixmap->devKind * pixmap->drawable.height; + clientCon->osBitmapAllocSize -= this_bytes; + LLOGLN(10, ("rdpClientConRemoveOsBitmap: this_bytes %d " + "clientCon->osBitmapAllocSize %d", this_bytes, + clientCon->osBitmapAllocSize)); + clientCon->osBitmaps[rdpindex].used = 0; + clientCon->osBitmaps[rdpindex].pixmap = 0; + clientCon->osBitmaps[rdpindex].priv = 0; + clientCon->osBitmapNumUsed--; + priv->status = 0; + priv->con_number = 0; + priv->use_count = 0; + } + else + { + LLOGLN(0, ("rdpup_remove_os_bitmap: error")); + } + + LLOGLN(10, ("rdpup_remove_os_bitmap: clientCon->osBitmapNumUsed %d", + clientCon->osBitmapNumUsed)); + return 0; +} + +/*****************************************************************************/ +int +rdpClientConUpdateOsUse(rdpPtr dev, rdpClientCon *clientCon, int rdpindex) +{ + if (clientCon->osBitmaps == NULL) + { + return 1; + } + + LLOGLN(10, ("rdpClientConUpdateOsUse: index %d stamp %d", + rdpindex, clientCon->osBitmaps[rdpindex].stamp)); + + if ((rdpindex < 0) && (rdpindex >= clientCon->maxOsBitmaps)) + { + return 1; + } + + if (clientCon->osBitmaps[rdpindex].used) + { + clientCon->osBitmaps[rdpindex].stamp = clientCon->osBitmapStamp; + clientCon->osBitmapStamp++; + } + else + { + LLOGLN(0, ("rdpClientConUpdateOsUse: error rdpindex %d", rdpindex)); + } + + return 0; +} + +/*****************************************************************************/ +/* returns error */ +static int +rdpClientConSend(rdpPtr dev, rdpClientCon *clientCon, char *data, int len) +{ + int sent; + + LLOGLN(10, ("rdpClientConSend - sending %d bytes", len)); + + if (clientCon->sckClosed) + { + return 1; + } + + while (len > 0) + { + sent = g_sck_send(clientCon->sck, data, len, 0); + + if (sent == -1) + { + if (g_sck_last_error_would_block(clientCon->sck)) + { + g_sleep(1); + } + else + { + LLOGLN(0, ("rdpClientConSend: g_tcp_send failed(returned -1)")); + rdpClientConDisconnect(dev, clientCon); + return 1; + } + } + else if (sent == 0) + { + LLOGLN(0, ("rdpClientConSend: g_tcp_send failed(returned zero)")); + rdpClientConDisconnect(dev, clientCon); + return 1; + } + else + { + data += sent; + len -= sent; + } + } + + return 0; +} + +/******************************************************************************/ +static int +rdpClientConSendMsg(rdpPtr dev, rdpClientCon *clientCon) +{ + int len; + int rv; + struct stream *s; + + rv = 1; + s = clientCon->out_s; + if (s != NULL) + { + len = (int) (s->end - s->data); + + if (len > s->size) + { + LLOGLN(0, ("rdpClientConSendMsg: overrun error len %d count %d", + len, clientCon->count)); + } + + s_pop_layer(s, iso_hdr); + out_uint16_le(s, 3); + out_uint16_le(s, clientCon->count); + out_uint32_le(s, len - 8); + rv = rdpClientConSend(dev, clientCon, s->data, len); + } + + if (rv != 0) + { + LLOGLN(0, ("rdpClientConSendMsg: error in rdpup_send_msg")); + } + + return rv; +} + +/******************************************************************************/ +static int +rdpClientConSendPending(rdpPtr dev, rdpClientCon *clientCon) +{ + int rv; + + rv = 0; + if (clientCon->connected && clientCon->begin) + { + out_uint16_le(clientCon->out_s, 2); /* XR_SERVER_END_UPDATE */ + out_uint16_le(clientCon->out_s, 4); /* size */ + clientCon->count++; + s_mark_end(clientCon->out_s); + if (rdpClientConSendMsg(dev, clientCon) != 0) + { + LLOGLN(0, ("rdpClientConSendPending: rdpClientConSendMsg failed")); + rv = 1; + } + } + clientCon->count = 0; + clientCon->begin = FALSE; + return rv; +} + +/******************************************************************************/ +static CARD32 +rdpClientConDeferredUpdateCallback(OsTimerPtr timer, CARD32 now, pointer arg) +{ + rdpPtr dev; + rdpClientCon *clientCon; + + LLOGLN(10, ("rdpClientConDeferredUpdateCallback")); + + dev = (rdpPtr) arg; + clientCon = dev->clientConHead; + while (clientCon != NULL) + { + if (dev->do_dirty_ons) + { + if (clientCon->rectId == clientCon->rectIdAck) + { + rdpClientConCheckDirtyScreen(dev, clientCon); + } + else + { + LLOGLN(0, ("rdpClientConDeferredUpdateCallback: skipping")); + } + } + else + { + rdpClientConSendPending(dev, clientCon); + } + clientCon = clientCon->next; + } + dev->sendUpdateScheduled = FALSE; + return 0; +} + +/******************************************************************************/ +void +rdpClientConScheduleDeferredUpdate(rdpPtr dev) +{ + if (dev->sendUpdateScheduled == FALSE) + { + dev->sendUpdateScheduled = TRUE; + dev->sendUpdateTimer = TimerSet(dev->sendUpdateTimer, 0, 40, + rdpClientConDeferredUpdateCallback, + dev); + } +} + +/******************************************************************************/ +int +rdpClientConCheckDirtyScreen(rdpPtr dev, rdpClientCon *clientCon) +{ + return 0; +} |