Search in sources :

Example 16 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class SimpleSession method contactUnsubscribed.

public void contactUnsubscribed(String targetSipAddress) {
    try {
        //			Roster     roster     = getTransport().getRosterManager().getRoster(getJID().getNode());
        JID contactJID = getTransport().convertIDToJID(targetSipAddress);
        //			RosterItem item       = roster.getRosterItem(contactJID);
        Log.debug("SimpleSession(" + getJID().getNode() + ").contactUnsubscribed:  Preparing presence packet...");
        Presence presence = new Presence();
        presence.setFrom(contactJID);
        presence.setTo(getJID());
        presence.setType(Presence.Type.unsubscribed);
        getTransport().sendPacket(presence);
        Log.debug("SimpleSession(" + getJID().getNode() + ").contactUnsubscribed:  Presence packet sent ==> \n" + presence.toXML());
    //			Log.debug("SimpleSession(" + jid.getNode() + ").contactUnsubscribed:  Synchronizing SIP user roster...");
    //			String rosteruserid = ((SimpleTransport) transport).convertJIDToID(item.getJid());
    //			myRoster.removeEntry(rosteruserid);
    //			Log.debug("SimpleSession(" + jid.getNode() + ").contactUnsubscribed:  Finished synchronizing SIP user roster.");
    //			syncContactGroups(contact, item.getGroups());
    } catch (Exception e) {
        Log.debug("SimpleSession(" + getJID().getNode() + ").contactUnsubscribed:  Exception occured when adding pending contact " + targetSipAddress, e);
    //			JID contactJID = getTransport().convertIDToJID(targetSipAddress);
    }
}
Also used : JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 17 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class SimpleSession method contactSubscribed.

//	private Request prepareNotifyRequest(Dialog dialog, SimplePresence simplePresence) throws ParseException {
//		Request request = prepareNotifyRequest(dialog);
//		request.setContent(simplePresence.toXML(), headerFactory.createContentTypeHeader("application", "pidf+xml"));
//
//		return request;
//	}
public void contactSubscribed(String targetSipAddress) {
    try {
        //			Roster     roster     = getTransport().getRosterManager().getRoster(getJID().getNode());
        JID contactJID = getTransport().convertIDToJID(targetSipAddress);
        //            RosterItem item       = roster.getRosterItem(contactJID);
        Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed:  Preparing presence packet...");
        Presence presence = new Presence();
        presence.setFrom(contactJID);
        presence.setTo(getJID());
        presence.setType(Presence.Type.subscribed);
        getTransport().sendPacket(presence);
        Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed:  Presence packet sent ==> \n" + presence.toXML());
    //			Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed:  Synchronizing SIP user roster...");
    //			String rosteruserid = ((SimpleTransport) transport).convertJIDToID(item.getJid());
    //			if (myRoster.getEntry(rosteruserid) == null) {
    //				SimpleBuddy simpleRosterItem = new SimpleBuddy(rosteruserid, item.getNickname(), 1L);
    //				myRoster.addEntry(rosteruserid, simpleRosterItem);
    //			}
    //			Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed:  Finished synchronizing SIP user roster.");
    //			syncContactGroups(contact, item.getGroups());
    } catch (Exception e) {
        Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed:  Exception occured when adding pending contact " + targetSipAddress, e);
    //			JID contactJID = getTransport().convertIDToJID(targetSipAddress);
    }
}
Also used : JID(org.xmpp.packet.JID) Presence(org.xmpp.packet.Presence) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 18 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class SSIHierarchy method gotBuddy.

/**
     * We've been told about a buddy that exists on the buddy list.
     * 
     * @param buddyItem
     *            the buddy we've been told about.
     */
public void gotBuddy(BuddyItem buddyItem) {
    updateHighestId(buddyItem);
    final TransportBuddyManager<OSCARBuddy> buddyManager = parent.getBuddyManager();
    try {
        final JID jid = parent.getTransport().convertIDToJID(buddyItem.getScreenname());
        final OSCARBuddy oscarBuddy = buddyManager.getBuddy(jid);
        oscarBuddy.tieBuddyItem(buddyItem, false);
    } catch (NotFoundException ee) {
        final OSCARBuddy oscarBuddy = new OSCARBuddy(buddyManager, buddyItem);
        buddyManager.storeBuddy(oscarBuddy);
    }
}
Also used : JID(org.xmpp.packet.JID) NotFoundException(org.jivesoftware.util.NotFoundException)

Example 19 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class SSIHierarchy method syncContactGroupsAndNickname.

/**
     * Synchronizes the basic characteristics of one contact, including:
     * <ul>
     * <li>the list of groups a contact is a member of</li>
     * <li>nicknames</li>
     * </ul>
     * 
     * As an OSCAR contact must be in at least one group, a default group is
     * used if the provided group list is empty or <tt>null</tt>.
     * 
     * @param contact
     *            Screen name/UIN of the contact.
     * @param nickname
     *            Nickname of the contact (should not be <tt>null</tt>)
     * @param grouplist
     *            List of groups the contact should be a member of.
     * @see SSIHierarchy#getDefaultGroup()
     */
public void syncContactGroupsAndNickname(String contact, String nickname, List<String> grouplist) {
    if (grouplist == null) {
        grouplist = new ArrayList<String>();
    }
    if (grouplist.isEmpty()) {
        Log.debug("No groups provided for the sync of contact " + contact + ". Using default group.");
        grouplist.add(getDefaultGroup());
    }
    Log.debug("Syncing contact = " + contact + ", nickname = " + nickname + ", grouplist = " + grouplist);
    OSCARBuddy oscarBuddy = null;
    try {
        final JID jid = parent.getTransport().convertIDToJID(contact);
        oscarBuddy = parent.getBuddyManager().getBuddy(jid);
        Log.debug("Found related oscarbuddy: " + oscarBuddy);
    } catch (NotFoundException e) {
        Log.debug("Didn't find related oscarbuddy. One will be created.");
    }
    //TODO: Should we do a premodcmd here and postmodcmd at the end and not have separate ones?
    // Stored 'removed' list of buddy items for later use
    final List<BuddyItem> freeBuddyItems = new ArrayList<BuddyItem>();
    // We'll keep the buddy items around for potential modification instead of deletion.
    if (oscarBuddy != null) {
        for (BuddyItem buddy : oscarBuddy.getBuddyItems()) {
            //                if (buddy.getScreenname().equalsIgnoreCase(contact)) {
            if (!groups.containsKey(buddy.getGroupId())) {
                // Well this is odd, a group we don't know about?  Nuke it.
                Log.debug("Removing " + buddy + " because of unknown group");
                freeBuddyItems.add(buddy);
            //                        request(new DeleteItemsCmd(buddy.toSsiItem()));
            //                        oscarBuddy.removeBuddyItem(buddy.getGroupId(), true);
            } else if (!grouplist.contains(groups.get(buddy.getGroupId()).getGroupName())) {
                Log.debug("Removing " + buddy + " because not in list of groups");
                freeBuddyItems.add(buddy);
            //                        request(new DeleteItemsCmd(buddy.toSsiItem()));
            //                        oscarBuddy.removeBuddyItem(buddy.getGroupId(), true);
            } else {
                // nothing to delete? lets update Aliases then.
                if (buddy.getAlias() == null || !buddy.getAlias().equals(nickname)) {
                    Log.debug("Updating alias for " + buddy);
                    buddy.setAlias(nickname);
                    request(new PreModCmd());
                    request(new ModifyItemsCmd(buddy.toSsiItem()));
                    request(new PostModCmd());
                    updateHighestId(buddy);
                    oscarBuddy.tieBuddyItem(buddy, true);
                }
            }
        //                }
        }
    }
    // Now, lets take the known good list of groups and add whatever is missing on the server.
    for (String group : grouplist) {
        Integer groupId = getGroupIdOrCreateNew(group);
        if (isMemberOfGroup(groupId, contact)) {
            // Already a member, moving on
            continue;
        }
        Integer newBuddyId = 1;
        if (highestBuddyIdPerGroup.containsKey(groupId)) {
            newBuddyId = getNextBuddyId(groupId);
        }
        if (freeBuddyItems.size() > 0) {
            // Moving a freed buddy item
            // TODO: This isn't working.. why?  Returns RESULT_ID_TAKEN
            //                BuddyItem buddy = freeBuddyItems.remove(0);
            //                if (oscarBuddy != null) {
            //                    oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
            //                }
            //                buddy.setGroupid(groupId);
            //                buddy.setId(newBuddyId);
            //                buddy.setAlias(nickname);
            //                request(new ModifyItemsCmd(buddy.toSsiItem()));
            //                if (oscarBuddy == null) {
            //                    oscarBuddy = new OSCARBuddy(getBuddyManager(), buddy);
            //                    // TODO: translate this
            //                    request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
            //                }
            //                else {
            //                    oscarBuddy.tieBuddyItem(buddy, false);
            //                }
            request(new PreModCmd());
            BuddyItem buddy = freeBuddyItems.remove(0);
            BuddyItem newBuddy = new BuddyItem(buddy);
            newBuddy.setGroupid(groupId);
            newBuddy.setId(newBuddyId);
            newBuddy.setAlias(nickname);
            request(new DeleteItemsCmd(buddy.toSsiItem()));
            if (oscarBuddy != null) {
                oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
            }
            request(new CreateItemsCmd(newBuddy.toSsiItem()));
            if (oscarBuddy == null) {
                oscarBuddy = new OSCARBuddy(parent.getBuddyManager(), newBuddy);
                // TODO: translate this
                request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
            } else {
                oscarBuddy.tieBuddyItem(newBuddy, false);
            }
            request(new PostModCmd());
        } else {
            // Creating a new buddy item
            final BuddyItem newBuddy = new BuddyItem(contact, groupId, newBuddyId);
            newBuddy.setAlias(nickname);
            updateHighestId(newBuddy);
            //  TODO: Should we be doing this for AIM too?
            if (parent.getTransport().getType().equals(TransportType.icq)) {
                newBuddy.setAwaitingAuth(true);
            }
            request(new PreModCmd());
            request(new CreateItemsCmd(newBuddy.toSsiItem()));
            request(new PostModCmd());
            if (oscarBuddy == null) {
                oscarBuddy = new OSCARBuddy(parent.getBuddyManager(), newBuddy);
                // TODO: translate this
                request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
            } else {
                oscarBuddy.tieBuddyItem(newBuddy, true);
            }
        }
    }
    // Now, lets remove any leftover buddy items that we're no longer using.
    for (BuddyItem buddy : freeBuddyItems) {
        request(new DeleteItemsCmd(buddy.toSsiItem()));
        if (oscarBuddy != null) {
            oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
        }
    }
    // Lastly, lets store the final buddy item after we've modified it, making sure to update groups first.
    if (oscarBuddy != null) {
        //            oscarBuddy.populateGroupList();
        parent.getBuddyManager().storeBuddy(oscarBuddy);
    }
}
Also used : DeleteItemsCmd(net.kano.joscar.snaccmd.ssi.DeleteItemsCmd) JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException) BuddyAuthRequest(net.kano.joscar.snaccmd.ssi.BuddyAuthRequest) PostModCmd(net.kano.joscar.snaccmd.ssi.PostModCmd) BuddyItem(net.kano.joscar.ssiitem.BuddyItem) PreModCmd(net.kano.joscar.snaccmd.ssi.PreModCmd) CreateItemsCmd(net.kano.joscar.snaccmd.ssi.CreateItemsCmd) ModifyItemsCmd(net.kano.joscar.snaccmd.ssi.ModifyItemsCmd)

Example 20 with JID

use of org.xmpp.packet.JID in project Openfire by igniterealtime.

the class MSNSession method completedPendingContactAdd.

/**
     * Completes the addition of groups to a new contact after the contact has been created.
     *
     * @param msnContact Contact that was added.
     */
public void completedPendingContactAdd(MsnContact msnContact) {
    try {
        Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
        Email contact = msnContact.getEmail();
        JID contactJID = getTransport().convertIDToJID(contact.toString());
        RosterItem item = roster.getRosterItem(contactJID);
        getBuddyManager().storeBuddy(new MSNBuddy(getBuddyManager(), msnContact));
        syncContactGroups(contact, item.getGroups());
    } catch (UserNotFoundException e) {
        Log.debug("MSN: Unable to find roster when adding pendingcontact for " + getJID());
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Email(net.sf.jml.Email) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID)

Aggregations

JID (org.xmpp.packet.JID)330 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)76 Element (org.dom4j.Element)70 ArrayList (java.util.ArrayList)55 IQ (org.xmpp.packet.IQ)38 Presence (org.xmpp.packet.Presence)38 SQLException (java.sql.SQLException)36 PreparedStatement (java.sql.PreparedStatement)31 Connection (java.sql.Connection)30 Group (org.jivesoftware.openfire.group.Group)30 Date (java.util.Date)28 ResultSet (java.sql.ResultSet)27 Message (org.xmpp.packet.Message)25 GroupJID (org.jivesoftware.openfire.group.GroupJID)23 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)23 NotFoundException (org.jivesoftware.util.NotFoundException)22 Roster (org.jivesoftware.openfire.roster.Roster)21 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)20 RosterItem (org.jivesoftware.openfire.roster.RosterItem)19 User (org.jivesoftware.openfire.user.User)17