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)));
}
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;
}
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);
}
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;
}
Aggregations