Exemple #1
0
        public static string GetValidPhoneNumber(string uri)
        {
            string result2;

            if (uri != null && (uri.StartsWith("sip:") || uri.StartsWith("sip:") || uri.StartsWith("tel:")))
            {
                SipUri sipUri = new SipUri(uri);
                if (sipUri.isValid())
                {
                    string userName = sipUri.getUserName();
                    if (userName != null)
                    {
                        try
                        {
                            string scheme = sipUri.getScheme();
                            if (scheme != null && scheme.Equals("tel"))
                            {
                                userName = userName.Replace("-", "");
                            }
                            long result = System.Convert.ToInt64(userName.StartsWith("+") ? userName.Substring(1) : userName);
                            if (result < 1000000000000L)
                            {
                                result2 = userName;
                                return(result2);
                            }
                        }
                        catch (System.FormatException)
                        {
                        }
                        catch (System.Exception e)
                        {
                            UriUtils.LOG.Error(e);
                        }
                    }
                }
                sipUri.Dispose();
            }
            else
            {
                try
                {
                    uri = uri.Replace("-", "");
                    long result = System.Convert.ToInt64(uri.StartsWith("+") ? uri.Substring(1) : uri);
                    if (result < 1000000000000L)
                    {
                        result2 = uri;
                        return(result2);
                    }
                }
                catch (System.FormatException)
                {
                }
                catch (System.Exception e)
                {
                    UriUtils.LOG.Error(e);
                }
            }
            result2 = null;
            return(result2);
        }
Exemple #2
0
        // very dirty
        public static String GetValidPhoneNumber(String uri)
        {
            if (uri != null && (uri.StartsWith("sip:") || uri.StartsWith("sip:") || uri.StartsWith("tel:")))
            {
                SipUri sipUri = new SipUri(uri);
                if (sipUri.isValid())
                {
                    String userName = sipUri.getUserName();
                    if (userName != null)
                    {
                        try
                        {
                            String scheme = sipUri.getScheme();
                            if (scheme != null && scheme.Equals("tel"))
                            {
                                userName = userName.Replace("-", "");
                            }

                            long result = Convert.ToInt64(userName.StartsWith("+") ? userName.Substring(1) : userName);
                            if (result < UriUtils.MAX_PHONE_NUMBER)
                            {
                                return(userName);
                            }
                        }
                        catch (FormatException) { }
                        catch (Exception e)
                        {
                            LOG.Error(e);
                        }
                    }
                }
                sipUri.Dispose();
            }
            else
            {
                try
                {
                    uri = uri.Replace("-", "");
                    long result = Convert.ToInt64(uri.StartsWith("+") ? uri.Substring(1) : uri);
                    if (result < UriUtils.MAX_PHONE_NUMBER)
                    {
                        return(uri);
                    }
                }
                catch (FormatException) { }
                catch (Exception e)
                {
                    LOG.Error(e);
                }
            }
            return(null);
        }
        private rlsservices CreateRLSDocument()
        {
            rlsservices rls = new rlsservices();

            rls.service = new serviceType[]
            {
                // RCS service
                this.CreatePresenceService(SpecialNames.SHARED_RCS),
                // OMA services
                this.CreatePresenceService(SpecialNames.SHARED_OMA_BUDDYLIST),
                this.CreatePresenceService(SpecialNames.SHARED_OMA_POCBUDDYLIST)
            };

            String documentUrl;

            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RLS_SERVICES_ID);
                documentUrl = this.xcapSelector.getString();
            }

            byte[]        payload     = this.Serialize(rls, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_IETF_RLS_SERVICES_ID));
            MyXcapMessage xcapMessage = this.xcapStack.PutDocument(documentUrl, payload, (uint)payload.Length, XcapService.XCAP_AUID_IETF_RLS_SERVICES_MIME_TYPE);

            if (xcapMessage != null)
            {
                if (XcapService.IsSuccessCode(xcapMessage.Code))
                {
                    return(rls);
                }
                else if (xcapMessage.Content != null && xcapMessage.Code == 409 /*Conflict*/ || xcapMessage.Code == 415 /*Unsupported Media Type*/)
                {
                    object    content = this.Deserialize(xcapMessage.Content, typeof(xcaperror));
                    xcaperror xerror;

                    if (content != null && ((xerror = content as xcaperror) != null))
                    {
                        LOG.Error(String.Format("XCAP Error={0}", xerror.ErrorPhrase));
                        if (xerror.ErrorType == xcaperror.xcaperrorItemType.ErrorElementUniquenessfailure)
                        {
                            xcaperrorErrorelementUniquenessfailure errorUniquenessfailure = xerror.Item as xcaperrorErrorelementUniquenessfailure;
                            if (errorUniquenessfailure != null && errorUniquenessfailure.exists != null && errorUniquenessfailure.exists.Length > 0)
                            {
                                xcaperrorErrorelementUniquenessfailureExists errorUniquenessfailureExists = errorUniquenessfailure.exists[0];
                                if (errorUniquenessfailureExists != null)
                                {
                                    String field    = errorUniquenessfailureExists.field;
                                    String altvalue = (errorUniquenessfailureExists.altvalue != null && errorUniquenessfailureExists.altvalue.Length > 0) ? errorUniquenessfailureExists.altvalue[0] : null;

                                    if (String.IsNullOrEmpty(altvalue))
                                    {
                                        SipUri sipUri = new SipUri(this.xcapStack.XUI);
                                        if (sipUri.isValid())
                                        {
                                            altvalue = String.Format(CultureInfo.CurrentCulture,
                                                                     "{0}:{1}_alt{2}",
                                                                     sipUri.getScheme(), sipUri.getUserName(), DateTime.Now.Ticks);
                                        }
                                        else
                                        {
                                            altvalue = "sip:[email protected]";
                                        }
                                    }
                                    rls.service[0].uri = altvalue;

                                    payload     = this.Serialize(rls, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_IETF_RLS_SERVICES_ID));
                                    xcapMessage = this.xcapStack.PutDocument(documentUrl, payload, (uint)payload.Length, XcapService.XCAP_AUID_IETF_RLS_SERVICES_MIME_TYPE);
                                    if (xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code))
                                    {
                                        return(rls);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }