public void Add(Node e) { // can't add a empty node, so return immediately // Some people tried dthis which caused an error if (e == null) return; this.List.Add(e); }
public void Add(Node e) { // can't add a empty node, so return immediately // Some people tried this which caused an error if (e == null) return; if (m_Owner != null) { e.Parent = m_Owner; if (e.Namespace == null) e.Namespace = m_Owner.Namespace; } e.m_Index = Count; this.List.Add(e); }
public override void Parse(Node e) { if ( e.GetType() == typeof(protocol.sasl.Challenge) ) { protocol.sasl.Challenge c = e as protocol.sasl.Challenge; sasl.DigestMD5.Step1 step1 = new sasl.DigestMD5.Step1(c.TextBase64); if (step1.Rspauth == null) { //response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9ImduYXVjayIscmVhbG09IiIsbm9uY2U9IjM4MDQzMjI1MSIsY25vbmNlPSIxNDE4N2MxMDUyODk3N2RiMjZjOWJhNDE2ZDgwNDI4MSIsbmM9MDAwMDAwMDEscW9wPWF1dGgsZGlnZXN0LXVyaT0ieG1wcC9qYWJiZXIucnUiLGNoYXJzZXQ9dXRmLTgscmVzcG9uc2U9NDcwMTI5NDU4Y2EwOGVjYjhhYTIxY2UzMDhhM2U5Nzc sasl.DigestMD5.Step2 s2 = new CSS.IM.XMPP.sasl.DigestMD5.Step2(step1, base.Username, base.Password, base.Server); protocol.sasl.Response r = new CSS.IM.XMPP.protocol.sasl.Response(s2.ToString()); base.XmppClientConnection.Send(r); } else { // SEND: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> base.XmppClientConnection.Send(new protocol.sasl.Response()); } } }
public override void StreamParserOnStreamStart(object sender, Node e) { base.StreamParserOnStreamStart (sender, e); m_StreamStarted = true; Login(); }
public override void StreamParserOnStreamEnd(object sender, Node e) { base.StreamParserOnStreamEnd (sender, e); if(!m_CleanUpDone) CleanupSession(); }
public override void StreamParserOnStreamElement(object sender, Node e) { base.StreamParserOnStreamElement (sender, e); if (e is Handshake) { m_Authenticated = true; if (OnLogin != null) OnLogin(this); if (KeepAlive) CreateKeepAliveTimer(); } else if (e is Route) { if (OnRoute != null) OnRoute(this, e as Route); } else if (e is protocol.Error) { protocol.Error streamErr = e as protocol.Error; switch (streamErr.Condition) { // Auth errors are important for the users here, so throw catch auth errors // in a separate event here case CSS.IM.XMPP.protocol.StreamErrorCondition.NotAuthorized: // Authentication Error if (OnAuthError != null) OnAuthError(this, e as Element); break; default: if (OnStreamError != null) OnStreamError(this, e as Element); break; } } else if (e is Message) { if (OnMessage != null) OnMessage(this, e as Message); } else if (e is Presence) { if (OnPresence != null) OnPresence(this, e as Presence); } else if (e is IQ) { if (OnIq != null) OnIq(this, e as IQ); } }
public virtual void StreamParserOnStreamEnd(object sender, Node e) { Element tag = e as Element; string qName; if (tag.Prefix == null) qName = tag.TagName; else qName = tag.Prefix + ":" + tag.TagName; string xml = "</" + qName + ">"; this.FireOnReadXml(this, xml); }
// ya, the Streamparser is only usable for parsing xmpp stream. // it also does a very good job here private void sp_OnStreamStart(object sender, Node e) { doc.ChildNodes.Add(e); }
private void sp_OnStreamElement(object sender, Node e) { doc.RootElement.ChildNodes.Add(e); }
public override void Parse(Node e) { // not needed here in PLAIN mechanism }
private void WriteTree(Node e, XmlTextWriter tw, Node parent) { if (e.NodeType == NodeType.Document) { //Write the ProcessingInstruction node. // <?xml version="1.0" encoding="windows-1252"?> ... Document doc = e as Document; string pi = null; if (doc.Version != null) pi += "version='" + doc.Version + "'"; if (doc.Encoding != null) { if (pi != null) pi += " "; pi += "encoding='" + doc.Encoding + "'"; } if (pi != null) tw.WriteProcessingInstruction("xml", pi); foreach(Node n in e.ChildNodes) { WriteTree(n, tw, e); } } else if (e.NodeType == NodeType.Text) { tw.WriteString(e.Value); } else if (e.NodeType == NodeType.Comment) { tw.WriteComment(e.Value); } else if (e.NodeType == NodeType.Element) { Element el = e as Element; if (el.Prefix==null) tw.WriteStartElement( el.TagName ); else tw.WriteStartElement( el.Prefix + ":" + el.TagName ); // Write Namespace if ( (parent == null || parent.Namespace != el.Namespace) && el.Namespace != null && el.Namespace.Length !=0 ) { if (el.Prefix==null) tw.WriteAttributeString("xmlns", el.Namespace); else tw.WriteAttributeString("xmlns:" + el.Prefix , el.Namespace); } foreach (string attName in el.Attributes.Keys) { tw.WriteAttributeString(attName, el.Attribute(attName)); } //tw.WriteString(el.Value); if (el.ChildNodes.Count > 0) { foreach(Node n in el.ChildNodes) { WriteTree(n, tw, e); } tw.WriteEndElement(); } else { tw.WriteEndElement(); } } }
private string BuildXml(Node e, Formatting format, int indent, char indentchar) { if ( e != null ) { System.IO.StringWriter tw = new StringWriter(); XmlTextWriter w = new XmlTextWriter(tw); w.Formatting = format; w.Indentation = indent; w.IndentChar = indentchar; WriteTree(this, w, null); return tw.ToString(); } else { return ""; } }
/// <summary> /// Appends the given Element as child element /// </summary> /// <param name="e"></param> public virtual void AddChild(Node e) { this.m_ChildNodes.Add(e); }
public override void StreamParserOnStreamStart(object sender, Node e) { base.StreamParserOnStreamStart(this, e); m_StreamStarted = true; //m_CleanUpDone = false; moved that to _Open(); protocol.Stream st = (protocol.Stream)e; if (st == null) return; // Read the server language string m_ServerLanguage = st.Language; // Auth stuff if (!RegisterAccount) { if (this.StreamVersion != null && this.StreamVersion.StartsWith("1.")) { if (!Authenticated) { // we assume server supports SASL here, because it advertised a StreamVersion 1.X // and wait for the stream features and initialize the SASL Handler InitSaslHandler(); } } else { // old auth stuff RequestLoginInfo(); } } else { // Register on "old" jabber servers without stream features if (this.StreamVersion == null) GetRegistrationFields(null); } }
public override void StreamParserOnStreamElement(object sender, Node e) { base.StreamParserOnStreamElement(sender, e); if ( e.GetType() == typeof(IQ) ) { if (OnIq != null) OnIq(this, e as IQ); IQ iq = e as IQ; if ( iq != null && iq.Query != null) { // Roster if (iq.Query is Roster) OnRosterIQ(iq); } } else if ( e.GetType() == typeof(Message) ) { if (OnMessage != null) OnMessage(this, e as Message); } else if ( e.GetType() == typeof(Presence) ) { if (OnPresence != null) OnPresence(this, e as Presence); } else if ( e.GetType() == typeof (CSS.IM.XMPP.protocol.stream.Features) ) { // Stream Features // StartTLS stuff CSS.IM.XMPP.protocol.stream.Features f = e as CSS.IM.XMPP.protocol.stream.Features; if (m_UseCompression && f.SupportsCompression && f.Compression.SupportsMethod(CompressionMethod.zlib)) { // Check for Stream Compression // we support only ZLIB because its a free algorithm without patents // yes ePatents suck DoChangeXmppConnectionState(XmppConnectionState.StartCompression); this.Send(new Compress(CompressionMethod.zlib)); } #if SSL || MONOSSL || BCCRYPTO else if (f.SupportsStartTls && m_UseStartTLS) { DoChangeXmppConnectionState(XmppConnectionState.Securing); this.Send(new StartTls()); } #endif else if (f.SupportsRegistration && m_RegisterAccount) { // Do registration after TLS when possible if (f.SupportsRegistration) GetRegistrationFields(e); else { // registration is not enabled on this server FireOnError(this, new RegisterException("Registration is not allowed on this server")); Close(); // Close the stream } } } #if SSL || MONOSSL || BCCRYPTO else if ( e.GetType() == typeof (Proceed) ) { StreamParser.Reset(); ClientSocket.StartTls(); SendStreamHeader(false); DoChangeXmppConnectionState(XmppConnectionState.Authenticating); } #endif else if ( e.GetType() == typeof (Compressed) ) { //DoChangeXmppConnectionState(XmppConnectionState.StartCompression); StreamParser.Reset(); ClientSocket.StartCompression(); // Start new Stream Header compressed. SendStreamHeader(false); DoChangeXmppConnectionState(XmppConnectionState.Compressed); } else if (e is CSS.IM.XMPP.protocol.Error) { if (OnStreamError != null) OnStreamError(this, e as Element); } }
/// <summary> /// Reset the XML Stream /// </summary> public void Reset() { m_Depth = 0; m_root = null; current = null; m_cdata = false; m_buf = null; m_buf = new BufferAggregate(); //m_buf.Clear(0); m_ns.Clear(); }
private void StartTag(byte[] buf, int offset, ContentToken ct, TOK tok) { m_Depth++; int colon; string name; string prefix; Hashtable ht = new Hashtable(); m_ns.PushScope(); // if i have attributes if ((tok == TOK.START_TAG_WITH_ATTS) || (tok == TOK.EMPTY_ELEMENT_WITH_ATTS)) { int start; int end; string val; for (int i=0; i<ct.getAttributeSpecifiedCount(); i++) { start = ct.getAttributeNameStart(i); end = ct.getAttributeNameEnd(i); name = utf.GetString(buf, start, end - start); start = ct.getAttributeValueStart(i); end = ct.getAttributeValueEnd(i); //val = utf.GetString(buf, start, end - start); val = NormalizeAttributeValue(buf, start, end - start); // <foo b='&'/> // <foo b='&amp;' // TODO: if val includes &, it gets double-escaped if (name.StartsWith("xmlns:")) { colon = name.IndexOf(':'); prefix = name.Substring(colon+1); m_ns.AddNamespace(prefix, val); } else if (name == "xmlns") { m_ns.AddNamespace(string.Empty, val); } else { ht.Add(name, val); } } } name = utf.GetString(buf, offset + m_enc.MinBytesPerChar, ct.NameEnd - offset - m_enc.MinBytesPerChar); colon = name.IndexOf(':'); string ns = ""; prefix = null; if (colon > 0) { prefix = name.Substring(0, colon); name = name.Substring(colon + 1); ns = m_ns.LookupNamespace(prefix); } else { ns = m_ns.DefaultNamespace; } Element newel = ElementFactory.GetElement(prefix, name, ns); foreach (string attrname in ht.Keys) { newel.SetAttribute(attrname, (string)ht[attrname]); } if (m_root == null) { m_root = newel; //FireOnDocumentStart(m_root); if (OnStreamStart!=null) OnStreamStart(this, m_root); } else { if (current != null) current.AddChild(newel); current = newel; } }
/// <summary> /// /// </summary> /// <param name="e"></param> public override void Parse(Node e) { // *No Challenges* in SASL ANONYMOUS }
private void sp_OnStreamEnd(object sender, Node e) { }
public NodeList(Node owner) { m_Owner = owner; }
public virtual void StreamParserOnStreamElement(object sender, Node e) { this.FireOnReadXml(this, e.ToString()); }
/// <summary> /// /// </summary> /// <param name="e"></param> public abstract void Parse(Node e);
public virtual void StreamParserOnStreamStart(object sender, Node e) { string xml = e.ToString().Trim(); xml = xml.Substring(0, xml.Length - 2) + ">"; this.FireOnReadXml(this, xml); protocol.Stream st = (protocol.Stream)e; if (st != null) { m_StreamId = st.StreamId; m_StreamVersion = st.Version; } }
public override void Parse(Node e) { // not needed here in X-GOOGLE-TOKEN mechanism }