Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
choquito #1
Member since Mar 2013 · 21 posts · Location: Spain
Group memberships: Members
Show profile · Link to this post
Subject: Task-based asynchronous MUC room configuration
Hi again Alex,

We are changing different functions to the new task based asynchronous pattern. In this case (make persistent muc), your example code from http://www.ag-software.net/2014/01/21/task-based-asynchron… works if exists a previous muc (eg:temporary...) otherwise an "forbidden (403)" error is returned by the server.

If previously at step 0, I insert the code:

var retiq = await mm.EnterRoomAsync(_roomJid, _usr);

the function works fine.

Is a good way to correct the error?
Avatar
Alex #2
Member since Feb 2003 · 4295 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
sorry, but I don't understand your question exactly. Maybe log files would help, one with success and one which shows the error.

Alex
Avatar
choquito #3
Member since Mar 2013 · 21 posts · Location: Spain
Group memberships: Members
Show profile · Link to this post
Subject: Task-based asynchronous MUC room configuration (CREATE NEW MUC ROOM)
Ok. I'll trying explain better the problem..

When I want create a NEW muc room, if I use your sample function:

  1. private async void MakeRoomPersitent(Jid roomJid)
  2. {   
  3.     // Step 1, request the room configuration
  4.     var iq = await mm.RequestRoomConfigurationAsync(roomJid);
  5.     if (iq.Type == IqType.result) // only proceed on result
  6.     {
  7.         // Step 2 and 3, parsing the current config and
  8.         // creating the result is done in the same loop here.
  9.         var xdata = iq.Query.Element<Data>();
  10.         var xDataResult = new Data
  11.         {
  12.             Type = FormType.submit
  13.         };
  14.  
  15.         foreach (var field in xdata.GetFields())
  16.         {
  17.             var retField = new Field()
  18.             {
  19.                 Type = field.Type, // keep the type
  20.                 Var = field.Var // keep the var
  21.             };
  22.  
  23.             // we are changing the muc#roomconfig_persistentroom only
  24.             // other fields get copied only with the existing values           
  25.             if (field.Var == "muc#roomconfig_persistentroom")
  26.                 retField.AddValue(true);
  27.             else
  28.                 retField.AddValues(field.GetValues().ToArray());
  29.  
  30.             xDataResult.AddField(retField);
  31.         }
  32.  
  33.         // Step 4, submit the changed configuration back to the server (room)
  34.         var submitIq = await mm.SubmitRoomConfigurationAsync(roomJid, xDataResult);
  35.         if (submitIq.Type == IqType.result)
  36.             Debug.WriteLine("success");
  37.         else
  38.             Debug.WriteLine("something went wrong");
  39.     }
  40. }

the server return an error 403 - forbidden (view the last<error> tag):

  1. 18-05-2014 19:01:03
  2. CLIENT SEND:
  3. <iq id="MX_3" type="get" to="rl_10000060@muc.im.sample.com" xmlns="jabber:client">
  4.  <query xmlns="http://jabber.org/protocol/muc#owner" />
  5. </iq>
  6.  
  7. 18-05-2014 19:01:03
  8. CLIENT RECV:
  9. <iq type="result" id="MX_3" from="rl_10000060@muc.im.sample.com" to="ttadmin001@im.sample.com/comEXT" xmlns="jabber:client">
  10.  <query xmlns="http://jabber.org/protocol/muc#owner">
  11.     <x type="form" xmlns="jabber:x:data">
  12.       <field var="muc#roomconfig_roomname" type="text-single" label="Natural-Language Room Name">
  13.         <value />
  14.       </field>
  15.       <field var="muc#roomconfig_roomdesc" type="text-single" label="Short Description of Room">
  16.         <value />
  17.       </field>
  18.       <field var="muc#roomconfig_persistentroom" type="boolean" label="Make Room Persistent?">
  19.         <value>0</value>
  20.       </field>
  21.       <field var="muc#roomconfig_publicroom" type="boolean" label="Make Room Publicly Searchable?">
  22.         <value>1</value>
  23.       </field>
  24.       <field var="muc#roomconfig_moderatedroom" type="boolean" label="Make Room Moderated?">
  25.         <value>0</value>
  26.       </field>
  27.       <field var="muc#roomconfig_membersonly" type="boolean" label="Make Room Members Only?">
  28.         <value>0</value>
  29.       </field>
  30.       <field var="muc#roomconfig_passwordprotectedroom" type="boolean" label="Password Required to Enter?">
  31.         <value>0</value>
  32.       </field>
  33.       <field var="muc#roomconfig_roomsecret" type="text-single" label="Password">
  34.         <value />
  35.       </field>
  36.       <field var="muc#roomconfig_anonymity" type="list-single" label="Room anonymity level:">
  37.         <value>semianonymous</value>
  38.         <option label="Non-Anonymous Room">
  39.           <value>nonanonymous</value>
  40.         </option>
  41.         <option label="Semi-Anonymous Room">
  42.           <value>semianonymous</value>
  43.         </option>
  44.         <option label="Fully-Anonymous Room">
  45.           <value>fullanonymous</value>
  46.         </option>
  47.       </field>
  48.       <field var="muc#roomconfig_changesubject" type="boolean" label="Allow Occupants to Change Subject?">
  49.         <value>0</value>
  50.       </field>
  51.       <field var="muc#roomconfig_enablelogging" type="boolean" label="Enable Public Logging?">
  52.         <value>0</value>
  53.       </field>
  54.       <field var="logging_format" type="list-single" label="Logging format:">
  55.         <value>html</value>
  56.         <option label="HTML">
  57.           <value>html</value>
  58.         </option>
  59.         <option label="Plain text">
  60.           <value>plain</value>
  61.         </option>
  62.       </field>
  63.       <field var="muc#maxhistoryfetch" type="text-single" label="Maximum Number of History Messages Returned by Room">
  64.         <value>50</value>
  65.       </field>
  66.     </x>
  67.  </query>
  68. </iq>
  69.  
  70. 18-05-2014 19:01:03
  71. CLIENT SEND:
  72. <iq id="MX_4" type="set" to="rl_10000060@muc.im.sample.com" xmlns="jabber:client">
  73.  <query xmlns="http://jabber.org/protocol/muc#owner">
  74.     <x type="submit" xmlns="jabber:x:data">
  75.       <field type="text-single" var="muc#roomconfig_roomname">
  76.         <value></value>
  77.       </field>
  78.       <field type="text-single" var="muc#roomconfig_roomdesc">
  79.         <value></value>
  80.       </field>
  81.       <field type="boolean" var="muc#roomconfig_persistentroom">
  82.         <value>1</value>
  83.       </field>
  84.       <field type="boolean" var="muc#roomconfig_publicroom">
  85.         <value>1</value>
  86.       </field>
  87.       <field type="boolean" var="muc#roomconfig_moderatedroom">
  88.         <value>0</value>
  89.       </field>
  90.       <field type="boolean" var="muc#roomconfig_membersonly">
  91.         <value>0</value>
  92.       </field>
  93.       <field type="boolean" var="muc#roomconfig_passwordprotectedroom">
  94.         <value>0</value>
  95.       </field>
  96.       <field type="text-single" var="muc#roomconfig_roomsecret">
  97.         <value></value>
  98.       </field>
  99.       <field type="list-single" var="muc#roomconfig_anonymity">
  100.         <value>semianonymous</value>
  101.       </field>
  102.       <field type="boolean" var="muc#roomconfig_changesubject">
  103.         <value>0</value>
  104.       </field>
  105.       <field type="boolean" var="muc#roomconfig_enablelogging">
  106.         <value>0</value>
  107.       </field>
  108.       <field type="list-single" var="logging_format">
  109.         <value>html</value>
  110.       </field>
  111.       <field type="text-single" var="muc#maxhistoryfetch">
  112.         <value>50</value>
  113.       </field>
  114.     </x>
  115.  </query>
  116. </iq>
  117.  
  118. 18-05-2014 19:01:04
  119. CLIENT RECV:
  120. <iq id="MX_4" from="rl_10000060@muc.im.sample.com" to="ttadmin001@im.sample.com/comEXT" type="error" xmlns="jabber:client">
  121.  <query xmlns="http://jabber.org/protocol/muc#owner">
  122.     <x type="submit" xmlns="jabber:x:data">
  123.       <field type="text-single" var="muc#roomconfig_roomname">
  124.         <value />
  125.       </field>
  126.       <field type="text-single" var="muc#roomconfig_roomdesc">
  127.         <value />
  128.       </field>
  129.       <field type="boolean" var="muc#roomconfig_persistentroom">
  130.         <value>1</value>
  131.       </field>
  132.       <field type="boolean" var="muc#roomconfig_publicroom">
  133.         <value>1</value>
  134.       </field>
  135.       <field type="boolean" var="muc#roomconfig_moderatedroom">
  136.         <value>0</value>
  137.       </field>
  138.       <field type="boolean" var="muc#roomconfig_membersonly">
  139.         <value>0</value>
  140.       </field>
  141.       <field type="boolean" var="muc#roomconfig_passwordprotectedroom">
  142.         <value>0</value>
  143.       </field>
  144.       <field type="text-single" var="muc#roomconfig_roomsecret">
  145.         <value />
  146.       </field>
  147.       <field type="list-single" var="muc#roomconfig_anonymity">
  148.         <value>semianonymous</value>
  149.       </field>
  150.       <field type="boolean" var="muc#roomconfig_changesubject">
  151.         <value>0</value>
  152.       </field>
  153.       <field type="boolean" var="muc#roomconfig_enablelogging">
  154.         <value>0</value>
  155.       </field>
  156.       <field type="list-single" var="logging_format">
  157.         <value>html</value>
  158.       </field>
  159.       <field type="text-single" var="muc#maxhistoryfetch">
  160.         <value>50</value>
  161.       </field>
  162.     </x>
  163.  </query>
  164.  <error type="auth" code="403">
  165.     <forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
  166.  </error>
  167. </iq>

but if at the beginning of the function I put the line:

 var retiq = await mm.EnterRoomAsync(_roomJid, _usr);

the function works fine, and a new persistent muc room is created.

  1. private async void MakeRoomPersitent(Jid roomJid)
  2. {   
  3.    
  4.    var retiq = await mm.EnterRoomAsync(_roomJid, _usr); // <----Enter room before...
  5.  
  6.  
  7.    // Step 1, request the room configuration
  8.     var iq = await mm.RequestRoomConfigurationAsync(roomJid);
  9.     if (iq.Type == IqType.result) // only proceed on result
  10.     {
  11.         // Step 2 and 3, parsing the current config and
  12.  
  13.   ....


I just want to know if this way to create a new persistent muc room is the most appropriate.

Thank you.
This post was edited 2 times, last on 2014-05-19, 10:58 by Alex.
Edit reason: fixed code formatting
Avatar
Alex #4
Member since Feb 2003 · 4295 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
This is how Muc is designed. You first have to create a room, or join a room.
After this you can change the configuration. Make a room persistent is only a configuration change.

You get the error because you try to change the configuration of a non existing room.

Alex
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