Unverified Commit 3b640a0f authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/options_on_reconnect' into 3.6.x

parents 39d45a0e 4ef4fbf1
...@@ -135,7 +135,7 @@ char nxagentShadowDisplayName[1024] = {0}; ...@@ -135,7 +135,7 @@ char nxagentShadowDisplayName[1024] = {0};
char nxagentWindowName[256]; char nxagentWindowName[256];
char nxagentDialogName[256]; char nxagentDialogName[256];
char nxagentSessionId[256] = {0}; char nxagentSessionId[256] = {0};
char *nxagentOptionsFilename; char *nxagentOptionsFilenameOrString;
Bool nxagentFullGeneration = False; Bool nxagentFullGeneration = False;
int nxagentDefaultClass = TrueColor; int nxagentDefaultClass = TrueColor;
...@@ -259,18 +259,18 @@ int ddxProcessArgument(int argc, char *argv[], int i) ...@@ -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 ((!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 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 #ifdef WARNING
else else
...@@ -283,25 +283,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) ...@@ -283,25 +283,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
} }
} }
if (nxagentOptionsFilename) nxagentProcessOptions(nxagentOptionsFilenameOrString);
{
/* 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);
}
}
} }
if (!strcmp(argv[i], "-B")) if (!strcmp(argv[i], "-B"))
...@@ -380,23 +362,19 @@ int ddxProcessArgument(int argc, char *argv[], int i) ...@@ -380,23 +362,19 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{ {
int size; int size;
if (nxagentOptionsFilename != NULL) free(nxagentOptionsFilenameOrString);
{ nxagentOptionsFilenameOrString = NULL;
free(nxagentOptionsFilename);
nxagentOptionsFilename = NULL;
}
if ((size = strlen(argv[i])) < 1024) if ((size = strlen(argv[i])) < 1024)
{ {
if ((nxagentOptionsFilename = malloc(size + 1)) == NULL) if ((nxagentOptionsFilenameOrString = malloc(size + 1)) == NULL)
{ {
FatalError("malloc failed"); FatalError("malloc failed");
} }
strncpy(nxagentOptionsFilename, argv[i], size); strncpy(nxagentOptionsFilenameOrString, argv[i], size);
nxagentOptionsFilename[size] = '\0'; nxagentOptionsFilenameOrString[size] = '\0';
} }
else else
{ {
...@@ -1584,10 +1562,38 @@ static void nxagentParseOptionString(char *string) ...@@ -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) void nxagentProcessOptionsFile(char * filename)
{ {
FILE *file; FILE *file = NULL;
char *data; char *data = NULL;
int offset; int offset;
int size; int size;
...@@ -1597,7 +1603,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1597,7 +1603,7 @@ void nxagentProcessOptionsFile(char * filename)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentProcessOptionsFile: Going to process option file [%s].\n", fprintf(stderr, "nxagentProcessOptionsFile: Going to process option file [%s].\n",
validateString(filename); validateString(filename));
#endif #endif
/* /*
...@@ -1623,7 +1629,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1623,7 +1629,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Couldn't position inside option file '%s'. Error is '%s'.\n", fprintf(stderr, "Warning: Couldn't position inside option file '%s'. Error is '%s'.\n",
validateString(filename), strerror(errno)); validateString(filename), strerror(errno));
goto nxagentProcessOptionsFileClose; goto nxagentProcessOptionsFileExit;
} }
if ((sizeOfFile = ftell(file)) == -1) if ((sizeOfFile = ftell(file)) == -1)
...@@ -1631,7 +1637,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1631,7 +1637,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Couldn't get the size of option file '%s'. Error is '%s'.\n", fprintf(stderr, "Warning: Couldn't get the size of option file '%s'. Error is '%s'.\n",
validateString(filename), strerror(errno)); validateString(filename), strerror(errno));
goto nxagentProcessOptionsFileClose; goto nxagentProcessOptionsFileExit;
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -1646,7 +1652,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1646,7 +1652,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Maximum file size exceeded for options '%s'.\n", fprintf(stderr, "Warning: Maximum file size exceeded for options '%s'.\n",
validateString(filename)); validateString(filename));
goto nxagentProcessOptionsFileClose; goto nxagentProcessOptionsFileExit;
} }
if ((data = malloc(sizeOfFile + 1)) == NULL) if ((data = malloc(sizeOfFile + 1)) == NULL)
...@@ -1654,7 +1660,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1654,7 +1660,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Memory allocation failed processing file '%s'.\n", fprintf(stderr, "Warning: Memory allocation failed processing file '%s'.\n",
validateString(filename)); validateString(filename));
goto nxagentProcessOptionsFileClose; goto nxagentProcessOptionsFileExit;
} }
offset = 0; offset = 0;
...@@ -1669,7 +1675,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1669,7 +1675,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Error reading the option file '%s'.\n", fprintf(stderr, "Warning: Error reading the option file '%s'.\n",
validateString(filename)); validateString(filename));
goto nxagentProcessOptionsFileFree; goto nxagentProcessOptionsFileExit;
} }
size += result; size += result;
...@@ -1686,7 +1692,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1686,7 +1692,7 @@ void nxagentProcessOptionsFile(char * filename)
fprintf(stderr, "Warning: Premature end of option file '%s' while reading.\n", fprintf(stderr, "Warning: Premature end of option file '%s' while reading.\n",
validateString(filename)); validateString(filename));
goto nxagentProcessOptionsFileFree; goto nxagentProcessOptionsFileExit;
} }
/* /*
...@@ -1699,22 +1705,18 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1699,22 +1705,18 @@ void nxagentProcessOptionsFile(char * filename)
nxagentParseOptionString(data); nxagentParseOptionString(data);
nxagentProcessOptionsFileFree: nxagentProcessOptionsFileExit:
if (data != NULL)
{
free(data); free(data);
}
nxagentProcessOptionsFileClose:
if (file)
{
if (fclose(file) != 0) if (fclose(file) != 0)
{ {
fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n", fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n",
validateString(filename), strerror(errno)); validateString(filename), strerror(errno));
} }
}
nxagentProcessOptionsFileExit:
return; return;
} }
......
...@@ -81,6 +81,7 @@ extern Bool nxagentIpaq; ...@@ -81,6 +81,7 @@ extern Bool nxagentIpaq;
extern int nxagentLockDeferLevel; extern int nxagentLockDeferLevel;
Bool nxagentPostProcessArgs(char *name, Display *dpy, Screen *scr); Bool nxagentPostProcessArgs(char *name, Display *dpy, Screen *scr);
void nxagentProcessOptions(char * string);
void nxagentProcessOptionsFile(char * filename); void nxagentProcessOptionsFile(char * filename);
void nxagentSetPackMethod(void); void nxagentSetPackMethod(void);
......
...@@ -103,7 +103,7 @@ extern Bool nxagentRenderEnable; ...@@ -103,7 +103,7 @@ extern Bool nxagentRenderEnable;
extern char *nxagentKeyboard; extern char *nxagentKeyboard;
extern char *nxagentOptionsFilename; extern char *nxagentOptionsFilenameOrString;
enum SESSION_STATE nxagentSessionState = SESSION_STARTING; enum SESSION_STATE nxagentSessionState = SESSION_STARTING;
...@@ -456,7 +456,7 @@ Bool nxagentReconnectSession(void) ...@@ -456,7 +456,7 @@ Bool nxagentReconnectSession(void)
nxagentResetOptions(); nxagentResetOptions();
nxagentProcessOptionsFile(nxagentOptionsFilename); nxagentProcessOptions(nxagentOptionsFilenameOrString);
if (nxagentReconnectDisplay(reconnectLossyLevel[DISPLAY_STEP]) == 0) if (nxagentReconnectDisplay(reconnectLossyLevel[DISPLAY_STEP]) == 0)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment