Search in sources :

Example 21 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class CarbonManager method addCarbonsListener.

private void addCarbonsListener(XMPPConnection connection) {
    EntityFullJid localAddress = connection.getUser();
    if (localAddress == null) {
        // carbons securely. Abort here. The ConnectionListener above will eventually setup the carbons listener.
        return;
    }
    // XEP-0280 ยง 11. Security Considerations "Any forwarded copies received by a Carbons-enabled client MUST be
    // from that user's bare JID; any copies that do not meet this requirement MUST be ignored." Otherwise, if
    // those copies do not get ignored, malicious users may be able to impersonate other users. That is why the
    // 'from' matcher is important here.
    connection.addSyncStanzaListener(carbonsListener, new AndFilter(CARBON_EXTENSION_FILTER, FromMatchesFilter.createBare(localAddress)));
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) EntityFullJid(org.jxmpp.jid.EntityFullJid)

Example 22 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class MucEnterConfiguration method getJoinPresence.

Presence getJoinPresence(MultiUserChat multiUserChat) {
    final EntityFullJid jid = JidCreate.entityFullFrom(multiUserChat.getRoom(), nickname);
    joinPresence.setTo(jid);
    return joinPresence;
}
Also used : EntityFullJid(org.jxmpp.jid.EntityFullJid)

Example 23 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class MultiUserChat method changeAvailabilityStatus.

/**
 * Changes the occupant's availability status within the room. The presence type
 * will remain available but with a new status that describes the presence update and
 * a new presence mode (e.g. Extended away).
 *
 * @param status a text message describing the presence update.
 * @param mode the mode type for the presence update.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws MucNotJoinedException if not joined to the Multi-User Chat.
 */
public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException, InterruptedException, MucNotJoinedException {
    final EntityFullJid myRoomJid = getMyRoomJid();
    if (myRoomJid == null) {
        throw new MucNotJoinedException(this);
    }
    // We change the availability status by sending a presence packet to the room with the
    // new presence status and mode
    Presence joinPresence = connection.getStanzaFactory().buildPresenceStanza().to(myRoomJid).ofType(Presence.Type.available).setStatus(status).setMode(mode).build();
    // Send join packet.
    connection.sendStanza(joinPresence);
}
Also used : EntityFullJid(org.jxmpp.jid.EntityFullJid) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence) MucNotJoinedException(org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException)

Example 24 with EntityFullJid

use of org.jxmpp.jid.EntityFullJid in project Smack by igniterealtime.

the class MultiUserChat method leave.

/**
 * Leave the chat room.
 *
 * @return the leave presence as reflected by the MUC.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws MucNotJoinedException if not joined to the Multi-User Chat.
 */
public synchronized Presence leave() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, MucNotJoinedException {
    // Note that this method is intentionally not guarded by
    // "if  (!joined) return" because it should be always be possible to leave the room in case the instance's
    // state does not reflect the actual state.
    final EntityFullJid myRoomJid = getMyRoomJid();
    if (myRoomJid == null) {
        throw new MucNotJoinedException(this);
    }
    // TODO: Consider adding a origin-id to the presence, once it is moved form smack-experimental into
    // smack-extensions, in case the MUC service does not support stable IDs, and modify
    // reflectedLeavePresenceFilters accordingly.
    // We leave a room by sending a presence packet where the "to"
    // field is in the form "roomName@service/nickname"
    Presence leavePresence = connection.getStanzaFactory().buildPresenceStanza().ofType(Presence.Type.unavailable).to(myRoomJid).build();
    List<StanzaFilter> reflectedLeavePresenceFilters = new ArrayList<>(3);
    reflectedLeavePresenceFilters.add(StanzaTypeFilter.PRESENCE);
    reflectedLeavePresenceFilters.add(new OrFilter(new AndFilter(FromMatchesFilter.createFull(myRoomJid), PresenceTypeFilter.UNAVAILABLE, MUCUserStatusCodeFilter.STATUS_110_PRESENCE_TO_SELF), new AndFilter(fromRoomFilter, PresenceTypeFilter.ERROR)));
    if (serviceSupportsStableIds()) {
        reflectedLeavePresenceFilters.add(new StanzaIdFilter(leavePresence));
    }
    StanzaFilter reflectedLeavePresenceFilter = new AndFilter(reflectedLeavePresenceFilters);
    Presence reflectedLeavePresence;
    try {
        reflectedLeavePresence = connection.createStanzaCollectorAndSend(reflectedLeavePresenceFilter, leavePresence).nextResultOrThrow();
    } finally {
        // Reset occupant information after we send the leave presence. This ensures that we only call userHasLeft()
        // and reset the local MUC state after we successfully left the MUC (or if an exception occurred).
        userHasLeft();
    }
    return reflectedLeavePresence;
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) StanzaIdFilter(org.jivesoftware.smack.filter.StanzaIdFilter) EntityFullJid(org.jxmpp.jid.EntityFullJid) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence) MucNotJoinedException(org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException) OrFilter(org.jivesoftware.smack.filter.OrFilter)

Aggregations

EntityFullJid (org.jxmpp.jid.EntityFullJid)24 EntityBareJid (org.jxmpp.jid.EntityBareJid)12 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)10 XMPPException (org.jivesoftware.smack.XMPPException)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)8 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)8 SmackException (org.jivesoftware.smack.SmackException)8 AndFilter (org.jivesoftware.smack.filter.AndFilter)4 Presence (org.jivesoftware.smack.packet.Presence)4 Jid (org.jxmpp.jid.Jid)4 ArrayList (java.util.ArrayList)3 MucNotJoinedException (org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException)3 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)3 StanzaListener (org.jivesoftware.smack.StanzaListener)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)2 Bind (org.jivesoftware.smack.packet.Bind)2 Message (org.jivesoftware.smack.packet.Message)2 Stanza (org.jivesoftware.smack.packet.Stanza)2