Commit 564df79c authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Applied bulk of patches from George Joseph. Adds ability to have multiple...

Applied bulk of patches from George Joseph.  Adds ability to have multiple groups for one roster item, improved iq registration handling, and minor code tweaks.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4897 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0375bf46
...@@ -204,7 +204,7 @@ public abstract class BaseTransport implements Component { ...@@ -204,7 +204,7 @@ public abstract class BaseTransport implements Component {
// This packet is to the transport itself. // This packet is to the transport itself.
if (packet.getType() == null) { if (packet.getType() == null) {
// User has come online. // User has come online.
TransportSession session = null; TransportSession session;
try { try {
session = sessionManager.getSession(from); session = sessionManager.getSession(from);
...@@ -219,7 +219,7 @@ public abstract class BaseTransport implements Component { ...@@ -219,7 +219,7 @@ public abstract class BaseTransport implements Component {
} }
else if (packet.getType() == Presence.Type.unavailable) { else if (packet.getType() == Presence.Type.unavailable) {
// User has gone offline. // User has gone offline.
TransportSession session = null; TransportSession session;
try { try {
session = sessionManager.getSession(from); session = sessionManager.getSession(from);
if (session.isLoggedIn()) { if (session.isLoggedIn()) {
...@@ -235,7 +235,7 @@ public abstract class BaseTransport implements Component { ...@@ -235,7 +235,7 @@ public abstract class BaseTransport implements Component {
} }
else if (packet.getType() == Presence.Type.probe) { else if (packet.getType() == Presence.Type.probe) {
// Client is asking for presence status. // Client is asking for presence status.
TransportSession session = null; TransportSession session;
try { try {
session = sessionManager.getSession(from); session = sessionManager.getSession(from);
if (session.isLoggedIn()) { if (session.isLoggedIn()) {
...@@ -428,6 +428,8 @@ public abstract class BaseTransport implements Component { ...@@ -428,6 +428,8 @@ public abstract class BaseTransport implements Component {
*/ */
private List<Packet> handleIQRegister(IQ packet) { private List<Packet> handleIQRegister(IQ packet) {
List<Packet> reply = new ArrayList<Packet>(); List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
Element remove = packet.getChildElement().element("remove"); Element remove = packet.getChildElement().element("remove");
if (remove != null) { if (remove != null) {
...@@ -437,15 +439,15 @@ public abstract class BaseTransport implements Component { ...@@ -437,15 +439,15 @@ public abstract class BaseTransport implements Component {
// Tell the end user the transport went byebye. // Tell the end user the transport went byebye.
Presence unavailable = new Presence(Presence.Type.unavailable); Presence unavailable = new Presence(Presence.Type.unavailable);
unavailable.setTo(packet.getFrom()); unavailable.setTo(from);
unavailable.setFrom(packet.getTo()); unavailable.setFrom(to);
reply.add(unavailable); reply.add(unavailable);
try { try {
this.deleteRegistration(packet.getFrom()); this.deleteRegistration(from);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
Log.error("Error cleaning up contact list of: " + packet.getFrom()); Log.error("Error cleaning up contact list of: " + from);
result.setError(Condition.bad_request); result.setError(Condition.bad_request);
} }
...@@ -499,10 +501,10 @@ public abstract class BaseTransport implements Component { ...@@ -499,10 +501,10 @@ public abstract class BaseTransport implements Component {
reply.add(result); reply.add(result);
try { try {
this.addNewRegistration(packet.getFrom(), username, password); this.addNewRegistration(from, username, password);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
Log.error("Someone attempted to register with the gateway who is not registered with the server: " + packet.getFrom()); Log.error("Someone attempted to register with the gateway who is not registered with the server: " + from);
IQ eresult = IQ.createResultIQ(packet); IQ eresult = IQ.createResultIQ(packet);
eresult.setError(Condition.bad_request); eresult.setError(Condition.bad_request);
reply.add(eresult); reply.add(eresult);
...@@ -511,8 +513,8 @@ public abstract class BaseTransport implements Component { ...@@ -511,8 +513,8 @@ public abstract class BaseTransport implements Component {
// Lets ask them what their presence is, maybe log // Lets ask them what their presence is, maybe log
// them in immediately. // them in immediately.
Presence p = new Presence(Presence.Type.probe); Presence p = new Presence(Presence.Type.probe);
p.setTo(packet.getFrom()); p.setTo(from);
p.setFrom(packet.getTo()); p.setFrom(to);
reply.add(p); reply.add(p);
} }
} }
...@@ -534,8 +536,17 @@ public abstract class BaseTransport implements Component { ...@@ -534,8 +536,17 @@ public abstract class BaseTransport implements Component {
passwordField.setType(FormField.Type.text_private); passwordField.setType(FormField.Type.text_private);
response.addElement("instructions").addText("Please enter your " + this.getName() + " username and password."); response.addElement("instructions").addText("Please enter your " + this.getName() + " username and password.");
Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType);
if (registrations.iterator().hasNext()) {
Registration registration = registrations.iterator().next();
response.addElement("registered");
response.addElement("username").addText(registration.getUsername());
response.addElement("password").addText(registration.getPassword());
}
else {
response.addElement("username"); response.addElement("username");
response.addElement("password"); response.addElement("password");
}
result.setChildElement(response); result.setChildElement(response);
...@@ -702,10 +713,10 @@ public abstract class BaseTransport implements Component { ...@@ -702,10 +713,10 @@ public abstract class BaseTransport implements Component {
* @param userjid JID of user to have item added to their roster. * @param userjid JID of user to have item added to their roster.
* @param contactjid JID to add to roster. * @param contactjid JID to add to roster.
* @param nickname Nickname of item. (can be null) * @param nickname Nickname of item. (can be null)
* @param group Group item is to be placed in. (can be null) * @param groups List of group the item is to be placed in. (can be null)
* @throws UserNotFoundException if userjid not found. * @throws UserNotFoundException if userjid not found.
*/ */
public void addOrUpdateRosterItem(JID userjid, JID contactjid, String nickname, String group) throws UserNotFoundException { public void addOrUpdateRosterItem(JID userjid, JID contactjid, String nickname, ArrayList<String> groups) throws UserNotFoundException {
try { try {
Roster roster = rosterManager.getRoster(userjid.getNode()); Roster roster = rosterManager.getRoster(userjid.getNode());
try { try {
...@@ -719,13 +730,11 @@ public abstract class BaseTransport implements Component { ...@@ -719,13 +730,11 @@ public abstract class BaseTransport implements Component {
gwitem.setAskStatus(RosterItem.ASK_NONE); gwitem.setAskStatus(RosterItem.ASK_NONE);
changed = true; changed = true;
} }
if (!gwitem.getNickname().equals(nickname)) { if (nickname != null && !gwitem.getNickname().equals(nickname)) {
gwitem.setNickname(nickname); gwitem.setNickname(nickname);
changed = true; changed = true;
} }
List<String> curgroups = gwitem.getGroups(); List<String> curgroups = gwitem.getGroups();
List<String> groups = new ArrayList<String>();
groups.add(group);
if (curgroups != groups) { if (curgroups != groups) {
try { try {
gwitem.setGroups(groups); gwitem.setGroups(groups);
...@@ -745,8 +754,6 @@ public abstract class BaseTransport implements Component { ...@@ -745,8 +754,6 @@ public abstract class BaseTransport implements Component {
gwitem.setSubStatus(RosterItem.SUB_BOTH); gwitem.setSubStatus(RosterItem.SUB_BOTH);
gwitem.setAskStatus(RosterItem.ASK_NONE); gwitem.setAskStatus(RosterItem.ASK_NONE);
gwitem.setNickname(nickname); gwitem.setNickname(nickname);
List<String> groups = new ArrayList<String>();
groups.add(group);
try { try {
gwitem.setGroups(groups); gwitem.setGroups(groups);
} }
...@@ -770,6 +777,26 @@ public abstract class BaseTransport implements Component { ...@@ -770,6 +777,26 @@ public abstract class BaseTransport implements Component {
} }
} }
/**
* Either updates or adds a JID to a user's roster.
*
* Tries to only edit the roster if it has to.
*
* @param userjid JID of user to have item added to their roster.
* @param contactjid JID to add to roster.
* @param nickname Nickname of item. (can be null)
* @param group Group item is to be placed in. (can be null)
* @throws UserNotFoundException if userjid not found.
*/
public void addOrUpdateRosterItem(JID userjid, JID contactjid, String nickname, String group) throws UserNotFoundException {
ArrayList<String> groups = null;
if (group != null) {
groups = new ArrayList<String>();
groups.add(group);
}
addOrUpdateRosterItem(userjid, contactjid, nickname, groups);
}
/** /**
* Either updates or adds a contact to a user's roster. * Either updates or adds a contact to a user's roster.
* *
...@@ -966,7 +993,7 @@ public abstract class BaseTransport implements Component { ...@@ -966,7 +993,7 @@ public abstract class BaseTransport implements Component {
try { try {
Roster roster = rosterManager.getRoster(jid.getNode()); Roster roster = rosterManager.getRoster(jid.getNode());
for (RosterItem ri : roster.getRosterItems()) { for (RosterItem ri : roster.getRosterItems()) {
if (ri.getJid().getDomain() == this.jid.getDomain()) { if (ri.getJid().getDomain().equals(this.jid.getDomain())) {
try { try {
roster.deleteRosterItem(ri.getJid(), false); roster.deleteRosterItem(ri.getJid(), false);
} }
......
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