nhttpd add some new configfile handling

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@543 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
yjogol
2010-04-12 05:32:20 +00:00
parent bcbc815bcc
commit c091ba4db3
4 changed files with 74 additions and 3 deletions

View File

@@ -30,13 +30,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
typedef std::map<std::string, std::string> ConfigDataMap;
class CConfigFile class CConfigFile
{ {
private: private:
typedef std::map<std::string, std::string> ConfigDataMap;
ConfigDataMap configData; ConfigDataMap configData;
char delimiter; char delimiter;
bool saveDefaults; bool saveDefaults;
@@ -106,6 +105,7 @@ class CConfigFile
bool getUnknownKeyQueryedFlag() const { return unknownKeyQueryedFlag; } bool getUnknownKeyQueryedFlag() const { return unknownKeyQueryedFlag; }
void setUnknownKeyQueryedFlag(const bool val) { unknownKeyQueryedFlag = val; } void setUnknownKeyQueryedFlag(const bool val) { unknownKeyQueryedFlag = val; }
ConfigDataMap getConfigDataMap(){ return configData; }
}; };
#endif /* __configfile_h__ */ #endif /* __configfile_h__ */

View File

@@ -192,6 +192,8 @@ const CControlAPI::TyCgiCall CControlAPI::yCgiCallList[]=
// utils // utils
{"build_live_url", &CControlAPI::build_live_url, ""}, {"build_live_url", &CControlAPI::build_live_url, ""},
{"get_logo", &CControlAPI::logoCGI, "text/plain"}, {"get_logo", &CControlAPI::logoCGI, "text/plain"},
// settings
{"config", &CControlAPI::ConfigCGI, "text/plain"},
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -2224,3 +2226,70 @@ void CControlAPI::logoCGI(CyhookHandler *hh)
&channel_id); &channel_id);
hh->Write(NeutrinoAPI->getLogoFile(hh->WebserverConfigList["Tuxbox.LogosURL"], channel_id)); hh->Write(NeutrinoAPI->getLogoFile(hh->WebserverConfigList["Tuxbox.LogosURL"], channel_id));
} }
//-------------------------------------------------------------------------
void CControlAPI::ConfigCGI(CyhookHandler *hh)
{
bool load = true;
CConfigFile *Config = new CConfigFile(',');
ConfigDataMap conf;
std::string config_filename="";
std::string error = "";
std::string result = "";
if (hh->ParamList["action"] == "submit")
load = false;
// Para "config" describes the config type
if(hh->ParamList["config"] == "neutrino")
config_filename = NEUTRINO_CONFIGFILE;
else if(hh->ParamList["config"] == "nhttpd")
config_filename = HTTPD_CONFIGFILE;
else if(hh->ParamList["config"] == "yweb")
config_filename = YWEB_CONFIGFILE;
if(config_filename != ""){
Config->loadConfig(config_filename);
if(load){
conf = Config->getConfigDataMap();
ConfigDataMap::iterator it;
for(it = conf.begin(); it != conf.end(); it++){
std::string key =it->first;
replace(key,".","_dot_");
replace(key,"-","_bind_");
if(!(hh->ParamList["config"] == "nhttpd" && it->first == "mod_auth.password")){
// Output as json (default)
if (hh->ParamList["format"] == "json" || hh->ParamList["format"] == ""){
result += string_printf("%s: '%s',\n", (key).c_str(), (it->second).c_str());
}
}
}
} else {
for (CStringList::iterator it = hh->ParamList.begin(); it
!= hh->ParamList.end(); it++)
if(it->first != "_dc" && it->first != "action" && it->first != "format" && it->first != "config"){
Config->setString(it->first, it->second);
}
if(config_filename != "")
Config->saveConfig(config_filename);
}
}
else
error = string_printf("no config defined for: %s", (hh->ParamList["config"]).c_str() );
if(error == ""){
if (hh->ParamList["format"] == "json" || hh->ParamList["format"] == ""){
hh->WriteLn("{success: 'true', data:{");
hh->WriteLn(result);
hh->WriteLn("}}");
}
} else {
if (hh->ParamList["format"] == "json" || hh->ParamList["format"] == ""){
hh->WriteLn("{success: 'false', error:{");
hh->WriteLn(error);
hh->WriteLn("}}");
}
}
delete Config;
}

View File

@@ -98,6 +98,7 @@ private:
void updateBouquetCGI(CyhookHandler *hh); void updateBouquetCGI(CyhookHandler *hh);
void build_live_url(CyhookHandler *hh); void build_live_url(CyhookHandler *hh);
void logoCGI(CyhookHandler *hh); void logoCGI(CyhookHandler *hh);
void ConfigCGI(CyhookHandler *hh);
protected: protected:
static const unsigned int PLUGIN_DIR_COUNT = 5; static const unsigned int PLUGIN_DIR_COUNT = 5;

View File

@@ -25,7 +25,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// General central Definitions <configure!> // General central Definitions <configure!>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#define HTTPD_VERSION "3.3.0" // Webserver version (can be overloaded) #define HTTPD_VERSION "3.3.1" // Webserver version (can be overloaded)
#define YHTTPD_VERSION "1.3.1" // Webserver version (Version of yhttpd-core!) #define YHTTPD_VERSION "1.3.1" // Webserver version (Version of yhttpd-core!)
#define IADDR_LOCAL "127.0.0.1" // local IP #define IADDR_LOCAL "127.0.0.1" // local IP
#define HTTPD_NAME "yhttpd" // Webserver name (can be overloaded) #define HTTPD_NAME "yhttpd" // Webserver name (can be overloaded)
@@ -103,6 +103,7 @@
#define HTTPD_CONFIGDIR "/var/tuxbox/config" #define HTTPD_CONFIGDIR "/var/tuxbox/config"
#define HTTPD_CONFIGFILE HTTPD_CONFIGDIR "/nhttpd.conf" #define HTTPD_CONFIGFILE HTTPD_CONFIGDIR "/nhttpd.conf"
#define YWEB_CONFIGFILE HTTPD_CONFIGDIR "/Y-Web.conf"
#define PUBLICDOCUMENTROOT "/var/httpd" #define PUBLICDOCUMENTROOT "/var/httpd"
#define NEUTRINO_CONFIGFILE "/var/tuxbox/config/neutrino.conf" #define NEUTRINO_CONFIGFILE "/var/tuxbox/config/neutrino.conf"
#define HOSTEDDOCUMENTROOT "/mnt/hosted" #define HOSTEDDOCUMENTROOT "/mnt/hosted"