bool CwxMcConfig::fetchHost(CwxIniParse& cnf, string const& node, CwxHostInfo& host) { string value; host.reset(); //get listen if (cnf.getAttr(node, "listen", value) && value.length()) { if (!mqParseHostPort(value, host)) { snprintf(m_szErrMsg, 2047, "%s:listen must be [host:port], [%s] is invalid.", node.c_str(), value.c_str()); return false; } } //load user if (cnf.getAttr(node, "user", value) && value.length()) { host.setUser(value); } else { host.setUser(""); } //load passwd if (cnf.getAttr(node, "passwd", value) && value.length()) { host.setPassword(value); } else { host.setPassword(""); } if (!host.getHostName().length()) { CwxCommon::snprintf(m_szErrMsg, 2047, "Must set [%s]'s [listen].", node.c_str()); return false; } return true; }
//加载sync的主机 int CwxMcConfig::loadSyncHost(string const& strSyncHostFile){ CwxIniParse cnf; string value; string strErrMsg; m_syncHosts.m_hosts.clear(); //解析配置文件 if (false == cnf.load(strSyncHostFile)) { CwxCommon::snprintf(m_szErrMsg, 2047, "Failure to Load conf file:%s. err:%s", strSyncHostFile.c_str(), cnf.getErrMsg()); return -1; } //load sync_host list<pair<string, string> > hosts; if (!cnf.getAttr("host", hosts) || !hosts.size()){ snprintf(m_szErrMsg, 2047, "Must set [host]."); return -1; } list<pair<string, string> >::iterator iter = hosts.begin(); list<string> items; list<string>::iterator item_iter; CwxMcConfigHost hostInfo; while(iter != hosts.end()){ CwxCommon::split(iter->second, items, ':'); if (items.size() != 4){ snprintf(m_szErrMsg, 2047, "[host:%s]'s value[%s] is invalid, must be [port:user:passwd:limit].", iter->first.c_str(), iter->second.c_str()); return -1; } hostInfo.m_host = iter->first; item_iter = items.begin(); hostInfo.m_port = strtoul(item_iter->c_str(), NULL, 10); ++item_iter; hostInfo.m_user = *item_iter; ++item_iter; hostInfo.m_passwd = *item_iter; ++item_iter; hostInfo.m_limit = strtoul(item_iter->c_str(), NULL, 10); if (m_syncHosts.m_hosts.find(hostInfo.m_host) != m_syncHosts.m_hosts.end()) { snprintf(m_szErrMsg, 2047, "[host name:%s] is duplicate.", hostInfo.m_host.c_str()); return -1; } m_syncHosts.m_hosts[hostInfo.m_host] = hostInfo; ++iter; } return 0; }
int CwxEchoChannelConfig::loadConfig(string const & strConfFile){ CwxIniParse parser; string value; //½âÎöÅäÖÃÎļþ if (false == parser.load(strConfFile)){ snprintf(m_szError, 2047, "Failure to Load conf file:%s", strConfFile.c_str()); return -1; } //load workdir if (!parser.getAttr("channel_svr", "workdir", value)|| !value.length()){ snprintf(m_szError, 2047, "Must set [channel_svr:workdir]."); return -1; } if ('/' != value[value.length()-1]) value +="/"; m_strWorkDir = value; //load unix if (!parser.getAttr("channel_svr", "unix", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [channel_svr:unix]."); return -1; } m_strUnixPathFile = value; // load query thread num if (!parser.getAttr("channel_svr", "thread_num", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [channel_svr:thread_num]."); return -1; } m_unThreadNum = strtoul(value.c_str(), NULL, 10); //load listen if (!parser.getAttr("channel_svr", "listen", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [channel_svr:listen]."); return -1; } m_listen.setHostName(value); if (!parser.getAttr("channel_svr", "port", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [channel_svr:port]."); return -1; } m_listen.setPort(strtoul(value.c_str(), NULL, 10)); return 0; }
int CwxMqImportConfig::loadConfig(string const & strConfFile) { CwxIniParse cnf; string value; //解析配置文件 if (false == cnf.load(strConfFile)) { CwxCommon::snprintf(m_szError, 2047, "Failure to Load conf file:%s. err:%s", strConfFile.c_str(), cnf.getErrMsg()); return -1; } //load import:home if (!cnf.getAttr("import", "home", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:home]."); return -1; } if ('/' != value[value.length() - 1]) value += "/"; m_strWorkDir = value; //load import:listen if (!cnf.getAttr("import", "listen", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:listen]."); return -1; } if (!mqParseHostPort(value, m_listen)) { snprintf(m_szError, 2047, "import:listen must be [host:port], [%s] is invalid.", value.c_str()); return -1; } //load import:unix if (!cnf.getAttr("import", "unix", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:unix]."); return -1; } m_strUnixPathFile = value; //load import:user if (!cnf.getAttr("import", "user", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:user]."); return -1; } m_strUser = value; //load import:passwd if (!cnf.getAttr("import", "passwd", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:passwd]."); return -1; } m_strPasswd = value; //load import:conn_type if (!cnf.getAttr("import", "conn_type", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:conn_type]."); return -1; } m_bTcp = (value == "tcp" ? true : false); //load import:conn_num if (!cnf.getAttr("import", "conn_num", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:conn_num]."); return -1; } m_unConnNum = strtoul(value.c_str(), NULL, 10); if (!m_unConnNum) m_unConnNum = 1; //load import:conn_lasting if (!cnf.getAttr("import", "conn_lasting", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:conn_lasting]."); return -1; } m_bLasting = (value == "1" ? true : false); //load import:data_group if (!cnf.getAttr("import", "data_group", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:data_group]."); return -1; } m_uiGroup = strtoul(value.c_str(), NULL, 10); //load import:data_size if (!cnf.getAttr("import", "data_size", value) || !value.length()) { snprintf(m_szError, 2047, "Must set [import:data_size]."); return -1; } m_unDataSize = strtoul(value.c_str(), NULL, 10); return 0; }
int CwxEchoClientConfig::loadConfig(string const & strConfFile){ CwxIniParse parser; string value; //½âÎöÅäÖÃÎļþ if (false == parser.load(strConfFile)){ snprintf(m_szError, 2047, "Failure to Load conf file:%s", strConfFile.c_str()); return -1; } //load workdir if (!parser.getAttr("client", "workdir", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:workdir]."); return -1; } if ('/' != value[value.length()-1]) value +="/"; m_strWorkDir = value; // load connect num if (!parser.getAttr("client", "conn_num", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:conn_num]."); return -1; } m_unConnNum = strtoul(value.c_str(), NULL, 10); // load query conn type if (!parser.getAttr("client", "conn_type", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:conn_type]."); return -1; } m_bTcp = strcasecmp("tcp", value.c_str())==0?true:false; // load query conn lasting if (!parser.getAttr("client", "conn_lasting", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:conn_lasting]."); return -1; } m_bLasting = strcasecmp("1", value.c_str())==0?true:false; // data size if (!parser.getAttr("client", "data_size", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:data_size]."); return -1; } m_uiDataSize =strtoul(value.c_str(), NULL, 10); //load listen if (!parser.getAttr("client", "listen", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:listen]."); return -1; } m_listen.setHostName(value.c_str()); if (!parser.getAttr("client", "port", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:port]."); return -1; } m_listen.setPort(strtoul(value.c_str(), NULL, 10)); //load svr_def:unix{path} if (!parser.getAttr("client","unix", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [client:unix]."); return -1; } m_strUnixPathFile = value; return 0; }
int CwxMcConfig::loadConfig(string const & strConfFile) { CwxIniParse cnf; string value; string strErrMsg; //解析配置文件 if (false == cnf.load(strConfFile)) { CwxCommon::snprintf(m_szErrMsg, 2047, "Failure to Load conf file:%s. err:%s", strConfFile.c_str(), cnf.getErrMsg()); return -1; } //load cmn:home if (!cnf.getAttr("cmn", "home", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [cmn:home]."); return -1; } if ('/' != value[value.length() - 1]) value += "/"; m_common.m_strWorkDir = value; //load cmn:monitor if (!cnf.getAttr("cmn", "monitor", value) || !value.length()) { m_common.m_monitor.reset(); } else { if (!mqParseHostPort(value, m_common.m_monitor)) { snprintf(m_szErrMsg, 2047, "cmn:monitor must be [host:port], [%s] is invalid.", value.c_str()); return -1; } } //load store:path if (!cnf.getAttr("store", "path", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:path]."); return -1; } if ('/' != value[value.length() - 1]) value += "/"; m_store.m_strPath = value; //load store:file_max_mbyte if (!cnf.getAttr("store", "file_max_mbyte", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:file_max_mbyte]."); return -1; } m_store.m_uiLogMSize = strtoul(value.c_str(), NULL, 10); if (m_store.m_uiLogMSize < CwxMcConfigStore::MIN_LOG_MSIZE) { m_store.m_uiLogMSize = CwxMcConfigStore::MIN_LOG_MSIZE; } if (m_store.m_uiLogMSize > CwxMcConfigStore::MAX_LOG_MSIZE) { m_store.m_uiLogMSize = CwxMcConfigStore::MAX_LOG_MSIZE; } //load store:reserve_day if (!cnf.getAttr("store", "reserve_day", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:reserve_day]."); return -1; } m_store.m_uiReserveDay = strtoul(value.c_str(), NULL, 10); //load store:append_return if (!cnf.getAttr("store", "append_return", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:append_return]."); return -1; } if (value=="yes"){ m_store.m_bAppendReturn = true; }else if (value=="no"){ m_store.m_bAppendReturn = false; }else{ snprintf(m_szErrMsg, 2047, "Invalid [store:append_return]'s value[%s], must be yes/no.", value.c_str()); return -1; } //load store:record_prefix if (!cnf.getAttr("store", "record_prefix", value) || !value.length()) { m_store.m_strRecordPrefix.erase(); }else{ m_store.m_strRecordPrefix = value; } //load store:file_max_second if (!cnf.getAttr("store", "file_max_second", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:file_max_second]."); return -1; } m_store.m_uiSwitchSecond = strtoul(value.c_str(), NULL, 10); //load store:flush_log_num if (!cnf.getAttr("store", "flush_log_num", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:flush_log_num]."); return -1; } m_store.m_uiFlushNum = strtoul(value.c_str(), NULL, 10); if (m_store.m_uiFlushNum < 1) { m_store.m_uiFlushNum = 1; } //load store:flush_log_second if (!cnf.getAttr("store", "flush_log_second", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [store:flush_log_second]."); return -1; } m_store.m_uiFlushSecond = strtoul(value.c_str(), NULL, 10); if (m_store.m_uiFlushSecond < 1) { m_store.m_uiFlushSecond = 1; } //fetch mq if (!fetchHost(cnf, "mq", m_mq.m_mq)) return -1; //load mq:log_path if (!cnf.getAttr("mq", "name", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [mq:name]."); return -1; } m_mq.m_strName = value; //load mq:cache_msize if (!cnf.getAttr("mq", "cache_msize", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [mq:cache_msize]."); return -1; } m_mq.m_uiCacheMSize = strtoul(value.c_str(), NULL, 10); if (m_mq.m_uiCacheMSize < 1) { m_mq.m_uiCacheMSize = 1; } //load mq:cache_second if (!cnf.getAttr("mq", "cache_second", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [mq:cache_second]."); return -1; } m_mq.m_uiCacheTimeout = strtoul(value.c_str(), NULL, 10); //load sync //load sync:source if (!cnf.getAttr("sync", "source", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:source]."); return -1; } m_sync.m_strSource = value; //load sync:sock_buf_kbyte if (!cnf.getAttr("sync", "sock_buf_kbyte", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:sock_buf_kbyte]."); return -1; } m_sync.m_uiSockBufKByte = strtoul(value.c_str(), NULL, 10); //load sync:max_chunk_kbyte if (!cnf.getAttr("sync", "max_chunk_kbyte", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:max_chunk_kbyte]."); return -1; } m_sync.m_uiChunkKBye = strtoul(value.c_str(), NULL, 10); if (m_sync.m_uiChunkKBye > CWX_MQ_MAX_CHUNK_KSIZE) m_sync.m_uiChunkKBye = CWX_MQ_MAX_CHUNK_KSIZE; //load sync:sync_conn_num if (!cnf.getAttr("sync", "sync_conn_num", value) || !value.length()) { snprintf(m_szErrMsg, 2047, "Must set [sync:sync_conn_num]."); return -1; } m_sync.m_uiConnNum = strtoul(value.c_str(), NULL, 10); if (m_sync.m_uiConnNum < 1) m_sync.m_uiConnNum = 1; //load sync:zip if (!cnf.getAttr("sync", "zip", value) || !value.length()) { m_sync.m_bzip = false; } else { if (value == "yes") m_sync.m_bzip = true; else m_sync.m_bzip = false; } return 0; }
int UnistorBenchConfig::loadConfig(string const & strConfFile){ CwxIniParse parser; string value; //½âÎöÅäÖÃÎļþ if (false == parser.load(strConfFile)){ snprintf(m_szError, 2047, "Failure to Load conf file. err=%s", parser.getErrMsg()); return -1; } //load unistor_bench:home if (!parser.getAttr("unistor_bench", "home", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:home] for running path."); return -1; } if ('/' != value[value.length()-1]) value +="/"; m_strWorkDir = value; //load unistor_bench:listen if (!parser.getAttr("unistor_bench", "listen", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:listen]."); return -1; } if (!parseHostPort(value, m_listen)){ snprintf(m_szError, 2047, "[unistor_bench:listen] is invalid, it should be [ip:port] format."); return -1; } // load echo unistor_bench:conn_num if (!parser.getAttr("unistor_bench", "conn_num", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:conn_num]."); return -1; } m_unConnNum = strtoul(value.c_str(), NULL, 0); // load echo unistor_bench:conn_lasting if (!parser.getAttr("unistor_bench", "conn_lasting", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:conn_lasting]."); return -1; } m_bLasting = value=="1"?true:false; // load echo unistor_bench:data_opr if (!parser.getAttr("unistor_bench", "data_opr", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_opr]."); return -1; } m_strOpr =value; if ((m_strOpr != "import")&&(m_strOpr != "add")&&(m_strOpr != "set")&&(m_strOpr != "update")&&(m_strOpr != "delete")&&(m_strOpr != "get")){ snprintf(m_szError, 2047, "invalid data opr[%s] for [unistor_bench:data_opr], must be [add/set/update/delete/import/get", m_strOpr.c_str()); return -1; } // load echo unistor_bench:data_size if (!parser.getAttr("unistor_bench", "data_size", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_size]."); return -1; } m_uiDataSize =strtoul(value.c_str(), NULL, 0); if (m_uiDataSize > 1024*1024) m_uiDataSize = 1024*1024; // load echo unistor_bench:data_key_in_order if (!parser.getAttr("unistor_bench", "data_key_in_order", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_key_in_order]."); return -1; } m_bKeyOrder = value=="yes"?true:false; // load echo unistor_bench:data_get_order if (!parser.getAttr("unistor_bench", "data_get_order", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_get_order]."); return -1; } m_bGetOrder = value == "yes"?true:false; // load echo unistor_bench:data_base if (!parser.getAttr("unistor_bench", "data_base", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_base]."); return -1; } m_uiDataBase =strtoul(value.c_str(), NULL, 0); if (m_uiDataBase < 10000) m_uiDataBase = 10000; // load echo unistor_bench:data_mod if (!parser.getAttr("unistor_bench", "data_mod", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_mod]."); return -1; } m_uiDataMod =strtoul(value.c_str(), NULL, 0); // load echo unistor_bench:data_master if (!parser.getAttr("unistor_bench", "data_master", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_master]."); return -1; } m_bGetMaster = (value == "yes"?true:false); // load echo unistor_bench:cache if (!parser.getAttr("unistor_bench", "cache", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:cache]."); return -1; } m_bCache = (value == "yes"?true:false); // load echo unistor_bench:data_group if (!parser.getAttr("unistor_bench", "data_group", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_group]."); return -1; } m_uiKeyGroup = strtoul(value.c_str(), NULL, 0); if (0 == m_uiKeyGroup) m_uiKeyGroup = 1; // load echo unistor_bench:data_group_index if (!parser.getAttr("unistor_bench", "data_group_index", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:data_group_index]."); return -1; } m_uiKeyIndex = strtoul(value.c_str(), NULL, 0); if (m_uiKeyIndex >= m_uiKeyGroup) m_uiKeyIndex = m_uiKeyGroup - 1; // load echo unistor_bench:expire if (!parser.getAttr("unistor_bench", "expire", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:expire]."); return -1; } m_uiExpire =strtoul(value.c_str(), NULL, 0); // load echo unistor_bench:user if (!parser.getAttr("unistor_bench", "user", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:user]."); return -1; } m_strUser = value; // load echo unistor_bench:passwd if (!parser.getAttr("unistor_bench", "passwd", value) || !value.length()){ snprintf(m_szError, 2047, "Must set [unistor_bench:passwd]."); return -1; } m_strPasswd = value; return 0; }