void ServerForge::operator() () const { Helper::log( "initializing server..." ); BaseServer *server; server = new BaseServer(); server->run(); Helper::log( "server crashed or exited" ); delete server; }
/** parses and stores an option */ static error_t parse_opt (int key, char *arg, struct argp_state *state) { struct arguments *arguments = (struct arguments *) state->input; switch (key) { case 'T': arguments->tunnel = 1; arguments->has_work++; break; case 'R': arguments->route = 1; arguments->has_work++; break; case 'D': arguments->discover = 1; break; case 'S': { const char *serverip; const char *name = arguments->eibnetname; EIBnetServer *c; int port = 0; char *a = strdup (OPT_ARG(arg, state, "")); char *b; if (!a) die ("out of memory"); b = strchr (a, ':'); if (b) { *b++ = 0; port = atoi (b); } if (port <= 0) port = 3671; serverip = a; if (!*serverip) serverip = "224.0.23.12"; c = new EIBnetServer (serverip, port, arguments->tunnel, arguments->route, arguments->discover, arguments->l3(), arguments->tracer(), (name && *name) ? name : "knxd"); if (!c->init ()) die ("initialization of the EIBnet/IP server failed"); free (a); arguments->tunnel = false; arguments->route = false; arguments->discover = false; arguments->eibnetname = 0; } break; case 'u': { BaseServer *s; const char *name = OPT_ARG(arg,state,"/run/knx"); s = new LocalServer (arguments->l3(), arguments->tracer(), name); if (!s->init ()) die ("initialisation of the knxd unix protocol failed"); arguments->has_work++; } break; case 'i': { BaseServer *s = NULL; int port = atoi(OPT_ARG(arg,state,"6720")); if (port > 0) s = new InetServer (arguments->l3(), arguments->tracer(), port); if (!s || !s->init ()) die ("initialisation of the knxd inet protocol failed"); arguments->has_work++; } break; case 't': if (arg) { char *x; unsigned long level = strtoul(arg, &x, 0); if (*x) die ("Trace level: '%s' is not a number", arg); arguments->tracer(true)->SetTraceLevel (level); } else arguments->tracer(true)->SetTraceLevel (0); break; case 'f': arguments->tracer(true)->SetErrorLevel (arg ? atoi (arg) : 0); break; case 'e': if (arguments->has_l3 ()) { die ("You need to specify '-e' earlier"); } arguments->addr = readaddr (arg); break; case 'p': arguments->pidfile = arg; break; case 'd': arguments->daemon = OPT_ARG(arg,state,"/dev/null"); break; case 'c': if (!CreateGroupCache (arguments->l3(), arguments->tracer(), true)) die ("initialisation of the group cache failed"); break; case 'n': arguments->eibnetname = (char *)arg; if(arguments->eibnetname[0] == '=') arguments->eibnetname++; if(strlen(arguments->eibnetname) >= 30) die("EIBnetServer/IP name must be shorter than 30 bytes"); break; case OPT_FORCE_BROADCAST: arguments->force_broadcast = true; break; case OPT_STOP_NOW: arguments->stop_now = true; break; case OPT_BACK_TUNNEL_NOQUEUE: arguments->l2opts.flags |= FLAG_B_TUNNEL_NOQUEUE; break; case OPT_BACK_TPUARTS_ACKGROUP: arguments->l2opts.flags |= FLAG_B_TPUARTS_ACKGROUP; break; case OPT_BACK_TPUARTS_ACKINDIVIDUAL: arguments->l2opts.flags |= FLAG_B_TPUARTS_ACKINDIVIDUAL; break; case OPT_BACK_TPUARTS_DISCH_RESET: arguments->l2opts.flags |= FLAG_B_TPUARTS_DISCH_RESET; break; case OPT_BACK_EMI_NOQUEUE: arguments->l2opts.flags |= FLAG_B_EMI_NOQUEUE; break; case 'N': arguments->l2opts.flags |= FLAG_B_NO_MONITOR; break; case ARGP_KEY_ARG: case 'b': { arguments->l2opts.t = arguments->tracer (); Layer2 *l2 = Create (arg, &arguments->l2opts, arguments->l3 ()); if (!l2 || !l2->init ()) die ("initialisation of backend '%s' failed", arg); if (arguments->l2opts.flags) die ("You provided options which '%s' does not recognize", arg); memset(&arguments->l2opts, 0, sizeof(arguments->l2opts)); arguments->has_work++; break; } case ARGP_KEY_FINI: if (arguments->l2opts.flags) die ("You need to use backend flags in front of the affected backend"); #ifdef HAVE_SYSTEMD { BaseServer *s = NULL; const int num_fds = sd_listen_fds(0); if( num_fds < 0 ) die("Error getting fds from systemd."); // zero FDs from systemd is not a bug for( int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START+num_fds; ++fd ) { if( sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1) <= 0 ) die("Error: socket not of expected type."); s = new SystemdServer(arguments->l3(), arguments->tracer(), fd); if (!s->init ()) die ("initialisation of the systemd socket failed"); arguments->has_work++; } } #endif errno = 0; if (arguments->tunnel || arguments->route || arguments->discover || arguments->eibnetname) die ("Option '-S' starts the multicast server.\n" "-T/-R/-D/-n after or without that option are useless."); if (arguments->l2opts.flags) die ("You provided L2 flags after specifying an L2 interface."); if (arguments->has_work == 0) die ("I know about no interface. Nothing to do. Giving up."); if (arguments->has_work == 1) die ("I only have one interface. Nothing to do. Giving up."); arguments->finish_l3(); break; default: return ARGP_ERR_UNKNOWN; } return 0; }
void* BaseServer::pthread_F5(void* arg) { BaseServer* pthis = (BaseServer*)arg; pthis->StartF5(13335); return NULL; }
void* BaseServer::pthread_web(void* arg) { BaseServer* pthis = (BaseServer*)arg; pthis->StartWeb(10086); return NULL; }
void* BaseServer::pthread_trans(void* arg) { BaseServer* pthis = (BaseServer*)arg; pthis->StartTrans(13334); return NULL; }
void* BaseServer::pthread_accept(void* arg) { BaseServer* pthis = (BaseServer*)arg; pthis->StartListen(13301,13330); return NULL; }
void* BaseServer::pthread_receive(void* arg) { BaseServer* pthis = (BaseServer*)arg; pthis->StartRecv(); return NULL; }
int main(int argc, char *argv[]) { BaseServer* b = new BaseServer(); b->run("0.0.0.0",80); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); application = &a; QFile* v_file_setting = new QFile(a.applicationDirPath()+"//bkedit.setting.ini"); if (!v_file_setting->exists()) { protoxml vProtoSetting; v_file_setting->open( QIODevice::WriteOnly | QIODevice::Text ); QTextStream stream( v_file_setting ); vProtoSetting.ProtoSetting().save(stream,0); v_file_setting->close(); qDebug()<<"Configuration file is created:"; qDebug()<< a.applicationDirPath()+"/bkedit.setting.ini"; qDebug()<<"Set the parameters and start again"; application->exit(); } if (!v_file_setting->open(QIODevice::ReadOnly|QIODevice::Text)) { qDebug () << "Error open file : " << a.applicationDirPath()<<"//bkedit.setting.ini"; return false; } Xml_Setting.setContent(v_file_setting); //----Получение пути проекта из XML QDomNodeList ListPuthProject = Xml_Setting.elementsByTagName("PuthProject"); for(int k=0;k<ListPuthProject.length();k++) l_vv_Project.insert(k,ListPuthProject.item(k).toElement().text()); //----Получение пути ключей пользователей QDomNodeList ListPuthUsers = Xml_Setting.elementsByTagName("PuthUsers"); for(int k=0;k<ListPuthUsers.length();k++) l_vv_Users.insert(k,ListPuthUsers.item(k).toElement().text()); //----Получение пути транзитных баз QDomNodeList ListPuthDB = Xml_Setting.elementsByTagName("PuthDB"); for(int k=0;k<ListPuthDB.length();k++) l_vv_DB.insert(k,ListPuthDB.item(k).toElement().text()); //--Получение списка к подключению баз логин QDomNodeList ListServerLogin = Xml_Setting.elementsByTagName("ServerLogin"); for(int k=0;k<ListServerLogin.length();k++) l_vv_BaseLogin.insert(k,ListServerLogin.item(k).toElement().text()); //--Получение списка к подключению баз логин QDomNodeList ListServerPass = Xml_Setting.elementsByTagName("ServerPass"); for(int k=0;k<ListServerPass.length();k++) l_vv_BasePass.insert(k,ListServerPass.item(k).toElement().text()); //--Получение списка к подключению баз адрес QDomNodeList ListBaseAdress = Xml_Setting.elementsByTagName("BaseAdress"); for(int k=0;k<ListBaseAdress.length();k++) l_vv_BaseAdress.insert(k,ListBaseAdress.item(k).toElement().text()); //--Получение списка к подключению баз имя QDomNodeList ListBaseName = Xml_Setting.elementsByTagName("BaseName"); for(int k=0;k<ListBaseName.length();k++) l_vv_BaseName.insert(k,ListBaseName.item(k).toElement().text()); //--Получение списка количества пользователей QDomNodeList ListCountUser = Xml_Setting.elementsByTagName("CountUser"); for(int k=0;k<ListCountUser.length();k++) l_vv_CountUser.insert(k,ListCountUser.item(k).toElement().text()); //ServerBase AddBase (ListPuthProject); QUuid idLocal = QUuid::createUuid(); QUuid idRemote = QUuid::createUuid(); QSqlDatabase databasetrans = QSqlDatabase::addDatabase("QSQLITE", idLocal.toString()); QSqlDatabase database1 = QSqlDatabase::addDatabase("QPSQL", idRemote.toString()); QSqlDatabase database2 = QSqlDatabase::addDatabase("QPSQL", idRemote.toString()+"2"); for (int i=0;i<l_vv_BaseAdress.length();i++) { database1.setHostName(l_vv_BaseAdress.value(i)); database1.setUserName(l_vv_BaseLogin.value(i)); database1.setPassword(l_vv_BasePass.value(i)); if(!database1.open()) { // mlog.Log(QString::fromLocal8Bit("\nНе доступен: %1 %2") .arg(l_vv_BaseAdress.value(i)) .arg(l_vv_BaseCod.value(i))); qDebug() << database1.lastError().text(); } else { QSqlQuery qSer1(database1); s1.create_user(qSer1); database2.setHostName(l_vv_BaseAdress.value(i)); database2.setDatabaseName(l_vv_BaseName.value(i)); database2.setUserName("bkUser"); database2.setPassword("bkPassword"); if(!database2.open()) { s1.create_database(qSer1,l_vv_BaseName.value(i)); database2.setHostName(l_vv_BaseAdress.value(i)); database2.setDatabaseName(l_vv_BaseName.value(i)); database2.setUserName("bkUser"); database2.setPassword("bkPassword"); database2.open(); QSqlQuery qSer2(database2); s1.create_lang(qSer2); s1.create_table(qSer2); s1.create_index(qSer2); s1.create_view(qSer2); s1.create_func(qSer2); s1.create_trigger(qSer2); s1.create_insert(qSer2); QSqlQuery qSer3(database2); QSqlQuery qSer4(database2); s1.createMasterLogin(qSer3); s1.createMasterUser(qSer3,qSer4); s1.createMasterFile(qSer3, l_vv_Users.value(i), l_vv_BaseName.value(i)); bool ok = 0; for (int inn = 2; inn < l_vv_CountUser.value(i).toInt(&ok) + 2; inn++) { s1.createUserLogin(qSer3, l_vv_BaseName.value(i), QString::number( inn )); s1.createUserFile(qSer3, l_vv_Users.value(i), l_vv_BaseName.value(i), QString::number( inn )); t1.createbase(databasetrans, l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db"); } QString FileProject = l_vv_Project.value(i); if(!QFile::exists(FileProject)) { p1.GetPackages(database2, l_vv_Project.value(i)); } else { p1.SavePackages(database2, l_vv_Project.value(i)); p1.GetPackages(database2, l_vv_Project.value(i)); } t1.addPackage(databasetrans, database2, l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db", l_vv_BaseName.value(i)); t1.addLogin(databasetrans, database2, l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db", l_vv_BaseName.value(i)); t1.addUsers(databasetrans, database2, l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db", l_vv_BaseName.value(i)); } else { QSqlQuery qSer2(database2); QSqlQuery qSer3(database2); bool ok = 0; for (int inn = 2; inn < l_vv_CountUser.value(i).toInt(&ok) + 2; inn++) { QString FileNameKey = l_vv_Users.value(i) + l_vv_BaseName.value(i) + "." + QString::number( inn ) + ".key"; //qDebug() << "FileName=" << FileNameKey; if(!QFile::exists(FileNameKey)) { s1.clearUserLogin(qSer2, l_vv_BaseName.value(i), QString::number( inn )); s1.createUserLogin(qSer2, l_vv_BaseName.value(i), QString::number( inn )); s1.createUserFile(qSer2, l_vv_Users.value(i), l_vv_BaseName.value(i), QString::number( inn )); } } QString FileNameMasterKey = l_vv_Users.value(i) + l_vv_BaseName.value(i) + ".MASTER.key"; if(!QFile::exists(FileNameMasterKey)) { s1.clearMasterLogin(qSer2); s1.createMasterLogin(qSer2); s1.createMasterUser(qSer2,qSer3); s1.createMasterFile(qSer2, l_vv_Users.value(i), l_vv_BaseName.value(i)); } QString FileBaseTransit = l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db"; if(!QFile::exists(FileBaseTransit)) { t1.createbase(databasetrans, FileBaseTransit); t1.addPackage(databasetrans, database2, l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db", l_vv_BaseName.value(i)); t1.addLogin(databasetrans, database2, l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db", l_vv_BaseName.value(i)); t1.addUsers(databasetrans, database2, l_vv_DB.value(i) + l_vv_BaseName.value(i) + ".db", l_vv_BaseName.value(i)); } QString FileProject = l_vv_Project.value(i); if(!QFile::exists(FileProject)) { p1.GetPackages(database2, l_vv_Project.value(i)); } else { p1.SavePackages(database2, l_vv_Project.value(i)); p1.GetPackages(database2, l_vv_Project.value(i)); } } database2.close(); database1.close(); } } }