Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
AndyGear #1
Member since Jan 2012 · 6 posts
Group memberships: Members, Premium
Show profile · Link to this post
Subject: Adding to and fetching Privacy Lists
I'm trying to add privacy functionality to my client, but it doesn't seem to be creating the entries in the server's database.  After searching the forums I see that I first need to have an active list.  To accomplish this I get the lists after connecting to the server.  If the list of lists is null I attempt to add a list called IgnoreList (the _ignoreList variable's const string)

//initialize connection settings
private void setXMPPClient(string jid, string pass)
    {
        _friends = new HashSet<string>();
        _friends.Clear();
        _username = new Jid(jid);
        _password = pass;

        _xmppCon = new XmppClientConnection();
       
        _xmppCon.Server = _domain;
        _xmppCon.ConnectServer = _connectServer;
        _xmppCon.Username = _username.User;
        _xmppCon.Password = _password;
        _xmppCon.Resource = null;
        _xmppCon.Port = 5222;
        _xmppCon.UseSSL = false;
        _xmppCon.AutoResolveConnectServer = true;
        _xmppCon.UseCompression = false;
        _xmppCon.KeepAliveInterval = 60;
        _xmppCon.AutoPresence = true;
        _xmppCon.AutoRoster = true;
       
        _privacyMan = new agsXMPP.protocol.iq.privacy.PrivacyManager(_xmppCon);
    }

//called to actually connect after setting the settings
public void Connect(onConnect connectDelegate)
    {
        _onConnect = connectDelegate;
        if (!_connected)
        {
            _xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage);
            _xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
            _xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
            _xmppCon.OnAuthError += new XmppElementHandler(xmppCon_OnAuthError);
            _xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence);
            _xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);

            _xmppCon.Open();
        }
    }

//called after logged in
private void xmppCon_OnLogin(object sender)
    {
        _connected = true;
        _privacyMan.GetLists(new IqCB(getListsCallback),null);
        _onConnect();
    }

//see if we have any privacy lists for this user
private void getListsCallback(object sender, IQ iq, object data)
    {
        agsXMPP.protocol.iq.privacy.List lists = iq.Query as agsXMPP.protocol.iq.privacy.List;
        if (lists == null)
        {
            agsXMPP.protocol.iq.privacy.List l = new agsXMPP.protocol.iq.privacy.List();
            _privacyMan.AddList(_ignoreList, l.GetItems(), getListsCallbackCallback, null);
        }
        else
        {
            _privacyMan.ChangeDefaultList(_ignoreList);
            _privacyMan.ChangeActiveList(_ignoreList);
        }
    }

    //IgnoreList created, now set it as default and active
    private void getListsCallbackCallback(object sender, IQ iq, object data)
    {
        _privacyMan.ChangeDefaultList(_ignoreList);
        _privacyMan.ChangeActiveList(_ignoreList);
    }

This doesn't seem to be working.  Do I need actual entries in the list to successfully create it?  If so then why does my function to add/remove a person from the privacy list not seem to work either?

public void ignore(string username, bool ignore)
    {
        _ignore = ignore;
        _ignoree = username;
        _privacyMan.GetList(_ignoreList, new IqCB(ignoreCallback), null);
    }

    private void ignoreCallback(object sender, IQ iq, object data)
    {
        bool createit = false;
        agsXMPP.protocol.iq.privacy.List list = iq.Query as agsXMPP.protocol.iq.privacy.List;
        if (list == null)
        {
            createit = true;
            list = new agsXMPP.protocol.iq.privacy.List(_ignoreList);
        }

        agsXMPP.protocol.iq.privacy.Item item = new agsXMPP.protocol.iq.privacy.Item();
        item.Type = agsXMPP.protocol.iq.privacy.Type.jid;
        item.Val = createJid(_ignoree);
        item.Order = 1;
        item.Action = (_ignore) ? agsXMPP.protocol.iq.privacy.Action.deny : agsXMPP.protocol.iq.privacy.Action.allow;
        item.Stanza = agsXMPP.protocol.iq.privacy.Stanza.Message | agsXMPP.protocol.iq.privacy.Stanza.IncomingPresence | agsXMPP.protocol.iq.privacy.Stanza.OutgoingPresence;

        list.AddItem(item);

        if (createit)
        {
            _privacyMan.AddList(_ignoreList, list.GetItems());
            _privacyMan.ChangeActiveList(_ignoreList);
            _privacyMan.ChangeDefaultList(_ignoreList);
        }
        else
        {
            _privacyMan.UpdateList(_ignoreList, list.GetItems());
        }
    }
Avatar
Alex #2
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by AndyGear:
Do I need actual entries in the list to successfully create it?  If so then why does my function to add/remove a person from the privacy list not seem to work either?

According to the protocol and the schema this is fine. But its possibel that the server implementation your are using has problems with such a list. So try to add a dummy entry to test this.

You should also check in your callbacks whether the server accepts your list and updates and returns result or error.
If it still does not work please attach or post the debug XML.
Avatar
AndyGear #3
Member since Jan 2012 · 6 posts
Group memberships: Members, Premium
Show profile · Link to this post
Thank you for the ideas, Alex.  As it turns out you hit the nail on the head; my clustered servers were set up differently so privacy lists were being saved differently on either causing things to look strange.
Avatar
AndyGear #4
Member since Jan 2012 · 6 posts
Group memberships: Members, Premium
Show profile · Link to this post
Okay.  Time for part 2 of my question.  I'm trying to manually request the list with:

  1. public void getIgnoreList(ignoreListDelegate callback)
  2.     {
  3.         _ignoreListDelegate = callback;
  4.         _privacyMan.GetList(_ignoreList, new IqCB(getIgnoreListCallback), null);
  5.     }
  6.  
  7.     private void getIgnoreListCallback(object sender, IQ iq, object data)
  8.     {
  9.         HashSet<string> ignorees = new HashSet<string>();
  10.         agsXMPP.protocol.iq.privacy.List list = iq.Query as agsXMPP.protocol.iq.privacy.List;
  11.  
  12.         agsXMPP.protocol.iq.privacy.Item[] items = list.GetItems();
  13.         foreach (agsXMPP.protocol.iq.privacy.Item item in items)
  14.         {
  15.             ignorees.Add(item.Val);
  16.         }
  17.         _ignoreListDelegate(ignorees);
  18.     }

According to the database and, I think, the XML I should be getting one result back, but in the code it appears the returned list is empty.  Here is the XML:

Request: <iq id="agsXMPP_7" type="get"><query xmlns="jabber:iq:privacy"><list name="IgnoreListketchup" /></query></iq>

Response: <iq xmlns="jabber:client" from="ketchup@wqhq01.familyguyonline.com" type="error" id="agsXMPP_6" to="ketchup@wqhq01.familyguyonline.com/3204163219132640259162226"><query xmlns="jabber:iq:privacy"><list name="IgnoreListketchup" /></query><error code="409" type="cancel"><conflict xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>

Response: <iq xmlns="jabber:client" from="ketchup@wqhq01.familyguyonline.com" type="result" id="agsXMPP_7" to="ketchup@wqhq01.familyguyonline.com/3204163219132640259162226"><query xmlns="jabber:iq:privacy"><list name="IgnoreListketchup"><item value="french_fries@wqhq01.familyguyonline.com" action="deny" type="jid" order="1" /></list></query></iq>

Is that 409:Cancel screwing up the return of the following list of privacy items?
Avatar
Alex #5
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You have not posted the xml of the request which returns the 409 error response.
can you post the request with the id="agsXMPP_6"?

Alex
Avatar
AndyGear #6
Member since Jan 2012 · 6 posts
Group memberships: Members, Premium
Show profile · Link to this post
It doesn't seem to be related:

<iq id="agsXMPP_6" type="set"><query xmlns="jabber:iq:privacy"><list name="IgnoreListketchup" /></query></iq>

EDIT:

Looks like I've got it figured out.  I cannot cast the returned iq.Query directly to a List.  It's type is Privacy which I then have to .GetList().  Works like a charm now!  Thanks very much!
This post was edited on 2012-01-13, 00:56 by AndyGear.
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: agsXMPP RSS