Xep-0004

Hi…

I have never done this before, so here goes…

I need to submit a XEP-0004 form using SMACK…

The info I need to submit is as follows. It is used to submit your GCM key for use with mod_push:

<command xmlns=‘http://jabber.org/protocol/commands

node=‘register-push-apns’

action=‘execute’>

<field

var=‘token’>

r3qpHKmzZHjYKYbG7yI4fhY+DWKqFZE5ZJEM8P+lDDo=

Home

Can anyone show me how to submit with SMACK API forms? Please?

Thanks…

Michael.

That’s more than just a data form, it’s an ad-hoc command. Which mod_push are we talking about?

Hi…

Its the GCm push module for ejabberd GitHub - royneary/mod_push

At the end of this page, the author specifies that in order to register your device for GCm, you must

fill in the XEP-004 form and send it to the server. And you are right, it is ad-hoc commands.

I just need some direction of formatting the XML request in a normal Smack Form class.

Thanks in advance…Michael.

I’d try Smack’s AdHocCommandManager: AdHocCommandManager (Smack 4.1.7 API)

Thanks for pointing me in the right direction. I will give it a try.

Hi…

This is how I got it right after inspecting the xml stanza with debugging enabled:

DataForm xep0004 = new DataForm(DataForm.Type.submit);

FormField token = new FormField(“token”);

token.addValue(“cvx7Ro2qtMg:APA91bGMcRGPXbqqPG0g5u0v78dwrwSll1-J912j9P8V5tKF40TvFbk-”);

xep0004.addField(token);

AdHocCommandData stanza = new AdHocCommandData();

stanza.setTo(“mcmcas.ddns.net”);

stanza.setType(IQ.Type.set);

stanza.setStanzaId(“0043423”);

stanza.setNode(“register-push-gcm”);

stanza.setAction(AdHocCommand.Action.execute);

stanza.setForm(xep0004);

connection.sendStanza(stanza);

I hope this will also help someone else…

Cheers

Michael.

Update: You must supply the full JID or you will get a 503 error.

stanza.setFrom(lconnection.getUser());

The elegant solution would have been to use AdHocCommandManager to discover the available command, and then execute the command, which would cause the remote to send you a blank data form, that you then fill out and send back.

But whatever works for you

Hi…

Sorry to bother, but I am at my last step to register my application for push notification, and I am not so clued up with sending

a particular stanza to the server.

The last step requires me to send and enabled request:

<iq type='set' id='x43'> <enable xmlns='urn:xmpp:push:0' jid='push-5.client.example' node='yxs32uqsflafdk3iuqo'> <x xmlns='jabber:x:data'> <field var='FORM_TYPE'><value>http://jabber.org/protocol/pubsub#publish-options</value></field> <field var='secret'><value>eruio234vzxc2kla-91<value></field> </x> </enable> </iq>

I know how to do the form data part, but what type of stanza should I use to include the element?

The command used AdHocCommand… I do not know what to use for the part.

Thanks in advance…

Michael.

The IQ stanza has EXACTLY one child element (if it’s attribute is set or get), so you cannot put AND in it.

See here, for the exact rules:

https://xmpp.org/rfcs/rfc6120.html#stanzas-semantics-iq

EDIT: My excuse, I didn’t notice, that the wraps the .

To answer your question: I guess there’s no such class for the enabled element in Smack. Maybe in smack-experimental. If it’s not there, you have to write your own.

After searching a lot of code, I finally got it right…I think.

This is the xml being sent to the server:

      <field var='FORM_TYPE'><value>http://jabber.org/protocol/pubsub#publish-options</value></field>

6278839944512557202

This is what I did to send this particular xml:

DataForm xep0357 = new DataForm(DataForm.Type.form);

FormField fType = new FormField(“FORM_TYPE”);

fType.addValue(“http://jabber.org/protocol/pubsub#publish-options”);

xep0357.addField(fType);

FormField fSecret = new FormField(“secret”);

fSecret.addValue(“6278839944512557202”);

xep0357.addField(fSecret);

IQ pushStanza = new IQ(“enable”,“urn:xmpp:push:0”) {

@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {

xml.attribute(“jid”,“push.yourserver.com”);

xml.attribute(“node”, “8945888236880377686”);

xml.setEmptyElement();

return xml;

}

};

pushStanza.setType(IQ.Type.set);

pushStanza.addExtension(xep0357);

localConnection.sendStanza(pushStanza);