Commit 6c78e9a9 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Adding in updated code from Ravin and Patrick.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@7306 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2378b9e4
......@@ -11,12 +11,18 @@
package org.jivesoftware.wildfire.gateway.protocols.simple;
import java.io.ByteArrayInputStream;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.util.Log;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import org.xmpp.packet.Presence;
/**
* This class performs conversions between presence packets of XMPP and SIMPLE formats.
......@@ -166,6 +172,15 @@ public class SimplePresence {
return this.tupleStatus;
}
private String getEightLength(int hash) {
StringBuffer buffer = new StringBuffer(Integer.toHexString(hash));
while (buffer.length() < 8) {
buffer.insert(0, "0");
}
return new String(buffer);
}
public String toXML() {
String result =
......@@ -175,8 +190,13 @@ public class SimplePresence {
" xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid'" +
" xmlns:c='urn:ietf:params:xml:ns:pidf:cipid'" +
" entity='" + entity + "'>" +
"<tuple id='t" + hashCode() + "'><status><basic>" + tupleStatus.toString() + "</basic></status></tuple>" +
"<dm:person id='p" + hashCode() + "'><rpid:activities><rpid:" + rpid.toString() + "/></rpid:activities></dm:person></presence>";
"<tuple id='t" + getEightLength(tupleStatus.hashCode()) + "'><status><basic>" + tupleStatus.toString() + "</basic></status></tuple>" +
"<dm:person id='p" + getEightLength(this.hashCode()) + "'><rpid:activities><rpid:" + rpid.toString() + "/></rpid:activities>" +
// "<tuple><status><basic>" + tupleStatus.toString() + "</basic></status></tuple>" +
// "<dm:person><rpid:activities><rpid:" + rpid.toString() + "/></rpid:activities>" +
((dmNote != null && !dmNote.equals("")) ? "<dm:note>" + dmNote + "</dm:note>" : "") +
"</dm:person>" +
"</presence>";
// DocumentFactory docFactory = DocumentFactory.getInstance();
//
......@@ -205,6 +225,7 @@ public class SimplePresence {
return result;
}
// public Presence convertSIPPresenceToXMPP(String sipPresence) {
// Presence xmppPresence = new Presence();
//
......@@ -344,16 +365,7 @@ public class SimplePresence {
tupleStatus = TupleStatus.getTupleStatus(data);
}
catch (IllegalArgumentException ex) {
// Ignore
}
// if(data.equals("open")) {
// statusType = "online";
// statusName = "Online";
// }
// else {
// statusType = "offline";
// statusName = "Offline";
// }
}
}
else if (isStatusType) {
// statusType = data;
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.gateway.protocols.simple;
import java.util.Hashtable;
import org.jivesoftware.util.Log;
/**
* This class represents the roster of SIP transport.
* <br><br>
* By now the SIP has no rosters stored so clients got to implement rosters themselves.
* @author Patrick Siu
* @version 0.0.2
*/
public class SimpleRoster {
private SimpleSession mySimpleSession;
private Hashtable<String, SimpleRosterItem> rosterItemList;
private boolean activated = false;
public SimpleRoster(SimpleSession mySimpleSession) {
if (mySimpleSession == null)
throw new NullPointerException("The SIP session provided cannot be null!");
this.mySimpleSession = mySimpleSession;
}
public synchronized void activate() {
this.activated = true;
}
public synchronized void deactivate() {
this.activated = false;
}
public void addEntry(String userid, SimpleRosterItem item) {
rosterItemList.put(userid, item);
}
public void removeEntry(String userid) {
rosterItemList.remove(userid);
}
public SimpleRosterItem getEntry(String userid) {
return rosterItemList.get(userid);
}
/**
* Loads the SIP roster from persistent store.
*/
public void loadRoster() {
// Roster should be loaded in persistent stores.
}
/**
* Stores the SIP roster into persistent store.
*/
public void storeRoster() {
// Roster should be stored in persistent stores.
}
public void finalize() {
Log.debug("SimpleRoster shutting down!");
rosterItemList.clear();
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.gateway.protocols.simple;
import javax.sip.Dialog;
/**
* This class represents a roster item of SIP transport.
*/
public class SimpleRosterItem {
private String userid;
private String nickname;
private SimplePresence presence;
private Dialog outgoingDialog;
private long seqNum;
public SimpleRosterItem(String userid, String nickname, long seqNum) {
this.userid = userid;
this.nickname = nickname;
this.seqNum = seqNum;
presence = new SimplePresence();
presence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
outgoingDialog = null;
}
public void incrementSeqNum() {
seqNum++;
}
public long getSeqNum() {
return seqNum;
}
public void updatePresence(String newPresence) throws Exception {
presence.parse(newPresence);
}
public void setOutgoingDialog(Dialog outgoingDialog) {
this.outgoingDialog = outgoingDialog;
}
public Dialog getOutgoingDialog() {
return outgoingDialog;
}
}
\ No newline at end of file
......@@ -10,14 +10,31 @@
package org.jivesoftware.wildfire.gateway.protocols.simple;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;
import java.util.TooManyListenersException;
import javax.sip.InvalidArgumentException;
import javax.sip.ListeningPoint;
import javax.sip.ObjectInUseException;
import javax.sip.PeerUnavailableException;
import javax.sip.SipFactory;
import javax.sip.SipProvider;
import javax.sip.SipStack;
import javax.sip.TransportNotSupportedException;
import javax.sip.address.AddressFactory;
import javax.sip.header.HeaderFactory;
import javax.sip.message.MessageFactory;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.TransportLoginStatus;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
/**
* A transport implementation for SIMPLE protocol.
......@@ -47,12 +64,15 @@ public class SimpleTransport extends BaseTransport {
public void registrationLoggedOut(TransportSession session) {
((SimpleSession) session).logout();
((SimpleSession) session).removeStack();
session.sessionDone();
// Just in case.
// session.setLoginStatus(TransportLoginStatus.LOGGED_OUT);
session.setLoginStatus(TransportLoginStatus.LOGGED_OUT);
}
/**
*/
public String getTerminologyUsername() {
return LocaleUtils.getLocalizedString("gateway.sip.username", "gateway");
}
......@@ -60,41 +80,180 @@ public class SimpleTransport extends BaseTransport {
public String getTerminologyPassword() {
return LocaleUtils.getLocalizedString("gateway.sip.password", "gateway");
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#getTerminologyNickname()
*/
public String getTerminologyNickname() {
// If this string is needed, then take it. Just put a draft code to ensure integrity.
return null;
String result = null;
return result;
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#getTerminologyRegistration()
*/
public String getTerminologyRegistration() {
return LocaleUtils.getLocalizedString("gateway.sip.registration", "gateway");
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isPasswordRequired()
*/
public Boolean isPasswordRequired() {
// Just put a draft code to ensure integrity.
return true;
Boolean result = true;
return result;
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isNicknameRequired()
*/
public Boolean isNicknameRequired() {
// Just put a draft code to ensure integrity.
return false;
Boolean result = false;
return result;
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isUsernameValid(String)
*/
public Boolean isUsernameValid(String username) {
// Just put a draft code to ensure integrity.
return username.matches("\\w+");
Log.debug("SimpleTransport.isUsernameValid: Checking '" + username + "'");
// Boolean result = username.matches("\\w+");
Boolean result = username.matches("[^ \\p{Cntrl}()@,;:\\\\\"\\[\\]]+@[^ \\p{Cntrl}()@,;:\\\\\"\\[\\]]+");
return result;
}
// The following code are generic custom classes for SIP-XMPP conversion.
public void convertJabStatusToSIP(PresenceType jabStatus) {
public SimplePresence convertJabStatusToSIP(PresenceType jabStatus) {
SimplePresence simplePresence = new SimplePresence();
switch (jabStatus) {
case available:
// simplePresence.setRpid(SimplePresence.Rpid.UNKNOWN);
simplePresence.setDmNote("Online");
break;
case away:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
case chat:
simplePresence.setRpid(SimplePresence.Rpid.OTHER);
simplePresence.setDmNote("Free to chat");
break;
case dnd:
simplePresence.setRpid(SimplePresence.Rpid.BUSY);
break;
case unavailable:
simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
break;
case unknown:
simplePresence.setRpid(SimplePresence.Rpid.UNKNOWN);
break;
case xa:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
default:
break;
}
return simplePresence;
}
public void convertSIPStatusToJap() {
public void convertSIPStatusToJap(Presence presence, SimplePresence simplePresence) {
if (simplePresence.getTupleStatus().isOpen()) {
switch (simplePresence.getRpid()) {
case APPOINTMENT:
presence.setShow(Presence.Show.dnd);
break;
case AWAY:
presence.setShow(Presence.Show.away);
break;
case BREAKFAST:
presence.setShow(Presence.Show.xa);
break;
case BUSY:
presence.setShow(Presence.Show.dnd);
break;
case DINNER:
presence.setShow(Presence.Show.xa);
break;
case HOLIDAY:
presence.setShow(Presence.Show.xa);
break;
case IN_TRANSIT:
presence.setShow(Presence.Show.xa);
break;
case LOOKING_FOR_WORK:
presence.setShow(Presence.Show.dnd);
break;
case LUNCH:
case MEAL:
presence.setShow(Presence.Show.xa);
break;
case MEETING:
presence.setShow(Presence.Show.dnd);
break;
case ON_THE_PHONE:
presence.setShow(Presence.Show.away);
presence.setStatus("On Phone");
break;
case OTHER:
break;
case PERFORMANCE:
presence.setShow(Presence.Show.dnd);
break;
case PERMANENT_ABSENCE:
presence.setType(Presence.Type.unavailable);
break;
case PLAYING:
presence.setShow(Presence.Show.away);
break;
case PRESENTATION:
presence.setShow(Presence.Show.dnd);
break;
case SHOPPING:
presence.setShow(Presence.Show.xa);
break;
case SLEEPING:
presence.setShow(Presence.Show.xa);
break;
case SPECTATOR:
presence.setShow(Presence.Show.xa);
break;
case STEERING:
presence.setShow(Presence.Show.xa);
break;
case TRAVEL:
presence.setShow(Presence.Show.xa);
break;
case TV:
presence.setShow(Presence.Show.away);
break;
case UNKNOWN:
// presence.setType(Presence.Type.unavailable);
break;
case VACATION:
presence.setShow(Presence.Show.xa);
break;
case WORKING:
presence.setShow(Presence.Show.dnd);
break;
case WORSHIP:
presence.setShow(Presence.Show.dnd);
break;
default:
break;
}
}
else {
presence.setType(Presence.Type.unavailable);
}
}
......
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