[Kamailio-Users] About http_query function and HTTP replies > 400

Iñaki Baz Castillo ibc at aliax.net
Mon Nov 24 17:29:38 CET 2008


Hi, I see in the code:

-----------
    curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &stat);
    if ((stat >= 200) && (stat < 400)) {
	at = index(stream, (char)10);  /* search for line feed */
	if (at == NULL) {
	    at = stream;  /* set empty string */
	}
	val.rs.s = stream;
	val.rs.len = at - stream;
	val.flags = PV_VAL_STR;
	dst = (pv_spec_t *)_dst;
	dst->setf(_m, &dst->pvp, (int)EQ_T, &val);
    }
	
    return stat;
-----------

So if the reply is > 400 then the function doesn't extract the first line of 
the body.

While it makes sense (if a web server returns 404 it means that the page has 
not been found so the body doesn't matter at all). But I'm trying to 
use "http_query" as a logic mechanism:

- alice calls bob.

- Kamailio asks a http server a query:
    http://web_server/check_permission.php?fu=alice&ru=bob

- The web server runs its own logic (asking to BD and so) and decides that 
alice is not allowed to call bob. But bob wants to "explain" alice why he 
doesn't accept calls from him, so the web server replies:

       -----------------
       HTTP/1.1 403 Forbidden
       
       Alice, you are very boring and I don't accept more calls from you
       -----------------

- So the $retcode of "http_query" would be 403 but we are also interested in 
the body (stored in $var(reply_http_query)) since we could generate a 
response like:

  sl_send_reply(403, "$var(reply_http_query)");


Doesn't it make sense?

Also, web server could reply "HTTP/1.1 302 Moved temporaly" being the first 
line of the body the new SIP URI to contact.


Opinions?


BTW it could be really great if the reply body could be more complete, for 
example storing more than one line (various variables) and so...


Regards.






-- 
Iñaki Baz Castillo




More information about the Users mailing list