diff options
-rw-r--r-- | libbbot/manifest.cxx | 28 | ||||
-rw-r--r-- | libbbot/manifest.hxx | 16 | ||||
-rw-r--r-- | tests/manifest/task-response.testscript | 29 |
3 files changed, 70 insertions, 3 deletions
diff --git a/libbbot/manifest.cxx b/libbbot/manifest.cxx index 7412e74..be642a0 100644 --- a/libbbot/manifest.cxx +++ b/libbbot/manifest.cxx @@ -12,6 +12,7 @@ #include <cstddef> // size_t #include <utility> // move() #include <cstdint> // uint64_t +#include <algorithm> // find_if() #include <stdexcept> // invalid_argument #include <libbutl/regex.hxx> @@ -955,6 +956,23 @@ namespace bbot result_url = move (v); } + else if (n.size () > 11 && + n.compare (n.size () - 11, 11, "-upload-url") == 0) + { + n.resize (n.size () - 11); + + if (find_if (upload_urls.begin (), upload_urls.end (), + [&n] (const upload_url& u) {return u.type == n;}) != + upload_urls.end ()) + { + bad_name ("task response upload url redefinition"); + } + + if (v.empty ()) + bad_value ("empty task response upload url"); + + upload_urls.emplace_back (move (v), move (n)); + } else if (n == "agent-checksum") { if (agent_checksum) @@ -993,12 +1011,15 @@ namespace bbot if (result_url) bad_value ("unexpected task response result url"); + if (!upload_urls.empty ()) + bad_value ("unexpected task response upload url"); + if (agent_checksum) bad_value ("unexpected task response agent checksum"); } - // If session is not empty then the task manifest must follow, otherwise it - // shouldn't. + // If session is not empty then the task manifest must follow, otherwise + // it shouldn't. // nv = p.next (); @@ -1034,6 +1055,9 @@ namespace bbot if (result_url) s.next ("result-url", *result_url); + for (const upload_url& u: upload_urls) + s.next (u.type + "-upload-url", u.url); + if (agent_checksum) s.next ("agent-checksum", *agent_checksum); diff --git a/libbbot/manifest.hxx b/libbbot/manifest.hxx index d51d95b..5807aed 100644 --- a/libbbot/manifest.hxx +++ b/libbbot/manifest.hxx @@ -260,6 +260,16 @@ namespace bbot validate_regex (const std::string&); }; + class upload_url + { + public: + std::string url; + std::string type; + + upload_url (std::string u, std::string t) + : url (std::move (u)), type (std::move (t)) {} + }; + class LIBBBOT_EXPORT task_response_manifest { public: @@ -267,10 +277,12 @@ namespace bbot // std::string session; - // Challenge, result url and task are absent if session is empty. + // Challenge, result url, and task are absent and upload urls list is + // empty if session is empty. // butl::optional<std::string> challenge; butl::optional<std::string> result_url; + std::vector<upload_url> upload_urls; // <type>-upload-url: <url> butl::optional<std::string> agent_checksum; @@ -279,11 +291,13 @@ namespace bbot task_response_manifest (std::string s, butl::optional<std::string> c, butl::optional<std::string> u, + std::vector<upload_url> uus, butl::optional<std::string> ac, butl::optional<task_manifest> t) : session (std::move (s)), challenge (std::move (c)), result_url (std::move (u)), + upload_urls (std::move (uus)), agent_checksum (std::move (ac)), task (std::move (t)) {} diff --git a/tests/manifest/task-response.testscript b/tests/manifest/task-response.testscript index df63f70..7615127 100644 --- a/tests/manifest/task-response.testscript +++ b/tests/manifest/task-response.testscript @@ -18,6 +18,7 @@ test.options += -ts session: abcd challenge: cc6585375ef81898cc60791b11852e3d2ed9ebb82ebb0874010fe0e6f9ebdb73 result-url: https://cppget.org/?build-result + bindist-upload-url: https://cppget.org/?upload=bindist agent-checksum: 1 : name: libfoo @@ -77,6 +78,15 @@ test.options += -ts result-url: https://cppget.org/?build-result EOI + : upload-url + : + $* <<EOI 2>'stdin:4:1: error: task response upload url redefinition' == 1 + : 1 + bindist-upload-url: https://cppget.org/?upload=bindist + other-upload-url: https://cppget.org/?upload=other + bindist-upload-url: https://cppget.org/?upload=bindist + EOI + : agent-checksum : $* <<EOI 2>'stdin:3:1: error: task response agent checksum redefinition' == 1 @@ -127,6 +137,25 @@ test.options += -ts EOI } + : upload-url + : + { + : empty + : + $* <<EOI 2>'stdin:2:20: error: empty task response upload url' == 1 + : 1 + bindist-upload-url: + EOI + + : redundant + : + $* <<EOI 2>'stdin:4:1: error: unexpected task response upload url' == 1 + : 1 + session: + bindist-upload-url: https://cppget.org/?upload=bindist + EOI + } + : agent-checksum : { |