Skip to content

Commit

Permalink
disable debug services by default
Browse files Browse the repository at this point in the history
  • Loading branch information
abeylot committed Mar 5, 2024
1 parent 6a3186d commit 6be139e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 20 deletions.
18 changes: 18 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
<parameter name="locale" value="fr;en"/>
<parameter name="DefaultColor" value="#EEFFEE"/>

<!-- various debug services -->
<parameter name="PingService" value="disabled"/>
<parameter name="RelationListService" value="disabled"/>
<parameter name="IdxListService" value="disabled"/>
<parameter name="IdxDetailService" value="disabled"/>
<parameter name="RelationDetailService" value="disabled"/>
<parameter name="WayDetailService" value="disabled"/>
<parameter name="SvgService" value="disabled"/>

<!-- map test service -->
<parameter name="MapDisplayService" value="enabled"/>

<!-- service that serves tiles -->
<parameter name="TileService" value="enabled"/>

<!-- geolocation service -->
<parameter name="GeolocationService" value="enabled"/>

<shp_file name="water-polygons-split-4326/water_polygons" tag="shape" value="ocean"/>
<shp_file name="ne_10m_admin_0_boundary_lines_land/ne_10m_admin_0_boundary_lines_land" tag="shape" value="frontier"/>
<shp_file name="ne_10m_lakes/ne_10m_lakes" tag="shape" value="lake"/>
Expand Down
14 changes: 8 additions & 6 deletions helpers/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,26 @@ struct ParmsXmlVisitor
{
}

long long getNumParam(const std::string& key, long long defaultValue)
long long getNumParam(const std::string& key, long long defaultValue) const
{
if(parameters.count(key)) return atoll(parameters[key].c_str());
auto it = parameters.find(key);
if(it != parameters.end()) return atoll(it->second.c_str());
else return defaultValue;
}

long long getNumParam(const std::string& key)
long long getNumParam(const std::string& key) const
{
return getNumParam(key, 0);
}

std::string getParam(std::string key, std::string defaultValue)
std::string getParam(std::string key, std::string defaultValue) const
{
if(parameters.count(key)) return parameters[key];
auto it = parameters.find(key);
if(it != parameters.end()) return it->second;
else return defaultValue;
}

std::string getParam(const std::string& key)
std::string getParam(const std::string& key) const
{
return getParam(key, "");
}
Expand Down
4 changes: 3 additions & 1 deletion server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ template<typename MSG> struct Exec
//printf("%s\n",url.c_str());
//time_t ctt = time(0);
//std::cout << asctime(localtime(&ctt)) << std::endl;
ServiceInterface* s = ServicesFactory::getService(url, params);
ServiceInterface* s = ServicesFactory::getService(url);
if(s)
{
rep = s->processRequest(m,mger);
Expand Down Expand Up @@ -263,6 +263,8 @@ int main(int argc, char *argv[])
XmlFileParser<ParmsXmlVisitor>::parseXmlFile(config,params);
fclose(config);

ServicesFactory::init(params);

std::vector<IndexDesc*> indexes;
std::map<std::string, std::string> symbols;
std::map<std::string, std::string> charconvs;
Expand Down
79 changes: 67 additions & 12 deletions services/ServicesFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,72 @@
#include "ServicesFactory.hpp"
#include <stdlib.h>
ServiceInterface* ServicesFactory::getService(std::string service, ParmsXmlVisitor& params)

bool ServicesFactory::_enabledPingService{false};
bool ServicesFactory::_enabledRelationListService{false};
bool ServicesFactory::_enabledIdxListService{false};
bool ServicesFactory::_enabledIdxDetailService{false};
bool ServicesFactory::_enabledRelationDetailService{false};
bool ServicesFactory::_enabledWayDetailService{false};
bool ServicesFactory::_enabledSvgService{false};
bool ServicesFactory::_enabledMapDisplayService{false};
bool ServicesFactory::_enabledTileService{false};
bool ServicesFactory::_enabledGeoLocationService{false};

int ServicesFactory::_cacheLevel;
std::string ServicesFactory::_defaultColor;
std::string ServicesFactory::_locale;

void ServicesFactory::init(const ParmsXmlVisitor& params)
{
_locale = params.getParam("locale");
_cacheLevel = params.getNumParam("CacheLevel", 8);
_defaultColor = params.getParam("DefaultColor");

_enabledPingService = (params.getParam("PingService") == "enabled");
if(_enabledPingService) std::cout << "ping service enabled \n";

_enabledRelationListService = (params.getParam("RelationListService") == "enabled");
if(_enabledRelationListService) std::cout << "relation list service enabled \n";

_enabledIdxListService = (params.getParam("IdxListService") == "enabled");
if(_enabledIdxListService) std::cout << "index list service enabled \n";

_enabledIdxDetailService = (params.getParam("IdxDetailService") == "enabled");
if(_enabledIdxDetailService) std::cout << "index detail service enabled \n";

_enabledRelationDetailService = (params.getParam("RelationDetailService") == "enabled");
if(_enabledRelationDetailService) std::cout << "relation detail service enabled \n";

_enabledWayDetailService = (params.getParam("WayDetailService") == "enabled");
if(_enabledWayDetailService) std::cout << "way detail service enabled \n";

_enabledSvgService = (params.getParam("SvgService") == "enabled");
if(_enabledSvgService) std::cout << "svg service enabled \n";

_enabledMapDisplayService = (params.getParam("MapDisplayService") == "enabled");
if(_enabledMapDisplayService) std::cout << "map display service enabled \n";

_enabledTileService = (params.getParam("TileService") == "enabled");
if(_enabledTileService) std::cout << "tile service enabled \n";

_enabledGeoLocationService = (params.getParam("GeolocationService") == "enabled");
if(_enabledGeoLocationService) std::cout << "geolocation service enabled \n";

}


ServiceInterface* ServicesFactory::getService(std::string service)
{
if(service == "/ping") return new Ping;
if(service == "/geoloc") return new Geolocation;
else if (service == "/relation/list") return new RelationList;
else if (service == "/index/list") return new IdxList;
else if (service == "/index/get") return new IdxDetail;
else if (service == "/relation/get") return new RelationDetail;
else if (service == "/way/get") return new WayDetail;
else if (service == "/svgMap.svg") return new Svg;
else if ((service == "/MapDisplay")||(service =="/")) return new MapDisplay;
else if(service.find(".svg") != std::string::npos)
if(_enabledPingService && service == "/ping") return new Ping;
else if(_enabledGeoLocationService && service == "/geoloc") return new Geolocation;
else if (_enabledRelationListService && service == "/relation/list") return new RelationList;
else if (_enabledIdxListService && service == "/index/list") return new IdxList;
else if (_enabledIdxDetailService && service == "/index/get") return new IdxDetail;
else if (_enabledRelationDetailService && service == "/relation/get") return new RelationDetail;
else if (_enabledWayDetailService && service == "/way/get") return new WayDetail;
else if (_enabledSvgService && service == "/svgMap.svg") return new Svg;
else if (_enabledMapDisplayService && ((service == "/MapDisplay")||(service =="/"))) return new MapDisplay;
else if(_enabledTileService && service.find(".svg") != std::string::npos)
{
unsigned int pos = 0;
const char* c = service.c_str();
Expand All @@ -25,7 +80,7 @@ ServiceInterface* ServicesFactory::getService(std::string service, ParmsXmlVisit
while(pos < service.length() && (*(c+pos) != '/')) pos++;
if(pos < service.length()) y = atoll(c+pos+1);
//std::cout << x <<":" << y << ";" << z << "\n";
return new Tile(z, x, y, params.getNumParam("CacheLevel", 8), params.getParam("locale"), params.getParam("DefaultColor", "#888888"));
return new Tile(z, x, y, _cacheLevel, _locale, _defaultColor);

}
else return NULL;
Expand Down
19 changes: 18 additions & 1 deletion services/ServicesFactory.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef SERVICESFACTORY_HPP
#define SERVICESFACTORY_HPP
#include <string>
#include "../CompiledDataManager.hpp"
#include "Ping.hpp"
#include "RelationList.hpp"
Expand All @@ -15,8 +16,24 @@
class ServicesFactory
{
private:
static bool _enabledPingService;
static bool _enabledRelationListService;
static bool _enabledIdxListService;
static bool _enabledIdxDetailService;
static bool _enabledRelationDetailService;
static bool _enabledWayDetailService;
static bool _enabledSvgService;
static bool _enabledMapDisplayService;
static bool _enabledTileService;
static bool _enabledGeoLocationService;
static int _cacheLevel;
static std::string _defaultColor;
static std::string _locale;


public:
static ServiceInterface* getService(std::string service,ParmsXmlVisitor& params);
static void init(const ParmsXmlVisitor& params);
static ServiceInterface* getService(std::string service);
static void releaseService(ServiceInterface* service);
};
#endif

0 comments on commit 6be139e

Please sign in to comment.