[sr-dev] Patch to add oma user-profile and pres-content support to xcap_server

Peter Dunkley peter.dunkley at crocodile-rcs.com
Thu May 12 12:32:42 CEST 2011


Hello,

Please find attached a patch to add oma user-profile and pres-content
(avatar) support to the xcap_server module.

To make use of these changes I also had to update my kamailio.cfg (based
on the example from
http://kb.asipto.com/kamailio:presence:k31-made-simple).  In particular
I had to update the event_route[xhttp:request] clause so that:

      * the xcap-caps response includes the auids and namespace entries
        for user-profile and pres-content
      * modify the auth user checking because (unlike the XML documents
        that were already there) any user can retrieve user-profile and
        pres-content, but only the owner can update them.


For reference, my updated event_route[xhttp:request] clause is included
below.

Regards,

Peter


event_route[xhttp:request] {
#!ifdef WITH_PRESENCE
        xdbg("===== xhttp: request [$rv] $rm => $hu\n");
#!ifdef WITH_XHTTPAUTH
        if (!www_authorize("xcap", "subscriber")) {
                www_challenge("xcap", "0");
                exit;
        }
#!endif

        if($hu=~"^/xcap-root/") {
                set_reply_close();
                set_reply_no_connect();
                # xcap ops
                $xcapuri(u=>data) = $hu;
                if($xcapuri(u=>xuid)=~"^sip:.+ at .+")
                        $var(uri) = $xcapuri(u=>xuid);
                else if($xcapuri(u=>xuid)=~".+ at .+")
                        $var(uri) = "sip:" + $xcapuri(u=>xuid);
                else
                        $var(uri) = "sip:"+ $xcapuri(u=>xuid) + "@" + $Ri;
                if($xcapuri(u=>auid)=="xcap-caps") {
                        $var(xbody) =
"<?xml version='1.0' encoding='UTF-8'?>
<xcap-caps xmlns='urn:ietf:params:xml:ns:xcap-caps'>
  <auids>
    <auid>rls-services</auid>
    <auid>pidf-manipulation</auid>
    <auid>xcap-caps</auid>
    <auid>resource-lists</auid>
    <auid>pres-rules</auid>
    <auid>org.openmobilealliance.pres-rules</auid>
    <auid>org.openmobilealliance.user-profile</auid> 
    <auid>org.openmobilealliance.pres-conent</auid>
  </auids>
  <extensions>
  </extensions>
  <namespaces>
    <namespace>urn:ietf:params:xml:ns:rls-services</namespace>
    <namespace>urn:ietf:params:xml:ns:pidf</namespace>
    <namespace>urn:ietf:params:xml:ns:xcap-caps</namespace>
    <namespace>urn:ietf:params:xml:ns:resource-lists</namespace>
    <namespace>urn:ietf:params:xml:ns:pres-rules</namespace>
    <namespace>urn:oma:xml:xdm:user-profile</namespace>
    <namespace>urn:oma:xml:prs:pres-content</namespace>
  </namespaces>
</xcap-caps>";
                        xhttp_reply("200", "ok", "application/xcap-caps+xml",
                                        "$var(xbody)");
                        exit;
                }

                switch($rm) {
                        case "PUT":
#!ifdef WITH_XHTTPAUTH
                                # be sure only auth user updates its documents
                                if ($au!=$(var(uri){uri.user})) {
                                        xhttp_reply("403", "Forbidden", "text/html",
                                            "<html><body>$si:$sp</body></html>");
                                        exit;
                                }
#!endif 
                                xcaps_put("$var(uri)", "$hu", "$rb");
                                if($xcapuri(u=>auid)=~"pres-rules") {
                                        pres_update_watchers("$var(uri)", "presence");
                                        pres_refresh_watchers("$var(uri)", "presence", 1);
                                }
                                exit;
                        break;
                        case "GET":
#!ifdef WITH_XHTTPAUTH
                                if (!($xcapuri(u=>auid)=~"user-profile" || $xcapuri(u=>auid)=~"pres-content")) {
                                        # be sure only auth user gets non-profile documents
                                        if ($au!=$(var(uri){uri.user})) {
                                                xhttp_reply("403", "Forbidden", "text/html",
                                                    "<html><body>$si:$sp</body></html>");
                                                exit;
                                        }
                                }
#!endif 
                                xcaps_get("$var(uri)", "$hu");
                                exit;
                        break;
                        case "DELETE":
#!ifdef WITH_XHTTPAUTH
                                # be sure only auth user deletes its documents
                                if ($au!=$(var(uri){uri.user})) {
                                        xhttp_reply("403", "Forbidden", "text/html",
                                            "<html><body>$si:$sp</body></html>");
                                        exit;
                                }
#!endif 
                                xcaps_del("$var(uri)", "$hu");
                                if($xcapuri(u=>auid)=~"pres-rules") {
                                        pres_update_watchers("$var(uri)", "presence");
                                        pres_refresh_watchers("$var(uri)", "presence", 1);
                                }
                                exit;
                        break;
                }
        }

        # http ops
        xhttp_reply("200", "ok", "text/html", "<html><body>OK: $si:$sp</body></html>");
        exit;
#!endif
}


-- 
Peter Dunkley
Technical Director
Crocodile RCS Ltd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20110512/507b324d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: user_profile_avatar.patch
Type: text/x-patch
Size: 3977 bytes
Desc: not available
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20110512/507b324d/attachment.bin>


More information about the sr-dev mailing list