Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/decode options #725

Merged
merged 2 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 49 additions & 14 deletions nx-X11/programs/Xserver/hw/nxagent/Args.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,17 +1037,52 @@ int ddxProcessArgument(int argc, char *argv[], int i)
return 0;
}

static void nxagentParseOptions(char *name, char *value)
/* copy from nxcomp's Loop.cpp */
static int
hexval(char c) {
if ((c >= '0') && (c <= '9'))
return c - '0';
if ((c >= 'a') && (c <= 'f'))
return c - 'a' + 10;
if ((c >= 'A') && (c <= 'F'))
return c - 'A' + 10;
return -1;
}

static void
URLDecodeInPlace(char *str)
{
if (str) {
char *to = str;
while (str[0])
{
if ((str[0] == '%') &&
(hexval(str[1]) >= 0) &&
(hexval(str[2]) >= 0))
{
*(to++) = hexval(str[1]) * 16 + hexval(str[2]);
str += 3;
}
else
*(to++) = *(str++);
}
*to = '\0';
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why copy of code here? We should rather use the version found in nxcomp, shouldn't we?

static void nxagentParseSingleOption(char *name, char *value)
{
int size, argc;

char *argv[2] = { NULL, NULL };

#ifdef TEST
fprintf(stderr, "nxagentParseOptions: Processing option '%s' = '%s'.\n",
fprintf(stderr, "nxagentParseSingleOption: Processing option '%s' = '%s'.\n",
validateString(name), validateString(value));
#endif

URLDecodeInPlace(value);

if (!strcmp(name, "kbtype") ||
!strcmp(name, "keyboard") ||
!strcmp(name, "id") ||
Expand Down Expand Up @@ -1081,7 +1116,7 @@ static void nxagentParseOptions(char *name, char *value)
if (nxagentReconnectTrap == True)
{
#ifdef DEBUG
fprintf(stderr, "nxagentParseOptions: Ignoring option 'render' at reconnection.\n");
fprintf(stderr, "nxagentParseSingleOption: Ignoring option 'render' at reconnection.\n");
#endif
}
else if (nxagentRenderEnable == UNDEFINED)
Expand Down Expand Up @@ -1113,7 +1148,7 @@ static void nxagentParseOptions(char *name, char *value)
if (nxagentReconnectTrap == True)
{
#ifdef DEBUG
fprintf(stderr, "nxagentParseOptions: Ignoring option 'fullscreen' at reconnection.\n");
fprintf(stderr, "nxagentParseSingleOption: Ignoring option 'fullscreen' at reconnection.\n");
#endif
}
else if (!strcmp(value, "1"))
Expand Down Expand Up @@ -1283,7 +1318,7 @@ static void nxagentParseOptions(char *name, char *value)
if (nxagentReconnectTrap == True)
{
#ifdef DEBUG
fprintf(stderr, "nxagentParseOptions: Ignoring option 'autodpi' at reconnection.\n");
fprintf(stderr, "nxagentParseSingleOption: Ignoring option 'autodpi' at reconnection.\n");
#endif
}
else if (!strcmp(value, "0"))
Expand Down Expand Up @@ -1368,7 +1403,7 @@ static void nxagentParseOptions(char *name, char *value)

if ((errno) && (0 == sleep_parse))
{
fprintf(stderr, "nxagentParseOptions: Unable to convert value [%s] of option [%s]. "
fprintf(stderr, "nxagentParseSingleOption: Unable to convert value [%s] of option [%s]. "
"Ignoring option.\n",
validateString(value), validateString(name));

Expand All @@ -1379,7 +1414,7 @@ static void nxagentParseOptions(char *name, char *value)
{
sleep_parse = UINT_MAX;

fprintf(stderr, "nxagentParseOptions: Warning: value [%s] of option [%s] "
fprintf(stderr, "nxagentParseSingleOption: Warning: value [%s] of option [%s] "
"out of range, clamped to [%lu].\n",
validateString(value), validateString(name), sleep_parse);
}
Expand All @@ -1388,7 +1423,7 @@ static void nxagentParseOptions(char *name, char *value)
{
sleep_parse = 0;

fprintf(stderr, "nxagentParseOptions: Warning: value [%s] of option [%s] "
fprintf(stderr, "nxagentParseSingleOption: Warning: value [%s] of option [%s] "
"out of range, clamped to [%lu].\n",
validateString(value), validateString(name), sleep_parse);
}
Expand Down Expand Up @@ -1427,7 +1462,7 @@ static void nxagentParseOptions(char *name, char *value)

if ((errno) && (0 == tolerance_parse))
{
fprintf(stderr, "nxagentParseOptions: Unable to convert value [%s] of option [%s]. "
fprintf(stderr, "nxagentParseSingleOption: Unable to convert value [%s] of option [%s]. "
"Ignoring option.\n",
validateString(value), validateString(name));

Expand All @@ -1438,7 +1473,7 @@ static void nxagentParseOptions(char *name, char *value)
{
tolerance_parse = UINT_MAX;

fprintf(stderr, "nxagentParseOptions: Warning: value [%s] of option [%s] "
fprintf(stderr, "nxagentParseSingleOption: Warning: value [%s] of option [%s] "
"out of range, clamped to [%lu].\n",
validateString(value), validateString(name), tolerance_parse);
}
Expand All @@ -1447,7 +1482,7 @@ static void nxagentParseOptions(char *name, char *value)
{
tolerance_parse = 0;

fprintf(stderr, "nxagentParseOptions: Warning: value [%s] of option [%s] "
fprintf(stderr, "nxagentParseSingleOption: Warning: value [%s] of option [%s] "
"out of range, clamped to [%lu].\n",
validateString(value), validateString(name), tolerance_parse);
}
Expand All @@ -1460,7 +1495,7 @@ static void nxagentParseOptions(char *name, char *value)
case ToleranceChecksBypass:
break;
default:
fprintf(stderr, "nxagentParseOptions: Warning: value [%s] of "
fprintf(stderr, "nxagentParseSingleOption: Warning: value [%s] of "
"option [%s] unknown, will be mapped to "
"\"Bypass\" [%u] value internally.\n",
validateString(value), validateString(name),
Expand Down Expand Up @@ -1495,7 +1530,7 @@ static void nxagentParseOptions(char *name, char *value)
else
{
#ifdef DEBUG
fprintf(stderr, "nxagentParseOptions: Ignored option [%s] with value [%s].\n",
fprintf(stderr, "nxagentParseSingleOption: Ignored option [%s] with value [%s].\n",
validateString(name), validateString(value));
#endif

Expand Down Expand Up @@ -1563,7 +1598,7 @@ static void nxagentParseOptionString(char *string)
value = NULL;
}

nxagentParseOptions(option, value);
nxagentParseSingleOption(option, value);
}
}

Expand Down
5 changes: 5 additions & 0 deletions nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ As <proxy-port> you can pick an arbitrary (unused) TCP port or Unix
socket file path. This is the port / socket that you have to connect to
with the \fBnxproxy\fR application.
.PP
The right hand side of an option (the part following the "=" character)
can include URL encoded characters. It is required to URL encode at
least "," (as %2D) and "=" (as %3D) to avoid wrong parsing of the
options string.
.PP
Available \fBnxagent\fR options (as an addition to nx/nx options supported
by nxcomp already):
.TP 8
Expand Down