diff --git a/src/protocol/webfinger/webfinger.cpp b/src/protocol/webfinger/webfinger.cpp
index 44f0357..ffc5716 100644
--- a/src/protocol/webfinger/webfinger.cpp
+++ b/src/protocol/webfinger/webfinger.cpp
@@ -16,6 +16,7 @@
* along with this program. If not, see .
*/
+#include "instance/instance.h"
#include "jsonhelper.h"
#include
#include
@@ -55,14 +56,18 @@ namespace
// TODO a lot
HTTP::Response Route::webfinger(std::any& args, const HTTP::Request& req, const HTTP::RequestArgs_t& arg)
{
+ using namespace std::string_literals;
+
DESTRUCT_WORMHOLE_ARGS(args);
- // auto args = std::any_cast(_args);
- using namespace std::string_literals;
rjson::Document root(rjson::kObjectType);
rjson::Document::AllocatorType& a = root.GetAllocator();
rjson::Value links(rjson::kArrayType);
+
+ // Resource to read into
std::string resource;
+ // Stored result of account string, stripped from resource
+ std::string acct_str;
User user;
try
@@ -73,24 +78,39 @@ HTTP::Response Route::webfinger(std::any& args, const HTTP::Request& req, const
return HTTP::Error::make_json_error_response("Missing resource parameter", HTTP::Code::BAD_REQUEST);
}
- // MUST have acct: at beginning
- std::string acct_str;
- constexpr std::string_view prefix = "acct:";
- if (!resource.compare(0, prefix.size(), prefix))
+ // Perform multiple different Resource formats
+ // TODO separate into functions?
+ constexpr std::string_view acct_prefix = "acct:";
+ static const std::string local_host_prefix = Instance::instance_host_https(true) + "user/";
+ static const std::string at_prefix = Instance::instance_host_https(true) + "@";
+
+ // Standard "acct:" prefix check
+ if (!resource.compare(0, acct_prefix.size(), acct_prefix))
{
// Get data after acct:
- acct_str = resource.substr(prefix.size());
+ acct_str = resource.substr(acct_prefix.size());
+ }
+ // Host prefix check
+ else if (!resource.compare(0, local_host_prefix.size(), local_host_prefix))
+ {
+ // Get data after acct:
+ acct_str = resource.substr(local_host_prefix.size());
+ }
+ // At prefix check
+ else if (!resource.compare(0, at_prefix.size(), at_prefix))
+ {
+ // Get data after acct:
+ acct_str = resource.substr(at_prefix.size());
}
else {
- return HTTP::Error::make_json_error_response("Missing \"acct:\" prefix", HTTP::Code::BAD_REQUEST);
+ return HTTP::Error::make_json_error_response("Invalid prefix", HTTP::Code::METHOD_NOT_ALLOWED);
}
try
{
user = db->get_user(acct_str);
}
- catch (...)
- {
+ catch (...) {
return HTTP::Error::make_json_error_response("Couldn't find user", HTTP::Code::NOT_FOUND);
}