int CIpAddress::LookupHost( const t_string &x_sServer, unsigned int x_uPort, unsigned int x_uType ) { #if defined( HTM_NOSOCKET2 ) return 0; #else // Lose old info Destroy(); // Ensure we have a valid pointer if ( !x_sServer.length() ) return 0; // First try to interpret as dot address unsigned long uAddr = inet_addr( x_sServer.c_str() ); if ( INADDR_NONE == uAddr ) { LPHOSTENT pHe = gethostbyname( x_sServer.c_str() ); if ( !pHe ) return 0; LPIN_ADDR pia = (LPIN_ADDR)*pHe->h_addr_list; if ( !pia ) return 0; // Grab the address uAddr = *(DWORD*)&pia->S_un.S_addr; } // end if SetRawAddress( ntohl( uAddr ), x_uPort, x_uType ); return 1; #endif }
variant luaW_tofaivariant(lua_State* L, int i) { switch(lua_type(L, i)) { case LUA_TBOOLEAN: return variant(lua_tointeger(L, i)); case LUA_TNUMBER: return variant(lua_tonumber(L, i), variant::DECIMAL_VARIANT); case LUA_TSTRING: return variant(lua_tostring(L, i)); case LUA_TTABLE: return variant(new lua_callable(L, i)); case LUA_TUSERDATA: static t_string tstr; static vconfig vcfg = vconfig::unconstructed_vconfig(); static map_location loc; if(luaW_totstring(L, i, tstr)) { return variant(tstr.str()); } else if(luaW_tovconfig(L, i, vcfg)) { return variant(new config_callable(vcfg.get_parsed_config())); } else if(unit* u = luaW_tounit(L, i)) { return variant(new unit_callable(*u)); } else if(luaW_tolocation(L, i, loc)) { return variant(new location_callable(loc)); } break; } return variant(); }
t_string interpolate_variables_into_tstring(const t_string &tstr, const variable_set& variables) { if(!tstr.str().empty()) { std::string interp = utils::interpolate_variables_into_string(tstr.str(), variables); if(tstr.str() != interp) { return t_string(interp); } } return tstr; }
/* * From the IRC log of 23.07.2010 * 07:52 <silene> Upth: what did it break? * 07:53 <Upth> silene: since that revision, the windows executable crashes * immediately before loading the main menu * 07:54 <silene> what kind of crash? * 07:54 <Upth> assertion failed in the std::string library * 07:54 <Upth> then "fatal error" * 07:54 <Upth> and abnormal termination * 07:54 <silene> which assertion? * 07:55 <Upth> Expression: ("_Myptr + _Off <= (((_Mystring * *)this->_Mycont)->_Myptr() + ((_Mystring *)this->_Mycont)->_Mysize) && * _Myptr + _Off >= ((_Mystring *)this->_Mycont)->_Myptr()", 0) * 07:56 <shadowmaster> ugly. * 07:57 <Upth> in the iterator += overload, called from the iterator + * overload, called from std::basic_string::end(), called from line 409 of * parser.cpp in write_key_val * 07:58 <Upth> err std::basic_string::end() is called from * t_string::walker::end(), which is called on line 409 of parser.cpp * 07:58 <silene> that doesn't make sense; as far as i can tell it's a compiler * bug * 07:58 <silene> which compiler is that so that the code is made conditional * on it? * 07:58 <Upth> MSVC9 */ t_string_base::walker::walker(const t_string& string) : string_(string.get().value_), begin_(0), end_(string_.size()), textdomain_(), translatable_(false) { if(string.get().translatable_) { update(); } }
void generate_pot(std::set<std::string>& msgids, const t_string& tstr, const std::string& default_textdomain) { if (tstr.str().empty()) { return; } std::vector<t_string_base::trans_str> trans = tstr.valuex(); if (!trans.empty()) { if (trans[0].td.empty() || trans[0].td == default_textdomain) { msgids.insert(trans[0].str); } } return; }
// +++ Make IPv6 safe int CIpAddress::SetDotAddress( const t_string &x_sDotAddress, unsigned int x_uPort, unsigned int x_uType ) { if ( !x_sDotAddress.length() ) return 0; // Convert the dot address u_long ip = ntohl( inet_addr( x_sDotAddress.c_str() ) ); if ( INADDR_NONE == ip ) return 0; SetRawAddress( ip, x_uPort, x_uType ); return 1; }
bool load_font_config() { //read font config separately, so we do not have to re-read the whole //config when changing languages config cfg; try { const std::string& cfg_path = filesystem::get_wml_location("hardwired/fonts.cfg"); if(cfg_path.empty()) { ERR_FT << "could not resolve path to fonts.cfg, file not found\n"; return false; } filesystem::scoped_istream stream = preprocess_file(cfg_path); read(cfg, *stream); } catch(config::error &e) { ERR_FT << "could not read fonts.cfg:\n" << e.message << '\n'; return false; } const config &fonts_config = cfg.child("fonts"); if (!fonts_config) return false; std::set<std::string> known_fonts; for (const config &font : fonts_config.child_range("font")) { known_fonts.insert(font["name"]); if (font.has_attribute("bold_name")) { known_fonts.insert(font["bold_name"]); } if (font.has_attribute("italic_name")) { known_fonts.insert(font["italic_name"]); } } family_order_sans = fonts_config["family_order"]; family_order_mono = fonts_config["family_order_monospace"]; if(family_order_mono.empty()) { ERR_FT << "No monospace font family order defined, falling back to sans serif order\n"; family_order_mono = family_order_sans; } std::vector<font::subset_descriptor> fontlist; for(auto font : utils::split(fonts_config["order"])) { add_font_to_fontlist(fonts_config, fontlist, font); known_fonts.erase(font); } for(auto kfont : known_fonts) { add_font_to_fontlist(fonts_config, fontlist, kfont); } if(fontlist.empty()) return false; sdl_ttf::set_font_list(fontlist); return true; }
CIpAddress::t_string CIpAddress::GetDomainName( const t_string &x_sServer ) { CIpAddress::t_string sRet; // Load netapi32.dll HMODULE hLib = LoadLibrary( tcT( "netapi32.dll" ) ); if ( !hLib ) return sRet; // Get function pointers pfn_NetApiBufferFree pNetApiBufferFree = (pfn_NetApiBufferFree)GetProcAddress( hLib, tcT( "NetApiBufferFree" ) ); pfn_NetWkstaGetInfo pNetWkstaGetInfo = (pfn_NetWkstaGetInfo)GetProcAddress( hLib, tcT( "NetWkstaGetInfo" ) ); // Attempt to read the domain name WKSTA_INFO_100 *pwi100 = 0; if ( pNetWkstaGetInfo && !pNetWkstaGetInfo( x_sServer.length() ? (LPWSTR)tcStr2Wc( x_sServer ).c_str() : 0, 100, (LPBYTE*)&pwi100 ) ) if ( pwi100 && pwi100->wki100_langroup ) sRet = tcWc2Str( pwi100->wki100_langroup ); // Free buffer if ( pNetApiBufferFree && pwi100 ) pNetApiBufferFree( pwi100 ); // Free library FreeLibrary( hLib ); // Send the domain name along return sRet; }
int CIpAddress::LookupUri( const t_string &x_sUrl, unsigned int x_uPort, unsigned int x_uType ) { // Lose old info Destroy(); // Ensure we have a valid pointer if ( !x_sUrl.length() ) return 0; // Crack the url t_pb8 pbUri = parser::DecodeUri< t_pb8 >( x_sUrl ); if ( !pbUri.size() ) return 0; // Did we get a host name? if ( !pbUri[ "host" ].length() ) return 0; // Get the port if ( !x_uPort ) x_uPort = pbUri[ "port" ].ToLong(); // Save the type m_uType = x_uType; return LookupHost( pbUri[ "host" ].str(), x_uPort ); }
bool DirUtil::CreateDirectory( const t_string &dirPath ) { if (!CreateParentDirectory(dirPath)) { return false; } return ::CreateDirectory(dirPath.c_str(), NULL) == TRUE; }
bool DirUtil::DeleteDirectory( const t_string &path ) { #if 0 SHFILEOPSTRUCT FileOp; ZeroMemory((void*)&FileOp, sizeof(SHFILEOPSTRUCT)); t_string strFromPath = MakePathRegular(path); // this string must be double-null terminated strFromPath.append(1, _T('\0')); FileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT; FileOp.hNameMappings = NULL; FileOp.hwnd = NULL; FileOp.lpszProgressTitle = NULL; FileOp.pFrom = strFromPath.c_str(); FileOp.pTo = NULL; FileOp.wFunc = FO_DELETE; return SHFileOperation(&FileOp) == 0; #endif bool ret = true; std::vector<t_string> fileList; std::vector<t_string> dirList; if (EnumFiles(path, fileList)) { for (size_t i = 0; i < fileList.size(); i++) { if (!DeleteFileIfExist(fileList.at(i))) { ret = false; break; } } } if (!ret) { return false; } if (EnumDirs(path, dirList)) { for (size_t i = 0; i < dirList.size(); i++) { if (!DeleteDirectory(dirList.at(i))) { ret = false; break; } } } if (!ret) { return false; } return ::RemoveDirectory(path.c_str()) ? true : false; }
bool DirUtil::DeleteFileIfExist( const t_string &filePath ) { if (IsFileExist(filePath)) { if (!::DeleteFile(filePath.c_str())) { _tchmod(filePath.c_str(), 0777); return ::DeleteFile(filePath.c_str()) ? true : false; } else { return true; } } else { return false; } }
void team::change_team(const std::string& name, const t_string& user_name) { info_.team_name = name; if(!user_name.empty()) { info_.user_team_name = user_name; } else { info_.user_team_name = name; } clear_caches(); }
void write_key_val(std::ostream &out, const std::string &key, const t_string &value, unsigned int level, std::string& textdomain) { bool first = true; if (value.empty()) { out << std::string(level, '\t') << key << AttributeEquals << AttributePrefix << AttributePostfix << AttributeEndPostfix;; return; } for(t_string::walker w(value); !w.eos(); w.next()) { std::string part(w.begin(), w.end()); if(w.translatable()) { if(w.textdomain() != textdomain) { out << TextdomainPrefix << w.textdomain() << TextdomainPostfix; textdomain = w.textdomain(); } if(first) { out << std::string(level, '\t') << key << AttributeEquals; } out << TranslatableAttributePrefix << escaped_string(part) << AttributePostfix; } else { if(first) { out << std::string(level, '\t') << key << AttributeEquals; } out << AttributePrefix << escaped_string(part) << AttributePostfix; } if(w.last()) { out << AttributeEndPostfix; } else { out << AttributeContPostfix; out << std::string(level+1, '\t'); } first = false; } }
DWORD Base::Write(const t_string & write_buffer, HANDLE pipe_handle, CRITICAL_SECTION & write_critical_section) { if (eState_ != STATE::started) { return ERROR_NOT_FOUND; } EnterCriticalSection(&write_critical_section); DWORD cbWritten; BOOL bSuccess = WriteFile ( pipe_handle, // pipe handle write_buffer.c_str(), // message write_buffer.length() * sizeof(t_string::traits_type::char_type), // message length &cbWritten, // bytes written NULL // not overlapped ); LeaveCriticalSection(&write_critical_section); return bSuccess ? ERROR_SUCCESS : GetLastError(); }
DWORD Client::Write(t_string write_buffer) { if (eState_ != STATE::started) { return ERROR_NOT_FOUND; } DWORD cbWritten; EnterCriticalSection(&csPipe_Write_); BOOL bSuccess = WriteFile ( hPipe_, // pipe handle write_buffer.c_str(), // message write_buffer.length() * sizeof(t_string::traits_type::char_type), // message length &cbWritten, // bytes written NULL // not overlapped ); LeaveCriticalSection(&csPipe_Write_); return bSuccess ? ERROR_SUCCESS : GetLastError(); }
int CIpSocket::Connect( const t_string &x_sAddress, unsigned int x_uPort ) { if ( !x_sAddress.length() ) return 0; // Punt if not initialized if ( !IsInitialized() ) return 0; CIpAddress addr; // Were we passed a URL? if ( !x_uPort && addr.LookupUri( x_sAddress ) ) return Connect( addr ); // Lookup the host address if ( addr.LookupHost( x_sAddress, x_uPort ) ) return Connect( addr ); return 0; }
/*WIKI * @begin{tag}{name="tip"}{min="0"}{max="-1"} * @begin{table}{config} * source & t_string & & Author * text & t_string & & Text of the tip. * @end{table} * @end{tag}{name="tip"} * @end{parent}{name="gui/"} */ const std::string& tgui_definition::read(const config& cfg) { id = cfg["id"].str(); description = cfg["description"]; VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id")); VALIDATE(!description.empty(), missing_mandatory_wml_key("gui", "description")); DBG_GUI_P << "Parsing gui " << id << '\n'; /***** Control definitions *****/ for(auto & widget_type : registred_widget_type()) { widget_type.second(*this, widget_type.first, cfg, nullptr); } /***** Window types *****/ for(const auto & w : cfg.child_range("window")) { std::pair<std::string, twindow_builder> child; child.first = child.second.read(w); window_types.insert(child); } if(id == "default") { // The default gui needs to define all window types since we're the // fallback in case another gui doesn't define the window type. for(std::vector<std::string>::const_iterator itor = registered_window_types().begin(); itor != registered_window_types().end(); ++itor) { const std::string error_msg( "Window not defined in WML: '" + *itor + "'. Perhaps a mismatch between data and source versions." " Try --data-dir <trunk-dir>"); VALIDATE(window_types.find(*itor) != window_types.end(), error_msg); } } /***** settings *****/ /** * @todo Regarding sounds: * Need to evaluate but probably we want the widget definition be able to: * - Override the default (and clear it). This will allow toggle buttons in * a * listbox to sound like a toggle panel. * - Override the default and above per instance of the widget, some buttons * can give a different sound. */ const config& settings = cfg.child("settings"); popup_show_delay_ = settings["popup_show_delay"]; popup_show_time_ = settings["popup_show_time"]; help_show_time_ = settings["help_show_time"]; double_click_time_ = settings["double_click_time"]; repeat_button_repeat_time_ = settings["repeat_button_repeat_time"]; VALIDATE(double_click_time_, missing_mandatory_wml_key("settings", "double_click_time")); sound_button_click_ = settings["sound_button_click"].str(); sound_toggle_button_click_ = settings["sound_toggle_button_click"].str(); sound_toggle_panel_click_ = settings["sound_toggle_panel_click"].str(); sound_slider_adjust_ = settings["sound_slider_adjust"].str(); has_helptip_message_ = settings["has_helptip_message"]; VALIDATE(!has_helptip_message_.empty(), missing_mandatory_wml_key("[settings]", "has_helptip_message")); tips_ = tips::load(cfg); return id; }
variant operator()(const t_string& s) const {return variant(s.str());}
bool DirUtil::EnumFilesOrDir( const t_string &path, std::vector<t_string> &fileList, int enumType) { if (path.empty()) { return false; } t_string strDirPath = MakePathRegular(path); if (strDirPath.find_last_of(DEFAULT_PATH_SPLITER) != strDirPath.length() - 1) { strDirPath.push_back(DEFAULT_PATH_SPLITER); } t_string filter = strDirPath; filter.append(_T("*")); WIN32_FIND_DATA fd; HANDLE hFind = FindFirstFile( filter.c_str(), &fd ); if ( hFind == INVALID_HANDLE_VALUE ){ return false; } do { if (ENUM_FILE & enumType) { if (!(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) { if (ENUM_ONLY_FILE_NAME & enumType) { fileList.push_back(fd.cFileName); } else { t_string fp = strDirPath; fp.append(fd.cFileName); fileList.push_back(fp); } } } if (ENUM_DIR & enumType) { if ( _tcscmp(fd.cFileName, _T(".")) != 0 && _tcscmp(fd.cFileName, _T("..")) != 0 && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (ENUM_ONLY_FILE_NAME & enumType) { fileList.push_back(fd.cFileName); } else { t_string fp = strDirPath; fp.append(fd.cFileName); fileList.push_back(fp); } } } } while ( FindNextFile( hFind, &fd ) != 0 ); FindClose( hFind ); return true; }
inline t_string operator+(const std::string& a, const t_string& b) { return t_string(a + b.str()); }
inline bool operator!=(const std::string& a, const t_string& b) { return a != b.str(); }
bool operator<(const t_string& o) const { return get() < o.get(); }
namespace font { bool check_font_file(std::string name) { if(game_config::path.empty() == false) { if(!filesystem::file_exists(game_config::path + "/fonts/" + name)) { if(!filesystem::file_exists("fonts/" + name)) { if(!filesystem::file_exists(name)) { WRN_FT << "Failed opening font file '" << name << "': No such file or directory" << std::endl; return false; } } } } else { if(!filesystem::file_exists("fonts/" + name)) { if(!filesystem::file_exists(name)) { WRN_FT << "Failed opening font file '" << name << "': No such file or directory" << std::endl; return false; } } } return true; } static bool add_font_to_fontlist(const config &fonts_config, std::vector<font::subset_descriptor>& fontlist, const std::string& name) { const config &font = fonts_config.find_child("font", "name", name); if (!font) { return false; } //DBG_FT << "Adding a font record: " << font.debug() << std::endl; fontlist.push_back(font::subset_descriptor(font)); return true; } // Current font family for sanserif and monospace fonts in the game t_string family_order_sans; t_string family_order_mono; /*** * Public interface */ bool load_font_config() { //read font config separately, so we do not have to re-read the whole //config when changing languages config cfg; try { const std::string& cfg_path = filesystem::get_wml_location("hardwired/fonts.cfg"); if(cfg_path.empty()) { ERR_FT << "could not resolve path to fonts.cfg, file not found\n"; return false; } filesystem::scoped_istream stream = preprocess_file(cfg_path); read(cfg, *stream); } catch(config::error &e) { ERR_FT << "could not read fonts.cfg:\n" << e.message << '\n'; return false; } const config &fonts_config = cfg.child("fonts"); if (!fonts_config) return false; std::set<std::string> known_fonts; for (const config &font : fonts_config.child_range("font")) { known_fonts.insert(font["name"]); if (font.has_attribute("bold_name")) { known_fonts.insert(font["bold_name"]); } if (font.has_attribute("italic_name")) { known_fonts.insert(font["italic_name"]); } } family_order_sans = fonts_config["family_order"]; family_order_mono = fonts_config["family_order_monospace"]; if(family_order_mono.empty()) { ERR_FT << "No monospace font family order defined, falling back to sans serif order\n"; family_order_mono = family_order_sans; } std::vector<font::subset_descriptor> fontlist; for(auto font : utils::split(fonts_config["order"])) { add_font_to_fontlist(fonts_config, fontlist, font); known_fonts.erase(font); } for(auto kfont : known_fonts) { add_font_to_fontlist(fonts_config, fontlist, kfont); } if(fontlist.empty()) return false; sdl_ttf::set_font_list(fontlist); return true; } const t_string& get_font_families(family_class fclass) { switch(fclass) { case FONT_MONOSPACE: return family_order_mono; default: return family_order_sans; } } /*** * Manager member functions */ manager::manager() { #ifdef CAIRO_HAS_FT_FONT std::string font_path = game_config::path + "/fonts"; if (!FcConfigAppFontAddDir(FcConfigGetCurrent(), reinterpret_cast<const FcChar8 *>(font_path.c_str()))) { ERR_FT << "Could not load the true type fonts" << std::endl; throw font::error("font config lib failed to add the font path: '" + font_path + "'"); } std::string font_file = font_path + "/fonts.conf"; if(!FcConfigParseAndLoad(FcConfigGetCurrent(), reinterpret_cast<const FcChar8*>(font_file.c_str()), FcFalse)) { ERR_FT << "Could not load local font configuration\n"; throw font::error("font config lib failed to find font.conf: '" + font_file + "'"); } else { LOG_FT << "Local font configuration loaded\n"; } #endif #if CAIRO_HAS_WIN32_FONT for(const std::string& path : filesystem::get_binary_paths("fonts")) { std::vector<std::string> files; if(filesystem::is_directory(path)) { filesystem::get_files_in_dir(path, &files, nullptr, filesystem::ENTIRE_FILE_PATH); } for(const std::string& file : files) { if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc") { const std::wstring wfile = unicode_cast<std::wstring>(file); AddFontResourceExW(wfile.c_str(), FR_PRIVATE, nullptr); } } } #endif } manager::~manager() { #ifdef CAIRO_HAS_FT_FONT FcConfigAppFontClear(FcConfigGetCurrent()); #endif #if CAIRO_HAS_WIN32_FONT for(const std::string& path : filesystem::get_binary_paths("fonts")) { std::vector<std::string> files; if(filesystem::is_directory(path)) filesystem::get_files_in_dir(path, &files, nullptr, filesystem::ENTIRE_FILE_PATH); for(const std::string& file : files) { if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc") { const std::wstring wfile = unicode_cast<std::wstring>(file); RemoveFontResourceExW(wfile.c_str(), FR_PRIVATE, nullptr); } } } #endif } } // end namespace font
void ttext::draw(surface& canvas , const game_logic::map_formula_callable& variables) { assert(variables.has_key("text")); // We first need to determine the size of the text which need the rendered // text. So resolve and render the text first and then start to resolve // the other formulas. const t_string text = text_(variables); if(text.empty()) { DBG_GUI_D << "Text: no text to render, leave.\n"; return; } static font::ttext text_renderer; text_renderer.set_text(text, text_markup_(variables)); text_renderer.set_font_size(font_size_) .set_font_style(font_style_) .set_alignment(text_alignment_(variables)) .set_foreground_color(color_) .set_maximum_width(maximum_width_(variables)) .set_maximum_height(maximum_height_(variables)) .set_ellipse_mode(variables.has_key("text_wrap_mode") ? static_cast<PangoEllipsizeMode> (variables.query_value("text_wrap_mode").as_int()) : PANGO_ELLIPSIZE_END); surface surf = text_renderer.render(); if(surf->w == 0) { DBG_GUI_D << "Text: Rendering '" << text << "' resulted in an empty canvas, leave.\n"; return; } game_logic::map_formula_callable local_variables(variables); local_variables.add("text_width", variant(surf->w)); local_variables.add("text_height", variant(surf->h)); /* std::cerr << "Text: drawing text '" << text << " maximum width " << maximum_width_(variables) << " maximum height " << maximum_height_(variables) << " text width " << surf->w << " text height " << surf->h; */ ///@todo formulas are now recalculated every draw cycle which is a // bit silly unless there has been a resize. So to optimize we should // use an extra flag or do the calculation in a separate routine. const unsigned x = x_(local_variables); const unsigned y = y_(local_variables); const unsigned w = w_(local_variables); const unsigned h = h_(local_variables); DBG_GUI_D << "Text: drawing text '" << text << "' drawn from " << x << ',' << y << " width " << w << " height " << h << " canvas size " << canvas->w << ',' << canvas->h << ".\n"; VALIDATE(static_cast<int>(x) < canvas->w && static_cast<int>(y) < canvas->h , _("Text doesn't start on canvas.")); // A text might be to long and will be clipped. if(surf->w > static_cast<int>(w)) { WRN_GUI_D << "Text: text is too wide for the " "canvas and will be clipped.\n"; } if(surf->h > static_cast<int>(h)) { WRN_GUI_D << "Text: text is too high for the " "canvas and will be clipped.\n"; } SDL_Rect dst = ::create_rect(x, y, canvas->w, canvas->h); blit_surface(surf, 0, canvas, &dst); }
int CIpAddress::LookupHost( const t_string &x_sServer, unsigned int x_uPort, unsigned int x_uType ) { // Lose old info Destroy(); // Ensure we have a valid pointer if ( !x_sServer.length() ) return 0; // +++ Get this working eventually // #if !defined( HTM_USE_GETHOSTBYNAME ) #if 0 in_addr ip4; if ( inet_pton( PF_INET, x_sServer.c_str(), &ip4 ) ) { SetRawAddress( ntohl( *(unsigned long*)&ip4.s_addr ), x_uPort, x_uType ); return 1; } // end if struct addrinfo hints, *addr = 0; memset( &hints, 0, sizeof( hints ) ); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; int rval = 0; if ( rval = getaddrinfo( x_sServer.c_str(), 0, &hints, &addr ) ) return 0; int max = 128; while ( !addr && max-- ) { switch( addr->ai_family ) { case AF_INET : { sockaddr_in *psai = (sockaddr_in*)addr->ai_addr; in_addr *pia = &psai->sin_addr; SetRawAddress( ntohl( *(unsigned long*)&pia->s_addr ), x_uPort, x_uType ); return 1; } break; case AF_INET6 : { // +++ Add v6 support sockaddr_in6 *psai = (sockaddr_in6*)addr->ai_addr; sin6_addr *pia6 = &psai->sin6_addr; } break; } // end switch if ( addr == addr->ai_next ) addr = 0; else addr = addr->ai_next; } // end while return 0; #else // First try to interpret as dot address unsigned int uAddr = inet_addr( x_sServer.c_str() ); if ( INADDR_NONE != uAddr ) { SetRawAddress( ntohl( uAddr ), x_uPort, x_uType ); return 1; } // end if struct hostent *pHe; do { pHe = gethostbyname( x_sServer.c_str() ); } while ( !pHe && EINTR == h_errno ); if ( !pHe || !pHe->h_addr_list ) return 0; in_addr *pia = (in_addr*)*pHe->h_addr_list; if ( !pia ) return 0; SetRawAddress( ntohl( *(unsigned int*)&pia->s_addr ), x_uPort, x_uType ); return 1; #endif }
std::string operator()(const t_string& s) const { return s.str(); }
t_string operator+(const t_string& o) const { return get() + o.get(); }
std::string operator()(t_string const &s) const { return s.str(); }
bool operator==(const t_string& o) const { return get() == o.get(); }