org.jivesoftware.smackx.carbons.packet.CarbonExtension Java Examples

The following examples show how to use org.jivesoftware.smackx.carbons.packet.CarbonExtension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OmemoManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * CarbonCopyListener that listens for incoming carbon copies which contain OMEMO elements.
 */
private void internalOmemoCarbonCopyListener(final CarbonExtension.Direction direction,
                final Message carbonCopy,
                final Message wrappingMessage) {
    Async.go(new Runnable() {
        @Override
        public void run() {
            if (isOmemoMessage(carbonCopy)) {
                try {
                    getOmemoService().onOmemoCarbonCopyReceived(direction, carbonCopy, wrappingMessage,
                            new LoggedInOmemoManager(OmemoManager.this));
                } catch (SmackException.NotLoggedInException | IOException e) {
                    LOGGER.log(Level.SEVERE, "Exception while processing OMEMO stanza", e);
                }
            }
        }
    });
}
 
Example #2
Source File: CarbonManagerProvider.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public CarbonExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    Direction dir = Direction.valueOf(parser.getName());
    Forwarded fwd = null;

    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getName().equals("forwarded")) {
            fwd = FORWARDED_PROVIDER.parse(parser);
        }
        else if (eventType == XmlPullParser.Event.END_ELEMENT && dir == Direction.valueOf(parser.getName()))
            done = true;
    }
    if (fwd == null) {
        // TODO: Should be SmackParseException.
        throw new IOException("sent/received must contain exactly one <forwarded> tag");
    }
    return new CarbonExtension(dir, fwd);
}
 
Example #3
Source File: CarbonTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Test
public void carbonReceivedTest() throws Exception {
    XmlPullParser parser;
    String control;
    CarbonExtension cc;

    control = XMLBuilder.create("received")
        .e("forwarded")
            .a("xmlns", "urn:xmpp:forwarded:0")
            .e("message")
                .a("from", "[email protected]")
        .asString(outputProperties);

    parser = PacketParserUtils.getParserFor(control);
    cc = new CarbonManagerProvider().parse(parser);

    assertEquals(CarbonExtension.Direction.received, cc.getDirection());

    // check end of tag
    assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
    assertEquals("received", parser.getName());
}
 
Example #4
Source File: CarbonTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void carbonSentTest() throws Exception {
    XmlPullParser parser;
    String control;
    CarbonExtension cc;
    Forwarded fwd;

    control = XMLBuilder.create("sent")
        .e("forwarded")
            .a("xmlns", "urn:xmpp:forwarded:0")
            .e("message")
                .a("from", "[email protected]")
        .asString(outputProperties);

    parser = PacketParserUtils.getParserFor(control);
    cc = new CarbonManagerProvider().parse(parser);
    fwd = cc.getForwarded();

    // meta
    assertEquals(CarbonExtension.Direction.sent, cc.getDirection());

    // no delay in packet
    assertEquals(null, fwd.getDelayInformation());

    // check message
    assertEquals("[email protected]", fwd.getForwardedStanza().getFrom().toString());

    // check end of tag
    assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
    assertEquals("sent", parser.getName());
}
 
Example #5
Source File: OmemoMessageListener.java    From Smack with Apache License 2.0 4 votes vote down vote up
void onOmemoCarbonCopyReceived(CarbonExtension.Direction direction,
Message carbonCopy,
Message wrappingMessage,
OmemoMessage.Received decryptedCarbonCopy);
 
Example #6
Source File: OmemoCarbonCopyStanzaReceivedListener.java    From Smack with Apache License 2.0 4 votes vote down vote up
void onOmemoCarbonCopyReceived(CarbonExtension.Direction direction, Message carbonCopy, Message wrappingMessage,
OmemoManager.LoggedInOmemoManager omemoManager) throws IOException;
 
Example #7
Source File: AbstractOmemoMessageListener.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public void onOmemoCarbonCopyReceived(CarbonExtension.Direction direction, Message carbonCopy, Message wrappingMessage, OmemoMessage.Received decryptedCarbonCopy) {
    // Override me
}
 
Example #8
Source File: ChatRoomImpl.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a 1-to-1 ChatRoom.
 *
 * Note that the participantJID value can be a bare JID, or a full JID. In regular one-on-one chats, a bare JID is
 * expected. This instance will then display relevant data sent by any of the (full) JIDs associated to the bare JID.
 * When this instance is created to reflect a private message in MUC context, a full JID is expected to be provided
 * as the participantJID value (room@service/nick). In such case, only data sent from that full JID is displayed.
 *
 * @param participantJID      the participants jid to chat with.
 * @param participantNickname the nickname of the participant.
 * @param title               the title of the room.
 */
public ChatRoomImpl(final EntityJid participantJID, Resourcepart participantNickname, CharSequence title, boolean initUi) {
    this.active = true;
    //activateNotificationTime = System.currentTimeMillis();
    setparticipantJID(participantJID);
    this.participantNickname = participantNickname;

    // Loads the current history for this user.
    loadHistory();

    // Register StanzaListeners
    final StanzaFilter directFilter = new AndFilter(
        FromMatchesFilter.create( participantJID ),
        new OrFilter( new StanzaTypeFilter( Presence.class ),
                      new StanzaTypeFilter( Message.class ) )
    );

    final StanzaFilter carbonFilter = new AndFilter(
        FromMatchesFilter.create( SparkManager.getSessionManager().getBareUserAddress() ), // Security Consideration, see https://xmpp.org/extensions/xep-0280.html#security
        new StanzaTypeFilter( Message.class ),
        new OrFilter(
            new StanzaExtensionFilter( "sent", CarbonExtension.NAMESPACE ),
            new StanzaExtensionFilter( "received", CarbonExtension.NAMESPACE )
        )
    );

    SparkManager.getConnection().addSyncStanzaListener( this, new OrFilter( directFilter, carbonFilter ) );

    // Use the agents username as the Tab Title
    this.tabTitle = title.toString();

    // The name of the room will be the node of the user jid + conversation.
    this.roomTitle = participantNickname.toString();

    // Add RoomInfo
    this.getSplitPane().setRightComponent(null);
    getSplitPane().setDividerSize(0);


    presence = PresenceManager.getPresence(participantJID.asBareJid());

    roster = Roster.getInstanceFor( SparkManager.getConnection() );

    RosterEntry entry = roster.getEntry(participantJID.asBareJid());

    tabIcon = PresenceManager.getIconFromPresence(presence);

    if (initUi) {
        // Create toolbar buttons.
        infoButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_24x24));
        infoButton.setToolTipText(Res.getString("message.view.information.about.this.user"));
        // Create basic toolbar.
        addChatRoomButton(infoButton);
        // Show VCard.
        infoButton.addActionListener(this);
    }

    // If this is a private chat from a group chat room, do not show toolbar.
    privateChat = participantNickname.equals(participantJID.getResourceOrNull());
    if ( privateChat ) {
        getToolBar().setVisible(false);
    }

    // If the user is not in the roster, then allow user to add them.
    addToRosterButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.ADD_IMAGE_24x24));
    if (entry == null && !privateChat) {
        addToRosterButton.setToolTipText(Res.getString("message.add.this.user.to.your.roster"));
        if (!Default.getBoolean("ADD_CONTACT_DISABLED") && Enterprise.containsFeature(Enterprise.ADD_CONTACTS_FEATURE)) addChatRoomButton(addToRosterButton);
        addToRosterButton.addActionListener(this);
    }

    lastActivity = System.currentTimeMillis();
}
 
Example #9
Source File: OmemoManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Notify all registered OmemoMessageListeners of an incoming OMEMO encrypted Carbon Copy.
 * Remember: If you want to receive OMEMO encrypted carbon copies, you have to enable carbons using
 * {@link CarbonManager#enableCarbons()}.
 *
 * @param direction             direction of the carbon copy
 * @param carbonCopy            carbon copy itself
 * @param wrappingMessage       wrapping message
 * @param decryptedCarbonCopy   decrypted carbon copy OMEMO element
 */
void notifyOmemoCarbonCopyReceived(CarbonExtension.Direction direction,
                                   Message carbonCopy,
                                   Message wrappingMessage,
                                   OmemoMessage.Received decryptedCarbonCopy) {
    for (OmemoMessageListener l : omemoMessageListeners) {
        l.onOmemoCarbonCopyReceived(direction, carbonCopy, wrappingMessage, decryptedCarbonCopy);
    }
}
 
Example #10
Source File: CarbonManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if XMPP Carbons are supported by the server.
 *
 * @return true if supported
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public boolean isSupportedByServer() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    return ServiceDiscoveryManager.getInstanceFor(connection()).serverSupportsFeature(CarbonExtension.NAMESPACE);
}