Ejemplo n.º 1
0
            /// <summary>
            /// Subscription events
            /// </summary>
            /// <param name="e"></param>
            /// <returns></returns>
            public override int OnSubscriptionEvent(SubscriptionEvent e)
            {
                tsip_subscribe_event_type_t type = e.getType();

                switch (type)
                {
                    case tsip_subscribe_event_type_t.tsip_i_notify:
                        {
                            SubscriptionSession session = e.getSession();
                            MySubscriptionSession mysession;
                            if (session == null || (mysession = this.sipService.FindSubscription(session.getId())) == null)
                            {
                                LOG.Error("Null session");
                                return -1;
                            }
                            SipMessage message = e.getSipMessage();
                            if (message == null)
                            {
                                LOG.Error("Null message");
                                return -1;
                            }
                            String contentType = message.getSipHeaderValue("c");
                            byte[] content = message.getSipContent();
                            if (String.IsNullOrEmpty(contentType) || content == null)
                            {
                                LOG.Error("Invalid content");
                                return -1;
                            }

                            // Save content: To allow the end user to request this content at any time
                            if (String.Equals(contentType, ContentType.REG_INFO))
                            {
                                this.sipService.subRegContent = content;
                            }
                            else if (String.Equals(contentType, ContentType.WATCHER_INFO))
                            {
                                this.sipService.subWinfoContent = content;
                            }

                            short code = e.getCode();
                            String phrase = e.getPhrase();

                            SubscriptionEventArgs eargs = new SubscriptionEventArgs(SubscriptionEventTypes.INCOMING_NOTIFY,
                                code, phrase, content, contentType, mysession.EventPackage);
                            eargs.AddExtra(SubscriptionEventArgs.EXTRA_SESSION, mysession);
                            if (ContentType.MULTIPART_RELATED.Equals(contentType, StringComparison.InvariantCultureIgnoreCase))
                            {
                                String ctype = message.getSipHeaderParamValue("c", "type");
                                eargs.AddExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_TYPE, ctype == null ? String.Empty : ctype.Replace("\"", String.Empty));

                                String start = message.getSipHeaderParamValue("c", "start");
                                eargs.AddExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_START, start == null ? String.Empty : start.Replace("\"", String.Empty));

                                String boundary = message.getSipHeaderParamValue("c", "boundary");
                                eargs.AddExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_BOUNDARY, boundary == null ? String.Empty : boundary.Replace("\"", String.Empty));
                            }
                            EventHandlerTrigger.TriggerEvent<SubscriptionEventArgs>(this.sipService.onSubscriptionEvent, this.sipService, eargs);

                            break;
                        }

                    default:
                    case tsip_subscribe_event_type_t.tsip_i_subscribe:
                    case tsip_subscribe_event_type_t.tsip_ao_subscribe:
                    case tsip_subscribe_event_type_t.tsip_i_unsubscribe:
                    case tsip_subscribe_event_type_t.tsip_ao_unsubscribe:
                    case tsip_subscribe_event_type_t.tsip_ao_notify:
                        {
                            break;
                        }
                }

                return 0;
            }
Ejemplo n.º 2
0
        public override int OnSubscriptionEvent(SubscriptionEvent e)
        {
            short code = e.getCode();
            tsip_subscribe_event_type_t type = e.getType();
            SubscriptionSession session = e.getSession();
            SipMessage message = e.getSipMessage();

            switch (type)
            {
                case tsip_subscribe_event_type_t.tsip_ao_subscribe:
                case tsip_subscribe_event_type_t.tsip_ao_unsubscribe:
                    break;

                case tsip_subscribe_event_type_t.tsip_i_notify:
                    byte[] content = message.getSipContent();
                    if (content != null)
                        Console.WriteLine("Notify Content ==> {0}", Encoding.UTF8.GetString(content));
                    break;
            }

            Console.WriteLine("OnSubscriptioChanged() ==> {0}:{1}", code, e.getPhrase());

            return 0;
        }