From e28ab8f48c891c03cf4b3a8ed88b98d38a561960 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 8 Dec 2015 13:45:08 +0200 Subject: Separate brep module configuration from Apache server configuration --- brep/module | 63 ++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 21 deletions(-) (limited to 'brep/module') diff --git a/brep/module b/brep/module index 295744d..4ac6023 100644 --- a/brep/module +++ b/brep/module @@ -9,6 +9,7 @@ #include #include + #include #include @@ -23,6 +24,7 @@ namespace brep using web::status_code; using web::invalid_request; using web::sequence_error; + using web::option_descriptions; using web::name_value; using web::name_values; using web::request; @@ -94,12 +96,24 @@ namespace brep module (); module (const module& ); + static name_values + filter (const name_values&, const option_descriptions&); + + static option_descriptions + convert (const cli::options&); + + static void + append (option_descriptions& dst, const cli::options& src); + + static void + append (option_descriptions& dst, const option_descriptions& src); + // Can be used by module implementation to parse HTTP request parameters. // - class param_scanner: public cli::scanner + class name_value_scanner: public cli::scanner { public: - param_scanner (const name_values&) noexcept; + name_value_scanner (const name_values&) noexcept; virtual bool more (); @@ -120,36 +134,43 @@ namespace brep }; public: - // Can be called normally by the web server or our custom request - // dispatching mechanism. - // - virtual void - handle (request&, response&) = 0; + virtual const cli::options& + cli_options () const = 0; - bool - loaded () const noexcept {return loaded_;} + virtual void + init (cli::scanner&) = 0; - private: + // Can be overriden by custom request dispatcher to initialize sub-modules. + // virtual void - handle (request&, response&, log&); + init (const name_values&); virtual void init (const name_values&, log&); - // Can be overriden by module implementation which has configuration - // options. + virtual bool + handle (request&, response&) = 0; + + // web::module interface. // - virtual void - init (cli::scanner& s) - { - // Just scan options to ensure there is no misspelled ones. - // - options::module o (s, cli::unknown_mode::fail, cli::unknown_mode::fail); - } + public: + // Custom request dispatcher can aggregate its own option descriptions with + // sub-modules option descriptions. In this case it should still call the + // base implementation in order to include the brep::module's options. + // + virtual option_descriptions + options (); + + private: + virtual bool + handle (request&, response&, log&); + + name_values + expand_options (const name_values&); // Diagnostics implementation details. // - private: + protected: log* log_ {nullptr}; // Diagnostics backend provided by the web server. private: -- cgit v1.1