How can I find the real user JID of user in MUC? - xmpp

When I join in a room XMPP xmpp, usually the other user see my JID as myconference#conference.localhost/myname instead of myname#localhost.
Pidgin is able to recover also my real JID when I talk with some of my friends (myname#localhost).
How is it possible? What kind of request should I make to the server?
This is important for me, because when I start talking with someone, I don't want to open two tabs, only because my client believes that my friend that I can see both in my roster and in the group roster, isn't the same guy.

See XEP-0045, section 7.2.4. In a non-anonymous room, the server will send all participants' jids in their presence stanzas:
<presence
from='coven#chat.shakespeare.lit/thirdwitch'
id='17232D15-134F-43C8-9A29-61C20A64B236'
to='crone1#shakespeare.lit/desktop'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='none'
jid='hag66#shakespeare.lit/pda'
role='participant'/>
</x>
</presence>

Related

How to allow Ejabberd external XMPP component to send presence packets on behalf of a user

I wrote an external component for Ejabberd, but when trying to send presence stanzas on behalf of a user i get a 400 error.
The component's name is bot.domain.com and the host name in Ejabberd is domain.com and I have set the "check_from" flag to false for my component.
Below is an example of a presence stanza I am trying to send from the component on behalf of a user:
<presence from="user#domain.com">
<status>Test status</status>
<show>dnd</show>
</presence>
And this is the error message that is returned by Ejabberd:
<presence type="error" to="user#domain.com">
<status>Test status</status>
<show>dnd</show>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</presence>
If I add to="user2#domain.com" in the package I'm sending, the destination user actually receives the package.
If I add to="domain.com", I don't get the 400 error anymore, but the presence is not broadcast to anyone in the user's roster.
The actual problem seems to be that Ejabberd is not broadcasting the presence packet to everyone in the user's roster.
Any ideas what I might be missing or why I get the 400 error when not specifying the "to" field?
You cannot broadcast roster presence on behalf of a user from a component. Component service does not load the user roster. Only the ejabberd_c2s is taking care of loading roster to broadcast presence. It also takes care of checking privacy list and many important features of XMPP.
As a side note, I do not know what you expect to do with that approach, but you can split presence from user session in XMPP. A user is online first because he has a session open on XMPP and only secondarily because he sent a presence. By faking presence sending from component for a users, you are not guaranteed that that user will have a session opened. In that case, the overall behaviour will certainly not the one you expect.

How can I tell the difference between the JID of a user and a JID of MUC?

Suppose I have two JIDs:
JID 1: bob#example.com
JID 2 room#chat.example.com
JID 2 clearly refers to the chat server, but the chat server isn't always going to have the word chat or conference in it.
Is there a way, using the Smack libraries, to tell which one is which?
You cannot tell by looking at the JID. You have to keep enough context in a given protocol exchange to know what you are talking to.
Typically on startup, a client will send a disco#items query to the server:
<iq type='get'
to='shakespeare.lit'
id='items1'>
<query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>
to find all of the local services, then send a disco#info query to each of those services to find out more about the service. Once you find a MUC server:
<iq from='chat.shakespeare.lit'
type='result'>
<query xmlns='http://jabber.org/protocol/disco#info'>
<identity
category='conference'
name='Shakespearean Chat Service'
type='text'/>
<feature var='http://jabber.org/protocol/muc'/>
</query>
</iq>
you know that all of the JIDs that include this domain name (chat.shakespeare.lit in the above example) are associated with MUC rooms.
A user JID in a MUC will (should) have the username at the end and will look like:
roomname#conference.example.com/username

Send string to XMPP MuC participants without using "Message" object

In my current project I want to communicate with people in a XMPP Multi User Chat. But also I need to send data to all participants in the conference, but this data should not be seen as a message.
Is it possible to send data (strings) to all participants in a MuC channel by not using a normal chat message?
I'm using Smack API, and I assume, that all participants use my program.
Thanks in advance!
The solution is to use a normal message (with type="groupchat"), but do not include a <body>.
I do not know how this is done in Smack, or if it is possible (I hope it is). An example message would be:
<message to="room#conference.server" type="groupchat">
<yourdata xmlns="your-xmlns">
<anything-you-want-here/>
</yourdata>
</message>
XMPP clients will ignore this message, as it has no <body> tag.

Problem creating a chat room with XMPP in an iOS app

I have an iphone app where I want to use chat rooms. I've installed an XMPP server (ejabberd) and downloaded the XMPP framework for iOS from google code (http://code.google.com/p/xmppframework/). The server and client work as expected, since I'm able to log in and send chat messages between two users.
However, when I try to create a chat room using the createOrJoinRoom method of the XMPPRoom class (in XEP-0045), I don't get any reply from the server and the chat room is not created.
I've debugged to see what kind of package is sent to the server and it looks like this:
<presence from="test2#beta.bogus.net/mynick" to="muumit15#conference.beta.bogus.net">
<x xmlns="http://jabber.org/protocol/muc"/>
</presence>
I get no error message back but the chat room (muumit15) is not created. At the same time I can use e.g. Adium client to create a chat room and it succeeds. The server has been configured so that every user has a right to create chat rooms.
Any ideas? I even tried sniffing the TCP/IP traffic sent by the Adium client but that was encrypted/compressed/binary so I couldn't see what kind of packages it is sending.
See section 7.2.2 of XEP-0045, particularly Example 18:
<presence
from='hag66#shakespeare.lit/pda'
to='coven#chat.shakespeare.lit/thirdwitch'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
Note that the to address MUST contain a resource, and yours doesn't. The resource is the string after the /, which is used as your nickname in the room. For more information on the XMPP address format, see RFC 6122.

user profile from XMPP iPhone

I am using XMPP for chatting in my iPhone application, I need to retrieve the profile of every user in buddy list, like phone number, street address etc.
How can I get started?
While XEP-54 can be used for this purpose, PLEASE do not spam the network by making vcard-temp requests for everyone on your roster every time your client logs in. Since you haven't told us what client library you're using, all we can do is provide you with the protocol you need to send:
<iq id='v1'
type='get'>
<vCard xmlns='vcard-temp'/>
</iq>
Note that XEP-54 is about to be obsoleted by XEP-292, but it will take several years for that transition to take place.