This commit is contained in:
Michael Jumper
2010-09-06 00:12:35 -07:00
parent 0761da0cbe
commit cbe9ca43c4

View File

@@ -1,4 +1,3 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -11,6 +10,9 @@
char __guac_password[] = "potato"; char __guac_password[] = "potato";
char* __GUAC_VNC_TAG_IO = "GUACIO";
char* __GUAC_VNC_TAG_PNG_ROWS = "PNG_ROWS";
char* guac_escape_string(const char* str) { char* guac_escape_string(const char* str) {
char* escaped; char* escaped;
@@ -77,16 +79,6 @@ void guac_write_png(png_structp png, png_bytep data, png_size_t length) {
void guac_write_flush(png_structp png) { void guac_write_flush(png_structp png) {
} }
rfbBool guac_malloc_framebuffer(rfbClient* client) {
/* STUB */
fprintf(stderr, "MALLOC FB!\n");
}
void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) {
/* STUB */
fprintf(stderr, "UPDATE!\n");
}
void guac_send_name(GUACIO* io, const char* name) { void guac_send_name(GUACIO* io, const char* name) {
guac_write_string(io, "name:"); guac_write_string(io, "name:");
guac_write_string(io, name); guac_write_string(io, name);
@@ -101,126 +93,21 @@ void guac_send_size(GUACIO* io, int w, int h) {
guac_write_string(io, ";"); guac_write_string(io, ";");
} }
char* guac_vnc_get_password(rfbClient* client) { void guac_send_png(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h) {
/* Freed after use by libvncclient */
char* password = malloc(64);
strncpy(password, __guac_password, 63);
fprintf(stderr, "Sending password: %s\n", password);
return password;
}
void proxy(int client_fd) {
png_structp png; png_structp png;
png_infop png_info; png_infop png_info;
png_byte** png_rows;
png_byte* row; png_byte* row;
char* hostname; /* For now, generate random test image */
char* escaped; for (y=0; y<h; y++) {
int wait_result;
rfbClient* rfb_client;
int x, y; row = png_rows[y];
int test_index; for (x=0; x<w; x++) {
GUACIO* io = guac_open(client_fd);
/*** INIT ***/
rfb_client = rfbGetClient(8, 3, 4); /* 32-bpp client */
/* Can't handle resizing */
/*rfb_client->canHandleNewFBSize = FALSE;
rfb_client->MallocFrameBuffer = guac_malloc_framebuffer;*/
/* Framebuffer update handler */
rfb_client->GotFrameBufferUpdate = guac_vnc_update;
/* Password */
rfb_client->GetPassword = guac_vnc_get_password;
/* No LED / chat */
/*rfb_client->HandleKeyboardLedState = 0;
rfb_client->HandleTextChat = 0;
rfb_client->Bell = 0;
rfb_client->HandleCursorPos = 0;
rfb_client->SoftCursorLockArea = 0;
rfb_client->SoftCursorUnlockScreen = 0;
rfb_client->GotXCutText = 0;
rfb_client->GotCursorShape = 0;
rfb_client->GotCopyRect = 0;*/
hostname = malloc(64);
strcpy(hostname, "localhost");
rfb_client->serverHost = hostname;
rfb_client->serverPort = 5902;
if (rfbInitClient(rfb_client, NULL, NULL)) {
fprintf(stderr, "SUCCESS.\n");
}
escaped = guac_escape_string(rfb_client->desktopName);
guac_send_name(io, escaped);
free(escaped);
guac_send_size(io, rfb_client->width, rfb_client->height);
guac_flush(io);
/* VNC Client Loop */
for (;;) {
wait_result = WaitForMessage(rfb_client, 2000);
if (wait_result < 0) {
fprintf(stderr, "WAIT FAIL\n");
break;
}
if (wait_result > 0) {
if (!HandleRFBServerMessage(rfb_client)) {
fprintf(stderr, "HANDLE FAIL\n");
break;
}
}
}
/* Clean up */
rfbClientCleanup(rfb_client);
/* Allocate rows for PNG */
png_rows = (png_byte**) malloc(100 /* height */ * sizeof(png_byte*));
guac_write_string(io, "name:hello;size:1024,768;");
for (test_index=0; test_index<20; test_index++) {
/* For now, generate test white image */
for (y=0; y<100 /* height */; y++) {
row = (png_byte*) malloc(sizeof(png_byte) * 3 * 100 /* width */);
png_rows[y] = row;
for (x=0; x<100 /* width */; x++) {
*row++ = random() % 0xFF; *row++ = random() % 0xFF;
if (test_index % 2 == 0)
*row++ = random() % 0xFF; *row++ = random() % 0xFF;
else
*row++ = 0x00;
if (test_index % 3 == 0)
*row++ = random() % 0xFF; *row++ = random() % 0xFF;
else
*row++ = 0x00;
} }
} }
@@ -253,8 +140,8 @@ void proxy(int client_fd) {
png_set_IHDR( png_set_IHDR(
png, png,
png_info, png_info,
100, /* width */ w,
100, /* height */ h,
8, 8,
PNG_COLOR_TYPE_RGB, PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_INTERLACE_NONE,
@@ -263,9 +150,9 @@ void proxy(int client_fd) {
); );
guac_write_string(io, "png:"); guac_write_string(io, "png:");
guac_write_int(io, random()%1024); guac_write_int(io, x);
guac_write_string(io, ","); guac_write_string(io, ",");
guac_write_int(io, random()%768); guac_write_int(io, y);
guac_write_string(io, ","); guac_write_string(io, ",");
png_set_rows(png, png_info, png_rows); png_set_rows(png, png_info, png_rows);
png_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL); png_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL);
@@ -279,8 +166,106 @@ void proxy(int client_fd) {
png_destroy_write_struct(&png, &png_info); png_destroy_write_struct(&png, &png_info);
guac_write_string(io, ";"); guac_write_string(io, ";");
}
void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) {
GUACIO* io = rfbClientGetClientData(client, __GUAC_VNC_TAG_IO);
png_byte** png_rows = rfbClientGetClientData(client, __GUAC_VNC_TAG_PNG_ROWS);
guac_send_png(io, x, y, png_rows, 100, 100);
guac_flush(io);
}
char* guac_vnc_get_password(rfbClient* client) {
/* Freed after use by libvncclient */
char* password = malloc(64);
strncpy(password, __guac_password, 63);
fprintf(stderr, "Sending password: %s\n", password);
return password;
}
void proxy(int client_fd) {
char* hostname;
char* escaped;
int wait_result;
rfbClient* rfb_client;
png_byte** png_rows;
png_byte* row;
int x, y;
GUACIO* io = guac_open(client_fd);
/*** INIT ***/
/* Allocate rows for PNG */
png_rows = (png_byte**) malloc(100 /* height */ * sizeof(png_byte*));
for (y=0; y<100 /* height */; y++) {
row = (png_byte*) malloc(sizeof(png_byte) * 3 * 100 /* width */);
png_rows[y] = row;
} }
rfb_client = rfbGetClient(8, 3, 4); /* 32-bpp client */
/* Framebuffer update handler */
rfb_client->GotFrameBufferUpdate = guac_vnc_update;
/* Password */
rfb_client->GetPassword = guac_vnc_get_password;
hostname = malloc(64);
strcpy(hostname, "localhost");
rfb_client->serverHost = hostname;
rfb_client->serverPort = 5902;
if (rfbInitClient(rfb_client, NULL, NULL)) {
fprintf(stderr, "SUCCESS.\n");
}
/* Store Guac data in client */
rfbClientSetClientData(rfb_client, __GUAC_VNC_TAG_IO, io);
rfbClientSetClientData(rfb_client, __GUAC_VNC_TAG_PNG_ROWS, png_rows);
/* Send name */
escaped = guac_escape_string(rfb_client->desktopName);
guac_send_name(io, escaped);
free(escaped);
/* Send size */
guac_send_size(io, rfb_client->width, rfb_client->height);
guac_flush(io);
/* VNC Client Loop */
for (;;) {
wait_result = WaitForMessage(rfb_client, 2000);
if (wait_result < 0) {
fprintf(stderr, "WAIT FAIL\n");
break;
}
if (wait_result > 0) {
if (!HandleRFBServerMessage(rfb_client)) {
fprintf(stderr, "HANDLE FAIL\n");
break;
}
}
}
/* Clean up */
rfbClientCleanup(rfb_client);
guac_write_string(io, "error:Test finished.;"); guac_write_string(io, "error:Test finished.;");
/* Free PNG data */ /* Free PNG data */