aboutsummaryrefslogtreecommitdiff
path: root/mod/mod-package-version-details.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-05-24 00:25:45 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-05-24 17:11:47 +0300
commit6ce19c537bd9de8d3c9821841bc5ed680b762742 (patch)
tree2a487b1d5ec75b05e3001a461f149e14e5a859a8 /mod/mod-package-version-details.cxx
parent3363e1239973a66722f681999771964e39a98332 (diff)
Adapt to inventing package_name type
Diffstat (limited to 'mod/mod-package-version-details.cxx')
-rw-r--r--mod/mod-package-version-details.cxx69
1 files changed, 41 insertions, 28 deletions
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<package> pkg;
+
+ session sn;
+ transaction t (package_db_->begin ());
+
+ try
+ {
+ pkg = package_db_->load<package> (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<package> pkg;
-
- session sn;
- transaction t (package_db_->begin ());
-
- try
- {
- pkg = package_db_->load<package> (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)
{