MCPcopy Create free account
hub / github.com/OSGeo/gdal / LoadUrl

Method LoadUrl

port/cpl_json.cpp:414–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

412 GDALProgressFunc pfnProgress, void *pProgressArg)
413#else
414bool 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

Callers 3

TEST_FFunction · 0.45
parseMethod · 0.45
OpenMethod · 0.45

Calls 10

CSLFetchNameValueDefFunction · 0.85
json_tokener_new_exFunction · 0.85
CPLHTTPFetchExFunction · 0.85
CPLHTTPDestroyResultFunction · 0.85
json_tokener_get_errorFunction · 0.85
CPLErrorFunction · 0.85
json_tokener_error_descFunction · 0.85
json_object_putFunction · 0.85
json_tokener_freeFunction · 0.85
c_strMethod · 0.45

Tested by 1

TEST_FFunction · 0.36