Skip to content

Commit

Permalink
uac_redirect: Migrate to new module interface
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Apr 2, 2019
1 parent 749fa45 commit 0654eda
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 320 deletions.
162 changes: 11 additions & 151 deletions modules/uac_redirect/doc/uac_redirect_admin.xml
Expand Up @@ -40,40 +40,6 @@
</para>
</section>

<section>
<title>Accounting</title>
<para>
UAC REDIRECT module allows to log all the redirection (to be later
used for CDR aggregation). This functionality may be dynamically
enabled for each redirection situation.
</para>
<para>
The logging will be done via the accounting module functions (all are
supported). The information to be logged will be the same as the
normal logged information directly via ACC module, but with
following differences:
</para>
<itemizedlist>
<listitem>
<para><emphasis>reason phrase</emphasis> - which will be
dynamically set by the redirection function;
</para>
</listitem>
<listitem>
<para><emphasis>outgoing URI</emphasis> - which will be the
redirect URI.
</para>
</listitem>
</itemizedlist>
<para>
For each redirect contact, a separate record will be logged. For
example, if a call is redirected to three new contacts, the
module will log three additional records corresponding to each
redirect URI.
</para>
</section>


<section id="dependencies" xreflabel="Dependencies">
<title>Dependencies</title>
<section>
Expand Down Expand Up @@ -195,71 +161,6 @@ modparam("uac_redirect","deny_filter",".*@siphub\.net")
<programlisting format="linespecific">
...
modparam("uac_redirect","accept_filter",".*@siphub\.net")
...
</programlisting>
</example>
</section>
<section id="param_acc_function" xreflabel="acc_function">
<title><varname>acc_function</varname> (string)</title>
<para>
Specifies the accounting function to be used. Just be defining
this parameter, the accounting support will not be enabled.
Accounting may only be enabled via two parameters
<function moreinfo="none">set_accept_filter()</function>
scripting function.
</para>
<para>
Its values my be:
</para>
<itemizedlist>
<listitem>
<para><emphasis>acc_log_request</emphasis></para>
</listitem>
<listitem>
<para><emphasis>acc_db_request</emphasis></para>
</listitem>
<listitem>
<para><emphasis>acc_rad_request</emphasis></para>
</listitem>
<listitem>
<para><emphasis>acc_diam_request</emphasis></para>
</listitem>
</itemizedlist>
<para>
<emphasis>
The default value is <quote>acc_log_request</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>acc_function</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("uac_redirect","acc_function","acc_db_request")
...
</programlisting>
</example>
</section>
<section id="param_acc_db_table" xreflabel="acc_db_table">
<title><varname>acc_db_table</varname> (string)</title>
<para>
Specifies the accounting table to be used if DB accounting was
chosen (<varname>acc_function</varname> was set to
<quote>acc_db_request</quote>). Just be defining
this parameter, the accounting support will not be enabled.
Accounting may only be enabled via two parameters
<function moreinfo="none">set_accept_filter()</function>
scripting function.
</para>
<para>
<emphasis>
The default value is <quote>acc</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>acc_db_table</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("uac_redirect","acc_db_table","acc_redirect")
...
</programlisting>
</example>
Expand Down Expand Up @@ -371,7 +272,7 @@ set_accept_filter(".*@domain1.net","");

<section id="func_get_redirects" xreflabel="get_redirects()">
<title>
<function moreinfo="none">get_redirects(max)</function>
<function moreinfo="none">get_redirects([max_total[, max_branch]])</function>
</title>
<para>
The function may be called only from failure routes. It will
Expand All @@ -381,82 +282,41 @@ set_accept_filter(".*@domain1.net","");
</para>
<para>
How many contacts (in total and per branch) are selected
depends of the <emphasis>max</emphasis> parameter values.
Its syntax is:
depends on the <emphasis>max_total</emphasis> and
<emphasis>max_branch</emphasis> parameters:
</para>
<itemizedlist>
<listitem><para>
max = max_total [":" max_branch]
</para></listitem>
<listitem><para>
max_total = number of total contacts to be selected
max_total (int, optional) - max overall number of contacts to be selected
</para></listitem>
<listitem><para>
max_branch = number of contacts per branch to be selected
max_branch (int, optional) - max number of contacts per branch to be selected
</para></listitem>
</itemizedlist>
<para>
Both <quote>max_total</quote> and <quote>max_branch</quote>
are positive integer. To specify unlimited values, use 0 value
or "*" character.
default to 0 (unlimited).
</para>
<para>
NOTE that during the selection process, each set of contacts
from a specific branch are ordered based on <quote>q</quote>
value.
</para>
<para>
This function will produce no accounting records.
</para>
<para>
This function can be used from FAILURE_ROUTE.
</para>
<example>
<title><function>get_redirects</function> usage</title>
<programlisting format="linespecific">
...
# max 2 contacts per branch, but no overall limit
get_redirects("*:2");
...
# no limits per branch, but not more than 6 overall contacts
get_redirects("6:*");
...
# no restrictions
get_redirects("*");
get_redirects();
...
</programlisting>
</example>
</section>

<section id="func_get_redirects_2" xreflabel="get_redirects()">
<title>
<function moreinfo="none">get_redirects(max,reason)</function>
</title>
<para>
The function has same functionality as
<function moreinfo="none">get_redirects(max)</function>
function, but it will produce accounting records.
</para>
<para>
The accounting records will be mark by the
<emphasis>reason</emphasis> phrase. This phrase shall be in the same format
as the <varname>reason</varname> parameter that would be passed to the
accounting function set by the <varname>acc_function</varname> module parameter.
See the ACC module documentation for more information.
</para>
<para>
If this function appears in the script, at startup, the module
will import the accounting function. Otherwise not.
</para>
<para>
This function can be used from FAILURE_ROUTE.
</para>
<example>
<title><function>get_redirects</function> usage</title>
<programlisting format="linespecific">
# no limits per branch, but not more than 6 overall contacts
get_redirects(6);
...
get_redirects("4:1","300"); # Record 300, using the default reason string for a 300
get_redirects("4:1","302 Redirected"); # Record as 302, with custom "Redirected" reason string
# max 2 contacts per branch, but no overall limit
get_redirects(, 2);
...
</programlisting>
</example>
Expand Down
22 changes: 4 additions & 18 deletions modules/uac_redirect/rd_funcs.c
Expand Up @@ -38,12 +38,9 @@
#define MAX_CONTACTS_PER_REPLY 16
#define DEFAULT_Q_VALUE 10

static int shmcontact2dset(struct sip_msg *req, struct sip_msg *shrpl,
long max, pv_elem_t *reason);
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *shrpl, long max);


int get_redirect( struct sip_msg *msg , int maxt, int maxb,
pv_elem_t *reason)
int get_redirect( struct sip_msg *msg , int maxt, int maxb)
{
struct cell *t;
int max;
Expand Down Expand Up @@ -80,7 +77,7 @@ int get_redirect( struct sip_msg *msg , int maxt, int maxb,
if (max==0)
continue;
/* get the contact from it */
n = shmcontact2dset( msg, t->uac[i].reply, max, reason);
n = shmcontact2dset( msg, t->uac[i].reply, max);
if ( n<0 ) {
LM_ERR("get contact from shm_reply branch %d failed\n",i);
/* do not go to error, try next branches */
Expand Down Expand Up @@ -158,16 +155,14 @@ static void sort_contacts(contact_t *ct_list, str *ct_array,
* 0 - ok, but no contact added
* n - ok and n contacts added
*/
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
long max, pv_elem_t *reason)
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl, long max)
{
static struct sip_msg dup_rpl;
static str scontacts[MAX_CONTACTS_PER_REPLY];
static qvalue_t sqvalues[MAX_CONTACTS_PER_REPLY];
struct hdr_field *hdr;
struct hdr_field *contact_hdr;
contact_t *contacts;
str backup_uri;
int n,i;
int added;
int dup;
Expand Down Expand Up @@ -270,15 +265,6 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
}
}
added++;
if (rd_acc_fct!=0 && reason) {
/* log the redirect */
backup_uri = req->new_uri;
req->new_uri = scontacts[i];
//FIXME
rd_acc_fct( req, (char*)reason, acc_db_table,
NULL, NULL, NULL, NULL);
req->new_uri = backup_uri;
}
}

ret = (added==0)?-1:added;
Expand Down
3 changes: 1 addition & 2 deletions modules/uac_redirect/rd_funcs.h
Expand Up @@ -40,8 +40,7 @@ extern cmd_function rd_acc_fct;

extern char *acc_db_table;

int get_redirect( struct sip_msg *msg , int maxt, int maxb,
pv_elem_t *reason);
int get_redirect( struct sip_msg *msg , int maxt, int maxb);

#endif

0 comments on commit 0654eda

Please sign in to comment.