Esempio n. 1
0
        public void RemakeXmpp()
        {
            if (Xmpp != null)
            {
                Xmpp.OnXmppConnectionStateChanged -= XmppOnOnXmppConnectionStateChanged;
                Xmpp.OnMessage     -= XmppOnOnMessage;
                Xmpp.OnError       -= XmppOnOnError;
                Xmpp.OnAuthError   -= Xmpp_OnAuthError;
                Xmpp.OnStreamError -= XmppOnOnStreamError;
                Xmpp.OnAgentStart  -= XmppOnOnAgentStart;
                Xmpp.Close();
                Xmpp = null;
            }
            Xmpp = new XmppClientConnection(AppConfig.Instance.ServerPath);
            ElementFactory.AddElementType("hostgamerequest", "octgn:hostgamerequest", typeof(HostGameRequest));

            Xmpp.RegisterAccount               = false;
            Xmpp.AutoAgents                    = true;
            Xmpp.AutoPresence                  = true;
            Xmpp.AutoRoster                    = true;
            Xmpp.Username                      = AppConfig.Instance.XmppUsername;
            Xmpp.Password                      = AppConfig.Instance.XmppPassword;
            Xmpp.Priority                      = 1;
            Xmpp.OnMessage                    += XmppOnOnMessage;
            Xmpp.OnError                      += XmppOnOnError;
            Xmpp.OnAuthError                  += Xmpp_OnAuthError;
            Xmpp.OnStreamError                += XmppOnOnStreamError;
            Xmpp.KeepAlive                     = true;
            Xmpp.KeepAliveInterval             = 60;
            Xmpp.OnAgentStart                 += XmppOnOnAgentStart;
            Xmpp.OnXmppConnectionStateChanged += XmppOnOnXmppConnectionStateChanged;
            Xmpp.Open();
        }
Esempio n. 2
0
        /// <summary>
        ///     Constructor with standard settings for a new HarmonyClient
        /// </summary>
        /// <param name="host">IP or hostname</param>
        /// <param name="token">Auth-token, or guest</param>
        /// <param name="port">The port to connect to, default 5222</param>
        /// <param name="keepAliveInterval">an optional keep alive interval, default is 50, Harmony needs 60 seconds</param>
        private HarmonyClient(string host, string token, int port = 5222, int?keepAliveInterval = 50)
        {
            Token = token;
            _xmpp = new XmppClientConnection(host, port)
            {
                UseStartTLS              = false,
                UseSSL                   = false,
                UseCompression           = false,
                AutoResolveConnectServer = false,
                AutoAgents               = false,
                AutoPresence             = true,
                AutoRoster               = true,
                // For https://github.com/Lakritzator/harmony/issues/19
                KeepAliveInterval = keepAliveInterval ?? 120,                 // 120 is the underlying default
                KeepAlive         = keepAliveInterval.HasValue
            };
            // Configure Sasl not to use auto and PLAIN for authentication
            _xmpp.OnSaslStart   += SaslStartHandler;
            _xmpp.OnLogin       += OnLoginHandler;
            _xmpp.OnIq          += OnIqResponseHandler;
            _xmpp.OnMessage     += OnMessage;
            _xmpp.OnSocketError += ErrorHandler;
            // Inform anyone who it may concern
            _xmpp.OnClose += sender => OnConnectionClosed?.Invoke(this, EventArgs.Empty);

            // Open the connection, do the login
            _xmpp.Open($"{token}@x.com", token);
        }
Esempio n. 3
0
        public void TestSendPresenceAndMessage()
        {
            //Logger logger = LogManager.GetLogger("foo");
            ILogger log = NLog.LogManager.GetLogger("foo");

            log.Info("Program started");
            Presence presence = new Presence(ShowType.Show);

            JabberID from    = new JabberID(myJid);
            JabberID to      = new JabberID(partnerJid);
            string   msg     = "Hello";
            Message  message = new Message(from, to, msg);

            XmppClientConnection connection = new XmppClientConnection(
                new JabberID(myJid), password);

            connection.Login();

            if (!connection.Connected || !connection.Authenticated)
            {
                throw new Exception("Not authenticate");
            }

            Assert.DoesNotThrow(() => { connection.Send(presence); });
            Assert.DoesNotThrow(() => { connection.Send(message); });

            //NLogger.ShutdownLogger();
        }
Esempio n. 4
0
        public void TestMessageGrabber()
        {
            Presence presence = new Presence(ShowType.Show);

            int    waitMessage = 20000;
            string msg         = "hello";
            string expected    = partnerJid + ":hello";

            JabberID jidPartner = new JabberID(partnerJid);
            Message  message    = new Message(myJid, jidPartner.Full, msg);

            XmppClientConnection connection = new XmppClientConnection(
                new JabberID(myJid), password);

            connection.MessageGrabber.Add(
                jidPartner, new MessageCallback(messageCallback));

            connection.Login();

            connection.Send(presence);
            connection.Send(message);

            while (partnerMessage == null)
            {
                Thread.Sleep(2000);
            }

            Assert.AreEqual(expected, partnerMessage);
        }
        public override void Init(XmppClientConnection con)
        {
            m_XmppClient = con;

            // <auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">$Message</auth>
            m_XmppClient.Send(new protocol.sasl.Auth(protocol.sasl.MechanismType.PLAIN, Message()));
        }
Esempio n. 6
0
 public frmMain()
 {
     this.InitializeComponent();
     base.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - base.Width, Screen.PrimaryScreen.WorkingArea.Height - base.Height);
     this.XmppCon = new XmppClientConnection();
     this.XmppCon.set_SocketConnectionType(0);
     this.XmppCon.add_OnReadXml(new XmlHandler(this, (IntPtr) this.XmppCon_OnReadXml));
     this.XmppCon.add_OnWriteXml(new XmlHandler(this, (IntPtr) this.XmppCon_OnWriteXml));
     this.XmppCon.add_OnRosterStart(new ObjectHandler(this, (IntPtr) this.XmppCon_OnRosterStart));
     this.XmppCon.add_OnRosterEnd(new ObjectHandler(this, (IntPtr) this.XmppCon_OnRosterEnd));
     this.XmppCon.add_OnRosterItem(new XmppClientConnection.RosterHandler(this, (IntPtr) this.XmppCon_OnRosterItem));
     this.XmppCon.add_OnAgentStart(new ObjectHandler(this, (IntPtr) this.XmppCon_OnAgentStart));
     this.XmppCon.add_OnAgentEnd(new ObjectHandler(this, (IntPtr) this.XmppCon_OnAgentEnd));
     this.XmppCon.add_OnAgentItem(new XmppClientConnection.AgentHandler(this, (IntPtr) this.XmppCon_OnAgentItem));
     this.XmppCon.add_OnLogin(new ObjectHandler(this, (IntPtr) this.XmppCon_OnLogin));
     this.XmppCon.add_OnClose(new ObjectHandler(this, (IntPtr) this.XmppCon_OnClose));
     this.XmppCon.add_OnError(new ErrorHandler(this, (IntPtr) this.XmppCon_OnError));
     this.XmppCon.add_OnPresence(new XmppClientConnection.PresenceHandler(this, (IntPtr) this.XmppCon_OnPresence));
     this.XmppCon.add_OnMessage(new XmppClientConnection.MessageHandler(this, (IntPtr) this.XmppCon_OnMessage));
     this.XmppCon.add_OnIq(new StreamHandler(this, (IntPtr) this.XmppCon_OnIq));
     this.XmppCon.add_OnAuthError(new OnXmppErrorHandler(this, (IntPtr) this.XmppCon_OnAuthError));
     this.XmppCon.add_OnReadSocketData(new BaseSocket.OnSocketDataHandler(this, (IntPtr) this.ClientSocket_OnReceive));
     this.XmppCon.add_OnWriteSocketData(new BaseSocket.OnSocketDataHandler(this, (IntPtr) this.ClientSocket_OnSend));
     this.XmppCon.get_ClientSocket().add_OnValidateCertificate(new RemoteCertificateValidationCallback(this.ClientSocket_OnValidateCertificate));
     this.XmppCon.add_OnXmppConnectionStateChanged(new XmppConnection.XmppConnectionStateHandler(this, (IntPtr) this.XmppCon_OnXmppConnectionStateChanged));
     this.XmppCon.add_OnSaslStart(new SaslEventHandler(this, (IntPtr) this.XmppCon_OnSaslStart));
 }
Esempio n. 7
0
        public override Task Close()
        {
            _client.Close();
            _client = null;

            return(Task.FromResult(0));
        }
Esempio n. 8
0
        private void SetupHipChatClient()
        {
            if (_client != null)
            {
                return;
            }

            _client = new XmppClientConnection(_host);
            _client.AutoResolveConnectServer = false;
            _client.OnLogin     += OnClientLogin;
            _client.OnMessage   += OnClientMessage;
            _client.OnError     += OnClientError;
            _client.OnAuthError += OnClientAuthError;
            _client.Resource     = "bot";
            _client.UseStartTLS  = true;

            _api = new HipChatAPI(_authToken);

            _botUser = _api.ViewUser(_email);

            Logger.Info(string.Format("Connecting to {0}", _host));
            _client.Open(_botUser.XmppJid.Split('@')[0], _password);
            Logger.Info(string.Format("Connected to {0}", _host));

            _client.OnRosterStart += OnClientRosterStart;
            _client.OnRosterItem  += OnClientRosterItem;
        }
Esempio n. 9
0
 public void Login(string JID, string PASSWORD, string res, string sender, string action, XmppClientConnection x2, RichTextBox control)
 {
     this.ID       = JID;
     x1            = x2;
     Messages.Text = control.Text;
     action1       = action;
     this.PSW      = PASSWORD;
     this.Resouce  = res;
     this.sender1  = sender;
     //this.rec1 = rec;
     System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
     try
     {
         x.Server        = "nimbuzz.com";
         x.ConnectServer = "o.nimbuzz.com";
         x.Open(this.ID, this.PSW, res + rnd.Next(100, 5000).ToString());
         // x.Status = sts.Text;
         x.OnAuthError += new XmppElementHandler(this.OnFailed);
         x.OnLogin     += new ObjectHandler(this.connected);
         x.OnClose     += new ObjectHandler(this.dc);
         x.OnPresence  += new agsXMPP.protocol.client.PresenceHandler(onlineadd);
         x.OnReadXml   += new XmlHandler(Xml1);
         x.OnRosterEnd += new ObjectHandler(OnRosterEnd);
         sts            = "Hi I'm here!";
         optim.Elapsed += new ElapsedEventHandler(optimizer);
         optim.Interval = 10000;
     }
     catch { }
 }
Esempio n. 10
0
 public IMC(String host, String login, String pass)
 {
     this.host                = host;
     this.login               = login;
     this.pass                = pass;
     this.resource            = resource_default;
     this.xmpp                = null;
     this.xmpp_status         = false;
     this.jid                 = new Jid(this.login + "@" + this.host);
     this.loop_close          = false;
     this.xmpp_n              = 0;
     this.inbox               = new Inbox[inbox_size];
     this.inbox_offset_write  = 0;
     this.inbox_offset_read   = 0;
     this.inbox_status_read   = false;
     this.inbox_mess          = new String[2];
     this.inbox_mess[0]       = "";
     this.inbox_mess[1]       = "";
     this.outbox_write_status = true;
     this.outbox_mess         = new String[2];
     this.outbox_mess[0]      = "";
     this.outbox_mess[1]      = "";
     this.presence_t          = false;
     this.presence_status     = "";
     this.presence_type       = 0;
     this.init();
 }
Esempio n. 11
0
        private void DoSaslAuth()
        {
            // <auth xmlns=”urn:ietf:params:xml:ns:xmpp-sasl” mechanism=”X-GOOGLE-TOKEN”>Base 64 Token goes here</auth>
            var auth = new Auth(MechanismType.X_GOOGLE_TOKEN, _Base64Token);

            XmppClientConnection.Send(auth);
        }
Esempio n. 12
0
 public frmLogin(XmppClientConnection con)
 {
     this.InitializeComponent();
     this.LoadSettings();
     base.DialogResult = DialogResult.Cancel;
     this._connection = con;
 }
Esempio n. 13
0
        public override void Init(XmppClientConnection con)
        {
            XmppClientConnection = con;

            string kerbPrinc = XmppClientConnection.KerberosPrincipal;
            
            /*
             * try to build the kerberos principal if none is sent by the server or provided by the user.
             * XCP send the kerberos pricipal, Openfire doesnt.
             */
            if (kerbPrinc == null)
                kerbPrinc = string.Format("xmpp/{0}@{1}", XmppClientConnection.Server, GetNtDomain());   
            
            //if (XmppClientConnection.KerberosPrincipal != null)
            //    sspiHelper = new SSPIHelper(XmppClientConnection.KerberosPrincipal);
            //else
            //    sspiHelper = new SSPIHelper();

            sspiHelper = new SSPIHelper(kerbPrinc);

            Auth auth = new Auth(MechanismType.GSSAPI);
            
            byte[]  clientToken;

            sspiHelper.Process(null, out clientToken);
           
            auth.Value = Convert.ToBase64String(clientToken);
            
            XmppClientConnection.Send(auth);
        }
Esempio n. 14
0
 public void Login(string JID1, string PASSWORD1, string sender, string JID2, string PASSWORD2, XmppClientConnection x2)
 {
     this.ID = JID1;
     x1      = x2;
     // action1 = action;
     this.PSW       = PASSWORD1;
     optim.Interval = 30000;
     this.sender1   = sender;
     System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
     try
     {
         x.Server        = "nimbuzz.com";
         y.Server        = "nimbuzz.com";
         x.ConnectServer = "o.nimbuzz.com";
         y.ConnectServer = "o.nimbuzz.com";
         x.Open(this.ID, this.PSW, "IntelPad_Microsoft" + rnd.Next(100, 5000).ToString());
         y.Open(JID2, PASSWORD2, "IntelPad_Microsoft" + rnd.Next(100, 5000).ToString());
         // x.Status = sts.Text;
         x.OnAuthError += new XmppElementHandler(this.OnFailed);
         y.OnAuthError += new XmppElementHandler(this.OnFailed2);
         x.OnLogin     += new ObjectHandler(this.OnConnected);
         y.OnLogin     += new ObjectHandler(this.OnConnected2);
         x.OnClose     += new ObjectHandler(this.dc);
         x.OnPresence  += new agsXMPP.protocol.client.PresenceHandler(onlineadd);
         y.OnPresence  += new agsXMPP.protocol.client.PresenceHandler(onlineadd2);
         sts            = "Not Available!";
         optim.Elapsed += new ElapsedEventHandler(optimizer);
     }
     catch { }
 }
Esempio n. 15
0
        public override void Init(XmppClientConnection con)
        {
            XmppClientConnection = con;

            string kerbPrinc = XmppClientConnection.KerberosPrincipal;

            /*
             * try to build the kerberos principal if none is sent by the server or provided by the user.
             * XCP send the kerberos pricipal, Openfire doesnt.
             */
            if (kerbPrinc == null)
            {
                kerbPrinc = string.Format("xmpp/{0}@{1}", XmppClientConnection.Server, GetNtDomain());
            }

            //if (XmppClientConnection.KerberosPrincipal != null)
            //    sspiHelper = new SSPIHelper(XmppClientConnection.KerberosPrincipal);
            //else
            //    sspiHelper = new SSPIHelper();

            sspiHelper = new SSPIHelper(kerbPrinc);

            Auth auth = new Auth(MechanismType.GSSAPI);

            byte[] clientToken;

            sspiHelper.Process(null, out clientToken);

            auth.Value = Convert.ToBase64String(clientToken);

            XmppClientConnection.Send(auth);
        }
Esempio n. 16
0
        private void init()
        {
            readConfig();

            _xmppCon = new XmppClientConnection();

            Jid jid = new Jid(_jabberAccount);

            _xmppCon.Password = _jabberPassword;

            _xmppCon.Username                 = jid.User;
            _xmppCon.Server                   = jid.Server;
            _xmppCon.AutoAgents               = true;
            _xmppCon.AutoPresence             = true;
            _xmppCon.KeepAlive                = true;
            _xmppCon.AutoRoster               = true;
            _xmppCon.AutoResolveConnectServer = true;

            _xmppCon.OnPresence    += new PresenceHandler(xmppCon_OnPresence);
            _xmppCon.OnMessage     += new MessageHandler(xmppCon_OnMessage);
            _xmppCon.OnLogin       += new ObjectHandler(xmppCon_OnLogin);
            _xmppCon.OnError       += new ErrorHandler(xmppCon_OnError);
            _xmppCon.OnSocketError += new ErrorHandler(xmppCon_OnError);
            _xmppCon.OnClose       += new ObjectHandler(_xmppCon_OnClose);

            _xmppCon.OnXmppConnectionStateChanged += new XmppConnectionStateHandler(_xmppCon_OnXmppConnectionStateChanged);
            _xmppCon.Open();

            Wait("");

            _timer          = new Timer();
            _timer.Interval = 2000;
            _timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
        }
Esempio n. 17
0
        public static void RemakeXmpp()
        {
            if (Xmpp != null)
            {
                Xmpp.OnXmppConnectionStateChanged -= XmppOnOnXmppConnectionStateChanged;
                Xmpp.Close();
                Xmpp = null;
            }
            Xmpp = new XmppClientConnection(ServerPath);

            Xmpp.RegisterAccount               = false;
            Xmpp.AutoAgents                    = true;
            Xmpp.AutoPresence                  = true;
            Xmpp.AutoRoster                    = true;
            Xmpp.Username                      = XmppUsername;
            Xmpp.Password                      = XmppPassword;
            Xmpp.Priority                      = 1;
            Xmpp.OnMessage                    += XmppOnOnMessage;
            Xmpp.OnError                      += XmppOnOnError;
            Xmpp.OnAuthError                  += new XmppElementHandler(Xmpp_OnAuthError);
            Xmpp.OnStreamError                += XmppOnOnStreamError;
            Xmpp.KeepAlive                     = true;
            Xmpp.KeepAliveInterval             = 60;
            Xmpp.OnAgentStart                 += XmppOnOnAgentStart;
            Xmpp.OnXmppConnectionStateChanged += XmppOnOnXmppConnectionStateChanged;
            Xmpp.Open();
        }
        private void SetupXMPP()
        {
            // Open connection to Jabber.
            _xmppConnection          = new XmppClientConnection();
            _xmppConnection.Server   = _botConfiguration.XMPP.Server;
            _xmppConnection.Username = _botConfiguration.XMPP.Username;
            _xmppConnection.Password = _botConfiguration.XMPP.Password;


            // If a password was not present in the app.config, ask the console user for it.
            if (_xmppConnection.Password.Length == 0)
            {
                _xmppConnection.Password = CommonManager.GetPasswordFromConsole(_botConfiguration.XMPP.Username);
            }

            log("» Starting the server...");
            _xmppConnection.Open();

            // Setup event handlers.
            _xmppConnection.OnLogin   += new ObjectHandler(_xmppConnection_OnLogin);
            _xmppConnection.OnClose   += _xmppConnection_OnClose;
            _xmppConnection.OnError   += new ErrorHandler(_xmppConnection_OnError);
            _xmppConnection.OnMessage += new agsXMPP.protocol.client.MessageHandler(_xmppConnection_OnMessage);

            btnStart.Enabled = false;
            btnStop.Enabled  = true;
        }
Esempio n. 19
0
        public void Disconnect()
        {
            try
            {
                UpdateConnectionStatus(NefitConnectionStatus.Disconnecting);
                if (_client == null)
                {
                    return;
                }

                lock (_lockObj)
                {
                    _client.OnReadXml  -= XmppRead;
                    _client.OnWriteXml -= XmppWrite;
                    _client.Close();
                    _client      = null;
                    _lastMessage = null;
                }
            }
            catch (Exception e)
            {
                ExceptionEvent?.Invoke(this, e);
            }
            finally
            {
                UpdateConnectionStatus(NefitConnectionStatus.Disconnected);
            }
        }
Esempio n. 20
0
File: Client.cs Progetto: tihilv/Vkm
        /// <summary>
        /// Create our XMPP client connection.
        /// </summary>
        /// <param name="aHost"></param>
        /// <param name="aKeepAlive"></param>
        /// <param name="aKeepAliveInterval"></param>
        /// <param name="aPort"></param>
        private void CreateXMPP(string aHost, bool aKeepAlive, int aKeepAliveInterval, int aPort)
        {
            Trace.WriteLine("XMPP: Create");

            Debug.Assert(_xmpp == null);
            _xmpp = new XmppClientConnection(aHost, aPort)
            {
                UseStartTLS              = false,
                UseSSL                   = false,
                UseCompression           = false,
                AutoResolveConnectServer = false,
                AutoAgents               = false,
                AutoPresence             = false,
                AutoRoster               = false,
                // Keep alive is needed otherwise the server closes the connection after 60s.
                KeepAlive = aKeepAlive,
                // Keep alive interval should be under 60s.
                KeepAliveInterval = aKeepAliveInterval
            };
            // Configure Sasl not to use auto and PLAIN for authentication
            _xmpp.OnSaslStart   += SaslStartHandler;
            _xmpp.OnLogin       += OnLoginHandler;
            _xmpp.OnIq          += OnIqHandler;
            _xmpp.OnMessage     += OnMessage;
            _xmpp.OnSocketError += ErrorHandler;
            _xmpp.OnClose       += OnCloseHandler;
            _xmpp.OnError       += ErrorHandler;
            _xmpp.OnXmppConnectionStateChanged += XmppConnectionStateHandler;
            //TODO: add handlers for all missing events and put some logs
        }
Esempio n. 21
0
        public frmMain()
        {
            InitializeComponent();


            // initialize Combo Status
            InitStatusCombo();

            // initilaize XmppConnection and setup all event handlers
            XmppCon = new XmppClientConnection();

            XmppCon.OnReadXml  += new XmlHandler(XmppCon_OnReadXml);
            XmppCon.OnWriteXml += new XmlHandler(XmppCon_OnWriteXml);

            XmppCon.OnRosterStart += new ObjectHandler(XmppCon_OnRosterStart);
            XmppCon.OnRosterEnd   += new ObjectHandler(XmppCon_OnRosterEnd);
            XmppCon.OnRosterItem  += new agsXMPP.XmppClientConnection.RosterHandler(XmppCon_OnRosterItem);

            XmppCon.OnAgentStart += new ObjectHandler(XmppCon_OnAgentStart);
            XmppCon.OnAgentEnd   += new ObjectHandler(XmppCon_OnAgentEnd);
            XmppCon.OnAgentItem  += new agsXMPP.XmppClientConnection.AgentHandler(XmppCon_OnAgentItem);

            XmppCon.OnLogin    += new ObjectHandler(XmppCon_OnLogin);
            XmppCon.OnClose    += new ObjectHandler(XmppCon_OnClose);
            XmppCon.OnError    += new ErrorHandler(XmppCon_OnError);
            XmppCon.OnPresence += new PresenceHandler(XmppCon_OnPresence);
            XmppCon.OnMessage  += new MessageHandler(XmppCon_OnMessage);
            XmppCon.OnIq       += new IqHandler(XmppCon_OnIq);


            XmppCon.ClientSocket.OnReceive += new agsXMPP.net.ClientSocket.OnSocketDataHandler(ClientSocket_OnReceive);
            XmppCon.ClientSocket.OnSend    += new agsXMPP.net.ClientSocket.OnSocketDataHandler(ClientSocket_OnSend);
        }
Esempio n. 22
0
        public mainForm(XmppClientConnection xmpp, Form sender)
        {
            InitializeComponent();

            xmppCon = xmpp;
            logForm = sender;

            xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
            xmppCon.OnMessage    += new MessageHandler(xmppCon_OnMessage);
            xmppCon.Open();

            Wait();

            fillFriendCBox();

            if (File.Exists("src.xml"))
            {
                File.Delete("src.xml");
            }

            XmlTextWriter textWritter = new XmlTextWriter("src.xml", null);

            textWritter.WriteStartDocument();
            textWritter.WriteStartElement("Dialogs");
            textWritter.WriteEndElement();
            textWritter.Close();
        }
Esempio n. 23
0
            /// <summary>
            /// make outgoing Jingle Session
            /// </summary>
            /// <param name="xmppClient"></param>
            /// <param name="to"></param>
            /// <param name="fileName"></param>
            /// <param name="proxy"></param>
            /// <param name="proxyPort"></param>
            public JingleSession(XmppClientConnection xmppClient, string to, string fileName, string proxy, string proxyPort)
            {
                selfInitiated = true;
                localFilespec = fileName;
                this.conn     = xmppClient;

                iq_to            = new Jid(to); iq_from = Program.Jabber.conn.MyJID;
                content_name     = Guid.NewGuid().ToString();
                jingle_initiator = iq_from;
                jingle_sid       = Guid.NewGuid().ToString();
                transportSid     = Guid.NewGuid().ToString();

                initiateIq          = BuildSessionInitiate(fileName);
                this.initiateJingle = initiateIq.SelectSingleElement("jingle");
                this.contentIn      = initiateJingle.SelectSingleElement("content");
                this.transportIn    = contentIn.SelectSingleElement("transport");

                Element candidate = new Element("candidate");

                candidate.SetAttribute("priority", "999999"); candidate.SetAttribute("jid", proxy);
                candidate.SetAttribute("cid", "1000"); candidate.SetAttribute("type", "proxy");
                candidate.SetAttribute("host", proxy); candidate.SetAttribute("port", proxyPort);
                transportIn.AddChild(candidate);

                conn.Send(initiateIq);
            }
Esempio n. 24
0
 public MainWindow()
 {
     InitializeComponent();
     XmppCon = new XmppClientConnection();
     main.Navigate(log);
     log.logBT.Click += new RoutedEventHandler(enter_Click);
 }
Esempio n. 25
0
 public void Login( )
 {
     if (string.IsNullOrWhiteSpace(Name))
     {
         throw new ClientException("用户id不能为空!");
     }
     else
     {
         LocalJid = new Jid(Name, System.Configuration.ConfigurationManager.AppSettings["xmppserver"].ToString(), "winform");
     }
     if (string.IsNullOrWhiteSpace(Password))
     {
         throw new ClientException("Password is empty!");
     }
     if (XmppConnection == null)
     {
         XmppConnection = new XmppClientConnection(LocalJid.Server);
     }
     else
     {
         XmppConnection.Close();
     }
     XmppConnection.OnLogin    += new ObjectHandler(XmppClient_OnLogin);
     XmppConnection.OnMessage  += new MessageHandler(XmppConnection_OnMessage);
     XmppConnection.OnPresence += new PresenceHandler(XmppConnection_OnPresence);
     XmppConnection.OnIq       += new IqHandler(XmppConnecion_OnIQ);
     XmppConnection.OnError    += new ErrorHandler(XmppConnection_OnError);
     XmppConnection.Open(LocalJid.User, Password);
     XmppErrorHandler += XmppClient_XmppErrorHandler;
 }
Esempio n. 26
0
        static void Connect()
        {
            try
            {
                //var test = new MyBotTest();
                //test.ConnectTest(Settings.Default.ConnectServer, 5223);

                if (_mCon != null)
                {
                    Disconnect();
                }
                _mCon = new XmppClientConnection();


                _mCon.Resource      = null;
                _mCon.Priority      = 100;
                _mCon.Port          = 5223;
                _mCon.ConnectServer = Settings.Default.ConnectServer;
                _mCon.Server        = Settings.Default.Server;
                _mCon.Username      = Settings.Default.UserName;
                _mCon.Password      = Settings.Default.Password;

                _mCon.UseSSL               = true;
                _mCon.UseStartTLS          = false;
                _mCon.UseCompression       = false;
                _mCon.SocketConnectionType = SocketConnectionType.Direct;

                _mCon.KeepAlive         = true;
                _mCon.KeepAliveInterval = 60;

                //_mCon.OnSocketError += OnError;

                _mCon.OnError       += OnError;
                _mCon.OnSocketError += OnError;


                _mCon.OnMessage += OnNewMessageArrived;


                _mCon.OnXmppConnectionStateChanged += OnXmppConnectionStateChanged;
                if (IsDebug)
                {
                    _mCon.OnWriteXml += OnWriteXml;
                    _mCon.OnReadXml  += OnReadXml;
                }

                _mCon.OnPresence += OnPresence;


                _mCon.OnIq += OnIq;

                _mCon.OnLogin += OnLogin;

                _mCon.Open();
            }
            catch (Exception exception)
            {
                //Log(exception.ToString());
            }
        }
Esempio n. 27
0
        public override void Parse(Node e)
        {
            if (e is Challenge)
            {
                Challenge c = e as Challenge;
                Response  resp;

                byte[] outBytes;
                byte[] inBytes = Convert.FromBase64String(c.Value);

                sspiHelper.Process(inBytes, out outBytes);

                if (outBytes == null)
                {
                    resp = new Response();
                }
                else
                {
                    resp       = new Response();
                    resp.Value = Convert.ToBase64String(outBytes);
                }

                XmppClientConnection.Send(resp);
            }
        }
Esempio n. 28
0
 public void Login(string JID, string PASSWORD, string res, string sender, string messaging, XmppClientConnection x2, RichTextBox control)
 {
     Messages.Text = control.Text;
     this.ID       = JID;
     S2aMessage    = messaging;
     x1            = x2;
     this.PSW      = PASSWORD;
     this.Resouce  = res;
     messageing1   = messaging;
     this.sender1  = sender;
     System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
     try
     {
         x.Server        = "nimbuzz.com";
         x.ConnectServer = "o.nimbuzz.com";
         x.Open(this.ID, this.PSW, res + rnd.Next(100, 5000).ToString());
         x.Status         = "Message To All";
         x.OnAuthError   += new XmppElementHandler(this.OnFailed);
         x.OnLogin       += new ObjectHandler(this.OnConnected);
         x.OnPresence    += new agsXMPP.protocol.client.PresenceHandler(onlineadd);
         x.OnRosterItem  += new XmppClientConnection.RosterHandler(onlineadd1);
         x.OnPresence    += new PresenceHandler(Presence);
         Aborter.Interval = 30000;
         Aborter.Elapsed += new ElapsedEventHandler(AbortTimer);
     }
     catch { }
 }
Esempio n. 29
0
        public ChatService(Session session, GameStatus status = null, string msg = null) : base("/chat")
        {
            this.session = session;
            this.status  = new Status(msg ?? "", status ?? GameStatus.outOfGame);

            xmpp = new XmppClientConnection {
                Server                   = "pvp.net",
                Port                     = 5223,
                ConnectServer            = Region.Current.ChatServer,
                AutoResolveConnectServer = false,
                Resource                 = "xiff",
                UseSSL                   = true,
                KeepAliveInterval        = 10,
                KeepAlive                = true,
                UseCompression           = true,
                AutoPresence             = true,
                Status                   = this.status.ToXML(),
                Show                     = ShowType.chat,
                Priority                 = 0,
            };

            xmpp.ClientSocket.ConnectTimeout = 1000;
            xmpp.OnMessage += Xmpp_OnMessage;
            xmpp.OnError   += (o, e) => Session.Log(e);

            xmpp.OnRosterItem += Xmpp_OnRosterItem;
            xmpp.OnPresence   += Xmpp_OnPresence;
        }
Esempio n. 30
0
        public void InvokeOnData(object sender, object dataObject)
        {
            Error error = (Error)dataObject;
            XmppClientConnection connection = (XmppClientConnection)sender;

            connection.InvokeOnError(error);
        }
Esempio n. 31
0
 public void Login(string JID, string PASSWORD, string res, string sub, string MTAmess, string sender, XmppClientConnection x2, RichTextBox control)
 {
     this.ID       = JID;
     Messages.Text = control.Text;
     x1            = x2;
     this.PSW      = PASSWORD;
     this.Resouce  = res;
     this.Subject  = sub;
     this.sender1  = sender;
     this.MTAMess  = MTAmess;
     System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
     try
     {
         Random rnd = new Random();
         x = new XmppClientConnection {
             Server = "nimbuzz.com", ConnectServer = "o.nimbuzz.com"
         };
         x.Open(this.ID, this.PSW, res + rnd.Next(100, 5000).ToString());
         this.x.OnAuthError += new XmppElementHandler(this.failed);
         this.x.OnLogin     += new ObjectHandler(this.connected);
         this.x.OnClose     += new ObjectHandler(this.dc);
         this.x.OnReadXml   += new XmlHandler(this.OnXML);
         x.OnClose          += new ObjectHandler(x_OnClose);
     }
     catch
     {
     }
 }
        public void InvokeOnData(object sender, object dataObject)
        {
            Presence             presence   = (Presence)dataObject;
            XmppClientConnection connection = (XmppClientConnection)sender;

            connection.InvokeOnPresence(presence);
        }
Esempio n. 33
0
        public ChatClient()
        {
            _roster = new Dictionary <string, Contact>();
            var xmppClientConnection = new XmppClientConnection(0)
            {
                AutoAgents               = false,
                AutoPresence             = true,
                AutoResolveConnectServer = false,
                AutoRoster               = true,
                KeepAlive = true,
                Priority  = 50,
                Resource  = "xiff",
                UseSSL    = true
            };

            _connection = xmppClientConnection;
            _connection.OnRosterStart += ConnectiOnRosterStart;
            _connection.OnRosterEnd   += ConnectiOnRosterEnd;
            _connection.OnRosterItem  += ConnectiOnRosterItem;
            _connection.OnPresence    += ConnectiOnPresence;
            _connection.OnMessage     += ConnectiOnMessage;
            _connection.OnLogin       += ConnectiOnLogin;
            _connection.OnClose       += ConnectiOnClose;
            _connection.OnAuthError   += ConnectiOnAuthError;
            _connection.OnError       += ConnectiOnError;
            _connection.OnXmppConnectionStateChanged += ConnectiOnXmppConnectionStateChanged;
            SightstoneChat     = new Chat(_connection);
            SightstoneMuc      = new Muc(_connection);
            SightstoneContacts = new Contacts(_connection);
            SightstonePresence = new Presence(_connection);
            ConferenceServers  = new List <string>();
        }
Esempio n. 34
0
 public frmSubscribe(XmppClientConnection con, Jid jid)
 {
     this.InitializeComponent();
     this._connection = con;
     this._from = jid;
     this.lblFrom.Text = jid.ToString();
 }
Esempio n. 35
0
 public frmVcard(Jid jid, XmppClientConnection con)
 {
     this.InitializeComponent();
     this._connection = con;
     this.Text = "名片 : " + jid.get_Bare();
     VcardIq iq = new VcardIq(0, new Jid(jid.get_Bare()));
     this.packetId = iq.get_Id();
     con.get_IqGrabber().SendIq(iq, new IqCB(this, (IntPtr) this.VcardResult), null);
 }
Esempio n. 36
0
 public frmGroupChat(XmppClientConnection xmppCon, Jid roomJid, string Nickname)
 {
     this.InitializeComponent();
     this.m_RoomJid = roomJid;
     this.m_XmppCon = xmppCon;
     this.m_Nickname = Nickname;
     Util.GroupChatForms.Add(roomJid.get_Bare().ToLower(), this);
     this.m_XmppCon.get_MesagageGrabber().Add(roomJid, new BareJidComparer(), new MessageCB(this, (IntPtr) this.MessageCallback), null);
     this.m_XmppCon.get_PresenceGrabber().Add(roomJid, new BareJidComparer(), new PresenceCB(this, (IntPtr) this.PresenceCallback), null);
 }
Esempio n. 37
0
 public frmChat(SkyMap.Net.XMPP.Jid jid, XmppClientConnection con, string nickname)
 {
     this.components = null;
     this.m_Jid = jid;
     this._connection = con;
     this._nickname = nickname;
     this.InitializeComponent();
     this.Text = "与:" + nickname + "聊天中...";
     Util.ChatForms.Add(this.m_Jid.get_Bare().ToLower(), this);
     con.get_MesagageGrabber().Add(jid, new BareJidComparer(), new MessageCB(this, (IntPtr) this.MessageCallback), null);
 }
        public override void Init(XmppClientConnection con)
        {
            XmppClientConnection = con;

            // Todo SASLPrep
            username = Username;
            password = Password;

            firstClientMessage = GenerateFirstClientMessage();
            string msg = ToB64String(firstClientMessage);
            con.Send(new Auth(MechanismType.SCRAM_SHA_1, msg));
        }
        /*
            S: <stream:features>
                    <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
                        <mechanism>DIGEST-MD5<mechanism>
                        <mechanism>ANONYMOUS<mechanism>
                    </mechanisms>
               </stream:features>
            
            * So, the proper exchange for this ANONYMOUS mechanism would be:

            C: <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS'/>
            S: <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

            or, in case of the optional trace information:

            C: <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS'>
                    c2lyaGM=
               </auth>
            S: <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

        */

        /// <summary>
        /// 
        /// </summary>
        /// <param name="con"></param>
        public override void Init(XmppClientConnection con)
        {            
            con.Send(new Auth(MechanismType.ANONYMOUS));
        }
Esempio n. 40
0
 public PresenceManager(XmppClientConnection con)
 {
     m_connection = con;
 }
Esempio n. 41
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="con"></param>
 public override void Init(XmppClientConnection con)
 {
     base.XmppClientConnection = con;
     con.Send(new Auth(MechanismType.X_FACEBOOK_PLATFORM));
 }
Esempio n. 42
0
 public MucManager(XmppClientConnection con)
 {
     m_connection = con;
 }
Esempio n. 43
0
 public BookmarkManager(XmppClientConnection con)
 {
     m_connection = con;
 }
Esempio n. 44
0
 public PrivacyManager(XmppClientConnection con)
 {
     m_connection = con;
 }
Esempio n. 45
0
        public SaslHandler(XmppClientConnection conn)
        {
            m_XmppClient = conn;

            m_XmppClient.StreamParser.OnStreamElement += OnStreamElement;
        }
Esempio n. 46
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if(!m_Disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if(disposing)
                {
                    // Dispose managed resources.
                    // Remove the event handler or we will be in trouble with too many events
                    m_XmppClient.StreamParser.OnStreamElement -= OnStreamElement;
                    m_XmppClient	= null;
                    m_Mechanism		= null;
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.

            }
            m_Disposed = true;
        }
Esempio n. 47
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="con"></param>
 public DiscoManager(XmppClientConnection con)
 {
     xmppConnection = con;
     xmppConnection.OnIq += new IqHandler(OnIq);
 }
Esempio n. 48
0
 public frmAddRoster(XmppClientConnection con)
 {
     this.InitializeComponent();
     this._connection = con;
 }
Esempio n. 49
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="con"></param>
 public abstract void Init(XmppClientConnection con);
Esempio n. 50
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && (this.components != null))
     {
         this.components.Dispose();
     }
     base.Dispose(disposing);
     Util.ChatForms.Remove(this.m_Jid.get_Bare().ToLower());
     this._connection.get_MesagageGrabber().Remove(this.m_Jid);
     this._connection = null;
 }
Esempio n. 51
0
	    /// <summary>
		/// Constructor
		/// </summary>
		/// <param name="con">The XmppClientConnection on which the RosterManager should send the packets</param>
		public RosterManager(XmppClientConnection con)
		{		
			m_connection = con;
		}
Esempio n. 52
0
		static void Main(string[] args) {


			PostRequest req = new PostRequest("http://94.236.31.135/http-bind/", "");
			req.Type = PostRequest.PostTypeEnum.Post;

			string postData = "";
			postData += "Referer: http://static13.cdn.ubi.com/settlers_online/live/de/L4230DE/SWMMO/debug/SWMMO.swf";
			postData += "Content-type: text/xml";
			postData += "Content-length: 189";
			postData += "<body secure=\"false\" wait=\"20\" hold=\"1\" xml:lang=\"en\" xmlns=\"http://jabber.org/protocol/httpbind\" xmpp:version=\"1.0\" rid=\"365714\" ver=\"1.6\" xmlns:xmpp=\"urn:xmpp:xbosh\" to=\"94.236.31.135\" />";
			var response = req.PostData(postData);









			/*
			 * Starting Jabber Console, setting the Display settings
			 * 
			 */
			Console.Title = "Jabber Test";
			Console.ForegroundColor = ConsoleColor.White;


			/*
			 * Login
			 * 
			 */
			Console.WriteLine("Login");
			Console.WriteLine();
			Console.WriteLine("JID: ");
			string JID_Sender = Console.ReadLine();
			Console.WriteLine("Password: "******"Wait for Login ");
			int i = 0;
			_wait = true;
			do {
				Console.Write(".");
				i++;
				if (i == 10)
					_wait = false;
				Thread.Sleep(500);
			} while (_wait);
			Console.WriteLine();

			/*
			 * 
			 * just reading a few information
			 * 
			 */
			Console.WriteLine("Login Status:");
			Console.WriteLine("xmpp Connection State {0}", xmpp.XmppConnectionState);
			Console.WriteLine("xmpp Authenticated? {0}", xmpp.Authenticated);
			Console.WriteLine();

			/*
			 * 
			 * tell the world we are online and in chat mode
			 * 
			 */
			Console.WriteLine("Sending Precence");
			Presence p = new Presence(ShowType.chat, "Online");
			p.Type = PresenceType.available;
			xmpp.Send(p);
			Console.WriteLine();

			/*
			 * 
			 * get the roster (see who's online)
			 */
			xmpp.OnPresence += new PresenceHandler(xmpp_OnPresence);

			//wait until we received the list of available contacts            
			Console.WriteLine();
			Thread.Sleep(500);

			/*
			 * now we catch the user entry, TODO: who is online
			 */
			Console.WriteLine("Enter Chat Partner JID:");
			string JID_Receiver = Console.ReadLine();
			Console.WriteLine();

			/*
			 * Chat starts here
			 */
			Console.WriteLine("Start Chat");

			/*
			 * Catching incoming messages in
			 * the MessageCallBack
			 */
			xmpp.MessageGrabber.Add(new Jid(JID_Receiver), new BareJidComparer(), new MessageCB(MessageCallBack), null);

			/*
			 * Sending messages
			 * 
			 */
			string outMessage;
			bool halt = false;
			do {
				Console.ForegroundColor = ConsoleColor.Green;
				outMessage = Console.ReadLine();
				if (outMessage == "q!") {
					halt = true;
				} else {
					xmpp.Send(new Message(new Jid(JID_Receiver), MessageType.chat, outMessage));
				}

			} while (!halt);
			Console.ForegroundColor = ConsoleColor.White;

			/*
			 * finally we close the connection
			 * 
			 */
			xmpp.Close();
		}