[SR-Users] Kamailio accepts and stores XCAP XML document from jitsi but rejects it on retrieval

Daniel-Constantin Mierla miconda at gmail.com
Thu May 29 14:51:18 CEST 2014


Hello,

the error message is printed in case of an invalid xml document.

Can you edit modules/xcap_server/xcap_misc.c  and add inside function:

int xcaps_check_doc_validity(str *doc)

the log:

LM_ERR("xmld document is: [[%.*s]]\n", doc->len, doc->s);

before the line with:

docxml = xmlParseMemory(doc->s, doc->len);

Re-compile and re-install. Then run a test and send here the output of 
this line.

Cheers,
Daniel

On 29/05/14 01:30, Alex Villací­s Lasso wrote:
> I am trying to set up XCAP support for SIP SIMPLE, and using jitsi as 
> the sample client. The kamailio database was previously configured 
> using ODBC and kamailio-4.1.3 and was apparently working correctly. I 
> was following the guide at 
> http://nil.uniza.sk/instant-messaging/simple/configuring-xcap-support-im-and-presence-over-kamailio-31-debian-lenny 
> as well as the standard documentation at 
> http://kamailio.org/docs/modules/4.1.x/modules/xcap_server.html . 
> However, the rls support is currently disabled. When I use jitsi to 
> connect, and add one contact to the empty contact list, I see the 
> database being populated (mysql backend):
>
> mysql> select * from xcap;
> +----+-------------+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+-----------------------+--------+-----------------------------------------------------------------------+------+ 
>
> | id | username    | domain          | doc | doc_type | 
> etag                  | source | doc_uri | port |
> +----+-------------+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+-----------------------+--------+-----------------------------------------------------------------------+------+ 
>
> |  3 | avillacisIM | pbx.elastix.com | <?xml version="1.0" 
> encoding="UTF-8" standalone="no"?><resource-lists 
> xmlns="urn:ietf:params:xml:ns:resource-lists"><list 
> name="RootGroup"><entry 
> uri="sip:bmacias at pbx.elastix.com"><display-name>bmacias</display-name></entry></list></resource-lists> 
> |        4 | sr-1401316328-31413-1 |      0 | 
> /xcap-root/resource-lists/users/sip:avillacisIM at pbx.elastix.com/index 
> |    0 |
> |  4 | avillacisIM | pbx.elastix.com | <?xml version="1.0" 
> encoding="UTF-8" standalone="no"?><ruleset 
> xmlns="urn:ietf:params:xml:ns:common-policy"><rule 
> id="presence_allow"><conditions><identity><one 
> id="sip:bmacias at pbx.elastix.com"/></identity></conditions><actions><sub-handling 
> xmlns="urn:ietf:params:xml:ns:pres-rules">allow</sub-handling></actions><transformations><provide-devices 
> xmlns="urn:ietf:params:xml:ns:pres-rules"><all-devices/></provide-devices><provide-persons 
> xmlns="urn:ietf:params:xml:ns:pres-rules"><all-persons/></provide-persons><provide-services 
> xmlns="urn:ietf:params:xml:ns:pres-rules"><all-services/></provide-services></transformations></rule></ruleset> 
> |        2 | sr-1401316328-31416-1 |      0 | 
> /xcap-root/pres-rules/users/sip:avillacisIM at pbx.elastix.com/presrules 
> |    0 |
> +----+-------------+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+-----------------------+--------+-----------------------------------------------------------------------+------+ 
>
> 2 rows in set (0.00 sec)
>
> As far as I can see, both XML documents are well formed.
>
> However, if I shutdown and then restart jitsi, I see (with wireshark) 
> that the server returned a 500 Server Error when trying to fetch 
> resource-lists . At the same time, the following appears on the log:
>
> May 28 17:39:12 elx /usr/sbin/kamailio[31421]: ALERT: <script>: ===== 
> xhttp: request [HTTP/1.1] GET => /xcap-root/xcap-caps/global/index
> May 28 17:39:12 elx /usr/sbin/kamailio[31421]: ALERT: <script>: ===== 
> xhttp: request [HTTP/1.1] GET => /xcap-root/xcap-caps/global/index
> May 28 17:39:12 elx /usr/sbin/kamailio[31421]: ALERT: <script>: ===== 
> xhttp: xcap-caps : <null>
> May 28 17:39:12 elx /usr/sbin/kamailio[31413]: ALERT: <script>: ===== 
> xhttp: request [HTTP/1.1] GET => 
> /xcap-root/resource-lists/users/sip:avillacisIM at pbx.elastix.com/index
> May 28 17:39:12 elx /usr/sbin/kamailio[31413]: ALERT: <script>: ===== 
> xhttp: request [HTTP/1.1] GET => 
> /xcap-root/resource-lists/users/sip:avillacisIM at pbx.elastix.com/index
> May 28 17:39:12 elx /usr/sbin/kamailio[31413]: ALERT: <script>: ===== 
> xhttp: resource-lists : sip:avillacisIM at pbx.elastix.com
> May 28 17:39:12 elx /usr/sbin/kamailio[31413]: ERROR: xcap_server 
> [xcap_server.c:758]: xcaps_get_db_doc(): invalid xml doc retrieved 
> from database
> May 28 17:39:12 elx /usr/sbin/kamailio[31413]: ERROR: xcap_server 
> [xcap_server.c:1171]: w_xcaps_get(): could not fetch xcap document
>
> What can I do to solve this issue. This is preventing contacts from 
> being retrieved or added once the first contact is stored.
>
> My event-route looks like this (WITH_XCAPSRV is defined elsewhere in 
> the configuration):
>
> #!ifdef WITH_XHTTP
> event_route[xhttp:request] {
> #!ifdef WITH_XHTTP_RPC
>        $var(xhttp_rpc_root) = $(hu{s.substr,0,9});
>        if ($var(xhttp_rpc_root) == "/http_rpc") {
>                dispatch_xhttp_rpc();
>        }
> #!endif
> #!ifdef WITH_XHTTP_PI
>        $var(xhttp_rpc_root) = $(hu{s.substr,0,8});
>        if ($var(xhttp_rpc_root) == "/http_pi") {
>                dispatch_xhttp_pi();
>        }
> #!endif
> #!ifdef WITH_XCAPSRV
>     if ($hu =~ "^/xcap-root/") {
>         route(XCAPSRV);
>     }
> #!endif
>
>         set_reply_close();
>         set_reply_no_connect();
>
> #        if ($Rp != 80
> ##!ifdef WITH_TLS
> #            && $Rp != 443
> ##!endif
> #        ) {
> #
> #                xlog("L_WARN", "HTTP request received on $Rp\n");
> #                xhttp_reply("403", "Forbidden", "text/html", 
> "Forbidden");
> #                exit;
> #        }
>
>         xlog("L_DBG", "HTTP Request Received\n");
>
>         if ($hdr(Upgrade)=~"websocket"
>                         && $hdr(Connection)=~"Upgrade"
>                         && $rm=~"GET") {
>
>                 # Validate Host - make sure the client is using the 
> correct
>                 # alias for WebSockets
>                 if ($hdr(Host) == $null || !is_myself("sip:" + 
> $hdr(Host))) {
>                         xlog("L_WARN", "Bad host $hdr(Host)\n");
>                         xhttp_reply("403", "Forbidden", "", "");
>                         exit;
>                 }
>
>                 # Optional... validate Origin - make sure the client 
> is from an
>                 # authorised website.  For example,
>                 #
>                 # if ($hdr(Origin) != "http://communicator.MY_DOMAIN"
>                 #     && $hdr(Origin) != 
> "https://communicator.MY_DOMAIN") {
>                 #       xlog("L_WARN", "Unauthorised client 
> $hdr(Origin)\n");
>                 #       xhttp_reply("403", "Forbidden", "", "");
>                 #       exit;
>                 # }
>
>                 # Optional... perform HTTP authentication
>
>                 # ws_handle_handshake() exits (no further 
> configuration file
>                 # processing of the request) when complete.
>                 if (ws_handle_handshake())
>         {
>             # Optional... cache some information about the
>             # successful connection
>             exit;
>         }
>         }
>
>
>
>        xhttp_reply("200", "OK", "text/html",
>                "<html><body>Wrong URL $hu</body></html>");
> }
> #!endif
>
> #!ifdef WITH_XCAPSRV
> route[XCAPSRV] {
>     xlog("L_ALERT", "===== xhttp: request [$rv] $rm => $hu\n");
>
>     # Remove port specification from Host header and use as 
> authentication domain
>     $var(http_domain) = $(hdr(Host){s.select,0,:});
>     if (!www_authorize("$var(http_domain)", "subscriber")) {
>         www_challenge("$var(http_domain)", "0");
>         exit;
>     }
>
>     set_reply_close();
>     set_reply_no_connect();
>
>     if ($hu=~"^/xcap-root/oma_status-icon/users/.*/.*$")
>         $var(doc_uri) = 
> $(hu{re.subst,/(^\/xcap-root\/)oma_status-icon(\/users\/.*\/).*$/\1org.openmobilealliance.pres-content\2oma_status-icon\/preseImage/});
>     else
>         $var(doc_uri) = $hu;
>
>     # xcap ops
>     $xcapuri(u=>data) = $var(doc_uri);
>     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;
>     xlog("L_ALERT", "===== xhttp: $xcapuri(u=>auid) : 
> $xcapuri(u=>xuid)\n");
>
>     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>
>         <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-content</auid>
>         <auid>org.openmobilealliance.search</auid>
> <auid>org.openmobilealliance.xcap-directory</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>
>         <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 ($au != $(var(uri){uri.user})) {
>         xhttp_reply("403", "Forbidden", "text/html", 
> "<html><body>$si:$sp</body></html>");
>         exit;
>     }
>
>     switch($rm) {
>     case "PUT":
>         xcaps_put("$var(uri)", "$var(doc_uri)", "$rb");
>         if ($xcapuri(u=>auid) =~ "pres-rules") {
>             pres_update_watchers("$var(uri)", "presence");
>             pres_refresh_watchers("$var(uri)", "presence", 1);
> #        } else if ($xcapuri(u=>auid) =~ "rls-services" || 
> $xcapuri(u=>auid) =~ "resource-lists") {
> #            rls_update_subs("$var(uri)", "presence");
>         } 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":
>         xcaps_get("$var(uri)", "$var(doc_uri)");
>         exit;
>         break;
>     case "DELETE":
>         xcaps_del("$var(uri)", "$var(doc_uri)");
>         if ($xcapuri(u=>auid) =~ "pres-rules") {
>             pres_update_watchers("$var(uri)", "presence");
>             pres_refresh_watchers("$var(uri)", "presence", 1);
> #        } else if ($xcapuri(u=>auid) =~ "rls-services" || 
> $xcapuri(u=>auid) =~ "resource-lists") {
> #            rls_update_subs("$var(uri)", "presence");
>         } 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;
>     }
>
>     # other http requests
>     xhttp_reply("404", "Not Found", "", "");
>     exit;
> }
> #!endif
>
>
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

-- 
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda




More information about the sr-users mailing list