diff options
Diffstat (limited to 'src/ContentManager.cpp')
-rw-r--r-- | src/ContentManager.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/ContentManager.cpp b/src/ContentManager.cpp index a110e05..da1ab65 100644 --- a/src/ContentManager.cpp +++ b/src/ContentManager.cpp @@ -7,12 +7,16 @@ void ContentManager::SetTemplateSystem(std::shared_ptr<TemplateManager> const & bool ContentManager::RegisterModule(std::shared_ptr<Content> ctnt) { - std::string const & basePath = ctnt->GetUriBasePath(); + std::string & basePath = ctnt->GetUriBasePath(); + ContentManager::RemoveGarbageSlashes(basePath); if (basePath.empty() == true) { return false; } +#if 0 + std::cout << "Base URI: " << basePath << std::endl; +#endif m_ContentModules[basePath] = ctnt; return true; @@ -29,11 +33,32 @@ bool ContentManager::InitAll(void) ret = false; } - Redirections const & rs = content.second->GetRedirections(); + Redirections & rs = content.second->GetRedirections(); for (auto & redirect : rs) { + ContentManager::RemoveGarbageSlashes(redirect); + if (redirect == content.second->GetUriBasePath()) + { + continue; + } + if (m_ContentModulesRoutes.find(redirect) != m_ContentModulesRoutes.end()) + { + std::cerr << "Redirect URI already exists: " << redirect << std::endl; + } + else + { +#if 0 + std::cout << "Redirect URI: " << redirect << std::endl; +#endif + } m_ContentModulesRoutes[redirect] = content.second; } + + std::string & basePath = content.second->GetUriBasePath(); + if (basePath.back() == '/') + { + basePath.pop_back(); + } } return ret; @@ -107,3 +132,18 @@ ContentModules const & ContentManager::GetAllModulesRoutes() const { return m_ContentModulesRoutes; } + +void ContentManager::RemoveGarbageSlashes(std::string & uri_basepath) +{ + size_t start_pos = 0; + static const std::string from = "//"; + static const std::string to = "/"; + + if (from.empty()) + return; + while ((start_pos = uri_basepath.find(from, start_pos)) != std::string::npos) + { + uri_basepath.replace(start_pos, from.length(), to); + start_pos += to.length(); + } +} |