コード例 #1
0
ファイル: XcapService.RLS.cs プロジェクト: xolile/boghe
        private String GetPresenceServiceUri(rlsservices services, String presList)
        {
            if (services == null || services.service == null || String.IsNullOrEmpty(presList))
            {
                LOG.Warn("Invalid RLS document");
                return String.Empty;
            }

            String resourceList; // e.g.:http://doubango.org:8080/services/resource-lists/users/sip:[email protected]/index/~~/resource-lists/list%5B@name=%22rcs%22%5D

            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)
                    .setAttribute("list", "name", presList);
                resourceList = this.xcapSelector.getString();
            }

            foreach (serviceType service in services.service)
            {
                if (service.packages == null || String.IsNullOrEmpty(service.uri))
                {
                    continue;
                }

                String _resourceList = service.Item as String;
                if (!String.IsNullOrEmpty(_resourceList) && _resourceList.Equals(resourceList))
                {
                    if (service.packages.Packages.Contains("presence"))
                    {
                        return service.uri;
                    }
                }
            }

            return String.Empty;
        }
コード例 #2
0
ファイル: XcapService.RLS.cs プロジェクト: xolile/boghe
        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;
        }
コード例 #3
0
ファイル: XcapService.RLS.cs プロジェクト: sarandogou/boghe
        private String GetPresenceServiceUri(rlsservices services, String presList)
        {
            if (services == null || services.service == null || String.IsNullOrEmpty(presList))
            {
                LOG.Warn("Invalid RLS document");
                return String.Empty;
            }

            String resourceList; // e.g.:http://doubango.org:8080/services/resource-lists/users/sip%3Amamadou%40colibria.com/index/~~/resource-lists/list%5B%40name%3D%22rcs%22%5D

            if (this.xcapDocumentsUris.ContainsKey(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID))
            {
                resourceList = String.Format("{0}/~~/resource-lists/list%5B%40name%3D%22{1}%22%5D",
                    this.xcapDocumentsUris[XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID],
                    presList);
            }
            else
            {
                lock (this.xcapSelector)
                {
                    this.xcapSelector.reset();
                    this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)
                        .setAttribute("list", "name", presList);
                    resourceList = this.xcapSelector.getString();
                }
            }

            foreach (serviceType service in services.service)
            {
                if (service.packages == null || String.IsNullOrEmpty(service.uri))
                {
                    continue;
                }

                String _resourceList = service.Item as String;
                if (!String.IsNullOrEmpty(_resourceList) && _resourceList.Equals(resourceList))
                {
                    if (service.packages.Packages.Contains("presence"))
                    {
                        return service.uri;
                    }
                }
            }

            return String.Empty;
        }