aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
Diffstat (limited to 'mod')
-rw-r--r--mod/build-config.cxx4
-rw-r--r--mod/mod-build-force.cxx12
-rw-r--r--mod/mod-build-log.cxx12
-rw-r--r--mod/mod-build-result.cxx12
-rw-r--r--mod/mod-build-task.cxx3
-rw-r--r--mod/mod-builds.cxx6
-rw-r--r--mod/mod-package-details.cxx64
-rw-r--r--mod/mod-package-version-details.cxx69
-rw-r--r--mod/mod-repository-root.cxx5
-rw-r--r--mod/page.cxx14
-rw-r--r--mod/page.hxx8
11 files changed, 123 insertions, 86 deletions
diff --git a/mod/build-config.cxx b/mod/build-config.cxx
index c460b2f..84562e7 100644
--- a/mod/build-config.cxx
+++ b/mod/build-config.cxx
@@ -118,7 +118,7 @@ namespace brep
// the package version into the URL path part and so don't encode it.
//
string url (host + root.representation () +
- mime_url_encode (b.package_name, false) + '/' +
+ mime_url_encode (b.package_name.string (), false) + '/' +
b.package_version.string () + "/log/" +
mime_url_encode (b.configuration, false) + '/' +
b.toolchain_version.string ());
@@ -141,7 +141,7 @@ namespace brep
// encoded by design.
//
return host + root.string () +
- "?build-force&pn=" + mime_url_encode (b.package_name) +
+ "?build-force&pn=" + mime_url_encode (b.package_name.string ()) +
"&pv=" + b.package_version.string () +
"&cf=" + mime_url_encode (b.configuration) +
"&tc=" + b.toolchain_version.string () + "&reason=";
diff --git a/mod/mod-build-force.cxx b/mod/mod-build-force.cxx
index da063ea..af47b4c 100644
--- a/mod/mod-build-force.cxx
+++ b/mod/mod-build-force.cxx
@@ -77,10 +77,16 @@ handle (request& rq, response& rs)
try
{
- string& p (params.package ());
+ package_name p;
- if (p.empty ())
- throw invalid_argument ("empty package name");
+ try
+ {
+ p = package_name (move (params.package ()));
+ }
+ catch (const invalid_argument& e)
+ {
+ throw invalid_argument (string ("invalid package name: ") + e.what ());
+ }
// We accept the non-url-encoded version representation. Note that the
// parameter is already url-decoded by the web server, so we just restore
diff --git a/mod/mod-build-log.cxx b/mod/mod-build-log.cxx
index 3fc24cc..c1eec4c 100644
--- a/mod/mod-build-log.cxx
+++ b/mod/mod-build-log.cxx
@@ -83,10 +83,16 @@ handle (request& rq, response& rs)
auto i (lpath.begin ());
assert (i != lpath.end ());
- string name (*i++);
+ package_name name;
- if (name.empty ())
- throw invalid_argument ("empty package name");
+ try
+ {
+ name = package_name (*i++);
+ }
+ catch (const invalid_argument& e)
+ {
+ throw invalid_argument (string ("invalid package name: ") + e.what ());
+ }
assert (i != lpath.end ());
diff --git a/mod/mod-build-result.cxx b/mod/mod-build-result.cxx
index 024502a..1253d14 100644
--- a/mod/mod-build-result.cxx
+++ b/mod/mod-build-result.cxx
@@ -117,9 +117,12 @@ handle (request& rq, response&)
if (p == string::npos)
throw invalid_argument ("no package version");
- string& name (rqm.result.name);
- if (name.compare (0, name.size (), s, 0, p) != 0)
- throw invalid_argument ("package name mismatch");
+ package_name& name (rqm.result.name);
+ {
+ const string& n (name.string ());
+ if (n.compare (0, n.size (), s, 0, p) != 0)
+ throw invalid_argument ("package name mismatch");
+ }
size_t b (p + 1); // Start of version.
p = s.find ('/', b); // End of version.
@@ -383,7 +386,8 @@ handle (request& rq, response&)
try
{
string subj ((unforced ? "build " : "rebuild ") +
- to_string (*b->status) + ": " + b->package_name + '/' +
+ to_string (*b->status) + ": " +
+ b->package_name.string () + '/' +
b->package_version.string () + '/' + b->configuration + '/' +
b->toolchain_name + '-' + b->toolchain_version.string ());
diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx
index 8287865..f1e4cdb 100644
--- a/mod/mod-build-task.cxx
+++ b/mod/mod-build-task.cxx
@@ -181,7 +181,8 @@ handle (request& rq, response& rs)
chrono::duration_cast<std::chrono::nanoseconds> (
b->timestamp.time_since_epoch ()).count ());
- string session (b->package_name + '/' + b->package_version.string () +
+ string session (b->package_name.string () + '/' +
+ b->package_version.string () +
'/' + b->configuration +
'/' + b->toolchain_version.string () +
'/' + to_string (ts));
diff --git a/mod/mod-builds.cxx b/mod/mod-builds.cxx
index 135aceb..e43739f 100644
--- a/mod/mod-builds.cxx
+++ b/mod/mod-builds.cxx
@@ -111,7 +111,8 @@ build_query (const brep::cstrings& configs, const brep::params::builds& params)
// Package name.
//
if (!params.name ().empty ())
- q = q && qb::id.package.name.like (transform (params.name ()));
+ q = q && qb::id.package.name.like (
+ package_name (transform (params.name ()), package_name::raw_string));
// Package version.
//
@@ -214,7 +215,8 @@ package_query (const brep::params::builds& params)
// Package name.
//
if (!params.name ().empty ())
- q = q && P::id.name.like (transform (params.name ()));
+ q = q && P::id.name.like (
+ package_name (transform (params.name ()), package_name::raw_string));
// Package version.
//
diff --git a/mod/mod-package-details.cxx b/mod/mod-package-details.cxx
index 7c825d1..c56d91a 100644
--- a/mod/mod-package-details.cxx
+++ b/mod/mod-package-details.cxx
@@ -50,7 +50,7 @@ init (scanner& s)
template <typename T>
static inline query<T>
-search_params (const brep::string& n, const brep::string& q)
+search_params (const brep::package_name& n, const brep::string& q)
{
using query = query<T>;
@@ -74,9 +74,6 @@ handle (request& rq, response& rs)
const size_t res_page (options_->search_results ());
const dir_path& root (options_->root ());
- const string& name (*rq.path ().rbegin ());
- const string ename (mime_url_encode (name, false));
-
params::package_details params;
bool full;
@@ -96,6 +93,31 @@ handle (request& rq, response& rs)
size_t page (params.page ());
const string& squery (params.query ());
+ session sn;
+ transaction t (package_db_->begin ());
+
+ shared_ptr<package> pkg;
+
+ try
+ {
+ package_name n (*rq.path ().rbegin ());
+
+ latest_package lp;
+ if (!package_db_->query_one<latest_package> (
+ query<latest_package> ("(" + query<latest_package>::_val (n) + ")"),
+ lp))
+ throw invalid_request (404, "Package '" + n.string () + "' not found");
+
+ pkg = package_db_->load<package> (lp.id);
+ }
+ catch (const invalid_argument& )
+ {
+ throw invalid_request (400, "invalid package name format");
+ }
+
+ const package_name& name (pkg->id.name);
+ const string ename (mime_url_encode (name.string (), false));
+
auto url = [&ename] (bool f = false,
const string& q = "",
size_t p = 0,
@@ -111,7 +133,7 @@ handle (request& rq, response& rs)
return u;
};
- xml::serializer s (rs.content (), name);
+ xml::serializer s (rs.content (), name.string ());
s << HTML
<< HEAD
@@ -140,26 +162,12 @@ handle (request& rq, response& rs)
if (full)
s << CLASS("full");
- s << DIV(ID="heading")
- << H1 << A(HREF=url ()) << name << ~A << ~H1
- << A(HREF=url (!full, squery, page))
- << (full ? "[brief]" : "[full]")
- << ~A
- << ~DIV;
-
- session sn;
- transaction t (package_db_->begin ());
-
- shared_ptr<package> pkg;
- {
- latest_package lp;
- if (!package_db_->query_one<latest_package> (
- query<latest_package>(
- "(" + query<latest_package>::_val (name) + ")"), lp))
- throw invalid_request (404, "Package '" + name + "' not found");
-
- pkg = package_db_->load<package> (lp.id);
- }
+ s << DIV(ID="heading")
+ << H1 << A(HREF=url ()) << name << ~A << ~H1
+ << A(HREF=url (!full, squery, page))
+ << (full ? "[brief]" : "[full]")
+ << ~A
+ << ~DIV;
const auto& licenses (pkg->license_alternatives);
@@ -182,10 +190,10 @@ handle (request& rq, response& rs)
<< TR_URL (pkg->url);
if (pkg->doc_url)
- s << TR_URL (*pkg->doc_url, "doc-url");
+ s << TR_URL (*pkg->doc_url, "doc-url");
if (pkg->src_url)
- s << TR_URL (*pkg->src_url, "src-url");
+ s << TR_URL (*pkg->src_url, "src-url");
s << TR_EMAIL (pkg->email)
<< TR_TAGS (pkg->tags, root)
@@ -226,7 +234,7 @@ handle (request& rq, response& rs)
// vector<vector<string>> class, so comments are not considered.
//
if (p->license_alternatives != licenses)
- s << TR_LICENSE (p->license_alternatives);
+ s << TR_LICENSE (p->license_alternatives);
assert (p->internal ());
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)
{
diff --git a/mod/mod-repository-root.cxx b/mod/mod-repository-root.cxx
index e9c491a..aaf6988 100644
--- a/mod/mod-repository-root.cxx
+++ b/mod/mod-repository-root.cxx
@@ -343,11 +343,6 @@ namespace brep
//
// If any of the checks fails, then the handling is declined.
//
- // @@ Shouldn't we validate that the package name is not "@", is not
- // digit-only, does not start with '.' while parsing and serializing
- // the package manifest ? Probably also need to mention these
- // constraints in the manifest.txt file.
- //
if (n != "@" && n.find_first_not_of ("0123456789") != string::npos &&
n[0] != '.')
{
diff --git a/mod/page.cxx b/mod/page.cxx
index 706b42f..94e4f4f 100644
--- a/mod/page.cxx
+++ b/mod/page.cxx
@@ -188,7 +188,8 @@ namespace brep
// Propagate search criteria to the package details page.
//
- << root_ / path (mime_url_encode (name_, false)) << query_param_
+ << root_ / path (mime_url_encode (name_.string (), false))
+ << query_param_
<< ~HREF
<< name_
@@ -218,8 +219,9 @@ namespace brep
else
{
assert (root_ != nullptr);
- s << A(HREF=*root_ / dir_path (mime_url_encode (*package_, false)) /
- path (version_))
+ s << A(HREF=*root_ /
+ dir_path (mime_url_encode (package_->string (), false)) /
+ path (version_))
<< version_;
if (stub_)
@@ -363,7 +365,7 @@ namespace brep
// Suppress package name duplicates.
//
- set<string> names;
+ set<package_name> names;
for (const auto& da: d)
names.emplace (da.name ());
@@ -375,7 +377,7 @@ namespace brep
bool first (true);
for (const auto& da: d)
{
- string n (da.name ());
+ package_name n (da.name ());
if (names.find (n) != names.end ())
{
names.erase (n);
@@ -393,7 +395,7 @@ namespace brep
? p->internal_repository.load ()
: p->other_repositories[0].load ());
- auto en (mime_url_encode (n, false));
+ auto en (mime_url_encode (n.string (), false));
if (r->url)
s << A(HREF=*r->url + en) << n << ~A;
diff --git a/mod/page.hxx b/mod/page.hxx
index 51b4b92..2b8c31f 100644
--- a/mod/page.hxx
+++ b/mod/page.hxx
@@ -163,14 +163,14 @@ namespace brep
class TR_NAME
{
public:
- TR_NAME (const string& n, const string& q, const dir_path& r)
+ TR_NAME (const package_name& n, const string& q, const dir_path& r)
: name_ (n), query_param_ (q), root_ (r) {}
void
operator() (xml::serializer&) const;
private:
- const string& name_;
+ const package_name& name_;
const string& query_param_;
const dir_path& root_;
};
@@ -182,7 +182,7 @@ namespace brep
public:
// Display the version as a link to the package version details page.
//
- TR_VERSION (const string& p, const version& v, const dir_path& r)
+ TR_VERSION (const package_name& p, const version& v, const dir_path& r)
: package_ (&p),
version_ (v.string ()),
stub_ (v.compare (wildcard_version, true) == 0),
@@ -204,7 +204,7 @@ namespace brep
operator() (xml::serializer&) const;
private:
- const string* package_;
+ const package_name* package_;
string version_;
bool stub_;
const dir_path* root_;