Skip to content

Commit

Permalink
Merge branch 'uli42-pr/options_on_reconnect' into 3.6.x
Browse files Browse the repository at this point in the history
Attributes GH PR #554: #554
  • Loading branch information
sunweaver committed Nov 20, 2017
2 parents 39d45a0 + 4ef4fbf commit 3b640a0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 57 deletions.
112 changes: 57 additions & 55 deletions nx-X11/programs/Xserver/hw/nxagent/Args.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ char nxagentShadowDisplayName[1024] = {0};
char nxagentWindowName[256];
char nxagentDialogName[256];
char nxagentSessionId[256] = {0};
char *nxagentOptionsFilename;
char *nxagentOptionsFilenameOrString;

Bool nxagentFullGeneration = False;
int nxagentDefaultClass = TrueColor;
Expand Down Expand Up @@ -259,18 +259,18 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{
if ((!strcmp(argv[j], "-options") || !strcmp(argv[j], "-option")) && j + 1 < argc)
{
if (nxagentOptionsFilename)
if (nxagentOptionsFilenameOrString)
{
nxagentOptionsFilename = (char *) realloc(nxagentOptionsFilename, strlen(argv[j + 1]) + 1);
nxagentOptionsFilenameOrString = (char *) realloc(nxagentOptionsFilenameOrString, strlen(argv[j + 1]) + 1);
}
else
{
nxagentOptionsFilename = (char *) malloc(strlen(argv[j + 1]) +1);
nxagentOptionsFilenameOrString = (char *) malloc(strlen(argv[j + 1]) +1);
}

if (nxagentOptionsFilename != NULL)
if (nxagentOptionsFilenameOrString != NULL)
{
nxagentOptionsFilename = strcpy(nxagentOptionsFilename, argv[j + 1]);
nxagentOptionsFilenameOrString = strcpy(nxagentOptionsFilenameOrString, argv[j + 1]);
}
#ifdef WARNING
else
Expand All @@ -283,25 +283,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
}
}

if (nxagentOptionsFilename)
{
/* if the "filename" starts with an nx marker treat it
as an option _string_ instead of a filename */
if (strncasecmp(nxagentOptionsFilename, "nx/nx,", 6) == 0 ||
strncasecmp(nxagentOptionsFilename, "nx/nx:", 6) == 0)
{
nxagentParseOptionString(nxagentOptionsFilename + 6);
}
else if (strncasecmp(nxagentOptionsFilename, "nx,", 3) == 0 ||
strncasecmp(nxagentOptionsFilename, "nx:", 3) == 0)
{
nxagentParseOptionString(nxagentOptionsFilename + 3);
}
else
{
nxagentProcessOptionsFile(nxagentOptionsFilename);
}
}
nxagentProcessOptions(nxagentOptionsFilenameOrString);
}

if (!strcmp(argv[i], "-B"))
Expand Down Expand Up @@ -380,23 +362,19 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{
int size;

if (nxagentOptionsFilename != NULL)
{
free(nxagentOptionsFilename);

nxagentOptionsFilename = NULL;
}
free(nxagentOptionsFilenameOrString);
nxagentOptionsFilenameOrString = NULL;

if ((size = strlen(argv[i])) < 1024)
{
if ((nxagentOptionsFilename = malloc(size + 1)) == NULL)
if ((nxagentOptionsFilenameOrString = malloc(size + 1)) == NULL)
{
FatalError("malloc failed");
}

strncpy(nxagentOptionsFilename, argv[i], size);
strncpy(nxagentOptionsFilenameOrString, argv[i], size);

nxagentOptionsFilename[size] = '\0';
nxagentOptionsFilenameOrString[size] = '\0';
}
else
{
Expand Down Expand Up @@ -1584,10 +1562,38 @@ static void nxagentParseOptionString(char *string)
}
}

void nxagentProcessOptions(char * string)
{
if (!string)
return;

#ifdef DEBUG
fprintf(stderr, "%s: Going to process option string/filename [%s].\n",
__func__, validateString(string));
#endif

/* if the "filename" starts with an nx marker treat it
as an option _string_ instead of a filename */
if (strncasecmp(string, "nx/nx,", 6) == 0 ||
strncasecmp(string, "nx/nx:", 6) == 0)
{
nxagentParseOptionString(string + 6);
}
else if (strncasecmp(string, "nx,", 3) == 0 ||
strncasecmp(string, "nx:", 3) == 0)
{
nxagentParseOptionString(string + 3);
}
else
{
nxagentProcessOptionsFile(string);
}
}

void nxagentProcessOptionsFile(char * filename)
{
FILE *file;
char *data;
FILE *file = NULL;
char *data = NULL;

int offset;
int size;
Expand All @@ -1597,7 +1603,7 @@ void nxagentProcessOptionsFile(char * filename)

#ifdef DEBUG
fprintf(stderr, "nxagentProcessOptionsFile: Going to process option file [%s].\n",
validateString(filename);
validateString(filename));
#endif

/*
Expand All @@ -1623,15 +1629,15 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Couldn't position inside option file '%s'. Error is '%s'.\n",
validateString(filename), strerror(errno));

goto nxagentProcessOptionsFileClose;
goto nxagentProcessOptionsFileExit;
}

if ((sizeOfFile = ftell(file)) == -1)
{
fprintf(stderr, "Warning: Couldn't get the size of option file '%s'. Error is '%s'.\n",
validateString(filename), strerror(errno));

goto nxagentProcessOptionsFileClose;
goto nxagentProcessOptionsFileExit;
}

#ifdef DEBUG
Expand All @@ -1646,15 +1652,15 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Maximum file size exceeded for options '%s'.\n",
validateString(filename));

goto nxagentProcessOptionsFileClose;
goto nxagentProcessOptionsFileExit;
}

if ((data = malloc(sizeOfFile + 1)) == NULL)
{
fprintf(stderr, "Warning: Memory allocation failed processing file '%s'.\n",
validateString(filename));

goto nxagentProcessOptionsFileClose;
goto nxagentProcessOptionsFileExit;
}

offset = 0;
Expand All @@ -1669,7 +1675,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Error reading the option file '%s'.\n",
validateString(filename));

goto nxagentProcessOptionsFileFree;
goto nxagentProcessOptionsFileExit;
}

size += result;
Expand All @@ -1686,7 +1692,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Premature end of option file '%s' while reading.\n",
validateString(filename));

goto nxagentProcessOptionsFileFree;
goto nxagentProcessOptionsFileExit;
}

/*
Expand All @@ -1699,23 +1705,19 @@ void nxagentProcessOptionsFile(char * filename)

nxagentParseOptionString(data);

nxagentProcessOptionsFileFree:

if (data != NULL)
{
free(data);
}
nxagentProcessOptionsFileExit:

nxagentProcessOptionsFileClose:
free(data);

if (fclose(file) != 0)
if (file)
{
fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n",
validateString(filename), strerror(errno));
if (fclose(file) != 0)
{
fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n",
validateString(filename), strerror(errno));
}
}

nxagentProcessOptionsFileExit:

return;
}

Expand Down
1 change: 1 addition & 0 deletions nx-X11/programs/Xserver/hw/nxagent/Args.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ extern Bool nxagentIpaq;
extern int nxagentLockDeferLevel;

Bool nxagentPostProcessArgs(char *name, Display *dpy, Screen *scr);
void nxagentProcessOptions(char * string);
void nxagentProcessOptionsFile(char * filename);

void nxagentSetPackMethod(void);
Expand Down
4 changes: 2 additions & 2 deletions nx-X11/programs/Xserver/hw/nxagent/Reconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extern Bool nxagentRenderEnable;

extern char *nxagentKeyboard;

extern char *nxagentOptionsFilename;
extern char *nxagentOptionsFilenameOrString;

enum SESSION_STATE nxagentSessionState = SESSION_STARTING;

Expand Down Expand Up @@ -456,7 +456,7 @@ Bool nxagentReconnectSession(void)

nxagentResetOptions();

nxagentProcessOptionsFile(nxagentOptionsFilename);
nxagentProcessOptions(nxagentOptionsFilenameOrString);

if (nxagentReconnectDisplay(reconnectLossyLevel[DISPLAY_STEP]) == 0)
{
Expand Down

0 comments on commit 3b640a0

Please sign in to comment.