#include <SDL.h>
#include <signal.h>
{0,0}
};
{0b00111111, 6},
{0b01111111, 7},
{0b00011111, 5},
{0b00001111, 4},
{0b00000111, 3},
{0,0}
};
static int enableResizable = 1, viewOnly, listenLoop, buttonMask;
static int rightAltKeyDown, leftAltKeyDown;
if (enableResizable)
SDL_Surface*
sdl=SDL_CreateRGBSurface(0,
depth,
0,0,0,0);
rfbClientErr(
"resize: error creating surface: %s\n", SDL_GetError());
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
rfbClientErr(
"resize: error creating window: %s\n", SDL_GetError());
} else {
}
rfbClientErr(
"resize: error creating renderer: %s\n", SDL_GetError());
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
}
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
rfbClientErr(
"resize: error creating texture: %s\n", SDL_GetError());
}
static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) {
SDL_Keycode sym = e->keysym.sym;
switch (sym) {
case SDLK_TAB: k =
XK_Tab;
break;
case SDLK_KP_0: k =
XK_KP_0;
break;
case SDLK_KP_1: k =
XK_KP_1;
break;
case SDLK_KP_2: k =
XK_KP_2;
break;
case SDLK_KP_3: k =
XK_KP_3;
break;
case SDLK_KP_4: k =
XK_KP_4;
break;
case SDLK_KP_5: k =
XK_KP_5;
break;
case SDLK_KP_6: k =
XK_KP_6;
break;
case SDLK_KP_7: k =
XK_KP_7;
break;
case SDLK_KP_8: k =
XK_KP_8;
break;
case SDLK_KP_9: k =
XK_KP_9;
break;
case SDLK_UP: k =
XK_Up;
break;
case SDLK_DOWN: k =
XK_Down;
break;
case SDLK_LEFT: k =
XK_Left;
break;
case SDLK_HOME: k =
XK_Home;
break;
case SDLK_END: k =
XK_End;
break;
case SDLK_F1: k =
XK_F1;
break;
case SDLK_F2: k =
XK_F2;
break;
case SDLK_F3: k =
XK_F3;
break;
case SDLK_F4: k =
XK_F4;
break;
case SDLK_F5: k =
XK_F5;
break;
case SDLK_F6: k =
XK_F6;
break;
case SDLK_F7: k =
XK_F7;
break;
case SDLK_F8: k =
XK_F8;
break;
case SDLK_F9: k =
XK_F9;
break;
case SDLK_F10: k =
XK_F10;
break;
case SDLK_F11: k =
XK_F11;
break;
case SDLK_F12: k =
XK_F12;
break;
case SDLK_F13: k =
XK_F13;
break;
case SDLK_F14: k =
XK_F14;
break;
case SDLK_F15: k =
XK_F15;
break;
#if 0
case SDLK_COMPOSE: k = XK_Compose; break;
#endif
case SDLK_HELP: k =
XK_Help;
break;
case SDLK_PRINTSCREEN: k =
XK_Print;
break;
default: break;
}
if (k == 0 && sym > 0x0 && sym < 0x100 && e->keysym.mod & KMOD_CTRL)
k = sym;
return k;
}
static rfbKeySym utf8char2rfbKeySym(
const char chr[4]) {
int bytes = strlen(chr);
int i;
for(i = 1; i < bytes; ++i, ++chr) {
}
return codep;
}
static void update(
rfbClient* cl,
int x,
int y,
int w,
int h) {
rfbClientErr(
"update: failed to update texture: %s\n", SDL_GetError());
rfbClientErr(
"update: failed to clear renderer: %s\n", SDL_GetError());
rfbClientErr(
"update: failed to copy texture to renderer: %s\n", SDL_GetError());
}
static void kbd_leds(
rfbClient* cl,
int value,
int pad) {
fprintf(stderr,"Led State= 0x%02X\n", value);
fflush(stderr);
}
static void text_chat(
rfbClient* cl,
int value,
char *text) {
switch(value) {
fprintf(stderr,"TextChat: We should open a textchat window!\n");
break;
fprintf(stderr,"TextChat: We should close our window!\n");
break;
fprintf(stderr,"TextChat: We should close our window!\n");
break;
default:
fprintf(stderr,"TextChat: Received \"%s\"\n", text);
break;
}
fflush(stderr);
}
#ifdef __MINGW32__
#define LOG_TO_FILE
#endif
#ifdef LOG_TO_FILE
#include <stdarg.h>
static void
log_to_file(const char *format, ...)
{
FILE* logfile;
static char* logfile_str=0;
va_list args;
char buf[256];
time_t log_clock;
return;
if(logfile_str==0) {
logfile_str=getenv("VNCLOG");
if(logfile_str==0)
logfile_str="vnc.log";
}
logfile=fopen(logfile_str,"a");
va_start(args, format);
time(&log_clock);
strftime(buf, 255, "%d/%m/%Y %X ", localtime(&log_clock));
fprintf(logfile,buf);
vfprintf(logfile, format, args);
fflush(logfile);
va_end(args);
fclose(logfile);
}
#endif
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
if(cl)
}
{
switch(e->type) {
case SDL_WINDOWEVENT:
switch (e->window.event) {
case SDL_WINDOWEVENT_EXPOSED:
break;
case SDL_WINDOWEVENT_RESIZED:
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
if (SDL_HasClipboardText()) {
char *text = SDL_GetClipboardText();
if(text) {
}
}
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
if (rightAltKeyDown) {
}
if (leftAltKeyDown) {
}
break;
}
break;
case SDL_MOUSEWHEEL:
{
int steps;
if (viewOnly)
break;
if(e->wheel.y > 0)
for(steps = 0; steps < e->wheel.y; ++steps) {
}
if(e->wheel.y < 0)
for(steps = 0; steps > e->wheel.y; --steps) {
}
if(e->wheel.x > 0)
for(steps = 0; steps < e->wheel.x; ++steps) {
}
if(e->wheel.x < 0)
for(steps = 0; steps > e->wheel.x; --steps) {
}
break;
}
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
{
int state, i;
if (viewOnly)
break;
if (e->type == SDL_MOUSEMOTION) {
state = e->motion.state;
}
else {
state = e->button.button;
if (e->type == SDL_MOUSEBUTTONDOWN)
buttonMask |= state;
else
buttonMask &= ~state;
break;
}
}
break;
}
case SDL_KEYUP:
case SDL_KEYDOWN:
if (viewOnly)
break;
if (e->key.keysym.sym == SDLK_RALT)
rightAltKeyDown = e->type == SDL_KEYDOWN;
if (e->key.keysym.sym == SDLK_LALT)
leftAltKeyDown = e->type == SDL_KEYDOWN;
break;
case SDL_TEXTINPUT:
if (viewOnly)
break;
rfbKeySym sym = utf8char2rfbKeySym(e->text.text);
break;
case SDL_QUIT:
if(listenLoop)
{
cleanup(cl);
}
else
{
exit(0);
}
default:
}
}
static void got_selection_latin1(
rfbClient *cl,
const char *text,
int len)
{
rfbClientLog(
"received latin1 clipboard text '%s'\n", text);
if(SDL_SetClipboardText(text) != 0)
rfbClientErr(
"could not set received latin1 clipboard text: %s\n", SDL_GetError());
}
static void got_selection_utf8(
rfbClient *cl,
const char *buf,
int len)
{
if(SDL_SetClipboardText(buf) != 0)
rfbClientErr(
"could not set received utf8 clipboard text: %s\n", SDL_GetError());
}
if (!c) {
return NULL;
}
free(c);
return NULL;
}
free(c);
return NULL;
}
rfbClientErr(
"something else than username and password required for authentication\n");
return NULL;
}
rfbClientLog(
"username and password required for authentication!\n");
printf("user: ");
printf("pass: ");
return c;
}
#ifdef mac
#define main SDLmain
#endif
int main(
int argc,
char** argv) {
int i, j;
SDL_Event e;
#ifdef LOG_TO_FILE
#endif
for (i = 1, j = 1; i < argc; i++)
if (!strcmp(argv[i], "-viewonly"))
viewOnly = 1;
else if (!strcmp(argv[i], "-resizable"))
enableResizable = 1;
else if (!strcmp(argv[i], "-no-resizable"))
enableResizable = 0;
else if (!strcmp(argv[i], "-listen")) {
listenLoop = 1;
argv[i] = "-listennofork";
++j;
}
else {
if (i != j)
argv[j] = argv[i];
j++;
}
argc = j;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
atexit(SDL_Quit);
signal(SIGINT, exit);
do {
{
cl = NULL;
cleanup(cl);
break;
}
while(1) {
if(SDL_PollEvent(&e)) {
if(!handleSDLEvent(cl, &e))
break;
}
else {
if(i<0)
{
cleanup(cl);
break;
}
if(i)
{
cleanup(cl);
break;
}
}
}
}
while(listenLoop);
return 0;
}
int main(int argc, char **argv)
struct @5 buttonMapping[]
SDL_Renderer * sdlRenderer
rfbBool SendClientCutText(rfbClient *client, char *str, int len)
Places a Latin-1-encoded string on the server's clipboard.
int WaitForMessage(rfbClient *client, unsigned int usecs)
Waits for an RFB message to arrive from the server.
rfbBool TextChatOpen(rfbClient *client)
Opens a text chat window on the server.
rfbClientLogProc rfbClientLog
rfbClient * rfbGetClient(int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
Allocates and returns a pointer to an rfbClient structure.
void rfbClientCleanup(rfbClient *client)
Cleans up the client structure and releases the memory allocated for it.
rfbBool SendExtDesktopSize(rfbClient *client, uint16_t width, uint16_t height)
Sends a SetDesktopSize event to the server.
rfbBool HandleRFBServerMessage(rfbClient *client)
Handles messages from the RFB server.
rfbBool SendPointerEvent(rfbClient *client, int x, int y, int buttonMask)
Sends a pointer event to the server.
rfbBool rfbInitClient(rfbClient *client, int *argc, char **argv)
Initializes the client.
rfbBool SendKeyEvent(rfbClient *client, uint32_t key, rfbBool down)
Sends a key event to the server.
rfbBool SendClientCutTextUTF8(rfbClient *client, char *str, int len)
Places a UTF-8-encoded string on the server's clipboard if the server supports it.
rfbBool SendFramebufferUpdateRequest(rfbClient *client, int x, int y, int w, int h, rfbBool incremental)
Sends a framebuffer update request to the server.
#define rfbCredentialTypeUser
#define LISTEN_PORT_OFFSET
void * rfbClientGetClientData(rfbClient *client, void *tag)
Returns a pointer to the client data associated with the given tag.
rfbClientLogProc rfbClientErr
void rfbClientSetClientData(rfbClient *client, void *tag, void *data)
Associates a client data tag with the given pointer.
rfbBool rfbEnableClientLogging
rfbBool SetFormatAndEncodings(rfbClient *client)
Sends format and encoding parameters to the server.
#define rfbTextChatFinished
GotFrameBufferUpdateProc GotFrameBufferUpdate
GotXCutTextProc GotXCutText
HandleTextChatProc HandleTextChat
GotXCutTextUTF8Proc GotXCutTextUTF8
Callback fired when "Extended Clipboard" UTF-8 text data is received.
GetCredentialProc GetCredential
To support security types that requires user input (except VNC password authentication),...
HandleKeyboardLedStateProc HandleKeyboardLedState
MallocFrameBufferProc MallocFrameBuffer
For GetCredentialProc callback function to return.
struct rfbCredential::@3 userCredential
Plain (VeNCrypt), MSLogon (UltraVNC)