void IdentityRedirectInserter::StartInsert(const long localidentityid, const std::string &redirect) { std::string idstring(""); StringFunctions::Convert(localidentityid,idstring); SQLite3DB::Statement st=m_db->Prepare("SELECT PrivateKey FROM tblLocalIdentity WHERE LocalIdentityID=?"); st.Bind(0, localidentityid); st.Step(); if(st.RowReturned()) { std::string privatekey(""); std::string messagebase(""); Option option(m_db); option.Get("MessageBase",messagebase); st.ResultText(0, privatekey); FCPv2::Message mess("ClientPut"); mess["URI"]="USK"+privatekey.substr(3)+messagebase+"|IdentityRedirect/0/"; mess["Identifier"]="IdentityRedirectInserter|"+idstring+"|"+mess["URI"]; mess["UploadFrom"]="redirect"; mess["TargetURI"]=redirect; m_fcp->Send(mess); m_log->debug("IdentityRedirectInserter::StartInsert inserting redirect for "+idstring+" to "+redirect); } }
/* returns empty string upon mismatch */ std::string Parser::id(){ std::string idstring(lexer->getLexeme()); if (match(TOK_ID, "id")) return idstring; else return ""; }
/* XXX: ugly hack to allow "Microsoft Office Document" (without ") */ std::string Parser::id_list(){ bool is_multiword = false; std::string idstring( id()); while(lexer->getToken() == TOK_ID){ idstring += " " + id(); is_multiword = true; } if (is_multiword) std::cout << lexer->getLinenumber() << ": Warning: multiword identifier ("<< idstring << ")\n"; return idstring; }
/* XXX: ugly hack to allow "Microsoft Office Document" (without ") */ std::string Parser::id_list(){ bool is_multiword = false; std::string idstring( id()); while(lexer->getToken() == TOK_ID){ idstring += " " + id(); is_multiword = true; } if (is_multiword) getLogStream(ocfa::misc::LOG_WARNING) << lexer->getLinenumber() << ": Error prone multiword identifier ("<< idstring << ")\n"; return idstring; }
void serverMessage(std::string command, std::string option, std::string data, IClientSocket *socket) { // Server command: client attempts a connection if(command == "newClient"){ std::string idcode = idstring(socket); if(findUser(data) == true){ remoteMessage("/error,userFound",socket); }else{ // Inform the client connection is accepted on server remoteMessage("/accepted,"+idcode,socket); // Inform all clients to show user as connected broadcastMessage("/userConnect,"+data+":"+idcode, socket); // Now send a list of current users to the client you just accepted std::string token,userlist = getUserlist(); for(size_t pos = userlist.find(";");pos != std::string::npos;pos = userlist.find(";")){ token = userlist.substr(0,pos); userlist = userlist.substr(pos+1); size_t sep = token.find(","); std::string user = token.substr(0,sep); std::string id = token.substr(sep+1); remoteMessage("/userConnect,"+user+":"+id,socket); } } } if(command == "info") { if(data == "listening") data = "Listening for clients"; if(data == "serverStart") data = "Server started"; if(data == "serverStop") data = "Server stopped, all clients disconnected"; if(data == "newClient") data = "incoming connection from client"; insertMessage("info",data); } }
// The network commandMessage method void commandMessage(std::string text, IClientSocket *socket) { std::string command, option, data; decodeMessage(text,command,option,data); fusion->errlog << "command = " << command << ", option = " << option << ", data = " << data << std::endl; // If all strings are empty, error occured, a blank // string, or messed up string cannot be processed if(command.empty() == true && option.empty() == true && data.empty() == true) return; if(socket == state.client) clientMessage(command,option,data,socket); else serverMessage(command,option,data,socket); /* Client/Server commands go here, where they are not resolved in the specific clientMessage/serverMessage methods */ // Client/Server command: both can change their userName they are chatting with if(command == "setUsername") { if(option.empty() == true){ // No ID passed with this command // WAITING CLIENT if(state.enableClient == true && getConnected() == "Connect"){ remoteMessage("/newClient,"+data); }else{ std::string name; std::string idcode = state.id; if(state.enableClient == true){ if(getConnected() == "Disconnect") name = state.username; else socket = state.client; }else if(state.enableServer == true){ if(socket == NULL) name = state.username; else idcode = idstring(socket); } clientMessage("/info,socket = "+idcode); remoteMessage("/setUsername,"+name+";"+data+":"+idcode,socket); } }else{ // ID was passed with this command size_t pos = option.find(";"); if(pos > 0){ std::string oldUser = option.substr(0,pos); std::string newUser = option.substr(pos+1); if(renameUser(oldUser,newUser,data) == true){ broadcastMessage("/setUsername,"+option+":"+data, socket); }else{ clientMessage("/error,userFound"); } }else{ updateUsername(option.substr(1)); } } } if(command == "quit") closeApp(); }