Search in sources :

Example 26 with EntityBareJid

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

the class MultiUserChatEntityIntegrationTest method mucTestForDiscoveringRoomItems.

/**
 * Asserts that a MUC Service returns disco info for a room's items.
 *
 * <p>From XEP-0045 ยง 6.5:</p>
 * <blockquote>
 * An entity MAY also query a specific chat room for its associated items. An implementation MAY return a list
 * of existing occupants if that information is publicly available, or return no list at all if this information is
 * kept private.
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestForDiscoveringRoomItems() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-discoitems");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));
    DiscoverItems roomItems;
    try {
        roomItems = ServiceDiscoveryManager.getInstanceFor(conTwo).discoverItems(mucAddress);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
    assertEquals(1, roomItems.getItems().size());
}
Also used : DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 27 with EntityBareJid

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

the class OmemoService method getMuc.

/**
 * Return the joined MUC with EntityBareJid jid, or null if its not a room and/or not joined.
 *
 * @param connection xmpp connection
 * @param jid jid (presumably) of the MUC
 * @return MultiUserChat or null if not a MUC.
 */
private static MultiUserChat getMuc(XMPPConnection connection, Jid jid) {
    EntityBareJid ebj = jid.asEntityBareJidIfPossible();
    if (ebj == null) {
        return null;
    }
    MultiUserChatManager mucm = MultiUserChatManager.getInstanceFor(connection);
    Set<EntityBareJid> joinedRooms = mucm.getJoinedRooms();
    if (joinedRooms.contains(ebj)) {
        return mucm.getMultiUserChat(ebj);
    }
    return null;
}
Also used : MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 28 with EntityBareJid

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

the class OmemoManager method multiUserChatSupportsOmemo.

/**
 * Returns true, if the MUC with the EntityBareJid multiUserChat is non-anonymous and members only (prerequisite
 * for OMEMO encryption in MUC).
 *
 * @param multiUserChat MUC
 * @return true if chat supports OMEMO
 *
 * @throws XMPPException.XMPPErrorException     if there was an XMPP protocol level error
 * @throws SmackException.NotConnectedException if the connection is not connected
 * @throws InterruptedException                 if the thread is interrupted
 * @throws SmackException.NoResponseException   if the server does not respond
 */
public boolean multiUserChatSupportsOmemo(MultiUserChat multiUserChat) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
    EntityBareJid jid = multiUserChat.getRoom();
    RoomInfo roomInfo = MultiUserChatManager.getInstanceFor(connection()).getRoomInfo(jid);
    return roomInfo.isNonanonymous() && roomInfo.isMembersOnly();
}
Also used : RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 29 with EntityBareJid

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

the class IoT method iotScenario.

public static void iotScenario(String dataThingJidString, String dataThingPassword, String readingThingJidString, String readingThingPassword, IotScenario scenario) throws Exception {
    final EntityBareJid dataThingJid = JidCreate.entityBareFrom(dataThingJidString);
    final EntityBareJid readingThingJid = JidCreate.entityBareFrom(readingThingJidString);
    final XMPPTCPConnectionConfiguration dataThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(dataThingJid.getLocalpart(), dataThingPassword).setXmppDomain(dataThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled).enableDefaultDebugger().build();
    final XMPPTCPConnectionConfiguration readingThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(readingThingJid.getLocalpart(), readingThingPassword).setXmppDomain(readingThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled).enableDefaultDebugger().build();
    final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration);
    final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration);
    dataThingConnection.setReplyTimeout(TIMEOUT);
    readingThingConnection.setReplyTimeout(TIMEOUT);
    dataThingConnection.setUseStreamManagement(false);
    readingThingConnection.setUseStreamManagement(false);
    try {
        dataThingConnection.connect().login();
        readingThingConnection.connect().login();
        scenario.iotScenario(dataThingConnection, readingThingConnection);
    } finally {
        dataThingConnection.disconnect();
        readingThingConnection.disconnect();
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 30 with EntityBareJid

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

the class OmemoClient method main.

public static void main(String[] args) throws XMPPException, SmackException, IOException, InterruptedException, CorruptedOmemoKeyException {
    SmackConfiguration.DEBUG = true;
    if (args.length != 2) {
        print("Missing arguments: <jid> <password>");
        return;
    }
    SignalOmemoService.acknowledgeLicense();
    SignalOmemoService.setup();
    SignalOmemoService omemoService = (SignalOmemoService) SignalOmemoService.getInstance();
    Path omemoStoreDirectory = Files.createTempDirectory("omemo-store");
    omemoService.setOmemoStoreBackend(new SignalCachingOmemoStore(new SignalFileBasedOmemoStore(omemoStoreDirectory.toFile())));
    EntityBareJid jid = JidCreate.entityBareFromOrThrowUnchecked(args[0]);
    String password = args[1];
    OmemoClient client = new OmemoClient(jid, password);
    try {
        client.start();
        while (true) {
            String input = scanner.nextLine();
            if (input.startsWith("/quit")) {
                break;
            }
            if (input.isEmpty()) {
                continue;
            }
            client.handleInput(input);
        }
    } finally {
        client.stop();
    }
}
Also used : Path(java.nio.file.Path) SignalCachingOmemoStore(org.jivesoftware.smackx.omemo.signal.SignalCachingOmemoStore) SignalFileBasedOmemoStore(org.jivesoftware.smackx.omemo.signal.SignalFileBasedOmemoStore) SignalOmemoService(org.jivesoftware.smackx.omemo.signal.SignalOmemoService) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Aggregations

EntityBareJid (org.jxmpp.jid.EntityBareJid)56 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)30 XMPPException (org.jivesoftware.smack.XMPPException)21 Resourcepart (org.jxmpp.jid.parts.Resourcepart)21 SmackException (org.jivesoftware.smack.SmackException)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)16 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)15 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)6 Presence (org.jivesoftware.smack.packet.Presence)6 Jid (org.jxmpp.jid.Jid)6 Message (org.jivesoftware.smack.packet.Message)5 ArrayList (java.util.ArrayList)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)4 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)4 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)4 UserJid (com.xabber.android.data.entity.UserJid)3 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2