Project "Tuxbox-GIT: apps": The branch, master has been updated via 1c25bb13f2db3d7e5a78f3f6b4cde362eefa1645 (commit) from b87baa0024402ce77dab20bd3e7f69b2439bf3b2 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 1c25bb13f2db3d7e5a78f3f6b4cde362eefa1645 Author: yjogol <yjogol@e54a6e83-5905-42d5-8d5c-058d10e6a962> Date: Thu Apr 2 21:41:51 2015 +0200 yWeb: introduce multilanguage (part2) port multilanguage function from N-HD bump yhttpd_core 1.3.0 Signed-off-by: GetAway <get-a...@t-online.de> diff --git a/tuxbox/neutrino/daemons/nhttpd/web/Y_Blocks.txt b/tuxbox/neutrino/daemons/nhttpd/web/Y_Blocks.txt index 73d353d..915360c 100644 --- a/tuxbox/neutrino/daemons/nhttpd/web/Y_Blocks.txt +++ b/tuxbox/neutrino/daemons/nhttpd/web/Y_Blocks.txt @@ -58,6 +58,7 @@ start-block~nhttpd_save_settings {=ini-set:/var/tuxbox/config/nhttpd.conf;WebsiteMain.override_directory;{=override_directory=}~cache=} {=ini-set:/var/tuxbox/config/nhttpd.conf;mod_sendfile.mime_types;{=mod_sendfile_mime_types=}~cache=} {=ini-set:/var/tuxbox/config/nhttpd.conf;mod_sendfile.sendAll;{=mod_sendfile_sendAll=}~cache=} +{=ini-set:/var/tuxbox/config/nhttpd.conf;Language.selected;{=language=}~cache=} {=ini-set:/var/tuxbox/config/nhttpd.conf;Tuxbox.LogosURL;{=Tuxbox_LogosURL=}~save=} {=func:do_reload_httpd_config=} end-block~nhttpd_save_settings diff --git a/tuxbox/neutrino/daemons/nhttpd/yconfig.h b/tuxbox/neutrino/daemons/nhttpd/yconfig.h index d8f80e0..0a780b3 100644 --- a/tuxbox/neutrino/daemons/nhttpd/yconfig.h +++ b/tuxbox/neutrino/daemons/nhttpd/yconfig.h @@ -33,7 +33,7 @@ // General central Definitions <configure!> //----------------------------------------------------------------------------- #define HTTPD_VERSION "3.1.8" // Webserver version (can be overloaded) -#define YHTTPD_VERSION "1.2.0" // Webserver version (Version of yhttpd-core!) +#define YHTTPD_VERSION "1.3.0" // Webserver version (Version of yhttpd-core!) #define IADDR_LOCAL "127.0.0.1" // local IP #define HTTPD_NAME "yhttpd" // Webserver name (can be overloaded) #define YHTTPD_NAME "yhttpd_core" // Webserver name (Name of yhttpd-core!) diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd.cpp b/tuxbox/neutrino/daemons/nhttpd/yhttpd.cpp index ef6c27b..652d939 100644 --- a/tuxbox/neutrino/daemons/nhttpd/yhttpd.cpp +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd.cpp @@ -12,6 +12,7 @@ // yhttpd #include "yconfig.h" #include "ylogging.h" +#include "ylanguage.h" #include "yhook.h" #ifdef Y_CONFIG_USE_YPARSER @@ -96,6 +97,11 @@ static void sig_catch(int msignal) } //----------------------------------------------------------------------------- +void yhttpd_reload_config() { + if (yhttpd) + yhttpd->ReadConfig(); +} +//----------------------------------------------------------------------------- // Main Entry //----------------------------------------------------------------------------- int main(int argc, char **argv) @@ -201,6 +207,7 @@ Cyhttpd::~Cyhttpd() { if(webserver) delete webserver; + CLanguage::deleteInstance(); webserver = NULL; } @@ -498,6 +505,7 @@ void Cyhttpd::ReadConfig(void) // language ConfigList["Language.directory"] = Config->getString("Language.directory", HTTPD_LANGUAGEDIR); ConfigList["Language.selected"] = Config->getString("Language.selected", HTTPD_DEFAULT_LANGUAGE); + yhttpd->ReadLanguage(); // Read App specifig settings by Hook CyhookHandler::Hooks_ReadConfig(Config, ConfigList); @@ -508,3 +516,13 @@ void Cyhttpd::ReadConfig(void) log_level_printf(3,"ReadConfig End\n"); delete Config; } +//----------------------------------------------------------------------------- +// Read Webserver Configurationfile for languages +//----------------------------------------------------------------------------- +void Cyhttpd::ReadLanguage(void) { + // Init Class vars + CLanguage *lang = CLanguage::getInstance(); + log_level_printf(3, "ReadLanguage:%s\n", + ConfigList["Language.selected"].c_str()); + lang->setLanguage(ConfigList["Language.selected"]); +} diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd.h b/tuxbox/neutrino/daemons/nhttpd/yhttpd.h index 507ad25..1466021 100644 --- a/tuxbox/neutrino/daemons/nhttpd/yhttpd.h +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd.h @@ -45,6 +45,7 @@ public: void hooks_attach(); // Add a Hook-Class to HookList void hooks_detach(); // Remove a Hook-Class from HookList void ReadConfig(void); // Read the config file for the webserver + void ReadLanguage(void); // Read Language Files }; #endif // __yhttpd_h__ diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/Makefile.am b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/Makefile.am index 692120e..37bcdac 100644 --- a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/Makefile.am +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/Makefile.am @@ -14,5 +14,10 @@ noinst_LIBRARIES = libyhttpd.a libyhttpd_a_SOURCES = \ ylogging.cpp helper.cpp \ - ywebserver.cpp yconnection.cpp yrequest.cpp yresponse.cpp yhook.cpp ysocket.cpp - + ywebserver.cpp \ + yconnection.cpp \ + yrequest.cpp \ + yresponse.cpp \ + yhook.cpp \ + ysocket.cpp \ + ylanguage.cpp diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.cpp b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.cpp new file mode 100644 index 0000000..43389c5 --- /dev/null +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.cpp @@ -0,0 +1,101 @@ +//============================================================================= +// YHTTPD +// Language +//============================================================================= + +// c +#include <cstdarg> +#include <cstdio> +#include <cstdlib> +#include <unistd.h> + +// yhttpd +#include <yconfig.h> +#include <yhttpd.h> +#include "ytypes_globals.h" +#include "ylanguage.h" +#include "yconnection.h" + +//============================================================================= +// Instance Handling - like Singelton Pattern +//============================================================================= +//----------------------------------------------------------------------------- +// Init as Singelton +//----------------------------------------------------------------------------- +CLanguage* CLanguage::instance = NULL; +CConfigFile* CLanguage::DefaultLanguage = NULL; +CConfigFile* CLanguage::ConfigLanguage = NULL; +std::string CLanguage::language = ""; +std::string CLanguage::language_dir = ""; +//----------------------------------------------------------------------------- +// There is only one Instance +//----------------------------------------------------------------------------- +CLanguage *CLanguage::getInstance(void) +{ + if (!instance) + instance = new CLanguage(); + return instance; +} + +//----------------------------------------------------------------------------- +void CLanguage::deleteInstance(void) +{ + if (instance) + delete instance; + instance = NULL; +} + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CLanguage::CLanguage(void) +{ + DefaultLanguage = new CConfigFile(','); + ConfigLanguage = new CConfigFile(','); + language = ""; + language_dir =getLanguageDir(); +} + +//----------------------------------------------------------------------------- +CLanguage::~CLanguage(void) +{ + delete DefaultLanguage; + delete ConfigLanguage; +} + +//============================================================================= + +//----------------------------------------------------------------------------- +void CLanguage::setLanguage(std::string _language) +{ + language=_language; + ConfigLanguage->loadConfig(language_dir + "/" + _language); + DefaultLanguage->loadConfig(language_dir + "/" + HTTPD_DEFAULT_LANGUAGE); +} + +//----------------------------------------------------------------------------- +// return translation for "id" if not found use default language +//----------------------------------------------------------------------------- +std::string CLanguage::getTranslation(std::string id) +{ + std::string trans=ConfigLanguage->getString(id,""); + if(trans.empty()) + trans=DefaultLanguage->getString(id,""); + if (trans.empty()) + trans = "# L:" + id + " #"; + return trans; +} +//----------------------------------------------------------------------------- +// Find language directory +//----------------------------------------------------------------------------- +std::string CLanguage::getLanguageDir(void) +{ + std::string tmpfilename = "/"+Cyhttpd::ConfigList["Language.directory"], dir = ""; + + if( access((Cyhttpd::ConfigList["WebsiteMain.override_directory"] + tmpfilename).c_str(), R_OK) == 0) + dir = Cyhttpd::ConfigList["WebsiteMain.override_directory"] + tmpfilename; + else if(access((Cyhttpd::ConfigList["WebsiteMain.directory"] + tmpfilename).c_str(), R_OK) == 0) + dir = Cyhttpd::ConfigList["WebsiteMain.directory"] + tmpfilename; + return dir; +} + diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.h b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.h new file mode 100644 index 0000000..e90658f --- /dev/null +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.h @@ -0,0 +1,44 @@ +//============================================================================= +// YHTTPD +// Language +//============================================================================= +#ifndef __yhttpd_language_h__ +#define __yhttpd_language_h__ + +#include <stdlib.h> +#include <configfile.h> +// yhttpd +#include <yconfig.h> +#include "ytypes_globals.h" +#include "ywebserver.h" + +// forward declaration +class CWebserverConnection; + +class CLanguage +{ + protected: + static CLanguage *instance; + CLanguage(void); + ~CLanguage(void); + + static CConfigFile *DefaultLanguage; + static CConfigFile *ConfigLanguage; + + public: + // Instance Handling + static CLanguage *getInstance(void); + static void deleteInstance(void); + + // Language + static std::string language; + static std::string language_dir; + + void setLanguage(std::string _language); + std::string getLanguage(void) {return language;}; + std::string getLanguageDir(void); + + std::string getTranslation(std::string id); +}; + +#endif /* __yttpd_language_h__ */ diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_cache.cpp b/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_cache.cpp index e54f4aa..c60a7e1 100644 --- a/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_cache.cpp +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_cache.cpp @@ -132,7 +132,7 @@ void CmodCache::AddToCache(CyhookHandler */*hh*/, std::string url, std::string c CacheList[url].mime_type = mime_type; CacheList[url].category = category; CacheList[url].created = time(NULL); - std::string test = CacheList[url].filename; +// std::string test = CacheList[url].filename; } fflush(fd); // flush and close file fclose(fd); diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.cpp b/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.cpp index b4f89f9..5f1f131 100644 --- a/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.cpp +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.cpp @@ -25,6 +25,7 @@ #include "helper.h" #include "ylogging.h" #include "mod_yparser.h" +#include <ylanguage.h> //============================================================================= // Initialization of static variables @@ -368,6 +369,7 @@ std::string CyParser::cgi_cmd_parsing(CyhookHandler *hh, std::string html_templ // global-var-get:<varname> // global-var-set:<varname>=<varvalue> // file-action:<filename>;<action=add|addend|delete>[;<content>] +// L:<translation-id> //----------------------------------------------------------------------------- std::string CyParser::YWeb_cgi_cmd(CyhookHandler *hh, std::string ycmd) @@ -376,7 +378,11 @@ std::string CyParser::YWeb_cgi_cmd(CyhookHandler *hh, std::string ycmd) if (ySplitString(ycmd,":",ycmd_type,ycmd_name)) { - if(ycmd_type == "script") + if (ycmd_type == "L") + { + yresult = CLanguage::getInstance()->getTranslation(ycmd_name); + } + else if(ycmd_type == "script") yresult = YexecuteScript(hh, ycmd_name); else if(ycmd_type == "if-empty") { @@ -698,11 +704,13 @@ std::string CyParser::YexecuteScript(CyhookHandler */*hh*/, std::string cmd) const CyParser::TyFuncCall CyParser::yFuncCallList[]= { - {"get_request_data", &CyParser::func_get_request_data}, - {"get_header_data", &CyParser::func_get_header_data}, - {"get_config_data", &CyParser::func_get_config_data}, - {"do_reload_httpd_config", &CyParser::func_do_reload_httpd_config}, - {"httpd_change", &CyParser::func_change_httpd}, + {"get_request_data", &CyParser::func_get_request_data}, + {"get_header_data", &CyParser::func_get_header_data}, + {"get_config_data", &CyParser::func_get_config_data}, + {"do_reload_httpd_config", &CyParser::func_do_reload_httpd_config}, + {"httpd_change", &CyParser::func_change_httpd}, + {"get_languages_as_dropdown", &CyParser::func_get_languages_as_dropdown}, + {"set_language", &CyParser::func_set_language} }; //------------------------------------------------------------------------- @@ -757,13 +765,13 @@ std::string CyParser::func_get_config_data(CyhookHandler *hh, std::string para) //------------------------------------------------------------------------- // y-func : Reload the httpd.conf //------------------------------------------------------------------------- -std::string CyParser::func_do_reload_httpd_config(CyhookHandler */*hh*/, std::string /*para*/) -{ - log_level_printf(1,"func_do_reload_httpd_config: raise USR1 !!!\n"); - raise(SIGUSR1); // Send HUP-Signal to Reload Settings +extern void yhttpd_reload_config(); +std::string CyParser::func_do_reload_httpd_config(CyhookHandler *, std::string) { + log_level_printf(1, "func_do_reload_httpd_config: raise USR1 !!!\n"); + //raise(SIGUSR1); // Send HUP-Signal to Reload Settings + yhttpd_reload_config(); return ""; } - //------------------------------------------------------------------------- // y-func : Change httpd (process image) on the fly //------------------------------------------------------------------------- @@ -778,3 +786,43 @@ std::string CyParser::func_change_httpd(CyhookHandler *hh, std::string para) else return "ERROR [change_httpd]: para has not path to a file"; } +//------------------------------------------------------------------------- +// y-func : get_header_data +//------------------------------------------------------------------------- +std::string CyParser::func_get_languages_as_dropdown(CyhookHandler *, + std::string para) { + std::string yresult, sel; + DIR *d; + + std::string act_language = CLanguage::getInstance()->language; + d = opendir((CLanguage::getInstance()->language_dir).c_str()); + if (d != NULL) { + struct dirent *dir; + while ((dir = readdir(d))) { + if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) + continue; + if (dir->d_type != DT_DIR) { + sel = (act_language == std::string(dir->d_name)) ? "selected=\"selected\"" : ""; + yresult += string_printf("<option value=%s %s>%s</option>", + dir->d_name, sel.c_str(), (encodeString(std::string(dir->d_name))).c_str()); + if(para != "nonl") + yresult += "\n"; + } + } + closedir(d); + } + return yresult; +} +//------------------------------------------------------------------------- +// y-func : get_header_data +//------------------------------------------------------------------------- +std::string CyParser::func_set_language(CyhookHandler *, std::string para) { + if (!para.empty()) { + CConfigFile *Config = new CConfigFile(','); + Config->loadConfig(HTTPD_CONFIGFILE); + Config->setString("Language.selected", para); + Config->saveConfig(HTTPD_CONFIGFILE); + yhttpd_reload_config(); + } + return ""; +} diff --git a/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.h b/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.h index 35b89b6..e68720f 100644 --- a/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.h +++ b/tuxbox/neutrino/daemons/nhttpd/yhttpd_mods/mod_yparser.h @@ -88,6 +88,8 @@ private: std::string func_get_config_data(CyhookHandler *hh, std::string para); std::string func_do_reload_httpd_config(CyhookHandler *hh, std::string para); std::string func_change_httpd(CyhookHandler *hh, std::string para); + std::string func_get_languages_as_dropdown(CyhookHandler *hh, std::string para); + std::string func_set_language(CyhookHandler *, std::string para); // helpers std::string YWeb_cgi_get_ini(CyhookHandler *hh, std::string filename, std::string varname, std::string yaccess); ----------------------------------------------------------------------- Summary of changes: tuxbox/neutrino/daemons/nhttpd/web/Y_Blocks.txt | 1 + tuxbox/neutrino/daemons/nhttpd/yconfig.h | 2 +- tuxbox/neutrino/daemons/nhttpd/yhttpd.cpp | 18 ++++ tuxbox/neutrino/daemons/nhttpd/yhttpd.h | 1 + .../daemons/nhttpd/yhttpd_core/Makefile.am | 9 ++- .../daemons/nhttpd/yhttpd_core/ylanguage.cpp | 101 ++++++++++++++++++++ .../daemons/nhttpd/yhttpd_core/ylanguage.h | 44 +++++++++ .../daemons/nhttpd/yhttpd_mods/mod_cache.cpp | 2 +- .../daemons/nhttpd/yhttpd_mods/mod_yparser.cpp | 70 ++++++++++++-- .../daemons/nhttpd/yhttpd_mods/mod_yparser.h | 2 + 10 files changed, 235 insertions(+), 15 deletions(-) create mode 100644 tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.cpp create mode 100644 tuxbox/neutrino/daemons/nhttpd/yhttpd_core/ylanguage.h -- Tuxbox-GIT: apps ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Tuxbox-cvs-commits mailing list Tuxbox-cvs-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tuxbox-cvs-commits