19

I am facing an issue with using XEP-0198 stream management.

Basically, I want to enable this for message dropping issue on Android when internet disconect randomly and server still has client presence online.

To solve this issue I want to use XEP-0198 which uses request and acknowledgement process. You can find more here.

Basically I am using sm:3 for this. The problem is that when I set

XMPPConnection.DEBUG_ENABLED=true;

I get sm:3 in log which is internal to asmack but I am unable to get that by ading any packetListner over connection.

This is what inside asmack debug prints:

<r xmlns='urn:xmpp:sm:3'/><message from='test1@pinmessage.com/Smack' to='test1@pinmessage.com' id='CQUe6-5'><received xmlns='urn:xmpp:receipts' id='CQUe6-4'/></message><r xmlns='urn:xmpp:sm:3'/>

This is what I get from packetFilter:

<message id="CQUe6-5" to="test1@pinmessage.com" from="test1@pinmessage.com/Smack"><received xmlns='urn:xmpp:receipts' id='CQUe6-4'/></message>

I had tried for custom packet filter by seeing the code of chat secure and yaxim as well but I am not getting how can I get this <r xmlns='urn:xmpp:sm:3'/> in my code so that I can return the number of packets received untill now to server so that server can send me back any missing packet.

I had also configured provider manager for this by adding the code below:

        addSimplePacketExtension("sm", URN_SM_3);
        addSimplePacketExtension("r", URN_SM_3);
        addSimplePacketExtension("a", URN_SM_3);
        addSimplePacketExtension("enabled", URN_SM_3);
        addSimplePacketExtension("resumed", URN_SM_3);
        addSimplePacketExtension("failed", URN_SM_3);


private static final String URN_SM_3 = "urn:xmpp:sm:3";
    private static void addSimplePacketExtension(final String name, final String namespace) {
        Log.e("adding simple packet extension", namespace+"---"+name);
        ProviderManager.getInstance().addExtensionProvider(name, namespace,
                new PacketExtensionProvider() {
            public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
                StreamHandlingPacket packet = new StreamHandlingPacket(name, namespace);
                Log.e("Stream ahndling packet ","------>"+packet.toXML());
                int attributeCount = parser.getAttributeCount();
                for (int i = 0 ; i < attributeCount ; i++) {
                    packet.addAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
                }
                return (PacketExtension) packet;
            }
        });
    }


static class StreamHandlingPacket extends Packet {
        private String name;
        private String namespace;
        Map<String, String> attributes;

        StreamHandlingPacket(String name, String namespace) {
            this.name = name;
            this.namespace = namespace;
            attributes = Collections.emptyMap();
        }

        public void addAttribute(String name, String value) {
            if (attributes == Collections.EMPTY_MAP)
                attributes = new HashMap<String, String>();
            attributes.put(name, value);
        }

        public String getAttribute(String name) {
            return attributes.get(name);
        }

        public String getNamespace() {
            return namespace;
        }

        public String getElementName() {
            return name;
        }

        public String toXML() {
            StringBuilder buf = new StringBuilder();
            buf.append("<").append(getElementName());

            // TODO Xmlns??
            if (getNamespace() != null) {
                buf.append(" xmlns=\"").append(getNamespace()).append("\"");
            }
            for (String key : attributes.keySet()) {
                buf.append(" ").append(key).append("=\"").append(StringUtils.escapeForXML(attributes.get(key))).append("\"");
            }
            buf.append("/>");
            Log.e("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&","&&&&&&&&&&&&&&&&&&&&&&&&&&&&=>"+buf.toString());
            return buf.toString();
        }

    }

Basically I get this idea by seeing chat secure implementation but it extends UnkownPacket rather than Packet. I had taken help from here.

I have also seen a git branch of asmack like this but wasn't able to understand how to implement it.

Please help if you have implemented it in any way with any library like chat secure, yaxim or any other android XMPP client.

Zaz
  • 39,637
  • 10
  • 70
  • 92
Akhil Dad
  • 1,728
  • 19
  • 33

3 Answers3

1

I recommend using Smack 4.1, which runs on Android and supports XEP-198 Stream Management.

Flow
  • 22,048
  • 13
  • 91
  • 147
  • 1
    Is there a tutorial about using xep 198 with smack 4.1 in android ? – Tolgay Toklar Feb 10 '15 at 14:34
  • Hi @Flow, can we override stream management to send ack every time we want ? I want send stream ack after inserting message to the DB, but in default stream management send ack as soon i get message. Thanks in advance. – Shayan Pourvatan Jun 08 '15 at 06:37
0

I can't offer you a solution because I'm having a similar problem but I can tell you from the second link that UnknownPacket extends Packet AND implements PacketExtension, that's why you had to cast your StreamHandlingPacket to (PacketExtension) in the return statement of your parseExtension method.

Are you able to catch the <enabled xmlns='urn:xmpp:sm:3' etc> xml that the XMPP server returns when you send <enable xmlns='urn:xmpp:sm:3' etc>? If so, that would be a beginning for your problem.

Let us know how it goes!

dbar
  • 1,710
  • 1
  • 15
  • 20
  • I am not able to get tag, that is the main issue as all these are printed in log but at my layer I am not able to get it. I can get all other – Akhil Dad Apr 23 '14 at 13:48
  • I'm afraid you are right and what we're trying to do is not possible: http://community.igniterealtime.org/message/238413#238413 – dbar Apr 23 '14 at 15:38
  • But I can see some of the clients has implemented it. Yoc can check ChatSecure and Yaxim on links below http://yaxim.org/blog/2014/01/30/yaxim-0-dot-8-7-stream-management-and-more/ https://github.com/devrandom/asmack/commit/5f8bee65064006ba6e479f2c515516f4670be1b5 https://github.com/guardianproject/ChatSecureAndroid/pull/116 and as per my knowledge they are also using aSmack. – Akhil Dad Apr 24 '14 at 06:06
  • I added a new answer with the lib you need :) – dbar Apr 24 '14 at 10:56
0

The patched asmack yaxim uses can be found here (the creator was kind enought to direct me to it, thanks Ge0rG!):

https://github.com/pfleidi/yaxim/tree/master/libs

Be sure to get libidn as well.

dbar
  • 1,710
  • 1
  • 15
  • 20
  • I had already tried that lib by adding to my build path but it gives fatal error at authentication as there might be some change in the lib (authentication may have been changed). I just wanted to know how to patch the lib so that I can make a patched lib according to my needs. Or do I need to see yaxim implementation details and all methods – Akhil Dad Apr 24 '14 at 11:19
  • did you add the libidn lib? – dbar Apr 24 '14 at 18:12
  • Now I added libidn also and for now Its working. I will test more over this first – Akhil Dad Apr 25 '14 at 04:57
  • Let me know how it goes, so far I have been unable to resume a stream, I always get a response after a resume. – dbar Apr 25 '14 at 08:39