MCPcopy Index your code
hub / github.com/MapServer/MapServer / msReturnPage

Function msReturnPage

maptemplate.c:4077–4167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4075#define MS_TEMPLATE_BUFFER 1024 /* 1k */
4076
4077int msReturnPage(mapservObj *mapserv, char *html, int mode, char **papszBuffer)
4078{
4079 FILE *stream;
4080 char line[MS_BUFFER_LENGTH], *tmpline;
4081 int nBufferSize = 0;
4082 int nCurrentSize = 0;
4083 int nExpandBuffer = 0;
4084
4085 ms_regex_t re; /* compiled regular expression to be matched */
4086 char szPath[MS_MAXPATHLEN];
4087
4088 if(!html) {
4089 msSetError(MS_WEBERR, "No template specified", "msReturnPage()");
4090 return MS_FAILURE;
4091 }
4092
4093 if(ms_regcomp(&re, MS_TEMPLATE_EXPR, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) {
4094 msSetError(MS_REGEXERR, NULL, "msReturnPage()");
4095 return MS_FAILURE;
4096 }
4097
4098 if(ms_regexec(&re, html, 0, NULL, 0) != 0) { /* no match */
4099 ms_regfree(&re);
4100 msSetError(MS_WEBERR, "Malformed template name (%s).", "msReturnPage()", html);
4101 return MS_FAILURE;
4102 }
4103 ms_regfree(&re);
4104
4105 if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, html), "r")) == NULL) {
4106 msSetError(MS_IOERR, html, "msReturnPage()");
4107 return MS_FAILURE;
4108 }
4109
4110 if(isValidTemplate(stream, html) != MS_TRUE) {
4111 fclose(stream);
4112 return MS_FAILURE;
4113 }
4114
4115 if(papszBuffer) {
4116 if((*papszBuffer) == NULL) {
4117 (*papszBuffer) = (char *)msSmallMalloc(MS_TEMPLATE_BUFFER);
4118 (*papszBuffer)[0] = '\0';
4119 nBufferSize = MS_TEMPLATE_BUFFER;
4120 nCurrentSize = 0;
4121 nExpandBuffer = 1;
4122 } else {
4123 nCurrentSize = strlen((*papszBuffer));
4124 nBufferSize = nCurrentSize;
4125 nExpandBuffer = (nCurrentSize/MS_TEMPLATE_BUFFER) + 1;
4126 }
4127 }
4128
4129 while(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) { /* now on to the end of the file */
4130
4131 if(strchr(line, '[') != NULL) {
4132 tmpline = processLine(mapserv, line, stream, mode);
4133 if(!tmpline)
4134 return MS_FAILURE;

Callers 5

mainFunction · 0.85
checkWebScaleFunction · 0.85
msReturnTemplateQueryFunction · 0.85
msProcessTemplateFunction · 0.85

Calls 10

msSetErrorFunction · 0.85
msBuildPathFunction · 0.85
isValidTemplateFunction · 0.85
msSmallMallocFunction · 0.85
processLineFunction · 0.85
msSmallReallocFunction · 0.85
msIO_fwriteFunction · 0.85
ms_regcompFunction · 0.70
ms_regexecFunction · 0.70
ms_regfreeFunction · 0.70

Tested by

no test coverage detected