29#define close closesocket
30#define strcasecmp _strcmpi
37#include "../rdesktop.h"
41#define HBITMAP R_HBITMAP
42#define HCURSOR R_HCURSOR
57#include <rfb/rfbregion.h>
60#define TOBYTES(bits) ((bits)/BITSPERBYTES)
67extern int client_counter;
118 if (*
cx < 0 || *
cy < 0)
120 return (*
cx > 0 && *
cy > 0 && *x < server->
width && *y < server->
height);
130#define FIRST_MODIFIER XK_Shift_L
131#define LAST_MODIFIER XK_Hyper_R
154vncKey(rfbBool
down, rfbKeySym keysym,
struct _rfbClientRec *cl)
198vncMouse(
int buttonMask,
int x,
int y,
struct _rfbClientRec *cl)
205 for (
b = 0;
b < 3;
b++)
221 rfbDefaultPtrAddEvent(buttonMask,
x,
y, cl);
232 int rfbListenSock, addrlen =
sizeof(
addr);
234 rfbListenSock = rfbListenOnTCPPort(
rfb_port);
236 if (rfbListenSock <= 0)
242 FD_SET(rfbListenSock, &fdset);
250 error(
"Error accepting client (%d: %s.\n",
257 error(
"Error connecting to RDP server.\n");
264 printf(
"Connection successful.\n");
266 printf(
"Disconnecting...\n");
285 for (
i = 0;
i < 0x100;
i++)
287 (((
i >> 7) & 1)) | (((
i >> 6) & 1) << 1) | (((
i >> 5) & 1) << 2) |
288 (((
i >> 4) & 1) << 3) | (((
i >> 3) & 1) << 4) | (((
i >> 2) & 1) << 5) |
289 (((
i >> 1) & 1) << 6) | (((
i >> 0) & 1) << 7);
297 server->httpPort = 6124 + client_counter;
298 server->port = 5924 + client_counter;
337 rfbCloseClient(
server->clientHead);
357 rfbProcessEvents(
server, 0);
406 uint8_t *cm = colourMap->data.bytes;
408 for (
i = 1;
i < 255;
i++)
410 m =
abs(cm[
i * 3] -
p[0]) +
abs(cm[
i * 3 + 1] -
p[1]) +
abs(cm[
i * 3 + 2] -
p[2]);
426 uint8_t white[3] = { 0xff, 0xff, 0xff };
427 uint8_t black[3] = { 0, 0, 0 };
430 rfbColourMap *colourMap = &
server->colourMap;
447 if (
cur[0] > 0x80 ||
cur[1] > 0x80 ||
cur[2] > 0x80)
449 if (!(d0[(
j *
width +
i) / 8] & (0x80 >> (
i & 7))))
453 d0[(
j *
width +
i) / 8] |= 0x80 >> (
i & 7);
467 cursor->mask = (
char *) d0;
469 cursor->richSource = cdata;
489 rfbFreeCursor((rfbCursorPtr)
cursor);
511 int byte =
x / 8 + (
y * ((
width + 7) / 8));
513 byte = (
byte >> (
x & 7)) & 0x01;
578 int x,
int y,
int cx,
int cy)
592 ((
char *) (
buf->data))[
i] = !((
char *) (
buf->data))[
i];
595 unimpl(
"ui_destblt: opcode=%d %d,%d %dx%d\n", opcode,
x,
y,
cx,
cy);
601 int x,
int y,
int cx,
int cy,
602 BRUSH * brush,
int bgcolour,
int fgcolour)
604 switch (brush->style)
613 for (yy = 0; yy <
cy; yy++)
634 for (yy = 0; yy < 8; yy++)
636 for (
xx = 0;
xx < 8;
xx++)
640 yy) ? fgcolour : bgcolour);
657 unimpl(
"pattern blit (%d,%d) opcode=%d bg=%d fg=%d\n",
x,
y, opcode, bgcolour, fgcolour);
669 unimpl(
"brush %d\n", brush->style);
675 int x,
int y,
int cx,
int cy,
693 int x,
int y,
int cx,
int cy,
722 unimpl(
"ui_memblt: op%d %d,%d %dx%d\n", opcode,
x,
y,
cx,
cy);
732 int x,
int y,
int cx,
int cy,
734 BRUSH * brush,
int bgcolour,
int fgcolour)
753 unimpl(
"ui_triblt 1x%x\n", opcode);
761 int startx,
int starty,
int endx,
int endy,
767 rfbDrawLine(
server, startx, starty, endx, endy, pen->
colour);
772 int x,
int y,
int cx,
int cy,
783 int x,
int y,
int cx,
int cy,
784 HGLYPH glyph,
int srcx,
int srcy,
785 int bgcolour,
int fgcolour)
797 bgcolour = fgcolour ^ 0xff;
802 for (yy = srcy; yy < srcy +
cy; yy++)
804 for (
xx = srcx;
xx < srcx +
cx;
xx++)
832 unimpl(
"mix %d\n", mixmode);
837#define DO_GLYPH(ttext,idx) \
839 glyph = cache_get_font (font, ttext[idx]);\
840 if (!(flags & TEXT2_IMPLICIT_X))\
842 offset = ttext[++idx];\
843 if ((offset & 0x80))\
844 offset = ((offset & 0x7f) << 8) | ttext[++idx];\
845 if (flags & TEXT2_VERTICAL)\
852 ui_draw_glyph (mixmode, x + (short) glyph->offset,\
853 y + (short) glyph->baseline,\
854 glyph->width, glyph->height,\
855 glyph->pixmap, 0, 0, bgcolour, fgcolour);\
856 if (flags & TEXT2_IMPLICIT_X)\
864 int clipx,
int clipy,
int clipcx,
int clipcy,
865 int boxx,
int boxy,
int boxcx,
int boxcy,
874 ui_rect(boxx, boxy, boxcx, boxcy, bgcolour);
878 ui_rect(clipx, clipy, clipcx, clipcy, bgcolour);
892 error(
"this shouldn't be happening\n");
949 int ox, oy, srcx, srcy;
974 {8, 8, 1, 0, 7, 7, 3, 0, 3, 6}
976 {16, 16, 1, 1, 31, 63, 31, 0, 5, 10}
978 {32, 24, 1, 1, 255, 255, 255, 0, 8, 16}
980 {32, 32, 1, 1, 2047, 2047, 1023, 0, 11, 22}
994 b->data = (
void *)
xmalloc(
w *
h * (
b->format->bitsPerPixel / 8));
1006 memcpy(
buf->data,
b->data,
b->linew *
b->h *
b->format->bitsPerPixel / 8);
1014 rfbPrintStats(
server->clientHead);
1019#define GETPIXEL(buf,x,y) \
1020 (((uint8_t*)(buf->data))[(x)+((y)*buf->linew)])
1021#define SETPIXEL(buf,x,y,p) \
1022 (((uint8_t*)(buf->data))[(x)+((y)*buf->linew)] = (uint8_t)p)
1032 if (
s->serverFormat.bitsPerPixel ==
src->format->bitsPerPixel
1033 && srcx + w <= src->
w && srcy + h <= src->
h)
1037 srcdata =
src->data + (srcy *
src->linew + srcx);
1038 dstdata =
s->frameBuffer + (
y *
s->paddedWidthInBytes +
x);
1039 for (yy = 0; yy <
h; yy++)
1042 dstdata +=
s->paddedWidthInBytes;
1043 srcdata +=
src->linew;
1049 for (yy =
y; yy <
y +
h; yy++)
1051 int ysrc = srcy + yy -
y;
1052 while (ysrc >=
src->h)
1057 int xsrc = srcx +
xx -
x;
1058 while (xsrc >=
src->linew)
1071 rfbDoCopyRect(
s,
x,
y,
x +
w,
y +
h,
x - srcx,
y - srcy);
1078 rfbMarkRectAsModified(
s,
x,
y,
x +
w,
y +
h);
1090 for (yy =
y; yy <
y +
h; yy++)
1092 int ysrc = srcy + yy -
y;
1093 while (ysrc >=
src->h)
1098 int xsrc = srcx +
xx -
x;
1099 while (xsrc >=
src->linew)
1108 rfbMarkRectAsModified(
s,
x,
y,
x +
w,
y +
h);
1119 for (yy =
y; yy <
y +
h; yy++)
1121 int ysrc = srcy + yy -
y;
1122 while (ysrc >=
src->h)
1127 int xsrc = srcx +
xx -
x;
1128 while (xsrc >=
src->linew)
1137 rfbMarkRectAsModified(
s,
x,
y,
x +
w,
y +
h);
1148 for (yy =
y; yy <
y +
h; yy++)
1150 int ysrc = srcy + yy -
y;
1151 while (ysrc >=
src->h)
1156 int xsrc = srcx +
xx -
x;
1157 while (xsrc >=
src->linew)
1166 rfbMarkRectAsModified(
s,
x,
y,
x +
w,
y +
h);
1181 int i,
j,
w = (
mask->w + 7) / 8, mask_size =
w *
mask->h,
1183 rfbCursorPtr
c = (rfbCursorPtr)
xmalloc(
sizeof(rfbCursor));
1186 error(
"ERROR! Mask is %dx%d, Pointer is %dx%d\n",
1192 c->height =
mask->h;
1194 c->mask = (
char *)
xmalloc(mask_size);
1195 for (
j = 0;
j <
c->height;
j++)
1196 for (
i = 0;
i <
w;
i++)
1197 c->mask[
j *
w +
i] =
1220 unsigned long offset = (
x + (
y * (
b->linew))) * (
b->format->bitsPerPixel >> 3);
1227 unsigned long offset = (
x + (
y * (
b->linew))) * (
b->format->bitsPerPixel >> 3);
1236 if (
x +
w >
s->width)
1238 if (
y +
h >
s->height)
1240 if (
w <= 0 ||
h <= 0)
1246 if (
s->serverFormat.bitsPerPixel == 8)
1250 dstdata =
s->frameBuffer + (
y *
s->paddedWidthInBytes +
x);
1251 for (yy = 0; yy <
h; yy++)
1254 dstdata +=
s->paddedWidthInBytes;
1259 for (yy =
y; yy <
y +
h; yy++)
1268 rfbMarkRectAsModified(
s,
x,
y,
x +
w,
y +
h);
1279 if (
s->serverFormat.bitsPerPixel == 8)
1282 int srcstep, dststep;
1283 char *srcdata, *dstdata;
1284 srcstep =
s->paddedWidthInBytes *
s->serverFormat.bitsPerPixel / 8;
1285 dststep =
w *
s->serverFormat.bitsPerPixel / 8;
1287 srcdata =
s->frameBuffer + (
y * srcstep +
x *
s->serverFormat.bitsPerPixel / 8);
1288 for (yy = 0; yy <
h; yy++)
1290 memcpy(dstdata, srcdata, dststep);
1297 for (yy =
y; yy <
y +
h; yy++)
1314 rfbColourMap *
m = (rfbColourMap *)
xmalloc(
sizeof(rfbColourMap));
1326 m->data.bytes[3 *
i + 0] =
r;
1327 m->data.bytes[3 *
i + 1] =
g;
1328 m->data.bytes[3 *
i + 2] =
b;
1336 free(
m->data.bytes);
1345 rfbSetClientColourMaps(
s, 0, 0);
1361 rfbClientIteratorPtr iter;
1369 iter = rfbGetClientIterator(
server);
1370 while ((cl = rfbClientIteratorNext(iter)))
1371 if (cl->useNewFBSize)
1372 cl->newFBSizePending =
TRUE;
1374 rfbLog(
"Warning: Client %s does not support NewFBSize!\n ", cl->host);
1375 rfbReleaseClientIterator(iter);
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
void cache_put_text(uint8 cache_id, void *data, int length)
void cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 *data)
DATABLOB * cache_get_text(uint8 cache_id)
uint8 * cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
#define MOUSE_FLAG_BUTTON1
#define MOUSE_FLAG_BUTTON2
#define MOUSE_FLAG_BUTTON3
RD_BOOL handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, RD_BOOL pressed)
void rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode)
void rdp_disconnect(void)
key_translation xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)
void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2)
RD_BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password, char *command, char *directory, RD_BOOL reconnect)
void ensure_remote_modifiers(uint32 ev_time, key_translation tr)
void unimpl(char *format,...)
void rdp_main_loop(RD_BOOL *deactivated, uint32 *ext_disc_reason)
void shell(int argc, const char *argv[])
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
GLint GLint GLsizei GLsizei GLsizei depth
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
GLuint GLuint GLsizei count
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLsizei GLsizei height
GLdouble GLdouble GLdouble r
GLint GLint GLsizei width
GLsizei const GLvoid * pointer
GLboolean GLboolean GLboolean b
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei GLsizei * length
GLenum const GLvoid * addr
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define memcpy(s1, s2, n)
const char * strerror(int err)
_Out_opt_ int _Out_opt_ int * cy
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
HBITMAP ui_create_bitmap(int width, int height, uint8 *data)
void vncTransBlitFrom(rfbScreenInfoPtr s, int x, int y, int w, int h, vncBuffer *src, int srcx, int srcy, int bg)
void ui_rect(int x, int y, int cx, int cy, int colour)
void vncAndBlitFrom(rfbScreenInfoPtr s, int x, int y, int w, int h, vncBuffer *src, int srcx, int srcy)
int ListenOnTCPPort(int port)
void ui_destroy_cursor(HCURSOR cursor)
vncBuffer * vncGetRect(rfbScreenInfoPtr s, int x, int y, int w, int h)
void ui_patblt(uint8 opcode, int x, int y, int cx, int cy, BRUSH *brush, int bgcolour, int fgcolour)
void vncSetColourMap(rfbScreenInfoPtr s, rfbColourMap *m)
BOOL vncwinClipRect(int *x, int *y, int *cx, int *cy)
#define DO_GLYPH(ttext, idx)
void ui_destroy_bitmap(HBITMAP bmp)
void ui_set_colourmap(HCOLOURMAP map)
static uint8_t reverseByte[0x100]
vncPixel vncGetPixel(vncBuffer *b, int x, int y)
HCURSOR ui_create_cursor(unsigned int x, unsigned int y, int width, int height, uint8 *mask, uint8 *data)
void vncDeleteColourMap(rfbColourMap *m)
void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy)
void ui_set_null_cursor(void)
void ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 *data)
void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y, int clipx, int clipy, int clipcx, int clipcy, int boxx, int boxy, int boxcx, int boxcy, int bgcolour, int fgcolour, uint8 *text, uint8 length)
void vncCopyBlit(rfbScreenInfoPtr s, int x, int y, int w, int h, int srcx, int srcy)
vncBuffer * vncDupBuffer(vncBuffer *b)
uint8_t vncLookupColour(rfbColourMap *colourMap, uint8_t *p)
void ui_triblt(uint8 opcode, int x, int y, int cx, int cy, HBITMAP src, int srcx, int srcy, BRUSH *brush, int bgcolour, int fgcolour)
#define GETPIXEL(buf, x, y)
void ui_draw_glyph(int mixmode, int x, int y, int cx, int cy, HGLYPH glyph, int srcx, int srcy, int bgcolour, int fgcolour)
void rdp2vnc_connect(char *server, uint32 flags, char *domain, char *password, char *shell, char *directory)
void vncCopyBlitFromNoEncode(rfbScreenInfoPtr s, int x, int y, int w, int h, vncBuffer *src, int srcx, int srcy)
void vncKey(rfbBool down, rfbKeySym keysym, struct _rfbClientRec *cl)
rfbCursorPtr vncNewCursor(vncBuffer *mask, vncBuffer *pointer, int hotx, int hoty)
void ui_line(uint8 opcode, int startx, int starty, int endx, int endy, PEN *pen)
rfbPixelFormat vnc_formats[]
void vncCopyBlitFrom(rfbScreenInfoPtr s, int x, int y, int w, int h, vncBuffer *src, int srcx, int srcy)
void xwin_toggle_fullscreen(void)
void ui_destroy_glyph(HGLYPH glyph)
void ui_set_cursor(HCURSOR cursor)
void ui_destblt(uint8 opcode, int x, int y, int cx, int cy)
void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
HGLYPH ui_create_glyph(int width, int height, uint8 *data)
void ui_set_clip(int x, int y, int cx, int cy)
void vncSetCursor(rfbScreenInfoPtr s, rfbCursorPtr c)
HCOLOURMAP ui_create_colourmap(COLOURMAP *colours)
void ui_destroy_colourmap(HCOLOURMAP map)
int ui_select(int rdpSocket)
void vncMouse(int buttonMask, int x, int y, struct _rfbClientRec *cl)
BOOL get_key_state(unsigned int state, uint32 keysym)
void vncDeleteBuffer(vncBuffer *b)
static BOOL keystate[LAST_MODIFIER - FIRST_MODIFIER]
#define SETPIXEL(buf, x, y, p)
void vncSetColourMapEntry(rfbColourMap *m, int i, vncPixel r, vncPixel g, vncPixel b)
void ui_memblt(uint8 opcode, int x, int y, int cx, int cy, HBITMAP src, int srcx, int srcy)
static rfbScreenInfoPtr server
void vncXorBlitFrom(rfbScreenInfoPtr s, int x, int y, int w, int h, vncBuffer *src, int srcx, int srcy)
rfbPixelFormat * vncNewFormat(int depth)
void ui_move_pointer(int x, int y)
void vncSetRect(rfbScreenInfoPtr s, int x, int y, int w, int h, vncPixel c)
static vncBuffer * frameBuffer
rfbColourMap * vncNewColourMap(rfbScreenInfoPtr s, int n)
vncBuffer * vncNewBuffer(int w, int h, int depth)
void vncSetPixel(vncBuffer *b, int x, int y, vncPixel c)
unsigned int pointer_size
#define FD_ISSET(fd, set)