示例#1
1
        public void Setup()
        {
            mocks = new MockRepository();

            stream = mocks.DynamicMock<JabberClient>();

            doc = new XmlDocument();
        }
示例#2
0
    /// <summary>Initiate a Xmpp client handle.</summary>
    public XmppService(string username, string password, int port)
    {
      _write_lock = new object();
      _jc = new JabberClient();

      JID jid = new JID(username);
      _jc.User = jid.User;
      _jc.Server = jid.Server;
      _jc.Password = password;
      _jc.Port = port;

      _jc.AutoReconnect = 30F;
      _jc.AutoStartTLS = true;
      _jc.KeepAlive = 30F;
      _jc.AutoPresence = false;
      _jc.AutoRoster = false;
      _jc.LocalCertificate = null;
      var rng = new RNGCryptoServiceProvider();
      byte[] id = new byte[4];
      rng.GetBytes(id);
      _jc.Resource = RESOURCE_NS + BitConverter.ToString(id).Replace("-", "");

      _jc.OnInvalidCertificate += HandleInvalidCert;
      _jc.OnAuthenticate += HandleAuthenticate;
      _jc.OnAuthError += HandleAuthError;
      _jc.OnError += HandleError;
      _jc.OnIQ += HandleIQ;
      _jc.OnPresence += HandlePresence;
      _jc.OnMessage += HandleMessage;

      _online = new Dictionary<string, JID>();
      _demux = new Dictionary<Type, QueryCallback>();
    }
示例#3
0
        public XmppProtocolManager(Session session)
            : base(session)
        {
            Trace.Call(session);

            JabberClient = new JabberClient();
            JabberClient.Resource = "Smuxi";
            JabberClient.AutoLogin = true;
            JabberClient.AutoPresence = false;
            JabberClient.OnStreamInit += OnStreamInit;
            JabberClient.OnMessage += OnMessage;
            JabberClient.OnConnect += OnConnect;
            JabberClient.OnDisconnect += OnDisconnect;
            JabberClient.OnAuthenticate += OnAuthenticate;
            JabberClient.OnError += OnError;
            JabberClient.OnProtocol += OnProtocol;
            JabberClient.OnWriteText += OnWriteText;
            JabberClient.OnIQ += OnIQ;

            RosterManager = new RosterManager();
            RosterManager.Stream = JabberClient;
            RosterManager.OnRosterItem += OnRosterItem;

            PresenceManager = new PresenceManager();
            PresenceManager.Stream = JabberClient;
            JabberClient.OnPresence += OnPresence;

            ConferenceManager = new ConferenceManager();
            ConferenceManager.Stream = JabberClient;
            ConferenceManager.OnJoin += OnJoin;
            ConferenceManager.OnLeave += OnLeave;
            ConferenceManager.OnParticipantJoin += OnParticipantJoin;
            ConferenceManager.OnParticipantLeave += OnParticipantLeave;
        }
示例#4
0
        public JabberNetwork(SocialUser user, byte[] certData, 
      BlockingQueue queue, string jabber_port)
        {
            _local_user = user;
              _queue = queue;
              _friends = new Dictionary<string, List<string>>();
              _online = false;
              _auth_pending = false;
              _pres_sent = false;
              _jclient = new JabberClient();

              _jclient.Port = Int32.Parse(jabber_port);
              _jclient.AutoReconnect = 30F;
              _jclient.AutoStartTLS = true;
              _jclient.KeepAlive = 30F;
              _jclient.AutoPresence = false;
              _jclient.AutoRoster = false;
              _jclient.LocalCertificate = null;
              _jclient.Resource = SVPNRESOURCE +
            _local_user.Fingerprint.Substring(0, 10);

              _jclient.OnError += HandleOnError;
              _jclient.OnAuthError += HandleOnAuthError;

            #if SVPN_NUNIT
              _jclient.OnReadText += HandleOnReadText;
              _jclient.OnWriteText += HandleOnWriteText;
            #endif
              _jclient.OnAuthenticate += HandleOnAuthenticate;
              _jclient.OnPresence += HandleOnPresence;
              _jclient.OnIQ += HandleOnIQ;
              _jclient.OnInvalidCertificate += HandleInvalidCert;
        }
 private void ApplyJabberUserConfiguration(JabberClient jabberClient)
 {
     jabberClient.User = _chatConfig.Username;
     jabberClient.Password = _chatConfig.Password;
     jabberClient.NetworkHost = _chatConfig.Server;
     jabberClient.Server = _chatConfig.ServerName;
 }
示例#6
0
        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);
        }
示例#7
0
        public void AssignEvents(JabberClient inConn)
        {
            inConn.OnMessage += (s, msg) => {
                lock (mLock) {
                    mMessages.Enqueue(msg);

                    Monitor.PulseAll(mLock);
                }
            };
        }
示例#8
0
 public ArchiveUsersList(JabberClient jabberClient)
 {
     _jabberClient = jabberClient;
     InitializeComponent();
     _users = new ObservableCollection<ChatUser>();
     _filterUsers = new ObservableCollection<ChatUser>();
     usersListView.ItemsSource = _filterUsers;
     _viewChatUsers = new ObservableCollection<ViewChatUser>();
     _allViewChatUsers = new Dictionary<string, ViewChatUser>();
 }
示例#9
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 bedrock.ObjectHandler(GotDisconnect);
        }
示例#10
0
        public XmppService(string jid, string password, string host)
        {
            _jc = new JabberClient();
            _jc.Resource = XMPP_RESOURCE;
            _jc.AutoStartTLS = false;
            _jc.SSL = false;

            JID j = new JID(jid);
            _jc.User = j.User;
            _jc.Server = j.Server;
            _jc.Password = password;
            _jc.NetworkHost = host;
        }
示例#11
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);
        }
        public void Notify()
        {
            var settings = EsFacade.Settings;
            string server = settings["JabberServer"];
            string login = settings["JabberLogin"];
            string pass = settings["JabberPassword"];

            if (!Validator.HasValue(server, login, pass))
            {
                EsFacade.Logger.Warn("Jabber settings not properly configured.");
                return;
            }

            // we will wait on this event until we're done sending
            ManualResetEvent done = new ManualResetEvent(false);

            JabberClient j = new JabberClient
            {
                User = login,
                Server = server,
                Password = pass,
                AutoPresence = false,
                AutoRoster = false,
                AutoReconnect = -1
            };

            // listen for errors.  Always do this!
            j.OnError += (o, ex) =>
            {
                EsFacade.Logger.Error("Jabber notification error.", ex.Message);
                done.Set();
            };

            // what to do when login completes
            j.OnAuthenticate += o =>
            {
                JabberClient client = (JabberClient)o;
                client.Message(_to.Jabber, _message);
                done.Set();
            };

            // Set everything in motion
            j.Connect();

            // wait until sending a message is complete
            done.WaitOne();

            // logout cleanly
            j.Close();
        }
        private JabberClient Connection(string inHostName, AuctionCredencial inCredencial)
        {
            var connection = new JabberClient();

            connection.AutoLogin = true;
            connection.AutoStartTLS = false;
            connection.User = inCredencial.Id.User;
            connection.Server = inCredencial.Id.Server;
            connection.Resource = inCredencial.Id.Resource;
            connection.Password = inCredencial.Password;
            connection.Port = 5222;
            connection.NetworkHost = inHostName;

            return connection;
        }
示例#14
0
        /// <summary>
        /// Create a jabber session
        /// </summary>
        public JabberSession(Dispatcher dispatcher = null)
        {
            Dispatcher = dispatcher;

            jabberClient = new JabberClient();
            conferenceManager = new ConferenceManager {Stream = jabberClient};
            Conferences = new ConferenceCollection(this);

            jabberClient.OnAuthenticate += s => Invoke(() => jabberClient_OnAuthenticate(s));
            jabberClient.OnAuthError += (s, rp) => Invoke(() => jabberClient_OnAuthError(s, rp));
            jabberClient.OnConnect += (s, stream) => Invoke(() => jabberClient_OnConnect(s, stream));
            jabberClient.OnDisconnect += s => Invoke(() => jabberClient_OnDisconnect(s));
            jabberClient.OnError += (s, exc) => Invoke(() => jabberClient_OnError(s, exc));
            jabberClient.OnInvalidCertificate += jabberClient_OnInvalidCertificate;
            jabberClient.OnStreamError += (s, rp) => Invoke(() => jabberClient_OnStreamError(s, rp));

            reconnectTimer = new DispatcherTimer {Interval = TimeSpan.FromSeconds(10)};
            reconnectTimer.Tick += reconnectTimer_Tick;
        }
示例#15
0
        public Chat(JID inToJId, JabberClient inConnection)
        {
            this.Connection = inConnection;
            this.Connection.OnMessage += (s, m) => {
                if (this.Translator != null) {
                    this.Translator.ProcessMessage(this, m);
                }
            };

            this.Connection.OnError += (s, ex) => {
                if (this.Translator != null) {
                }
            };

            this.ToJId = inToJId;
            this.FromId = new JID(
                this.Connection.User, this.Connection.NetworkHost, this.Connection.Resource
            );
        }
示例#16
0
        static void Main(string[] args)
        {
            var client = new JabberClient();

            client.AutoPresence = false;
            client.AutoRoster = false;
            client.AutoReconnect = -1;

            client.User = "******";
            client.Password = "******";
            client.Server = "gmail.com";
            client.Port = 5222;
            client.Resource = "Pidgin";

            client.OnMessage += (s, e) =>
                                    {
                                        Console.WriteLine("Message sent...");
                                    };

            client.OnAuthError += (s, e) =>
                                      {
                                          Console.WriteLine("Auth Error: " + e.InnerText);
                                          client.Close();
                                      };

            client.OnAuthenticate += s =>
                                         {
                                             Console.WriteLine("Authenticated...");
                                             client.Message("*****@*****.**", "Testing");
                                         };

            client.OnError += (s, e) =>
                                  {
                                      Console.WriteLine("Error! " + e.Message);
                                      client.Close();
                                  };

            client.Connect();

            done.WaitOne();
            client.Close();
        }
        public GTalkConnection(string strUsername, string strPassword)
        {
            _jc = new JabberClient();
            _jc.AutoReconnect = 3F;
            _jc.AutoStartCompression = true;
            _jc.AutoStartTLS = true;
            _jc.KeepAlive = 30F;
            _jc.LocalCertificate = null;
            _jc.SSL = false;
            _jc.Proxy = jabber.connection.ProxyType.None;
            _jc.Server = "gmail.com";
            _jc.Password = strPassword;
            _jc.User = strUsername;

            _jc.OnError += new bedrock.ExceptionHandler(_jc_OnError);
            _jc.OnConnect += new jabber.connection.StanzaStreamHandler(this._jc_OnConnect);
            _jc.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(_jc_OnInvalidCertificate);
            _jc.OnAuthError += new jabber.protocol.ProtocolHandler(_jc_OnAuthError);
            _jc.OnMessage += new MessageHandler(_jc_OnMessage);
            _jc.OnDisconnect += new bedrock.ObjectHandler(_jc_OnDisconnect);
        }
示例#18
0
        static XmppGlobal()
        {
            jabber_client = new JabberClient ();

            roster_manager = new RosterManager ();
            roster_manager.Stream = jabber_client;

            presence_manager = new PresenceManager ();
            presence_manager.Stream = jabber_client;

            iq_tracker = new IQTracker (jabber_client);

            connection = new Connection ();
            debug = new Debug ();
            disco = new Disco ();
            presence = new Presence ();
            roster = new Roster ();
            queries = new Queries ();
            query_cache = new QueryCache ();
            messaging = new Messaging ();
        }
示例#19
0
        public static void WaitDisconnectingTo(JabberClient inClient)
        {
            if (! inClient.IsAuthenticated) return;

            var locker = new object();
            var connected = true;

            inClient.OnDisconnect += (s) => {
                lock (locker) {
                    connected = false;
                    Monitor.PulseAll(locker);
                }
            };

            while (true) {
                lock (locker) {
                    Monitor.Wait(locker, TimeSpan.FromMilliseconds(100));

                    if (! connected) break;
                }
            }
        }
示例#20
0
        public GoogleTalkDataAccess()
        {
            var client = new JabberClient();

            client.AutoLogin = true;
            client.AutoPresence = true;
            client.AutoRoster = false;
            client.AutoReconnect = 1;

            client.Server = "gmail.com";
            client.Port = 5222;
            client.Resource = "Alloy";
            client.OnAuthenticate += client_OnAuthenticate;

            client.OnConnect += (s, e) =>
                                    {
                                        IsConnected = e.Connected;

                                    };

            client.OnError += (s, e) =>
            {
                throw e;
            };
            client.OnAuthError += (s, e) => OnAuthError.SafelyInvoke(s, null);
            client.OnMessage += (s, e) => OnMessage.SafelyInvoke(s, new GTalkMessageEventArgs(e.From.User, e.Body, DateTime.Now));

            client.OnPresence += (sndr, e) => OnContactsReceived.SafelyInvoke(this, new ContactEventArgs()
                                                                                        {
                                                                                            ReceivedContacts =
                                                                                                new IIdentity[]
                                                                                                    {
                                                                                                        new Identity(e.From.User, null)
                                                                                                    }
                                                                                        });
            _Client = client;
        }
        public ConfigurationWindow(JabberClient jClient, ClientConfig config)
        {
            InitializeComponent();
            var chatConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "gibbon.config");
            if(File.Exists(chatConfigPath))
            {
                ReadChatConfig(chatConfigPath);
            }
            else
            {
                ReadAppConfig(config);
            }

            jabberClient = jClient;

            userNameTextbox.Text = _chatConfig.Username;
            userPasswordBox.Text = _chatConfig.Password;
            serverTextbox.Text = _chatConfig.Server;
            serverNameTextbox.Text = _chatConfig.ServerName;

            jabberClient.OnAuthenticate += new bedrock.ObjectHandler(jabberClient_OnAuthenticate);
            jabberClient.OnAuthError += new jabber.protocol.ProtocolHandler(jabberClient_OnAuthError);
            jabberClient.OnError += new bedrock.ExceptionHandler(jabberClient_OnError);
        }
示例#22
0
    public JabberNetwork(string network_host, string jabber_port,
      bool autoFriend, SocialNode node) {

      _jclient = new JabberClient();
      _jclient.Port = Int32.Parse(jabber_port);
      _jclient.NetworkHost = network_host;
      _jclient.AutoReconnect = 30F;
      _jclient.AutoStartTLS = true;
      _jclient.AutoStartCompression = false;
      _jclient.KeepAlive = 30F;
      _jclient.AutoPresence = true;
      _jclient.AutoRoster = false;
      _jclient.LocalCertificate = null;
      Random rand = new Random();
      _jclient.Resource = SVPNRESOURCE + rand.Next(Int32.MaxValue);

      _jclient.OnAuthenticate += HandleOnAuthenticate;
      _jclient.OnPresence += HandleOnPresence;
      _jclient.OnIQ += HandleOnIQ;
      _jclient.OnInvalidCertificate += 
        new RemoteCertificateValidationCallback(HandleInvalidCert);
      
      _jclient.OnError += HandleOnError;
      _jclient.OnAuthError += HandleOnAuthError;
      _jclient.OnReadText += HandleOnReadText;
      _jclient.OnWriteText += HandleOnWriteText;

      _rman = null;
      _node = node;

      if(autoFriend) {
        _rman = new RosterManager();
        _rman.Stream = _jclient;
        _rman.AutoAllow = jabber.client.AutoSubscriptionHanding.AllowAll;
      }
    }
 private JID ToJid(string inItemId, JabberClient inConnection)
 {
     return new JID(
         string.Format(ItemIdAsLogin, inItemId),
         inConnection.Server,
         inConnection.Resource
     );
 }
示例#24
0
        public void Connect(bool initialPresence)
        {
            this.jabberClient = new JabberClient();
            this.jabberClient.OnReadText += this.InternalOnReadText;
            this.jabberClient.OnWriteText += this.InternalOnWriteText;
            this.jabberClient.OnError += new ExceptionHandler(this.OnError);
            this.jabberClient.OnStreamError += new jabber.protocol.ProtocolHandler(this.OnStreamError);

            var jid = new JID(this.username);
            this.jabberClient.User = jid.User;
            this.jabberClient.Server = jid.Server;
            this.jabberClient.NetworkHost = this.host;
            this.jabberClient.Port = this.port;
            this.jabberClient.Resource = "Hangout Phone";
            this.jabberClient.Password = this.password;
            this.jabberClient.AutoStartTLS = true;
            this.jabberClient.AutoPresence = initialPresence;
            this.jabberClient.AutoReconnect = 3f;

            this.capabilityManager = new CapsManager { Stream = this.jabberClient, Node = "http://rankida.com" };

            this.jabberClient.Connect();
        }
示例#25
0
 public void Close()
 {
     if (this.jabberClient != null)
     {
         this.jabberClient.Close();
         this.jabberClient.Dispose();
         this.jabberClient = null;
     }
 }
示例#26
0
        void Init()
        {
            client = new JabberClient ();
            var j = profile.Username;

            var jid = new JID (j);
            client.User = jid.User;
            client.Server = jid.Server;
            client.Resource = jid.Resource;
            client.NetworkHost = profile.NetworkHost;
            client.Password = profile.Password;
        }
示例#27
0
        public XmppProtocolManager(Session session)
            : base(session)
        {
            Trace.Call(session);

            _JabberClient = new JabberClient();
            _JabberClient.Resource = Engine.VersionString;
            _JabberClient.AutoLogin = true;
            _JabberClient.AutoPresence = false;
            _JabberClient.OnMessage += new MessageHandler(_OnMessage);
            _JabberClient.OnConnect += OnConnect;
            _JabberClient.OnDisconnect += OnDisconnect;
            _JabberClient.OnAuthenticate += OnAuthenticate;
            _JabberClient.OnError += OnError;
            _JabberClient.OnProtocol += OnProtocol;
            _JabberClient.OnWriteText += OnWriteText;

            _RosterManager = new RosterManager();
            _RosterManager.Stream = _JabberClient;

            _ConferenceManager = new ConferenceManager();
            _ConferenceManager.Stream = _JabberClient;
            _ConferenceManager.OnJoin += OnJoin;
            _ConferenceManager.OnLeave += OnLeave;
            _ConferenceManager.OnParticipantJoin += OnParticipantJoin;
            _ConferenceManager.OnParticipantLeave += OnParticipantLeave;
        }
        private void JoinAuction(JabberClient inConnection, string inItemId)
        {
            mAuction = new XMPPAuction(
                new Chat(this.ToJid(inItemId, inConnection), inConnection), new SniperStateDisplayer()
            );

            if (this.BeginJoining != null) {
                this.BeginJoining(inConnection);
            }

            inConnection.Connect();
            ConsoleAppHelper.WaitConnectingTo(inConnection);

            mAuction.Join();
        }
示例#29
0
 private void ApplyDefaultJabberConfiguration(JabberClient jabberClient)
 {
     jabberClient.User = _config.Username;
     jabberClient.Password = _config.Password;
     jabberClient.NetworkHost = _config.Server;
     jabberClient.Server = _config.ServerName;
     jabberClient.AutoReconnect = 30F;
     jabberClient.AutoStartCompression = true;
     jabberClient.AutoStartTLS = true;
     jabberClient.KeepAlive = 30F;
     jabberClient.LocalCertificate = null;
 }
示例#30
0
文件: Bot.cs 项目: mbsky/bugx
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"></see> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application</param>
        public void Init(HttpApplication context)
        {
            if (ErrorModule.IsReBug || _Initialized)
            {//Disable bot when it's a ReBug or if module is already initialized
                return;
            }
            _Initialized = true;
            SubscriptionCollection.LoadSettings();
            _Bot = new JabberClient();
            _Bot.AutoReconnect = 0;
            _Bot.AutoPresence = false;
            _Bot.OnMessage += new MessageHandler(Bot_OnMessage);
            _Bot.OnAuthenticate += new bedrock.ObjectHandler(Bot_OnAuthenticate);
            _Bot.OnPresence += new PresenceHandler(_Bot_OnPresence);

            AsyncSocket.UntrustedRootOK = true;
            ErrorModule.ErrorComplete += new EventHandler<BugEventArgs>(ErrorModule_ErrorComplete);
            ErrorModule.ApplicationUnload += new EventHandler<ApplicationUnloadEventArgs>(ErrorModule_ApplicationUnload);

            SubscriptionCollection settings = SubscriptionCollection.Instance;
            _Bot.User         = settings.User;
            _Bot.Password     = settings.Password;
            _Bot.Server       = settings.Server;
            _Bot.NetworkHost  = settings.NetworkHost;
            _Bot.Resource     = "Bugx Talk (bot)";
            _Bot.AutoStartTLS = true;

            _Bot.Connect();
        }
示例#31
0
 public void Connect()
 {
     _jabberClient = new JabberClient
     {
         Server = this.Server,
         User = this.UserName,
         Password = this.Password,
         Resource = this.Resource,
         AutoStartTLS = true,
         PlaintextAuth = true,
         AutoPresence = true,
         AutoRoster = false,
         AutoReconnect = -1,
         AutoLogin = true
     };
     _presenceManager = new PresenceManager
     {
         Stream = _jabberClient
     };
     _discoManager = new DiscoManager();
     // add presence manager event handlers
     _presenceManager.OnPrimarySessionChange += presenceManager_OnPrimarySessionChange;
     _presenceManager.OnStreamChanged += presenceManager_OnStreamChanged;
     _presenceManager.OnPrimarySessionChange += presenceManager_OnPrimarySessionChange;
     // add jabber client event handlers
     _jabberClient.OnAfterPresenceOut += jabber_OnAfterPresenceOut;
     _jabberClient.OnAuthenticate += jabber_OnAuthenticate;
     _jabberClient.OnAuthError += jabber_OnAuthError;
     _jabberClient.OnBeforePresenceOut += jabber_OnBeforePresenceOut;
     _jabberClient.OnConnect += jabber_OnConnect;
     _jabberClient.OnDisconnect += jabber_OnDisconnect;
     _jabberClient.OnError += jabber_OnError;
     _jabberClient.OnInvalidCertificate += jabber_OnInvalidCertificate;
     _jabberClient.OnIQ += jabber_OnIQ;
     _jabberClient.OnLoginRequired += jabber_OnLoginRequired;
     _jabberClient.OnMessage += jabber_OnMessage;
     _jabberClient.OnPresence += jabber_OnPresence;
     _jabberClient.OnProtocol += jabber_OnProtocol;
     _jabberClient.OnReadText += jabber_OnReadText;
     _jabberClient.OnRegistered += jabber_OnRegistered;
     _jabberClient.OnRegisterInfo += jabber_OnRegisterInfo;
     _jabberClient.OnStreamError += jabber_OnStreamError;
     _jabberClient.OnStreamHeader += jabber_OnStreamHeader;
     _jabberClient.OnStreamInit += jabber_OnStreamInit;
     _jabberClient.OnWriteText += jabber_OnWriteText;
     // add discovery manager event handlers
     _discoManager.OnStreamChanged += discoManager_OnStreamChanged;
     // connect to the HipChat server
     this.Logger.Info(string.Format("Connecting to '{0}'", _jabberClient.Server));
     _jabberClient.Connect();
     var retryCountLimit = 10;
     while (!_jabberClient.IsAuthenticated && retryCountLimit > 0)
     {
         this.Logger.Info(string.Format("Waiting..."));
         retryCountLimit--;
         Thread.Sleep(1000);
     }
     if (_jabberClient.IsAuthenticated)
     {
         this.Logger.Info(string.Format("Authenticated as '{0}'", _jabberClient.User));
     }
 }
示例#32
0
        public Class1(string[] args)
        {
            JabberClient m_jc = new JabberClient();
            m_jc.OnReadText += new bedrock.TextHandler(jc_OnReadText);
            m_jc.OnWriteText += new bedrock.TextHandler(jc_OnWriteText);
            m_jc.OnError +=new bedrock.ExceptionHandler(jc_OnError);
            m_jc.OnStreamError += new jabber.protocol.ProtocolHandler(jc_OnStreamError);

            m_jc.AutoReconnect = 3f;

            m_jc.Resource = "StagePresence";
            m_jc.AutoPresence = false;//true;//HACK: initialPresence;

            // connect over a BOSH stuff
            m_jc.Server = "chat-test.vix.tv";
            m_jc.NetworkHost = "chat-test.vix.tv";
            m_jc.Port = 443;
            m_jc[Options.POLL_URL] = "https://chat.vix.tv/http-bind/";

            // Set server based on BOSH URL
            Uri uri = new Uri(m_jc[Options.POLL_URL].ToString());
            m_jc.Server = uri.Host;
            m_jc[Options.CONNECTION_TYPE] = ConnectionType.HTTP_Binding;
            m_jc[Options.ANONYMOUS] = true;
            m_jc[Options.AUTO_ROSTER] = false;

            CapsManager cm = new CapsManager();
            cm.Stream = m_jc;
            cm.Node = "http://vix.tv";

            Console.WriteLine("Connecting");
            m_jc.Connect();
            Console.WriteLine("Connected");

            //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;
            //    Uri uri = new Uri(jc[Options.POLL_URL].ToString());
            //    jc.Server = uri.Host;
            //    jc[Options.ANONYMOUS] = true;
            //    jc[Options.AUTO_ROSTER] = false;
            //}

            //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://vix.tv";

            //Console.WriteLine("Connecting");
            //jc.Connect();
            //Console.WriteLine("Connected");

            //while (true)
            //{
            //
            //}
            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")) {
                    m_jc.Close();
                    break;
                }
                if (line.Trim() == "") {
                    continue;
                }
                try {
                    if (line == "</stream:stream>") {
                        m_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)
                            m_jc.Write(elem);
                    }
                }
                catch (XmlException ex) {
                    Console.WriteLine("Invalid XML: " + ex.Message);
                }
            }
        }
示例#33
0
        public Class1(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);
                }
            }
        }