diff --git a/CMakeLists.txt b/CMakeLists.txt index 3315923db6..6bf39ab991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 3.0) project (MapServer) @@ -20,6 +20,24 @@ set (MapServer_VERSION_MINOR 5) set (MapServer_VERSION_REVISION 0) set (MapServer_VERSION_SUFFIX "") +# Set C++ version +# Make CMAKE_CXX_STANDARD available as cache option overridable by user +set(CMAKE_CXX_STANDARD 11 + CACHE STRING "C++ standard version to use (default is 11)") +message(STATUS "Requiring C++${CMAKE_CXX_STANDARD}") +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +message(STATUS "Requiring C++${CMAKE_CXX_STANDARD} - done") + +# Set C99 version +# Make CMAKE_C_STANDARD available as cache option overridable by user +set(CMAKE_C_STANDARD 99 + CACHE STRING "C standard version to use (default is 99)") +message(STATUS "Requiring C${CMAKE_C_STANDARD}") +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) +message(STATUS "Requiring C${CMAKE_C_STANDARD} - done") + set(TARGET_VERSION_MAJOR ${MapServer_VERSION_MAJOR}) set(TARGET_VERSION_MINOR ${MapServer_VERSION_MINOR}) @@ -260,7 +278,7 @@ maptree.c mapdebug.c maplexer.c mapquantization.c mapunion.c mapdraw.c maplibxml2.c mapquery.c maputil.c strptime.c mapdrawgdal.c mapraster.c mapuvraster.c mapdummyrenderer.c mapobject.c maprasterquery.c mapwcs.c maperror.c mapogcfilter.c mapregex.c mapwcs11.c mapfile.c -mapogcfiltercommon.c maprendering.c mapwcs20.c mapogcsld.c mapmetadata.c +mapogcfiltercommon.cpp maprendering.c mapwcs20.c mapogcsld.c mapmetadata.c mapresample.c mapwfs.c mapgdal.c mapogcsos.c mapscale.c mapwfs11.c mapwfs20.c mapgeomtransform.c mapogroutput.c mapwfslayer.c mapagg.cpp mapkml.cpp mapgeomutil.cpp mapkmlrenderer.cpp fontcache.c textlayout.c maputfgrid.cpp diff --git a/mapogcfilter.h b/mapogcfilter.h index 07710c4b90..579d0b45af 100644 --- a/mapogcfilter.h +++ b/mapogcfilter.h @@ -31,11 +31,6 @@ #include "mapserver.h" -/*dont need ogr for these functikons*/ -MS_DLL_EXPORT int FLTIsNumeric(const char *pszValue); -MS_DLL_EXPORT int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression); -MS_DLL_EXPORT char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char *value, int forcecharcter); - /* There is a dependency to OGR for the MiniXML parser */ #include "cpl_minixml.h" @@ -45,6 +40,9 @@ MS_DLL_EXPORT char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *i #include #endif +#ifdef __cplusplus +extern "C" { +#endif typedef struct { char *pszWildCard; @@ -56,6 +54,10 @@ typedef struct { /* -------------------------------------------------------------------- */ /* prototypes. */ /* -------------------------------------------------------------------- */ +MS_DLL_EXPORT int FLTIsNumeric(const char *pszValue); +MS_DLL_EXPORT int FLTApplyExpressionToLayer(layerObj *lp, const char *pszExpression); +MS_DLL_EXPORT char *FLTGetExpressionForValuesRanges(layerObj *lp, const char *item, const char *value, int forcecharcter); + MS_DLL_EXPORT FilterEncodingNode *FLTParseFilterEncoding(const char *szXMLString); MS_DLL_EXPORT FilterEncodingNode *FLTCreateFilterEncodingNode(void); MS_DLL_EXPORT char** FLTSplitFilters(const char* pszStr, int* pnTokens); @@ -143,4 +145,8 @@ int FLTApplyFilterToLayerCommonExpressionWithRect(mapObj *map, int iLayerIndex, int FLTProcessPropertyIsNull(FilterEncodingNode *psFilterNode, mapObj *map, int i); +#ifdef __cplusplus +} +#endif + #endif diff --git a/mapogcfiltercommon.c b/mapogcfiltercommon.cpp similarity index 81% rename from mapogcfiltercommon.c rename to mapogcfiltercommon.cpp index 5f48bd06b9..6896044703 100644 --- a/mapogcfiltercommon.c +++ b/mapogcfiltercommon.cpp @@ -26,82 +26,55 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ****************************************************************************/ -#include "cpl_minixml.h" - #include "mapogcfilter.h" #include "mapserver.h" #include "mapows.h" #include "mapowscommon.h" +#include "cpl_minixml.h" -char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode) -{ - const size_t bufferSize = 1024; - char szBuffer[1024]; - char szTmp[512]; - char *pszValue = NULL; - - const char *pszWild = NULL; - const char *pszSingle = NULL; - const char *pszEscape = NULL; - int bCaseInsensitive = 0; - FEPropertyIsLike* propIsLike; - - int nLength=0, i=0, iTmp=0; +#include +static std::string FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode) +{ /* From http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04 */ /* also add double quote because we are within a string */ const char* pszRegexSpecialCharsAndDoubleQuote = "\\^${[().*+?|\""; if (!psFilterNode || !psFilterNode->pOther || !psFilterNode->psLeftNode || !psFilterNode->psRightNode || !psFilterNode->psRightNode->pszValue) - return NULL; + return std::string(); - propIsLike = (FEPropertyIsLike *)psFilterNode->pOther; - pszWild = propIsLike->pszWildCard; - pszSingle = propIsLike->pszSingleChar; - pszEscape = propIsLike->pszEscapeChar; - bCaseInsensitive = propIsLike->bCaseInsensitive; + const FEPropertyIsLike* propIsLike = (const FEPropertyIsLike *)psFilterNode->pOther; + const char* pszWild = propIsLike->pszWildCard; + const char* pszSingle = propIsLike->pszSingleChar; + const char* pszEscape = propIsLike->pszEscapeChar; + const bool bCaseInsensitive = propIsLike->bCaseInsensitive != 0; if (!pszWild || strlen(pszWild) == 0 || !pszSingle || strlen(pszSingle) == 0 || !pszEscape || strlen(pszEscape) == 0) - return NULL; + return std::string(); /* -------------------------------------------------------------------- */ /* Use operand with regular expressions. */ /* -------------------------------------------------------------------- */ - szBuffer[0] = '\0'; - sprintf(szTmp, "%s", "(\"["); - szTmp[4] = '\0'; - - strlcat(szBuffer, szTmp, bufferSize); + std::string expr("(\"["); /* attribute */ - strlcat(szBuffer, psFilterNode->psLeftNode->pszValue, bufferSize); - szBuffer[strlen(szBuffer)] = '\0'; + expr += psFilterNode->psLeftNode->pszValue; /* #3521 */ - if (bCaseInsensitive == 1) - sprintf(szTmp, "%s", "]\" ~* \""); + if (bCaseInsensitive ) + expr += "]\" ~* \""; else - sprintf(szTmp, "%s", "]\" ~ \""); - szTmp[7] = '\0'; - strlcat(szBuffer, szTmp, bufferSize); - szBuffer[strlen(szBuffer)] = '\0'; - - pszValue = psFilterNode->psRightNode->pszValue; - nLength = strlen(pszValue); - /* The 4 factor is in case of \. See below */ - if( 1 + 4 * nLength + 1 + 1 + 1 >= sizeof(szTmp) ) - return NULL; + expr += "]\" ~ \""; + + const char* pszValue = psFilterNode->psRightNode->pszValue; + const size_t nLength = strlen(pszValue); - iTmp =0; if (nLength > 0) { - szTmp[iTmp]= '^'; - iTmp++; + expr += '^'; } - for (i=0; i 0) { - szTmp[iTmp]= '$'; - iTmp++; - } - szTmp[iTmp] = '"'; - szTmp[++iTmp] = '\0'; -#if 0 - msDebug("like: %s\n", pszValue); - msDebug("regexp (with \\ escaping for MapServer use): %s\n", szTmp); -#endif - strlcat(szBuffer, szTmp, bufferSize); - strlcat(szBuffer, ")", bufferSize); - return msStrdup(szBuffer); + expr += '$'; + } + expr += "\")"; + return expr; } -char *FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp) +static std::string FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNode, layerObj *lp) { - const size_t bufferSize = 1024; - char szBuffer[1024]; - char **aszBounds = NULL; - int nBounds = 0; - int bString=0; - int bDateTime = 0; - char *pszExpression=NULL, *pszTmpEscaped; - if (!psFilterNode || !(strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0)) - return NULL; + return std::string(); if (psFilterNode->psLeftNode == NULL || psFilterNode->psRightNode == NULL ) - return NULL; + return std::string(); /* -------------------------------------------------------------------- */ /* Get the bounds value which are stored like boundmin;boundmax */ /* -------------------------------------------------------------------- */ - aszBounds = msStringSplit(psFilterNode->psRightNode->pszValue, ';', &nBounds); + int nBounds = 0; + char** aszBounds = msStringSplit(psFilterNode->psRightNode->pszValue, ';', &nBounds); if (nBounds != 2) { msFreeCharArray(aszBounds, nBounds); - return NULL; + return std::string(); } /* -------------------------------------------------------------------- */ /* check if the value is a numeric value or alphanumeric. If it */ /* is alphanumeric, add quotes around attribute and values. */ /* -------------------------------------------------------------------- */ - bString = 0; + bool bString = false; + bool bDateTime = false; if (aszBounds[0]) { - const char* pszType; - snprintf(szBuffer, bufferSize, "%s_type", psFilterNode->psLeftNode->pszValue); - pszType = msOWSLookupMetadata(&(lp->metadata), "OFG", szBuffer); + const char* pszType = msOWSLookupMetadata(&(lp->metadata), "OFG", + (std::string(psFilterNode->psLeftNode->pszValue)+ "_type").c_str()); if (pszType != NULL && (strcasecmp(pszType, "Character") == 0)) - bString = 1; + bString = true; else if (pszType != NULL && (strcasecmp(pszType, "Date") == 0)) - bDateTime = 1; + bDateTime = true; else if (FLTIsNumeric(aszBounds[0]) == MS_FALSE) - bString = 1; + bString = true; } if (!bString && !bDateTime) { if (aszBounds[1]) { if (FLTIsNumeric(aszBounds[1]) == MS_FALSE) - bString = 1; + bString = true; } } + std::string expr; /* -------------------------------------------------------------------- */ /* build expresssion. */ /* -------------------------------------------------------------------- */ /* attribute */ if (bString) - sprintf(szBuffer, "%s", "(\"["); + expr += "(\"["; else - sprintf(szBuffer, "%s", "(["); - pszExpression = msStringConcatenate(pszExpression, szBuffer); - - pszExpression = msStringConcatenate(pszExpression, psFilterNode->psLeftNode->pszValue); + expr += "(["; + + expr += psFilterNode->psLeftNode->pszValue; if (bString) - sprintf(szBuffer, "%s", "]\" "); + expr += "]\" "; else - sprintf(szBuffer, "%s", "] "); - pszExpression = msStringConcatenate(pszExpression, szBuffer); + expr += "] "; - sprintf(szBuffer, "%s", " >= "); - pszExpression = msStringConcatenate(pszExpression, szBuffer); + expr += " >= "; if (bString) { - pszExpression = msStringConcatenate(pszExpression, "\""); + expr += '\"'; } else if (bDateTime) { - pszExpression = msStringConcatenate(pszExpression, "`"); + expr += '`'; + } + + { + char* pszTmpEscaped = msStringEscape(aszBounds[0]); + expr += pszTmpEscaped; + if(pszTmpEscaped != aszBounds[0] ) msFree(pszTmpEscaped); } - pszTmpEscaped = msStringEscape(aszBounds[0]); - snprintf(szBuffer, bufferSize, "%s", pszTmpEscaped); - if(pszTmpEscaped != aszBounds[0] ) msFree(pszTmpEscaped); - pszExpression = msStringConcatenate(pszExpression, szBuffer); if (bString) { - pszExpression = msStringConcatenate(pszExpression, "\""); + expr += '\"'; } else if (bDateTime) { - pszExpression = msStringConcatenate(pszExpression, "`"); + expr += '`'; } - sprintf(szBuffer, "%s", " AND "); - pszExpression = msStringConcatenate(pszExpression, szBuffer); + expr += " AND "; if (bString) - sprintf(szBuffer, "%s", " \"["); + expr += " \"["; else - sprintf(szBuffer, "%s", " ["); - pszExpression = msStringConcatenate(pszExpression, szBuffer); + expr += " ["; /* attribute */ - pszExpression = msStringConcatenate(pszExpression, psFilterNode->psLeftNode->pszValue); + expr += psFilterNode->psLeftNode->pszValue; if (bString) - sprintf(szBuffer, "%s", "]\" "); + expr += "]\" "; else - sprintf(szBuffer, "%s", "] "); - pszExpression = msStringConcatenate(pszExpression, szBuffer); + expr += "] "; + + expr += " <= "; - sprintf(szBuffer, "%s", " <= "); - pszExpression = msStringConcatenate(pszExpression, szBuffer); if (bString) { - pszExpression = msStringConcatenate(pszExpression, "\""); + expr += '\"'; } else if (bDateTime) { - pszExpression = msStringConcatenate(pszExpression, "`"); + expr += '`'; + } + + { + char* pszTmpEscaped = msStringEscape(aszBounds[1]); + expr += pszTmpEscaped; + if(pszTmpEscaped != aszBounds[1] ) msFree(pszTmpEscaped); } - pszTmpEscaped = msStringEscape(aszBounds[1]); - snprintf(szBuffer, bufferSize, "%s", pszTmpEscaped); - if (pszTmpEscaped != aszBounds[1]) msFree(pszTmpEscaped); - pszExpression = msStringConcatenate(pszExpression, szBuffer); if (bString) { - pszExpression = msStringConcatenate(pszExpression, "\""); + expr += '\"'; } else if (bDateTime) { - pszExpression = msStringConcatenate(pszExpression, "`"); + expr += '`'; } - sprintf(szBuffer, "%s", ")"); - pszExpression = msStringConcatenate(pszExpression, szBuffer); + expr += ')'; msFreeCharArray(aszBounds, nBounds); - return pszExpression; + return expr; } char *FLTGetBinaryComparisonCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) @@ -728,9 +672,9 @@ char *FLTGetCommonExpression(FilterEncodingNode *psFilterNode, layerObj *lp) if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue)) pszExpression = FLTGetBinaryComparisonCommonExpression(psFilterNode, lp); else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0) - pszExpression = FLTGetIsLikeComparisonCommonExpression(psFilterNode); + pszExpression = msStrdup(FLTGetIsLikeComparisonCommonExpression(psFilterNode).c_str()); else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0) - pszExpression = FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp); + pszExpression = msStrdup(FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp).c_str()); } } else if (psFilterNode->eType == FILTER_NODE_TYPE_LOGICAL) { pszExpression = FLTGetLogicalComparisonCommonExpression(psFilterNode, lp);