[SR-Users] xcap server config snippets

Daniel-Constantin Mierla miconda at gmail.com
Wed Oct 2 20:49:46 CEST 2013


Hello,

there were several emails related to usage of embedded xcap server 
module, so I am pasting here relevant snippets from config file that 
should get people started.

Cheers,
Daniel

#!define WITH_XHTTP
#!define WITH_XCAPSRV

tcp_accept_no_cl=yes
tcp_rd_buf_size=65536
pv_buffer_size=65536
sql_buffer_size=65536


#!define XHTTP_PORT 8080
#!define XHTTPS_PORT 8443

#!ifdef WITH_XHTTP
loadmodule "xhttp.so"
#!endif

#!ifdef WITH_XCAPSRV
loadmodule "xcap_server.so"
#!endif


#!ifdef WITH_XCAPSRV
# ----- xcap_server params -----
modparam("xcap_server", "db_url", DBURL)
modparam("xcap_server", "buf_size", 65536)
#!endif

...

#!ifdef WITH_XHTTP
event_route[xhttp:request] {
     xdbg("===== xhttp: request [$rv] $rm => $hu\n");

     set_reply_no_connect();


     if ($Rp != XHTTP_PORT
#!ifdef WITH_TLS
                 && $Rp != XHTTPS_PORT
#!endif
             ) {
         set_reply_close();
         xlog("L_WARN", "HTTP request received on $Rp\n");
         xhttp_reply("403", "Forbidden", "", "");
         exit;
     }

     if (!www_authorize("mydomain.com", "subscriber"))
     {
         www_challenge("mydomain.com", "0");
         exit;
     }
     set_reply_close();

     route(XCAPSRV);

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

route[XCAPSRV] {
#!ifdef WITH_XCAPSRV
     if(! ($hu=~"^/xcap-root/")) {
         return;
     }
     # xcap ops - break down http uri to get xcap user id
     route(XCAPURI);
     $xcapuri(u=>data) = $var(hu);

     if($xcapuri(u=>uri)==$null) {
         xlog("==== xhttp failed uri => [$hu] ~ [$var(hu)]\n");
         xhttp_reply("404", "Not Found", "text/html",
                 "unsupported xcap uri");
         exit;
     }

     if($xcapuri(u=>xuid)=~"^sip:.+ at .+")
         $var(uri) = $xcapuri(u=>xuid);
     else
         $var(uri) = "sip:"+ $xcapuri(u=>xuid) + "@" + $Ri;

     # handle XCAP capability request
     if($xcapuri(u=>auid)=="xcap-caps") {
         if ($rm == "GET") {
             $var(xbody) =
"<?xml version='1.0' encoding='UTF-8'?>
<xcap-caps xmlns='urn:ietf:params:xml:ns:xcap-caps'>
   <auids>
" +
#!ifdef WITH_RLS
"    <auid>rls-services</auid>
" +
#!endif
"    <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-content</auid>
     <auid>org.openmobilealliance.search</auid>
<auid>org.openmobilealliance.xcap-directory</auid>
   </auids>
   <extensions>
   </extensions>
   <namespaces>
" +
#!ifdef WITH_RLS
" <namespace>urn:ietf:params:xml:ns:rls-services</namespace>
" +
#!endif
" <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>
<namespace>urn:oma:xml:xdm:search</namespace>
<namespace>urn:oma:xml:xdm:xcap-directory</namespace>
   </namespaces>
</xcap-caps>";
             xhttp_reply("200", "ok", "application/xcap-caps+xml",
                             "$var(xbody)");
         } else {
             append_to_reply("Allow: GET\r\n");
             xhttp_reply("405", "Method Not Allowed", "", "");
         }
         exit;
     }

     # be sure auth user access only its documents
     if ($rm!="GET" && $au!=$(var(uri){uri.user})) {
         xlog("==== xhttp forbidden => [$au] != [$(var(uri){uri.user})]\n");
         xhttp_reply("403", "Forbidden", "text/html",
                 "operation not allowed");
         exit;
     }

     xdbg("SCRIPT: xcap service $xcapuri(u=>auid) for $xcapuri(u=>xuid)\n");
     switch($rm) {
         case "PUT":
             xcaps_put("$var(uri)", "$var(hu)", "$rb");
             if($xcapuri(u=>auid)=~"pres-rules")
             {
                 pres_update_watchers("$var(uri)", "presence");
                 pres_refresh_watchers("$var(uri)", "presence", 1);
#!ifdef WITH_RLS
             } else if($xcapuri(u=>auid)=~"rls-services"
                     || $xcapuri(u=>auid)=~"resource-lists") {
                 rls_update_subs("$var(uri)", "presence");
#!endif
             } else if($xcapuri(u=>auid)=~"pidf-manipulation") {
                 pres_refresh_watchers("$var(uri)", "presence", 2,
                             "$xcapuri(u=>uri_adoc)", "$xcapuri(u=>file)");
             }
             exit;
         break;
         case "GET":
             $var(furi) = "sip:" + $au + "@" + $ar;
             if ($au!=$(var(uri){uri.user})) {
                 # be sure only auth user gets its non-profile documents
                 if (!($xcapuri(u=>auid)=~"user-profile"
                         || $xcapuri(u=>auid)=~"pres-content")) {
                     xhttp_reply("403", "Forbidden", "", "");
                     exit;
                 } else {
                     # be sure only permitted user gets others profile 
documents
                     pres_auth_status("$var(furi)", "$var(uri)");
                     $var(rc) = $rc;
                     if ($var(rc) != 1) {
                         xhttp_reply("403", "Forbidden", "", "");
                         exit;
                     }
                 }
             }
             xcaps_get("$var(uri)", "$var(hu)");
             exit;
         break;
         case "DELETE":
             xcaps_del("$var(uri)", "$var(hu)");
             if($xcapuri(u=>auid)=~"pres-rules") {
                 pres_update_watchers("$var(uri)", "presence");
                 pres_refresh_watchers("$var(uri)", "presence", 1);
#!ifdef WITH_RLS
             } else if($xcapuri(u=>auid)=~"rls-services"
                     || $xcapuri(u=>auid)=~"resource-lists") {
                 rls_update_subs("$var(uri)", "presence");
#!endif
             } else if($xcapuri(u=>auid)=~"pidf-manipulation") {
                 pres_refresh_watchers("$var(uri)", "presence", 2,
                         "$xcapuri(u=>uri_adoc)", "$xcapuri(u=>file)");
             }
             exit;
         break;
         case "POST":
             if($xcapuri(u=>auid)=~"search") {
                 xhttp_reply("501", "Not Implemented", "", "");
             } else {
                 if($xcapuri(u=>auid)=~"xcap-directory") {
                     append_to_reply("Allow: GET\r\n");
                 } else {
                     append_to_reply("Allow: DELETE, GET, PUT\r\n");
                 }
                 xhttp_reply("405", "Method Not Allowed", "", "");
             }
             exit;
         break;
     }
#!endif
     return;
}

# Return fixed XCAP URI in $var(hu)
route[XCAPURI] {
#!ifdef WITH_XCAPSRV
     # Jitsi...
     if ($hu=~"^/xcap-root/resource-lists/users/.*/index$") {
         $var(hu) = 
$(hu{re.subst,!(^/xcap-root/resource-lists/users/.*/).*$!\1generallist.xml!});
     } else if ($hu=~"^/xcap-root/pres-rules/users/.*/presrules$") {
         $var(hu) = 
$(hu{re.subst,!(^/xcap-root/)pres-rules(/users/.*/)presrules!\1org.openmobilealliance.pres-rules\2pres-rules!});
     } else if ($hu=~"^/xcap-root/oma_status-icon/users/.*/.*$") {
         $var(hu) = 
$(hu{re.subst,!(^/xcap-root/)oma_status-icon(/users/.*/).*$!\1org.openmobilealliance.pres-content\2oma_status-icon/icon_document!});

     # Bria...
     } else if 
($hu=~"^/xcap-root/resource-lists/users/.*/contacts-resource-list.xml$") {
         $var(hu) = 
$(hu{re.subst,!(^/xcap-root/resource-lists/users/.*/).*$!\1generallist.xml!});
     } else if 
($hu=~"^/xcap-root/resource-lists/users/.*/resource-list.xml$") {
         $var(doc_uri) = 
$(hu{re.subst,!(^/xcap-root/resource-lists/users/.*/).*$!\1generallist.xml!});

     # No modification required...
     } else {
         $var(hu) = $hu;
     }
#!endif
     return;
}


-- 
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio Advanced Trainings - Berlin, Nov 25-28; Miami, Nov 18-20, 2013
   - more details about Kamailio trainings at http://www.asipto.com -




More information about the sr-users mailing list