Skip to content

Commit

Permalink
Added support for MapServer#6968 and associated test.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdlime committed Feb 23, 2024
1 parent a00eda5 commit 828776c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 39 deletions.
3 changes: 3 additions & 0 deletions etc/mapserver-sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ CONFIG
#
# see https://mapserver.org/mapfile/web.html#EMPTY
# MS_EMPTY_URL "https://mapserver.org/"
#
# see https://mapserver.org/mapfile/web.html#ERROR
# MS_ERROR_URL "https://mapserver.org/"

#
# Default Map
Expand Down
6 changes: 6 additions & 0 deletions msautotest/config/6968.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CONFIG
ENV
MS_MAP_PATTERN "."
MS_ERROR_URL "http://localhost/6968.html"
END
END
6 changes: 6 additions & 0 deletions msautotest/config/6968.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Test 1: malformed mapfile
# RUN_PARMS: 6968_test001.txt [MAPSERV] QUERY_STRING='map=[MAPFILE]&mode=map' > [RESULT]
#
# Test 2: mapformed mapfile, MS_ERROR_URL in config
# RUN_PARMS: 6968_test002.txt [MAPSERV] -conf 6968.conf QUERY_STRING='map=[MAPFILE]&mode=MAP' > [RESULT]
BADTOKEN
7 changes: 7 additions & 0 deletions msautotest/config/expected/6968_test001.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Content-Type: text/html

<HTML>
<HEAD><TITLE>MapServer Message</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
msLoadMap(): Unknown identifier. First token must be MAP, this doesn&#39;t look like a mapfile.
</BODY></HTML>
5 changes: 5 additions & 0 deletions msautotest/config/expected/6968_test002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Status: 302 Found
Uri: http://localhost/6968.html
Location: http://localhost/6968.html
Content-Type: text/html

65 changes: 28 additions & 37 deletions src/mapservutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,43 +79,8 @@ void msCGIWriteError(mapservObj *mapserv) {
}

if (!mapserv || !mapserv->map) {
msIO_setHeader("Content-Type", "text/html");
msIO_sendHeaders();
msIO_printf("<HTML>\n");
msIO_printf("<HEAD><TITLE>MapServer Message</TITLE></HEAD>\n");
msIO_printf("<BODY BGCOLOR=\"#FFFFFF\">\n");
msWriteErrorXML(stdout);
msIO_printf("</BODY></HTML>");
return;
}

if ((ms_error->code == MS_NOTFOUND) &&
(mapserv->map->web.empty != NULL ||
CPLGetConfigOption("MS_EMPTY_URL", NULL) != NULL)) {
const char *url = mapserv->map->web.empty;
if (url == NULL)
url = CPLGetConfigOption("MS_EMPTY_URL", NULL);
if (msReturnURL(mapserv, url, BROWSE) != MS_SUCCESS) {
msIO_setHeader("Content-Type", "text/html");
msIO_sendHeaders();
msIO_printf("<HTML>\n");
msIO_printf("<HEAD><TITLE>MapServer Message</TITLE></HEAD>\n");
msIO_printf("<BODY BGCOLOR=\"#FFFFFF\">\n");
msWriteErrorXML(stdout);
msIO_printf("</BODY></HTML>");
}
} else {
if (mapserv->map->web.error) {
/* msRedirect(mapserv->map->web.error); */
if (msReturnURL(mapserv, mapserv->map->web.error, BROWSE) != MS_SUCCESS) {
msIO_setHeader("Content-Type", "text/html");
msIO_sendHeaders();
msIO_printf("<HTML>\n");
msIO_printf("<HEAD><TITLE>MapServer Message</TITLE></HEAD>\n");
msIO_printf("<BODY BGCOLOR=\"#FFFFFF\">\n");
msWriteErrorXML(stdout);
msIO_printf("</BODY></HTML>");
}
if (CPLGetConfigOption("MS_ERROR_URL", NULL) != NULL) {
msRedirect(CPLGetConfigOption("MS_ERROR_URL", NULL));
} else {
msIO_setHeader("Content-Type", "text/html");
msIO_sendHeaders();
Expand All @@ -125,7 +90,33 @@ void msCGIWriteError(mapservObj *mapserv) {
msWriteErrorXML(stdout);
msIO_printf("</BODY></HTML>");
}
return;
}

if ((ms_error->code == MS_NOTFOUND) &&
(mapserv->map->web.empty != NULL ||
CPLGetConfigOption("MS_EMPTY_URL", NULL) != NULL)) {
const char *url = mapserv->map->web.empty; // takes precedence
if (url == NULL)
url = CPLGetConfigOption("MS_EMPTY_URL", NULL);
msRedirect(url);
} else if (mapserv->map->web.error != NULL ||
CPLGetConfigOption("MS_ERROR_URL", NULL) != NULL) {
const char *url = mapserv->map->web.error; // takes precedence
if (url == NULL)
url = CPLGetConfigOption("MS_ERROR_URL", NULL);
msRedirect(url);
} else {
msIO_setHeader("Content-Type", "text/html");
msIO_sendHeaders();
msIO_printf("<HTML>\n");
msIO_printf("<HEAD><TITLE>MapServer Message</TITLE></HEAD>\n");
msIO_printf("<BODY BGCOLOR=\"#FFFFFF\">\n");
msWriteErrorXML(stdout);
msIO_printf("</BODY></HTML>");
}

return;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/maptemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static int isValidTemplate(FILE *stream, const char *filename) {
* Redirect to (only use in CGI)
*
*/
int msRedirect(char *url) {
int msRedirect(const char *url) {
msIO_setHeader("Status", "302 Found");
msIO_setHeader("Uri", "%s", url);
msIO_setHeader("Location", "%s", url);
Expand Down
2 changes: 1 addition & 1 deletion src/maptemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ MS_DLL_EXPORT int msReturnTemplateQuery(mapservObj *msObj, char *pszMimeType,
char **papszBuffer);
MS_DLL_EXPORT int msReturnOpenLayersPage(mapservObj *mapserv);

MS_DLL_EXPORT int msRedirect(char *url);
MS_DLL_EXPORT int msRedirect(const char *url);

MS_DLL_EXPORT char *generateLegendTemplate(mapservObj *msObj);

Expand Down

0 comments on commit 828776c

Please sign in to comment.