diff options
author | tastytea | 2020-01-14 21:53:42 +0100 |
---|---|---|
committer | tastytea | 2020-01-14 21:53:42 +0100 |
commit | 0d8b2e849077be8a67c22e95ff90f13a56bfd3e7 (patch) | |
tree | 9c0f057429cb82f668db7b0bc54afdaecf9bfd99 | |
parent | 223db7b2555958e37ab149303e05e5d54edd81bc (diff) | |
download | mastodonpp-0d8b2e849077be8a67c22e95ff90f13a56bfd3e7.tar mastodonpp-0d8b2e849077be8a67c22e95ff90f13a56bfd3e7.tar.gz mastodonpp-0d8b2e849077be8a67c22e95ff90f13a56bfd3e7.zip |
Use regex to extract NodeInfo addresses.
-rw-r--r-- | src/instance.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/instance.cpp b/src/instance.cpp index 7b1d5c1..ac2f308 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -77,7 +77,6 @@ uint64_t Instance::get_max_chars() noexcept answer_type Instance::get_nodeinfo() { - debuglog << "Finding location of NodeInfo on " << _hostname << "…\n"; auto answer{make_request(http_method::GET, _baseuri + "/.well-known/nodeinfo", {})}; if (!answer) @@ -86,15 +85,15 @@ answer_type Instance::get_nodeinfo() return answer; } - size_t pos{0}; vector<string> hrefs; - constexpr string_view searchstring{R"("href":")"}; - while ((pos = answer.body.find(searchstring, pos)) != string::npos) + const regex re_href{R"("href"\s*:\s*"([^"]+)\")"}; + smatch match; + string body = answer.body; + while (regex_search(body, match, re_href)) { - pos += searchstring.size(); - auto endpos{answer.body.find('"', pos)}; - hrefs.push_back(answer.body.substr(pos, endpos - pos)); + hrefs.push_back(match[1].str()); debuglog << "Found href: " << hrefs.back() << '\n'; + body = match.suffix(); } sort(hrefs.begin(), hrefs.end()); // We assume they are sortable strings. debuglog << "Selecting href: " << hrefs.back() << '\n'; |