Example #1
0
        public bool GroupDelete(Group group)
        {
            if (!this.hasResourceLists)
            {
                LOG.Warn("Group connot be updated as XDMS doesn't support 'resource-lists'");
                return(false);
            }

            String url;

            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)
                .setAttribute("list", "name", group.Name);
                url = this.xcapSelector.getString();
            }
            MyXcapMessage xcapMessage = this.xcapStack.DeleteElement(url);
            bool          ok          = (xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code));

            // FIXME: Delete all anchors
            LOG.Error("Anchors must also be deleted");

            return(ok);
        }
Example #2
0
        private bool HandleRLSEvent(short code, byte[] content)
        {
            rlsservices rls = null;

            try
            {
                if (XcapService.IsSuccessCode(code))
                {
                    rls = this.Deserialize(content, typeof(rlsservices)) as rlsservices;
                }
                else if (code == 404)
                {
                    rls = this.CreateRLSDocument();
                }

                // RCS Service Uri used as request URI in the SUBSCRIBE requests
                if (rls != null)
                {
                    this.rlsPresUri = this.GetPresenceServiceUri(rls, SpecialNames.SHARED_RCS);
                }
            }
            catch (Exception e)
            {
                XcapService.LOG.Error("Fialed to handle 'rls-services' event", e);
                return(false);
            }

            return(rls != null);
        }
Example #3
0
        public bool ContactAdd(Contact contact)
        {
            if (!this.hasResourceLists)
            {
                LOG.Warn("Contact connot be added as XDMS doesn't support 'resource-lists'");
                return(false);
            }

            entryType entry = this.ContactToEntry(contact);

            byte[] payload = this.Serialize(entry, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID));
            String url;

            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)
                .setAttribute("list", "name", contact.GroupName)
                .setAttribute("entry", "uri", contact.UriString);
                url = this.xcapSelector.getString();
            }

            MyXcapMessage xcapMessage = this.xcapStack.PutElement(url, payload, (uint)payload.Length);

            return(xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code));
        }
Example #4
0
        private bool HandleResourceListsEvent(short code, byte[] content)
        {
            try
            {
                resourcelists rlist;
                if (XcapService.IsSuccessCode(code))
                {
                    rlist = this.Deserialize(content, typeof(resourcelists)) as resourcelists;
                    if (rlist == null || rlist.list == null)
                    {
                        return(false);
                    }

                    return(this.FromResouceListToContacts(rlist));
                }
                else if (code == 404)
                {
                    if ((rlist = this.CreateResourceListsDocument()) != null)
                    {
                        return(this.FromResouceListToContacts(rlist));
                    }
                }
            }
            catch (Exception e)
            {
                XcapService.LOG.Error("Failed to handle 'resource-lists' event", e);
                return(false);
            }

            return(false);
        }
Example #5
0
        // xcap-casps
        private bool handleXcapCapsEvent(short code, byte[] content)
        {
            try
            {
                if (XcapService.IsSuccessCode(code))
                {
                    xcapcaps caps = this.Deserialize(content, typeof(xcapcaps)) as xcapcaps;
                    if (caps == null || caps.auids == null || caps.auids.auid == null)
                    {
                        return(false);
                    }
                    List <String> auids = new List <String>(caps.auids.auid);

                    this.hasOMADirectory       = auids.Contains(XcapService.XCAP_AUID_OMA_DIRECTORY_ID);
                    this.hasResourceLists      = auids.Contains(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID);
                    this.hasRLS                = auids.Contains(XcapService.XCAP_AUID_IETF_RLS_SERVICES_ID);
                    this.hasPresRules          = auids.Contains(XcapService.XCAP_AUID_IETF_PRES_RULES_ID);
                    this.hasOMAPresRules       = auids.Contains(XcapService.XCAP_AUID_OMA_PRES_RULES_ID);
                    this.hasOMAPresenceContent = auids.Contains(XcapService.XCAP_AUID_OMA_PRES_CONTENT_ID);

                    return(true);
                }
            }
            catch (Exception e)
            {
                XcapService.LOG.Error("Fialed to handle 'xcap-caps' event", e);
                return(false);
            }

            return(false);
        }
        private bool HandlePresContent(short code, byte[] content)
        {
            try
            {
                if (XcapService.IsSuccessCode(code))
                {
                    content presContent = this.Deserialize(content, typeof(content)) as content;
                    if (presContent != null && presContent.data != null && !String.IsNullOrEmpty(presContent.data.Value))
                    {
                        this.Avatar = presContent.data.Value;
                        return(true);
                    }
                }
                else if (code == 404)
                {
                    XcapService.LOG.Error("'org.openmobilealliance.pres-content' document not found");
                    return(true);
                }
            }
            catch (Exception e)
            {
                XcapService.LOG.Error("Fialed to handle 'org.openmobilealliance.pres-content' event", e);
                return(false);
            }

            return(false);
        }
        public bool CreatePresenceContentDocument(String base64Content, String mimeType)
        {
            if (String.IsNullOrEmpty(base64Content) || String.IsNullOrEmpty(mimeType))
            {
                LOG.Error("Invalid content or mimeType");
                return(false);
            }

            content document = new content();

            document.mimetype             = new contentMimetype();
            document.mimetype.Value       = mimeType;
            document.encoding             = new contentEncoding();
            document.encoding.Value       = "base64";
            document.description          = new contentDescription[1];
            document.description[0]       = new contentDescription();
            document.description[0].Value = "Doubango";
            document.data       = new contentData();
            document.data.Value = base64Content;

            String documentUrl;

            if (this.xcapDocumentsUris.ContainsKey(XcapService.XCAP_AUID_OMA_PRES_CONTENT_ID))
            {
                documentUrl = this.xcapDocumentsUris[XcapService.XCAP_AUID_OMA_PRES_CONTENT_ID];
            }
            else
            {
                lock (this.xcapSelector)
                {
                    this.xcapSelector.reset();
                    this.xcapSelector.setAUID(XcapService.XCAP_AUID_OMA_PRES_CONTENT_ID);
                    documentUrl = this.xcapSelector.getString();
                }
            }
            byte[] payload = this.Serialize(document, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_OMA_PRES_CONTENT_ID));

            MyXcapMessage xcapMessage = this.xcapStack.PutDocument(documentUrl, payload, (uint)payload.Length, XcapService.XCAP_AUID_OMA_PRES_CONTENT_MIME_TYPE);

            if (xcapMessage != null)
            {
                if (XcapService.IsSuccessCode(xcapMessage.Code))
                {
                    return(true);
                }
                else
                {
                    LOG.Error(String.Format("Failed to update statusicon with code={0}", xcapMessage.Code));
                }
            }
            else
            {
                LOG.Error("Failed to update statusicon");
            }

            return(false);
        }
Example #8
0
        // org.openmobilealliance.xcap-directory
        private bool handleOMADirectoryEvent(short code, byte[] content)
        {
            try
            {
                if (XcapService.IsSuccessCode(code))
                {
                    this.xcapDocumentsUris.Clear();

                    xcapdirectory xcap_dir = this.Deserialize(content, typeof(xcapdirectory)) as xcapdirectory;
                    if (xcap_dir == null || xcap_dir.folder == null)
                    {
                        return(false);
                    }

                    foreach (xcapdirectoryFolder folder in xcap_dir.folder)
                    {
                        if (String.IsNullOrEmpty(folder.auid) || folder.Entries.Count == 0)
                        {
                            continue;
                        }

                        xcapdirectoryFolderEntry entry = null;

                        if (String.Equals(folder.auid, XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID))
                        {
                            // I prefer 'index' document
                            entry = folder.Entries.FirstOrDefault(x => x != null && !String.IsNullOrEmpty(x.uri) && x.uri.EndsWith(String.Format("/{0}", XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_DOC)));
                        }
                        if (entry == null)
                        {
                            entry = folder.Entries.FirstOrDefault(x => x != null && !String.IsNullOrEmpty(x.uri));
                        }
                        if (entry != null)
                        {
                            this.xcapDocumentsUris.Add(folder.auid, entry.uri);
                        }
                    }

                    return(true);
                }
            }
            catch (Exception e)
            {
                XcapService.LOG.Error("Fialed to handle 'org.openmobilealliance.xcap-directory' event", e);
                return(false);
            }

            return(false);
        }
Example #9
0
        public bool ContactDelete(Contact contact)
        {
            if (!this.hasResourceLists)
            {
                LOG.Warn("Contact connot be deleted as XDMS doesn't support 'resource-lists'");
                return(false);
            }

            String url;

            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)
                .setAttribute("list", "name", contact.GroupName)
                .setAttribute("entry", "uri", contact.UriString);
                url = this.xcapSelector.getString();
            }

            MyXcapMessage xcapMessage = this.xcapStack.DeleteElement(url);

            return(xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code));
        }
Example #10
0
        public bool ContactUpdate(Contact contact, String prevGroupName)
        {
            if (!this.hasResourceLists)
            {
                LOG.Warn("Contact connot be updated as XDMS doesn't support 'resource-lists'");
                return(false);
            }

            // 1. Add contact
            entryType entry = this.ContactToEntry(contact);

            byte[] payload = this.Serialize(entry, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID));
            String url;

            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)
                .setAttribute("list", "name", contact.GroupName)
                .setAttribute("entry", "uri", contact.UriString);
                url = this.xcapSelector.getString();
            }

            MyXcapMessage xcapMessage = this.xcapStack.PutElement(url, payload, (uint)payload.Length);
            bool          ok          = (xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code));

            // 2. Remove from old group
            if (ok && !String.Equals(contact.GroupName, prevGroupName))
            {
                Contact clone = new Contact();
                clone.UriString = contact.UriString;
                clone.GroupName = prevGroupName;
                ok &= this.ContactDelete(clone);
            }

            return(ok);
        }
Example #11
0
        private resourcelists CreateResourceListsDocument()
        {
            resourcelists list  = new resourcelists();
            int           count = 0;

            listType[] rcs = this.GetRCSLists();
            listType[] oma = this.GetOMALists();

            list.list = new listType[rcs.Length + oma.Length + 1];
            rcs.ToList().ForEach(x => list.list[count++] = x);
            oma.ToList().ForEach(x => list.list[count++] = x);

            // Doubango List
            list.list[count]                   = new listType();
            list.list[count].displayname       = new displaynameType();
            list.list[count].displayname.Value = "My Default Contacts";
            list.list[count].name              = SpecialNames.SHARED_DOUBANGO;

            String documentUrl;

            //if(this.xcapDocumentsUris.ContainsKey())
            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID);
                documentUrl = this.xcapSelector.getString();
            }
            byte[] payload = this.Serialize(list, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID));

            MyXcapMessage xcapMessage = this.xcapStack.PutDocument(documentUrl, payload, (uint)payload.Length, XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_MIME_TYPE);

            if (xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code))
            {
                return(list);
            }
            return(null);
        }
Example #12
0
        private bool HandleOMAPresRules(short code, byte[] content)
        {
            try
            {
                ruleset document;
                if (XcapService.IsSuccessCode(code))
                {
                    document = this.Deserialize(content, typeof(ruleset)) as ruleset;
                    if (document != null && document.rules != null)
                    {
                        if (document.rules.Count(x =>
                                                 SpecialNames.PRESRULES_OMA_ALLOW_OWN.Equals(x.id) ||
                                                 SpecialNames.PRESRULES_OMA_BLOCKED_CONTACTS.Equals(x.id) ||
                                                 SpecialNames.PRESRULES_OMA_GRANTED_CONTACTS.Equals(x.id) ||
                                                 SpecialNames.PRESRULES_OMA_UNLISTED.Equals(x.id) ||
                                                 SpecialNames.PRESRULES_RCS_ALLOW_SERVICE_ANONYMOUS.Equals(x.id)) != 5)
                        {
                            return((document = this.CreateOMAPresRulesDocument()) != null);
                        }
                        return(true);
                    }

                    return(false);
                }
                else if (code == 404)
                {
                    return((document = this.CreateOMAPresRulesDocument()) != null);
                }
            }
            catch (Exception e)
            {
                XcapService.LOG.Error("Failed to handle 'resource-lists' event", e);
                return(false);
            }

            return(false);
        }
Example #13
0
        public bool GroupUpdate(Group group)
        {
            if (!this.hasResourceLists)
            {
                LOG.Warn("Group connot be updated as XDMS doesn't support 'resource-lists'");
                return(false);
            }

            listType list = this.GroupToList(group);

            byte[] payload = this.Serialize(list, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID));
            String url;

            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_IETF_RESOURCE_LISTS_ID)
                .setAttribute("list", "name", group.Name);
                url = this.xcapSelector.getString();
            }
            MyXcapMessage xcapMessage = this.xcapStack.PutElement(url, payload, (uint)payload.Length);

            return(xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code));
        }
Example #14
0
        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);
        }
Example #15
0
        private ruleset CreateOMAPresRulesDocument()
        {
            ruleset document = new ruleset();

            //<cr:conditions>
            //  <cr:identity>
            //    <cr:one id="sip:[email protected]" />
            //  </cr:identity>
            //</cr:conditions>
            identityType identityCond = new identityType();

            identityCond.Items = new oneType[1];
            oneType otype = new oneType();

            otype.id = this.xcapStack.XUI;
            identityCond.Items[0] = otype;

            //<cr:conditions>
            //  <anonymous-request xmlns="urn:oma:xml:xdm:common-policy" />
            //</cr:conditions>
            anonymousRequest anonymousCond = new anonymousRequest();

            // <cr:conditions>
            //  <other-identity xmlns="urn:oma:xml:xdm:common-policy" />
            //</cr:conditions>
            otherIdentity otherIdentityCond = new otherIdentity();

            // <cr:conditions>
            //  <external-list xmlns="urn:oma:xml:xdm:common-policy">
            //    <entry anc="http://doubango.org:8080/services/resource-lists/users/sip:[email protected]/index/~~/resource-lists/list%5B@name=%22oma_grantedcontacts%22%5D" />
            //  </external-list>
            //</cr:conditions>
            externallist omaGrantedCond = this.CreatePresRulesExternalList(SpecialNames.SHARED_OMA_GRANTEDCONTACTS);

            //<cr:conditions>
            //  <external-list xmlns="urn:oma:xml:xdm:common-policy">
            //    <entry anc="http://doubango.org:8080/services/resource-lists/users/sip:[email protected]/index/~~/resource-lists/list%5B@name=%22oma_blockedcontacts%22%5D" />
            //  </external-list>
            //</cr:conditions>
            externallist omaBlockedCond = this.CreatePresRulesExternalList(SpecialNames.SHARED_OMA_BLOCKEDCONTACTS);

            document.rule = new ruleType[]
            {
                CreatePresRule(SpecialNames.PRESRULES_OMA_ALLOW_OWN, "allow", true, identityCond),
                CreatePresRule(SpecialNames.PRESRULES_RCS_ALLOW_SERVICE_ANONYMOUS, "allow", true, anonymousCond),
                CreatePresRule(SpecialNames.PRESRULES_OMA_UNLISTED, "confirm", false, otherIdentityCond),
                CreatePresRule(SpecialNames.PRESRULES_OMA_GRANTED_CONTACTS, "allow", true, omaGrantedCond),
                CreatePresRule(SpecialNames.PRESRULES_OMA_BLOCKED_CONTACTS, "block", false, omaBlockedCond)
            };


            String documentUrl;

            //if(this.xcapDocumentsUris.ContainsKey())
            lock (this.xcapSelector)
            {
                this.xcapSelector.reset();
                this.xcapSelector.setAUID(XcapService.XCAP_AUID_OMA_PRES_RULES_ID);
                documentUrl = this.xcapSelector.getString();
            }
            byte[] payload = this.Serialize(document, true, true, this.GetSerializerNSFromAUID(XcapService.XCAP_AUID_OMA_PRES_RULES_ID));

            MyXcapMessage xcapMessage = this.xcapStack.PutDocument(documentUrl, payload, (uint)payload.Length, XcapService.XCAP_AUID_OMA_PRES_RULES_MIME_TYPE);

            if (xcapMessage != null && XcapService.IsSuccessCode(xcapMessage.Code))
            {
                return(document);
            }
            return(null);
        }