Fix the minor style issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2022-10-08 16:31:21 +08:00
committed by Petro Karashchenko
parent 4941182cc6
commit 893387b2c5
112 changed files with 605 additions and 576 deletions

View File

@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
/* Open the redirects file. */
fp = fopen(".redirects", "r");
if (fp == (FILE *) 0)
if (fp == NULL)
{
internal_error("Couldn't open .redirects file.");
errcode = 3;

View File

@@ -99,81 +99,82 @@ static void internal_error(char *reason)
{
char *title = "500 Internal Error";
printf("\
<HTML><HEAD><TITLE>%s</TITLE></HEAD>\n\
<BODY><H2>%s</H2>\n\
Something unusual went wrong during a server-side-includes request:\n\
<BLOCKQUOTE>\n\
%s\n\
</BLOCKQUOTE>\n\
</BODY></HTML>\n", title, title, reason);
printf("<HTML><HEAD><TITLE>%s</TITLE></HEAD>\n"
"<BODY><H2>%s</H2>\n"
"Something unusual went wrong during a server-side-includes request:\n"
"<BLOCKQUOTE>\n"
"%s\n"
"</BLOCKQUOTE>\n"
"</BODY></HTML>\n",
title, title, reason);
}
static void not_found(char *filename)
{
char *title = "404 Not Found";
printf("\
<HTML><HEAD><TITLE>%s</TITLE></HEAD>\n\
<BODY><H2>%s</H2>\n\
The requested server-side-includes filename, %s,\n\
does not seem to exist.\n\
</BODY></HTML>\n", title, title, filename);
printf("<HTML><HEAD><TITLE>%s</TITLE></HEAD>\n"
"<BODY><H2>%s</H2>\n"
"The requested server-side-includes filename, %s,\n"
"does not seem to exist.\n"
"</BODY></HTML>\n",
title, title, filename);
}
static void not_found2(char *directive, char *tag, char *filename)
{
char *title = "Not Found";
printf("\
<HR><H2>%s</H2>\n\
The filename requested in a %s %s directive, %s,\n\
does not seem to exist.\n\
<HR>\n", title, directive, tag, filename);
printf("<HR><H2>%s</H2>\n"
"The filename requested in a %s %s directive, %s,\n"
"does not seem to exist.\n"
"<HR>\n",
title, directive, tag, filename);
}
static void not_permitted(char *directive, char *tag, char *val)
{
char *title = "Not Permitted";
printf("\
<HR><H2>%s</H2>\n\
The filename requested in the %s %s=%s directive\n\
may not be fetched.\n\
<HR>\n", title, directive, tag, val);
printf("<HR><H2>%s</H2>\n"
"The filename requested in the %s %s=%s directive\n"
"may not be fetched.\n"
"<HR>\n",
title, directive, tag, val);
}
static void unknown_directive(char *filename, char *directive)
{
char *title = "Unknown Directive";
printf("\
<HR><H2>%s</H2>\n\
The requested server-side-includes filename, %s,\n\
tried to use an unknown directive, %s.\n\
<HR>\n", title, filename, directive);
printf("<HR><H2>%s</H2>\n"
"The requested server-side-includes filename, %s,\n"
"tried to use an unknown directive, %s.\n"
"<HR>\n",
title, filename, directive);
}
static void unknown_tag(char *filename, char *directive, char *tag)
{
char *title = "Unknown Tag";
printf("\
<HR><H2>%s</H2>\n\
The requested server-side-includes filename, %s,\n\
tried to use the directive %s with an unknown tag, %s.\n\
<HR>\n", title, filename, directive, tag);
printf("<HR><H2>%s</H2>\n"
"The requested server-side-includes filename, %s,\n"
"tried to use the directive %s with an unknown tag, %s.\n"
"<HR>\n",
title, filename, directive, tag);
}
static void unknown_value(char *filename, char *directive, char *tag, char *val)
static void unknown_value(char *filename, char *directive,
char *tag, char *val)
{
char *title = "Unknown Value";
printf("\
<HR><H2>%s</H2>\n\
The requested server-side-includes filename, %s,\n\
tried to use the directive %s %s with an unknown value, %s.\n\
<HR>\n", title, filename, directive, tag, val);
printf("<HR><H2>%s</H2>\n"
"The requested server-side-includes filename, %s,\n"
"tried to use the directive %s %s with an unknown value, %s.\n"
"<HR>\n",
title, filename, directive, tag, val);
}
static int get_filename(char *vfilename, char *filename,
@@ -223,6 +224,7 @@ static int get_filename(char *vfilename, char *filename,
not_permitted(directive, tag, val);
return -1;
}
if (fl + 1 + strlen(val) >= fnsize)
{
return -1;
@@ -235,6 +237,7 @@ static int get_filename(char *vfilename, char *filename,
cp = &fn[strlen(fn)];
*cp = '/';
}
strcpy(++cp, val);
}
else
@@ -242,6 +245,7 @@ static int get_filename(char *vfilename, char *filename,
unknown_tag(filename, directive, tag);
return -1;
}
return 0;
}
@@ -269,12 +273,13 @@ static int check_filename(char *filename)
cgi_pattern = CGI_PATTERN;
}
#endif /* CGI_PATTERN */
inited = 1;
}
/* ../ is not permitted. */
if (strstr(filename, "../") !=NULL)
if (strstr(filename, "../") != NULL)
{
return 0;
}
@@ -285,7 +290,8 @@ static int check_filename(char *filename)
fnl = strlen(filename);
if (strcmp(filename, CONFIG_AUTH_FILE) == 0 ||
(fnl >= sizeof(CONFIG_AUTH_FILE) &&
strcmp(&filename[fnl - sizeof(CONFIG_AUTH_FILE) + 1], CONFIG_AUTH_FILE) == 0 &&
strcmp(&filename[fnl - sizeof(CONFIG_AUTH_FILE) + 1],
CONFIG_AUTH_FILE) == 0 &&
filename[fnl - sizeof(CONFIG_AUTH_FILE)] == '/'))
{
return 0;
@@ -342,6 +348,7 @@ static int check_filename(char *filename)
{
return 0;
}
return 1;
}
@@ -440,7 +447,8 @@ static void do_include(FILE *instream, char *vfilename, char *filename,
/* Inserts the text of another document into the parsed document. */
ret = get_filename(vfilename, filename, directive, tag, val, g_iobuffer1, BUFFER_SIZE);
ret = get_filename(vfilename, filename, directive, tag, val, g_iobuffer1,
BUFFER_SIZE);
if (ret < 0)
{
return;
@@ -453,7 +461,7 @@ static void do_include(FILE *instream, char *vfilename, char *filename,
}
instream2 = fopen(g_iobuffer1, "r");
if (instream2 == (FILE *) 0)
if (instream2 == NULL)
{
not_found2(directive, tag, g_iobuffer1);
return;
@@ -461,7 +469,7 @@ static void do_include(FILE *instream, char *vfilename, char *filename,
if (strcmp(tag, "virtual") == 0)
{
if (strlen(val) <BUFFER_SIZE)
if (strlen(val) < BUFFER_SIZE)
{
strcpy(g_iobuffer2, val);
}
@@ -482,6 +490,7 @@ static void do_include(FILE *instream, char *vfilename, char *filename,
cp = &g_iobuffer2[strlen(g_iobuffer2)];
*cp = '/';
}
strcpy(++cp, val);
}
else
@@ -500,8 +509,9 @@ static void do_echo(FILE *instream, char *vfilename, char *filename,
char *cp;
/* Prints the value of one of the include variables. Any dates are
* printed subject to the currently configured g_timeformat. The only valid
* tag is var, whose value is the name of the variable you wish to echo.
* printed subject to the currently configured g_timeformat. The only
* valid tag is var, whose value is the name of the variable you wish
* to echo.
*/
if (strcmp(tag, "var") != 0)
@@ -585,7 +595,8 @@ static void do_fsize(FILE *instream, char *vfilename, char *filename,
/* Prints the size of the specified file. */
ret = get_filename(vfilename, filename, directive, tag, val, g_iobuffer1, BUFFER_SIZE);
ret = get_filename(vfilename, filename, directive, tag, val, g_iobuffer1,
BUFFER_SIZE);
if (ret < 0)
{
return;
@@ -607,7 +618,8 @@ static void do_flastmod(FILE *instream, char *vfilename, char *filename,
/* Prints the last modification date of the specified file. */
ret = get_filename(vfilename, filename, directive, tag, val, g_iobuffer1, BUFFER_SIZE);
ret = get_filename(vfilename, filename, directive, tag, val, g_iobuffer1,
BUFFER_SIZE);
if (ret < 0)
{
return;
@@ -618,6 +630,7 @@ static void do_flastmod(FILE *instream, char *vfilename, char *filename,
not_found2(directive, tag, g_iobuffer1);
return;
}
show_time(g_sb.st_mtime, 0);
}
@@ -635,7 +648,7 @@ static void parse(FILE *instream, char *vfilename, char *filename, char *str)
ntags = 0;
cp = directive;
for (;;)
for (; ; )
{
cp = strpbrk(cp, " \t\n\r\"");
if (cp == (char *)0)
@@ -718,11 +731,13 @@ static void parse(FILE *instream, char *vfilename, char *filename, char *str)
switch (dirn)
{
case DI_CONFIG:
do_config(instream, vfilename, filename, directive, g_tags[i], val);
do_config(instream, vfilename, filename, directive, g_tags[i],
val);
break;
case DI_INCLUDE:
do_include(instream, vfilename, filename, directive, g_tags[i], val);
do_include(instream, vfilename, filename, directive, g_tags[i],
val);
break;
case DI_ECHO:
@@ -734,7 +749,8 @@ static void parse(FILE *instream, char *vfilename, char *filename, char *str)
break;
case DI_FLASTMOD:
do_flastmod(instream, vfilename, filename, directive, g_tags[i], val);
do_flastmod(instream, vfilename, filename, directive, g_tags[i],
val);
break;
}
}
@@ -915,12 +931,13 @@ int main(int argc, char *argv[])
path_info = "";
}
g_url = (char*)malloc(strlen(script_name) + strlen(path_info) + 1);
g_url = (char *)malloc(strlen(script_name) + strlen(path_info) + 1);
if (!g_url)
{
internal_error("Out of memory.");
return 2;
}
sprintf(g_url, "%s%s", script_name, path_info);
/* Get the name of the file to parse. */