I got possible fields from my server:
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser@company.com/iPhone" id="search1" type="result"><query xmlns="jabber:iq:search">
<instructions>You need an x:data capable client to search</instructions>
<x xmlns="jabber:x:data" type="form">
<title>Search users in vjud.company.com</title>
<instructions>Fill in the form to search for any matching Jabber User (Add * to the end of field to match substring)
</instructions>
<field type="text-single" label="User" var="user"/>
<field type="text-single" label="Full Name" var="fn"/>
<field type="text-single" label="Name" var="first"/>
<field type="text-single" label="Middle Name" var="middle"/>
<field type="text-single" label="Family Name" var="last"/>
<field type="text-single" label="Nickname" var="nick"/>
<field type="text-single" label="Birthday" var="bday"/>
<field type="text-single" label="Country" var="ctry"/>
<field type="text-single" label="City" var="locality"/>
<field type="text-single" label="Email" var="email"/>
<field type="text-single" label="Organization Name" var="orgname"/>
<field type="text-single" label="Organization Unit" var="orgunit"/>
</x>
</query>
</iq>
Suppose I want to search a user with JID admin@company.com
Composed request wil look like this:
XMPPIQ *iq2 = [[XMPPIQ alloc] init];
[iq2 addAttributeWithName:@"type" stringValue:@"set"];
[iq2 addAttributeWithName:@"from" stringValue:@"testuser@company.com"];
[iq2 addAttributeWithName:@"to" stringValue:@"vjud.company.com"];
[iq2 addAttributeWithName:@"id" stringValue:@"search1"];
XMPPElement *query2 = [XMPPElement elementWithName:@"query"];
[query2 setXmlns:@"jabber:iq:search"];
XMPPElement *user = [XMPPElement elementWithName:@"user"];
[user setStringValue:@"admin"];
[iq2 addChild:query2];
[query addChild:user];
The error stanza:
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser@company.com/iPhone" type="error" id="search1">
<query xmlns="jabber:iq:search"/>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
So, basically there are 2 questions:
- Why there is no
</query>
element in response? - Is it the actual reason of the error?
-The server's response should look like this-
Big thanks to @legoscia user, in case request was composed right, you will get something like this(notice <item>
element):
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser@company.com/iPhone" id="search1" type="result»>
<query xmlns="jabber:iq:search"><x xmlns="jabber:x:data" type="result»>
<title>Search Results for vjud.company.com</title>
<reported>
<field type="text-single" label="Jabber ID" var="jid»/>
<field type="text-single" label="Full Name" var="fn»/>
<field type="text-single" label="Name" var="first»/>
<field type="text-single" label="Middle Name" var="middle»/>
<field type="text-single" label="Family Name" var="last"/><field type="text-single" label="Nickname" var="nick»/>
<field type="text-single" label="Birthday" var="bday»/>
<field type="text-single" label="Country" var="ctry»/>
<field type="text-single" label="City" var="locality»/>
<field type="text-single" label="Email" var="email»/>
<field type="text-single" label="Organization Name" var="orgname"/><field type="text-single" label="Organization Unit" var="orgunit»/>
</reported>
<item>
<field var="jid»>
<value>admin@company.com</value>
</field>
<field var="fn"><value/></field>
<field var="last"><value/></field>
<field var="first"><value/></field>
<field var="middle"><value/></field>
<field var="nick"><value/></field>
<field var="bday"><value/></field>
<field var="ctry"><value/></field>
<field var="locality"><value/></field>
<field var="email"><value/></field>
<field var="orgname"><value/></field>
<field var="orgunit"><value/></field></item>
</x>
</query>
</iq>
If there is no matches,you will just receive <reported>
element with lots of fields. You may want to have look at this as well.
This search service doesn't support "plain" XEP-0055 search fields, but requires you to submit the
x:data
form returned in the response to the "get" request; see XEP-0004.You can tell this by the fact that the result doesn't contain any suggested search fields as children of the query element (see example 2 of XEP-0055), and also the
<instructions/>
element says so. This means that you need to look at the<x xmlns="jabber:x:data" type="form">
element and submit it.Thus, you need to send something like:
(This is example 8 from XEP-0055, modified to search for the user with username "admin".)