| 1791 | /************************************************************************/ |
| 1792 | |
| 1793 | void pj_load_ini(PJ_CONTEXT *ctx) { |
| 1794 | if (ctx->iniFileLoaded) |
| 1795 | return; |
| 1796 | |
| 1797 | const char *endpoint_from_env = getenv("PROJ_NETWORK_ENDPOINT"); |
| 1798 | if (endpoint_from_env && endpoint_from_env[0] != '\0') { |
| 1799 | ctx->endpoint = endpoint_from_env; |
| 1800 | } |
| 1801 | |
| 1802 | ctx->iniFileLoaded = true; |
| 1803 | auto file = std::unique_ptr<NS_PROJ::File>( |
| 1804 | reinterpret_cast<NS_PROJ::File *>(pj_open_lib_internal( |
| 1805 | ctx, "proj.ini", "rb", pj_open_file_with_manager, nullptr, 0))); |
| 1806 | if (!file) |
| 1807 | return; |
| 1808 | file->seek(0, SEEK_END); |
| 1809 | const auto filesize = file->tell(); |
| 1810 | if (filesize == 0 || filesize > 100 * 1024U) |
| 1811 | return; |
| 1812 | file->seek(0, SEEK_SET); |
| 1813 | std::string content; |
| 1814 | content.resize(static_cast<size_t>(filesize)); |
| 1815 | const auto nread = file->read(&content[0], content.size()); |
| 1816 | if (nread != content.size()) |
| 1817 | return; |
| 1818 | content += '\n'; |
| 1819 | size_t pos = 0; |
| 1820 | while (pos != std::string::npos) { |
| 1821 | const auto eol = content.find_first_of("\r\n", pos); |
| 1822 | if (eol == std::string::npos) { |
| 1823 | break; |
| 1824 | } |
| 1825 | |
| 1826 | const auto equal = content.find('=', pos); |
| 1827 | if (equal < eol) { |
| 1828 | const auto key = trim(content.substr(pos, equal - pos)); |
| 1829 | const auto value = |
| 1830 | trim(content.substr(equal + 1, eol - (equal + 1))); |
| 1831 | if (ctx->endpoint.empty() && key == "cdn_endpoint") { |
| 1832 | ctx->endpoint = value; |
| 1833 | } else if (key == "network") { |
| 1834 | const char *enabled = getenv("PROJ_NETWORK"); |
| 1835 | if (enabled == nullptr || enabled[0] == '\0') { |
| 1836 | ctx->networking.enabled = ci_equal(value, "ON") || |
| 1837 | ci_equal(value, "YES") || |
| 1838 | ci_equal(value, "TRUE"); |
| 1839 | } |
| 1840 | } else if (key == "cache_enabled") { |
| 1841 | ctx->gridChunkCache.enabled = ci_equal(value, "ON") || |
| 1842 | ci_equal(value, "YES") || |
| 1843 | ci_equal(value, "TRUE"); |
| 1844 | } else if (key == "cache_size_MB") { |
| 1845 | const int val = atoi(value.c_str()); |
| 1846 | ctx->gridChunkCache.max_size = |
| 1847 | val > 0 ? static_cast<long long>(val) * 1024 * 1024 : -1; |
| 1848 | } else if (key == "cache_ttl_sec") { |
| 1849 | ctx->gridChunkCache.ttl = atoi(value.c_str()); |
| 1850 | } else if (key == "tmerc_default_algo") { |
no test coverage detected