Permalink
Browse files

Make msLookupHashTable() return a const char*, and do all related cha…

…nges
  • Loading branch information...
rouault committed Dec 1, 2017
1 parent 924f2e4 commit bd40892ab776eb14f007cbd1c39f939cb0df9fbd
Showing with 125 additions and 119 deletions.
  1. +1 −1 fontcache.c
  2. +47 −34 mapcontext.c
  3. +3 −3 mapfile.c
  4. +1 −1 mapgeomtransform.c
  5. +1 −1 maphash.c
  6. +1 −1 maphash.h
  7. +9 −9 mapkmlrenderer.cpp
  8. +3 −3 mapkmlrenderer.h
  9. +1 −2 mapogcsld.c
  10. +8 −8 mappostgis.c
  11. +2 −2 mapserver.h
  12. +3 −3 mapstring.c
  13. +43 −50 maptemplate.c
  14. +2 −1 mapwcs20.c
@@ -204,7 +204,7 @@ face_element* msGetFontFace(char *key, fontSetObj *fontset) {
}
UT_HASH_FIND_STR(cache->face_cache,key,fc);
if(!fc) {
char *fontfile = NULL;
const char *fontfile = NULL;
fc = msSmallCalloc(1,sizeof(face_element));
if(fontset && strcmp(key,MS_DEFAULT_FONT_KEY)) {
fontfile = msLookupHashTable(&(fontset->fonts),key);
@@ -264,7 +264,8 @@ int msLoadMapContextListInMetadata( CPLXMLNode *psRoot, hashTableObj *metadata,
char *pszXMLName, char *pszMetadataName,
char *pszHashDelimiter)
{
char *pszHash, *pszXMLValue, *pszMetadata;
const char *pszHash, *pszXMLValue;
char *pszMetadata;
if(psRoot == NULL || psRoot->psChild == NULL ||
metadata == NULL || pszMetadataName == NULL || pszXMLName == NULL)
@@ -350,7 +351,9 @@ int msLoadMapContextContactInfo( CPLXMLNode *psRoot, hashTableObj *metadata )
*/
int msLoadMapContextLayerFormat(CPLXMLNode *psFormat, layerObj *layer)
{
char *pszValue, *pszValue1, *pszHash;
const char *pszValue;
char *pszValue1;
const char* pszHash;
if(psFormat->psChild != NULL &&
strcasecmp(psFormat->pszValue, "Format") == 0 ) {
@@ -442,7 +445,9 @@ int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer,
int nStyle)
{
char *pszValue, *pszValue1, *pszValue2;
char *pszHash, *pszStyle=NULL, *pszStyleName;
const char *pszHash;
char* pszStyle=NULL;
char *pszStyleName;
CPLXMLNode *psStyleSLDBody;
pszStyleName =(char*)CPLGetXMLValue(psStyle,"Name",NULL);
@@ -576,7 +581,8 @@ int msLoadMapContextLayerStyle(CPLXMLNode *psStyle, layerObj *layer,
int msLoadMapContextLayerDimension(CPLXMLNode *psDimension, layerObj *layer)
{
char *pszValue, *pszHash;
char *pszValue;
const char *pszHash;
char *pszDimension=NULL, *pszDimensionName=NULL;
pszDimensionName =(char*)CPLGetXMLValue(psDimension,"name",NULL);
@@ -805,7 +811,8 @@ int msLoadMapContextLayer(mapObj *map, CPLXMLNode *psLayer, int nVersion,
{
char *pszProj=NULL;
char *pszValue;
char *pszHash, *pszName=NULL;
const char *pszHash;
char *pszName=NULL;
CPLXMLNode *psFormatList, *psFormat, *psStyleList, *psStyle, *psExtension;
CPLXMLNode *psDimensionList, *psDimension;
int nStyle;
@@ -1304,8 +1311,8 @@ int msWriteMapContext(mapObj *map, FILE *stream)
#if defined(USE_WMS_LYR) && defined(USE_OGR)
const char * version;
char *pszEPSG;
char * tabspace=NULL, *pszValue, *pszChar,*pszSLD=NULL,*pszURL,*pszSLD2=NULL;
char *pszStyle, *pszCurrent, *pszStyleItem, *pszSLDBody;
char * tabspace=NULL, *pszChar,*pszSLD=NULL,*pszURL,*pszSLD2=NULL;
char *pszStyle, *pszStyleItem, *pszSLDBody;
char *pszEncodedVal;
int i, nValue, nVersion=OWS_VERSION_NOTSET;
/* Dimension element */
@@ -1443,7 +1450,7 @@ int msWriteMapContext(mapObj *map, FILE *stream)
char **papszKeywords;
int nKeywords, iKey;
pszValue = msLookupHashTable(&(map->web.metadata),
const char* pszValue = msLookupHashTable(&(map->web.metadata),
"wms_keywordlist");
papszKeywords = msStringSplit(pszValue, ',', &nKeywords);
if(nKeywords > 0 && papszKeywords) {
@@ -1511,6 +1518,9 @@ int msWriteMapContext(mapObj *map, FILE *stream)
/* Loop on all layer */
for(i=0; i<map->numlayers; i++) {
if(GET_LAYER(map, i)->status != MS_DELETE && GET_LAYER(map, i)->connectiontype == MS_WMS) {
const char* pszValue;
char* pszValueMod;
const char* pszCurrent;
if(GET_LAYER(map, i)->status == MS_OFF)
nValue = 1;
else
@@ -1549,21 +1559,21 @@ int msWriteMapContext(mapObj *map, FILE *stream)
/* Get base url of the online resource to be the default value */
if(GET_LAYER(map, i)->connection)
pszValue = msStrdup( GET_LAYER(map, i)->connection );
pszValueMod = msStrdup( GET_LAYER(map, i)->connection );
else
pszValue = msStrdup( "" );
pszChar = strchr(pszValue, '?');
pszValueMod = msStrdup( "" );
pszChar = strchr(pszValueMod, '?');
if( pszChar )
pszValue[pszChar - pszValue] = '\0';
pszValueMod[pszChar - pszValueMod] = '\0';
if(msOWSPrintEncodeMetadata(stream, &(GET_LAYER(map, i)->metadata),
NULL, "wms_onlineresource", OWS_WARN,
" <OnlineResource xlink:type=\"simple\" xlink:href=\"%s\"/>\n",
pszValue) == OWS_WARN)
pszValueMod) == OWS_WARN)
msIO_fprintf(stream, "<!-- wms_onlineresource not set, using base URL"
" , but probably not what you want -->\n");
msIO_fprintf(stream, " </Server>\n");
if(pszValue)
free(pszValue);
if(pszValueMod)
free(pszValueMod);
/* */
/* Layer information */
@@ -1645,17 +1655,17 @@ int msWriteMapContext(mapObj *map, FILE *stream)
pszURL = msStrdup( GET_LAYER(map, i)->connection );
else
pszURL = msStrdup( "" );
pszValue = pszURL;
pszValue = strstr( pszValue, "FORMAT=" );
if( pszValue ) {
pszValue += 7;
pszChar = strchr(pszValue, '&');
pszValueMod = pszURL;
pszValueMod = strstr( pszValueMod, "FORMAT=" );
if( pszValueMod ) {
pszValueMod += 7;
pszChar = strchr(pszValueMod, '&');
if( pszChar )
pszValue[pszChar - pszValue] = '\0';
if(strcasecmp(pszValue, "") != 0) {
pszEncodedVal = msEncodeHTMLEntities(pszValue);
pszValueMod[pszChar - pszValueMod] = '\0';
if(strcasecmp(pszValueMod, "") != 0) {
pszEncodedVal = msEncodeHTMLEntities(pszValueMod);
msIO_fprintf( stream, " <FormatList>\n");
msIO_fprintf(stream," <Format>%s</Format>\n",pszValue);
msIO_fprintf(stream," <Format>%s</Format>\n",pszValueMod);
msIO_fprintf( stream, " </FormatList>\n");
msFree(pszEncodedVal);
}
@@ -1698,21 +1708,23 @@ int msWriteMapContext(mapObj *map, FILE *stream)
/* First check the stylelist */
pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata),
"wms_stylelist");
if(pszValue == NULL || strlen(msStringTrimLeft(pszValue)) < 1) {
while( pszValue && *pszValue == ' ' )
pszValue ++;
if(pszValue == NULL || strlen(pszValue) < 1) {
/* Check if the style is in the connection URL */
pszURL = "";
if(GET_LAYER(map, i)->connection)
pszURL = msStrdup( GET_LAYER(map, i)->connection );
else
pszURL = msStrdup( "" );
pszValue = pszURL;
pszValueMod = pszURL;
/* Grab the STYLES in the URL */
pszValue = strstr( pszValue, "STYLES=" );
if( pszValue ) {
pszValue += 7;
pszChar = strchr(pszValue, '&');
pszValueMod = strstr( pszValueMod, "STYLES=" );
if( pszValueMod ) {
pszValueMod += 7;
pszChar = strchr(pszValueMod, '&');
if( pszChar )
pszValue[pszChar - pszValue] = '\0';
pszValueMod[pszChar - pszValueMod] = '\0';
/* Check the SLD string from the URL */
if(GET_LAYER(map, i)->connection)
@@ -1740,14 +1752,14 @@ int msWriteMapContext(mapObj *map, FILE *stream)
pszSLDBody[pszChar - pszSLDBody] = '\0';
pszSLDBody += 9;
}
if( (pszValue && (strcasecmp(pszValue, "") != 0)) ||
if( (pszValueMod && (strcasecmp(pszValueMod, "") != 0)) ||
(pszSLD && (strcasecmp(pszSLD, "") != 0)) ||
(pszSLDBody && (strcasecmp(pszSLDBody, "") != 0))) {
/* Write Name and Title */
msIO_fprintf( stream, " <StyleList>\n");
msIO_fprintf( stream, " <Style current=\"1\">\n");
if( pszValue && (strcasecmp(pszValue, "") != 0)) {
pszEncodedVal = msEncodeHTMLEntities(pszValue);
if( pszValueMod && (strcasecmp(pszValueMod, "") != 0)) {
pszEncodedVal = msEncodeHTMLEntities(pszValueMod);
msIO_fprintf(stream, " <Name>%s</Name>\n",
pszEncodedVal);
msIO_fprintf(stream," <Title>%s</Title>\n",
@@ -1782,6 +1794,7 @@ int msWriteMapContext(mapObj *map, FILE *stream)
pszURL = NULL;
}
} else {
const char* pszCurrent;
/* If the style information is not in the connection URL, */
/* read the metadata. */
pszValue = msLookupHashTable(&(GET_LAYER(map, i)->metadata),
@@ -94,7 +94,7 @@ char *msPositionsText[MS_POSITIONS_LENGTH] = {"UL", "LR", "UR", "LL", "CR", "CL"
** Validates a string (value) against a series of patterns. We support up to four to allow cascading from classObj to
** layerObj to webObj plus a legacy pattern like TEMPLATEPATTERN.
*/
int msValidateParameter(char *value, char *pattern1, char *pattern2, char *pattern3, char *pattern4)
int msValidateParameter(const char *value, const char *pattern1, const char *pattern2, const char *pattern3, const char *pattern4)
{
if(msEvalRegex(pattern1, value) == MS_TRUE) return MS_SUCCESS;
if(msEvalRegex(pattern2, value) == MS_TRUE) return MS_SUCCESS;
@@ -7141,7 +7141,7 @@ static void applyLayerDefaultSubstitutions(layerObj *layer, hashTableObj *table)
while(default_key) {
if(!strncmp(default_key,"default_",8)) {
size_t buffer_size = (strlen(default_key)-5);
char *to = msLookupHashTable(table, default_key);
const char *to = msLookupHashTable(table, default_key);
char *tag = (char *)msSmallMalloc(buffer_size);
snprintf(tag, buffer_size, "%%%s%%", &(default_key[8]));
@@ -7163,7 +7163,7 @@ static void applyHashTableDefaultSubstitutions(hashTableObj *hashTab, hashTableO
while (default_key) {
if (!strncmp(default_key, "default_", 8)) {
size_t buffer_size = (strlen(default_key) - 5);
char *to = msLookupHashTable(table, default_key);
const char *to = msLookupHashTable(table, default_key);
char *tag = (char *)msSmallMalloc(buffer_size);
snprintf(tag, buffer_size, "%%%s%%", &(default_key[8]));
@@ -280,7 +280,7 @@ int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape)
/* data_cellsize is only set with contour layer */
if (layer->connectiontype == MS_CONTOUR)
{
char *value = msLookupHashTable(&layer->metadata, "__data_cellsize__");
const char *value = msLookupHashTable(&layer->metadata, "__data_cellsize__");
if (value)
p.dblval2 = atof(value);
}
@@ -149,7 +149,7 @@ struct hashObj *msInsertHashTable(hashTableObj *table,
return tp;
}
char *msLookupHashTable(hashTableObj *table, const char *key)
const char *msLookupHashTable(hashTableObj *table, const char *key)
{
struct hashObj *tp;
@@ -115,7 +115,7 @@ extern "C" {
* RETURNS:
* string value of item
*/
MS_DLL_EXPORT char *msLookupHashTable( hashTableObj *table, const char *key);
MS_DLL_EXPORT const char *msLookupHashTable( hashTableObj *table, const char *key);
/* msRemoveHashTable - remove item from table at key
* ARGS:
@@ -419,7 +419,7 @@ int KmlRenderer::startNewLayer(imageObj *img, layerObj *layer)
}
char* elevationAttribute = msLookupHashTable(&layer->metadata, "kml_elevation_attribute");
const char* elevationAttribute = msLookupHashTable(&layer->metadata, "kml_elevation_attribute");
if( elevationAttribute ) {
mElevationFromAttribute = true;
for( int i = 0; i < layer->numitems; ++i ) {
@@ -497,7 +497,7 @@ void KmlRenderer::setupRenderingParams(hashTableObj *layerMetadata)
Extrude = 0;
Tessellate = 0;
char *altitudeModeVal = msLookupHashTable(layerMetadata, "kml_altitudeMode");
const char *altitudeModeVal = msLookupHashTable(layerMetadata, "kml_altitudeMode");
if (altitudeModeVal) {
if(strcasecmp(altitudeModeVal, "absolute") == 0)
AltitudeMode = absolute;
@@ -507,12 +507,12 @@ void KmlRenderer::setupRenderingParams(hashTableObj *layerMetadata)
AltitudeMode = clampToGround;
}
char *extrudeVal = msLookupHashTable(layerMetadata, "kml_extrude");
const char *extrudeVal = msLookupHashTable(layerMetadata, "kml_extrude");
if (altitudeModeVal) {
Extrude = atoi(extrudeVal);
}
char *tessellateVal = msLookupHashTable(layerMetadata, "kml_tessellate");
const char *tessellateVal = msLookupHashTable(layerMetadata, "kml_tessellate");
if (tessellateVal) {
Tessellate = atoi(tessellateVal);
}
@@ -955,7 +955,7 @@ xmlNodePtr KmlRenderer::getGeomParentNode(const char *geomName)
}
}
char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *symstyle)
const char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *symstyle)
{
char symbolHexColor[32];
/*
@@ -975,7 +975,7 @@ char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyle
symstyle->style->color.green, symstyle->style->color.red);
snprintf(SymbolName, sizeof(SymbolName), "symbol_%s_%.1f_%s", symbol->name, symstyle->scale, symbolHexColor);
char *symbolUrl = msLookupHashTable(StyleHashTable, SymbolName);
const char *symbolUrl = msLookupHashTable(StyleHashTable, SymbolName);
if (!symbolUrl) {
char iconFileName[MS_MAXPATHLEN];
char iconUrl[MS_MAXPATHLEN];
@@ -1005,7 +1005,7 @@ char* KmlRenderer::lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyle
return symbolUrl;
}
char* KmlRenderer::lookupPlacemarkStyle()
const char* KmlRenderer::lookupPlacemarkStyle()
{
char lineHexColor[32];
char polygonHexColor[32];
@@ -1107,7 +1107,7 @@ char* KmlRenderer::lookupPlacemarkStyle()
styleName = msStringConcatenate(styleName, SymbolName);
}
char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
const char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
if (!styleUrl) {
char *styleValue=NULL;
styleValue = msStringConcatenate(styleValue, "#");
@@ -1176,7 +1176,7 @@ char* KmlRenderer::lookupPlacemarkStyle()
void KmlRenderer::flushPlacemark()
{
if (PlacemarkNode) {
char *styleUrl = lookupPlacemarkStyle();
const char *styleUrl = lookupPlacemarkStyle();
xmlNewChild(PlacemarkNode, NULL, BAD_CAST "styleUrl", BAD_CAST styleUrl);
if (DescriptionNode)
@@ -46,7 +46,7 @@ class KmlRenderer
int nIncludeItems;
char **papszLayerExcludeItems;
int nExcludeItems;
char *pszLayerNameAttributeMetadata;
const char *pszLayerNameAttributeMetadata;
protected:
@@ -116,7 +116,7 @@ class KmlRenderer
xmlNodePtr createGroundOverlayNode(xmlNodePtr parentNode, char *imageHref, layerObj *layer);
xmlNodePtr createDescriptionNode(shapeObj *shape);
char* lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *style);
const char* lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *style);
void addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts);
@@ -135,7 +135,7 @@ class KmlRenderer
void renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color);
void renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text);
char* lookupPlacemarkStyle();
const char* lookupPlacemarkStyle();
void flushPlacemark();
xmlNodePtr getGeomParentNode(const char *geomName);
char* getLayerName(layerObj *layer);
@@ -3187,7 +3187,6 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer,
int nSymbol = -1;
symbolObj *psSymbol = NULL;
char szTmp[512];
char *pszURL = NULL;
char szFormat[4];
int i = 0, nLength = 0;
int bFillColor = 0, bColorAvailable=0;
@@ -3362,7 +3361,7 @@ char *msSLDGetGraphicSLD(styleObj *psStyle, layerObj *psLayer,
bGenerateDefaultSymbol =1;
} else if (psSymbol->type == MS_SYMBOL_PIXMAP || psSymbol->type == MS_SYMBOL_SVG) {
if (psSymbol->name) {
pszURL = msLookupHashTable(&(psLayer->metadata), "WMS_SLD_SYMBOL_URL");
const char *pszURL = msLookupHashTable(&(psLayer->metadata), "WMS_SLD_SYMBOL_URL");
if (!pszURL)
pszURL = msLookupHashTable(&(psLayer->map->web.metadata), "WMS_SLD_SYMBOL_URL");
Oops, something went wrong.

0 comments on commit bd40892

Please sign in to comment.