diff options
-rw-r--r-- | gentoobrowse/src/base.cpp | 45 | ||||
-rw-r--r-- | gentoobrowse/src/packages.cpp | 472 | ||||
-rw-r--r-- | gentoobrowse/src/search.cpp | 68 | ||||
-rw-r--r-- | gentoobrowse/src/test.cpp | 213 | ||||
-rw-r--r-- | gentoobrowse/src/user.cpp | 388 |
5 files changed, 594 insertions, 592 deletions
diff --git a/gentoobrowse/src/base.cpp b/gentoobrowse/src/base.cpp index e9c3033..23b5aa8 100644 --- a/gentoobrowse/src/base.cpp +++ b/gentoobrowse/src/base.cpp @@ -1,11 +1,11 @@ #ifndef GENTOOBROWSE_BASE_H #define GENTOOBROWSE_BASE_H -#include <icespider-routes-base.h> -#include <mash.h> #include <algorithm> #include <core.h> #include <exceptions.h> +#include <icespider-routes-base.h> +#include <mash.h> namespace GentooBrowse { ::Gentoo::UserPtr @@ -35,9 +35,11 @@ namespace GentooBrowse { std::transform(packages.begin(), packages.end(), std::inserter(ids, ids.begin()), [](auto p) { return p->categoryid; }); - categories.erase(std::remove_if(categories.begin(), categories.end(), [&ids](auto category) { - return ids.find(category->categoryid) == ids.end(); - }), categories.end()); + categories.erase(std::remove_if(categories.begin(), categories.end(), + [&ids](auto category) { + return ids.find(category->categoryid) == ids.end(); + }), + categories.end()); } void @@ -47,9 +49,11 @@ namespace GentooBrowse { std::transform(packages.begin(), packages.end(), std::inserter(ids, ids.begin()), [](auto p) { return p->categoryid; }); - categories.erase(std::remove_if(categories.begin(), categories.end(), [&ids](auto category) { - return ids.find(category->categoryid) == ids.end(); - }), categories.end()); + categories.erase(std::remove_if(categories.begin(), categories.end(), + [&ids](auto category) { + return ids.find(category->categoryid) == ids.end(); + }), + categories.end()); } void @@ -59,25 +63,26 @@ namespace GentooBrowse { std::transform(ebuilds.begin(), ebuilds.end(), std::inserter(ids, ids.begin()), [](auto e) { return e->packageid; }); - packages.erase(std::remove_if(packages.begin(), packages.end(), [&ids](auto package) { - return ids.find(package->packageid) == ids.end(); - }), packages.end()); + packages.erase(std::remove_if(packages.begin(), packages.end(), + [&ids](auto package) { + return ids.find(package->packageid) == ids.end(); + }), + packages.end()); } class SlicerNoRowsHandler : public IceSpider::ErrorHandler { - public: - IceSpider::ErrorHandlerResult - handleError(IceSpider::IHttpRequest *, const std::exception & ex) const - { - if (dynamic_cast<const Slicer::NoRowsReturned *>(&ex)) { - throw IceSpider::Http404_NotFound(); - } - return IceSpider::ErrorHandlerResult_Unhandled; + public: + IceSpider::ErrorHandlerResult + handleError(IceSpider::IHttpRequest *, const std::exception & ex) const + { + if (dynamic_cast<const Slicer::NoRowsReturned *>(&ex)) { + throw IceSpider::Http404_NotFound(); } + return IceSpider::ErrorHandlerResult_Unhandled; + } }; } PLUGIN(GentooBrowse::SlicerNoRowsHandler, IceSpider::ErrorHandler); #endif - diff --git a/gentoobrowse/src/packages.cpp b/gentoobrowse/src/packages.cpp index 3ef592d..54f58db 100644 --- a/gentoobrowse/src/packages.cpp +++ b/gentoobrowse/src/packages.cpp @@ -1,28 +1,30 @@ // Standard headers. -#include <irouteHandler.h> #include <core.h> -#include <util.h> +#include <irouteHandler.h> #include <slicer/serializer.h> +#include <util.h> // Interface headers. #include <mash.h> #include <portage.h> // Extra headers. -#include <xsltStreamSerializer.h> #include <icespider-routes-base.h> #include <safeMapFind.h> +#include <xsltStreamSerializer.h> namespace GentooBrowse { const IceSpider::RouteOptions noDefaultSerializersOptions { - false // addDefaultSerializers + false // addDefaultSerializers }; - template<typename I, typename T> std::map<I, T> makeMap(const std::vector<T> & items, const std::function<I(const T &)> & id) + template<typename I, typename T> + std::map<I, T> + makeMap(const std::vector<T> & items, const std::function<I(const T &)> & id) { std::map<I, T> rtn; for (const auto & item : items) { - rtn.insert({ id(item), item }); + rtn.insert({id(item), item}); } return rtn; } @@ -31,278 +33,267 @@ namespace GentooBrowse { // Route name: index // path: / - class index : public IceSpider::IRouteHandler, - public common { - public: - index(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/"), - common(core), - prx0(core->getProxy<Gentoo::Portage>()), - prx1(core->getProxy<Gentoo::Users>()), - _pd_syncs(3) - { - addRouteSerializer({ "application", "atom+xml" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/home-atom.xslt")); - addRouteSerializer({ "text", "html" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/home.xslt")); - } + class index : public IceSpider::IRouteHandler, public common { + public: + index(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/"), common(core), + prx0(core->getProxy<Gentoo::Portage>()), prx1(core->getProxy<Gentoo::Users>()), _pd_syncs(3) + { + addRouteSerializer({"application", "atom+xml"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/home-atom.xslt")); + addRouteSerializer({"text", "html"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/home.xslt")); + } - void execute(IceSpider::IHttpRequest * request) const - { - ::GentooBrowse::IndexPtr _responseModel = std::make_shared<::GentooBrowse::Index>(); - auto _ar_categories = prx0->getCategoriesWithRecentAdditionsAsync(_pd_syncs, request->getContext()); - auto _ar_ebuilds = prx0->getRecentAdditionsAsync(_pd_syncs, request->getContext()); - auto _ar_packages = prx0->getPackagesWithRecentAdditionsAsync(_pd_syncs, request->getContext()); - addUser(request, _responseModel); - std::future<::Gentoo::PackageIds> _ar_t; - if (_responseModel->user) { - _ar_t = prx1->trackedAsync(_responseModel->user->userid); - } - const auto ebuilds = _ar_ebuilds.get(); - const auto packages = GentooBrowse::makeMap<Ice::Int, Gentoo::PackagePtr>(_ar_packages.get(), [](auto p){ return p->packageid; }); - const auto categories = GentooBrowse::makeMap<Ice::Int, Gentoo::CategoryPtr>(_ar_categories.get(), [](auto c){ return c->categoryid; }); - ::Gentoo::PackageIds tracked; - if (_responseModel->user) { - tracked = _ar_t.get(); - } - for(const auto & ebuild : ebuilds) { - if (auto pi = packages.find(ebuild->packageid); pi != packages.end()) { - auto & p = pi->second; - if (auto ci = categories.find(p->categoryid); ci != categories.end()) { - auto & c = ci->second; - auto & s = _responseModel->syncs[ebuild->firstseen.substr(0, 10)]; - bool isTracked = std::find(tracked.begin(), tracked.end(), p->packageid) != tracked.end(); - auto & pw = s[{ isTracked, c->name }][{ isTracked, p->name }]; - if (!pw.detail) pw.detail = p; - pw.ebuilds.push_back(ebuild); - } + void + execute(IceSpider::IHttpRequest * request) const + { + ::GentooBrowse::IndexPtr _responseModel = std::make_shared<::GentooBrowse::Index>(); + auto _ar_categories = prx0->getCategoriesWithRecentAdditionsAsync(_pd_syncs, request->getContext()); + auto _ar_ebuilds = prx0->getRecentAdditionsAsync(_pd_syncs, request->getContext()); + auto _ar_packages = prx0->getPackagesWithRecentAdditionsAsync(_pd_syncs, request->getContext()); + addUser(request, _responseModel); + std::future<::Gentoo::PackageIds> _ar_t; + if (_responseModel->user) { + _ar_t = prx1->trackedAsync(_responseModel->user->userid); + } + const auto ebuilds = _ar_ebuilds.get(); + const auto packages = GentooBrowse::makeMap<Ice::Int, Gentoo::PackagePtr>(_ar_packages.get(), [](auto p) { + return p->packageid; + }); + const auto categories + = GentooBrowse::makeMap<Ice::Int, Gentoo::CategoryPtr>(_ar_categories.get(), [](auto c) { + return c->categoryid; + }); + ::Gentoo::PackageIds tracked; + if (_responseModel->user) { + tracked = _ar_t.get(); + } + for (const auto & ebuild : ebuilds) { + if (auto pi = packages.find(ebuild->packageid); pi != packages.end()) { + auto & p = pi->second; + if (auto ci = categories.find(p->categoryid); ci != categories.end()) { + auto & c = ci->second; + auto & s = _responseModel->syncs[ebuild->firstseen.substr(0, 10)]; + bool isTracked = std::find(tracked.begin(), tracked.end(), p->packageid) != tracked.end(); + auto & pw = s[{isTracked, c->name}][{isTracked, p->name}]; + if (!pw.detail) + pw.detail = p; + pw.ebuilds.push_back(ebuild); } } - request->response(this, _responseModel); } + request->response(this, _responseModel); + } - private: - const Gentoo::PortagePrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; - const ::Ice::Int _pd_syncs; + private: + const Gentoo::PortagePrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; + const ::Ice::Int _pd_syncs; }; // Route name: category // path: /packages/{category} - class category : public IceSpider::IRouteHandler, - public common { - public: - category(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/packages/{category}"), - common(core), - prx0(core->getProxy<Gentoo::Portage>()), - _pi_category(1) - { - addRouteSerializer({ "text", "html" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/category.xslt")); - } + class category : public IceSpider::IRouteHandler, public common { + public: + category(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/packages/{category}"), common(core), + prx0(core->getProxy<Gentoo::Portage>()), _pi_category(1) + { + addRouteSerializer({"text", "html"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/category.xslt")); + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_category(request->getURLParam<::std::string>(_pi_category)); - auto cat = prx0->findCategory(_p_category, request->getContext()); - auto _ar_pkgs = prx0->getPackagesInCategoryAsync(cat->categoryid, request->getContext()); - ::GentooBrowse::CategoryPtr model = std::make_shared<::GentooBrowse::Category>(); - model->category = cat; - model->packages = _ar_pkgs.get(); - addUser(request, model); - request->response(this, model); - } + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_category(request->getURLParam<::std::string>(_pi_category)); + auto cat = prx0->findCategory(_p_category, request->getContext()); + auto _ar_pkgs = prx0->getPackagesInCategoryAsync(cat->categoryid, request->getContext()); + ::GentooBrowse::CategoryPtr model = std::make_shared<::GentooBrowse::Category>(); + model->category = cat; + model->packages = _ar_pkgs.get(); + addUser(request, model); + request->response(this, model); + } - private: - const Gentoo::PortagePrxPtr prx0; - const ::Ice::Int _pi_category; + private: + const Gentoo::PortagePrxPtr prx0; + const ::Ice::Int _pi_category; }; // Route name: package // path: /packages/{category}/{package} - class package : public IceSpider::IRouteHandler, - public common { - public: - package(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/packages/{category}/{package}"), - common(core), - prx0(core->getProxy<Gentoo::Portage>()), - prx1(core->getProxy<Gentoo::Users>()), - _pi_category(1), - _pi_package(2) - { - addRouteSerializer({ "text", "html" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/package.xslt")); - } + class package : public IceSpider::IRouteHandler, public common { + public: + package(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/packages/{category}/{package}"), common(core), + prx0(core->getProxy<Gentoo::Portage>()), prx1(core->getProxy<Gentoo::Users>()), _pi_category(1), + _pi_package(2) + { + addRouteSerializer({"text", "html"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/package.xslt")); + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_category(request->getURLParam<::std::string>(_pi_category)); - auto _p_package(request->getURLParam<::std::string>(_pi_package)); - auto _ar_p = prx0->findPackageAsync(_p_category, _p_package, request->getContext()); - auto _ar_r = prx0->getRepositoriesAsync(request->getContext()); - auto _ar_cats = prx0->getAllCategoriesAsync(request->getContext()); - ::GentooBrowse::PackagePtr model = std::make_shared<::GentooBrowse::Package>(); - model->package = _ar_p.get(); - auto _ar_cl = prx0->getPackageChangeLogAsync(model->package->packageid, request->getContext()); - auto _ar_ebuilds = prx0->getPackageVersionDetailsAsync(model->package->packageid, request->getContext()); - auto _ar_bugs = prx0->getPackageBugsAsync(model->package->packageid, request->getContext()); - auto _ar_d = prx0->getPackageDependenciesAsync(model->package->packageid, request->getContext()); - auto _ar_rd = prx0->getPackageRuntimeDependenciesAsync(model->package->packageid, request->getContext()); - auto _ar_dp = prx0->getPackagesDependingAsync(model->package->packageid, request->getContext()); - auto _ar_m = prx0->getPackageMasksAsync(model->package->packageid, request->getContext()); - auto _ar_u = prx0->getPackageUsesAsync(model->package->packageid, request->getContext()); - auto _ar_urls = prx0->getPackageUrlsAsync(model->package->packageid, request->getContext()); - addUser(request, model); - std::future<::Gentoo::PackageIds> _ar_t; - if (model->user) { - _ar_t = prx1->trackedAsync(model->user->userid); - } - model->categories = _ar_cats.get(); - model->changelog = _ar_cl.get(); - model->ebuilds = _ar_ebuilds.get(); - model->bugs = _ar_bugs.get(); - model->dependencies = _ar_d.get(); - model->rdependencies = _ar_rd.get(); - model->depending = _ar_dp.get(); - model->masks = _ar_m.get(); - model->uses = _ar_u.get(); - model->repos = _ar_r.get(); - model->urls = _ar_urls.get(); - std::set<Ice::Int> ids({ model->package->categoryid }); - collateCategoryIds(ids, model->dependencies); - collateCategoryIds(ids, model->depending); - collateCategoryIds(ids, model->rdependencies); - model->categories.erase(std::remove_if(model->categories.begin(), model->categories.end(), [&ids](auto category) { - return ids.find(category->categoryid) == ids.end(); - }), model->categories.end()); - if (model->user) { - model->tracked = AdHoc::containerContains(_ar_t.get(), model->package->packageid); - } - request->response(this, model); + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_category(request->getURLParam<::std::string>(_pi_category)); + auto _p_package(request->getURLParam<::std::string>(_pi_package)); + auto _ar_p = prx0->findPackageAsync(_p_category, _p_package, request->getContext()); + auto _ar_r = prx0->getRepositoriesAsync(request->getContext()); + auto _ar_cats = prx0->getAllCategoriesAsync(request->getContext()); + ::GentooBrowse::PackagePtr model = std::make_shared<::GentooBrowse::Package>(); + model->package = _ar_p.get(); + auto _ar_cl = prx0->getPackageChangeLogAsync(model->package->packageid, request->getContext()); + auto _ar_ebuilds = prx0->getPackageVersionDetailsAsync(model->package->packageid, request->getContext()); + auto _ar_bugs = prx0->getPackageBugsAsync(model->package->packageid, request->getContext()); + auto _ar_d = prx0->getPackageDependenciesAsync(model->package->packageid, request->getContext()); + auto _ar_rd = prx0->getPackageRuntimeDependenciesAsync(model->package->packageid, request->getContext()); + auto _ar_dp = prx0->getPackagesDependingAsync(model->package->packageid, request->getContext()); + auto _ar_m = prx0->getPackageMasksAsync(model->package->packageid, request->getContext()); + auto _ar_u = prx0->getPackageUsesAsync(model->package->packageid, request->getContext()); + auto _ar_urls = prx0->getPackageUrlsAsync(model->package->packageid, request->getContext()); + addUser(request, model); + std::future<::Gentoo::PackageIds> _ar_t; + if (model->user) { + _ar_t = prx1->trackedAsync(model->user->userid); } - - private: - template<typename T> - static void collateCategoryIds(std::set<Ice::Int> & ids, const std::vector<T> & packages) - { - std::transform(packages.begin(), packages.end(), std::inserter(ids, ids.begin()), [](auto p) { - return p->categoryid; - }); + model->categories = _ar_cats.get(); + model->changelog = _ar_cl.get(); + model->ebuilds = _ar_ebuilds.get(); + model->bugs = _ar_bugs.get(); + model->dependencies = _ar_d.get(); + model->rdependencies = _ar_rd.get(); + model->depending = _ar_dp.get(); + model->masks = _ar_m.get(); + model->uses = _ar_u.get(); + model->repos = _ar_r.get(); + model->urls = _ar_urls.get(); + std::set<Ice::Int> ids({model->package->categoryid}); + collateCategoryIds(ids, model->dependencies); + collateCategoryIds(ids, model->depending); + collateCategoryIds(ids, model->rdependencies); + model->categories.erase(std::remove_if(model->categories.begin(), model->categories.end(), + [&ids](auto category) { + return ids.find(category->categoryid) == ids.end(); + }), + model->categories.end()); + if (model->user) { + model->tracked = AdHoc::containerContains(_ar_t.get(), model->package->packageid); } - const Gentoo::PortagePrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; - const ::Ice::Int _pi_category; - const ::Ice::Int _pi_package; - }; + request->response(this, model); + } + private: + template<typename T> + static void + collateCategoryIds(std::set<Ice::Int> & ids, const std::vector<T> & packages) + { + std::transform(packages.begin(), packages.end(), std::inserter(ids, ids.begin()), [](auto p) { + return p->categoryid; + }); + } + const Gentoo::PortagePrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; + const ::Ice::Int _pi_category; + const ::Ice::Int _pi_package; + }; // Route name: track package // path: /packages/{category}/{package}/tracked - class packageTrack : public IceSpider::IRouteHandler, - public common { - public: - packageTrack(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::PUT, "/packages/{category}/{package}/tracked"), - common(core), - prx0(core->getProxy<Gentoo::Portage>()), - prx1(core->getProxy<Gentoo::Users>()), - _pi_category(1), - _pi_package(2) - { - } + class packageTrack : public IceSpider::IRouteHandler, public common { + public: + packageTrack(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::PUT, "/packages/{category}/{package}/tracked"), + common(core), prx0(core->getProxy<Gentoo::Portage>()), prx1(core->getProxy<Gentoo::Users>()), + _pi_category(1), _pi_package(2) + { + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_category(request->getURLParam<::std::string>(_pi_category)); - auto _p_package(request->getURLParam<::std::string>(_pi_package)); - auto p = prx0->findPackage(_p_category, _p_package, request->getContext()); - auto u = this->currentUser(request); - prx1->track(u->userid, p->packageid); - request->response(204, "Tracked"); - } + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_category(request->getURLParam<::std::string>(_pi_category)); + auto _p_package(request->getURLParam<::std::string>(_pi_package)); + auto p = prx0->findPackage(_p_category, _p_package, request->getContext()); + auto u = this->currentUser(request); + prx1->track(u->userid, p->packageid); + request->response(204, "Tracked"); + } - private: - const Gentoo::PortagePrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; - const ::Ice::Int _pi_category; - const ::Ice::Int _pi_package; + private: + const Gentoo::PortagePrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; + const ::Ice::Int _pi_category; + const ::Ice::Int _pi_package; }; - // Route name: untrack package // path: /packages/{category}/{package}/tracked - class packageUntrack : public IceSpider::IRouteHandler, - public common { - public: - packageUntrack(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::DELETE, "/packages/{category}/{package}/tracked"), - common(core), - prx0(core->getProxy<Gentoo::Portage>()), - prx1(core->getProxy<Gentoo::Users>()), - _pi_category(1), - _pi_package(2) - { - } + class packageUntrack : public IceSpider::IRouteHandler, public common { + public: + packageUntrack(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::DELETE, "/packages/{category}/{package}/tracked"), + common(core), prx0(core->getProxy<Gentoo::Portage>()), prx1(core->getProxy<Gentoo::Users>()), + _pi_category(1), _pi_package(2) + { + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_category(request->getURLParam<::std::string>(_pi_category)); - auto _p_package(request->getURLParam<::std::string>(_pi_package)); - auto p = prx0->findPackage(_p_category, _p_package, request->getContext()); - auto u = this->currentUser(request); - prx1->untrack(u->userid, p->packageid); - request->response(204, "Untracked"); - } + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_category(request->getURLParam<::std::string>(_pi_category)); + auto _p_package(request->getURLParam<::std::string>(_pi_package)); + auto p = prx0->findPackage(_p_category, _p_package, request->getContext()); + auto u = this->currentUser(request); + prx1->untrack(u->userid, p->packageid); + request->response(204, "Untracked"); + } - private: - const Gentoo::PortagePrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; - const ::Ice::Int _pi_category; - const ::Ice::Int _pi_package; + private: + const Gentoo::PortagePrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; + const ::Ice::Int _pi_category; + const ::Ice::Int _pi_package; }; - // Route name: userAtom // path: /atom/{username} - class userAtom : public IceSpider::IRouteHandler, - public common { - public: - userAtom(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/atom/{username}", noDefaultSerializersOptions), - common(core), - prx0(core->getProxy<Gentoo::Portage>()), - prx1(core->getProxy<Gentoo::Users>()), - _pi_username(1) - { - addRouteSerializer({ "application", "atom+xml" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-atom.xslt")); - } + class userAtom : public IceSpider::IRouteHandler, public common { + public: + userAtom(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/atom/{username}", noDefaultSerializersOptions), + common(core), prx0(core->getProxy<Gentoo::Portage>()), prx1(core->getProxy<Gentoo::Users>()), + _pi_username(1) + { + addRouteSerializer({"application", "atom+xml"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-atom.xslt")); + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_username(request->getURLParam<::std::string>(_pi_username)); - auto user = prx1->find(_p_username); - auto _ar_cs = prx0->getAllCategoriesAsync(request->getContext()); - auto _ar_ps = prx0->getUserTrackedPackagesAsync(user->userid, request->getContext()); - auto _ar_vs = prx0->getUserTrackedRecentVersionsAsync(user->userid, 50, request->getContext()); - GentooBrowse::UserTrackedPtr ut = std::make_shared<GentooBrowse::UserTracked>(); - ut->categories = _ar_cs.get(); - ut->packages = _ar_ps.get(); - ut->versions = _ar_vs.get(); - common::trimPackages(ut->packages, ut->versions); - common::trimCategories(ut->categories, ut->packages); - request->response(this, ut); - } + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_username(request->getURLParam<::std::string>(_pi_username)); + auto user = prx1->find(_p_username); + auto _ar_cs = prx0->getAllCategoriesAsync(request->getContext()); + auto _ar_ps = prx0->getUserTrackedPackagesAsync(user->userid, request->getContext()); + auto _ar_vs = prx0->getUserTrackedRecentVersionsAsync(user->userid, 50, request->getContext()); + GentooBrowse::UserTrackedPtr ut = std::make_shared<GentooBrowse::UserTracked>(); + ut->categories = _ar_cs.get(); + ut->packages = _ar_ps.get(); + ut->versions = _ar_vs.get(); + common::trimPackages(ut->packages, ut->versions); + common::trimCategories(ut->categories, ut->packages); + request->response(this, ut); + } - private: - const Gentoo::PortagePrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; - const ::Ice::Int _pi_username; + private: + const Gentoo::PortagePrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; + const ::Ice::Int _pi_username; }; - } // namespace gentoobrowse // Register route handlers. @@ -312,4 +303,3 @@ FACTORY(GentooBrowse::package, IceSpider::RouteHandlerFactory); FACTORY(GentooBrowse::packageTrack, IceSpider::RouteHandlerFactory); FACTORY(GentooBrowse::packageUntrack, IceSpider::RouteHandlerFactory); FACTORY(GentooBrowse::userAtom, IceSpider::RouteHandlerFactory); - diff --git a/gentoobrowse/src/search.cpp b/gentoobrowse/src/search.cpp index e1740f8..0e405e1 100644 --- a/gentoobrowse/src/search.cpp +++ b/gentoobrowse/src/search.cpp @@ -1,63 +1,63 @@ // Standard headers. -#include <irouteHandler.h> #include <core.h> -#include <util.h> +#include <irouteHandler.h> #include <slicer/serializer.h> +#include <util.h> // Interface headers. #include <mash.h> #include <portage.h> // Extra headers. -#include <xsltStreamSerializer.h> #include <icespider-routes-base.h> #include <safeMapFind.h> +#include <xsltStreamSerializer.h> namespace GentooBrowse { // Base classes. } // namespace GentooBrowse - namespace GentooBrowse { // Route name: sitemap // path: /sitemap.xml class sitemap : public IceSpider::IRouteHandler { - public: - sitemap(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/sitemap.xml"), - prx0(core->getProxy<Gentoo::Portage>()) - { - addRouteSerializer({ "application", "xml" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/sitemap.xslt")); + public: + sitemap(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/sitemap.xml"), + prx0(core->getProxy<Gentoo::Portage>()) + { + addRouteSerializer({"application", "xml"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/sitemap.xslt")); + } + + void + execute(IceSpider::IHttpRequest * request) const + { + auto _ar_categories = prx0->getAllOverviewCategoriesAsync(request->getContext()); + auto _ar_packages = prx0->getAllPackagesAsync(request->getContext()); + ::GentooBrowse::SitemapPtr _responseModel = std::make_shared<::GentooBrowse::Sitemap>(); + auto categories = _ar_categories.get(); + auto packages = _ar_packages.get(); + for (const auto & super : categories) { + std::transform(super.second.begin(), super.second.end(), + std::inserter(_responseModel->categories, _responseModel->categories.begin()), + [&packages](auto c) { + Gentoo::Packages ps; + std::copy_if(packages.begin(), packages.end(), std::inserter(ps, ps.begin()), [&c](auto p) { + return p->categoryid == c->categoryid; + }); + return GentooBrowse::Wrappers::SiteMapCategory({c, ps}); + }); } + request->response(this, _responseModel); + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _ar_categories = prx0->getAllOverviewCategoriesAsync(request->getContext()); - auto _ar_packages = prx0->getAllPackagesAsync(request->getContext()); - ::GentooBrowse::SitemapPtr _responseModel = std::make_shared<::GentooBrowse::Sitemap>(); - auto categories = _ar_categories.get(); - auto packages = _ar_packages.get(); - for (const auto & super : categories) { - std::transform(super.second.begin(), super.second.end(), - std::inserter(_responseModel->categories, _responseModel->categories.begin()), [&packages](auto c) { - Gentoo::Packages ps; - std::copy_if(packages.begin(), packages.end(), std::inserter(ps, ps.begin()), [&c](auto p) { - return p->categoryid == c->categoryid; - }); - return GentooBrowse::Wrappers::SiteMapCategory({ c, ps }); - }); - } - request->response(this, _responseModel); - } - - private: - const Gentoo::PortagePrxPtr prx0; + private: + const Gentoo::PortagePrxPtr prx0; }; } // namespace GentooBrowse // Register route handlers. FACTORY(GentooBrowse::sitemap, IceSpider::RouteHandlerFactory); - diff --git a/gentoobrowse/src/test.cpp b/gentoobrowse/src/test.cpp index 1ba1278..ebb3e78 100644 --- a/gentoobrowse/src/test.cpp +++ b/gentoobrowse/src/test.cpp @@ -4,223 +4,235 @@ #include <core.h> #include <definedDirs.h> #include <filesystem> +#include <libxml++/parsers/domparser.h> #include <testRequest.h> #include <tidy.h> -#include <libxml++/parsers/domparser.h> using namespace IceSpider; -int streamGet(void * s) { return reinterpret_cast<std::istream *>(s)->get(); } -void streamUnget(void * s, unsigned char ch) { reinterpret_cast<std::istream *>(s)->putback(ch); } -Bool streamEof(void * s) { return reinterpret_cast<std::istream *>(s)->eof() ? yes : no; } +int +streamGet(void * s) +{ + return reinterpret_cast<std::istream *>(s)->get(); +} +void +streamUnget(void * s, unsigned char ch) +{ + reinterpret_cast<std::istream *>(s)->putback(ch); +} +Bool +streamEof(void * s) +{ + return reinterpret_cast<std::istream *>(s)->eof() ? yes : no; +} class ChromiumRequest : public TestRequest { - public: - ChromiumRequest(const Core * c, HttpMethod m, const std::string & p) : - TestRequest(c, m, p) - { - hdr["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.21 Safari/537.36"; - hdr["Accept-Encoding"] = "gzip, deflate, sdch"; - hdr["Accept-Language"] = "en-GB,en;q=0.8"; - } - - virtual void standardAssertions(const char * name) = 0; +public: + ChromiumRequest(const Core * c, HttpMethod m, const std::string & p) : TestRequest(c, m, p) + { + hdr["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/56.0.2924.21 Safari/537.36"; + hdr["Accept-Encoding"] = "gzip, deflate, sdch"; + hdr["Accept-Language"] = "en-GB,en;q=0.8"; + } + + virtual void standardAssertions(const char * name) = 0; }; class ChromiumRequestHtml : public ChromiumRequest { - public: - ChromiumRequestHtml(const Core * c, HttpMethod m, const std::string & p) : - ChromiumRequest(c, m, p) - { - hdr["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; - } - - virtual void standardAssertions(const char * name) override - { - auto h = getResponseHeaders(); - BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); - BOOST_REQUIRE_EQUAL(h["Content-Type"], "text/html"); - - TidyDoc tdoc = tidyCreate(); - TidyInputSource tis{ &output, &streamGet, &streamUnget, &streamEof }; - BOOST_REQUIRE_EQUAL(1, tidyOptSetBool(tdoc, TidyIndentContent, yes)); - BOOST_REQUIRE_EQUAL(1, tidyOptSetBool(tdoc, TidyQuiet, yes)); - BOOST_REQUIRE_EQUAL(1, tidyOptSetInt(tdoc, TidyWrapLen, 0)); - BOOST_REQUIRE_EQUAL(0, tidyParseSource(tdoc, &tis)); - BOOST_REQUIRE_EQUAL(0, tidyCleanAndRepair(tdoc)); - BOOST_REQUIRE_EQUAL(0, tidySaveFile(tdoc, (binDir / name).replace_extension(".html").c_str())); - BOOST_REQUIRE_EQUAL(0, tidyRunDiagnostics(tdoc)); - tidyRelease(tdoc); - } +public: + ChromiumRequestHtml(const Core * c, HttpMethod m, const std::string & p) : ChromiumRequest(c, m, p) + { + hdr["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; + } + + virtual void + standardAssertions(const char * name) override + { + auto h = getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); + BOOST_REQUIRE_EQUAL(h["Content-Type"], "text/html"); + + TidyDoc tdoc = tidyCreate(); + TidyInputSource tis {&output, &streamGet, &streamUnget, &streamEof}; + BOOST_REQUIRE_EQUAL(1, tidyOptSetBool(tdoc, TidyIndentContent, yes)); + BOOST_REQUIRE_EQUAL(1, tidyOptSetBool(tdoc, TidyQuiet, yes)); + BOOST_REQUIRE_EQUAL(1, tidyOptSetInt(tdoc, TidyWrapLen, 0)); + BOOST_REQUIRE_EQUAL(0, tidyParseSource(tdoc, &tis)); + BOOST_REQUIRE_EQUAL(0, tidyCleanAndRepair(tdoc)); + BOOST_REQUIRE_EQUAL(0, tidySaveFile(tdoc, (binDir / name).replace_extension(".html").c_str())); + BOOST_REQUIRE_EQUAL(0, tidyRunDiagnostics(tdoc)); + tidyRelease(tdoc); + } }; class ChromiumRequest404 : public ChromiumRequest { - public: - ChromiumRequest404(const Core * c, HttpMethod m, const std::string & p) : - ChromiumRequest(c, m, p) { } - - virtual void standardAssertions(const char *) override - { - auto h = getResponseHeaders(); - BOOST_REQUIRE_EQUAL(h["Status"], "404 Not found"); - } +public: + ChromiumRequest404(const Core * c, HttpMethod m, const std::string & p) : ChromiumRequest(c, m, p) { } + + virtual void + standardAssertions(const char *) override + { + auto h = getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "404 Not found"); + } }; class ChromiumRequestXml : public ChromiumRequest { - public: - ChromiumRequestXml(const Core * c, HttpMethod m, const std::string & p) : - ChromiumRequest(c, m, p) - { - hdr["Accept"] = "application/xml"; - } - - virtual void standardAssertions(const char *) override - { - auto h = getResponseHeaders(); - BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); - BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/xml"); - xmlpp::DomParser p; - p.parse_stream(this->output); - } +public: + ChromiumRequestXml(const Core * c, HttpMethod m, const std::string & p) : ChromiumRequest(c, m, p) + { + hdr["Accept"] = "application/xml"; + } + + virtual void + standardAssertions(const char *) override + { + auto h = getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); + BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/xml"); + xmlpp::DomParser p; + p.parse_stream(this->output); + } }; class ChromiumRequestAtom : public ChromiumRequest { - public: - ChromiumRequestAtom(const Core * c, HttpMethod m, const std::string & p) : - ChromiumRequest(c, m, p) - { - hdr["Accept"] = "application/atom+xml"; - } - - virtual void standardAssertions(const char *) override - { - auto h = getResponseHeaders(); - BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); - BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/atom+xml"); - xmlpp::DomParser p; - p.parse_stream(this->output); - } +public: + ChromiumRequestAtom(const Core * c, HttpMethod m, const std::string & p) : ChromiumRequest(c, m, p) + { + hdr["Accept"] = "application/atom+xml"; + } + + virtual void + standardAssertions(const char *) override + { + auto h = getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); + BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/atom+xml"); + xmlpp::DomParser p; + p.parse_stream(this->output); + } }; -BOOST_AUTO_TEST_CASE( cd ) +BOOST_AUTO_TEST_CASE(cd) { std::filesystem::current_path(rootDir.parent_path()); } -BOOST_FIXTURE_TEST_SUITE(ta, CoreWithDefaultRouter, * boost::unit_test::depends_on("cd")); +BOOST_FIXTURE_TEST_SUITE(ta, CoreWithDefaultRouter, *boost::unit_test::depends_on("cd")); -BOOST_AUTO_TEST_CASE( endpointCount ) +BOOST_AUTO_TEST_CASE(endpointCount) { BOOST_REQUIRE_EQUAL(25, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); BOOST_REQUIRE_EQUAL(5, routes.size()); } -BOOST_AUTO_TEST_CASE( home ) +BOOST_AUTO_TEST_CASE(home) { ChromiumRequestHtml request(this, HttpMethod::GET, "/"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( news ) +BOOST_AUTO_TEST_CASE(news) { ChromiumRequestHtml request(this, HttpMethod::GET, "/news"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( news_ruby_20_removal ) +BOOST_AUTO_TEST_CASE(news_ruby_20_removal) { ChromiumRequestHtml request(this, HttpMethod::GET, "/news/2016-12-06-ruby-20-removal"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( news_404 ) +BOOST_AUTO_TEST_CASE(news_404) { ChromiumRequest404 request(this, HttpMethod::GET, "/news/404"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( packages ) +BOOST_AUTO_TEST_CASE(packages) { ChromiumRequestHtml request(this, HttpMethod::GET, "/packages"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( packages_popular ) +BOOST_AUTO_TEST_CASE(packages_popular) { ChromiumRequestHtml request(this, HttpMethod::GET, "/packages/popular"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( packages_virtual ) +BOOST_AUTO_TEST_CASE(packages_virtual) { ChromiumRequestHtml request(this, HttpMethod::GET, "/packages/virtual"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( packages_404 ) +BOOST_AUTO_TEST_CASE(packages_404) { ChromiumRequest404 request(this, HttpMethod::GET, "/packages/404"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( packages_virtual_cron ) +BOOST_AUTO_TEST_CASE(packages_virtual_cron) { ChromiumRequestHtml request(this, HttpMethod::GET, "/packages/virtual/cron"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( packages_virtual_404 ) +BOOST_AUTO_TEST_CASE(packages_virtual_404) { ChromiumRequest404 request(this, HttpMethod::GET, "/packages/virtual/404"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( use ) +BOOST_AUTO_TEST_CASE(use) { ChromiumRequestHtml request(this, HttpMethod::GET, "/use"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( use_gles ) +BOOST_AUTO_TEST_CASE(use_gles) { ChromiumRequestHtml request(this, HttpMethod::GET, "/use/gles"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( use_404 ) +BOOST_AUTO_TEST_CASE(use_404) { ChromiumRequest404 request(this, HttpMethod::GET, "/use/404"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( usegroup ) +BOOST_AUTO_TEST_CASE(usegroup) { ChromiumRequestHtml request(this, HttpMethod::GET, "/usegroup"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( usegroup_gles ) +BOOST_AUTO_TEST_CASE(usegroup_gles) { ChromiumRequestHtml request(this, HttpMethod::GET, "/usegroup/i18n"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( search_default ) +BOOST_AUTO_TEST_CASE(search_default) { ChromiumRequestHtml request(this, HttpMethod::GET, "/search"); request.qs["criteria"] = "default"; @@ -228,28 +240,28 @@ BOOST_AUTO_TEST_CASE( search_default ) request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( search_sitemap ) +BOOST_AUTO_TEST_CASE(search_sitemap) { ChromiumRequestXml request(this, HttpMethod::GET, "/sitemap.xml"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( home_atom ) +BOOST_AUTO_TEST_CASE(home_atom) { ChromiumRequestAtom request(this, HttpMethod::GET, "/"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( news_atom ) +BOOST_AUTO_TEST_CASE(news_atom) { ChromiumRequestAtom request(this, HttpMethod::GET, "/news"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( user_atom ) +BOOST_AUTO_TEST_CASE(user_atom) { ChromiumRequestAtom request(this, HttpMethod::GET, "/atom/randomdan"); process(&request); @@ -257,4 +269,3 @@ BOOST_AUTO_TEST_CASE( user_atom ) } BOOST_AUTO_TEST_SUITE_END(); - diff --git a/gentoobrowse/src/user.cpp b/gentoobrowse/src/user.cpp index c764872..b7b06a1 100644 --- a/gentoobrowse/src/user.cpp +++ b/gentoobrowse/src/user.cpp @@ -1,16 +1,16 @@ // Standard headers. -#include <irouteHandler.h> #include <core.h> +#include <irouteHandler.h> #include <slicer/serializer.h> // Interface headers. #include <mash.h> -#include <users.h> #include <session.h> +#include <users.h> // Extra headers. -#include <xsltStreamSerializer.h> #include <icespider-routes-base.h> +#include <xsltStreamSerializer.h> namespace GentooBrowse { using namespace std::literals; @@ -20,241 +20,238 @@ namespace GentooBrowse { // Route name: login // path: /user/login class login : public IceSpider::IRouteHandler { - public: - login(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::POST, "/user/login"), - prx0(core->getProxy<IceSpider::SessionManager>()), - prx1(core->getProxy<Gentoo::Users>()) - { - } - - void execute(IceSpider::IHttpRequest * request) const - { - auto credentials = *request->getBody<GentooBrowse::CredentialsPtr>(); - auto user = prx1->authenticate(credentials->username, credentials->password); - auto s = prx0->createSession(); - s->variables[USERID] = boost::lexical_cast<std::string>(user->userid); - prx0->updateSession(s); - request->setCookie(SESSIONID, s->id, std::nullopt, "/"s); - request->responseRedirect("/user/home", "Authenticated"s); - } - - private: - const IceSpider::SessionManagerPrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; + public: + login(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::POST, "/user/login"), + prx0(core->getProxy<IceSpider::SessionManager>()), prx1(core->getProxy<Gentoo::Users>()) + { + } + + void + execute(IceSpider::IHttpRequest * request) const + { + auto credentials = *request->getBody<GentooBrowse::CredentialsPtr>(); + auto user = prx1->authenticate(credentials->username, credentials->password); + auto s = prx0->createSession(); + s->variables[USERID] = boost::lexical_cast<std::string>(user->userid); + prx0->updateSession(s); + request->setCookie(SESSIONID, s->id, std::nullopt, "/"s); + request->responseRedirect("/user/home", "Authenticated"s); + } + + private: + const IceSpider::SessionManagerPrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; }; // Route name: signup // path: /user/signup class signup : public IceSpider::IRouteHandler { - public: - signup(const IceSpider::Core *) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/signup") - { - addRouteSerializer({ "text", "html" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-signup.xslt")); - } - - void execute(IceSpider::IHttpRequest * request) const - { - request->response(this, std::make_shared<PageBase>()); - } + public: + signup(const IceSpider::Core *) : IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/signup") + { + addRouteSerializer({"text", "html"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-signup.xslt")); + } + + void + execute(IceSpider::IHttpRequest * request) const + { + request->response(this, std::make_shared<PageBase>()); + } }; // Route name: signup post // path: /user/signup class signupPost : public IceSpider::IRouteHandler { - public: - signupPost(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::POST, "/user/signup"), - prx1(core->getProxy<Gentoo::Users>()) - { - } - - void execute(IceSpider::IHttpRequest * request) const - { - auto signup = *request->getBody<GentooBrowse::SignUpPtr>(); - auto user = prx1->create(signup->username, signup->password, signup->realname, signup->email); - request->responseRedirect("/user/verification", "Pending verification"s); - } - - private: - const Gentoo::UsersPrxPtr prx1; + public: + signupPost(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::POST, "/user/signup"), prx1(core->getProxy<Gentoo::Users>()) + { + } + + void + execute(IceSpider::IHttpRequest * request) const + { + auto signup = *request->getBody<GentooBrowse::SignUpPtr>(); + auto user = prx1->create(signup->username, signup->password, signup->realname, signup->email); + request->responseRedirect("/user/verification", "Pending verification"s); + } + + private: + const Gentoo::UsersPrxPtr prx1; }; // Route name: verification // path: /user/verification class verification : public IceSpider::IRouteHandler { - public: - verification(const IceSpider::Core *) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/verification") - { - addRouteSerializer({ "text", "html" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-verification.xslt")); - } - - void execute(IceSpider::IHttpRequest * request) const - { - request->response(this, std::make_shared<PageBase>()); - } + public: + verification(const IceSpider::Core *) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/verification") + { + addRouteSerializer({"text", "html"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-verification.xslt")); + } + + void + execute(IceSpider::IHttpRequest * request) const + { + request->response(this, std::make_shared<PageBase>()); + } }; class verificationHandler { - protected: - verificationHandler(const IceSpider::Core * core) : - prx0(core->getProxy<IceSpider::SessionManager>()), - prx1(core->getProxy<Gentoo::Users>()) - { - } - - void execute(IceSpider::IHttpRequest * request, const std::string & _p_username, const std::string & _p_guid) const - { - auto user = prx1->verify(_p_username, _p_guid, request->getContext()); - auto s = prx0->createSession(); - s->variables[USERID] = boost::lexical_cast<std::string>(user->userid); - prx0->updateSession(s); - request->setCookie(SESSIONID, s->id, std::nullopt, "/"s); - request->responseRedirect("/user/home", "Verified, welcome!"s); - } - - private: - const IceSpider::SessionManagerPrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; + protected: + verificationHandler(const IceSpider::Core * core) : + prx0(core->getProxy<IceSpider::SessionManager>()), prx1(core->getProxy<Gentoo::Users>()) + { + } + + void + execute(IceSpider::IHttpRequest * request, const std::string & _p_username, const std::string & _p_guid) const + { + auto user = prx1->verify(_p_username, _p_guid, request->getContext()); + auto s = prx0->createSession(); + s->variables[USERID] = boost::lexical_cast<std::string>(user->userid); + prx0->updateSession(s); + request->setCookie(SESSIONID, s->id, std::nullopt, "/"s); + request->responseRedirect("/user/home", "Verified, welcome!"s); + } + + private: + const IceSpider::SessionManagerPrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; }; // Route name: verification post // path: /user/verification class verificationPost : public IceSpider::IRouteHandler, verificationHandler { - public: - verificationPost(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::POST, "/user/verification"), - verificationHandler(core), - _pn_username("username"), - _pn_guid("guid") - { - } - - void execute(IceSpider::IHttpRequest * request) const - { - auto _pbody(request->getBody<IceSpider::StringMap>()); - auto _p_username(request->getBodyParam<::std::string>(_pbody, _pn_username) / - [this]() { return requiredParameterNotFound<::std::string>("Body", _pn_username); }); - auto _p_guid(request->getBodyParam<::std::string>(_pbody, _pn_guid) / - [this]() { return requiredParameterNotFound<::std::string>("Body", _pn_guid); }); - verificationHandler::execute(request, _p_username, _p_guid); - } - - private: - const std::string _pn_username; - const std::string _pn_guid; + public: + verificationPost(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::POST, "/user/verification"), verificationHandler(core), + _pn_username("username"), _pn_guid("guid") + { + } + + void + execute(IceSpider::IHttpRequest * request) const + { + auto _pbody(request->getBody<IceSpider::StringMap>()); + auto _p_username(request->getBodyParam<::std::string>(_pbody, _pn_username) / [this]() { + return requiredParameterNotFound<::std::string>("Body", _pn_username); + }); + auto _p_guid(request->getBodyParam<::std::string>(_pbody, _pn_guid) / [this]() { + return requiredParameterNotFound<::std::string>("Body", _pn_guid); + }); + verificationHandler::execute(request, _p_username, _p_guid); + } + + private: + const std::string _pn_username; + const std::string _pn_guid; }; // Route name: verification post // path: /user/verification/{guid}/{username} class verificationGet : public IceSpider::IRouteHandler, verificationHandler { - public: - verificationGet(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/verification/{guid}/{username}"), - verificationHandler(core), - _pi_guid(2), - _pi_username(3) - { - } - - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_guid(request->getURLParam<::std::string>(_pi_guid)); - auto _p_username(request->getURLParam<::std::string>(_pi_username)); - verificationHandler::execute(request, _p_username, _p_guid); - } - - private: - const ::Ice::Int _pi_guid; - const ::Ice::Int _pi_username; + public: + verificationGet(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/verification/{guid}/{username}"), + verificationHandler(core), _pi_guid(2), _pi_username(3) + { + } + + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_guid(request->getURLParam<::std::string>(_pi_guid)); + auto _p_username(request->getURLParam<::std::string>(_pi_username)); + verificationHandler::execute(request, _p_username, _p_guid); + } + + private: + const ::Ice::Int _pi_guid; + const ::Ice::Int _pi_username; }; // Route name: home // path: /user/home - class home : public IceSpider::IRouteHandler, - public common { - public: - home(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/home"), - common(core), - prx0(core->getProxy<IceSpider::SessionManager>()), - prx1(core->getProxy<Gentoo::Users>()) - { - addRouteSerializer({ "text", "html" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-home.xslt")); - } - - void execute(IceSpider::IHttpRequest * request) const - { - PageBasePtr p = std::make_shared<PageBase>(); - addUser(request, p); - request->response(this, p); - } - - private: - const IceSpider::SessionManagerPrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; + class home : public IceSpider::IRouteHandler, public common { + public: + home(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/home"), common(core), + prx0(core->getProxy<IceSpider::SessionManager>()), prx1(core->getProxy<Gentoo::Users>()) + { + addRouteSerializer({"text", "html"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-home.xslt")); + } + + void + execute(IceSpider::IHttpRequest * request) const + { + PageBasePtr p = std::make_shared<PageBase>(); + addUser(request, p); + request->response(this, p); + } + + private: + const IceSpider::SessionManagerPrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; }; // Route name: tracked // path: /user/tracked - class tracked : public IceSpider::IRouteHandler, - public common { - public: - tracked(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/tracked"), - common(core), - prx0(core->getProxy<IceSpider::SessionManager>()), - prx1(core->getProxy<Gentoo::Users>()), - prx2(core->getProxy<Gentoo::Portage>()) - { - addRouteSerializer({ "text", "html" }, - std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-tracked.xslt")); - } - - void execute(IceSpider::IHttpRequest * request) const - { - PopularPtr u = std::make_shared<Popular>(); - auto _ar_c = prx2->getAllCategoriesAsync(request->getContext()); - addUser(request, u); - auto _ar_p = prx2->getUserTrackedPackagesAsync(u->user->userid, request->getContext()); - u->categories = _ar_c.get(); - u->packages = _ar_p.get(); - request->response(this, u); - } - - private: - const IceSpider::SessionManagerPrxPtr prx0; - const Gentoo::UsersPrxPtr prx1; - const Gentoo::PortagePrxPtr prx2; + class tracked : public IceSpider::IRouteHandler, public common { + public: + tracked(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/tracked"), common(core), + prx0(core->getProxy<IceSpider::SessionManager>()), prx1(core->getProxy<Gentoo::Users>()), + prx2(core->getProxy<Gentoo::Portage>()) + { + addRouteSerializer({"text", "html"}, + std::make_shared<IceSpider::XsltStreamSerializer::IceSpiderFactory>("xslt/user-tracked.xslt")); + } + + void + execute(IceSpider::IHttpRequest * request) const + { + PopularPtr u = std::make_shared<Popular>(); + auto _ar_c = prx2->getAllCategoriesAsync(request->getContext()); + addUser(request, u); + auto _ar_p = prx2->getUserTrackedPackagesAsync(u->user->userid, request->getContext()); + u->categories = _ar_c.get(); + u->packages = _ar_p.get(); + request->response(this, u); + } + + private: + const IceSpider::SessionManagerPrxPtr prx0; + const Gentoo::UsersPrxPtr prx1; + const Gentoo::PortagePrxPtr prx2; }; // Route name: logout // path: /user/logout class logout : public IceSpider::IRouteHandler { - public: - logout(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/logout"), - prx0(core->getProxy<IceSpider::SessionManager>()) - { - } - - void execute(IceSpider::IHttpRequest * request) const - { - prx0->destroySession(*request->getCookieParam<std::string>(SESSIONID)); - request->setCookie(SESSIONID, std::string(), std::nullopt, "/"s, false, 0); - request->responseRedirect("/", "Logged out"s); - } - - private: - const IceSpider::SessionManagerPrxPtr prx0; + public: + logout(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/user/logout"), + prx0(core->getProxy<IceSpider::SessionManager>()) + { + } + + void + execute(IceSpider::IHttpRequest * request) const + { + prx0->destroySession(*request->getCookieParam<std::string>(SESSIONID)); + request->setCookie(SESSIONID, std::string(), std::nullopt, "/"s, false, 0); + request->responseRedirect("/", "Logged out"s); + } + + private: + const IceSpider::SessionManagerPrxPtr prx0; }; - } // namespace gentoobrowse // Register route handlers. @@ -267,4 +264,3 @@ FACTORY(GentooBrowse::signupPost, IceSpider::RouteHandlerFactory); FACTORY(GentooBrowse::verification, IceSpider::RouteHandlerFactory); FACTORY(GentooBrowse::verificationGet, IceSpider::RouteHandlerFactory); FACTORY(GentooBrowse::verificationPost, IceSpider::RouteHandlerFactory); - |