示例#1
0
 /// <summary>
 /// Bloque un identifiant Jabber
 /// </summary>
 /// <param name="jbid">Identifiant Jabber</param>
 public void block(string jbid)
 {
     if (Jabber.xmpp.Authenticated)
     {
         agsXMPP.Jid jid = new agsXMPP.Jid(jbid);
         if (jid != null && jid.ToString() != Jabber.xmpp.MyJID.ToString())
         {
             agsXMPP.protocol.iq.privacy.PrivacyIq piq = new agsXMPP.protocol.iq.privacy.PrivacyIq();
             piq.From = Jabber.xmpp.MyJID;
             piq.Type = agsXMPP.protocol.client.IqType.set;
             agsXMPP.protocol.iq.privacy.List list = new agsXMPP.protocol.iq.privacy.List(Jabber.xmpp.MyJID.Bare.Replace("@", "_").Replace("/", "_").Replace(".", "_"));
             agsXMPP.protocol.iq.privacy.Item item = new agsXMPP.protocol.iq.privacy.Item();
             item.Action = agsXMPP.protocol.iq.privacy.Action.deny;
             item.BlockIncomingPresence = false;
             item.BlockIq               = true;
             item.BlockMessage          = true;
             item.BlockOutgoingPresence = true;
             item.Order  = 1;
             item.Stanza = agsXMPP.protocol.iq.privacy.Stanza.Iq | agsXMPP.protocol.iq.privacy.Stanza.Message | agsXMPP.protocol.iq.privacy.Stanza.OutgoingPresence;
             item.Type   = agsXMPP.protocol.iq.privacy.Type.jid;
             item.Val    = jid.ToString();
             list.AddItem(item);
             piq.Query.AddList(list);
             PrivacyStructure ps = new PrivacyStructure();
             ps.id  = piq.Id;
             ps.jid = jid;
             Jabber.xmpp.IqGrabber.SendIq(piq, new agsXMPP.IqCB(blockResult), ps);
         }
     }
 }
示例#2
0
 /// <summary>
 /// Bloque un identifiant Jabber
 /// </summary>
 /// <param name="jbid">Identifiant Jabber</param>
 public void block(string jbid)
 {
     if (Jabber.xmpp.Authenticated)
     {
         agsXMPP.Jid jid = new agsXMPP.Jid(jbid);
         if (jid != null && jid.ToString() != Jabber.xmpp.MyJID.ToString())
         {
             agsXMPP.protocol.iq.privacy.PrivacyIq piq = new agsXMPP.protocol.iq.privacy.PrivacyIq();
             piq.From = Jabber.xmpp.MyJID;
             piq.Type = agsXMPP.protocol.client.IqType.set;
             agsXMPP.protocol.iq.privacy.List list = new agsXMPP.protocol.iq.privacy.List(Jabber.xmpp.MyJID.Bare.Replace("@", "_").Replace("/", "_").Replace(".", "_"));
             agsXMPP.protocol.iq.privacy.Item item = new agsXMPP.protocol.iq.privacy.Item();
             item.Action = agsXMPP.protocol.iq.privacy.Action.deny;
             item.BlockIncomingPresence = false;
             item.BlockIq = true;
             item.BlockMessage = true;
             item.BlockOutgoingPresence = true;
             item.Order = 1;
             item.Stanza = agsXMPP.protocol.iq.privacy.Stanza.Iq | agsXMPP.protocol.iq.privacy.Stanza.Message | agsXMPP.protocol.iq.privacy.Stanza.OutgoingPresence;
             item.Type = agsXMPP.protocol.iq.privacy.Type.jid;
             item.Val = jid.ToString();
             list.AddItem(item);
             piq.Query.AddList(list);
             PrivacyStructure ps = new PrivacyStructure();
             ps.id = piq.Id;
             ps.jid = jid;
             Jabber.xmpp.IqGrabber.SendIq(piq, new agsXMPP.IqCB(blockResult), ps);
         }
     }
 }
示例#3
0
        private static agsXMPP.XmppClientConnection CreateClient()
        {
            var client = new agsXMPP.XmppClientConnection();
            agsXMPP.Jid id = new agsXMPP.Jid("*****@*****.**");
            client.Password = "******";
            client.Username = id.User;
            client.Server = id.Server;
            client.AutoResolveConnectServer = true;

            client.OnMessage += (o, e) => { Console.WriteLine(e.Value); };
            client.OnAuthError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Value); };
            client.OnError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Message); };
            client.OnLogin += (o) =>
            {
                int i = 0;
                while (i<20)
                {
                    agsXMPP.Jid to = new agsXMPP.Jid("*****@*****.**");
                    agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message(to);
                    msg.Body = "Hi how are you cmyworld";
                    msg.Type = agsXMPP.protocol.client.MessageType.chat;
                    client.Send(msg);
                    System.Threading.Thread.Sleep(2000);
                    i++;
                }
            };
            client.Open();
            return client;
        }
示例#4
0
 private void getListResult(object sender, agsXMPP.protocol.client.IQ iq, object data)
 {
     if (iq.Type == agsXMPP.protocol.client.IqType.result && iq.Error == null)
     {
         if (iq.Query != null && iq.Query is agsXMPP.protocol.iq.privacy.Privacy)
         {
             agsXMPP.protocol.iq.privacy.Privacy privacy = iq.Query as agsXMPP.protocol.iq.privacy.Privacy;
             if (Jabber.xmpp.IqGrabber != null)
             {
                 Jabber.xmpp.IqGrabber.Remove(data as string);
             }
             agsXMPP.protocol.iq.privacy.List   customList = null;
             agsXMPP.protocol.iq.privacy.List[] lists      = privacy.GetList();
             if (lists != null)
             {
                 foreach (agsXMPP.protocol.iq.privacy.List list in lists)
                 {
                     if (list.Name == Jabber.xmpp.MyJID.Bare.Replace("@", "_").Replace("/", "_").Replace(".", "_"))
                     {
                         customList = list;
                         break;
                     }
                 }
             }
             if (customList != null)
             {
                 agsXMPP.protocol.iq.privacy.Item[] items = customList.GetItems();
                 if (items != null)
                 {
                     bool updated = false;
                     foreach (agsXMPP.protocol.iq.privacy.Item item in items)
                     {
                         if (item.Type == agsXMPP.protocol.iq.privacy.Type.jid)
                         {
                             agsXMPP.Jid jid = new agsXMPP.Jid(item.Val);
                             if (jid != null)
                             {
                                 if (item.Action == agsXMPP.protocol.iq.privacy.Action.deny && !_blockedJid.Contains(jid.ToString()))
                                 {
                                     _blockedJid.Add(jid.ToString());
                                     updated = true;
                                 }
                                 else if (item.Action == agsXMPP.protocol.iq.privacy.Action.allow && _blockedJid.Contains(jid.ToString()))
                                 {
                                     _blockedJid.Remove(jid.ToString());
                                     updated = true;
                                 }
                             }
                         }
                     }
                     if (updated)
                     {
                         OnPrivacyListUpdated();
                     }
                 }
             }
         }
     }
 }
 public void SendNotification(Receiver receiver,Notification notification)
 {
     agsXMPP.Jid to = new agsXMPP.Jid(receiver.Email);
     agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message(to);
     msg.Body = CreateBody(notification);
     msg.Type = agsXMPP.protocol.client.MessageType.chat;
     _jabberClient.Send(msg);
 }
示例#6
0
        public bool Start()
        {
            if (string.IsNullOrEmpty(UserName))
            {
                if (OnError != null)
                {
                    OnError(new ErrorEvent("用户名为空"));
                }
                return(false);
            }
            if (string.IsNullOrEmpty(UserPassword))
            {
                if (OnError != null)
                {
                    OnError(new ErrorEvent("用户名密码为空"));
                }
                return(false);
            }
            if (string.IsNullOrEmpty(MessageServerHost))
            {
                if (OnError != null)
                {
                    OnError(new ErrorEvent("消息服务主机名为空"));
                }
                return(false);
            }
            if (MessageServerPort < 1)
            {
                if (OnError != null)
                {
                    OnError(new ErrorEvent("消息服务端口号没设置"));
                }
                return(false);
            }



            XmppClient            = XmppEx.XmppClient.GetInstance();
            XmppClient.Name       = UserName;
            XmppClient.Password   = UserPassword;
            XmppClient.ServerPort = MessageServerPort;
            var server = new agsXMPP.Jid("0@" + MessageServerHost + "/" + Resource);

            XmppClient.ServerJid      = server;
            XmppClient.ServerResource = Resource;
            XmppClient.LocalJid       = new agsXMPP.Jid(UserName + "@" + MessageServerHost + "/" + Resource);
            regXmppEvent();
            try
            {
                XmppClient.Login();
                return(true);
            }
            catch (Exception e)
            {
                OnError(new ErrorEvent("启动xmpp客户端错误," + e.Message));
                return(false);
            }
        }
示例#7
0
        public IXmppConnection GetConnection(Jid jid)
        {
            IXmppConnection[] temp;

            lock (this._connections)
            {
                temp = this._connections.ToArray();
            }

            return(temp.Where(x => x.Session.Jid.ToString() == jid.ToString()).FirstOrDefault());
        }
示例#8
0
        public IEnumerable <IXmppConnection> GetConnections(Jid jid)
        {
            IXmppConnection[] temp;

            lock (this._connections)
            {
                temp = this._connections.ToArray();
            }

            return(temp.Where(x => x.Session.Jid.Bare == jid.Bare));
        }
示例#9
0
        public void RegUser(string strUserName, string strPassword)
        {
            objXmpp = new agsXMPP.XmppClientConnection();
            objXmpp.OnRegistered          += new agsXMPP.ObjectHandler(objXmpp_OnRegistered);
            objXmpp.OnRegisterError       += new agsXMPP.XmppElementHandler(objXmpp_OnRegisterError);
            objXmpp.OnRegisterInformation += new agsXMPP.protocol.iq.register.RegisterEventHandler(objXmpp_OnRegisterInformation);

            strUserName = strUserName + "@ishow.xba.com.cn";

            agsXMPP.Jid jid = new agsXMPP.Jid(strUserName);
            objXmpp.Password        = strPassword;
            objXmpp.Username        = jid.User;
            objXmpp.Server          = jid.Server;
            objXmpp.RegisterAccount = true;
            objXmpp.Open();
        }
        public void Connect(Action onConnected)
        {
            _jabberClient = new agsXMPP.XmppClientConnection();
            agsXMPP.Jid id = new agsXMPP.Jid("*****@*****.**");
            _jabberClient.Password = "******";
            //client.Password="******";
            _jabberClient.Username = id.User;
            _jabberClient.Server = id.Server;
            _jabberClient.AutoResolveConnectServer = true;

            _jabberClient.OnAuthError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Value); };
            _jabberClient.OnError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Message); };
            _jabberClient.OnLogin += (o) =>
            {
                System.Diagnostics.Trace.TraceInformation("Login Successful");
                onConnected();
            };
            _jabberClient.Open();
        }
示例#11
0
 /// <summary>
 /// Constructeur
 /// </summary>
 /// <param name="jid">Identifiant Jabber</param>
 public Identity(agsXMPP.Jid jid)
 {
     if (jid == null)
     {
         return;
     }
     _jabberID          = new JabberID();
     _jabberID.user     = (jid.User != null) ? jid.User : string.Empty;
     _jabberID.domain   = (jid.Server != null) ? jid.Server : string.Empty;
     _jabberID.resource = (jid.Resource != null) ? jid.Resource : string.Empty;
     _jabberID.bare     = (jid.Bare != null) ? jid.Bare : string.Empty;
     _jabberID.full     = jid.ToString();
     _name              = new Name();
     _name.firstname    = string.Empty;
     _name.lastname     = string.Empty;
     _name.middle       = string.Empty;
     _organization      = new Organization();
     _organization.name = string.Empty;
     _organization.unit = string.Empty;
     load();
     Jabber.xmpp.OnIq += new agsXMPP.protocol.client.IqHandler(iqManager);
 }
示例#12
0
        void ProcessBind(Iq iq, Element bind)
        {
            var resource = bind.SelectSingleElement("resource").Value;
            var search   = new Jid(this.Session.Jid.Bare + $"/{resource}");
            var conflict = this._listener.GetConnection(search) != null;

            if (conflict)
            {
                this.Send(iq.ToError(agsXMPP.protocol.client.ErrorType.modify, agsXMPP.protocol.client.ErrorCondition.Conflict));
                return;
            }

            this.Session.Bind(resource);

            iq.SwitchDirection();
            iq.Type = IqType.result;
            iq.RemoveAllChildNodes();

            iq.C("bind", ns: Namespaces.BIND)
            .C("jid", this.Session.Jid);

            this.Send(iq);
        }
示例#13
0
            //<User>
            //  <UserID>test</UserID>
            //  <UserName>test</UserName>
            //  <Password>test</Password>
            //  <Role>0</Role>
            //  <Group>SiteView</Group>
            //  <Privacy></Privacy>
            //  <Privilege>0</Privilege>
            //  <Roster>
            //    <Friend>
            //      <Company>SiteView</Company>
            //      <Group>SiteView</Group>
            //      <NickName>test1</NickName>
            //      <JID>[email protected]</JID>
            //      <Subscribe>
            //        <type>both</type>
            //        <status>0</status>
            //      </Subscribe>
            //    </Friend>
            //    <Friend>
            //      <Company>SiteView</Company>
            //      <Group>SiteView</Group>
            //      <NickName>test2</NickName>
            //      <JID>[email protected]</JID>
            //      <Subscribe>
            //        <type>both</type>
            //        <status>0</status>
            //      </Subscribe>
            //    </Friend>
            //    <Friend>
            //      <Company>SiteView</Company>
            //      <Group>SiteView</Group>
            //      <NickName>test3</NickName>
            //      <JID>[email protected]</JID>
            //      <Subscribe>
            //        <type>both</type>
            //        <status>0</status>
            //      </Subscribe>
            //    </Friend>
            //  </Roster>
            //</User>

            public Account FindAccount(string strJID)
            {
                agsXMPP.Jid objJID = new agsXMPP.Jid(strJID);
                foreach (Account account in this.accounts)
                {
                    if (account.JID.Bare.ToLower() == objJID.Bare.ToLower())
                    {
                        return account;
                    }
                }

                return null;
            }
 private void SendNotification(Notification data)
 {
     agsXMPP.Jid to = new agsXMPP.Jid("*****@*****.**");
     agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message(to);
     msg.Body = RenderPartialViewToString("NotificationMessage", data);
     msg.Type = agsXMPP.protocol.client.MessageType.chat;
     JabberClient.Open();
     JabberClient.Send(msg);
 }
        private static agsXMPP.XmppClientConnection CreateClient()
        {
            var client = new agsXMPP.XmppClientConnection();
            agsXMPP.Jid id = new agsXMPP.Jid("*****@*****.**");
            client.Password = "******";
            client.Username = id.User;
            client.Server = id.Server;
            client.AutoResolveConnectServer = true;

            client.OnAuthError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Value); };
            client.OnError += (o, e) => { System.Diagnostics.Trace.TraceError(e.Message); };
            client.OnLogin += (o) =>
            {
                System.Diagnostics.Trace.TraceInformation("Login Successful");
                //agsXMPP.Jid to = new agsXMPP.Jid("*****@*****.**");
                //agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message(to);
                //msg.Body = "Hi how are you cmyworld";
                //msg.Type = agsXMPP.protocol.client.MessageType.chat;
                //client.Send(msg);
            };
            return client;
        }
示例#16
0
 public static Element A(this Element element, string name, Jid value)
 {
     element.SetAttribute(name, value);
     return(element);
 }
示例#17
0
 /// <summary>
 /// Ajouter un contact
 /// </summary>
 /// <param name="jbid">Identifiant Jabber</param>
 public void add(string jbid)
 {
     agsXMPP.Jid jid = new agsXMPP.Jid(jbid);
     if (jid != null)
     {
         if (!contacts.ContainsKey(jid.Bare))
         {
             Jabber.xmpp.RosterManager.AddRosterItem(new agsXMPP.Jid(jid.Bare));
             Jabber.xmpp.PresenceManager.Subscribe(new agsXMPP.Jid(jid.Bare));
         }
     }
 }
示例#18
0
 /// <summary>
 /// Supprimer une ressource ou un contact avec toutes ses ressources
 /// </summary>
 /// <param name="jbid">Identifiant Jabber</param>
 public void remove(string jbid)
 {
     agsXMPP.Jid jid = new agsXMPP.Jid(jbid);
     if (jid != null)
     {
         if (contacts.ContainsKey(jid.Bare))
         {
             if (jid.Resource != null && contacts[jid.Bare].ContainsKey(jid.Resource.Trim()))
             {
                 Jabber.xmpp.PresenceManager.Unsubscribe(jid);
                 Jabber.xmpp.RosterManager.RemoveRosterItem(jid);
             }
             else
             {
                 foreach (KeyValuePair<string, Contact> r in contacts[jid.Bare])
                 {
                     remove(r.Value.identity.jabberID.full);
                 }
                 Jabber.xmpp.PresenceManager.Unsubscribe(jid);
                 Jabber.xmpp.RosterManager.RemoveRosterItem(jid);
             }
         }
     }
 }
示例#19
0
 private void getListResult(object sender, agsXMPP.protocol.client.IQ iq, object data)
 {
     if (iq.Type == agsXMPP.protocol.client.IqType.result && iq.Error == null)
     {
         if (iq.Query != null && iq.Query is agsXMPP.protocol.iq.privacy.Privacy)
         {
             agsXMPP.protocol.iq.privacy.Privacy privacy = iq.Query as agsXMPP.protocol.iq.privacy.Privacy;
             if (Jabber.xmpp.IqGrabber != null)
             {
                 Jabber.xmpp.IqGrabber.Remove(data as string);
             }
             agsXMPP.protocol.iq.privacy.List customList = null;
             agsXMPP.protocol.iq.privacy.List[] lists = privacy.GetList();
             if (lists != null)
             {
                 foreach (agsXMPP.protocol.iq.privacy.List list in lists)
                 {
                     if (list.Name == Jabber.xmpp.MyJID.Bare.Replace("@", "_").Replace("/", "_").Replace(".", "_"))
                     {
                         customList = list;
                         break;
                     }
                 }
             }
             if (customList != null)
             {
                 agsXMPP.protocol.iq.privacy.Item[] items = customList.GetItems();
                 if (items != null)
                 {
                     bool updated = false;
                     foreach (agsXMPP.protocol.iq.privacy.Item item in items)
                     {
                         if (item.Type == agsXMPP.protocol.iq.privacy.Type.jid)
                         {
                             agsXMPP.Jid jid = new agsXMPP.Jid(item.Val);
                             if (jid != null)
                             {
                                 if (item.Action == agsXMPP.protocol.iq.privacy.Action.deny && !_blockedJid.Contains(jid.ToString()))
                                 {
                                     _blockedJid.Add(jid.ToString());
                                     updated = true;
                                 }
                                 else if (item.Action == agsXMPP.protocol.iq.privacy.Action.allow && _blockedJid.Contains(jid.ToString()))
                                 {
                                     _blockedJid.Remove(jid.ToString());
                                     updated = true;
                                 }
                             }
                         }
                     }
                     if (updated)
                     {
                         OnPrivacyListUpdated();
                     }
                 }
             }
         }
     }
 }