Пример #1
0
        public async Task ProcessStanza(IChannelHandlerContext context, Iq iq)
        {
            var bind = iq.Query as Bind;

            // read desired resource
            string res = bind.Resource;

            if (String.IsNullOrEmpty(res) ||
                SecureResource)
            {
                // no resource given, assign random
                res = Guid.NewGuid().ToString();
            }

            var serverSession = context.Channel.Pipeline.Get <ServerConnectionHandler>();

            var jid   = new Jid(serverSession.User, serverSession.XmppDomain, res);
            var resIq = new BindIq
            {
                Id   = iq.Id,
                Type = Matrix.Xmpp.IqType.Result,
                Bind = { Jid = jid }
            };

            await SendAsync(resIq);

            serverSession.Resource     = res;
            serverSession.SessionState = SessionState.Binded;
        }
Пример #2
0
        public IPAddress GetExternalAddress()
        {
            IPAddress address;

            if (!this.ecapa.Supports(base.im.Jid.Domain, new Extension[] { Extension.ServerIpCheck }))
            {
                throw new NotSupportedException("The XMPP server does not support the 'Server IP Check' extension.");
            }
            Iq errorIq = base.im.IqRequest(IqType.Get, null, base.im.Jid, Xml.Element("address", "urn:xmpp:sic:1"), null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The external IP address could not be retrieved.");
            }
            XmlElement element = errorIq.Data["address"];

            if ((element == null) || (element["ip"] == null))
            {
                throw new XmppException("Erroneous IQ response.");
            }
            string innerText = element["ip"].InnerText;

            try
            {
                address = IPAddress.Parse(innerText);
            }
            catch (Exception exception)
            {
                throw new XmppException("The returned address is not a valid IP address.", exception);
            }
            return(address);
        }
Пример #3
0
        public void TestBuildRequestIq()
        {
            var put = new Put
            {
                Url = "https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg"
            };

            put.AddHeader(HeaderNames.Authorization, "Basic Base64String==");
            put.AddHeader(HeaderNames.Cookie, "foo=bar; user=romeo");

            var get = new Get
            {
                Url = "https://download.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg"
            };

            var slot = new Slot
            {
                Put = put,
                Get = get,
            };

            var iq = new Iq {
                Type = Matrix.Xmpp.IqType.Result, Id = "step_03", To = "[email protected]/garden", From = "upload.montague.tld"
            };

            iq.Add(slot);

            iq.ShouldBe(Resource.Get("Xmpp.HttpUpload.slot-request-iq.xml"));
        }
Пример #4
0
        public string GetDefaultPrivacyList()
        {
            this.AssertValid(true);
            Iq errorIq = this.IqRequest(IqType.Get, null, this.Jid, Xml.Element("query", "jabber:iq:privacy"), null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The privacy list could not be retrieved.");
            }
            XmlElement element = errorIq.Data["query"];

            if ((element == null) || (element.NamespaceURI != "jabber:iq:privacy"))
            {
                throw new XmppException("Erroneous server response: " + errorIq);
            }
            XmlElement element2 = element["default"];

            if (element2 == null)
            {
                return(null);
            }
            string attribute = element2.GetAttribute("name");

            if (string.IsNullOrEmpty(attribute))
            {
                return(null);
            }
            return(attribute);
        }
Пример #5
0
        /// <summary>
        /// Retrieves the item with the specified id from the collection of items
        /// of the node with the specified node id.
        /// </summary>
        /// <param name="jid">The JID of the node service.</param>
        /// <param name="node">The Id of the node whose item to retrieve.</param>
        /// <param name="itemId">The id of the item to retrieve.</param>
        /// <returns>The item with the specified item id.</returns>
        /// <exception cref="ArgumentNullException">The jid parameter or the node
        /// parameter or the itemId parameter is null.</exception>
        /// <exception cref="XmppErrorException">The server returned an XMPP error code.
        /// Use the Error property of the XmppErrorException to obtain the specific
        /// error condition.</exception>
        /// <exception cref="XmppException">The server returned invalid data or another
        /// unspecified XMPP error occurred.</exception>
        public XmlElement RetrieveItem(Jid jid, string node, string itemId)
        {
            jid.ThrowIfNull("jid");
            node.ThrowIfNull("node");
            itemId.ThrowIfNull("itemId");
            var xml = Xml.Element("pubsub", "http://jabber.org/protocol/pubsub").Child(
                Xml.Element("items").Attr("node", node).Child(
                    Xml.Element("item").Attr("id", itemId))
                );
            Iq iq = im.IqRequest(IqType.Get, jid, im.Jid, xml);

            if (iq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(iq, "The item could not be retrieved.");
            }
            var pubsub = iq.Data["pubsub"];

            if (pubsub == null || pubsub.NamespaceURI != "http://jabber.org/protocol/pubsub")
            {
                throw new XmppException("Expected 'pubsub' element: " + iq);
            }
            var items = pubsub["items"];

            if (items == null || items.GetAttribute("node") != node)
            {
                throw new XmppException("Expected 'items' element: " + iq);
            }
            if (items["item"] == null || items["item"].GetAttribute("id") != itemId)
            {
                throw new XmppException("Expected 'item' element: " + items.ToXmlString());
            }
            return(items["item"]);
        }
Пример #6
0
        void SessionInitiateCallback(object sender, XPathEventArgs e)
        {
            try
            {
                Iq iqIn = (Iq)e.Stanza;
                if (iqIn.Type != IqType.Error)
                {
                    Log.Info("<SessionInitiate");


                    Messaging.Jingle.JingleSdp jingleIn = null;

                    // jingleIn = (Messaging.Jingle.JingleSdp) iqIn.Query;
                    jingleIn = iqIn.Element <Messaging.Jingle.JingleSdp>();

                    this.SendAck(iqIn.From, iqIn.Id);
                    if (this.OnReceiveSessionInitiate != null)
                    {
                        this.OnReceiveSessionInitiate(this, new Messaging.Jingle.JingleSdpEventArgs(iqIn.From, jingleIn.ToSdp()));
                    }
                }
                else
                {
                    Log.Error("SessionInitiateCallback Error");
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
Пример #7
0
        /// <summary>
        /// Search for user's to add by email address
        /// </summary>
        /// <param name="email"></param>
        /// <param name="callback"></param>
        public async void Search(string email, EventHandler <IqEventArgs> callback)
        {
            // query to list searchable fields
            // openfire responds w/first last nick email/

            /*
             * var s2 = new Iq() {
             * To = "search.messaging.beetmessenger.com",
             * Type = IqType.Get,
             * Query = new Matrix.Xmpp.Search.Search()
             * };
             */
            var search = new Matrix.Xmpp.Search.Search();

            search.Email = email;

            var s = new Iq()
            {
                To    = "search.messaging.beetmessenger.com",
                Type  = IqType.Set,
                Query = search,
            };

            s.GenerateId();

            this.xmppClient.IqFilter.SendIq(s, callback);
        }
Пример #8
0
        void SessionAcceptCallback(object sender, XPathEventArgs e)
        {
            try
            {
                Log.Info("<SessionAccept");

                Iq iqIn = (Iq)e.Stanza;
                Messaging.Jingle.JingleSdp jingleIn = null;

                // jingleIn = (Messaging.Jingle.JingleSdp) iqIn.Query;
                jingleIn = iqIn.Element <Messaging.Jingle.JingleSdp>();

                this.SendAck(iqIn.From, iqIn.Id);
                // This event needs to get passed back up to IceLink.Conference.OnReceiveOfferAnswer
                if (this.OnReceiveSessionAccept != null)
                {
                    Log.Info("Raising OnReceiveSessionAccept");
                    this.OnReceiveSessionAccept(this, new Messaging.Jingle.JingleSdpEventArgs(iqIn.From, jingleIn.ToSdp()));
                }
                else
                {
                    Log.Info("No OnReceiveSessionAccept handler");
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
Пример #9
0
        public IEnumerable <PrivacyList> GetPrivacyLists()
        {
            this.AssertValid(true);
            Iq errorIq = this.IqRequest(IqType.Get, null, this.Jid, Xml.Element("query", "jabber:iq:privacy"), null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                Util.ExceptionFromError(errorIq, "The privacy lists could not be retrieved.");
            }
            XmlElement element = errorIq.Data["query"];

            if ((element == null) || (element.NamespaceURI != "jabber:iq:privacy"))
            {
                throw new XmppException("Erroneous server response: " + errorIq);
            }
            ISet <PrivacyList> set = new HashSet <PrivacyList>();

            foreach (XmlElement element2 in element.GetElementsByTagName("list"))
            {
                string attribute = element2.GetAttribute("name");
                if (!string.IsNullOrEmpty(attribute))
                {
                    set.Add(this.GetPrivacyList(attribute));
                }
            }
            return(set);
        }
Пример #10
0
        /// <summary>
        /// Request the Search Form
        /// </summary>
        /// <returns>DataForm for avaible fields search</returns>
        public DataForm RequestSearchForm()
        {
            Jid searchDomain = SearchDomain();

            if (searchDomain == null)
            {
                throw new Exception("Feauture not supported");
            }

            Iq iq = im.IqRequest(IqType.Get, searchDomain, im.Jid, Xml.Element("query", xmlns));

            if (iq.Type == IqType.Result)
            {
                var query = iq.Data["query"];
                if (query == null || query.NamespaceURI != xmlns)
                {
                    throw new XmppException("Erroneous server response.");
                }

                return(DataFormFactory.Create(query["x"]));
            }
            else
            {
                var error = iq.Data["error"];
                throw new Exception(error["text"].InnerText);
            }
        }
Пример #11
0
        public void TestOnlineUsers()
        {
            string XML1 = @"<iq id='get-online-users-list-1'
                to='shakespeare.lit'
                type='set'
                xmlns='jabber:client'>
                <command xmlns='http://jabber.org/protocol/commands' 
                           action='execute'
                           node='http://jabber.org/protocol/admin#get-online-users-list'/>
                </iq>";

            var iq = new Iq
            {
                To   = "shakespeare.lit",
                Id   = "get-online-users-list-1",
                Type = Matrix.Xmpp.IqType.Set
            };

            var cmd = new Command()
            {
                Action = Action.Execute,
                Node   = "http://jabber.org/protocol/admin#get-online-users-list"
            };

            iq.Add(cmd);

            iq.ShouldBe(XML1);
        }
Пример #12
0
        /// <summary>
        /// Retrieves the client's external IP address.
        /// </summary>
        /// <returns>The XMPP client's external IP address.</returns>
        /// <exception cref="NotSupportedException">The XMPP server does not
        /// support the 'Server IP Check' XMPP extension.</exception>
        /// <exception cref="XmppErrorException">The server returned an XMPP error code.
        /// Use the Error property of the XmppErrorException to obtain the specific
        /// error condition.</exception>
        /// <exception cref="XmppException">The server returned invalid data or another
        /// unspecified XMPP error occurred.</exception>
        public IPAddress GetExternalAddress()
        {
            if (!ecapa.Supports(im.Jid.Domain, Extension.ServerIpCheck))
            {
                throw new NotSupportedException("The XMPP server does not support " +
                                                "the 'Server IP Check' extension.");
            }
            Iq iq = im.IqRequest(IqType.Get, null, im.Jid,
                                 Xml.Element("address", "urn:xmpp:sic:1"));

            if (iq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(iq, "The external IP address could not " +
                                              "be retrieved.");
            }
            var address = iq.Data["address"];

            if (address == null || address["ip"] == null)
            {
                throw new XmppException("Erroneous IQ response.");
            }
            string ip = address["ip"].InnerText;

            try {
                return(IPAddress.Parse(ip));
            } catch (Exception e) {
                throw new XmppException("The returned address is not a valid IP " +
                                        "address.", e);
            }
        }
Пример #13
0
        /// <summary>
        /// Registers a new account on the XMPP server.
        /// compression.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="RegisterException">Thrown when the registration fails.</exception>
        private async Task DoRegisterAsync(CancellationToken cancellationToken)
        {
            XmppSessionState.Value = SessionState.Registering;
            var regInfoIqResult =
                await SendIqAsync(
                    new RegisterIq { Type = IqType.Get, To = XmppDomain },
                    cancellationToken);

            if (regInfoIqResult.Type == IqType.Result && regInfoIqResult.Query is Register)
            {
                var regIq = new Iq {
                    Type = IqType.Set, To = new Jid(XmppDomain)
                };
                regIq.GenerateId();
                regIq.Query = await RegistrationHandler?.RegisterAsync(regInfoIqResult.Query as Register);

                var regResult = await SendIqAsync(regIq, cancellationToken);

                if (regResult.Type == IqType.Result)
                {
                    XmppSessionState.Value = SessionState.Registered;
                    return;
                }
                else
                {
                    throw new RegisterException(regResult);
                }
            }
            throw new RegisterException(regInfoIqResult);
        }
Пример #14
0
        internal Iq IqRequest(IqType type, S22.Xmpp.Jid to = null, S22.Xmpp.Jid from = null, XmlElement data = null, CultureInfo language = null, int millisecondsTimeout = -1, string seqID = "")
        {
            //Iq stanza = new Iq(type, null, to, from, data, language);
            //foreach (XmppExtension extension in this.extensions)
            //{
            //    IOutputFilter<Iq> filter = extension as IOutputFilter<Iq>;
            //    if (filter != null)
            //    {
            //        filter.Output(stanza);
            //    }
            //}
            //return this.core.IqRequest(stanza, millisecondsTimeout, seqID);

            Iq iq = new Iq(type, null, to, from, data, language);

            // Invoke IOutput<Iq> Plugins.
            foreach (var ext in extensions)
            {
                var filter = ext as IOutputFilter <Iq>;
                if (filter != null)
                {
                    filter.Output(iq);
                }
            }
            return(core.IqRequest(iq, millisecondsTimeout, seqID));
        }
Пример #15
0
        public XmlElement RetrieveItem(Jid jid, string node, string itemId)
        {
            jid.ThrowIfNull <Jid>("jid");
            node.ThrowIfNull <string>("node");
            itemId.ThrowIfNull <string>("itemId");
            XmlElement data    = Xml.Element("pubsub", "http://jabber.org/protocol/pubsub").Child(Xml.Element("items", null).Attr("node", node).Child(Xml.Element("item", null).Attr("id", itemId)));
            Iq         errorIq = base.im.IqRequest(IqType.Get, jid, base.im.Jid, data, null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The item could not be retrieved.");
            }
            XmlElement element2 = errorIq.Data["pubsub"];

            if ((element2 == null) || (element2.NamespaceURI != "http://jabber.org/protocol/pubsub"))
            {
                throw new XmppException("Expected 'pubsub' element: " + errorIq);
            }
            XmlElement e = element2["items"];

            if ((e == null) || (e.GetAttribute("node") != node))
            {
                throw new XmppException("Expected 'items' element: " + errorIq);
            }
            if ((e["item"] == null) || (e["item"].GetAttribute("id") != itemId))
            {
                throw new XmppException("Expected 'item' element: " + e.ToXmlString(false, false));
            }
            return(e["item"]);
        }
Пример #16
0
        private bool PostPrivilegeChange(Jid room, Jid user, Affiliation affiliation, string reason, string nickname)
        {
            room.ThrowIfNull("room");
            user.ThrowIfNull("user");

            var item = Xml.Element("item")
                       .Attr("affiliation", affiliation.ToString().ToLower())
                       .Attr("jid", user.ToString());

            if (!string.IsNullOrWhiteSpace(nickname))
            {
                item.Attr("nick", nickname);
            }
            if (!string.IsNullOrWhiteSpace(reason))
            {
                item.Child(Xml.Element("reason").Text(reason));
            }

            var queryElement = Xml.Element("query", MucNs.NsAdmin)
                               .Child(item);

            Iq iq = im.IqRequest(IqType.Set, room, im.Jid, queryElement);

            return(iq.Type == IqType.Result);
        }
Пример #17
0
        /// <summary>
        /// Requests the items of the node with the specified node id.
        /// </summary>
        /// <param name="jid">The JID of the node service.</param>
        /// <param name="node">The Id of the node whose items to retrieve.</param>
        /// <returns>An enumerable collection of items maintained by the node
        /// with the specified node id.</returns>
        /// <exception cref="ArgumentNullException">The jid parameter or the node
        /// parameter is null.</exception>
        /// <exception cref="XmppErrorException">The server returned an XMPP error code.
        /// Use the Error property of the XmppErrorException to obtain the specific
        /// error condition.</exception>
        /// <exception cref="XmppException">The server returned invalid data or another
        /// unspecified XMPP error occurred.</exception>
        public IEnumerable <XmlElement> RetrieveItems(Jid jid, string node)
        {
            jid.ThrowIfNull("jid");
            node.ThrowIfNull("node");
            var xml = Xml.Element("pubsub", "http://jabber.org/protocol/pubsub")
                      .Child(Xml.Element("items").Attr("node", node));
            Iq iq = im.IqRequest(IqType.Get, jid, im.Jid, xml);

            if (iq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(iq, "The items could not be retrieved.");
            }
            var pubsub = iq.Data["pubsub"];

            if (pubsub == null || pubsub.NamespaceURI != "http://jabber.org/protocol/pubsub")
            {
                throw new XmppException("Expected 'pubsub' element: " + iq);
            }
            var items = pubsub["items"];

            if (items == null || items.GetAttribute("node") != node)
            {
                throw new XmppException("Expected 'items' element: " + iq);
            }
            ISet <XmlElement> set = new HashSet <XmlElement>();

            foreach (XmlElement e in items.GetElementsByTagName("item"))
            {
                set.Add(e);
            }
            return(set);
        }
Пример #18
0
        public PrivacyList GetPrivacyList(string name)
        {
            this.AssertValid(true);
            name.ThrowIfNull <string>("name");
            XmlElement data    = Xml.Element("query", "jabber:iq:privacy").Child(Xml.Element("list", null).Attr("name", name));
            Iq         errorIq = this.IqRequest(IqType.Get, null, this.Jid, data, null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The privacy list could not be retrieved.");
            }
            data = errorIq.Data["query"];
            if (((data == null) || (data.NamespaceURI != "jabber:iq:privacy")) || (data["list"] == null))
            {
                throw new XmppException("Erroneous server response: " + errorIq);
            }
            PrivacyList list     = new PrivacyList(name);
            XmlElement  element2 = data["list"];

            foreach (XmlElement element3 in element2.GetElementsByTagName("item"))
            {
                try
                {
                    PrivacyRule item = this.ParsePrivacyItem(element3);
                    list.Add(item);
                }
                catch (Exception exception)
                {
                    throw new XmppException("Erroneous privacy rule.", exception);
                }
            }
            return(list);
        }
Пример #19
0
        public void Publish(string node, string itemId = null, params XmlElement[] data)
        {
            node.ThrowIfNull <string>("node");
            if (!this.Supported)
            {
                throw new NotSupportedException("The server does not support publishing of information.");
            }
            XmlElement element = Xml.Element("pubsub", "http://jabber.org/protocol/pubsub").Child(Xml.Element("publish", null).Attr("node", node));

            if (data != null)
            {
                XmlElement e = Xml.Element("item", null);
                if (itemId != null)
                {
                    e.Attr("id", itemId);
                }
                foreach (XmlElement element3 in data)
                {
                    if (element3 != null)
                    {
                        e.Child(element3);
                    }
                }
                if (!e.IsEmpty)
                {
                    element["publish"].Child(e);
                }
            }
            Iq errorIq = base.im.IqRequest(IqType.Set, null, base.im.Jid, element, null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The data could not be published.");
            }
        }
Пример #20
0
        public IEnumerable <XmlElement> RetrieveItems(Jid jid, string node)
        {
            jid.ThrowIfNull <Jid>("jid");
            node.ThrowIfNull <string>("node");
            XmlElement data    = Xml.Element("pubsub", "http://jabber.org/protocol/pubsub").Child(Xml.Element("items", null).Attr("node", node));
            Iq         errorIq = base.im.IqRequest(IqType.Get, jid, base.im.Jid, data, null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The items could not be retrieved.");
            }
            XmlElement element2 = errorIq.Data["pubsub"];

            if ((element2 == null) || (element2.NamespaceURI != "http://jabber.org/protocol/pubsub"))
            {
                throw new XmppException("Expected 'pubsub' element: " + errorIq);
            }
            XmlElement element3 = element2["items"];

            if ((element3 == null) || (element3.GetAttribute("node") != node))
            {
                throw new XmppException("Expected 'items' element: " + errorIq);
            }
            ISet <XmlElement> set = new HashSet <XmlElement>();

            foreach (XmlElement element4 in element3.GetElementsByTagName("item"))
            {
                set.Add(element4);
            }
            return(set);
        }
Пример #21
0
        public override void Execute(Tag data = null)
        {
            if (data == null)
            {
                var iq = new Iq
                {
                    IdAttr   = Tag.NextId(),
                    FromAttr = Manager.Settings.Id,
                    ToAttr   = Manager.Settings.Id.Server,
                    TypeAttr = Iq.TypeEnum.set
                };

                iq.Add(new Session());

                Manager.Connection.Send(iq);
            }
            else
            {
                Manager.SetAndExecState(new RunningState(Manager), false);

                Manager.Events.Ready(this);

                Manager.Connection.Send(new Presence());

                if (Manager.Transport == Transport.Bosh)
                {
                    (Manager.Connection as Bosh).StartPolling();
                }
            }
        }
Пример #22
0
        internal void IqError(Iq iq, ErrorType type, ErrorCondition condition, string text = null, params XmlElement[] data)
        {
            this.AssertValid(false);
            iq.ThrowIfNull <Iq>("iq");
            Iq response = new Iq(IqType.Error, iq.Id, iq.From, this.Jid, new XmppError(type, condition, text, data).Data, null);

            this.core.IqResponse(response);
        }
Пример #23
0
        internal void IqResult(Iq iq, XmlElement data = null)
        {
            this.AssertValid(false);
            iq.ThrowIfNull <Iq>("iq");
            Iq response = new Iq(IqType.Result, iq.Id, iq.From, this.Jid, data, null);

            this.core.IqResponse(response);
        }
Пример #24
0
        public override void Execute(Tag data = null)
        {
            if (data == null)
            {
                var bind = new Bind();
                var iq   = new Iq {
                    IdAttr = Tag.NextId()
                };

                if (Manager.Settings.Id.Resource != null)
                {
                    Tag res = new Resource();
                    ((XElement)res).Value = Manager.Settings.Id.Resource;
                    bind.Add(res);
                }

                iq.TypeAttr = Iq.TypeEnum.set;
                iq.Add(bind);

                Manager.Connection.Send(iq);
            }
            else
            {
                Bind bind = null;

                var iq = data as Iq;
                if (iq != null)
                {
                    if (iq.TypeAttr == Iq.TypeEnum.error)
                    {
                        Error e = iq.ErrorElements.First();
                        if (e != null)
                        {
                            Manager.Events.Error(this, ErrorType.BindingToResourceFailed, ErrorPolicyType.Deactivate, ((XElement)e).Value);
                        }
                    }

                    bind = iq.Element <Bind>(Namespace.Bind);
                }

                if (bind != null)
                {
                    Tags.XmppBind.Jid jid = bind.Jid;
                    if (jid != null)
                    {
                        Manager.Settings.Id = jid.Value;
                    }
                }

#if DEBUG
                Manager.Events.LogMessage(this, LogType.Info, "Bind success, JID is now: {0}", Manager.Settings.Id);
#endif
                Manager.Events.Receive(this, data);
                Manager.Events.ResourceBound(this, Manager.Settings.Id.ToString());

                Manager.SetAndExecState(new SessionState(Manager));
            }
        }
Пример #25
0
        public void TestPublishItem()
        {
            const string XML = @"<iq type='set'            
            to='pubsub.shakespeare.lit'
            id='publish1'
            xmlns='jabber:client'>
          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
            <publish node='princely_musings'>
              <item>
                <entry xmlns='http://www.w3.org/2005/Atom'>
                  <title>Soliloquy</title>
                  <summary>
        To be, or not to be: that is the question:
        Whether 'tis nobler in the mind to suffer
        The slings and arrows of outrageous fortune,
        Or to take arms against a sea of troubles,
        And by opposing end them?
                  </summary>
                  <link rel='alternate' type='text/html'
                        href='http://denmark.lit/2003/12/13/atom03'/>
                  <id>tag:denmark.lit,2003:entry-32397</id>
                  <published>2003-12-13T18:30:02Z</published>
                  <updated>2003-12-13T18:30:02Z</updated>
                </entry>
              </item>
            </publish>
          </pubsub>
        </iq>";

            const string PAYLOAD1 =
                @"<entry xmlns='http://www.w3.org/2005/Atom'>
                  <title>Soliloquy</title>
                  <summary>
        To be, or not to be: that is the question:
        Whether 'tis nobler in the mind to suffer
        The slings and arrows of outrageous fortune,
        Or to take arms against a sea of troubles,
        And by opposing end them?
                  </summary>
                  <link rel='alternate' type='text/html'
                        href='http://denmark.lit/2003/12/13/atom03'/>
                  <id>tag:denmark.lit,2003:entry-32397</id>
                  <published>2003-12-13T18:30:02Z</published>
                  <updated>2003-12-13T18:30:02Z</updated>
                </entry>";

            var payload = XmppXElement.LoadXml(PAYLOAD1);

            var item = new Item();

            item.Add(payload);

            Iq iq = PubSubBuilder.PublishItems("pubsub.shakespeare.lit", "princely_musings", new[] { item });

            iq.Id = "publish1";

            iq.ShouldBe(XML);
        }
        public void IqType_IsAnyOf_Values_Should_Return_False()
        {
            var iq = new Iq
            {
                Type = IqType.Result
            };

            iq.Type.IsAnyOf(IqType.Error, IqType.Get).ShouldBeFalse();
        }
Пример #27
0
        private void EstablishSession()
        {
            Iq errorIq = this.IqRequest(IqType.Set, this.Hostname, null, Xml.Element("session", "urn:ietf:params:xml:ns:xmpp-session"), null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "Session establishment failed.");
            }
        }
Пример #28
0
        public void RequestInstantRoom(Jid room)
        {
            Iq iq = im.IqRequest(IqType.Set, room, im.Jid, Xml.Element("query", MucNs.NsOwner).Child(Xml.Element("x", "jabber:x:data").Attr("type", "submit")));

            if (iq.Type != IqType.Result)
            {
                throw new NotSupportedException("Could not query features: " + iq);
            }
        }
Пример #29
0
        void SessionTerminateCallback(object sender, XPathEventArgs e)
        {
            Console.WriteLine("<SessionTerminate");

            Iq iqIn = (Iq)e.Stanza;

            // send ack
            this.SendAck(iqIn.From, iqIn.Id);
        }
Пример #30
0
        public void Register(RegistrationCallback callback)
        {
            callback.ThrowIfNull <RegistrationCallback>("callback");
            Iq errorIq = base.im.IqRequest(IqType.Get, null, null, Xml.Element("query", "jabber:iq:register"), null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw new NotSupportedException("The XMPP server does not support the 'In-Band Registration' extension.");
            }
            XmlElement query = errorIq.Data["query"];

            if ((query == null) || (query.NamespaceURI != "jabber:iq:register"))
            {
                throw new XmppException("Erroneous server response: " + errorIq);
            }
            if (query["registered"] != null)
            {
                throw new XmppException("The XMPP entity is already registered.");
            }
            XmlElement element2 = query["data"];

            if ((element2 != null) && (element2.NamespaceURI == "urn:xmpp:bob"))
            {
                BobData bob = BobData.Parse(element2);
                this.bob.Add(bob);
            }
            RequestForm form = null;
            bool        flag = query["x"] != null;

            if (flag)
            {
                form = DataFormFactory.Create(query["x"]) as RequestForm;
            }
            else
            {
                form = this.CreateDataForm(query);
            }
            SubmitForm form2 = callback(form);
            XmlElement e     = Xml.Element("query", "jabber:iq:register");

            if (flag)
            {
                e.Child(form2.ToXmlElement());
            }
            else
            {
                foreach (DataField field in form2.Fields)
                {
                    e.Child(Xml.Element(field.Name, null).Text(field.Values.FirstOrDefault <string>()));
                }
            }
            errorIq = base.im.IqRequest(IqType.Set, null, null, e, null, -1, "");
            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The registration could not be completed.");
            }
        }