libvncserver icon indicating copy to clipboard operation
libvncserver copied to clipboard

Adds lastError to rfbClientRec, adds 'error changed' callback

Open nicmorais opened this issue 1 year ago • 3 comments

As requested in https://github.com/LibVNC/libvncserver/issues/577 (Work in progress)

New rfbClientSetErr() function is only being called in auth.c, when simple password authentication fails.

Calling rfbErr() and rfbClientSetErr() in sequence with the same parameters does not feel good... Not sure what would be the best solution.

Also, do we need some mutex logic when changing cl->lastError?

nicmorais avatar May 12 '24 13:05 nicmorais

How to use it (based on examples/server/simple.c):

#include <rfb/rfb.h>

void clientErrorHandler(rfbClientPtr r) {
    printf("[ERROR] %s\n", r->lastError);
}

int main(int argc,char** argv)
{                                                                
  rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4);
  if(!server)
    return 1;
  server->clientErrorChanged = clientErrorHandler;
  server->frameBuffer=(char*)malloc(400*300*4);
  rfbInitServer(server);           
  rfbRunEventLoop(server,-1,FALSE);
  return(0);
}

Run this server: ./mytestserver -passwd 12345678

And start any VNC client of your preference, but input a wrong password.

nicmorais avatar May 12 '24 13:05 nicmorais

return is a statement, not a function. Therefore the returned value does not need (…) around it. ;-)

RokerHRO avatar May 12 '24 19:05 RokerHRO

@RokerHRO true! I just copied from simple.c and did not notice it ¯_ (ツ)_/¯

nicmorais avatar May 12 '24 19:05 nicmorais