Esempio n. 1
0
        public void Setup()
        {
            mocks = new MockRepository();

            stream = mocks.DynamicMock<JabberClient>();

            doc = new XmlDocument();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //newThread = new Thread(new ThreadStart(() =>
            //{
            jc = new JabberClient();
            jc.OnReadText += new Bedrock.TextHandler((sender, text) => Console.WriteLine(text));
            jc.OnWriteText += new Bedrock.TextHandler((sender, text) => Console.WriteLine(text));
            jc.OnError += new Bedrock.ExceptionHandler((sender, ex) => Console.WriteLine(ex.Message));
            jc.OnStreamError += new Jabber.Protocol.ProtocolHandler((sender, ex) => Console.WriteLine(ex.ToString()));
            jc.AutoReconnect = 3f;
            jc.OnInvalidCertificate += jc_OnInvalidCertificate;
            jc.User = Console.ReadLine();
            jc.Server = "jabber.devsmm.com";
            jc.NetworkHost = "192.168.1.46";
            jc.Port = 5222;
            jc.Resource = "Jabber.Net Console Client";
            jc.Password = "******";
            jc.AutoStartTLS = true;
            jc.AutoPresence = true;
            jc.Connection = ConnectionType.Socket;
            jc["USE_WINDOWS_CREDS"] = false;
            jc["plaintext"] = false;
            jc["to"] = "jabber.devsmm.com";
            jc["network_host"] = "192.168.1.46"; //"jabber.devsmm.com";
            jc["ssl"] = false;
            jc["port"] = 5222;
            jc["poll.url"] = "";
            jc.OnMessage += jc_OnMessage;
            jc.OnAuthError += jc_OnAuthError;
            jc.OnAuthenticate += jc_OnAuthenticate;
            jc.OnConnect += jc_OnConnect;

            Console.WriteLine("Connecting");
            jc.Connect();
            Console.WriteLine("Connected");
            Console.ReadLine();
            Console.WriteLine("Subject:");
            var subject = Console.ReadLine();
            Console.WriteLine("Subject:" + subject);
            Console.WriteLine("Body:");
            var body = Console.ReadLine();
            Message msg = new Message(jc.Document);
            msg.To = "admin@" + jc.Server;
            //msg.From = new JID("kill@" + jc.Server);
            msg.Subject = subject;
            msg.Body = body;
            jc.Write(msg);

            Console.WriteLine("sent");
            Console.WriteLine("Closing");
            //}));
            //newThread.Start();

            //handle = new ManualResetEvent(false);
            //handle.WaitOne(Timeout.Infinite);
            Console.WriteLine("Closing");
            Console.ReadLine();
        }
Esempio n. 3
0
        /// <summary>
        /// Entry point for XMPP stream events
        /// </summary>
        /// <param name="sender"></param>
        private void RpcManager_OnStreamChanged(object sender)
        {
            JabberClient cli = m_stream as JabberClient;

            if (cli == null)
            {
                return;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Entry point for XMPP stream events
        /// </summary>
        /// <param name="sender"></param>
        private void PingManager_OnStreamChanged(object sender)
        {
            JabberClient cli = m_stream as JabberClient;

            if (cli == null)
            {
                return;
            }

            cli.OnIQ += new IQHandler(this.GotIQ);
        }
        private void PresenceManager_OnStreamChanged(object sender)
        {
            JabberClient cli = m_stream as JabberClient;

            if (cli == null)
            {
                return;
            }

            cli.OnPresence   += new PresenceHandler(GotPresence);
            cli.OnDisconnect += new Bedrock.ObjectHandler(GotDisconnect);
        }
Esempio n. 6
0
        /// <summary>
        /// Entry point for XMPP stream events
        /// </summary>
        /// <param name="sender"></param>
        private void JingleManager_OnStreamChanged(object sender)
        {
            //this.Tracker = new IQTracker(m_stream);

            JabberClient cli = m_stream as JabberClient;

            if (cli == null)
            {
                return;
            }

            cli.OnIQ += new IQHandler(this.GotIQ);
        }
Esempio n. 7
0
        private void RosterManager_OnStreamChanged(object sender)
        {
            JabberClient cli = m_stream as JabberClient;

            if (cli == null)
            {
                return;
            }

            cli.OnIQ         += new IQHandler(GotIQ);
            cli.OnPresence   += new PresenceHandler(cli_OnPresence);
            cli.OnDisconnect += new ObjectHandler(GotDisconnect);
        }
Esempio n. 8
0
        private void BookmarkManager_OnStreamChanged(object sender)
        {
            m_stream.OnDisconnect += new Bedrock.ObjectHandler(m_stream_OnDisconnect);
            m_stream.OnError      += new Bedrock.ExceptionHandler(m_stream_OnError);
            JabberClient cli = m_stream as JabberClient;

            if (cli == null)
            {
                return;
            }

            cli.OnAuthenticate += new Bedrock.ObjectHandler(cli_OnAuthenticate);
        }
Esempio n. 9
0
        public Program(string[] args)
        {
            JabberClient jc = new JabberClient();
            jc.OnReadText += new Bedrock.TextHandler(jc_OnReadText);
            jc.OnWriteText += new Bedrock.TextHandler(jc_OnWriteText);
            jc.OnError += new Bedrock.ExceptionHandler(jc_OnError);
            jc.OnStreamError += new 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 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);
                }
            }
        }