Search in sources :

Example 96 with Presence

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

the class SimpleSession method sendNotify.

public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
    Request notifyRequest = prepareNotifyRequest(dialog);
    try {
        User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
        Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
        String presenceContent;
        SimplePresence simplePresence = new SimplePresence();
        simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
        simplePresence.setDmNote(myPresence.getStatus());
        if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
        else {
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
            if (myPresence.getShow() != null) {
                switch(myPresence.getShow()) {
                    case away:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    case dnd:
                        simplePresence.setRpid(SimplePresence.Rpid.BUSY);
                        break;
                    case xa:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    default:
                        break;
                }
            }
        }
        presenceContent = simplePresence.toXML();
        ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
        notifyRequest.setContent(presenceContent, contentTypeHeader);
    } catch (Exception e) {
        Log.debug("Unable to include presence details in the packet.", e);
    }
    sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
Also used : User(org.jivesoftware.openfire.user.User) ContentTypeHeader(javax.sip.header.ContentTypeHeader) Request(javax.sip.message.Request) 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 97 with Presence

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

the class IRCMUCSession method leaveRoom.

@Override
public void leaveRoom() {
    try {
        getSession().getConnection().sendCommand(new PartCommand(roomname));
    } catch (Exception e) {
        Log.debug("IRC: Error while trying to part chat room:", e);
    }
    try {
        autoJoin.disable();
    } catch (Exception e) {
    // Ignore
    }
    autoJoin = null;
    for (String contact : getContacts()) {
        Presence p = new Presence();
        p.setType(Presence.Type.unavailable);
        p.setTo(session.getJID());
        p.setFrom(transport.convertIDToJID(roomname, contact));
        Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
        Element item = elem.addElement("item");
        item.addAttribute("affiliation", "none");
        item.addAttribute("role", "none");
        transport.sendPacket(p);
    }
    Presence p = new Presence();
    p.setType(Presence.Type.unavailable);
    p.setTo(session.getJID());
    p.setFrom(transport.convertIDToJID(roomname, nickname));
    Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
    Element item = elem.addElement("item");
    item.addAttribute("affiliation", "none");
    item.addAttribute("role", "none");
    Element status = elem.addElement("status");
    status.addAttribute("code", "110");
    transport.sendPacket(p);
}
Also used : PartCommand(f00f.net.irc.martyr.commands.PartCommand) Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 98 with Presence

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

the class BaseMUCTransport method processPacket.

/**
     * Handles all incoming presence stanzas.
     *
     * @param packet The presence packet to be processed.
     * @return list of packets that will be sent back to the presence requester.
     */
private List<Packet> processPacket(Presence packet) {
    Log.debug("Received presence packet: " + packet.toXML());
    List<Packet> reply = new ArrayList<Packet>();
    JID from = packet.getFrom();
    JID to = packet.getTo();
    if (packet.getType() == Presence.Type.error) {
        // We don't want to do anything with this.  Ignore it.
        return reply;
    }
    try {
        TransportSession<B> session = getTransport().getSessionManager().getSession(from);
        if (!session.isLoggedIn()) {
            Message m = new Message();
            m.setError(Condition.service_unavailable);
            m.setTo(from);
            m.setFrom(getJID());
            m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
            reply.add(m);
        } else if (to.getNode() == null) {
        // Ignore undirected presence.
        } else if (to.getResource() != null) {
            // Presence to a specific resource.
            if (packet.getType() == Presence.Type.unavailable) {
                // Handle logout.
                try {
                    MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
                    mucSession.leaveRoom();
                    session.getMUCSessionManager().removeSession(to.getNode());
                } catch (NotFoundException e) {
                // Not found?  Well then no problem.
                }
            } else {
                // Handle login.
                try {
                    MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
                    // Active session.
                    mucSession.updateStatus(this.getTransport().getPresenceType(packet));
                } catch (NotFoundException e) {
                    // No current session, lets create one.
                    MUCTransportSession mucSession = createRoom(session, to.getNode(), to.getResource());
                    session.getMUCSessionManager().storeSession(to.getNode(), mucSession);
                    mucSession.enterRoom();
                }
            }
        } else {
            // Presence to the room itself.  Return error as per protocol.
            Presence p = new Presence();
            p.setError(Condition.jid_malformed);
            p.setType(Presence.Type.error);
            p.setTo(from);
            p.setFrom(to);
            reply.add(p);
        }
    } catch (NotFoundException e) {
        Log.debug("Unable to find session.");
        Message m = new Message();
        m.setError(Condition.service_unavailable);
        m.setTo(from);
        m.setFrom(getJID());
        m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
        reply.add(m);
    }
    return reply;
}
Also used : Packet(org.xmpp.packet.Packet) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException) Presence(org.xmpp.packet.Presence)

Example 99 with Presence

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

the class RegistrationHandler method completeRegistration.

public void completeRegistration(TransportSession session) {
    final IQ result = IQ.createResultIQ(session.getRegistrationPacket());
    if (!session.getFailureStatus().equals(ConnectionFailureReason.NO_ISSUE)) {
        // Ooh there was a connection issue, we're going to report that back!
        if (session.getFailureStatus().equals(ConnectionFailureReason.USERNAME_OR_PASSWORD_INCORRECT)) {
            result.setError(Condition.not_authorized);
        } else if (session.getFailureStatus().equals(ConnectionFailureReason.CAN_NOT_CONNECT)) {
            result.setError(Condition.service_unavailable);
        } else if (session.getFailureStatus().equals(ConnectionFailureReason.LOCKED_OUT)) {
            result.setError(Condition.forbidden);
        } else {
            result.setError(Condition.undefined_condition);
        }
        result.setType(IQ.Type.error);
    }
    parent.sendPacket(result);
    session.setRegistrationPacket(null);
    // Lets ask them what their presence is, maybe log them in immediately.
    final Presence p = new Presence(Presence.Type.probe);
    p.setTo(session.getJID());
    p.setFrom(parent.getJID());
    parent.sendPacket(p);
}
Also used : IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Example 100 with Presence

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

the class TransportBuddy method setPresence.

/**
     * Sets the current status.
     *
     * @param newpresence New presence to set to.
     */
public void setPresence(PresenceType newpresence) {
    if (newpresence == null) {
        newpresence = PresenceType.unknown;
    }
    if (newpresence.equals(PresenceType.unavailable)) {
        verboseStatus = "";
    }
    if (!presence.equals(newpresence) && newpresence != PresenceType.unknown) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
        if (!verboseStatus.equals("")) {
            p.setStatus(verboseStatus);
        }
        if (avatarSet && avatar != null) {
            Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
            vcard.addElement("photo").addCDATA(avatar.getXmppHash());
            vcard.addElement("hash").addCDATA(avatar.getXmppHash());
        }
        getManager().sendPacket(p);
    }
    presence = newpresence;
    lastActivityTimestamp = new Date().getTime();
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence) Date(java.util.Date)

Aggregations

Presence (org.xmpp.packet.Presence)109 JID (org.xmpp.packet.JID)38 Element (org.dom4j.Element)34 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)20 Message (org.xmpp.packet.Message)17 IQ (org.xmpp.packet.IQ)16 UpdatePresence (org.jivesoftware.openfire.muc.cluster.UpdatePresence)14 NotFoundException (org.jivesoftware.util.NotFoundException)12 ArrayList (java.util.ArrayList)11 MUCRole (org.jivesoftware.openfire.muc.MUCRole)10 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)9 DefaultElement (org.dom4j.tree.DefaultElement)8 IOException (java.io.IOException)7 SQLException (java.sql.SQLException)7 GroupJID (org.jivesoftware.openfire.group.GroupJID)7 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)7 Date (java.util.Date)6 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)6 ConflictException (org.jivesoftware.openfire.muc.ConflictException)6 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)6