Add hooks to client library to ontain network and authentication status

pull/1/head
Timothy Pearson 10 years ago
parent 0ca63a7ab6
commit 1d8b3c0548

@ -431,6 +431,8 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
/* serverHost is a hostname */ /* serverHost is a hostname */
if (!StringToIPAddr(hostname, &host)) { if (!StringToIPAddr(hostname, &host)) {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkNameResolutionFailed);
rfbClientLog("Couldn't convert '%s' to host address\n", hostname); rfbClientLog("Couldn't convert '%s' to host address\n", hostname);
return FALSE; return FALSE;
} }
@ -439,6 +441,8 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
} }
if (client->sock < 0) { if (client->sock < 0) {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkConnectionFailed);
rfbClientLog("Unable to connect to VNC server\n"); rfbClientLog("Unable to connect to VNC server\n");
return FALSE; return FALSE;
} }
@ -513,6 +517,9 @@ rfbHandleAuthResult(rfbClient* client)
authResult = rfbClientSwap32IfLE(authResult); authResult = rfbClientSwap32IfLE(authResult);
if (client->AuthenticationResults)
client->AuthenticationResults(client, authResult);
switch (authResult) { switch (authResult) {
case rfbVncAuthOK: case rfbVncAuthOK:
rfbClientLog("VNC authentication succeeded\n"); rfbClientLog("VNC authentication succeeded\n");
@ -643,13 +650,19 @@ HandleVncAuth(rfbClient *client)
char *passwd=NULL; char *passwd=NULL;
int i; int i;
if (!ReadFromRFBServer(client, (char *)challenge, CHALLENGESIZE)) return FALSE; if (!ReadFromRFBServer(client, (char *)challenge, CHALLENGESIZE)) {
if (client->AuthenticationResults)
client->AuthenticationResults(client, rfbVncAuthFailed);
return FALSE;
}
if (client->serverPort!=-1) { /* if not playing a vncrec file */ if (client->serverPort!=-1) { /* if not playing a vncrec file */
if (client->GetPassword) if (client->GetPassword)
passwd = client->GetPassword(client); passwd = client->GetPassword(client);
if ((!passwd) || (strlen(passwd) == 0)) { if ((!passwd) || (strlen(passwd) == 0)) {
if (client->AuthenticationResults)
client->AuthenticationResults(client, rfbVncAuthFailed);
rfbClientLog("Reading password failed\n"); rfbClientLog("Reading password failed\n");
return FALSE; return FALSE;
} }
@ -665,7 +678,11 @@ HandleVncAuth(rfbClient *client)
} }
free(passwd); free(passwd);
if (!WriteToRFBServer(client, (char *)challenge, CHALLENGESIZE)) return FALSE; if (!WriteToRFBServer(client, (char *)challenge, CHALLENGESIZE)) {
if (client->AuthenticationResults)
client->AuthenticationResults(client, rfbVncAuthFailed);
return FALSE;
}
} }
/* Handle the SecurityResult message */ /* Handle the SecurityResult message */
@ -1080,7 +1097,11 @@ InitialiseRFBConnection(rfbClient* client)
if (client->listenSpecified) if (client->listenSpecified)
errorMessageOnReadFailure = FALSE; errorMessageOnReadFailure = FALSE;
if (!ReadFromRFBServer(client, pv, sz_rfbProtocolVersionMsg)) return FALSE; if (!ReadFromRFBServer(client, pv, sz_rfbProtocolVersionMsg)) {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkRFBServerNotValid);
return FALSE;
}
pv[sz_rfbProtocolVersionMsg]=0; pv[sz_rfbProtocolVersionMsg]=0;
errorMessageOnReadFailure = TRUE; errorMessageOnReadFailure = TRUE;
@ -1088,6 +1109,8 @@ InitialiseRFBConnection(rfbClient* client)
pv[sz_rfbProtocolVersionMsg] = 0; pv[sz_rfbProtocolVersionMsg] = 0;
if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2) { if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2) {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkRFBServerNotValid);
rfbClientLog("Not a valid VNC server (%s)\n",pv); rfbClientLog("Not a valid VNC server (%s)\n",pv);
return FALSE; return FALSE;
} }
@ -1133,17 +1156,29 @@ InitialiseRFBConnection(rfbClient* client)
sprintf(pv,rfbProtocolVersionFormat,client->major,client->minor); sprintf(pv,rfbProtocolVersionFormat,client->major,client->minor);
if (!WriteToRFBServer(client, pv, sz_rfbProtocolVersionMsg)) return FALSE; if (!WriteToRFBServer(client, pv, sz_rfbProtocolVersionMsg)) {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkRFBProtocolFailure);
return FALSE;
}
/* 3.7 and onwards sends a # of security types first */ /* 3.7 and onwards sends a # of security types first */
if (client->major==3 && client->minor > 6) if (client->major==3 && client->minor > 6)
{ {
if (!ReadSupportedSecurityType(client, &authScheme, FALSE)) return FALSE; if (!ReadSupportedSecurityType(client, &authScheme, FALSE)) {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkRFBProtocolFailure);
return FALSE;
}
} }
else else
{ {
if (!ReadFromRFBServer(client, (char *)&authScheme, 4)) return FALSE; if (!ReadFromRFBServer(client, (char *)&authScheme, 4)) {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkRFBProtocolFailure);
return FALSE;
}
authScheme = rfbClientSwap32IfLE(authScheme); authScheme = rfbClientSwap32IfLE(authScheme);
} }

@ -173,6 +173,8 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
return FALSE; return FALSE;
} }
} else { } else {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkConnectionClosed);
if (errorMessageOnReadFailure) { if (errorMessageOnReadFailure) {
rfbClientLog("VNC server closed connection\n"); rfbClientLog("VNC server closed connection\n");
} }
@ -212,6 +214,8 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n)
return FALSE; return FALSE;
} }
} else { } else {
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkConnectionClosed);
if (errorMessageOnReadFailure) { if (errorMessageOnReadFailure) {
rfbClientLog("VNC server closed connection\n"); rfbClientLog("VNC server closed connection\n");
} }

@ -250,11 +250,17 @@ static rfbBool rfbInitConnection(rfbClient* client)
} }
} }
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkConnectionSuccess);
/* Initialise the VNC connection, including reading the password */ /* Initialise the VNC connection, including reading the password */
if (!InitialiseRFBConnection(client)) if (!InitialiseRFBConnection(client))
return FALSE; return FALSE;
if (client->NetworkStatus)
client->NetworkStatus(client, rfbNetworkRFBConnectionSuccess);
client->width=client->si.framebufferWidth; client->width=client->si.framebufferWidth;
client->height=client->si.framebufferHeight; client->height=client->si.framebufferHeight;
if (!client->MallocFrameBuffer(client)) if (!client->MallocFrameBuffer(client))

@ -169,6 +169,8 @@ typedef void (*SoftCursorUnlockScreenProc)(struct _rfbClient* client);
typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h); typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h);
typedef void (*FinishedFrameBufferUpdateProc)(struct _rfbClient* client); typedef void (*FinishedFrameBufferUpdateProc)(struct _rfbClient* client);
typedef char* (*GetPasswordProc)(struct _rfbClient* client); typedef char* (*GetPasswordProc)(struct _rfbClient* client);
typedef void (*AuthenticationResultsProc)(struct _rfbClient* client, uint32_t authResult);
typedef void (*NetworkStatusProc)(struct _rfbClient* client, uint32_t errorCode);
typedef rfbCredential* (*GetCredentialProc)(struct _rfbClient* client, int credentialType); typedef rfbCredential* (*GetCredentialProc)(struct _rfbClient* client, int credentialType);
typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client); typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client);
typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen); typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen);
@ -292,6 +294,8 @@ typedef struct _rfbClient {
GotFrameBufferUpdateProc GotFrameBufferUpdate; GotFrameBufferUpdateProc GotFrameBufferUpdate;
/** the pointer returned by GetPassword will be freed after use! */ /** the pointer returned by GetPassword will be freed after use! */
GetPasswordProc GetPassword; GetPasswordProc GetPassword;
AuthenticationResultsProc AuthenticationResults;
NetworkStatusProc NetworkStatus;
MallocFrameBufferProc MallocFrameBuffer; MallocFrameBufferProc MallocFrameBuffer;
GotXCutTextProc GotXCutText; GotXCutTextProc GotXCutText;
BellProc Bell; BellProc Bell;

@ -126,6 +126,14 @@ typedef uint32_t in_addr_t;
#define MAX_ENCODINGS 21 #define MAX_ENCODINGS 21
#define rfbNetworkConnectionSuccess 0
#define rfbNetworkRFBConnectionSuccess 1
#define rfbNetworkConnectionClosed 2
#define rfbNetworkConnectionFailed 3
#define rfbNetworkNameResolutionFailed 4
#define rfbNetworkRFBServerNotValid 5
#define rfbNetworkRFBProtocolFailure 6
/***************************************************************************** /*****************************************************************************
* *
* Structures used in several messages * Structures used in several messages

Loading…
Cancel
Save