std::string stringOf( const void* lpvEStr , int iESize ) { if ( IsTextUnicode( (CONST LPVOID)lpvEStr , iESize , NULL ) ){ return( stringOf( (LPCWSTR)lpvEStr ) ); } return ( stringOf( (LPCSTR)lpvEStr ) ) ; }
ConfigHandler::ConfigHandler(User *user, const std::string &from, const std::string &id) : m_from(from), m_user(user) { setRequestType(CALLER_ADHOC); std::string bare(JID(from).bare()); IQ _response(IQ::Result, from, id); Tag *response = _response.tag(); response->addAttribute("from", Transport::instance()->jid()); AdhocTag *adhocTag = new AdhocTag(Transport::instance()->getId(), "transport_irc_config", "executing"); adhocTag->setAction("complete"); adhocTag->setTitle("IRC Nickserv password configuration"); adhocTag->setInstructions("Choose the server you want to change password for."); std::map <std::string, std::string> values; std::map<std::string, UserRow> users = Transport::instance()->sql()->getUsersByJid(bare); for (std::map<std::string, UserRow>::iterator it = users.begin(); it != users.end(); it++) { std::string server = (*it).second.jid.substr(bare.size()); values[server] = stringOf((*it).second.id); m_userId.push_back(stringOf((*it).second.id)); } adhocTag->addListSingle("IRC server", "irc_server", values); adhocTag->addTextPrivate("New NickServ password", "password"); response->addChild(adhocTag); Transport::instance()->send(response); }
void FileHeaderParser::parse(std::string data) { storedData += data; if (storedData.find("\r\n\r\n") != 0) { headerPassed = true; total += storedData.length() - storedData.find("\r\n\r\n") - 4; std::istringstream iss(storedData, std::istringstream::in); while(!iss.eof()) { std::string line; std::getline(iss, line); if (line == "\r") break; line[line.length()-1] = 0; Logger::instance().log("FileHeaderParser: ["+line+"]", DEBUG); //std::cout << "Line: [" << line << "]" << std::endl; if (line.find("Content-Length:") == 0) { std::vector<std::string> parts; split(line, parts, ':', 2); lengthRecieved = true; contentLength = valueOfString<int>(parts[1]); Logger::instance().log("GOT Content-Length: "+stringOf(contentLength), DEBUG); } } checkEnd(); } }
void NetworkPlugin::sendMemoryUsage() { pbnetwork::Stats stats; stats.set_init_res(m_init_res); double res = 0; double shared = 0; #ifndef WIN32 process_mem_usage(shared, res); #endif double e_res; double e_shared; handleMemoryUsage(e_res, e_shared); stats.set_res(res + e_res); stats.set_shared(shared + e_shared); stats.set_id(stringOf(getpid())); std::string message; stats.SerializeToString(&message); WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_STATS); send(message); }
bool ConfigFile::loadHostPort(std::string &host, int &port, const std::string §ion, const std::string &key, const std::string &def_host, const int &def_port) { std::string str; if (!g_key_file_has_key(keyfile, section.c_str(), key.c_str(), NULL)) { if (def_host == "required") { Log("loadConfigFile", "You have to specify `" << key << "` in [" << section << "] section of config file."); return false; } host = def_host; port = def_port; return true; } loadString(str, section, key); if (str.find_first_of(':') == std::string::npos) port = 0; else { std::string p = str.substr(str.find_first_of(':') + 1, str.size()).c_str(); replace(p, "$filename:port", stringOf(m_port).c_str()); port = atoi(p.c_str()); } host = str.substr(0, str.find_last_of(':')); return true; }
string iSpace( int N ) { return stringOf( N, ' ' ); }
Tpath traceM_buildSeed( generalmatrix &Mat ) { Tpath seed; if ( Mat.mode_localOnly() ) { // were local hence seed = "" seed.Starti = Mat.locali(); seed.Startj = Mat.localj(); seed.path = ""; } else { if ( Mat.mode_chargeOverHang() ) { // easy start at the end of the matrix seed.Starti = Mat.nCols() - 1; seed.Startj = Mat.nRows() - 1; seed.path = ""; // no start path } else { if ( Mat.overhangi() < Mat.nCols() - 1 ) { seed.Startj = Mat.nRows() - 1; if ( Mat.mode_showSkip() ) { seed.path = stringOf( Mat.nCols() - Mat.overhangi() - 1, '2' ); seed.Starti = Mat.nCols() - 1; } else { seed.Starti = Mat.overhangi(); seed.path = ""; } } else if ( Mat.overhangj() < Mat.nRows() - 1 ) { seed.Starti = Mat.nCols() - 1; if ( Mat.mode_showSkip() ) { seed.path = stringOf( Mat.nRows() - Mat.overhangj() - 1, '4' ); seed.Startj = Mat.nRows() - 1; } else { seed.Startj = Mat.overhangj(); seed.path = ""; } } else { seed.Starti = Mat.nCols() - 1; seed.Startj = Mat.nRows() - 1; seed.path = ""; } } } return seed; }
void traceM_construct( TmatrixPaths &paths, generalmatrix &Mat, int mx ) { paths.clear(); // make sure its empty int i, j; std::string seed = ""; if ( Mat.mode_localOnly() ) { i = Mat.locali(); j = Mat.localj(); } else if ( !Mat.mode_chargeOverHang() ) { if ( Mat.mode_showSkip() ) { if ( Mat.overhangi() < Mat.nCols() - 1 ) { seed = stringOf( Mat.nCols() - Mat.overhangi(), '2' ); i = Mat.overhangi(); j = Mat.nRows() - 1; } else if ( Mat.overhangj() < Mat.nRows() - 1 ) { seed = stringOf( Mat.nRows() - Mat.overhangj(), '4' ); i = Mat.nCols() - 1; j = Mat.overhangj(); } else { i = Mat.nCols() - 1; j = Mat.nRows() - 1; } } else { i = Mat.nCols() - 1; j = Mat.nRows() - 1; } } else { i = Mat.nCols() - 1; j = Mat.nRows() - 1; } //seed+= 48 + Mat.getT( i , j ); Tpath cPath; Tpath tmp; cPath.Starti = i; cPath.Startj = j; cPath.path = seed; // test cPath = traceM_buildSeed( Mat ); paths.push_back( cPath ); int nr = 0; int exs = 1; char T; TPos P; int mg; while ( exs != 0 ) { exs = 0; nr = 0; while (nr != paths.size() ) { cPath = paths[nr]; if ( needsExtention( cPath.path ) ) { exs++; P = calcEndPos( cPath ); T = Mat.getT( P.x, P.y ); mg = 0; if ( T == 0 ) { paths[nr].path+= '0'; } if ( ( T & 1 ) == 1 ) { mg++; paths[nr].path+= '1'; } if ( ( T & 2 ) == 2 ) { if ( mg > 0 ) { //cout << "doub" << endl; if ( paths.size() < mx ) { tmp = cPath; tmp.path+=stringOf( Mat.getHgap( P.x, P.y ), '2' ); paths.push_back( tmp ); //cout << paths.size() << endl; } } else paths[nr].path+=stringOf( Mat.getHgap( P.x, P.y ), '2' ); mg++; } if ( ( T & 4 ) == 4 ) { if ( mg > 0 ) { //cout << "doub" << endl; if ( paths.size() < mx ) { tmp = cPath; tmp.path += stringOf( Mat.getVgap( P.x, P.y ), '4' ); paths.push_back( tmp ); //cout << paths.size() << endl; } } else paths[nr].path+= stringOf( Mat.getVgap( P.x, P.y), '4' ); } } nr++; } } }