Skip to content

Commit

Permalink
registrar: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent fb7c59c commit 42d357e
Show file tree
Hide file tree
Showing 21 changed files with 1,704 additions and 1,672 deletions.
41 changes: 17 additions & 24 deletions src/modules/registrar/api.c
Expand Up @@ -37,10 +37,9 @@
*/
int regapi_save(sip_msg_t *msg, str *table, int flags)
{
udomain_t* d;
udomain_t *d;

if(ul.get_udomain(table->s, &d)<0)
{
if(ul.get_udomain(table->s, &d) < 0) {
LM_ERR("usrloc domain [%s] not found\n", table->s);
return -1;
}
Expand All @@ -53,10 +52,9 @@ int regapi_save(sip_msg_t *msg, str *table, int flags)
*/
int regapi_save_uri(sip_msg_t *msg, str *table, int flags, str *uri)
{
udomain_t* d;
udomain_t *d;

if(ul.get_udomain(table->s, &d)<0)
{
if(ul.get_udomain(table->s, &d) < 0) {
LM_ERR("usrloc domain [%s] not found\n", table->s);
return -1;
}
Expand All @@ -69,10 +67,9 @@ int regapi_save_uri(sip_msg_t *msg, str *table, int flags, str *uri)
*/
int regapi_lookup(sip_msg_t *msg, str *table)
{
udomain_t* d;
udomain_t *d;

if(ul.get_udomain(table->s, &d)<0)
{
if(ul.get_udomain(table->s, &d) < 0) {
LM_ERR("usrloc domain [%s] not found\n", table->s);
return -1;
}
Expand All @@ -85,10 +82,9 @@ int regapi_lookup(sip_msg_t *msg, str *table)
*/
int regapi_lookup_uri(sip_msg_t *msg, str *table, str *uri)
{
udomain_t* d;
udomain_t *d;

if(ul.get_udomain(table->s, &d)<0)
{
if(ul.get_udomain(table->s, &d) < 0) {
LM_ERR("usrloc domain [%s] not found\n", table->s);
return -1;
}
Expand All @@ -101,10 +97,9 @@ int regapi_lookup_uri(sip_msg_t *msg, str *table, str *uri)
*/
int regapi_registered(sip_msg_t *msg, str *table)
{
udomain_t* d;
udomain_t *d;

if(ul.get_udomain(table->s, &d)<0)
{
if(ul.get_udomain(table->s, &d) < 0) {
LM_ERR("usrloc domain [%s] not found\n", table->s);
return -1;
}
Expand All @@ -117,8 +112,7 @@ int regapi_registered(sip_msg_t *msg, str *table)
int regapi_set_q_override(sip_msg_t *msg, str *new_q)
{
int _q;
if (str2q(&_q, new_q->s, new_q->len) < 0)
{
if(str2q(&_q, new_q->s, new_q->len) < 0) {
LM_ERR("invalid q parameter\n");
return -1;
}
Expand All @@ -131,10 +125,9 @@ int regapi_set_q_override(sip_msg_t *msg, str *new_q)
*/
int regapi_lookup_to_dset(sip_msg_t *msg, str *table, str *uri)
{
udomain_t* d;
udomain_t *d;

if(ul.get_udomain(table->s, &d)<0)
{
if(ul.get_udomain(table->s, &d) < 0) {
LM_ERR("usrloc domain [%s] not found\n", table->s);
return -1;
}
Expand All @@ -146,13 +139,13 @@ int regapi_lookup_to_dset(sip_msg_t *msg, str *table, str *uri)
*/
int bind_registrar(registrar_api_t *api)
{
if (!api) {
if(!api) {
ERR("Invalid parameter value\n");
return -1;
}
api->save = regapi_save;
api->save_uri = regapi_save_uri;
api->lookup = regapi_lookup;
api->save = regapi_save;
api->save_uri = regapi_save_uri;
api->lookup = regapi_lookup;
api->lookup_uri = regapi_lookup_uri;
api->lookup_to_dset = regapi_lookup_to_dset;
api->registered = regapi_registered;
Expand Down
21 changes: 11 additions & 10 deletions src/modules/registrar/api.h
Expand Up @@ -32,7 +32,8 @@
typedef int (*regapi_save_f)(sip_msg_t *msg, str *table, int flags);
int regapi_save(sip_msg_t *msg, str *table, int flags);

typedef int (*regapi_save_uri_f)(sip_msg_t *msg, str *table, int flags, str *uri);
typedef int (*regapi_save_uri_f)(
sip_msg_t *msg, str *table, int flags, str *uri);
int regapi_save_uri(sip_msg_t *msg, str *table, int flags, str *uri);

typedef int (*regapi_lookup_f)(sip_msg_t *msg, str *table);
Expand All @@ -49,18 +50,19 @@ int regapi_set_q_override(sip_msg_t *msg, str *new_q);
/**
* @brief REGISTRAR API structure
*/
typedef struct registrar_api {
regapi_save_f save;
regapi_save_uri_f save_uri;
regapi_lookup_f lookup;
typedef struct registrar_api
{
regapi_save_f save;
regapi_save_uri_f save_uri;
regapi_lookup_f lookup;
regapi_lookup_uri_f lookup_uri;
regapi_lookup_uri_f lookup_to_dset;
regapi_lookup_f registered;
regapi_lookup_f registered;
regapi_set_q_override_f set_q_override;
} registrar_api_t;

typedef int (*bind_registrar_f)(registrar_api_t* api);
int bind_registrar(registrar_api_t* api);
typedef int (*bind_registrar_f)(registrar_api_t *api);
int bind_registrar(registrar_api_t *api);

/**
* @brief Load the REGISTRAR API
Expand All @@ -74,8 +76,7 @@ static inline int registrar_load_api(registrar_api_t *api)
LM_ERR("cannot find bind_registrar\n");
return -1;
}
if (bindregistrar(api) < 0)
{
if(bindregistrar(api) < 0) {
LM_ERR("cannot bind registrar api\n");
return -1;
}
Expand Down
33 changes: 16 additions & 17 deletions src/modules/registrar/common.c
Expand Up @@ -39,7 +39,7 @@
/*! \brief
* Extract Address of Record
*/
int extract_aor(str* _uri, str* _a, sip_uri_t *_pu)
int extract_aor(str *_uri, str *_a, sip_uri_t *_pu)
{
static char aor_buf[MAX_AOR_LEN];
str tmp;
Expand All @@ -50,22 +50,22 @@ int extract_aor(str* _uri, str* _a, sip_uri_t *_pu)
str realm_prefix = {0};

memset(aor_buf, 0, MAX_AOR_LEN);
uri=_uri;
uri = _uri;

if(_pu!=NULL)
if(_pu != NULL)
puri = _pu;
else
puri = &turi;

if (parse_uri(uri->s, uri->len, puri) < 0) {
if(parse_uri(uri->s, uri->len, puri) < 0) {
rerrno = R_AOR_PARSE;
LM_ERR("failed to parse AoR [%.*s]\n", uri->len, uri->s);
return -1;
}

if ( (puri->user.len + puri->host.len + 1) > MAX_AOR_LEN
|| puri->user.len > USERNAME_MAX_SIZE
|| puri->host.len > DOMAIN_MAX_SIZE ) {
if((puri->user.len + puri->host.len + 1) > MAX_AOR_LEN
|| puri->user.len > USERNAME_MAX_SIZE
|| puri->host.len > DOMAIN_MAX_SIZE) {
rerrno = R_AOR_LEN;
LM_ERR("Address Of Record too long\n");
return -2;
Expand All @@ -74,28 +74,27 @@ int extract_aor(str* _uri, str* _a, sip_uri_t *_pu)
_a->s = aor_buf;
_a->len = puri->user.len;

if (un_escape(&puri->user, _a) < 0) {
if(un_escape(&puri->user, _a) < 0) {
rerrno = R_UNESCAPE;
LM_ERR("failed to unescape username\n");
return -3;
}

user_len = _a->len;

if (reg_use_domain) {
if (user_len)
if(reg_use_domain) {
if(user_len)
aor_buf[_a->len++] = '@';
/* strip prefix (if defined) */
realm_prefix.len = cfg_get(registrar, registrar_cfg, realm_pref).len;
if(realm_prefix.len>0) {
if(realm_prefix.len > 0) {
realm_prefix.s = cfg_get(registrar, registrar_cfg, realm_pref).s;
LM_DBG("realm prefix is [%.*s]\n", realm_prefix.len,
(realm_prefix.len>0)?realm_prefix.s:"");
(realm_prefix.len > 0) ? realm_prefix.s : "");
}
if (realm_prefix.len>0
&& realm_prefix.len<puri->host.len
&& (memcmp(realm_prefix.s, puri->host.s, realm_prefix.len)==0))
{
if(realm_prefix.len > 0 && realm_prefix.len < puri->host.len
&& (memcmp(realm_prefix.s, puri->host.s, realm_prefix.len)
== 0)) {
memcpy(aor_buf + _a->len, puri->host.s + realm_prefix.len,
puri->host.len - realm_prefix.len);
_a->len += puri->host.len - realm_prefix.len;
Expand All @@ -105,7 +104,7 @@ int extract_aor(str* _uri, str* _a, sip_uri_t *_pu)
}
}

if (cfg_get(registrar, registrar_cfg, case_sensitive) && user_len) {
if(cfg_get(registrar, registrar_cfg, case_sensitive) && user_len) {
tmp.s = _a->s + user_len + 1;
tmp.len = _a->s + _a->len - tmp.s;
strlower(&tmp);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/registrar/common.h
Expand Up @@ -33,12 +33,12 @@
#include "../../core/str.h"
#include "../../core/parser/parse_uri.h"

#define REG_GRUU_SEP '-'
#define REG_GRUU_SEP '-'

/*! \brief
* Extract Address Of Record
*/
int extract_aor(str* _uri, str* _a, sip_uri_t *_pu);
int extract_aor(str *_uri, str *_a, sip_uri_t *_pu);


#endif /* COMMON_H */
100 changes: 58 additions & 42 deletions src/modules/registrar/config.c
Expand Up @@ -29,47 +29,63 @@

#include "config.h"

struct cfg_group_registrar default_registrar_cfg = {
STR_NULL, /* realm_pref */
3600, /* default_expires */
0, /* default_expires_range */
0, /* expires_range */
60, /* min_expires */
0, /* max_expires */
0, /* max_contacts */
0, /* retry_after */
0, /* case_sensitive */
Q_UNSPECIFIED, /* default_q */
1, /* append_branches */
0 /* use_expired_contacts */
};
struct cfg_group_registrar default_registrar_cfg = {
STR_NULL, /* realm_pref */
3600, /* default_expires */
0, /* default_expires_range */
0, /* expires_range */
60, /* min_expires */
0, /* max_expires */
0, /* max_contacts */
0, /* retry_after */
0, /* case_sensitive */
Q_UNSPECIFIED, /* default_q */
1, /* append_branches */
0 /* use_expired_contacts */
};

void *registrar_cfg = &default_registrar_cfg;
void *registrar_cfg = &default_registrar_cfg;

cfg_def_t registrar_cfg_def[] = {
{"realm_pref", CFG_VAR_STR, 0, 0, 0, 0,
"Realm prefix to be removed. Default is \"\""},
{"default_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, default_expires_stats_update,
"Contains number of second to expire if no expire hf or contact expire present" },
{"default_expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 100, 0, default_expires_range_update,
"Percent from default_expires that will be used in generating the range for the expire interval"},
{"expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 100, 0, expires_range_update,
"Percent from incoming expires that will be used in generating the range for the expire interval"},
{"min_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, 0,
"The minimum expires value of a Contact. Value 0 disables the checking. "},
{"max_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, max_expires_stats_update,
"The maximum expires value of a Contact. Value 0 disables the checking. "},
{"max_contacts", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"The maximum number of Contacts for an AOR. Value 0 disables the checking. "},
{"retry_after", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"If you want to add the Retry-After header field in 5xx replies, set this parameter to a value grater than zero"},
{"case_sensitive", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"If set to 1 then AOR comparison will be case sensitive. Recommended and default is 0, case insensitive"},
{"default_q", CFG_VAR_INT | CFG_ATOMIC, -1, 1000, 0, 0,
"The parameter represents default q value for new contacts."}, /* Q_UNSPECIFIED is -1 */
{"append_branches", CFG_VAR_INT , 0, 0, 0, 0,
"If set to 1(default), lookup will put all contacts found in msg structure"},
{"use_expired_contacts",CFG_VAR_INT , 0, 0, 0, 0,
"Toggles using expired contacts as if they were active."},
{0, 0, 0, 0, 0, 0}
};
cfg_def_t registrar_cfg_def[] =
{{"realm_pref", CFG_VAR_STR, 0, 0, 0, 0,
"Realm prefix to be removed. Default is \"\""},
{"default_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0,
default_expires_stats_update,
"Contains number of second to expire if no expire hf "
"or contact expire present"},
{"default_expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0,
100, 0, default_expires_range_update,
"Percent from default_expires that will be used in "
"generating the range for the expire interval"},
{"expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 100, 0,
expires_range_update,
"Percent from incoming expires that will be used in "
"generating the range for the expire interval"},
{"min_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, 0,
"The minimum expires value of a Contact. Value 0 "
"disables the checking. "},
{"max_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0,
max_expires_stats_update,
"The maximum expires value of a Contact. Value 0 "
"disables the checking. "},
{"max_contacts", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"The maximum number of Contacts for an AOR. Value 0 "
"disables the checking. "},
{"retry_after", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"If you want to add the Retry-After header field in "
"5xx replies, set this parameter to a value grater "
"than zero"},
{"case_sensitive", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"If set to 1 then AOR comparison will be case "
"sensitive. Recommended and default is 0, case "
"insensitive"},
{"default_q", CFG_VAR_INT | CFG_ATOMIC, -1, 1000, 0, 0,
"The parameter represents default q value for new "
"contacts."}, /* Q_UNSPECIFIED is -1 */
{"append_branches", CFG_VAR_INT, 0, 0, 0, 0,
"If set to 1(default), lookup will put all contacts "
"found in msg structure"},
{"use_expired_contacts", CFG_VAR_INT, 0, 0, 0, 0,
"Toggles using expired contacts as if they were "
"active."},
{0, 0, 0, 0, 0, 0}};

0 comments on commit 42d357e

Please sign in to comment.