Hi, Kamailio uses the following syntax for =~ operator:
if ( $rU =~ "^2[0-9]{2}$" ) {
Reading the SR commits, it seems that SR will support regular
expressions in 'switch' stament:
switch ($rU) {
case 200: # INTEGER
[...]
case "alice": # STRING
[...]
case /2[0-9]{2}/: # REGULAR EXPRESSION
[...]
}
If the above is correct, it requires two different syntax for a
regular expression:
a) =~ "^2[0-9]{2}$"
b) case /2[0-9]{2}/:
Wouldn't make sense to have an unique syntax for regular expressions?
IMHO the best one is:
/2[0-9]{2}/
so =~ would use:
if ( $rU =~ /^2[0-9]{2}$/ ) {
Opinions? Regards.
--
Iñaki Baz Castillo
<ibc(a)aliax.net>
Hello,
working to integrate the PV module I reached the AVPs and after a short
analyze I wonder (and ask you) whether you should drop the naming scheme
we have in Kamailio (integer id and string name) and stick to string
names all the time. ser seems to use mostly that although looks like
support for ID is still there, but I cannot see how they can be used
with the naming scheme in config (e.g., is it possible to have $f.i:34
in config to refer to avp with id 34?).
The benefits I see:
- complexity in dealing with integer id or string name
- avp name aliases removed
Note that even for string-named AVPs there is an integer id computed and
used in comparisons to speed up.
Jan in an email some time ago mentioned that no performance penalty
could be observed. I pasted most of the content of Jan's email about ser
avps at:
http://sip-router.org/wiki/devel/avps-ser
Looking at the code where there are lot of IF name is string or integer,
I wonder if really worth the complexity. Today we have lot of other
variables for quick and shared-memory operations ($var(...), $shv(...),
$sht(...), $dbr(...) and latest $mct(...)), avps not being anymore used
for everywhere.
Drawback is the naming scheme backward compatibility. We can treat
"i:20" simply as string or throw error at startup (I prefer the second
because is cleaner in long time).
Opinions?
Cheers,
Daniel
--
Daniel-Constantin Mierla
http://www.asipto.com
Module: sip-router
Branch: master
Commit: f971c09ff103cfe61bbf8bf930905432ca528b95
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f971c09…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Mon Mar 23 15:04:41 2009 +0100
Kamailio compatiblity: Added pointer to a free function to tm callbacks
This patch adds a new pointer to the tm_callback structure. The
parameter contains pointer to a function which, if not NULL, will be
called to dispose the callback parameter when it is not needed anymore.
This is useful if the parameter given ti a transaction callback is a
complex data structure of it is stored on the heap and the memory needs
to be free when the corresponding transaction is being destroyed.
Patch contributed by Ovidiu Sas.
---
modules/tm/h_table.c | 3 +++
modules/tm/t_hooks.c | 9 ++++++---
modules/tm/t_hooks.h | 13 ++++++++++---
modules/tm/uac.c | 3 ++-
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/modules/tm/h_table.c b/modules/tm/h_table.c
index 6b38496..11fb1a8 100644
--- a/modules/tm/h_table.c
+++ b/modules/tm/h_table.c
@@ -141,6 +141,9 @@ void free_cell( struct cell* dead_cell )
for( cbs=(struct tm_callback*)dead_cell->tmcb_hl.first ; cbs ; ) {
cbs_tmp = cbs;
cbs = cbs->next;
+ if (cbs_tmp->release) {
+ cbs_tmp->release(cbs_tmp->param);
+ }
shm_free_unsafe( cbs_tmp );
}
diff --git a/modules/tm/t_hooks.c b/modules/tm/t_hooks.c
index 788172a..6e149ea 100644
--- a/modules/tm/t_hooks.c
+++ b/modules/tm/t_hooks.c
@@ -117,7 +117,8 @@ void destroy_tmcb_lists()
/* lockless insert: should be always safe */
int insert_tmcb(struct tmcb_head_list *cb_list, int types,
- transaction_cb f, void *param )
+ transaction_cb f, void *param,
+ release_tmcb_param rel_func)
{
struct tm_callback *cbp;
struct tm_callback *old;
@@ -133,6 +134,7 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
/* ... and fill it up */
cbp->callback = f;
cbp->param = param;
+ cbp->release = rel_func;
cbp->types = types;
cbp->id=0;
old=(struct tm_callback*)cb_list->first;
@@ -164,7 +166,8 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
* from mod_init (before forking!).
*/
int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
- transaction_cb f, void *param )
+ transaction_cb f, void *param,
+ release_tmcb_param rel_func)
{
//struct cell* t;
struct tmcb_head_list *cb_list;
@@ -217,7 +220,7 @@ int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
cb_list = &(t->tmcb_hl);
}
- return insert_tmcb( cb_list, types, f, param );
+ return insert_tmcb( cb_list, types, f, param, rel_func );
}
diff --git a/modules/tm/t_hooks.h b/modules/tm/t_hooks.h
index 38721fb..b396737 100644
--- a/modules/tm/t_hooks.h
+++ b/modules/tm/t_hooks.h
@@ -385,9 +385,12 @@ do{ \
/* callback function prototype */
typedef void (transaction_cb) (struct cell* t, int type, struct tmcb_params*);
+/*! \brief function to release the callback param */
+typedef void (release_tmcb_param) (void* param);
/* register callback function prototype */
typedef int (*register_tmcb_f)(struct sip_msg* p_msg, struct cell *t,
- int cb_types, transaction_cb f, void *param);
+ int cb_types, transaction_cb f, void *param,
+ release_tmcb_param func);
struct tm_callback {
@@ -395,6 +398,8 @@ struct tm_callback {
int types; /* types of events that trigger the callback*/
transaction_cb* callback; /* callback function */
void *param; /* param to be passed to callback function */
+ release_tmcb_param* release; /**< Function to release the callback param
+ * when the callback is deleted */
struct tm_callback* next;
};
@@ -423,11 +428,13 @@ void destroy_tmcb_lists();
/* register a callback for several types of events */
int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
- transaction_cb f, void *param );
+ transaction_cb f, void *param,
+ release_tmcb_param rel_func);
/* inserts a callback into the a callback list */
int insert_tmcb(struct tmcb_head_list *cb_list, int types,
- transaction_cb f, void *param );
+ transaction_cb f, void *param,
+ release_tmcb_param rel_func);
/* run all transaction callbacks for an event type */
void run_trans_callbacks( int type , struct cell *trans,
diff --git a/modules/tm/uac.c b/modules/tm/uac.c
index 50089c0..6dfd0fc 100644
--- a/modules/tm/uac.c
+++ b/modules/tm/uac.c
@@ -319,7 +319,8 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
/* Register the callbacks after everything is successful and nothing can fail.
Otherwise the callback parameter would be freed twise, once from TMCB_DESTROY,
and again because of the negative return code. */
- if(uac_r->cb && insert_tmcb(&(new_cell->tmcb_hl), uac_r->cb_flags, *(uac_r->cb), uac_r->cbp)!=1){
+ if(uac_r->cb && insert_tmcb(&(new_cell->tmcb_hl), uac_r->cb_flags,
+ *(uac_r->cb), uac_r->cbp, NULL)!=1){
ret=E_OUT_OF_MEM;
LOG(L_ERR, "t_uac: short of tmcb shmem\n");
goto error1;