| 114 | } // namespace |
| 115 | |
| 116 | ParsedMapApi::UrlType ParsedMapApi::SetUrlAndParse(std::string const & raw) |
| 117 | { |
| 118 | Reset(); |
| 119 | SCOPE_GUARD(guard, [this] |
| 120 | { |
| 121 | if (m_requestType == UrlType::Incorrect) |
| 122 | Reset(); |
| 123 | }); |
| 124 | |
| 125 | if (auto const [prefix, checkForGe0Link] = FindUrlPrefix(raw); prefix != std::string::npos) |
| 126 | { |
| 127 | url::Url const url{"cm://" + raw.substr(prefix)}; |
| 128 | if (!url.IsValid()) |
| 129 | return m_requestType = UrlType::Incorrect; |
| 130 | |
| 131 | std::string const & type = url.GetHost(); |
| 132 | // The URL is prefixed by one of the kGe0Prefixes or kLegacyMwmPrefixes prefixes |
| 133 | // => check for well-known API methods first. |
| 134 | if (type == "map") |
| 135 | { |
| 136 | bool correctOrder = true; |
| 137 | url.ForEachParam([&correctOrder, this](auto const & key, auto const & value) |
| 138 | { ParseMapParam(key, value, correctOrder); }); |
| 139 | |
| 140 | if (m_mapPoints.empty() || !correctOrder) |
| 141 | return m_requestType = UrlType::Incorrect; |
| 142 | |
| 143 | return m_requestType = UrlType::Map; |
| 144 | } |
| 145 | else if (type == "route") |
| 146 | { |
| 147 | m_routePoints.clear(); |
| 148 | using namespace route; |
| 149 | std::vector pattern{kSourceLatLon, kSourceName, kDestLatLon, kDestName, kRouteType}; |
| 150 | url.ForEachParam([&pattern, this](auto const & key, auto const & value) |
| 151 | { ParseRouteParam(key, value, pattern); }); |
| 152 | |
| 153 | if (pattern.size() != 0) |
| 154 | return m_requestType = UrlType::Incorrect; |
| 155 | |
| 156 | if (m_routePoints.size() != 2) |
| 157 | return m_requestType = UrlType::Incorrect; |
| 158 | |
| 159 | return m_requestType = UrlType::Route; |
| 160 | } |
| 161 | else if (type == "search") |
| 162 | { |
| 163 | url.ForEachParam([this](auto const & key, auto const & value) { ParseSearchParam(key, value); }); |
| 164 | if (m_searchRequest.m_query.empty()) |
| 165 | return m_requestType = UrlType::Incorrect; |
| 166 | |
| 167 | return m_requestType = UrlType::Search; |
| 168 | } |
| 169 | else if (type == "crosshair") |
| 170 | { |
| 171 | url.ForEachParam([this](auto const & key, auto const & value) { ParseCommonParam(key, value); }); |
| 172 | |
| 173 | return m_requestType = UrlType::Crosshair; |