/* ** Little helper function to allow us to build symbol files on-the-fly ** from just a file name. ** ** Returns the symbol index or -1 if it could not be added. */ int msAddImageSymbol(symbolSetObj *symbolset, char *filename) { char szPath[MS_MAXPATHLEN]; symbolObj *symbol=NULL; if(!symbolset) { msSetError(MS_SYMERR, "Symbol structure unallocated.", "msAddImageSymbol()"); return(-1); } if(!filename || strlen(filename) == 0) return(-1); /* Allocate/init memory for new symbol if needed */ if (msGrowSymbolSet(symbolset) == NULL) return -1; symbol = symbolset->symbol[symbolset->numsymbols]; #ifdef USE_CURL if (strncasecmp(filename, "http", 4) == 0) { char *tmpfullfilename = NULL; char *tmpfilename = NULL; char *tmppath = NULL; int status = 0; char szPath[MS_MAXPATHLEN]; int bCheckLocalCache = MS_TRUE; tmppath = msTmpPath(NULL, NULL, NULL); if (tmppath) { tmpfilename = msEncodeUrl(filename); tmpfullfilename = msBuildPath(szPath, tmppath, tmpfilename); if (tmpfullfilename) { /*use the url for now as a caching mechanism*/ if (msHTTPGetFile(filename, tmpfullfilename, &status, -1, bCheckLocalCache, 0) == MS_SUCCESS) { symbol->imagepath = msStrdup(tmpfullfilename); symbol->full_pixmap_path = msStrdup(tmpfullfilename); } } msFree(tmpfilename); msFree(tmppath); } } #endif /*if the http did not work, allow it to be treated as a file*/ if (!symbol->full_pixmap_path) { if(symbolset->map) { symbol->full_pixmap_path = msStrdup(msBuildPath(szPath, symbolset->map->mappath, filename)); } else { symbol->full_pixmap_path = msStrdup(msBuildPath(szPath, NULL, filename)); } symbol->imagepath = msStrdup(filename); } symbol->name = msStrdup(filename); symbol->type = MS_SYMBOL_PIXMAP; return(symbolset->numsymbols++); }
/********************************************************************** * msBuildWFSLayerGetURL() * * Build a WFS GetFeature URL for a Get Request. * * Returns a reference to a newly allocated string that should be freed * by the caller. **********************************************************************/ static char *msBuildWFSLayerGetURL(mapObj *map, layerObj *lp, rectObj *bbox, wfsParamsObj *psParams) { char *pszURL = NULL, *pszOnlineResource=NULL; const char *pszTmp; char *pszVersion, *pszService, *pszTypename = NULL; int bVersionInConnection = 0, bServiceInConnection = 0; int bTypenameInConnection = 0; size_t bufferSize = 0; if (lp->connectiontype != MS_WFS || lp->connection == NULL) { msSetError(MS_WFSCONNERR, "Call supported only for CONNECTIONTYPE WFS", "msBuildWFSLayerGetURL()"); return NULL; } /* -------------------------------------------------------------------- */ /* Find out request version. Look first for the wfs_version */ /* metedata. If not available try to find out if the CONNECTION */ /* string contains the version. This last test is done for */ /* backward compatiblity but is depericated. */ /* -------------------------------------------------------------------- */ pszVersion = psParams->pszVersion; if (!pszVersion) { if ((pszTmp = strstr(lp->connection, "VERSION=")) == NULL && (pszTmp = strstr(lp->connection, "version=")) == NULL ) { msSetError(MS_WFSCONNERR, "Metadata wfs_version must be set in the layer", "msBuildWFSLayerGetURL()"); return NULL; } pszVersion = strchr(pszTmp, '=')+1; bVersionInConnection = 1; } if (strncmp(pszVersion, "0.0.14", 6) != 0 && strncmp(pszVersion, "1.0.0", 5) != 0 && strncmp(pszVersion, "1.1", 3) != 0) { msSetError(MS_WFSCONNERR, "MapServer supports only WFS 1.0.0 or 0.0.14 (please verify the version metadata wfs_version).", "msBuildWFSLayerGetURL()"); return NULL; } /* -------------------------------------------------------------------- */ /* Find out the service. It is always set to WFS in function */ /* msBuildRequestParms (check Bug 1302 for details). */ /* -------------------------------------------------------------------- */ pszService = psParams->pszService; /* -------------------------------------------------------------------- */ /* Find out the typename. Look first for the wfs_tyename */ /* metadata. If not available try to find out if the CONNECTION */ /* string contains it. This last test is done for */ /* backward compatiblity but is depericated. */ /* -------------------------------------------------------------------- */ pszTypename = psParams->pszTypeName; if (!pszTypename) { if ((pszTmp = strstr(lp->connection, "TYPENAME=")) == NULL && (pszTmp = strstr(lp->connection, "typename=")) == NULL ) { msSetError(MS_WFSCONNERR, "Metadata wfs_typename must be set in the layer", "msBuildWFSLayerGetURL()"); return NULL; } bTypenameInConnection = 1; } /* -------------------------------------------------------------------- * Build the request URL. * At this point we set only the following parameters for GetFeature: * REQUEST * BBOX * VERSION * SERVICE * TYPENAME * FILTER * MAXFEATURES * * For backward compatiblity the user could also have in the connection * string the following parameters (but it is depricated): * VERSION * SERVICE * TYPENAME * -------------------------------------------------------------------- */ /* Make sure we have a big enough buffer for the URL */ bufferSize = strlen(lp->connection)+1024; pszURL = (char *)malloc(bufferSize); MS_CHECK_ALLOC(pszURL, bufferSize, NULL); /* __TODO__ We have to urlencode each value... especially the BBOX values */ /* because if they end up in exponent format (123e+06) the + will be seen */ /* as a space by the remote server. */ /* -------------------------------------------------------------------- */ /* build the URL, */ /* -------------------------------------------------------------------- */ /* make sure connection ends with "&" or "?" */ pszOnlineResource = msOWSTerminateOnlineResource(lp->connection); snprintf(pszURL, bufferSize, "%s", pszOnlineResource); msFree(pszOnlineResource); /* REQUEST */ snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&REQUEST=GetFeature"); /* VERSION */ if (!bVersionInConnection) snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&VERSION=%s", pszVersion); /* SERVICE */ if (!bServiceInConnection) snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&SERVICE=%s", pszService); /* TYPENAME */ if (!bTypenameInConnection) snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&TYPENAME=%s", pszTypename); /* -------------------------------------------------------------------- */ /* If the filter parameter is given in the wfs_filter metadata, */ /* we use it and do not send the BBOX paramter as they are */ /* mutually exclusive. */ /* -------------------------------------------------------------------- */ if (psParams->pszFilter) { char *encoded_filter = msEncodeUrl(psParams->pszFilter); snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&FILTER=%s",encoded_filter); free(encoded_filter); } else { /* * take care about the axis order for WFS 1.1 */ char *projUrn; char *projEpsg; projUrn = msOWSGetProjURN(&(lp->projection), &(lp->metadata), "FO", 1); msOWSGetEPSGProj(&(lp->projection), &(lp->metadata), "FO", 1, &projEpsg); /* * WFS 1.1 supports including the SRS in the BBOX parameter, should * respect axis order in the BBOX and has a separate SRSNAME parameter for * the desired result SRS. * WFS 1.0 is always easting, northing, doesn't include the SRS as part of * the BBOX parameter and has no SRSNAME parameter: if we don't have a * URN then fallback to WFS 1.0 style */ if ((strncmp(pszVersion, "1.1", 3) == 0) && projUrn) { if (projEpsg && (strncmp(projEpsg, "EPSG:", 5) == 0) && msIsAxisInverted(atoi(projEpsg + 5))) { snprintf(pszURL + strlen(pszURL), bufferSize - strlen(pszURL), "&BBOX=%.15g,%.15g,%.15g,%.15g,%s&SRSNAME=%s", bbox->miny, bbox->minx, bbox->maxy, bbox->maxx, projUrn, projUrn); } else { snprintf(pszURL + strlen(pszURL), bufferSize - strlen(pszURL), "&BBOX=%.15g,%.15g,%.15g,%.15g,%s&SRSNAME=%s", bbox->minx, bbox->miny, bbox->maxy, bbox->maxy, projUrn, projUrn); } } else { snprintf(pszURL + strlen(pszURL), bufferSize - strlen(pszURL), "&BBOX=%.15g,%.15g,%.15g,%.15g", bbox->minx, bbox->miny, bbox->maxx, bbox->maxy); } msFree(projUrn); msFree(projEpsg); } if (psParams->nMaxFeatures > 0) snprintf(pszURL + strlen(pszURL), bufferSize-strlen(pszURL), "&MAXFEATURES=%d", psParams->nMaxFeatures); return pszURL; }