#include #include #include #include #include #include "guacio.h" #include "proxy.h" 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* escaped; char* current; int i; int length = 0; /* Determine length */ for (i=0; str[i] != '\0'; i++) { switch (str[i]) { case ';': length += 2; break; case ',': length += 2; break; default: length++; } } /* Allocate new */ escaped = malloc(length+1); current = escaped; for (i=0; str[i] != '\0'; i++) { switch (str[i]) { case ';': *(current++) = '\\'; *(current++) = 's'; break; case ',': *(current++) = '\\'; *(current++) = 'c'; break; default: *(current++) = str[i]; } } return escaped; } void guac_write_png(png_structp png, png_bytep data, png_size_t length) { if (guac_write_base64((GUACIO*) png->io_ptr, data, length) < 0) { perror("Error writing PNG"); png_error(png, "Error writing PNG"); return; } } void guac_write_flush(png_structp png) { } void guac_send_name(GUACIO* io, const char* name) { guac_write_string(io, "name:"); guac_write_string(io, name); guac_write_string(io, ";"); } void guac_send_size(GUACIO* io, int w, int h) { guac_write_string(io, "size:"); guac_write_int(io, w); guac_write_string(io, ","); guac_write_int(io, h); guac_write_string(io, ";"); } void guac_send_png(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h) { png_structp png; png_infop png_info; png_byte* row; /* For now, generate random test image */ for (y=0; yGotFrameBufferUpdate = 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.;"); /* Free PNG data */ for (y = 0; y<100 /* height */; y++) free(png_rows[y]); free(png_rows); guac_close(io); }