Commit 3869a1a9 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-761] Added in registration pieces and service discovery response. Removed...

[JM-761] Added in registration pieces and service discovery response.  Removed unused i18n stuff (may add back in future).

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4507 b35dd754-fafc-0310-a699-88a17e54d16e
parent 37646757
invaliduser=Unknown user
\ No newline at end of file
login.title=Admin Console
externalgateway.startup=Started external gateway {0}.
externalgateway.filenotfound=Configuration file {0} not found: {1}
externalgateway.invalidconfig=Invalid configuratino file: {0}
externalgateway.missingconfig=Unable to locate config.properties in classpath. \
Either specify on the command line the config properties or include it in the proper jar file.
externalgateway.invalidcommandline=Invalid command line option. {0}
externalgateway.usingdefaultgateway=Using default gateway "{0}" with secret passphrase "{1}".
externalgateway.addcomponentfailed=Unable to add component. Please ensure that the domain ({0}) is correct and matches the secret phrase ({1}) on the server. Error from server: {2}
persistencemanager.unabletoflush=Unable to flush roster.
persistencemanager.loadrosterfailed=Unable to load roster.
persistencemanager.registrarFinalize=PersistenceManager destroyed.
persistencemanager.nokey=Unable to locate secret key.
persistencemanager.gennewkey=Generating new key.
register.unabletologout=Unable to log out of session: {0}.
basegateway.unknownhost=Unable to determine host for this gateway.
basegateway.domainname=Setting gateway domain to: {0}.
basegateway.dataformnotused=DataForm not used, reverting to IQ level elements.
basegateway.notfound={0} not found.
basegateway.unregister=Unregister {0}.
basegateway.register=Registering user: {0}.
basegateway.unabletofind=Unable to find JID: {0}.
basegateway.unauthorizedrequest=Unauthorized request ({0}) by {1}.
basegateway.unabletolocatesession=Unable to locate GatewaySession for: {0}.
basegateway.subscribed=Subscribed to legacy user.
basegateway.unabletosendpresence=Unable to send presense packet.
basegateway.maintenancestart=Starting maintenance.
basegateway.maintenancestop=Finished maintenance.
basegateway.registerfirst=Please register first.
basegateway.statusexception=Unable to get status from {1} to send to {0}. Error message: {2}
basegateway.gatewaypresence=Gateway presence requested and served.
jabberendpoint.sendpacketenqueue=Enqueue packet from {0}.
yahoogatewaysession.status=YahooGatewaySession status: {0}
yahoogatewaysession.login=[{0}] {1}: logged in.
STATUS_AVAILABLE = "Available";
STATUS_BRB = "Be right back";
STATUS_BUSY = "Busy";
STATUS_NOTATHOME = "Not at home";
STATUS_NOTATDESK = "Not at desk";
STATUS_NOTINOFFICE = "Not in office";
STATUS_ONPHONE = "On the phone";
STATUS_ONVACATION = "On vacation";
STATUS_OUTTOLUNCH = "Out to lunch";
STATUS_STEPPEDOUT = "Stepped out";
STATUS_INVISIBLE = "Invisible";
STATUS_CUSTOM = "<custom>";
STATUS_IDLE = "Zzz";
STATUS_OFFLINE = "Offline";
STATUS_TYPING = "Typing";
...@@ -13,9 +13,16 @@ package org.jivesoftware.wildfire.gateway; ...@@ -13,9 +13,16 @@ package org.jivesoftware.wildfire.gateway;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.xmpp.component.Component; import org.xmpp.component.Component;
import org.xmpp.component.ComponentException; import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManager; import org.xmpp.component.ComponentManager;
...@@ -23,6 +30,7 @@ import org.xmpp.packet.IQ; ...@@ -23,6 +30,7 @@ import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError.Condition;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
/** /**
...@@ -82,6 +90,11 @@ public abstract class BaseTransport implements Component { ...@@ -82,6 +90,11 @@ public abstract class BaseTransport implements Component {
*/ */
public ComponentManager componentManager = null; public ComponentManager componentManager = null;
/**
* Manager component for user rosters.
*/
public final RosterManager rosterManager = new RosterManager();
/** /**
* Type of the transport in question. * Type of the transport in question.
* @see org.jivesoftware.wildfire.gateway.TransportType * @see org.jivesoftware.wildfire.gateway.TransportType
...@@ -239,13 +252,13 @@ public abstract class BaseTransport implements Component { ...@@ -239,13 +252,13 @@ public abstract class BaseTransport implements Component {
} }
if (xmlns.equals(DISCO_INFO)) { if (xmlns.equals(DISCO_INFO)) {
reply.add(handleDiscoInfo(packet)); reply.addAll(handleDiscoInfo(packet));
} }
else if (xmlns.equals(DISCO_ITEMS)) { else if (xmlns.equals(DISCO_ITEMS)) {
reply.add(handleDiscoItems(packet)); reply.addAll(handleDiscoItems(packet));
} }
else if (xmlns.equals(IQ_REGISTER)) { else if (xmlns.equals(IQ_REGISTER)) {
reply.add(handleIQRegister(packet)); reply.addAll(handleIQRegister(packet));
} }
return reply; return reply;
...@@ -257,8 +270,23 @@ public abstract class BaseTransport implements Component { ...@@ -257,8 +270,23 @@ public abstract class BaseTransport implements Component {
* @param packet An IQ packet in the disco info namespace. * @param packet An IQ packet in the disco info namespace.
* @return An IQ packet to be returned to the user. * @return An IQ packet to be returned to the user.
*/ */
private IQ handleDiscoInfo(IQ packet) { private List<Packet> handleDiscoInfo(IQ packet) {
IQ reply = IQ.createResultIQ(packet); List<Packet> reply = new ArrayList<Packet>();
if (packet.getTo().getNode() == null) {
// Requested info from transport itself.
IQ result = IQ.createResultIQ(packet);
Element response = DocumentHelper.createElement(QName.get("query", DISCO_INFO));
response.addElement("identity")
.addAttribute("category", "gateway")
.addAttribute("type", this.transportType.toString())
.addAttribute("name", this.description);
response.addElement("feature")
.addAttribute("var", IQ_REGISTER);
result.setChildElement(response);
reply.add(result);
}
return reply; return reply;
} }
...@@ -268,8 +296,10 @@ public abstract class BaseTransport implements Component { ...@@ -268,8 +296,10 @@ public abstract class BaseTransport implements Component {
* @param packet An IQ packet in the disco items namespace. * @param packet An IQ packet in the disco items namespace.
* @return An IQ packet to be returned to the user. * @return An IQ packet to be returned to the user.
*/ */
private IQ handleDiscoItems(IQ packet) { private List<Packet> handleDiscoItems(IQ packet) {
IQ reply = IQ.createResultIQ(packet); List<Packet> reply = new ArrayList<Packet>();
IQ result = IQ.createResultIQ(packet);
reply.add(result);
return reply; return reply;
} }
...@@ -279,8 +309,135 @@ public abstract class BaseTransport implements Component { ...@@ -279,8 +309,135 @@ public abstract class BaseTransport implements Component {
* @param packet An IQ packet in the iq registration namespace. * @param packet An IQ packet in the iq registration namespace.
* @return An IQ packet to be returned to the user. * @return An IQ packet to be returned to the user.
*/ */
private IQ handleIQRegister(IQ packet) { private List<Packet> handleIQRegister(IQ packet) {
IQ reply = IQ.createResultIQ(packet); List<Packet> reply = new ArrayList<Packet>();
Element remove = packet.getChildElement().element("remove");
if (remove != null) {
// User wants to unregister. =(
// this.convinceNotToLeave() ... kidding.
IQ result = IQ.createResultIQ(packet);
Collection<Registration> registrations = registrationManager.getRegistrations(packet.getFrom(), this.transportType);
// For now, we're going to have to just nuke all of these. Sorry.
for (Registration reg : registrations) {
registrationManager.deleteRegistration(reg);
}
// Tell the end user the transport went byebye.
Presence unavailable = new Presence(Presence.Type.unavailable);
unavailable.setTo(packet.getFrom());
unavailable.setFrom(packet.getTo());
reply.add(unavailable);
// Clean up the user's contact list.
try {
Roster roster = rosterManager.getRoster(packet.getFrom().getNode());
for (RosterItem ri : roster.getRosterItems()) {
if (ri.getJid().getDomain() == this.jid.getDomain()) {
try {
roster.deleteRosterItem(ri.getJid(), false);
}
catch (Exception e) {
Log.error("Error removing roster item: " + ri.toString());
}
}
}
}
catch (UserNotFoundException e) {
Log.error("Error cleaning up contact list of: " + packet.getFrom());
result.setError(Condition.bad_request);
}
reply.add(result);
}
else {
// User wants to register with the transport.
String username = null;
String password = null;
if (packet.getType() == IQ.Type.set) {
Element userEl = packet.getChildElement().element("username");
Element passEl = packet.getChildElement().element("password");
if (userEl != null) {
username = userEl.getTextTrim();
}
if (passEl != null) {
password = passEl.getTextTrim();
}
if (username == null || password == null) {
// Found nothing from stanza, lets yell.
IQ result = IQ.createResultIQ(packet);
result.setError(Condition.bad_request);
reply.add(result);
}
else {
Log.info("Registered " + packet.getFrom() + " as " + username);
IQ result = IQ.createResultIQ(packet);
Element response = DocumentHelper.createElement(QName.get("query", IQ_REGISTER));
result.setChildElement(response);
reply.add(result);
registrationManager.createRegistration(packet.getFrom(), this.transportType, username, password);
try {
Roster roster = rosterManager.getRoster(packet.getFrom().getNode());
try {
RosterItem gwitem = roster.getRosterItem(packet.getTo());
if (gwitem.getSubStatus() != RosterItem.SUB_BOTH) {
gwitem.setSubStatus(RosterItem.SUB_BOTH);
}
if (gwitem.getAskStatus() != RosterItem.ASK_NONE) {
gwitem.setAskStatus(RosterItem.ASK_NONE);
}
roster.updateRosterItem(gwitem);
}
catch (UserNotFoundException e) {
try {
RosterItem gwitem = roster.createRosterItem(packet.getTo(), true);
gwitem.setSubStatus(RosterItem.SUB_BOTH);
gwitem.setAskStatus(RosterItem.ASK_NONE);
roster.updateRosterItem(gwitem);
}
catch (UserAlreadyExistsException ee) {
Log.error("getRosterItem claims user exists, but couldn't find via getRosterItem?");
IQ eresult = IQ.createResultIQ(packet);
eresult.setError(Condition.bad_request);
reply.add(eresult);
}
catch (Exception ee) {
Log.error("createRosterItem caused exception: " + ee.getMessage());
IQ eresult = IQ.createResultIQ(packet);
eresult.setError(Condition.bad_request);
reply.add(eresult);
}
}
}
catch (UserNotFoundException e) {
Log.error("Someone attempted to register with the gateway who is not registered with the server: " + packet.getFrom());
IQ eresult = IQ.createResultIQ(packet);
eresult.setError(Condition.bad_request);
reply.add(eresult);
}
}
}
else if (packet.getType() == IQ.Type.get) {
Element response = DocumentHelper.createElement(QName.get("query", IQ_REGISTER));
IQ result = IQ.createResultIQ(packet);
response.addElement("instruction").addText("Please enter your " + this.getName() + " username and password.");
response.addElement("username");
response.addElement("password");
result.setChildElement(response);
reply.add(result);
}
}
return reply; return reply;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment