Search in sources :

Example 6 with IQ

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

the class SipComponent method processIQ.

private void processIQ(IQ iq) {
    IQ reply = IQ.createResultIQ(iq);
    String namespace = iq.getChildElement().getNamespaceURI();
    Element childElement = iq.getChildElement().createCopy();
    reply.setChildElement(childElement);
    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return service identity and features
            Element identity = childElement.addElement("identity");
            identity.addAttribute("category", "component");
            identity.addAttribute("type", "generic");
            identity.addAttribute("name", "SIP Controller");
            childElement.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            childElement.addElement("feature").addAttribute("var", "http://www.jivesoftware.com/protocol/sipark");
        }
    } else if (NAMESPACE.equals(namespace)) {
        if (iq.getTo().getNode() == null && iq.getFrom() != null) {
            SipAccount sipAccount = SipAccountDAO.getAccountByUser(iq.getFrom().toBareJID().split("@")[0]);
            if (iq.getChildElement().element("status") == null) {
                if (sipAccount != null && sipAccount.isEnabled()) {
                    // There is a SIP mapping for this user so return mapping information
                    Element registration = childElement.addElement("registration");
                    registration.addElement("jid").setText(sipAccount.getUsername() + "@" + componentManager.getServerName());
                    registration.addElement("username").setText(sipAccount.getSipUsername());
                    registration.addElement("authUsername").setText(sipAccount.getAuthUsername());
                    registration.addElement("displayPhoneNum").setText(sipAccount.getDisplayName());
                    registration.addElement("password").setText(sipAccount.getPassword());
                    registration.addElement("server").setText(sipAccount.getServer());
                    registration.addElement("stunServer").setText(sipAccount.getStunServer());
                    registration.addElement("stunPort").setText(sipAccount.getStunPort());
                    registration.addElement("useStun").setText(String.valueOf(sipAccount.isUseStun()));
                    registration.addElement("voicemail").setText(sipAccount.getVoiceMailNumber());
                    registration.addElement("enabled").setText(String.valueOf(sipAccount.isEnabled()));
                    registration.addElement("outboundproxy").setText(sipAccount.getOutboundproxy());
                    registration.addElement("promptCredentials").setText(String.valueOf(sipAccount.isPromptCredentials()));
                } else {
                    // No SIP mapping was found
                    reply.getChildElement().addAttribute("type", "unregistered");
                }
            } else {
                if (sipAccount != null) {
                    Element status = iq.getChildElement().element("status");
                    if (!status.getTextTrim().equals("")) {
                        sipAccount.setStatus(SipRegisterStatus.valueOf(status.getTextTrim()));
                        try {
                            SipAccountDAO.update(sipAccount);
                        } catch (SQLException e) {
                            Log.error(e.getMessage(), e);
                        }
                    }
                }
            }
        }
    } else {
        // Answer an error since the server can't handle the requested
        // namespace
        reply.setError(PacketError.Condition.service_unavailable);
    }
    try {
        componentManager.sendPacket(this, reply);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
    Log.debug("PACKET SENT: " + reply.toXML());
}
Also used : SQLException(java.sql.SQLException) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) SQLException(java.sql.SQLException)

Example 7 with IQ

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

the class RegistrationHandler method handleDeregister.

/**
     * Processes an IQ-register request that is expressing the wish to
     * deregister from a gateway.
     *
     * @param packet the IQ-register stanza.
     */
private void handleDeregister(final IQ packet) {
    final IQ result = IQ.createResultIQ(packet);
    if (packet.getChildElement().elements().size() != 1) {
        Log.debug("Cannot process this stanza - exactly one" + " childelement of <remove> expected:" + packet.toXML());
        final IQ error = IQ.createResultIQ(packet);
        error.setError(Condition.bad_request);
        parent.sendPacket(error);
        return;
    }
    final JID from = packet.getFrom();
    final JID to = packet.getTo();
    // Tell the end user the transport went byebye.
    final Presence unavailable = new Presence(Presence.Type.unavailable);
    unavailable.setTo(from);
    unavailable.setFrom(to);
    this.parent.sendPacket(unavailable);
    try {
        deleteRegistration(from);
    } catch (UserNotFoundException e) {
        Log.debug("Error cleaning up contact list of: " + from);
        result.setError(Condition.registration_required);
    }
    parent.sendPacket(result);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Example 8 with IQ

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

the class BaseMUCTransport method sendRooms.

/**
     * Sends a list of rooms as a response to a service discovery request.
     *
     * @param to JID we will be sending the response to.
     * @param rooms List of MUCTransportRoom objects to send as a response.
     */
public void sendRooms(JID to, Collection<MUCTransportRoom> rooms) {
    IQ request = getPendingRequest(to, this.getJID(), NameSpace.DISCO_ITEMS);
    if (request != null) {
        IQ result = IQ.createResultIQ(request);
        Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_ITEMS));
        for (MUCTransportRoom room : rooms) {
            Element item = response.addElement("item");
            item.addAttribute("jid", room.getJid().toBareJID());
            item.addAttribute("name", room.getName());
        }
        result.setChildElement(response);
        this.sendPacket(result);
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 9 with IQ

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

the class BaseMUCTransport method expirePendingRequest.

/**
     * Expires a pending request.
     *
     * @param request The request that will be expired
     */
public void expirePendingRequest(IQ request) {
    IQ result = IQ.createResultIQ(request);
    result.setError(PacketError.Condition.remote_server_timeout);
    getTransport().sendPacket(result);
    pendingIQRequests.remove(request);
}
Also used : IQ(org.xmpp.packet.IQ)

Example 10 with IQ

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

the class IQListHandler method handleIQ.

public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ reply = IQ.createResultIQ(packet);
    ListRequest listRequest = new ListRequest(packet.getChildElement());
    JID from = packet.getFrom();
    Element listElement = reply.setChildElement("list", NAMESPACE);
    Collection<Conversation> conversations = list(from, listRequest);
    XmppResultSet resultSet = listRequest.getResultSet();
    for (Conversation conversation : conversations) {
        addChatElement(listElement, conversation);
    }
    if (resultSet != null) {
        listElement.add(resultSet.createResultElement());
    }
    return reply;
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Conversation(com.reucon.openfire.plugin.archive.model.Conversation) XmppResultSet(com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)

Aggregations

IQ (org.xmpp.packet.IQ)208 Element (org.dom4j.Element)141 JID (org.xmpp.packet.JID)49 PacketError (org.xmpp.packet.PacketError)35 Presence (org.xmpp.packet.Presence)19 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)18 Message (org.xmpp.packet.Message)17 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)16 ClientSession (org.jivesoftware.openfire.session.ClientSession)14 DataForm (org.xmpp.forms.DataForm)13 ArrayList (java.util.ArrayList)11 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)10 Packet (org.xmpp.packet.Packet)10 PacketException (org.jivesoftware.openfire.PacketException)9 User (org.jivesoftware.openfire.user.User)8 List (java.util.List)7 PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)7 Iterator (java.util.Iterator)6 Test (org.junit.Test)6 FormField (org.xmpp.forms.FormField)6