Adds jabber version XEP-0092: Software Version.

cusax-fix
Damian Minkov 14 years ago
parent 9a0572e7f2
commit ae8f43fd76

@ -18,6 +18,7 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.service.googlecontacts.*;
import net.java.sip.communicator.service.version.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
@ -104,6 +105,12 @@ public class JabberActivator
*/
private static GoogleContactsService googleService = null;
/**
* A reference to the currently valid <tt>VersionService</tt>
* instance.
*/
private static VersionService versionService = null;
/**
* Called when this bundle is started so the Framework can perform the
* bundle-specific activities necessary to start this bundle.
@ -387,4 +394,26 @@ public static GoogleContactsService getGoogleService()
}
return googleService;
}
/**
* Returns a reference to a VersionService implementation currently
* registered in the bundle context or null if no such implementation
* was found.
*
* @return a reference to a VersionService implementation currently
* registered in the bundle context or null if no such implementation
* was found.
*/
public static VersionService getVersionService()
{
if(versionService == null)
{
ServiceReference versionServiceReference
= bundleContext.getServiceReference(
VersionService.class.getName());
versionService = (VersionService)bundleContext
.getService(versionServiceReference);
}
return versionService;
}
}

@ -18,6 +18,7 @@
import net.java.sip.communicator.impl.protocol.jabber.extensions.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.cobri.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.keepalive.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.version.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.jabberconstants.*;
@ -366,6 +367,11 @@ enum ConnectState
*/
private KeepAliveManager keepAliveManager = null;
/**
* The version manager.
*/
private VersionManager versionManager = null;
/**
* Returns the state of the registration of this protocol provider
* @return the <tt>RegistrationState</tt> that this provider is
@ -1719,6 +1725,10 @@ protected void initialize(String screenname,
OperationSetGenericNotifications.class,
new OperationSetGenericNotificationsJabberImpl(this));
supportedFeatures.add("jabber:iq:version");
if(versionManager == null)
versionManager = new VersionManager(this);
isInitialized = true;
}
}

@ -1,65 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.version;
import org.jivesoftware.smack.packet.*;
/**
* EXtension providing application version
*
* @author Damian Minkov
*/
public class Version
implements PacketExtension
{
/**
* Element name.
*/
public static final String ELEMENT_NAME = "c";
/**
* Namespace.
*/
public static final String NAMESPACE = "http://jabber.org/protocol/caps";
/**
* Returns the root element name.
*
* @return the element name.
*/
public String getElementName()
{
return ELEMENT_NAME;
}
/**
* Returns the root element XML namespace.
*
* @return the namespace.
*/
public String getNamespace()
{
return NAMESPACE;
}
/**
* Returns the XML reppresentation of the PacketExtension.
*
* @return the packet extension as XML.
*/
public String toXML()
{
StringBuffer buf = new StringBuffer();
buf.append("<").append(getElementName()).
append(" xmlns=\"").append(getNamespace()).append("\"").
append(" node=\"http://jitsi.org\"").
append(" ver=\"").
append(System.getProperty("sip-communicator.version")).
append("\"/>");
return buf.toString();
}
}

@ -0,0 +1,34 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.version;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.xmlpull.v1.*;
/**
* XEP-0092: Software Version.
*
* @author Damian Minkov
*/
public class VersionIQProvider
implements IQProvider
{
/**
* Creates empty Version packet to register the request.
*
* @param parser the parser.
* @return the new packet.
* @throws Exception if
*/
public IQ parseIQ(XmlPullParser parser)
throws
Exception
{
return new org.jivesoftware.smackx.packet.Version();
}
}

@ -0,0 +1,99 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.version;
import net.java.sip.communicator.impl.protocol.jabber.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.version.Version;
import net.java.sip.communicator.service.protocol.event.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
/**
* XEP-0092: Software Version.
* Provider that fills the version IQ using our Version Service.
*
* @author Damian Minkov
*/
public class VersionManager
implements RegistrationStateChangeListener,
PacketListener
{
/**
* Our parent provider.
*/
private ProtocolProviderServiceJabberImpl parentProvider = null;
/**
* Creates and registers the provider.
* @param parentProvider
*/
public VersionManager(ProtocolProviderServiceJabberImpl parentProvider)
{
this.parentProvider = parentProvider;
this.parentProvider.addRegistrationStateChangeListener(this);
ProviderManager.getInstance().addIQProvider(
"query",
"jabber:iq:version",
new VersionIQProvider());
}
/**
* The method is called by a ProtocolProvider implementation whenever
* a change in the registration state of the corresponding provider had
* occurred.
* @param evt ProviderStatusChangeEvent the event describing the status
* change.
*/
public void registrationStateChanged(RegistrationStateChangeEvent evt)
{
if (evt.getNewState() == RegistrationState.REGISTERED)
{
parentProvider.getConnection().removePacketListener(this);
parentProvider.getConnection().addPacketListener(this,
new AndFilter(new IQTypeFilter(IQ.Type.GET),
new PacketTypeFilter(
org.jivesoftware.smackx.packet.Version.class)));
}
else if(evt.getNewState() == RegistrationState.UNREGISTERED
|| evt.getNewState() == RegistrationState.CONNECTION_FAILED
|| evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED)
{
if(parentProvider.getConnection() != null)
parentProvider.getConnection().removePacketListener(this);
}
}
/**
* A packet Listener for incoming Version packets.
* @param packet an incoming packet
*/
public void processPacket(Packet packet)
{
// send packet
org.jivesoftware.smackx.packet.Version versionIQ =
new org.jivesoftware.smackx.packet.Version();
versionIQ.setType(IQ.Type.RESULT);
versionIQ.setTo(packet.getFrom());
versionIQ.setFrom(packet.getTo());
versionIQ.setPacketID(packet.getPacketID());
Version ver = JabberActivator.getVersionService().getCurrentVersion();
String appName = ver.getApplicationName();
if(!appName.toLowerCase().contains("jitsi"))
appName += "-Jitsi";
versionIQ.setName(appName);
versionIQ.setVersion(ver.toString());
parentProvider.getConnection().sendPacket(versionIQ);
}
}

@ -52,6 +52,7 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.service.certificate,
net.java.sip.communicator.service.httputil,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.version,
org.xmlpull.v1,
org.xmlpull.mxp1,
javax.xml.parsers,

Loading…
Cancel
Save