Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Walance #1
Member since Jan 2013 · 12 posts
Group memberships: Members
Show profile · Link to this post
Subject: Creating new user, updating VCard and adding that user to a group
A while ago I made a topic about the OnRosterItem not being fired. You said that the problem is probably in the OpenFire pluging that we use. So yesterday/today I started making something that uses the MatriX SDK to add new users, but I'm having some problems with it.

I used the tutorial as an example. The user gets added to OpenFire properly, but when I try to update the VCard and add the user to a group, nothing happens. I don't get any error, but the VCard and group don't get updated either.

Here's the code I made:
  1. public void AddUserToChat(string userName, string password)
  2. {
  3.     var client = new XmppClient();
  4.  
  5.     client.OnRegisterError += (sender, args) =>
  6.     {
  7.         logger.Error("Failed to register user in chat: " + args.Iq);
  8.         client.Close();
  9.     };
  10.  
  11.     client.OnRegisterInformation += (sender, args) =>
  12.     {
  13.         args.Register.RemoveAll<Data>();
  14.         args.Register.Username = client.Username;
  15.         args.Register.Password = client.Password;
  16.     };
  17.  
  18.     client.OnSendXml += (sender, args) => logger.Debug("ONSENDXML: " + args.Text);
  19.     client.OnReceiveXml += (sender, args) => logger.Debug("ONRECEIVEXML:" + args.Text);
  20.  
  21.     client.OnRosterEnd += (sender, args) =>
  22.     {
  23.         var jid = client.Username + "@" + client.XmppDomain;
  24.         var viq = new VcardIq
  25.         {
  26.             Type = IqType.set,
  27.             Vcard = new Vcard
  28.             {
  29.                 Fullname = "Deze naam staat hardcoded"
  30.             }
  31.         };
  32.  
  33.         client.Send(viq);
  34.  
  35.         var rosterManager = new RosterManager(client);
  36.         rosterManager.Add(jid, client.Username, chatGroup, this.AddedToRoster);
  37.     };
  38.  
  39.     client.SetXmppDomain(ConfigurationManager.AppSettings["OpenFireLocation"]);
  40.     client.SetUsername(userName);
  41.     client.Password = password;
  42.     client.RegisterNewAccount = true;
  43.     client.Open();
  44. }
  45.  
  46. private void AddedToRoster(object sender, IqEventArgs e)
  47. {
  48. }

As you can see, I wait untill the OnRosterEnd event to update the VCard and group. I tried doing that in the "OnRegister" at first, but it seems that's too early, because I was getting "not-authorized" errors. I put my xml logs on pastebin again so that this post does not too messy.
This post was edited on 2013-02-13, 16:18 by Walance.
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the server replies to both your requests with result. So everything is fine and should be updated.
did you post the complete log to pastebin? Because normally the server should send you also a roster push which I don't see here.

If the server replies with result bit did nothing then this is a server bug.
Instead of OnRosterEnd you could try the OnBeforeSendPresence event. When this occurs the first time then MatriX sent your presence and the session is ready for roster and vcard updates.

Alex
Avatar
Walance #3
Member since Jan 2013 · 12 posts
Group memberships: Members
Show profile · Link to this post
Yes, I did put the complete log on pastebin, we never received a roster push, except for this one:
  1. <iq type="result" id="MX_13" to="ihv_testing123_992247@chat-test.obec.local/MatriX" xmlns="jabber:client">
  2.  <query xmlns="jabber:iq:roster" />
  3. </iq>
This is also in pastebon, but that is before I update the group. I'm guessing that I'm supposed to receive a new roster after that?

I tried using the OnBeforeSendPresence event, instead of OnRosterEnd, but there is no difference in doing that.

I just looked manually in the database of OpenFire and I can see the correct VCard there, but OpenFire doesn't show it in the web interface. The group is not set in the database either. So it does indeed seem to be a problem with the server, the VCard part at least.

// Edit: Nevermind about the vcard, OpenFire doesn't seem to show VCards in general, so I think that part is working correctly, but we still have the problem with the roster group.
This post was edited on 2013-02-13, 17:24 by Walance.
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by Walance:
Yes, I did put the complete log on pastebin, we never received a roster push, except for this one:
  1. <iq type="result" id="MX_13" to="ihv_testing123_992247@chat-test.obec.local/MatriX" xmlns="jabber:client">
  2.  <query xmlns="jabber:iq:roster" />
  3. </iq>
This is also in pastebon, but that is before I update the group. I'm guessing that I'm supposed to receive a new roster after that?

that is the full roster during the the login, no roster push.
After your last packet MX_15 which is the reply to your roster update you must receive the roster push.

You can try to close the session after register and reconnect. Maybe this helps.

Alex
Avatar
hkui #5
Member since Feb 2013 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hi, I'm Walance's colleague. He is at home now, so I'm continuing doing some work for him.

We have the vcard working, but we don't have the adding the user to a group working yet.

What we did before was (OpenFire, through an Oracle stored procedure):
      insert into ofgroup (groupname) values(AddChatUser.pvChatGroup);
      insert into ofgroupuser (UserName,groupname,ADMINISTRATOR) values (lvUserName,AddChatUser.pvChatGroup,0);

We now want to do this using MatriX.

The problem is, I can't figure out anywhere how to achieve this usiing XMPP. Also, I can't figure out how to achieve this using MatriX.

We thought we needed RosterManager.Add(), but now I think this is wrong. I think we need PubSubManager.PublishItem() or PubSubManager.PublishStanza().

Also, I'm wondering what exactly the ofgroupuser table means. What's it used for? There's also ofroster and ofrostergroups. Right now, these tables are empty (there are some records because of tests with RosterManager.Add()). Is it maybe shared groups? Or something like that?

Thank you for your help so far, using MatriX XMPP has been amazing. I'm glad to work on this for a bit, now that Walance has gone home.
Avatar
Alex #6
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
normal xmpp roster groups and Openfire shared groups are something totally different.

The last code which Walance posted is absolutely correct to set a vcard and add a user to the roster with a group.
However if you want to use the Openfire shared roster stuff then there is no way to configure this from a XMPP client. The hsared groups are a special admin feature which can be configured only in the admin console. Or manipulating the server database with SQL directly.
This post was edited on 2013-02-13, 20:48 by Alex.
Avatar
Alex #7
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I found a problem in line 36 of teh code Walance posted:

  1. // you set your own Jid here
  2. var jid = client.Username + "@" + client.XmppDomain;
  3.  
  4. // because jid is your own jid you are adding yourself to your own contact list which cannot work
  5. // you can add only other users to your contact list
  6. rosterManager.Add(jid, client.Username, chatGroup, this.AddedToRoster);

Alex
Avatar
Walance #8
Member since Jan 2013 · 12 posts
Group memberships: Members
Show profile · Link to this post
Thanks for your answers, Alex. I didn't know that xmpp roster groups and OpenFire shared groups are different and I also didn't know that "rosterManager.Add()" only adds users to my own contact list, I thought it would add the user to the global xmpp roster group.

I think we do need to keep using the shared rosters, because we have several groups of people in our chat and those people are only allowed to see and chat with people in specific groups. So I guess I have to go back to manipulating the database directly, or see if I can do this, or something close to it, with xmpp roster groups.
Avatar
Alex #9
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
shared roster groups are just a feature to populate the rosters dynamic automatically on the server.

Example:
You have 3 user, bob, alice and bill.
You have a shared group called friends
Now you put all of these 3 users in the shared group friends.

When you login and the shared group feature is enabled the server automatically creates a roster for this users where they are all on each others contact list and automatically subscribed. Most servers do this automatically in memory. The behavior can be very different in each server implementation. This is not a core feature of XMPP.

because Openfire creates the roster the on login in memory you get no roster pushes.

Of course you can write you own XMPP bots, database scripts or web admin tool for roster management which populate the regular XMPP roster automatically.
Avatar
hkui #10
Member since Feb 2013 · 3 posts
Group memberships: Members
Show profile · Link to this post
What I have found is this:
http://xmpp.org/extensions/xep-0140.html#add

If I look through the OpenFire source code, I see that normal groups and shared groups in OpenFire are essentially the same class, the same thing.

OpenFire determines a shared group this way:
  1.     /**
  2.      * Returns true if the specified Group may be included in a user roster. The decision is made
  3.      * based on the group properties that are configurable through the Admin Console.
  4.      *
  5.      * @param group the group to check if it may be considered a shared group.
  6.      * @return true if the specified Group may be included in a user roster.
  7.      */
  8.     public static boolean isSharedGroup(Group group) {
  9.         String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
  10.         if ("onlyGroup".equals(showInRoster) || "everybody".equals(showInRoster)) {
  11.             return true;
  12.         }
  13.         return false;
  14.     }

Would it be possible to just make this user a member of a group, using the above XMPP? And if so, how would we do it with your library? So far, I'm not understanding a lot of the PubSubManager.
Avatar
Alex #11
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by hkui:
What I have found is this:
http://xmpp.org/extensions/xep-0140.html#add

this document is from 2004 and retracted. I don't think that it is supported in Openfire. You have to ask the Openfire developers if the server supports it.

Quote by hkui:
Would it be possible to just make this user a member of a group, using the above XMPP? And if so, how would we do it with your library? So far, I'm not understanding a lot of the PubSubManager.
first check with the Openfire guys if they support it. If they support it and we have the Xml format then we can take the next step and I can tell you how to build the packets in MatriX.
Avatar
hkui #12
Member since Feb 2013 · 3 posts
Group memberships: Members
Show profile · Link to this post
I just created a topic on the OpenFire community boards.

http://community.igniterealtime.org/message/227104#227104
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS