21#include "redirect_watcher.hpp"
27#include <winpr/string.h>
31 std::string from_url_encoded_str(
const std::string& str)
34 auto cstr = winpr_str_url_decode(str.c_str(), str.length());
37 cxxstr = std::string(cstr);
43 std::vector<std::string> split(
const std::string& input,
const std::string& regex)
47 std::sregex_token_iterator first{ input.begin(), input.end(), re, -1 };
48 std::sregex_token_iterator last;
49 return { first, last };
52 std::map<std::string, std::string> urlsplit(
const std::string& url)
54 auto pos = url.find(
'?');
55 if (pos == std::string::npos)
59 auto surl = url.substr(pos);
60 auto args = split(surl,
"&");
62 std::map<std::string, std::string> argmap;
63 for (
const auto& arg : args)
65 auto kv = split(arg,
"=");
67 argmap.insert({ kv[0], kv[1] });
74RedirectWatcher::RedirectWatcher(std::string redirectUri) : _redirect_uri(std::move(redirectUri))
78bool RedirectWatcher::matches(
const std::string& uri)
const
80 if (_redirect_uri.empty())
83 std::string duri = from_url_encoded_str(uri);
84 if (duri.length() < _redirect_uri.length())
87 return _strnicmp(duri.c_str(), _redirect_uri.c_str(), _redirect_uri.length()) == 0;
90bool RedirectWatcher::hasError(
const std::string& uri, std::string& error)
const
92 auto args = urlsplit(uri);
93 auto err = args.find(
"error");
94 if (err == args.end())
98 auto suberr = args.find(
"error_subcode");
99 if (suberr != args.end())
100 error +=
": " + suberr->second;