Module: sip-router Branch: master Commit: c437c250b34ad052ffd9fa289e1480bdc04f8585 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c437c250...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Sat Oct 16 16:42:44 2010 +0300
modules/utils: added is_int() function - added is_int() function that checks if its pvar argument contains integer value. better place would be core, but that is out of my reach.
---
modules/utils/README | 52 +++++++++++++++++++++++++------------ modules/utils/doc/utils_admin.xml | 22 +++++++++++++++ modules/utils/functions.c | 18 +++++++++++++ modules/utils/functions.h | 5 +++ modules/utils/utils.c | 2 + 5 files changed, 82 insertions(+), 17 deletions(-)
diff --git a/modules/utils/README b/modules/utils/README index d818238..aaf7d35 100644 --- a/modules/utils/README +++ b/modules/utils/README @@ -4,7 +4,7 @@ Juha Heinanen
TutPro Inc.
- Copyright � 2008 Juha Heinanen + Copyright © 2008-2009 Juha Heinanen __________________________________________________________________
Table of Contents @@ -28,6 +28,7 @@ Juha Heinanen
4.1. http_query(url, result) 4.2. xcap_auth_status(watcher_uri, presentity_uri) + 4.3. is_int(pvar)
5. MI Commands
@@ -46,10 +47,11 @@ Juha Heinanen 1.4. Set xcap_table parameter 1.5. http_query() usage 1.6. xcap_auth_status() usage - 1.7. forward_list usage - 1.8. forward_switch usage - 1.9. forward_filter usage - 1.10. forward_proxy usage + 1.7. is_int() usage + 1.8. forward_list usage + 1.9. forward_switch usage + 1.10. forward_filter usage + 1.11. forward_proxy usage
Chapter 1. Admin Guide
@@ -72,6 +74,7 @@ Chapter 1. Admin Guide
4.1. http_query(url, result) 4.2. xcap_auth_status(watcher_uri, presentity_uri) + 4.3. is_int(pvar)
5. MI Commands
@@ -98,7 +101,7 @@ Chapter 1. Admin Guide deactivated.
Function xcap_auth_status can be used to check from presence server - database, if watcher is authorized to subscribe event "presence" of + database, if watcher is authorized to subscribe event “presence” of presentity.
2. Dependencies @@ -109,7 +112,7 @@ Chapter 1. Admin Guide 2.1. Kamailio Modules
The following modules must be loaded before this module: - * None. + * a database module if xcap_auth_status function is enabled.
2.2. External Libraries or Applications
@@ -128,7 +131,7 @@ Chapter 1. Admin Guide
Defines in seconds how long Kamailio waits response from HTTP server.
- Default value is "4". + Default value is null, i.e., xcap_auth_status function is disabled.
Example 1.1. Set http_query_timeout parameter ... @@ -139,7 +142,7 @@ modparam("utils", "http_query_timeout", 2)
Defines if the forwarding callback should be installed.
- Default value is "0". + Default value is “0”.
Example 1.2. Set forward_active parameter ... @@ -162,7 +165,7 @@ modparam("utils", "pres_db_url", "mysql://foo:secret@localhost/pres")
Defines name of xcap table in presence server database.
- Default value is "xcap". + Default value is “xcap”.
Example 1.4. Set xcap_table parameter ... @@ -173,14 +176,15 @@ modparam("utils", "xcap_table", "pres_xcap")
4.1. http_query(url, result) 4.2. xcap_auth_status(watcher_uri, presentity_uri) + 4.3. is_int(pvar)
4.1. http_query(url, result)
- Sends HTTP GET request according to URL given in "url" parameter, which + Sends HTTP GET request according to URL given in “url” parameter, which is a string that may contain pseudo variables.
If HTTP server returns a class 2xx or 3xx reply, first line of reply's - body (if any) is stored in "result" parameter, which must be a writable + body (if any) is stored in “result” parameter, which must be a writable pseudo variable.
Function returns reply code of HTTP reply or -1 if something went @@ -202,7 +206,7 @@ switch ($retcode) { 4.2. xcap_auth_status(watcher_uri, presentity_uri)
Function checks from presence server database if watcher is authorized - to subscribe event "presence" of presentity. Sphere checking is not + to subscribe event “presence” of presentity. Sphere checking is not included.
Both watcher_uri and presentity_uri are pseudo variables. Function @@ -225,6 +229,20 @@ if (method=="MESSAGE") { } ...
+4.3. is_int(pvar) + + Function checks if pvar argument contains integer value and returns 1 + if it does and -1 otherwise. + + Function can be used from all kinds of routes. + + Example 1.7. is_int() usage +... +if (is_int("$var(foo)")) { + xlog("L_INFO", "variable foo contains integer value\n"); +} +... + 5. MI Commands
5.1. forward_list @@ -238,7 +256,7 @@ if (method=="MESSAGE") {
No parameters.
- Example 1.7. forward_list usage + Example 1.8. forward_list usage ... kamctl fifo forward_list id switch filter proxy @@ -251,7 +269,7 @@ id switch filter proxy The syntax of this configuration string is described in 1.6. (switch_setting_list).
- Example 1.8. forward_switch usage + Example 1.9. forward_switch usage ... kamctl fifo sp_forward_switch 0=on ... @@ -270,7 +288,7 @@ kamctl fifo sp_forward_switch 0=on The syntax of this configuration string is described in 1.6. (filter_setting_list).
- Example 1.9. forward_filter usage + Example 1.10. forward_filter usage ... kamctl fifo sp_forward_filter 0=REGISTER:INVITE ... @@ -283,7 +301,7 @@ kamctl fifo sp_forward_filter 0=REGISTER:INVITE switch). The syntax of this configuration string is described in 1.6. (proxy_setting_list).
- Example 1.10. forward_proxy usage + Example 1.11. forward_proxy usage ... kamctl fifo sp_forward_proxy 0=host-c.domain-c:5060 ... diff --git a/modules/utils/doc/utils_admin.xml b/modules/utils/doc/utils_admin.xml index f683f51..23527d0 100644 --- a/modules/utils/doc/utils_admin.xml +++ b/modules/utils/doc/utils_admin.xml @@ -229,6 +229,28 @@ if (method=="MESSAGE") { </programlisting> </example> </section> + <section> + <title> + <function moreinfo="none">is_int(pvar)</function> + </title> + <para> + Function checks if pvar argument contains integer value + and returns 1 if it does and -1 otherwise. + </para> + <para> + Function can be used from all kinds of routes. + </para> + <example> + <title><function>is_int()</function> usage</title> + <programlisting format="linespecific"> +... +if (is_int("$var(foo)")) { + xlog("L_INFO", "variable foo contains integer value\n"); +} +... + </programlisting> + </example> + </section> </section> <section> diff --git a/modules/utils/functions.c b/modules/utils/functions.c index aadfdd5..878073a 100644 --- a/modules/utils/functions.c +++ b/modules/utils/functions.c @@ -139,3 +139,21 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst) return stat; } + + +/* + * Checks if pvar argument contains int value + */ +int is_int(struct sip_msg* _m, char* _pvar, char* _s2) +{ + pv_spec_t *pvar_sp; + pv_value_t pv_val; + + pvar_sp = (pv_spec_t *)_pvar; + + if (pvar_sp && (pv_get_spec_value(_m, pvar_sp, &pv_val) == 0)) { + return (pv_val.flags & PV_VAL_INT)?1:-1; + } + + return -1; +} diff --git a/modules/utils/functions.h b/modules/utils/functions.h index 5e666f9..df34211 100644 --- a/modules/utils/functions.h +++ b/modules/utils/functions.h @@ -42,4 +42,9 @@ int http_query(struct sip_msg* _m, char* _page, char* _params, char* _dst);
+/* + * Checks if pvar argument contains int value + */ +int is_int(struct sip_msg* _m, char* _pvar, char* _s2); + #endif /* UTILS_FUNCTIONS_H */ diff --git a/modules/utils/utils.c b/modules/utils/utils.c index 86f71ea..b5fa5b1 100644 --- a/modules/utils/utils.c +++ b/modules/utils/utils.c @@ -101,6 +101,8 @@ static cmd_export_t cmds[] = { REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, {"xcap_auth_status", (cmd_function)xcap_auth_status, 2, fixup_pvar_pvar, fixup_free_pvar_pvar, REQUEST_ROUTE}, + {"is_int", (cmd_function)is_int, 1, fixup_pvar_null, fixup_free_pvar_null, + REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, {0, 0, 0, 0, 0, 0} };