예제 #1
0
        /// <summary>
        /// Converts the given value to the type of this converter.
        /// Empty strings are converted to null.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value == null)
            {
                return(null);
            }

            string s = value as string;

            if (s != null)
            {
                if (s == "")
                {
                    return(null);
                }
                return(new JID(s));
            }
            JID j = value as JID;

            if (j != null)
            {
                return(j);
            }
            return(base.ConvertFrom(context, culture, value));
        }
예제 #2
0
        /// <summary>
        /// Returns whether the given value object is valid for this type.
        /// Empty strings are allowed, since they will map to null.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool IsValid(System.ComponentModel.ITypeDescriptorContext context, object value)
        {
            string s = value as string;
            JID    j;

            if (s != null)
            {
                if (s == "")
                {
                    return(true);
                }

                try
                {
                    j = new JID(s);
                }
                catch (JIDFormatException)
                {
                    return(false);
                }
                return(true);
            }
            j = value as JID;
            return(j != null);
        }
예제 #3
0
파일: XmppService.cs 프로젝트: hseom/brunet
    /// <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>();
    }
예제 #4
0
 [Test] public void Test_Parse_7()
 {
     JID j = new JID("boo@foo/bar/baz");
     Assert.AreEqual("boo", j.User);
     Assert.AreEqual("foo", j.Server);
     Assert.AreEqual("bar/baz", j.Resource);
 }
예제 #5
0
 [Test] public void Test_Parse_3()
 {
     JID j = new JID("boo@foo");
     Assert.AreEqual("boo", j.User);
     Assert.AreEqual("foo", j.Server);
     Assert.AreEqual(null, j.Resource);
 }
예제 #6
0
 public UserLocation(JID jid, string locationName, string latitude, string longitude, string source)
 {
     m_Jid          = jid;
     m_LocationName = locationName;
     m_Latitude     = latitude;
     m_Longitude    = longitude;
     m_Source       = source;
 }
예제 #7
0
        private void ReceivedAvatarMetadata(JID from, string node, XmlNode items)
        {
            if (items.ChildNodes.Count == 0)
                return;

            Console.WriteLine("Received Avatar Data");
            Console.WriteLine(items.ToString());
        }
예제 #8
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the comparands. The return value has these meanings:
        /// Less than zero This instance is less than obj.
        /// Zero This instance is equal to obj.
        /// Greater than zero This instance is greater than obj.
        /// </returns>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            if (obj == (object)this)
            {
                return(0);
            }

            JID oj = obj as JID;

            if (oj == null)
            {
                throw new ArgumentException("Comparison of JID to non-JID", "obj");
            }

            // hm.  How tricky to get?
            // It could be that sorting by domain first is correct...
            //return this.m_JID.CompareTo(oj.m_JID);
            this.parse();
            oj.parse();

            int c = this.m_server.ToLower().CompareTo(oj.m_server.ToLower());

            if (c != 0)
            {
                return(c);
            }

            if (this.m_user == null)
            {
                if (oj.m_user != null)
                {
                    return(-1);
                }
            }
            else
            {
                if (oj.m_user == null)
                {
                    return(1);
                }

                c = this.m_user.ToLower().CompareTo(oj.m_user.ToLower());
                if (c != 0)
                {
                    return(c);
                }
            }

            if (this.m_resource == null)
            {
                return((oj.m_resource == null) ? 0 : -1);
            }
            return(this.m_resource.CompareTo(oj.m_resource));
        }
예제 #9
0
 public static bool TryParse(string j, out JID jid)
 {
     try {
         jid = new JID(j);
         return(true);
     } catch { }
     jid = null;
     return(false);
 }
예제 #10
0
        public void Setup()
        {
            mocks = new MockRepository();
            stream = mocks.DynamicMock<XmppStream>();
            tracker = mocks.DynamicMock<IIQTracker>();
            doc = new XmlDocument();

            jid = new JID("test.example.com");
        }
예제 #11
0
        public void SendMessage(JID toJid, string body, MessageType type)
        {
            Message m = new Message (XmppGlobal.InternalClient.Document);

            m.To = toJid;
            m.Body = body;
            m.Type = type;

            XmppGlobal.InternalClient.Write (m);
        }
예제 #12
0
        public ChatContentMessage(Account account, JID source, string sourceDisplayName, JID destination, DateTime date, bool isAutoReply)
            : base(account, source, sourceDisplayName, destination, date)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            if (destination == null)
                throw new ArgumentNullException("destination");

            m_IsAutoReply = isAutoReply;
        }
예제 #13
0
 [Test] public void Test_Create()
 {
     JID j = new JID("foo", "jabber.com", "there");
     Assert.AreEqual("[email protected]/there", j.ToString());
     j = new JID(null, "jabber.com", null);
     Assert.AreEqual("jabber.com", j.ToString());
     j = new JID("foo", "jabber.com", null);
     Assert.AreEqual("*****@*****.**", j.ToString());
     j = new JID(null, "jabber.com", "there");
     Assert.AreEqual("jabber.com/there", j.ToString());
 }
예제 #14
0
        public ChatHandler(Account account, bool isMucUser, JID jid)
            : base(account)
        {
            m_Jid = jid;
            m_IsMucUser = isMucUser;

            base.Account.ConnectionStateChanged += HandleConnectionStateChanged;
            base.Ready = (base.Account.ConnectionState == AccountConnectionState.Connected);

            base.AppendStatus(String.Format("Conversation with {0}.", jid.ToString()));
        }
예제 #15
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;
        }
예제 #16
0
        public AbstractChatContent(Account account, JID source, string sourceDisplayName, JID destination, DateTime date)
        {
            if (account == null)
                throw new ArgumentNullException("account");

            if (date == null)
                throw new ArgumentNullException("date");

            m_Account = account;
            m_Source = source;
            m_SourceDisplayName = sourceDisplayName;
            m_Destination = destination;
            m_Date = date;
        }
        public AuctionMessageTranslator(JID inSniperJId, IAuctionEventListener inListener)
        {
            mSniperId = inSniperJId;

            mParser.RegisterAction("CLOSE", (ev) => {
                inListener.AuctionClosed();
            });
            mParser.RegisterAction("PRICE", (ev) => {
                inListener.CurrentPrice(
                    ev.IntegerValueOf("CurrentPrice"),
                    ev.IntegerValueOf("Increment"),
                    ev.PriceSourceFrom(mSniperId)
                );
            });
        }
예제 #18
0
        public ProfileWindow(Account account, JID jid)
            : base()
        {
            SetupUi();

            webView.SetHtml("<p>Loading...</p>");

            account.RequestVCard(jid, delegate (object sender, IQ iq, object data) {
                if (iq.Type == IQType.result)
                    Populate((VCard)iq.FirstChild);
                else
                    Populate(null);
            }, null);

            Gui.CenterWidgetOnScreen(this);
        }
예제 #19
0
        public void TestAdd()
        {
            PresenceManager pp = new PresenceManager();
            Presence pres = new Presence(doc);
            JID f = new JID("foo", "bar", "baz");
            pres.From = f;
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/baz", pp[f].From.ToString());
            f.Resource = null;
            Assert.AreEqual("foo@bar/baz", pp[f].From.ToString());

            pres = new Presence(doc);
            pres.Status = "wandering";
            pres.From = new JID("foo", "bar", "baz");
            pp.AddPresence(pres);
            Assert.AreEqual("wandering", pp[f].Status);
        }
예제 #20
0
 public void Test_BadCompare()
 {
     try
     {
         JID j = new JID("foo@boo/bar");
         j.CompareTo("foo@boo/bar");
         Assert.IsTrue(false);
     }
     catch (ArgumentException)
     {
         Assert.IsTrue(true);
     }
     catch (Exception)
     {
         Assert.IsTrue(false);
     }
 }
예제 #21
0
        /// <summary>Initializes a new chat window, and adds it to the hashtable of chat windows</summary>
        /// <param name="jid">JID of recipient</param>
        /// <param name="nickName">nickname of recipient</param>
        /// <returns>FrmChat object of new chat window</returns>
        private FrmChat InitializeChatWindow(jabber.JID jid, string nickName)
        {
            // Attempt to use existing chat window
            FrmChat chatWindow = ActiveChatWindow(jid);

            if (chatWindow == null)
            {
                // Create new chat window
                chatWindow = new FrmChat();
                chatWindow.JabberObject = jabberClient;
                chatWindow.JID          = jid;
                chatWindow.Nickname     = (nickName != null) ? nickName : jid.User;
                chatWindow.Text         = chatWindow.Nickname;
                chatForms[jid.Bare]     = chatWindow;
            }
            return(chatWindow);
        }
예제 #22
0
 public void Test_AtAt()
 {
     try
     {
         JID j = new JID("boo@@foo");
         string u = j.User;
         Assert.IsTrue(false);
     }
     catch (JIDFormatException)
     {
         Assert.IsTrue(true);
     }
     catch (Exception)
     {
         Assert.IsTrue(false);
     }
 }
예제 #23
0
        internal Conference(JabberSession session, JID conferenceJid)
        {
            if (conferenceJid == null)
                throw new ArgumentNullException("conferenceJid");

            JabberSession = session;
            JabberSession.ConnectionDropped += OnConnectionDropped;
            ConferenceJid = conferenceJid;

            Members = new ConferenceMemberCollection(session);
            Messages = new ConferenceMessageCollection(session);

            //if we are currently authenticated - then lets join to the channel imidiatly
            if (JabberSession.IsAuthenticated)
                Authenticated(this, new AuthenticationEventArgs());

            JabberSession.Authenticated += Authenticated;
        }
예제 #24
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
            );
        }
예제 #25
0
 public void Test_Compare_Equal()
 {
     JID j = new JID("foo@bar/baz");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("foo@bar/baz")));
     j = new JID("foo@bar");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("foo@bar")));
     Assert.IsTrue(j == new JID("foo@bar"));
     Assert.IsTrue(j == new JID("foo@BAR"));
     Assert.IsTrue(j == new JID("FOO@BAR"));
     Assert.IsTrue(j == new JID("FOO@bar"));
     Assert.AreEqual(new JID("FOO@bar").GetHashCode(), j.GetHashCode());
     j = new JID("bar");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("bar")));
     j = new JID("foo/bar");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("foo/bar")));
     Assert.AreEqual(true, j >= new JID("foo/bar"));
     Assert.AreEqual(true, j <= new JID("foo/bar"));
 }
예제 #26
0
        public void TestRetrieve()
        {
            PresenceManager pp = new PresenceManager();
            Presence pres = new Presence(doc);
            JID f = new JID("foo", "bar", "baz");
            pres.From = f;
            pres.Priority = "0";
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/baz", pp[f.Bare].From.ToString());

            pres = new Presence(doc);
            f = new JID("foo", "bar", "bay");
            pres.From = f;
            pres.Priority = "1";
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/bay", pp[f.Bare].From.ToString());

            pres = new Presence(doc);
            pres.From = f;
            pres.Type = PresenceType.unavailable;
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/baz", pp[f.Bare].From.ToString());
        }
예제 #27
0
 private void txtJID_Leave(object sender, EventArgs e)
 {
     if (!txtJID.Text.Contains("@") && (m_domain != null))
     {
         txtJID.Text = txtJID.Text + "@" + m_domain;
     }
     if (txtNickname.Text == "")
     {
         JID jid = new JID(txtJID.Text);
         txtNickname.Text = jid.User;
     }
 }
예제 #28
0
 public AbstractChatContent(Account account, JID source, string sourceDisplayName, JID destination)
     : this(account, source, sourceDisplayName, destination, DateTime.Now)
 {
 }
예제 #29
0
파일: Form1.cs 프로젝트: Akku/XmppNetTest
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxAddUsername.Text))
                MessageBox.Show("Username may not be empty");
            try
            {
                var u = textBoxAddUsername.Text;
                var jid = new JID(u, Server, null);
                var nick = textBoxAddNickname.Text;
                if (string.IsNullOrEmpty(nick))
                    nick = null;
                var group = textBoxAddGroupname.Text;
                if (!string.IsNullOrEmpty(group))
                {
                    rosterTree1.AddGroup(group);
                    jabberClient1.Subscribe(jid, nick, new string[] { group });
                }
                else
                    jabberClient1.Subscribe(jid, nick, null);

                jabberClient1.GetRoster();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message + ex.StackTrace);
                MessageBox.Show("Exception: " + ex.Message + ex.StackTrace);
            }
        }
예제 #30
0
 PersonModel CreatePerson(JID jid)
 {
     if (jid == null) {
         throw new ArgumentNullException("jid");
     }
     var contact = RosterManager[jid.Bare];
     string nickname = null;
     if (contact == null || String.IsNullOrEmpty(contact.Nickname)) {
         nickname = jid.Bare;
     } else {
         nickname = contact.Nickname;
     }
     return CreatePerson(jid.Bare, nickname);
 }
예제 #31
0
 public HipChatResponse(HipChatSession session, JID replyTo, MessageType messageType)
 {
     this.Session = session;
     this.ReplyTo = replyTo;
     this.MessageType = messageType;
 }
예제 #32
0
 //#############################################################################################################
 // Chat window creation
 /// <summary>Gets the active chat window for a JID</summary>
 /// <param name="bareJID">JID of chat</param>
 /// <returns>FrmChat if chat exists, null otherwise</returns>
 private FrmChat ActiveChatWindow(JID jid)
 {
     if (chatForms.ContainsKey(jid.Bare))
     {
         FrmChat chatWindow = chatForms[jid.Bare];
         if ((chatWindow != null) &&
             (chatWindow.Enabled != false) &&
             !chatWindow.IsDisposed)
         {
             return chatWindow;
         }
     }
     return null;
 }
예제 #33
0
        /// <summary>Signin button</summary>
        private void btnSignin_Click(object sender, EventArgs e)
        {
            panelCredentials.Enabled = false;

            JID jid = new JID(txtUserName.Text);
            if (String.IsNullOrEmpty(jid.User))
            {
                jabberClient.User = txtUserName.Text;
                jabberClient.Server = cbServer.Text.Equals(DEFAULT_SERVER) ? "gmail.com" : cbServer.Text;
            }
            else
            {
                jabberClient.User = jid.User;
                jabberClient.Server = jid.Server;
            }
            jabberClient.NetworkHost = cbServer.Text;
            jabberClient.Password = txtPassword.Text;
            jabberClient.AutoRoster = true;
            jabberClient.AutoStartTLS = true;
            jabberClient.AutoPresence = true;
            jabberClient.AutoLogin = true;
            jabberClient.Resource = "realjabber";
            //jabberClient.PlaintextAuth = true;
            jabberClient.OnAuthenticate += new bedrock.ObjectHandler(jabberClient_OnAuthenticate);
            jabberClient.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(jabberClient_OnInvalidCertificate);
            jabberClient.AddNamespace("rtt", RealTimeTextUtil.RealTimeText.NAMESPACE);
            jabberClient.OnIQ += new IQHandler(jabberClient_OnIQ);

            rosterMgr = new RosterManager();
            rosterMgr.Stream = jabberClient;
            rosterMgr.AutoSubscribe = true;
            rosterMgr.AutoAllow = jabber.client.AutoSubscriptionHanding.AllowAll;
            rosterMgr.OnRosterBegin += new bedrock.ObjectHandler(RosterMgr_OnRosterBegin);
            rosterMgr.OnRosterEnd += new bedrock.ObjectHandler(RosterMgr_OnRosterEnd);
            rosterMgr.OnRosterItem += new RosterItemHandler(RosterMgr_OnRosterItem);
            rosterMgr.OnSubscription += new SubscriptionHandler(rosterMgr_OnSubscription);
            rosterMgr.OnUnsubscription += new UnsubscriptionHandler(rosterMgr_OnUnsubscription);

            discoMgr = new DiscoManager();
            discoMgr.Stream = jabberClient;

            capsMgr = new CapsManager();
            capsMgr.DiscoManager = discoMgr;
            capsMgr.AddFeature(RealTimeTextUtil.RealTimeText.NAMESPACE);
            capsMgr.Node = RealTimeTextUtil.RealTimeText.NAMESPACE;
            capsMgr.Stream = jabberClient;

            presenceMgr = new PresenceManager();
            presenceMgr.Stream = jabberClient;
            presenceMgr.CapsManager = capsMgr;

            rosterTree.RosterManager = rosterMgr;
            rosterTree.PresenceManager = presenceMgr;
            rosterTree.DoubleClick += new EventHandler(rosterTree_DoubleClick);

            lblUser.Text = jabberClient.User;
            jabberClient.Connect();
        }
예제 #34
0
        private void m_pres_OnPrimarySessionChange(object sender, JID bare)
        {
            Presence pres = m_pres[bare];
            LinkedList nodelist = (LinkedList) m_items[bare.ToString()];
            if (nodelist == null)
                return;

            foreach (ItemNode n in nodelist)
            {
                n.ChangePresence(pres);
            }
        }
예제 #35
0
 public void Login(string username, string password) {
   JID jid = new JID(username);
   _jclient.User = jid.User;
   _jclient.Server = jid.Server;
   _jclient.Password = password;
   _jclient.Connect();
 }