void MessageHandlerI::deliverFeed(const string& msg, const string& type, const MyUtil::IntSeq& ids, const Ice::Current&) { StatFunc statF("MessageHandlerI::deliverFeed"); //MCE_DEBUG("call MessageHandlerI::deliverFeed"); ostringstream os; os<< "<message type='headline' from='"<<type<<"@news.talk.xiaonei.com'>" << msg << "</message>"; xml_document doc; if (!doc.load(os.str().c_str())) { MCE_WARN("Parser xml err !!!"); return; } //TargetHandlerSeq res; JidSeqMap jmap; try{ jmap = OnlineCenterAdapter::instance().getUsersJids(ids); }catch(Ice::Exception& e){ MCE_WARN("MessageHandlerI::deliverFeed-->OnlineCenterAdapter::getUsersJids-->" << e); } MessageSeq seq; for (JidSeqMap::iterator it = jmap.begin(); it != jmap.end(); ++it) { for (size_t i = 0; i < it->second.size(); ++i) { if (it->second.at(i)->index <= 1) { // this user is old im client or web client, ignore this feed continue; } MessagePtr mPtr = new Message(); mPtr->from = new Jid(); mPtr->from->userId = -1; mPtr->from->endpoint = type; mPtr->from->index = -1; mPtr->to = it->second.at(i); mPtr->type = SYSTEM_MESSAGE; doc.child("message").append_attribute("to") = jidToString(it->second.at(i),false).c_str(); mPtr->msg = doc.xml(); seq.push_back(mPtr); if (it->second.at(i)->userId == 128487631) { MCE_DEBUG("NEWS:"<<mPtr->msg); } } } if (!seq.empty()) { //NotifyTaskManager::instance().addTargetHandler(res); MCE_DEBUG("send news to Dispatch list"); try{ TalkDeliverAdapter::instance().deliver(seq); }catch(Ice::Exception& e){ MCE_WARN("MessageHandlerI::deliverFeed-->TalkDeliverAdapter::deliver-->" << e); } } //NotifyTaskManager::instance().addNotify(new Notify< std::pair<string,MyUtil::IntSeq>,FeedNotifyHandler>(std::make_pair(msg,ids))); }
void NotifySetPermisionTask::handle(){ MucActiveUserSeq::const_iterator targetit = targetusers.begin(); MessageSeq seq; for(; targetit != targetusers.end(); ++targetit){//每个即将改变权限的用户 string from_identity_str = mucUserIdentityToString((*targetit)->identity); string from_jid_str = jidToString((*targetit)->jid); if(from_identity_str.empty() || from_jid_str.empty()){ continue; } JidSeq::const_iterator jit = presenceUsers.begin(); for(; jit != presenceUsers.end(); ++jit){ if((*jit)->endpoint[0] == 'T'){ xml_document doc; xml_node presenceNode = doc.append_child(); presenceNode.set_name("presence"); presenceNode.append_attribute("from").set_value(from_identity_str.c_str()); presenceNode.append_attribute("to").set_value(jidToString((*jit)).c_str()); if(permision < PMember){ presenceNode.append_attribute("type").set_value("unavailable"); } xml_node xNode = presenceNode.append_child(); xNode.set_name("x"); xNode.append_attribute("xmlns").set_value("http://jabber.org/protocol/muc#user"); xml_node itemNode = xNode.append_child(); itemNode.set_name("item"); itemNode.append_attribute("affiliation").set_value(MucGateManagerI::instance().Permision2Str(permision).c_str()); itemNode.append_attribute("role").set_value(MucGateManagerI::instance().Psermision2Role(permision).c_str()); if(equal((*targetit)->jid, (*jit)) && permision < PMember){ xml_node actorNode = itemNode.append_child(); actorNode.set_name("actor"); actorNode.append_attribute("jid").set_value(jidToString(opuser->jid).c_str()); } else{ itemNode.append_attribute("jid").set_value(from_jid_str.c_str()); } MessagePtr msg = new Message(); msg->from = opuser->jid; msg->to = (*jit); msg->msg = doc.xml(); msg->type = PRESENCE_COMMON;//none seq.push_back(msg); } } } try{ MCE_INFO("MucGateManagerI::NotifySetPermision--> CALL MucDeliver.deliver seq.size = " << seq.size()); MucDeliverAdapter::instance().deliver(seq); } catch(Ice::Exception& e){ MCE_WARN("MucGateManagerI::NotifySetPermision--> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e); }catch(std::exception& e){ MCE_WARN("MucGateManagerI::NotifySetPermision--> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e.what()); } }
void NoticePipe::handle(const ObjectSeq& objs){ MessageSeq msgs; IntSeq ids; for (size_t i = 0; i < objs.size(); ++i) { MessagePtr m = MessagePtr::dynamicCast(objs.at(i)); msgs.push_back(m); ids.push_back(m->to->userId); } JidSeqMap jmap; try{ //jmap = OnlineCenterAdapter::instance().getUsersJids(ids); jmap = TalkFunStateAdapter::instance().getUsersJids(ids); }catch(Ice::Exception& e){ //MCE_WARN("NoticePipe::handle --> call OnlineCenterAdapter.getUsersJids error : " << e); MCE_WARN("NoticePipe::handle --> call TalkFunStateAdapter.getUsersJids error : " << e); } MessageSeq res; for (size_t i = 0; i < msgs.size(); ++i) { JidSeqMap::iterator it = jmap.find(msgs.at(i)->to->userId); if (it == jmap.end()) { continue; } for (size_t j = 0; j < it->second.size(); ++j) { if (it->second.at(j)->endpoint.size() > 1 && it->second.at(j)->endpoint[0] == 'T') { MessagePtr m = new Message(); m->from = new Jid(); m->from->userId = -1; m->from->endpoint = "appnotice.talk.xiaonei.com"; m->from->index = -1; m->to = it->second.at(j); m->type = msgs.at(i)->type; m->msg = msgs.at(i)->msg; res.push_back(m); } } } if (!res.empty()) { MCE_INFO("NoticePipe::handle --> Notice size:"<<res.size()); try{ TalkDeliverAdapter::instance().deliver(res); }catch(Ice::Exception& e){ MCE_WARN("NoticePipe::handle --> call TalkDeliverAdapter.deliver error : " << e); } } }
void NotifyPrivateChatTask::handle(){ string sender_identity_str = mucUserIdentityToString(sender->identity); if(sender_identity_str.empty()){ return; } MCE_DEBUG("MucGateManagerI::NotifyPrivateChat--> senderjid = " << jidToString(sender->jid) << " roomid = " << mucRoomIdToString(sender->identity->roomid) << " targetuser = "******" msg = " << msg); JidSeq imusers; try{ imusers = OnlineCenterAdapter::instance().getUserJids(targetuser, 4); MCE_DEBUG("MucGateManagerI::NotifyPrivateChat --> CALL ONLINECENTER get IM jids.size = " << imusers.size()); } catch(Ice::Exception& e){ MCE_WARN("MucGateManagerI::NotifyPrivateChat --> call OnlineCenterAdapter.getUserJids ERR line:"<<__LINE__<<" err:"<<e); } catch(std::exception& e){ MCE_WARN("MucGateManagerI::NotifyPrivateChat --> call OnlineCenterAdapter.getUserJids ERR line:"<<__LINE__<<" err:"<<e.what()); } MessageSeq seq; JidSeq::const_iterator jit = imusers.begin(); for(; jit != imusers.end(); ++jit){ xml_document doc; xml_node messageNode = doc.append_child(); messageNode.set_name("message"); messageNode.append_attribute("from").set_value(sender_identity_str.c_str()); messageNode.append_attribute("to").set_value(jidToString((*jit)).c_str()); messageNode.append_attribute("type").set_value("chat"); xml_node bodyNode = messageNode.append_child(); bodyNode.set_name("body"); bodyNode.append_child(node_pcdata).set_value(msg.c_str()); MessagePtr msg = new Message(); msg->from = sender->jid; msg->to = (*jit); msg->msg = doc.xml(); msg->type = MESSAGE;//none msg->msgKey = -1; seq.push_back(msg); } try{ MCE_INFO("MucGateManagerI::NotifyPrivateChat --> CALL MucDeliver.deliver seq.size = " << seq.size()); MucDeliverAdapter::instance().deliver(seq); } catch(Ice::Exception& e){ MCE_WARN("MucGateManagerI::NotifyPrivateChat --> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e); } catch(std::exception& e){ MCE_WARN("MucGateManagerI::NotifyPritateChat--> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e.what()); } }
//-------------------------------------------------------------------------------- void PostPipe::handle(const ObjectSeq& seq) { if (seq.empty()) { return; } MessageSeq mseq; for (size_t i = 0; i < seq.size(); ++i) { mseq.push_back(MessagePtr::dynamicCast(seq.at(i))); } try { MucDeliverManagerI::instance().getProxyServerOneway(mseq.at(0)->to)->deliver(mseq); } catch(Ice::Exception& e) { MCE_WARN("PostPipe::handle --> deliver err:"<<e<<" to endpoint:"<< mseq.at(0)->to); } MCE_DEBUG(__FUNCTION__ << " --> deliver size="<<mseq.size()); }
void PostPipe::handle(const ObjectSeq& seq) { if (seq.empty()) { return; } else { MCE_DEBUG("PostPipe::handle --> objectseq size = " <<seq.size()); } MessageSeq mseq; for (size_t i = 0; i < seq.size(); ++i) { mseq.push_back(MessagePtr::dynamicCast(seq.at(i))); } try { MCE_DEBUG("start to deliver --> toid:"<<mseq.at(0)->to->userId); WTalkProxyManagerI::instance().getAccessServerOneway(getName())->deliver(mseq); MCE_DEBUG("end deliver --> toid:"<<mseq.at(0)->to->userId); } catch(Ice::Exception& e) { MCE_WARN("PostPipe::handle --> deliver err:"<<e<<" to endpoint:"<< mseq.at(0)->to); } }
void NotifyNicknameErrorTask::handle(){ if(!roomid || !jid){ return; } string from = mucRoomIdToString(roomid); string to = jidToString(jid); if(from.empty() || to.empty()){ return; } xml_document doc; xml_node presenceNode = doc.append_child(); presenceNode.set_name("presence"); presenceNode.append_attribute("from").set_value(from.c_str()); presenceNode.append_attribute("to").set_value(to.c_str()); presenceNode.append_attribute("type").set_value("error"); xml_node xNode = presenceNode.append_child(); xNode.set_name("x"); xNode.append_attribute("xmlns").set_value("http://jabber.org/protocol/muc"); xml_node errorNode = presenceNode.append_child(); errorNode.set_name("error"); errorNode.append_attribute("type").set_value("cancel"); xml_node conflictNode = errorNode.append_child(); conflictNode.set_name("conflict"); conflictNode.append_attribute("xmlns").set_value("urn:ietf:params:xml:ns:xmpp-stanzas"); MessageSeq seq; MessagePtr msg = new Message(); msg->from = jid; msg->to = jid; msg->msg = doc.xml(); msg->type = PRESENCE_COMMON;//none seq.push_back(msg); try{ MCE_INFO("NotifyNicknameErrorTask::handle --> CALL MucDeliver.deliver seq.size = " << seq.size()); MucDeliverAdapter::instance().deliver(seq); } catch(Ice::Exception& e){ MCE_WARN("NotifyNicknameErrorTask::handle --> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e); } catch(std::exception& e){ MCE_WARN("NotifyNicknameErrorTask::handle --> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e.what()); } }
void InviteIMUsersTask::handle(){ MCE_DEBUG("InviteIMUsersTask::handle --> BEGIN"); string roomstr = mucRoomIdToString(roomid); if(roomstr.empty()){ return; } MessageSeq seq; JidSeq::const_iterator jit = imusers.begin(); for(; jit != imusers.end(); ++jit){ MCE_DEBUG("InviteIMUsersTask::handle--> invite imusers invite_jid is = " << jidToString((*jit))); xml_document doc; xml_node messageNode = doc.append_child(); messageNode.set_name("message"); messageNode.append_attribute("from").set_value(roomstr.c_str()); messageNode.append_attribute("to").set_value(jidToString((*jit)).c_str()); xml_node xNode = messageNode.append_child(); xNode.set_name("x"); xNode.append_attribute("xmlns").set_value("http://jabber.org/protocol/muc#user"); xml_node inviteNode = xNode.append_child(); inviteNode.set_name("invite"); inviteNode.append_attribute("from").set_value("*****@*****.**"); //TODO here from is who MessagePtr msg = new Message(); msg->from = (*jit); msg->to = (*jit); msg->msg = doc.xml(); msg->type = MESSAGE;//none msg->msgKey = -1; seq.push_back(msg); } try{ MCE_INFO("InviteIMUsersTask::handle--> CALL MucDeliver.deliver seq.size = " << seq.size()); MucDeliverAdapter::instance().deliver(seq); } catch(Ice::Exception& e){ MCE_WARN("InviteIMUsersTask::handle--> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e); } catch(std::exception& e){ MCE_WARN("InviteIMUsersTask::handle--> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e.what()); } }
void DeliverManagerI::deliver(const MessageSeq& seq, const Ice::Current& current) { //TaskManager::instance().execute(new MessageTask(seq)); //MCE_DEBUG("DeliverManagerI::deliver --> seq.size="<<seq.size()); if (!seq.empty()) { if (seq.at(0)->to->userId == 128487631 || seq.at(0)->to->userId == 200865373) { //MCE_DEBUG("DeliverManagerI::deliver --> msg:"<< seq.at(0)->msg); } } for(MessageSeq::const_iterator it = seq.begin(); it != seq.end(); ++it){ MessagePtr m = (*it); if(m->type == MESSAGE){ MCE_INFO("DeliverManagerI::deliver message-->from=" << jidToString(m->from) << " to=" << jidToString(m->to)); } if(m->type == NOTIFY2_MESSAGE){ MCE_INFO("DeliverManagerI::deliver notify2-->from=" << jidToString(m->from) << " to=" << jidToString(m->to)); } } for (size_t i = 0; i < seq.size(); ++i) { PipePool::instance().push("TalkRight", abs(seq.at(i)->to->userId)%10, seq.at(i)); } }
void PostPipe::handle(const ObjectSeq& seq) { //MCE_INFO("PostPipe::handle --> thread_id = " << pthread_self()); if (seq.empty()) { return; } else { //MCE_DEBUG("PostPipe::handle --> objectseq size = " <<seq.size()); } //MCE_DEBUG("PostPipe::handle --> size:" << seq.size()); MessageSeq mseq; for (size_t i = 0; i < seq.size(); ++i) { mseq.push_back(MessagePtr::dynamicCast(seq.at(i))); } try { if((mseq.at(0)->to->endpoint[0] == 'T') || (mseq.at(0)->to->endpoint[0] == 'W') || (mseq.at(0)->to->endpoint[0] == 'P')){ DeliverManagerI::instance().getProxyServerOneway(mseq.at(0)->to)->deliver(mseq); } } catch(Ice::Exception& e) { MCE_WARN("PostPipe::handle -->ProxyAdapter::delivere-->"<<e<<" to endpoint:"<< mseq.at(0)->to); } }
void RoomPresenceTask::_modifyPresence(OccupantPtr occupant, RoomJidPtr newRoomJid) { return; MCE_DEBUG("RoomPresenceTask::_changeNick --> from " << roomJidToString(occupant->rJid) << " to " << roomJidToString(newRoomJid)); bool flag = false; MCE_DEBUG("RoomPresenceTask::_changeNick --> invoke Occupants changeNick"); try{ flag = OccupantsAdapter::instance().changeNick(newRoomJid, _jid); } catch(Ice::Exception& e){ MCE_WARN("RoomPresenceTask::_modifyPresence-->OccupantsAdapter::changeNick-->" << e); } MCE_DEBUG("RoomPresenceTask::_changeNick --> invoke Occupants changeNick" << flag); MessageSeq msgs; if (false == flag) { ostringstream os; os << "<presence from='"<<roomIdToString(newRoomJid->rid)<<"' to='" <<jidToString(_jid) <<"' type='error' id='" << _doc->child("presence").attribute("id").value() << "'>" << "<x xmlns='http://jabber.org/protocol/muc'/>" << "<error type='cancel'>" << "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" << "</error>" <<"</presence>"; MessagePtr msg = new Message(); msg->from = _jid; msg->to = _jid; msg->msg = os.str(); msg->type = PRESENCE_COMMON; MCE_DEBUG(" " << os.str()); msgs.push_back(msg); MCE_DEBUG("RoomPresenceTask::handle --> deliver msgs " << msgs.size()); try{ MucDeliverAdapter::instance().deliver(msgs); }catch(Ice::Exception& e){ MCE_WARN("RoomPresenceTask::handle-->MucDeliverAdapter::deliver-->err" << e); } return; } MCE_DEBUG("RoomPresenceTask::_changeNick --> invoke Occupants getOccupants"); OccupantSeq oseq; try{ oseq = OccupantsAdapter::instance().getOccupants(newRoomJid->rid); }catch(Ice::Exception& e){ MCE_WARN("RoomPresenceTask::handle-->OccupantsAdapter::getOccupants-->" << e); } MCE_DEBUG("RoomPresenceTask::_changeNick --> invoke Occupants getOccupants " << oseq.size()); // remove all x node xml_node presenceNode = _doc->child("presence"); xml_node removeNode; while (removeNode = presenceNode.child("x"), removeNode) { presenceNode.remove_child(removeNode); } //------------------ for (size_t i = 0; i < oseq.size(); ++i) { //for(size_t j = 0; j < oseq.at(i)->jids.size(); ++j){ ostringstream os; os << "<presence from='"<<roomJidToString(occupant->rJid)<<"' to='" <<jidToString(oseq.at(i)->fJid)<<"' type='unavailable'>" << "<x xmlns='http://jabber.org/protocol/muc#user'>" << "<item affiliation='"<<_affiliationStr(occupant->aType) << "' nick='" << newRoomJid->nick << "' role='" << _roleStr(occupant->role); //if (Moderator == oseq.at(i)->role) { os << "' jid='" << jidToString(_jid); //} os << "'/>" << "<status code='303'/>" << "</x>" << "</presence>"; MessagePtr msg = new Message(); msg->from = _jid; msg->to = oseq.at(i)->fJid; msg->msg = os.str(); msg->type = PRESENCE_COMMON; MCE_DEBUG(" " << os.str()); msgs.push_back(msg); presenceNode.append_attribute("from").set_value(roomJidToString(newRoomJid).c_str()); presenceNode.append_attribute("to").set_value(jidToString(oseq.at(i)->fJid).c_str()); if (i == 0) { xml_node xNode = presenceNode.append_child(); xNode.set_name("x"); xNode.append_attribute("xmlns").set_value("http://jabber.org/protocol/muc#user"); xml_node itemNode = xNode.append_child(); itemNode.set_name("item"); itemNode.append_attribute("affiliation").set_value(_affiliationStr(occupant->aType).c_str()); itemNode.append_attribute("role").set_value(_roleStr(occupant->role).c_str()); itemNode.append_attribute("jid").set_value(jidToString(_jid).c_str()); } msg = new Message(); msg->from = _jid; msg->to = oseq.at(i)->fJid; msg->msg = _doc->xml();// os2.str(); msg->type = PRESENCE_COMMON; // MCE_DEBUG(" " << os2.str()); msgs.push_back(msg); //} } MCE_DEBUG("RoomPresenceTask::handle --> deliver msgs " << msgs.size()); try{ MucDeliverAdapter::instance().deliver(msgs); }catch(Ice::Exception& e){ MCE_WARN("RoomPresenceTask::handle-->MucDeliverAdapter::deliver-->err" << e); } }
bool run_sorting_test(const DomainParticipant_var& dp, const MessageTypeSupport_var& ts, const Publisher_var& pub, const Subscriber_var& sub) { DataWriter_var dw; DataReader_var dr; test_setup(dp, ts, pub, sub, "MyTopic", dw, dr); ReturnCode_t ret = RETCODE_OK; MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw); Message sample; sample.key = 0; sample.name = "data_X"; sample.nest.value = B; for (int i(0); i < 20; ++i, ++sample.key) { //replace the 'X' with a random letter sample.name.inout()[5] = static_cast<char>((rand() % 26) + 'A'); ret = mdw->write(sample, HANDLE_NIL); if (ret != RETCODE_OK) return false; if (!(i % 4)) { //once in a while write more than 1 sample per instance Message sample2(sample); sample2.nest.value = A; sample2.name.inout()[5] = static_cast<char>((rand() % 26) + 'A'); ret = mdw->write(sample2, HANDLE_NIL); if (ret != RETCODE_OK) return false; sample2.nest.value = C; ret = mdw->write(sample2, HANDLE_NIL); if (ret != RETCODE_OK) return false; } } DDS::StringSeq empty_query_params; ReadCondition_var dr_qc = dr->create_querycondition(ANY_SAMPLE_STATE, ANY_VIEW_STATE, ALIVE_INSTANCE_STATE, "ORDER BY name, nest.value", empty_query_params); WaitSet_var ws = new WaitSet; ws->attach_condition(dr_qc); MessageDataReader_var mdr = MessageDataReader::_narrow(dr); Duration_t five_seconds = {5, 0}; bool passed = true, done = false; while (!done) { ConditionSeq active; ret = ws->wait(active, five_seconds); if (ret == RETCODE_TIMEOUT) { cout << "timeout "; done = true; //continue to try and read } else if (ret != RETCODE_OK) { passed = false; break; } cout << "wait returned" << endl; MessageSeq data; SampleInfoSeq info; ret = mdr->take_w_condition(data, info, LENGTH_UNLIMITED, dr_qc); if (ret == RETCODE_NO_DATA) { // fall-through } else if (ret != RETCODE_OK) { cout << "ERROR: take_w_condition returned " << ret << endl; passed = false; done = true; } else { char largest = 0; for (CORBA::ULong i(0); i < data.length(); ++i) { cout << "Info:\tinstance_handle = " << info[i].instance_handle << "\tsample_rank = " << info[i].sample_rank << '\n'; if (info[i].valid_data) { cout << "Data:\tkey = " << data[i].key << " \tname = " << data[i].name << "\tnest.value = " << data[i].nest.value << '\n'; if (data[i].name[5] >= largest) { largest = data[i].name[5]; } else { cout << "ERROR: data is not sorted for key: " << data[i].key << endl; passed = false; } } cout << endl; } } } MessageSeq data; SampleInfoSeq info; ret = mdr->take_w_condition(data, info, LENGTH_UNLIMITED, dr_qc); if (ret != RETCODE_NO_DATA) { cout << "WARNING: there is still data in the reader\n"; } ws->detach_condition(dr_qc); dr->delete_readcondition(dr_qc); return passed; }
void deliverNotifyWebpagerTask::handle(){ TimeStatN ts; MessageSeq msgs; bool is_feed_actor = false; Ice::Long nid = 0; if(_content.find("ugc_content") != string::npos){ is_feed_actor = true; } size_t npos = _content.find("\"nid\":\""); if(npos != string::npos){ size_t ipos = _content.find_first_of("\"", npos + 7); if(ipos != string::npos){ string snid = _content.substr(npos+7, ipos - (npos+7)); try{ nid = boost::lexical_cast<Ice::Long>(snid); }catch(...){ MCE_WARN("PowerTransfer::deliverNotifyWebpager--> boost cast nid error nid = " << nid); } } } JidSeqMap jmap; try{ jmap = TalkFunStateAdapter::instance().getUsersJids(_toids,2); } catch(Ice::Exception& e) { MCE_WARN("PowerTransfer::deliverNotifyWebpager-->TalkFunStateAdapter::getUserJids-->" << e); PowerTransferI::instance().UpCount(200000,0); return ; } for(JidSeqMap::iterator jit = jmap.begin();jit != jmap.end();++jit) { JidSeq& jseq = (jit->second); for(int j=0; j<(int)jseq.size(); j++){ if(jseq.at(j)->endpoint[0] == 'W'){ MessagePtr msg = new Message(); JidPtr jfrom = new Jid(); jfrom->userId = 0; jfrom->endpoint = "feed.talk.xiaonei.com"; jfrom->index = -1; ostringstream os; os << "<message type='common' from='" << jidToString(jfrom) << "' to='" << jidToString(jseq.at(j)) << "'>" << "</message>"; xml_document doc; if(!doc.load(os.str().c_str())){ continue; } xml_node body = doc.child("message").append_child(); body.set_name("body"); body.append_child(node_pcdata).set_value(_content.c_str()); msg->from = jfrom; msg->to = jseq.at(j); msg->type = NOTIFY2_MESSAGE; msg->msg = doc.xml(); msgs.push_back(msg); } } } if(msgs.empty()){ PowerTransferI::instance().UpCount(200000,0); return; } ostringstream os; for(IntSeq::iterator idit = _toids.begin(); idit != _toids.end(); ++idit){ os << (*idit) << " "; } try{ MCE_INFO("PowerTransfer::deliverNotifyWebpager--> is_feed_actor = " << is_feed_actor << " nid : " << nid << " toids.size :" << _toids.size() << " toids : " << os.str()); TalkDeliverAdapter::instance().deliver(msgs); }catch(Ice::Exception& e){ MCE_WARN("PowerTransfer::deliverNotifyWebpager-->TalkDeliverAdapter::deliver--> " << e); PowerTransferI::instance().UpCount(200000,0); return ; } FunStatManager::instance().Stat("PowerTransfer::deliverNotifyWebpager", ts.getTime(), false); PowerTransferI::instance().UpCount(200000,1,msgs.size()); }
void deliverNotifyPhoneTask::handle(){ TimeStatN ts; xml_document doc; if(!doc.load(_content.c_str())){ MCE_WARN("PowerTransfer::deliverNotifyPhone --> xml err, " <<_content); PowerTransferI::instance().UpCount(300000,0); return; } Ice::Long nid = 0; size_t npos = _content.find("\"nid\":\""); if(npos != string::npos){ size_t ipos = _content.find_first_of("\"", npos + 7); if(ipos != string::npos){ string snid = _content.substr(npos+7, ipos - (npos+7)); try{ nid = boost::lexical_cast<Ice::Long>(snid); }catch(...){ MCE_WARN("PowerTransfer::deliverNotifyClient--> boost cast nid error nid = " << nid); } } } MessageSeq msgs; JidSeqMap jmap; try{ jmap = TalkFunStateAdapter::instance().getUsersJids(_toids,16); }catch(Ice::Exception& e){ MCE_WARN("PowerTransfer::deliverNotifyPhone-->TalkFunStateAdapter::getUserJids--> " << e); PowerTransferI::instance().UpCount(300000,0); return ; } for(JidSeqMap::iterator jit = jmap.begin();jit != jmap.end();++jit) { JidSeq& jseq = (jit->second); for(int j=0; j<(int)jseq.size(); j++){ if(jseq.at(j)->endpoint[0] == 'P'){ MessagePtr msg = new Message(); JidPtr jfrom = new Jid(); jfrom->userId = 0; jfrom->endpoint = "feed.talk.xiaonei.com"; jfrom->index = -1; doc.child("message").append_attribute("to") = jidToString(jseq.at(j)).c_str(); msg->from = jfrom; msg->to = jseq.at(j); msg->type = PHONE_NOTIFY; msg->msg = doc.xml(); msgs.push_back(msg); } } } if(msgs.empty()){ PowerTransferI::instance().UpCount(300000,0); return; } try{ TalkDeliverAdapter::instance().deliver(msgs); }catch(Ice::Exception& e){ MCE_WARN("PowerTransfer::deliverNotifyPhone-->TalkDeliverAdapter::deliver-->" << e); PowerTransferI::instance().UpCount(300000,0); } FunStatManager::instance().Stat("PowerTransfer::deliverNotifyPhone", ts.getTime(), false); PowerTransferI::instance().UpCount(300000,1,msgs.size()); }
void MucDeliverManagerI::deliver(const MessageSeq& seq, const Ice::Current& current) { MCE_DEBUG(__FUNCTION__ << " --> seq.size="<<seq.size()); for (size_t i = 0; i < seq.size(); ++i) { PipePool::instance().push(seq.at(i)->to->endpoint, 0, seq.at(i)); } }
void FeedReplyPipe::handle(){ FeedReplyToMessagConverter converter; TimeStat ts; float totalwait = 0.0; FeedReplyWithTargetSeq objs; WTransitManagerI::instance().SwapFeedReplySeq(objs); if(objs.empty()){ return; } //for(size_t x = 0; x < objs.size(); ++x){ //FeedReplyWithTargetPtr reply = FeedReplyWithTargetPtr::dynamicCast(objs.at(x)); //FeedReplyWithTargetPtr reply = objs.at(x); //totalwait += reply->latets.getTime(); //} MessageSeq msgs; for (size_t x = 0; x < objs.size(); ++x) { //FeedReplyWithTargetPtr reply = FeedReplyWithTargetPtr::dynamicCast(objs.at(x)); FeedReplyWithTargetPtr reply = objs.at(x); converter.setData(reply->replyData); if(reply->replyData->actor == 257876975 || reply->replyData->actor == 238489851){ //MCE_DEBUG(reply->replyData->actor << " " << reply->replyData->xml); } // MyUtil::IntSeq target = reply->getTarget(); MCE_DEBUG(" FeedReplyPipe::handle --> feed->target.size = "<< reply->target.size()); JidSeqMap jmap; try { //jmap = OnlineCenterAdapter::instance().getUsersJids(reply->target); jmap = TalkFunStateAdapter::instance().getUsersJids(reply->target, 22); } catch (Ice::Exception& e) { MCE_WARN("FeedReplyPipe::handle-->TalkFunStateAdapter::getUsersJids-->" << reply->replyData->actor << " " << reply->target.size() << " "<<e); } catch (std::exception& e) { MCE_WARN("FeedReplyPipe::handle --> online center err: " << reply->target.size() << " "<<e.what()); } if (jmap.empty()) { MCE_DEBUG("FeedReplyPipe::handle --> no friend online "); continue; } MCE_DEBUG("FeedReplyPipe::handle --> jmap.size = "<<jmap.size()); for (size_t i = 0; i < reply->target.size(); ++i) { JidSeqMap::const_iterator it = jmap.find(reply->target.at(i)); if (it == jmap.end()) { MCE_DEBUG("FeedReplyPipe::handle --> can not find jmap feed->target(i)="<<reply->target.at(i)); continue; } for (size_t j = 0; j < it->second.size(); ++j) { MessagePtr msg; if ( (!it->second.at(j)->endpoint.empty()) ){ if( it->second.at(j)->endpoint[0] == 'T' ){ //MCE_DEBUG("FeedReplyPipe::handle-->SEND REPLY source=" << reply->replyData->source << " actor=" << reply->replyData->actor << " replyid=" << reply->replyData->replyId << " to userid=" << it->second.at(j)->userId); msg = converter.getToTalkMessage(it->second.at(j)); } if(msg){ msgs.push_back(msg); } } } } } if (!msgs.empty()) { try{ TalkDeliverAdapter::instance().deliver(msgs); }catch(Ice::Exception& e){ MCE_WARN("FeedReplyPipe::handle --> TalkDeliverAdapter::deliver--> error : " << e); } } MONITOR("SignForTimeuse::WTransit::FeedReplyPipe::handle-->" << ts.getTime() << "|" << "count" << objs.size()); }
void IqHandlerI::removeBuddyNotify(Ice::Int from, Ice::Int to, const Ice::Current&) { StatFunc statF("IqHandlerI::removeBuddyNotify"); //JidSeq toJids = PresenceAdapter::instance().getOnlineUserJidSeq(to); //JidSeq fromJids = PresenceAdapter::instance().getOnlineUserJidSeq(from); JidSeq toJids; JidSeq fromJids; try{ //toJids = OnlineCenterAdapter::instance().getUserJids(to, 4); toJids = TalkFunStateAdapter::instance().getUserJids(to, 4); }catch(Ice::Exception& e){ MCE_WARN("IqHandlerI::removeBuddyNotify-->OnlineCenterAdapter::getUserJids-->err" << e); } try{ //fromJids = OnlineCenterAdapter::instance().getUserJids(from, 4); fromJids = TalkFunStateAdapter::instance().getUserJids(from, 4); }catch(Ice::Exception& e){ MCE_WARN("IqHandlerI::removeBuddyNotify-->OnlineCenterAdapter::getUserJids-->err" << e); } if(toJids.empty() && fromJids.empty()){ return; } MessageSeq seq; for (size_t i = 0; i < fromJids.size(); ++i) { ostringstream msg; msg<<"<iq type='set' id='"<<time(NULL)<<"'>" <<"<query xmlns='jabber:iq:roster'>" <<"<item jid='"<<to <<"@talk.xiaonei.com' subscription='remove' />" <<"</query></iq>"; // IqHandlerI::instance().getProxyServerOneway(fromJids.at(i)->endpoint)->deliver(fromJids.at(i), msg.str()); MessagePtr mPtr = new Message(); mPtr->from = new Jid(); mPtr->from->userId = -1; mPtr->to = fromJids.at(i); mPtr->msg = msg.str(); mPtr->type = IQ_SET; seq.push_back(mPtr); } for (size_t i = 0; i < toJids.size(); ++i) { JidPtr fromJid = new Jid(); fromJid->userId = from; fromJid->endpoint = "talk.xiaonei.com"; fromJid->index = -1; ostringstream msg; msg<<"<presence from='"<<from<<"@talk.xiaonei.com' to='" <<jidToString(toJids.at(i))<<"' type='unsubscribed' id='" <<time(NULL) <<"'/>"; MessagePtr mPtr = new Message(); mPtr -> from = fromJid; mPtr -> to = toJids.at(i); mPtr -> msg = msg.str(); mPtr -> type = PRESENCE_COMMON; seq.push_back(mPtr); msg.str(""); msg<<"<iq type='set' id='"<<time(NULL)<<"'>" <<"<query xmlns='jabber:iq:roster'>" <<"<item jid='"<<from <<"@talk.xiaonei.com' subscription='remove' />" <<"</query></iq>"; // IqHandlerI::instance().getProxyServerOneway(toJids.at(i)->endpoint)->deliver(toJids.at(i), msg.str()); mPtr = new Message(); mPtr -> from = fromJid; mPtr -> to = toJids.at(i); mPtr -> msg = msg.str(); mPtr -> type = IQ_SET; seq.push_back(mPtr); } try{ TalkDeliverAdapter::instance().deliver(seq); }catch(Ice::Exception& e){ MCE_WARN("IqHandlerI::removeBuddyNotify-->TalkDeliverAdapter::deliver-->err" << e); } }
void IqHandlerI::changeBuddyGroupNotify(const BuddyItemPtr& bi, const Ice::Current&) { if(!bi){ return; } MCE_DEBUG("IqHandlerI::changeBuddyGroupNotify --> host:"<<bi->host); MyUtil::IntSeq buddys; for (map<int,MyUtil::StrSeq>::iterator it = bi->items.begin(); it != bi->items.end(); ++it) { buddys.push_back(it->first); } TalkUserMap buddyInfo; try{ buddyInfo = TalkCacheClient::instance().GetUserBySeqWithLoad(bi->host, buddys); if(buddyInfo.size() != buddys.size()){ MCE_INFO("IqHandlerI::changeBuddyGroupNotify --> may be warn get from TalkCacheClient size is not equal actor = " << bi->host << " ids.size = " << buddys.size() << " map.size = " << buddyInfo.size()); }else{ MCE_INFO("IqHandlerI::changeBuddyGroupNotify --> success get from TalkCacheClient size is equal actor = " << bi->host << " ids.size = " << buddys.size() << " map.size = " << buddyInfo.size()); } }catch(Ice::Exception& e){ MCE_WARN("IqHandlerI::changeBuddyGroupNotify --> TalkCacheClient err, " << e); } MessageSeq mSeq; JidSeq jids; try{ //jids = OnlineCenterAdapter::instance().getUserJids(bi->host, 4); jids = TalkFunStateAdapter::instance().getUserJids(bi->host, 4); }catch(Ice::Exception& e){ MCE_WARN("IqHandlerI::changeBuddyGroupNotify-->OnlineCenterAdapter::getUserJids-->" << e); } for (size_t j = 0; j < jids.size(); ++j) { for (map<int,MyUtil::StrSeq>::iterator it = bi->items.begin(); it != bi->items.end(); ++it) { xml_document doc; xml_node iqNode = doc.append_child(); iqNode.set_name("iq"); iqNode.append_attribute("type") = "set"; iqNode.append_attribute("id") = (int)time(NULL); iqNode.append_attribute("to") = jidToString(jids.at(j)).c_str(); xml_node queryNode = iqNode.append_child(); queryNode.set_name("query"); queryNode.append_attribute("xmlns") = "jabber:iq:roster"; xml_node itemNode = queryNode.append_child(); itemNode.set_name("item"); ostringstream jos; jos << it->first << "@talk.xiaonei.com"; itemNode.append_attribute("jid") = jos.str().c_str();//jid.c_str(); TalkUserMap::iterator oit = buddyInfo.find(it->first); if (oit != buddyInfo.end()) { itemNode.append_attribute("name") = oit->second->name.c_str(); } else { itemNode.append_attribute("name") = boost::lexical_cast<string>(it->first).c_str(); } //itemNode.append_attribute("name") = name.c_str(); itemNode.append_attribute("subscription") = "both"; for (size_t k = 0; k < it->second.size(); ++k) { xml_node groupNode = itemNode.append_child(); groupNode.set_name("group"); groupNode.append_child(node_pcdata).set_value(it->second.at(k).c_str()); } MessagePtr mPtr = new Message(); //mPtr->from = new Jid(); mPtr->from = jids.at(j); mPtr->to = jids.at(j); mPtr->type = IQ_SET; mPtr->msg = doc.xml(); mSeq.push_back(mPtr); MCE_DEBUG("IqHandlerI::changeBuddyGroupNotify --> xml:"<<doc.xml()); } } try{ TalkDeliverAdapter::instance().deliver(mSeq); }catch(Ice::Exception& e){ MCE_WARN("IqHandlerI::changeBuddyGroupNotify-->TalkDeliverAdapter::deliver-->err" << e); } }
void MucDeliverAdapter::deliver(const MessageSeq& seq) { if(seq.empty()) { return; } getManagerOneway(seq.at(0)->to->userId)->deliver(seq); }
void WTalkProxyManagerI::deliver(const MessageSeq& msgs, const Ice::Current&) { MCE_DEBUG("WTalkProxyManagerI::deliver --> msgs.size:"<<msgs.size()); for (size_t i = 0; i < msgs.size(); ++i) { if ((msgs.at(i)->type == MESSAGE) || (msgs.at(i)->type == OFFLINE_MESSAGE) || (msgs.at(i)->type == PHONE_NOTIFY)) { //MCE_DEBUG("msg:"<<msgs.at(i)->msg<<" toid:"<<msgs.at(i)->to->userId); JidSeq jseq = _pools[msgs.at(i)->to->userId % POOLSIZE].getAccessJid(msgs.at(i)->to->userId); //MCE_DEBUG("jid size:"<<jseq.size()<<" toid:"<<msgs.at(i)->to->userId); string body; xml_document doc; try{ msgs.at(i)->msg = MsgFilterAdapter::instance().wapFilter(msgs.at(i)->msg); }catch(Ice::Exception& e){ MCE_WARN("WTalkProxyManagerI::deliver --> invoke antispam err, " << e); } if(doc.load(msgs.at(i)->msg.c_str())){ body = doc.child("message").child("body").first_child().value(); } MCE_INFO("WTalkProxyManagerI::deliver --> from:" << jidToString(msgs.at(i)->from) << " to:" << jidToString(msgs.at(i)->to) << " msg:" << body); _pools[msgs.at(i)->to->userId % POOLSIZE].storeMsg(msgs.at(i)); if (jseq.empty()) { //TalkLogicAdapter::instance().unbind(msgs.at(i)->to); MCE_WARN("WTalkProxyManagerI::deliver --> access jid size = 0"); return; } for (size_t j = 0; j < jseq.size(); ++j) { MessagePtr msg = new Message(); msg->from = msgs.at(i)->from; msg->to = jseq.at(j); msg->type = msgs.at(i)-> type; msg->msg = msgs.at(i)->msg; msg->msgKey = msgs.at(i)->msgKey; MCE_DEBUG("call pipepool toid:"<<msg->to->userId); PipePool::instance().push(jseq.at(j)->endpoint, 0, msg); } } } }
void NotifyGroupChatTask::handle(){ string activeuser_identity_str = mucUserIdentityToString(activeuser->identity); string activeuser_jid_str = jidToString(activeuser->jid); int gid = GetIdFromMucRoomId(activeuser->identity->roomid); if(activeuser_identity_str.empty() || activeuser_jid_str.empty()){ return; } if('T' == activeuser->jid->endpoint[0] && PERMANENT == activeuser->identity->roomid->domain){ return; } bool load_group_name = false; string minigroup_name = ""; xml_document msgdoc; string msg = ""; string attachment = ""; MCE_DEBUG("NotifyGroupChatTask::handle --> messagenode," << msgNode); if(msgdoc.load(msgNode.c_str())){ xml_node msn = msgdoc.child("message"); msg = msn.child("body").first_child().value(); attachment = msn.child("attachment").first_child().xml(); } else { msg = msgNode; } MCE_DEBUG("NotifyGroupChatTask::handle --> msg," << msg << ",attachment," << attachment); MCE_DEBUG("NotifyGroupChatTask::handle"); MessageSeq seq; for(JidSeq::iterator it = presenceUsers.begin(); it != presenceUsers.end(); ++it){ xml_document doc; xml_node messageNode = doc.append_child(); messageNode.set_name("message"); messageNode.append_attribute("from") = activeuser_identity_str.c_str(); messageNode.append_attribute("to") = ""; messageNode.append_attribute("type").set_value("groupchat"); xml_node bodyNode = messageNode.append_child(); bodyNode.set_name("body"); bodyNode.append_child(node_pcdata).set_value(msg.c_str()); xml_node attachNode = messageNode.append_child(); attachNode.set_name("attachment"); attachNode.append_child(node_pcdata).set_value(attachment.c_str()); //attachNode.set_value(attachment.c_str()); MCE_DEBUG("NotifyGroupChatTask::handle --> msgNode," << messageNode.xml()); if('W' == (*it)->endpoint[0]){ if(!load_group_name){ GroupNamePtr gn = ServiceI::instance().locateObject<GroupNamePtr>(GN,gid); if(gn){ minigroup_name = gn->groupname; } load_group_name = true; } xml_node roomNameNode = messageNode.append_child(); roomNameNode.set_name("roomname"); MCE_DEBUG("NotifyGroupChatTask::handle --> minigroup_name = " << minigroup_name); roomNameNode.append_child(node_pcdata).set_value(minigroup_name.c_str()); } MessagePtr message = new Message(); message->from = activeuser->jid; message->to = (*it); messageNode.attribute("to").set_value(jidToString((*it)).c_str()); message->msg = doc.xml(); MCE_DEBUG("NotifyGroupChatTask::handle -->doc = " << doc.xml()); MCE_DEBUG("NotifyGroupChatTask::handle -->doc = " << doc.child("message").child("roomname").first_child().value()); message->type = MUC_MESSAGE;//none message->msgKey = -1; seq.push_back(message); } if(PERMANENT == activeuser->identity->roomid->domain){ try { // MucTalkRecordAdapter::instance().RecordTalkMsg(activeuser->jid->userId, gid, msg); MessageVO ugcrec; ugcrec.senderId = activeuser->jid->userId; ugcrec.toId = -1; // 单聊需要 ugcrec.sessionId = gid; // 群聊 ugcrec.content = msg; ugcrec.sourceType = MUC_MESSAGE; ugcrec.attachmentKey = 0; ugcrec.attachmentType = 0; ugcrec.attachmentInfo = attachment; ugcrec.smallImageUrl = ""; ugcrec.bigImageUrl = ""; UgcMessageRecordAdapter::instance().saveMessge(ugcrec); MCE_DEBUG("NotifyGroupChatTask::handle -->" " CALL UgcMessageRecordAdapter.saveMessge sid," << gid << ",msg," << msg << ",fid," << activeuser->jid->userId << ",attachment," << attachment); } catch (Ice::Exception &e) { MCE_WARN("NotifyGroupChatTask::handle -->" " call UgcMessageRecordAdapter.saveMessge ERR line:"<<__LINE__<<" err:"<<e); } catch (std::exception &e) { MCE_WARN("NotifyGroupChatTask::handle-->" " call UgcMessageRecordAdapter.saveMessge ERR line:"<<__LINE__<<" err:"<<e.what()); } /* bool spamok = false; try{ TimeStat ts_spam; vector<string> v; v.push_back(msg); CheckResultMore spamobj = OzeinFilterClient::instance().checkerAndFilter(activeuser->jid->userId, -1, 109, v, ""); if(!spamobj.getFlag()){ spamok = true; } MCE_INFO("interface OzeinFilter usetime : " << ts_spam.getTime() << " spamflag : " << spamobj.getFlag()); } catch(Ice::Exception& e){ MCE_WARN("NotifyGroupChatTask::handle --> call OzeinFilterClient.checkerAndFilter ERR line:"<<__LINE__<<" err:"<<e); } catch(std::exception& e){ MCE_WARN("NotifyGroupChatTask::handle --> call OzeinFilterClient.checkerAndFilter ERR line:"<<__LINE__<<" err:"<<e.what()); } if(spamok){ try { // MucTalkRecordAdapter::instance().RecordTalkMsg(activeuser->jid->userId, gid, msg); MessageVO ugcrec; ugcrec.senderId = activeuser->jid->userId; //ugcrec.toId = ; // 单聊需要 ugcrec.sessionId = gid; // 群聊 ugcrec.content = msg; ugcrec.sourceType = MUC_MESSAGE; ugcrec.attachmentKey = 0; ugcrec.attachmentType = 0; ugcrec.attachmentInfo = attachment; ugcrec.smallImageUrl = ""; ugcrec.bigImageUrl = ""; UgcMessageRecordAdapter::instance().saveMessge(ugcrec); MCE_DEBUG("NotifyGroupChatTask::handle -->" " CALL UgcMessageRecordAdapter.saveMessge sid," << gid << ",msg," << msg << ",fid," << activeuser->jid->userId << ",attachment," << attachment); } catch(Ice::Exception &e) { MCE_WARN("NotifyGroupChatTask::handle -->" " call UgcMessageRecordAdapter.saveMessge ERR line:"<<__LINE__<<" err:"<<e); } catch(std::exception &e) { MCE_WARN("NotifyGroupChatTask::handle-->" " call UgcMessageRecordAdapter.saveMessge ERR line:"<<__LINE__<<" err:"<<e.what()); } } */ } try{ MucDeliverAdapter::instance().deliver(seq); } catch(Ice::Exception& e){ MCE_WARN("NotifyGroupChatTask::handle --> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e); } catch(std::exception& e){ MCE_WARN("NotifyGroupChatTask::handle--> call MucDeliver.deliver ERR line:"<<__LINE__<<" err:"<<e.what()); } }
void ManagerI::deliver(const MessageSeq& mseq, const Ice::Current&) { //MCE_INFO("ManagerI::deliver --> deliver a message to jsclient size=" << mseq.size()); for (size_t i = 0; i < mseq.size(); ++i) { ClientPoolManager::instance().getClientPool(mseq.at(i)->to->index).pushMsg(mseq.at(i)->to->index, mseq.at(i)); } }