void MainController::handleLoginRequest(const std::string &username, const std::string &password, const std::string& certificatePath, CertificateWithKey::ref certificate, const ClientOptions& options, bool remember, bool loginAutomatically) { jid_ = JID(username); if (options.singleSignOn && (!jid_.isValid() || !jid_.getNode().empty())) { loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'wonderland.lit'")); loginWindow_->setIsLoggingIn(false); } else if (!options.singleSignOn && (!jid_.isValid() || jid_.getNode().empty())) { loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form '*****@*****.**'")); loginWindow_->setIsLoggingIn(false); } else { #ifdef SWIFTEN_PLATFORM_WIN32 if (options.singleSignOn) { std::string userName; std::string clientName; std::string serverName; boost::shared_ptr<boost::system::error_code> errorCode = getUserNameEx(userName, clientName, serverName); if (!errorCode) { /* Create JID using the Windows logon name and user provided domain name */ jid_ = JID(clientName, username); } else { loginWindow_->setMessage(str(format(QT_TRANSLATE_NOOP("", "Error obtaining Windows user name (%1%)")) % errorCode->message())); loginWindow_->setIsLoggingIn(false); return; } } #endif loginWindow_->setMessage(""); loginWindow_->setIsLoggingIn(true); profileSettings_ = new ProfileSettingsProvider(username, settings_); if (!settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { profileSettings_->storeString("jid", username); profileSettings_->storeString("certificate", certificatePath); profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : ""); std::string optionString = serializeClientOptions(options); profileSettings_->storeString("options", optionString); settings_->storeSetting(SettingConstants::LAST_LOGIN_JID, username); settings_->storeSetting(SettingConstants::LOGIN_AUTOMATICALLY, loginAutomatically); loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate"), options); } password_ = password; certificate_ = certificate; clientOptions_ = options; performLoginFromCachedCredentials(); } }
void QtUserSearchWindow::handleAccepted() { JID jid; std::vector<JID> jids; switch(type_) { case AddContact: jid = getContactJID(); eventStream_->send(boost::make_shared<AddContactUIEvent>(jid, detailsPage_->getName(), detailsPage_->getSelectedGroups())); break; case ChatToContact: if (contactVector_.size() == 1) { boost::shared_ptr<UIEvent> event(new RequestChatUIEvent(contactVector_[0]->jid)); eventStream_->send(event); break; } foreach(Contact::ref contact, contactVector_) { jids.push_back(contact->jid); } eventStream_->send(boost::make_shared<CreateImpromptuMUCUIEvent>(jids, JID(), Q2PSTRING(firstMultiJIDPage_->reason_->text()))); break; case InviteToChat: foreach(Contact::ref contact, contactVector_) { jids.push_back(contact->jid); }
CJabberCore::CJabberCore() { initscr(); cbreak(); //keypad(stdscr, TRUE); height = LINES; width = COLS; // setting up chat and input window borderWindow = createWindow(5, width - 3, height - 5, 3); inputWindow = createWindow(3, width - 5, height - 4, 4); chatWindow = createWindow(height - 5, width , 0 , 0); keypad(inputWindow, TRUE); // for proper input cursor position wrefresh(inputWindow); wmove(inputWindow, 0, 0); int y, x; getparyx(inputWindow, y, x); MessageWindow::getInstance().setInputX(x); MessageWindow::getInstance().setInputY(y); // setting refs for printMsg MessageWindow::getInstance().setWindow(chatWindow, height - 5, width); scrollok(MessageWindow::getInstance().getWindow(), TRUE); jid = JID(""); }
void UserSearchController::initializeUserWindow() { if (!window_) { UserSearchWindow::Type windowType = UserSearchWindow::AddContact; switch(type_) { case AddContact: windowType = UserSearchWindow::AddContact; break; case StartChat: windowType = UserSearchWindow::ChatToContact; break; case InviteToChat: windowType = UserSearchWindow::InviteToChat; break; } window_ = factory_->createUserSearchWindow(windowType, uiEventStream_, rosterController_->getGroups()); if (!window_) { // UI Doesn't support user search return; } window_->onNameSuggestionRequested.connect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1)); window_->onFormRequested.connect(boost::bind(&UserSearchController::handleFormRequested, this, _1)); window_->onSearchRequested.connect(boost::bind(&UserSearchController::handleSearch, this, _1, _2)); window_->onContactSuggestionsRequested.connect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1)); window_->onJIDUpdateRequested.connect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1)); window_->onJIDAddRequested.connect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1)); window_->onJIDEditFieldChanged.connect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1)); window_->setSelectedService(JID(jid_.getDomain())); window_->clear(); } }
void MUCUserPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == ItemLevel) { if (element == "item") { MUCUserPayload::Item item; std::string affiliation = attributes.getAttribute("affiliation"); std::string role = attributes.getAttribute("role"); std::string nick = attributes.getAttribute("nick"); std::string jid = attributes.getAttribute("jid"); item.affiliation = parseAffiliation(affiliation); item.role = parseRole(role); if (!jid.empty()) { item.realJID = JID(jid); } if (!nick.empty()) { item.nick = nick; } getPayloadInternal()->addItem(item); } else if (element == "status") { MUCUserPayload::StatusCode status; try { status.code = boost::lexical_cast<int>(attributes.getAttribute("code").c_str()); getPayloadInternal()->addStatusCode(status); } catch (boost::bad_lexical_cast&) { } } } ++level; }
void UserSearchController::handleVCardChanged(const JID& jid, VCard::ref vcard) { if (jid == suggestionsJID_) { window_->setNameSuggestions(ContactEditController::nameSuggestionsFromVCard(vcard)); suggestionsJID_ = JID(); } handleJIDUpdateRequested(std::vector<JID>(1, jid)); }
bool SOCKS5Bytestream::connect() { if( !m_connection || !m_socks5 || !m_manager ) return false; if( m_open ) return true; StreamHostList::const_iterator it = m_hosts.begin(); for( ; it != m_hosts.end(); ++it ) { if( ++it == m_hosts.end() ) m_connected = true; --it; // FIXME ++it followed by --it is kinda ugly m_connection->setServer( (*it).host, (*it).port ); if( m_socks5->connect() == ConnNoError ) { m_proxy = (*it).jid; m_connected = true; return true; } } m_manager->acknowledgeStreamHost( false, JID(), EmptyString ); return false; }
MessageSession *MessageSessionManager::session(const JID &jid, Message::Type type, bool create) { Q_D(MessageSessionManager); QList<QPointer<MessageSession> > sessions = d->fullSessions.values(jid.full()); Logger::debug() << "d->full_sessions" << d->fullSessions; foreach(MessageSession *session, sessions) Logger::debug() << "MessageSession" << (session ? session->jid() : JID()); for(int i = 0; i < sessions.size(); i++) { if(sessions[i].isNull()) { d->fullSessions.remove(jid.full(), sessions[i]); continue; } return sessions[i]; } if(!create) return 0; MessageSessionHandler *handler = d->sessionHandlers.value(type); if(!handler) return 0; MessageSession *session = new MessageSession(this, jid.full(), false, QString()); handler->handleMessageSession(session); return session; }
VCardReply *VCardManager::store(const Jreen::VCard::Ptr &vcard) { Q_D(VCardManager); IQ iq(IQ::Set, JID()); iq.addExtension(vcard); return new VCardReply(d->client->jid().bareJID(), NULL, d->client->send(iq)); }
void PichiEvent::doAction(std::string action, std::string value, std::string option, std::string coincidence) { std::vector<std::string> exploder; if(action == "send_message") { std::string room; if(coincidence != "") { exploder = system::explode(",", coincidence); exploder = system::explode("=", exploder[0]); if(exploder[0] == "room") { room = exploder[1]; } else { //$this->log->log("Old send_message handler", PichiLog::LEVEL_WARNING); return; } } else { return; } if(option == "") if(value != "") pichi->jabber->sendMessage(JID(room), value); //$this->log->log("EVENT: {$action} (Send message {$value})", PichiLog::LEVEL_VERBOSE); return; } //($hook = PichiPlugin::fetch_hook('event_action')) ? eval($hook) : false; }
void Client::createSession() { notifyStreamEvent( StreamEventSessionCreation ); IQ iq( IQ::Set, JID(), getID() ); iq.addExtension( new SessionCreation() ); send( iq, this, CtxSessionEstablishment ); }
void SearchPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == TopLevel) { } else if (level == PayloadLevel) { if (element == "x" && ns == "jabber:x:data") { assert(!formParser); formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); } else if (element == "item") { assert(!currentItem); currentItem.reset(SearchPayload::Item()); currentItem->jid = JID(attributes.getAttribute("jid")); } else { currentText.clear(); } } else if (level == ItemLevel && currentItem) { currentText.clear(); } if (formParser) { formParser->handleStartElement(element, ns, attributes); } ++level; }
ConfigHandler::ConfigHandler(User *user, const std::string &from, const std::string &id) : m_from(from), m_user(user) { setRequestType(CALLER_ADHOC); std::string bare(JID(from).bare()); IQ _response(IQ::Result, from, id); Tag *response = _response.tag(); response->addAttribute("from", Transport::instance()->jid()); AdhocTag *adhocTag = new AdhocTag(Transport::instance()->getId(), "transport_irc_config", "executing"); adhocTag->setAction("complete"); adhocTag->setTitle("IRC Nickserv password configuration"); adhocTag->setInstructions("Choose the server you want to change password for."); std::map <std::string, std::string> values; std::map<std::string, UserRow> users = Transport::instance()->sql()->getUsersByJid(bare); for (std::map<std::string, UserRow>::iterator it = users.begin(); it != users.end(); it++) { std::string server = (*it).second.jid.substr(bare.size()); values[server] = stringOf((*it).second.id); m_userId.push_back(stringOf((*it).second.id)); } adhocTag->addListSingle("IRC server", "irc_server", values); adhocTag->addTextPrivate("New NickServ password", "password"); response->addChild(adhocTag); Transport::instance()->send(response); }
void CapabilityHandlerTest::handleDiscoInfoBadIdentity() { int context = m_handler->waitForCapabilities("http://code.google.com/p/exodus#QgayPKawpkPSDYmwT/WM94uAlu0=", "[email protected]/psi"); CPPUNIT_ASSERT (m_handler->hasVersion(context)); Tag *query = new Tag("query"); query->addAttribute("xmlns", "http://jabber.org/protocol/disco#info"); query->addAttribute("node", "http://code.google.com/p/exodus#QgayPKawpkPSDYmwT/WM94uAlu0="); Tag *identity = new Tag("identity"); identity->addAttribute("category", "not-client"); identity->addAttribute("name", "Exodus 0.9.1"); identity->addAttribute("type", "pc"); query->addChild(identity); m_user->setConnected(false); m_user->setReadyForConnect(true); m_user->setResource("psi", 50, 0); m_handler->handleDiscoInfo(JID("[email protected]/psi"), query, context); CPPUNIT_ASSERT (m_user->isConnected() == false); CPPUNIT_ASSERT (m_user->hasFeature(GLOOX_FEATURE_ROSTERX, "psi") == false); CPPUNIT_ASSERT (m_user->hasFeature(GLOOX_FEATURE_FILETRANSFER, "psi") == false); CPPUNIT_ASSERT (m_user->hasFeature(GLOOX_FEATURE_CHATSTATES, "psi") == false); CPPUNIT_ASSERT (m_user->hasFeature(GLOOX_FEATURE_XHTML_IM, "psi") == false); }
JID QtTreeWidget::selectedJID() const { QModelIndexList list = selectedIndexes(); if (list.size() != 1) { return JID(); } return jidFromIndex(list[0]); }
void UserSearchController::loadSavedDirectories() { savedDirectories_.clear(); for (auto&& stringItem : String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) { if(!stringItem.empty()) { savedDirectories_.push_back(JID(stringItem)); } } }
void FlexibleOffline::messageOperation( int context, const StringList& msgs ) { const std::string& id = m_parent->getID(); IQ::IqType iqType = context == FORequestMsgs ? IQ::Get : IQ::Set; IQ iq( iqType, JID(), id ); iq.addExtension( new Offline( context, msgs ) ); m_parent->send( iq, this, context ); }
void IRCProtocol::makeRoomJID(User *user, std::string &name) { // #pidgin" -> "#pidgin%[email protected]" std::transform(name.begin(), name.end(), name.begin(),(int(*)(int)) std::tolower); std::string name_safe = name; std::for_each( name_safe.begin(), name_safe.end(), replaceBadJidCharacters() ); // OK name.assign(name_safe + "%" + JID(user->username()).server() + "@" + Transport::instance()->jid()); std::cout << "ROOMJID: " << name << "\n"; }
void MUCDestroyPayloadParser::handleTree(ParserElement::ref root) { std::string ns = root->getNamespace(); std::string jid = root->getAttributes().getAttribute("jid"); if (!jid.empty()) { getPayloadInternal()->setNewVenue(JID(jid)); } getPayloadInternal()->setReason(root->getChild("reason", ns)->getText()); }
void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) { if (isInitialized()) { onElementReceived(element); } else { if (AuthRequest* authRequest = dynamic_cast<AuthRequest*>(element.get())) { if (authRequest->getMechanism() == "PLAIN" || (allowSASLEXTERNAL && authRequest->getMechanism() == "EXTERNAL")) { if (authRequest->getMechanism() == "EXTERNAL") { getXMPPLayer()->writeElement(boost::make_shared<AuthSuccess>()); authenticated_ = true; getXMPPLayer()->resetParser(); } else { PLAINMessage plainMessage(authRequest->getMessage() ? *authRequest->getMessage() : createSafeByteArray("")); if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), getLocalJID().getDomain()), plainMessage.getPassword())) { getXMPPLayer()->writeElement(boost::make_shared<AuthSuccess>()); user_ = plainMessage.getAuthenticationID(); authenticated_ = true; getXMPPLayer()->resetParser(); } else { getXMPPLayer()->writeElement(boost::shared_ptr<AuthFailure>(new AuthFailure)); finishSession(AuthenticationFailedError); } } } else { getXMPPLayer()->writeElement(boost::shared_ptr<AuthFailure>(new AuthFailure)); finishSession(NoSupportedAuthMechanismsError); } } else if (IQ* iq = dynamic_cast<IQ*>(element.get())) { if (boost::shared_ptr<ResourceBind> resourceBind = iq->getPayload<ResourceBind>()) { setRemoteJID(JID(user_, getLocalJID().getDomain(), resourceBind->getResource())); boost::shared_ptr<ResourceBind> resultResourceBind(new ResourceBind()); resultResourceBind->setJID(getRemoteJID()); getXMPPLayer()->writeElement(IQ::createResult(JID(), iq->getID(), resultResourceBind)); } else if (iq->getPayload<StartSession>()) { getXMPPLayer()->writeElement(IQ::createResult(getRemoteJID(), iq->getID())); setInitialized(); } } } }
void NonSaslAuth::handleIqID( const IQ& iq, int context ) { switch( iq.subtype() ) { case IQ::Error: { const Error* e = iq.error(); if( e ) { switch( e->error() ) { case StanzaErrorConflict: m_parent->setAuthFailure( NonSaslConflict ); break; case StanzaErrorNotAcceptable: m_parent->setAuthFailure( NonSaslNotAcceptable ); break; case StanzaErrorNotAuthorized: m_parent->setAuthFailure( NonSaslNotAuthorized ); break; default: break; } } m_parent->setAuthed( false ); m_parent->disconnect( ConnAuthenticationFailed ); break; } case IQ::Result: switch( context ) { case TrackRequestAuthFields: { const Query* q = iq.findExtension<Query>( ExtNonSaslAuth ); if( !q ) return; const std::string& id = m_parent->getID(); IQ re( IQ::Set, JID(), id ); re.addExtension( q->newInstance( m_parent->username(), m_sid, m_parent->password(), m_parent->jid().resource() ) ); m_parent->send( re, this, TrackSendAuth ); break; } case TrackSendAuth: m_parent->setAuthed( true ); m_parent->connected(); break; } break; default: break; } }
void VCardManager::requestVCard(const JID& requestedJID) { JID jid = requestedJID.equals(ownJID, JID::WithoutResource) ? JID() : requestedJID; if (requestedVCards.find(jid) != requestedVCards.end()) { return; } GetVCardRequest::ref request = GetVCardRequest::create(jid, iqRouter); request->onResponse.connect(boost::bind(&VCardManager::handleVCardReceived, this, jid, _1, _2)); request->send(); requestedVCards.insert(jid); }
void RosterManager::remove( const JID& jid ) { if( !jid ) return; IQ iq( IQ::Set, JID(), m_parent->getID() ); iq.addExtension( new Query( jid ) ); m_parent->send( iq, this, RemoveRosterItem ); }
void RosterManager::add( const JID& jid, const std::string& name, const StringList& groups ) { if( !jid ) return; IQ iq( IQ::Set, JID(), m_parent->getID() ); iq.addExtension( new Query( jid, name, groups) ); m_parent->send( iq, this, AddRosterItem ); }
void RosterManager::fill() { if( !m_parent ) return; m_privateXML->requestXML( "roster", XMLNS_ROSTER_DELIMITER, this ); IQ iq( IQ::Get, JID(), m_parent->getID() ); iq.addExtension( new Query() ); m_parent->send( iq, this, RequestRoster ); }
// ---- Client ---- Client::Client( const std::string& server ) : ClientBase( XMLNS_CLIENT, server ), m_rosterManager( 0 ), m_auth( 0 ), m_presence( Presence::Available, JID() ), m_resourceBound( false ), m_forceNonSasl( false ), m_manageRoster( true ), m_doAuth( false ), m_streamFeatures( 0 ), m_priority( 0 ) { m_jid.setServer( server ); init(); }
bool Client::bindOperation( const std::string& resource, bool bind ) { if( !( m_streamFeatures & StreamFeatureUnbind ) && m_resourceBound ) return false; IQ iq( IQ::Set, JID(), getID() ); iq.addExtension( new ResourceBind( resource, bind ) ); send( iq, this, bind ? CtxResourceBind : CtxResourceUnbind ); return true; }
void ResourceBindParser::handleEndElement(const std::string&, const std::string&) { --level_; if (level_ == 1) { if (inJID_) { getPayloadInternal()->setJID(JID(text_)); } else if (inResource_) { getPayloadInternal()->setResource(text_); } } }
std::string PrivacyManager::operation( IdType context, const std::string& name ) { const std::string& id = m_parent->getID(); IQ::IqType iqType = IQ::Set; if( context == PLRequestNames || context == PLRequestList ) iqType = IQ::Get; IQ iq( iqType, JID(), id ); iq.addExtension( new Query( context, name ) ); m_parent->send( iq, this, context ); return id; }
Client::Client( const JID& jid, const std::string& password, int port ) : ClientBase( XMLNS_CLIENT, password, EmptyString, port ), m_rosterManager( 0 ), m_auth( 0 ), m_presence( Presence::Available, JID() ), m_resourceBound( false ), m_forceNonSasl( false ), m_manageRoster( true ), m_doAuth( true ), m_streamFeatures( 0 ), m_priority( 0 ) { m_jid = jid; m_server = m_jid.serverRaw(); init(); }