Skip to content

Commit

Permalink
p_usrloc: 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 3b770d3 commit 878a2c8
Show file tree
Hide file tree
Showing 48 changed files with 2,719 additions and 2,395 deletions.
58 changes: 32 additions & 26 deletions src/modules/p_usrloc/config.c
Expand Up @@ -29,32 +29,38 @@

#include "config.h"

struct cfg_group_p_usrloc default_p_usrloc_cfg = {
DEFAULT_EXPIRE, /* expire_time */
struct cfg_group_p_usrloc default_p_usrloc_cfg = {
DEFAULT_EXPIRE, /* expire_time */
DEFAULT_ERR_THRESHOLD, /* db_err_threshold */
DEFAULT_FAILOVER_LEVEL, /* failover_level */
0, /* db_ops_ruid */
1, /* db_update_as_insert */
CONTACT_ONLY, /* matching_mode */
0, /* utc_timestamps */
};
DEFAULT_FAILOVER_LEVEL, /* failover_level */
0, /* db_ops_ruid */
1, /* db_update_as_insert */
CONTACT_ONLY, /* matching_mode */
0, /* utc_timestamps */
};

void *p_usrloc_cfg = &default_p_usrloc_cfg;
void *p_usrloc_cfg = &default_p_usrloc_cfg;

cfg_def_t p_usrloc_cfg_def[] = {
{"expire_time", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Contains number of second to expire if no expire hf or contact expire present" },
{"db_err_threshold", CFG_VAR_INT | CFG_ATOMIC, 0, 100, 0, 0,
" Specifies the error value on which a database shall be turned off. "},
{"failover_level", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Specifies the manner a failover is done (1 = turn off, 2 = find a spare) "},
{"db_ops_ruid", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0,
"Set this if you want to update / delete from DB using ruid value "},
{"db_update_as_insert", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
"Set this parameter if you want to do INSERT DB operations instead of UPDATE DB operations. "},
{"matching_mode", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Specified which contact maching algorithm to be used (0 - Contact only / 1 - Contact and Call-ID / 2 - Contact and Path)"},
{"utc_timestamps", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Expires and last_modified timestamps in UTC time format"},
{0, 0, 0, 0, 0, 0}
};
cfg_def_t p_usrloc_cfg_def[] = {
{"expire_time", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Contains number of second to expire if no expire hf or "
"contact expire present"},
{"db_err_threshold", CFG_VAR_INT | CFG_ATOMIC, 0, 100, 0, 0,
" Specifies the error value on which a database shall be "
"turned off. "},
{"failover_level", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Specifies the manner a failover is done (1 = turn off, 2 = "
"find a spare) "},
{"db_ops_ruid", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0,
"Set this if you want to update / delete from DB using ruid "
"value "},
{"db_update_as_insert", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
"Set this parameter if you want to do INSERT DB operations "
"instead of UPDATE DB operations. "},
{"matching_mode", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Specified which contact maching algorithm to be used (0 - "
"Contact only / 1 - Contact and Call-ID / 2 - Contact and "
"Path)"},
{"utc_timestamps", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
"Expires and last_modified timestamps in UTC time format"},
{0, 0, 0, 0, 0, 0}};
29 changes: 15 additions & 14 deletions src/modules/p_usrloc/config.h
Expand Up @@ -26,22 +26,23 @@
#include "../../core/str.h"
#include "p_usrloc_mod.h"

struct cfg_group_p_usrloc {
unsigned int expire_time;
unsigned int db_err_threshold;
unsigned int failover_level;
unsigned int db_ops_ruid;
unsigned int db_update_as_insert;
unsigned int matching_mode;
unsigned int utc_timestamps;
struct cfg_group_p_usrloc
{
unsigned int expire_time;
unsigned int db_err_threshold;
unsigned int failover_level;
unsigned int db_ops_ruid;
unsigned int db_update_as_insert;
unsigned int matching_mode;
unsigned int utc_timestamps;
};

extern struct cfg_group_p_usrloc default_p_usrloc_cfg;
extern void *p_usrloc_cfg;
extern cfg_def_t p_usrloc_cfg_def[];
extern struct cfg_group_p_usrloc default_p_usrloc_cfg;
extern void *p_usrloc_cfg;
extern cfg_def_t p_usrloc_cfg_def[];

extern void default_expires_stats_update(str*, str*);
extern void default_expires_range_update(str*, str*);
extern void max_expires_stats_update(str*, str*);
extern void default_expires_stats_update(str *, str *);
extern void default_expires_range_update(str *, str *);
extern void max_expires_stats_update(str *, str *);

#endif
70 changes: 34 additions & 36 deletions src/modules/p_usrloc/dlist.c
Expand Up @@ -28,16 +28,16 @@


#include "dlist.h"
#include <stdlib.h> /* abort */
#include <string.h> /* strlen, memcmp */
#include <stdio.h> /* printf */
#include <stdlib.h> /* abort */
#include <string.h> /* strlen, memcmp */
#include <stdio.h> /* printf */
#include "../../core/ut.h"
#include "../../lib/srdb1/db.h"
#include "../../core/mem/shm_mem.h"
#include "../../core/dprint.h"
#include "../../core/ip_addr.h"
#include "../../core/socket_info.h"
#include "udomain.h" /* new_udomain, free_udomain */
#include "udomain.h" /* new_udomain, free_udomain */
#include "utime.h"
#include "p_usrloc_mod.h"

Expand All @@ -46,47 +46,46 @@
static struct domain_list_item *domain_list;



static inline struct domain_list_item * find_dlist (str *name) {
static inline struct domain_list_item *find_dlist(str *name)
{
struct domain_list_item *item;

for (item = domain_list; item != NULL; item = item->next) {
if (item->name.len == name->len
&& memcmp (item->name.s, name->s, name->len) == 0) {
for(item = domain_list; item != NULL; item = item->next) {
if(item->name.len == name->len
&& memcmp(item->name.s, name->s, name->len) == 0) {
return item;
}
}
return NULL;
}




static inline struct domain_list_item * add_to_dlist (str *name, int type) {
static inline struct domain_list_item *add_to_dlist(str *name, int type)
{
struct domain_list_item *item;
int i;
item = (struct domain_list_item *)
pkg_malloc (sizeof (struct domain_list_item));
if (item == NULL) {
item = (struct domain_list_item *)pkg_malloc(
sizeof(struct domain_list_item));
if(item == NULL) {
LM_ERR("Out of pkg memory.\n");
return NULL;
}
item->name.s = (char *) pkg_malloc (name->len + 1);
if (item->name.s == NULL) {
item->name.s = (char *)pkg_malloc(name->len + 1);
if(item->name.s == NULL) {
LM_ERR("Out of pkg memory (1).\n");
pkg_free(item);
return NULL;
}
memcpy (item->name.s, name->s, name->len);
memcpy(item->name.s, name->s, name->len);
item->name.s[name->len] = '\0';
item->name.len = name->len;

memset (&item->domain, 0, sizeof (struct udomain));
memset(&item->domain, 0, sizeof(struct udomain));
item->domain.name = &item->name;
item->domain.dbt = type;

item->domain.table = (hslot_t*)pkg_malloc(sizeof(hslot_t) * ul_hash_size);
if (!item->domain.table) {
item->domain.table = (hslot_t *)pkg_malloc(sizeof(hslot_t) * ul_hash_size);
if(!item->domain.table) {
LM_ERR("Out of pkg memory (2)\n");
pkg_free(item->name.s);
pkg_free(item);
Expand Down Expand Up @@ -117,32 +116,33 @@ static inline struct domain_list_item * add_to_dlist (str *name, int type) {
* \param _d new created domain
* \return 0 on success, -1 on failure
*/
int register_udomain(const char *name, udomain_t **domain) {
int register_udomain(const char *name, udomain_t **domain)
{
struct domain_list_item *item;
str name_str;
ul_domain_db_t * d;
ul_domain_db_t *d;

name_str.s = (char *) name;
name_str.len = strlen (name);
item = find_dlist (&name_str);
if (item == NULL) {
if((d = ul_find_domain(name)) == NULL){
name_str.s = (char *)name;
name_str.len = strlen(name);
item = find_dlist(&name_str);
if(item == NULL) {
if((d = ul_find_domain(name)) == NULL) {
LM_ERR("domain %s not found.\n", name);
return -1;
}
item = add_to_dlist (&name_str, d->dbt);
item = add_to_dlist(&name_str, d->dbt);
}
if (item == NULL) {
if(item == NULL) {
return -1;
}
*domain = &item->domain;
LM_DBG("found domain %.*s, type: %s\n", (*domain)->name->len, (*domain)->name->s, (((*domain)->dbt) == DB_TYPE_CLUSTER ? "cluster" : "single"));
LM_DBG("found domain %.*s, type: %s\n", (*domain)->name->len,
(*domain)->name->s,
(((*domain)->dbt) == DB_TYPE_CLUSTER ? "cluster" : "single"));
return 0;
}




/*!
* \brief Loops through all domains summing up the number of users
* \return the number of users, could be zero
Expand All @@ -156,7 +156,7 @@ unsigned long get_number_of_users(void)


int get_all_ucontacts(void *buf, int len, unsigned int flags,
unsigned int part_idx, unsigned int part_max, int options)
unsigned int part_idx, unsigned int part_max, int options)
{
LM_INFO("not available with partitioned interface\n");
return -1;
Expand All @@ -171,5 +171,3 @@ int synchronize_all_udomains(void)
LM_INFO("not available with partitioned interface\n");
return res;
}


13 changes: 7 additions & 6 deletions src/modules/p_usrloc/dlist.h
Expand Up @@ -36,10 +36,11 @@
/*!
* List of all domains registered with usrloc
*/
struct domain_list_item {
struct domain_list_item
{
str name;
udomain_t domain;
struct domain_list_item*next;
struct domain_list_item *next;
};


Expand Down Expand Up @@ -72,7 +73,7 @@ unsigned long get_number_of_users(void);
* \param _d new created domain
* \return 0 on success, -1 on failure
*/
int register_udomain(const char* _n, udomain_t** _d);
int register_udomain(const char *_n, udomain_t **_d);

/*!
* \brief Get all contacts from the usrloc, in partitions if wanted
Expand Down Expand Up @@ -106,16 +107,16 @@ int register_udomain(const char* _n, udomain_t** _d);
* \param part_max maximal part
* \return 0 on success, positive if buffer size was not sufficient, negative on failure
*/
int get_all_ucontacts(void *, int, unsigned int,
unsigned int part_idx, unsigned int part_max, int options);
int get_all_ucontacts(void *, int, unsigned int, unsigned int part_idx,
unsigned int part_max, int options);

/*!
* \brief Find a particular domain, small wrapper around find_dlist
* \param _d domain name
* \param _p pointer to domain if found
* \return 1 if domain was found, 0 otherwise
*/
int find_domain(str* _d, udomain_t** _p);
int find_domain(str *_d, udomain_t **_p);


#endif

0 comments on commit 878a2c8

Please sign in to comment.