コード例 #1
0
        void HandleSubscribe(XElement Node)
        {
            if (OnSubscribe == null)
            {
                return;
            }

            JID From = new JID(Node.Attribute("from").Value);
            SubscribeResponse Action = OnSubscribe.Invoke(From);

            if (Action == SubscribeResponse.Reject)
            {
                return;
            }

            XElement PresenceTag = new XElement("presence");

            PresenceTag.SetAttributeValue("to", From.GetBareJID());
            PresenceTag.SetAttributeValue("type", "subscribed");
            Uplink.GetNetworkClient().WriteTextToSocket(PresenceTag.ToString());

            if (Action == SubscribeResponse.Allow)
            {
                return;
            }

            Subscribe(From);
        }
コード例 #2
0
ファイル: Stanza.cs プロジェクト: ehasting/dxmppnet
        public override void EnforceAttributes(JID From)
        {
            base.EnforceAttributes(From);

            switch (MessageType)
            {
            case StanzaMessageType.Chat:
                Payload.SetAttributeValue("type", "chat");
                break;

            case StanzaMessageType.Error:
                Payload.SetAttributeValue("type", "error");
                break;

            case StanzaMessageType.Groupchat:
                Payload.SetAttributeValue("type", "groupchat");
                break;

            case StanzaMessageType.Headline:
                Payload.SetAttributeValue("type", "headline");
                break;

            case StanzaMessageType.Normal:
                Payload.SetAttributeValue("type", "normal");
                break;
            }
        }
コード例 #3
0
 public Connection(string Hostname,
                   int Portnumber,
                   JID RequestedJID,
                   X509Certificate2 Certificate)
     :  this(Hostname, Portnumber, RequestedJID, null, Certificate)
 {
 }
コード例 #4
0
ファイル: DataSource.cs プロジェクト: Clayster/samples
        List <ResourceAccess> GetAccessRights(DXMPP.JID Actor, AccessToken Token)
        {
            try
            {
                AccessTokenSession TV = AccessTokens[Actor.GetBareJID() + Token];

                if (TV.ExpiresAtUTC <= DateTime.UtcNow)
                {
                    AccessTokens.TryRemove(Token, out TV);
                    throw new AccessViolation();
                }

                if (TV.Actor.GetBareJID() != Actor.GetBareJID())
                {
                    throw new AccessViolation();
                }

                return(TV.Rights);
            }
            catch
            {
                if (ForceAccessTokenSessions)
                {
                    throw new AccessViolation();
                }
            }

            throw new AccessViolation();
        }
コード例 #5
0
 public Connection(string Hostname,
                   int Portnumber,
                   JID RequestedJID,
                   X509Certificate2 Certificate,
                   int DebugLevel = 0)
     :  this(Hostname, Portnumber, RequestedJID, null, Certificate, false, 30, DebugLevel)
 {
 }
コード例 #6
0
        public void Unsubscribe(JID To)
        {
            XElement PresenceTag = new XElement("presence");

            PresenceTag.SetAttributeValue("to", To.GetBareJID());
            PresenceTag.SetAttributeValue("type", "unsubscribe");
            Uplink.GetNetworkClient().WriteTextToSocket(PresenceTag.ToString());
        }
コード例 #7
0
ファイル: Roster.cs プロジェクト: ehasting/dxmppnet
        void PresenceHandler(XElement Node)
        {
            string type = "available";

            if (Node.Attribute("type") != null)
            {
                type = Node.Attribute("type").Value;
            }

            switch (type)
            {
            case "subcribe":
                HandleSubscribe(Node);
                return;

            case "subcribed":
                HandleSubscribed(Node);
                return;

            case "unsubscribe":
                HandleUnsubscribe(Node);
                return;

            case "unsubscribed":
                HandleUnsubscribed(Node);
                return;
            }
            JID      From     = new JID(Node.Attribute("from").Value);
            int      Priority = 0;
            XElement PrioNode = Node.XPathSelectElement("//priority");

            if (PrioNode != null)
            {
                Priority = Convert.ToInt32(PrioNode.Value);
            }

            string Show   = string.Empty;
            string Status = string.Empty;

            XElement ShowNode = Node.XPathSelectElement("//show");

            if (ShowNode != null)
            {
                Show = ShowNode.Value;
            }
            XElement StatusNode = Node.XPathSelectElement("//status");

            if (StatusNode != null)
            {
                Show = StatusNode.Value;
            }

            if (OnPresence != null)
            {
                OnPresence.Invoke(From, Status != "unavailable", Priority, Status, Show);
            }
        }
コード例 #8
0
        void HandleUnsubscribed(XElement Node)
        {
            if (OnUnsubscribed == null)
            {
                return;
            }

            JID From = new JID(Node.Attribute("from").Value);

            OnUnsubscribed.Invoke(From);
        }
コード例 #9
0
ファイル: Stanza.cs プロジェクト: ehasting/dxmppnet
        public virtual void EnforceAttributes(JID From)
        {
            if (To != null)
            {
                Payload.SetAttributeValue("to", To.ToString());
            }

            if (From != null)
            {
                Payload.SetAttributeValue("from", From.ToString());
            }

            Payload.SetAttributeValue("id", ID);
        }
コード例 #10
0
 public Connection(string Hostname,
                   int Portnumber,
                   JID RequestedJID,
                   string Password,
                   X509Certificate2 Certificate = null)
 {
     this.Hostname   = Hostname;
     this.Portnumber = Portnumber;
     this.MyJID      = RequestedJID;
     if (MyJID.GetResource() == string.Empty)
     {
         MyJID.SetResource(System.Guid.NewGuid().ToString());
     }
     this.Password         = Password;
     this.RosterMaintainer = new Roster(this);
     this.Certificate      = Certificate;
 }
コード例 #11
0
        void CheckForBindSuccess(XElement Doc)
        {
            if (Doc.Name.LocalName != "iq")
            {
                Console.WriteLine("no iqnode?!");
                BroadcastConnectionState(CallbackConnectionState.ErrorUnknown);
                CurrentConnectionState = ConnectionState.ErrorUnknown;
                return;
            }

            this.MyJID = new JID((Doc.FirstNode as XElement).Value);


            string StartSession = "<iq type='set' id='1'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>";

            Client.WriteTextToSocket(StartSession);
            CurrentConnectionState     = ConnectionState.WaitingForSession;
            CurrentAuthenticationState = AuthenticationState.Authenticated;
        }
コード例 #12
0
ファイル: Stanza.cs プロジェクト: ehasting/dxmppnet
        public Stanza(XElement Payload)
        {
            this.Payload = Payload;

            if (Payload.Attribute("to") != null)
            {
                To = new JID(Payload.Attribute("to").Value);
            }

            if (Payload.Attribute("from") != null)
            {
                From = new JID(Payload.Attribute("from").Value);
            }

            if (Payload.Attribute("id") != null)
            {
                this.ID = Payload.Attribute("id").Value;
            }
        }
コード例 #13
0
 public Connection(string Hostname,
                   int Portnumber,
                   JID RequestedJID,
                   string Password,
                   X509Certificate2 Certificate          = null,
                   bool AllowSelfSignedServerCertificate = false,
                   int KeepAliveByWhiteSpaceInterval     = 30,
                   int DebugLevel = 0)
 {
     this.Hostname   = Hostname;
     this.Portnumber = Portnumber;
     this.MyJID      = RequestedJID;
     if (MyJID.GetResource() == string.Empty)
     {
         MyJID.SetResource(System.Guid.NewGuid().ToString());
     }
     this.Password         = Password;
     this.RosterMaintainer = new Roster(this);
     this.Certificate      = Certificate;
     this.AllowSelfSignedServerCertificate = AllowSelfSignedServerCertificate;
     this.KeepAliveByWhiteSpaceInterval    = KeepAliveByWhiteSpaceInterval;
     this.DebugLevel = DebugLevel;
 }
コード例 #14
0
ファイル: Stanza.cs プロジェクト: ehasting/dxmppnet
        public override void EnforceAttributes(JID From)
        {
            base.EnforceAttributes(From);

            switch (IQType)
            {
            case StanzaIQType.Get:
                Payload.SetAttributeValue("type", "get");
                break;

            case StanzaIQType.Set:
                Payload.SetAttributeValue("type", "set");
                break;

            case StanzaIQType.Result:
                Payload.SetAttributeValue("type", "result");
                break;

            case StanzaIQType.Error:
                Payload.SetAttributeValue("type", "error");
                break;
            }
        }
コード例 #15
0
        void PresenceHandler(XElement Node)
        {
            string type = "available";

            if (Node.Attribute("type") != null)
            {
                type = Node.Attribute("type").Value;
            }

            switch (type)
            {
            case "subscribe":
                HandleSubscribe(Node);
                return;

            case "subscribed":
                HandleSubscribed(Node);
                return;

            case "unsubscribe":
                HandleUnsubscribe(Node);
                return;

            case "unsubscribed":
                HandleUnsubscribed(Node);
                return;
            }
            JID      From     = new JID(Node.Attribute("from").Value);
            int      Priority = 0;
            XElement PrioNode = Node.XPathSelectElement("//priority");

            if (PrioNode != null)
            {
                Priority = Convert.ToInt32(PrioNode.Value);
            }

            string Show   = string.Empty;
            string Status = string.Empty;

            XElement ShowNode = Node.XPathSelectElement("//show");

            if (ShowNode != null)
            {
                Show = ShowNode.Value;
            }
            XElement StatusNode = Node.XPathSelectElement("//status");

            if (StatusNode != null)
            {
                Show = StatusNode.Value;
            }

            PresenceInformation PI = new PresenceInformation()
            {
                FullJID  = From,
                Priority = Priority,
                Show     = Show,
                Status   = Status
            };

            if (!AggregatedPresence.ContainsKey(From.GetBareJID()))
            {
                AggregatedPresence[From.GetBareJID()] = new List <PresenceInformation>();
            }
            AggregatedPresence[From.GetBareJID()].Add(PI);

            if (OnPresence != null)
            {
                OnPresence.Invoke(From, Status != "unavailable", Priority, Status, Show);
            }
        }
コード例 #16
0
ファイル: Stanza.cs プロジェクト: ehasting/dxmppnet
 public new void EnforceAttributes(JID From)
 {
     base.EnforceAttributes(From);
 }