Exemple #1
0
Presence::ref PresenceOracle::getLastPresence(const JID& jid) const {
    PresencesMap::const_iterator i = entries_.find(jid.toBare());
    if (i == entries_.end()) {
        return Presence::ref();
    }
    PresenceMap presenceMap = i->second;
    PresenceMap::const_iterator j = presenceMap.find(jid);
    if (j != presenceMap.end()) {
        return j->second;
    }
    else {
        return Presence::ref();
    }
}
 virtual bool handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ ) //发生收到好友请求(添加联系人-1)
 {
     //ack {false, true} {拒绝联系人请求,同意联系人请求}
     bool ack = true;
                 
     printf( "subscription: %s\n", jid.bare().c_str() );
     StringList groups;
     groups.push_back("Group-1");
     JID id( jid );
     //添加到了本地花名册
     j->rosterManager()->subscribe( id, "", groups, "" );
     
     return ack;
 }
void MainController::handleVCardReceived(const JID& jid, VCard::ref vCard) {
	if (!jid.equals(jid_, JID::WithoutResource) || !vCard) {
		return;
	}
	std::string hash;
	if (!vCard->getPhoto().empty()) {
		hash = Hexify::hexify(networkFactories_->getCryptoProvider()->getSHA1Hash(vCard->getPhoto()));
	}
	if (hash != vCardPhotoHash_) {
		vCardPhotoHash_ = hash;
		if (client_ && client_->isAvailable()) {
			sendPresence(statusTracker_->getNextPresence());
		}
	}
}
Exemple #4
0
  void RosterManager::remove( const JID& jid )
  {
    const std::string& id = m_parent->getID();

    Tag *iq = new Tag( "iq" );
    iq->addAttribute( "type", "set" );
    iq->addAttribute( "id", id );
    Tag *q = new Tag( iq, "query" );
    q->addAttribute( "xmlns", XMLNS_ROSTER );
    Tag *i = new Tag( q, "item" );
    i->addAttribute( "jid", jid.bare() );
    i->addAttribute( "subscription", "remove" );

    m_parent->send( iq );
  }
 void InBandBytestreamManager::rejectInBandBytestream( InBandBytestream *ibb,
     const JID& from, const std::string& id )
 {
   delete ibb;
   Tag *iq = new Tag( "iq" );
   iq->addAttribute( "type", "error" );
   iq->addAttribute( "to", from.full() );
   iq->addAttribute( "id", id );
   Tag *e = new Tag( iq, "error" );
   e->addAttribute( "code", "501" );
   e->addAttribute( "type", "cancel" );
   Tag *f = new Tag( e, "feature-not-implemented" );
   f->addAttribute( "xmlns", XMLNS_XMPP_STANZAS );
   m_parent->send( iq );
 }
void JAccountRegistrationPage::onSuccess()
{
	ui->errorLabel->setText(QString());
	m_registered = true;
	if (m_jabberForm) {
		DataForm::Ptr form = m_jabberForm->getDataForm();
		DataFormField jidField = form->field(QLatin1String("username"));
		QString server = field(QLatin1String("server")).toString();
		JID jid = jidField.value() + QLatin1Char('@') + server;
		setField(QLatin1String("jid"), jid.bare());
		setField(QLatin1String("password"), QString());
		setField(QLatin1String("savePassword"), false);
	} else {
		DataItem item = m_form->item();
		DataItem jidItem = item.subitem(QString::number(Jreen::RegistrationData::UsernameField));
		QString server = field(QLatin1String("server")).toString();
		JID jid = jidItem.data().toString() + QLatin1Char('@') + server;
		setField(QLatin1String("jid"), jid.bare());
		setField(QLatin1String("password"), QString());
		setField(QLatin1String("savePassword"), false);
	}
	emit completeChanged();
	wizard()->next();
}
 void SOCKS5BytestreamManager::rejectSOCKS5Bytestream( const JID& from, const std::string& id,
                                                       StanzaError reason )
 {
   Tag *iq = new Tag( "iq" );
   iq->addAttribute( "type", "error" );
   iq->addAttribute( "to", from.full() );
   iq->addAttribute( "id", id );
   Tag *e = new Tag( iq, "error" );
   switch( reason )
   {
     case StanzaErrorForbidden:
     {
       new Tag( iq, "query", "xmlns", XMLNS_BYTESTREAMS );
       e->addAttribute( "code", "403" );
       e->addAttribute( "type", "auth" );
       Tag *f = new Tag( e, "forbidden" );
       f->addAttribute( "xmlns", XMLNS_XMPP_STANZAS );
       break;
     }
     case StanzaErrorFeatureNotImplemented:
     {
       e->addAttribute( "code", "404" );
       e->addAttribute( "type", "cancel" );
       Tag *f = new Tag( e, "item-not-found" );
       f->addAttribute( "xmlns", XMLNS_XMPP_STANZAS );
       break;
     }
     case StanzaErrorNotAllowed:
     {
       new Tag( iq, "query", "xmlns", XMLNS_BYTESTREAMS );
       e->addAttribute( "code", "405" );
       e->addAttribute( "type", "cancel" );
       Tag *f = new Tag( e, "not-allowed" );
       f->addAttribute( "xmlns", XMLNS_XMPP_STANZAS );
       break;
     }
     case StanzaErrorNotAcceptable:
     default:
     {
       e->addAttribute( "code", "406" );
       e->addAttribute( "type", "auth" );
       Tag *f = new Tag( e, "not-acceptable" );
       f->addAttribute( "xmlns", XMLNS_XMPP_STANZAS );
       break;
     }
   }
   m_parent->send( iq );
 }
IBBReceiveSession::IBBReceiveSession(
		const std::string& id, 
		const JID& from, 
		const JID& to, 
		size_t size, 
		IQRouter* router) : 
			id(id), 
			from(from), 
			to(to), 
			size(size), 
			router(router), 
			active(false) {
	assert(!id.empty());
	assert(from.isValid());
	responder = new IBBResponder(this, router);
}
Exemple #9
0
  void VCardManager::fetchVCard( const JID& jid, VCardHandler* vch )
  {
    if( !m_parent || !vch )
      return;

    TrackMap::const_iterator it = m_trackMap.find( jid.bare() );
    if( it != m_trackMap.end() )
      return;

    const std::string& id = m_parent->getID();
    IQ iq ( IQ::Get, jid, id );
    iq.addExtension( new VCard() );

    m_trackMap[id] = vch;
    m_parent->send( iq, this,VCardHandler::FetchVCard  );
  }
Exemple #10
0
  void RosterManager::subscribe( const JID& jid, const std::string& name,
                                 const StringList& groups, const std::string& msg )
  {
    if( !jid )
      return;

    add( jid, name, groups );

    Tag *s = new Tag( "presence" );
    s->addAttribute( "type", "subscribe" );
    s->addAttribute( "to", jid.bare() );
    s->addAttribute( "from", m_parent->jid().full() );
    if( !msg.empty() )
      new Tag( s, "status", msg );

    m_parent->send( s );
  }
Exemple #11
0
IBBReceiveSession::IBBReceiveSession(
        const std::string& id,
        const JID& from,
        const JID& to,
        unsigned long long size,
        std::shared_ptr<WriteBytestream> bytestream,
        IQRouter* router) :
            id(id),
            from(from),
            to(to),
            size(size),
            bytestream(bytestream),
            router(router),
            active(false) {
    assert(!id.empty());
    assert(from.isValid());
    responder = new IBBResponder(this, router);
}
Exemple #12
0
		void handleCapsChanged(JID jid) {
			if (jid.toBare() == recipient) {
				// create ReadBytestream from file
				boost::shared_ptr<FileReadBytestream> fileStream = boost::make_shared<FileReadBytestream>(file);

				outgoingFileTransfer = client->getFileTransferManager()->createOutgoingFileTransfer(recipient, file, "Some File!", fileStream);

				if (outgoingFileTransfer) {
					outgoingFileTransfer->onFinished.connect(boost::bind(&FileSender::handleFileTransferFinished, this, _1));
					std::cout << "Starting file-transfer to " << recipient.toString() << "." << std::endl;
					outgoingFileTransfer->start();
					// TODO: getting notified about FT status and end
				} else {
					std::cout << recipient << " doesn't support any kind of file transfer!" << std::endl;
					client->disconnect();
				}
			}
		}
Exemple #13
0
static void handleRoomsItemsResponse(std::shared_ptr<DiscoItems> items, ErrorPayload::ref error) {
    if (error) {
        cout << "Error fetching list of rooms." << endl;
        return;
    }

    int roomCount = 0;
    cout << "List of rooms at " << mucJID.toString() << endl;
    for (auto&& item : items->getItems()) {
        roomCount++;
        cout << "\t" << roomCount << ". " << item.getJID().getNode() << " - " << item.getName() << std::endl;
        if (roomCount == 1) {
            roomJID = item.getJID();
        }
    }
    cout << endl;
    joinMUC();
}
Exemple #14
0
  void Search::fetchSearchFields( const JID& directory, SearchHandler *sh )
  {
    if( !m_parent || !directory || !sh )
      return;

    const std::string& id = m_parent->getID();

    Tag *iq = new Tag( "iq" );
    iq->addAttribute( "type", "get" );
    iq->addAttribute( "id", id );
    iq->addAttribute( "to", directory.full() );
    Tag *q = new Tag( iq, "query" );
    q->addAttribute( "xmlns", XMLNS_SEARCH );

    m_track[id] = sh;
    m_parent->trackID( this, id, FetchSearchFields );
    m_parent->send( iq );
  }
Exemple #15
0
void TalkDiscoHandler::handleDiscoInfo(const JID& from, const Disco::Info& info, int context)
{
        ServerDiscoWindow* discowindow = Bodies::Get_Bodies().get_main_window().get_disco_window();

        if (NULL == discowindow)
                return ;


        const Disco::IdentityList& list = info.identities();

        Disco::IdentityList::const_iterator iter = list.begin();

        for (; iter != list.end(); ++iter) {
                if ((*iter)->category() == "server") {

                        discowindow->setLabel(from.full(), (*iter)->name());
                }
        }
}
Exemple #16
0
  void Search::search( const JID& directory, const DataForm& form, SearchHandler *sh )
  {
    if( !m_parent || !directory || !sh )
      return;

    const std::string& id = m_parent->getID();

    Tag *iq = new Tag( "iq" );
    iq->addAttribute( "id", id );
    iq->addAttribute( "type", "set" );
    iq->addAttribute( "to", directory.full() );
    Tag *q = new Tag( iq, "query" );
    q->addAttribute( "xmlns", XMLNS_SEARCH );
    q->addChild( form.tag() );

    m_track[id] = sh;
    m_parent->trackID( this, id, DoSearch );
    m_parent->send( iq );
  }
Exemple #17
0
void CapsManager::handleDiscoInfoReceived(const JID& from, const std::string& hash, DiscoInfo::ref discoInfo, ErrorPayload::ref error) {
    requestedDiscoInfos.erase(hash);
    if (error || !discoInfo || CapsInfoGenerator("", crypto).generateCapsInfo(*discoInfo.get()).getVersion() != hash) {
        if (warnOnInvalidHash && !error &&  discoInfo) {
            SWIFT_LOG(warning) << "Caps from " << from.toString() << " do not verify" << std::endl;
        }
        failingCaps.insert(std::make_pair(from, hash));
        std::map<std::string, std::set< std::pair<JID, std::string> > >::iterator i = fallbacks.find(hash);
        if (i != fallbacks.end() && !i->second.empty()) {
            std::pair<JID,std::string> fallbackAndNode = *i->second.begin();
            i->second.erase(i->second.begin());
            requestDiscoInfo(fallbackAndNode.first, fallbackAndNode.second, hash);
        }
        return;
    }
    fallbacks.erase(hash);
    capsStorage->setDiscoInfo(hash, discoInfo);
    onCapsAvailable(hash);
}
void SOCKS5BytestreamManager::acknowledgeStreamHost( bool success, const JID& jid,
        const std::string& sid )
{
    AsyncTrackMap::const_iterator it = m_asyncTrackMap.find( sid );
    if( it == m_asyncTrackMap.end() || !m_parent )
        return;

    const AsyncS5BItem& item = (*it).second;

    IQ* iq = 0;

    if( item.incoming )
    {
        iq = new IQ( IQ::Result, item.from.full(), item.id );
        if( item.to )
            iq->setFrom( item.to );

        if( success )
            iq->addExtension( new Query( jid, sid, false ) );
        else
            iq->addExtension( new Error( StanzaErrorTypeCancel, StanzaErrorItemNotFound ) );

        m_parent->send( *iq );
    }
    else
    {
        if( success )
        {
            const std::string& id = m_parent->getID();
            iq = new IQ( IQ::Set, jid.full(), id );
            iq->addExtension( new Query( item.from, sid, true ) );

            m_trackMap[id] = sid;
            m_parent->send( *iq, this, S5BActivateStream );
        }
    }

    delete iq;
}
Exemple #19
0
void UserSearchController::addToSavedDirectories(const JID& jid) {
    if (!jid.isValid()) {
        return;
    }

    savedDirectories_.erase(std::remove(savedDirectories_.begin(), savedDirectories_.end(), jid), savedDirectories_.end());
    savedDirectories_.insert(savedDirectories_.begin(), jid);

    std::string collapsed;
    int i = 0;
    for (const auto& jidItem : savedDirectories_) {
        if (i >= 15) {
            break;
        }
        if (!collapsed.empty()) {
            collapsed += "\n";
        }
        collapsed += jidItem.toString();
        ++i;
    }
    settings_->storeString(SEARCHED_DIRECTORIES, collapsed);
    window_->addSavedServices(savedDirectories_);
}
Exemple #20
0
		void TalkServiceI::voicePush(Ice::Int fromId, Ice::Int toId, const std::string& msg, 
				const Ice::Int messageType, const Ice::Int appId, const Ice::Current& current){
			MilliTimer tStart;			

            LOG_W(fromId, "TalkServiceI::voicePush", messageType, msg);

			MessageType::Type type = static_cast<MessageType::Type>(messageType);
			LOG_DEBUG("TalkServiceI::voicePush => accept a voicePush : fromId = " << fromId 
					<< " toId = " << toId << " msg = " << msg << " type = " << type);

			pugi::xml_document doc;
			pugi::xml_parse_result xmlResult = doc.load(msg.c_str());

			if(!xmlResult || !doc.first_child()){
				LOG_ERROR("TalkServiceI::voicePush => read voice xmpp error : " << xmlResult.description());
			}

			JID from;
			pugi::xml_node node=doc.first_child();
			pugi::xml_attribute attr ;
			attr = node.attribute("from");
			if(attr){
				from.parser(attr.value());
			} else {
			}

			string fname(node.attribute("fname").value());

            #ifndef INTERNATIONAL
			if(fname.empty()){
				fname = UserNameClient::GetUserName(from.getUserId());
				node.append_attribute("fname").set_value(fname.c_str());
				LOG_DEBUG("此处添加fname : "<<fname);
				std::cout<<"添加名字 : "<<fname<<std::endl;
			}
            #endif

			node.append_attribute("fromCAppid").set_value(appId);


			string text = utils::MsgTransform::voice2text(doc.first_child());
			LOG_DEBUG("TalkServiceI::voicePush => voice2text : voice = [" << msg << "] text = [" << text << "]");

			

			stringstream os;
			long fromSixinId = changer_.getSixinIdByRenRenId(fromId);
			long toSixinId = changer_.getSixinIdByRenRenId(toId);
			if(fromSixinId == -1 || toSixinId == -1){
				return ;
			}

			if(!text.empty()){
				MessageTails::addTail(appId, type, text);

				string textMsg = text.append("  ");
				imGateForPhoneAdapterPtr_->sendMessage(fromSixinId, toSixinId, textMsg);

			}

			changer_.changToSixin("talk.m.renren.com",node);
			node.print(os, "\t", pugi::format_raw);

			voicePushV1(fromSixinId, toSixinId, os.str(), messageType, appId, current);
		}
JID VCardUpdateAvatarManager::getAvatarJID(const JID& jid) const {
	JID bareFrom = jid.toBare();
	return (mucRegistry_ && mucRegistry_->isMUC(bareFrom)) ? jid : bareFrom;
}
Exemple #22
0
void QtVCardJIDField::setJID(const JID& jid) {
	std::string jidStr = jid.toBare().toString();
	jidLineEdit->setText(P2QSTRING(jidStr));
}
Exemple #23
0
 virtual void handleItemUpdated( const JID& jid )
 {
   printf( "updated %s\n", jid.bare().c_str() );
 }
Exemple #24
0
 virtual void handleItemRemoved( const JID& jid )
 {
   printf( "removed %s\n", jid.bare().c_str() );
 }
Exemple #25
0
 virtual void handleItemUnsubscribed( const JID& jid )
 {
   printf( "unsubscribed %s\n", jid.bare().c_str() );
 }
Exemple #26
0
 virtual void handleItemAdded( const JID& jid )
 {
   printf( "added %s\n", jid.bare().c_str() );
 }
Exemple #27
0
 virtual bool handleUnsubscriptionRequest( const JID& jid, const std::string& /*msg*/ )
 {
   printf( "unsubscription: %s\n", jid.bare().c_str() );
   return true;
 }
 virtual void handleMUCInviteDecline( MUCRoom * /*room*/, const JID& invitee, const std::string& reason )
 {
   printf( "Invitee %s declined invitation. reason given: %s\n", invitee.full().c_str(), reason.c_str() );
 }
Exemple #29
0
void CMsgSessionManager::handleChatState( const JID& from, ChatStateType state )
{
	printf( "received state: %d from: %s\n", state, from.bare().c_str() );
}
Exemple #30
0
void CMsgSessionManager::handleMessageEvent( const JID& from, MessageEventType event )
{
	printf( "received event: %d from: %s\n", event, from.bare().c_str() );
}