From 0103e8a96182ad12b3b98629ffe295a706ddcb66 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 12 Nov 2015 12:39:40 +0200 Subject: Add url, email, summary, description members to the repository_manifest class --- bpkg/manifest | 7 +++++ bpkg/manifest.cxx | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-) (limited to 'bpkg') diff --git a/bpkg/manifest b/bpkg/manifest index cc45bb4..106b6ca 100644 --- a/bpkg/manifest +++ b/bpkg/manifest @@ -469,6 +469,13 @@ namespace bpkg repository_location location; butl::optional role; + // The following values may only be present for the base repository. + // + butl::optional url; + butl::optional email; + butl::optional summary; + butl::optional description; + public: repository_manifest (manifest_parser&); repository_manifest (manifest_parser&, manifest_name_value start); diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx index d421e7e..3857c28 100644 --- a/bpkg/manifest.cxx +++ b/bpkg/manifest.cxx @@ -1245,6 +1245,46 @@ namespace bpkg role = static_cast (i - b); } + else if (n == "url") + { + if (url) + bad_name ("url redefinition"); + + if (v.empty ()) + bad_value ("empty url"); + + url = move (v); + } + else if (n == "email") + { + if (email) + bad_name ("email redefinition"); + + if (v.empty ()) + bad_value ("empty email"); + + email = move (v); + } + else if (n == "summary") + { + if (summary) + bad_name ("summary redefinition"); + + if (v.empty ()) + bad_value ("empty summary"); + + summary = move (v); + } + else if (n == "description") + { + if (description) + bad_name ("description redefinition"); + + if (v.empty ()) + bad_value ("empty description"); + + description = move (v); + } else bad_name ("unknown name '" + n + "' in repository manifest"); } @@ -1256,11 +1296,29 @@ namespace bpkg // if (role && location.empty () != (*role == repository_role::base)) bad_value ("invalid role"); + + if (effective_role () != repository_role::base) + { + if (url) + bad_value ("url not allowed"); + + if (email) + bad_value ("email not allowed"); + + if (summary) + bad_value ("summary not allowed"); + + if (description) + bad_value ("description not allowed"); + } } void repository_manifest:: serialize (serializer& s) const { + auto bad_value ([&s](const string& d) { + throw serialization (s.name (), d);}); + s.next ("", "1"); // Start of manifest. if (!location.empty ()) @@ -1269,13 +1327,47 @@ namespace bpkg if (role) { if (location.empty () != (*role == repository_role::base)) - throw serialization (s.name (), "invalid role"); + bad_value ("invalid role"); auto r (static_cast (*role)); assert (r < repository_role_names.size ()); s.next ("role", repository_role_names[r]); } + bool b (effective_role () == repository_role::base); + + if (url) + { + if (!b) + bad_value ("url not allowed"); + + s.next ("url", *url); + } + + if (email) + { + if (!b) + bad_value ("email not allowed"); + + s.next ("email", *email); + } + + if (summary) + { + if (!b) + bad_value ("summary not allowed"); + + s.next ("summary", *summary); + } + + if (description) + { + if (!b) + bad_value ("description not allowed"); + + s.next ("description", *description); + } + s.next ("", ""); // End of manifest. } -- cgit v1.1