From 6ce19c537bd9de8d3c9821841bc5ed680b762742 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 24 May 2018 00:25:45 +0300 Subject: Adapt to inventing package_name type --- mod/mod-package-version-details.cxx | 69 ++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 28 deletions(-) (limited to 'mod/mod-package-version-details.cxx') diff --git a/mod/mod-package-version-details.cxx b/mod/mod-package-version-details.cxx index 2683388..2134cc6 100644 --- a/mod/mod-package-version-details.cxx +++ b/mod/mod-package-version-details.cxx @@ -83,10 +83,18 @@ handle (request& rq, response& rs) throw invalid_request (400, "invalid package version format"); } - const string& sver (ver.string ()); - assert (i != rq.path ().rend ()); - const string& name (*i); + + package_name pn; + + try + { + pn = package_name (*i); + } + catch (const invalid_argument& ) + { + throw invalid_request (400, "invalid package name format"); + } params::package_version_details params; bool full; @@ -104,6 +112,8 @@ handle (request& rq, response& rs) throw invalid_request (400, e.what ()); } + const string& sver (ver.string ()); + auto url = [&sver] (bool f = false, const string& a = "") -> string { string u (sver); @@ -113,6 +123,32 @@ handle (request& rq, response& rs) return u; }; + bool not_found (false); + shared_ptr pkg; + + session sn; + transaction t (package_db_->begin ()); + + try + { + pkg = package_db_->load (package_id (pn, ver)); + + // If the requested package turned up to be an "external" one just + // respond that no "internal" package is present. + // + not_found = !pkg->internal (); + } + catch (const object_not_persistent& ) + { + not_found = true; + } + + if (not_found) + throw invalid_request ( + 404, "Package '" + pn.string () + ' ' + sver + "' not found"); + + const string& name (pkg->id.name.string ()); + const string title (name + " " + sver); xml::serializer s (rs.content (), title); @@ -139,29 +175,6 @@ handle (request& rq, response& rs) << A(HREF=url (!full)) << (full ? "[brief]" : "[full]") << ~A << ~DIV; - bool not_found (false); - shared_ptr pkg; - - session sn; - transaction t (package_db_->begin ()); - - try - { - pkg = package_db_->load (package_id (name, ver)); - - // If the requested package turned up to be an "external" one just - // respond that no "internal" package is present. - // - not_found = !pkg->internal (); - } - catch (const object_not_persistent& ) - { - not_found = true; - } - - if (not_found) - throw invalid_request (404, "Package '" + title + "' not found"); - s << H2 << pkg->summary << ~H2; static const string id ("description"); @@ -256,8 +269,8 @@ handle (request& rq, response& rs) : p->other_repositories[0].load ()); const auto& dcon (d.constraint); - const string& dname (p->id.name); - string ename (mime_url_encode (dname, false)); + const package_name& dname (p->id.name); + string ename (mime_url_encode (dname.string (), false)); if (r->url) { -- cgit v1.1