allow using local config file for server

This commit is contained in:
lxsang 2018-09-23 14:09:43 +02:00
parent 32e2de083b
commit e05f22063d

47
wvnc.c
View File

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <rfb/rfbclient.h>
#include <pthread.h>
#ifdef USE_ZLIB
@ -422,24 +423,64 @@ static char *get_password(rfbClient *client)
void open_session(void *data, const char *addr)
{
// main loop
int argc = 2;
char *argv[2];
argv[0] = "-listennofork";
argv[1] = (char *)addr;
int len = 0;
FILE *fp = NULL;
char *buffer = NULL;
char c;
wvnc_user_data_t *user_data = get_user_data(data);
if (access(addr, F_OK) != -1)
{
//open the file
fp = fopen(addr, "r");
if (fp == NULL)
{
vnc_fatal(data, "Unable to read server file");
return;
}
// find length of first line
// lines end in "\n", but some malformed text files may not have this char at all
// and whole file contents will be considered as the first line
while ((c = fgetc(fp)) != EOF)
{
if (c == '\n')
{
break;
}
len++;
}
// allocate memory for size of first line (len)
buffer = (char *)malloc(sizeof(char) * len);
// seek to beginning of file
fseek(fp, 0, SEEK_SET);
fread(buffer, sizeof(char), len, fp);
fclose(fp);
argv[1] = buffer;
}
else
{
argv[1] = (char *)addr;
}
LOG("client.BBP: %d\n", user_data->bbp);
LOG("client.flag: %d\n", user_data->flag);
LOG("client.JPEG.quality: %d\n", user_data->quality);
LOG("Server: %s\n", addr);
LOG("Server: %s\n", argv[1]);
//LOG("Rate is %d\n", user_data->rate);
if (!rfbInitClient(user_data->vncl, &argc, argv))
{
user_data->vncl = NULL; /* rfbInitClient has already freed the client struct */
//cleanup(vncl);
vnc_fatal(user_data, "Cannot connect to the server");
if(buffer) free(buffer);
return;
}
if(buffer) free(buffer);
while (1)
{
if (!user_data->status)