Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Properly handle nick assignment when joining a MUC room #208

Merged
merged 1 commit into from
Jan 13, 2014
Merged

Properly handle nick assignment when joining a MUC room #208

merged 1 commit into from
Jan 13, 2014

Conversation

PaulSD
Copy link
Contributor

@PaulSD PaulSD commented Jan 10, 2014

When joining a MUC room, the MUC protocol allows the server ignore the nick requested by the client and assign a different nick. As currently implemented, Candy breaks if the server does this. This patch corrects this issue.

Thanks!

@mweibel
Copy link
Member

mweibel commented Jan 11, 2014

Hey Paul,

thanks for your various contributions 👍 :)
Is there a possibility to test it? Didn't encounter this case yet and can't really see how to force this :D

Will release a new beta with this fix afterwards.

  • Michael

@PaulSD
Copy link
Contributor Author

PaulSD commented Jan 11, 2014

I've tested it against my own XMPP server, which runs a customized version of MongooseIM (https://github.com/esl/MongooseIM). Our users authenticate to the server using an enterprise login account, and our MUC module requires the user's nick to be set to their real name (so it assigns the proper nick using their enterprise account info if the user doesn't specify the correct one when joining a room).

Unfortunately, I don't think any of the standard XMPP servers do something like this out-of-the-box, so testing it will probably require patching the server.

Here is a simple patch for ejabberd (https://github.com/processone/ejabberd) if you want to try it:

diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index b1c5c92..2f19ae2 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -1762,10 +1762,11 @@ nick_collision(User, Nick, StateData) ->
       jlib:jid_remove_resource(jlib:jid_tolower(UserOfNick))
        /= jlib:jid_remove_resource(jlib:jid_tolower(User)).

-add_new_user(From, Nick,
+add_new_user(From, _RequestedNick,
             #xmlel{attrs = Attrs, children = Els} = Packet,
             StateData) ->
     Lang = xml:get_attr_s(<<"xml:lang">>, Attrs),
+    Nick = <<"Nick Assignment Test">>,
     MaxUsers = get_max_users(StateData),
     MaxAdminUsers = MaxUsers +
                      get_max_users_admin_threshold(StateData),
@@ -2178,6 +2179,10 @@ send_new_presence(NJID, Reason, StateData) ->
                                          [#xmlel{name = <<"status">>,
                                                  attrs =
                                                      [{<<"code">>, <<"110">>}],
+                                                 children = []},
+                                          #xmlel{name = <<"status">>,
+                                                 attrs =
+                                                     [{<<"code">>, <<"210">>}],
                                                  children = []}
                                           | Status2];
                                      false -> Status2

mweibel added a commit that referenced this pull request Jan 13, 2014
Thanks @PaulSD for the PR. I made minor changes to the commit,
hope you don't mind :)
@mweibel mweibel merged commit 81b18f7 into candy-chat:dev Jan 13, 2014
@mweibel
Copy link
Member

mweibel commented Jan 13, 2014

Thanks for the patch. Somehow though I couldn't try it out because of some library missing.. Anyway, you have an interesting use case :)

I merged it in, as you see.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants