[mapserver-commits] r7212 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Mon Dec 24 14:23:10 EST 2007
Author: sdlime
Date: 2007-12-24 14:23:10 -0500 (Mon, 24 Dec 2007)
New Revision: 7212
Modified:
trunk/mapserver/maptemplate.c
Log:
Initial support for template include tag. Works for local files only at the moment.
Modified: trunk/mapserver/maptemplate.c
===================================================================
--- trunk/mapserver/maptemplate.c 2007-12-23 21:24:23 UTC (rev 7211)
+++ trunk/mapserver/maptemplate.c 2007-12-24 19:23:10 UTC (rev 7212)
@@ -962,6 +962,79 @@
}
/*
+** function process a [include src="..."] tag.
+**
+** TODO's:
+** - Allow URLs.
+*/
+static int processInclude(mapObj *map, char **line)
+{
+ char *tag, *tagStart, *tagEnd;
+ hashTableObj *tagArgs=NULL;
+ int tagOffset, tagLength;
+
+ char *content=NULL, *src=NULL;
+
+ FILE *stream;
+ char buffer[MS_BUFFER_LENGTH], path[MS_MAXPATHLEN];
+
+ if(!*line) {
+ msSetError(MS_WEBERR, "Invalid line pointer.", "processInclude()");
+ return(MS_FAILURE);
+ }
+
+ tagStart = findTag(*line, "include");
+
+ /* It is OK to have no include tags, just return. */
+ if( !tagStart ) return MS_SUCCESS;
+
+ while( tagStart ) {
+ tagOffset = tagStart - *line;
+
+ /* check for any tag arguments */
+ if(getTagArgs("include", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE);
+ if(tagArgs) {
+ src = msLookupHashTable(tagArgs, "src");
+ }
+
+ if(!src) return(MS_SUCCESS); /* don't process the tag, could be something else so return MS_SUCCESS */
+
+ if((stream = fopen(msBuildPath(path, map->mappath, src), "r")) == NULL) {
+ msSetError(MS_IOERR, src, "processInclude()");
+ return MS_FAILURE;
+ }
+
+ while(fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL)
+ content = msStringConcatenate(content, buffer);
+
+ /* find the end of the tag */
+ tagEnd = strchr(tagStart, ']');
+ tagEnd++;
+
+ /* build the complete tag so we can do substitution */
+ tagLength = tagEnd - tagStart;
+ tag = (char *) malloc(tagLength + 1);
+ strncpy(tag, tagStart, tagLength);
+ tag[tagLength] = '\0';
+
+ /* do the replacement */
+ *line = msReplaceSubstring(*line, tag, content);
+
+ /* clean up */
+ free(tag); tag = NULL;
+ msFreeHashTable(tagArgs); tagArgs=NULL;
+ free(content);
+
+ if((*line)[tagOffset] != '\0')
+ tagStart = findTag(*line+tagOffset+1, "include");
+ else
+ tagStart = NULL;
+ }
+
+ return(MS_SUCCESS);
+}
+
+/*
** Function to process a [shpxy ...] tag: line contains the tag, shape holds the coordinates.
**
** TODO's:
@@ -2911,6 +2984,9 @@
} /* end query mode specific substitutions */
+ if(processInclude(msObj->Map, &outstr) != MS_SUCCESS)
+ return(NULL);
+
for(i=0;i<msObj->request->NumParams;i++) {
/* Replace [variable] tags using values from URL. We cannot offer a
* [variable_raw] option here due to the risk of XSS
More information about the mapserver-commits
mailing list