Esempio n. 1
0
        public void Subscribe(GenaMessage request, GenaMessage response)
        {
            VerifyHeaders(request);

            //subscribe
            var sub = new GenaSubscription();

            lock (_subscriptions)
            {
                this._subscriptions.Add(sub.SubscriptionId, sub);
            }

            sub.Callbacks     = request.Callbacks;
            sub.RenewInterval = request.Timeout ?? TimeSpan.MaxValue;

            if (sub.RenewInterval != TimeSpan.MaxValue)
            {
                _dispatcher.Add(() => CheckSubscription(sub), sub.RenewInterval);
            }


            //update timeout value if one is present
            RespondToSubscribe(request, response, sub);

            /**
             * SUBSCRIBE:
             *
             * SUBSCRIBE publisher path HTTP/1.1
             *  HOST: publisher host:publisher port
             *  USER-AGENT: OS/version UPnP/1.1 product/version
             *  CALLBACK: <delivery URL>
             *  NT: upnp:event
             *  TIMEOUT: Second-requested subscription duration
             *
             * SUBSCRIBE RESPONSE:
             *
             *  HTTP/1.1 200 OK
             *  DATE: when response was generated
             *  SERVER: OS/version UPnP/1.1 product/version
             *  SID: uuid:subscription-UUID
             *  CONTENT-LENGTH: 0
             *  TIMEOUT: Second-actual subscription duration
             *
             * RENEWAL:
             *  SUBSCRIBE publisher path HTTP/1.1
             *  HOST: publisher host:publisher port
             *  SID: uuid:subscription UUID
             *  TIMEOUT: Second-requested subscription duration
             *
             * RENEWAL RESPONSE is the same as SUBSCRIBE RESPONSE
             *
             */
        }
Esempio n. 2
0
        public void Subscribe(GenaMessage request, GenaMessage response)
        {
            VerifyHeaders(request);

            //subscribe
            var sub = new GenaSubscription();

            lock (_subscriptions)
            {
                this._subscriptions.Add(sub.SubscriptionId, sub);
            }

            sub.Callbacks = request.Callbacks;
            sub.RenewInterval = request.Timeout ?? TimeSpan.MaxValue;

            if(sub.RenewInterval != TimeSpan.MaxValue)
                _dispatcher.Add(() => CheckSubscription(sub), sub.RenewInterval);

            //update timeout value if one is present
            RespondToSubscribe(request, response, sub);

            /**
             * SUBSCRIBE:
             *
             * SUBSCRIBE publisher path HTTP/1.1
             *  HOST: publisher host:publisher port
             *  USER-AGENT: OS/version UPnP/1.1 product/version
             *  CALLBACK: <delivery URL>
             *  NT: upnp:event
             *  TIMEOUT: Second-requested subscription duration
             *
             * SUBSCRIBE RESPONSE:
             *
             *  HTTP/1.1 200 OK
             *  DATE: when response was generated
             *  SERVER: OS/version UPnP/1.1 product/version
             *  SID: uuid:subscription-UUID
             *  CONTENT-LENGTH: 0
             *  TIMEOUT: Second-actual subscription duration
             *
             * RENEWAL:
             *  SUBSCRIBE publisher path HTTP/1.1
             *  HOST: publisher host:publisher port
             *  SID: uuid:subscription UUID
             *  TIMEOUT: Second-requested subscription duration
             *
             * RENEWAL RESPONSE is the same as SUBSCRIBE RESPONSE
             *
            */
        }
Esempio n. 3
0
        private static void RespondToSubscribe(GenaMessage request, GenaMessage response, GenaSubscription sub)
        {
            var timeout = request.Timeout;

            if (timeout.HasValue)
            {
                sub.RenewInterval = timeout.Value;
            }

            response.SubscriptionId = sub.SubscriptionId;
            response.Timeout        = sub.RenewInterval;
            response.Date           = DateTime.Now;
            response.UserAgent      = String.Format("{0}/{1} UPnP/1.1 UPnPLib/1.1", Environment.OSVersion.Platform, Environment.OSVersion.Version);;
        }
Esempio n. 4
0
        public void Unsubscribe(GenaMessage request, GenaMessage response)
        {
            VerifyHeaders(request);

            var sid = request.SubscriptionId;

            lock (_subscriptions)
            {
                if (!_subscriptions.ContainsKey(sid))
                {
                    throw new GenaException(HttpStatusCode.PreconditionFailed);
                }

                _subscriptions.Remove(sid);
            }
        }
Esempio n. 5
0
        public void Renew(GenaMessage request, GenaMessage response)
        {
            GenaSubscription sub;

            var sid = request.SubscriptionId;

            //renew
            lock (_subscriptions)
            {
                if (!_subscriptions.TryGetValue(sid, out sub))
                    throw new GenaException(HttpStatusCode.PreconditionFailed);
            }

            sub.Renew();

            RespondToSubscribe(request, response, sub);
        }
Esempio n. 6
0
        private static void VerifyHeaders(GenaMessage message)
        {
            if (message == null)
            {
                throw new GenaException(HttpStatusCode.BadRequest);
            }

            var sid       = message.SubscriptionId;
            var nt        = message.NotificationType;
            var callbacks = message.Callbacks;

            //If a SID header field and one of NT or CALLBACK header fields are present.
            if (!string.IsNullOrEmpty(sid) && (!string.IsNullOrEmpty(nt) || callbacks != null))
            {
                throw new GenaException(HttpStatusCode.BadRequest);
            }
        }
Esempio n. 7
0
        public void Renew(GenaMessage request, GenaMessage response)
        {
            GenaSubscription sub;

            var sid = request.SubscriptionId;

            //renew
            lock (_subscriptions)
            {
                if (!_subscriptions.TryGetValue(sid, out sub))
                {
                    throw new GenaException(HttpStatusCode.PreconditionFailed);
                }
            }

            sub.Renew();

            RespondToSubscribe(request, response, sub);
        }
Esempio n. 8
0
 public GenaMessageEventArgs(string serviceId)
 {
     this.ServiceId = serviceId;
     this.Request   = GenaMessage.CreateRequest();
     this.Response  = GenaMessage.CreateResponse();
 }
Esempio n. 9
0
        private static void VerifyHeaders(GenaMessage message)
        {
            if (message == null)
                throw new GenaException(HttpStatusCode.BadRequest);

            var sid = message.SubscriptionId;
            var nt = message.NotificationType;
            var callbacks = message.Callbacks;

            //If a SID header field and one of NT or CALLBACK header fields are present.
            if (!string.IsNullOrEmpty(sid) && (!string.IsNullOrEmpty(nt) || callbacks != null))
                throw new GenaException(HttpStatusCode.BadRequest);
        }
Esempio n. 10
0
        private static void RespondToSubscribe(GenaMessage request, GenaMessage response, GenaSubscription sub)
        {
            var timeout = request.Timeout;
            if (timeout.HasValue)
                sub.RenewInterval = timeout.Value;

            response.SubscriptionId = sub.SubscriptionId;
            response.Timeout = sub.RenewInterval;
            response.Date = DateTime.Now;
            response.UserAgent = String.Format("{0}/{1} UPnP/1.1 UPnPLib/1.1", Environment.OSVersion.Platform, Environment.OSVersion.Version); ;
        }
Esempio n. 11
0
        public void Unsubscribe(GenaMessage request, GenaMessage response)
        {
            VerifyHeaders(request);

            var sid = request.SubscriptionId;

            lock (_subscriptions)
            {
                if (!_subscriptions.ContainsKey(sid))
                    throw new GenaException(HttpStatusCode.PreconditionFailed);

                _subscriptions.Remove(sid);
            }
        }