Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions examples/client/SDLvncviewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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 */
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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());
}


Expand All @@ -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: ");
Expand Down
4 changes: 2 additions & 2 deletions examples/client/backchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions examples/client/ppmtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <rfb/rfbclient.h>

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) {
Expand All @@ -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;
}

Expand Down
32 changes: 17 additions & 15 deletions include/rfb/rfbclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -745,56 +747,56 @@ 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
@param port 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 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
@param port 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);
Expand Down
4 changes: 2 additions & 2 deletions src/common/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/common/sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...));


/*
Expand Down
30 changes: 15 additions & 15 deletions src/libvncclient/listen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand All @@ -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
Expand Down Expand Up @@ -109,15 +109,15 @@ 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... */

switch (fork()) {

case -1:
rfbClientErr("fork\n");
rfbClientErr2(client, "fork\n");
return;

case 0:
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand All @@ -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) {
Expand Down
Loading
Loading