//------------------------------------------------------------------------------------------------- inline void_t File::reopen( std::ctstring_t &a_filePath, const ExOpenMode &a_mode, cbool_t &a_isUseBuffering ) { xTEST_EQ(a_filePath.empty(), false); xTEST_NA(a_mode); xTEST_NA(a_isUseBuffering); // create dir Dir( Path(a_filePath).dir() ).pathCreate(); // create, reopen file { std::FILE *file = xTFREOPEN(a_filePath.c_str(), _openMode(a_mode).c_str(), get()); xTEST_PTR(file); _handle = file; _filePath = a_filePath; } // buffering if (!a_isUseBuffering) { setVBuff(xPTR_NULL, bmNo, 0); } else { setVBuff(xPTR_NULL, bmFull, BUFSIZ); } }
//------------------------------------------------------------------------------------------------- inline Dir::Dir( std::ctstring_t &a_dirPath ) : _dirPath(a_dirPath) { xTEST_EQ(a_dirPath.empty(), false); }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::sendRaw ( std::ctstring_t &a_filePath, std::ctstring_t &a_from, std::ctstring_t &a_to ) { // TODO: xTEST_DIFF(xSOCKET_HANDLE_INVALID, _socket, false); xTEST_EQ(a_from.empty(), false); xTEST_EQ(a_to.empty(), false); std::tstring_t sRv; /////////std::ctstring_t helloCmd = "HELO HOST\r\n"; // std::ctstring_t helloCmd = "HELO\r\n"; std::ctstring_t fromCmd = xT("MAIL FROM: <") + a_from + xT(">\r\n"); std::ctstring_t toCmd = xT("RCPT TO: <") + a_to + xT(">\r\n"); std::ctstring_t dataCmd = xT("DATA\r\n"); std::ctstring_t endCmd = xT("\r\n.\r\n"); //////////------------------------------------- //////////[HELO\r\n] ////////////bRv = _bCommand(helloCmd, "\r\n", /*ref*/sRv); ////////////xCHECK_RET(!bRv, false); //------------------------------------- //[MAIL FROM:<*****@*****.**>\r\n] _command(fromCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[RCPT TO:<*****@*****.**>\r\n] _command(toCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[DATA\r\n] _command(dataCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- std::tstring_t text; File::textRead(a_filePath, &text); //------------------------------------- //[DataText\r\n.\r\n] _command(text + endCmd, xT("\r\n"), /*ref*/sRv); }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::_command( std::ctstring_t &a_command, std::ctstring_t &a_replyDelimiter, std::tstring_t &a_reply ) { xTEST_EQ(a_command.empty(), false); xTEST_EQ(a_replyDelimiter.empty(), false); std::tstring_t sRv; _socket.sendAll(a_command, 0); sRv = _socket.recvAll(0, a_replyDelimiter); a_reply.swap(sRv); }
//------------------------------------------------------------------------------------------------- inline void_t Config::keyClear( std::ctstring_t &a_key ) { xTEST_EQ(a_key.empty(), false); keyWriteString(a_key, std::tstring_t()); }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::send( std::ctstring_t &a_text, std::ctstring_t &a_from, std::ctstring_t &a_to ) { // TODO: xTEST_DIFF(xSOCKET_HANDLE_INVALID, _socket); xTEST_EQ(a_from.empty(), false); xTEST_EQ(a_to.empty(), false); std::tstring_t sRv; std::ctstring_t helloCmd = xT("HELO HOST\r\n"); std::ctstring_t fromCmd = xT("MAIL FROM: <") + a_from + xT(">\r\n"); std::ctstring_t toCmd = xT("RCPT TO: <") + a_to + xT(">\r\n"); std::ctstring_t dataCmd = xT("DATA\r\n"); std::ctstring_t endCmd = xT("\r\n.\r\n"); //////------------------------------------- //////[HELO DrWEB\r\n] ////bRv = _bCommand(helloCmd, "\r\n", /*ref*/sRv); ////xCHECK_RET(!bRv, false); //------------------------------------- //[MAIL FROM:<*****@*****.**>\r\n] _command(fromCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[RCPT TO:<*****@*****.**>\r\n] _command(toCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[DATA\r\n] _command(dataCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //�������� ����� _socket.sendAll(a_text, 0); //------------------------------------- //[\r\n.\r\n] _command(endCmd, xT("\r\n"), /*ref*/sRv); }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::create( std::ctstring_t &a_user, std::ctstring_t &a_password, std::ctstring_t &a_server, cushort_t &a_port ) { xTEST_EQ(a_user.empty(), false); ////xTEST_EQ(a_password.empty(), false); xTEST_EQ(a_server.empty(), false); xTEST_EQ((32767 > a_port) && (0 < a_port), true); _user = a_user; _password = a_password; _server = a_server; _port = a_port; }
//------------------------------------------------------------------------------------------------- inline void_t Config::setPath( std::ctstring_t &a_filePath ) { xTEST_EQ(a_filePath.empty(), false); Dir( Path(a_filePath).dir() ).pathCreate(); _filePath = a_filePath; }
//------------------------------------------------------------------------------------------------- inline void_t Config::keyWriteString( std::ctstring_t &a_key, std::ctstring_t &a_value ) { xTEST_EQ(a_key.empty(), false); xTEST_NA(a_value); _write(a_key, a_value); }
//------------------------------------------------------------------------------------------------- inline void_t Locale::setCurrent( std::ctstring_t &a_locale ) const { xTEST_NA(a_locale); ctchar_t *locale = a_locale.empty() ? xPTR_NULL : a_locale.c_str(); ctchar_t *pcszRv = xTSETLOCALE(LC_ALL, locale); xTEST_PTR(pcszRv); }
//------------------------------------------------------------------------------------------------- inline std::tstring_t Config::keyReadString( std::ctstring_t &a_key, std::ctstring_t &a_defaultValue ) { xTEST_EQ(a_key.empty(), false); xTEST_NA(a_defaultValue); std::tstring_t sRv; _read(a_key, a_defaultValue, &sRv); return sRv; }
//------------------------------------------------------------------------------------------------- inline Config::Config( std::ctstring_t &a_filePath ) : _separator(Const::equal()), _fileExt ( Path::fileExt(Path::seConfig) ), _filePath (), _config () { xTEST_EQ(_separator.empty(), false); xTEST_EQ(_fileExt.empty(), false); xTEST_EQ(_filePath.empty(), true); xTEST_EQ(a_filePath.empty(), false); setPath( Path(a_filePath).setExt(_fileExt) ); }
//------------------------------------------------------------------------------------------------- inline bool_t SmtpClient::_isError( std::ctstring_t &a_text ) { xTEST_EQ(a_text.empty(), false); bool_t bRv = !( !std::memcmp(a_text.c_str(), xT("334"), 3) || // 334 VXNlcm5hbWU6 !std::memcmp(a_text.c_str(), xT("235"), 3) || // 235 2.0.0 Authentication successful !std::memcmp(a_text.c_str(), xT("220"), 3) || // 220 Kerio MailServer ESMTP ready !std::memcmp(a_text.c_str(), xT("250"), 3) || // 250 2.0.0 OK !std::memcmp(a_text.c_str(), xT("354"), 3) || // 354 Enter mail, end with CRLF.CRLF !std::memcmp(a_text.c_str(), xT("221"), 3) // 221 221 2.0.0 SMTP closing connection ); return bRv; }
//------------------------------------------------------------------------------------------------- inline void_t Config::keyDelete( std::ctstring_t &a_key ) { xTEST_EQ(a_key.empty(), false); // read from file File::textRead(path(), _separator, &_config); xCHECK_DO(_config.end() == _config.find(a_key), return); // delete from std::map_tstring_t _config.erase(a_key); // write to file File::textWrite(path(), _separator, _config, File::omWrite); }
//------------------------------------------------------------------------------------------------- inline void_t Config::_write( std::ctstring_t &a_key, std::ctstring_t &a_value ) { xTEST_EQ(a_key.empty(), false); xTEST_NA(a_value); // write to std::map_tstring_t std::map_tstring_t::iterator it = _config.find(a_key); if (it == _config.end()) { _config.insert( std::pair<std::tstring_t, std::tstring_t>(a_key, a_value) ); } else { it->second = a_value; } // write to file File::textWrite(path(), _separator, _config, File::omWrite); }
//------------------------------------------------------------------------------------------------- inline void_t Console::prompt( std::ctstring_t &a_prompt, cbool_t &a_isVisible, std::tstring_t *a_answer ) const { #if xENV_WIN xTEST_DIFF(_wnd, xWND_NATIVE_HANDLE_NULL); xTEST_EQ(_stdIn.isValid(), true); xTEST_EQ(_stdOut.isValid(), true); #endif xTEST_EQ(a_prompt.empty(), false); xTEST_PTR(a_answer); for ( ; ; ) { write(a_prompt + xT(": ")); for ( ; ; ) { ctchar_t letter = static_cast<tchar_t>( std::tcin.get() ); // asterisks xCHECK_DO(a_isVisible, write(xT("*"))); // ENTER xCHECK_DO(letter == 10, break); // BACKSPACE xCHECK_DO(letter == 0x8, a_answer->clear(); continue); a_answer->push_back(letter); } writeLine(Const::strEmpty()); xCHECK_DO(a_answer->empty(), continue); break; } }
//------------------------------------------------------------------------------------------------- inline void_t Process::create( std::ctstring_t &a_filePath, ctchar_t *a_params, ... ) { xTEST_EQ(a_filePath.empty(), false); xTEST_EQ(File::isExists(a_filePath), true); xTEST_PTR(a_params); std::tstring_t cmdLine; va_list args; xVA_START(args, a_params); cmdLine = String::formatV(a_params, args); xVA_END(args); // xTRACEV(xT("cmdLine: %s"), cmdLine.c_str()); _create_impl(a_filePath, cmdLine); }
//------------------------------------------------------------------------------------------------- inline bool_t Dir::isEmpty( std::ctstring_t &a_shellFilter /* = Const::maskAll() */ ) const { xTEST_EQ(a_shellFilter.empty(), false); bool_t bRv = true; Finder finder(dirPath(), a_shellFilter); for ( ; ; ) { xCHECK_DO(!finder.moveNext(), break); xCHECK_DO(finder.entryName() == Const::dot(), continue); xCHECK_DO(finder.entryName() == Const::dot2(), continue); bRv = false; break; } return bRv; }