Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Richard #1
Member since Mar 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: Re-using messages
What is the best way of reusing incoming messages in the OnIQ event handler?
I want to send the message back with extra data but keeping the original ID etc

My function sig in a component is - _OnIq(object sender, agsXMPP.protocol.component.IQ iq)
this is different from the sample documentation which gives:
 
private void XmppCon_OnIq(object sender, agsXMPP.Xml.Dom.Node e)

Now the iq may be anything from a Disco to a custom message type eg Weather IQ so I need to cast it somehow but the compiler isnt allowing it.
Thanks
Avatar
Richard #2
Member since Mar 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
Just to clarify what I want to do - if the incoming IQ is a Disco I want to add Indentity and Feature to the underlying query:

For example if I create the the object
 DiscoInfoIq diq = new DiscoInfoIq(agsXMPP.protocol.client.IqType.result);

I can then do this:

 diq.Query.AddIdentity(di);
 diq.Query.AddFeature(df1);
 diq.Query.AddFeature(df2);

But what the event handler is being passed is a generic IQ
Do I have to use the XML attributes/child nodes of the Query?
Avatar
Alex #3
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your code looks correct so far.

you can do a:
  1. diq.ChildNodes.Clear();
in case there are childnodes in the query which you should remove before adding new stuff.

then do a:
  1. iq.SwitchDirection();
this exchanges the from and to addresses.

before you can send it back change the type attribute, you probably want the result type

  1. iq.Type = IqType.result;

Alex
Avatar
Richard #4
Member since Mar 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
Thanks, but I sort of knew I had not made this clear enough!

In the component:

void comp_OnIq(object sender, agsXMPP.protocol.component.IQ iq)
{
   
    DiscoInfoIQ diq = iq as DiscoInfoIQ ; // doesnt compile cannot typecast it
Error    1    Cannot convert type 'agsXMPP.protocol.component.IQ' to 'agsXMPP.protocol.iq.disco.DiscoInfoIq' via a built-in conversion   


This is the bit I really need to do .......

    DiscoFeature df1 = new DiscoFeature("http://abc.net/protocol/def");

    ((DiscoInfoIq)iq).AddFeature(df1) ; // same cannot cast IQ to DiscoInfoIQ
Error    5    Cannot convert type 'agsXMPP.protocol.component.IQ' to 'agsXMPP.protocol.iq.disco.DiscoInfoIq'

    So do I have to get the iq.Query element and then work on the XML directly to add the <feature var=" ..... stuff?




   

}
Avatar
Alex #5
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you cannot cast an Iq to DiscoIq. You have to cast iq.Query to DiscoInfo.

  1. DiscoInfo di = iq.Query as DiscoInfo;

Alex
Avatar
Richard #6
Member since Mar 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
Alex,
Thank you that is what I was looking for!
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