From 36adbffffe899be66c1e798fbca444422427bd4e Mon Sep 17 00:00:00 2001 From: alexandertuna Date: Wed, 7 May 2025 16:03:09 -0700 Subject: [PATCH 1/8] Start implementing mkdir with lots of debugging --- src/HTTPCommands.cc | 13 +++++++++++++ src/HTTPCommands.hh | 16 ++++++++++++++++ src/HTTPFile.cc | 8 ++++++++ src/HTTPFileSystem.cc | 25 +++++++++++++++++++++++++ src/HTTPFileSystem.hh | 4 +--- test/http_tests.cc | 9 +++++++++ 6 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/HTTPCommands.cc b/src/HTTPCommands.cc index d43a10c..e178369 100644 --- a/src/HTTPCommands.cc +++ b/src/HTTPCommands.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -827,3 +828,15 @@ bool HTTPHead::SendRequest() { } // --------------------------------------------------------------------------- + +HTTPMkcol::~HTTPMkcol() {} + +bool HTTPMkcol::SendRequest() { + httpVerb = "MKCOL"; + std::string noPayloadAllowed; + std::cout << "TUNA MKCOL BEFORE responseCode " << responseCode << std::endl; + const auto res = SendHTTPRequest(noPayloadAllowed); + std::cout << "TUNA MKCOL AFTER responseCode " << responseCode << std::endl; + return res; +} + diff --git a/src/HTTPCommands.hh b/src/HTTPCommands.hh index 47a3d6a..196c4e2 100644 --- a/src/HTTPCommands.hh +++ b/src/HTTPCommands.hh @@ -336,3 +336,19 @@ class HTTPHead : public HTTPRequest { protected: std::string object; }; + +class HTTPMkcol : public HTTPRequest { + public: + HTTPMkcol(const std::string &h, const std::string &o, XrdSysError &log, + const TokenFile *token) + : HTTPRequest(h, log, token), object(o) { + hostUrl = hostUrl + "/" + object; + } + + virtual ~HTTPMkcol(); + + virtual bool SendRequest(); + + protected: + std::string object; +}; diff --git a/src/HTTPFile.cc b/src/HTTPFile.cc index dff96ee..fe15af9 100644 --- a/src/HTTPFile.cc +++ b/src/HTTPFile.cc @@ -159,10 +159,18 @@ int HTTPFile::Fstat(struct stat *buff) { return 0; } + std::cout << "TUNA 000000000000000000000000000" << std::endl; + std::cout << "HTTPFile::Fstat " + << "About to perform HTTPFile::Fstat():" + << " " << m_hostUrl.c_str() + << " " << m_object.c_str() + << std::endl; m_log.Log(LogMask::Debug, "HTTPFile::Fstat", "About to perform HTTPFile::Fstat():", m_hostUrl.c_str(), m_object.c_str()); + std::cout << "TUNA 111111111111111111111111111" << std::endl; HTTPHead head(m_hostUrl, m_object, m_log, m_oss->getToken()); + std::cout << "TUNA 222222222222222222222222222" << std::endl; if (!head.SendRequest()) { // SendRequest() returns false for all errors, including ones diff --git a/src/HTTPFileSystem.cc b/src/HTTPFileSystem.cc index 536cabe..42bee73 100644 --- a/src/HTTPFileSystem.cc +++ b/src/HTTPFileSystem.cc @@ -18,6 +18,7 @@ #include "HTTPFileSystem.hh" #include "HTTPDirectory.hh" +#include "HTTPCommands.hh" #include "HTTPFile.hh" #include "logging.hh" @@ -35,6 +36,7 @@ #include #include #include +#include #include "stl_string_utils.hh" @@ -173,3 +175,26 @@ int HTTPFileSystem::Create(const char *tid, const char *path, mode_t mode, return 0; } + +int HTTPFileSystem::Mkdir(const char *path, mode_t mode, int mkpath, + XrdOucEnv *env) { + // Is path valid? + // std::string object; + // std::string hostname = this->getHTTPHostName(); + // int rv = parse_path(hostname, path, object); + // if (rv != 0) { + // return rv; + // } + std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; + std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; + std::cout << "TUNA HTTPFileSystem::Mkdir http_host_name " << http_host_name << std::endl; + std::cout << "TUNA HTTPFileSystem::Mkdir http_host_url " << http_host_url << std::endl; + std::cout << "TUNA HTTPFileSystem::Mkdir m_url_base " << m_url_base << std::endl; + std::cout << "TUNA HTTPFileSystem::Mkdir m_storage_prefix " << m_storage_prefix << std::endl; + HTTPMkcol mkcol(m_url_base, path, m_log, getToken()); + // HTTPMkcol mkcol(m_hostUrl, m_object, m_log, m_oss->getToken()); + std::cout << "TUNA HTTPFileSystem::Mkdir SendRequest " << mkcol.SendRequest() << std::endl; + std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; + std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; + return 0; +} diff --git a/src/HTTPFileSystem.hh b/src/HTTPFileSystem.hh index ac21e90..5a76e87 100644 --- a/src/HTTPFileSystem.hh +++ b/src/HTTPFileSystem.hh @@ -54,9 +54,7 @@ class HTTPFileSystem : public XrdOss { int Init(XrdSysLogger *lp, const char *cfn) { return 0; } int Init(XrdSysLogger *lp, const char *cfn, XrdOucEnv *en) { return 0; } int Mkdir(const char *path, mode_t mode, int mkpath = 0, - XrdOucEnv *env = 0) { - return -ENOSYS; - } + XrdOucEnv *env = 0); int Reloc(const char *tident, const char *path, const char *cgName, const char *anchor = 0) { return -ENOSYS; diff --git a/test/http_tests.cc b/test/http_tests.cc index 4429f53..244e07a 100644 --- a/test/http_tests.cc +++ b/test/http_tests.cc @@ -82,6 +82,15 @@ TEST(TestHTTPFile, TestXfer) { ASSERT_EQ(fh->Close(), 0); } +TEST(TestHTTPFile, TestMkdir) { + XrdSysLogger log; + + HTTPFileSystem fs(&log, g_config_file.c_str(), nullptr); + + const auto ret = fs.Mkdir("/newdir", 0755); + ASSERT_EQ(ret, 0); +} + class TestHTTPRequest : public HTTPRequest { public: XrdSysLogger log{}; From 0fbb9d63540d2b7c78e436096526b03949f4e8b8 Mon Sep 17 00:00:00 2001 From: alexandertuna Date: Wed, 30 Jul 2025 17:05:35 -0700 Subject: [PATCH 2/8] Messing around with slashes --- test/http_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/http_tests.cc b/test/http_tests.cc index 244e07a..165d893 100644 --- a/test/http_tests.cc +++ b/test/http_tests.cc @@ -87,7 +87,7 @@ TEST(TestHTTPFile, TestMkdir) { HTTPFileSystem fs(&log, g_config_file.c_str(), nullptr); - const auto ret = fs.Mkdir("/newdir", 0755); + const auto ret = fs.Mkdir("newdir/", 0755); ASSERT_EQ(ret, 0); } From 1e3a7616bb0ac6cdd539c515dc29485caba438bf Mon Sep 17 00:00:00 2001 From: alexandertuna Date: Wed, 30 Jul 2025 17:15:37 -0700 Subject: [PATCH 3/8] Add MKCOL to verb handling --- src/HTTPCommands.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/HTTPCommands.cc b/src/HTTPCommands.cc index e178369..aa50630 100644 --- a/src/HTTPCommands.cc +++ b/src/HTTPCommands.cc @@ -469,6 +469,15 @@ bool HTTPRequest::SetupHandle(CURL *curl) { } } + if (httpVerb == "MKCOL") { + rv = curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "MKCOL"); + if (rv != CURLE_OK) { + this->errorCode = "E_CURL_LIB"; + this->errorMessage = "curl_easy_setopt( CURLOPT_MKCOL ) failed."; + return false; + } + } + if (httpVerb == "POST") { rv = curl_easy_setopt(curl, CURLOPT_POST, 1); if (rv != CURLE_OK) { @@ -833,10 +842,8 @@ HTTPMkcol::~HTTPMkcol() {} bool HTTPMkcol::SendRequest() { httpVerb = "MKCOL"; + expectedResponseCode = 201; std::string noPayloadAllowed; - std::cout << "TUNA MKCOL BEFORE responseCode " << responseCode << std::endl; - const auto res = SendHTTPRequest(noPayloadAllowed); - std::cout << "TUNA MKCOL AFTER responseCode " << responseCode << std::endl; - return res; + return SendHTTPRequest(noPayloadAllowed); } From 90a1b94d86a1e854fcc1ec759a85269b84ce0132 Mon Sep 17 00:00:00 2001 From: alexandertuna Date: Wed, 30 Jul 2025 17:36:23 -0700 Subject: [PATCH 4/8] Trimming down --- src/HTTPFileSystem.cc | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/HTTPFileSystem.cc b/src/HTTPFileSystem.cc index 42bee73..c8990ac 100644 --- a/src/HTTPFileSystem.cc +++ b/src/HTTPFileSystem.cc @@ -178,23 +178,7 @@ int HTTPFileSystem::Create(const char *tid, const char *path, mode_t mode, int HTTPFileSystem::Mkdir(const char *path, mode_t mode, int mkpath, XrdOucEnv *env) { - // Is path valid? - // std::string object; - // std::string hostname = this->getHTTPHostName(); - // int rv = parse_path(hostname, path, object); - // if (rv != 0) { - // return rv; - // } - std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; - std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; - std::cout << "TUNA HTTPFileSystem::Mkdir http_host_name " << http_host_name << std::endl; - std::cout << "TUNA HTTPFileSystem::Mkdir http_host_url " << http_host_url << std::endl; - std::cout << "TUNA HTTPFileSystem::Mkdir m_url_base " << m_url_base << std::endl; - std::cout << "TUNA HTTPFileSystem::Mkdir m_storage_prefix " << m_storage_prefix << std::endl; - HTTPMkcol mkcol(m_url_base, path, m_log, getToken()); - // HTTPMkcol mkcol(m_hostUrl, m_object, m_log, m_oss->getToken()); - std::cout << "TUNA HTTPFileSystem::Mkdir SendRequest " << mkcol.SendRequest() << std::endl; - std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; - std::cout << "TUNA HTTPFileSystem::Mkdir" << std::endl; + HTTPMkcol mkcol(m_url_base, path, m_log, getToken()); + mkcol.SendRequest(); return 0; } From 388adf7018651e279c5859b6a784f4e23bc4f669 Mon Sep 17 00:00:00 2001 From: alexandertuna Date: Wed, 30 Jul 2025 17:48:00 -0700 Subject: [PATCH 5/8] Add insert auth for mkcol --- test/xrdhttp-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/xrdhttp-setup.sh b/test/xrdhttp-setup.sh index 0449c5e..495d8f4 100755 --- a/test/xrdhttp-setup.sh +++ b/test/xrdhttp-setup.sh @@ -161,7 +161,7 @@ EOF cat > $XROOTD_CONFIGDIR/authdb < Date: Wed, 30 Jul 2025 17:53:15 -0700 Subject: [PATCH 6/8] Remove more debugging --- src/HTTPFile.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/HTTPFile.cc b/src/HTTPFile.cc index fe15af9..dff96ee 100644 --- a/src/HTTPFile.cc +++ b/src/HTTPFile.cc @@ -159,18 +159,10 @@ int HTTPFile::Fstat(struct stat *buff) { return 0; } - std::cout << "TUNA 000000000000000000000000000" << std::endl; - std::cout << "HTTPFile::Fstat " - << "About to perform HTTPFile::Fstat():" - << " " << m_hostUrl.c_str() - << " " << m_object.c_str() - << std::endl; m_log.Log(LogMask::Debug, "HTTPFile::Fstat", "About to perform HTTPFile::Fstat():", m_hostUrl.c_str(), m_object.c_str()); - std::cout << "TUNA 111111111111111111111111111" << std::endl; HTTPHead head(m_hostUrl, m_object, m_log, m_oss->getToken()); - std::cout << "TUNA 222222222222222222222222222" << std::endl; if (!head.SendRequest()) { // SendRequest() returns false for all errors, including ones From 211e14c8dd547665f5c630c619e7d4f9cc585f95 Mon Sep 17 00:00:00 2001 From: alexandertuna Date: Wed, 30 Jul 2025 17:54:04 -0700 Subject: [PATCH 7/8] Remove iostream debugging lib --- src/HTTPCommands.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/HTTPCommands.cc b/src/HTTPCommands.cc index aa50630..d29ce91 100644 --- a/src/HTTPCommands.cc +++ b/src/HTTPCommands.cc @@ -25,7 +25,6 @@ #include #include #include -#include #include #include From aef824bdae99d7773d3331fab06608bca66472b2 Mon Sep 17 00:00:00 2001 From: alexandertuna Date: Wed, 30 Jul 2025 17:55:52 -0700 Subject: [PATCH 8/8] Remove iostream debugging lib --- src/HTTPFileSystem.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/HTTPFileSystem.cc b/src/HTTPFileSystem.cc index c8990ac..aa37f1f 100644 --- a/src/HTTPFileSystem.cc +++ b/src/HTTPFileSystem.cc @@ -36,7 +36,6 @@ #include #include #include -#include #include "stl_string_utils.hh"