Exemple #1
0
        private void sipService_onSubscriptionEvent(object sender, SubscriptionEventArgs e)
        {
            if (e.Type != SubscriptionEventTypes.INCOMING_NOTIFY
                || e.Content == null
                || (e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.REG && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO)
                )
            {
                return;
            }

            switch (e.Type)
            {
                case SubscriptionEventTypes.INCOMING_NOTIFY:
                    {
                        new Thread(delegate()
                        {
                            this.Dispatcher.Invoke((System.Threading.ThreadStart)delegate
                                {
                                    if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.REG)
                                    {
                                        this.ParseRegInfo(e.Content);
                                    }
                                    else if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO)
                                    {
                                        this.ParseWatcherInfo(e.Content);
                                    }
                                });
                        })
                        .Start();
                        break;
                    }
            }
        }
Exemple #2
0
        private void sipService_onSubscriptionEvent(object sender, SubscriptionEventArgs e)
        {
            if (e.Type != SubscriptionEventTypes.INCOMING_NOTIFY
                || e.Content == null
                || (e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.REG && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY)
                )
            {
                return;
            }

            switch (e.Type)
            {
                case SubscriptionEventTypes.INCOMING_NOTIFY:
                    {
                        new Thread(delegate()
                        {
                            this.Dispatcher.Invoke((System.Threading.ThreadStart)delegate
                                {
                                    if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.REG)
                                    {
                                        this.ParseRegInfo(e.Content);
                                    }
                                    else if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO)
                                    {
                                        this.ParseWatcherInfo(e.Content);
                                    }
                                    else if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY)
                                    {
                                        MessageSummary ms = MessageSummary.Parse(e.Content);
                                        if (ms != null)
                                        {
                                            this.imageMailbox.Visibility = ms.HaveWaitingMessages ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
                                            String tooltip = String.Format("Message-Account: {0}\n", ms.Account);
                                            new String[] { "Voice-Message", "Fax-Message", "Pager-Message", "Multimedia-Message", "Text-Message" }.ToList().ForEach(x =>
                                                {
                                                    tooltip += String.Format("{0}: {1}/{2} ({3}/{4})\n", x, ms.GetNewMessages(x), ms.GetOldMessages(x), ms.GetNewUrgentMessages(x), ms.GetOldUrgentMessages(x));
                                                });
                                            this.imageMailbox.ToolTip = tooltip;
                                        }
                                    }
                                });
                        })
                        .Start();
                        break;
                    }
            }
        }
        private void sipService_onSubscriptionEvent(object sender, SubscriptionEventArgs e)
        {
            if (e.Type != SubscriptionEventTypes.INCOMING_NOTIFY ||
                (e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.PRESENCE_LIST)
                || e.Content == null)
            {
                return;
            }

            switch (e.Type)
            {
                case SubscriptionEventTypes.INCOMING_NOTIFY:
                    {
                        new Thread(delegate()
                        {
                            this.Dispatcher.Invoke((System.Threading.ThreadStart)delegate
                            {
                                this.ParsePresenceContent(e);
                            });
                        })
                        .Start();
                        break;
                    }
            }
        }
Exemple #4
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;
            }
        private void ParsePresenceContent(SubscriptionEventArgs e)
        {
            try
            {
                if (ContentType.MULTIPART_RELATED.Equals(e.ContentType) && (e.GetExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_TYPE) as String).Contains(ContentType.RLMI))
                {
                    String boundary = e.GetExtra(SubscriptionEventArgs.EXTRA_CONTENTYPE_BOUNDARY) as String;
                    // to support both \r\n and \n\n
                   String[] contents = Encoding.UTF8.GetString(e.Content).Split(new String[] { ("\n--" + boundary), ("\r--" + boundary) }, StringSplitOptions.RemoveEmptyEntries);
                   int indexStart, indexEnd, contentStart;
                   String contentType;
                   foreach(String content in contents)
                   {
                       String _content = content.Trim();
                       if (_content == String.Empty)
                       {
                           continue;
                       }
                       indexStart = _content.IndexOf("Content-Type:", StringComparison.InvariantCultureIgnoreCase);
                       if (indexStart == -1)
                       {
                           continue;
                       }
                       indexEnd = _content.IndexOf("\n", indexStart);
                       if (indexEnd == -1)
                       {
                           continue;
                       }
                       contentType = _content.Substring(indexStart + 13, (indexEnd - indexStart - 13)).Split(";".ToCharArray(),  StringSplitOptions.RemoveEmptyEntries)[0].Trim();

                       if ((contentStart = _content.IndexOf("\r\n\r\n")) == -1 && (contentStart = _content.IndexOf("\n\n\r\n")) == -1)
                       {
                           continue;
                       }
                       _content = _content.Substring(contentStart).Trim();

                       if (ContentType.RLMI.Equals(contentType, StringComparison.InvariantCultureIgnoreCase))
                       {
                           this.ParseRLMI(Encoding.UTF8.GetBytes(_content));
                       }
                       else if (ContentType.PIDF.Equals(contentType, StringComparison.InvariantCultureIgnoreCase))
                       {
                           this.ParsePidf(Encoding.UTF8.GetBytes(_content));
                       }
                   }
                }
                else if (ContentType.RLMI.Equals(e.ContentType))
                {
                    this.ParseRLMI(e.Content);
                }
                else if (ContentType.PIDF.Equals(e.ContentType))
                {
                    this.ParsePidf(e.Content);
                }
            }
            catch (Exception ex)
            {
                LOG.Error(ex);
            }
        }