Module: sip-router
Branch: master
Commit: 8ab4daa7f13a70f1fb77d7a98f11f7290a42c321
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8ab4daa…
Author: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Date: Thu Jul 12 21:50:00 2012 +0100
modules/ipops: Corrected is_in_subnet() exported function and added is_ip to module C API
- Fixes and enhancements by Hugh Waite @ Crocodile RCS
---
modules/ipops/api.c | 12 ++++++++++++
modules/ipops/api.h | 3 +++
modules/ipops/ipops_mod.c | 2 +-
3 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/modules/ipops/api.c b/modules/ipops/api.c
index 8730be9..8f5a07c 100644
--- a/modules/ipops/api.c
+++ b/modules/ipops/api.c
@@ -120,6 +120,17 @@ int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const
ip2)
/**
*
*/
+int ipopsapi_is_ip(const str * const ip)
+{
+ if (ip_parser_execute(ip->s, ip->len) != ip_type_error)
+ return 1;
+ else
+ return -1;
+}
+
+/**
+ *
+ */
int bind_ipops(ipops_api_t* api)
{
if (!api) {
@@ -128,6 +139,7 @@ int bind_ipops(ipops_api_t* api)
}
api->compare_ips = ipopsapi_compare_ips;
api->ip_is_in_subnet = ipopsapi_ip_is_in_subnet;
+ api->is_ip = ipopsapi_is_ip;
return 0;
}
diff --git a/modules/ipops/api.h b/modules/ipops/api.h
index aa15dca..2a86649 100644
--- a/modules/ipops/api.h
+++ b/modules/ipops/api.h
@@ -36,12 +36,15 @@ int ipopsapi_compare_ips(const str *const ip1, const str *const ip2);
typedef int (*ip_is_in_subnet_f)(const str *const, const str *const);
int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2);
+typedef int (*is_ip_f)(const str * const ip);
+int ipopsapi_is_ip(const str * const ip);
/**
* @brief IPOPS API structure
*/
typedef struct ipops_api {
compare_ips_f compare_ips;
ip_is_in_subnet_f ip_is_in_subnet;
+ is_ip_f is_ip;
} ipops_api_t;
typedef int (*bind_ipops_f)(ipops_api_t* api);
diff --git a/modules/ipops/ipops_mod.c b/modules/ipops/ipops_mod.c
index 402a8a4..164177b 100644
--- a/modules/ipops/ipops_mod.c
+++ b/modules/ipops/ipops_mod.c
@@ -108,7 +108,7 @@ static cmd_export_t cmds[] =
REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
{ "is_ip_rfc1918", (cmd_function)w_is_ip_rfc1918, 1, fixup_spve_null, 0,
REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
- { "is_in_subnet", (cmd_function)w_ip_is_in_subnet, 2, fixup_spve_null, 0,
+ { "is_in_subnet", (cmd_function)w_ip_is_in_subnet, 2, fixup_spve_spve, 0,
REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
{ "bind_ipops", (cmd_function)bind_ipops, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0 }