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());
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations