template <typename T> static inline size_t insertInBimap (boost::bimap<size_t, T>& bimap, T value) { if (bimap.right.count (value) != 0) { return bimap.right.at (value); } else { size_t s = bimap.size (); bimap.insert (typename boost::bimap<size_t, T>::value_type (s, value)); return s; } }
void UserMappingGridmap::Store( std::string dn, std::string users, std::string user_seperator, boost::bimap< std::string, std::string > &new_username, std::multimap< std::string, std::string > &new_groupname) { // if there are several usernames, use only the first one escaped_list_separator<char> els2("", user_seperator.c_str(), ""); tokenizer< escaped_list_separator<char> > tok_user(users, els2); tokenizer< escaped_list_separator<char> >::iterator first_username = tok_user.begin(); std::string user = std::string(*first_username); // cout << "gridmap: dn: '" << dn << "'" << std::endl; // cout << "gridmap: user: "******"OU=", 0); while (ou_pos != string::npos) { size_t end_pos = dn.find(",", ou_pos+1); std::string ou = dn.substr(ou_pos+3, end_pos-ou_pos-3); // cout << "gridmap: group: " << ou << std::endl; // add one usergroup (OU=...) new_groupname.insert(std::pair<std::string, std::string>(dn, ou)); // search in the remaining string ou_pos = dn.find("OU=", ou_pos+1); } }
void operator ()(Shuttler& shuttle, const char* name, const boost::bimap<K, V, AP1, AP2, AP3>& value) const { shuttle.StartSequence(name, static_cast<int>(value.size())); for(auto& i : value.left) { shuttle.Send(std::make_pair(i.first, i.second)); } shuttle.EndSequence(); }
void operator ()(Shuttler& shuttle, const char* name, boost::bimap<K, V, AP1, AP2, AP3>& value) const { using Pair = std::pair< typename boost::bimap<K, V, AP1, AP2, AP3>::left_key_type, typename boost::bimap<K, V, AP1, AP2, AP3>::right_key_type>; value.clear(); int count; shuttle.StartSequence(name, count); for(auto i = 0; i < count; ++i) { Pair entry; shuttle.Shuttle(entry); value.left.insert(std::move(entry)); } shuttle.EndSequence(); }
/* * 接收key,建立连接 */ void recv_key(SOCKET aisocket) { char lirecv[32]; int liret; liret = g_recv(aisocket, lirecv, 32); if (liret <= 0) { closesocket(aisocket); return; } if (size_t(liret) < sizeof(uint32_t)) { closesocket(aisocket); return; } uint32_t lkey = *((uint32_t*)(lirecv)); auto itor = m_socket_key.right.find(lkey); if (itor != m_socket_key.right.end()) { if( (const_cast<key_stat*>(&itor->first))->get_stat() ) { closesocket(aisocket); return; } else { m_socket_key.right.erase( itor ); } } m_socket_key.insert(boost::bimap<SOCKET, key_stat>::value_type(aisocket, lkey)); /** 回复 */ if (g_send(aisocket, lirecv, liret) <= 0) { closesocket(aisocket); return; } middleware::tools::threadpool::asyn_thread( boost::bind( &accept_key_socket::recv, this, aisocket, lkey) ); }