XEP - 0055 with iOS and ejabberd? - ios

I am trying to implement XEP-0055 which is supported by ejabbed as shown here in supported xeps
This is my request:
XMPPIQ *iq = [[XMPPIQ alloc] init];
[iq addAttributeWithName:#"type" stringValue:#"get"];
[iq addAttributeWithName:#"from" stringValue:#"testuser1#company.com"];
[iq addAttributeWithName:#"to" stringValue:#"company.com"];
[iq addAttributeWithName:#"id" stringValue:#"search1"];
XMPPElement *query = [XMPPElement elementWithName:#"query"];
[query setXmlns:#"jabber:iq:search"];
[iq addChild:query];
[self.xmppStream sendElement:iq];
I am getting this response:
<iq xmlns="jabber:client" from="company.com" to="testuser1#company.com/2834146151141475281662718" type="error" id="search1">
<query xmlns="jabber:iq:search"/>
<error code="501" type="cancel">
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
Why am I receiving feature-not-implemented? Link to official XEP description.

In ejabberd, the search functionality is delegated to a subdomain, by default using the vjud prefix. Try sending the search request to vjud.company.com instead.

Related

Get list of Chat group using XMPPFramework

I am trying to fetch the list of available chat groups in my Ejabbered server with the help of XMPPFramework. Following is my code to fetch the list of Chat Group.
- (void) getChatGroupList{
XMPPJID *servrJID = [XMPPJID jidWithString:#"conference.Server"];
XMPPIQ *iq = [XMPPIQ iqWithType:#"get" to:servrJID];
[iq addAttributeWithName:#"from" stringValue:[[self xmppStream] myJID].full];
NSXMLElement *query = [NSXMLElement elementWithName:#"query"];
[query addAttributeWithName:#"xmlns" stringValue:#"http://jabber.org/protocol/disco#items"];
[iq addChild:query];
[[self xmppStream] sendElement:iq];
}
In response I am getting following XML inside didReceiveIQ
<presence xmlns="jabber:client" from="username#Server/38489493512952747921478847202003609" to="username# Server/38489493512952747921478847202003609"><priority>24</priority><x xmlns="vcard-temp:x:update"><photo/></x><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://github.com/robbiehanson/XMPPFramework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/></presence>
Exact name of the group I can't see in the response. Can anyone help what is missing here or How can I get list of Group name and list of users inside each group?
Have you figure what happened?
From what I see, your request looks OK, but the response should be for other request.
And not sure what version XMPPFramework you are using, in the latest, there is a XMPPMUC class in XEP-0045. You can call discoverRoomsForServiceNamed to do the same stuff. Just make sure to implement XMPPMUCDelegate when you use it.

OS X ejabberd, New user register by XMPPFramework

I'm new for ejabberd. I want to add new user on server through my iOS App.
I tried with many code that was find out from the Google but no one can solve my issue.
I set module to http://localhost:5280/admin/server/localhost/node/ejabberd#localhost/modules/
For enable mod_register also change ejabberd.yml file from etc/ejabberd folder.
And my Listened Ports at ejabberd#localhost
And I used below code for register user.
NSXMLElement *query = [NSXMLElement elementWithName:#"query" xmlns:#"jabber:iq:register"];
[query addChild:[NSXMLElement elementWithName:#"username" stringValue:#"syam"]];
[query addChild:[NSXMLElement elementWithName:#"password" stringValue:#"Vrin#123"]];
NSXMLElement *iq = [NSXMLElement elementWithName:#"iq"];
[iq addAttributeWithName:#"type" stringValue:#"set"];
[iq addAttributeWithName:#"id" stringValue:#"reg2"];
[iq addChild:query];
[APP_DELEGATE.xmppStream sendElement:iq];
[APP_DELEGATE.xmppStream setHostName:#"0.0.0.0"];
[APP_DELEGATE.xmppStream setHostPort:5222];
NSError *error;
if (![APP_DELEGATE.xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error connecting"
message:#"See console for error details."
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}
But didn't get success and occurred below error message.
<iq xmlns="jabber:client" from="himanshu#localhost" to="himanshu#localhost/15505992182228745748626" type="error" id="reg2"><query xmlns="jabber:iq:register"><username>syam</username><password>Vrin#123</password></query><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></service-unavailable><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">No module is handling this query</text></error></iq>
Please help me to solve my issue.
access: register means - only already registered users are able to access mod_register (to change password, for example). You need to have access: all to allow registration. And do not forget to protect registration with CAPTCHA when server will be opened for public network (and in this case that simple registration implementation in XMPPFramework will not enough)
Also it's not clear is mod_register enabled for your virtualhost, check mod_register presence in modules: block of your configuration

XMPPFramework - 'didReceiveMessage' called two times when message is received

Whenever I receive any new messages, these two methods gets called two times.
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
I am sending request to server to get my roster list with the following code.
NSXMLElement *query = [NSXMLElement elementWithName:#"query" xmlns:#"jabber:iq:roster"];
XMPPIQ *iq = [XMPPIQ iq];
[iq addAttributeWithName:#"id" stringValue:#"buddyRequest"];
[iq addAttributeWithName:#"to" stringValue:#"54.186.107.171"];
[iq addAttributeWithName:#"type" stringValue:#"get"];
[iq addChild:query];
[self.xmppStream sendElement:iq];
Could somebody point out to me where the problem might lie?
Thank you.
I think you set the delegate to XMPPStream twice.Remove one and check.Then also u got two response , check the xmppstream object value.is both are different , surely you set twice.

How to integrate XEP-0055 in xmpp Chat app for search user in ios

I am creating a XMPP chat app on iOS. I am trying to do is search user over XMPP. I checked the opernfire server and it has the search plugin enabled. I gone through XEP:0055 and found the stanza.
See http://xmpp.org/extensions/xep-0055.html for reference on the format of the XML you should send and expect to receive back.
If you are trying to perform a search, here is an example for searching for a user by email address
NSString *bareJID = [self.xmppStream.myJID bare];
NSXMLElement *query = [NSXMLElement elementWithName:#"query"];
[query addAttributeWithName:#"xmlns" stringValue:#"jabber:iq:search"];
NSXMLElement *email = [NSXMLElement elementWithName:#"email" stringValue:searchQuery];
[query addChild:email];
NSXMLElement *iq = [NSXMLElement elementWithName:#"iq"];
[iq addAttributeWithName:#"type" stringValue:#"set"];
[iq addAttributeWithName:#"id" stringValue:#"search2"];
[iq addAttributeWithName:#"to" stringValue:[NSString stringWithFormat:#"search.%#",self.xmppStream.myJID.domain]];
[iq addAttributeWithName:#"from" stringValue:bareJID];
[iq addAttributeWithName:#"xml:lang" stringValue:#"en"];
[iq addChild:query];
[self.xmppStream sendElement:iq];
In your callback for xmppStream:didReceiveIQ: you will receive a response from the server, with the same id you specified above (in this case 'search2'). This will be an XML response, as indicated on the initial URL I mentioned for the XEP-0055 reference page, and you can parse it out accordingly.
You can go http://blog.csdn.net/dangfm/article/details/36185879,and follow '搜索关键词' to assemble XML(iq),then _xmppStream send it(iq).

Message not sent through XMPP

I am using XMPP in my app. My messages are not being sent whenever I attempt to send a message to any specific ID (for example 'test.codemen#gmail.com' in my code).
My code is given below. Thanks in advance.
- (IBAction)sendMsg:(id)sender
{
NSXMLElement *body = [NSXMLElement elementWithName:#"body"];
[body setStringValue:msgField.text];
NSXMLElement *message = [NSXMLElement elementWithName:#"message"];
[message addAttributeWithName:#"type" stringValue:#"chat"];
[message addAttributeWithName:#"to" stringValue:#"test.codemen#gmail.com"];
[message addChild:body];
iPhoneXMPPAppDelegate *share = [iPhoneXMPPAppDelegate sharedInstance];
[[share xmppStream] sendElement:message];
}
your code looks fine to me.
Google Talk routes messages only to contacts you are subscribed to. Is the user you send the message to on your contact list?
Print the xml , then see what's in the message .Maybe you are sending message to a wrong JID .

Resources