private void GotIQ(Elements.IQ iq) { switch (iq.IQType) { case IQType.error: case IQType.result: int no; if (iq.ID.StartsWith("n") && int.TryParse(iq.ID.Substring(1), out no)) { IQReply repl = null; lock (fIQReplies) { if (fIQReplies.TryGetValue(no, out repl)) { fIQReplies.Remove(no); } } if (repl.Callback != null) { repl.Callback(iq); } } break; // else it's not one of ours default: // TODO: any known iq items here if (OnIQ(iq)) { return; } Elements.IQ replyiq = new IQ(); replyiq.ID = iq.ID; replyiq.IQType = IQType.error; break; } }
public IQEventArgs(IQ aIQ) { fIQ = aIQ; }
private Element CreateNode(XmlNodeResult nd, Element parent) { string ens; if (nd.Prefix != null) { RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == "xmlns" && a.Name == nd.Prefix); if (at == null) { Element el = parent; ens = string.Empty; while (el != null) { RemObjects.InternetPack.XMPP.Elements.Attribute els = el.Attributes.Where(a => a.Prefix == "xmlns" && a.Name == nd.Prefix).FirstOrDefault(); if (els != null) { ens = els.Value; break; } el = el.Parent; } } else ens = at.Value; } else { RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns"); if (at == null) ens = string.Empty; else ens = at.Value; } Element res = null; switch (ens) { case Namespaces.ClientStreamNamespace: case Namespaces.ServerStreamNamespace: case "": if (ens == null && parent != null && parent.Type == ElementType.IQ && nd.Name == "error") res = new IQError(); else switch (nd.Name) { case "iq": res = new IQ(); break; case "presence": res = new Presence(); break; case "message": res = new Message(); break; } break; case Namespaces.StreamNamespace: switch (nd.Name) { case "stream": RemObjects.InternetPack.XMPP.Elements.Attribute att = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns"); if (att == null || att.Value == Namespaces.ClientStreamNamespace) res = new ClientStream(); else res = new ServerStream(); break; case "features": res = new StreamFeatures(); break; case "error": res = new StreamError(); break; } break; case Namespaces.StartTLSNamespace: switch (nd.Name) { case "starttls": res = new StartTLS(); break; case "failure": res = new StartTLSFailure(); break; case "proceed": res = new StartTLSProceed(); break; } break; case Namespaces.SaslNamespace: switch (nd.Name) { case "mechanisms": res = new Mechanisms(); break; case "auth": res = new SaslAuth(); break; case "challenge": res = new SaslChallenge(); break; case "response": res = new SaslResponse(); break; case "abort": res = new SaslAbort(); break; case "success": res = new SaslSuccess(); break; case "failure": res = new SaslFailure(); break; } break; } if (res == null) { res = new UnknownElement(); } else res.Attributes.Clear(); // default ones shouldn't be here during the reading process if (parent != null) { res.Parent = parent; if (parent != fServerRoot) parent.Elements.Add(res); } res.Prefix = nd.Prefix; res.Name = nd.Name; foreach (var el in nd.Attribute) res.Attributes.Add(el); return res; }
protected bool OnIQ(IQ anIQ) { if (IQ != null) { IQEventArgs args = new IQEventArgs(anIQ); IQ(this, args); return args.SkipReply; } return false; }
public void SendIQ(IQ packet, Action<IQ> reply) { lock (fIQReplies) { packet.ID = "n" + fCounter.ToString(); fIQReplies.Add(fCounter, new IQReply { Callback = reply, Timeout = DateTime.UtcNow.Add(fTimeout) }); fCounter++; if (fIQReplies.Count == 1) BeginTimeout(new Action(IQTimeoutCheck), true); } BeginSend(packet, WriteMode.None, null); }
private void SendResourceBinding() { fState = XMPP.State.BindingResource; var iq = new IQ(); iq.IQType = IQType.set; iq.Elements.Add(new RemObjects.InternetPack.XMPP.Elements.IQTypes.Bind { Resource = this.Resource }); SendIQ(iq, a => { if (a == null) { OnError(new TimeoutException("ResourceBinding")); Close(); return; } if (a.IQType != IQType.result) { OnError(new XMPPException("Error binding resource: "+a)); Close(); return; } if (CreateSession) { SendCreateSession(); } else { fState = XMPP.State.Active; OnActive(); } }); }
private void SendCreateSession() { fState = XMPP.State.CreatingSession; OnCreateSession(); var iq = new IQ(); iq.To = new JID(Domain); iq.IQType = IQType.set; iq.Elements.Add(new UnknownElement { NamespaceURI = Namespaces.SessionNamespace, Name = "sesion"}); SendIQ(iq, a => { if (a == null) { OnError(new TimeoutException("CreateSession")); Close(); return; } if (a.IQType != IQType.result) { OnError(new XMPPException("Error creating session: " + a)); Close(); return; } fState = XMPP.State.Active; OnActive(); if (SendPresenceAndPriority) { var pres = new Presence(); pres.Priority = Priority; SendPresence(pres); } }); }
private void GotIQ(Elements.IQ iq) { switch (iq.IQType) { case IQType.error: case IQType.result: int no; if (iq.ID.StartsWith("n") && int.TryParse(iq.ID.Substring(1), out no)) { IQReply repl = null; lock (fIQReplies) { if (fIQReplies.TryGetValue(no, out repl)) { fIQReplies.Remove(no); } } if (repl.Callback != null) repl.Callback(iq); } break; // else it's not one of ours default: // TODO: any known iq items here if (OnIQ(iq)) return; Elements.IQ replyiq = new IQ(); replyiq.ID = iq.ID; replyiq.IQType = IQType.error; break; } }