Skip to content

Commit

Permalink
mid_registrar: Clean up code / documentation
Browse files Browse the repository at this point in the history
    * drop auto-insertion by Path (it's Contact-only now)
	(reason: it cannot work without also adding Contact info,
	         so why use it in the first place?)
    * update documentation
    * prepare modparams / documentation for upcoming tweaks
	- rename insertion_mode -> contact_id_insertion
	- rename contact_match_param -> contact_id_param

(cherry picked from commit 3ead207)
  • Loading branch information
liviuchircu committed Apr 3, 2018
1 parent 5f05e02 commit 29e5a9f
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 858 deletions.
376 changes: 178 additions & 198 deletions modules/mid_registrar/README

Large diffs are not rendered by default.

422 changes: 191 additions & 231 deletions modules/mid_registrar/doc/mid_registrar_admin.xml

Large diffs are not rendered by default.

44 changes: 1 addition & 43 deletions modules/mid_registrar/lookup.c
Expand Up @@ -66,48 +66,6 @@ unsigned int nbranches;
static char urimem[MAX_BRANCHES-1][MAX_URI_SIZE];
static str branch_uris[MAX_BRANCHES-1];

int get_match_token(str *uri, str *out_tok, struct sip_uri *out_puri, int *out_idx)
{
struct sip_uri puri;
int i;

if (parse_uri(uri->s, uri->len, &puri) < 0) {
LM_ERR("failed to parse contact <%.*s>\n", uri->len, uri->s);
return -1;
}

if (matching_mode == MATCH_BY_PARAM) {
for (i = 0; i < puri.u_params_no; i++) {
if (!str_strcmp(&puri.u_name[i], &matching_param)) {
*out_tok = puri.u_val[i];
if (out_idx)
*out_idx = i;
break;
}
}

if (!out_tok->s || out_tok->len <= 0) {
LM_ERR("a Contact from main registrar (%.*s) is missing the '%.*s'"
" hf parameter\n", uri->len, uri->s,
matching_param.len, matching_param.s);
return -1;
}
} else {
*out_tok = puri.user;

if (!out_tok->s || out_tok->len <= 0) {
LM_ERR("missing SIP user in Contact from main registrar (%.*s)\n",
uri->len, uri->s);
return -1;
}
}

if (out_puri)
*out_puri = puri;

return 0;
}

int mid_reg_lookup(struct sip_msg* req, char* _t, char* _f, char* _s)
{
unsigned int flags;
Expand Down Expand Up @@ -228,7 +186,7 @@ int mid_reg_lookup(struct sip_msg* req, char* _t, char* _f, char* _s)
*(ua+re_len) = tmp;
}

if (reg_mode != MID_REG_THROTTLE_AOR && insertion_mode == INSERT_BY_CONTACT) {
if (reg_mode != MID_REG_THROTTLE_AOR) {
if (parse_uri(uri.s, uri.len, &puri) < 0) {
LM_ERR("failed to parse R-URI <%.*s>, ci: %.*s\n", uri.len,
uri.s, req->callid->body.len, req->callid->body.s);
Expand Down
2 changes: 0 additions & 2 deletions modules/mid_registrar/lookup.h
Expand Up @@ -36,6 +36,4 @@

int mid_reg_lookup(struct sip_msg* req, char* _t, char* _f, char* _s);

int get_match_token(str *uri, str *out_tok, struct sip_uri *out_puri, int *out_idx);

#endif /* __MID_REG_LOOKUP_ */
52 changes: 13 additions & 39 deletions modules/mid_registrar/mid_registrar.c
Expand Up @@ -111,9 +111,6 @@ char* realm_pref = "";
str realm_prefix;
int reg_use_domain = 0;

#define is_insertion_mode(v) (v == INSERT_BY_CONTACT || v == INSERT_BY_PATH)
#define insertion_mode_str(v) (v == INSERT_BY_CONTACT ? "by Contact" : "by Path")

static int mod_init(void);

static int domain_fixup(void** param);
Expand All @@ -131,21 +128,10 @@ enum mid_reg_mode reg_mode = MID_REG_MIRROR;

unsigned int outgoing_expires = 3600;

#define is_matching_mode(v) (v == MATCH_BY_PARAM || v == MATCH_BY_USER)
#define matching_mode_str(v) (v == MATCH_BY_PARAM ? "by uri param" : "by user")

enum mid_reg_insertion_mode insertion_mode = INSERT_BY_CONTACT;

//TODO: remove the Path-based mid-registrar logic starting with OpenSIPS 2.4
enum mid_reg_matching_mode matching_mode = MATCH_BY_PARAM;
enum mid_reg_insertion_mode ctid_insertion = MR_REPLACE_USER;
char *mp_ctid_insertion = "ct-param";

/*
* TODO: get rid of this (no pun intended)
* Only used in INSERT_BY_CONTACT insertion mode
* Allows us to match the request contact set with the reply contact set,
* which contains rewritten Contact header field domains
*/
str matching_param = str_init("rid");
str ctid_param = str_init("ctid");

static cmd_export_t cmds[] = {
{ "mid_registrar_save", (cmd_function)mid_reg_save, 1,
Expand Down Expand Up @@ -182,8 +168,8 @@ static param_export_t mod_params[] = {
{ "gruu_secret", STR_PARAM, &gruu_secret.s },
{ "disable_gruu", INT_PARAM, &disable_gruu },
{ "outgoing_expires", INT_PARAM, &outgoing_expires },
{ "insertion_mode", INT_PARAM, &insertion_mode },
{ "contact_match_param", STR_PARAM, &matching_param.s },
{ "contact_id_insertion", STR_PARAM, &mp_ctid_insertion },
{ "contact_id_param", STR_PARAM, &ctid_param.s },
{ "extra_contact_params_avp", STR_PARAM, &extra_ct_params_str.s },
{ 0,0,0 }
};
Expand Down Expand Up @@ -294,20 +280,14 @@ static int mod_init(void)
return -1;
}

if (!is_insertion_mode(insertion_mode)) {
insertion_mode = INSERT_BY_PATH;
LM_WARN("bad \"insertion_mode\" (%d) - using '%s' as a default\n",
insertion_mode, insertion_mode_str(insertion_mode));
if (!strncasecmp(mp_ctid_insertion, STR_L("ct-param"))) {
ctid_insertion = MR_APPEND_PARAM;
} else if (!strncasecmp(mp_ctid_insertion, STR_L("ct-user"))) {
ctid_insertion = MR_REPLACE_USER;
} else {
LM_DBG("insertion mode: '%s'\n", insertion_mode_str(insertion_mode));
}

if (!is_matching_mode(matching_mode)) {
matching_mode = MATCH_BY_PARAM;
LM_WARN("bad \"matching_mode\" (%d) - using '%s' as a default\n",
matching_mode, matching_mode_str(matching_mode));
} else {
LM_DBG("contact matching mode: '%s'\n", matching_mode_str(matching_mode));
LM_WARN("bad 'contact_id_insertion' (%s) - using 'ct-param' as a "
"default\n", mp_ctid_insertion);
ctid_insertion = MR_APPEND_PARAM;
}

if (min_expires > default_expires) {
Expand Down Expand Up @@ -356,7 +336,7 @@ static int mod_init(void)
tcp_persistent_flag = get_flag_id_by_name(FLAG_TYPE_MSG, tcp_persistent_flag_s);
tcp_persistent_flag = (tcp_persistent_flag != -1) ? (1 << tcp_persistent_flag) : 0;

matching_param.len = strlen(matching_param.s);
ctid_param.len = strlen(ctid_param.s);

if (reg_mode != MID_REG_MIRROR) {
if (ul_api.register_ulcb(
Expand Down Expand Up @@ -497,12 +477,6 @@ void mri_free(struct mid_reg_info *mri)
if (mri->user_agent.s)
shm_free(mri->user_agent.s);

if (mri->path.s)
shm_free(mri->path.s);

if (mri->path_received.s)
shm_free(mri->path_received.s);

free_ct_mappings(&mri->ct_mappings);

#ifdef EXTRA_DEBUG
Expand Down
12 changes: 2 additions & 10 deletions modules/mid_registrar/mid_registrar.h
Expand Up @@ -52,14 +52,8 @@ enum mid_reg_mode {
};

enum mid_reg_insertion_mode {
INSERT_BY_CONTACT,
INSERT_BY_PATH,
};

//TODO: remove the Path-based mid-registrar logic starting with OpenSIPS 2.4
enum mid_reg_matching_mode {
MATCH_BY_PARAM,
MATCH_BY_USER,
MR_REPLACE_USER,
MR_APPEND_PARAM,
};

struct ct_mapping {
Expand Down Expand Up @@ -116,8 +110,6 @@ struct mid_reg_info {

/* ucontact_info dup'ed fields */
str user_agent;
str path_received;
str path;
unsigned int ul_flags;
unsigned int cflags;

Expand Down

0 comments on commit 29e5a9f

Please sign in to comment.