Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
genilto #1
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
Subject: Private XML Storage
How can I store my (serialized class-object in xml) in a PrivateIq?
Avatar
Alex #2
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have to send a PrivateIq of type set an add your object as children of the query tag.
See also: http://xmpp.org/extensions/xep-0049.html

Alex
Avatar
genilto #3
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
Am I correct?

PrivateIq piq;
Private pv;
Myclass myinstance;

this.piq = new PrivateIq(IqType.get, new Jid(jid.Bare));
Connection.IqGrabber.SendIq(piq, new IqCB(PrivateResult), null); //Receive PrivateIq

send my Private class:
piq.Type = IqType.set;
pv.AddChild(myinstance);
Connection.send(piq);

Receive my Private class:
private void PrivateResult(object sender,IQ iq, object data)
        { ...
this.pv = iq.Query as Private;
 if (pv.HasChildElements)
                   {
                           myinstance = (Myclass)pv.FirstChild;
                   }
}
Avatar
Alex #4
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
yes this looks correct. You don't have to include the to attribute, because the private Iqs are handled directly on the server.
Avatar
genilto #5
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
my PrivateIq query is returning null childs

I also try with my class added in children of Private and PrivateIq
Conexao.Send(pv);
Conexao.Send(piq);

My class need something special?
... public class Usuario  : Element
    { ...


Obs: My server is ejabberd 2.1.3
Avatar
Alex #6
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your get request must include the root of your custom element, otherwise the server does not know which stored item you want to retrieve.
Can you please post the debug xml of the set and get request? Both with the response of the server.

Alex
This post was edited on 2010-05-13, 19:56 by Alex.
Avatar
genilto #7
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
Enviado:<query xmlns="jabber:iq:private">< />< />< /></query>
Enviado:<iq id="agsXMPP_13" to="gd@smi.inviolavel.com" type="set"><query xmlns="jabber:iq:private" /></iq>
Enviado:<iq id="agsXMPP_13" to="gd@smi.inviolavel.com" type="set"><query xmlns="jabber:iq:private" /></iq>
Recebido:<stream:error xmlns:stream="http://etherx.jabber.org/streams"><xml-not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams" /></stream:error>
Avatar
genilto #8
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
Enviado:<iq id="agsXMPP_13" type="get" to="gd@smi.inviolavel.com"><query xmlns="jabber:iq:private" /></iq>
RECEBIDO:<iq xmlns="jabber:client" type="result" from="gd@smi.inviolavel.com" to="gd@smi.inviolavel.com/agsXMPP" id="agsXMPP_13"><query xmlns="jabber:iq:private" /></iq>
Avatar
Alex #9
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In reply to post #7
Quote by genilto:
<query xmlns="jabber:iq:private">< /><  />< /></query>
As you can see you first request contains invalid Xml, empty tags and is not embedded in the iq tag.

Alex
Avatar
Alex #10
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
And your get request does not include the namespace you want to receive from the private storage.

Alex
Avatar
genilto #11
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
Sending my (own packet type):
  public Unidade()
        {
            this.TagName = "Unidade";
            this.Namespace = "jabber:iq:private";
        }

        public int IdUnidade
        {
            get { return GetTagInt("IdUnidade"); }
            set { SetTag("idunidade", value.ToString());}
        }

...

agsXMPP.Factory.ElementFactory.AddElementType("unidade","agsoftware:unidade", typeof(Unidade));
piq.AddChild(unidade);
Conexao.Send(piq);
Output:
Enviado:<iq id="agsXMPP_14" to="genilto@smi.inviolavel.com" type="set"><query xmlns="jabber:iq:private" /><Unidade xmlns="jabber:iq:private"><idunidade>99</idunidade></Unidade></iq>
RECEBIDO:<stream:error xmlns:stream="http://etherx.jabber.org/streams"><xml-not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams" /></stream:error>
RECEBIDO:</stream:stream>


agsXMPP.Factory.ElementFactory.AddElementType("Unidade", "jabber:iq:private", typeof(Unidade));
piq.AddChild(unidade);
Conexao.Send(piq);
...
Enviado:<iq id="agsXMPP_14" to="genilto@smi.inviolavel.com" type="set"><query xmlns="jabber:iq:private" /><Unidade xmlns="jabber:iq:private"><idunidade>99</idunidade></Unidade></iq>
RECEBIDO:<stream:error xmlns:stream="http://etherx.jabber.org/streams"><xml-not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams" /></stream:error>
Avatar
genilto #12
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
Sending any string:

var e = new agsXMPP.Xml.Dom.Element("Nome", "Genilto", "qualquercoisa");
 piq.AddChild(e);
Conexao.Send(piq);

Enviado:<iq id="agsXMPP_14" to="genilto@smi.inviolavel.com" type="set"><query xmlns="jabber:iq:private" /><Nome xmlns="qualquercoisa">Genilto</Nome></iq>
RECEBIDO:<stream:error xmlns:stream="http://etherx.jabber.org/streams"><xml-not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams" /></stream:error>
RECEBIDO:</stream:stream>



You have any working example?

Tks!
Avatar
Alex #13
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
first I create a custom Element for my storage in my own namespace:

  1. public class Storage : Element
  2. {
  3.     public Storage()
  4.     {
  5.         TagName = "storage";
  6.         Namespace = "ag-software:storage";
  7.     }
  8.  
  9.     public int Id
  10.     {
  11.         get { return GetTagInt("id"); }
  12.         set { SetTag("id", value.ToString());}
  13.     }
  14. }

This should be registered in the ElementFactory before we use it with the following code:

  1. agsXMPP.Factory.ElementFactory.AddElementType("storage", "ag-software:storage", typeof(Storage));

Now to store something I use the following code:
  1. var piq = new PrivateIq {Type = IqType.set};
  2. piq.Query.AddChild(new Storage {Id = 999});
  3. XmppCon.Send(piq);

Tpo receive this storage use the following code:
  1. var piq = new PrivateIq { Type = IqType.get };
  2. piq.Query.AddChild(new Storage());
  3. XmppCon.Send(piq);

I hope this helps.

Alex
Avatar
genilto #14
User title: Genilto Dallo
Member since May 2010 · 10 posts · Location: Guarapuava/PR - Brasil
Group memberships: Members
Show profile · Link to this post
Subject: It Works!
Thanks Alex, it's working!

Snd: <iq id="agsXMPP_76" type="get" to="genilto@smi.inviolavel.com"><query xmlns="jabber:iq:private"><storage xmlns="ag-software:storage" /></query></iq>

Rcv: <iq xmlns="jabber:client" type="result" from="genilto@smi.inviolavel.com" to="gd@smi.inviolavel.com/agsXMPP" id="agsXMPP_76"><query xmlns="jabber:iq:private"><storage xmlns="ag-software:storage"><id>1</id><login>gd</login><nome>Genilto Dallo</nome><setor>TI</setor><unidade>Guarapuava</unidade><email>geniltodallo@email.com</email><celular>99xx 8489</celular></storage></query></iq>
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