//"#COMMAND#type=fileRequest,packId=xxx" void CMsgSessionManager::SendCmd(tstring strDestAccount, ECmdType eType, tstring& strParas) { //check if session exist; MessageSession* pDestSesion = NULL; MapAccount2Sessions::iterator itFind = m_mapAccount2Sessions.find(strDestAccount); if (itFind != m_mapAccount2Sessions.end()) { pDestSesion = itFind->second; } if (NULL == pDestSesion) { JID jid(strDestAccount); pDestSesion = new MessageSession(j, jid); if (NULL != pDestSesion) { pDestSesion->registerMessageHandler(this); m_mapAccount2Sessions.insert(make_pair(strDestAccount, pDestSesion)); } } if (NULL != pDestSesion) { pDestSesion->send(strParas.c_str()); } }
void CMsgSessionManager::SendMsg(tstring strDestAccount, tstring& strMsg) { //check if session exist; MessageSession* pDestSesion = NULL; MapAccount2Sessions::iterator itFind = m_mapAccount2Sessions.find(strDestAccount); if (itFind != m_mapAccount2Sessions.end()) { pDestSesion = itFind->second; } if (NULL == pDestSesion) { JID jid(strDestAccount); pDestSesion = new MessageSession(j, jid); if (NULL != pDestSesion) { pDestSesion->registerMessageHandler(this); m_mapAccount2Sessions.insert(make_pair(strDestAccount, pDestSesion)); } } if (NULL != pDestSesion) { MapMsgEventFilters::iterator itMsgFiler = m_mapDest2MsgEventFilters.find(strDestAccount); if (itMsgFiler != m_mapDest2MsgEventFilters.end()) { MessageEventFilter*pFilter = itMsgFiler->second; if (NULL != pFilter) { pFilter->raiseMessageEvent(MessageEventComposing); } } MapChatStateFilters::iterator itStatefilter = m_mapDest2ChatStateFilters.find(strDestAccount); if (itStatefilter != m_mapDest2ChatStateFilters.end()) { ChatStateFilter* pFilter = itStatefilter->second; if (NULL != pFilter) { pFilter->setChatState(ChatStateComposing); } } tstring strOut; CChineseCode::GB2312ToUTF_8(strOut, (char*)strMsg.c_str(), strMsg.size()); pDestSesion->send(/*strMsg*/strOut, ""); } }
//following function is used for sending async-event-notification to subscribed buddy bool ADXmppProxy::SendMessageToBuddy(std::string address, const std::string & body, const std::string & subject) { //for testing async-sync event //XmppProxy.SendMessageToBuddy(cmdArg,"hellloooo","test-subjext"); //return RPC_SRV_RESULT_SUCCESS; if(iConnect==false) { if(DebugLog) cout<<"ADXmppProxy::SendMessageToBuddy:client disconnected, cannot send message to buddy!!!"<<endl; return false; } //check if address is in my buddy-list(doesnt make sense to send message to non-buddy - it will not be delivered) vector<std::string>::iterator it; for(it = BuddyList.begin(); it != BuddyList.end(); it++) { string str = *it; if(address==str) { Sessions::iterator it = mySessions.find(address); if (it != mySessions.end()) //check if session already exists in my list { it->second.m_messageEventFilter->raiseMessageEvent( MessageEventDisplayed ); it->second.m_messageEventFilter->raiseMessageEvent( MessageEventComposing ); it->second.m_chatStateFilter->setChatState( ChatStateComposing ); it->second.m_session->send( body, subject);//gloox::EmptyString ); if(DebugLog) cout<<"ADXmppProxy::SendMessageToBuddy:address="<<address<<" body="<<body<<" subject="<<subject<<endl; } else //if session doesnt exist in my list, then create new session and send the message { MessageSession* session = new MessageSession(j,JID(address)); session->send(body, subject);//todo: presence check needed before sending message? j->disposeMessageSession( session ); if(DebugLog) cout<<"ADXmppProxy::SendMessageToBuddy:address="<<address<<" body="<<body<<" subject="<<subject<<endl; } return true; } } return false;//address is not in my buddy-list }
void MessageFilter::send( Message& msg ) { m_parent->send( msg ); }