| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Project: OpenGIS Simple Features Reference Implementation |
| 4 | * Purpose: Implementation of private utilities used within OGR GeoJSON Driver. |
| 5 | * Author: Mateusz Loskot, [email protected] |
| 6 | * |
| 7 | ****************************************************************************** |
| 8 | * Copyright (c) 2007, Mateusz Loskot |
| 9 | * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com> |
| 10 | * |
| 11 | * SPDX-License-Identifier: MIT |
| 12 | ****************************************************************************/ |
| 13 | |
| 14 | #include "ogrgeojsonutils.h"cxx . . $ `<file>/ogr/ogrsf_frmts/geojson/ogrgeojsonutils.h`/ |
| 15 | #include <assert.h> |
| 16 | #include "cpl_port.h"cxx . . $ `<file>/port/cpl_port.h`/ |
| 17 | #include "cpl_conv.h"cxx . . $ `<file>/port/cpl_conv.h`/ |
| 18 | #include "cpl_json_streaming_parser.h"cxx . . $ `<file>/port/cpl_json_streaming_parser.h`/ |
| 19 | #include "ogr_geometry.h"cxx . . $ `<file>/ogr/ogr_geometry.h`/ |
| 20 | #include <json.h> // JSON-C |
| 21 | |
| 22 | #include <algorithm> |
| 23 | #include <memory> |
| 24 | |
| 25 | constexpr const char szESRIJSonFeaturesGeometryRingscxx . . $ szESRIJSonFeaturesGeometryRings.[] = |
| 26 | "\"features\":[{\"geometry\":{\"rings\":["; |
| 27 | |
| 28 | // Cf https://github.com/OSGeo/gdal/issues/9996#issuecomment-2129845692 |
| 29 | constexpr const char szESRIJSonFeaturesAttributescxx . . $ szESRIJSonFeaturesAttributes.[] = |
| 30 | "\"features\":[{\"attributes\":{"; |
| 31 | |
| 32 | /************************************************************************/ |
| 33 | /* SkipUTF8BOM() */ |
| 34 | /************************************************************************/ |
| 35 | |
| 36 | static void SkipUTF8BOMcxx . . $ SkipUTF8BOM(30ad0281919313c0).(const char *&pszText) |
| 37 | { |
| 38 | /* Skip UTF-8 BOM (#5630) */ |
| 39 | const GBytecxx . . $ GByte# *pabyData = reinterpret_cast<const GBytecxx . . $ GByte# *>(pszText); |
| 40 | if (pabyData[0] == 0xEF && pabyData[1] == 0xBB && pabyData[2] == 0xBF) |
| 41 | pszText += 3; |
| 42 | } |
| 43 | |
| 44 | /************************************************************************/ |
| 45 | /* IsJSONObject() */ |
| 46 | /************************************************************************/ |
| 47 | |
| 48 | static bool IsJSONObjectcxx . . $ IsJSONObject(c5f7da30cbc0f4e9).(const char *pszText) |
| 49 | { |
| 50 | if (nullptr == pszText) |
| 51 | return false; |
| 52 | |
| 53 | SkipUTF8BOMcxx . . $ SkipUTF8BOM(30ad0281919313c0).(pszText); |
| 54 | |
| 55 | /* -------------------------------------------------------------------- */ |
| 56 | /* This is a primitive test, but we need to perform it fast. */ |
| 57 | /* -------------------------------------------------------------------- */ |
| 58 | while (*pszText != '\0' && isspace(static_cast<unsigned char>(*pszText))) |
| 59 | pszText++; |
| 60 | |
| 61 | const char *const apszPrefix[] = {"loadGeoJSON(", "jsonp("}; |
| 62 | for (size_t iP = 0; iP < sizeof(apszPrefix) / sizeof(apszPrefix[0]); iP++) |
| 63 | { |
| 64 | if (strncmp(pszText, apszPrefix[iP], strlen(apszPrefix[iP])) == 0) |
| 65 | { |
| 66 | pszText += strlen(apszPrefix[iP]); |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (*pszText != '{') |
| 72 | return false; |
| 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | /************************************************************************/ |
| 78 | /* GetTopLevelType() */ |
| 79 | /************************************************************************/ |
| 80 | |
| 81 | static stdcxx . . $ std/::string GetTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).(const char *pszText) |
| 82 | { |
| 83 | if (!strstr(pszText, "\"type\"")) |
| 84 | return stdcxx . . $ std/::string(); |
| 85 | |
| 86 | SkipUTF8BOMcxx . . $ SkipUTF8BOM(30ad0281919313c0).(pszText); |
| 87 | |
| 88 | struct MyParsercxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser# : public CPLJSonStreamingParsercxx . . $ CPLJSonStreamingParser# |
| 89 | { |
| 90 | stdcxx . . $ std/::string m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel.{}; |
| 91 | bool m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType. = false; |
| 92 | stdcxx . . $ std/::string m_osTopLevelTypeValuecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osTopLevelTypeValue.{}; |
| 93 | |
| 94 | void StartObjectMembercxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#StartObjectMember(c8024318075daf50).(stdcxx . . $ std/::string_view sKey) override |
| 95 | { |
| 96 | m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType. = false; |
| 97 | if (sKey == "type" && m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel. == "{") |
| 98 | { |
| 99 | m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType. = true; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void Stringcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#String(c8024318075daf50).(stdcxx . . $ std/::string_view sValue) override |
| 104 | { |
| 105 | if (m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType.) |
| 106 | { |
| 107 | m_osTopLevelTypeValuecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osTopLevelTypeValue. = sValue; |
| 108 | StopParsingcxx . . $ CPLJSonStreamingParser#StopParsing(49f6e7a06ebc5aa8).(); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | void StartObjectcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#StartObject(49f6e7a06ebc5aa8).() override |
| 113 | { |
| 114 | m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel. += '{'; |
| 115 | m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType. = false; |
| 116 | } |
| 117 | |
| 118 | void EndObjectcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#EndObject(49f6e7a06ebc5aa8).() override |
| 119 | { |
| 120 | if (!m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel..empty()) |
| 121 | m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel..pop_back(); |
| 122 | m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType. = false; |
| 123 | } |
| 124 | |
| 125 | void StartArraycxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#StartArray(49f6e7a06ebc5aa8).() override |
| 126 | { |
| 127 | m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel. += '['; |
| 128 | m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType. = false; |
| 129 | } |
| 130 | |
| 131 | void EndArraycxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#EndArray(49f6e7a06ebc5aa8).() override |
| 132 | { |
| 133 | if (!m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel..empty()) |
| 134 | m_osLevelcxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osLevel..pop_back(); |
| 135 | m_bInTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_bInTopLevelType. = false; |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | MyParsercxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser# oParser; |
| 140 | oParser.Parsecxx . . $ CPLJSonStreamingParser#Parse(3f475e4eb84a56cf).(stdcxx . . $ std/::string_view(pszText), true); |
| 141 | return oParser.m_osTopLevelTypeValuecxx . . $ GetTopLevelType(d06bf7adff8c4caf).MyParser#m_osTopLevelTypeValue.; |
| 142 | } |
| 143 | |
| 144 | /************************************************************************/ |
| 145 | /* GetCompactJSon() */ |
| 146 | /************************************************************************/ |
| 147 | |
| 148 | static CPLString GetCompactJSoncxx . . $ GetCompactJSon(e75ce93c20d007bf).(const char *pszText, size_t nMaxSize) |
| 149 | { |
| 150 | /* Skip UTF-8 BOM (#5630) */ |
| 151 | const GBytecxx . . $ GByte# *pabyData = reinterpret_cast<const GBytecxx . . $ GByte# *>(pszText); |
| 152 | if (pabyData[0] == 0xEF && pabyData[1] == 0xBB && pabyData[2] == 0xBF) |
| 153 | pszText += 3; |
| 154 | |
| 155 | CPLString osWithoutSpace; |
| 156 | bool bInString = false; |
| 157 | for (int i = 0; pszText[i] != '\0' && osWithoutSpace.size() < nMaxSize; i++) |
| 158 | { |
| 159 | if (bInString) |
| 160 | { |
| 161 | if (pszText[i] == '\\') |
| 162 | { |
| 163 | osWithoutSpace += pszText[i]; |
| 164 | if (pszText[i + 1] == '\0') |
| 165 | break; |
| 166 | osWithoutSpace += pszText[i + 1]; |
| 167 | i++; |
| 168 | } |
| 169 | else if (pszText[i] == '"') |
| 170 | { |
| 171 | bInString = false; |
| 172 | osWithoutSpace += '"'; |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | osWithoutSpace += pszText[i]; |
| 177 | } |
| 178 | } |
| 179 | else if (pszText[i] == '"') |
| 180 | { |
| 181 | bInString = true; |
| 182 | osWithoutSpace += '"'; |
| 183 | } |
| 184 | else if (!isspace(static_cast<unsigned char>(pszText[i]))) |
| 185 | { |
| 186 | osWithoutSpace += pszText[i]; |
| 187 | } |
| 188 | } |
| 189 | return osWithoutSpace; |
| 190 | } |
| 191 | |
| 192 | /************************************************************************/ |
| 193 | /* IsGeoJSONLikeObject() */ |
| 194 | /************************************************************************/ |
| 195 | |
| 196 | static bool IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).(const char *pszText, bool &bMightBeSequence, |
| 197 | bool &bReadMoreBytes, GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo, |
| 198 | const char *pszExpectedDriverName) |
| 199 | { |
| 200 | bMightBeSequence = false; |
| 201 | bReadMoreBytes = false; |
| 202 | |
| 203 | if (!IsJSONObjectcxx . . $ IsJSONObject(c5f7da30cbc0f4e9).(pszText)) |
| 204 | return false; |
| 205 | |
| 206 | const stdcxx . . $ std/::string osTopLevelType = GetTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).(pszText); |
| 207 | if (osTopLevelType == "Topology") |
| 208 | return false; |
| 209 | |
| 210 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).(pszExpectedDriverName) && |
| 211 | GDALGetDriverByName(pszExpectedDriverName)) |
| 212 | { |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | if ((!poOpenInfo->papszAllowedDriverscxx . . $ GDALOpenInfo#papszAllowedDrivers. || |
| 217 | CSLFindString(poOpenInfo->papszAllowedDriverscxx . . $ GDALOpenInfo#papszAllowedDrivers., "JSONFG") >= 0) && |
| 218 | GDALGetDriverByName("JSONFG") && JSONFGIsObjectcxx . . $ JSONFGIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 219 | { |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | if (osTopLevelType == "FeatureCollection") |
| 224 | { |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | const stdcxx . . $ std/::string osWithoutSpace = GetCompactJSoncxx . . $ GetCompactJSon(e75ce93c20d007bf).(pszText, strlen(pszText)); |
| 229 | if (osWithoutSpace.find("{\"features\":[") == 0 && |
| 230 | osWithoutSpace.find(szESRIJSonFeaturesGeometryRingscxx . . $ szESRIJSonFeaturesGeometryRings.) == |
| 231 | stdcxx . . $ std/::string::npos && |
| 232 | osWithoutSpace.find(szESRIJSonFeaturesAttributescxx . . $ szESRIJSonFeaturesAttributes.) == stdcxx . . $ std/::string::npos) |
| 233 | { |
| 234 | return true; |
| 235 | } |
| 236 | |
| 237 | // See |
| 238 | // https://raw.githubusercontent.com/icepack/icepack-data/master/meshes/larsen/larsen_inflow.geojson |
| 239 | // "{"crs":...,"features":[..." |
| 240 | // or |
| 241 | // https://gist.githubusercontent.com/NiklasDallmann/27e339dd78d1942d524fbcd179f9fdcf/raw/527a8319d75a9e29446a32a19e4c902213b0d668/42XR9nLAh8Poh9Xmniqh3Bs9iisNm74mYMC56v3Wfyo=_isochrones_fails.geojson |
| 242 | // "{"bbox":...,"features":[..." |
| 243 | if (osWithoutSpace.find(",\"features\":[") != stdcxx . . $ std/::string::npos) |
| 244 | { |
| 245 | return !ESRIJSONIsObjectcxx . . $ ESRIJSONIsObject(f1b58c377e804f9b).(pszText, poOpenInfo); |
| 246 | } |
| 247 | |
| 248 | // See https://github.com/OSGeo/gdal/issues/2720 |
| 249 | if (osWithoutSpace.find("{\"coordinates\":[") == 0 || |
| 250 | // and https://github.com/OSGeo/gdal/issues/2787 |
| 251 | osWithoutSpace.find("{\"geometry\":{\"coordinates\":[") == 0 || |
| 252 | // and https://github.com/qgis/QGIS/issues/61266 |
| 253 | osWithoutSpace.find( |
| 254 | "{\"geometry\":{\"type\":\"Point\",\"coordinates\":[") == 0 || |
| 255 | osWithoutSpace.find( |
| 256 | "{\"geometry\":{\"type\":\"LineString\",\"coordinates\":[") == 0 || |
| 257 | osWithoutSpace.find( |
| 258 | "{\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[") == 0 || |
| 259 | osWithoutSpace.find( |
| 260 | "{\"geometry\":{\"type\":\"MultiPoint\",\"coordinates\":[") == 0 || |
| 261 | osWithoutSpace.find( |
| 262 | "{\"geometry\":{\"type\":\"MultiLineString\",\"coordinates\":[") == |
| 263 | 0 || |
| 264 | osWithoutSpace.find( |
| 265 | "{\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[") == |
| 266 | 0 || |
| 267 | osWithoutSpace.find("{\"geometry\":{\"type\":\"GeometryCollection\"," |
| 268 | "\"geometries\":[") == 0) |
| 269 | { |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | if (osTopLevelType == "Feature" || osTopLevelType == "Point" || |
| 274 | osTopLevelType == "LineString" || osTopLevelType == "Polygon" || |
| 275 | osTopLevelType == "MultiPoint" || osTopLevelType == "MultiLineString" || |
| 276 | osTopLevelType == "MultiPolygon" || |
| 277 | osTopLevelType == "GeometryCollection") |
| 278 | { |
| 279 | bMightBeSequence = true; |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | // See https://github.com/OSGeo/gdal/issues/3280 |
| 284 | if (osWithoutSpace.find("{\"properties\":{") == 0) |
| 285 | { |
| 286 | bMightBeSequence = true; |
| 287 | bReadMoreBytes = true; |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | return false; |
| 292 | } |
| 293 | |
| 294 | static bool IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(a1714b088e2e3661).(const char *pszText, GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo, |
| 295 | const char *pszExpectedDriverName) |
| 296 | { |
| 297 | bool bMightBeSequence; |
| 298 | bool bReadMoreBytes; |
| 299 | return IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).(pszText, bMightBeSequence, bReadMoreBytes, |
| 300 | poOpenInfo, pszExpectedDriverName); |
| 301 | } |
| 302 | |
| 303 | /************************************************************************/ |
| 304 | /* ESRIJSONIsObject() */ |
| 305 | /************************************************************************/ |
| 306 | |
| 307 | bool ESRIJSONIsObjectcxx . . $ ESRIJSONIsObject(f1b58c377e804f9b).(const char *pszText, GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 308 | { |
| 309 | if (!IsJSONObjectcxx . . $ IsJSONObject(c5f7da30cbc0f4e9).(pszText)) |
| 310 | return false; |
| 311 | |
| 312 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("ESRIJSON") && |
| 313 | GDALGetDriverByName("ESRIJSON")) |
| 314 | { |
| 315 | return true; |
| 316 | } |
| 317 | |
| 318 | if ( // ESRI Json geometry |
| 319 | (strstr(pszText, "\"geometryType\"") != nullptr && |
| 320 | strstr(pszText, "\"esriGeometry") != nullptr) |
| 321 | |
| 322 | // ESRI Json "FeatureCollection" |
| 323 | || strstr(pszText, "\"fieldAliases\"") != nullptr |
| 324 | |
| 325 | // ESRI Json "FeatureCollection" |
| 326 | || (strstr(pszText, "\"fields\"") != nullptr && |
| 327 | strstr(pszText, "\"esriFieldType") != nullptr)) |
| 328 | { |
| 329 | return true; |
| 330 | } |
| 331 | |
| 332 | const stdcxx . . $ std/::string osWithoutSpace = GetCompactJSoncxx . . $ GetCompactJSon(e75ce93c20d007bf).(pszText, strlen(pszText)); |
| 333 | if (osWithoutSpace.find(szESRIJSonFeaturesGeometryRingscxx . . $ szESRIJSonFeaturesGeometryRings.) != |
| 334 | stdcxx . . $ std/::string::npos || |
| 335 | osWithoutSpace.find(szESRIJSonFeaturesAttributescxx . . $ szESRIJSonFeaturesAttributes.) != |
| 336 | stdcxx . . $ std/::string::npos || |
| 337 | osWithoutSpace.find("\"spatialReference\":{\"wkid\":") != |
| 338 | stdcxx . . $ std/::string::npos) |
| 339 | { |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | return false; |
| 344 | } |
| 345 | |
| 346 | /************************************************************************/ |
| 347 | /* TopoJSONIsObject() */ |
| 348 | /************************************************************************/ |
| 349 | |
| 350 | bool TopoJSONIsObjectcxx . . $ TopoJSONIsObject(f1b58c377e804f9b).(const char *pszText, GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 351 | { |
| 352 | if (!IsJSONObjectcxx . . $ IsJSONObject(c5f7da30cbc0f4e9).(pszText)) |
| 353 | return false; |
| 354 | |
| 355 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("TopoJSON") && |
| 356 | GDALGetDriverByName("TopoJSON")) |
| 357 | { |
| 358 | return true; |
| 359 | } |
| 360 | |
| 361 | return GetTopLevelTypecxx . . $ GetTopLevelType(d06bf7adff8c4caf).(pszText) == "Topology"; |
| 362 | } |
| 363 | |
| 364 | /************************************************************************/ |
| 365 | /* IsLikelyNewlineSequenceGeoJSON() */ |
| 366 | /************************************************************************/ |
| 367 | |
| 368 | static GDALIdentifyEnumcxx . . $ GDALIdentifyEnum# |
| 369 | IsLikelyNewlineSequenceGeoJSONcxx . . $ IsLikelyNewlineSequenceGeoJSON(896405f530db0e57).(VSILFILE *fpL, const GBytecxx . . $ GByte# *pabyHeader, |
| 370 | const char *pszFileContent) |
| 371 | { |
| 372 | const size_t nBufferSize = 4096 * 10; |
| 373 | stdcxx . . $ std/::vector<GBytecxx . . $ GByte#> abyBuffer; |
| 374 | abyBuffer.resize(nBufferSize + 1); |
| 375 | |
| 376 | int nCurlLevel = 0; |
| 377 | bool bInString = false; |
| 378 | bool bLastIsEscape = false; |
| 379 | bool bFirstIter = true; |
| 380 | bool bEOLFound = false; |
| 381 | int nCountObject = 0; |
| 382 | while (true) |
| 383 | { |
| 384 | size_t nRead; |
| 385 | bool bEnd = false; |
| 386 | if (bFirstIter) |
| 387 | { |
| 388 | const char *pszText = |
| 389 | pszFileContent ? pszFileContent |
| 390 | : reinterpret_cast<const char *>(pabyHeader); |
| 391 | assertcxx . . $ `<external>/4398592474888995393/assert.h:137:11`!(pszText); |
| 392 | nRead = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(strlen(pszText), nBufferSize); |
| 393 | memcpy(abyBuffer.data(), pszText, nRead); |
| 394 | bFirstIter = false; |
| 395 | if (fpL) |
| 396 | { |
| 397 | VSIFSeekL(fpL, static_cast<vsi_l_offset>(nRead), SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`!); |
| 398 | } |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | nRead = VSIFReadL(abyBuffer.data(), 1, nBufferSize, fpL); |
| 403 | bEnd = nRead < nBufferSize; |
| 404 | } |
| 405 | for (size_t i = 0; i < nRead; i++) |
| 406 | { |
| 407 | if (nCurlLevel == 0) |
| 408 | { |
| 409 | if (abyBuffer[i] == '{') |
| 410 | { |
| 411 | nCountObject++; |
| 412 | if (nCountObject == 2) |
| 413 | { |
| 414 | break; |
| 415 | } |
| 416 | nCurlLevel++; |
| 417 | } |
| 418 | else if (nCountObject == 1 && abyBuffer[i] == '\n') |
| 419 | { |
| 420 | bEOLFound = true; |
| 421 | } |
| 422 | else if (!isspace(static_cast<unsigned char>(abyBuffer[i]))) |
| 423 | { |
| 424 | return GDAL_IDENTIFY_FALSEcxx . . $ GDAL_IDENTIFY_FALSE.; |
| 425 | } |
| 426 | } |
| 427 | else if (bInString) |
| 428 | { |
| 429 | if (bLastIsEscape) |
| 430 | { |
| 431 | bLastIsEscape = false; |
| 432 | } |
| 433 | else if (abyBuffer[i] == '\\') |
| 434 | { |
| 435 | bLastIsEscape = true; |
| 436 | } |
| 437 | else if (abyBuffer[i] == '"') |
| 438 | { |
| 439 | bInString = false; |
| 440 | } |
| 441 | } |
| 442 | else if (abyBuffer[i] == '"') |
| 443 | { |
| 444 | bInString = true; |
| 445 | } |
| 446 | else if (abyBuffer[i] == '{') |
| 447 | { |
| 448 | nCurlLevel++; |
| 449 | } |
| 450 | else if (abyBuffer[i] == '}') |
| 451 | { |
| 452 | nCurlLevel--; |
| 453 | } |
| 454 | } |
| 455 | if (!fpL || bEnd || nCountObject == 2) |
| 456 | break; |
| 457 | } |
| 458 | if (bEOLFound && nCountObject == 2) |
| 459 | return GDAL_IDENTIFY_TRUEcxx . . $ GDAL_IDENTIFY_TRUE.; |
| 460 | return GDAL_IDENTIFY_UNKNOWNcxx . . $ GDAL_IDENTIFY_UNKNOWN.; |
| 461 | } |
| 462 | |
| 463 | /************************************************************************/ |
| 464 | /* GeoJSONFileIsObject() */ |
| 465 | /************************************************************************/ |
| 466 | |
| 467 | static bool GeoJSONFileIsObjectcxx . . $ GeoJSONFileIsObject(8e59e7504f0850f4).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 468 | { |
| 469 | // By default read first 6000 bytes. |
| 470 | // 6000 was chosen as enough bytes to |
| 471 | // enable all current tests to pass. |
| 472 | |
| 473 | if (poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL. == nullptr || !poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(6000)) |
| 474 | { |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | bool bMightBeSequence = false; |
| 479 | bool bReadMoreBytes = false; |
| 480 | if (!IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).( |
| 481 | reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.), |
| 482 | bMightBeSequence, bReadMoreBytes, poOpenInfo, "GeoJSON")) |
| 483 | { |
| 484 | if (!(bReadMoreBytes && poOpenInfo->nHeaderBytescxx . . $ GDALOpenInfo#nHeaderBytes. >= 6000 && |
| 485 | poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(1000 * 1000) && |
| 486 | !IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).( |
| 487 | reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.), |
| 488 | bMightBeSequence, bReadMoreBytes, poOpenInfo, "GeoJSON"))) |
| 489 | { |
| 490 | return false; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | return !(bMightBeSequence && IsLikelyNewlineSequenceGeoJSONcxx . . $ IsLikelyNewlineSequenceGeoJSON(896405f530db0e57).( |
| 495 | poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL., poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader., |
| 496 | nullptr) == GDAL_IDENTIFY_TRUEcxx . . $ GDAL_IDENTIFY_TRUE.); |
| 497 | } |
| 498 | |
| 499 | /************************************************************************/ |
| 500 | /* GeoJSONIsObject() */ |
| 501 | /************************************************************************/ |
| 502 | |
| 503 | bool GeoJSONIsObjectcxx . . $ GeoJSONIsObject(f1b58c377e804f9b).(const char *pszText, GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 504 | { |
| 505 | bool bMightBeSequence = false; |
| 506 | bool bReadMoreBytes = false; |
| 507 | if (!IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).(pszText, bMightBeSequence, bReadMoreBytes, |
| 508 | poOpenInfo, "GeoJSON")) |
| 509 | { |
| 510 | return false; |
| 511 | } |
| 512 | |
| 513 | return !(bMightBeSequence && |
| 514 | IsLikelyNewlineSequenceGeoJSONcxx . . $ IsLikelyNewlineSequenceGeoJSON(896405f530db0e57).(nullptr, nullptr, pszText) == |
| 515 | GDAL_IDENTIFY_TRUEcxx . . $ GDAL_IDENTIFY_TRUE.); |
| 516 | } |
| 517 | |
| 518 | /************************************************************************/ |
| 519 | /* GeoJSONSeqFileIsObject() */ |
| 520 | /************************************************************************/ |
| 521 | |
| 522 | static bool GeoJSONSeqFileIsObjectcxx . . $ GeoJSONSeqFileIsObject(8e59e7504f0850f4).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 523 | { |
| 524 | // By default read first 6000 bytes. |
| 525 | // 6000 was chosen as enough bytes to |
| 526 | // enable all current tests to pass. |
| 527 | |
| 528 | if (poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL. == nullptr || !poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(6000)) |
| 529 | { |
| 530 | return false; |
| 531 | } |
| 532 | |
| 533 | const char *pszText = |
| 534 | reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.); |
| 535 | if (pszText[0] == '\x1e') |
| 536 | return IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(a1714b088e2e3661).(pszText + 1, poOpenInfo, "GeoJSONSeq"); |
| 537 | |
| 538 | bool bMightBeSequence = false; |
| 539 | bool bReadMoreBytes = false; |
| 540 | if (!IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).(pszText, bMightBeSequence, bReadMoreBytes, |
| 541 | poOpenInfo, "GeoJSONSeq")) |
| 542 | { |
| 543 | if (!(bReadMoreBytes && poOpenInfo->nHeaderBytescxx . . $ GDALOpenInfo#nHeaderBytes. >= 6000 && |
| 544 | poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(1000 * 1000) && |
| 545 | IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).( |
| 546 | reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.), |
| 547 | bMightBeSequence, bReadMoreBytes, poOpenInfo, "GeoJSONSeq"))) |
| 548 | { |
| 549 | return false; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("GeoJSONSeq") && |
| 554 | IsLikelyNewlineSequenceGeoJSONcxx . . $ IsLikelyNewlineSequenceGeoJSON(896405f530db0e57).(poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL., poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader., |
| 555 | nullptr) != GDAL_IDENTIFY_FALSEcxx . . $ GDAL_IDENTIFY_FALSE. && |
| 556 | GDALGetDriverByName("GeoJSONSeq")) |
| 557 | { |
| 558 | return true; |
| 559 | } |
| 560 | |
| 561 | return bMightBeSequence && IsLikelyNewlineSequenceGeoJSONcxx . . $ IsLikelyNewlineSequenceGeoJSON(896405f530db0e57).( |
| 562 | poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL., poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader., |
| 563 | nullptr) == GDAL_IDENTIFY_TRUEcxx . . $ GDAL_IDENTIFY_TRUE.; |
| 564 | } |
| 565 | |
| 566 | bool GeoJSONSeqIsObjectcxx . . $ GeoJSONSeqIsObject(f1b58c377e804f9b).(const char *pszText, GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 567 | { |
| 568 | if (pszText[0] == '\x1e') |
| 569 | return IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(a1714b088e2e3661).(pszText + 1, poOpenInfo, "GeoJSONSeq"); |
| 570 | |
| 571 | bool bMightBeSequence = false; |
| 572 | bool bReadMoreBytes = false; |
| 573 | if (!IsGeoJSONLikeObjectcxx . . $ IsGeoJSONLikeObject(94750f8a743fa7e0).(pszText, bMightBeSequence, bReadMoreBytes, |
| 574 | poOpenInfo, "GeoJSONSeq")) |
| 575 | { |
| 576 | return false; |
| 577 | } |
| 578 | |
| 579 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("GeoJSONSeq") && |
| 580 | IsLikelyNewlineSequenceGeoJSONcxx . . $ IsLikelyNewlineSequenceGeoJSON(896405f530db0e57).(nullptr, nullptr, pszText) != |
| 581 | GDAL_IDENTIFY_FALSEcxx . . $ GDAL_IDENTIFY_FALSE. && |
| 582 | GDALGetDriverByName("GeoJSONSeq")) |
| 583 | { |
| 584 | return true; |
| 585 | } |
| 586 | |
| 587 | return bMightBeSequence && |
| 588 | IsLikelyNewlineSequenceGeoJSONcxx . . $ IsLikelyNewlineSequenceGeoJSON(896405f530db0e57).(nullptr, nullptr, pszText) == |
| 589 | GDAL_IDENTIFY_TRUEcxx . . $ GDAL_IDENTIFY_TRUE.; |
| 590 | } |
| 591 | |
| 592 | /************************************************************************/ |
| 593 | /* JSONFGFileIsObject() */ |
| 594 | /************************************************************************/ |
| 595 | |
| 596 | static bool JSONFGFileIsObjectcxx . . $ JSONFGFileIsObject(8e59e7504f0850f4).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 597 | { |
| 598 | // 6000 somewhat arbitrary. Based on other JSON-like drivers |
| 599 | if (poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL. == nullptr || !poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(6000)) |
| 600 | { |
| 601 | return false; |
| 602 | } |
| 603 | |
| 604 | const char *pszText = |
| 605 | reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.); |
| 606 | return JSONFGIsObjectcxx . . $ JSONFGIsObject(f1b58c377e804f9b).(pszText, poOpenInfo); |
| 607 | } |
| 608 | |
| 609 | bool JSONFGIsObjectcxx . . $ JSONFGIsObject(f1b58c377e804f9b).(const char *pszText, GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 610 | { |
| 611 | if (!IsJSONObjectcxx . . $ IsJSONObject(c5f7da30cbc0f4e9).(pszText)) |
| 612 | return false; |
| 613 | |
| 614 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("JSONFG") && |
| 615 | GDALGetDriverByName("JSONFG")) |
| 616 | { |
| 617 | return true; |
| 618 | } |
| 619 | |
| 620 | const stdcxx . . $ std/::string osWithoutSpace = GetCompactJSoncxx . . $ GetCompactJSon(e75ce93c20d007bf).(pszText, strlen(pszText)); |
| 621 | |
| 622 | // In theory, conformsTo should be required, but let be lax... |
| 623 | if (osWithoutSpace.find("conformsTo") != stdcxx . . $ std/::string::npos) |
| 624 | { |
| 625 | if (osWithoutSpace.find("\"[ogc-json-fg-1-") != stdcxx . . $ std/::string::npos || |
| 626 | osWithoutSpace.find("\"http://www.opengis.net/spec/json-fg-1/") != |
| 627 | stdcxx . . $ std/::string::npos || |
| 628 | osWithoutSpace.find( |
| 629 | "\"http:\\/\\/www.opengis.net\\/spec\\/json-fg-1\\/") != |
| 630 | stdcxx . . $ std/::string::npos) |
| 631 | { |
| 632 | return true; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | if (osWithoutSpace.find("\"place\":{\"type\":") != stdcxx . . $ std/::string::npos || |
| 637 | osWithoutSpace.find("\"place\":{\"coordinates\":") != |
| 638 | stdcxx . . $ std/::string::npos || |
| 639 | osWithoutSpace.find("\"time\":{\"date\":") != stdcxx . . $ std/::string::npos || |
| 640 | osWithoutSpace.find("\"time\":{\"timestamp\":") != stdcxx . . $ std/::string::npos || |
| 641 | osWithoutSpace.find("\"time\":{\"interval\":") != stdcxx . . $ std/::string::npos || |
| 642 | osWithoutSpace.find("\"type\":\"CircularString\"") != |
| 643 | stdcxx . . $ std/::string::npos || |
| 644 | osWithoutSpace.find("\"type\":\"CompoundCurve\"") != |
| 645 | stdcxx . . $ std/::string::npos || |
| 646 | osWithoutSpace.find("\"type\":\"CurvePolygon\"") != stdcxx . . $ std/::string::npos || |
| 647 | osWithoutSpace.find("\"type\":\"MultiCurve\"") != stdcxx . . $ std/::string::npos || |
| 648 | osWithoutSpace.find("\"type\":\"MultiSurface\"") != stdcxx . . $ std/::string::npos) |
| 649 | { |
| 650 | return true; |
| 651 | } |
| 652 | |
| 653 | if (osWithoutSpace.find("\"coordRefSys\":") != stdcxx . . $ std/::string::npos || |
| 654 | osWithoutSpace.find("\"featureType\":") != stdcxx . . $ std/::string::npos) |
| 655 | { |
| 656 | // Check that coordRefSys and/or featureType are either at the |
| 657 | // FeatureCollection or Feature level |
| 658 | struct MyParsercxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser# : public CPLJSonStreamingParsercxx . . $ CPLJSonStreamingParser# |
| 659 | { |
| 660 | bool m_bFoundJSONFGFeatureTypecxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGFeatureType. = false; |
| 661 | bool m_bFoundJSONFGCoordrefSyscxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGCoordrefSys. = false; |
| 662 | stdcxx . . $ std/::string m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel.{}; |
| 663 | |
| 664 | void StartObjectMembercxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#StartObjectMember(c8024318075daf50).(stdcxx . . $ std/::string_view sKey) override |
| 665 | { |
| 666 | if (sKey == "featureType") |
| 667 | { |
| 668 | m_bFoundJSONFGFeatureTypecxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGFeatureType. = |
| 669 | (m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel. == "{" || // At FeatureCollection level |
| 670 | m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel. == "{[{"); // At Feature level |
| 671 | if (m_bFoundJSONFGFeatureTypecxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGFeatureType.) |
| 672 | StopParsingcxx . . $ CPLJSonStreamingParser#StopParsing(49f6e7a06ebc5aa8).(); |
| 673 | } |
| 674 | else if (sKey == "coordRefSys") |
| 675 | { |
| 676 | m_bFoundJSONFGCoordrefSyscxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGCoordrefSys. = |
| 677 | (m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel. == "{" || // At FeatureCollection level |
| 678 | m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel. == "{[{"); // At Feature level |
| 679 | if (m_bFoundJSONFGCoordrefSyscxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGCoordrefSys.) |
| 680 | StopParsingcxx . . $ CPLJSonStreamingParser#StopParsing(49f6e7a06ebc5aa8).(); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | void StartObjectcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#StartObject(49f6e7a06ebc5aa8).() override |
| 685 | { |
| 686 | m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel. += '{'; |
| 687 | } |
| 688 | |
| 689 | void EndObjectcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#EndObject(49f6e7a06ebc5aa8).() override |
| 690 | { |
| 691 | if (!m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel..empty()) |
| 692 | m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel..pop_back(); |
| 693 | } |
| 694 | |
| 695 | void StartArraycxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#StartArray(49f6e7a06ebc5aa8).() override |
| 696 | { |
| 697 | m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel. += '['; |
| 698 | } |
| 699 | |
| 700 | void EndArraycxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#EndArray(49f6e7a06ebc5aa8).() override |
| 701 | { |
| 702 | if (!m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel..empty()) |
| 703 | m_osLevelcxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_osLevel..pop_back(); |
| 704 | } |
| 705 | }; |
| 706 | |
| 707 | MyParsercxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser# oParser; |
| 708 | oParser.Parsecxx . . $ CPLJSonStreamingParser#Parse(3f475e4eb84a56cf).(stdcxx . . $ std/::string_view(pszText), true); |
| 709 | if (oParser.m_bFoundJSONFGFeatureTypecxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGFeatureType. || |
| 710 | oParser.m_bFoundJSONFGCoordrefSyscxx . . $ JSONFGIsObject(f1b58c377e804f9b).MyParser#m_bFoundJSONFGCoordrefSys.) |
| 711 | { |
| 712 | return true; |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | return false; |
| 717 | } |
| 718 | |
| 719 | /************************************************************************/ |
| 720 | /* IsLikelyESRIJSONURL() */ |
| 721 | /************************************************************************/ |
| 722 | |
| 723 | static bool IsLikelyESRIJSONURLcxx . . $ IsLikelyESRIJSONURL(c5f7da30cbc0f4e9).(const char *pszURL) |
| 724 | { |
| 725 | // URLs with f=json are strong candidates for ESRI JSON services |
| 726 | // except if they have "/items?", in which case they are likely OAPIF |
| 727 | return (strstr(pszURL, "f=json") != nullptr || |
| 728 | strstr(pszURL, "f=pjson") != nullptr || |
| 729 | strstr(pszURL, "resultRecordCount=") != nullptr) && |
| 730 | strstr(pszURL, "/items?") == nullptr; |
| 731 | } |
| 732 | |
| 733 | /************************************************************************/ |
| 734 | /* GeoJSONGetSourceType() */ |
| 735 | /************************************************************************/ |
| 736 | |
| 737 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# GeoJSONGetSourceTypecxx . . $ GeoJSONGetSourceType(65c02b8a52088083).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 738 | { |
| 739 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# srcType = eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 740 | |
| 741 | // NOTE: Sometimes URL ends with .geojson token, for example |
| 742 | // http://example/path/2232.geojson |
| 743 | // It's important to test beginning of source first. |
| 744 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GEOJSON:http://") || |
| 745 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GEOJSON:https://") || |
| 746 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GEOJSON:ftp://")) |
| 747 | { |
| 748 | srcType = eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 749 | } |
| 750 | else if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "http://") || |
| 751 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "https://") || |
| 752 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "ftp://")) |
| 753 | { |
| 754 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("GeoJSON")) |
| 755 | { |
| 756 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 757 | } |
| 758 | if ((strstr(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., "SERVICE=WFS") || |
| 759 | strstr(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., "service=WFS") || |
| 760 | strstr(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., "service=wfs")) && |
| 761 | !strstr(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., "json")) |
| 762 | { |
| 763 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 764 | } |
| 765 | if (IsLikelyESRIJSONURLcxx . . $ IsLikelyESRIJSONURL(c5f7da30cbc0f4e9).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename.)) |
| 766 | { |
| 767 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 768 | } |
| 769 | srcType = eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 770 | } |
| 771 | else if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GeoJSON:")) |
| 772 | { |
| 773 | VSIStatBufL sStat; |
| 774 | if (VSIStatL(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("GeoJSON:"), &sStat) == 0) |
| 775 | { |
| 776 | return eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 777 | } |
| 778 | const char *pszText = poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("GeoJSON:"); |
| 779 | if (GeoJSONIsObjectcxx . . $ GeoJSONIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 780 | return eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 781 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 782 | } |
| 783 | else if (GeoJSONIsObjectcxx . . $ GeoJSONIsObject(f1b58c377e804f9b).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., poOpenInfo)) |
| 784 | { |
| 785 | srcType = eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 786 | } |
| 787 | else if (GeoJSONFileIsObjectcxx . . $ GeoJSONFileIsObject(8e59e7504f0850f4).(poOpenInfo)) |
| 788 | { |
| 789 | srcType = eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 790 | } |
| 791 | |
| 792 | return srcType; |
| 793 | } |
| 794 | |
| 795 | /************************************************************************/ |
| 796 | /* ESRIJSONDriverGetSourceType() */ |
| 797 | /************************************************************************/ |
| 798 | |
| 799 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# ESRIJSONDriverGetSourceTypecxx . . $ ESRIJSONDriverGetSourceType(65c02b8a52088083).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 800 | { |
| 801 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "ESRIJSON:http://") || |
| 802 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "ESRIJSON:https://") || |
| 803 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "ESRIJSON:ftp://")) |
| 804 | { |
| 805 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 806 | } |
| 807 | else if (STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(poOpenInfo->pszFilename, "http://") || |
| 808 | STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(poOpenInfo->pszFilename, "https://") || |
| 809 | STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(poOpenInfo->pszFilename, "ftp://")) |
| 810 | { |
| 811 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("ESRIJSON")) |
| 812 | { |
| 813 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 814 | } |
| 815 | if (IsLikelyESRIJSONURLcxx . . $ IsLikelyESRIJSONURL(c5f7da30cbc0f4e9).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename.)) |
| 816 | { |
| 817 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 818 | } |
| 819 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 820 | } |
| 821 | |
| 822 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "ESRIJSON:")) |
| 823 | { |
| 824 | VSIStatBufL sStat; |
| 825 | if (VSIStatL(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("ESRIJSON:"), &sStat) == |
| 826 | 0) |
| 827 | { |
| 828 | return eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 829 | } |
| 830 | const char *pszText = poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("ESRIJSON:"); |
| 831 | if (ESRIJSONIsObjectcxx . . $ ESRIJSONIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 832 | return eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 833 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 834 | } |
| 835 | |
| 836 | if (poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL. == nullptr) |
| 837 | { |
| 838 | const char *pszText = poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename.; |
| 839 | if (ESRIJSONIsObjectcxx . . $ ESRIJSONIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 840 | return eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 841 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 842 | } |
| 843 | |
| 844 | // By default read first 6000 bytes. |
| 845 | // 6000 was chosen as enough bytes to |
| 846 | // enable all current tests to pass. |
| 847 | if (!poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(6000)) |
| 848 | { |
| 849 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 850 | } |
| 851 | |
| 852 | if (poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader. != nullptr && |
| 853 | ESRIJSONIsObjectcxx . . $ ESRIJSONIsObject(f1b58c377e804f9b).(reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.), |
| 854 | poOpenInfo)) |
| 855 | { |
| 856 | return eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 857 | } |
| 858 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 859 | } |
| 860 | |
| 861 | /************************************************************************/ |
| 862 | /* TopoJSONDriverGetSourceType() */ |
| 863 | /************************************************************************/ |
| 864 | |
| 865 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# TopoJSONDriverGetSourceTypecxx . . $ TopoJSONDriverGetSourceType(65c02b8a52088083).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 866 | { |
| 867 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "TopoJSON:http://") || |
| 868 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "TopoJSON:https://") || |
| 869 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "TopoJSON:ftp://")) |
| 870 | { |
| 871 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 872 | } |
| 873 | else if (STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(poOpenInfo->pszFilename, "http://") || |
| 874 | STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(poOpenInfo->pszFilename, "https://") || |
| 875 | STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(poOpenInfo->pszFilename, "ftp://")) |
| 876 | { |
| 877 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("TOPOJSON")) |
| 878 | { |
| 879 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 880 | } |
| 881 | if (IsLikelyESRIJSONURLcxx . . $ IsLikelyESRIJSONURL(c5f7da30cbc0f4e9).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename.)) |
| 882 | { |
| 883 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 884 | } |
| 885 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 886 | } |
| 887 | |
| 888 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "TopoJSON:")) |
| 889 | { |
| 890 | VSIStatBufL sStat; |
| 891 | if (VSIStatL(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("TopoJSON:"), &sStat) == |
| 892 | 0) |
| 893 | { |
| 894 | return eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 895 | } |
| 896 | const char *pszText = poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("TopoJSON:"); |
| 897 | if (TopoJSONIsObjectcxx . . $ TopoJSONIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 898 | return eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 899 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 900 | } |
| 901 | |
| 902 | if (poOpenInfo->fpLcxx . . $ GDALOpenInfo#fpL. == nullptr) |
| 903 | { |
| 904 | const char *pszText = poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename.; |
| 905 | if (TopoJSONIsObjectcxx . . $ TopoJSONIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 906 | return eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 907 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 908 | } |
| 909 | |
| 910 | // By default read first 6000 bytes. |
| 911 | // 6000 was chosen as enough bytes to |
| 912 | // enable all current tests to pass. |
| 913 | if (!poOpenInfo->TryToIngestcxx . . $ GDALOpenInfo#TryToIngest(7864480464b09eea).(6000)) |
| 914 | { |
| 915 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 916 | } |
| 917 | |
| 918 | if (poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader. != nullptr && |
| 919 | TopoJSONIsObjectcxx . . $ TopoJSONIsObject(f1b58c377e804f9b).(reinterpret_cast<const char *>(poOpenInfo->pabyHeadercxx . . $ GDALOpenInfo#pabyHeader.), |
| 920 | poOpenInfo)) |
| 921 | { |
| 922 | return eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 923 | } |
| 924 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 925 | } |
| 926 | |
| 927 | /************************************************************************/ |
| 928 | /* GeoJSONSeqGetSourceType() */ |
| 929 | /************************************************************************/ |
| 930 | |
| 931 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# GeoJSONSeqGetSourceTypecxx . . $ GeoJSONSeqGetSourceType(65c02b8a52088083).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 932 | { |
| 933 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# srcType = eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 934 | |
| 935 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GEOJSONSeq:http://") || |
| 936 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GEOJSONSeq:https://") || |
| 937 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GEOJSONSeq:ftp://")) |
| 938 | { |
| 939 | srcType = eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 940 | } |
| 941 | else if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "http://") || |
| 942 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "https://") || |
| 943 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "ftp://")) |
| 944 | { |
| 945 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("GeoJSONSeq")) |
| 946 | { |
| 947 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 948 | } |
| 949 | if (IsLikelyESRIJSONURLcxx . . $ IsLikelyESRIJSONURL(c5f7da30cbc0f4e9).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename.)) |
| 950 | { |
| 951 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 952 | } |
| 953 | srcType = eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 954 | } |
| 955 | else if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "GEOJSONSeq:")) |
| 956 | { |
| 957 | VSIStatBufL sStat; |
| 958 | if (VSIStatL(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("GEOJSONSeq:"), &sStat) == |
| 959 | 0) |
| 960 | { |
| 961 | return eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 962 | } |
| 963 | const char *pszText = poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + strlen("GEOJSONSeq:"); |
| 964 | if (GeoJSONSeqIsObjectcxx . . $ GeoJSONSeqIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 965 | return eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 966 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 967 | } |
| 968 | else if (GeoJSONSeqIsObjectcxx . . $ GeoJSONSeqIsObject(f1b58c377e804f9b).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., poOpenInfo)) |
| 969 | { |
| 970 | srcType = eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 971 | } |
| 972 | else if (GeoJSONSeqFileIsObjectcxx . . $ GeoJSONSeqFileIsObject(8e59e7504f0850f4).(poOpenInfo)) |
| 973 | { |
| 974 | srcType = eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 975 | } |
| 976 | |
| 977 | return srcType; |
| 978 | } |
| 979 | |
| 980 | /************************************************************************/ |
| 981 | /* JSONFGDriverGetSourceType() */ |
| 982 | /************************************************************************/ |
| 983 | |
| 984 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# JSONFGDriverGetSourceTypecxx . . $ JSONFGDriverGetSourceType(65c02b8a52088083).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 985 | { |
| 986 | GeoJSONSourceTypecxx . . $ GeoJSONSourceType# srcType = eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 987 | |
| 988 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "JSONFG:http://") || |
| 989 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "JSONFG:https://") || |
| 990 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "JSONFG:ftp://")) |
| 991 | { |
| 992 | srcType = eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 993 | } |
| 994 | else if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "http://") || |
| 995 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "https://") || |
| 996 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "ftp://")) |
| 997 | { |
| 998 | if (poOpenInfo->IsSingleAllowedDrivercxx . . $ GDALOpenInfo#IsSingleAllowedDriver(7d4bdb1abc417636).("JSONFG")) |
| 999 | { |
| 1000 | return eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 1001 | } |
| 1002 | if (IsLikelyESRIJSONURLcxx . . $ IsLikelyESRIJSONURL(c5f7da30cbc0f4e9).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename.)) |
| 1003 | { |
| 1004 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 1005 | } |
| 1006 | srcType = eGeoJSONSourceServicecxx . . $ eGeoJSONSourceService.; |
| 1007 | } |
| 1008 | else if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "JSONFG:")) |
| 1009 | { |
| 1010 | VSIStatBufL sStat; |
| 1011 | const size_t nJSONFGPrefixLen = strlen("JSONFG:"); |
| 1012 | if (VSIStatL(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + nJSONFGPrefixLen, &sStat) == 0) |
| 1013 | { |
| 1014 | return eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 1015 | } |
| 1016 | const char *pszText = poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename. + nJSONFGPrefixLen; |
| 1017 | if (JSONFGIsObjectcxx . . $ JSONFGIsObject(f1b58c377e804f9b).(pszText, poOpenInfo)) |
| 1018 | return eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 1019 | return eGeoJSONSourceUnknowncxx . . $ eGeoJSONSourceUnknown.; |
| 1020 | } |
| 1021 | else if (JSONFGIsObjectcxx . . $ JSONFGIsObject(f1b58c377e804f9b).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., poOpenInfo)) |
| 1022 | { |
| 1023 | srcType = eGeoJSONSourceTextcxx . . $ eGeoJSONSourceText.; |
| 1024 | } |
| 1025 | else if (JSONFGFileIsObjectcxx . . $ JSONFGFileIsObject(8e59e7504f0850f4).(poOpenInfo)) |
| 1026 | { |
| 1027 | srcType = eGeoJSONSourceFilecxx . . $ eGeoJSONSourceFile.; |
| 1028 | } |
| 1029 | |
| 1030 | return srcType; |
| 1031 | } |
| 1032 | |
| 1033 | /************************************************************************/ |
| 1034 | /* GeoJSONStringPropertyToFieldType() */ |
| 1035 | /************************************************************************/ |
| 1036 | |
| 1037 | OGRFieldType GeoJSONStringPropertyToFieldTypecxx . . $ GeoJSONStringPropertyToFieldType(3345d6154f7d975b).(json_object *poObject, |
| 1038 | int &nTZFlag) |
| 1039 | { |
| 1040 | if (poObject == nullptr) |
| 1041 | { |
| 1042 | return OFTString; |
| 1043 | } |
| 1044 | const char *pszStr = json_object_get_string(poObject); |
| 1045 | |
| 1046 | nTZFlag = 0; |
| 1047 | OGRField sWrkField; |
| 1048 | CPLPushErrorHandler(CPLQuietErrorHandler); |
| 1049 | const bool bSuccess = CPL_TO_BOOL(OGRParseDate(pszStr, &sWrkField, 0)); |
| 1050 | CPLPopErrorHandler(); |
| 1051 | CPLErrorReset(); |
| 1052 | if (bSuccess) |
| 1053 | { |
| 1054 | const bool bHasDate = |
| 1055 | strchr(pszStr, '/') != nullptr || strchr(pszStr, '-') != nullptr; |
| 1056 | const bool bHasTime = strchr(pszStr, ':') != nullptr; |
| 1057 | nTZFlag = sWrkField.Date.TZFlag; |
| 1058 | if (bHasDate && bHasTime) |
| 1059 | return OFTDateTime; |
| 1060 | else if (bHasDate) |
| 1061 | return OFTDate; |
| 1062 | else |
| 1063 | return OFTTime; |
| 1064 | // TODO: What if both are false? |
| 1065 | } |
| 1066 | return OFTString; |
| 1067 | } |
| 1068 | |
| 1069 | /************************************************************************/ |
| 1070 | /* GeoJSONHTTPFetchWithContentTypeHeader() */ |
| 1071 | /************************************************************************/ |
| 1072 | |
| 1073 | CPLHTTPResult * |
| 1074 | GeoJSONHTTPFetchWithContentTypeHeadercxx . . $ GeoJSONHTTPFetchWithContentTypeHeader(d64012b975ca0241).(const char *pszURL, bool bCanUsePOST, |
| 1075 | const GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo) |
| 1076 | { |
| 1077 | stdcxx . . $ std/::string osHeaders; |
| 1078 | const char *pszGDAL_HTTP_HEADERS = |
| 1079 | CPLGetConfigOption("GDAL_HTTP_HEADERS", nullptr); |
| 1080 | bool bFoundAcceptHeader = false; |
| 1081 | if (pszGDAL_HTTP_HEADERS) |
| 1082 | { |
| 1083 | bool bHeadersDone = false; |
| 1084 | // Compatibility hack for "HEADERS=Accept: text/plain, application/json" |
| 1085 | if (strstr(pszGDAL_HTTP_HEADERS, "\r\n") == nullptr) |
| 1086 | { |
| 1087 | const char *pszComma = strchr(pszGDAL_HTTP_HEADERS, ','); |
| 1088 | if (pszComma != nullptr && strchr(pszComma, ':') == nullptr) |
| 1089 | { |
| 1090 | osHeaders = pszGDAL_HTTP_HEADERS; |
| 1091 | bFoundAcceptHeader = |
| 1092 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(pszGDAL_HTTP_HEADERS, "Accept:"); |
| 1093 | bHeadersDone = true; |
| 1094 | } |
| 1095 | } |
| 1096 | if (!bHeadersDone) |
| 1097 | { |
| 1098 | // We accept both raw headers with \r\n as a separator, or as |
| 1099 | // a comma separated list of foo: bar values. |
| 1100 | const CPLStringList aosTokens( |
| 1101 | strstr(pszGDAL_HTTP_HEADERS, "\r\n") |
| 1102 | ? CSLTokenizeString2(pszGDAL_HTTP_HEADERS, "\r\n", 0) |
| 1103 | : CSLTokenizeString2(pszGDAL_HTTP_HEADERS, ",", |
| 1104 | CSLT_HONOURSTRINGScxx . . $ `port/cpl_string.h:70:9`!)); |
| 1105 | for (int i = 0; i < aosTokens.size(); ++i) |
| 1106 | { |
| 1107 | if (!osHeaders.empty()) |
| 1108 | osHeaders += "\r\n"; |
| 1109 | if (!bFoundAcceptHeader) |
| 1110 | bFoundAcceptHeader = |
| 1111 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(aosTokens[i], "Accept:"); |
| 1112 | osHeaders += aosTokens[i]; |
| 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | if (!bFoundAcceptHeader) |
| 1117 | { |
| 1118 | if (!osHeaders.empty()) |
| 1119 | osHeaders += "\r\n"; |
| 1120 | osHeaders += "Accept: text/plain, application/json"; |
| 1121 | } |
| 1122 | |
| 1123 | CPLStringList aosOptions; |
| 1124 | aosOptions.SetNameValue("HEADERS", osHeaders.c_str()); |
| 1125 | |
| 1126 | stdcxx . . $ std/::string osURL(pszURL); |
| 1127 | if (bCanUsePOST && poOpenInfo) |
| 1128 | { |
| 1129 | const char *pszHTTPMethod = CSLFetchNameValueDef( |
| 1130 | poOpenInfo->papszOpenOptionscxx . . $ GDALOpenInfo#papszOpenOptions., "HTTP_METHOD", "AUTO"); |
| 1131 | constexpr size_t MAX_URL_LEN_FOR_GET = 256; // arbitrary |
| 1132 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszHTTPMethod, "AUTO")) |
| 1133 | pszHTTPMethod = |
| 1134 | (strlen(pszURL) < MAX_URL_LEN_FOR_GET) ? "GET" : "POST"; |
| 1135 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszHTTPMethod, "POST")) |
| 1136 | { |
| 1137 | const auto nQuestionMarkPos = osURL.find('?'); |
| 1138 | if (nQuestionMarkPos != stdcxx . . $ std/::string::npos) |
| 1139 | { |
| 1140 | aosOptions.SetNameValue( |
| 1141 | "POSTFIELDS", osURL.substr(nQuestionMarkPos + 1).c_str()); |
| 1142 | osURL.resize(nQuestionMarkPos); |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | CPLHTTPResult *pResult = CPLHTTPFetch(osURL.c_str(), aosOptions.List()); |
| 1148 | |
| 1149 | if (nullptr == pResult || 0 == pResult->nDataLen || |
| 1150 | 0 != CPLGetLastErrorNo()) |
| 1151 | { |
| 1152 | CPLHTTPDestroyResult(pResult); |
| 1153 | return nullptr; |
| 1154 | } |
| 1155 | |
| 1156 | if (0 != pResult->nStatus) |
| 1157 | { |
| 1158 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Curl reports error: %d: %s", |
| 1159 | pResult->nStatus, pResult->pszErrBuf); |
| 1160 | CPLHTTPDestroyResult(pResult); |
| 1161 | return nullptr; |
| 1162 | } |
| 1163 | |
| 1164 | return pResult; |
| 1165 | } |