aboutsummaryrefslogtreecommitdiff
path: root/brep
diff options
context:
space:
mode:
Diffstat (limited to 'brep')
-rw-r--r--brep/module25
-rw-r--r--brep/module.cxx60
-rw-r--r--brep/options.cli43
-rw-r--r--brep/search2
-rw-r--r--brep/search.cxx21
-rw-r--r--brep/view2
-rw-r--r--brep/view.cxx6
7 files changed, 135 insertions, 24 deletions
diff --git a/brep/module b/brep/module
index e38d60d..08fbfea 100644
--- a/brep/module
+++ b/brep/module
@@ -92,6 +92,29 @@ namespace brep
module ();
module (const module& );
+ class param_scanner: public cli::scanner
+ {
+ public:
+ param_scanner (const name_values&) noexcept;
+
+ virtual bool
+ more ();
+
+ virtual const char*
+ peek ();
+
+ virtual const char*
+ next ();
+
+ virtual void
+ skip ();
+
+ private:
+ const name_values& name_values_;
+ name_values::const_iterator i_;
+ bool name_;
+ };
+
private:
virtual void
handle (request&, response&, log&);
@@ -110,7 +133,7 @@ namespace brep
{
// Just scan options to ensure there is no misspelled ones.
//
- module_options o (s, cli::unknown_mode::fail, cli::unknown_mode::fail);
+ options::module o (s, cli::unknown_mode::fail, cli::unknown_mode::fail);
}
// Diagnostics implementation details.
diff --git a/brep/module.cxx b/brep/module.cxx
index ceadc23..c52d13a 100644
--- a/brep/module.cxx
+++ b/brep/module.cxx
@@ -25,6 +25,8 @@ using namespace placeholders; // For std::bind's _1, etc.
namespace brep
{
+ // module
+ //
void module::
handle (request& rq, response& rs, log& l)
{
@@ -111,7 +113,7 @@ namespace brep
const_cast<char**> (argv.data ()),
"conf");
- module_options o (s, cli::unknown_mode::skip, cli::unknown_mode::skip);
+ options::module o (s, cli::unknown_mode::skip, cli::unknown_mode::skip);
verb_ = o.verb ();
}
catch (const server_error& e)
@@ -228,4 +230,60 @@ namespace brep
}
}
}
+
+ // module::param_scanner
+ //
+ module::param_scanner::
+ param_scanner (const name_values& nv) noexcept
+ : name_values_ (nv),
+ i_ (nv.begin ()),
+ name_ (true)
+ {
+ }
+
+ bool module::param_scanner::
+ more ()
+ {
+ return i_ != name_values_.end ();
+ }
+
+ const char* module::param_scanner::
+ peek ()
+ {
+ if (i_ != name_values_.end ())
+ return name_ ? i_->name.c_str () : i_->value.c_str ();
+ else
+ throw cli::eos_reached ();
+ }
+
+ const char* module::param_scanner::
+ next ()
+ {
+ if (i_ != name_values_.end ())
+ {
+ const char* r (name_ ? i_->name.c_str () : i_->value.c_str ());
+
+ if (!name_)
+ ++i_;
+
+ name_ = !name_;
+ return r;
+ }
+ else
+ throw cli::eos_reached ();
+ }
+
+ void module::param_scanner::
+ skip ()
+ {
+ if (i_ != name_values_.end ())
+ {
+ if (!name_)
+ ++i_;
+
+ name_ = !name_;
+ }
+ else
+ throw cli::eos_reached ();
+ }
}
diff --git a/brep/options.cli b/brep/options.cli
index b7c571e..2894979 100644
--- a/brep/options.cli
+++ b/brep/options.cli
@@ -7,23 +7,38 @@ include <cstdint>;
namespace brep
{
- class module_options
+ // Web module configuration options.
+ //
+ namespace options
{
- std::uint16_t verb = 0;
- };
+ class module
+ {
+ std::uint16_t verb = 0;
+ };
- class db_options
- {
- std::string db-host = "localhost";
- std::uint16_t db-port = 5432;
- };
+ class db
+ {
+ std::string db-host = "localhost";
+ std::uint16_t db-port = 5432;
+ };
- class search_options: module_options, db_options
- {
- size_t results-on-page = 10;
- };
+ class search: module, db
+ {
+ size_t results-on-page = 10;
+ };
+
+ class view: module, db
+ {
+ };
+ }
- class view_options: module_options, db_options
+ // Web module request parameters.
+ //
+ namespace params
{
- };
+ class search
+ {
+ size_t page = 0;
+ };
+ }
}
diff --git a/brep/search b/brep/search
index 078922e..0283859 100644
--- a/brep/search
+++ b/brep/search
@@ -24,7 +24,7 @@ namespace brep
init (cli::scanner&);
private:
- std::shared_ptr<search_options> options_;
+ std::shared_ptr<options::search> options_;
std::shared_ptr<odb::core::database> db_;
};
}
diff --git a/brep/search.cxx b/brep/search.cxx
index 3aa6503..9185aa5 100644
--- a/brep/search.cxx
+++ b/brep/search.cxx
@@ -30,9 +30,9 @@ namespace brep
{
MODULE_DIAG;
- options_ = make_shared<search_options> (s,
- cli::unknown_mode::fail,
- cli::unknown_mode::fail);
+ options_ = make_shared<options::search> (s,
+ cli::unknown_mode::fail,
+ cli::unknown_mode::fail);
db_ = shared_database (options_->db_host (), options_->db_port ());
@@ -141,6 +141,21 @@ namespace brep
o << "<br>\n" << p.name << "=" << p.value;
}
+ param_scanner s (ps);
+ unique_ptr<params::search> prm;
+
+ try
+ {
+ prm.reset (new params::search (s,
+ cli::unknown_mode::fail,
+ cli::unknown_mode::fail));
+ }
+ catch (const cli::unknown_argument& e)
+ {
+ throw invalid_request (400, e.what ());
+ }
+
+ o << "<br>\nPage num: " << prm->page ();
o << "<p>\n<b>Cookies:</b>";
for (const auto& c: rq.cookies ())
diff --git a/brep/view b/brep/view
index 69c7d3c..280b9ab 100644
--- a/brep/view
+++ b/brep/view
@@ -24,7 +24,7 @@ namespace brep
init (cli::scanner&);
private:
- std::shared_ptr<view_options> options_;
+ std::shared_ptr<options::view> options_;
std::shared_ptr<odb::core::database> db_;
};
}
diff --git a/brep/view.cxx b/brep/view.cxx
index 2f3bd17..3098e93 100644
--- a/brep/view.cxx
+++ b/brep/view.cxx
@@ -26,9 +26,9 @@ namespace brep
void view::
init (cli::scanner& s)
{
- options_ = make_shared<view_options> (s,
- cli::unknown_mode::fail,
- cli::unknown_mode::fail);
+ options_ = make_shared<options::view> (s,
+ cli::unknown_mode::fail,
+ cli::unknown_mode::fail);
db_ = shared_database (options_->db_host (), options_->db_port ());
}