Skip to content

Commit

Permalink
siputils: removed duplicated function for e164 check
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jun 10, 2022
1 parent da4f786 commit 64ae9ed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
8 changes: 4 additions & 4 deletions src/modules/siputils/checks.c
Expand Up @@ -656,7 +656,7 @@ int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res)
/*
* Check if parameter is an e164 number.
*/
static inline int e164_check(str* _user)
int siputils_e164_check(str* _user)
{
int i;
char c;
Expand All @@ -675,7 +675,7 @@ static inline int e164_check(str* _user)
/*
* Check if user part of URI in pseudo variable is an e164 number
*/
int is_e164(struct sip_msg* _m, char* _sp, char* _s2)
int w_is_e164(struct sip_msg* _m, char* _sp, char* _s2)
{
pv_spec_t *sp;
pv_value_t pv_val;
Expand All @@ -688,7 +688,7 @@ int is_e164(struct sip_msg* _m, char* _sp, char* _s2)
LM_DBG("missing argument\n");
return -1;
}
return e164_check(&(pv_val.rs));
return siputils_e164_check(&(pv_val.rs));
} else {
LM_ERR("pseudo variable value is not string\n");
return -1;
Expand Down Expand Up @@ -743,7 +743,7 @@ int is_uri_user_e164(str *uri)
if (chr == NULL) return -1;
user.len = chr - user.s;

return e164_check(&user);
return siputils_e164_check(&user);
}

/*
Expand Down
4 changes: 3 additions & 1 deletion src/modules/siputils/checks.h
Expand Up @@ -89,7 +89,9 @@ int is_uri_user_e164(str *uri);
/*
* Check if pseudo variable argument value is an e164 number
*/
int is_e164(struct sip_msg* _m, char* _sp, char* _s2);
int w_is_e164(struct sip_msg* _m, char* _sp, char* _s2);

int siputils_e164_check(str* _user);

/*
* Set userpart of URI
Expand Down
26 changes: 2 additions & 24 deletions src/modules/siputils/rpid.c
Expand Up @@ -37,6 +37,7 @@
#include "../../core/parser/parser_f.h"
#include "../../core/ut.h"
#include "../../core/pvar.h"
#include "checks.h"
#include "rpid.h"


Expand Down Expand Up @@ -95,29 +96,6 @@ void get_rpid_avp( int_str *rpid_avp_p, int *rpid_avp_type_p )
}


/*!
* \brief Check if user is a E164 number
* \param _user user
* \note Copy of is_e164 from enum module
* \return 1 if its a E164 number, -1 if not
*/
static inline int is_e164(str* _user)
{
int i;
char c;

if ((_user->len > 2) && (_user->len < 17) && ((_user->s)[0] == '+')) {
for (i = 1; i < _user->len; i++) {
c = (_user->s)[i];
if ((c < '0') || (c > '9')) return -1;
}
return 1;
} else {
return -1;
}
}


/*!
* \brief Append RPID helper function
* \param _m SIP message
Expand Down Expand Up @@ -325,7 +303,7 @@ int is_rpid_user_e164(struct sip_msg* _m, char* _s1, char* _s2)
goto err;
}

return is_e164(&uri.user);
return siputils_e164_check(&uri.user);

err:
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/siputils/siputils.c
Expand Up @@ -141,7 +141,7 @@ static cmd_export_t cmds[]={
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE},
{"is_uri", (cmd_function)is_uri, 1, fixup_spve_null,
fixup_free_spve_null, ANY_ROUTE},
{"is_e164", (cmd_function)is_e164, 1, fixup_pvar_null,
{"is_e164", (cmd_function)w_is_e164, 1, fixup_pvar_null,
fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
{"is_uri_user_e164", (cmd_function)w_is_uri_user_e164, 1, fixup_pvar_null,
fixup_free_pvar_null, ANY_ROUTE},
Expand Down

0 comments on commit 64ae9ed

Please sign in to comment.