| 412 | GDALProgressFunc pfnProgress, void *pProgressArg) |
| 413 | #else |
| 414 | bool CPLJSONDocument::LoadUrl(const std::string & /*osUrl*/, |
| 415 | const char *const * /*papszOptions*/, |
| 416 | GDALProgressFunc /*pfnProgress*/, |
| 417 | void * /*pProgressArg*/) |
| 418 | #endif // HAVE_CURL |
| 419 | { |
| 420 | #ifdef HAVE_CURL |
| 421 | int nDepth = |
| 422 | atoi(CSLFetchNameValueDef(papszOptions, "JSON_DEPTH", |
| 423 | "32")); // Same as JSON_TOKENER_DEFAULT_DEPTH |
| 424 | JsonContext ctx = {nullptr, json_tokener_new_ex(nDepth)}; |
| 425 | |
| 426 | CPLHTTPFetchWriteFunc pWriteFunc = CPLJSONWriteFunction; |
| 427 | CPLHTTPResult *psResult = |
| 428 | CPLHTTPFetchEx(osUrl.c_str(), papszOptions, pfnProgress, pProgressArg, |
| 429 | pWriteFunc, &ctx); |
| 430 | |
| 431 | bool bResult = |
| 432 | psResult->nStatus == 0 /*CURLE_OK*/ && psResult->pszErrBuf == nullptr; |
| 433 | |
| 434 | CPLHTTPDestroyResult(psResult); |
| 435 | |
| 436 | enum json_tokener_error jerr; |
| 437 | if ((jerr = json_tokener_get_error(ctx.pTokener)) != json_tokener_success) |
| 438 | { |
| 439 | CPLError(CE_Failure, CPLE_AppDefined, "JSON error: %s\n", |
| 440 | json_tokener_error_desc(jerr)); |
| 441 | bResult = false; |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | if (m_poRootJsonObject) |
| 446 | json_object_put(TO_JSONOBJ(m_poRootJsonObject)); |
| 447 | |
| 448 | m_poRootJsonObject = ctx.pObject; |
| 449 | } |
| 450 | json_tokener_free(ctx.pTokener); |
| 451 | |
| 452 | return bResult; |
| 453 | #else |
| 454 | CPLError(CE_Failure, CPLE_NotSupported, |
| 455 | "LoadUrl() not supported in a build without Curl"); |
| 456 | return false; |
| 457 | #endif |
| 458 | } |
| 459 | |
| 460 | //------------------------------------------------------------------------------ |
| 461 | // JSONObject |