diff --git a/examples/client/SDLvncviewer.c b/examples/client/SDLvncviewer.c index bbb7fc26..55ae2885 100644 --- a/examples/client/SDLvncviewer.c +++ b/examples/client/SDLvncviewer.c @@ -50,7 +50,7 @@ static rfbBool resize(rfbClient* client) { depth, 0,0,0,0); if(!sdl) - rfbClientErr("resize: error creating surface: %s\n", SDL_GetError()); + rfbClientErr2(client, "resize: error creating surface: %s\n", SDL_GetError()); rfbClientSetClientData(client, SDL_Init, sdl); client->width = sdl->pitch / (depth / 8); @@ -74,7 +74,7 @@ static rfbBool resize(rfbClient* client) { height, sdlFlags); if(!sdlWindow) - rfbClientErr("resize: error creating window: %s\n", SDL_GetError()); + rfbClientErr2(client, "resize: error creating window: %s\n", SDL_GetError()); } else { SDL_SetWindowSize(sdlWindow, width, height); } @@ -83,7 +83,7 @@ static rfbBool resize(rfbClient* client) { if(!sdlRenderer) { sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0); if(!sdlRenderer) - rfbClientErr("resize: error creating renderer: %s\n", SDL_GetError()); + rfbClientErr2(client, "resize: error creating renderer: %s\n", SDL_GetError()); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); /* make the scaled rendering look smoother. */ } SDL_RenderSetLogicalSize(sdlRenderer, width, height); /* this is a departure from the SDL1.2-based version, but more in the sense of a VNC viewer in keeeping aspect ratio */ @@ -96,7 +96,7 @@ static rfbBool resize(rfbClient* client) { SDL_TEXTUREACCESS_STREAMING, width, height); if(!sdlTexture) - rfbClientErr("resize: error creating texture: %s\n", SDL_GetError()); + rfbClientErr2(client, "resize: error creating texture: %s\n", SDL_GetError()); return TRUE; } @@ -198,12 +198,12 @@ static void update(rfbClient* cl,int x,int y,int w,int h) { /* update texture from surface->pixels */ SDL_Rect r = {x,y,w,h}; if(SDL_UpdateTexture(sdlTexture, &r, sdl->pixels + y*sdl->pitch + x*4, sdl->pitch) < 0) - rfbClientErr("update: failed to update texture: %s\n", SDL_GetError()); + rfbClientErr2(client, "update: failed to update texture: %s\n", SDL_GetError()); /* copy texture to renderer and show */ if(SDL_RenderClear(sdlRenderer) < 0) - rfbClientErr("update: failed to clear renderer: %s\n", SDL_GetError()); + rfbClientErr2(client, "update: failed to clear renderer: %s\n", SDL_GetError()); if(SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL) < 0) - rfbClientErr("update: failed to copy texture to renderer: %s\n", SDL_GetError()); + rfbClientErr2(client, "update: failed to copy texture to renderer: %s\n", SDL_GetError()); SDL_RenderPresent(sdlRenderer); } @@ -303,7 +303,7 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) if (SDL_HasClipboardText()) { char *text = SDL_GetClipboardText(); if(text) { - rfbClientLog("sending clipboard text '%s'\n", text); + rfbClientLog2(client, "sending clipboard text '%s'\n", text); if(!SendClientCutTextUTF8(cl, text, strlen(text))) SendClientCutText(cl, text, strlen(text)); } @@ -314,12 +314,12 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) if (rightAltKeyDown) { SendKeyEvent(cl, XK_Alt_R, FALSE); rightAltKeyDown = FALSE; - rfbClientLog("released right Alt key\n"); + rfbClientLog2(client, "released right Alt key\n"); } if (leftAltKeyDown) { SendKeyEvent(cl, XK_Alt_L, FALSE); leftAltKeyDown = FALSE; - rfbClientLog("released left Alt key\n"); + rfbClientLog2(client, "released left Alt key\n"); } break; } @@ -413,23 +413,23 @@ static rfbBool handleSDLEvent(rfbClient *cl, SDL_Event *e) exit(0); } default: - rfbClientLog("ignore SDL event: 0x%x\n", e->type); + rfbClientLog2(client, "ignore SDL event: 0x%x\n", e->type); } return TRUE; } static void got_selection_latin1(rfbClient *cl, const char *text, int len) { - rfbClientLog("received latin1 clipboard text '%s'\n", text); + rfbClientLog2(client, "received latin1 clipboard text '%s'\n", text); if(SDL_SetClipboardText(text) != 0) - rfbClientErr("could not set received latin1 clipboard text: %s\n", SDL_GetError()); + rfbClientErr2(client, "could not set received latin1 clipboard text: %s\n", SDL_GetError()); } static void got_selection_utf8(rfbClient *cl, const char *buf, int len) { - rfbClientLog("received utf8 clipboard text '%s'\n", buf); + rfbClientLog2(client, "received utf8 clipboard text '%s'\n", buf); if(SDL_SetClipboardText(buf) != 0) - rfbClientErr("could not set received utf8 clipboard text: %s\n", SDL_GetError()); + rfbClientErr2(client, "could not set received utf8 clipboard text: %s\n", SDL_GetError()); } @@ -451,11 +451,11 @@ static rfbCredential* get_credential(rfbClient* cl, int credentialType){ } if(credentialType != rfbCredentialTypeUser) { - rfbClientErr("something else than username and password required for authentication\n"); + rfbClientErr2(client, "something else than username and password required for authentication\n"); return NULL; } - rfbClientLog("username and password required for authentication!\n"); + rfbClientLog2(client, "username and password required for authentication!\n"); printf("user: "); fgets(c->userCredential.username, RFB_BUF_SIZE, stdin); printf("pass: "); diff --git a/examples/client/backchannel.c b/examples/client/backchannel.c index a7db9a0c..2b42ec55 100644 --- a/examples/client/backchannel.c +++ b/examples/client/backchannel.c @@ -35,7 +35,7 @@ static void sendMessage(rfbClient* client, char* text) msg.size = rfbClientSwap32IfLE(length); if(!WriteToRFBServer(client, (char*)&msg, sizeof(msg)) || !WriteToRFBServer(client, text, length)) { - rfbClientLog("enableBackChannel: write error (%d: %s)", errno, strerror(errno)); + rfbClientLog2(client, "enableBackChannel: write error (%d: %s)", errno, strerror(errno)); } } @@ -59,7 +59,7 @@ static rfbBool handleBackChannelMessage(rfbClient* client, return TRUE; } - rfbClientLog("got back channel message: %s\n", text); + rfbClientLog2(client, "got back channel message: %s\n", text); free(text); return TRUE; diff --git a/examples/client/ppmtest.c b/examples/client/ppmtest.c index 378b8fe1..ef0fae26 100644 --- a/examples/client/ppmtest.c +++ b/examples/client/ppmtest.c @@ -10,7 +10,7 @@ #include static void PrintRect(rfbClient* client, int x, int y, int w, int h) { - rfbClientLog("Received an update for %d,%d,%d,%d.\n",x,y,w,h); + rfbClientLog2(client, "Received an update for %d,%d,%d,%d.\n",x,y,w,h); } static void SaveFramebufferAsPPM(rfbClient* client, int x, int y, int w, int h) { @@ -30,13 +30,13 @@ static void SaveFramebufferAsPPM(rfbClient* client, int x, int y, int w, int h) /* assert bpp=4 */ if(bpp!=4 && bpp!=2) { - rfbClientLog("bpp = %d (!=4)\n",bpp); + rfbClientLog2(client, "bpp = %d (!=4)\n",bpp); return; } f=fopen("framebuffer.ppm","wb"); if(!f) { - rfbClientErr("Could not open framebuffer.ppm\n"); + rfbClientErr2(client, "Could not open framebuffer.ppm\n"); return; } diff --git a/include/rfb/rfbclient.h b/include/rfb/rfbclient.h index 07ef0cf5..3c7b8cd4 100644 --- a/include/rfb/rfbclient.h +++ b/include/rfb/rfbclient.h @@ -509,7 +509,9 @@ extern int listenForIncomingConnectionsNoFork(rfbClient* viewer, int usec_timeou extern rfbBool rfbEnableClientLogging; typedef void (*rfbClientLogProc)(const char *format, ...); -extern rfbClientLogProc rfbClientLog,rfbClientErr; +typedef void (*rfbClientLogProc2)(rfbClient* client, const char *format, ...); +//extern rfbClientLogProc rfbClientLog,rfbClientErr; +extern rfbClientLogProc2 rfbClientLog2,rfbClientErr2; extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port); extern rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int repeaterPort, const char *destHost, int destPort); extern void SetClientAuthSchemes(rfbClient* client,const uint32_t *authSchemes, int size); @@ -670,7 +672,7 @@ extern rfbBool TextChatFinish(rfbClient* client); extern rfbBool PermitServerInput(rfbClient* client, int enabled); extern rfbBool SendXvpMsg(rfbClient* client, uint8_t version, uint8_t code); -extern void PrintPixelFormat(rfbPixelFormat *format); +extern void PrintPixelFormat(rfbClient* client, rfbPixelFormat *format); extern rfbBool SupportsClient2Server(rfbClient* client, int messageType); extern rfbBool SupportsServer2Client(rfbClient* client, int messageType); @@ -745,29 +747,29 @@ extern rfbBool errorMessageOnReadFailure; extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n); extern rfbBool WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n); -extern int FindFreeTcpPort(void); -extern rfbSocket ListenAtTcpPort(int port); -extern rfbSocket ListenAtTcpPortAndAddress(int port, const char *address); +extern int FindFreeTcpPort(rfbClient* client); +extern rfbSocket ListenAtTcpPort(rfbClient* client, int port); +extern rfbSocket ListenAtTcpPortAndAddress(rfbClient* client, int port, const char *address); /** Tries to connect to an IPv4 host. @param host Binary IPv4 address @param port Port @return A blocking socket or RFB_INVALID_SOCKET if the connection failed */ -extern rfbSocket ConnectClientToTcpAddr(unsigned int host, int port); +extern rfbSocket ConnectClientToTcpAddr(rfbClient* client, unsigned int host, int port); /** Tries to connect to an IPv4 or IPv6 host. @param hostname A hostname or IP address @param port Port @return A blocking socket or RFB_INVALID_SOCKET if the connection failed */ -extern rfbSocket ConnectClientToTcpAddr6(const char *hostname, int port); +extern rfbSocket ConnectClientToTcpAddr6(rfbClient* client, const char *hostname, int port); /** Tries to connect to a Unix socket. @param sockFile Path of the socket file @return A blocking socket or RFB_INVALID_SOCKET if the connection failed */ -extern rfbSocket ConnectClientToUnixSock(const char *sockFile); +extern rfbSocket ConnectClientToUnixSock(rfbClient* client, const char *sockFile); /** Tries to connect to an IPv4 host using the given timeout value. @param host Binary IPv4 address @@ -775,7 +777,7 @@ extern rfbSocket ConnectClientToUnixSock(const char *sockFile); @param timeout The time in seconds to wait for a connection @return A nonblocking socket or RFB_INVALID_SOCKET if the connection failed */ -extern rfbSocket ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int timeout); +extern rfbSocket ConnectClientToTcpAddrWithTimeout(rfbClient* client, unsigned int host, int port, unsigned int timeout); /** Tries to connect to an IPv4 or IPv6 host using the given timeout value. @param hostname A hostname or IP address @@ -783,18 +785,18 @@ extern rfbSocket ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, @param timeout The time in seconds to wait for a connection @return A nonblocking socket or RFB_INVALID_SOCKET if the connection failed */ -extern rfbSocket ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout); +extern rfbSocket ConnectClientToTcpAddr6WithTimeout(rfbClient* client, const char *hostname, int port, unsigned int timeout); /** Tries to connect to a Unix socket using the given timeout value. @param sockFile Path of the socket file @param timeout The time in seconds to wait for a connection @return A nonblocking socket or RFB_INVALID_SOCKET if the connection failed */ -extern rfbSocket ConnectClientToUnixSockWithTimeout(const char *sockFile, unsigned int timeout); -extern rfbSocket AcceptTcpConnection(rfbSocket listenSock); -extern rfbBool SetNonBlocking(rfbSocket sock); -extern rfbBool SetBlocking(rfbSocket sock); -extern rfbBool SetDSCP(rfbSocket sock, int dscp); +extern rfbSocket ConnectClientToUnixSockWithTimeout(rfbClient* client, const char *sockFile, unsigned int timeout); +extern rfbSocket AcceptTcpConnection(rfbClient* client, rfbSocket listenSock); +extern rfbBool SetNonBlocking(rfbClient *client, rfbSocket sock); +extern rfbBool SetBlocking(rfbClient *client, rfbSocket sock); +extern rfbBool SetDSCP(rfbClient* client, rfbSocket sock, int dscp); extern rfbBool StringToIPAddr(const char *str, unsigned int *addr); extern rfbBool SameMachine(rfbSocket sock); diff --git a/src/common/sockets.c b/src/common/sockets.c index 32fe1a1e..52f88f21 100644 --- a/src/common/sockets.c +++ b/src/common/sockets.c @@ -29,7 +29,7 @@ #include "sockets.h" -rfbBool sock_set_nonblocking(rfbSocket sock, rfbBool non_blocking, void (*log)(const char *format, ...)) +rfbBool sock_set_nonblocking(void* client, rfbSocket sock, rfbBool non_blocking, void (*log)(void* client, const char *format, ...)) { #ifdef WIN32 unsigned long non_blocking_ulong = non_blocking; @@ -44,7 +44,7 @@ rfbBool sock_set_nonblocking(rfbSocket sock, rfbBool non_blocking, void (*log)(c new_flags = flags & ~O_NONBLOCK; if(flags < 0 || fcntl(sock, F_SETFL, new_flags) < 0) { #endif - log("Setting socket to %sblocking mode failed: %s\n", non_blocking ? "non-" : "", strerror(errno)); + log(client, "Setting socket to %sblocking mode failed: %s\n", non_blocking ? "non-" : "", strerror(errno)); return FALSE; } return TRUE; diff --git a/src/common/sockets.h b/src/common/sockets.h index 99a2f15e..ecbc1300 100644 --- a/src/common/sockets.h +++ b/src/common/sockets.h @@ -73,7 +73,7 @@ Set (non)blocking mode for a socket. Returns TRUE on succcess, FALSE on failure. */ -rfbBool sock_set_nonblocking(rfbSocket sock, rfbBool non_blocking, void (*log)(const char *format, ...)); +rfbBool sock_set_nonblocking(void* client, rfbSocket sock, rfbBool non_blocking, void (*log)(void* client, const char *format, ...)); /* diff --git a/src/libvncclient/listen.c b/src/libvncclient/listen.c index 7815570a..e4aba6cf 100644 --- a/src/libvncclient/listen.c +++ b/src/libvncclient/listen.c @@ -50,7 +50,7 @@ listenForIncomingConnections(rfbClient* client) { #ifdef WIN32 /* FIXME */ - rfbClientErr("listenForIncomingConnections on MinGW32 NOT IMPLEMENTED\n"); + rfbClientErr2(client, "listenForIncomingConnections on MinGW32 NOT IMPLEMENTED\n"); return; #else int listenSocket = RFB_INVALID_SOCKET, listen6Socket = RFB_INVALID_SOCKET; @@ -63,9 +63,9 @@ listenForIncomingConnections(rfbClient* client) if (listenSocket == RFB_INVALID_SOCKET) return; - rfbClientLog("%s -listen: Listening on port %d\n", + rfbClientLog2(client, "%s -listen: Listening on port %d\n", client->programName,client->listenPort); - rfbClientLog("%s -listen: Command line errors are not reported until " + rfbClientLog2(client, "%s -listen: Command line errors are not reported until " "a connection comes in.\n", client->programName); #ifdef LIBVNCSERVER_IPv6 /* only try that if we're IPv6-capable, otherwise we may try to bind to the same port which would make all that listening fail */ @@ -77,9 +77,9 @@ listenForIncomingConnections(rfbClient* client) if (listen6Socket == RFB_INVALID_SOCKET) return; - rfbClientLog("%s -listen: Listening on IPV6 port %d\n", + rfbClientLog2(client, "%s -listen: Listening on IPV6 port %d\n", client->programName,client->listenPort); - rfbClientLog("%s -listen: Command line errors are not reported until " + rfbClientLog2(client, "%s -listen: Command line errors are not reported until " "a connection comes in.\n", client->programName); } #endif @@ -109,7 +109,7 @@ listenForIncomingConnections(rfbClient* client) if (client->sock == RFB_INVALID_SOCKET) return; - if (!SetNonBlocking(client->sock)) + if (!SetNonBlocking(client, client->sock)) return; /* Now fork off a new process to deal with it... */ @@ -117,7 +117,7 @@ listenForIncomingConnections(rfbClient* client) switch (fork()) { case -1: - rfbClientErr("fork\n"); + rfbClientErr2(client, "fork\n"); return; case 0: @@ -160,14 +160,14 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout) if (client->listenSock == RFB_INVALID_SOCKET) { - client->listenSock = ListenAtTcpPortAndAddress(client->listenPort, client->listenAddress); + client->listenSock = ListenAtTcpPortAndAddress(client, client->listenPort, client->listenAddress); if (client->listenSock == RFB_INVALID_SOCKET) return -1; - rfbClientLog("%s -listennofork: Listening on port %d\n", + rfbClientLog2(client, "%s -listennofork: Listening on port %d\n", client->programName,client->listenPort); - rfbClientLog("%s -listennofork: Command line errors are not reported until " + rfbClientLog2(client, "%s -listennofork: Command line errors are not reported until " "a connection comes in.\n", client->programName); } @@ -180,9 +180,9 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout) if (client->listen6Sock == RFB_INVALID_SOCKET) return -1; - rfbClientLog("%s -listennofork: Listening on IPV6 port %d\n", + rfbClientLog2(client, "%s -listennofork: Listening on IPV6 port %d\n", client->programName,client->listenPort); - rfbClientLog("%s -listennofork: Command line errors are not reported until " + rfbClientLog2(client, "%s -listennofork: Command line errors are not reported until " "a connection comes in.\n", client->programName); } #endif @@ -202,13 +202,13 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout) if (r > 0) { if (client->listenSock != RFB_INVALID_SOCKET && FD_ISSET(client->listenSock, &fds)) - client->sock = AcceptTcpConnection(client->listenSock); + client->sock = AcceptTcpConnection(client, client->listenSock); else if (client->listen6Sock != RFB_INVALID_SOCKET && FD_ISSET(client->listen6Sock, &fds)) - client->sock = AcceptTcpConnection(client->listen6Sock); + client->sock = AcceptTcpConnection(client, client->listen6Sock); if (client->sock == RFB_INVALID_SOCKET) return -1; - if (!SetNonBlocking(client->sock)) + if (!SetNonBlocking(client, client->sock)) return -1; if(client->listenSock != RFB_INVALID_SOCKET) { diff --git a/src/libvncclient/rfbclient.c b/src/libvncclient/rfbclient.c index f6baf641..a8381014 100644 --- a/src/libvncclient/rfbclient.c +++ b/src/libvncclient/rfbclient.c @@ -74,7 +74,7 @@ rfbBool rfbEnableClientLogging=TRUE; static void -rfbDefaultClientLog(const char *format, ...) +rfbDefaultClientLog2(rfbClient* client, const char *format, ...) { va_list args; char buf[256]; @@ -95,8 +95,10 @@ rfbDefaultClientLog(const char *format, ...) va_end(args); } -rfbClientLogProc rfbClientLog=rfbDefaultClientLog; -rfbClientLogProc rfbClientErr=rfbDefaultClientLog; +//rfbClientLogProc rfbClientLog=rfbDefaultClientLog; +//rfbClientLogProc rfbClientErr=rfbDefaultClientLog; +rfbClientLogProc2 rfbClientLog2=rfbDefaultClientLog2; +rfbClientLogProc2 rfbClientErr2=rfbDefaultClientLog2; /* extensions */ @@ -299,7 +301,7 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port) char buffer[10]; rfbVNCRec* rec = (rfbVNCRec*)malloc(sizeof(rfbVNCRec)); if(!rec) { - rfbClientLog("Could not allocate rfbVNCRec memory\n"); + rfbClientLog2(client, "Could not allocate rfbVNCRec memory\n"); return FALSE; } client->vncRec = rec; @@ -310,13 +312,13 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port) rec->doNotSleep = FALSE; if (!rec->file) { - rfbClientLog("Could not open %s.\n",client->serverHost); + rfbClientLog2(client, "Could not open %s.\n",client->serverHost); return FALSE; } setbuf(rec->file,NULL); if (fread(buffer,1,strlen(magic),rec->file) != strlen(magic) || strncmp(buffer,magic,strlen(magic))) { - rfbClientLog("File %s was not recorded by vncrec.\n",client->serverHost); + rfbClientLog2(client, "File %s was not recorded by vncrec.\n",client->serverHost); fclose(rec->file); return FALSE; } @@ -332,25 +334,25 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port) #endif { #ifdef LIBVNCSERVER_IPv6 - client->sock = ConnectClientToTcpAddr6WithTimeout(hostname, port, client->connectTimeout); + client->sock = ConnectClientToTcpAddr6WithTimeout(client, hostname, port, client->connectTimeout); #else unsigned int host; /* serverHost is a hostname */ if (!StringToIPAddr(hostname, &host)) { - rfbClientLog("Couldn't convert '%s' to host address\n", hostname); + rfbClientLog2(client, "Couldn't convert '%s' to host address\n", hostname); return FALSE; } - client->sock = ConnectClientToTcpAddrWithTimeout(host, port, client->connectTimeout); + client->sock = ConnectClientToTcpAddrWithTimeout(client, host, port, client->connectTimeout); #endif } if (client->sock == RFB_INVALID_SOCKET) { - rfbClientLog("Unable to connect to VNC server\n"); + rfbClientLog2(client, "Unable to connect to VNC server\n"); return FALSE; } - if(client->QoS_DSCP && !SetDSCP(client->sock, client->QoS_DSCP)) + if(client->QoS_DSCP && !SetDSCP(client, client->sock, client->QoS_DSCP)) return FALSE; return TRUE; @@ -360,26 +362,26 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port) * ConnectToRFBRepeater. */ -rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int repeaterPort, const char *destHost, int destPort) +rfbBool ConnectToRFBRepeater(rfbClient* client, const char *repeaterHost, int repeaterPort, const char *destHost, int destPort) { rfbProtocolVersionMsg pv; int major,minor; char tmphost[250]; #ifdef LIBVNCSERVER_IPv6 - client->sock = ConnectClientToTcpAddr6WithTimeout(repeaterHost, repeaterPort, client->connectTimeout); + client->sock = ConnectClientToTcpAddr6WithTimeout(client, repeaterHost, repeaterPort, client->connectTimeout); #else unsigned int host; if (!StringToIPAddr(repeaterHost, &host)) { - rfbClientLog("Couldn't convert '%s' to host address\n", repeaterHost); + rfbClientLog2(client, "Couldn't convert '%s' to host address\n", repeaterHost); return FALSE; } - client->sock = ConnectClientToTcpAddrWithTimeout(host, repeaterPort, client->connectTimeout); + client->sock = ConnectClientToTcpAddrWithTimeout(client, host, repeaterPort, client->connectTimeout); #endif if (client->sock == RFB_INVALID_SOCKET) { - rfbClientLog("Unable to connect to VNC repeater\n"); + rfbClientLog2(client, "Unable to connect to VNC repeater\n"); return FALSE; } @@ -389,11 +391,11 @@ rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int rep /* UltraVNC repeater always report version 000.000 to identify itself */ if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2 || major != 0 || minor != 0) { - rfbClientLog("Not a valid VNC repeater (%s)\n",pv); + rfbClientLog2(client, "Not a valid VNC repeater (%s)\n",pv); return FALSE; } - rfbClientLog("Connected to VNC repeater, using protocol version %d.%d\n", major, minor); + rfbClientLog2(client, "Connected to VNC repeater, using protocol version %d.%d\n", major, minor); memset(tmphost, 0, sizeof(tmphost)); if(snprintf(tmphost, sizeof(tmphost), "%s:%d", destHost, destPort) >= (int)sizeof(tmphost)) @@ -416,13 +418,13 @@ ReadReason(rfbClient* client) if (!ReadFromRFBServer(client, (char *)&reasonLen, 4)) return; reasonLen = rfbClientSwap32IfLE(reasonLen); if(reasonLen > 1<<20) { - rfbClientLog("VNC connection failed, but sent reason length of %u exceeds limit of 1MB",(unsigned int)reasonLen); + rfbClientLog2(client, "VNC connection failed, but sent reason length of %u exceeds limit of 1MB",(unsigned int)reasonLen); return; } reason = malloc(reasonLen+1); if (!reason || !ReadFromRFBServer(client, reason, reasonLen)) { free(reason); return; } reason[reasonLen]=0; - rfbClientLog("VNC connection failed: %s\n",reason); + rfbClientLog2(client, "VNC connection failed: %s\n",reason); free(reason); } @@ -437,7 +439,7 @@ rfbHandleAuthResult(rfbClient* client) switch (authResult) { case rfbVncAuthOK: - rfbClientLog("VNC authentication succeeded\n"); + rfbClientLog2(client, "VNC authentication succeeded\n"); return TRUE; break; case rfbVncAuthFailed: @@ -447,14 +449,14 @@ rfbHandleAuthResult(rfbClient* client) ReadReason(client); return FALSE; } - rfbClientLog("VNC authentication failed\n"); + rfbClientLog2(client, "VNC authentication failed\n"); return FALSE; case rfbVncAuthTooMany: - rfbClientLog("VNC authentication failed - too many tries\n"); + rfbClientLog2(client, "VNC authentication failed - too many tries\n"); return FALSE; } - rfbClientLog("Unknown VNC authentication result: %d\n", + rfbClientLog2(client, "Unknown VNC authentication result: %d\n", (int)authResult); return FALSE; } @@ -476,26 +478,26 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth) if (count==0) { - rfbClientLog("List of security types is ZERO, expecting an error to follow\n"); + rfbClientLog2(client, "List of security types is ZERO, expecting an error to follow\n"); ReadReason(client); return FALSE; } - rfbClientLog("We have %d security types to read\n", count); + rfbClientLog2(client, "We have %d security types to read\n", count); authScheme=0; /* now, we have a list of available security types to read ( uint8_t[] ) */ for (loop=0;loop0 ? ", %d" : "%d"), (int)tAuth[loop]); strncat(buf1, buf2, sizeof(buf1)-strlen(buf1)-1); } - rfbClientLog("Unknown authentication scheme from VNC server: %s\n", + rfbClientLog2(client, "Unknown authentication scheme from VNC server: %s\n", buf1); return FALSE; } @@ -578,7 +580,7 @@ HandleVncAuth(rfbClient *client) passwd = client->GetPassword(client); if ((!passwd) || (strlen(passwd) == 0)) { - rfbClientLog("Reading password failed\n"); + rfbClientLog2(client, "Reading password failed\n"); return FALSE; } if (strlen(passwd) > 8) { @@ -619,13 +621,13 @@ HandlePlainAuth(rfbClient *client) if (!client->GetCredential) { - rfbClientLog("GetCredential callback is not set.\n"); + rfbClientLog2(client, "GetCredential callback is not set.\n"); return FALSE; } cred = client->GetCredential(client, rfbCredentialTypeUser); if (!cred) { - rfbClientLog("Reading credential failed\n"); + rfbClientLog2(client, "Reading credential failed\n"); return FALSE; } @@ -704,26 +706,26 @@ HandleUltraMSLogonIIAuth(rfbClient *client) if (!ReadFromRFBServer(client, (char *)resp, sizeof(resp))) return FALSE; if(!dh_generate_keypair(priv, pub, gen, sizeof(gen), mod, sizeof(priv))) { - rfbClientErr("HandleUltraMSLogonIIAuth: generating keypair failed\n"); + rfbClientErr2(client, "HandleUltraMSLogonIIAuth: generating keypair failed\n"); return FALSE; } if(!dh_compute_shared_key(key, priv, resp, mod, sizeof(key))) { - rfbClientErr("HandleUltraMSLogonIIAuth: creating shared key failed\n"); + rfbClientErr2(client, "HandleUltraMSLogonIIAuth: creating shared key failed\n"); return FALSE; } if (!client->GetCredential) { - rfbClientLog("GetCredential callback is not set.\n"); + rfbClientLog2(client, "GetCredential callback is not set.\n"); return FALSE; } - rfbClientLog("WARNING! MSLogon security type has very low password encryption! "\ + rfbClientLog2(client, "WARNING! MSLogon security type has very low password encryption! "\ "Use it only with SSH tunnel or trusted network.\n"); cred = client->GetCredential(client, rfbCredentialTypeUser); if (!cred) { - rfbClientLog("Reading credential failed\n"); + rfbClientLog2(client, "Reading credential failed\n"); return FALSE; } @@ -762,15 +764,15 @@ HandleMSLogonAuth(rfbClient *client) if (!client->GetCredential) { - rfbClientLog("GetCredential callback is not set.\n"); + rfbClientLog2(client, "GetCredential callback is not set.\n"); return FALSE; } - rfbClientLog("WARNING! MSLogon security type has very low password encryption! "\ + rfbClientLog2(client, "WARNING! MSLogon security type has very low password encryption! "\ "Use it only with SSH tunnel or trusted network.\n"); cred = client->GetCredential(client, rfbCredentialTypeUser); if (!cred) { - rfbClientLog("Reading credential failed\n"); + rfbClientLog2(client, "Reading credential failed\n"); return FALSE; } @@ -818,11 +820,11 @@ HandleARDAuth(rfbClient *client) /* Step 1: Read the authentication material from the socket. A two-byte generator value, a two-byte key length value. */ if (!ReadFromRFBServer(client, (char *)gen, 2)) { - rfbClientErr("HandleARDAuth: reading generator value failed\n"); + rfbClientErr2(client, "HandleARDAuth: reading generator value failed\n"); goto out; } if (!ReadFromRFBServer(client, (char *)len, 2)) { - rfbClientErr("HandleARDAuth: reading key length failed\n"); + rfbClientErr2(client, "HandleARDAuth: reading key length failed\n"); goto out; } keylen = 256*len[0]+len[1]; /* convert from char[] to int */ @@ -839,17 +841,17 @@ HandleARDAuth(rfbClient *client) /* Step 1: Read the authentication material from the socket. The prime modulus (keylen bytes) and the peer's generated public key (keylen bytes). */ if (!ReadFromRFBServer(client, (char *)mod, keylen)) { - rfbClientErr("HandleARDAuth: reading prime modulus failed\n"); + rfbClientErr2(client, "HandleARDAuth: reading prime modulus failed\n"); goto out; } if (!ReadFromRFBServer(client, (char *)resp, keylen)) { - rfbClientErr("HandleARDAuth: reading peer's generated public key failed\n"); + rfbClientErr2(client, "HandleARDAuth: reading peer's generated public key failed\n"); goto out; } /* Step 2: Generate own Diffie-Hellman public-private key pair. */ if(!dh_generate_keypair(priv, pub, gen, 2, mod, keylen)) { - rfbClientErr("HandleARDAuth: generating keypair failed\n"); + rfbClientErr2(client, "HandleARDAuth: generating keypair failed\n"); goto out; } @@ -857,7 +859,7 @@ HandleARDAuth(rfbClient *client) prime (mod), and the peer's public key. The output will be a shared secret known to both us and the peer. */ if(!dh_compute_shared_key(key, priv, resp, mod, keylen)) { - rfbClientErr("HandleARDAuth: creating shared key failed\n"); + rfbClientErr2(client, "HandleARDAuth: creating shared key failed\n"); goto out; } @@ -865,7 +867,7 @@ HandleARDAuth(rfbClient *client) This 128-bit (16-byte) value will be used as the AES key. */ shared = malloc(MD5_HASH_SIZE); if(!hash_md5(shared, key, keylen)) { - rfbClientErr("HandleARDAuth: hashing shared key failed\n"); + rfbClientErr2(client, "HandleARDAuth: hashing shared key failed\n"); goto out; } @@ -874,12 +876,12 @@ HandleARDAuth(rfbClient *client) Null-terminate each. Fill the unused bytes with random characters so that the encryption output is less predictable. */ if(!client->GetCredential) { - rfbClientErr("HandleARDAuth: GetCredential callback is not set\n"); + rfbClientErr2(client, "HandleARDAuth: GetCredential callback is not set\n"); goto out; } cred = client->GetCredential(client, rfbCredentialTypeUser); if(!cred) { - rfbClientErr("HandleARDAuth: reading credential failed\n"); + rfbClientErr2(client, "HandleARDAuth: reading credential failed\n"); goto out; } passwordLen = strlen(cred->userCredential.password)+1; @@ -896,7 +898,7 @@ HandleARDAuth(rfbClient *client) from step 4, using the AES 128-bit symmetric cipher in electronic codebook (ECB) mode. Use no further padding for this block cipher. */ if(!encrypt_aes128ecb(ciphertext, &ciphertext_len, shared, userpass, sizeof(userpass))) { - rfbClientErr("HandleARDAuth: encrypting credentials failed\n"); + rfbClientErr2(client, "HandleARDAuth: encrypting credentials failed\n"); goto out; } @@ -982,7 +984,7 @@ InitialiseRFBConnection(rfbClient* client) pv[sz_rfbProtocolVersionMsg] = 0; if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2) { - rfbClientLog("Not a valid VNC server (%s)\n",pv); + rfbClientLog2(client, "Not a valid VNC server (%s)\n",pv); return FALSE; } @@ -998,7 +1000,7 @@ InitialiseRFBConnection(rfbClient* client) /* Legacy version of UltraVNC uses minor codes 4 and 6 for the server */ /* left in for backwards compatibility */ if (major==3 && (minor==4 || minor==6)) { - rfbClientLog("UltraVNC server detected, enabling UltraVNC specific messages\n",pv); + rfbClientLog2(client, "UltraVNC server detected, enabling UltraVNC specific messages\n",pv); DefaultSupportedMessagesUltraVNC(client); } @@ -1007,14 +1009,14 @@ InitialiseRFBConnection(rfbClient* client) if (major==3 && (minor==14 || minor==16)) { minor = minor - 10; client->minor = minor; - rfbClientLog("UltraVNC Single Click server detected, enabling UltraVNC specific messages\n",pv); + rfbClientLog2(client, "UltraVNC Single Click server detected, enabling UltraVNC specific messages\n",pv); DefaultSupportedMessagesUltraVNC(client); } /* Legacy version of TightVNC uses minor codes 5 for the server */ /* left in for backwards compatibility */ if (major==3 && minor==5) { - rfbClientLog("TightVNC server detected, enabling TightVNC specific messages\n",pv); + rfbClientLog2(client, "TightVNC server detected, enabling TightVNC specific messages\n",pv); DefaultSupportedMessagesTightVNC(client); } @@ -1025,7 +1027,7 @@ InitialiseRFBConnection(rfbClient* client) client->minor=8; } - rfbClientLog("VNC server supports protocol version %d.%d (viewer %d.%d)\n", + rfbClientLog2(client, "VNC server supports protocol version %d.%d (viewer %d.%d)\n", major, minor, rfbProtocolMajorVersion, rfbProtocolMinorVersion); sprintf(pv,rfbProtocolVersionFormat,client->major,client->minor); @@ -1044,7 +1046,7 @@ InitialiseRFBConnection(rfbClient* client) authScheme = rfbClientSwap32IfLE(authScheme); } - rfbClientLog("Selected Security Scheme %d\n", authScheme); + rfbClientLog2(client, "Selected Security Scheme %d\n", authScheme); client->authScheme = authScheme; switch (authScheme) { @@ -1054,7 +1056,7 @@ InitialiseRFBConnection(rfbClient* client) return FALSE; case rfbNoAuth: - rfbClientLog("No authentication needed\n"); + rfbClientLog2(client, "No authentication needed\n"); /* 3.8 and upwards sends a Security Result for rfbNoAuth */ if ((client->major==3 && client->minor > 7) || client->major>3) @@ -1099,7 +1101,7 @@ InitialiseRFBConnection(rfbClient* client) return FALSE; case rfbNoAuth: - rfbClientLog("No sub authentication needed\n"); + rfbClientLog2(client, "No sub authentication needed\n"); /* 3.8 and upwards sends a Security Result for rfbNoAuth */ if ((client->major==3 && client->minor > 7) || client->major>3) if (!rfbHandleAuthResult(client)) return FALSE; @@ -1116,7 +1118,7 @@ InitialiseRFBConnection(rfbClient* client) #endif /* LIBVNCSERVER_HAVE_SASL */ default: - rfbClientLog("Unknown sub authentication scheme from VNC server: %d\n", + rfbClientLog2(client, "Unknown sub authentication scheme from VNC server: %d\n", (int)subAuthScheme); return FALSE; } @@ -1146,7 +1148,7 @@ InitialiseRFBConnection(rfbClient* client) case rfbNoAuth: case rfbVeNCryptTLSNone: case rfbVeNCryptX509None: - rfbClientLog("No sub authentication needed\n"); + rfbClientLog2(client, "No sub authentication needed\n"); if (!rfbHandleAuthResult(client)) return FALSE; break; @@ -1170,7 +1172,7 @@ InitialiseRFBConnection(rfbClient* client) #endif /* LIBVNCSERVER_HAVE_SASL */ default: - rfbClientLog("Unknown sub authentication scheme from VNC server: %d\n", + rfbClientLog2(client, "Unknown sub authentication scheme from VNC server: %d\n", client->subAuthScheme); return FALSE; } @@ -1194,7 +1196,7 @@ InitialiseRFBConnection(rfbClient* client) } if (authHandled) break; } - rfbClientLog("Unknown authentication scheme from VNC server: %d\n", + rfbClientLog2(client, "Unknown authentication scheme from VNC server: %d\n", (int)authScheme); return FALSE; } @@ -1213,13 +1215,13 @@ InitialiseRFBConnection(rfbClient* client) client->si.nameLength = rfbClientSwap32IfLE(client->si.nameLength); if (client->si.nameLength > 1<<20) { - rfbClientErr("Too big desktop name length sent by server: %u B > 1 MB\n", (unsigned int)client->si.nameLength); + rfbClientErr2(client, "Too big desktop name length sent by server: %u B > 1 MB\n", (unsigned int)client->si.nameLength); return FALSE; } client->desktopName = malloc(client->si.nameLength + 1); if (!client->desktopName) { - rfbClientLog("Error allocating memory for desktop name, %lu bytes\n", + rfbClientLog2(client, "Error allocating memory for desktop name, %lu bytes\n", (unsigned long)client->si.nameLength); return FALSE; } @@ -1228,13 +1230,13 @@ InitialiseRFBConnection(rfbClient* client) client->desktopName[client->si.nameLength] = 0; - rfbClientLog("Desktop name \"%s\"\n",client->desktopName); + rfbClientLog2(client, "Desktop name \"%s\"\n",client->desktopName); - rfbClientLog("Connected to VNC server, using protocol version %d.%d\n", + rfbClientLog2(client, "Connected to VNC server, using protocol version %d.%d\n", client->major, client->minor); - rfbClientLog("VNC server default format:\n"); - PrintPixelFormat(&client->si.format); + rfbClientLog2(client, "VNC server default format:\n"); + PrintPixelFormat(client, &client->si.format); return TRUE; } @@ -1336,7 +1338,7 @@ SetFormatAndEncodings(rfbClient* client) } else if (strncasecmp(encStr,"rre",encStrLen) == 0) { encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRRE); } else { - rfbClientLog("Unknown encoding '%.*s'\n",encStrLen,encStr); + rfbClientLog2(client, "Unknown encoding '%.*s'\n",encStrLen,encStr); } encStr = nextEncStr; @@ -1359,11 +1361,11 @@ SetFormatAndEncodings(rfbClient* client) /* TODO: if (!tunnelSpecified) { */ - rfbClientLog("Same machine: preferring raw encoding\n"); + rfbClientLog2(client, "Same machine: preferring raw encoding\n"); encs[se->nEncodings++] = rfbClientSwap32IfLE(rfbEncodingRaw); /* } else { - rfbClientLog("Tunneling active: preferring tight encoding\n"); + rfbClientLog2(client, "Tunneling active: preferring tight encoding\n"); } */ } @@ -1497,7 +1499,7 @@ SendFramebufferUpdateRequest(rfbClient* client, int x, int y, int w, int h, rfbB if (!SupportsClient2Server(client, rfbFramebufferUpdateRequest)) return TRUE; if (client->requestedResize) { - rfbClientLog("Skipping Update - resize in progress\n"); + rfbClientLog2(client, "Skipping Update - resize in progress\n"); return TRUE; } @@ -1705,12 +1707,12 @@ SendExtDesktopSize(rfbClient* client, uint16_t width, uint16_t height) rfbExtDesktopScreen screen; if (client->screen.width == 0 && client->screen.height == 0 ) { - rfbClientLog("Screen not yet received from server - not sending dimensions %dx%d\n", width, height); + rfbClientLog2(client, "Screen not yet received from server - not sending dimensions %dx%d\n", width, height); return TRUE; } if (client->screen.width != rfbClientSwap16IfLE(width) || client->screen.height != rfbClientSwap16IfLE(height)) { - rfbClientLog("Sending dimensions %dx%d\n", width, height); + rfbClientLog2(client, "Sending dimensions %dx%d\n", width, height); sdm.type = rfbSetDesktopSize; sdm.width = rfbClientSwap16IfLE(width); sdm.height = rfbClientSwap16IfLE(height); @@ -1865,7 +1867,7 @@ sendExtClientCutTextProvide(rfbClient *client, char* data, int len) unsigned char *buf = malloc(sz_to_compressed); if (!buf) { - rfbClientLog("sendExtClientCutTextProvide. alloc buf failed\n"); + rfbClientLog2(client, "sendExtClientCutTextProvide. alloc buf failed\n"); return FALSE; } memcpy(buf, &be_size, sizeof(be_size)); @@ -1874,13 +1876,13 @@ sendExtClientCutTextProvide(rfbClient *client, char* data, int len) unsigned char *cbuf = malloc(sizeof(be_flags) + csz); /*flag, compressed*/ if (!cbuf) { - rfbClientLog("sendExtClientCutTextProvide. alloc cbuf failed\n"); + rfbClientLog2(client, "sendExtClientCutTextProvide. alloc cbuf failed\n"); free(buf); return FALSE; } memcpy(cbuf, &be_flags, sizeof(be_flags)); if (CompressClipData(cbuf + sizeof(be_flags), &csz, buf, sz_to_compressed) != Z_OK) { - rfbClientLog("sendExtClientCutTextProvide: compress cbuf failed\n"); + rfbClientLog2(client, "sendExtClientCutTextProvide: compress cbuf failed\n"); free(buf); free(cbuf); return FALSE; @@ -1936,7 +1938,7 @@ rfbClientProcessExtServerCutText(rfbClient* client, char *data, int len) { uint32_t flags; if (len < sizeof(flags)) { - rfbClientLog("rfbClientProcessExtServerCutText. len < 4\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. len < 4\n"); return FALSE; } memcpy(&flags, data, sizeof(flags)); @@ -1949,15 +1951,15 @@ rfbClientProcessExtServerCutText(rfbClient* client, char *data, int len) * modify here if need more types(rtf,html,dib,files) */ if (!(flags & rfbExtendedClipboard_Text)) { - rfbClientLog("rfbClientProcessExtServerCutText. not text type. ignore\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. not text type. ignore\n"); return TRUE; } if (!(flags & rfbExtendedClipboard_Provide)) { - rfbClientLog("rfbClientProcessExtServerCutText. not provide type. ignore\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. not provide type. ignore\n"); return TRUE; } if (flags & rfbExtendedClipboard_Caps) { - rfbClientLog("rfbClientProcessExtServerCutText. default cap.\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. default cap.\n"); client->extendedClipboardServerCapabilities |= rfbExtendedClipboard_Text; /* for now, only text */ return TRUE; } @@ -1969,7 +1971,7 @@ rfbClientProcessExtServerCutText(rfbClient* client, char *data, int len) stream.avail_in = 0; stream.next_in = NULL; if (inflateInit(&stream) != Z_OK) { - rfbClientLog("rfbClientProcessExtServerCutText. inflateInit failed\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. inflateInit failed\n"); return FALSE; } stream.avail_in = len; @@ -1979,20 +1981,20 @@ rfbClientProcessExtServerCutText(rfbClient* client, char *data, int len) stream.avail_out = sizeof(size); stream.next_out = (unsigned char *)&size; if (inflate(&stream, Z_SYNC_FLUSH) != Z_OK) { - rfbClientLog("rfbClientProcessExtServerCutText. inflate size failed\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. inflate size failed\n"); inflateEnd(&stream); return FALSE; } size = rfbClientSwap32IfLE(size); if (size > (1 << 20)) { - rfbClientLog("rfbClientProcessExtServerCutText. size too large\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. size too large\n"); inflateEnd(&stream); return FALSE; } unsigned char *buf = malloc(size); if (!buf) { - rfbClientLog("rfbClientProcessExtServerCutText. alloc buf failed\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. alloc buf failed\n"); inflateEnd(&stream); return FALSE; } @@ -2001,13 +2003,13 @@ rfbClientProcessExtServerCutText(rfbClient* client, char *data, int len) uLong out_before = stream.total_out; int err = inflate(&stream, Z_SYNC_FLUSH); if (err != Z_OK && err != Z_STREAM_END) { - rfbClientLog("rfbClientProcessExtServerCutText. inflate buf failed\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. inflate buf failed\n"); free(buf); inflateEnd(&stream); return FALSE; } if ((stream.total_out - out_before) != size) { - rfbClientLog("rfbClientProcessExtServerCutText. inflate size error\n"); + rfbClientLog2(client, "rfbClientProcessExtServerCutText. inflate size error\n"); free(buf); inflateEnd(&stream); return FALSE; @@ -2149,7 +2151,7 @@ HandleRFBServerMessage(rfbClient* client) if(!ResizeClientBuffer(client, rect.r.w, rect.r.h)) return FALSE; SendFramebufferUpdateRequest(client, 0, 0, rect.r.w, rect.r.h, FALSE); - rfbClientLog("Got new framebuffer size: %dx%d\n", rect.r.w, rect.r.h); + rfbClientLog2(client, "Got new framebuffer size: %dx%d\n", rect.r.w, rect.r.h); continue; } @@ -2181,7 +2183,7 @@ HandleRFBServerMessage(rfbClient* client) if(!ResizeClientBuffer(client, rect.r.w, rect.r.h)) { return FALSE; } - rfbClientLog("Updated desktop size: %dx%d\n", rect.r.w, rect.r.h); + rfbClientLog2(client, "Updated desktop size: %dx%d\n", rect.r.w, rect.r.h); } client->requestedResize = FALSE; @@ -2197,17 +2199,17 @@ HandleRFBServerMessage(rfbClient* client) /* msgs is two sets of bit flags of supported messages client2server[] and server2client[] */ /* currently ignored by this library */ - rfbClientLog("client2server supported messages (bit flags)\n"); + rfbClientLog2(client, "client2server supported messages (bit flags)\n"); for (loop=0;loop<32;loop+=8) - rfbClientLog("%02X: %04x %04x %04x %04x - %04x %04x %04x %04x\n", loop, + rfbClientLog2(client, "%02X: %04x %04x %04x %04x - %04x %04x %04x %04x\n", loop, client->supportedMessages.client2server[loop], client->supportedMessages.client2server[loop+1], client->supportedMessages.client2server[loop+2], client->supportedMessages.client2server[loop+3], client->supportedMessages.client2server[loop+4], client->supportedMessages.client2server[loop+5], client->supportedMessages.client2server[loop+6], client->supportedMessages.client2server[loop+7]); - rfbClientLog("server2client supported messages (bit flags)\n"); + rfbClientLog2(client, "server2client supported messages (bit flags)\n"); for (loop=0;loop<32;loop+=8) - rfbClientLog("%02X: %04x %04x %04x %04x - %04x %04x %04x %04x\n", loop, + rfbClientLog2(client, "%02X: %04x %04x %04x %04x - %04x %04x %04x %04x\n", loop, client->supportedMessages.server2client[loop], client->supportedMessages.server2client[loop+1], client->supportedMessages.server2client[loop+2], client->supportedMessages.server2client[loop+3], client->supportedMessages.server2client[loop+4], client->supportedMessages.server2client[loop+5], @@ -2241,7 +2243,7 @@ HandleRFBServerMessage(rfbClient* client) return FALSE; } buffer[rect.r.w]=0; /* null terminate, just in case */ - rfbClientLog("Connected to Server \"%s\"\n", buffer); + rfbClientLog2(client, "Connected to Server \"%s\"\n", buffer); free(buffer); continue; } @@ -2252,7 +2254,7 @@ HandleRFBServerMessage(rfbClient* client) if ((rect.r.x + rect.r.w > client->width) || (rect.r.y + rect.r.h > client->height)) { - rfbClientLog("Rect too large: %dx%d at (%d, %d)\n", + rfbClientLog2(client, "Rect too large: %dx%d at (%d, %d)\n", rect.r.w, rect.r.h, rect.r.x, rect.r.y); return FALSE; } @@ -2262,7 +2264,7 @@ HandleRFBServerMessage(rfbClient* client) if ((rect.encoding != rfbEncodingTight) && (rect.r.h * rect.r.w == 0)) { - rfbClientLog("Zero size rect - ignoring (encoding=%d (0x%08x) %dx, %dy, %dw, %dh)\n", rect.encoding, rect.encoding, rect.r.x, rect.r.y, rect.r.w, rect.r.h); + rfbClientLog2(client, "Zero size rect - ignoring (encoding=%d (0x%08x) %dx, %dy, %dw, %dh)\n", rect.encoding, rect.encoding, rect.r.x, rect.r.y, rect.r.w, rect.r.h); continue; } */ @@ -2556,7 +2558,7 @@ HandleRFBServerMessage(rfbClient* client) handled = TRUE; if(!handled) { - rfbClientLog("Unknown rect encoding %d\n", + rfbClientLog2(client, "Unknown rect encoding %d\n", (int)rect.encoding); return FALSE; } @@ -2604,7 +2606,7 @@ HandleRFBServerMessage(rfbClient* client) #endif if (msg.sct.length > 1<<20) { - rfbClientErr("Ignoring too big cut text length sent by server: %u B > 1 MB\n", (unsigned int)msg.sct.length); + rfbClientErr2(client, "Ignoring too big cut text length sent by server: %u B > 1 MB\n", (unsigned int)msg.sct.length); return FALSE; } @@ -2644,17 +2646,17 @@ HandleRFBServerMessage(rfbClient* client) msg.tc.length = rfbClientSwap32IfLE(msg.sct.length); switch(msg.tc.length) { case rfbTextChatOpen: - rfbClientLog("Received TextChat Open\n"); + rfbClientLog2(client, "Received TextChat Open\n"); if (client->HandleTextChat!=NULL) client->HandleTextChat(client, (int)rfbTextChatOpen, NULL); break; case rfbTextChatClose: - rfbClientLog("Received TextChat Close\n"); + rfbClientLog2(client, "Received TextChat Close\n"); if (client->HandleTextChat!=NULL) client->HandleTextChat(client, (int)rfbTextChatClose, NULL); break; case rfbTextChatFinished: - rfbClientLog("Received TextChat Finished\n"); + rfbClientLog2(client, "Received TextChat Finished\n"); if (client->HandleTextChat!=NULL) client->HandleTextChat(client, (int)rfbTextChatFinished, NULL); break; @@ -2669,7 +2671,7 @@ HandleRFBServerMessage(rfbClient* client) } /* Null Terminate */ buffer[msg.tc.length]=0; - rfbClientLog("Received TextChat \"%s\"\n", buffer); + rfbClientLog2(client, "Received TextChat \"%s\"\n", buffer); if (client->HandleTextChat!=NULL) client->HandleTextChat(client, (int)msg.tc.length, buffer); free(buffer); @@ -2705,7 +2707,7 @@ HandleRFBServerMessage(rfbClient* client) return FALSE; SendFramebufferUpdateRequest(client, 0, 0, client->width, client->height, FALSE); - rfbClientLog("Got new framebuffer size: %dx%d\n", client->width, client->height); + rfbClientLog2(client, "Got new framebuffer size: %dx%d\n", client->width, client->height); break; } @@ -2717,7 +2719,7 @@ HandleRFBServerMessage(rfbClient* client) if (!ResizeClientBuffer(client, rfbClientSwap16IfLE(msg.prsfb.buffer_w), rfbClientSwap16IfLE(msg.prsfb.buffer_h))) return FALSE; SendFramebufferUpdateRequest(client, 0, 0, client->width, client->height, FALSE); - rfbClientLog("Got new framebuffer size: %dx%d\n", client->width, client->height); + rfbClientLog2(client, "Got new framebuffer size: %dx%d\n", client->width, client->height); break; } @@ -2732,7 +2734,7 @@ HandleRFBServerMessage(rfbClient* client) if(!handled) { char buffer[256]; - rfbClientLog("Unknown message type %d from VNC server\n",msg.type); + rfbClientLog2(client, "Unknown message type %d from VNC server\n",msg.type); ReadFromRFBServer(client, buffer, 256); return FALSE; } @@ -2818,26 +2820,26 @@ HandleRFBServerMessage(rfbClient* client) */ void -PrintPixelFormat(rfbPixelFormat *format) +PrintPixelFormat(rfbClient* client, rfbPixelFormat *format) { if (format->bitsPerPixel == 1) { - rfbClientLog(" Single bit per pixel.\n"); - rfbClientLog( + rfbClientLog2(client, " Single bit per pixel.\n"); + rfbClientLog2(client, " %s significant bit in each byte is leftmost on the screen.\n", (format->bigEndian ? "Most" : "Least")); } else { - rfbClientLog(" %d bits per pixel.\n",format->bitsPerPixel); + rfbClientLog2(client, " %d bits per pixel.\n",format->bitsPerPixel); if (format->bitsPerPixel != 8) { - rfbClientLog(" %s significant byte first in each pixel.\n", + rfbClientLog2(client, " %s significant byte first in each pixel.\n", (format->bigEndian ? "Most" : "Least")); } if (format->trueColour) { - rfbClientLog(" TRUE colour: max red %d green %d blue %d" + rfbClientLog2(client, " TRUE colour: max red %d green %d blue %d" ", shift red %d green %d blue %d\n", format->redMax, format->greenMax, format->blueMax, format->redShift, format->greenShift, format->blueShift); } else { - rfbClientLog(" Colour map (not true colour).\n"); + rfbClientLog2(client, " Colour map (not true colour).\n"); } } } diff --git a/src/libvncclient/sasl.c b/src/libvncclient/sasl.c index 68dd8eec..386af578 100644 --- a/src/libvncclient/sasl.c +++ b/src/libvncclient/sasl.c @@ -64,7 +64,7 @@ static int log_func(void *context, int level, const char *message) { - rfbClientLog("SASL: %s\n", message); + rfbClientLog2(client, "SASL: %s\n", message); return SASL_OK; } @@ -77,12 +77,12 @@ static int user_callback_adapt(void *context, rfbClient* client = (rfbClient *)context; if (id != SASL_CB_AUTHNAME) { - rfbClientLog("Unrecognized SASL callback ID %d\n", id); + rfbClientLog2(client, "Unrecognized SASL callback ID %d\n", id); return SASL_FAIL; } if (!client->GetUser) { - rfbClientLog("Client user callback not found\n"); + rfbClientLog2(client, "Client user callback not found\n"); return SASL_FAIL; } @@ -102,7 +102,7 @@ static int password_callback_adapt(sasl_conn_t *conn, char * password; if (id != SASL_CB_PASS) { - rfbClientLog("Unrecognized SASL callback ID %d\n", id); + rfbClientLog2(client, "Unrecognized SASL callback ID %d\n", id); return SASL_FAIL; } @@ -112,7 +112,7 @@ static int password_callback_adapt(sasl_conn_t *conn, } if (!client->GetPassword) { - rfbClientLog("Client password callback not found\n"); + rfbClientLog2(client, "Client password callback not found\n"); return SASL_FAIL; } @@ -122,7 +122,7 @@ static int password_callback_adapt(sasl_conn_t *conn, sasl_secret_t *lsec = (sasl_secret_t *)malloc(sizeof(sasl_secret_t) + strlen(password)); if (!lsec) { - rfbClientLog("Could not allocate sasl_secret_t\n"); + rfbClientLog2(client, "Could not allocate sasl_secret_t\n"); return SASL_FAIL; } @@ -177,9 +177,9 @@ HandleSASLAuth(rfbClient *client) /* Sets up the SASL library as a whole */ err = sasl_client_init(NULL); - rfbClientLog("Client initialize SASL authentication %d\n", err); + rfbClientLog2(client, "Client initialize SASL authentication %d\n", err); if (err != SASL_OK) { - rfbClientLog("failed to initialize SASL library: %d (%s)\n", + rfbClientLog2(client, "failed to initialize SASL library: %d (%s)\n", err, sasl_errstring(err, NULL, NULL)); goto error; } @@ -191,7 +191,7 @@ HandleSASLAuth(rfbClient *client) int port; if (getsockname(client->sock, (struct sockaddr*)&localAddress, &addressLength)) { - rfbClientLog("failed to get local address\n"); + rfbClientLog2(client, "failed to get local address\n"); goto error; } @@ -206,14 +206,14 @@ HandleSASLAuth(rfbClient *client) port = ntohs(sa_in->sin6_port); localAddr = vnc_connection_addr_to_string(buf, port); } else { - rfbClientLog("failed to get local address\n"); + rfbClientLog2(client, "failed to get local address\n"); goto error; } /* Get remote address in form IPADDR:PORT */ remoteAddr = vnc_connection_addr_to_string(client->serverHost, client->serverPort); - rfbClientLog("Client SASL new host:'%s' local:'%s' remote:'%s'\n", client->serverHost, localAddr, remoteAddr); + rfbClientLog2(client, "Client SASL new host:'%s' local:'%s' remote:'%s'\n", client->serverHost, localAddr, remoteAddr); /* Setup a handle for being a client */ err = sasl_client_new("vnc", @@ -227,7 +227,7 @@ HandleSASLAuth(rfbClient *client) free(remoteAddr); if (err != SASL_OK) { - rfbClientLog("Failed to create SASL client context: %d (%s)\n", + rfbClientLog2(client, "Failed to create SASL client context: %d (%s)\n", err, sasl_errstring(err, NULL, NULL)); goto error; } @@ -235,14 +235,14 @@ HandleSASLAuth(rfbClient *client) /* Initialize some connection props we care about */ if (client->tlsSession) { if (!(ssf = (sasl_ssf_t)GetTLSCipherBits(client))) { - rfbClientLog("%s", "invalid cipher size for TLS session\n"); + rfbClientLog2(client, "%s", "invalid cipher size for TLS session\n"); goto error; } - rfbClientLog("Setting external SSF %d\n", ssf); + rfbClientLog2(client, "Setting external SSF %d\n", ssf); err = sasl_setprop(saslconn, SASL_SSF_EXTERNAL, &ssf); if (err != SASL_OK) { - rfbClientLog("cannot set external SSF %d (%s)\n", + rfbClientLog2(client, "cannot set external SSF %d (%s)\n", err, sasl_errstring(err, NULL, NULL)); goto error; } @@ -259,20 +259,20 @@ HandleSASLAuth(rfbClient *client) err = sasl_setprop(saslconn, SASL_SEC_PROPS, &secprops); if (err != SASL_OK) { - rfbClientLog("cannot set security props %d (%s)\n", + rfbClientLog2(client, "cannot set security props %d (%s)\n", err, sasl_errstring(err, NULL, NULL)); goto error; } /* Get the supported mechanisms from the server */ if (!ReadFromRFBServer(client, (char *)&mechlistlen, 4)) { - rfbClientLog("failed to read mechlistlen\n"); + rfbClientLog2(client, "failed to read mechlistlen\n"); goto error; } mechlistlen = rfbClientSwap32IfLE(mechlistlen); - rfbClientLog("mechlistlen is %d\n", mechlistlen); + rfbClientLog2(client, "mechlistlen is %d\n", mechlistlen); if (mechlistlen > SASL_MAX_MECHLIST_LEN) { - rfbClientLog("mechlistlen %d too long\n", mechlistlen); + rfbClientLog2(client, "mechlistlen %d too long\n", mechlistlen); goto error; } @@ -289,7 +289,7 @@ HandleSASLAuth(rfbClient *client) if (wantmech && *wantmech != 0) { if (strstr(mechlist, wantmech) == NULL) { - rfbClientLog("Client requested SASL mechanism %s not supported by server\n", + rfbClientLog2(client, "Client requested SASL mechanism %s not supported by server\n", wantmech); free(mechlist); free(wantmech); @@ -301,7 +301,7 @@ HandleSASLAuth(rfbClient *client) } } - rfbClientLog("Client start negotiation mechlist '%s'\n", mechlist); + rfbClientLog2(client, "Client start negotiation mechlist '%s'\n", mechlist); /* Start the auth negotiation on the client end first */ err = sasl_client_start(saslconn, @@ -311,7 +311,7 @@ HandleSASLAuth(rfbClient *client) &clientoutlen, &mechname); if (err != SASL_OK && err != SASL_CONTINUE && err != SASL_INTERACT) { - rfbClientLog("Failed to start SASL negotiation: %d (%s)\n", + rfbClientLog2(client, "Failed to start SASL negotiation: %d (%s)\n", err, sasl_errdetail(saslconn)); free(mechlist); mechlist = NULL; @@ -320,15 +320,15 @@ HandleSASLAuth(rfbClient *client) /* Need to gather some credentials from the client */ if (err == SASL_INTERACT) { - rfbClientLog("User interaction required but not currently supported\n"); + rfbClientLog2(client, "User interaction required but not currently supported\n"); goto error; } - rfbClientLog("Server start negotiation with mech %s. Data %d bytes %p '%s'\n", + rfbClientLog2(client, "Server start negotiation with mech %s. Data %d bytes %p '%s'\n", mechname, clientoutlen, clientout, clientout); if (clientoutlen > SASL_MAX_DATA_LEN) { - rfbClientLog("SASL negotiation data too long: %d bytes\n", + rfbClientLog2(client, "SASL negotiation data too long: %d bytes\n", clientoutlen); goto error; } @@ -348,13 +348,13 @@ HandleSASLAuth(rfbClient *client) if (!WriteToRFBServer(client, (char *)&temp, 4)) goto error; } - rfbClientLog("%s", "Getting sever start negotiation reply\n"); + rfbClientLog2(client, "%s", "Getting sever start negotiation reply\n"); /* Read the 'START' message reply from server */ if (!ReadFromRFBServer(client, (char *)&serverinlen, 4)) goto error; serverinlen = rfbClientSwap32IfLE(serverinlen); if (serverinlen > SASL_MAX_DATA_LEN) { - rfbClientLog("SASL negotiation data too long: %d bytes\n", + rfbClientLog2(client, "SASL negotiation data too long: %d bytes\n", serverinlen); goto error; } @@ -370,7 +370,7 @@ HandleSASLAuth(rfbClient *client) } if (!ReadFromRFBServer(client, (char *)&complete, 1)) goto error; - rfbClientLog("Client start result complete: %d. Data %d bytes %p '%s'\n", + rfbClientLog2(client, "Client start result complete: %d. Data %d bytes %p '%s'\n", complete, serverinlen, serverin, serverin); /* Loop-the-loop... @@ -384,14 +384,14 @@ HandleSASLAuth(rfbClient *client) &clientout, &clientoutlen); if (err != SASL_OK && err != SASL_CONTINUE && err != SASL_INTERACT) { - rfbClientLog("Failed SASL step: %d (%s)\n", + rfbClientLog2(client, "Failed SASL step: %d (%s)\n", err, sasl_errdetail(saslconn)); goto error; } /* Need to gather some credentials from the client */ if (err == SASL_INTERACT) { - rfbClientLog("User interaction required but not currently supported\n"); + rfbClientLog2(client, "User interaction required but not currently supported\n"); goto error; } @@ -400,7 +400,7 @@ HandleSASLAuth(rfbClient *client) serverin = NULL; } - rfbClientLog("Client step result %d. Data %d bytes %p '%s'\n", err, clientoutlen, clientout, clientout); + rfbClientLog2(client, "Client step result %d. Data %d bytes %p '%s'\n", err, clientoutlen, clientout, clientout); /* Previous server call showed completion & we're now locally complete too */ if (complete && err == SASL_OK) @@ -418,13 +418,13 @@ HandleSASLAuth(rfbClient *client) if (!WriteToRFBServer(client, (char *)&temp, 4)) goto error; } - rfbClientLog("Server step with %d bytes %p\n", clientoutlen, clientout); + rfbClientLog2(client, "Server step with %d bytes %p\n", clientoutlen, clientout); if (!ReadFromRFBServer(client, (char *)&serverinlen, 4)) goto error; serverinlen = rfbClientSwap32IfLE(serverinlen); if (serverinlen > SASL_MAX_DATA_LEN) { - rfbClientLog("SASL negotiation data too long: %d bytes\n", + rfbClientLog2(client, "SASL negotiation data too long: %d bytes\n", serverinlen); goto error; } @@ -440,7 +440,7 @@ HandleSASLAuth(rfbClient *client) } if (!ReadFromRFBServer(client, (char *)&complete, 1)) goto error; - rfbClientLog("Client step result complete: %d. Data %d bytes %p '%s'\n", + rfbClientLog2(client, "Client step result complete: %d. Data %d bytes %p '%s'\n", complete, serverinlen, serverin, serverin); /* This server call shows complete, and earlier client step was OK */ @@ -455,32 +455,32 @@ HandleSASLAuth(rfbClient *client) if (!client->tlsSession) { err = sasl_getprop(saslconn, SASL_SSF, &val); if (err != SASL_OK) { - rfbClientLog("cannot query SASL ssf on connection %d (%s)\n", + rfbClientLog2(client, "cannot query SASL ssf on connection %d (%s)\n", err, sasl_errstring(err, NULL, NULL)); goto error; } ssf = *(const int *)val; - rfbClientLog("SASL SSF value %d\n", ssf); + rfbClientLog2(client, "SASL SSF value %d\n", ssf); if (ssf < 56) { /* 56 == DES level, good for Kerberos */ - rfbClientLog("negotiation SSF %d was not strong enough\n", ssf); + rfbClientLog2(client, "negotiation SSF %d was not strong enough\n", ssf); goto error; } } - rfbClientLog("%s", "SASL authentication complete\n"); + rfbClientLog2(client, "%s", "SASL authentication complete\n"); uint32_t result; if (!ReadFromRFBServer(client, (char *)&result, 4)) { - rfbClientLog("Failed to read authentication result\n"); + rfbClientLog2(client, "Failed to read authentication result\n"); goto error; } result = rfbClientSwap32IfLE(result); if (result != 0) { - rfbClientLog("Authentication failure\n"); + rfbClientLog2(client, "Authentication failure\n"); goto error; } - rfbClientLog("Authentication successful - switching to SSF\n"); + rfbClientLog2(client, "Authentication successful - switching to SSF\n"); /* This must come *after* check-auth-result, because the former * is defined to be sent unencrypted, and setting saslconn turns @@ -541,7 +541,7 @@ ReadFromSASL(rfbClient* client, char *out, unsigned int n) &client->saslDecoded, &client->saslDecodedLength); free(encoded); if (err != SASL_OK) { - rfbClientLog("Failed to decode SASL data %s\n", + rfbClientLog2(client, "Failed to decode SASL data %s\n", sasl_errstring(err, NULL, NULL)); return -EINVAL; } diff --git a/src/libvncclient/sockets.c b/src/libvncclient/sockets.c index 0318391b..2bf1b474 100644 --- a/src/libvncclient/sockets.c +++ b/src/libvncclient/sockets.c @@ -41,7 +41,7 @@ #include "tls.h" #include "sasl.h" -void PrintInHex(char *buf, int len); +void PrintInHex(rfbClient* client, char *buf, int len); rfbBool errorMessageOnReadFailure = TRUE; @@ -68,7 +68,7 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) #ifdef DEBUG_READ_EXACT char* oout=out; unsigned int nn=n; - rfbClientLog("ReadFromRFBServer %d bytes\n",n); + rfbClientLog2(client, "ReadFromRFBServer %d bytes\n",n); #endif /* Handle attempts to write to NULL out buffer that might occur @@ -156,7 +156,7 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) if (client->readTimeout > 0 && ++retries > (client->readTimeout * 1000 * 1000 / USECS_WAIT_PER_RETRY)) { - rfbClientLog("Connection timed out\n"); + rfbClientLog2(client, "Connection timed out\n"); return FALSE; } /* TODO: @@ -165,12 +165,12 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) WaitForMessage(client, USECS_WAIT_PER_RETRY); i = 0; } else { - rfbClientErr("read (%d: %s)\n",errno,strerror(errno)); + rfbClientErr2(client, "read (%d: %s)\n",errno,strerror(errno)); return FALSE; } } else { if (errorMessageOnReadFailure) { - rfbClientLog("VNC server closed connection\n"); + rfbClientLog2(client, "VNC server closed connection\n"); } return FALSE; } @@ -205,7 +205,7 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) if (client->readTimeout > 0 && ++retries > (client->readTimeout * 1000 * 1000 / USECS_WAIT_PER_RETRY)) { - rfbClientLog("Connection timed out\n"); + rfbClientLog2(client, "Connection timed out\n"); return FALSE; } /* TODO: @@ -214,12 +214,12 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) WaitForMessage(client, USECS_WAIT_PER_RETRY); i = 0; } else { - rfbClientErr("read (%s)\n",strerror(errno)); + rfbClientErr2(client, "read (%s)\n",strerror(errno)); return FALSE; } } else { if (errorMessageOnReadFailure) { - rfbClientLog("VNC server closed connection\n"); + rfbClientLog2(client, "VNC server closed connection\n"); } return FALSE; } @@ -275,7 +275,7 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n) buf, n, &output, &outputlen); if (err != SASL_OK) { - rfbClientLog("Failed to encode SASL data %s", + rfbClientLog2(client, "Failed to encode SASL data %s", sasl_errstring(err, NULL, NULL)); return FALSE; } @@ -298,7 +298,7 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n) errno == EAGAIN) { if(client->sock == RFB_INVALID_SOCKET) { errno = EBADF; - rfbClientErr("socket invalid\n"); + rfbClientErr2(client, "socket invalid\n"); return FALSE; } @@ -306,16 +306,16 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n) FD_SET(client->sock,&fds); if (select(client->sock+1, NULL, &fds, NULL, NULL) <= 0) { - rfbClientErr("select\n"); + rfbClientErr2(client, "select\n"); return FALSE; } j = 0; } else { - rfbClientErr("write\n"); + rfbClientErr2(client, "write\n"); return FALSE; } } else { - rfbClientLog("write failed\n"); + rfbClientLog2(client, "write failed\n"); return FALSE; } } @@ -326,18 +326,18 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n) rfbSocket -ConnectClientToTcpAddr(unsigned int host, int port) +ConnectClientToTcpAddr(rfbClient* client, unsigned int host, int port) { - rfbSocket sock = ConnectClientToTcpAddrWithTimeout(host, port, DEFAULT_CONNECT_TIMEOUT); + rfbSocket sock = ConnectClientToTcpAddrWithTimeout(client, host, port, DEFAULT_CONNECT_TIMEOUT); /* put socket back into blocking mode for compatibility reasons */ if (sock != RFB_INVALID_SOCKET) { - SetBlocking(sock); + SetBlocking(client, sock); } return sock; } rfbSocket -ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int timeout) +ConnectClientToTcpAddrWithTimeout(rfbClient* client, unsigned int host, int port, unsigned int timeout) { rfbSocket sock; struct sockaddr_in addr; @@ -352,11 +352,11 @@ ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int time #ifdef WIN32 errno=WSAGetLastError(); #endif - rfbClientErr("ConnectToTcpAddr: socket (%s)\n",strerror(errno)); + rfbClientErr2(client, "ConnectToTcpAddr: socket (%s)\n",strerror(errno)); return RFB_INVALID_SOCKET; } - if (!SetNonBlocking(sock)) + if (!SetNonBlocking(client, sock)) return FALSE; if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { @@ -364,7 +364,7 @@ ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int time errno=WSAGetLastError(); #endif if (!((errno == EWOULDBLOCK || errno == EINPROGRESS) && sock_wait_for_connected(sock, timeout))) { - rfbClientErr("ConnectToTcpAddr: connect\n"); + rfbClientErr2(client, "ConnectToTcpAddr: connect\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } @@ -372,7 +372,7 @@ ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int time if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { - rfbClientErr("ConnectToTcpAddr: setsockopt\n"); + rfbClientErr2(client, "ConnectToTcpAddr: setsockopt\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } @@ -381,18 +381,18 @@ ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int time } rfbSocket -ConnectClientToTcpAddr6(const char *hostname, int port) +ConnectClientToTcpAddr6(rfbClient* client, const char *hostname, int port) { - rfbSocket sock = ConnectClientToTcpAddr6WithTimeout(hostname, port, DEFAULT_CONNECT_TIMEOUT); + rfbSocket sock = ConnectClientToTcpAddr6WithTimeout(client, hostname, port, DEFAULT_CONNECT_TIMEOUT); /* put socket back into blocking mode for compatibility reasons */ if (sock != RFB_INVALID_SOCKET) { - SetBlocking(sock); + SetBlocking(client, sock); } return sock; } rfbSocket -ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout) +ConnectClientToTcpAddr6WithTimeout(rfbClient* client, const char *hostname, int port, unsigned int timeout) { #ifdef LIBVNCSERVER_IPv6 rfbSocket sock; @@ -407,7 +407,7 @@ ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int hints.ai_socktype = SOCK_STREAM; if ((n = getaddrinfo(strcmp(hostname,"") == 0 ? "localhost": hostname, port_s, &hints, &res))) { - rfbClientErr("ConnectClientToTcpAddr6: getaddrinfo (%s)\n", gai_strerror(n)); + rfbClientErr2(client, "ConnectClientToTcpAddr6: getaddrinfo (%s)\n", gai_strerror(n)); return RFB_INVALID_SOCKET; } @@ -418,7 +418,7 @@ ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sock != RFB_INVALID_SOCKET) { - if (SetNonBlocking(sock)) { + if (SetNonBlocking(client, sock)) { if (connect(sock, res->ai_addr, res->ai_addrlen) == 0) { break; } else { @@ -441,13 +441,13 @@ ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int if (sock == RFB_INVALID_SOCKET) { - rfbClientErr("ConnectClientToTcpAddr6: connect\n"); + rfbClientErr2(client, "ConnectClientToTcpAddr6: connect\n"); return RFB_INVALID_SOCKET; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { - rfbClientErr("ConnectToTcpAddr: setsockopt\n"); + rfbClientErr2(client, "ConnectToTcpAddr: setsockopt\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } @@ -456,51 +456,51 @@ ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int #else - rfbClientErr("ConnectClientToTcpAddr6: IPv6 disabled\n"); + rfbClientErr2(client, "ConnectClientToTcpAddr6: IPv6 disabled\n"); return RFB_INVALID_SOCKET; #endif } rfbSocket -ConnectClientToUnixSock(const char *sockFile) +ConnectClientToUnixSock(rfbClient* client, const char *sockFile) { - rfbSocket sock = ConnectClientToUnixSockWithTimeout(sockFile, DEFAULT_CONNECT_TIMEOUT); + rfbSocket sock = ConnectClientToUnixSockWithTimeout(client, sockFile, DEFAULT_CONNECT_TIMEOUT); /* put socket back into blocking mode for compatibility reasons */ if (sock != RFB_INVALID_SOCKET) { - SetBlocking(sock); + SetBlocking(client, sock); } return sock; } rfbSocket -ConnectClientToUnixSockWithTimeout(const char *sockFile, unsigned int timeout) +ConnectClientToUnixSockWithTimeout(rfbClient* client, const char *sockFile, unsigned int timeout) { #ifdef WIN32 - rfbClientErr("Windows doesn't support UNIX sockets\n"); + rfbClientErr2(client, "Windows doesn't support UNIX sockets\n"); return RFB_INVALID_SOCKET; #else rfbSocket sock; struct sockaddr_un addr; addr.sun_family = AF_UNIX; if(strlen(sockFile) + 1 > sizeof(addr.sun_path)) { - rfbClientErr("ConnectToUnixSock: socket file name too long\n"); + rfbClientErr2(client, "ConnectToUnixSock: socket file name too long\n"); return RFB_INVALID_SOCKET; } strcpy(addr.sun_path, sockFile); sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock == RFB_INVALID_SOCKET) { - rfbClientErr("ConnectToUnixSock: socket (%s)\n",strerror(errno)); + rfbClientErr2(client, "ConnectToUnixSock: socket (%s)\n",strerror(errno)); return RFB_INVALID_SOCKET; } - if (!SetNonBlocking(sock)) + if (!SetNonBlocking(client, sock)) return RFB_INVALID_SOCKET; if (connect(sock, (struct sockaddr *)&addr, sizeof(addr.sun_family) + strlen(addr.sun_path)) < 0 && !(errno == EINPROGRESS && sock_wait_for_connected(sock, timeout))) { - rfbClientErr("ConnectToUnixSock: connect\n"); + rfbClientErr2(client, "ConnectToUnixSock: connect\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } @@ -517,7 +517,7 @@ ConnectClientToUnixSockWithTimeout(const char *sockFile, unsigned int timeout) */ int -FindFreeTcpPort(void) +FindFreeTcpPort(rfbClient* client) { rfbSocket sock; int port; @@ -528,7 +528,7 @@ FindFreeTcpPort(void) sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == RFB_INVALID_SOCKET) { - rfbClientErr(": FindFreeTcpPort: socket\n"); + rfbClientErr2(client, ": FindFreeTcpPort: socket\n"); return 0; } @@ -550,9 +550,9 @@ FindFreeTcpPort(void) */ rfbSocket -ListenAtTcpPort(int port) +ListenAtTcpPort(rfbClient* client, int port) { - return ListenAtTcpPortAndAddress(port, NULL); + return ListenAtTcpPortAndAddress(client, port, NULL); } @@ -563,7 +563,7 @@ ListenAtTcpPort(int port) */ rfbSocket -ListenAtTcpPortAndAddress(int port, const char *address) +ListenAtTcpPortAndAddress(rfbClient* client, int port, const char *address) { rfbSocket sock = RFB_INVALID_SOCKET; int one = 1; @@ -580,19 +580,19 @@ ListenAtTcpPortAndAddress(int port, const char *address) sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == RFB_INVALID_SOCKET) { - rfbClientErr("ListenAtTcpPort: socket\n"); + rfbClientErr2(client, "ListenAtTcpPort: socket\n"); return RFB_INVALID_SOCKET; } if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(one)) < 0) { - rfbClientErr("ListenAtTcpPort: setsockopt\n"); + rfbClientErr2(client, "ListenAtTcpPort: setsockopt\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - rfbClientErr("ListenAtTcpPort: bind\n"); + rfbClientErr2(client, "ListenAtTcpPort: bind\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } @@ -610,7 +610,7 @@ ListenAtTcpPortAndAddress(int port, const char *address) hints.ai_flags = AI_PASSIVE; /* fill in wildcard address if address == NULL */ if ((rv = getaddrinfo(address, port_str, &hints, &servinfo)) != 0) { - rfbClientErr("ListenAtTcpPortAndAddress: error in getaddrinfo: %s\n", gai_strerror(rv)); + rfbClientErr2(client, "ListenAtTcpPortAndAddress: error in getaddrinfo: %s\n", gai_strerror(rv)); return RFB_INVALID_SOCKET; } @@ -623,7 +623,7 @@ ListenAtTcpPortAndAddress(int port, const char *address) #ifdef IPV6_V6ONLY /* we have separate IPv4 and IPv6 sockets since some OS's do not support dual binding */ if (p->ai_family == AF_INET6 && setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&one, sizeof(one)) < 0) { - rfbClientErr("ListenAtTcpPortAndAddress: error in setsockopt IPV6_V6ONLY: %s\n", strerror(errno)); + rfbClientErr2(client, "ListenAtTcpPortAndAddress: error in setsockopt IPV6_V6ONLY: %s\n", strerror(errno)); rfbCloseSocket(sock); freeaddrinfo(servinfo); return RFB_INVALID_SOCKET; @@ -631,7 +631,7 @@ ListenAtTcpPortAndAddress(int port, const char *address) #endif if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)) < 0) { - rfbClientErr("ListenAtTcpPortAndAddress: error in setsockopt SO_REUSEADDR: %s\n", strerror(errno)); + rfbClientErr2(client, "ListenAtTcpPortAndAddress: error in setsockopt SO_REUSEADDR: %s\n", strerror(errno)); rfbCloseSocket(sock); freeaddrinfo(servinfo); return RFB_INVALID_SOCKET; @@ -646,7 +646,7 @@ ListenAtTcpPortAndAddress(int port, const char *address) } if (p == NULL) { - rfbClientErr("ListenAtTcpPortAndAddress: error in bind: %s\n", strerror(errno)); + rfbClientErr2(client, "ListenAtTcpPortAndAddress: error in bind: %s\n", strerror(errno)); return RFB_INVALID_SOCKET; } @@ -655,7 +655,7 @@ ListenAtTcpPortAndAddress(int port, const char *address) #endif if (listen(sock, 5) < 0) { - rfbClientErr("ListenAtTcpPort: listen\n"); + rfbClientErr2(client, "ListenAtTcpPort: listen\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } @@ -669,7 +669,7 @@ ListenAtTcpPortAndAddress(int port, const char *address) */ rfbSocket -AcceptTcpConnection(rfbSocket listenSock) +AcceptTcpConnection(rfbClient* client, rfbSocket listenSock) { rfbSocket sock; struct sockaddr_in addr; @@ -678,13 +678,13 @@ AcceptTcpConnection(rfbSocket listenSock) sock = accept(listenSock, (struct sockaddr *) &addr, &addrlen); if (sock == RFB_INVALID_SOCKET) { - rfbClientErr("AcceptTcpConnection: accept\n"); + rfbClientErr2(client, "AcceptTcpConnection: accept\n"); return RFB_INVALID_SOCKET; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { - rfbClientErr("AcceptTcpConnection: setsockopt\n"); + rfbClientErr2(client, "AcceptTcpConnection: setsockopt\n"); rfbCloseSocket(sock); return RFB_INVALID_SOCKET; } @@ -698,15 +698,15 @@ AcceptTcpConnection(rfbSocket listenSock) */ rfbBool -SetNonBlocking(rfbSocket sock) +SetNonBlocking(rfbClient* client, rfbSocket sock) { - return sock_set_nonblocking(sock, TRUE, rfbClientErr); + return sock_set_nonblocking(client, sock, TRUE, rfbClientErr2); } -rfbBool SetBlocking(rfbSocket sock) +rfbBool SetBlocking(rfbClient* client, rfbSocket sock) { - return sock_set_nonblocking(sock, FALSE, rfbClientErr); + return sock_set_nonblocking(client, sock, FALSE, rfbClientErr2); } @@ -715,10 +715,10 @@ rfbBool SetBlocking(rfbSocket sock) */ rfbBool -SetDSCP(rfbSocket sock, int dscp) +SetDSCP(rfbClient* client, rfbSocket sock, int dscp) { #ifdef WIN32 - rfbClientErr("Setting of QoS IP DSCP not implemented for Windows\n"); + rfbClientErr2(client, "Setting of QoS IP DSCP not implemented for Windows\n"); return TRUE; #else int level, cmd; @@ -726,7 +726,7 @@ SetDSCP(rfbSocket sock, int dscp) socklen_t addrlen = sizeof(addr); if(getsockname(sock, &addr, &addrlen) != 0) { - rfbClientErr("Setting socket QoS failed while getting socket address: %s\n",strerror(errno)); + rfbClientErr2(client, "Setting socket QoS failed while getting socket address: %s\n",strerror(errno)); return FALSE; } @@ -743,12 +743,12 @@ SetDSCP(rfbSocket sock, int dscp) cmd = IP_TOS; break; default: - rfbClientErr("Setting socket QoS failed: Not bound to IP address"); + rfbClientErr2(client, "Setting socket QoS failed: Not bound to IP address"); return FALSE; } if(setsockopt(sock, level, cmd, (void*)&dscp, sizeof(dscp)) != 0) { - rfbClientErr("Setting socket QoS failed: %s\n", strerror(errno)); + rfbClientErr2(client, "Setting socket QoS failed: %s\n", strerror(errno)); return FALSE; } @@ -813,39 +813,39 @@ SameMachine(rfbSocket sock) */ void -PrintInHex(char *buf, int len) +PrintInHex(rfbClient* client, char *buf, int len) { int i, j; char c, str[17]; str[16] = 0; - rfbClientLog("ReadExact: "); + rfbClientLog2(client, "ReadExact: "); for (i = 0; i < len; i++) { if ((i % 16 == 0) && (i != 0)) { - rfbClientLog(" "); + rfbClientLog2(client, " "); } c = buf[i]; str[i % 16] = (((c > 31) && (c < 127)) ? c : '.'); - rfbClientLog("%02x ",(unsigned char)c); + rfbClientLog2(client, "%02x ",(unsigned char)c); if ((i % 4) == 3) - rfbClientLog(" "); + rfbClientLog2(client, " "); if ((i % 16) == 15) { - rfbClientLog("%s\n",str); + rfbClientLog2(client, "%s\n",str); } } if ((i % 16) != 0) { for (j = i % 16; j < 16; j++) { - rfbClientLog(" "); - if ((j % 4) == 3) rfbClientLog(" "); + rfbClientLog2(client, " "); + if ((j % 4) == 3) rfbClientLog2(client, " "); } str[i % 16] = 0; - rfbClientLog("%s\n",str); + rfbClientLog2(client, "%s\n",str); } fflush(stderr); @@ -877,7 +877,7 @@ int WaitForMessage(rfbClient* client,unsigned int usecs) #ifdef WIN32 errno=WSAGetLastError(); #endif - rfbClientLog("Waiting for message failed: %d (%s)\n",errno,strerror(errno)); + rfbClientLog2(client, "Waiting for message failed: %d (%s)\n",errno,strerror(errno)); } return num; diff --git a/src/libvncclient/tight.c b/src/libvncclient/tight.c index 57a3715b..c1ae00fd 100644 --- a/src/libvncclient/tight.c +++ b/src/libvncclient/tight.c @@ -147,7 +147,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) return FALSE; if (rx + rw > client->width || ry + rh > client->height) { - rfbClientLog("Rect out of bounds: %dx%d at (%d, %d)\n", rx, ry, rw, rh); + rfbClientLog2(client, "Rect out of bounds: %dx%d at (%d, %d)\n", rx, ry, rw, rh); return FALSE; } @@ -159,7 +159,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) if ((comp_ctl & 1) && client->zlibStreamActive[stream_id]) { if (inflateEnd (&client->zlibStream[stream_id]) != Z_OK && client->zlibStream[stream_id].msg != NULL) - rfbClientLog("inflateEnd: %s\n", client->zlibStream[stream_id].msg); + rfbClientLog2(client, "inflateEnd: %s\n", client->zlibStream[stream_id].msg); client->zlibStreamActive[stream_id] = FALSE; } comp_ctl >>= 1; @@ -194,7 +194,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) #if BPP == 8 if (comp_ctl == rfbTightJpeg) { - rfbClientLog("Tight encoding: JPEG is not supported in 8 bpp mode.\n"); + rfbClientLog2(client, "Tight encoding: JPEG is not supported in 8 bpp mode.\n"); return FALSE; } #else @@ -205,7 +205,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) /* Quit on unsupported subencoding value. */ if (comp_ctl > rfbTightMaxSubencoding) { - rfbClientLog("Tight encoding: bad subencoding value received.\n"); + rfbClientLog2(client, "Tight encoding: bad subencoding value received.\n"); return FALSE; } @@ -233,7 +233,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) bitsPixel = InitFilterGradientBPP(client, rw, rh); break; default: - rfbClientLog("Tight encoding: unknown filter code received.\n"); + rfbClientLog2(client, "Tight encoding: unknown filter code received.\n"); return FALSE; } } else { @@ -241,7 +241,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) bitsPixel = InitFilterCopyBPP(client, rw, rh); } if (bitsPixel == 0) { - rfbClientLog("Tight encoding: error receiving palette.\n"); + rfbClientLog2(client, "Tight encoding: error receiving palette.\n"); return FALSE; } @@ -259,12 +259,12 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) /* Read the length (1..3 bytes) of compressed data following. */ compressedLen = (int)ReadCompactLen(client); if (compressedLen <= 0) { - rfbClientLog("Incorrect data received from the server.\n"); + rfbClientLog2(client, "Incorrect data received from the server.\n"); return FALSE; } if (readUncompressed) { if (compressedLen > RFB_BUFFER_SIZE) { - rfbClientErr("Received uncompressed byte count exceeds our buffer size.\n"); + rfbClientErr2(client, "Received uncompressed byte count exceeds our buffer size.\n"); return FALSE; } @@ -286,7 +286,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) err = inflateInit(zs); if (err != Z_OK) { if (zs->msg != NULL) - rfbClientLog("InflateInit error: %s.\n", zs->msg); + rfbClientLog2(client, "InflateInit error: %s.\n", zs->msg); return FALSE; } client->zlibStreamActive[stream_id] = TRUE; @@ -297,7 +297,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) bufferSize = RFB_BUFFER_SIZE * bitsPixel / (bitsPixel + BPP) & 0xFFFFFFFC; if (rowSize > bufferSize) { /* Should be impossible when RFB_BUFFER_SIZE >= 16384 */ - rfbClientLog("Internal error: incorrect buffer size.\n"); + rfbClientLog2(client, "Internal error: incorrect buffer size.\n"); return FALSE; } @@ -327,9 +327,9 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) break; if (err != Z_OK && err != Z_STREAM_END) { if (zs->msg != NULL) { - rfbClientLog("Inflate error: %s.\n", zs->msg); + rfbClientLog2(client, "Inflate error: %s.\n", zs->msg); } else { - rfbClientLog("Inflate error: %d.\n", err); + rfbClientLog2(client, "Inflate error: %d.\n", err); } return FALSE; } @@ -348,7 +348,7 @@ HandleTightBPP (rfbClient* client, int rx, int ry, int rw, int rh) } if (rowsProcessed != rh) { - rfbClientLog("Incorrect number of scan lines after decompression.\n"); + rfbClientLog2(client, "Incorrect number of scan lines after decompression.\n"); return FALSE; } @@ -603,13 +603,13 @@ DecompressJpegRectBPP(rfbClient* client, int x, int y, int w, int h) compressedLen = (int)ReadCompactLen(client); if (compressedLen <= 0) { - rfbClientLog("Incorrect data received from the server.\n"); + rfbClientLog2(client, "Incorrect data received from the server.\n"); return FALSE; } compressedData = malloc(compressedLen); if (compressedData == NULL) { - rfbClientLog("Memory allocation error.\n"); + rfbClientLog2(client, "Memory allocation error.\n"); return FALSE; } @@ -623,7 +623,7 @@ DecompressJpegRectBPP(rfbClient* client, int x, int y, int w, int h) if (!client->tjhnd) { if ((client->tjhnd = tjInitDecompress()) == NULL) { - rfbClientLog("TurboJPEG error: %s\n", tjGetErrorStr()); + rfbClientLog2(client, "TurboJPEG error: %s\n", tjGetErrorStr()); free(compressedData); return FALSE; } @@ -646,7 +646,7 @@ DecompressJpegRectBPP(rfbClient* client, int x, int y, int w, int h) if (tjDecompress(client->tjhnd, compressedData, (unsigned long)compressedLen, dst, w, pitch, h, pixelSize, flags)==-1) { - rfbClientLog("TurboJPEG error: %s\n", tjGetErrorStr()); + rfbClientLog2(client, "TurboJPEG error: %s\n", tjGetErrorStr()); free(compressedData); return FALSE; } diff --git a/src/libvncclient/tls_gnutls.c b/src/libvncclient/tls_gnutls.c index 744fabd2..1955d25f 100644 --- a/src/libvncclient/tls_gnutls.c +++ b/src/libvncclient/tls_gnutls.c @@ -46,13 +46,13 @@ verify_certificate_callback (gnutls_session_t session) sptr = (rfbClient *)gnutls_session_get_ptr(session); if (!sptr) { - rfbClientLog("Failed to validate certificate - missing client data\n"); + rfbClientLog2(client, "Failed to validate certificate - missing client data\n"); return GNUTLS_E_CERTIFICATE_ERROR; } hostname = sptr->serverHost; if (!hostname) { - rfbClientLog("No server hostname found for client\n"); + rfbClientLog2(client, "No server hostname found for client\n"); return GNUTLS_E_CERTIFICATE_ERROR; } @@ -67,19 +67,19 @@ verify_certificate_callback (gnutls_session_t session) } if (status & GNUTLS_CERT_INVALID) - rfbClientLog("The certificate is not trusted.\n"); + rfbClientLog2(client, "The certificate is not trusted.\n"); if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - rfbClientLog("The certificate hasn't got a known issuer.\n"); + rfbClientLog2(client, "The certificate hasn't got a known issuer.\n"); if (status & GNUTLS_CERT_REVOKED) - rfbClientLog("The certificate has been revoked.\n"); + rfbClientLog2(client, "The certificate has been revoked.\n"); if (status & GNUTLS_CERT_EXPIRED) - rfbClientLog("The certificate has expired\n"); + rfbClientLog2(client, "The certificate has expired\n"); if (status & GNUTLS_CERT_NOT_ACTIVATED) - rfbClientLog("The certificate is not yet activated\n"); + rfbClientLog2(client, "The certificate is not yet activated\n"); if (status) return GNUTLS_E_CERTIFICATE_ERROR; @@ -89,32 +89,32 @@ verify_certificate_callback (gnutls_session_t session) * be easily extended to work with openpgp keys as well. */ if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509) { - rfbClientLog("The certificate was not X509\n"); + rfbClientLog2(client, "The certificate was not X509\n"); return GNUTLS_E_CERTIFICATE_ERROR; } if (gnutls_x509_crt_init (&cert) < 0) { - rfbClientLog("Error initialising certificate structure\n"); + rfbClientLog2(client, "Error initialising certificate structure\n"); return GNUTLS_E_CERTIFICATE_ERROR; } cert_list = gnutls_certificate_get_peers (session, &cert_list_size); if (cert_list == NULL) { - rfbClientLog("No certificate was found!\n"); + rfbClientLog2(client, "No certificate was found!\n"); return GNUTLS_E_CERTIFICATE_ERROR; } if (gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0) { - rfbClientLog("Error parsing certificate\n"); + rfbClientLog2(client, "Error parsing certificate\n"); return GNUTLS_E_CERTIFICATE_ERROR; } if (!gnutls_x509_crt_check_hostname (cert, hostname)) { - rfbClientLog("The certificate's owner does not match hostname '%s'\n", + rfbClientLog2(client, "The certificate's owner does not match hostname '%s'\n", hostname); return GNUTLS_E_CERTIFICATE_ERROR; } @@ -135,10 +135,10 @@ InitializeTLS(void) (ret = gnutls_dh_params_init(&rfbDHParams)) < 0 || (ret = gnutls_dh_params_generate2(rfbDHParams, DH_BITS)) < 0) { - rfbClientLog("Failed to initialized GnuTLS: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Failed to initialized GnuTLS: %s.\n", gnutls_strerror(ret)); return FALSE; } - rfbClientLog("GnuTLS version %s initialized.\n", gnutls_check_version(NULL)); + rfbClientLog2(client, "GnuTLS version %s initialized.\n", gnutls_check_version(NULL)); rfbTLSInitialized = TRUE; return TRUE; } @@ -255,14 +255,14 @@ InitializeTLSSession(rfbClient* client, rfbBool anonTLS) if ((ret = gnutls_init((gnutls_session_t*)&client->tlsSession, GNUTLS_CLIENT)) < 0) { - rfbClientLog("Failed to initialized TLS session: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Failed to initialized TLS session: %s.\n", gnutls_strerror(ret)); return FALSE; } if ((ret = gnutls_priority_set_direct((gnutls_session_t)client->tlsSession, anonTLS ? rfbAnonTLSPriority : rfbTLSPriority, &p)) < 0) { - rfbClientLog("Warning: Failed to set TLS priority: %s (%s).\n", gnutls_strerror(ret), p); + rfbClientLog2(client, "Warning: Failed to set TLS priority: %s (%s).\n", gnutls_strerror(ret), p); } gnutls_transport_set_ptr((gnutls_session_t)client->tlsSession, (gnutls_transport_ptr_t)client); @@ -274,7 +274,7 @@ InitializeTLSSession(rfbClient* client, rfbBool anonTLS) INIT_MUTEX(client->tlsRwMutex); - rfbClientLog("TLS session initialized.\n"); + rfbClientLog2(client, "TLS session initialized.\n"); return TRUE; } @@ -289,10 +289,10 @@ SetTLSAnonCredential(rfbClient* client) (ret = gnutls_credentials_set((gnutls_session_t)client->tlsSession, GNUTLS_CRD_ANON, anonCred)) < 0) { FreeTLS(client); - rfbClientLog("Failed to create anonymous credentials: %s", gnutls_strerror(ret)); + rfbClientLog2(client, "Failed to create anonymous credentials: %s", gnutls_strerror(ret)); return FALSE; } - rfbClientLog("TLS anonymous credential created.\n"); + rfbClientLog2(client, "TLS anonymous credential created.\n"); return TRUE; } @@ -305,15 +305,15 @@ HandshakeTLS(rfbClient* client) { if (!gnutls_error_is_fatal(ret)) { - rfbClientLog("TLS handshake got a temporary error: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "TLS handshake got a temporary error: %s.\n", gnutls_strerror(ret)); continue; } - rfbClientLog("TLS handshake failed: %s\n", gnutls_strerror(ret)); + rfbClientLog2(client, "TLS handshake failed: %s\n", gnutls_strerror(ret)); FreeTLS(client); return FALSE; } - rfbClientLog("TLS handshake done.\n"); + rfbClientLog2(client, "TLS handshake done.\n"); return TRUE; } @@ -331,18 +331,18 @@ ReadVeNCryptSecurityType(rfbClient* client, uint32_t *result) if (count==0) { - rfbClientLog("List of security types is ZERO. Giving up.\n"); + rfbClientLog2(client, "List of security types is ZERO. Giving up.\n"); return FALSE; } - rfbClientLog("We have %d security types to read\n", count); + rfbClientLog2(client, "We have %d security types to read\n", count); authScheme=0; /* now, we have a list of available security types to read ( uint8_t[] ) */ for (loop=0;loop0 ? ", %d" : "%d"), (int)tAuth[loop]); strncat(buf1, buf2, sizeof(buf1)-strlen(buf1)-1); } - rfbClientLog("Unknown VeNCrypt authentication scheme from VNC server: %s\n", + rfbClientLog2(client, "Unknown VeNCrypt authentication scheme from VNC server: %s\n", buf1); return FALSE; } else { - rfbClientLog("Selecting security type %d\n", authScheme); + rfbClientLog2(client, "Selecting security type %d\n", authScheme); /* send back 4 bytes (in original byte order!) indicating which security type to use */ if (!WriteToRFBServer(client, (char *)&origAuthScheme, 4)) return FALSE; } @@ -411,7 +411,7 @@ CreateX509CertCredential(rfbCredential *cred) if ((ret = gnutls_certificate_allocate_credentials(&x509_cred)) < 0) { - rfbClientLog("Cannot allocate credentials: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Cannot allocate credentials: %s.\n", gnutls_strerror(ret)); return NULL; } if (cred->x509Credential.x509CACertFile) @@ -419,14 +419,14 @@ CreateX509CertCredential(rfbCredential *cred) if ((ret = gnutls_certificate_set_x509_trust_file(x509_cred, cred->x509Credential.x509CACertFile, GNUTLS_X509_FMT_PEM)) < 0) { - rfbClientLog("Cannot load CA credentials: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Cannot load CA credentials: %s.\n", gnutls_strerror(ret)); gnutls_certificate_free_credentials (x509_cred); return NULL; } } else { int certs = gnutls_certificate_set_x509_system_trust (x509_cred); - rfbClientLog("Using default paths for certificate verification, %d certs found\n", certs); + rfbClientLog2(client, "Using default paths for certificate verification, %d certs found\n", certs); } if (cred->x509Credential.x509ClientCertFile && cred->x509Credential.x509ClientKeyFile) { @@ -434,26 +434,26 @@ CreateX509CertCredential(rfbCredential *cred) cred->x509Credential.x509ClientCertFile, cred->x509Credential.x509ClientKeyFile, GNUTLS_X509_FMT_PEM)) < 0) { - rfbClientLog("Cannot load client certificate or key: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Cannot load client certificate or key: %s.\n", gnutls_strerror(ret)); gnutls_certificate_free_credentials (x509_cred); return NULL; } } else { - rfbClientLog("No client certificate or key provided.\n"); + rfbClientLog2(client, "No client certificate or key provided.\n"); } if (cred->x509Credential.x509CACrlFile) { if ((ret = gnutls_certificate_set_x509_crl_file(x509_cred, cred->x509Credential.x509CACrlFile, GNUTLS_X509_FMT_PEM)) < 0) { - rfbClientLog("Cannot load CRL: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Cannot load CRL: %s.\n", gnutls_strerror(ret)); gnutls_certificate_free_credentials (x509_cred); return NULL; } } else { - rfbClientLog("No CRL provided.\n"); + rfbClientLog2(client, "No CRL provided.\n"); } gnutls_certificate_set_dh_params (x509_cred, rfbDHParams); return x509_cred; @@ -487,11 +487,11 @@ HandleVeNCryptAuth(rfbClient* client) { return FALSE; } - rfbClientLog("Got VeNCrypt version %d.%d from server.\n", (int)major, (int)minor); + rfbClientLog2(client, "Got VeNCrypt version %d.%d from server.\n", (int)major, (int)minor); if (major != 0 && minor != 2) { - rfbClientLog("Unsupported VeNCrypt version.\n"); + rfbClientLog2(client, "Unsupported VeNCrypt version.\n"); return FALSE; } @@ -504,7 +504,7 @@ HandleVeNCryptAuth(rfbClient* client) if (status != 0) { - rfbClientLog("Server refused VeNCrypt version %d.%d.\n", (int)major, (int)minor); + rfbClientLog2(client, "Server refused VeNCrypt version %d.%d.\n", (int)major, (int)minor); return FALSE; } @@ -538,7 +538,7 @@ HandleVeNCryptAuth(rfbClient* client) /* Ack is only requred for the encrypted connection */ if (!ReadFromRFBServer(client, (char *)&status, 1) || status != 1) { - rfbClientLog("Server refused VeNCrypt authentication %d (%d).\n", authScheme, (int)status); + rfbClientLog2(client, "Server refused VeNCrypt authentication %d (%d).\n", authScheme, (int)status); return FALSE; } @@ -551,13 +551,13 @@ HandleVeNCryptAuth(rfbClient* client) if (!client->GetCredential) { - rfbClientLog("GetCredential callback is not set.\n"); + rfbClientLog2(client, "GetCredential callback is not set.\n"); return FALSE; } cred = client->GetCredential(client, rfbCredentialTypeX509); if (!cred) { - rfbClientLog("Reading credential failed\n"); + rfbClientLog2(client, "Reading credential failed\n"); return FALSE; } @@ -581,7 +581,7 @@ HandleVeNCryptAuth(rfbClient* client) if ((ret = gnutls_credentials_set((gnutls_session_t)client->tlsSession, GNUTLS_CRD_CERTIFICATE, x509_cred)) < 0) { - rfbClientLog("Cannot set x509 credential: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Cannot set x509 credential: %s.\n", gnutls_strerror(ret)); FreeTLS(client); return FALSE; } @@ -610,7 +610,7 @@ ReadFromTLS(rfbClient* client, char *out, unsigned int n) errno = EAGAIN; } else { - rfbClientLog("Error reading from TLS: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Error reading from TLS: %s.\n", gnutls_strerror(ret)); errno = EINTR; } return -1; @@ -632,7 +632,7 @@ WriteToTLS(rfbClient* client, const char *buf, unsigned int n) if (ret < 0) { if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) continue; - rfbClientLog("Error writing to TLS: %s.\n", gnutls_strerror(ret)); + rfbClientLog2(client, "Error writing to TLS: %s.\n", gnutls_strerror(ret)); return -1; } offset += (unsigned int)ret; diff --git a/src/libvncclient/tls_none.c b/src/libvncclient/tls_none.c index d436ce9c..bb3a1245 100644 --- a/src/libvncclient/tls_none.c +++ b/src/libvncclient/tls_none.c @@ -23,21 +23,21 @@ rfbBool HandleAnonTLSAuth(rfbClient* client) { - rfbClientLog("TLS is not supported.\n"); + rfbClientLog2(client, "TLS is not supported.\n"); return FALSE; } rfbBool HandleVeNCryptAuth(rfbClient* client) { - rfbClientLog("TLS is not supported.\n"); + rfbClientLog2(client, "TLS is not supported.\n"); return FALSE; } int ReadFromTLS(rfbClient* client, char *out, unsigned int n) { - rfbClientLog("TLS is not supported.\n"); + rfbClientLog2(client, "TLS is not supported.\n"); errno = EINTR; return -1; } @@ -45,7 +45,7 @@ int ReadFromTLS(rfbClient* client, char *out, unsigned int n) int WriteToTLS(rfbClient* client, const char *buf, unsigned int n) { - rfbClientLog("TLS is not supported.\n"); + rfbClientLog2(client, "TLS is not supported.\n"); errno = EINTR; return -1; } @@ -60,7 +60,7 @@ void FreeTLS(rfbClient* client) int GetTLSCipherBits(rfbClient* client) { - rfbClientLog("TLS is not supported.\n"); + rfbClientLog2(client, "TLS is not supported.\n"); return 0; } #endif /* LIBVNCSERVER_HAVE_SASL */ diff --git a/src/libvncclient/tls_openssl.c b/src/libvncclient/tls_openssl.c index edf5f7fd..c917a8bf 100644 --- a/src/libvncclient/tls_openssl.c +++ b/src/libvncclient/tls_openssl.c @@ -93,7 +93,7 @@ static rfbBool InitLockingCb() { mutex_buf = malloc(CRYPTO_num_locks() * MUTEX_SIZE); if (mutex_buf == NULL) { - rfbClientLog("Failed to initialized OpenSSL: memory.\n"); + rfbClientLog2(client, "Failed to initialized OpenSSL: memory.\n"); return FALSE; } @@ -154,7 +154,7 @@ InitializeTLS(void) SSLeay_add_ssl_algorithms(); RAND_load_file("/dev/urandom", 1024); - rfbClientLog("OpenSSL version %s initialized.\n", SSLeay_version(SSLEAY_VERSION)); + rfbClientLog2(client, "OpenSSL version %s initialized.\n", SSLeay_version(SSLEAY_VERSION)); rfbTLSInitialized = TRUE; return TRUE; } @@ -204,7 +204,7 @@ static int wait_for_data(SSL *ssl, int ret, int timeout) retval = 3; long verify_res = SSL_get_verify_result(ssl); if (verify_res != X509_V_OK) - rfbClientLog("Could not verify server certificate: %s.\n", + rfbClientLog2(client, "Could not verify server certificate: %s.\n", X509_verify_cert_error_string(verify_res)); break; } @@ -263,7 +263,7 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti if (!(ssl_ctx = SSL_CTX_new(SSLv23_client_method()))) { - rfbClientLog("Could not create new SSL context.\n"); + rfbClientLog2(client, "Could not create new SSL context.\n"); return NULL; } @@ -277,12 +277,12 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti { if (!SSL_CTX_load_verify_locations(ssl_ctx, cred->x509Credential.x509CACertFile, NULL)) { - rfbClientLog("Failed to load CA certificate from %s.\n", + rfbClientLog2(client, "Failed to load CA certificate from %s.\n", cred->x509Credential.x509CACertFile); goto error_free_ctx; } } else { - rfbClientLog("Using default paths for certificate verification.\n"); + rfbClientLog2(client, "Using default paths for certificate verification.\n"); SSL_CTX_set_default_verify_paths (ssl_ctx); } @@ -290,7 +290,7 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti { if (!load_crls_from_file(cred->x509Credential.x509CACrlFile, ssl_ctx)) { - rfbClientLog("CRLs could not be loaded.\n"); + rfbClientLog2(client, "CRLs could not be loaded.\n"); goto error_free_ctx; } if (verify_crls == rfbX509CrlVerifyNone) verify_crls = rfbX509CrlVerifyAll; @@ -300,19 +300,19 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti { if (SSL_CTX_use_certificate_chain_file(ssl_ctx, cred->x509Credential.x509ClientCertFile) != 1) { - rfbClientLog("Client certificate could not be loaded.\n"); + rfbClientLog2(client, "Client certificate could not be loaded.\n"); goto error_free_ctx; } if (SSL_CTX_use_PrivateKey_file(ssl_ctx, cred->x509Credential.x509ClientKeyFile, SSL_FILETYPE_PEM) != 1) { - rfbClientLog("Client private key could not be loaded.\n"); + rfbClientLog2(client, "Client private key could not be loaded.\n"); goto error_free_ctx; } if (SSL_CTX_check_private_key(ssl_ctx) == 0) { - rfbClientLog("Client certificate and private key do not match.\n"); + rfbClientLog2(client, "Client certificate and private key do not match.\n"); goto error_free_ctx; } } @@ -326,7 +326,7 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti if(!X509_VERIFY_PARAM_set1_host(param, client->serverHost, strlen(client->serverHost))) { - rfbClientLog("Could not set server name for verification.\n"); + rfbClientLog2(client, "Could not set server name for verification.\n"); goto error_free_ctx; } SSL_CTX_set1_param(ssl_ctx, param); @@ -351,7 +351,7 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti if (!(ssl = SSL_new (ssl_ctx))) { - rfbClientLog("Could not create a new SSL session.\n"); + rfbClientLog2(client, "Could not create a new SSL session.\n"); goto error_free_ctx; } @@ -400,7 +400,7 @@ InitializeTLSSession(rfbClient* client, rfbBool anonTLS, rfbCredential *cred) INIT_MUTEX(client->tlsRwMutex); - rfbClientLog("TLS session initialized.\n"); + rfbClientLog2(client, "TLS session initialized.\n"); return TRUE; } @@ -417,7 +417,7 @@ return TRUE; { if (ret != -1) { - rfbClientLog("TLS handshake blocking.\n"); + rfbClientLog2(client, "TLS handshake blocking.\n"); #ifdef WIN32 Sleep(1000); #else @@ -426,7 +426,7 @@ return TRUE; timeout--; continue; } - rfbClientLog("TLS handshake failed.\n"); + rfbClientLog2(client, "TLS handshake failed.\n"); FreeTLS(client); return FALSE; @@ -434,12 +434,12 @@ return TRUE; if (timeout <= 0) { - rfbClientLog("TLS handshake timeout.\n"); + rfbClientLog2(client, "TLS handshake timeout.\n"); FreeTLS(client); return FALSE; } - rfbClientLog("TLS handshake done.\n"); + rfbClientLog2(client, "TLS handshake done.\n"); return TRUE; } @@ -457,18 +457,18 @@ ReadVeNCryptSecurityType(rfbClient* client, uint32_t *result) if (count==0) { - rfbClientLog("List of security types is ZERO. Giving up.\n"); + rfbClientLog2(client, "List of security types is ZERO. Giving up.\n"); return FALSE; } - rfbClientLog("We have %d security types to read\n", count); + rfbClientLog2(client, "We have %d security types to read\n", count); authScheme=0; /* now, we have a list of available security types to read ( uint8_t[] ) */ for (loop=0;loop0 ? ", %d" : "%d"), (int)tAuth[loop]); strncat(buf1, buf2, sizeof(buf1)-strlen(buf1)-1); } - rfbClientLog("Unknown VeNCrypt authentication scheme from VNC server: %s\n", + rfbClientLog2(client, "Unknown VeNCrypt authentication scheme from VNC server: %s\n", buf1); return FALSE; } else { - rfbClientLog("Selecting security type %d\n", authScheme); + rfbClientLog2(client, "Selecting security type %d\n", authScheme); /* send back 4 bytes (in original byte order!) indicating which security type to use */ if (!WriteToRFBServer(client, (char *)&origAuthScheme, 4)) return FALSE; } @@ -554,11 +554,11 @@ HandleVeNCryptAuth(rfbClient* client) { return FALSE; } - rfbClientLog("Got VeNCrypt version %d.%d from server.\n", (int)major, (int)minor); + rfbClientLog2(client, "Got VeNCrypt version %d.%d from server.\n", (int)major, (int)minor); if (major != 0 && minor != 2) { - rfbClientLog("Unsupported VeNCrypt version.\n"); + rfbClientLog2(client, "Unsupported VeNCrypt version.\n"); return FALSE; } @@ -571,7 +571,7 @@ HandleVeNCryptAuth(rfbClient* client) if (status != 0) { - rfbClientLog("Server refused VeNCrypt version %d.%d.\n", (int)major, (int)minor); + rfbClientLog2(client, "Server refused VeNCrypt version %d.%d.\n", (int)major, (int)minor); return FALSE; } @@ -605,7 +605,7 @@ HandleVeNCryptAuth(rfbClient* client) /* Ack is only requred for the encrypted connection */ if (!ReadFromRFBServer(client, (char *)&status, 1) || status != 1) { - rfbClientLog("Server refused VeNCrypt authentication %d (%d).\n", authScheme, (int)status); + rfbClientLog2(client, "Server refused VeNCrypt authentication %d (%d).\n", authScheme, (int)status); return FALSE; } @@ -617,13 +617,13 @@ HandleVeNCryptAuth(rfbClient* client) if (!client->GetCredential) { - rfbClientLog("GetCredential callback is not set.\n"); + rfbClientLog2(client, "GetCredential callback is not set.\n"); return FALSE; } cred = client->GetCredential(client, rfbCredentialTypeX509); if (!cred) { - rfbClientLog("Reading credential failed\n"); + rfbClientLog2(client, "Reading credential failed\n"); return FALSE; } } @@ -658,7 +658,7 @@ ReadFromTLS(rfbClient* client, char *out, unsigned int n) else { errno = ssl_error_to_errno(ssl_error); if (errno != EAGAIN) { - rfbClientLog("Error reading from TLS: -.\n"); + rfbClientLog2(client, "Error reading from TLS: -.\n"); } } @@ -686,7 +686,7 @@ WriteToTLS(rfbClient* client, const char *buf, unsigned int n) { errno = ssl_error_to_errno(ssl_error); if (errno == EAGAIN || errno == EWOULDBLOCK) continue; - rfbClientLog("Error writing to TLS: -\n"); + rfbClientLog2(client, "Error writing to TLS: -\n"); return -1; } offset += (unsigned int)ret; diff --git a/src/libvncclient/trle.c b/src/libvncclient/trle.c index cf06c185..35881ce2 100644 --- a/src/libvncclient/trle.c +++ b/src/libvncclient/trle.c @@ -76,7 +76,7 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { client->raw_buffer = (char *)malloc(client->raw_buffer_size); } - rfbClientLog("Update %d %d %d %d\n", rx, ry, rw, rh); + rfbClientLog2(client, "Update %d %d %d %d\n", rx, ry, rw, rh); for (y = ry; y < ry + rh; y += 16) { for (x = rx; x < rx + rw; x += 16) { @@ -198,7 +198,7 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { } } if (length > 0) - rfbClientLog("Warning: possible TRLE corruption\n"); + rfbClientLog2(client, "Warning: possible TRLE corruption\n"); } type = last_type; @@ -244,7 +244,7 @@ static rfbBool HandleTRLE(rfbClient *client, int rx, int ry, int rw, int rh) { } } if (length > 0) - rfbClientLog("Warning: possible TRLE corruption\n"); + rfbClientLog2(client, "Warning: possible TRLE corruption\n"); } if (type == 129) { diff --git a/src/libvncclient/ultra.c b/src/libvncclient/ultra.c index 1d3aaba6..ec523384 100644 --- a/src/libvncclient/ultra.c +++ b/src/libvncclient/ultra.c @@ -46,13 +46,13 @@ HandleUltraBPP (rfbClient* client, int rx, int ry, int rw, int rh) if (toRead==0) return TRUE; if (toRead < 0) { - rfbClientErr("ultra error: remote sent negative payload size\n"); + rfbClientErr2(client, "ultra error: remote sent negative payload size\n"); return FALSE; } if (uncompressedBytes==0) { - rfbClientLog("ultra error: rectangle has 0 uncomressed bytes ((%dw * %dh) * (%d / 8))\n", rw, rh, BPP); + rfbClientLog2(client, "ultra error: rectangle has 0 uncomressed bytes ((%dw * %dh) * (%d / 8))\n", rw, rh, BPP); return FALSE; } @@ -100,7 +100,7 @@ HandleUltraBPP (rfbClient* client, int rx, int ry, int rw, int rh) /* Note that uncompressedBytes will be 0 on output overrun */ if ((rw * rh * (BPP / 8)) != uncompressedBytes) - rfbClientLog("Ultra decompressed unexpected amount of data (%d != %d)\n", (rw * rh * (BPP / 8)), uncompressedBytes); + rfbClientLog2(client, "Ultra decompressed unexpected amount of data (%d != %d)\n", (rw * rh * (BPP / 8)), uncompressedBytes); /* Put the uncompressed contents of the update on the screen. */ if ( inflateResult == LZO_E_OK ) @@ -109,7 +109,7 @@ HandleUltraBPP (rfbClient* client, int rx, int ry, int rw, int rh) } else { - rfbClientLog("ultra decompress returned error: %d\n", + rfbClientLog2(client, "ultra decompress returned error: %d\n", inflateResult); return FALSE; } @@ -137,13 +137,13 @@ HandleUltraZipBPP (rfbClient* client, int rx, int ry, int rw, int rh) if (toRead==0) return TRUE; if (toRead < 0) { - rfbClientErr("ultrazip error: remote sent negative payload size\n"); + rfbClientErr2(client, "ultrazip error: remote sent negative payload size\n"); return FALSE; } if (uncompressedBytes==0) { - rfbClientLog("ultrazip error: rectangle has 0 uncomressed bytes (%dy + (%dw * 65535)) (%d rectangles)\n", ry, rw, rx); + rfbClientLog2(client, "ultrazip error: rectangle has 0 uncomressed bytes (%dy + (%dw * 65535)) (%d rectangles)\n", ry, rw, rx); return FALSE; } @@ -187,7 +187,7 @@ HandleUltraZipBPP (rfbClient* client, int rx, int ry, int rw, int rh) (lzo_byte *)client->raw_buffer, &uncompressedBytes, NULL); if ( inflateResult != LZO_E_OK ) { - rfbClientLog("ultra decompress returned error: %d\n", + rfbClientLog2(client, "ultra decompress returned error: %d\n", inflateResult); return FALSE; } diff --git a/src/libvncclient/vncviewer.c b/src/libvncclient/vncviewer.c index 4a0d7ebf..73455211 100644 --- a/src/libvncclient/vncviewer.c +++ b/src/libvncclient/vncviewer.c @@ -98,14 +98,14 @@ static rfbBool MallocFrameBuffer(rfbClient* client) { allocSize = (uint64_t)client->width * client->height * client->format.bitsPerPixel/8; if (allocSize >= SIZE_MAX) { - rfbClientErr("CRITICAL: cannot allocate frameBuffer, requested size is too large\n"); + rfbClientErr2(client, "CRITICAL: cannot allocate frameBuffer, requested size is too large\n"); return FALSE; } client->frameBuffer=malloc( (size_t)allocSize ); if (client->frameBuffer == NULL) - rfbClientErr("CRITICAL: frameBuffer allocation failed, requested size too large or not enough memory?\n"); + rfbClientErr2(client, "CRITICAL: frameBuffer allocation failed, requested size too large or not enough memory?\n"); return client->frameBuffer?TRUE:FALSE; } @@ -124,7 +124,7 @@ static void FillRectangle(rfbClient* client, int x, int y, int w, int h, uint32_ } if (!CheckRect(client, x, y, w, h)) { - rfbClientLog("Rect out of bounds: %dx%d at (%d, %d)\n", x, y, w, h); + rfbClientLog2(client, "Rect out of bounds: %dx%d at (%d, %d)\n", x, y, w, h); return; } @@ -138,7 +138,7 @@ static void FillRectangle(rfbClient* client, int x, int y, int w, int h, uint32_ case 16: FILL_RECT(16); break; case 32: FILL_RECT(32); break; default: - rfbClientLog("Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel); + rfbClientLog2(client, "Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel); } } @@ -150,7 +150,7 @@ static void CopyRectangle(rfbClient* client, const uint8_t* buffer, int x, int y } if (!CheckRect(client, x, y, w, h)) { - rfbClientLog("Rect out of bounds: %dx%d at (%d, %d)\n", x, y, w, h); + rfbClientLog2(client, "Rect out of bounds: %dx%d at (%d, %d)\n", x, y, w, h); return; } @@ -168,7 +168,7 @@ static void CopyRectangle(rfbClient* client, const uint8_t* buffer, int x, int y case 16: COPY_RECT(16); break; case 32: COPY_RECT(32); break; default: - rfbClientLog("Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel); + rfbClientLog2(client, "Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel); } } @@ -181,12 +181,12 @@ static void CopyRectangleFromRectangle(rfbClient* client, int src_x, int src_y, } if (!CheckRect(client, src_x, src_y, w, h)) { - rfbClientLog("Source rect out of bounds: %dx%d at (%d, %d)\n", src_x, src_y, w, h); + rfbClientLog2(client, "Source rect out of bounds: %dx%d at (%d, %d)\n", src_x, src_y, w, h); return; } if (!CheckRect(client, dest_x, dest_y, w, h)) { - rfbClientLog("Dest rect out of bounds: %dx%d at (%d, %d)\n", dest_x, dest_y, w, h); + rfbClientLog2(client, "Dest rect out of bounds: %dx%d at (%d, %d)\n", dest_x, dest_y, w, h); return; } @@ -225,7 +225,7 @@ static void CopyRectangleFromRectangle(rfbClient* client, int src_x, int src_y, case 16: COPY_RECT_FROM_RECT(16); break; case 32: COPY_RECT_FROM_RECT(32); break; default: - rfbClientLog("Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel); + rfbClientLog2(client, "Unsupported bitsPerPixel: %d\n",client->format.bitsPerPixel); } } @@ -255,12 +255,12 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel, #endif rfbClient* client=(rfbClient*)calloc(sizeof(rfbClient),1); if(!client) { - rfbClientErr("Couldn't allocate client structure!\n"); + rfbClientErr2(client, "Couldn't allocate client structure!\n"); return NULL; } #ifdef WIN32 if((errno = WSAStartup(MAKEWORD(2,0), &unused)) != 0) { - rfbClientErr("Could not init Windows Sockets: %s\n", strerror(errno)); + rfbClientErr2(client, "Could not init Windows Sockets: %s\n", strerror(errno)); return NULL; } #endif @@ -520,14 +520,14 @@ void rfbClientCleanup(rfbClient* client) { if (client->zlibStreamActive[i] == TRUE ) { if (inflateEnd (&client->zlibStream[i]) != Z_OK && client->zlibStream[i].msg != NULL) - rfbClientLog("inflateEnd: %s\n", client->zlibStream[i].msg); + rfbClientLog2(client, "inflateEnd: %s\n", client->zlibStream[i].msg); } } if ( client->decompStreamInited == TRUE ) { if (inflateEnd (&client->decompStream) != Z_OK && client->decompStream.msg != NULL) - rfbClientLog("inflateEnd: %s\n", client->decompStream.msg ); + rfbClientLog2(client, "inflateEnd: %s\n", client->decompStream.msg ); } #ifdef LIBVNCSERVER_HAVE_LIBJPEG @@ -573,7 +573,7 @@ void rfbClientCleanup(rfbClient* client) { #ifdef WIN32 if(WSACleanup() != 0) { errno=WSAGetLastError(); - rfbClientErr("Could not terminate Windows Sockets: %s\n", strerror(errno)); + rfbClientErr2(client, "Could not terminate Windows Sockets: %s\n", strerror(errno)); } #endif diff --git a/src/libvncclient/zlib.c b/src/libvncclient/zlib.c index fc6f1382..cf498e0e 100644 --- a/src/libvncclient/zlib.c +++ b/src/libvncclient/zlib.c @@ -77,7 +77,7 @@ HandleZlibBPP (rfbClient* client, int rx, int ry, int rw, int rh) inflateResult = inflateInit( &client->decompStream ); if ( inflateResult != Z_OK ) { - rfbClientLog( + rfbClientLog2(client, "inflateInit returned error: %d, msg: %s\n", inflateResult, client->decompStream.msg); @@ -115,11 +115,11 @@ HandleZlibBPP (rfbClient* client, int rx, int ry, int rw, int rh) /* We never supply a dictionary for compression. */ if ( inflateResult == Z_NEED_DICT ) { - rfbClientLog("zlib inflate needs a dictionary!\n"); + rfbClientLog2(client, "zlib inflate needs a dictionary!\n"); return FALSE; } if ( inflateResult < 0 ) { - rfbClientLog( + rfbClientLog2(client, "zlib inflate returned error: %d, msg: %s\n", inflateResult, client->decompStream.msg); @@ -131,7 +131,7 @@ HandleZlibBPP (rfbClient* client, int rx, int ry, int rw, int rh) */ if (( client->decompStream.avail_in > 0 ) && ( client->decompStream.avail_out <= 0 )) { - rfbClientLog("zlib inflate ran out of space!\n"); + rfbClientLog2(client, "zlib inflate ran out of space!\n"); return FALSE; } @@ -146,7 +146,7 @@ HandleZlibBPP (rfbClient* client, int rx, int ry, int rw, int rh) } else { - rfbClientLog( + rfbClientLog2(client, "zlib inflate returned error: %d, msg: %s\n", inflateResult, client->decompStream.msg); diff --git a/src/libvncclient/zrle.c b/src/libvncclient/zrle.c index 6859519f..74769142 100644 --- a/src/libvncclient/zrle.c +++ b/src/libvncclient/zrle.c @@ -126,7 +126,7 @@ HandleZRLE (rfbClient* client, int rx, int ry, int rw, int rh) inflateResult = inflateInit( &client->decompStream ); if ( inflateResult != Z_OK ) { - rfbClientLog( + rfbClientLog2(client, "inflateInit returned error: %d, msg: %s\n", inflateResult, client->decompStream.msg); @@ -164,11 +164,11 @@ HandleZRLE (rfbClient* client, int rx, int ry, int rw, int rh) /* We never supply a dictionary for compression. */ if ( inflateResult == Z_NEED_DICT ) { - rfbClientLog("zlib inflate needs a dictionary!\n"); + rfbClientLog2(client, "zlib inflate needs a dictionary!\n"); return FALSE; } if ( inflateResult < 0 ) { - rfbClientLog( + rfbClientLog2(client, "zlib inflate returned error: %d, msg: %s\n", inflateResult, client->decompStream.msg); @@ -180,7 +180,7 @@ HandleZRLE (rfbClient* client, int rx, int ry, int rw, int rh) */ if (( client->decompStream.avail_in > 0 ) && ( client->decompStream.avail_out <= 0 )) { - rfbClientLog("zlib inflate ran out of space!\n"); + rfbClientLog2(client, "zlib inflate ran out of space!\n"); return FALSE; } @@ -201,7 +201,7 @@ HandleZRLE (rfbClient* client, int rx, int ry, int rw, int rh) int result=HandleZRLETile(client,(uint8_t *)buf,remaining,rx+i,ry+j,subWidth,subHeight); if(result<0) { - rfbClientLog("ZRLE decoding failed (%d)\n",result); + rfbClientLog2(client, "ZRLE decoding failed (%d)\n",result); return TRUE; return FALSE; } @@ -212,7 +212,7 @@ return TRUE; } else { - rfbClientLog( + rfbClientLog2(client, "zlib inflate returned error: %d, msg: %s\n", inflateResult, client->decompStream.msg); @@ -270,7 +270,7 @@ static int HandleZRLETile(rfbClient* client, int i,j; if(1+w*h*REALBPP/8>buffer_length) { - rfbClientLog("expected %d bytes, got only %d (%dx%d)\n",1+w*h*REALBPP/8,buffer_length,w,h); + rfbClientLog2(client, "expected %d bytes, got only %d (%dx%d)\n",1+w*h*REALBPP/8,buffer_length,w,h); return -3; } @@ -355,7 +355,7 @@ static int HandleZRLETile(rfbClient* client, } } if(length>0) - rfbClientLog("Warning: possible ZRLE corruption\n"); + rfbClientLog2(client, "Warning: possible ZRLE corruption\n"); } } @@ -407,7 +407,7 @@ static int HandleZRLETile(rfbClient* client, } } if(length>0) - rfbClientLog("Warning: possible ZRLE corruption\n"); + rfbClientLog2(client, "Warning: possible ZRLE corruption\n"); } } } diff --git a/test/encodingstest.c b/test/encodingstest.c index 50cf4695..cbf3c0f0 100644 --- a/test/encodingstest.c +++ b/test/encodingstest.c @@ -127,7 +127,7 @@ static void update(rfbClient* client,int x,int y,int w,int h) { fprintf(stderr,"%c\r",progress[counter]); #else clientData* cd = (clientData*)rfbClientGetClientData(client, clientLoop); - rfbClientLog("Got update (encoding=%s): (%d,%d)-(%d,%d)\n", + rfbClientLog2(client, "Got update (encoding=%s): (%d,%d)-(%d,%d)\n", testEncodings[cd->encodingIndex].str, x,y,x+w,y+h); #endif @@ -157,11 +157,11 @@ static THREAD_ROUTINE_RETURN_TYPE clientLoop(void* data) { client->appData.qualityLevel = 7; /* ZYWRLE fails the test with standard settings */ THREAD_SLEEP_MS(1000); - rfbClientLog("Starting client (encoding %s, display %s)\n", + rfbClientLog2(client, "Starting client (encoding %s, display %s)\n", testEncodings[cd->encodingIndex].str, cd->display); if(!rfbInitClient(client,NULL,NULL)) { - rfbClientErr("Had problems starting client (encoding %s)\n", + rfbClientErr2(client, "Had problems starting client (encoding %s)\n", testEncodings[cd->encodingIndex].str); updateStatistics(cd->encodingIndex,TRUE); free(cd);