/// /// Load the xml file and set const pointers. /// int LanguageXMLfile(const char * filename) { if(xmlFile.open((char *)filename)) return -1; loaded = true; SetValueXML((char **)&LanguageXMLLast_Change, "LAST_CHANGE"); SetValueXML((char **)&LanguageXMLNot_Found, "NOT_FOUND"); SetValueXML((char **)&LanguageXMLReload_Prev, "RELOAD_PREV"); SetValueXML((char **)&LanguageXMLEnter_Default, "ENTER_DEFAULT"); SetValueXML((char **)&LanguageXMLAbout_Text, "ABOUT_TEXT"); SetValueXML((char **)&LanguageXMLEnter_Extension, "ENTER_EXTENSION"); SetValueXML((char **)&LanguageXMLEnter_MIME, "ENTER_MIME"); SetValueXML((char **)&LanguageXMLEnter_Name, "ENTER_NAME"); SetValueXML((char **)&LanguageXMLEnter_Host, "ENTER_HOST"); SetValueXML((char **)&LanguageXMLEnter_Ip, "ENTER_IP"); SetValueXML((char **)&LanguageXMLDownload_Config, "DOWNLAD_CONFIG"); SetValueXML((char **)&LanguageXMLDownload_Failed, "DOWNLAD_FAILED"); SetValueXML((char **)&LanguageXMLKill_All, "KILL_ALL"); SetValueXML((char **)&LanguageXMLSend_Config, "SEND_CONFIG"); SetValueXML((char **)&LanguageXMLUpload_Failed, "UPLOAD_FAILED"); SetValueXML((char **)&LanguageXMLNot_Save, "NOT_SAVE"); SetValueXML((char **)&LanguageXMLReboot_Failed, "REBOOT_FAILED"); SetValueXML((char **)&LanguageXMLConnect_Server, "CONNECT_SERVER"); SetValueXML((char **)&LanguageXMLLogin_Failed, "LOGIN_FAILED"); SetValueXML((char **)&LanguageXMLCannot_Connect, "CANNOT_CONNECT"); SetValueXML((char **)&LanguageXMLServer_Closed, "SERVER_CLOSED"); SetValueXML((char **)&LanguageXMLYes, "YES"); SetValueXML((char **)&LanguageXMLNo, "NO"); return 0; }
bool mainwid::readFromFile(QString& path){ XmlParser xf; if(xf.open(config_file_path) == false){ return false; } xf.loadXmlData(); path = xf.getAlarmFile(); return true; }
/// /// Load the MIME types configuration file. /// Returns -1 on error. /// int MIMEtypeXML::load(const char * filename) { XmlParser parser; if(parser.open((char *)filename)) // but I promis I wont modify return -1; int ret = load_core(parser); parser.close(); return ret; }
MainWindow::MainWindow() { XmlParser xf; xf.open(config_file_path); xf.loadXmlData(); enableSysTray = xf.getCheckbox(QString::fromStdString("notification")); real_close = false; w = new CentralWidget(); connect(w,SIGNAL(change_ctd_d(const ctd_d*)),this,SLOT(changeTrayTime(const ctd_d*))); connect(w,SIGNAL(change_pause_f(QString)),this,SLOT(changeWindowTitle(QString))); sysTrayIcon = new QSystemTrayIcon(QIcon(":/photos/resource/p_icon.png")); sysTrayIcon->setVisible(true);//show!! if(enableSysTray) sysTrayIcon->showMessage(tr("gat2"),tr("Welcome to gat2!"),QSystemTrayIcon::Information,1500); connect(w,SIGNAL(finishCountDown()),this,SLOT(userCall())); config_editor = new PreferenceDialog(); connect(config_editor,SIGNAL(chNotificationCheckBox(bool)),this,SLOT(changeNotificationCheckBox(bool))); about_widget = new gat_about_widget(); a_about = new QAction(tr("&About"),this); a_about->setIcon(QIcon(":/photos/resource/p_icon_mini2.png")); connect(a_about,SIGNAL(triggered()),this,SLOT(about())); a_config = new QAction(tr("&Preferences"),this); connect(a_config,SIGNAL(triggered()),this,SLOT(callConfigDialog())); a_close = new QAction(tr("&Close"),this); connect(a_close,SIGNAL(triggered()),this,SLOT(closeApplication())); vSwitch = new QAction(tr("gat2"),this); connect(vSwitch,SIGNAL(triggered()),this,SLOT(changeVisible())); showTime = new QAction(tr("-----"),this); connect(showTime,SIGNAL(triggered()),this,SLOT(timeMessage())); help_bar = menuBar()->addMenu(tr("&gat2")); help_bar->addAction(a_about); help_bar->addAction(a_close); config_app = menuBar()->addMenu(tr("&Options")); config_app->addAction(a_config); sTaryIcon_Menu = new QMenu(tr("ContextMenu")); sTaryIcon_Menu->addAction(showTime); sTaryIcon_Menu->addSeparator(); sTaryIcon_Menu->addAction(vSwitch); sTaryIcon_Menu->addAction(a_close); sysTrayIcon->setContextMenu(sTaryIcon_Menu); connect(this,SIGNAL(close_mainwid()),w,SLOT(delete_phonon_object())); setCentralWidget(w); setWindowTitle(tr("Gat2")); setWindowIcon(QIcon(":/photos/resource/p_icon.png")); };
/*! * pathでaudio fileへのPATHを受け取ってファイルに書き出す */ bool configDialog::writeToFile(const QString &path){ XmlParser xf; if(xf.open(config_file_path) == false){ std::cout<<"Failed to save xml"<<std::endl; return false; } xf.loadXmlData(); xf.setAlarmFile(path); xf.save(); return true; };
void configDialog::notificationCheckChanged(int n){ QString s = "notification"; std::cout<<"Notification check box changed.["<<n<<"]"<<std::endl; XmlParser xf; if(xf.open(config_file_path) == false){ std::cout<<"Failed to save xml"<<std::endl; return; } xf.loadXmlData(); if(n == 0){ xf.setCheckbox(s,false); emit chNotificationCheckBox(false); }else{ xf.setCheckbox(s,true); emit chNotificationCheckBox(true); } xf.save(); }
configDialog::configDialog(QWidget* parent): QDialog(parent) { audioFileEdit = new QLineEdit();audioFileEdit->setReadOnly(true); notificationCheck = new QCheckBox("Notification"); connect(notificationCheck,SIGNAL(stateChanged(int)),this,SLOT(notificationCheckChanged(int))); /*xml read*/ XmlParser xf; xf.open(config_file_path); xf.loadXmlData(); audioFileEdit->setText(xf.getAlarmFile()); if(xf.getCheckbox(QString::fromStdString("notification")) == true){ notificationCheck->setChecked(true); }else{ notificationCheck->setChecked(false); } /*--------*/ QString a = QCoreApplication::applicationFilePath(); audioFileEditLabel = new QLabel(tr("audio file")); audioFileEditCallPathDialogButton = new QPushButton(tr("Choice")); connect(audioFileEditCallPathDialogButton,SIGNAL(clicked()),this,SLOT(audioFileEditCallPathDialogButton_is_Pushed())); QHBoxLayout *audioFileEditLayout = new QHBoxLayout(); audioFileEditLayout->addWidget(audioFileEditLabel); audioFileEditLayout->addWidget(audioFileEdit); audioFileEditLayout->addWidget(audioFileEditCallPathDialogButton); QVBoxLayout *checkboxes = new QVBoxLayout(); checkboxes->addWidget(notificationCheck); QVBoxLayout *mainLayout = new QVBoxLayout(); mainLayout->addLayout(audioFileEditLayout); mainLayout->addSpacing(12); mainLayout->addLayout(checkboxes); setLayout(mainLayout); };
/*! Loads the plugin info. \param name The plugin name. \param path the plugin xml descriptor path. */ PluginInfo* PluginsManager::loadInfo (Server* server, string &name, string &path) { PluginInfo* pinfo = getPluginInfo (name); auto_ptr<PluginInfo> pinfoAutoPtr (NULL); if (!pinfo) pinfoAutoPtr.reset (pinfo = new PluginInfo (name)); else if (pinfo->getVersion () != 0) return NULL; XmlParser xml; if (xml.open (path, true)) { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s'"), name.c_str ()); return NULL; } auto_ptr<XmlXPathResult> xpathResPlugin = auto_ptr<XmlXPathResult> (xml.evaluateXpath ("/PLUGIN")); xmlNodeSetPtr nodes = xpathResPlugin->getNodeSet (); int size = (nodes) ? nodes->nodeNr : 0; if (size != 1) { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } if (xmlHasProp (nodes->nodeTab[0], (const xmlChar*) "min-version")) { xmlChar *minVersion = xmlGetProp (nodes->nodeTab[0], (const xmlChar*) "min-version"); string sMinVer ((char*) minVersion); pinfo->setMyServerMinVersion (PluginInfo::convertVersion (sMinVer)); } else { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } if (xmlHasProp (nodes->nodeTab[0], (const xmlChar*) "max-version")) { xmlChar* maxVersion = xmlGetProp (nodes->nodeTab[0], (const xmlChar*) "max-version"); string sMaxVer ((char*)maxVersion); pinfo->setMyServerMaxVersion (PluginInfo::convertVersion (sMaxVer)); } else { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } auto_ptr<XmlXPathResult> xpathResPluginName = auto_ptr<XmlXPathResult> (xml.evaluateXpath ("/PLUGIN/NAME/text ()")); nodes = xpathResPluginName->getNodeSet (); size = (nodes) ? nodes->nodeNr : 0; if (size != 1) { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } const char* cname = (const char*) nodes->nodeTab[0]->content; if (strcmp (name.c_str (), cname)) return NULL; auto_ptr<XmlXPathResult> xpathResPluginVersion = auto_ptr<XmlXPathResult> (xml.evaluateXpath ("/PLUGIN/VERSION/text ()")); nodes = xpathResPluginVersion->getNodeSet (); size = (nodes) ? nodes->nodeNr : 0; if (size != 1) { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } string verStr ((char*) nodes->nodeTab[0]->content); int version = PluginInfo::convertVersion (verStr); if (version != -1) pinfo->setVersion (version); else { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } auto_ptr<XmlXPathResult> xpathResDeps = auto_ptr<XmlXPathResult> (xml.evaluateXpath ("/PLUGIN/DEPENDS")); nodes = xpathResDeps->getNodeSet (); size = (nodes) ? nodes->nodeNr : 0; for (int i = 0; i < size; i++) { const char* depends = (const char*) nodes->nodeTab[i]->children->content; string nameDep (depends); if (!xmlHasProp (nodes->nodeTab[i], (const xmlChar*) "min-version") || !xmlHasProp (nodes->nodeTab[i], (const xmlChar*) "max-version")) { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } string minVerStr = ((char*) xmlGetProp (nodes->nodeTab[i], (const xmlChar*) "min-version")); string maxVerStr = ((char*) xmlGetProp (nodes->nodeTab[i], (const xmlChar*) "max-version")); int minVersion = PluginInfo::convertVersion (minVerStr); int maxVersion = PluginInfo::convertVersion (maxVerStr); if (minVersion == -1 || maxVersion == -1) { server->log (MYSERVER_LOG_MSG_ERROR, _("Error loading plugin `%s': invalid plugin.xml"), name.c_str ()); return NULL; } pinfo->addDependence (nameDep, minVersion, maxVersion); } pinfoAutoPtr.release (); return pinfo; }
/*! Load the virtual hosts from a XML configuration file Returns non-null on errors. \param filename The XML file to open. */ int XmlVhostHandler::load (const char *filename) { XmlParser parser; xmlDocPtr doc; xmlNodePtr node; if (parser.open (filename)) { Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR, _("Error opening %s"), filename); return -1; } doc = parser.getDoc (); node = doc->children->children; for (; node; node = node->next ) { xmlNodePtr lcur; Vhost *vh; if (xmlStrcmp (node->name, (const xmlChar *) "VHOST")) continue; lcur = node->children; vh = new Vhost (logManager); SslContext* sslContext = vh->getVhostSSLContext (); while (lcur) { XmlConf::build (lcur, vh->getHashedDataTrees (), vh->getHashedData ()); if (!xmlStrcmp (lcur->name, (const xmlChar *) "HOST")) { int useRegex = 0; for (xmlAttr *attrs = lcur->properties; attrs; attrs = attrs->next) { if (!xmlStrcmp (attrs->name, (const xmlChar *) "isRegex") && attrs->children && attrs->children->content && (!xmlStrcmp (attrs->children->content, (const xmlChar *) "YES"))) useRegex = 1; } vh->addHost ((const char *)lcur->children->content, useRegex); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "NAME")) { vh->setName ((char *) lcur->children->content); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "LOCATION")) { string loc; for (xmlAttr *attrs = lcur->properties; attrs; attrs = attrs->next) if (!xmlStrcmp (attrs->name, (const xmlChar *) "path")) loc = ((const char *) attrs->children->content); MimeRecord *record = XmlMimeHandler::readRecord (lcur); MimeRecord *prev = vh->addLocationMime (loc, record); if (prev) { Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR, _("The location `%s' is registered multiple times"), loc.c_str ()); delete prev; } vh->getLocationsMime ()->put (loc, record); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "SSL_PRIVATEKEY")) { string pk ((char *) lcur->children->content); sslContext->setPrivateKeyFile (pk); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "SSL_CERTIFICATE")) { string certificate ((char *) lcur->children->content); sslContext->setCertificateFile (certificate); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "CONNECTIONS_PRIORITY")) { vh->setDefaultPriority (atoi ((const char *)lcur->children->content)); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "SSL_PASSWORD")) { string pw ((char *) lcur->children->content); sslContext->setPassword (pw); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "IP")) { int useRegex = 0; xmlAttr *attrs = lcur->properties; while (attrs) { if (!xmlStrcmp (attrs->name, (const xmlChar *) "isRegex") && !xmlStrcmp (attrs->children->content, (const xmlChar *) "YES")) useRegex = 1; attrs = attrs->next; } vh->addIP ((char *) lcur->children->content, useRegex); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "PORT")) { int val = atoi ((char *) lcur->children->content); if (val > (1 << 16) || val <= 0) Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR, _("An invalid port was specified: %s"), lcur->children->content); vh->setPort ((u_short)val); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "PROTOCOL")) { char* lastChar = (char *) lcur->children->content; while (*lastChar != '\0') { *lastChar = tolower (*lastChar); lastChar++; } vh->setProtocolName ((char *) lcur->children->content); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "DOCROOT")) { char* lastChar = (char *) lcur->children->content; while (*(lastChar+1) != '\0') lastChar++; if (*lastChar == '\\' || *lastChar == '/') *lastChar = '\0'; vh->setDocumentRoot ((const char *)lcur->children->content); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "SYSROOT")) { char* lastChar = (char *) lcur->children->content; while (*(lastChar+1) != '\0') lastChar++; if (*lastChar == '\\' || *lastChar == '/') *lastChar = '\0'; vh->setSystemRoot ((const char *)lcur->children->content); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "CACHEROOT")) { char* lastChar = (char *) lcur->children->content; while (*(lastChar+1) != '\0') lastChar++; if (*lastChar == '\\' || *lastChar == '/') *lastChar = '\0'; vh->setCacheRoot ((const char *)lcur->children->content); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "ACCESSLOG")) { loadXMLlogData ("ACCESSLOG", vh, lcur); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "WARNINGLOG")) { loadXMLlogData ("WARNINGLOG", vh, lcur); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "MIME_FILE")) { string hnd ("xml"); for (xmlAttr *attrs = lcur->properties; attrs; attrs = attrs->next) { if (!xmlStrcmp (attrs->name, (const xmlChar *) "name") && attrs->children && attrs->children->content) hnd.assign((const char *) attrs->children->content); } const char *filename = (const char *) lcur->children->content; MimeManagerHandler *handler = Server::getInstance ()->getMimeManager ()->buildHandler (hnd); try { handler->load (filename); } catch (...) { delete handler; handler = NULL; Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR, _("Error loading mime types file: %s"), filename); } vh->setMimeHandler (handler); } else if (!xmlStrcmp (lcur->name, (const xmlChar *) "THROTTLING_RATE")) { u_long rate = (u_long)atoi ((char *) lcur->children->content); vh->setThrottlingRate (rate); } lcur = lcur->next; }/* while (lcur) */ if (vh->openLogFiles ()) { Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR, _("Error opening log files")); delete vh; vh = 0; continue; } if (vh->initializeSSL () < 0) { Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR, _("Error initializing SSL for %s"), vh->getName ()); delete vh; vh = 0; continue; } if (addVHost (vh)) { Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR, _("Internal error")); delete vh; vh = 0; continue; } } parser.close (); changeLocationsOwner (); return 0; }
/// /// The *hack* to load the correct xml file. /// This looks for the myserver.xml file and grabs the name of the /// lanugage file. Then it tries to load that file in the default /// locations. /// void LanguageXMLload() { char languages_path[MAX_PATH]; char language_file[MAX_PATH]; char main_configuration_file[MAX_PATH]; char * chrptr; XmlParser xmlFile; bool langFound = true; bool confFound = true; int ret; LanguageXMLinit(); // Find the language files: #ifdef WIN32 strncpy(languages_path, "languages/", MAX_PATH); #else if(FilesUtility::fileExists("languages")) { strncpy(languages_path, "languages/", MAX_PATH); } else { # ifdef PREFIX snprintf(languages_path, MAX_PATH, "%s/share/myserver/languages/", PREFIX); # else strncpy(languages_path, "/usr/share/myserver/languages/", MAX_PATH); # endif } if(!(FilesUtility::fileExists(languages_path))) { loadok = false; langFound = false; return; } #endif // Search for myserver.xml /* Under an *nix environment look for .xml files in the following order. * 1) myserver executable working directory * 2) ~/.myserver/ * 3) /etc/myserver/ */ #ifndef WIN32 // just a little hack snprintf(main_configuration_file, MAX_PATH, "%s/.myserver/myserver.xml", getenv("HOME")); #endif if(FilesUtility::fileExists("myserver.xml")) { strncpy(main_configuration_file,"myserver.xml", MAX_PATH); } #ifndef WIN32 else if(FilesUtility::fileExists(main_configuration_file)) { // do nothing } else if(FilesUtility::fileExists("/etc/myserver/myserver.xml")) { strncpy(main_configuration_file,"/etc/myserver/myserver.xml", MAX_PATH); } #endif else { confFound = false; loadok = false; return; } // Load the language file for configure if(confFound && langFound) { xmlFile.open(main_configuration_file); chrptr = xmlFile.getValue("LANGUAGE"); if(chrptr != NULL) snprintf(language_file, MAX_PATH, "%sconfigure/%s", languages_path, chrptr); xmlFile.close(); ret = LanguageXMLfile(language_file); if(ret) loadok = false; } }