| 73 | /************************************************************************/ |
| 74 | |
| 75 | static GDALDataset *HTTPOpen(GDALOpenInfo *poOpenInfo) |
| 76 | |
| 77 | { |
| 78 | if (poOpenInfo->nHeaderBytes != 0) |
| 79 | return nullptr; |
| 80 | |
| 81 | const char *pszFilename = poOpenInfo->pszFilename; |
| 82 | if (STARTS_WITH_CI(pszFilename, "HTTP:http://") || |
| 83 | STARTS_WITH_CI(pszFilename, "HTTP:https://") || |
| 84 | STARTS_WITH_CI(pszFilename, "HTTP:ftp://")) |
| 85 | { |
| 86 | pszFilename += strlen("HTTP:"); |
| 87 | } |
| 88 | else if (!STARTS_WITH(pszFilename, "http://") && |
| 89 | !STARTS_WITH(pszFilename, "https://") && |
| 90 | !STARTS_WITH(pszFilename, "ftp://")) |
| 91 | { |
| 92 | return nullptr; |
| 93 | } |
| 94 | |
| 95 | /* -------------------------------------------------------------------- */ |
| 96 | /* Fetch the result. */ |
| 97 | /* -------------------------------------------------------------------- */ |
| 98 | CPLErrorReset(); |
| 99 | CPLHTTPResult *psResult = CPLHTTPFetch(pszFilename, nullptr); |
| 100 | |
| 101 | /* -------------------------------------------------------------------- */ |
| 102 | /* Try to handle errors. */ |
| 103 | /* -------------------------------------------------------------------- */ |
| 104 | if (psResult == nullptr || psResult->nDataLen == 0 || |
| 105 | CPLGetLastErrorNo() != 0) |
| 106 | { |
| 107 | CPLHTTPDestroyResult(psResult); |
| 108 | return nullptr; |
| 109 | } |
| 110 | |
| 111 | /* -------------------------------------------------------------------- */ |
| 112 | /* Create a memory file from the result. */ |
| 113 | /* -------------------------------------------------------------------- */ |
| 114 | std::string osFilename = |
| 115 | HTTPFetchContentDispositionFilename(psResult->papszHeaders); |
| 116 | if (osFilename.empty()) |
| 117 | { |
| 118 | osFilename = CPLGetFilename(pszFilename); |
| 119 | /* If we have special characters, let's default to a fixed name */ |
| 120 | if (strchr(osFilename.c_str(), '?') || strchr(osFilename.c_str(), '&')) |
| 121 | osFilename = "file.dat"; |
| 122 | } |
| 123 | |
| 124 | // If changing the _gdal_http_ marker, change jpgdataset.cpp that tests for it |
| 125 | const CPLString osResultFilename = VSIMemGenerateHiddenFilename( |
| 126 | std::string("_gdal_http_").append(osFilename).c_str()); |
| 127 | |
| 128 | VSILFILE *fp = VSIFileFromMemBuffer(osResultFilename, psResult->pabyData, |
| 129 | psResult->nDataLen, TRUE); |
| 130 | |
| 131 | if (fp == nullptr) |
| 132 | return nullptr; |
nothing calls this directly
no test coverage detected