📄 sip2p.cpp
字号:
#include "sip2p.h"#include "Logger.h"#include "Database.h"#include "SipServer.h"#include "time.h"#include <iostream>#include <sstream>#include <fstream>using namespace std;/** Logger */static Logger * log = new Logger("sip2p");/** Main */int main(int argc, char* argv[]) { // // Read data from configuration file // // Get file name char* confFile = "sip2p.ini"; if (argc == 1) { log->debug("No configuration file specified -> defautl sip2p.ini will be used."); } else { confFile = argv[1]; } // Read settings. If error, exit if (! readSettings(confFile)) { log->debug("Could not read settings. Program will exit!"); exit(1); } // Init database Database::getInstance(); // Start the server try { SipServer server(s2pServerPort); server.start(); } catch (SocketException &e) { string msg = string((const char*) e); log->debug("ERROR: " + msg); } // Release memory Database::close(); delete log; return 0; }/** Reads setting from configuration file */bool readSettings(char* fileName) { const string SERVER_PORT = "S2P_SERVER_PORT"; const string SERVER_IP = "S2P_SERVER_IP"; const string KADC_INI_FILE = "KADC_INI_FILE"; const string KEY_DEBUG = "DEBUG"; const string DUMMY_USERS_BEGIN = "[DUMMY_P2P_USERS]"; const string DUMMY_USERS_END = "[DUMMY_P2P_USERS_END]"; const string KEY_DUMMY_PUBLISH = "DUMMY_PUBLISH"; const string KEY_DUMMY_FAST_SEARCH = "DUMMY_FAST_SEARCH"; ifstream inFile(fileName); if(inFile.is_open()) { string line; while(! inFile.eof()) { getline(inFile, line); if (line.find("#") == 0) { // Comments start with '#' continue; } if (line.find(SERVER_PORT) != string::npos) { // read port int index = line.find('='); string portString = line.substr(index + 1); s2pServerPort = atoi(portString.c_str()); } else if (line.find(SERVER_IP) != string::npos) { // read ip adress int index = line.find('='); s2pServerIP = line.substr(index + 1).c_str(); } else if (line.find(KADC_INI_FILE) != string::npos) { // read kadc ini file int index = line.find('='); kadcIniFile = line.substr(index + 1); } else if (line.find(KEY_DEBUG) != string::npos) { // debug mode int index = line.find('='); if (line.substr(index + 1) == "TRUE") { DEBUG = true; } } else if (line.find(KEY_DUMMY_PUBLISH) != string::npos) { // publish dummy users int index = line.find('='); if (line.substr(index + 1) == "TRUE") { DUMMY_PUBLISH = true; } } else if (line.find(KEY_DUMMY_FAST_SEARCH) != string::npos) { // fast search dummies int index = line.find('='); if (line.substr(index + 1) == "TRUE") { DUMMY_FAST_SEARCH = true; } } else if (line.find(DUMMY_USERS_BEGIN) != string::npos) { // Read dummy users for (getline(inFile, line); line != DUMMY_USERS_END; getline(inFile, line)) { if (line.find("#") == 0) { // Comments start with '#' continue; } int index = line.find('='); string key = line.substr(0, index); string value = line.substr(index + 1); dummyUsers[key] = value; } } } inFile.close(); // Print out what is read log->debug("SIP Server IP: " + s2pServerIP); log->debug("SIP Server port: ", s2pServerPort); log->debug("KadcFile: " + kadcIniFile); if (DEBUG) { log->debug(" -- DEBUG Mode on! --"); } if (DUMMY_PUBLISH) { log->debug(" -- Dummy publishing on! --"); } if (DUMMY_FAST_SEARCH) { log->debug(" -- Dummy fast search on! --"); } log->debug("==========================="); return true; } else { log->debug("Could not find conf file " + string(fileName)); return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -