void CTaxon3::Init(const STimeout* timeout, unsigned reconnect_attempts) { SetLastError(NULL); if ( timeout ) { m_timeout_value = *timeout; m_timeout = &m_timeout_value; } else { m_timeout = 0; } m_nReconnectAttempts = reconnect_attempts; CNcbiEnvironment env; bool bFound = false; m_sService = env.Get("NI_SERVICE_NAME_TAXON3", &bFound); if( !bFound ) { m_sService = env.Get("NI_TAXON3_SERVICE_NAME", &bFound); if( !bFound ) { m_sService = "TaxService3"; } } #ifdef USE_TEXT_ASN m_eDataFormat = eSerial_AsnText; #else m_eDataFormat = eSerial_AsnBinary; #endif }
CDBInterfacesFileConnParams::CDBInterfacesFileConnParams( const CDBConnParams& other, const string& file ) : CDBConnParamsDelegate(other) { string file_name; if (!file.empty() && CFile(file).Exists()) { file_name = file; } else { const CNcbiEnvironment env; // Get it from a default place ... file_name = env.Get("SYBASE") + "/interfaces"; if (!CFile(file_name).Exists()) { file_name = env.Get("HOME") + "/.interfaces"; if (!CFile(file_name).Exists()) { return; } } } CNcbiIfstream istr(file_name.c_str()); if (!istr) { return; } string line; string key; string host_str; string port_str; vector<string> arr_param; enum EState {eInitial, eKeyRead, eValueRead}; EState state = eInitial; bool tli_format = false; while (NcbiGetlineEOL(istr, line)) { if (line[0] == '#' || line.empty()) { continue; } else if (line[0] == '\t') { if (state == eKeyRead) { NStr::TruncateSpacesInPlace(line); arr_param.clear(); NStr::Tokenize(line, "\t ", arr_param); if (NStr::Equal(arr_param[0], "query")) { if (NStr::Equal(arr_param[1], "tli")) { tli_format = true; const string tli_str = arr_param[arr_param.size() - 1]; host_str = tli_str.substr(10 - 1, 8); port_str = tli_str.substr(6 - 1, 4); } else { host_str = arr_param[arr_param.size() - 2]; port_str = arr_param[arr_param.size() - 1]; } state = eValueRead; } } else { // Skip all values except the first one ... continue; } } else { if (state == eInitial) { key = line; NStr::TruncateSpacesInPlace(key); state = eKeyRead; } else { // Error ... DATABASE_DRIVER_ERROR("Invalid interfaces file line: " + line, 20001); } } if (state == eValueRead) { Uint4 host = 0; unsigned char* b = (unsigned char*) &host; if (!host_str.empty() && !port_str.empty()) { if (tli_format) { b[0] = NStr::StringToUInt(host_str.substr(0, 2), 0, 16); b[1] = NStr::StringToUInt(host_str.substr(2, 2), 0, 16); b[2] = NStr::StringToUInt(host_str.substr(4, 2), 0, 16); b[3] = NStr::StringToUInt(host_str.substr(6, 2), 0, 16); m_Records[key] = SIRecord(host, NStr::StringToUInt(port_str, 0, 16)); } else { NStr::TruncateSpacesInPlace(host_str); arr_param.clear(); NStr::Tokenize(host_str, ".", arr_param); b[0] = NStr::StringToUInt(arr_param[0]); b[1] = NStr::StringToUInt(arr_param[1]); b[2] = NStr::StringToUInt(arr_param[2]); b[3] = NStr::StringToUInt(arr_param[3]); m_Records[key] = SIRecord(host, NStr::StringToUInt(port_str)); } } state = eInitial; } } }