Module: sip-router Branch: master Commit: de490ed1559028ba737b0dea81eaba50a6e72852 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=de490ed1...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Sun May 16 19:25:13 2010 +0300
modules/lcr: caller_uri argument of load_gws() is now optional - If not given, it defaults to empty string.
---
modules/lcr/README | 11 +++++---- modules/lcr/doc/lcr_admin.xml | 5 ++- modules/lcr/lcr_mod.c | 44 +++++++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/modules/lcr/README b/modules/lcr/README index ce1ffb4..2e5a025 100644 --- a/modules/lcr/README +++ b/modules/lcr/README @@ -59,7 +59,7 @@ Juha Heinanen
4. Exported Functions
- 4.1. load_gws(lcr_id, caller_uri) + 4.1. load_gws(lcr_id[, caller_uri]) 4.2. next_gw() 4.3. defunct_gw(period) 4.4. from_gw(lcr_id [, ip_addr]) @@ -162,7 +162,7 @@ Chapter 1. Admin Guide
4. Exported Functions
- 4.1. load_gws(lcr_id, caller_uri) + 4.1. load_gws(lcr_id[, caller_uri]) 4.2. next_gw() 4.3. defunct_gw(period) 4.4. from_gw(lcr_id [, ip_addr]) @@ -625,7 +625,7 @@ modparam("lcr", "fetch_rows", 3000)
4. Exported Functions
- 4.1. load_gws(lcr_id, caller_uri) + 4.1. load_gws(lcr_id[, caller_uri]) 4.2. next_gw() 4.3. defunct_gw(period) 4.4. from_gw(lcr_id [, ip_addr]) @@ -633,13 +633,14 @@ modparam("lcr", "fetch_rows", 3000) 4.6. to_gw(lcr_id [, ip_addr]) 4.7. to_any_gw([ip_addr])
-4.1. load_gws(lcr_id, caller_uri) +4.1. load_gws(lcr_id[, caller_uri])
Loads URI schemes, IP addresses, hostnames, ports, params, and transports of matching gateways to gw_uri_avp (see Overview section). Argument lcr_id specifies the used LCR instance. It can be an integer or a pseudo variable containing an integer value. Caller's URI is given - by caller_uri argument, which must be a pseudo variable. + by caller_uri argument, which must be a pseudo variable. If caller_uri + argument is omitted, it defaults to empty string.
Returns 1 if at least one matching gateway was found, 2 if no matching gateways was found, and -1 on error. diff --git a/modules/lcr/doc/lcr_admin.xml b/modules/lcr/doc/lcr_admin.xml index 04ba61c..55d5cfd 100644 --- a/modules/lcr/doc/lcr_admin.xml +++ b/modules/lcr/doc/lcr_admin.xml @@ -765,7 +765,7 @@ modparam("lcr", "fetch_rows", 3000) <title>Exported Functions</title> <section> <title> - <function moreinfo="none">load_gws(lcr_id, caller_uri)</function> + <function moreinfo="none">load_gws(lcr_id[, caller_uri])</function> </title> <para> Loads URI schemes, IP addresses, hostnames, ports, @@ -775,7 +775,8 @@ modparam("lcr", "fetch_rows", 3000) LCR instance. It can be an integer or a pseudo variable containing an integer value. Caller's URI is given by caller_uri argument, which - must be a pseudo variable. + must be a pseudo variable. If caller_uri argument is + omitted, it defaults to empty string. </para> <para> Returns 1 if at least one matching gateway was found, 2 diff --git a/modules/lcr/lcr_mod.c b/modules/lcr/lcr_mod.c index 13fb7e0..add81d9 100644 --- a/modules/lcr/lcr_mod.c +++ b/modules/lcr/lcr_mod.c @@ -246,7 +246,8 @@ struct lcr_info ***lcrtp = (struct lcr_info ***)NULL; /* * Functions that are defined later */ -static int load_gws(struct sip_msg* _m, char* _s1, char* _s2); +static int load_gws_1(struct sip_msg* _m, char* _s1, char* _s2); +static int load_gws_2(struct sip_msg* _m, char* _s1, char* _s2); static int next_gw(struct sip_msg* _m, char* _s1, char* _s2); static int defunct_gw(struct sip_msg* _m, char* _s1, char* _s2); static int from_gw_1(struct sip_msg* _m, char* _s1, char* _s2); @@ -262,7 +263,9 @@ static int to_any_gw_1(struct sip_msg* _m, char* _s1, char* _s2); * Exported functions */ static cmd_export_t cmds[] = { - {"load_gws", (cmd_function)load_gws, 2, fixup_igp_pvar, + {"load_gws", (cmd_function)load_gws_1, 1, fixup_igp_null, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"load_gws", (cmd_function)load_gws_2, 2, fixup_igp_pvar, fixup_free_igp_pvar, REQUEST_ROUTE | FAILURE_ROUTE}, {"next_gw", (cmd_function)next_gw, 0, 0, 0, REQUEST_ROUTE | FAILURE_ROUTE}, @@ -1536,7 +1539,7 @@ void add_gws_into_avps(struct gw_info *gws, struct matched_gw_info *matched_gws, /* * Load info of matching GWs into gw_uri_avps */ -static int load_gws(struct sip_msg* _m, char *_lcr_id, char *_from_uri) +static int load_gws(struct sip_msg* _m, fparam_t *_lcr_id, fparam_t *_from_uri) { str ruri_user, from_uri; int i, j, lcr_id; @@ -1548,7 +1551,7 @@ static int load_gws(struct sip_msg* _m, char *_lcr_id, char *_from_uri) char *hostname;
/* Get and check parameter values */ - if (get_int_fparam(&lcr_id, _m, (fparam_t *)_lcr_id) != 0) { + if (get_int_fparam(&lcr_id, _m, _lcr_id) != 0) { LM_ERR("no lcr_id param value\n"); return -1; } @@ -1556,14 +1559,18 @@ static int load_gws(struct sip_msg* _m, char *_lcr_id, char *_from_uri) LM_ERR("invalid lcr_id parameter value %d\n", lcr_id); return -1; } - - if (get_str_fparam(&from_uri, _m, (fparam_t *)_from_uri) != 0) { - LM_ERR("no from_uri parameter value\n"); - return -1; - } - if (from_uri.len == 0) { - LM_ERR("empry from_uri param value\n"); - return -1; + if (_from_uri) { + if (get_str_fparam(&from_uri, _m, _from_uri) != 0) { + LM_ERR("no from_uri parameter value\n"); + return -1; + } + if (from_uri.len == 0) { + LM_ERR("empty from_uri parameter value\n"); + return -1; + } + } else { + from_uri.len = 0; + from_uri.s = (char *)0; }
/* Use gws and lcr rules with index lcr_id */ @@ -1677,6 +1684,18 @@ static int load_gws(struct sip_msg* _m, char *_lcr_id, char *_from_uri) }
+static int load_gws_1(struct sip_msg* _m, char *_lcr_id, char *_s2) +{ + return load_gws(_m, (fparam_t *)_lcr_id, (fparam_t *)0); +} + + +static int load_gws_2(struct sip_msg* _m, char *_lcr_id, char *_from_uri) +{ + return load_gws(_m, (fparam_t *)_lcr_id, (fparam_t *)_from_uri); +} + + /* Generate Request-URI and Destination URI */ static int generate_uris(char *r_uri, str *r_uri_user, unsigned int *r_uri_len, char *dst_uri, unsigned int *dst_uri_len, @@ -1938,6 +1957,7 @@ static int next_gw(struct sip_msg* _m, char* _s1, char* _s2) if (dst_uri_len > 0) { uri_str.s = dst_uri; uri_str.len = dst_uri_len; + LM_DBG("setting du to <%.*s>\n", uri_str.len, uri_str.s); rval = set_dst_uri(_m, &uri_str); if (rval != 0) { LM_ERR("calling do_action failed with return value <%d>\n", rval);