The original (kamailio) version of acc module accesed the flags in sip_msg structure directly through a few macros declared in this module. In SER we introduced the concept of named flags and created a set of functions that can be used to access and modify the flags.
First of all we need to replace calls to flag_idx2mask from mod_init function, this function does not exist in the sip-router core because all flag related functions there get the index of the flag as parameter. This means that we do not have to convert values of flag-related modparams in this module, all we have to do is check whether they have a valid value. This is done using flag_is_in_range. But because the module uses -1 to denote that a particular flag is not set, we need only need to call that function if the flag is not set to -1.
After that we need to update is_acc_flag_set and reset_acc_flag macros to call functions from flags.h, instead of modifying the flags directly. But again, the functions from flags.h should only be called if the particular flag is not set to -1.
If we also wanted to add support for named flags then we would need to update the definition of modparams holding the value of flags in this module. This is not done in this patch. We can do it later after we merge acc modules from ser and kamailio. --- modules/acc/acc_logic.c | 4 ++-- modules/acc/acc_mod.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/modules/acc/acc_logic.c b/modules/acc/acc_logic.c index e92d827..90426a5 100644 --- a/modules/acc/acc_logic.c +++ b/modules/acc/acc_logic.c @@ -55,8 +55,8 @@ extern struct rr_binds rrb; struct acc_enviroment acc_env;
-#define is_acc_flag_set(_rq,_flag) (((_rq)->flags)&(_flag)) -#define reset_acc_flag(_rq,_flag) (_rq)->flags &= ~(_flag) +#define is_acc_flag_set(_rq,_flag) (((_flag) != -1) && (isflagset((_rq), (_flag)) == 1)) +#define reset_acc_flag(_rq,_flag) (resetflag((_rq), (_flag)))
#define is_failed_acc_on(_rq) is_acc_flag_set(_rq,failed_transaction_flag)
diff --git a/modules/acc/acc_mod.c b/modules/acc/acc_mod.c index a9da577..17f159a 100644 --- a/modules/acc/acc_mod.c +++ b/modules/acc/acc_mod.c @@ -377,8 +377,11 @@ static int mod_init( void )
/* ----------- GENERIC INIT SECTION ----------- */
- if (flag_idx2mask(&failed_transaction_flag)<0) + if ((failed_transaction_flag != -1) && + !flag_in_range(failed_transaction_flag)) { + LM_ERR("failed_transaction_flag set to invalid value\n"); return -1; + }
/* load the TM API */ if (load_tm_api(&tmb)!=0) { @@ -423,11 +426,15 @@ static int mod_init( void ) return -1; }
- if (flag_idx2mask(&log_flag)<0) + if ((log_flag != -1) && !flag_in_range(log_flag)) { + LM_ERR("log_flag set to invalid value\n"); return -1; + }
- if (flag_idx2mask(&log_missed_flag)<0) + if ((log_missed_flag != -1) && !flag_in_range(log_missed_flag)) { + LM_ERR("log_missed_flag set to invalid value\n"); return -1; + }
acc_log_init();
@@ -445,10 +452,16 @@ static int mod_init( void ) return -1; } /* fix the flags */ - if (flag_idx2mask(&db_flag)<0) + + if ((db_flag != -1) && !flag_in_range(db_flag)) { + LM_ERR("db_flag set to invalid value\n"); return -1; - if (flag_idx2mask(&db_missed_flag)<0) + } + + if ((db_missed_flag != -1) && !flag_in_range(db_missed_flag)) { + LM_ERR("db_missed_flag set to invalid value\n"); return -1; + } } else { db_flag = 0; db_missed_flag = 0; @@ -466,10 +479,16 @@ static int mod_init( void ) }
/* fix the flags */ - if (flag_idx2mask(&radius_flag)<0) + if ((radius_flag != -1) && !flag_in_range(radius_flag)) { + LM_ERR("radius_flag set to invalid value\n"); return -1; - if (flag_idx2mask(&radius_missed_flag)<0) + } + + if ((radius_missed_flag != -1) && !flag_in_range(radius_missed_flag)) { + LM_ERR("radius_missed_flag set to invalid value\n"); return -1; + } + if (init_acc_rad( radius_config, service_type)!=0 ) { LM_ERR("failed to init radius\n"); return -1;