Skip to content

Commit

Permalink
htable: 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 003cfd2 commit e3a31a0
Show file tree
Hide file tree
Showing 11 changed files with 1,550 additions and 1,703 deletions.
78 changes: 42 additions & 36 deletions src/modules/htable/api.c
Expand Up @@ -32,15 +32,17 @@
/**
*
*/
int ht_api_set_cell(str *hname, str *name, int type,
int_str *val, int mode)
int ht_api_set_cell(str *hname, str *name, int type, int_str *val, int mode)
{
ht_t* ht;
ht_t *ht;
ht = ht_get_table(hname);
if(ht==NULL)
if(ht == NULL)
return -1;

if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, hname, name, type, val, mode)!=0) {
if(ht->dmqreplicate > 0
&& ht_dmq_replicate_action(
HT_DMQ_SET_CELL, hname, name, type, val, mode)
!= 0) {
LM_ERR("dmq replication failed\n");
}

Expand All @@ -52,11 +54,13 @@ int ht_api_set_cell(str *hname, str *name, int type,
*/
int ht_api_del_cell(str *hname, str *name)
{
ht_t* ht;
ht_t *ht;
ht = ht_get_table(hname);
if(ht==NULL)
if(ht == NULL)
return -1;
if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, hname, name, 0, NULL, 0)!=0) {
if(ht->dmqreplicate > 0
&& ht_dmq_replicate_action(HT_DMQ_DEL_CELL, hname, name, 0, NULL, 0)
!= 0) {
LM_ERR("dmq replication failed\n");
}
return ht_del_cell(ht, name);
Expand All @@ -65,14 +69,16 @@ int ht_api_del_cell(str *hname, str *name)
/**
*
*/
int ht_api_set_cell_expire(str *hname, str *name,
int type, int_str *val)
int ht_api_set_cell_expire(str *hname, str *name, int type, int_str *val)
{
ht_t* ht;
ht_t *ht;
ht = ht_get_table(hname);
if(ht==NULL)
if(ht == NULL)
return -1;
if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, hname, name, type, val, 0)!=0) {
if(ht->dmqreplicate > 0
&& ht_dmq_replicate_action(
HT_DMQ_SET_CELL_EXPIRE, hname, name, type, val, 0)
!= 0) {
LM_ERR("dmq replication failed\n");
}
return ht_set_cell_expire(ht, name, type, val);
Expand All @@ -81,12 +87,11 @@ int ht_api_set_cell_expire(str *hname, str *name,
/**
*
*/
int ht_api_get_cell_expire(str *hname, str *name,
unsigned int *val)
int ht_api_get_cell_expire(str *hname, str *name, unsigned int *val)
{
ht_t* ht;
ht_t *ht;
ht = ht_get_table(hname);
if(ht==NULL)
if(ht == NULL)
return -1;
return ht_get_cell_expire(ht, name, val);
}
Expand All @@ -95,33 +100,35 @@ int ht_api_get_cell_expire(str *hname, str *name,
* get a clone in pkg for an htable item
* - returned pointer must be pkg_free() after use
*/
ht_cell_t* ht_api_get_cell_clone(str *hname, str *name)
ht_cell_t *ht_api_get_cell_clone(str *hname, str *name)
{
ht_t* ht;
ht = ht_get_table(hname);
if(ht==NULL)
return NULL;
return ht_cell_pkg_copy(ht, name, NULL);
ht_t *ht;
ht = ht_get_table(hname);
if(ht == NULL)
return NULL;
return ht_cell_pkg_copy(ht, name, NULL);
}

/**
*
*/
int ht_api_rm_cell_re(str *hname, str *sre, int mode)
{
ht_t* ht;
ht_t *ht;
int_str isval;
ht = ht_get_table(hname);
if(ht==NULL)
if(ht == NULL)
return -1;
if (ht->dmqreplicate>0) {
if(ht->dmqreplicate > 0) {
isval.s.s = sre->s;
isval.s.len = sre->len;
if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, hname, NULL, AVP_VAL_STR, &isval, mode)!=0) {
if(ht_dmq_replicate_action(
HT_DMQ_RM_CELL_RE, hname, NULL, AVP_VAL_STR, &isval, mode)
!= 0) {
LM_ERR("dmq replication failed\n");
}
}
if(ht_rm_cell_re(sre, ht, mode /* 0 - name; 1 - value */)<0)
if(ht_rm_cell_re(sre, ht, mode /* 0 - name; 1 - value */) < 0)
return -1;
return 0;
}
Expand All @@ -131,31 +138,30 @@ int ht_api_rm_cell_re(str *hname, str *sre, int mode)
*/
int ht_api_count_cells_re(str *hname, str *sre, int mode)
{
ht_t* ht;
ht_t *ht;
ht = ht_get_table(hname);
if(ht==NULL)
if(ht == NULL)
return -1;
if(ht_count_cells_re(sre, ht, mode /* 0 - name; 1 - value */)<0)
if(ht_count_cells_re(sre, ht, mode /* 0 - name; 1 - value */) < 0)
return -1;
return 0;
}

/**
*
*/
int bind_htable(htable_api_t* api)
int bind_htable(htable_api_t *api)
{
if (!api) {
if(!api) {
ERR("Invalid parameter value\n");
return -1;
}
api->set = ht_api_set_cell;
api->get_clone = ht_api_get_cell_clone;
api->rm = ht_api_del_cell;
api->rm = ht_api_del_cell;
api->set_expire = ht_api_set_cell_expire;
api->get_expire = ht_api_get_cell_expire;
api->rm_re = ht_api_rm_cell_re;
api->rm_re = ht_api_rm_cell_re;
api->count_re = ht_api_count_cells_re;
return 0;
}

24 changes: 12 additions & 12 deletions src/modules/htable/api.h
Expand Up @@ -25,20 +25,21 @@
#include "../../core/sr_module.h"
#include "../../core/usr_avp.h"

typedef int (*ht_api_set_cell_f)(str *hname, str *name, int type,
int_str *val, int mode);
typedef ht_cell_t* (*ht_api_get_cell_clone_f)(str *hname, str *name);
typedef int (*ht_api_set_cell_f)(
str *hname, str *name, int type, int_str *val, int mode);
typedef ht_cell_t *(*ht_api_get_cell_clone_f)(str *hname, str *name);
typedef int (*ht_api_del_cell_f)(str *hname, str *name);

typedef int (*ht_api_set_cell_expire_f)(str *hname, str *name,
int type, int_str *val);
typedef int (*ht_api_get_cell_expire_f)(str *hname, str *name,
unsigned int *val);
typedef int (*ht_api_set_cell_expire_f)(
str *hname, str *name, int type, int_str *val);
typedef int (*ht_api_get_cell_expire_f)(
str *hname, str *name, unsigned int *val);

typedef int (*ht_api_rm_cell_re_f)(str *hname, str *sre, int mode);
typedef int (*ht_api_count_cells_re_f)(str *hname, str *sre, int mode);

typedef struct htable_api {
typedef struct htable_api
{
ht_api_set_cell_f set;
ht_api_get_cell_clone_f get_clone;
ht_api_del_cell_f rm;
Expand All @@ -48,8 +49,8 @@ typedef struct htable_api {
ht_api_count_cells_re_f count_re;
} htable_api_t;

typedef int (*bind_htable_f)(htable_api_t* api);
int bind_htable(htable_api_t* api);
typedef int (*bind_htable_f)(htable_api_t *api);
int bind_htable(htable_api_t *api);

/**
* @brief Load the Sanity API
Expand All @@ -63,8 +64,7 @@ static inline int htable_load_api(htable_api_t *api)
LM_ERR("cannot find bind_htable\n");
return -1;
}
if(bindhtable(api)<0)
{
if(bindhtable(api) < 0) {
LM_ERR("cannot bind htable api\n");
return -1;
}
Expand Down

0 comments on commit e3a31a0

Please sign in to comment.