public void OnBeforePresenceOutTest()
        {
            IEventRaiser presHandler;
            using (mocks.Record())
            {
                stream.OnBeforePresenceOut += null;
                presHandler = LastCall.IgnoreArguments().GetEventRaiser();
            }

            using (mocks.Playback())
            {
                CapsManager cm = new CapsManager();
                cm.Stream = stream;
                cm.Node = NODE;

                Presence packet = CreatePresencePacket();
                presHandler.Raise(new object[] { null, packet });

                string original = packet.OuterXml.Replace(" ", "");
                string comparison = GetPresenceWithCaps(cm.Ver).Replace(" ", "");
                Assert.IsTrue(original == comparison);
            }
        }
        public void TestCaps()
        {
            PresenceManager pp = new PresenceManager();
            Presence pres = new Presence(doc);
            pres.From = baz;

            CapsManager cm = new CapsManager();
            pp.CapsManager = cm;

            cm.FileName = "caps.xml";
            cm.Node = "http://cursive.net/clients/PresenceManagerTest";
            cm.AddFeature(URI.DISCO_INFO);
            cm.AddFeature(URI.DELAY);
            cm.AddIdentity("client", "pc", null, "Presence Manager Test");

            DiscoInfo info = new DiscoInfo(doc);
            cm.FillInInfo(info);
            cm[cm.Ver] = info;

            pres.AddChild(cm.GetCaps(pres.OwnerDocument));
            pp.AddPresence(pres);

            JID dij = pp.GetFeatureJID(bare, URI.DISCO_INFO);
            Assert.AreEqual(baz, dij);
            dij = pp.GetFeatureJID(bare, URI.DISCO_ITEMS);
            Assert.IsNull(dij);
            dij = pp.GetFeatureJID(baz, URI.DISCO_INFO);
            Assert.AreEqual(baz, dij);

            StringSet fs = pp.GetFeatures(bare);
            Assert.IsTrue(fs[URI.DISCO_INFO]);
            Assert.IsFalse(fs[URI.DISCO_ITEMS]);
        }
 public JID GetFeatureJID(CapsManager caps, string featureURI)
 {
     gen.LinkedListNode<Presence> n;
     for (n = m_all.Last; n != null; n = n.Previous)
     {
         StringSet f = GetFeatures(caps, n.Value);
         if ((f != null) && f.Contains(featureURI))
             return n.Value.From;
     }
     return null;
 }
            public StringSet GetAllFeatures(CapsManager caps)
            {
                if (caps == null)
                    throw new ArgumentNullException("caps");

                StringSet features = new StringSet();
                foreach (Presence p in m_all)
                {
                    StringSet f = GetFeatures(caps, p);
                    if (f != null)
                        features.Add(f);
                }
                return features;
            }
            public StringSet GetFeatures(CapsManager caps, string resource)
            {
                if (resource == null)
                    return GetAllFeatures(caps);

                return GetFeatures(caps, this[resource]);
            }
            private StringSet GetFeatures(CapsManager caps, Presence p)
            {
                if (p == null)
                    return null;

                Caps c = p.GetChildElement<Caps>();
                if (c == null)
                    return null;

                DiscoInfo di = caps[c.Version];
                if (di == null)
                    return null;

                return di.FeatureSet;
            }
Exemple #7
0
        public Class1(string[] args)
        {
            JabberClient jc = new JabberClient();
            jc.OnReadText += new Kixeye.Bedrock.TextHandler(jc_OnReadText);
            jc.OnWriteText += new Kixeye.Bedrock.TextHandler(jc_OnWriteText);
            jc.OnError +=new Kixeye.Bedrock.ExceptionHandler(jc_OnError);
            jc.OnStreamError += new Kixeye.Jabber.Protocol.ProtocolHandler(jc_OnStreamError);

            jc.AutoReconnect = 3f;

            GetOpt go = new GetOpt(this);
            try
            {
                go.Process(args);
            }
            catch (ArgumentException)
            {
                go.UsageExit();
            }

            if (untrustedOK)
                jc.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(jc_OnInvalidCertificate);

            JID j = new JID(jid);
            jc.User = j.User;
            jc.Server = j.Server;
            jc.NetworkHost = networkHost;
            jc.Port = port;
            jc.Resource = "Jabber.Net Console Client";
            jc.Password = pass;
            jc.AutoStartTLS = TLS;
            jc.AutoPresence = initialPresence;

            if (certificateFile != null)
            {
                jc.SetCertificateFile(certificateFile, certificatePass);
                Console.WriteLine(jc.LocalCertificate.ToString(true));
            }

            if (boshURL != null)
            {
                jc[Options.POLL_URL] = boshURL;
                jc[Options.CONNECTION_TYPE] = ConnectionType.HTTP_Binding;
            }
            
            if (register)
            {
                jc.AutoLogin = false;
                jc.OnLoginRequired +=
                    new Kixeye.Bedrock.ObjectHandler(jc_OnLoginRequired);
                jc.OnRegisterInfo += new RegisterInfoHandler(this.jc_OnRegisterInfo);
                jc.OnRegistered += new IQHandler(jc_OnRegistered);
            }

            CapsManager cm = new CapsManager();
            cm.Stream = jc;
            cm.Node = "http://cursive.net/clients/ConsoleClient";
            
            Console.WriteLine("Connecting");
            jc.Connect();
            Console.WriteLine("Connected");

            string line;
            while ((line = Console.ReadLine()) != null)
            {
                if (line == "/clear")
                {
                    // Hm.... I wonder if this works on windows.
                    Console.Write("\x1b[H\x1b[2J");
                    continue;
                }
                if ((line == "/q") || (line == "/quit"))
                {
                    jc.Close();
                    break;
                }
                if (line.Trim() == "")
                {
                    continue;
                }
                try
                {
                    if (line == "</stream:stream>")
                    {
                        jc.Write(line);
                    }
                    else
                    {
                        // TODO: deal with stanzas that span lines... keep
                        // parsing until we have a full "doc".
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(line);
                        XmlElement elem = doc.DocumentElement;
                        if (elem != null)
                            jc.Write(elem);
                    }
                }
                catch (XmlException ex)
                {
                    Console.WriteLine("Invalid XML: " + ex.Message);
                }
            }
        }
        public void IqRequestTest()
        {
            string nodever = "";

            IEventRaiser iqEvent;
            using (mocks.Record())
            {
                stream.OnIQ += null;
                iqEvent = LastCall.IgnoreArguments().GetEventRaiser();

                Expect.Call(stream.Document).Return(doc);
                stream.Write((XmlElement)null);
                LastCall.Callback((Func<XmlElement, bool>)
                    delegate(XmlElement arg0)
                        {
                            string original = arg0.OuterXml.Replace(" ", "");
                            string comparison = GetIQResponse(nodever).Replace(" ", "");
                            return original == comparison;
                        });
            }

            using (mocks.Playback())
            {
                CapsManager cm = new CapsManager();
                cm.Stream = stream;
                cm.Node = NODE;

                nodever = cm.NodeVer;

                iqEvent.Raise(new object[] { null, CreateIqRequest() });
            }
        }
        public void ComplexGenerationExample()
        {

            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<book xml:lang='en'/>");
            XmlElement book = doc.DocumentElement;
            foreach (XmlAttribute attr in book.Attributes)
            {
                System.Console.WriteLine(attr.Name);
            }

            XmlElement root = doc.DocumentElement;

            DiscoInfo info = new DiscoInfo(doc);
            info.AddFeature("http://kixeye.jabber.org/protocol/muc");
            info.AddFeature("http://kixeye.jabber.org/protocol/disco#info");
            info.AddFeature("http://kixeye.jabber.org/protocol/disco#items");
            info.AddIdentity("client", "pc", "Psi 0.9.1", "en");
            info.AddIdentity("client", "pc", "\u03a8 0.9.1", "el");
            Data x = info.CreateExtension();
            x.FormType = "urn:xmpp:dataforms:softwareinfo";
            x.AddField("ip_version").Vals = new string[] { "ipv4", "ipv6" };
            x.AddField("os").Val = "Mac";
            x.AddField("os_version").Val = "10.5.1";
            x.AddField("software").Val = "Psi";
            x.AddField("software_version").Val = "0.11";

            DiscoNode dn = new DiscoNode(new JID(null, "placeholder", null), null);
            dn.AddInfo(info);

            CapsManager cm = new CapsManager(dn);
            Assert.AreEqual("8lu+88MRxmKM7yO3MEzY7YmTsWs=", cm.Ver);
        }
 public void SimpleGenerationExample()
 {
     CapsManager cm = new CapsManager();
     cm.AddIdentity("client", "pc", null, "Exodus 0.9.1");
     cm.AddFeature("http://kixeye.jabber.org/protocol/muc");
     cm.AddFeature("http://kixeye.jabber.org/protocol/disco#info");
     cm.AddFeature("http://kixeye.jabber.org/protocol/disco#items");
     Assert.AreEqual("SrFo9ar2CCk2EnOH4q4QANeuxLQ=", cm.Ver);
 }