Module: sip-router Branch: master Commit: 1dfc197d38672eac079ad2a93238cb5642c6c253 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1dfc197d...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Thu Aug 27 11:22:10 2009 +0300
core: callback function support for myself check
- modules can register callback functions for myself check condition - domain module is one candidate, resulting in coherent handling of local domains via check myself operation - callback functions must have same prototype and return codes as check_self(...) function from core
---
forward.c | 40 +++++++++++++++++++++++++++++++++++++++- forward.h | 3 +++ 2 files changed, 42 insertions(+), 1 deletions(-)
diff --git a/forward.c b/forward.c index 3080b1d..dea7584 100644 --- a/forward.c +++ b/forward.c @@ -301,7 +301,44 @@ not_forced: return send_sock; }
+static struct _check_self_func { + check_self_f fself; + struct _check_self_func *next; +} *_check_self_func_list = NULL; + +/* register a function to be called when matching for myself + * - return 0 on success, -1 on error + * - f must have same prototype as check_self() and return same kind of values + */ +int register_check_self_func(check_self_f f) +{ + struct _check_self_func *nf = 0; + nf=(struct _check_self_func*)pkg_malloc(sizeof(struct _check_self_func)); + if(nf==0) + { + LM_ERR("no more pkg\n"); + return -1; + } + nf->fself = f; + nf->next = _check_self_func_list; + _check_self_func_list = nf; + return 0; +}
+/* run registered check self functions + * returns 1 if true, 0 if false + */ +int run_check_self_func(str* host, unsigned short port, unsigned short proto) +{ + struct _check_self_func *sf = 0; + + if(_check_self_func_list==NULL) + return 0; + for(sf=_check_self_func_list; sf; sf=sf->next) + if(sf->fself(host, port, proto)==1) + return 1; + return 0; +}
/* checks if the proto: host:port is one of the address we listen on; * if port==0, the port number is ignored @@ -316,7 +353,8 @@ int check_self(str* host, unsigned short port, unsigned short proto) /* try to look into the aliases*/ if (grep_aliases(host->s, host->len, port, proto)==0){ DBG("check_self: host != me\n"); - return 0; + return (_check_self_func_list==NULL)?0:run_check_self_func(host, + port, proto); } found: return 1; diff --git a/forward.h b/forward.h index 0a5750a..12ce134 100644 --- a/forward.h +++ b/forward.h @@ -83,6 +83,9 @@ inline static struct socket_info* get_send_socket(struct sip_msg* msg,
struct socket_info* get_out_socket(union sockaddr_union* to, int proto); +typedef int (*check_self_f)(str* host, unsigned short port, + unsigned short proto); +int register_check_self_func(check_self_f f); int check_self(str* host, unsigned short port, unsigned short proto); int check_self_port(unsigned short port, unsigned short proto); int forward_request( struct sip_msg* msg, str* dst, unsigned short port,