Esempio n. 1
0
 public override Packet Handle(Packet packet)
 {
     if (packet.GetAttribute("type") == "result")
     {
         Logger.Log("Features discovered");
     }
     return packet;
 }
Esempio n. 2
0
 public override Packet Handle(Packet packet)
 {
     if (packet.HasChild("bind"))
     {
         var jid = packet.GetChild("bind").GetChild("jid").Value;
         Logger.Log("Full jid = " + jid);
         OnBinding(packet);
     }
     return packet;
 }
Esempio n. 3
0
        public void Enqueue(Packet packet)
        {
            lock (_lockQ)
            {
                if (_packetQ == null) return;
                if (Stopped) return;

                _packetQ.Add(packet);
                // Logger.Log("Enqueuing stanza, count = " + _packetQ.Count);
                Monitor.Pulse(_lockQ);
            }
        }
Esempio n. 4
0
        public void Bind(string resource)
        {
            var packet = new Packet("resource") { Value = resource };

            var binder = new Packet("bind", "urn:ietf:params:xml:ns:xmpp-bind");
            binder.AddChild(packet);

            var iq = new IQ(IQType.Set);
            iq.AddChild(binder);

            Register(iq);
            Stream.Send(iq);
        }
        private Packet GetAuthPacket()
        {
            var auth = new Packet("auth", "urn:ietf:params:xml:ns:xmpp-sasl");
            auth.SetAttribute("mechanism", "PLAIN-PW-TOKEN");

            var userId = _account.Jid;
            if (userId.Contains('@'.ToString(CultureInfo.InvariantCulture)))
                userId = userId.Substring(0, _account.Jid.IndexOf('@'));

            var token = "\0" + userId + "\0" + _account.Password + "\0" + "somerandomstring";
            Logger.Log("Token = " + token);

            auth.Value = Convert.ToBase64String(Encoding.UTF8.GetBytes(token));
            return auth;
        }
 public override Packet Handle(Packet packet)
 {
     if (packet.Name == "failure")
     {
         // Logger.Log("Auth FAIL - " + packet);
     }
     if (packet.Name == "success")
     {
         var token = packet.GetChild("pw-token");
         var expiry = Int32.Parse(token.GetAttribute("expires_in_minutes"));
         var value = token.Value;
         Session.Token = new AuthToken(value, expiry);
         OnAuthentication(packet);
     }
     return packet;
 }
        public override Packet Handle(Packet packet)
        {
            if (packet.HasChild("mechanisms"))
            {
                var mechanisms = packet.GetChild("mechanisms").GetChildren("mechanism");

                if (mechanisms.Any(mechanism => mechanism.Value == "PLAIN-PW-TOKEN"))
                {
                    var pwAuth = new AuthenticationPlainPw(Session);
                    pwAuth.OnAuthentication += stanza => OnAuthenticated(stanza);
                    pwAuth.Authenticate();
                }
            }

            if (packet.HasChild("bind"))
            {
                var binder = new ResourceBinder(Session);
                binder.OnBinding += stanza => OnResourceBinding(stanza);
                binder.Bind(Session.Account.Resource);
            }

            return packet;
        }
Esempio n. 8
0
 public override Packet Handle(Packet packet)
 {
     return packet;
 }
Esempio n. 9
0
 public abstract Packet Handle(Packet packet);
Esempio n. 10
0
 public void Send(Packet packet)
 {
     Send(packet.ToString());
 }
Esempio n. 11
0
 public void Pulse(Packet packetForStop)
 {
     lock (_lockQ)
     {
         // Stopped = true;
         _packetQ.Clear();
         _packetQ.Add(packetForStop);
         Monitor.Pulse(_lockQ);
     }
 }
Esempio n. 12
0
        private void HandlePacket(Packet packet)
        {
            if (packet == null) return;

            // Logger.Log("Handling packet ...");

            if (packet.Name.Equals("empty"))
            {
                Logger.Log("Packet is empty");
            }

            if (packet.Name.Equals("error"))
            {
                Logger.Log(packet.HasChild("host-unknown")
                               ? "error - host unknown"
                               : "error");
            }

            if (!packet.HasAttribute("to"))
            {
                // Logger.Log("Packet does not have To attribute");
            }
            else
            {
                if (!packet.GetAttribute("to").ToLower().Trim().StartsWith(Properties.Account.Jid.ToLower().Trim()))
                {
                    // Logger.Log("Packet To attribute does not start with Jid " + Properties.Account.Jid);
                }
            }

            _stanzaQueue.Enqueue(packet);
        }
Esempio n. 13
0
 private void PushPacketOnStackOrProcessPacket(Packet packet)
 {
     if (_xmlBuildStack.Count > 0)
     {
         _xmlBuildStack.Peek().AddChild(packet);
     }
     else
     {
         if (packet != null)
         {
             Logger.Log("RECD:\n" + packet);
             HandlePacket(packet);
         }
     }
 }
Esempio n. 14
0
 public override bool HandlingCondition(Packet packet)
 {
     return packet.Name == "iq" && packet.GetAttribute("id") == _iq.Id;
 }
Esempio n. 15
0
        public void CloneAttributesAndChildrenFrom(Packet packetToCloneFrom)
        {
            var attribute = packetToCloneFrom.Element.Attributes();
            var element = packetToCloneFrom.Element.Elements();
            foreach (var xElement in element)
            {

            }
            _element.ReplaceAttributes(attribute);
            _element.Add(element);
        }
 public override bool HandlingCondition(Packet packet)
 {
     return (packet.Name == "features" && packet.HasChild("mechanisms")) ||
            (packet.Name == "features" && packet.HasChild("bind"));
 }
Esempio n. 17
0
 public static bool IsSuccess(Packet iq)
 {
     return iq.HasAttribute(_TYPE, "result");
 }
Esempio n. 18
0
 protected void add(Packet node)
 {
     _element.Add(node.Element);
 }
Esempio n. 19
0
        public void UpdateXmlnsIfEmpty(Packet peek)
        {
            var aw = peek.Element.Name.Namespace;

            if (string.IsNullOrEmpty(_element.Name.Namespace.NamespaceName))
                _element.Name = aw.GetName(_element.Name.LocalName);
        }
Esempio n. 20
0
        public bool RemoveChild(Packet child)
        {
            var elements = _element.Elements().Where(e => e.Name.LocalName == child.Name);

            if (elements.Any())
            {
                elements.Remove();
                return true;
            }
            return false;
        }
Esempio n. 21
0
 public abstract bool HandlingCondition(Packet packet);
Esempio n. 22
0
        private Packet GetXElement()
        {
            var packet = new Packet(_reader.LocalName);
            if (!_reader.HasAttributes) return packet;

            while (_reader.MoveToNextAttribute())
            {
                packet.SetAttribute(_reader.LocalName, _reader.Value);
            }

            if (_xmlBuildStack.Count > 0)
            {
                packet.UpdateXmlnsIfEmpty(_xmlBuildStack.Peek());
            }

            _reader.MoveToElement();
            return packet;
        }
 public override bool HandlingCondition(Packet packet)
 {
     return (packet.Name == "success" && packet.HasAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl")) ||
            (packet.Name == "failure" && packet.HasAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"));
 }
Esempio n. 24
0
        public void AddChild(Packet child)
        {
            var aw = _element.Name.Namespace;
            var xmlElement = child.Element;
            if (!aw.Equals(XNamespace.None))
            {
                while (xmlElement.Name.Namespace == XNamespace.None)
                {
                    /*if (String.IsNullOrEmpty(child.getXElement().Name.Namespace.NamespaceName))
                    {
                        child.getXElement().Name = aw.GetName(child.getXElement().Name.LocalName);
                    }*/
                    SetNameSpace(aw, xmlElement);

                }
            }
            _element.Add(child.Element);
        }
Esempio n. 25
0
 public Packet HandleStanza(Packet packet)
 {
     // Logger.Log("Handling packet at Xmpp ...");
     OnPacketReceived(packet);
     return packet;
 }
Esempio n. 26
0
 public static bool IsSet(Packet iq)
 {
     return iq.HasAttribute(_TYPE, "set");
 }