private VersionManager(final XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Version.NAMESPACE); connection.registerIQRequestHandler(new AbstractIqRequestHandler(Version.ELEMENT, Version.NAMESPACE, IQ.Type.get, Mode.async) { @Override public IQ handleIQRequest(IQ iqRequest) { if (ourVersion == null) { return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable)); } return Version.createResultFor(iqRequest, ourVersion); } }); }
@CommandHandler(name = ACTION_VERSION) private boolean handleVersion(Intent intent) { if (isConnected()) { try { Version version = new Version(JidCreate.from(intent.getStringExtra(EXTRA_TO))); version.setStanzaId(intent.getStringExtra(EXTRA_PACKET_ID)); sendPacket(version); } catch (XmppStringprepException e) { Log.w(TAG, "error parsing JID: " + e.getCausingString(), e); // report it because it's a big deal ReportingManager.logException(e); } } return false; }
/** * {@inheritDoc} * * Gets the namespaces of features that this <tt>Component</tt> * offers/supports i.e. {@link ColibriConferenceIQ#NAMESPACE}. */ @Override protected String[] discoInfoFeatureNamespaces() { return new String[] { ColibriConferenceIQ.NAMESPACE, HealthCheckIQ.NAMESPACE, ProtocolProviderServiceJabberImpl .URN_XMPP_JINGLE_DTLS_SRTP, ProtocolProviderServiceJabberImpl .URN_XMPP_JINGLE_ICE_UDP_1, ProtocolProviderServiceJabberImpl .URN_XMPP_JINGLE_RAW_UDP_0, Version.NAMESPACE }; }
@Override public Version parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { String name = null, version = null, os = null; outerloop: while (true) { int eventType = parser.next(); switch (eventType) { case XmlPullParser.START_TAG: String tagName = parser.getName(); switch (tagName) { case "name": name = parser.nextText(); break; case "version": version = parser.nextText(); break; case "os": os = parser.nextText(); break; } break; case XmlPullParser.END_TAG: if (parser.getDepth() == initialDepth && parser.getName().equals(IQ.QUERY_ELEMENT)) { break outerloop; } } } if (name == null && version == null && os == null) { return new Version(); } return new Version(name, version, os); }
@Override public void processStanza(Stanza packet) { Version p = (Version) packet; Intent i = new Intent(ACTION_VERSION); i.putExtra(EXTRA_PACKET_ID, p.getStanzaId()); i.putExtra(EXTRA_FROM, p.getFrom().toString()); i.putExtra(EXTRA_TO, p.getTo().toString()); i.putExtra(EXTRA_VERSION_NAME, p.getName()); i.putExtra(EXTRA_VERSION_NUMBER, p.getVersion()); sendBroadcast(i); }
/** * Handles a <tt>Version</tt> stanza which represents a request. * * @param versionRequest the <tt>Version</tt> stanza represents * the request to handle * @return an <tt>org.jivesoftware.smack.packet.IQ</tt> stanza which * represents the response to the specified request. */ private org.jivesoftware.smack.packet.IQ handleVersionIQ( org.jivesoftware.smackx.iqversion.packet.Version versionRequest) { VersionService versionService = getVersionService(); if (versionService == null) { return org.jivesoftware.smack.packet.IQ.createErrorResponse( versionRequest, XMPPError.getBuilder(XMPPError.Condition.service_unavailable)); } org.jitsi.service.version.Version currentVersion = versionService.getCurrentVersion(); if (currentVersion == null) { return org.jivesoftware.smack.packet.IQ.createErrorResponse( versionRequest, XMPPError.getBuilder(XMPPError.Condition.internal_server_error)); } // send packet org.jivesoftware.smackx.iqversion.packet.Version versionResult = new org.jivesoftware.smackx.iqversion.packet.Version( currentVersion.getApplicationName(), currentVersion.toString(), System.getProperty("os.name") ); // to, from and packetId are set by the caller. // versionResult.setTo(versionRequest.getFrom()); // versionResult.setFrom(versionRequest.getTo()); // versionResult.setPacketID(versionRequest.getPacketID()); versionResult.setType(org.jivesoftware.smack.packet.IQ.Type.result); return versionResult; }
public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Version.NAMESPACE); }
private static Version generateVersionFrom(String name, String version, String os) { if (autoAppendSmackVersion) { name += " (Smack " + SmackConfiguration.getVersion() + ')'; } return new Version(name, version, os); }
private org.jivesoftware.smack.packet.IQ handleIQRequest( org.jivesoftware.smack.packet.IQ request) throws Exception { // Requests can be categorized in pieces of Videobridge functionality // based on the org.jivesoftware.smack.packet.IQ runtime type (of their // child element) and forwarded to specialized Videobridge methods for // convenience. if (request instanceof org.jivesoftware.smackx.iqversion.packet.Version) { return handleVersionIQ( (org.jivesoftware.smackx.iqversion.packet.Version) request); } Videobridge videobridge = getVideobridge(); if (videobridge == null) { return IQUtils.createError( request, XMPPError.Condition.internal_server_error, "No Videobridge service is running"); } org.jivesoftware.smack.packet.IQ response; if (request instanceof ColibriConferenceIQ) { response = videobridge.handleColibriConferenceIQ( (ColibriConferenceIQ) request); } else if (request instanceof HealthCheckIQ) { response = videobridge.handleHealthCheckIQ((HealthCheckIQ) request); } else if (request instanceof ShutdownIQ) { response = videobridge.handleShutdownIQ((ShutdownIQ) request); } else { response = null; } return response; }
/** * Request version information from a given JID. * * @param jid * @return the version information or {@code null} if not supported by JID * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException */ public Version getVersion(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException { if (!isSupported(jid)) { return null; } return connection().createPacketCollectorAndSend(new Version(jid)).nextResultOrThrow(); }