summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/cgi/cgiProgRouter.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp
index 9218c89..ff7c864 100644
--- a/project2/cgi/cgiProgRouter.cpp
+++ b/project2/cgi/cgiProgRouter.cpp
@@ -36,7 +36,7 @@ class RoutingTable {
std::string routeScriptPath;
const std::string & present(const std::string & path, VarMap & vars) const {
- BOOST_FOREACH(const auto route, routes) {
+ BOOST_FOREACH(const auto & route, routes) {
vars.clear();
if (route->matches(path, vars)) {
return route->present;
@@ -74,12 +74,13 @@ class RoutingTable {
public:
Route(ScriptNodePtr s) :
SourceObject(s),
- present(s->value("present").as<std::string>())
+ present(s->value("present").as<std::string>()),
+ path(s->value("path").as<std::string>())
{
- boost::filesystem::path path = s->value("path").as<std::string>();
- boost::filesystem::path::iterator p = path.begin();
+ boost::filesystem::path fspath = path;
+ boost::filesystem::path::iterator p = fspath.begin();
p++;
- while(p != path.end() && p->string() != ".") {
+ while(p != fspath.end() && p->string() != ".") {
switch (p->string().front()) {
case '{':
routeElems.push_back(new RouteVar(p->string()));
@@ -105,6 +106,7 @@ class RoutingTable {
typedef std::list<RouteElemPtr> RouteElems;
RouteElems routeElems;
const std::string present;
+ const std::string path;
};
typedef boost::intrusive_ptr<Route> RoutePtr;
@@ -184,3 +186,34 @@ class ProgRouter : public Router {
};
DECLARE_CUSTOM_COMPONENT_LOADER("progRouter", ProgRouter, ProgRouterLoader, RouterLoader);
+
+class Routes : public RowSet {
+ public:
+ Routes(ScriptNodePtr s) :
+ RowSet(s) { }
+ class RouteRowState : public RowState {
+ public:
+ RouteRowState() {
+ columns.insert(new Column(0, "present"));
+ columns.insert(new Column(1, "path"));
+ fields.resize(2);
+ }
+ const Columns & getColumns() const { return columns; }
+ mutable Columns columns;
+ friend class Routes;
+ };
+ void execute(const Glib::ustring & filter, const RowProcessor * rp) const
+ {
+ RouteRowState rs;
+ BOOST_FOREACH(const auto & r, ProgRouterLoader::routingTable.routes) {
+ if (boost::algorithm::starts_with(r->path, filter)) {
+ rs.fields[0] = VariableType(r->present);
+ rs.fields[1] = VariableType(r->path);
+ rs.process(rp);
+ }
+ }
+ }
+};
+
+DECLARE_LOADER("routes", Routes);
+