From 6e89f3e252dc6e8353ca3b7f2d7b29ab4173e8c8 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 17 May 2023 16:37:41 +0200 Subject: [PATCH] usrloc: clang-format for coherent indentation and coding style --- src/modules/usrloc/dlist.c | 383 ++++++++-------- src/modules/usrloc/dlist.h | 17 +- src/modules/usrloc/hslot.c | 21 +- src/modules/usrloc/hslot.h | 22 +- src/modules/usrloc/ucontact.c | 711 +++++++++++++++--------------- src/modules/usrloc/ucontact.h | 34 +- src/modules/usrloc/udomain.c | 695 +++++++++++++++-------------- src/modules/usrloc/udomain.h | 53 +-- src/modules/usrloc/ul_callback.c | 36 +- src/modules/usrloc/ul_callback.h | 50 +-- src/modules/usrloc/ul_keepalive.c | 148 +++---- src/modules/usrloc/ul_keepalive.h | 6 +- src/modules/usrloc/ul_rpc.c | 545 ++++++++++------------- src/modules/usrloc/urecord.c | 351 ++++++++------- src/modules/usrloc/urecord.h | 37 +- src/modules/usrloc/usrloc.c | 52 +-- src/modules/usrloc/usrloc.h | 255 +++++------ src/modules/usrloc/usrloc_mod.c | 493 +++++++++++---------- src/modules/usrloc/usrloc_mod.h | 34 +- 19 files changed, 1979 insertions(+), 1964 deletions(-) diff --git a/src/modules/usrloc/dlist.c b/src/modules/usrloc/dlist.c index 4e54f9628e5..57a9b4a9e45 100644 --- a/src/modules/usrloc/dlist.c +++ b/src/modules/usrloc/dlist.c @@ -28,16 +28,16 @@ #include "dlist.h" -#include /* abort */ -#include /* strlen, memcmp */ -#include /* printf */ +#include /* abort */ +#include /* strlen, memcmp */ +#include /* printf */ #include "../../core/ut.h" #include "../../lib/srdb1/db_ut.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 "usrloc.h" #include "utime.h" #include "ul_keepalive.h" @@ -64,14 +64,13 @@ void ul_set_max_partition(unsigned int m) * \param _d pointer to domain * \return 0 if the domain was found and 1 of not */ -static inline int find_dlist(str* _n, dlist_t** _d) +static inline int find_dlist(str *_n, dlist_t **_d) { - dlist_t* ptr; + dlist_t *ptr; ptr = _ksr_ul_root; while(ptr) { - if ((_n->len == ptr->name.len) && - !memcmp(_n->s, ptr->name.s, _n->len)) { + if((_n->len == ptr->name.len) && !memcmp(_n->s, ptr->name.s, _n->len)) { *_d = ptr; return 0; } @@ -87,11 +86,11 @@ static inline int find_dlist(str* _n, dlist_t** _d) */ int ul_ka_db_records(int partidx) { - db1_res_t* res = NULL; + db1_res_t *res = NULL; db_row_t *row = NULL; db_key_t keys1[4]; /* where */ db_val_t vals1[4]; - db_op_t ops1[4]; + db_op_t ops1[4]; db_key_t keys2[9]; /* select */ int n[2] = {2, 9}; /* number of dynamic values used on key1/key2 */ dlist_t *dom = NULL; @@ -126,12 +125,12 @@ int ul_ka_db_records(int partidx) ops1[1] = OP_EQ; vals1[1].type = DB1_INT; vals1[1].nul = 0; - if(_ul_max_partition>0) + if(_ul_max_partition > 0) vals1[1].val.int_val = partidx; else vals1[1].val.int_val = 0; - if (ul_ka_mode & ULKA_NAT) { + if(ul_ka_mode & ULKA_NAT) { keys1[n[0]] = &ul_keepalive_col; ops1[n[0]] = OP_EQ; vals1[n[0]].type = DB1_INT; @@ -139,7 +138,7 @@ int ul_ka_db_records(int partidx) vals1[n[0]].val.int_val = 1; n[0]++; } - if(ul_ka_filter&GAU_OPT_SERVER_ID) { + if(ul_ka_filter & GAU_OPT_SERVER_ID) { keys1[n[0]] = &ul_srv_id_col; ops1[n[0]] = OP_EQ; vals1[n[0]].type = DB1_INT; @@ -148,17 +147,18 @@ int ul_ka_db_records(int partidx) n[0]++; } - for (dom = _ksr_ul_root; dom!=NULL ; dom=dom->next) { - if (ul_dbf.use_table(ul_dbh, dom->d->name) < 0) { + for(dom = _ksr_ul_root; dom != NULL; dom = dom->next) { + if(ul_dbf.use_table(ul_dbh, dom->d->name) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.query(ul_dbh, keys1, ops1, vals1, keys2, - n[0], n[1], NULL, &res) <0 ) { + if(ul_dbf.query( + ul_dbh, keys1, ops1, vals1, keys2, n[0], n[1], NULL, &res) + < 0) { LM_ERR("query error\n"); return -1; } - if( RES_ROW_N(res)==0 ) { + if(RES_ROW_N(res) == 0) { ul_dbf.free_result(ul_dbh, res); continue; } @@ -169,8 +169,9 @@ int ul_ka_db_records(int partidx) memset(&uc, 0, sizeof(ucontact_t)); /* received */ - uc.received.s = (char*)VAL_STRING(ROW_VALUES(row)); - if ( VAL_NULL(ROW_VALUES(row)) || uc.received.s==0 || uc.received.s[0]==0 ) { + uc.received.s = (char *)VAL_STRING(ROW_VALUES(row)); + if(VAL_NULL(ROW_VALUES(row)) || uc.received.s == 0 + || uc.received.s[0] == 0) { uc.received.s = NULL; uc.received.len = 0; } else { @@ -178,8 +179,8 @@ int ul_ka_db_records(int partidx) } /* contact */ - uc.c.s = (char*)VAL_STRING(ROW_VALUES(row)+1); - if (VAL_NULL(ROW_VALUES(row)+1) || uc.c.s==0 || uc.c.s[0]==0) { + uc.c.s = (char *)VAL_STRING(ROW_VALUES(row) + 1); + if(VAL_NULL(ROW_VALUES(row) + 1) || uc.c.s == 0 || uc.c.s[0] == 0) { LM_ERR("empty contact -> skipping\n"); continue; } else { @@ -187,8 +188,9 @@ int ul_ka_db_records(int partidx) } /* path */ - uc.path.s = (char*)VAL_STRING(ROW_VALUES(row)+4); - if (VAL_NULL(ROW_VALUES(row)+4) || uc.path.s==0 || uc.path.s[0]==0){ + uc.path.s = (char *)VAL_STRING(ROW_VALUES(row) + 4); + if(VAL_NULL(ROW_VALUES(row) + 4) || uc.path.s == 0 + || uc.path.s[0] == 0) { uc.path.s = NULL; uc.path.len = 0; } else { @@ -196,25 +198,26 @@ int ul_ka_db_records(int partidx) } /* ruid */ - uc.ruid.s = (char*)VAL_STRING(ROW_VALUES(row)+5); - if (VAL_NULL(ROW_VALUES(row)+5) || uc.ruid.s==0 || uc.ruid.s[0]==0){ + uc.ruid.s = (char *)VAL_STRING(ROW_VALUES(row) + 5); + if(VAL_NULL(ROW_VALUES(row) + 5) || uc.ruid.s == 0 + || uc.ruid.s[0] == 0) { uc.ruid.s = NULL; uc.ruid.len = 0; } else { uc.ruid.len = strlen(uc.ruid.s); } /* sock */ - p = (char*)VAL_STRING(ROW_VALUES(row) + 2); - if (VAL_NULL(ROW_VALUES(row)+2) || p==0 || p[0]==0){ + p = (char *)VAL_STRING(ROW_VALUES(row) + 2); + if(VAL_NULL(ROW_VALUES(row) + 2) || p == 0 || p[0] == 0) { uc.sock = 0; } else { - if (parse_phostport(p, &host.s, &host.len, - &port, &proto)!=0) { + if(parse_phostport(p, &host.s, &host.len, &port, &proto) != 0) { LM_ERR("bad socket <%s>...set to 0\n", p); uc.sock = 0; } else { - uc.sock = grep_sock_info( &host, (unsigned short)port, proto); - if (uc.sock==0) { + uc.sock = + grep_sock_info(&host, (unsigned short)port, proto); + if(uc.sock == 0) { LM_DBG("non-local socket <%s>...set to 0\n", p); } } @@ -231,8 +234,8 @@ int ul_ka_db_records(int partidx) ur.domain = &dom->name; /* user */ - p = (char*)VAL_STRING(ROW_VALUES(row) + 6); - if (VAL_NULL(ROW_VALUES(row)+6) || p==0 || p[0]==0) { + p = (char *)VAL_STRING(ROW_VALUES(row) + 6); + if(VAL_NULL(ROW_VALUES(row) + 6) || p == 0 || p[0] == 0) { LM_ERR("empty username -> skipping\n"); continue; } @@ -244,8 +247,8 @@ int ul_ka_db_records(int partidx) strcpy(aorbuf, p); /* domain */ - p = (char*)VAL_STRING(ROW_VALUES(row) + 7); - if (!(VAL_NULL(ROW_VALUES(row)+7) || p==0 || p[0]==0)) { + p = (char *)VAL_STRING(ROW_VALUES(row) + 7); + if(!(VAL_NULL(ROW_VALUES(row) + 7) || p == 0 || p[0] == 0)) { if(ur.aor.len + strlen(p) >= ULKA_AORBUF_SIZE - 2) { LM_DBG("long aor ->skipping\n"); continue; @@ -258,7 +261,7 @@ int ul_ka_db_records(int partidx) ur.contacts = &uc; /* tcpconn_id */ - uc.tcpconn_id = VAL_INT(ROW_VALUES(row)+8); + uc.tcpconn_id = VAL_INT(ROW_VALUES(row) + 8); ul_ka_urecord(&ur); } /* row cycle */ @@ -281,12 +284,11 @@ int ul_ka_db_records(int partidx) * \return 0 on success, positive if buffer size was not sufficient, negative on failure */ static inline int get_all_db_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) { struct socket_info *sock; unsigned int dbflags; - db1_res_t* res = NULL; + db1_res_t *res = NULL; db_row_t *row; dlist_t *dom; int port, proto; @@ -302,9 +304,9 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, int shortage, needed; db_key_t keys1[4]; /* where */ db_val_t vals1[4]; - db_op_t ops1[4]; + db_op_t ops1[4]; db_key_t keys2[6]; /* select */ - int n[2] = {2,6}; /* number of dynamic values used on key1/key2 */ + int n[2] = {2, 6}; /* number of dynamic values used on key1/key2 */ cp = buf; shortage = 0; @@ -331,12 +333,12 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, ops1[1] = OP_EQ; vals1[1].type = DB1_INT; vals1[1].nul = 0; - if(_ul_max_partition>0) + if(_ul_max_partition > 0) vals1[1].val.int_val = part_idx; else vals1[1].val.int_val = 0; - if (flags & ul_nat_bflag) { + if(flags & ul_nat_bflag) { keys1[n[0]] = &ul_keepalive_col; ops1[n[0]] = OP_EQ; vals1[n[0]].type = DB1_INT; @@ -344,7 +346,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, vals1[n[0]].val.int_val = 1; n[0]++; } - if(options&GAU_OPT_SERVER_ID) { + if(options & GAU_OPT_SERVER_ID) { keys1[n[0]] = &ul_srv_id_col; ops1[n[0]] = OP_EQ; vals1[n[0]].type = DB1_INT; @@ -355,17 +357,18 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, /* TODO: use part_idx and part_max on keys1 */ - for (dom = _ksr_ul_root; dom!=NULL ; dom=dom->next) { - if (ul_dbf.use_table(ul_dbh, dom->d->name) < 0) { + for(dom = _ksr_ul_root; dom != NULL; dom = dom->next) { + if(ul_dbf.use_table(ul_dbh, dom->d->name) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.query(ul_dbh, keys1, ops1, vals1, keys2, - n[0], n[1], NULL, &res) <0 ) { + if(ul_dbf.query( + ul_dbh, keys1, ops1, vals1, keys2, n[0], n[1], NULL, &res) + < 0) { LM_ERR("query error\n"); return -1; } - if( RES_ROW_N(res)==0 ) { + if(RES_ROW_N(res) == 0) { ul_dbf.free_result(ul_dbh, res); continue; } @@ -375,28 +378,26 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, /* received */ - recv.s = (char*)VAL_STRING(ROW_VALUES(row)); - if ( VAL_NULL(ROW_VALUES(row)) || recv.s==0 || recv.s[0]==0 ) { + recv.s = (char *)VAL_STRING(ROW_VALUES(row)); + if(VAL_NULL(ROW_VALUES(row)) || recv.s == 0 || recv.s[0] == 0) { recv.s = NULL; recv.len = 0; - } - else { + } else { recv.len = strlen(recv.s); } /* contact */ - addr.s = (char*)VAL_STRING(ROW_VALUES(row)+1); - if (VAL_NULL(ROW_VALUES(row)+1) || addr.s==0 || addr.s[0]==0) { + addr.s = (char *)VAL_STRING(ROW_VALUES(row) + 1); + if(VAL_NULL(ROW_VALUES(row) + 1) || addr.s == 0 || addr.s[0] == 0) { LM_ERR("empty contact -> skipping\n"); continue; - } - else { + } else { addr.len = strlen(addr.s); } /* path */ - path.s = (char*)VAL_STRING(ROW_VALUES(row)+4); - if (VAL_NULL(ROW_VALUES(row)+4) || path.s==0 || path.s[0]==0){ + path.s = (char *)VAL_STRING(ROW_VALUES(row) + 4); + if(VAL_NULL(ROW_VALUES(row) + 4) || path.s == 0 || path.s[0] == 0) { path.s = NULL; path.len = 0; } else { @@ -404,52 +405,49 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, } /* ruid */ - ruid.s = (char*)VAL_STRING(ROW_VALUES(row)+5); - if (VAL_NULL(ROW_VALUES(row)+5) || ruid.s==0 || ruid.s[0]==0){ + ruid.s = (char *)VAL_STRING(ROW_VALUES(row) + 5); + if(VAL_NULL(ROW_VALUES(row) + 5) || ruid.s == 0 || ruid.s[0] == 0) { ruid.s = NULL; ruid.len = 0; } else { ruid.len = strlen(ruid.s); } - needed = (int)(sizeof(addr.len) + addr.len - + sizeof(recv.len) + recv.len - + sizeof(sock) + sizeof(dbflags) - + sizeof(path.len) + path.len - + sizeof(ruid.len) + ruid.len - + sizeof(aorhash)); - if (len < needed) { - shortage += needed ; + needed = (int)(sizeof(addr.len) + addr.len + sizeof(recv.len) + + recv.len + sizeof(sock) + sizeof(dbflags) + + sizeof(path.len) + path.len + sizeof(ruid.len) + + ruid.len + sizeof(aorhash)); + if(len < needed) { + shortage += needed; continue; } /* write contact */ memcpy(cp, &addr.len, sizeof(addr.len)); - cp = (char*)cp + sizeof(addr.len); + cp = (char *)cp + sizeof(addr.len); memcpy(cp, addr.s, addr.len); - cp = (char*)cp + addr.len; + cp = (char *)cp + addr.len; /* write received */ memcpy(cp, &recv.len, sizeof(recv.len)); - cp = (char*)cp + sizeof(recv.len); + cp = (char *)cp + sizeof(recv.len); /* copy received only if exist */ - if(recv.len){ + if(recv.len) { memcpy(cp, recv.s, recv.len); - cp = (char*)cp + recv.len; + cp = (char *)cp + recv.len; } /* sock */ - p = (char*)VAL_STRING(ROW_VALUES(row) + 2); - if (VAL_NULL(ROW_VALUES(row)+2) || p==0 || p[0]==0){ + p = (char *)VAL_STRING(ROW_VALUES(row) + 2); + if(VAL_NULL(ROW_VALUES(row) + 2) || p == 0 || p[0] == 0) { sock = 0; } else { - if (parse_phostport( p, &host.s, &host.len, - &port, &proto)!=0) { + if(parse_phostport(p, &host.s, &host.len, &port, &proto) != 0) { LM_ERR("bad socket <%s>...set to 0\n", p); sock = 0; } else { - sock = grep_sock_info( &host, (unsigned short)port, proto); - if (sock==0) { + sock = grep_sock_info(&host, (unsigned short)port, proto); + if(sock == 0) { LM_DBG("non-local socket <%s>...set to 0\n", p); } } @@ -460,31 +458,31 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, /* write sock and flags */ memcpy(cp, &sock, sizeof(sock)); - cp = (char*)cp + sizeof(sock); + cp = (char *)cp + sizeof(sock); memcpy(cp, &dbflags, sizeof(dbflags)); - cp = (char*)cp + sizeof(dbflags); + cp = (char *)cp + sizeof(dbflags); /* write path */ memcpy(cp, &path.len, sizeof(path.len)); - cp = (char*)cp + sizeof(path.len); + cp = (char *)cp + sizeof(path.len); /* copy path only if exist */ - if(path.len){ + if(path.len) { memcpy(cp, path.s, path.len); - cp = (char*)cp + path.len; + cp = (char *)cp + path.len; } /* write ruid */ memcpy(cp, &ruid.len, sizeof(ruid.len)); - cp = (char*)cp + sizeof(ruid.len); + cp = (char *)cp + sizeof(ruid.len); /* copy ruid only if exist */ - if(ruid.len){ + if(ruid.len) { memcpy(cp, ruid.s, ruid.len); - cp = (char*)cp + ruid.len; + cp = (char *)cp + ruid.len; } /* aorhash not used for db-only records, but it is added * (as 0) to match the struct used for mem records */ memcpy(cp, &aorhash, sizeof(aorhash)); - cp = (char*)cp + sizeof(aorhash); + cp = (char *)cp + sizeof(aorhash); len -= needed; } /* row cycle */ @@ -493,11 +491,11 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, } /* domain cycle */ /* len < 0 is possible, if size of the buffer < sizeof(c->c.len) */ - if (len >= 0) + if(len >= 0) memset(cp, 0, sizeof(addr.len)); /* Shouldn't happen */ - if (shortage > 0 && len > shortage) { + if(shortage > 0 && len > shortage) { abort(); } @@ -519,8 +517,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, * \return 0 on success, positive if buffer size was not sufficient, negative on failure */ static inline int get_all_mem_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) { dlist_t *p; urecord_t *r; @@ -534,45 +531,42 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags, time_t tnow = 0; - if(ul_keepalive_timeout>0) + if(ul_keepalive_timeout > 0) tnow = time(NULL); /* Reserve space for terminating 0000 */ len -= sizeof(c->c.len); - for (p = _ksr_ul_root; p != NULL; p = p->next) { + for(p = _ksr_ul_root; p != NULL; p = p->next) { - for(i=0; id->size; i++) { + for(i = 0; i < p->d->size; i++) { - if ( (i % part_max) != part_idx ) + if((i % part_max) != part_idx) continue; lock_ulslot(p->d, i); - if(p->d->table[i].n<=0) - { + if(p->d->table[i].n <= 0) { unlock_ulslot(p->d, i); continue; } - for (r = p->d->table[i].first; r != NULL; r = r->next) { - for (c = r->contacts; c != NULL; c = c->next) { - if (c->c.len <= 0) + for(r = p->d->table[i].first; r != NULL; r = r->next) { + for(c = r->contacts; c != NULL; c = c->next) { + if(c->c.len <= 0) continue; /* * List only contacts that have all requested * flags set */ - if ((c->cflags & flags) != flags) + if((c->cflags & flags) != flags) continue; - if(options&GAU_OPT_SERVER_ID && server_id!=c->server_id) + if(options & GAU_OPT_SERVER_ID && server_id != c->server_id) continue; - if(ul_keepalive_timeout>0 && c->last_keepalive>0) - { - if(c->sock!=NULL && c->sock->proto==PROTO_UDP) - { - if(c->last_keepalive+ul_keepalive_timeout < tnow) - { + if(ul_keepalive_timeout > 0 && c->last_keepalive > 0) { + if(c->sock != NULL && c->sock->proto == PROTO_UDP) { + if(c->last_keepalive + ul_keepalive_timeout + < tnow) { /* set contact as expired in 10s */ if(c->expires > tnow + 10) c->expires = tnow + 10; @@ -582,34 +576,34 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags, } needed = (int)(sizeof(c->c.len) + c->c.len - + sizeof(c->received.len) + c->received.len - + sizeof(c->sock) + sizeof(c->cflags) - + sizeof(c->path.len) + c->path.len - + sizeof(c->ruid.len) + c->ruid.len - + sizeof(r->aorhash)); - if (len >= needed) { + + sizeof(c->received.len) + c->received.len + + sizeof(c->sock) + sizeof(c->cflags) + + sizeof(c->path.len) + c->path.len + + sizeof(c->ruid.len) + c->ruid.len + + sizeof(r->aorhash)); + if(len >= needed) { memcpy(cp, &c->c.len, sizeof(c->c.len)); - cp = (char*)cp + sizeof(c->c.len); + cp = (char *)cp + sizeof(c->c.len); memcpy(cp, c->c.s, c->c.len); - cp = (char*)cp + c->c.len; - memcpy(cp,&c->received.len,sizeof(c->received.len)); - cp = (char*)cp + sizeof(c->received.len); + cp = (char *)cp + c->c.len; + memcpy(cp, &c->received.len, sizeof(c->received.len)); + cp = (char *)cp + sizeof(c->received.len); memcpy(cp, c->received.s, c->received.len); - cp = (char*)cp + c->received.len; + cp = (char *)cp + c->received.len; memcpy(cp, &c->sock, sizeof(c->sock)); - cp = (char*)cp + sizeof(c->sock); + cp = (char *)cp + sizeof(c->sock); memcpy(cp, &c->cflags, sizeof(c->cflags)); - cp = (char*)cp + sizeof(c->cflags); + cp = (char *)cp + sizeof(c->cflags); memcpy(cp, &c->path.len, sizeof(c->path.len)); - cp = (char*)cp + sizeof(c->path.len); + cp = (char *)cp + sizeof(c->path.len); memcpy(cp, c->path.s, c->path.len); - cp = (char*)cp + c->path.len; + cp = (char *)cp + c->path.len; memcpy(cp, &c->ruid.len, sizeof(c->ruid.len)); - cp = (char*)cp + sizeof(c->ruid.len); + cp = (char *)cp + sizeof(c->ruid.len); memcpy(cp, c->ruid.s, c->ruid.len); - cp = (char*)cp + c->ruid.len; + cp = (char *)cp + c->ruid.len; memcpy(cp, &r->aorhash, sizeof(r->aorhash)); - cp = (char*)cp + sizeof(r->aorhash); + cp = (char *)cp + sizeof(r->aorhash); len -= needed; } else { shortage += needed; @@ -620,11 +614,11 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags, } } /* len < 0 is possible, if size of the buffer < sizeof(c->c.len) */ - if (len >= 0) + if(len >= 0) memset(cp, 0, sizeof(c->c.len)); /* Shouldn't happen */ - if (shortage > 0 && len > shortage) { + if(shortage > 0 && len > shortage) { abort(); } @@ -634,7 +628,6 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags, } - /*! * \brief Get all contacts from the usrloc, in partitions if wanted * @@ -669,21 +662,22 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags, * \return 0 on success, positive if buffer size was not sufficient, negative on failure */ 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) { - if (ul_db_mode==DB_ONLY) - return get_all_db_ucontacts( buf, len, flags, part_idx, part_max, options); + if(ul_db_mode == DB_ONLY) + return get_all_db_ucontacts( + buf, len, flags, part_idx, part_max, options); else - return get_all_mem_ucontacts( buf, len, flags, part_idx, part_max, options); + return get_all_mem_ucontacts( + buf, len, flags, part_idx, part_max, options); } /** * */ -int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval, - unsigned int rtrip) +int ul_update_keepalive( + unsigned int _aorhash, str *_ruid, time_t tval, unsigned int rtrip) { dlist_t *p; urecord_t *r; @@ -692,32 +686,28 @@ int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval, /* todo: get location domain via param */ - for (p = _ksr_ul_root; p != NULL; p = p->next) - { - i = _aorhash&(p->d->size-1); + for(p = _ksr_ul_root; p != NULL; p = p->next) { + i = _aorhash & (p->d->size - 1); lock_ulslot(p->d, i); - if(p->d->table[i].n<=0) - { + if(p->d->table[i].n <= 0) { unlock_ulslot(p->d, i); continue; } - for (r = p->d->table[i].first; r != NULL; r = r->next) - { - if(r->aorhash==_aorhash) - { - for (c = r->contacts; c != NULL; c = c->next) - { - if (c->c.len <= 0 || c->ruid.len<=0) + for(r = p->d->table[i].first; r != NULL; r = r->next) { + if(r->aorhash == _aorhash) { + for(c = r->contacts; c != NULL; c = c->next) { + if(c->c.len <= 0 || c->ruid.len <= 0) continue; - if(c->ruid.len==_ruid->len - && !memcmp(c->ruid.s, _ruid->s, _ruid->len)) - { + if(c->ruid.len == _ruid->len + && !memcmp(c->ruid.s, _ruid->s, _ruid->len)) { /* found */ c->last_keepalive = tval; c->ka_roundtrip = rtrip; - LM_DBG("updated keepalive for [%.*s:%u] to %u (rtrip: %u)\n", + LM_DBG("updated keepalive for [%.*s:%u] to %u (rtrip: " + "%u)\n", _ruid->len, _ruid->s, _aorhash, - (unsigned int)c->last_keepalive, c->ka_roundtrip); + (unsigned int)c->last_keepalive, + c->ka_roundtrip); unlock_ulslot(p->d, i); return 0; } @@ -746,23 +736,23 @@ int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid) * function must be called before the server forks if it should * be available to all processes */ -static inline int new_dlist(str* _n, dlist_t** _d) +static inline int new_dlist(str *_n, dlist_t **_d) { - dlist_t* ptr; + dlist_t *ptr; /* Domains are created before ser forks, * so we can create them using pkg_malloc */ - ptr = (dlist_t*)shm_malloc(sizeof(dlist_t)); - if (ptr == 0) { + ptr = (dlist_t *)shm_malloc(sizeof(dlist_t)); + if(ptr == 0) { SHM_MEM_ERROR; return -1; } memset(ptr, 0, sizeof(dlist_t)); /* copy domain name as null terminated string */ - ptr->name.s = (char*)shm_malloc(_n->len+1); - if (ptr->name.s == 0) { + ptr->name.s = (char *)shm_malloc(_n->len + 1); + if(ptr->name.s == 0) { SHM_MEM_ERROR; shm_free(ptr); return -2; @@ -772,7 +762,7 @@ static inline int new_dlist(str* _n, dlist_t** _d) ptr->name.len = _n->len; ptr->name.s[ptr->name.len] = 0; - if (new_udomain(&(ptr->name), ul_hash_size, &(ptr->d)) < 0) { + if(new_udomain(&(ptr->name), ul_hash_size, &(ptr->d)) < 0) { LM_ERR("creating domain structure failed\n"); shm_free(ptr->name.s); shm_free(ptr); @@ -791,9 +781,9 @@ static inline int new_dlist(str* _n, dlist_t** _d) * \param _d usrloc domain * \return 0 on success, -1 on failure */ -int get_udomain(const char* _n, udomain_t** _d) +int get_udomain(const char *_n, udomain_t **_d) { - dlist_t* d; + dlist_t *d; str s; if(_n == NULL) { @@ -801,14 +791,14 @@ int get_udomain(const char* _n, udomain_t** _d) goto notfound; } - s.s = (char*)_n; + s.s = (char *)_n; s.len = strlen(_n); if(s.len <= 0) { LM_ERR("empty location table name\n"); goto notfound; } - if (find_dlist(&s, &d) == 0) { + if(find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } @@ -828,21 +818,21 @@ int get_udomain(const char* _n, udomain_t** _d) * \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) { - dlist_t* d; + dlist_t *d; str s; - db1_con_t* con; + db1_con_t *con; - s.s = (char*)_n; + s.s = (char *)_n; s.len = strlen(_n); - if (find_dlist(&s, &d) == 0) { + if(find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } - if (new_dlist(&s, &d) < 0) { + if(new_dlist(&s, &d) < 0) { LM_ERR("failed to create new domain\n"); return -1; } @@ -850,20 +840,21 @@ int register_udomain(const char* _n, udomain_t** _d) /* Test tables from database if we are gonna * to use database */ - if (ul_db_mode != NO_DB) { + if(ul_db_mode != NO_DB) { con = ul_dbf.init(&ul_db_url); - if (!con) { + if(!con) { LM_ERR("failed to open database connection\n"); goto dberror; } if(ul_version_table != 0 - && db_check_table_version(&ul_dbf, con, &s, UL_TABLE_VERSION) < 0) { + && db_check_table_version(&ul_dbf, con, &s, UL_TABLE_VERSION) + < 0) { DB_TABLE_VERSION_ERROR(s); goto dberror; } /* test if DB really exists */ - if (testdb_udomain(con, d->d) < 0) { + if(testdb_udomain(con, d->d) < 0) { LM_ERR("testing domain '%.*s' failed\n", s.len, ZSW(s.s)); goto dberror; } @@ -879,7 +870,8 @@ int register_udomain(const char* _n, udomain_t** _d) return 0; dberror: - if (con) ul_dbf.close(con); + if(con) + ul_dbf.close(con); con = 0; free_udomain(d->d); shm_free(d->name.s); @@ -893,7 +885,7 @@ int register_udomain(const char* _n, udomain_t** _d) */ void free_all_udomains(void) { - dlist_t* ptr; + dlist_t *ptr; while(_ksr_ul_root) { ptr = _ksr_ul_root; @@ -910,9 +902,9 @@ void free_all_udomains(void) * \brief Print all domains, just for debugging * \param _f output file */ -void print_all_udomains(FILE* _f) +void print_all_udomains(FILE *_f) { - dlist_t* ptr; + dlist_t *ptr; ptr = _ksr_ul_root; @@ -933,14 +925,13 @@ unsigned long get_number_of_users(void) { long numberOfUsers = 0; - dlist_t* current_dlist; + dlist_t *current_dlist; current_dlist = _ksr_ul_root; - while (current_dlist) - { + while(current_dlist) { numberOfUsers += get_stat_val(current_dlist->d->users); - current_dlist = current_dlist->next; + current_dlist = current_dlist->next; } return numberOfUsers; @@ -954,21 +945,21 @@ unsigned long get_number_of_users(void) int synchronize_all_udomains(int istart, int istep) { int res = 0; - dlist_t* ptr; + dlist_t *ptr; ul_get_act_time(); /* Get and save actual time */ - if (ul_db_mode==DB_ONLY) { + if(ul_db_mode == DB_ONLY) { if(istart == 0) { - for( ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) { + for(ptr = _ksr_ul_root; ptr; ptr = ptr->next) { res |= db_timer_udomain(ptr->d); } } - if (ul_ka_mode != ULKA_NONE) { + if(ul_ka_mode != ULKA_NONE) { ul_ka_db_records((unsigned int)istart); } } else { - for( ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) { + for(ptr = _ksr_ul_root; ptr; ptr = ptr->next) { mem_timer_udomain(ptr->d, istart, istep); } } @@ -983,11 +974,11 @@ int synchronize_all_udomains(int istart, int istep) int ul_db_clean_udomains(void) { int res = 0; - dlist_t* ptr; + dlist_t *ptr; ul_get_act_time(); /* Get and save actual time */ - for( ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) + for(ptr = _ksr_ul_root; ptr; ptr = ptr->next) res |= db_timer_udomain(ptr->d); return res; @@ -999,12 +990,12 @@ int ul_db_clean_udomains(void) * \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) { - dlist_t* d; + dlist_t *d; - if (find_dlist(_d, &d) == 0) { - *_p = d->d; + if(find_dlist(_d, &d) == 0) { + *_p = d->d; return 0; } diff --git a/src/modules/usrloc/dlist.h b/src/modules/usrloc/dlist.h index 0362b6f0cb1..ad68a8a00dc 100644 --- a/src/modules/usrloc/dlist.h +++ b/src/modules/usrloc/dlist.h @@ -36,10 +36,11 @@ /*! * List of all domains registered with usrloc */ -typedef struct dlist { - str name; /*!< Name of the domain (null terminated) */ - udomain_t* d; /*!< Payload */ - struct dlist* next; /*!< Next element in the list */ +typedef struct dlist +{ + str name; /*!< Name of the domain (null terminated) */ + udomain_t *d; /*!< Payload */ + struct dlist *next; /*!< Next element in the list */ } dlist_t; /*! \brief Global list of all registered domains */ @@ -56,7 +57,7 @@ extern dlist_t *_ksr_ul_root; * \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); /*! @@ -69,7 +70,7 @@ void free_all_udomains(void); * \brief Print all domains, just for debugging * \param _f output file */ -void print_all_udomains(FILE* _f); +void print_all_udomains(FILE *_f); /*! @@ -123,7 +124,7 @@ int get_all_ucontacts(void *buf, int len, unsigned int flags, * \param _d usrloc domain (location table) * \return 0 on success, -1 on failure */ - int get_udomain(const char* _n, udomain_t** _d); +int get_udomain(const char *_n, udomain_t **_d); /*! * \brief Loops through all domains summing up the number of users @@ -138,7 +139,7 @@ unsigned long get_number_of_users(void); * \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); /*! diff --git a/src/modules/usrloc/hslot.c b/src/modules/usrloc/hslot.c index 9133997d36a..8345e35dd75 100644 --- a/src/modules/usrloc/hslot.c +++ b/src/modules/usrloc/hslot.c @@ -26,7 +26,6 @@ */ - #include "hslot.h" /*! @@ -35,13 +34,13 @@ * \param _s hash slot * \param n used to get the slot number (modulo number or locks) */ -int init_slot(struct udomain* _d, hslot_t* _s, int n) +int init_slot(struct udomain *_d, hslot_t *_s, int n) { _s->n = 0; _s->first = 0; _s->last = 0; _s->d = _d; - if(rec_lock_init(&_s->rlock)==NULL) { + if(rec_lock_init(&_s->rlock) == NULL) { LM_ERR("failed to initialize the slock (%d)\n", n); return -1; } @@ -53,9 +52,9 @@ int init_slot(struct udomain* _d, hslot_t* _s, int n) * \brief Deinitialize given slot structure * \param _s hash slot */ -void deinit_slot(hslot_t* _s) +void deinit_slot(hslot_t *_s) { - struct urecord* ptr; + struct urecord *ptr; /* Remove all elements */ while(_s->first) { @@ -67,7 +66,7 @@ void deinit_slot(hslot_t* _s) _s->n = 0; _s->last = 0; - _s->d = 0; + _s->d = 0; } @@ -76,9 +75,9 @@ void deinit_slot(hslot_t* _s) * \param _s hash slot * \param _r added record */ -void slot_add(hslot_t* _s, struct urecord* _r) +void slot_add(hslot_t *_s, struct urecord *_r) { - if (_s->n == 0) { + if(_s->n == 0) { _s->first = _s->last = _r; } else { _r->prev = _s->last; @@ -95,15 +94,15 @@ void slot_add(hslot_t* _s, struct urecord* _r) * \param _s hash slot * \param _r removed record */ -void slot_rem(hslot_t* _s, struct urecord* _r) +void slot_rem(hslot_t *_s, struct urecord *_r) { - if (_r->prev) { + if(_r->prev) { _r->prev->next = _r->next; } else { _s->first = _r->next; } - if (_r->next) { + if(_r->next) { _r->next->prev = _r->prev; } else { _s->last = _r->prev; diff --git a/src/modules/usrloc/hslot.h b/src/modules/usrloc/hslot.h index c891fb99fe7..61cd3778130 100644 --- a/src/modules/usrloc/hslot.h +++ b/src/modules/usrloc/hslot.h @@ -24,7 +24,6 @@ */ - #ifndef HSLOT_H #define HSLOT_H @@ -38,35 +37,36 @@ struct udomain; struct urecord; -typedef struct hslot { - int n; /*!< Number of elements in the collision slot */ - struct urecord* first; /*!< First element in the list */ - struct urecord* last; /*!< Last element in the list */ - struct udomain* d; /*!< Domain we belong to */ - rec_lock_t rlock; /*!< Recursive lock for hash entry */ +typedef struct hslot +{ + int n; /*!< Number of elements in the collision slot */ + struct urecord *first; /*!< First element in the list */ + struct urecord *last; /*!< Last element in the list */ + struct udomain *d; /*!< Domain we belong to */ + rec_lock_t rlock; /*!< Recursive lock for hash entry */ } hslot_t; /*! \brief * Initialize slot structure */ -int init_slot(struct udomain* _d, hslot_t* _s, int n); +int init_slot(struct udomain *_d, hslot_t *_s, int n); /*! \brief * Deinitialize given slot structure */ -void deinit_slot(hslot_t* _s); +void deinit_slot(hslot_t *_s); /*! \brief * Add an element to slot linked list */ -void slot_add(hslot_t* _s, struct urecord* _r); +void slot_add(hslot_t *_s, struct urecord *_r); /*! \brief * Remove an element from slot linked list */ -void slot_rem(hslot_t* _s, struct urecord* _r); +void slot_rem(hslot_t *_s, struct urecord *_r); #endif /* HSLOT_H */ diff --git a/src/modules/usrloc/ucontact.c b/src/modules/usrloc/ucontact.c index 08e98c6a324..fbb16e4b88d 100644 --- a/src/modules/usrloc/ucontact.c +++ b/src/modules/usrloc/ucontact.c @@ -56,16 +56,17 @@ void ul_set_xavp_contact_clone(int v) void ucontact_xavp_store(ucontact_t *_c) { sr_xavp_t *xavp; - if(_c==NULL) + if(_c == NULL) return; if(ul_xavp_contact_clone == 0) return; - if(ul_xavp_contact_name.s==NULL) + if(ul_xavp_contact_name.s == NULL) return; /* remove old list if it is set -- update case */ - if (_c->xavp) xavp_destroy_list(&_c->xavp); + if(_c->xavp) + xavp_destroy_list(&_c->xavp); xavp = xavp_get(&ul_xavp_contact_name, NULL); - if(xavp==NULL) + if(xavp == NULL) return; /* clone the xavp found in core */ LM_DBG("trying to clone per contact xavps\n"); @@ -73,7 +74,7 @@ void ucontact_xavp_store(ucontact_t *_c) return; } -int uldb_delete_attrs_ruid(str* _dname, str *_ruid); +int uldb_delete_attrs_ruid(str *_dname, str *_ruid); /*! * \brief Create a new contact structure @@ -83,37 +84,45 @@ int uldb_delete_attrs_ruid(str* _dname, str *_ruid); * \param _ci contact informations * \return new created contact on success, 0 on failure */ -ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _ci) +ucontact_t *new_ucontact( + str *_dom, str *_aor, str *_contact, ucontact_info_t *_ci) { ucontact_t *c; - if(unlikely(_ci->ruid.len<=0)) { + if(unlikely(_ci->ruid.len <= 0)) { LM_ERR("no ruid for aor: %.*s\n", _aor->len, ZSW(_aor->s)); return 0; } - c = (ucontact_t*)shm_malloc(sizeof(ucontact_t)); - if (!c) { + c = (ucontact_t *)shm_malloc(sizeof(ucontact_t)); + if(!c) { SHM_MEM_ERROR; return 0; } memset(c, 0, sizeof(ucontact_t)); - if (shm_str_dup( &c->c, _contact) < 0) goto error; - if (shm_str_dup( &c->callid, _ci->callid) < 0) goto error; - if (shm_str_dup( &c->user_agent, _ci->user_agent) < 0) goto error; + if(shm_str_dup(&c->c, _contact) < 0) + goto error; + if(shm_str_dup(&c->callid, _ci->callid) < 0) + goto error; + if(shm_str_dup(&c->user_agent, _ci->user_agent) < 0) + goto error; - if (_ci->received.s && _ci->received.len) { - if (shm_str_dup( &c->received, &_ci->received) < 0) goto error; + if(_ci->received.s && _ci->received.len) { + if(shm_str_dup(&c->received, &_ci->received) < 0) + goto error; } - if (_ci->path && _ci->path->len) { - if (shm_str_dup( &c->path, _ci->path) < 0) goto error; + if(_ci->path && _ci->path->len) { + if(shm_str_dup(&c->path, _ci->path) < 0) + goto error; } - if (_ci->ruid.s && _ci->ruid.len) { - if (shm_str_dup( &c->ruid, &_ci->ruid) < 0) goto error; + if(_ci->ruid.s && _ci->ruid.len) { + if(shm_str_dup(&c->ruid, &_ci->ruid) < 0) + goto error; } - if (_ci->instance.s && _ci->instance.len) { - if (shm_str_dup( &c->instance, &_ci->instance) < 0) goto error; + if(_ci->instance.s && _ci->instance.len) { + if(shm_str_dup(&c->instance, &_ci->instance) < 0) + goto error; } c->domain = _dom; @@ -131,43 +140,59 @@ ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _ c->last_keepalive = time(NULL); c->tcpconn_id = _ci->tcpconn_id; c->server_id = _ci->server_id; - c->keepalive = (_ci->cflags & ul_nat_bflag)?1:0; + c->keepalive = (_ci->cflags & ul_nat_bflag) ? 1 : 0; ucontact_xavp_store(c); return c; error: SHM_MEM_ERROR; - if (c->path.s) shm_free(c->path.s); - if (c->received.s) shm_free(c->received.s); - if (c->user_agent.s) shm_free(c->user_agent.s); - if (c->callid.s) shm_free(c->callid.s); - if (c->c.s) shm_free(c->c.s); - if (c->ruid.s) shm_free(c->ruid.s); - if (c->instance.s) shm_free(c->instance.s); - if (c->xavp) xavp_destroy_list(&c->xavp); + if(c->path.s) + shm_free(c->path.s); + if(c->received.s) + shm_free(c->received.s); + if(c->user_agent.s) + shm_free(c->user_agent.s); + if(c->callid.s) + shm_free(c->callid.s); + if(c->c.s) + shm_free(c->c.s); + if(c->ruid.s) + shm_free(c->ruid.s); + if(c->instance.s) + shm_free(c->instance.s); + if(c->xavp) + xavp_destroy_list(&c->xavp); shm_free(c); return 0; } - /*! * \brief Free all memory associated with given contact structure * \param _c freed contact */ -void free_ucontact(ucontact_t* _c) +void free_ucontact(ucontact_t *_c) { - if (!_c) return; - if (_c->path.s) shm_free(_c->path.s); - if (_c->received.s) shm_free(_c->received.s); - if (_c->user_agent.s) shm_free(_c->user_agent.s); - if (_c->callid.s) shm_free(_c->callid.s); - if (_c->c.s) shm_free(_c->c.s); - if (_c->ruid.s) shm_free(_c->ruid.s); - if (_c->instance.s) shm_free(_c->instance.s); - if (_c->xavp) xavp_destroy_list(&_c->xavp); - shm_free( _c ); + if(!_c) + return; + if(_c->path.s) + shm_free(_c->path.s); + if(_c->received.s) + shm_free(_c->received.s); + if(_c->user_agent.s) + shm_free(_c->user_agent.s); + if(_c->callid.s) + shm_free(_c->callid.s); + if(_c->c.s) + shm_free(_c->c.s); + if(_c->ruid.s) + shm_free(_c->ruid.s); + if(_c->instance.s) + shm_free(_c->instance.s); + if(_c->xavp) + xavp_destroy_list(&_c->xavp); + shm_free(_c); } @@ -176,16 +201,24 @@ void free_ucontact(ucontact_t* _c) * \param _f output file * \param _c printed contact */ -void print_ucontact(FILE* _f, ucontact_t* _c) +void print_ucontact(FILE *_f, ucontact_t *_c) { time_t t = time(0); - char* st; + char *st; switch(_c->state) { - case CS_NEW: st = "CS_NEW"; break; - case CS_SYNC: st = "CS_SYNC"; break; - case CS_DIRTY: st = "CS_DIRTY"; break; - default: st = "CS_UNKNOWN"; break; + case CS_NEW: + st = "CS_NEW"; + break; + case CS_SYNC: + st = "CS_SYNC"; + break; + case CS_DIRTY: + st = "CS_DIRTY"; + break; + default: + st = "CS_UNKNOWN"; + break; } fprintf(_f, "~~~Contact(%p)~~~\n", _c); @@ -193,11 +226,11 @@ void print_ucontact(FILE* _f, ucontact_t* _c) fprintf(_f, "aor : '%.*s'\n", _c->aor->len, ZSW(_c->aor->s)); fprintf(_f, "Contact : '%.*s'\n", _c->c.len, ZSW(_c->c.s)); fprintf(_f, "Expires : "); - if (_c->expires == 0) { + if(_c->expires == 0) { fprintf(_f, "Permanent\n"); - } else if (_c->expires == UL_EXPIRED_TIME) { + } else if(_c->expires == UL_EXPIRED_TIME) { fprintf(_f, "Deleted\n"); - } else if (t > _c->expires) { + } else if(t > _c->expires) { fprintf(_f, "Expired\n"); } else { fprintf(_f, "%u\n", (unsigned int)(_c->expires - t)); @@ -205,25 +238,21 @@ void print_ucontact(FILE* _f, ucontact_t* _c) fprintf(_f, "q : %s\n", q2str(_c->q, 0)); fprintf(_f, "Call-ID : '%.*s'\n", _c->callid.len, ZSW(_c->callid.s)); fprintf(_f, "CSeq : %d\n", _c->cseq); - fprintf(_f, "User-Agent: '%.*s'\n", - _c->user_agent.len, ZSW(_c->user_agent.s)); - fprintf(_f, "received : '%.*s'\n", - _c->received.len, ZSW(_c->received.s)); - fprintf(_f, "Path : '%.*s'\n", - _c->path.len, ZSW(_c->path.s)); + fprintf(_f, "User-Agent: '%.*s'\n", _c->user_agent.len, + ZSW(_c->user_agent.s)); + fprintf(_f, "received : '%.*s'\n", _c->received.len, ZSW(_c->received.s)); + fprintf(_f, "Path : '%.*s'\n", _c->path.len, ZSW(_c->path.s)); fprintf(_f, "State : %s\n", st); fprintf(_f, "Flags : %u\n", _c->flags); - if (_c->sock) { - fprintf(_f, "Sock : %.*s (%p)\n", - _c->sock->sock_str.len,_c->sock->sock_str.s,_c->sock); + if(_c->sock) { + fprintf(_f, "Sock : %.*s (%p)\n", _c->sock->sock_str.len, + _c->sock->sock_str.s, _c->sock); } else { fprintf(_f, "Sock : none (null)\n"); } fprintf(_f, "Methods : %u\n", _c->methods); - fprintf(_f, "ruid : '%.*s'\n", - _c->ruid.len, ZSW(_c->ruid.s)); - fprintf(_f, "instance : '%.*s'\n", - _c->instance.len, ZSW(_c->instance.s)); + fprintf(_f, "ruid : '%.*s'\n", _c->ruid.len, ZSW(_c->ruid.s)); + fprintf(_f, "instance : '%.*s'\n", _c->instance.len, ZSW(_c->instance.s)); fprintf(_f, "reg-id : %u\n", _c->reg_id); fprintf(_f, "next : %p\n", _c->next); fprintf(_f, "prev : %p\n", _c->prev); @@ -237,51 +266,53 @@ void print_ucontact(FILE* _f, ucontact_t* _c) * \param _ci contact informations * \return 0 on success, -1 on failure */ -int mem_update_ucontact(ucontact_t* _c, ucontact_info_t* _ci) +int mem_update_ucontact(ucontact_t *_c, ucontact_info_t *_ci) { -#define update_str(_old,_new) \ - do{\ - if ((_old)->len < (_new)->len) { \ - ptr = (char*)shm_malloc((_new)->len); \ - if (ptr == 0) { \ - SHM_MEM_ERROR; \ - return -1; \ - }\ - memcpy(ptr, (_new)->s, (_new)->len);\ - if ((_old)->s) shm_free((_old)->s);\ - (_old)->s = ptr;\ - } else {\ - memcpy((_old)->s, (_new)->s, (_new)->len);\ - }\ - (_old)->len = (_new)->len;\ +#define update_str(_old, _new) \ + do { \ + if((_old)->len < (_new)->len) { \ + ptr = (char *)shm_malloc((_new)->len); \ + if(ptr == 0) { \ + SHM_MEM_ERROR; \ + return -1; \ + } \ + memcpy(ptr, (_new)->s, (_new)->len); \ + if((_old)->s) \ + shm_free((_old)->s); \ + (_old)->s = ptr; \ + } else { \ + memcpy((_old)->s, (_new)->s, (_new)->len); \ + } \ + (_old)->len = (_new)->len; \ } while(0) - char* ptr; + char *ptr; - if(_ci->instance.s!=NULL && _ci->instance.len>0) - { + if(_ci->instance.s != NULL && _ci->instance.len > 0) { /* when we have instance set, update contact address */ - if(_ci->c!=NULL && _ci->c->s!=NULL && _ci->c->len>0) - update_str( &_c->c, _ci->c); + if(_ci->c != NULL && _ci->c->s != NULL && _ci->c->len > 0) + update_str(&_c->c, _ci->c); } /* refresh call-id */ - if(_ci->callid!=NULL && _ci->callid->s!=NULL && _ci->callid->len>0) - update_str( &_c->callid, _ci->callid); - update_str( &_c->user_agent, _ci->user_agent); + if(_ci->callid != NULL && _ci->callid->s != NULL && _ci->callid->len > 0) + update_str(&_c->callid, _ci->callid); + update_str(&_c->user_agent, _ci->user_agent); - if (_ci->received.s && _ci->received.len) { - update_str( &_c->received, &_ci->received); + if(_ci->received.s && _ci->received.len) { + update_str(&_c->received, &_ci->received); } else { - if (_c->received.s) shm_free(_c->received.s); + if(_c->received.s) + shm_free(_c->received.s); _c->received.s = 0; _c->received.len = 0; } - if (_ci->path) { - update_str( &_c->path, _ci->path); + if(_ci->path) { + update_str(&_c->path, _ci->path); } else { - if (_c->path.s) shm_free(_c->path.s); + if(_c->path.s) + shm_free(_c->path.s); _c->path.s = 0; _c->path.len = 0; } @@ -310,33 +341,33 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t* _ci) * \brief Update state of the contact if we are using write-back scheme * \param _c updated contact */ -void st_update_ucontact(ucontact_t* _c) +void st_update_ucontact(ucontact_t *_c) { switch(_c->state) { - case CS_NEW: + case CS_NEW: /* Contact is new and is not in the database yet, * we remain in the same state here because the * contact must be inserted later in the timer */ - break; + break; - case CS_SYNC: + case CS_SYNC: /* For db mode 1 & 2 a modified contact needs to be * updated also in the database, so transit into * CS_DIRTY and let the timer to do the update * again. For db mode 1 we try to update right * now and if fails, let the timer to do the job */ - if (ul_db_mode == WRITE_BACK || ul_db_mode == WRITE_THROUGH) { - _c->state = CS_DIRTY; - } - break; + if(ul_db_mode == WRITE_BACK || ul_db_mode == WRITE_THROUGH) { + _c->state = CS_DIRTY; + } + break; - case CS_DIRTY: + case CS_DIRTY: /* Modification of dirty contact results in * dirty contact again, don't change anything */ - break; + break; } } @@ -346,18 +377,18 @@ void st_update_ucontact(ucontact_t* _c) * \param _c updated contact * \return 1 if the contact should be deleted from memory immediately, 0 otherwise */ -int st_delete_ucontact(ucontact_t* _c) +int st_delete_ucontact(ucontact_t *_c) { switch(_c->state) { - case CS_NEW: + case CS_NEW: /* Contact is new and isn't in the database * yet, we can delete it from the memory * safely. */ - return 1; + return 1; - case CS_SYNC: - case CS_DIRTY: + case CS_SYNC: + case CS_DIRTY: /* Contact is in the database, * we cannot remove it from the memory * directly, but we can set expires to zero @@ -365,17 +396,17 @@ int st_delete_ucontact(ucontact_t* _c) * the contact from the memory as well as * from the database */ - if (ul_db_mode == WRITE_BACK) { - _c->expires = UL_EXPIRED_TIME; - return 0; - } else { - /* WRITE_THROUGH or NO_DB -- we can + if(ul_db_mode == WRITE_BACK) { + _c->expires = UL_EXPIRED_TIME; + return 0; + } else { + /* WRITE_THROUGH or NO_DB -- we can * remove it from memory immediately and * the calling function would also remove * it from the database if needed */ - return 1; - } + return 1; + } } return 0; /* Makes gcc happy */ @@ -387,7 +418,7 @@ int st_delete_ucontact(ucontact_t* _c) * \param _c expired contact * \return 1 if the contact should be removed from the database and 0 otherwise */ -int st_expired_ucontact(ucontact_t* _c) +int st_expired_ucontact(ucontact_t *_c) { /* There is no need to change contact * state, because the contact will @@ -395,16 +426,16 @@ int st_expired_ucontact(ucontact_t* _c) */ switch(_c->state) { - case CS_NEW: - /* Contact is not in the database + case CS_NEW: + /* Contact is not in the database * yet, remove it from memory only */ - return 0; + return 0; - case CS_SYNC: - case CS_DIRTY: - /* Remove from database here */ - return 1; + case CS_SYNC: + case CS_DIRTY: + /* Remove from database here */ + return 1; } return 0; /* Makes gcc happy */ @@ -416,30 +447,30 @@ int st_expired_ucontact(ucontact_t* _c) * \param _c flushed contact * \return 1 if the contact should be inserted, 2 if update and 0 otherwise */ -int st_flush_ucontact(ucontact_t* _c) +int st_flush_ucontact(ucontact_t *_c) { switch(_c->state) { - case CS_NEW: - /* Contact is new and is not in + case CS_NEW: + /* Contact is new and is not in * the database yet so we have * to insert it */ - _c->state = CS_SYNC; - return 1; + _c->state = CS_SYNC; + return 1; - case CS_SYNC: - /* Contact is synchronized, do + case CS_SYNC: + /* Contact is synchronized, do * nothing */ - return 0; + return 0; - case CS_DIRTY: - /* Contact has been modified and + case CS_DIRTY: + /* Contact has been modified and * is in the db already so we * have to update it */ - _c->state = CS_SYNC; - return 2; + _c->state = CS_SYNC; + return 2; } return 0; /* Makes gcc happy */ @@ -456,19 +487,18 @@ static unsigned int _ul_partition_counter = 0; * \param _c inserted contact * \return 0 on success, -1 on failure */ -int db_insert_ucontact(ucontact_t* _c) +int db_insert_ucontact(ucontact_t *_c) { - char* dom; + char *dom; db_key_t keys[22]; db_val_t vals[22]; int nr_cols; - if (_c->flags & FL_MEM) { + if(_c->flags & FL_MEM) { return 0; } - if(unlikely(_c->ruid.len<=0)) { - LM_ERR("invalid ruid for aor: %.*s\n", - _c->aor->len, ZSW(_c->aor->s)); + if(unlikely(_c->ruid.len <= 0)) { + LM_ERR("invalid ruid for aor: %.*s\n", _c->aor->len, ZSW(_c->aor->s)); return -1; } @@ -523,54 +553,54 @@ int db_insert_ucontact(ucontact_t* _c) nr_cols = 9; - if (_c->received.s) { + if(_c->received.s) { keys[nr_cols] = &ul_received_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 0; vals[nr_cols].val.str_val.s = _c->received.s; vals[nr_cols].val.str_val.len = _c->received.len; nr_cols++; - } else if(ul_db_insert_null!=0) { + } else if(ul_db_insert_null != 0) { keys[nr_cols] = &ul_received_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 1; nr_cols++; } - if (_c->path.s) { + if(_c->path.s) { keys[nr_cols] = &ul_path_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 0; vals[nr_cols].val.str_val.s = _c->path.s; vals[nr_cols].val.str_val.len = _c->path.len; nr_cols++; - } else if(ul_db_insert_null!=0) { + } else if(ul_db_insert_null != 0) { keys[nr_cols] = &ul_path_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 1; nr_cols++; } - if (_c->sock) { + if(_c->sock) { keys[nr_cols] = &ul_sock_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].val.str_val = _c->sock->sock_str; vals[nr_cols].nul = 0; nr_cols++; - } else if(ul_db_insert_null!=0) { + } else if(ul_db_insert_null != 0) { keys[nr_cols] = &ul_sock_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 1; nr_cols++; } - if (_c->methods != 0xFFFFFFFF) { + if(_c->methods != 0xFFFFFFFF) { keys[nr_cols] = &ul_methods_col; vals[nr_cols].type = DB1_BITMAP; vals[nr_cols].val.bitmap_val = _c->methods; vals[nr_cols].nul = 0; nr_cols++; - } else if(ul_db_insert_null!=0) { + } else if(ul_db_insert_null != 0) { keys[nr_cols] = &ul_methods_col; vals[nr_cols].type = DB1_BITMAP; vals[nr_cols].nul = 1; @@ -583,28 +613,26 @@ int db_insert_ucontact(ucontact_t* _c) nr_cols++; - if(_c->ruid.len>0) - { + if(_c->ruid.len > 0) { keys[nr_cols] = &ul_ruid_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 0; vals[nr_cols].val.str_val = _c->ruid; nr_cols++; - } else if(ul_db_insert_null!=0) { + } else if(ul_db_insert_null != 0) { keys[nr_cols] = &ul_ruid_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 1; nr_cols++; } - if(_c->instance.len>0) - { + if(_c->instance.len > 0) { keys[nr_cols] = &ul_instance_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 0; vals[nr_cols].val.str_val = _c->instance; nr_cols++; - } else if(ul_db_insert_null!=0) { + } else if(ul_db_insert_null != 0) { keys[nr_cols] = &ul_instance_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 1; @@ -638,22 +666,22 @@ int db_insert_ucontact(ucontact_t* _c) keys[nr_cols] = &ul_partition_col; vals[nr_cols].type = DB1_INT; vals[nr_cols].nul = 0; - if(_ul_max_partition>0) { - vals[nr_cols].val.int_val = ((_ul_partition_counter++) + my_pid()) - % _ul_max_partition; + if(_ul_max_partition > 0) { + vals[nr_cols].val.int_val = + ((_ul_partition_counter++) + my_pid()) % _ul_max_partition; } else { vals[nr_cols].val.int_val = 0; } nr_cols++; - if (ul_use_domain) { + if(ul_use_domain) { keys[nr_cols] = &ul_domain_col; vals[nr_cols].type = DB1_STR; vals[nr_cols].nul = 0; dom = memchr(_c->aor->s, '@', _c->aor->len); - if (dom==0) { + if(dom == 0) { vals[0].val.str_val.len = 0; vals[nr_cols].val.str_val = *_c->aor; } else { @@ -664,35 +692,35 @@ int db_insert_ucontact(ucontact_t* _c) nr_cols++; } - if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { + if(ul_dbf.use_table(ul_dbh, _c->domain) < 0) { if(_c->domain) { LM_ERR("sql use_table failed for: %.*s\n", - (_c->domain->s)?_c->domain->len:0, - (_c->domain->s)?_c->domain->s:""); + (_c->domain->s) ? _c->domain->len : 0, + (_c->domain->s) ? _c->domain->s : ""); } else { LM_ERR("sql use_table failed - null\n"); } return -1; } - if (ul_db_insert_update && ul_dbf.insert_update) { - if (ul_dbf.insert_update(ul_dbh, keys, vals, nr_cols) < 0) { + if(ul_db_insert_update && ul_dbf.insert_update) { + if(ul_dbf.insert_update(ul_dbh, keys, vals, nr_cols) < 0) { LM_ERR("inserting with update contact in db failed %.*s (%.*s)\n", - _c->aor->len, ZSW(_c->aor->s), _c->ruid.len, ZSW(_c->ruid.s)); + _c->aor->len, ZSW(_c->aor->s), _c->ruid.len, + ZSW(_c->ruid.s)); return -1; } } else { - if (ul_dbf.insert(ul_dbh, keys, vals, nr_cols) < 0) { - LM_ERR("inserting contact in db failed %.*s (%.*s)\n", - _c->aor->len, ZSW(_c->aor->s), _c->ruid.len, ZSW(_c->ruid.s)); + if(ul_dbf.insert(ul_dbh, keys, vals, nr_cols) < 0) { + LM_ERR("inserting contact in db failed %.*s (%.*s)\n", _c->aor->len, + ZSW(_c->aor->s), _c->ruid.len, ZSW(_c->ruid.s)); return -1; } } - if (ul_xavp_contact_name.s) { + if(ul_xavp_contact_name.s) { uldb_insert_attrs(_c->domain, &vals[0].val.str_val, - &vals[nr_cols-1].val.str_val, - &_c->ruid, _c->xavp); + &vals[nr_cols - 1].val.str_val, &_c->ruid, _c->xavp); } return 0; @@ -704,9 +732,9 @@ int db_insert_ucontact(ucontact_t* _c) * \param _c updated contact * \return 0 on success, -1 on failure */ -int db_update_ucontact_addr(ucontact_t* _c) +int db_update_ucontact_addr(ucontact_t *_c) { - char* dom; + char *dom; db_key_t keys1[4]; db_val_t vals1[4]; int n1 = 0; @@ -716,7 +744,7 @@ int db_update_ucontact_addr(ucontact_t* _c) int nr_cols2 = 0; - if (_c->flags & FL_MEM) { + if(_c->flags & FL_MEM) { return 0; } @@ -731,10 +759,11 @@ int db_update_ucontact_addr(ucontact_t* _c) vals1[n1].type = DB1_STR; vals1[n1].nul = 0; vals1[n1].val.str_val = _c->c; - LM_DBG("contact:%.*s\n", vals1[n1].val.str_val.len, vals1[n1].val.str_val.s); + LM_DBG("contact:%.*s\n", vals1[n1].val.str_val.len, + vals1[n1].val.str_val.s); n1++; - switch (ul_matching_mode) { + switch(ul_matching_mode) { case CONTACT_ONLY: /* update call-id */ keys2[nr_cols2] = &ul_callid_col; @@ -745,7 +774,7 @@ int db_update_ucontact_addr(ucontact_t* _c) /* update path */ keys2[nr_cols2] = &ul_path_col; vals2[nr_cols2].type = DB1_STR; - if (_c->path.s == 0) { + if(_c->path.s == 0) { vals2[nr_cols2].nul = 1; } else { vals2[nr_cols2].nul = 0; @@ -758,12 +787,13 @@ int db_update_ucontact_addr(ucontact_t* _c) vals1[n1].type = DB1_STR; vals1[n1].nul = 0; vals1[n1].val.str_val = _c->callid; - LM_DBG("callid:%.*s\n", vals1[n1].val.str_val.len, vals1[n1].val.str_val.s); + LM_DBG("callid:%.*s\n", vals1[n1].val.str_val.len, + vals1[n1].val.str_val.s); n1++; /* update path */ keys2[nr_cols2] = &ul_path_col; vals2[nr_cols2].type = DB1_STR; - if (_c->path.s == 0) { + if(_c->path.s == 0) { vals2[nr_cols2].nul = 1; } else { vals2[nr_cols2].nul = 0; @@ -774,13 +804,14 @@ int db_update_ucontact_addr(ucontact_t* _c) case CONTACT_PATH: keys1[n1] = &ul_path_col; vals1[n1].type = DB1_STR; - if (_c->path.s == 0) { + if(_c->path.s == 0) { vals1[n1].nul = 1; LM_DBG("path: NULL\n"); } else { vals1[n1].nul = 0; vals1[n1].val.str_val = _c->path; - LM_DBG("path:%.*s\n", vals1[n1].val.str_val.len, vals1[n1].val.str_val.s); + LM_DBG("path:%.*s\n", vals1[n1].val.str_val.len, + vals1[n1].val.str_val.s); } n1++; /* update call-id */ @@ -832,7 +863,7 @@ int db_update_ucontact_addr(ucontact_t* _c) keys2[nr_cols2] = &ul_received_col; vals2[nr_cols2].type = DB1_STR; - if (_c->received.s == 0) { + if(_c->received.s == 0) { vals2[nr_cols2].nul = 1; } else { vals2[nr_cols2].nul = 0; @@ -842,7 +873,7 @@ int db_update_ucontact_addr(ucontact_t* _c) keys2[nr_cols2] = &ul_sock_col; vals2[nr_cols2].type = DB1_STR; - if (_c->sock) { + if(_c->sock) { vals2[nr_cols2].val.str_val = _c->sock->sock_str; vals2[nr_cols2].nul = 0; } else { @@ -852,7 +883,7 @@ int db_update_ucontact_addr(ucontact_t* _c) keys2[nr_cols2] = &ul_methods_col; vals2[nr_cols2].type = DB1_BITMAP; - if (_c->methods == 0xFFFFFFFF) { + if(_c->methods == 0xFFFFFFFF) { vals2[nr_cols2].nul = 1; } else { vals2[nr_cols2].val.bitmap_val = _c->methods; @@ -867,8 +898,7 @@ int db_update_ucontact_addr(ucontact_t* _c) keys2[nr_cols2] = &ul_ruid_col; vals2[nr_cols2].type = DB1_STR; - if(_c->ruid.len>0) - { + if(_c->ruid.len > 0) { vals2[nr_cols2].nul = 0; vals2[nr_cols2].val.str_val = _c->ruid; } else { @@ -878,8 +908,7 @@ int db_update_ucontact_addr(ucontact_t* _c) keys2[nr_cols2] = &ul_instance_col; vals2[nr_cols2].type = DB1_STR; - if(_c->instance.len>0) - { + if(_c->instance.len > 0) { vals2[nr_cols2].nul = 0; vals2[nr_cols2].val.str_val = _c->instance; } else { @@ -915,15 +944,16 @@ int db_update_ucontact_addr(ucontact_t* _c) vals2[nr_cols2].type = DB1_STR; vals2[nr_cols2].nul = 0; vals2[nr_cols2].val.str_val = _c->c; - LM_DBG("contact:%.*s\n", vals2[nr_cols2].val.str_val.len, vals2[nr_cols2].val.str_val.s); + LM_DBG("contact:%.*s\n", vals2[nr_cols2].val.str_val.len, + vals2[nr_cols2].val.str_val.s); nr_cols2++; - if (ul_use_domain) { + if(ul_use_domain) { keys1[n1] = &ul_domain_col; vals1[n1].type = DB1_STR; vals1[n1].nul = 0; dom = memchr(_c->aor->s, '@', _c->aor->len); - if (dom==0) { + if(dom == 0) { vals1[0].val.str_val.len = 0; vals1[n1].val.str_val = *_c->aor; } else { @@ -934,39 +964,37 @@ int db_update_ucontact_addr(ucontact_t* _c) n1++; } - if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { + if(ul_dbf.use_table(ul_dbh, _c->domain) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, n1, - nr_cols2) < 0) { + if(ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, n1, nr_cols2) < 0) { LM_ERR("updating database failed\n"); return -1; } - if (ul_db_check_update==1 && ul_dbf.affected_rows) { + if(ul_db_check_update == 1 && ul_dbf.affected_rows) { /* supposed to be an UPDATE, but if affected rows is 0, then try * to do an INSERT */ - if(ul_dbf.affected_rows(ul_dbh)==0) { + if(ul_dbf.affected_rows(ul_dbh) == 0) { LM_DBG("affected rows by UPDATE was 0, doing an INSERT\n"); - if(db_insert_ucontact(_c)<0) + if(db_insert_ucontact(_c) < 0) return -1; } } /* delete old db attrs and add the current list */ - if (ul_xavp_contact_name.s) { - if (ul_use_domain) { + if(ul_xavp_contact_name.s) { + if(ul_use_domain) { uldb_delete_attrs(_c->domain, &vals1[0].val.str_val, - &vals1[n1-1].val.str_val, &_c->ruid); + &vals1[n1 - 1].val.str_val, &_c->ruid); uldb_insert_attrs(_c->domain, &vals1[0].val.str_val, - &vals1[n1-1].val.str_val, - &_c->ruid, _c->xavp); + &vals1[n1 - 1].val.str_val, &_c->ruid, _c->xavp); } else { - uldb_delete_attrs(_c->domain, &vals1[0].val.str_val, - NULL, &_c->ruid); - uldb_insert_attrs(_c->domain, &vals1[0].val.str_val, - NULL, &_c->ruid, _c->xavp); + uldb_delete_attrs( + _c->domain, &vals1[0].val.str_val, NULL, &_c->ruid); + uldb_insert_attrs(_c->domain, &vals1[0].val.str_val, NULL, + &_c->ruid, _c->xavp); } } @@ -978,7 +1006,7 @@ int db_update_ucontact_addr(ucontact_t* _c) * \param _c updated contact * \return 0 on success, -1 on failure */ -int db_update_ucontact_ruid(ucontact_t* _c) +int db_update_ucontact_ruid(ucontact_t *_c) { str auser; str adomain; @@ -991,16 +1019,16 @@ int db_update_ucontact_ruid(ucontact_t* _c) int n2; - if (_c->flags & FL_MEM) { + if(_c->flags & FL_MEM) { return 0; } - if(_c->ruid.len<=0) { + if(_c->ruid.len <= 0) { LM_ERR("updating record in database failed - empty ruid\n"); return -1; } - if (ul_dbh==NULL) { + if(ul_dbh == NULL) { LM_ERR("database connection handle not initialized\n"); return -1; } @@ -1051,7 +1079,7 @@ int db_update_ucontact_ruid(ucontact_t* _c) keys2[n2] = &ul_received_col; vals2[n2].type = DB1_STR; - if (_c->received.s == 0) { + if(_c->received.s == 0) { vals2[n2].nul = 1; } else { vals2[n2].nul = 0; @@ -1061,7 +1089,7 @@ int db_update_ucontact_ruid(ucontact_t* _c) keys2[n2] = &ul_path_col; vals2[n2].type = DB1_STR; - if (_c->path.s == 0) { + if(_c->path.s == 0) { vals2[n2].nul = 1; } else { vals2[n2].nul = 0; @@ -1071,7 +1099,7 @@ int db_update_ucontact_ruid(ucontact_t* _c) keys2[n2] = &ul_sock_col; vals2[n2].type = DB1_STR; - if (_c->sock) { + if(_c->sock) { vals2[n2].val.str_val = _c->sock->sock_str; vals2[n2].nul = 0; } else { @@ -1081,7 +1109,7 @@ int db_update_ucontact_ruid(ucontact_t* _c) keys2[n2] = &ul_methods_col; vals2[n2].type = DB1_BITMAP; - if (_c->methods == 0xFFFFFFFF) { + if(_c->methods == 0xFFFFFFFF) { vals2[n2].nul = 1; } else { vals2[n2].val.bitmap_val = _c->methods; @@ -1102,8 +1130,7 @@ int db_update_ucontact_ruid(ucontact_t* _c) keys2[n2] = &ul_instance_col; vals2[n2].type = DB1_STR; - if(_c->instance.len>0) - { + if(_c->instance.len > 0) { vals2[n2].nul = 0; vals2[n2].val.str_val = _c->instance; } else { @@ -1139,53 +1166,50 @@ int db_update_ucontact_ruid(ucontact_t* _c) vals2[n2].type = DB1_STR; vals2[n2].nul = 0; vals2[n2].val.str_val = _c->c; - LM_DBG("contact:%.*s\n", vals2[n2].val.str_val.len, vals2[n2].val.str_val.s); + LM_DBG("contact:%.*s\n", vals2[n2].val.str_val.len, + vals2[n2].val.str_val.s); n2++; - if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { + if(ul_dbf.use_table(ul_dbh, _c->domain) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, n1, n2) < 0) { + if(ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, n1, n2) < 0) { LM_ERR("updating database failed\n"); return -1; } - if (ul_db_check_update==1 && ul_dbf.affected_rows) { + if(ul_db_check_update == 1 && ul_dbf.affected_rows) { /* supposed to be an UPDATE, but if affected rows is 0, then try * to do an INSERT */ - if(ul_dbf.affected_rows(ul_dbh)==0) { + if(ul_dbf.affected_rows(ul_dbh) == 0) { LM_DBG("affected rows by UPDATE was 0, doing an INSERT\n"); - if(db_insert_ucontact(_c)<0) + if(db_insert_ucontact(_c) < 0) return -1; } } /* delete old db attrs and add the current list */ - if (ul_xavp_contact_name.s) { + if(ul_xavp_contact_name.s) { auser = *_c->aor; - if (ul_use_domain) { + if(ul_use_domain) { adomain.s = memchr(_c->aor->s, '@', _c->aor->len); - if (adomain.s==0) { + if(adomain.s == 0) { auser.len = 0; adomain = *_c->aor; } else { auser.len = adomain.s - _c->aor->s; adomain.s++; - adomain.len = _c->aor->s + - _c->aor->len - adomain.s; + adomain.len = _c->aor->s + _c->aor->len - adomain.s; } - uldb_delete_attrs(_c->domain, &auser, - &adomain, &_c->ruid); - uldb_insert_attrs(_c->domain, &auser, - &adomain, &_c->ruid, _c->xavp); + uldb_delete_attrs(_c->domain, &auser, &adomain, &_c->ruid); + uldb_insert_attrs( + _c->domain, &auser, &adomain, &_c->ruid, _c->xavp); } else { - uldb_delete_attrs(_c->domain, &auser, - NULL, &_c->ruid); - uldb_insert_attrs(_c->domain, &auser, - NULL, &_c->ruid, _c->xavp); + uldb_delete_attrs(_c->domain, &auser, NULL, &_c->ruid); + uldb_insert_attrs(_c->domain, &auser, NULL, &_c->ruid, _c->xavp); } } @@ -1197,7 +1221,7 @@ int db_update_ucontact_ruid(ucontact_t* _c) * \param _c updated contact * \return 0 on success, -1 on failure */ -int db_update_ucontact_instance(ucontact_t* _c) +int db_update_ucontact_instance(ucontact_t *_c) { str auser; str adomain; @@ -1210,11 +1234,11 @@ int db_update_ucontact_instance(ucontact_t* _c) int n2; - if (_c->flags & FL_MEM) { + if(_c->flags & FL_MEM) { return 0; } - if(_c->instance.len<=0) { + if(_c->instance.len <= 0) { LM_ERR("updating record in database failed - empty instance\n"); return -1; } @@ -1231,7 +1255,8 @@ int db_update_ucontact_instance(ucontact_t* _c) vals1[n1].type = DB1_STR; vals1[n1].nul = 0; vals1[n1].val.str_val = _c->instance; - LM_DBG("instance:%.*s\n", vals1[n1].val.str_val.len, vals1[n1].val.str_val.s); + LM_DBG("instance:%.*s\n", vals1[n1].val.str_val.len, + vals1[n1].val.str_val.s); n1++; keys1[n1] = &ul_reg_id_col; @@ -1279,7 +1304,7 @@ int db_update_ucontact_instance(ucontact_t* _c) keys2[n2] = &ul_received_col; vals2[n2].type = DB1_STR; - if (_c->received.s == 0) { + if(_c->received.s == 0) { vals2[n2].nul = 1; } else { vals2[n2].nul = 0; @@ -1289,7 +1314,7 @@ int db_update_ucontact_instance(ucontact_t* _c) keys2[n2] = &ul_path_col; vals2[n2].type = DB1_STR; - if (_c->path.s == 0) { + if(_c->path.s == 0) { vals2[n2].nul = 1; } else { vals2[n2].nul = 0; @@ -1299,7 +1324,7 @@ int db_update_ucontact_instance(ucontact_t* _c) keys2[n2] = &ul_sock_col; vals2[n2].type = DB1_STR; - if (_c->sock) { + if(_c->sock) { vals2[n2].val.str_val = _c->sock->sock_str; vals2[n2].nul = 0; } else { @@ -1309,7 +1334,7 @@ int db_update_ucontact_instance(ucontact_t* _c) keys2[n2] = &ul_methods_col; vals2[n2].type = DB1_BITMAP; - if (_c->methods == 0xFFFFFFFF) { + if(_c->methods == 0xFFFFFFFF) { vals2[n2].nul = 1; } else { vals2[n2].val.bitmap_val = _c->methods; @@ -1351,16 +1376,17 @@ int db_update_ucontact_instance(ucontact_t* _c) vals2[n2].nul = 0; vals2[n2].val.str_val.s = _c->c.s; vals2[n2].val.str_val.len = _c->c.len; - LM_DBG("contact:%.*s\n", vals2[n2].val.str_val.len, vals2[n2].val.str_val.s); + LM_DBG("contact:%.*s\n", vals2[n2].val.str_val.len, + vals2[n2].val.str_val.s); n2++; auser = *_c->aor; - if (ul_use_domain) { + if(ul_use_domain) { keys1[n1] = &ul_domain_col; vals1[n1].type = DB1_STR; vals1[n1].nul = 0; adomain.s = memchr(_c->aor->s, '@', _c->aor->len); - if (adomain.s==0) { + if(adomain.s == 0) { vals1[0].val.str_val.len = 0; vals1[n1].val.str_val = *_c->aor; auser.len = 0; @@ -1368,48 +1394,45 @@ int db_update_ucontact_instance(ucontact_t* _c) } else { vals1[0].val.str_val.len = adomain.s - _c->aor->s; vals1[n1].val.str_val.s = adomain.s + 1; - vals1[n1].val.str_val.len = _c->aor->s + _c->aor->len - adomain.s - 1; + vals1[n1].val.str_val.len = + _c->aor->s + _c->aor->len - adomain.s - 1; auser.len = adomain.s - _c->aor->s; adomain.s++; - adomain.len = _c->aor->s + - _c->aor->len - adomain.s; + adomain.len = _c->aor->s + _c->aor->len - adomain.s; } n1++; } - if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { + if(ul_dbf.use_table(ul_dbh, _c->domain) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, n1, n2) < 0) { + if(ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, n1, n2) < 0) { LM_ERR("updating database failed\n"); return -1; } - if (ul_db_check_update==1 && ul_dbf.affected_rows) { + if(ul_db_check_update == 1 && ul_dbf.affected_rows) { LM_DBG("update affected_rows 0\n"); /* supposed to be an UPDATE, but if affected rows is 0, then try * to do an INSERT */ - if(ul_dbf.affected_rows(ul_dbh)==0) { + if(ul_dbf.affected_rows(ul_dbh) == 0) { LM_DBG("affected rows by UPDATE was 0, doing an INSERT\n"); - if(db_insert_ucontact(_c)<0) + if(db_insert_ucontact(_c) < 0) return -1; } } /* delete old db attrs and add the current list */ - if (ul_xavp_contact_name.s) { - if (ul_use_domain) { - uldb_delete_attrs(_c->domain, &auser, - &adomain, &_c->ruid); - uldb_insert_attrs(_c->domain, &auser, - &adomain, &_c->ruid, _c->xavp); + if(ul_xavp_contact_name.s) { + if(ul_use_domain) { + uldb_delete_attrs(_c->domain, &auser, &adomain, &_c->ruid); + uldb_insert_attrs( + _c->domain, &auser, &adomain, &_c->ruid, _c->xavp); } else { - uldb_delete_attrs(_c->domain, &auser, - NULL, &_c->ruid); - uldb_insert_attrs(_c->domain, &auser, - NULL, &_c->ruid, _c->xavp); + uldb_delete_attrs(_c->domain, &auser, NULL, &_c->ruid); + uldb_insert_attrs(_c->domain, &auser, NULL, &_c->ruid, _c->xavp); } } @@ -1421,13 +1444,12 @@ int db_update_ucontact_instance(ucontact_t* _c) * \param _c updated contact * \return 0 on success, -1 on failure */ -int db_update_ucontact(ucontact_t* _c) +int db_update_ucontact(ucontact_t *_c) { - if(ul_db_ops_ruid==0) - if (_c->instance.len<=0) { + if(ul_db_ops_ruid == 0) + if(_c->instance.len <= 0) { return db_update_ucontact_addr(_c); - } - else { + } else { return db_update_ucontact_instance(_c); } else @@ -1439,14 +1461,14 @@ int db_update_ucontact(ucontact_t* _c) * \param _c deleted contact * \return 0 on success, -1 on failure */ -int db_delete_ucontact_addr(ucontact_t* _c) +int db_delete_ucontact_addr(ucontact_t *_c) { - char* dom; + char *dom; db_key_t keys[4]; db_val_t vals[4]; int n; - if (_c->flags & FL_MEM) { + if(_c->flags & FL_MEM) { return 0; } @@ -1464,7 +1486,7 @@ int db_delete_ucontact_addr(ucontact_t* _c) vals[n].val.str_val = _c->c; n++; - switch (ul_matching_mode) { + switch(ul_matching_mode) { case CONTACT_ONLY: break; case CONTACT_CALLID: @@ -1477,7 +1499,7 @@ int db_delete_ucontact_addr(ucontact_t* _c) case CONTACT_PATH: keys[n] = &ul_path_col; vals[n].type = DB1_STR; - if (_c->path.s == 0) { + if(_c->path.s == 0) { vals[n].nul = 1; } else { vals[n].nul = 0; @@ -1490,34 +1512,32 @@ int db_delete_ucontact_addr(ucontact_t* _c) return -1; } - if (ul_use_domain) { + if(ul_use_domain) { keys[n] = &ul_domain_col; vals[n].type = DB1_STR; vals[n].nul = 0; dom = memchr(_c->aor->s, '@', _c->aor->len); - if (dom==0) { + if(dom == 0) { vals[0].val.str_val.len = 0; vals[n].val.str_val = *_c->aor; } else { vals[0].val.str_val.len = dom - _c->aor->s; vals[n].val.str_val.s = dom + 1; - vals[n].val.str_val.len = _c->aor->s + - _c->aor->len - dom - 1; + vals[n].val.str_val.len = _c->aor->s + _c->aor->len - dom - 1; } uldb_delete_attrs(_c->domain, &vals[0].val.str_val, &vals[n].val.str_val, &_c->ruid); n++; } else { - uldb_delete_attrs(_c->domain, &vals[0].val.str_val, - NULL, &_c->ruid); + uldb_delete_attrs(_c->domain, &vals[0].val.str_val, NULL, &_c->ruid); } - if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { + if(ul_dbf.use_table(ul_dbh, _c->domain) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.delete(ul_dbh, keys, 0, vals, n) < 0) { + if(ul_dbf.delete(ul_dbh, keys, 0, vals, n) < 0) { LM_ERR("deleting from database failed\n"); return -1; } @@ -1530,17 +1550,17 @@ int db_delete_ucontact_addr(ucontact_t* _c) * \param _c deleted contact * \return 0 on success, -1 on failure */ -int db_delete_ucontact_ruid(ucontact_t* _c) +int db_delete_ucontact_ruid(ucontact_t *_c) { db_key_t keys[1]; db_val_t vals[1]; int n; - if (_c->flags & FL_MEM) { + if(_c->flags & FL_MEM) { return 0; } - if(_c->ruid.len<=0) { + if(_c->ruid.len <= 0) { LM_ERR("deleting from database failed - empty ruid\n"); return -1; } @@ -1554,12 +1574,12 @@ int db_delete_ucontact_ruid(ucontact_t* _c) uldb_delete_attrs_ruid(_c->domain, &_c->ruid); - if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { + if(ul_dbf.use_table(ul_dbh, _c->domain) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.delete(ul_dbh, keys, 0, vals, n) < 0) { + if(ul_dbf.delete(ul_dbh, keys, 0, vals, n) < 0) { LM_ERR("deleting from database failed\n"); return -1; } @@ -1572,9 +1592,9 @@ int db_delete_ucontact_ruid(ucontact_t* _c) * \param _c deleted contact * \return 0 on success, -1 on failure */ -int db_delete_ucontact(ucontact_t* _c) +int db_delete_ucontact(ucontact_t *_c) { - if(ul_db_ops_ruid==0) + if(ul_db_ops_ruid == 0) return db_delete_ucontact_addr(_c); else return db_delete_ucontact_ruid(_c); @@ -1585,16 +1605,16 @@ int db_delete_ucontact(ucontact_t* _c) * \param _r record the contact belongs * \param _c removed contact */ -static inline void unlink_contact(struct urecord* _r, ucontact_t* _c) +static inline void unlink_contact(struct urecord *_r, ucontact_t *_c) { - if (_c->prev) { + if(_c->prev) { _c->prev->next = _c->next; - if (_c->next) { + if(_c->next) { _c->next->prev = _c->prev; } } else { _r->contacts = _c->next; - if (_c->next) { + if(_c->next) { _c->next->prev = 0; } } @@ -1606,13 +1626,13 @@ static inline void unlink_contact(struct urecord* _r, ucontact_t* _c) * \param _r record that holds the sorted contacts * \param _c new contact */ -static inline void update_contact_pos(struct urecord* _r, ucontact_t* _c) +static inline void update_contact_pos(struct urecord *_r, ucontact_t *_c) { ucontact_t *pos, *ppos; - if (ul_desc_time_order) { + if(ul_desc_time_order) { /* order by time - first the newest */ - if (_c->prev==0) + if(_c->prev == 0) return; unlink_contact(_r, _c); /* insert it at the beginning */ @@ -1622,15 +1642,17 @@ static inline void update_contact_pos(struct urecord* _r, ucontact_t* _c) _r->contacts = _c; } else { /* order by q - first the smaller q */ - if ( (_c->prev==0 || _c->q<=_c->prev->q) - && (_c->next==0 || _c->q>=_c->next->q) ) + if((_c->prev == 0 || _c->q <= _c->prev->q) + && (_c->next == 0 || _c->q >= _c->next->q)) return; /* need to move , but where? */ unlink_contact(_r, _c); _c->next = _c->prev = 0; - for(pos=_r->contacts,ppos=0;pos&&pos->q<_c->q;ppos=pos,pos=pos->next); - if (pos) { - if (!pos->prev) { + for(pos = _r->contacts, ppos = 0; pos && pos->q < _c->q; + ppos = pos, pos = pos->next) + ; + if(pos) { + if(!pos->prev) { pos->prev = _c; _c->next = pos; _r->contacts = _c; @@ -1640,7 +1662,7 @@ static inline void update_contact_pos(struct urecord* _r, ucontact_t* _c) pos->prev->next = _c; pos->prev = _c; } - } else if (ppos) { + } else if(ppos) { ppos->next = _c; _c->prev = ppos; } else { @@ -1654,16 +1676,16 @@ static inline void update_contact_pos(struct urecord* _r, ucontact_t* _c) * \param _c contact * \return 0 on success, -1 on failure */ -static inline int update_contact_db(ucontact_t* _c) +static inline int update_contact_db(ucontact_t *_c) { int res; - if (ul_db_update_as_insert) + if(ul_db_update_as_insert) res = db_insert_ucontact(_c); else res = db_update_ucontact(_c); - if (res < 0) { + if(res < 0) { LM_ERR("failed to update database\n"); return -1; } else { @@ -1679,32 +1701,33 @@ static inline int update_contact_db(ucontact_t* _c) * \param _ci new contact informations * \return 0 on success, -1 on failure */ -int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci) +int update_ucontact(struct urecord *_r, ucontact_t *_c, ucontact_info_t *_ci) { struct urecord _ur; /* we have to update memory in any case, but database directly * only in db_mode 1 */ - if (mem_update_ucontact( _c, _ci) < 0) { + if(mem_update_ucontact(_c, _ci) < 0) { LM_ERR("failed to update memory\n"); return -1; } - if (ul_db_mode==DB_ONLY) { + if(ul_db_mode == DB_ONLY) { /* urecord is static generate a copy for later */ - if (_r) memcpy(&_ur, _r, sizeof(struct urecord)); - if (update_contact_db(_c) < 0) return -1; + if(_r) + memcpy(&_ur, _r, sizeof(struct urecord)); + if(update_contact_db(_c) < 0) + return -1; } /* run callbacks for UPDATE event */ - if (exists_ulcb_type(UL_CONTACT_UPDATE)) - { + if(exists_ulcb_type(UL_CONTACT_UPDATE)) { LM_DBG("exists callback for type= UL_CONTACT_UPDATE\n"); - run_ul_callbacks( UL_CONTACT_UPDATE, _c); + run_ul_callbacks(UL_CONTACT_UPDATE, _c); } - if (_r) { - if (ul_db_mode!=DB_ONLY) { - update_contact_pos( _r, _c); + if(_r) { + if(ul_db_mode != DB_ONLY) { + update_contact_pos(_r, _c); } else { /* urecord was static restore copy */ memcpy(_r, &_ur, sizeof(struct urecord)); @@ -1713,8 +1736,9 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci) st_update_ucontact(_c); - if (ul_db_mode == WRITE_THROUGH) { - if (update_contact_db(_c) < 0) return -1; + if(ul_db_mode == WRITE_THROUGH) { + if(update_contact_db(_c) < 0) + return -1; } return 0; } @@ -1730,24 +1754,24 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci) * \param _ruid usrloc record unique id * \return 0 on success, -1 on failure */ -int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid) +int uldb_delete_attrs(str *_dname, str *_user, str *_domain, str *_ruid) { char tname_buf[64]; str tname; db_key_t keys[3]; db_val_t vals[3]; - if(ul_db_ops_ruid==1) + if(ul_db_ops_ruid == 1) return uldb_delete_attrs_ruid(_dname, _ruid); LM_DBG("trying to delete location attributes\n"); - if(ul_xavp_contact_name.s==NULL) { + if(ul_xavp_contact_name.s == NULL) { /* feature disabled by mod param */ return 0; } - if(_dname->len+6>=64) { + if(_dname->len + 6 >= 64) { LM_ERR("attributes table name is too big\n"); return -1; } @@ -1769,18 +1793,18 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid) vals[1].nul = 0; vals[1].val.str_val = *_ruid; - if (ul_use_domain) { + if(ul_use_domain) { vals[2].type = DB1_STR; vals[2].nul = 0; vals[2].val.str_val = *_domain; } - if (ul_dbf.use_table(ul_dbh, &tname) < 0) { + if(ul_dbf.use_table(ul_dbh, &tname) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.delete(ul_dbh, keys, 0, vals, (ul_use_domain) ? (3) : (2)) < 0) { + if(ul_dbf.delete(ul_dbh, keys, 0, vals, (ul_use_domain) ? (3) : (2)) < 0) { LM_ERR("deleting from database failed\n"); return -1; } @@ -1795,7 +1819,7 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid) * \param _ruid usrloc record unique id * \return 0 on success, -1 on failure */ -int uldb_delete_attrs_ruid(str* _dname, str *_ruid) +int uldb_delete_attrs_ruid(str *_dname, str *_ruid) { char tname_buf[64]; str tname; @@ -1804,12 +1828,12 @@ int uldb_delete_attrs_ruid(str* _dname, str *_ruid) LM_DBG("trying to delete location attributes\n"); - if(ul_xavp_contact_name.s==NULL) { + if(ul_xavp_contact_name.s == NULL) { /* feature disabled by mod param */ return 0; } - if(_dname->len+6>=64) { + if(_dname->len + 6 >= 64) { LM_ERR("attributes table name is too big\n"); return -1; } @@ -1825,12 +1849,12 @@ int uldb_delete_attrs_ruid(str* _dname, str *_ruid) vals[0].nul = 0; vals[0].val.str_val = *_ruid; - if (ul_dbf.use_table(ul_dbh, &tname) < 0) { + if(ul_dbf.use_table(ul_dbh, &tname) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) { + if(ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) { LM_ERR("deleting from database failed\n"); return -1; } @@ -1847,8 +1871,8 @@ int uldb_delete_attrs_ruid(str* _dname, str *_ruid) * \param _xhead head of xavp list * \return 0 on success, -1 on failure */ -int uldb_insert_attrs(str *_dname, str *_user, str *_domain, - str *_ruid, sr_xavp_t *_xhead) +int uldb_insert_attrs( + str *_dname, str *_user, str *_domain, str *_ruid, sr_xavp_t *_xhead) { char tname_buf[64]; str tname; @@ -1860,20 +1884,20 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain, LM_DBG("trying to insert location attributes\n"); - if(ul_xavp_contact_name.s==NULL) { + if(ul_xavp_contact_name.s == NULL) { /* feature disabled by mod param */ LM_DBG("location attributes disabled\n"); return 0; } - if(_xhead==NULL || _xhead->val.type!=SR_XTYPE_XAVP - || _xhead->val.v.xavp==NULL) { + if(_xhead == NULL || _xhead->val.type != SR_XTYPE_XAVP + || _xhead->val.v.xavp == NULL) { /* nothing to write */ LM_DBG("no location attributes\n"); return 0; } - if(_dname->len+6>=64) { + if(_dname->len + 6 >= 64) { LM_ERR("attributes table name is too big\n"); return -1; } @@ -1883,7 +1907,7 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain, tname.s = tname_buf; tname.len = _dname->len + 6; - if (ul_dbf.use_table(ul_dbh, &tname) < 0) { + if(ul_dbf.use_table(ul_dbh, &tname) < 0) { LM_ERR("sql use_table failed for %.*s\n", tname.len, tname.s); return -1; } @@ -1907,7 +1931,7 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain, vals[2].nul = 0; UL_DB_EXPIRES_SET(&vals[2], time(NULL)); - if (ul_use_domain && _domain!=NULL && _domain->s!=NULL) { + if(ul_use_domain && _domain != NULL && _domain->s != NULL) { nr_cols = 7; vals[6].type = DB1_STR; vals[6].nul = 0; @@ -1917,17 +1941,17 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain, nr_cols = 6; } - for(xavp=_xhead->val.v.xavp; xavp; xavp=xavp->next) { + for(xavp = _xhead->val.v.xavp; xavp; xavp = xavp->next) { vals[3].type = DB1_STR; vals[3].nul = 0; vals[3].val.str_val = xavp->name; vals[4].type = DB1_INT; vals[4].nul = 0; - if(xavp->val.type==SR_XTYPE_STR) { + if(xavp->val.type == SR_XTYPE_STR) { vals[4].val.int_val = 0; avalue = xavp->val.v.s; - } else if(xavp->val.type==SR_XTYPE_LONG) { + } else if(xavp->val.type == SR_XTYPE_LONG) { vals[4].val.int_val = 1; avalue.s = sint2str(xavp->val.v.l, &avalue.len); } else { @@ -1938,11 +1962,10 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain, vals[5].nul = 0; vals[5].val.str_val = avalue; - if (ul_dbf.insert(ul_dbh, keys, vals, nr_cols) < 0) { + if(ul_dbf.insert(ul_dbh, keys, vals, nr_cols) < 0) { LM_ERR("inserting contact in db failed\n"); return -1; } - } return 0; } diff --git a/src/modules/usrloc/ucontact.h b/src/modules/usrloc/ucontact.h index 321bd95f7bc..5fac7029dbe 100644 --- a/src/modules/usrloc/ucontact.h +++ b/src/modules/usrloc/ucontact.h @@ -46,15 +46,15 @@ * \param _ci contact informations * \return new created contact on success, 0 on failure */ -ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, - ucontact_info_t* _ci); +ucontact_t *new_ucontact( + str *_dom, str *_aor, str *_contact, ucontact_info_t *_ci); /*! * \brief Free all memory associated with given contact structure * \param _c freed contact */ -void free_ucontact(ucontact_t* _c); +void free_ucontact(ucontact_t *_c); /*! @@ -62,7 +62,7 @@ void free_ucontact(ucontact_t* _c); * \param _f output file * \param _c printed contact */ -void print_ucontact(FILE* _f, ucontact_t* _c); +void print_ucontact(FILE *_f, ucontact_t *_c); /*! @@ -71,7 +71,7 @@ void print_ucontact(FILE* _f, ucontact_t* _c); * \param _ci contact informations * \return 0 */ -int mem_update_ucontact(ucontact_t* _c, ucontact_info_t *_ci); +int mem_update_ucontact(ucontact_t *_c, ucontact_info_t *_ci); /* ===== State transition functions - for write back cache scheme ======== */ @@ -80,7 +80,7 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t *_ci); * \brief Update state of the contact if we are using write-back scheme * \param _c updated contact */ -void st_update_ucontact(ucontact_t* _c); +void st_update_ucontact(ucontact_t *_c); /*! @@ -88,7 +88,7 @@ void st_update_ucontact(ucontact_t* _c); * \param _c updated contact * \return 1 if the contact should be deleted from memory immediately, 0 otherwise */ -int st_delete_ucontact(ucontact_t* _c); +int st_delete_ucontact(ucontact_t *_c); /*! @@ -96,7 +96,7 @@ int st_delete_ucontact(ucontact_t* _c); * \param _c expired contact * \return 1 if the contact should be removed from the database and 0 otherwise */ -int st_expired_ucontact(ucontact_t* _c); +int st_expired_ucontact(ucontact_t *_c); /*! @@ -104,7 +104,7 @@ int st_expired_ucontact(ucontact_t* _c); * \param _c flushed contact * \return 1 if the contact should be inserted, 2 if update and 0 otherwise */ -int st_flush_ucontact(ucontact_t* _c); +int st_flush_ucontact(ucontact_t *_c); /* ==== Database related functions ====== */ @@ -114,7 +114,7 @@ int st_flush_ucontact(ucontact_t* _c); * \param _c inserted contact * \return 0 on success, -1 on failure */ -int db_insert_ucontact(ucontact_t* _c); +int db_insert_ucontact(ucontact_t *_c); /*! @@ -122,7 +122,7 @@ int db_insert_ucontact(ucontact_t* _c); * \param _c updated contact * \return 0 on success, -1 on failure */ -int db_update_ucontact(ucontact_t* _c); +int db_update_ucontact(ucontact_t *_c); /*! @@ -130,7 +130,7 @@ int db_update_ucontact(ucontact_t* _c); * \param _c deleted contact * \return 0 on success, -1 on failure */ -int db_delete_ucontact(ucontact_t* _c); +int db_delete_ucontact(ucontact_t *_c); /* ====== Module interface ====== */ @@ -141,7 +141,7 @@ int db_delete_ucontact(ucontact_t* _c); * \param _ci new contact informations * \return 0 on success, -1 on failure */ -int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci); +int update_ucontact(struct urecord *_r, ucontact_t *_c, ucontact_info_t *_ci); /* ====== per contact attributes ====== */ @@ -156,7 +156,7 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci); * \param _ruid usrloc record unique id * \return 0 on success, -1 on failure */ -int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid); +int uldb_delete_attrs(str *_dname, str *_user, str *_domain, str *_ruid); /*! * \brief Insert contact attributes into the database @@ -167,8 +167,8 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid); * \param _xhead head of xavp list * \return 0 on success, -1 on failure */ -int uldb_insert_attrs(str *_dname, str *_user, str *_domain, - str *_ruid, sr_xavp_t *_xhead); +int uldb_insert_attrs( + str *_dname, str *_user, str *_domain, str *_ruid, sr_xavp_t *_xhead); /*! * \brief Set the value for cloning the xavp list to contact structure @@ -176,6 +176,6 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain, */ void ul_set_xavp_contact_clone(int v); -int uldb_delete_attrs_ruid(str* _dname, str *_ruid); +int uldb_delete_attrs_ruid(str *_dname, str *_ruid); #endif diff --git a/src/modules/usrloc/udomain.c b/src/modules/usrloc/udomain.c index 1d30d813bd7..0c1296bf13e 100644 --- a/src/modules/usrloc/udomain.c +++ b/src/modules/usrloc/udomain.c @@ -36,7 +36,7 @@ #include "../../core/ut.h" #include "../../core/hashes.h" #include "../../core/sr_module.h" -#include "usrloc_mod.h" /* usrloc module parameters */ +#include "usrloc_mod.h" /* usrloc module parameters */ #include "usrloc.h" #include "utime.h" #include "ul_callback.h" @@ -47,22 +47,22 @@ extern int ul_rm_expired_delay; extern int ul_db_clean_tcp; #ifdef STATISTICS -static char *build_stat_name( str* domain, char *var_name) +static char *build_stat_name(str *domain, char *var_name) { int n; char *s; char *p; n = domain->len + 1 + strlen(var_name) + 1; - s = (char*)shm_malloc( n ); - if (s==0) { + s = (char *)shm_malloc(n); + if(s == 0) { SHM_MEM_ERROR; return 0; } - memcpy( s, domain->s, domain->len); + memcpy(s, domain->s, domain->len); p = s + domain->len; *(p++) = *ksr_stats_namesep; - memcpy( p , var_name, strlen(var_name)); + memcpy(p, var_name, strlen(var_name)); p += strlen(var_name); *(p++) = 0; return s; @@ -78,7 +78,7 @@ static char *build_stat_name( str* domain, char *var_name) * \param _d new created domain * \return 0 on success, -1 on failure */ -int new_udomain(str* _n, int _s, udomain_t** _d) +int new_udomain(str *_n, int _s, udomain_t **_d) { int i; #ifdef STATISTICS @@ -89,15 +89,15 @@ int new_udomain(str* _n, int _s, udomain_t** _d) * the cache is accessed from timer which * lives in a separate process */ - *_d = (udomain_t*)shm_malloc(sizeof(udomain_t)); - if (!(*_d)) { + *_d = (udomain_t *)shm_malloc(sizeof(udomain_t)); + if(!(*_d)) { SHM_MEM_ERROR; goto error0; } memset(*_d, 0, sizeof(udomain_t)); - (*_d)->table = (hslot_t*)shm_malloc(sizeof(hslot_t) * _s); - if (!(*_d)->table) { + (*_d)->table = (hslot_t *)shm_malloc(sizeof(hslot_t) * _s); + if(!(*_d)->table) { SHM_MEM_ERROR; goto error1; } @@ -105,7 +105,7 @@ int new_udomain(str* _n, int _s, udomain_t** _d) (*_d)->name = _n; for(i = 0; i < _s; i++) { - if(init_slot(*_d, &((*_d)->table[i]), i)<0) { + if(init_slot(*_d, &((*_d)->table[i]), i) < 0) { LM_ERR("failed to init hash table slot %d\n", i); goto error2; } @@ -115,18 +115,23 @@ int new_udomain(str* _n, int _s, udomain_t** _d) #ifdef STATISTICS /* register the statistics */ - if ( (name=build_stat_name(_n,"users"))==0 || register_stat("usrloc", - name, &(*_d)->users, STAT_NO_RESET|STAT_SHM_NAME)!=0 ) { + if((name = build_stat_name(_n, "users")) == 0 + || register_stat("usrloc", name, &(*_d)->users, + STAT_NO_RESET | STAT_SHM_NAME) + != 0) { LM_ERR("failed to add stat variable\n"); goto error2; } - if ( (name=build_stat_name(_n,"contacts"))==0 || register_stat("usrloc", - name, &(*_d)->contacts, STAT_NO_RESET|STAT_SHM_NAME)!=0 ) { + if((name = build_stat_name(_n, "contacts")) == 0 + || register_stat("usrloc", name, &(*_d)->contacts, + STAT_NO_RESET | STAT_SHM_NAME) + != 0) { LM_ERR("failed to add stat variable\n"); goto error2; } - if ( (name=build_stat_name(_n,"expires"))==0 || register_stat("usrloc", - name, &(*_d)->expires, STAT_SHM_NAME)!=0 ) { + if((name = build_stat_name(_n, "expires")) == 0 + || register_stat("usrloc", name, &(*_d)->expires, STAT_SHM_NAME) + != 0) { LM_ERR("failed to add stat variable\n"); goto error2; } @@ -148,11 +153,11 @@ int new_udomain(str* _n, int _s, udomain_t** _d) * \brief Free all memory allocated for the domain * \param _d freed domain */ -void free_udomain(udomain_t* _d) +void free_udomain(udomain_t *_d) { int i; - if (_d->table) { + if(_d->table) { for(i = 0; i < _d->size; i++) { deinit_slot(_d->table + i); } @@ -168,12 +173,12 @@ void free_udomain(udomain_t* _d) * \param _aor address of record * \param _r new created urecord */ -static inline void get_static_urecord(udomain_t* _d, str* _aor, - struct urecord** _r) +static inline void get_static_urecord( + udomain_t *_d, str *_aor, struct urecord **_r) { static struct urecord r; - memset( &r, 0, sizeof(struct urecord) ); + memset(&r, 0, sizeof(struct urecord)); r.aor = *_aor; r.aorhash = ul_get_aorhash(_aor); r.domain = _d->name; @@ -184,23 +189,22 @@ static inline void get_static_urecord(udomain_t* _d, str* _aor, /*! * \brief Debugging helper function */ -void print_udomain(FILE* _f, udomain_t* _d) +void print_udomain(FILE *_f, udomain_t *_d) { int i; - int max=0, slot=0, n=0; - struct urecord* r; + int max = 0, slot = 0, n = 0; + struct urecord *r; fprintf(_f, "---Domain---\n"); fprintf(_f, "name : '%.*s'\n", _d->name->len, ZSW(_d->name->s)); fprintf(_f, "size : %d\n", _d->size); fprintf(_f, "table: %p\n", _d->table); /*fprintf(_f, "lock : %d\n", _d->lock); -- can be a structure --andrei*/ fprintf(_f, "\n"); - for(i=0; i<_d->size; i++) - { + for(i = 0; i < _d->size; i++) { r = _d->table[i].first; n += _d->table[i].n; - if(max<_d->table[i].n){ - max= _d->table[i].n; + if(max < _d->table[i].n) { + max = _d->table[i].n; slot = i; } while(r) { @@ -224,62 +228,63 @@ void print_udomain(FILE* _f, udomain_t* _d) * \param rcon restore connection id * \return pointer to the ucontact_info on success, 0 on failure */ -static inline ucontact_info_t* dbrow2info(db_val_t *vals, str *contact, int rcon) +static inline ucontact_info_t *dbrow2info( + db_val_t *vals, str *contact, int rcon) { static ucontact_info_t ci; static str callid, ua, received, host, path; int port, proto; char *p; - memset( &ci, 0, sizeof(ucontact_info_t)); + memset(&ci, 0, sizeof(ucontact_info_t)); - contact->s = (char*)VAL_STRING(vals); - if (VAL_NULL(vals) || contact->s==0 || contact->s[0]==0) { + contact->s = (char *)VAL_STRING(vals); + if(VAL_NULL(vals) || contact->s == 0 || contact->s[0] == 0) { LM_CRIT("bad contact\n"); return 0; } contact->len = strlen(contact->s); - if (VAL_NULL(vals+1)) { + if(VAL_NULL(vals + 1)) { LM_CRIT("empty expire\n"); return 0; } - ci.expires = UL_DB_EXPIRES_GET(vals+1); + ci.expires = UL_DB_EXPIRES_GET(vals + 1); - if (VAL_NULL(vals+2)) { + if(VAL_NULL(vals + 2)) { LM_CRIT("empty q\n"); return 0; } - ci.q = double2q(VAL_DOUBLE(vals+2)); + ci.q = double2q(VAL_DOUBLE(vals + 2)); - if (VAL_NULL(vals+4)) { + if(VAL_NULL(vals + 4)) { LM_CRIT("empty cseq_nr\n"); return 0; } - ci.cseq = VAL_INT(vals+4); + ci.cseq = VAL_INT(vals + 4); - callid.s = (char*)VAL_STRING(vals+3); - if (VAL_NULL(vals+3) || !callid.s || !callid.s[0]) { + callid.s = (char *)VAL_STRING(vals + 3); + if(VAL_NULL(vals + 3) || !callid.s || !callid.s[0]) { LM_CRIT("bad callid\n"); return 0; } - callid.len = strlen(callid.s); + callid.len = strlen(callid.s); ci.callid = &callid; - if (VAL_NULL(vals+5)) { + if(VAL_NULL(vals + 5)) { LM_CRIT("empty flag\n"); return 0; } - ci.flags = VAL_BITMAP(vals+5); + ci.flags = VAL_BITMAP(vals + 5); - if (VAL_NULL(vals+6)) { + if(VAL_NULL(vals + 6)) { LM_CRIT("empty cflag\n"); return 0; } - ci.cflags = VAL_BITMAP(vals+6); + ci.cflags = VAL_BITMAP(vals + 6); - ua.s = (char*)VAL_STRING(vals+7); - if (VAL_NULL(vals+7) || !ua.s || !ua.s[0]) { + ua.s = (char *)VAL_STRING(vals + 7); + if(VAL_NULL(vals + 7) || !ua.s || !ua.s[0]) { ua.s = 0; ua.len = 0; } else { @@ -287,8 +292,8 @@ static inline ucontact_info_t* dbrow2info(db_val_t *vals, str *contact, int rcon } ci.user_agent = &ua; - received.s = (char*)VAL_STRING(vals+8); - if (VAL_NULL(vals+8) || !received.s || !received.s[0]) { + received.s = (char *)VAL_STRING(vals + 8); + if(VAL_NULL(vals + 8) || !received.s || !received.s[0]) { received.len = 0; received.s = 0; } else { @@ -296,77 +301,76 @@ static inline ucontact_info_t* dbrow2info(db_val_t *vals, str *contact, int rcon } ci.received = received; - path.s = (char*)VAL_STRING(vals+9); - if (VAL_NULL(vals+9) || !path.s || !path.s[0]) { - path.len = 0; - path.s = 0; - } else { - path.len = strlen(path.s); - } - ci.path= &path; + path.s = (char *)VAL_STRING(vals + 9); + if(VAL_NULL(vals + 9) || !path.s || !path.s[0]) { + path.len = 0; + path.s = 0; + } else { + path.len = strlen(path.s); + } + ci.path = &path; /* socket name */ - p = (char*)VAL_STRING(vals+10); - if (VAL_NULL(vals+10) || p==0 || p[0]==0){ + p = (char *)VAL_STRING(vals + 10); + if(VAL_NULL(vals + 10) || p == 0 || p[0] == 0) { ci.sock = 0; } else { - if (parse_phostport( p, &host.s, &host.len, - &port, &proto)!=0) { + if(parse_phostport(p, &host.s, &host.len, &port, &proto) != 0) { LM_ERR("bad socket <%s>\n", p); return 0; } - ci.sock = grep_sock_info( &host, (unsigned short)port, proto); - if (ci.sock==0) { + ci.sock = grep_sock_info(&host, (unsigned short)port, proto); + if(ci.sock == 0) { LM_DBG("non-local socket <%s>...ignoring\n", p); - if (ul_skip_remote_socket) { + if(ul_skip_remote_socket) { return 0; } } } /* supported methods */ - if (VAL_NULL(vals+11)) { + if(VAL_NULL(vals + 11)) { ci.methods = ALL_METHODS; } else { - ci.methods = VAL_BITMAP(vals+11); + ci.methods = VAL_BITMAP(vals + 11); } /* last modified time */ - if (!VAL_NULL(vals+12)) { - ci.last_modified = UL_DB_EXPIRES_GET(vals+12); + if(!VAL_NULL(vals + 12)) { + ci.last_modified = UL_DB_EXPIRES_GET(vals + 12); } /* record internal uid */ - if (!VAL_NULL(vals+13)) { - ci.ruid.s = (char*)VAL_STRING(vals+13); + if(!VAL_NULL(vals + 13)) { + ci.ruid.s = (char *)VAL_STRING(vals + 13); ci.ruid.len = strlen(ci.ruid.s); } /* sip instance */ - if (!VAL_NULL(vals+14)) { - ci.instance.s = (char*)VAL_STRING(vals+14); + if(!VAL_NULL(vals + 14)) { + ci.instance.s = (char *)VAL_STRING(vals + 14); ci.instance.len = strlen(ci.instance.s); } /* reg-id */ - if (!VAL_NULL(vals+15)) { - ci.reg_id = VAL_UINT(vals+15); + if(!VAL_NULL(vals + 15)) { + ci.reg_id = VAL_UINT(vals + 15); } /* server_id */ - if (!VAL_NULL(vals+16)) { - ci.server_id = VAL_UINT(vals+16); + if(!VAL_NULL(vals + 16)) { + ci.server_id = VAL_UINT(vals + 16); } /* tcp connection id (not restored always) */ ci.tcpconn_id = -1; - if(rcon==1 && !VAL_NULL(vals+17)) { - ci.tcpconn_id = VAL_UINT(vals+17); + if(rcon == 1 && !VAL_NULL(vals + 17)) { + ci.tcpconn_id = VAL_UINT(vals + 17); } /* keepalive */ - if (!VAL_NULL(vals+18)) { - ci.keepalive = VAL_UINT(vals+18); + if(!VAL_NULL(vals + 18)) { + ci.keepalive = VAL_UINT(vals + 18); } return &ci; @@ -379,23 +383,24 @@ static inline ucontact_info_t* dbrow2info(db_val_t *vals, str *contact, int rcon * \param _d loaded domain * \return 0 on success, -1 on failure */ -int uldb_delete_tcp_records(db1_con_t* _c, udomain_t* _d) +int uldb_delete_tcp_records(db1_con_t *_c, udomain_t *_d) { db_key_t keys[2]; - db_op_t ops[2]; + db_op_t ops[2]; db_val_t vals[2]; int nr_keys = 0; LM_DBG("delete location tcp records\n"); - keys[nr_keys] = &ul_con_id_col;; + keys[nr_keys] = &ul_con_id_col; + ; ops[nr_keys] = OP_GT; vals[nr_keys].type = DB1_INT; vals[nr_keys].nul = 0; vals[nr_keys].val.int_val = 0; nr_keys++; - if (ul_db_srvid != 0) { + if(ul_db_srvid != 0) { keys[nr_keys] = &ul_srv_id_col; ops[nr_keys] = OP_EQ; vals[nr_keys].type = DB1_INT; @@ -404,13 +409,13 @@ int uldb_delete_tcp_records(db1_con_t* _c, udomain_t* _d) nr_keys++; } - if (ul_dbf.use_table(_c, _d->name) < 0) { + if(ul_dbf.use_table(_c, _d->name) < 0) { LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.delete(_c, keys, ops, vals, nr_keys) < 0) { + if(ul_dbf.delete(_c, keys, ops, vals, nr_keys) < 0) { LM_ERR("deleting from database failed\n"); return -1; } @@ -428,25 +433,25 @@ int uldb_delete_tcp_records(db1_con_t* _c, udomain_t* _d) * \param _d loaded domain * \return 0 on success, -1 on failure */ -int preload_udomain(db1_con_t* _c, udomain_t* _d) +int preload_udomain(db1_con_t *_c, udomain_t *_d) { char uri[MAX_URI_SIZE]; ucontact_info_t *ci; db_row_t *row; db_key_t columns[21]; - db1_res_t* res = NULL; + db1_res_t *res = NULL; db_key_t keys[1]; /* where */ db_val_t vals[1]; - db_op_t ops[1]; + db_op_t ops[1]; str user, contact; - char* domain; + char *domain; int i; int n; - urecord_t* r; - ucontact_t* c; + urecord_t *r; + ucontact_t *c; - if(ul_db_clean_tcp!=0) { + if(ul_db_clean_tcp != 0) { uldb_delete_tcp_records(_c, _d); } @@ -472,7 +477,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) columns[19] = &ul_keepalive_col; columns[20] = &ul_domain_col; - if (ul_dbf.use_table(_c, _d->name) < 0) { + if(ul_dbf.use_table(_c, _d->name) < 0) { LM_ERR("sql use_table failed\n"); return -1; } @@ -481,7 +486,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) LM_NOTICE("load start time [%d]\n", (int)time(NULL)); #endif - if (ul_db_srvid) { + if(ul_db_srvid) { LM_NOTICE("filtered by server_id[%d]\n", server_id); keys[0] = &ul_srv_id_col; ops[0] = OP_EQ; @@ -490,31 +495,31 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) vals[0].val.int_val = server_id; } - if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { - if (ul_dbf.query(_c, (ul_db_srvid)?(keys):(0), - (ul_db_srvid)?(ops):(0), (ul_db_srvid)?(vals):(0), - columns, (ul_db_srvid)?(1):(0), - (ul_use_domain)?(21):(20), 0, 0) < 0) - { + if(DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { + if(ul_dbf.query(_c, (ul_db_srvid) ? (keys) : (0), + (ul_db_srvid) ? (ops) : (0), (ul_db_srvid) ? (vals) : (0), + columns, (ul_db_srvid) ? (1) : (0), + (ul_use_domain) ? (21) : (20), 0, 0) + < 0) { LM_ERR("db_query (1) failed\n"); return -1; } - if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows)<0) { + if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows) < 0) { LM_ERR("fetching rows failed\n"); return -1; } } else { - if (ul_dbf.query(_c, (ul_db_srvid)?(keys):(0), - (ul_db_srvid)?(ops):(0), (ul_db_srvid)?(vals):(0), - columns, (ul_db_srvid)?(1):(0), - (ul_use_domain)?(21):(20), 0, &res) < 0) - { + if(ul_dbf.query(_c, (ul_db_srvid) ? (keys) : (0), + (ul_db_srvid) ? (ops) : (0), (ul_db_srvid) ? (vals) : (0), + columns, (ul_db_srvid) ? (1) : (0), + (ul_use_domain) ? (21) : (20), 0, &res) + < 0) { LM_ERR("db_query failed\n"); return -1; } } - if (RES_ROW_N(res) == 0) { + if(RES_ROW_N(res) == 0) { LM_DBG("table is empty\n"); ul_dbf.free_result(_c, res); return 0; @@ -527,49 +532,50 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) for(i = 0; i < RES_ROW_N(res); i++) { row = RES_ROWS(res) + i; - user.s = (char*)VAL_STRING(ROW_VALUES(row)); - if (VAL_NULL(ROW_VALUES(row)) || user.s==0 || user.s[0]==0) { + user.s = (char *)VAL_STRING(ROW_VALUES(row)); + if(VAL_NULL(ROW_VALUES(row)) || user.s == 0 || user.s[0] == 0) { LM_CRIT("empty username record in table %s...skipping\n", _d->name->s); continue; } user.len = strlen(user.s); - ci = dbrow2info(ROW_VALUES(row)+1, &contact, 0); - if (ci==0) { - LM_ERR("skipping record for %.*s in table %s\n", - user.len, user.s, _d->name->s); + ci = dbrow2info(ROW_VALUES(row) + 1, &contact, 0); + if(ci == 0) { + LM_ERR("skipping record for %.*s in table %s\n", user.len, + user.s, _d->name->s); continue; } - if (ul_use_domain) { - domain = (char*)VAL_STRING(ROW_VALUES(row) + 20); - if (VAL_NULL(ROW_VALUES(row)+17) || domain==0 || domain[0]==0){ + if(ul_use_domain) { + domain = (char *)VAL_STRING(ROW_VALUES(row) + 20); + if(VAL_NULL(ROW_VALUES(row) + 17) || domain == 0 + || domain[0] == 0) { LM_CRIT("empty domain record for user %.*s...skipping\n", user.len, user.s); continue; } /* user.s cannot be NULL - checked previosly */ - user.len = snprintf(uri, MAX_URI_SIZE, "%.*s@%s", - user.len, user.s, domain); + user.len = snprintf( + uri, MAX_URI_SIZE, "%.*s@%s", user.len, user.s, domain); user.s = uri; - if (user.s[user.len]!=0) { + if(user.s[user.len] != 0) { LM_CRIT("URI '%.*s@%s' longer than %d\n", user.len, user.s, - domain, MAX_URI_SIZE); + domain, MAX_URI_SIZE); continue; } } lock_udomain(_d, &user); - if (get_urecord(_d, &user, &r) > 0) { - if (mem_insert_urecord(_d, &user, &r) < 0) { + if(get_urecord(_d, &user, &r) > 0) { + if(mem_insert_urecord(_d, &user, &r) < 0) { LM_ERR("failed to create a record\n"); unlock_udomain(_d, &user); goto error; } } - if ( (c=mem_insert_ucontact(r, &contact, ci)) == 0) { + if((c = mem_insert_ucontact(r, &contact, ci)) == 0) { LM_ERR("inserting contact failed\n"); unlock_udomain(_d, &user); goto error1; @@ -581,8 +587,8 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) unlock_udomain(_d, &user); } - if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { - if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows)<0) { + if(DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { + if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows) < 0) { LM_ERR("fetching rows (1) failed\n"); ul_dbf.free_result(_c, res); return -1; @@ -590,7 +596,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) } else { break; } - } while(RES_ROW_N(res)>0); + } while(RES_ROW_N(res) > 0); ul_dbf.free_result(_c, res); @@ -614,7 +620,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) * \param _aor address of record * \return pointer to the record on success, 0 on errors or if nothing is found */ -urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) +urecord_t *db_load_urecord(db1_con_t *_c, udomain_t *_d, str *_aor) { char tname_buf[64]; str tname; @@ -623,7 +629,7 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) db_key_t keys[2]; db_key_t order; db_val_t vals[2]; - db1_res_t* res = NULL; + db1_res_t *res = NULL; db_row_t *row; str aname; str avalue; @@ -632,24 +638,24 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) char *domain; int i; - urecord_t* r; - ucontact_t* c; + urecord_t *r; + ucontact_t *c; keys[0] = &ul_user_col; vals[0].type = DB1_STR; vals[0].nul = 0; - if (ul_use_domain) { + if(ul_use_domain) { keys[1] = &ul_domain_col; vals[1].type = DB1_STR; vals[1].nul = 0; domain = memchr(_aor->s, '@', _aor->len); - vals[0].val.str_val.s = _aor->s; - if (domain==0) { + vals[0].val.str_val.s = _aor->s; + if(domain == 0) { vals[0].val.str_val.len = 0; vals[1].val.str_val = *_aor; } else { vals[0].val.str_val.len = domain - _aor->s; - vals[1].val.str_val.s = domain+1; + vals[1].val.str_val.s = domain + 1; vals[1].val.str_val.len = _aor->s + _aor->len - domain - 1; } } else { @@ -676,24 +682,26 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) columns[17] = &ul_con_id_col; columns[18] = &ul_keepalive_col; - if (ul_desc_time_order) + if(ul_desc_time_order) order = &ul_last_mod_col; else order = &ul_q_col; - if (ul_dbf.use_table(_c, _d->name) < 0) { + if(ul_dbf.use_table(_c, _d->name) < 0) { LM_ERR("failed to use table %.*s\n", _d->name->len, _d->name->s); return 0; } - if (ul_dbf.query(_c, keys, 0, vals, columns, (ul_use_domain)?2:1, 19, order, - &res) < 0) { + if(ul_dbf.query(_c, keys, 0, vals, columns, (ul_use_domain) ? 2 : 1, 19, + order, &res) + < 0) { LM_ERR("db_query failed\n"); return 0; } - if (RES_ROW_N(res) == 0) { - LM_DBG("aor %.*s not found in table %.*s\n",_aor->len, _aor->s, _d->name->len, _d->name->s); + if(RES_ROW_N(res) == 0) { + LM_DBG("aor %.*s not found in table %.*s\n", _aor->len, _aor->s, + _d->name->len, _d->name->s); ul_dbf.free_result(_c, res); return 0; } @@ -702,16 +710,16 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) for(i = 0; i < RES_ROW_N(res); i++) { ci = dbrow2info(ROW_VALUES(RES_ROWS(res) + i), &contact, 1); - if (ci==0) { - LM_ERR("skipping record for %.*s in table %s\n", - _aor->len, _aor->s, _d->name->s); + if(ci == 0) { + LM_ERR("skipping record for %.*s in table %s\n", _aor->len, _aor->s, + _d->name->s); continue; } - if ( r==0 ) - get_static_urecord( _d, _aor, &r); + if(r == 0) + get_static_urecord(_d, _aor, &r); - if ( (c=mem_insert_ucontact(r, &contact, ci)) == 0) { + if((c = mem_insert_ucontact(r, &contact, ci)) == 0) { LM_ERR("mem_insert failed\n"); free_urecord(r); ul_dbf.free_result(_c, res); @@ -726,12 +734,12 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) ul_dbf.free_result(_c, res); /* Retrieve ul attributes */ - if(ul_xavp_contact_name.s==NULL) { + if(ul_xavp_contact_name.s == NULL) { /* feature disabled by mod param */ goto done; } - if(_d->name->len + 6>=64) { + if(_d->name->len + 6 >= 64) { LM_ERR("attributes table name is too big\n"); goto done; } @@ -748,23 +756,24 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) columns[1] = &ulattrs_atype_col; columns[2] = &ulattrs_avalue_col; - if (ul_dbf.use_table(ul_dbh, &tname) < 0) { + if(ul_dbf.use_table(ul_dbh, &tname) < 0) { LM_ERR("sql use_table failed for %.*s\n", tname.len, tname.s); goto done; } - if(r==0) goto done; + if(r == 0) + goto done; - for (c = r->contacts; c != NULL; c = c->next) { + for(c = r->contacts; c != NULL; c = c->next) { vals[0].val.str_val.s = c->ruid.s; vals[0].val.str_val.len = c->ruid.len; - if (ul_dbf.query(ul_dbh, keys, 0, vals, columns, 1, 3, 0, &res) < 0) { + if(ul_dbf.query(ul_dbh, keys, 0, vals, columns, 1, 3, 0, &res) < 0) { LM_ERR("db_query failed\n"); continue; } - if (RES_ROW_N(res) == 0) { + if(RES_ROW_N(res) == 0) { LM_DBG("location attrs table is empty\n"); ul_dbf.free_result(ul_dbh, res); continue; @@ -773,16 +782,16 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) for(i = 0; i < RES_ROW_N(res); i++) { row = RES_ROWS(res) + i; - aname.s = (char*)VAL_STRING(ROW_VALUES(row)); + aname.s = (char *)VAL_STRING(ROW_VALUES(row)); aname.len = strlen(aname.s); - avalue.s = (char*)VAL_STRING(ROW_VALUES(row) + 2); + avalue.s = (char *)VAL_STRING(ROW_VALUES(row) + 2); avalue.len = strlen(avalue.s); memset(&aval, 0, sizeof(sr_xval_t)); - if(VAL_INT(ROW_VALUES(row)+1)==0) { + if(VAL_INT(ROW_VALUES(row) + 1) == 0) { /* string value */ aval.v.s = avalue; aval.type = SR_XTYPE_STR; - } else if(VAL_INT(ROW_VALUES(row)+1)==1) { + } else if(VAL_INT(ROW_VALUES(row) + 1) == 1) { /* long int value */ str2slong(&avalue, &aval.v.l); aval.type = SR_XTYPE_LONG; @@ -792,13 +801,15 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) } /* add xavp to contact */ - if(c->xavp==NULL) { - if(xavp_add_xavp_value(&ul_xavp_contact_name, &aname, - &aval, &c->xavp)==NULL) + if(c->xavp == NULL) { + if(xavp_add_xavp_value( + &ul_xavp_contact_name, &aname, &aval, &c->xavp) + == NULL) LM_INFO("cannot add first xavp to contact - ignoring\n"); } else { - if(c->xavp->val.type==SR_XTYPE_XAVP) { - if(xavp_add_value(&aname, &aval, &c->xavp->val.v.xavp)==NULL) + if(c->xavp->val.type == SR_XTYPE_XAVP) { + if(xavp_add_value(&aname, &aval, &c->xavp->val.v.xavp) + == NULL) LM_INFO("cannot add values to contact xavp\n"); } } @@ -818,22 +829,22 @@ urecord_t* db_load_urecord(db1_con_t* _c, udomain_t* _d, str *_aor) * \param _ruid record unique id * \return pointer to the record on success, 0 on errors or if nothing is found */ -urecord_t* db_load_urecord_by_ruid(db1_con_t* _c, udomain_t* _d, str *_ruid) +urecord_t *db_load_urecord_by_ruid(db1_con_t *_c, udomain_t *_d, str *_ruid) { ucontact_info_t *ci; db_key_t columns[21]; db_key_t keys[1]; db_key_t order; db_val_t vals[1]; - db1_res_t* res = NULL; + db1_res_t *res = NULL; db_row_t *row; str contact; str aor; static char aorbuf[512]; str domain; - urecord_t* r; - ucontact_t* c; + urecord_t *r; + ucontact_t *c; keys[0] = &ul_ruid_col; vals[0].type = DB1_STR; @@ -862,24 +873,23 @@ urecord_t* db_load_urecord_by_ruid(db1_con_t* _c, udomain_t* _d, str *_ruid) columns[19] = &ul_user_col; columns[20] = &ul_domain_col; - if (ul_desc_time_order) + if(ul_desc_time_order) order = &ul_last_mod_col; else order = &ul_q_col; - if (ul_dbf.use_table(_c, _d->name) < 0) { + if(ul_dbf.use_table(_c, _d->name) < 0) { LM_ERR("failed to use table %.*s\n", _d->name->len, _d->name->s); return 0; } - if (ul_dbf.query(_c, keys, 0, vals, columns, 1, 21, order, - &res) < 0) { + if(ul_dbf.query(_c, keys, 0, vals, columns, 1, 21, order, &res) < 0) { LM_ERR("db_query failed\n"); return 0; } - if (RES_ROW_N(res) == 0) { - LM_DBG("aor %.*s not found in table %.*s\n",_ruid->len, _ruid->s, + if(RES_ROW_N(res) == 0) { + LM_DBG("aor %.*s not found in table %.*s\n", _ruid->len, _ruid->s, _d->name->len, _d->name->s); ul_dbf.free_result(_c, res); return 0; @@ -891,20 +901,21 @@ urecord_t* db_load_urecord_by_ruid(db1_con_t* _c, udomain_t* _d, str *_ruid) row = RES_ROWS(res); ci = dbrow2info(ROW_VALUES(RES_ROWS(res)), &contact, 1); - if (ci==0) { - LM_ERR("skipping record for %.*s in table %s\n", - _ruid->len, _ruid->s, _d->name->s); + if(ci == 0) { + LM_ERR("skipping record for %.*s in table %s\n", _ruid->len, _ruid->s, + _d->name->s); goto done; } - aor.s = (char*)VAL_STRING(ROW_VALUES(row) + 19); + aor.s = (char *)VAL_STRING(ROW_VALUES(row) + 19); aor.len = strlen(aor.s); - if (ul_use_domain) { - domain.s = (char*)VAL_STRING(ROW_VALUES(row) + 20); - if (VAL_NULL(ROW_VALUES(row)+20) || domain.s==0 || domain.s[0]==0){ - LM_CRIT("empty domain record for user %.*s...skipping\n", - aor.len, aor.s); + if(ul_use_domain) { + domain.s = (char *)VAL_STRING(ROW_VALUES(row) + 20); + if(VAL_NULL(ROW_VALUES(row) + 20) || domain.s == 0 + || domain.s[0] == 0) { + LM_CRIT("empty domain record for user %.*s...skipping\n", aor.len, + aor.s); goto done; } domain.len = strlen(domain.s); @@ -919,9 +930,9 @@ urecord_t* db_load_urecord_by_ruid(db1_con_t* _c, udomain_t* _d, str *_ruid) aor.s = aorbuf; aor.s[aor.len] = '\0'; } - get_static_urecord( _d, &aor, &r); + get_static_urecord(_d, &aor, &r); - if ( (c=mem_insert_ucontact(r, &contact, ci)) == 0) { + if((c = mem_insert_ucontact(r, &contact, ci)) == 0) { LM_ERR("mem_insert failed\n"); free_urecord(r); ul_dbf.free_result(_c, res); @@ -946,20 +957,20 @@ urecord_t* db_load_urecord_by_ruid(db1_con_t* _c, udomain_t* _d, str *_ruid) * \param _d loaded domain * \return 0 on success, -1 on failure */ -int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) +int udomain_contact_expired_cb(db1_con_t *_c, udomain_t *_d) { ucontact_info_t *ci; db_row_t *row; db_key_t columns[21], query_cols[3]; - db_op_t query_ops[3]; + db_op_t query_ops[3]; db_val_t query_vals[3]; int key_num = 2; - db1_res_t* res = NULL; + db1_res_t *res = NULL; str user, contact, domain; int i; int n; urecord_t r; - ucontact_t* c; + ucontact_t *c; #define RUIDBUF_SIZE 128 char ruidbuf[RUIDBUF_SIZE]; str ruid; @@ -967,7 +978,7 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) char aorbuf[AORBUF_SIZE]; str aor; - if (ul_db_mode!=DB_ONLY) { + if(ul_db_mode != DB_ONLY) { return 0; } @@ -1003,7 +1014,7 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) query_vals[1].nul = 0; UL_DB_EXPIRES_SET(&query_vals[1], 0); - if (ul_db_srvid != 0) { + if(ul_db_srvid != 0) { query_cols[2] = &ul_srv_id_col; query_ops[2] = OP_EQ; query_vals[2].type = DB1_INT; @@ -1012,7 +1023,7 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) key_num = 3; } - if (ul_dbf.use_table(_c, _d->name) < 0) { + if(ul_dbf.use_table(_c, _d->name) < 0) { LM_ERR("sql use_table failed\n"); return -1; } @@ -1021,27 +1032,27 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) LM_NOTICE("udomain contact-expired start time [%d]\n", (int)time(NULL)); #endif - if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { - if (ul_dbf.query(_c, query_cols, query_ops, query_vals, columns, key_num, - (ul_use_domain)?(21):(20), 0, - 0) < 0) { + if(DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { + if(ul_dbf.query(_c, query_cols, query_ops, query_vals, columns, key_num, + (ul_use_domain) ? (21) : (20), 0, 0) + < 0) { LM_ERR("db_query (1) failed\n"); return -1; } - if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows)<0) { + if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows) < 0) { LM_ERR("fetching rows failed\n"); return -1; } } else { - if (ul_dbf.query(_c, query_cols, query_ops, query_vals, columns, key_num, - (ul_use_domain)?(21):(20), 0, - &res) < 0) { + if(ul_dbf.query(_c, query_cols, query_ops, query_vals, columns, key_num, + (ul_use_domain) ? (21) : (20), 0, &res) + < 0) { LM_ERR("db_query failed\n"); return -1; } } - if (RES_ROW_N(res) == 0) { + if(RES_ROW_N(res) == 0) { LM_DBG("no rows to be contact expired\n"); ul_dbf.free_result(_c, res); return 0; @@ -1053,14 +1064,14 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) for(i = 0; i < RES_ROW_N(res); i++) { row = RES_ROWS(res) + i; - user.s = (char*)VAL_STRING(ROW_VALUES(row)); - if (VAL_NULL(ROW_VALUES(row)) || user.s==0 || user.s[0]==0) { + user.s = (char *)VAL_STRING(ROW_VALUES(row)); + if(VAL_NULL(ROW_VALUES(row)) || user.s == 0 || user.s[0] == 0) { LM_CRIT("empty username record in table %s...skipping\n", - _d->name->s); + _d->name->s); continue; } user.len = strlen(user.s); - if(user.len < AORBUF_SIZE ) { + if(user.len < AORBUF_SIZE) { memcpy(aorbuf, user.s, user.len); aor.s = aorbuf; aor.len = user.len; @@ -1069,19 +1080,19 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) continue; } - ci = dbrow2info(ROW_VALUES(row)+1, &contact, 0); - if (ci==0) { - LM_CRIT("skipping record for %.*s in table %s\n", - user.len, user.s, _d->name->s); + ci = dbrow2info(ROW_VALUES(row) + 1, &contact, 0); + if(ci == 0) { + LM_CRIT("skipping record for %.*s in table %s\n", user.len, + user.s, _d->name->s); continue; } if(ul_use_domain) { - domain.s = (char*)VAL_STRING(ROW_VALUES(row)+20); + domain.s = (char *)VAL_STRING(ROW_VALUES(row) + 20); domain.len = strlen(domain.s); if(domain.len + aor.len < AORBUF_SIZE) { aorbuf[aor.len] = '@'; - memcpy(aorbuf+aor.len+1, domain.s, domain.len); + memcpy(aorbuf + aor.len + 1, domain.s, domain.len); aor.len += domain.len + 1; } else { LM_ERR("aor too long, using user part only\n"); @@ -1090,22 +1101,22 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) lock_udomain(_d, &aor); /* don't use the same static value from get_static_urecord() */ - memset( &r, 0, sizeof(struct urecord) ); + memset(&r, 0, sizeof(struct urecord)); r.aor = aor; r.aorhash = ul_get_aorhash(&aor); r.domain = _d->name; - if ( (c=mem_insert_ucontact(&r, &contact, ci)) == 0) { - LM_ERR("inserting temporary contact failed for %.*s\n", - aor.len, aor.s); + if((c = mem_insert_ucontact(&r, &contact, ci)) == 0) { + LM_ERR("inserting temporary contact failed for %.*s\n", aor.len, + aor.s); release_urecord(&r); unlock_udomain(_d, &aor); goto error; } /* Call the contact-expired call-back if it exists for the contact */ - if (exists_ulcb_type(UL_CONTACT_EXPIRE)) { - run_ul_callbacks( UL_CONTACT_EXPIRE, c); + if(exists_ulcb_type(UL_CONTACT_EXPIRE)) { + run_ul_callbacks(UL_CONTACT_EXPIRE, c); } c->state = CS_SYNC; ruid.len = 0; @@ -1129,8 +1140,8 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) } } - if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { - if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows)<0) { + if(DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { + if(ul_dbf.fetch_result(_c, &res, ul_fetch_rows) < 0) { LM_ERR("fetching rows (1) failed\n"); ul_dbf.free_result(_c, res); return -1; @@ -1138,7 +1149,7 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) } else { break; } - } while(RES_ROW_N(res)>0); + } while(RES_ROW_N(res) > 0); ul_dbf.free_result(_c, res); @@ -1160,15 +1171,15 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d) * \param _d cleaned domain * \return 0 on success, -1 on failure */ -int db_timer_udomain(udomain_t* _d) +int db_timer_udomain(udomain_t *_d) { db_key_t keys[3]; - db_op_t ops[3]; + db_op_t ops[3]; db_val_t vals[3]; int key_num = 2; /* If contact-expired callback exists, run it for a domain before deleting database rows */ - if (exists_ulcb_type(UL_CONTACT_EXPIRE)) { + if(exists_ulcb_type(UL_CONTACT_EXPIRE)) { udomain_contact_expired_cb(ul_dbh, _d); } @@ -1182,7 +1193,7 @@ int db_timer_udomain(udomain_t* _d) vals[1].nul = 0; UL_DB_EXPIRES_SET(&vals[1], 0); - if (ul_db_srvid != 0) { + if(ul_db_srvid != 0) { keys[2] = &ul_srv_id_col; ops[2] = OP_EQ; vals[2].type = DB1_INT; @@ -1191,13 +1202,13 @@ int db_timer_udomain(udomain_t* _d) key_num = 3; } - if (ul_dbf.use_table(ul_dbh, _d->name) < 0) { + if(ul_dbf.use_table(ul_dbh, _d->name) < 0) { LM_ERR("use_table failed\n"); return -1; } - if (ul_dbf.delete(ul_dbh, keys, ops, vals, key_num) < 0) { - LM_ERR("failed to delete from table %s\n",_d->name->s); + if(ul_dbf.delete(ul_dbh, keys, ops, vals, key_num) < 0) { + LM_ERR("failed to delete from table %s\n", _d->name->s); return -1; } @@ -1210,11 +1221,11 @@ int db_timer_udomain(udomain_t* _d) * \param con database connection * \param d domain */ -int testdb_udomain(db1_con_t* con, udomain_t* d) +int testdb_udomain(db1_con_t *con, udomain_t *d) { db_key_t key[2], col[1]; db_val_t val[2]; - db1_res_t* res = NULL; + db1_res_t *res = NULL; if(ul_dbf.use_table(con, d->name) < 0) { LM_ERR("failed to change table\n"); @@ -1230,17 +1241,19 @@ int testdb_udomain(db1_con_t* con, udomain_t* d) VAL_NULL(val) = 0; VAL_STRING(val) = "dummy_user"; - VAL_TYPE(val+1) = DB1_STRING; - VAL_NULL(val+1) = 0; - VAL_STRING(val+1) = "dummy_domain"; + VAL_TYPE(val + 1) = DB1_STRING; + VAL_NULL(val + 1) = 0; + VAL_STRING(val + 1) = "dummy_domain"; - if(ul_dbf.query(con, key, 0, val, col, (ul_use_domain)?2:1, 1, 0, &res)<0) { - if(res) ul_dbf.free_result( con, res); + if(ul_dbf.query(con, key, 0, val, col, (ul_use_domain) ? 2 : 1, 1, 0, &res) + < 0) { + if(res) + ul_dbf.free_result(con, res); LM_ERR("failure in db_query\n"); return -1; } - ul_dbf.free_result( con, res); + ul_dbf.free_result(con, res); return 0; } @@ -1252,18 +1265,18 @@ int testdb_udomain(db1_con_t* con, udomain_t* d) * \param _r new created record * \return 0 on success, -1 on failure */ -int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r) +int mem_insert_urecord(udomain_t *_d, str *_aor, struct urecord **_r) { int sl; - if (new_urecord(_d->name, _aor, _r) < 0) { + if(new_urecord(_d->name, _aor, _r) < 0) { LM_ERR("creating urecord failed\n"); return -1; } - sl = ((*_r)->aorhash)&(_d->size-1); + sl = ((*_r)->aorhash) & (_d->size - 1); slot_add(&_d->table[sl], *_r); - update_stat( _d->users, 1); + update_stat(_d->users, 1); return 0; } @@ -1273,11 +1286,11 @@ int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r) * \param _d domain the record belongs to * \param _r deleted record */ -void mem_delete_urecord(udomain_t* _d, struct urecord* _r) +void mem_delete_urecord(udomain_t *_d, struct urecord *_r) { slot_rem(_r->slot, _r); free_urecord(_r); - update_stat( _d->users, -1); + update_stat(_d->users, -1); } @@ -1287,21 +1300,21 @@ void mem_delete_urecord(udomain_t* _d, struct urecord* _r) * \param istart start of run * \param istep loop steps */ -void mem_timer_udomain(udomain_t* _d, int istart, int istep) +void mem_timer_udomain(udomain_t *_d, int istart, int istep) { - struct urecord* ptr, *t; + struct urecord *ptr, *t; int i; - for(i=istart; i<_d->size; i+=istep) - { - if(likely(destroy_modules_phase()==0)) lock_ulslot(_d, i); + for(i = istart; i < _d->size; i += istep) { + if(likely(destroy_modules_phase() == 0)) + lock_ulslot(_d, i); ptr = _d->table[i].first; while(ptr) { timer_urecord(ptr); /* Remove the entire record if it is empty */ - if (ptr->contacts == 0) { + if(ptr->contacts == 0) { t = ptr; ptr = ptr->next; mem_delete_urecord(_d, t); @@ -1310,7 +1323,8 @@ void mem_timer_udomain(udomain_t* _d, int istart, int istep) ptr = ptr->next; } } - if(likely(destroy_modules_phase()==0)) unlock_ulslot(_d, i); + if(likely(destroy_modules_phase() == 0)) + unlock_ulslot(_d, i); } } @@ -1320,11 +1334,10 @@ void mem_timer_udomain(udomain_t* _d, int istart, int istep) * \param _d domain * \param _aor address of record, used as hash source for the lock slot */ -void lock_udomain(udomain_t* _d, str* _aor) +void lock_udomain(udomain_t *_d, str *_aor) { unsigned int sl; - if (ul_db_mode!=DB_ONLY) - { + if(ul_db_mode != DB_ONLY) { sl = ul_get_aorhash(_aor) & (_d->size - 1); rec_lock_get(&_d->table[sl].rlock); @@ -1337,11 +1350,10 @@ void lock_udomain(udomain_t* _d, str* _aor) * \param _d domain * \param _aor address of record, uses as hash source for the lock slot */ -void unlock_udomain(udomain_t* _d, str* _aor) +void unlock_udomain(udomain_t *_d, str *_aor) { unsigned int sl; - if (ul_db_mode!=DB_ONLY) - { + if(ul_db_mode != DB_ONLY) { sl = ul_get_aorhash(_aor) & (_d->size - 1); rec_lock_release(&_d->table[sl].rlock); } @@ -1352,9 +1364,9 @@ void unlock_udomain(udomain_t* _d, str* _aor) * \param _d domain * \param i slot number */ -void lock_ulslot(udomain_t* _d, int i) +void lock_ulslot(udomain_t *_d, int i) { - if (ul_db_mode!=DB_ONLY) + if(ul_db_mode != DB_ONLY) rec_lock_get(&_d->table[i].rlock); } @@ -1364,14 +1376,13 @@ void lock_ulslot(udomain_t* _d, int i) * \param _d domain * \param i slot number */ -void unlock_ulslot(udomain_t* _d, int i) +void unlock_ulslot(udomain_t *_d, int i) { - if (ul_db_mode!=DB_ONLY) + if(ul_db_mode != DB_ONLY) rec_lock_release(&_d->table[i].rlock); } - /*! * \brief Create and insert a new record * \param _d domain to insert the new record @@ -1379,15 +1390,15 @@ void unlock_ulslot(udomain_t* _d, int i) * \param _r new created record * \return return 0 on success, -1 on failure */ -int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r) +int insert_urecord(udomain_t *_d, str *_aor, struct urecord **_r) { - if (ul_db_mode!=DB_ONLY) { - if (mem_insert_urecord(_d, _aor, _r) < 0) { + if(ul_db_mode != DB_ONLY) { + if(mem_insert_urecord(_d, _aor, _r) < 0) { LM_ERR("inserting record failed\n"); return -1; } } else { - get_static_urecord( _d, _aor, _r); + get_static_urecord(_d, _aor, _r); } return 0; } @@ -1400,29 +1411,26 @@ int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r) * \param _r new created record * \return 0 if a record was found, 1 if nothing could be found */ -int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r) +int get_urecord(udomain_t *_d, str *_aor, struct urecord **_r) { unsigned int sl, i, aorhash; - urecord_t* r; - ucontact_t* ptr = NULL; + urecord_t *r; + ucontact_t *ptr = NULL; - if (ul_db_mode!=DB_ONLY) { + if(ul_db_mode != DB_ONLY) { /* search in cache */ aorhash = ul_get_aorhash(_aor); - sl = aorhash&(_d->size-1); + sl = aorhash & (_d->size - 1); r = _d->table[sl].first; - for(i = 0; r!=NULL && i < _d->table[sl].n; i++) { - if((r->aorhash==aorhash) && (r->aor.len==_aor->len) - && !memcmp(r->aor.s,_aor->s,_aor->len)) - { - if (ul_handle_lost_tcp) - { - for (ptr = r->contacts;ptr;ptr = ptr->next) - { - if (ptr->expires == UL_EXPIRED_TIME ) + for(i = 0; r != NULL && i < _d->table[sl].n; i++) { + if((r->aorhash == aorhash) && (r->aor.len == _aor->len) + && !memcmp(r->aor.s, _aor->s, _aor->len)) { + if(ul_handle_lost_tcp) { + for(ptr = r->contacts; ptr; ptr = ptr->next) { + if(ptr->expires == UL_EXPIRED_TIME) continue; - if (is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) + if(is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) ptr->expires = UL_EXPIRED_TIME; } } @@ -1434,14 +1442,14 @@ int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r) } } else { /* search in DB */ - r = db_load_urecord( ul_dbh, _d, _aor); - if (r) { + r = db_load_urecord(ul_dbh, _d, _aor); + if(r) { *_r = r; return 0; } } - return 1; /* Nothing found */ + return 1; /* Nothing found */ } /*! @@ -1453,25 +1461,25 @@ int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r) * \param _c store pointer to contact structure * \return 0 if a record was found, -1 if nothing could be found */ -int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash, - str *_ruid, struct urecord** _r, struct ucontact** _c) +int get_urecord_by_ruid(udomain_t *_d, unsigned int _aorhash, str *_ruid, + struct urecord **_r, struct ucontact **_c) { unsigned int sl, i; - urecord_t* r; - ucontact_t* c; + urecord_t *r; + ucontact_t *c; - sl = _aorhash&(_d->size-1); + sl = _aorhash & (_d->size - 1); lock_ulslot(_d, sl); - if (ul_db_mode!=DB_ONLY) { + if(ul_db_mode != DB_ONLY) { /* search in cache */ r = _d->table[sl].first; for(i = 0; i < _d->table[sl].n; i++) { - if(r->aorhash==_aorhash) { + if(r->aorhash == _aorhash) { c = r->contacts; while(c) { - if(c->ruid.len==_ruid->len + if(c->ruid.len == _ruid->len && !memcmp(c->ruid.s, _ruid->s, _ruid->len)) { *_r = r; *_c = c; @@ -1485,11 +1493,11 @@ int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash, } else { /* search in DB */ r = db_load_urecord_by_ruid(ul_dbh, _d, _ruid); - if (r) { - if(r->aorhash==_aorhash) { + if(r) { + if(r->aorhash == _aorhash) { c = r->contacts; while(c) { - if(c->ruid.len==_ruid->len + if(c->ruid.len == _ruid->len && !memcmp(c->ruid.s, _ruid->s, _ruid->len)) { *_r = r; *_c = c; @@ -1502,7 +1510,7 @@ int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash, } unlock_ulslot(_d, (_aorhash & (_d->size - 1))); - return -1; /* Nothing found */ + return -1; /* Nothing found */ } /*! @@ -1512,14 +1520,14 @@ int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash, * \param _r deleted record * \return 0 on success, -1 if the record could not be deleted */ -int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r) +int delete_urecord(udomain_t *_d, str *_aor, struct urecord *_r) { - struct ucontact* c, *t; + struct ucontact *c, *t; - if (ul_db_mode==DB_ONLY) { - if (_r==0) - get_static_urecord( _d, _aor, &_r); - if (db_delete_urecord(_r)<0) { + if(ul_db_mode == DB_ONLY) { + if(_r == 0) + get_static_urecord(_d, _aor, &_r); + if(db_delete_urecord(_r) < 0) { LM_ERR("DB delete failed\n"); return -1; } @@ -1527,8 +1535,8 @@ int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r) return 0; } - if (_r==0) { - if (get_urecord(_d, _aor, &_r) > 0) { + if(_r == 0) { + if(get_urecord(_d, _aor, &_r) > 0) { return 0; } } @@ -1537,7 +1545,7 @@ int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r) while(c) { t = c; c = c->next; - if (delete_ucontact(_r, t) < 0) { + if(delete_ucontact(_r, t) < 0) { LM_ERR("deleting contact failed\n"); return -1; } @@ -1558,12 +1566,12 @@ int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r) int uldb_preload_attrs(udomain_t *_d) { char uri[MAX_URI_SIZE]; - str suri; + str suri; char tname_buf[64]; str tname; db_row_t *row; db_key_t columns[6]; - db1_res_t* res = NULL; + db1_res_t *res = NULL; str user = {0}; str domain = {0}; str ruid; @@ -1573,15 +1581,15 @@ int uldb_preload_attrs(udomain_t *_d) int i; int n; - urecord_t* r; - ucontact_t* c; + urecord_t *r; + ucontact_t *c; - if(ul_xavp_contact_name.s==NULL) { + if(ul_xavp_contact_name.s == NULL) { /* feature disabled by mod param */ return 0; } - if(_d->name->len + 6>=64) { + if(_d->name->len + 6 >= 64) { LM_ERR("attributes table name is too big\n"); return -1; } @@ -1598,7 +1606,7 @@ int uldb_preload_attrs(udomain_t *_d) columns[4] = &ulattrs_avalue_col; columns[5] = &ulattrs_domain_col; - if (ul_dbf.use_table(ul_dbh, &tname) < 0) { + if(ul_dbf.use_table(ul_dbh, &tname) < 0) { LM_ERR("sql use_table failed for %.*s\n", tname.len, tname.s); return -1; } @@ -1607,25 +1615,27 @@ int uldb_preload_attrs(udomain_t *_d) LM_NOTICE("load start time [%d]\n", (int)time(NULL)); #endif - if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { - if (ul_dbf.query(ul_dbh, 0, 0, 0, columns, 0, (ul_use_domain)?(6):(5), 0, - 0) < 0) { + if(DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { + if(ul_dbf.query(ul_dbh, 0, 0, 0, columns, 0, + (ul_use_domain) ? (6) : (5), 0, 0) + < 0) { LM_ERR("db_query (1) failed\n"); return -1; } - if(ul_dbf.fetch_result(ul_dbh, &res, ul_fetch_rows)<0) { + if(ul_dbf.fetch_result(ul_dbh, &res, ul_fetch_rows) < 0) { LM_ERR("fetching rows failed\n"); return -1; } } else { - if (ul_dbf.query(ul_dbh, 0, 0, 0, columns, 0, (ul_use_domain)?(6):(5), 0, - &res) < 0) { + if(ul_dbf.query(ul_dbh, 0, 0, 0, columns, 0, + (ul_use_domain) ? (6) : (5), 0, &res) + < 0) { LM_ERR("db_query failed\n"); return -1; } } - if (RES_ROW_N(res) == 0) { + if(RES_ROW_N(res) == 0) { LM_DBG("location attrs table is empty\n"); ul_dbf.free_result(ul_dbh, res); return 0; @@ -1638,26 +1648,26 @@ int uldb_preload_attrs(udomain_t *_d) for(i = 0; i < RES_ROW_N(res); i++) { row = RES_ROWS(res) + i; - user.s = (char*)VAL_STRING(ROW_VALUES(row)); - if (VAL_NULL(ROW_VALUES(row)) || user.s==0 || user.s[0]==0) { + user.s = (char *)VAL_STRING(ROW_VALUES(row)); + if(VAL_NULL(ROW_VALUES(row)) || user.s == 0 || user.s[0] == 0) { LM_CRIT("empty username record in table %s...skipping\n", _d->name->s); continue; } user.len = strlen(user.s); - ruid.s = (char*)VAL_STRING(ROW_VALUES(row) + 1); + ruid.s = (char *)VAL_STRING(ROW_VALUES(row) + 1); ruid.len = strlen(ruid.s); - aname.s = (char*)VAL_STRING(ROW_VALUES(row) + 2); + aname.s = (char *)VAL_STRING(ROW_VALUES(row) + 2); aname.len = strlen(aname.s); - avalue.s = (char*)VAL_STRING(ROW_VALUES(row) + 4); + avalue.s = (char *)VAL_STRING(ROW_VALUES(row) + 4); avalue.len = strlen(avalue.s); memset(&aval, 0, sizeof(sr_xval_t)); - if(VAL_INT(ROW_VALUES(row)+3)==0) { + if(VAL_INT(ROW_VALUES(row) + 3) == 0) { /* string value */ aval.v.s = avalue; aval.type = SR_XTYPE_STR; - } else if(VAL_INT(ROW_VALUES(row)+3)==1) { + } else if(VAL_INT(ROW_VALUES(row) + 3) == 1) { /* long int value */ str2slong(&avalue, &aval.v.l); aval.type = SR_XTYPE_LONG; @@ -1666,19 +1676,20 @@ int uldb_preload_attrs(udomain_t *_d) continue; } - if (ul_use_domain) { - domain.s = (char*)VAL_STRING(ROW_VALUES(row) + 5); - if (VAL_NULL(ROW_VALUES(row)+5) || domain.s==0 || domain.s[0]==0){ + if(ul_use_domain) { + domain.s = (char *)VAL_STRING(ROW_VALUES(row) + 5); + if(VAL_NULL(ROW_VALUES(row) + 5) || domain.s == 0 + || domain.s[0] == 0) { LM_CRIT("empty domain record for user %.*s...skipping\n", user.len, user.s); continue; } domain.len = strlen(domain.s); /* user.s cannot be NULL - checked previosly */ - suri.len = snprintf(uri, MAX_URI_SIZE, "%.*s@%s", - user.len, user.s, domain.s); + suri.len = snprintf(uri, MAX_URI_SIZE, "%.*s@%s", user.len, + user.s, domain.s); suri.s = uri; - if (suri.s[suri.len]!=0) { + if(suri.s[suri.len] != 0) { LM_CRIT("URI '%.*s@%s' longer than %d\n", user.len, user.s, domain.s, MAX_URI_SIZE); continue; @@ -1687,19 +1698,23 @@ int uldb_preload_attrs(udomain_t *_d) suri = user; } - if (get_urecord_by_ruid(_d, ul_get_aorhash(&suri), &ruid, &r, &c) < 0) { + if(get_urecord_by_ruid(_d, ul_get_aorhash(&suri), &ruid, &r, &c) + < 0) { /* delete attrs records from db table */ LM_INFO("no contact record for this ruid\n"); uldb_delete_attrs(_d->name, &user, &domain, &ruid); } else { /* add xavp to contact */ - if(c->xavp==NULL) { - if(xavp_add_xavp_value(&ul_xavp_contact_name, &aname, - &aval, &c->xavp)==NULL) - LM_INFO("cannot add first xavp to contact - ignoring\n"); + if(c->xavp == NULL) { + if(xavp_add_xavp_value( + &ul_xavp_contact_name, &aname, &aval, &c->xavp) + == NULL) + LM_INFO("cannot add first xavp to contact - " + "ignoring\n"); } else { - if(c->xavp->val.type==SR_XTYPE_XAVP) { - if(xavp_add_value(&aname, &aval, &c->xavp->val.v.xavp)==NULL) + if(c->xavp->val.type == SR_XTYPE_XAVP) { + if(xavp_add_value(&aname, &aval, &c->xavp->val.v.xavp) + == NULL) LM_INFO("cannot add values to contact xavp\n"); } } @@ -1708,8 +1723,8 @@ int uldb_preload_attrs(udomain_t *_d) } } - if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { - if(ul_dbf.fetch_result(ul_dbh, &res, ul_fetch_rows)<0) { + if(DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) { + if(ul_dbf.fetch_result(ul_dbh, &res, ul_fetch_rows) < 0) { LM_ERR("fetching rows (1) failed\n"); ul_dbf.free_result(ul_dbh, res); return -1; @@ -1717,7 +1732,7 @@ int uldb_preload_attrs(udomain_t *_d) } else { break; } - } while(RES_ROW_N(res)>0); + } while(RES_ROW_N(res) > 0); ul_dbf.free_result(ul_dbh, res); diff --git a/src/modules/usrloc/udomain.h b/src/modules/usrloc/udomain.h index 97125c09c72..0382bf3628c 100644 --- a/src/modules/usrloc/udomain.h +++ b/src/modules/usrloc/udomain.h @@ -37,21 +37,22 @@ #include "hslot.h" #include "usrloc.h" -struct hslot; /*!< Hash table slot */ +struct hslot; /*!< Hash table slot */ struct urecord; /*!< Usrloc record */ /*! \brief * The structure represents a usrloc domain */ -struct udomain { - str* name; /*!< Domain name (NULL terminated) */ - int size; /*!< Hash table size */ - struct hslot* table; /*!< Hash table - array of collision slots */ +struct udomain +{ + str *name; /*!< Domain name (NULL terminated) */ + int size; /*!< Hash table size */ + struct hslot *table; /*!< Hash table - array of collision slots */ /* statistics */ - stat_var *users; /*!< no of registered users */ - stat_var *contacts; /*!< no of registered contacts */ - stat_var *expires; /*!< no of expires */ + stat_var *users; /*!< no of registered users */ + stat_var *contacts; /*!< no of registered contacts */ + stat_var *expires; /*!< no of expires */ }; @@ -63,20 +64,20 @@ struct udomain { * \param _d new created domain * \return 0 on success, -1 on failure */ -int new_udomain(str* _n, int _s, udomain_t** _d); +int new_udomain(str *_n, int _s, udomain_t **_d); /*! * \brief Free all memory allocated for the domain * \param _d freed domain */ -void free_udomain(udomain_t* _d); +void free_udomain(udomain_t *_d); /*! * \brief Print udomain, debugging helper function */ -void print_udomain(FILE* _f, udomain_t* _d); +void print_udomain(FILE *_f, udomain_t *_d); /*! @@ -88,7 +89,7 @@ void print_udomain(FILE* _f, udomain_t* _d); * \param _d loaded domain * \return 0 on success, -1 on failure */ -int preload_udomain(db1_con_t* _c, udomain_t* _d); +int preload_udomain(db1_con_t *_c, udomain_t *_d); /*! @@ -96,7 +97,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d); * \param con database connection * \param d domain */ -int testdb_udomain(db1_con_t* con, udomain_t* d); +int testdb_udomain(db1_con_t *con, udomain_t *d); /*! @@ -104,7 +105,7 @@ int testdb_udomain(db1_con_t* con, udomain_t* d); * \param _d cleaned domain * \return 0 on success, -1 on failure */ -int db_timer_udomain(udomain_t* _d); +int db_timer_udomain(udomain_t *_d); /*! @@ -113,7 +114,7 @@ int db_timer_udomain(udomain_t* _d); * \param istart index of hash table slot to start processing * \param istep step through hash table slots to process */ -void mem_timer_udomain(udomain_t* _d, int istart, int istep); +void mem_timer_udomain(udomain_t *_d, int istart, int istep); /*! @@ -123,7 +124,7 @@ void mem_timer_udomain(udomain_t* _d, int istart, int istep); * \param _r new created record * \return 0 on success, -1 on failure */ -int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r); +int mem_insert_urecord(udomain_t *_d, str *_aor, struct urecord **_r); /*! @@ -131,13 +132,13 @@ int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r); * \param _d domain the record belongs to * \param _r deleted record */ -void mem_delete_urecord(udomain_t* _d, struct urecord* _r); +void mem_delete_urecord(udomain_t *_d, struct urecord *_r); /*! \brief * Timer handler for given domain */ -void lock_udomain(udomain_t* _d, str *_aor); +void lock_udomain(udomain_t *_d, str *_aor); /*! @@ -145,7 +146,7 @@ void lock_udomain(udomain_t* _d, str *_aor); * \param _d domain * \param _aor address of record, uses as hash source for the lock slot */ -void unlock_udomain(udomain_t* _d, str *_aor); +void unlock_udomain(udomain_t *_d, str *_aor); /*! @@ -153,14 +154,14 @@ void unlock_udomain(udomain_t* _d, str *_aor); * \param _d domain * \param i slot number */ -void lock_ulslot(udomain_t* _d, int i); +void lock_ulslot(udomain_t *_d, int i); /*! * \brief Release lock for a slot * \param _d domain * \param i slot number */ -void unlock_ulslot(udomain_t* _d, int i); +void unlock_ulslot(udomain_t *_d, int i); /* ===== module interface ======= */ @@ -172,7 +173,7 @@ void unlock_ulslot(udomain_t* _d, int i); * \param _r new created record * \return return 0 on success, -1 on failure */ -int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r); +int insert_urecord(udomain_t *_d, str *_aor, struct urecord **_r); /*! @@ -182,7 +183,7 @@ int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r); * \param _r new created record * \return 0 if a record was found, 1 if nothing could be found */ -int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r); +int get_urecord(udomain_t *_d, str *_aor, struct urecord **_r); /*! * \brief Obtain a urecord pointer if the urecord exists in domain (lock slot) @@ -193,8 +194,8 @@ int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r); * \param _c store pointer to contact structure * \return 0 if a record was found, 1 if nothing could be found */ -int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash, - str *_ruid, struct urecord** _r, struct ucontact** _c); +int get_urecord_by_ruid(udomain_t *_d, unsigned int _aorhash, str *_ruid, + struct urecord **_r, struct ucontact **_c); /*! * \brief Delete a urecord from domain @@ -203,7 +204,7 @@ int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash, * \param _r deleted record * \return 0 on success, -1 if the record could not be deleted */ -int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r); +int delete_urecord(udomain_t *_d, str *_aor, struct urecord *_r); /* ===== per-contact attributes ======= */ diff --git a/src/modules/usrloc/ul_callback.c b/src/modules/usrloc/ul_callback.c index a3f028b15d5..aa710c1f1e6 100644 --- a/src/modules/usrloc/ul_callback.c +++ b/src/modules/usrloc/ul_callback.c @@ -35,15 +35,14 @@ #include "ul_callback.h" #include "ucontact.h" -struct ulcb_head_list* ulcb_list = 0; - +struct ulcb_head_list *ulcb_list = 0; int init_ulcb_list(void) { - ulcb_list = (struct ulcb_head_list*)shm_malloc - ( sizeof(struct ulcb_head_list) ); - if (ulcb_list==0) { + ulcb_list = + (struct ulcb_head_list *)shm_malloc(sizeof(struct ulcb_head_list)); + if(ulcb_list == 0) { SHM_MEM_CRITICAL; return -1; } @@ -57,41 +56,41 @@ void destroy_ulcb_list(void) { struct ul_callback *cbp, *cbp_tmp; - if (!ulcb_list) + if(!ulcb_list) return; - for( cbp=ulcb_list->first; cbp ; ) { + for(cbp = ulcb_list->first; cbp;) { cbp_tmp = cbp; cbp = cbp->next; - if (cbp_tmp->param) shm_free( cbp_tmp->param ); - shm_free( cbp_tmp ); + if(cbp_tmp->param) + shm_free(cbp_tmp->param); + shm_free(cbp_tmp); } shm_free(ulcb_list); } - /*! \brief register a callback function 'f' for 'types' mask of events; */ -int register_ulcb( int types, ul_cb f, void *param ) +int register_ulcb(int types, ul_cb f, void *param) { struct ul_callback *cbp; /* are the callback types valid?... */ - if ( types<0 || types>ULCB_MAX ) { - LM_CRIT("invalid callback types: mask=%d\n",types); + if(types < 0 || types > ULCB_MAX) { + LM_CRIT("invalid callback types: mask=%d\n", types); return E_BUG; } /* we don't register null functions */ - if (f==0) { + if(f == 0) { LM_CRIT("null callback function\n"); return E_BUG; } /* build a new callback structure */ - if (!(cbp=(struct ul_callback*)shm_malloc(sizeof( struct ul_callback)))) { + if(!(cbp = (struct ul_callback *)shm_malloc(sizeof(struct ul_callback)))) { SHM_MEM_ERROR; return E_OUT_OF_MEM; } @@ -104,13 +103,10 @@ int register_ulcb( int types, ul_cb f, void *param ) cbp->callback = f; cbp->param = param; cbp->types = types; - if (cbp->next) - cbp->id = cbp->next->id+1; + if(cbp->next) + cbp->id = cbp->next->id + 1; else cbp->id = 0; return 1; } - - - diff --git a/src/modules/usrloc/ul_callback.h b/src/modules/usrloc/ul_callback.h index b65870c1477..598efab2b35 100644 --- a/src/modules/usrloc/ul_callback.h +++ b/src/modules/usrloc/ul_callback.h @@ -32,37 +32,38 @@ /* forward declaration for ucontact_t */ struct ucontact; -#define UL_CONTACT_INSERT (1<<0) -#define UL_CONTACT_UPDATE (1<<1) -#define UL_CONTACT_DELETE (1<<2) -#define UL_CONTACT_EXPIRE (1<<3) -#define ULCB_MAX ((1<<4)-1) +#define UL_CONTACT_INSERT (1 << 0) +#define UL_CONTACT_UPDATE (1 << 1) +#define UL_CONTACT_DELETE (1 << 2) +#define UL_CONTACT_EXPIRE (1 << 3) +#define ULCB_MAX ((1 << 4) - 1) /*! \brief callback function prototype */ -typedef void (ul_cb) (struct ucontact *c, int type, void *param); +typedef void(ul_cb)(struct ucontact *c, int type, void *param); /*! \brief register callback function prototype */ -typedef int (*register_ulcb_t)( int cb_types, ul_cb f, void *param); +typedef int (*register_ulcb_t)(int cb_types, ul_cb f, void *param); -struct ul_callback { - int id; /*!< id of this callback - useless */ - int types; /*!< types of events that trigger the callback*/ - ul_cb* callback; /*!< callback function */ - void *param; /*!< param to be passed to callback function */ - struct ul_callback* next; +struct ul_callback +{ + int id; /*!< id of this callback - useless */ + int types; /*!< types of events that trigger the callback*/ + ul_cb *callback; /*!< callback function */ + void *param; /*!< param to be passed to callback function */ + struct ul_callback *next; }; -struct ulcb_head_list { +struct ulcb_head_list +{ struct ul_callback *first; int reg_types; }; -extern struct ulcb_head_list* ulcb_list; +extern struct ulcb_head_list *ulcb_list; -#define exists_ulcb_type(_types_) \ - ( (ulcb_list->reg_types)&(_types_) ) +#define exists_ulcb_type(_types_) ((ulcb_list->reg_types) & (_types_)) int init_ulcb_list(void); @@ -71,22 +72,21 @@ void destroy_ulcb_list(void); /*! \brief register a callback for several types of events */ -int register_ulcb( int types, ul_cb f, void *param ); +int register_ulcb(int types, ul_cb f, void *param); /*! \brief run all transaction callbacks for an event type */ -static inline void run_ul_callbacks( int type , struct ucontact *c) +static inline void run_ul_callbacks(int type, struct ucontact *c) { struct ul_callback *cbp; - for (cbp=ulcb_list->first; cbp; cbp=cbp->next) { - if(cbp->types&type) { - LM_DBG("contact=%p, callback type %d/%d, id %d entered\n", - c, type, cbp->types, cbp->id ); - cbp->callback( c, type, cbp->param ); + for(cbp = ulcb_list->first; cbp; cbp = cbp->next) { + if(cbp->types & type) { + LM_DBG("contact=%p, callback type %d/%d, id %d entered\n", c, type, + cbp->types, cbp->id); + cbp->callback(c, type, cbp->param); } } } - #endif diff --git a/src/modules/usrloc/ul_keepalive.c b/src/modules/usrloc/ul_keepalive.c index ba855eb0115..9897233ea53 100644 --- a/src/modules/usrloc/ul_keepalive.c +++ b/src/modules/usrloc/ul_keepalive.c @@ -62,14 +62,15 @@ Content-Length: 0\r\n\r\n" #define ULKA_CALLID_PREFIX "ksrulka-" #define ULKA_CALLID_PREFIX_LEN (sizeof(ULKA_CALLID_PREFIX) - 1) -#define ULKA_MSG "%.*s %.*s SIP/2.0\r\n" \ - "Via: SIP/2.0/%.*s %s%.*s%s:%.*s;branch=z9hG4bKx.%u.%u.0\r\n" \ - "%s%.*s%.*s" \ - "From: <%.*s>;tag=%.*s-%x-%lx-%lx-%x.%x\r\n" \ - "To: \r\n" \ - "Call-ID: " ULKA_CALLID_PREFIX "%x-%x-%x.%x\r\n" \ - "CSeq: 80 %.*s\r\n" \ - "Content-Length: 0\r\n\r\n" +#define ULKA_MSG \ + "%.*s %.*s SIP/2.0\r\n" \ + "Via: SIP/2.0/%.*s %s%.*s%s:%.*s;branch=z9hG4bKx.%u.%u.0\r\n" \ + "%s%.*s%.*s" \ + "From: <%.*s>;tag=%.*s-%x-%lx-%lx-%x.%x\r\n" \ + "To: \r\n" \ + "Call-ID: " ULKA_CALLID_PREFIX "%x-%x-%x.%x\r\n" \ + "CSeq: 80 %.*s\r\n" \ + "Content-Length: 0\r\n\r\n" extern str ul_ka_from; extern str ul_ka_domain; @@ -109,46 +110,47 @@ int ul_ka_urecord(urecord_t *ur) struct timeval tv; time_t tnow = 0; - if (ul_ka_mode == ULKA_NONE) { + if(ul_ka_mode == ULKA_NONE) { return 0; } - if(likely(destroy_modules_phase()!=0)) { + if(likely(destroy_modules_phase() != 0)) { return 0; } LM_DBG("keepalive for aor: %.*s\n", ur->aor.len, ur->aor.s); tnow = time(NULL); - for(i=0; iaor.len; i++) { + for(i = 0; i < ur->aor.len; i++) { if(ur->aor.s[i] == '@') { aortype = 1; break; } } _ul_ka_counter++; - for (uc = ur->contacts; uc != NULL; uc = uc->next) { - if (uc->c.len <= 0) { + for(uc = ur->contacts; uc != NULL; uc = uc->next) { + if(uc->c.len <= 0) { continue; } - if((ul_ka_filter&GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) { + if((ul_ka_filter & GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) { continue; } if(ul_ka_mode & ULKA_NAT) { /* keepalive for natted contacts only */ - if (ul_nat_bflag == 0) { + if(ul_nat_bflag == 0) { continue; } - if ((uc->cflags & ul_nat_bflag) != ul_nat_bflag) { + if((uc->cflags & ul_nat_bflag) != ul_nat_bflag) { continue; } } - if(ul_keepalive_timeout>0 && uc->last_keepalive>0) { - if(uc->last_keepalive+ul_keepalive_timeout < tnow) { + if(ul_keepalive_timeout > 0 && uc->last_keepalive > 0) { + if(uc->last_keepalive + ul_keepalive_timeout < tnow) { /* set contact as expired in 10s */ LM_DBG("set expired contact on keepalive (%u + %u < %u)" - " - aor: %.*s c: %.*s\n", (unsigned int)uc->last_keepalive, + " - aor: %.*s c: %.*s\n", + (unsigned int)uc->last_keepalive, (unsigned int)ul_keepalive_timeout, (unsigned int)tnow, ur->aor.len, ur->aor.s, uc->c.len, uc->c.s); if(uc->expires > tnow + 10) { @@ -160,7 +162,7 @@ int ul_ka_urecord(urecord_t *ur) if(uc->received.len > 0) { sdst = uc->received; } else { - if (uc->path.len > 0) { + if(uc->path.len > 0) { if(get_path_dst_uri(&uc->path, &sdst) < 0) { LM_ERR("failed to get first uri for path\n"); continue; @@ -204,12 +206,12 @@ int ul_ka_urecord(urecord_t *ur) idst.id = uc->tcpconn_id; if(ssock->useinfo.name.len > 0) { - if (ssock->useinfo.address.af == AF_INET6) { + if(ssock->useinfo.address.af == AF_INET6) { via_ipv6 = 1; } vaddr = ssock->useinfo.name; } else { - if (ssock->address.af == AF_INET6) { + if(ssock->address.af == AF_INET6) { via_ipv6 = 1; } vaddr = ssock->address_str; @@ -224,39 +226,29 @@ int ul_ka_urecord(urecord_t *ur) bcnt++; gettimeofday(&tv, NULL); kabuf_len = snprintf(kabuf, ULKA_BUF_SIZE - 1, ULKA_MSG, - ul_ka_method.len, ul_ka_method.s, - uc->c.len, uc->c.s, - sproto.len, sproto.s, - (via_ipv6==1)?"[":"", - vaddr.len, vaddr.s, - (via_ipv6==1)?"]":"", - vport.len, vport.s, - _ul_ka_counter, bcnt, - (uc->path.len>0)?"Route: ":"", - (uc->path.len>0)?uc->path.len:0, - (uc->path.len>0)?uc->path.s:"", - (uc->path.len>0)?2:0, - (uc->path.len>0)?"\r\n":"", - ul_ka_from.len, ul_ka_from.s, - uc->ruid.len, uc->ruid.s, ur->aorhash, - (unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec, - _ul_ka_counter, bcnt, - ur->aor.len, ur->aor.s, - (aortype==1)?"":"@", - (aortype==1)?0:ul_ka_domain.len, (aortype==1)?"":ul_ka_domain.s, - fastrand(), my_pid(), - _ul_ka_counter, bcnt, - ul_ka_method.len, ul_ka_method.s); - if(kabuf_len<=0 || kabuf_len>=ULKA_BUF_SIZE) { + ul_ka_method.len, ul_ka_method.s, uc->c.len, uc->c.s, + sproto.len, sproto.s, (via_ipv6 == 1) ? "[" : "", vaddr.len, + vaddr.s, (via_ipv6 == 1) ? "]" : "", vport.len, vport.s, + _ul_ka_counter, bcnt, (uc->path.len > 0) ? "Route: " : "", + (uc->path.len > 0) ? uc->path.len : 0, + (uc->path.len > 0) ? uc->path.s : "", + (uc->path.len > 0) ? 2 : 0, (uc->path.len > 0) ? "\r\n" : "", + ul_ka_from.len, ul_ka_from.s, uc->ruid.len, uc->ruid.s, + ur->aorhash, (unsigned long)tv.tv_sec, + (unsigned long)tv.tv_usec, _ul_ka_counter, bcnt, ur->aor.len, + ur->aor.s, (aortype == 1) ? "" : "@", + (aortype == 1) ? 0 : ul_ka_domain.len, + (aortype == 1) ? "" : ul_ka_domain.s, fastrand(), my_pid(), + _ul_ka_counter, bcnt, ul_ka_method.len, ul_ka_method.s); + if(kabuf_len <= 0 || kabuf_len >= ULKA_BUF_SIZE) { LM_ERR("failed to print the keepalive request\n"); } else { - LM_DBG("keepalive request (len: %d) [[\n%.*s]]\n", - kabuf_len, kabuf_len, kabuf); + LM_DBG("keepalive request (len: %d) [[\n%.*s]]\n", kabuf_len, + kabuf_len, kabuf); kamsg.s = kabuf; kamsg.len = kabuf_len; ul_ka_send(&kamsg, &idst); } - } return 0; } @@ -266,7 +258,7 @@ int ul_ka_urecord(urecord_t *ur) */ static int ul_ka_send(str *kamsg, dest_info_t *kadst) { - if (kadst->proto == PROTO_UDP) { + if(kadst->proto == PROTO_UDP) { return udp_send(kadst, kamsg->s, kamsg->len); } @@ -274,8 +266,7 @@ static int ul_ka_send(str *kamsg, dest_info_t *kadst) else if(kadst->proto == PROTO_WS || kadst->proto == PROTO_WSS) { /*ws-wss*/ return wss_send(kadst, kamsg->s, kamsg->len); - } - else if(kadst->proto == PROTO_TCP) { + } else if(kadst->proto == PROTO_TCP) { /*tcp*/ return tcp_send(kadst, 0, kamsg->s, kamsg->len); } @@ -293,8 +284,7 @@ static int ul_ka_send(str *kamsg, dest_info_t *kadst) } #endif else { - LM_ERR("unknown proto [%d] for sending keepalive\n", - kadst->proto); + LM_ERR("unknown proto [%d] for sending keepalive\n", kadst->proto); return -1; } } @@ -304,19 +294,25 @@ static int ul_ka_send(str *kamsg, dest_info_t *kadst) */ unsigned long ul_ka_fromhex(str *shex, int *err) { - unsigned long v = 0; + unsigned long v = 0; int i; *err = 0; - for (i=0; ilen; i++) { - char b = shex->s[i]; - if (b >= '0' && b <= '9') b = b - '0'; - else if (b >= 'a' && b <='f') b = b - 'a' + 10; - else if (b >= 'A' && b <='F') b = b - 'A' + 10; - else { *err = 1; return 0; }; - v = (v << 4) | (b & 0xF); - } - return v; + for(i = 0; i < shex->len; i++) { + char b = shex->s[i]; + if(b >= '0' && b <= '9') + b = b - '0'; + else if(b >= 'a' && b <= 'f') + b = b - 'a' + 10; + else if(b >= 'A' && b <= 'F') + b = b - 'A' + 10; + else { + *err = 1; + return 0; + }; + v = (v << 4) | (b & 0xF); + } + return v; } /** @@ -344,7 +340,8 @@ int ul_ka_reply_received(sip_msg_t *msg) if(get_cseq(msg)->method.len != ul_ka_method.len) { return 1; } - if(strncmp(get_cseq(msg)->method.s, ul_ka_method.s, ul_ka_method.len) != 0) { + if(strncmp(get_cseq(msg)->method.s, ul_ka_method.s, ul_ka_method.len) + != 0) { return 1; } @@ -399,7 +396,7 @@ int ul_ka_reply_received(sip_msg_t *msg) } LM_DBG("tv usec string is [%.*s] (%d)\n", tok.len, tok.s, tok.len); tvm.tv_usec = ul_ka_fromhex(&tok, &err); - if(err==1) { + if(err == 1) { LM_DBG("invalid tv usec value\n"); return 1; } @@ -421,7 +418,7 @@ int ul_ka_reply_received(sip_msg_t *msg) } LM_DBG("tv sec string is [%.*s] (%d)\n", tok.len, tok.s, tok.len); tvm.tv_sec = ul_ka_fromhex(&tok, &err); - if(err==1) { + if(err == 1) { LM_DBG("invalid tv sec value\n"); return 1; } @@ -443,7 +440,7 @@ int ul_ka_reply_received(sip_msg_t *msg) } LM_DBG("aor hash string is [%.*s] (%d)\n", tok.len, tok.s, tok.len); aorhash = ul_ka_fromhex(&tok, &err); - if(err==1) { + if(err == 1) { LM_DBG("invalid aor hash value\n"); return 1; } @@ -459,21 +456,22 @@ int ul_ka_reply_received(sip_msg_t *msg) } gettimeofday(&tvn, NULL); - tvdiff = (tvn.tv_sec - tvm.tv_sec) * 1000000 - + (tvn.tv_usec - tvm.tv_usec); + tvdiff = (tvn.tv_sec - tvm.tv_sec) * 1000000 + (tvn.tv_usec - tvm.tv_usec); ul_update_keepalive(aorhash, &ruid, tvn.tv_sec, tvdiff); if(ul_ka_loglevel != 255 && ul_ka_logfmt != NULL) { - if (pv_printf_s(msg, ul_ka_logfmt, &tok) == 0) { - LOG(ul_ka_loglevel, "keepalive roundtrip: %u.%06u sec - ruid [%.*s]%.*s\n", - tvdiff/1000000, tvdiff%1000000, ruid.len, ruid.s, + if(pv_printf_s(msg, ul_ka_logfmt, &tok) == 0) { + LOG(ul_ka_loglevel, + "keepalive roundtrip: %u.%06u sec - ruid [%.*s]%.*s\n", + tvdiff / 1000000, tvdiff % 1000000, ruid.len, ruid.s, tok.len, tok.s); return 0; } } - LM_DBG("response of keepalive for ruid [%.*s] aorhash [%u] roundtrip: %u.%06u secs\n", - ruid.len, ruid.s, aorhash, tvdiff/1000000, tvdiff%1000000); + LM_DBG("response of keepalive for ruid [%.*s] aorhash [%u] roundtrip: " + "%u.%06u secs\n", + ruid.len, ruid.s, aorhash, tvdiff / 1000000, tvdiff % 1000000); return 0; } diff --git a/src/modules/usrloc/ul_keepalive.h b/src/modules/usrloc/ul_keepalive.h index 71a59db81a8..b807d392c57 100644 --- a/src/modules/usrloc/ul_keepalive.h +++ b/src/modules/usrloc/ul_keepalive.h @@ -29,9 +29,9 @@ #include "urecord.h" #define ULKA_NONE 0 -#define ULKA_ALL 1 -#define ULKA_NAT (1<<1) -#define ULKA_UDP (1<<2) +#define ULKA_ALL 1 +#define ULKA_NAT (1 << 1) +#define ULKA_UDP (1 << 2) int ul_ka_urecord(urecord_t *ur); int ul_ka_reply_received(sip_msg_t *msg); diff --git a/src/modules/usrloc/ul_rpc.c b/src/modules/usrloc/ul_rpc.c index 491f9134e97..a0e927fca86 100644 --- a/src/modules/usrloc/ul_rpc.c +++ b/src/modules/usrloc/ul_rpc.c @@ -35,269 +35,234 @@ static str rpc_ul_cid = str_init("dfjrewr12386fd6-343@kamailio.rpc"); /*! path used for ul_add and ul_rm_contact */ static str rpc_ul_path = str_init("dummypath"); /*! user agent used for ul_add */ -static str rpc_ul_ua = str_init(NAME " SIP Router - RPC Server"); +static str rpc_ul_ua = str_init(NAME " SIP Router - RPC Server"); extern sruid_t _ul_sruid; -static const char* ul_rpc_dump_doc[2] = { - "Dump user location tables", - 0 -}; +static const char *ul_rpc_dump_doc[2] = {"Dump user location tables", 0}; -int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c) +int rpc_dump_contact(rpc_t *rpc, void *ctx, void *ih, ucontact_t *c) { - void* vh; + void *vh; str empty_str = {"[not set]", 9}; str state_str = {"[not set]", 9}; str socket_str = {"[not set]", 9}; time_t t; t = time(0); - if(rpc->struct_add(ih, "{", "Contact", &vh)<0) - { + if(rpc->struct_add(ih, "{", "Contact", &vh) < 0) { rpc->fault(ctx, 500, "Internal error creating contact struct"); return -1; } - if(rpc->struct_add(vh, "S", "Address", &c->c)<0) - { + if(rpc->struct_add(vh, "S", "Address", &c->c) < 0) { rpc->fault(ctx, 500, "Internal error adding addr"); return -1; } - if (c->expires == 0) { if(rpc->struct_add(vh, "s", "Expires", "permanent")<0) - { + if(c->expires == 0) { + if(rpc->struct_add(vh, "s", "Expires", "permanent") < 0) { rpc->fault(ctx, 500, "Internal error adding expire"); return -1; } - } else if (c->expires == UL_EXPIRED_TIME) { - if(rpc->struct_add(vh, "s", "Expires", "deleted")<0) - { + } else if(c->expires == UL_EXPIRED_TIME) { + if(rpc->struct_add(vh, "s", "Expires", "deleted") < 0) { rpc->fault(ctx, 500, "Internal error adding expire"); return -1; } - } else if (t > c->expires) { - if(rpc->struct_add(vh, "s", "Expires", "expired")<0) - { + } else if(t > c->expires) { + if(rpc->struct_add(vh, "s", "Expires", "expired") < 0) { rpc->fault(ctx, 500, "Internal error adding expire"); return -1; } } else { - if(rpc->struct_add(vh, "d", "Expires", (int)(c->expires - t))<0) - { + if(rpc->struct_add(vh, "d", "Expires", (int)(c->expires - t)) < 0) { rpc->fault(ctx, 500, "Internal error adding expire"); return -1; } } - if (c->state == CS_NEW) { + if(c->state == CS_NEW) { state_str.s = "CS_NEW"; state_str.len = 6; - } else if (c->state == CS_SYNC) { + } else if(c->state == CS_SYNC) { state_str.s = "CS_SYNC"; state_str.len = 7; - } else if (c->state== CS_DIRTY) { + } else if(c->state == CS_DIRTY) { state_str.s = "CS_DIRTY"; state_str.len = 8; } else { state_str.s = "CS_UNKNOWN"; state_str.len = 10; } - if(c->sock) - { + if(c->sock) { socket_str.s = c->sock->sock_str.s; socket_str.len = c->sock->sock_str.len; } - if(rpc->struct_add(vh, "f", "Q", q2double(c->q))<0) - { + if(rpc->struct_add(vh, "f", "Q", q2double(c->q)) < 0) { rpc->fault(ctx, 500, "Internal error adding q"); return -1; } - if(rpc->struct_add(vh, "S", "Call-ID", &c->callid)<0) - { + if(rpc->struct_add(vh, "S", "Call-ID", &c->callid) < 0) { rpc->fault(ctx, 500, "Internal error adding callid"); return -1; } - if(rpc->struct_add(vh, "d", "CSeq", c->cseq)<0) - { + if(rpc->struct_add(vh, "d", "CSeq", c->cseq) < 0) { rpc->fault(ctx, 500, "Internal error adding cseq"); return -1; } if(rpc->struct_add(vh, "S", "User-Agent", - (c->user_agent.len)?&c->user_agent: &empty_str)<0) - { + (c->user_agent.len) ? &c->user_agent : &empty_str) + < 0) { rpc->fault(ctx, 500, "Internal error adding user-agent"); return -1; } if(rpc->struct_add(vh, "S", "Received", - (c->received.len)?&c->received: &empty_str)<0) - { + (c->received.len) ? &c->received : &empty_str) + < 0) { rpc->fault(ctx, 500, "Internal error adding received"); return -1; } - if(rpc->struct_add(vh, "S", "Path", - (c->path.len)?&c->path: &empty_str)<0) - { + if(rpc->struct_add(vh, "S", "Path", (c->path.len) ? &c->path : &empty_str) + < 0) { rpc->fault(ctx, 500, "Internal error adding path"); return -1; } - if(rpc->struct_add(vh, "S", "State", &state_str)<0) - { + if(rpc->struct_add(vh, "S", "State", &state_str) < 0) { rpc->fault(ctx, 500, "Internal error adding state"); return -1; } - if(rpc->struct_add(vh, "u", "Flags", c->flags)<0) - { + if(rpc->struct_add(vh, "u", "Flags", c->flags) < 0) { rpc->fault(ctx, 500, "Internal error adding flags"); return -1; } - if(rpc->struct_add(vh, "u", "CFlags", c->cflags)<0) - { + if(rpc->struct_add(vh, "u", "CFlags", c->cflags) < 0) { rpc->fault(ctx, 500, "Internal error adding cflags"); return -1; } - if(rpc->struct_add(vh, "S", "Socket", &socket_str)<0) - { + if(rpc->struct_add(vh, "S", "Socket", &socket_str) < 0) { rpc->fault(ctx, 500, "Internal error adding socket"); return -1; } - if(rpc->struct_add(vh, "u", "Methods", c->methods)<0) - { + if(rpc->struct_add(vh, "u", "Methods", c->methods) < 0) { rpc->fault(ctx, 500, "Internal error adding methods"); return -1; } - if(rpc->struct_add(vh, "S", "Ruid", (c->ruid.len)?&c->ruid: &empty_str)<0) - { + if(rpc->struct_add(vh, "S", "Ruid", (c->ruid.len) ? &c->ruid : &empty_str) + < 0) { rpc->fault(ctx, 500, "Internal error adding ruid"); return -1; } if(rpc->struct_add(vh, "S", "Instance", - (c->instance.len)?&c->instance: &empty_str)<0) - { + (c->instance.len) ? &c->instance : &empty_str) + < 0) { rpc->fault(ctx, 500, "Internal error adding instance"); return -1; } - if(rpc->struct_add(vh, "u", "Reg-Id", c->reg_id)<0) - { + if(rpc->struct_add(vh, "u", "Reg-Id", c->reg_id) < 0) { rpc->fault(ctx, 500, "Internal error adding reg_id"); return -1; } - if(rpc->struct_add(vh, "d", "Server-Id", c->server_id)<0) - { + if(rpc->struct_add(vh, "d", "Server-Id", c->server_id) < 0) { rpc->fault(ctx, 500, "Internal error adding server_id"); return -1; } - if(rpc->struct_add(vh, "d", "Tcpconn-Id", c->tcpconn_id)<0) - { + if(rpc->struct_add(vh, "d", "Tcpconn-Id", c->tcpconn_id) < 0) { rpc->fault(ctx, 500, "Internal error adding tcpconn_id"); return -1; } - if(rpc->struct_add(vh, "d", "Keepalive", c->keepalive)<0) - { + if(rpc->struct_add(vh, "d", "Keepalive", c->keepalive) < 0) { rpc->fault(ctx, 500, "Internal error adding keepalive"); return -1; } - if(rpc->struct_add(vh, "d", "Last-Keepalive", (int)c->last_keepalive)<0) - { + if(rpc->struct_add(vh, "d", "Last-Keepalive", (int)c->last_keepalive) < 0) { rpc->fault(ctx, 500, "Internal error adding last_keepalive"); return -1; } - if(rpc->struct_add(vh, "d", "KA-Roundtrip", (int)c->ka_roundtrip)<0) - { + if(rpc->struct_add(vh, "d", "KA-Roundtrip", (int)c->ka_roundtrip) < 0) { rpc->fault(ctx, 500, "Internal error adding keepalive roundtrip"); return -1; } - if(rpc->struct_add(vh, "d", "Last-Modified", (int)c->last_modified)<0) - { + if(rpc->struct_add(vh, "d", "Last-Modified", (int)c->last_modified) < 0) { rpc->fault(ctx, 500, "Internal error adding last_modified"); return -1; } return 0; } -static void ul_rpc_dump(rpc_t* rpc, void* ctx) +static void ul_rpc_dump(rpc_t *rpc, void *ctx) { - struct urecord* r; - dlist_t* dl; - udomain_t* dom; + struct urecord *r; + dlist_t *dl; + udomain_t *dom; str brief = {0, 0}; int summary = 0; - ucontact_t* c; - void* th; - void* dah; - void* dh; - void* ah; - void* bh; - void* ih; - void* sh; + ucontact_t *c; + void *th; + void *dah; + void *dh; + void *ah; + void *bh; + void *ih; + void *sh; int max, n, i; rpc->scan(ctx, "*S", &brief); - if(brief.len==5 && (strncmp(brief.s, "brief", 5)==0)) + if(brief.len == 5 && (strncmp(brief.s, "brief", 5) == 0)) summary = 1; - if (rpc->add(ctx, "{", &th) < 0) - { + if(rpc->add(ctx, "{", &th) < 0) { rpc->fault(ctx, 500, "Internal error creating top rpc"); return; } - if (rpc->struct_add(th, "[", "Domains", &dah) < 0) - { + if(rpc->struct_add(th, "[", "Domains", &dah) < 0) { rpc->fault(ctx, 500, "Internal error creating inner struct"); return; } - - for( dl=_ksr_ul_root ; dl ; dl=dl->next ) { + + for(dl = _ksr_ul_root; dl; dl = dl->next) { dom = dl->d; - if (rpc->struct_add(dah, "{", "Domain", &dh) < 0) - { + if(rpc->struct_add(dah, "{", "Domain", &dh) < 0) { rpc->fault(ctx, 500, "Internal error creating inner struct"); return; } - if(rpc->struct_add(dh, "Sd[", - "Domain", &dl->name, - "Size", (int)dom->size, - "AoRs", &ah)<0) - { + if(rpc->struct_add(dh, "Sd[", "Domain", &dl->name, "Size", + (int)dom->size, "AoRs", &ah) + < 0) { rpc->fault(ctx, 500, "Internal error creating inner struct"); return; } - for(i=0,n=0,max=0; isize; i++) { - lock_ulslot( dom, i); + for(i = 0, n = 0, max = 0; i < dom->size; i++) { + lock_ulslot(dom, i); n += dom->table[i].n; - if(maxtable[i].n) - max= dom->table[i].n; - for( r = dom->table[i].first ; r ; r=r->next ) { - if(summary==1) - { - if(rpc->struct_add(ah, "S", - "AoR", &r->aor)<0) - { - unlock_ulslot( dom, i); - rpc->fault(ctx, 500, "Internal error creating aor struct"); + if(max < dom->table[i].n) + max = dom->table[i].n; + for(r = dom->table[i].first; r; r = r->next) { + if(summary == 1) { + if(rpc->struct_add(ah, "S", "AoR", &r->aor) < 0) { + unlock_ulslot(dom, i); + rpc->fault( + ctx, 500, "Internal error creating aor struct"); return; } } else { - if(rpc->struct_add(ah, "{", - "Info", &bh)<0) - { - unlock_ulslot( dom, i); - rpc->fault(ctx, 500, "Internal error creating aor struct"); + if(rpc->struct_add(ah, "{", "Info", &bh) < 0) { + unlock_ulslot(dom, i); + rpc->fault( + ctx, 500, "Internal error creating aor struct"); return; } - if(rpc->struct_add(bh, "Su[", - "AoR", &r->aor, - "HashID", r->aorhash, - "Contacts", &ih)<0) - { - unlock_ulslot( dom, i); - rpc->fault(ctx, 500, "Internal error creating aor struct"); + if(rpc->struct_add(bh, "Su[", "AoR", &r->aor, "HashID", + r->aorhash, "Contacts", &ih) + < 0) { + unlock_ulslot(dom, i); + rpc->fault( + ctx, 500, "Internal error creating aor struct"); return; } - for( c=r->contacts ; c ; c=c->next) - { - if (rpc_dump_contact(rpc, ctx, ih, c) == -1) { + for(c = r->contacts; c; c = c->next) { + if(rpc_dump_contact(rpc, ctx, ih, c) == -1) { unlock_ulslot(dom, i); return; } @@ -305,42 +270,36 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx) } } - unlock_ulslot( dom, i); + unlock_ulslot(dom, i); } /* extra attributes node */ - if(rpc->struct_add(dh, "{", "Stats", &sh)<0) - { + if(rpc->struct_add(dh, "{", "Stats", &sh) < 0) { rpc->fault(ctx, 500, "Internal error creating stats struct"); return; } - if(rpc->struct_add(sh, "dd", - "Records", n, - "Max-Slots", max)<0) - { + if(rpc->struct_add(sh, "dd", "Records", n, "Max-Slots", max) < 0) { rpc->fault(ctx, 500, "Internal error adding stats"); return; } } } -static const char* ul_rpc_lookup_doc[2] = { - "Lookup one AOR in the usrloc location table", - 0 -}; +static const char *ul_rpc_lookup_doc[2] = { + "Lookup one AOR in the usrloc location table", 0}; /*! * \brief Search a domain in the global domain list * \param table domain (table) name * \return pointer to domain if found, 0 if not found */ -static inline udomain_t* rpc_find_domain(str* table) +static inline udomain_t *rpc_find_domain(str *table) { - dlist_t* dom; + dlist_t *dom; - for( dom=_ksr_ul_root ; dom ; dom=dom->next ) { - if ((dom->name.len == table->len) && - !memcmp(dom->name.s, table->s, table->len)) + for(dom = _ksr_ul_root; dom; dom = dom->next) { + if((dom->name.len == table->len) + && !memcmp(dom->name.s, table->s, table->len)) return dom->d; } return 0; @@ -358,12 +317,12 @@ static inline int rpc_fix_aor(str *aor) { char *p; - p = memchr( aor->s, '@', aor->len); - if (ul_use_domain) { - if (p==NULL) + p = memchr(aor->s, '@', aor->len); + if(ul_use_domain) { + if(p == NULL) return -1; } else { - if (p) + if(p) aor->len = p - aor->s; } if(!get_aor_case_sensitive()) @@ -378,45 +337,45 @@ static inline int rpc_fix_aor(str *aor) * \param ctx not used * \note expects 2 arguments: the table name and the AOR */ -static void ul_rpc_lookup(rpc_t* rpc, void* ctx) +static void ul_rpc_lookup(rpc_t *rpc, void *ctx) { - udomain_t* dom; + udomain_t *dom; str table = {0, 0}; str aor = {0, 0}; - void* th; - void* ih; + void *th; + void *ih; urecord_t *rec; - ucontact_t* con; + ucontact_t *con; int ret; int rpl_tree; - if (rpc->scan(ctx, "S", &table) != 1) { + if(rpc->scan(ctx, "S", &table) != 1) { rpc->fault(ctx, 500, "Not enough parameters (table and AOR to lookup)"); return; } - if (rpc->scan(ctx, "S", &aor) != 1) { + if(rpc->scan(ctx, "S", &aor) != 1) { rpc->fault(ctx, 500, "Not enough parameters (table and AOR to lookup)"); return; } /* look for table */ - dom = rpc_find_domain( &table ); - if (dom == NULL) { + dom = rpc_find_domain(&table); + if(dom == NULL) { rpc->fault(ctx, 500, "Domain table not found"); return; } /* process the aor */ - if ( rpc_fix_aor(&aor) != 0 ) { + if(rpc_fix_aor(&aor) != 0) { rpc->fault(ctx, 500, "Domain missing in AOR"); return; } - lock_udomain( dom, &aor); + lock_udomain(dom, &aor); - ret = get_urecord( dom, &aor, &rec); - if (ret == 1) { - unlock_udomain( dom, &aor); + ret = get_urecord(dom, &aor, &rec); + if(ret == 1) { + unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "AOR not found in location table"); return; } @@ -424,17 +383,13 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx) ul_get_act_time(); rpl_tree = 0; - if (rpc->add(ctx, "{", &th) < 0) - { + if(rpc->add(ctx, "{", &th) < 0) { release_urecord(rec); unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Internal error creating outer rpc"); return; } - if(rpc->struct_add(th, "S[", - "AoR", &aor, - "Contacts", &ih)<0) - { + if(rpc->struct_add(th, "S[", "AoR", &aor, "Contacts", &ih) < 0) { release_urecord(rec); unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Internal error creating aor struct"); @@ -442,10 +397,10 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx) } /* We have contacts, list them */ - for( con=rec->contacts ; con ; con=con->next) { - if (VALID_CONTACT(con, ul_act_time)) { + for(con = rec->contacts; con; con = con->next) { + if(VALID_CONTACT(con, ul_act_time)) { rpl_tree++; - if (rpc_dump_contact(rpc, ctx, ih, con) == -1) { + if(rpc_dump_contact(rpc, ctx, ih, con) == -1) { release_urecord(rec); unlock_udomain(dom, &aor); return; @@ -453,124 +408,121 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx) } } release_urecord(rec); - unlock_udomain( dom, &aor); + unlock_udomain(dom, &aor); - if (rpl_tree==0) { + if(rpl_tree == 0) { rpc->fault(ctx, 500, "AOR has no contacts"); return; } return; } -static void ul_rpc_rm_aor(rpc_t* rpc, void* ctx) +static void ul_rpc_rm_aor(rpc_t *rpc, void *ctx) { - udomain_t* dom; + udomain_t *dom; str table = {0, 0}; str aor = {0, 0}; - if (rpc->scan(ctx, "SS", &table, &aor) != 2) { + if(rpc->scan(ctx, "SS", &table, &aor) != 2) { rpc->fault(ctx, 500, "Not enough parameters (table and AOR to lookup)"); return; } /* look for table */ - dom = rpc_find_domain( &table ); - if (dom == NULL) { + dom = rpc_find_domain(&table); + if(dom == NULL) { rpc->fault(ctx, 500, "Domain table not found"); return; } /* process the aor */ - if ( rpc_fix_aor(&aor) != 0 ) { + if(rpc_fix_aor(&aor) != 0) { rpc->fault(ctx, 500, "Domain missing in AOR"); return; } - lock_udomain( dom, &aor); - if (delete_urecord( dom, &aor, 0) < 0) { - unlock_udomain( dom, &aor); + lock_udomain(dom, &aor); + if(delete_urecord(dom, &aor, 0) < 0) { + unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Failed to delete AOR"); return; } - unlock_udomain( dom, &aor); + unlock_udomain(dom, &aor); return; } -static const char* ul_rpc_rm_aor_doc[2] = { - "Delete an address of record including its contacts", - 0 -}; +static const char *ul_rpc_rm_aor_doc[2] = { + "Delete an address of record including its contacts", 0}; -static void ul_rpc_rm_contact(rpc_t* rpc, void* ctx) +static void ul_rpc_rm_contact(rpc_t *rpc, void *ctx) { - udomain_t* dom; + udomain_t *dom; str table = {0, 0}; str aor = {0, 0}; str contact = {0, 0}; urecord_t *rec; - ucontact_t* con; + ucontact_t *con; int ret; - if (rpc->scan(ctx, "SSS", &table, &aor, &contact) != 3) { + if(rpc->scan(ctx, "SSS", &table, &aor, &contact) != 3) { rpc->fault(ctx, 500, "Not enough parameters (table, AOR and contact)"); return; } /* look for table */ - dom = rpc_find_domain( &table ); - if (dom == NULL) { + dom = rpc_find_domain(&table); + if(dom == NULL) { rpc->fault(ctx, 500, "Domain table not found"); return; } /* process the aor */ - if ( rpc_fix_aor(&aor) != 0 ) { + if(rpc_fix_aor(&aor) != 0) { rpc->fault(ctx, 500, "Domain missing in AOR"); return; } - lock_udomain( dom, &aor); + lock_udomain(dom, &aor); - ret = get_urecord( dom, &aor, &rec); - if (ret == 1) { - unlock_udomain( dom, &aor); + ret = get_urecord(dom, &aor, &rec); + if(ret == 1) { + unlock_udomain(dom, &aor); rpc->fault(ctx, 404, "AOR not found"); return; } - ret = get_ucontact( rec, &contact, &rpc_ul_cid, &rpc_ul_path, RPC_UL_CSEQ+1, &con); - if (ret < 0) { + ret = get_ucontact( + rec, &contact, &rpc_ul_cid, &rpc_ul_path, RPC_UL_CSEQ + 1, &con); + if(ret < 0) { release_urecord(rec); - unlock_udomain( dom, &aor); + unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Internal error (can't get contact)"); return; } - if (ret > 0) { + if(ret > 0) { release_urecord(rec); - unlock_udomain( dom, &aor); + unlock_udomain(dom, &aor); rpc->fault(ctx, 404, "Contact not found"); return; } - if (delete_ucontact(rec, con) < 0) { + if(delete_ucontact(rec, con) < 0) { release_urecord(rec); - unlock_udomain( dom, &aor); + unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Internal error (can't delete contact)"); return; } release_urecord(rec); - unlock_udomain( dom, &aor); + unlock_udomain(dom, &aor); return; } -static const char* ul_rpc_rm_contact_doc[2] = { - "Delete a contact from an AOR record", - 0 -}; +static const char *ul_rpc_rm_contact_doc[2] = { + "Delete a contact from an AOR record", 0}; -static void ul_rpc_flush(rpc_t* rpc, void* ctx) +static void ul_rpc_flush(rpc_t *rpc, void *ctx) { if(synchronize_all_udomains(0, 1) != 0) { rpc->fault(ctx, 500, "Operation failed"); @@ -578,10 +530,8 @@ static void ul_rpc_flush(rpc_t* rpc, void* ctx) return; } -static const char* ul_rpc_flush_doc[2] = { - "Flush the usrloc memory cache to DB", - 0 -}; +static const char *ul_rpc_flush_doc[2] = { + "Flush the usrloc memory cache to DB", 0}; /** * test if a rpc parameter is set @@ -591,11 +541,11 @@ static const char* ul_rpc_flush_doc[2] = { */ int ul_rpc_is_param_set(str *p) { - if(p==NULL || p->len==0 || p->s==NULL) + if(p == NULL || p->len == 0 || p->s == NULL) return 0; - if(p->len>1) + if(p->len > 1) return 1; - if((strncmp(p->s, ".", 1)==0) || (strncmp(p->s, "0", 1)==0)) + if((strncmp(p->s, ".", 1) == 0) || (strncmp(p->s, "0", 1) == 0)) return 0; return 1; } @@ -605,7 +555,7 @@ int ul_rpc_is_param_set(str *p) * \note Expects 9 parameters: table name, AOR, contact, expires, Q, * path, flags, cflags, methods */ -static void ul_rpc_add(rpc_t* rpc, void* ctx) +static void ul_rpc_add(rpc_t *rpc, void *ctx) { str table = {0, 0}; str aor = {0, 0}; @@ -616,8 +566,8 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) str temp = {0, 0}; double dtemp; ucontact_info_t ci; - urecord_t* r; - ucontact_t* c; + urecord_t *r; + ucontact_t *c; udomain_t *dom; int ret; @@ -626,7 +576,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) ret = rpc->scan(ctx, "SSSdfSuuu*SS", &table, &aor, &contact, &ci.expires, &dtemp, &path, &ci.flags, &ci.cflags, &ci.methods, &received, &socket); - if (ret < 9) { + if(ret < 9) { LM_ERR("not enough parameters - read so far: %d\n", ret); rpc->fault(ctx, 500, "Not enough parameters or wrong format"); return; @@ -636,43 +586,42 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) } else { LM_DBG("path == 0 -> unset\n"); } - if(ret>9) { + if(ret > 9) { /* received parameter */ if(ul_rpc_is_param_set(&received)) { ci.received.s = received.s; ci.received.len = received.len; } } - if(ret>10) { + if(ret > 10) { /* socket parameter */ if(ul_rpc_is_param_set(&socket)) { ci.sock = lookup_local_socket(&socket); } } LM_DBG("ret: %d table:%.*s aor:%.*s contact:%.*s expires:%d" - " dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n", + " dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n", ret, table.len, table.s, aor.len, aor.s, contact.len, contact.s, - (int) ci.expires, dtemp, (ci.path)?ci.path->len:0, - (ci.path && ci.path->s)?ci.path->s:"", ci.flags, ci.cflags, - (int) ci.methods); + (int)ci.expires, dtemp, (ci.path) ? ci.path->len : 0, + (ci.path && ci.path->s) ? ci.path->s : "", ci.flags, ci.cflags, + (int)ci.methods); ci.q = double2q(dtemp); - temp.s = q2str(ci.q, (unsigned int*)&temp.len); + temp.s = q2str(ci.q, (unsigned int *)&temp.len); LM_DBG("q:%.*s\n", temp.len, temp.s); /* look for table */ - dom = rpc_find_domain( &table ); - if (dom == NULL) { + dom = rpc_find_domain(&table); + if(dom == NULL) { rpc->fault(ctx, 500, "Domain table not found"); return; } /* process the aor */ - if (rpc_fix_aor(&aor) != 0 ) { + if(rpc_fix_aor(&aor) != 0) { rpc->fault(ctx, 500, "Domain missing in AOR"); return; } - if(sruid_next_safe(&_ul_sruid)<0) - { + if(sruid_next_safe(&_ul_sruid) < 0) { rpc->fault(ctx, 500, "Can't obtain next uid"); return; } @@ -683,18 +632,17 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) lock_udomain(dom, &aor); ret = get_urecord(dom, &aor, &r); - if(ret==1) { - if (insert_urecord(dom, &aor, &r) < 0) - { + if(ret == 1) { + if(insert_urecord(dom, &aor, &r) < 0) { unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Can't insert record"); return; } c = 0; } else { - if (get_ucontact( r, &contact, &rpc_ul_cid, &rpc_ul_path, - RPC_UL_CSEQ+1, &c) < 0) - { + if(get_ucontact( + r, &contact, &rpc_ul_cid, &rpc_ul_path, RPC_UL_CSEQ + 1, &c) + < 0) { unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Can't get record"); return; @@ -707,20 +655,18 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) ci.user_agent = &rpc_ul_ua; ci.cseq = RPC_UL_CSEQ; /* 0 expires means permanent contact */ - if (ci.expires!=0) + if(ci.expires != 0) ci.expires += ul_act_time; - if (c) { - if (update_ucontact( r, c, &ci) < 0) - { + if(c) { + if(update_ucontact(r, c, &ci) < 0) { release_urecord(r); unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Can't update contact"); return; } } else { - if ( insert_ucontact(r, &contact, &ci, &c) < 0 ) - { + if(insert_ucontact(r, &contact, &ci, &c) < 0) { release_urecord(r); unlock_udomain(dom, &aor); rpc->fault(ctx, 500, "Can't insert contact"); @@ -733,57 +679,55 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx) return; } -static const char* ul_rpc_add_doc[2] = { - "Add a new contact for an address of record", - 0 -}; +static const char *ul_rpc_add_doc[2] = { + "Add a new contact for an address of record", 0}; #define QUERY_LEN 256 -static void ul_rpc_db_users(rpc_t* rpc, void* ctx) +static void ul_rpc_db_users(rpc_t *rpc, void *ctx) { str table = {0, 0}; char query[QUERY_LEN]; str query_str; - db1_res_t* res = NULL; + db1_res_t *res = NULL; int count = 0; - if (ul_db_mode == NO_DB) { + if(ul_db_mode == NO_DB) { rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); return; } - if (rpc->scan(ctx, "S", &table) != 1) { + if(rpc->scan(ctx, "S", &table) != 1) { rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); return; } - if (ul_user_col.len + ul_domain_col.len + table.len + 32 > QUERY_LEN) { + if(ul_user_col.len + ul_domain_col.len + table.len + 32 > QUERY_LEN) { rpc->fault(ctx, 500, "Too long database query"); return; } - if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + if(!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { rpc->fault(ctx, 500, "Database does not support raw queries"); return; } - if (ul_dbf.use_table(ul_dbh, &table) < 0) { + if(ul_dbf.use_table(ul_dbh, &table) < 0) { rpc->fault(ctx, 500, "Failed to use table"); return; } memset(query, 0, QUERY_LEN); query_str.len = snprintf(query, QUERY_LEN, - "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())", - ul_user_col.len, ul_user_col.s, - ul_domain_col.len, ul_domain_col.s, + "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s WHERE " + "(UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())", + ul_user_col.len, ul_user_col.s, ul_domain_col.len, ul_domain_col.s, table.len, table.s); query_str.s = query; - if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res==NULL) { + if(ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res == NULL) { rpc->fault(ctx, 500, "Failed to query AoR count"); return; } - if (RES_ROW_N(res) > 0) { + if(RES_ROW_N(res) > 0) { count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); } ul_dbf.free_result(ul_dbh, res); @@ -791,53 +735,55 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx) rpc->add(ctx, "d", count); } -static const char* ul_rpc_db_users_doc[2] = { - "Tell number of different unexpired users (AoRs) in database table (db_mode!=0 only)", - 0 -}; +static const char *ul_rpc_db_users_doc[2] = { + "Tell number of different unexpired users (AoRs) in database table " + "(db_mode!=0 only)", + 0}; -static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx) +static void ul_rpc_db_contacts(rpc_t *rpc, void *ctx) { str table = {0, 0}; char query[QUERY_LEN]; str query_str; - db1_res_t* res = NULL; + db1_res_t *res = NULL; int count = 0; - if (ul_db_mode == NO_DB) { + if(ul_db_mode == NO_DB) { rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); return; } - if (rpc->scan(ctx, "S", &table) != 1) { + if(rpc->scan(ctx, "S", &table) != 1) { rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); return; } - if (table.len + 22 > QUERY_LEN) { + if(table.len + 22 > QUERY_LEN) { rpc->fault(ctx, 500, "Too long database query"); return; } - if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + if(!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { rpc->fault(ctx, 500, "Database does not support raw queries"); return; } - if (ul_dbf.use_table(ul_dbh, &table) < 0) { + if(ul_dbf.use_table(ul_dbh, &table) < 0) { rpc->fault(ctx, 500, "Failed to use table"); return; } memset(query, 0, QUERY_LEN); - query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())", + query_str.len = snprintf(query, QUERY_LEN, + "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR " + "(expires > NOW())", table.len, table.s); query_str.s = query; - if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res==NULL) { + if(ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res == NULL) { rpc->fault(ctx, 500, "Failed to query contact count"); return; } - if (RES_ROW_N(res) > 0) { + if(RES_ROW_N(res) > 0) { count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); } ul_dbf.free_result(ul_dbh, res); @@ -845,53 +791,54 @@ static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx) rpc->add(ctx, "d", count); } -static const char* ul_rpc_db_contacts_doc[2] = { - "Tell number of unexpired contacts in database table (db_mode=3 only)", - 0 -}; +static const char *ul_rpc_db_contacts_doc[2] = { + "Tell number of unexpired contacts in database table (db_mode=3 only)", + 0}; -static void ul_rpc_db_expired_contacts(rpc_t* rpc, void* ctx) +static void ul_rpc_db_expired_contacts(rpc_t *rpc, void *ctx) { str table = {0, 0}; char query[QUERY_LEN]; str query_str; - db1_res_t* res = NULL; + db1_res_t *res = NULL; int count = 0; - if (ul_db_mode == NO_DB) { + if(ul_db_mode == NO_DB) { rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); return; } - if (rpc->scan(ctx, "S", &table) != 1) { + if(rpc->scan(ctx, "S", &table) != 1) { rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); return; } - if (table.len + 22 > QUERY_LEN) { + if(table.len + 22 > QUERY_LEN) { rpc->fault(ctx, 500, "Too long database query"); return; } - if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + if(!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { rpc->fault(ctx, 500, "Database does not support raw queries"); return; } - if (ul_dbf.use_table(ul_dbh, &table) < 0) { + if(ul_dbf.use_table(ul_dbh, &table) < 0) { rpc->fault(ctx, 500, "Failed to use table"); return; } memset(query, 0, QUERY_LEN); - query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) > 0) AND (expires <= NOW())", + query_str.len = snprintf(query, QUERY_LEN, + "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) > 0) AND " + "(expires <= NOW())", table.len, table.s); query_str.s = query; - if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res==NULL) { + if(ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res == NULL) { rpc->fault(ctx, 500, "Failed to query contact count"); return; } - if (RES_ROW_N(res) > 0) { + if(RES_ROW_N(res) > 0) { count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); } ul_dbf.free_result(ul_dbh, res); @@ -899,22 +846,18 @@ static void ul_rpc_db_expired_contacts(rpc_t* rpc, void* ctx) rpc->add(ctx, "d", count); } -static const char* ul_rpc_db_expired_contacts_doc[2] = { - "Tell number of expired contacts in database table (db_mode=3 only)", - 0 -}; - -rpc_export_t ul_rpc[] = { - {"ul.dump", ul_rpc_dump, ul_rpc_dump_doc, 0}, - {"ul.lookup", ul_rpc_lookup, ul_rpc_lookup_doc, 0}, - {"ul.rm", ul_rpc_rm_aor, ul_rpc_rm_aor_doc, 0}, - {"ul.rm_contact", ul_rpc_rm_contact, ul_rpc_rm_contact_doc, 0}, - {"ul.flush", ul_rpc_flush, ul_rpc_flush_doc, 0}, - {"ul.add", ul_rpc_add, ul_rpc_add_doc, 0}, - {"ul.db_users", ul_rpc_db_users, ul_rpc_db_users_doc, 0}, - {"ul.db_contacts", ul_rpc_db_contacts, ul_rpc_db_contacts_doc, 0}, - {"ul.db_expired_contacts", ul_rpc_db_expired_contacts, ul_rpc_db_expired_contacts_doc, 0}, - {0, 0, 0, 0} -}; - - +static const char *ul_rpc_db_expired_contacts_doc[2] = { + "Tell number of expired contacts in database table (db_mode=3 only)", + 0}; + +rpc_export_t ul_rpc[] = {{"ul.dump", ul_rpc_dump, ul_rpc_dump_doc, 0}, + {"ul.lookup", ul_rpc_lookup, ul_rpc_lookup_doc, 0}, + {"ul.rm", ul_rpc_rm_aor, ul_rpc_rm_aor_doc, 0}, + {"ul.rm_contact", ul_rpc_rm_contact, ul_rpc_rm_contact_doc, 0}, + {"ul.flush", ul_rpc_flush, ul_rpc_flush_doc, 0}, + {"ul.add", ul_rpc_add, ul_rpc_add_doc, 0}, + {"ul.db_users", ul_rpc_db_users, ul_rpc_db_users_doc, 0}, + {"ul.db_contacts", ul_rpc_db_contacts, ul_rpc_db_contacts_doc, 0}, + {"ul.db_expired_contacts", ul_rpc_db_expired_contacts, + ul_rpc_db_expired_contacts_doc, 0}, + {0, 0, 0, 0}}; diff --git a/src/modules/usrloc/urecord.c b/src/modules/usrloc/urecord.c index aa43ac94b37..e027affc8aa 100644 --- a/src/modules/usrloc/urecord.c +++ b/src/modules/usrloc/urecord.c @@ -52,17 +52,17 @@ int ul_cseq_delay = 20; * \param _r pointer to the new record * \return 0 on success, negative on failure */ -int new_urecord(str* _dom, str* _aor, urecord_t** _r) +int new_urecord(str *_dom, str *_aor, urecord_t **_r) { - *_r = (urecord_t*)shm_malloc(sizeof(urecord_t)); - if (*_r == 0) { + *_r = (urecord_t *)shm_malloc(sizeof(urecord_t)); + if(*_r == 0) { SHM_MEM_ERROR; return -1; } memset(*_r, 0, sizeof(urecord_t)); - (*_r)->aor.s = (char*)shm_malloc(_aor->len); - if ((*_r)->aor.s == 0) { + (*_r)->aor.s = (char *)shm_malloc(_aor->len); + if((*_r)->aor.s == 0) { SHM_MEM_ERROR; shm_free(*_r); *_r = 0; @@ -84,9 +84,9 @@ int new_urecord(str* _dom, str* _aor, urecord_t** _r) * lists first * \param _r freed record list */ -void free_urecord(urecord_t* _r) +void free_urecord(urecord_t *_r) { - ucontact_t* ptr; + ucontact_t *ptr; while(_r->contacts) { ptr = _r->contacts; @@ -95,8 +95,9 @@ void free_urecord(urecord_t* _r) } /* if mem cache is not used, the urecord struct is static*/ - if (ul_db_mode!=DB_ONLY) { - if (_r->aor.s) shm_free(_r->aor.s); + if(ul_db_mode != DB_ONLY) { + if(_r->aor.s) + shm_free(_r->aor.s); shm_free(_r); } } @@ -107,17 +108,17 @@ void free_urecord(urecord_t* _r) * \param _f print output * \param _r printed record */ -void print_urecord(FILE* _f, urecord_t* _r) +void print_urecord(FILE *_f, urecord_t *_r) { - ucontact_t* ptr; + ucontact_t *ptr; fprintf(_f, "...Record(%p)...\n", _r); fprintf(_f, "domain : '%.*s'\n", _r->domain->len, ZSW(_r->domain->s)); fprintf(_f, "aor : '%.*s'\n", _r->aor.len, ZSW(_r->aor.s)); fprintf(_f, "aorhash: '%u'\n", (unsigned)_r->aorhash); - fprintf(_f, "slot: '%d'\n", _r->aorhash&(_r->slot->d->size-1)); + fprintf(_f, "slot: '%d'\n", _r->aorhash & (_r->slot->d->size - 1)); - if (_r->contacts) { + if(_r->contacts) { ptr = _r->contacts; while(ptr) { print_ucontact(_f, ptr); @@ -139,29 +140,30 @@ void print_urecord(FILE* _f, urecord_t* _r) * \param _ci contact information * \return pointer to new created contact on success, 0 on failure */ -ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci) +ucontact_t *mem_insert_ucontact(urecord_t *_r, str *_c, ucontact_info_t *_ci) { - ucontact_t* ptr, *prev = 0; - ucontact_t* c; + ucontact_t *ptr, *prev = 0; + ucontact_t *c; - if ( (c=new_ucontact(_r->domain, &_r->aor, _c, _ci)) == 0) { + if((c = new_ucontact(_r->domain, &_r->aor, _c, _ci)) == 0) { LM_ERR("failed to create new contact\n"); return 0; } - if_update_stat( _r->slot, _r->slot->d->contacts, 1); + if_update_stat(_r->slot, _r->slot->d->contacts, 1); ptr = _r->contacts; - if (!ul_desc_time_order) { + if(!ul_desc_time_order) { while(ptr) { - if (ptr->q < c->q) break; + if(ptr->q < c->q) + break; prev = ptr; ptr = ptr->next; } } - if (ptr) { - if (!ptr->prev) { + if(ptr) { + if(!ptr->prev) { ptr->prev = c; c->next = ptr; _r->contacts = c; @@ -171,7 +173,7 @@ ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci) ptr->prev->next = c; ptr->prev = c; } - } else if (prev) { + } else if(prev) { prev->next = c; c->prev = prev; } else { @@ -187,16 +189,16 @@ ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci) * \param _r record this contact belongs to * \param _c removed contact */ -void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c) +void mem_remove_ucontact(urecord_t *_r, ucontact_t *_c) { - if (_c->prev) { + if(_c->prev) { _c->prev->next = _c->next; - if (_c->next) { + if(_c->next) { _c->next->prev = _c->prev; } } else { _r->contacts = _c->next; - if (_c->next) { + if(_c->next) { _c->next->prev = 0; } } @@ -208,16 +210,16 @@ void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c) * \param _r record this contact belongs to * \param _c deleted contact */ -void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c) +void mem_delete_ucontact(urecord_t *_r, ucontact_t *_c) { mem_remove_ucontact(_r, _c); - if_update_stat( _r->slot, _r->slot->d->contacts, -1); + if_update_stat(_r->slot, _r->slot->d->contacts, -1); free_ucontact(_c); } int is_valid_tcpconn(ucontact_t *c) { - if (c->tcpconn_id == -1) + if(c->tcpconn_id == -1) return 0; /* tcpconn_id is not present */ else return 1; /* valid tcpconn_id */ @@ -228,7 +230,7 @@ int is_tcp_alive(ucontact_t *c) struct tcp_connection *con = NULL; int rc = 0; - if ((con = tcpconn_get(c->tcpconn_id, 0, 0, 0, 0))) { + if((con = tcpconn_get(c->tcpconn_id, 0, 0, 0, 0))) { tcpconn_put(con); /* refcnt-- */ rc = 1; } @@ -242,11 +244,12 @@ int is_tcp_alive(ucontact_t *c) * Requests the TCP main process to close the specified TCP connection * \param conid the internal connection ID */ -static inline int close_connection(int conid) { +static inline int close_connection(int conid) +{ struct tcp_connection *con; long msg[2]; int n; - if ((con = tcpconn_get(conid, 0, 0, 0, 0))) { + if((con = tcpconn_get(conid, 0, 0, 0, 0))) { msg[0] = (long)con; msg[1] = CONN_EOF; @@ -254,8 +257,9 @@ static inline int close_connection(int conid) { con->flags |= F_CONN_FORCE_EOF; n = send_all(unix_tcp_sock, msg, sizeof(msg)); - if (unlikely(n <= 0)){ - LM_ERR("failed to send close request: %s (%d)\n", strerror(errno), errno); + if(unlikely(n <= 0)) { + LM_ERR("failed to send close request: %s (%d)\n", strerror(errno), + errno); return 0; } return 1; @@ -270,31 +274,32 @@ static inline int close_connection(int conid) { * the record, delete the expired ones from memory. * \param _r processed record */ -static inline void nodb_timer(urecord_t* _r) +static inline void nodb_timer(urecord_t *_r) { - ucontact_t* ptr, *t; + ucontact_t *ptr, *t; ptr = _r->contacts; while(ptr) { - if (ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) { - LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s); + if(ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) { + LM_DBG("tcp connection has been lost, expiring contact %.*s\n", + ptr->c.len, ptr->c.s); ptr->expires = UL_EXPIRED_TIME; } - if (!VALID_CONTACT(ptr, ul_act_time)) { + if(!VALID_CONTACT(ptr, ul_act_time)) { /* run callbacks for EXPIRE event */ - if (!(ptr->flags&FL_EXPCLB) && exists_ulcb_type(UL_CONTACT_EXPIRE)) { - run_ul_callbacks( UL_CONTACT_EXPIRE, ptr); + if(!(ptr->flags & FL_EXPCLB) + && exists_ulcb_type(UL_CONTACT_EXPIRE)) { + run_ul_callbacks(UL_CONTACT_EXPIRE, ptr); ptr->flags |= FL_EXPCLB; } - LM_DBG("Binding '%.*s','%.*s' has expired\n", - ptr->aor->len, ZSW(ptr->aor->s), - ptr->c.len, ZSW(ptr->c.s)); + LM_DBG("Binding '%.*s','%.*s' has expired\n", ptr->aor->len, + ZSW(ptr->aor->s), ptr->c.len, ZSW(ptr->c.s)); - if (ul_close_expired_tcp && is_valid_tcpconn(ptr)) { + if(ul_close_expired_tcp && is_valid_tcpconn(ptr)) { close_connection(ptr->tcpconn_id); } @@ -302,7 +307,7 @@ static inline void nodb_timer(urecord_t* _r) ptr = ptr->next; mem_delete_ucontact(_r, t); - update_stat( _r->slot->d->expires, 1); + update_stat(_r->slot->d->expires, 1); } else { ptr = ptr->next; } @@ -318,35 +323,34 @@ static inline void nodb_timer(urecord_t* _r) * \param _r processed record * \note currently unused, this mode is also handled by the wb_timer */ -static inline void wt_timer(urecord_t* _r) +static inline void wt_timer(urecord_t *_r) { - ucontact_t* ptr, *t; + ucontact_t *ptr, *t; ptr = _r->contacts; while(ptr) { - if (!VALID_CONTACT(ptr, ul_act_time)) { + if(!VALID_CONTACT(ptr, ul_act_time)) { /* run callbacks for EXPIRE event */ - if (exists_ulcb_type(UL_CONTACT_EXPIRE)) { - run_ul_callbacks( UL_CONTACT_EXPIRE, ptr); + if(exists_ulcb_type(UL_CONTACT_EXPIRE)) { + run_ul_callbacks(UL_CONTACT_EXPIRE, ptr); } - LM_DBG("Binding '%.*s','%.*s' has expired\n", - ptr->aor->len, ZSW(ptr->aor->s), - ptr->c.len, ZSW(ptr->c.s)); + LM_DBG("Binding '%.*s','%.*s' has expired\n", ptr->aor->len, + ZSW(ptr->aor->s), ptr->c.len, ZSW(ptr->c.s)); - if (ul_close_expired_tcp && is_valid_tcpconn(ptr)) { + if(ul_close_expired_tcp && is_valid_tcpconn(ptr)) { close_connection(ptr->tcpconn_id); } t = ptr; ptr = ptr->next; - if (db_delete_ucontact(t) < 0) { + if(db_delete_ucontact(t) < 0) { LM_ERR("deleting contact from database failed\n"); } mem_delete_ucontact(_r, t); - update_stat( _r->slot->d->expires, 1); + update_stat(_r->slot->d->expires, 1); } else { ptr = ptr->next; } @@ -362,9 +366,9 @@ static inline void wt_timer(urecord_t* _r) * ones in the DB. * \param _r processed record */ -static inline void wb_timer(urecord_t* _r) +static inline void wb_timer(urecord_t *_r) { - ucontact_t* ptr, *t; + ucontact_t *ptr, *t; cstate_t old_state; int op; int res; @@ -372,23 +376,23 @@ static inline void wb_timer(urecord_t* _r) ptr = _r->contacts; while(ptr) { - if (ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) { - LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s); + if(ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) { + LM_DBG("tcp connection has been lost, expiring contact %.*s\n", + ptr->c.len, ptr->c.s); ptr->expires = UL_EXPIRED_TIME; } - if (!VALID_CONTACT(ptr, ul_act_time)) { + if(!VALID_CONTACT(ptr, ul_act_time)) { /* run callbacks for EXPIRE event */ - if (exists_ulcb_type(UL_CONTACT_EXPIRE)) { - run_ul_callbacks( UL_CONTACT_EXPIRE, ptr); + if(exists_ulcb_type(UL_CONTACT_EXPIRE)) { + run_ul_callbacks(UL_CONTACT_EXPIRE, ptr); } - LM_DBG("Binding '%.*s','%.*s' has expired\n", - ptr->aor->len, ZSW(ptr->aor->s), - ptr->c.len, ZSW(ptr->c.s)); - update_stat( _r->slot->d->expires, 1); + LM_DBG("Binding '%.*s','%.*s' has expired\n", ptr->aor->len, + ZSW(ptr->aor->s), ptr->c.len, ZSW(ptr->c.s)); + update_stat(_r->slot->d->expires, 1); - if (ul_close_expired_tcp && is_valid_tcpconn(ptr)) { + if(ul_close_expired_tcp && is_valid_tcpconn(ptr)) { close_connection(ptr->tcpconn_id); } @@ -396,10 +400,10 @@ static inline void wb_timer(urecord_t* _r) ptr = ptr->next; /* Should we remove the contact from the database ? */ - if (st_expired_ucontact(t) == 1) { - if (db_delete_ucontact(t) < 0) { + if(st_expired_ucontact(t) == 1) { + if(db_delete_ucontact(t) < 0) { LM_ERR("failed to delete contact from the database" - " (aor: %.*s)\n", + " (aor: %.*s)\n", t->aor->len, ZSW(t->aor->s)); } } @@ -411,29 +415,29 @@ static inline void wb_timer(urecord_t* _r) op = st_flush_ucontact(ptr); switch(op) { - case 0: /* do nothing, contact is synchronized */ - break; - - case 1: /* insert */ - if (db_insert_ucontact(ptr) < 0) { - LM_ERR("inserting contact into database failed" - " (aor: %.*s)\n", - ptr->aor->len, ZSW(ptr->aor->s)); - ptr->state = old_state; - } - break; - - case 2: /* update */ - if (ul_db_update_as_insert) - res = db_insert_ucontact(ptr); - else - res = db_update_ucontact(ptr); - if (res < 0) { - LM_ERR("updating contact in db failed (aor: %.*s)\n", - ptr->aor->len, ZSW(ptr->aor->s)); - ptr->state = old_state; - } - break; + case 0: /* do nothing, contact is synchronized */ + break; + + case 1: /* insert */ + if(db_insert_ucontact(ptr) < 0) { + LM_ERR("inserting contact into database failed" + " (aor: %.*s)\n", + ptr->aor->len, ZSW(ptr->aor->s)); + ptr->state = old_state; + } + break; + + case 2: /* update */ + if(ul_db_update_as_insert) + res = db_insert_ucontact(ptr); + else + res = db_update_ucontact(ptr); + if(res < 0) { + LM_ERR("updating contact in db failed (aor: %.*s)\n", + ptr->aor->len, ZSW(ptr->aor->s)); + ptr->state = old_state; + } + break; } ptr = ptr->next; @@ -449,7 +453,7 @@ static inline void wb_timer(urecord_t* _r) * on the db_mode setting. * \param _r processed record */ -void timer_urecord(urecord_t* _r) +void timer_urecord(urecord_t *_r) { switch(ul_db_mode) { case DB_READONLY: @@ -473,11 +477,11 @@ void timer_urecord(urecord_t* _r) * \param _r deleted record * \return 0 on success, -1 on failure */ -int db_delete_urecord(urecord_t* _r) +int db_delete_urecord(urecord_t *_r) { db_key_t keys[2]; db_val_t vals[2]; - char* dom; + char *dom; keys[0] = &ul_user_col; keys[1] = &ul_domain_col; @@ -486,7 +490,7 @@ int db_delete_urecord(urecord_t* _r) vals[0].val.str_val.s = _r->aor.s; vals[0].val.str_val.len = _r->aor.len; - if (ul_use_domain) { + if(ul_use_domain) { dom = memchr(_r->aor.s, '@', _r->aor.len); vals[0].val.str_val.len = dom - _r->aor.s; @@ -496,12 +500,12 @@ int db_delete_urecord(urecord_t* _r) vals[1].val.str_val.len = _r->aor.s + _r->aor.len - dom - 1; } - if (ul_dbf.use_table(ul_dbh, _r->domain) < 0) { + if(ul_dbf.use_table(ul_dbh, _r->domain) < 0) { LM_ERR("use_table failed\n"); return -1; } - if (ul_dbf.delete(ul_dbh, keys, 0, vals, (ul_use_domain) ? (2) : (1)) < 0) { + if(ul_dbf.delete(ul_dbh, keys, 0, vals, (ul_use_domain) ? (2) : (1)) < 0) { LM_ERR("failed to delete from database\n"); return -1; } @@ -525,17 +529,17 @@ int db_delete_urecord_by_ruid(str *_table, str *_ruid) vals[0].val.str_val.s = _ruid->s; vals[0].val.str_val.len = _ruid->len; - if (ul_dbf.use_table(ul_dbh, _table) < 0) { + if(ul_dbf.use_table(ul_dbh, _table) < 0) { LM_ERR("use_table failed\n"); return -1; } - if (ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) { + if(ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) { LM_ERR("failed to delete from database\n"); return -1; } - if (ul_dbf.affected_rows(ul_dbh) == 0) { + if(ul_dbf.affected_rows(ul_dbh) == 0) { return -2; } @@ -551,11 +555,11 @@ int db_delete_urecord_by_ruid(str *_table, str *_ruid) * it is not necessary, as this function already releases the record. * \param _r released record */ -void release_urecord(urecord_t* _r) +void release_urecord(urecord_t *_r) { - if (ul_db_mode==DB_ONLY) { + if(ul_db_mode == DB_ONLY) { free_urecord(_r); - } else if (_r->contacts == 0) { + } else if(_r->contacts == 0) { mem_delete_urecord(_r->slot->d, _r); } } @@ -569,20 +573,20 @@ void release_urecord(urecord_t* _r) * \param _c new created contact * \return 0 on success, -1 on failure */ -int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci, - ucontact_t** _c) +int insert_ucontact( + urecord_t *_r, str *_contact, ucontact_info_t *_ci, ucontact_t **_c) { struct urecord _ur; - if ( ((*_c)=mem_insert_ucontact(_r, _contact, _ci)) == 0) { + if(((*_c) = mem_insert_ucontact(_r, _contact, _ci)) == 0) { LM_ERR("failed to insert contact\n"); return -1; } - if (ul_db_mode==DB_ONLY) { + if(ul_db_mode == DB_ONLY) { /* urecord is static generate a copy for later */ memcpy(&_ur, _r, sizeof(struct urecord)); - if (db_insert_ucontact(*_c) < 0) { + if(db_insert_ucontact(*_c) < 0) { LM_ERR("failed to insert in database\n"); return -1; } else { @@ -590,23 +594,23 @@ int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci, } } - if (exists_ulcb_type(UL_CONTACT_INSERT)) { - run_ul_callbacks( UL_CONTACT_INSERT, *_c); + if(exists_ulcb_type(UL_CONTACT_INSERT)) { + run_ul_callbacks(UL_CONTACT_INSERT, *_c); } - switch (ul_db_mode) { + switch(ul_db_mode) { case WRITE_THROUGH: - if (db_insert_ucontact(*_c) < 0) { + if(db_insert_ucontact(*_c) < 0) { LM_ERR("failed to insert in database\n"); return -1; } else { (*_c)->state = CS_SYNC; } - break; + break; case DB_ONLY: /* urecord was static restore copy */ memcpy(_r, &_ur, sizeof(struct urecord)); - break; + break; } return 0; @@ -619,28 +623,28 @@ int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci, * \param _c deleted contact * \return 0 on success, -1 on failure */ -int delete_ucontact(urecord_t* _r, struct ucontact* _c) +int delete_ucontact(urecord_t *_r, struct ucontact *_c) { int ret = 0; struct urecord _ur; - if (ul_db_mode==DB_ONLY) { + if(ul_db_mode == DB_ONLY) { /* urecord is static generate a copy for later */ memcpy(&_ur, _r, sizeof(struct urecord)); } - if (exists_ulcb_type(UL_CONTACT_DELETE)) { - run_ul_callbacks( UL_CONTACT_DELETE, _c); + if(exists_ulcb_type(UL_CONTACT_DELETE)) { + run_ul_callbacks(UL_CONTACT_DELETE, _c); } - if (ul_db_mode==DB_ONLY) { + if(ul_db_mode == DB_ONLY) { /* urecord was static restore copy */ memcpy(_r, &_ur, sizeof(struct urecord)); } - if (st_delete_ucontact(_c) > 0) { - if (ul_db_mode == WRITE_THROUGH || ul_db_mode==DB_ONLY) { - if (db_delete_ucontact(_c) < 0) { + if(st_delete_ucontact(_c) > 0) { + if(ul_db_mode == WRITE_THROUGH || ul_db_mode == DB_ONLY) { + if(db_delete_ucontact(_c) < 0) { LM_ERR("failed to remove contact from database\n"); ret = -1; } @@ -653,10 +657,11 @@ int delete_ucontact(urecord_t* _r, struct ucontact* _c) } -int delete_urecord_by_ruid(udomain_t* _d, str *_ruid) +int delete_urecord_by_ruid(udomain_t *_d, str *_ruid) { - if (ul_db_mode != DB_ONLY) { - LM_ERR("delete_urecord_by_ruid currently available only in db_mode=3\n"); + if(ul_db_mode != DB_ONLY) { + LM_ERR("delete_urecord_by_ruid currently available only in " + "db_mode=3\n"); return -1; } @@ -670,10 +675,10 @@ int delete_urecord_by_ruid(udomain_t* _d, str *_ruid) * \param _c contact string * \return ptr on successfull match, 0 when they not match */ -static inline struct ucontact* contact_match( ucontact_t* ptr, str* _c) +static inline struct ucontact *contact_match(ucontact_t *ptr, str *_c) { while(ptr) { - if ((_c->len == ptr->c.len) && !memcmp(_c->s, ptr->c.s, _c->len)) { + if((_c->len == ptr->c.len) && !memcmp(_c->s, ptr->c.s, _c->len)) { return ptr; } @@ -690,14 +695,13 @@ static inline struct ucontact* contact_match( ucontact_t* ptr, str* _c) * \param _callid callid * \return ptr on successfull match, 0 when they not match */ -static inline struct ucontact* contact_callid_match( ucontact_t* ptr, - str* _c, str *_callid) +static inline struct ucontact *contact_callid_match( + ucontact_t *ptr, str *_c, str *_callid) { while(ptr) { - if ( (_c->len==ptr->c.len) && (_callid->len==ptr->callid.len) - && !memcmp(_c->s, ptr->c.s, _c->len) - && !memcmp(_callid->s, ptr->callid.s, _callid->len) - ) { + if((_c->len == ptr->c.len) && (_callid->len == ptr->callid.len) + && !memcmp(_c->s, ptr->c.s, _c->len) + && !memcmp(_callid->s, ptr->callid.s, _callid->len)) { return ptr; } @@ -713,16 +717,18 @@ static inline struct ucontact* contact_callid_match( ucontact_t* ptr, * \param _path path * \return ptr on successfull match, 0 when they not match */ -static inline struct ucontact* contact_path_match( ucontact_t* ptr, str* _c, str *_path) +static inline struct ucontact *contact_path_match( + ucontact_t *ptr, str *_c, str *_path) { /* if no path is preset (in REGISTER request) or use_path is not configured * in registrar module, default to contact_match() */ - if( _path == NULL) return contact_match(ptr, _c); + if(_path == NULL) + return contact_match(ptr, _c); while(ptr) { - if ( (_c->len==ptr->c.len) && (_path->len==ptr->path.len) - && !memcmp(_c->s, ptr->c.s, _c->len) - && !memcmp(_path->s, ptr->path.s, _path->len) ) { + if((_c->len == ptr->c.len) && (_path->len == ptr->path.len) + && !memcmp(_c->s, ptr->c.s, _c->len) + && !memcmp(_path->s, ptr->path.s, _path->len)) { return ptr; } @@ -732,17 +738,18 @@ static inline struct ucontact* contact_path_match( ucontact_t* ptr, str* _c, str } - /*! * \brief Match a contact record to a Call-ID only * \param ptr contact record * \param _callid callid string * \return ptr on successfull match, 0 when they not match */ -static inline struct ucontact* contact_match_callidonly( ucontact_t* ptr, str* _callid) +static inline struct ucontact *contact_match_callidonly( + ucontact_t *ptr, str *_callid) { while(ptr) { - if ((_callid->len == ptr->callid.len) && !memcmp(_callid->s, ptr->callid.s, _callid->len)) { + if((_callid->len == ptr->callid.len) + && !memcmp(_callid->s, ptr->callid.s, _callid->len)) { return ptr; } @@ -763,44 +770,47 @@ static inline struct ucontact* contact_match_callidonly( ucontact_t* ptr, str* _ * \return 0 - found, 1 - not found, -1 - invalid found, * -2 - found, but to be skipped (same cseq) */ -int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path, int _cseq, - struct ucontact** _co) +int get_ucontact(urecord_t *_r, str *_c, str *_callid, str *_path, int _cseq, + struct ucontact **_co) { - ucontact_t* ptr; + ucontact_t *ptr; int no_callid; ptr = 0; no_callid = 0; *_co = 0; - switch (ul_matching_mode) { + switch(ul_matching_mode) { case CONTACT_ONLY: - ptr = contact_match( _r->contacts, _c); + ptr = contact_match(_r->contacts, _c); break; case CONTACT_CALLID: - ptr = contact_callid_match( _r->contacts, _c, _callid); + ptr = contact_callid_match(_r->contacts, _c, _callid); no_callid = 1; break; case CONTACT_PATH: - ptr = contact_path_match( _r->contacts, _c, _path); + ptr = contact_path_match(_r->contacts, _c, _path); break; case CONTACT_CALLID_ONLY: - ptr = contact_match_callidonly( _r->contacts, _callid); + ptr = contact_match_callidonly(_r->contacts, _callid); break; default: LM_CRIT("unknown matching_mode %d\n", ul_matching_mode); return -1; } - if (ptr) { + if(ptr) { /* found -> check callid and cseq */ - if ( no_callid || (ptr->callid.len==_callid->len - && memcmp(_callid->s, ptr->callid.s, _callid->len)==0 ) ) { - if (_cseqcseq) + if(no_callid + || (ptr->callid.len == _callid->len + && memcmp(_callid->s, ptr->callid.s, _callid->len) + == 0)) { + if(_cseq < ptr->cseq) return -1; - if (_cseq==ptr->cseq) { + if(_cseq == ptr->cseq) { ul_get_act_time(); - return (ptr->last_modified+ul_cseq_delay>ul_act_time)?-2:-1; + return (ptr->last_modified + ul_cseq_delay > ul_act_time) ? -2 + : -1; } } *_co = ptr; @@ -813,33 +823,32 @@ int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path, int _cseq, /* * Get pointer to ucontact with given info (by address or sip.instance) */ -int get_ucontact_by_instance(urecord_t* _r, str* _c, ucontact_info_t* _ci, - ucontact_t** _co) +int get_ucontact_by_instance( + urecord_t *_r, str *_c, ucontact_info_t *_ci, ucontact_t **_co) { - ucontact_t* ptr; + ucontact_t *ptr; str i1; str i2; - if (_ci->instance.s == NULL || _ci->instance.len <= 0) { + if(_ci->instance.s == NULL || _ci->instance.len <= 0) { return get_ucontact(_r, _c, _ci->callid, _ci->path, _ci->cseq, _co); } /* find by instance */ ptr = _r->contacts; while(ptr) { - if (ptr->instance.len>0 && _ci->reg_id==ptr->reg_id) - { + if(ptr->instance.len > 0 && _ci->reg_id == ptr->reg_id) { i1 = _ci->instance; i2 = ptr->instance; - if(i1.s[0]=='<' && i1.s[i1.len-1]=='>') { + if(i1.s[0] == '<' && i1.s[i1.len - 1] == '>') { i1.s++; - i1.len-=2; + i1.len -= 2; } - if(i2.s[0]=='<' && i2.s[i2.len-1]=='>') { + if(i2.s[0] == '<' && i2.s[i2.len - 1] == '>') { i2.s++; - i2.len-=2; + i2.len -= 2; } - if(i1.len==i2.len && memcmp(i1.s, i2.s, i2.len)==0) { + if(i1.len == i2.len && memcmp(i1.s, i2.s, i2.len) == 0) { *_co = ptr; return 0; } diff --git a/src/modules/usrloc/urecord.h b/src/modules/usrloc/urecord.h index 38e9cfa5114..41edf4378da 100644 --- a/src/modules/usrloc/urecord.h +++ b/src/modules/usrloc/urecord.h @@ -39,8 +39,6 @@ struct hslot; /*!< Hash table slot */ - - /*! * \brief Create and initialize new record structure * \param _dom domain name @@ -48,7 +46,7 @@ struct hslot; /*!< Hash table slot */ * \param _r pointer to the new record * \return 0 on success, negative on failure */ -int new_urecord(str* _dom, str* _aor, urecord_t** _r); +int new_urecord(str *_dom, str *_aor, urecord_t **_r); /*! @@ -59,7 +57,7 @@ int new_urecord(str* _dom, str* _aor, urecord_t** _r); * lists first * \param _r freed record list */ -void free_urecord(urecord_t* _r); +void free_urecord(urecord_t *_r); /*! @@ -67,7 +65,7 @@ void free_urecord(urecord_t* _r); * \param _f print output * \param _r printed record */ -void print_urecord(FILE* _f, urecord_t* _r); +void print_urecord(FILE *_f, urecord_t *_r); /*! @@ -80,7 +78,7 @@ void print_urecord(FILE* _f, urecord_t* _r); * \param _ci contact information * \return pointer to new created contact on success, 0 on failure */ -ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci); +ucontact_t *mem_insert_ucontact(urecord_t *_r, str *_c, ucontact_info_t *_ci); /*! @@ -88,7 +86,7 @@ ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci); * \param _r record this contact belongs to * \param _c removed contact */ -void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c); +void mem_remove_ucontact(urecord_t *_r, ucontact_t *_c); /*! @@ -96,7 +94,7 @@ void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c); * \param _r record this contact belongs to * \param _c deleted contact */ -void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c); +void mem_delete_ucontact(urecord_t *_r, ucontact_t *_c); /*! @@ -106,7 +104,7 @@ void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c); * on the db_mode setting. * \param _r processed record */ -void timer_urecord(urecord_t* _r); +void timer_urecord(urecord_t *_r); /*! @@ -114,7 +112,7 @@ void timer_urecord(urecord_t* _r); * \param _r deleted record * \return 0 on success, -1 on failure */ -int db_delete_urecord(urecord_t* _r); +int db_delete_urecord(urecord_t *_r); /*! @@ -124,7 +122,7 @@ int db_delete_urecord(urecord_t* _r); * \return 0 on success, -1 on failure, and -2 if record was * not found */ -int delete_urecord_by_ruid(udomain_t* _d, str *_ruid); +int delete_urecord_by_ruid(udomain_t *_d, str *_ruid); /* ===== Module interface ======== */ @@ -138,7 +136,7 @@ int delete_urecord_by_ruid(udomain_t* _d, str *_ruid); * it is not necessary, as this function already releases the record. * \param _r released record */ -void release_urecord(urecord_t* _r); +void release_urecord(urecord_t *_r); /*! @@ -149,8 +147,8 @@ void release_urecord(urecord_t* _r); * \param _c new created contact * \return 0 on success, -1 on failure */ -int insert_ucontact(urecord_t* _r, str* _contact, - ucontact_info_t* _ci, ucontact_t** _c); +int insert_ucontact( + urecord_t *_r, str *_contact, ucontact_info_t *_ci, ucontact_t **_c); /*! @@ -159,7 +157,7 @@ int insert_ucontact(urecord_t* _r, str* _contact, * \param _c deleted contact * \return 0 on success, -1 on failure */ -int delete_ucontact(urecord_t* _r, struct ucontact* _c); +int delete_ucontact(urecord_t *_r, struct ucontact *_c); /*! @@ -173,9 +171,8 @@ int delete_ucontact(urecord_t* _r, struct ucontact* _c); * \return 0 - found, 1 - not found, -1 - invalid found, * -2 - found, but to be skipped (same cseq) */ -int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path, - int _cseq, - struct ucontact** _co); +int get_ucontact(urecord_t *_r, str *_c, str *_callid, str *_path, int _cseq, + struct ucontact **_co); /*! * \brief Get pointer to ucontact with given contact @@ -186,8 +183,8 @@ int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path, * \return 0 - found, 1 - not found, -1 - invalid found, * -2 - found, but to be skipped (same cseq) */ -int get_ucontact_by_instance(urecord_t* _r, str* _c, ucontact_info_t* _ci, - ucontact_t** _co); +int get_ucontact_by_instance( + urecord_t *_r, str *_c, ucontact_info_t *_ci, ucontact_t **_co); int is_valid_tcpconn(ucontact_t *c); diff --git a/src/modules/usrloc/usrloc.c b/src/modules/usrloc/usrloc.c index 76c643c48e5..32c1ce4f71a 100644 --- a/src/modules/usrloc/usrloc.c +++ b/src/modules/usrloc/usrloc.c @@ -40,45 +40,45 @@ * \param api usrloc API * \return 0 on success, -1 on failure */ -int bind_usrloc(usrloc_api_t* api) +int bind_usrloc(usrloc_api_t *api) { - if (!api) { + if(!api) { LM_ERR("invalid parameter value\n"); return -1; } - if (ul_init_flag==0) { + if(ul_init_flag == 0) { LM_ERR("configuration error - trying to bind to usrloc module" - " before being initialized\n"); + " before being initialized\n"); return -1; } - api->register_udomain = register_udomain; - api->get_udomain = get_udomain; - api->get_all_ucontacts = get_all_ucontacts; - api->insert_urecord = insert_urecord; - api->delete_urecord = delete_urecord; - api->delete_urecord_by_ruid = delete_urecord_by_ruid; - api->get_urecord = get_urecord; - api->lock_udomain = lock_udomain; - api->unlock_udomain = unlock_udomain; - api->release_urecord = release_urecord; - api->insert_ucontact = insert_ucontact; - api->delete_ucontact = delete_ucontact; - api->get_ucontact = get_ucontact; - api->update_ucontact = update_ucontact; - api->register_ulcb = register_ulcb; - api->get_aorhash = ul_get_aorhash; + api->register_udomain = register_udomain; + api->get_udomain = get_udomain; + api->get_all_ucontacts = get_all_ucontacts; + api->insert_urecord = insert_urecord; + api->delete_urecord = delete_urecord; + api->delete_urecord_by_ruid = delete_urecord_by_ruid; + api->get_urecord = get_urecord; + api->lock_udomain = lock_udomain; + api->unlock_udomain = unlock_udomain; + api->release_urecord = release_urecord; + api->insert_ucontact = insert_ucontact; + api->delete_ucontact = delete_ucontact; + api->get_ucontact = get_ucontact; + api->update_ucontact = update_ucontact; + api->register_ulcb = register_ulcb; + api->get_aorhash = ul_get_aorhash; - api->get_urecord_by_ruid = get_urecord_by_ruid; + api->get_urecord_by_ruid = get_urecord_by_ruid; api->get_ucontact_by_instance = get_ucontact_by_instance; - api->set_keepalive_timeout = ul_set_keepalive_timeout; - api->refresh_keepalive = ul_refresh_keepalive; - api->set_max_partition = ul_set_max_partition; + api->set_keepalive_timeout = ul_set_keepalive_timeout; + api->refresh_keepalive = ul_refresh_keepalive; + api->set_max_partition = ul_set_max_partition; api->use_domain = ul_use_domain; - api->db_mode = ul_db_mode; - api->nat_flag = ul_nat_bflag; + api->db_mode = ul_db_mode; + api->nat_flag = ul_nat_bflag; return 0; } diff --git a/src/modules/usrloc/usrloc.h b/src/modules/usrloc/usrloc.h index a9a0309d9d5..54f7986080d 100644 --- a/src/modules/usrloc/usrloc.h +++ b/src/modules/usrloc/usrloc.h @@ -32,13 +32,13 @@ #include "../../core/str.h" #include "../../core/xavp.h" -#define NO_DB 0 +#define NO_DB 0 #define WRITE_THROUGH 1 -#define WRITE_BACK 2 -#define DB_ONLY 3 -#define DB_READONLY 4 +#define WRITE_BACK 2 +#define DB_ONLY 3 +#define DB_READONLY 4 -#define GAU_OPT_SERVER_ID (1<<0) /* filter query by server_id */ +#define GAU_OPT_SERVER_ID (1 << 0) /* filter query by server_id */ /*forward declaration necessary for udomain*/ @@ -48,141 +48,149 @@ typedef struct udomain udomain_t; /*! * \brief States for in-memory contacts in regards to contact storage handler (db, in-memory, ldap etc) */ -typedef enum cstate { - CS_NEW, /*!< New contact - not flushed yet */ - CS_SYNC, /*!< Synchronized contact with the database */ - CS_DIRTY /*!< Update contact - not flushed yet */ +typedef enum cstate +{ + CS_NEW, /*!< New contact - not flushed yet */ + CS_SYNC, /*!< Synchronized contact with the database */ + CS_DIRTY /*!< Update contact - not flushed yet */ } cstate_t; /*! \brief Flags that can be associated with a Contact */ -typedef enum flags { - FL_NONE = 0, /*!< No flags set */ - FL_MEM = 1 << 0, /*!< Update memory only */ - FL_DMQRPL = 1 << 1, /*!< DMQ replication */ - FL_EXPCLB = 1 << 2, /*!< Expired callback executed */ - FL_ALL = (int)0xFFFFFFFF /*!< All flags set */ +typedef enum flags +{ + FL_NONE = 0, /*!< No flags set */ + FL_MEM = 1 << 0, /*!< Update memory only */ + FL_DMQRPL = 1 << 1, /*!< DMQ replication */ + FL_EXPCLB = 1 << 2, /*!< Expired callback executed */ + FL_ALL = (int)0xFFFFFFFF /*!< All flags set */ } flags_t; /*! \brief Valid contact is a contact that either didn't expire yet or is permanent */ -#define VALID_CONTACT(c, t) ((c->expires>t) || (c->expires==0)) +#define VALID_CONTACT(c, t) ((c->expires > t) || (c->expires == 0)) struct hslot; /*!< Hash table slot */ struct socket_info; /*! \brief Main structure for handling of registered Contact data */ -typedef struct ucontact { - str* domain; /*!< Pointer to domain name (NULL terminated) */ - str ruid; /*!< Pointer to record internal unique id */ - str* aor; /*!< Pointer to the AOR string in record structure*/ - str c; /*!< Contact address */ - str received; /*!< IP+port+protocol we received the REGISTER from */ - str path; /*!< Path header */ - time_t expires; /*!< Expires parameter */ - qvalue_t q; /*!< q parameter */ - str callid; /*!< Call-ID header field of registration */ - int cseq; /*!< CSeq value */ - cstate_t state; /*!< State of the contact (\ref cstate) */ - unsigned int flags; /*!< Various internal flags (sync, etc) */ - unsigned int cflags; /*!< Custom contact flags (from script - bflags) */ - str user_agent; /*!< User-Agent header field */ - str uniq; /*!< Uniq header field */ - struct socket_info *sock; /*!< received socket */ - time_t last_modified; /*!< When the record was last modified */ - time_t last_keepalive; /*!< Last keepalive timestamp */ +typedef struct ucontact +{ + str *domain; /*!< Pointer to domain name (NULL terminated) */ + str ruid; /*!< Pointer to record internal unique id */ + str *aor; /*!< Pointer to the AOR string in record structure*/ + str c; /*!< Contact address */ + str received; /*!< IP+port+protocol we received the REGISTER from */ + str path; /*!< Path header */ + time_t expires; /*!< Expires parameter */ + qvalue_t q; /*!< q parameter */ + str callid; /*!< Call-ID header field of registration */ + int cseq; /*!< CSeq value */ + cstate_t state; /*!< State of the contact (\ref cstate) */ + unsigned int flags; /*!< Various internal flags (sync, etc) */ + unsigned int cflags; /*!< Custom contact flags (from script - bflags) */ + str user_agent; /*!< User-Agent header field */ + str uniq; /*!< Uniq header field */ + struct socket_info *sock; /*!< received socket */ + time_t last_modified; /*!< When the record was last modified */ + time_t last_keepalive; /*!< Last keepalive timestamp */ unsigned int ka_roundtrip; /*!< Keepalive roundtrip in microseconds */ - unsigned int methods; /*!< Supported methods */ - str instance; /*!< SIP instance value - gruu */ - unsigned int reg_id; /*!< reg-id parameters */ - int server_id; /*!< server id */ - int tcpconn_id; /*!< unique tcp connection id */ - int keepalive; /*!< keepalive */ - sr_xavp_t * xavp; /*!< per contact xavps */ - struct ucontact* next; /*!< Next contact in the linked list */ - struct ucontact* prev; /*!< Previous contact in the linked list */ + unsigned int methods; /*!< Supported methods */ + str instance; /*!< SIP instance value - gruu */ + unsigned int reg_id; /*!< reg-id parameters */ + int server_id; /*!< server id */ + int tcpconn_id; /*!< unique tcp connection id */ + int keepalive; /*!< keepalive */ + sr_xavp_t *xavp; /*!< per contact xavps */ + struct ucontact *next; /*!< Next contact in the linked list */ + struct ucontact *prev; /*!< Previous contact in the linked list */ } ucontact_t; /*! \brief Informations related to a contact */ -typedef struct ucontact_info { - str ruid; /*!< Pointer to record internal unique id */ - str *c; /*!< Contact address */ - str received; /*!< Received interface */ - str* path; /*!< Path informations */ - time_t expires; /*!< Contact expires */ - qvalue_t q; /*!< Q-value */ - str* callid; /*!< call-ID */ - int cseq; /*!< CSEQ number */ - unsigned int flags; /*!< message flags */ - unsigned int cflags; /*!< contact flags */ - str *user_agent; /*!< user agent header */ +typedef struct ucontact_info +{ + str ruid; /*!< Pointer to record internal unique id */ + str *c; /*!< Contact address */ + str received; /*!< Received interface */ + str *path; /*!< Path informations */ + time_t expires; /*!< Contact expires */ + qvalue_t q; /*!< Q-value */ + str *callid; /*!< call-ID */ + int cseq; /*!< CSEQ number */ + unsigned int flags; /*!< message flags */ + unsigned int cflags; /*!< contact flags */ + str *user_agent; /*!< user agent header */ struct socket_info *sock; /*!< socket informations */ - unsigned int methods; /*!< supported methods */ - str instance; /*!< SIP instance value - gruu */ - unsigned int reg_id; /*!< reg-id parameters */ - int server_id; /*!< server id */ - int tcpconn_id; /*!< connection id */ - int keepalive; /*!< keepalive */ - sr_xavp_t * xavp; /*!< per contact xavps */ - time_t last_modified; /*!< last modified */ + unsigned int methods; /*!< supported methods */ + str instance; /*!< SIP instance value - gruu */ + unsigned int reg_id; /*!< reg-id parameters */ + int server_id; /*!< server id */ + int tcpconn_id; /*!< connection id */ + int keepalive; /*!< keepalive */ + sr_xavp_t *xavp; /*!< per contact xavps */ + time_t last_modified; /*!< last modified */ } ucontact_info_t; -typedef struct udomain_head{ - str* name; +typedef struct udomain_head +{ + str *name; } udomain_head_t; /*! \brief * Basic hash table element */ -typedef struct urecord { - str* domain; /*!< Pointer to domain we belong to +typedef struct urecord +{ + str *domain; /*!< Pointer to domain we belong to * ( null terminated string) */ - str aor; /*!< Address of record */ - unsigned int aorhash; /*!< Hash over address of record */ - ucontact_t* contacts; /*!< One or more contact fields */ + str aor; /*!< Address of record */ + unsigned int aorhash; /*!< Hash over address of record */ + ucontact_t *contacts; /*!< One or more contact fields */ - struct hslot* slot; /*!< Collision slot in the hash table + struct hslot *slot; /*!< Collision slot in the hash table * array we belong to */ - struct urecord* prev; /*!< Next item in the hash entry */ - struct urecord* next; /*!< Previous item in the hash entry */ + struct urecord *prev; /*!< Next item in the hash entry */ + struct urecord *next; /*!< Previous item in the hash entry */ } urecord_t; -typedef int (*insert_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r); +typedef int (*insert_urecord_t)( + struct udomain *_d, str *_aor, struct urecord **_r); -typedef int (*get_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r); +typedef int (*get_urecord_t)( + struct udomain *_d, str *_aor, struct urecord **_r); -typedef int (*get_urecord_by_ruid_t)(udomain_t* _d, unsigned int _aorhash, - str *_ruid, struct urecord** _r, struct ucontact** _c); +typedef int (*get_urecord_by_ruid_t)(udomain_t *_d, unsigned int _aorhash, + str *_ruid, struct urecord **_r, struct ucontact **_c); -typedef int (*delete_urecord_t)(struct udomain* _d, str* _aor, struct urecord* _r); +typedef int (*delete_urecord_t)( + struct udomain *_d, str *_aor, struct urecord *_r); -typedef int (*delete_urecord_by_ruid_t)(struct udomain* _d, str* _ruid); +typedef int (*delete_urecord_by_ruid_t)(struct udomain *_d, str *_ruid); -typedef int (*update_ucontact_t)(struct urecord* _r, struct ucontact* _c, - struct ucontact_info* _ci); -typedef void (*release_urecord_t)(struct urecord* _r); +typedef int (*update_ucontact_t)( + struct urecord *_r, struct ucontact *_c, struct ucontact_info *_ci); +typedef void (*release_urecord_t)(struct urecord *_r); -typedef int (*insert_ucontact_t)(struct urecord* _r, str* _contact, - struct ucontact_info* _ci, struct ucontact** _c); +typedef int (*insert_ucontact_t)(struct urecord *_r, str *_contact, + struct ucontact_info *_ci, struct ucontact **_c); -typedef int (*delete_ucontact_t)(struct urecord* _r, struct ucontact* _c); +typedef int (*delete_ucontact_t)(struct urecord *_r, struct ucontact *_c); -typedef int (*get_ucontact_t)(struct urecord* _r, str* _c, str* _callid, - str* _path, int _cseq, - struct ucontact** _co); +typedef int (*get_ucontact_t)(struct urecord *_r, str *_c, str *_callid, + str *_path, int _cseq, struct ucontact **_co); -typedef int (*get_ucontact_by_instance_t)(struct urecord* _r, str* _c, - ucontact_info_t* _ci, ucontact_t** _co); +typedef int (*get_ucontact_by_instance_t)( + struct urecord *_r, str *_c, ucontact_info_t *_ci, ucontact_t **_co); -typedef void (*lock_udomain_t)(struct udomain* _d, str *_aor); +typedef void (*lock_udomain_t)(struct udomain *_d, str *_aor); -typedef void (*unlock_udomain_t)(struct udomain* _d, str *_aor); +typedef void (*unlock_udomain_t)(struct udomain *_d, str *_aor); -typedef int (*register_udomain_t)(const char* _n, struct udomain** _d); +typedef int (*register_udomain_t)(const char *_n, struct udomain **_d); -typedef int (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags, +typedef int (*get_all_ucontacts_t)(void *buf, int len, unsigned int flags, unsigned int part_idx, unsigned int part_max, int options); -typedef int (*get_udomain_t)(const char* _n, udomain_t** _d); +typedef int (*get_udomain_t)(const char *_n, udomain_t **_d); typedef unsigned int (*ul_get_aorhash_t)(str *_aor); unsigned int ul_get_aorhash(str *_aor); @@ -193,48 +201,49 @@ int ul_set_keepalive_timeout(int _to); typedef int (*ul_refresh_keepalive_t)(unsigned int _aorhash, str *_ruid); int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid); -int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval, - unsigned int rtrip); +int ul_update_keepalive( + unsigned int _aorhash, str *_ruid, time_t tval, unsigned int rtrip); typedef void (*ul_set_max_partition_t)(unsigned int m); /*! usrloc API export structure */ -typedef struct usrloc_api { - int use_domain; /*! use_domain module parameter */ - int db_mode; /*! db_mode module parameter */ - unsigned int nat_flag; /*! nat_flag module parameter */ +typedef struct usrloc_api +{ + int use_domain; /*! use_domain module parameter */ + int db_mode; /*! db_mode module parameter */ + unsigned int nat_flag; /*! nat_flag module parameter */ - register_udomain_t register_udomain; - get_udomain_t get_udomain; - get_all_ucontacts_t get_all_ucontacts; + register_udomain_t register_udomain; + get_udomain_t get_udomain; + get_all_ucontacts_t get_all_ucontacts; - insert_urecord_t insert_urecord; - delete_urecord_t delete_urecord; - delete_urecord_by_ruid_t delete_urecord_by_ruid; - get_urecord_t get_urecord; - lock_udomain_t lock_udomain; - unlock_udomain_t unlock_udomain; + insert_urecord_t insert_urecord; + delete_urecord_t delete_urecord; + delete_urecord_by_ruid_t delete_urecord_by_ruid; + get_urecord_t get_urecord; + lock_udomain_t lock_udomain; + unlock_udomain_t unlock_udomain; - release_urecord_t release_urecord; - insert_ucontact_t insert_ucontact; - delete_ucontact_t delete_ucontact; - get_ucontact_t get_ucontact; + release_urecord_t release_urecord; + insert_ucontact_t insert_ucontact; + delete_ucontact_t delete_ucontact; + get_ucontact_t get_ucontact; - get_urecord_by_ruid_t get_urecord_by_ruid; - get_ucontact_by_instance_t get_ucontact_by_instance; + get_urecord_by_ruid_t get_urecord_by_ruid; + get_ucontact_by_instance_t get_ucontact_by_instance; - update_ucontact_t update_ucontact; + update_ucontact_t update_ucontact; - register_ulcb_t register_ulcb; - ul_get_aorhash_t get_aorhash; + register_ulcb_t register_ulcb; + ul_get_aorhash_t get_aorhash; ul_set_keepalive_timeout_t set_keepalive_timeout; - ul_refresh_keepalive_t refresh_keepalive; - ul_set_max_partition_t set_max_partition; + ul_refresh_keepalive_t refresh_keepalive; + ul_set_max_partition_t set_max_partition; } usrloc_api_t; /*! usrloc API export bind function */ -typedef int (*bind_usrloc_t)(usrloc_api_t* api); +typedef int (*bind_usrloc_t)(usrloc_api_t *api); #endif diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c index dc31c6f6eb7..85d722dbfef 100644 --- a/src/modules/usrloc/usrloc_mod.c +++ b/src/modules/usrloc/usrloc_mod.c @@ -44,15 +44,15 @@ #include "../../core/sr_module.h" #include "../../core/dprint.h" #include "../../core/rpc_lookup.h" -#include "../../core/timer.h" /* register_timer */ +#include "../../core/timer.h" /* register_timer */ #include "../../core/timer_proc.h" /* register_sync_timer */ #include "../../core/globals.h" -#include "../../core/ut.h" /* str_init */ +#include "../../core/ut.h" /* str_init */ #include "../../core/utils/sruid.h" -#include "dlist.h" /* register_udomain */ -#include "udomain.h" /* {insert,delete,get,release}_urecord */ -#include "urecord.h" /* {insert,delete,get}_ucontact */ -#include "ucontact.h" /* update_ucontact */ +#include "dlist.h" /* register_udomain */ +#include "udomain.h" /* {insert,delete,get,release}_urecord */ +#include "urecord.h" /* {insert,delete,get}_ucontact */ +#include "ucontact.h" /* update_ucontact */ #include "ul_rpc.h" #include "ul_callback.h" #include "ul_keepalive.h" @@ -60,51 +60,54 @@ MODULE_VERSION -#define RUID_COL "ruid" -#define USER_COL "username" -#define DOMAIN_COL "domain" -#define CONTACT_COL "contact" -#define EXPIRES_COL "expires" -#define Q_COL "q" -#define CALLID_COL "callid" -#define CSEQ_COL "cseq" -#define FLAGS_COL "flags" -#define CFLAGS_COL "cflags" +#define RUID_COL "ruid" +#define USER_COL "username" +#define DOMAIN_COL "domain" +#define CONTACT_COL "contact" +#define EXPIRES_COL "expires" +#define Q_COL "q" +#define CALLID_COL "callid" +#define CSEQ_COL "cseq" +#define FLAGS_COL "flags" +#define CFLAGS_COL "cflags" #define USER_AGENT_COL "user_agent" -#define RECEIVED_COL "received" -#define PATH_COL "path" -#define SOCK_COL "socket" -#define METHODS_COL "methods" -#define INSTANCE_COL "instance" -#define REG_ID_COL "reg_id" -#define LAST_MOD_COL "last_modified" -#define SRV_ID_COL "server_id" -#define CON_ID_COL "connection_id" -#define KEEPALIVE_COL "keepalive" -#define PARTITION_COL "partition" - -#define ULATTRS_USER_COL "username" -#define ULATTRS_DOMAIN_COL "domain" -#define ULATTRS_RUID_COL "ruid" -#define ULATTRS_ANAME_COL "aname" -#define ULATTRS_ATYPE_COL "atype" -#define ULATTRS_AVALUE_COL "avalue" -#define ULATTRS_LAST_MOD_COL "last_modified" - -static int mod_init(void); /*!< Module initialization function */ -static void destroy(void); /*!< Module destroy function */ -static void ul_core_timer(unsigned int ticks, void* param); /*!< Core timer handler */ -static void ul_local_timer(unsigned int ticks, void* param); /*!< Local timer handler */ -static void ul_db_clean_timer(unsigned int ticks, void* param); /*!< DB clean timer handler */ -static int child_init(int rank); /*!< Per-child init function */ +#define RECEIVED_COL "received" +#define PATH_COL "path" +#define SOCK_COL "socket" +#define METHODS_COL "methods" +#define INSTANCE_COL "instance" +#define REG_ID_COL "reg_id" +#define LAST_MOD_COL "last_modified" +#define SRV_ID_COL "server_id" +#define CON_ID_COL "connection_id" +#define KEEPALIVE_COL "keepalive" +#define PARTITION_COL "partition" + +#define ULATTRS_USER_COL "username" +#define ULATTRS_DOMAIN_COL "domain" +#define ULATTRS_RUID_COL "ruid" +#define ULATTRS_ANAME_COL "aname" +#define ULATTRS_ATYPE_COL "atype" +#define ULATTRS_AVALUE_COL "avalue" +#define ULATTRS_LAST_MOD_COL "last_modified" + +static int mod_init(void); /*!< Module initialization function */ +static void destroy(void); /*!< Module destroy function */ +static void ul_core_timer( + unsigned int ticks, void *param); /*!< Core timer handler */ +static void ul_local_timer( + unsigned int ticks, void *param); /*!< Local timer handler */ +static void ul_db_clean_timer( + unsigned int ticks, void *param); /*!< DB clean timer handler */ +static int child_init(int rank); /*!< Per-child init function */ static int ul_sip_reply_received(sip_msg_t *msg); /*!< SIP response handling */ -#define UL_PRELOAD_SIZE 8 -static char* ul_preload_list[UL_PRELOAD_SIZE]; +#define UL_PRELOAD_SIZE 8 +static char *ul_preload_list[UL_PRELOAD_SIZE]; static int ul_preload_index = 0; -static int ul_preload_param(modparam_t type, void* val); +static int ul_preload_param(modparam_t type, void *val); -extern int bind_usrloc(usrloc_api_t* api); +extern int bind_usrloc(usrloc_api_t *api); int ul_db_update_as_insert = 0; int ul_timer_procs = 0; int ul_db_check_update = 0; @@ -135,50 +138,84 @@ sruid_t _ul_sruid; * Module parameters and their default values */ -str ul_ruid_col = str_init(RUID_COL); /*!< Name of column containing record unique id */ -str ul_user_col = str_init(USER_COL); /*!< Name of column containing usernames */ -str ul_domain_col = str_init(DOMAIN_COL); /*!< Name of column containing domains */ -str ul_contact_col = str_init(CONTACT_COL); /*!< Name of column containing contact addresses */ -str ul_expires_col = str_init(EXPIRES_COL); /*!< Name of column containing expires values */ -str ul_q_col = str_init(Q_COL); /*!< Name of column containing q values */ -str ul_callid_col = str_init(CALLID_COL); /*!< Name of column containing callid string */ -str ul_cseq_col = str_init(CSEQ_COL); /*!< Name of column containing cseq values */ -str ul_flags_col = str_init(FLAGS_COL); /*!< Name of column containing internal flags */ -str ul_cflags_col = str_init(CFLAGS_COL); /*!< Name of column containing contact flags */ -str ul_user_agent_col = str_init(USER_AGENT_COL); /*!< Name of column containing user agent string */ -str ul_received_col = str_init(RECEIVED_COL); /*!< Name of column containing transport info of REGISTER */ -str ul_path_col = str_init(PATH_COL); /*!< Name of column containing the Path header */ -str ul_sock_col = str_init(SOCK_COL); /*!< Name of column containing the received socket */ -str ul_methods_col = str_init(METHODS_COL); /*!< Name of column containing the supported methods */ -str ul_instance_col = str_init(INSTANCE_COL); /*!< Name of column containing the SIP instance value */ -str ul_reg_id_col = str_init(REG_ID_COL); /*!< Name of column containing the reg-id value */ -str ul_last_mod_col = str_init(LAST_MOD_COL); /*!< Name of column containing the last modified date */ -str ul_srv_id_col = str_init(SRV_ID_COL); /*!< Name of column containing the server id value */ -str ul_con_id_col = str_init(CON_ID_COL); /*!< Name of column containing the connection id value */ -str ul_keepalive_col = str_init(KEEPALIVE_COL); /*!< Name of column containing the keepalive value */ -str ul_partition_col = str_init(PARTITION_COL); /*!< Name of column containing the partition value */ - -str ulattrs_user_col = str_init(ULATTRS_USER_COL); /*!< Name of column containing username */ -str ulattrs_domain_col = str_init(ULATTRS_DOMAIN_COL); /*!< Name of column containing domain */ -str ulattrs_ruid_col = str_init(ULATTRS_RUID_COL); /*!< Name of column containing record unique id */ -str ulattrs_aname_col = str_init(ULATTRS_ANAME_COL); /*!< Name of column containing attribute name */ -str ulattrs_atype_col = str_init(ULATTRS_ATYPE_COL); /*!< Name of column containing attribute type */ -str ulattrs_avalue_col = str_init(ULATTRS_AVALUE_COL); /*!< Name of column containing attribute value */ -str ulattrs_last_mod_col = str_init(ULATTRS_LAST_MOD_COL); /*!< Name of column containing the last modified date */ - -str ul_db_url = str_init(DEFAULT_DB_URL); /*!< Database URL */ -int ul_timer_interval = 60; /*!< Timer interval in seconds */ -int ul_db_mode = 0; /*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */ -int ul_db_load = 1; /*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */ -int ul_db_insert_update = 0; /*!< Database : update on duplicate key instead of error */ -int ul_use_domain = 0; /*!< Whether usrloc should use domain part of aor */ -int ul_desc_time_order = 0; /*!< By default do not enable timestamp ordering */ -int ul_handle_lost_tcp = 0; /*!< By default do not remove contacts before expiration time */ -int ul_close_expired_tcp = 0; /*!< By default do not close TCP connections for expired contacts */ -int ul_skip_remote_socket = 0; /*!< By default do not skip remote socket */ -int ul_db_clean_tcp = 0; /*!< Clean TCP/TLS/WSS contacts in DB before loading records */ - -int ul_fetch_rows = 2000; /*!< number of rows to fetch from result */ +str ul_ruid_col = + str_init(RUID_COL); /*!< Name of column containing record unique id */ +str ul_user_col = + str_init(USER_COL); /*!< Name of column containing usernames */ +str ul_domain_col = + str_init(DOMAIN_COL); /*!< Name of column containing domains */ +str ul_contact_col = str_init( + CONTACT_COL); /*!< Name of column containing contact addresses */ +str ul_expires_col = + str_init(EXPIRES_COL); /*!< Name of column containing expires values */ +str ul_q_col = str_init(Q_COL); /*!< Name of column containing q values */ +str ul_callid_col = + str_init(CALLID_COL); /*!< Name of column containing callid string */ +str ul_cseq_col = + str_init(CSEQ_COL); /*!< Name of column containing cseq values */ +str ul_flags_col = + str_init(FLAGS_COL); /*!< Name of column containing internal flags */ +str ul_cflags_col = + str_init(CFLAGS_COL); /*!< Name of column containing contact flags */ +str ul_user_agent_col = str_init( + USER_AGENT_COL); /*!< Name of column containing user agent string */ +str ul_received_col = str_init( + RECEIVED_COL); /*!< Name of column containing transport info of REGISTER */ +str ul_path_col = + str_init(PATH_COL); /*!< Name of column containing the Path header */ +str ul_sock_col = str_init( + SOCK_COL); /*!< Name of column containing the received socket */ +str ul_methods_col = str_init( + METHODS_COL); /*!< Name of column containing the supported methods */ +str ul_instance_col = str_init( + INSTANCE_COL); /*!< Name of column containing the SIP instance value */ +str ul_reg_id_col = + str_init(REG_ID_COL); /*!< Name of column containing the reg-id value */ +str ul_last_mod_col = str_init( + LAST_MOD_COL); /*!< Name of column containing the last modified date */ +str ul_srv_id_col = str_init( + SRV_ID_COL); /*!< Name of column containing the server id value */ +str ul_con_id_col = str_init( + CON_ID_COL); /*!< Name of column containing the connection id value */ +str ul_keepalive_col = str_init( + KEEPALIVE_COL); /*!< Name of column containing the keepalive value */ +str ul_partition_col = str_init( + PARTITION_COL); /*!< Name of column containing the partition value */ + +str ulattrs_user_col = + str_init(ULATTRS_USER_COL); /*!< Name of column containing username */ +str ulattrs_domain_col = + str_init(ULATTRS_DOMAIN_COL); /*!< Name of column containing domain */ +str ulattrs_ruid_col = str_init( + ULATTRS_RUID_COL); /*!< Name of column containing record unique id */ +str ulattrs_aname_col = str_init( + ULATTRS_ANAME_COL); /*!< Name of column containing attribute name */ +str ulattrs_atype_col = str_init( + ULATTRS_ATYPE_COL); /*!< Name of column containing attribute type */ +str ulattrs_avalue_col = str_init( + ULATTRS_AVALUE_COL); /*!< Name of column containing attribute value */ +str ulattrs_last_mod_col = str_init( + ULATTRS_LAST_MOD_COL); /*!< Name of column containing the last modified date */ + +str ul_db_url = str_init(DEFAULT_DB_URL); /*!< Database URL */ +int ul_timer_interval = 60; /*!< Timer interval in seconds */ +int ul_db_mode = + 0; /*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */ +int ul_db_load = + 1; /*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */ +int ul_db_insert_update = + 0; /*!< Database : update on duplicate key instead of error */ +int ul_use_domain = 0; /*!< Whether usrloc should use domain part of aor */ +int ul_desc_time_order = 0; /*!< By default do not enable timestamp ordering */ +int ul_handle_lost_tcp = + 0; /*!< By default do not remove contacts before expiration time */ +int ul_close_expired_tcp = + 0; /*!< By default do not close TCP connections for expired contacts */ +int ul_skip_remote_socket = 0; /*!< By default do not skip remote socket */ +int ul_db_clean_tcp = + 0; /*!< Clean TCP/TLS/WSS contacts in DB before loading records */ + +int ul_fetch_rows = 2000; /*!< number of rows to fetch from result */ int ul_hash_size = 10; int ul_db_insert_null = 0; int ul_db_timer_clean = 0; @@ -187,7 +224,7 @@ int ul_db_timer_clean = 0; unsigned int ul_nat_bflag = (unsigned int)-1; unsigned int ul_init_flag = 0; -db1_con_t* ul_dbh = 0; /* Database connection handle */ +db1_con_t *ul_dbh = 0; /* Database connection handle */ db_func_t ul_dbf; /* filter on load and during cleanup by server id */ @@ -197,95 +234,90 @@ unsigned int ul_db_srvid = 0; * Exported functions */ static cmd_export_t cmds[] = { - {"ul_bind_usrloc", (cmd_function)bind_usrloc, 1, 0, 0, 0}, - {0, 0, 0, 0, 0, 0} -}; + {"ul_bind_usrloc", (cmd_function)bind_usrloc, 1, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}}; /*! \brief * Exported parameters */ -static param_export_t params[] = { - {"ruid_column", PARAM_STR, &ul_ruid_col }, - {"user_column", PARAM_STR, &ul_user_col }, - {"domain_column", PARAM_STR, &ul_domain_col }, - {"contact_column", PARAM_STR, &ul_contact_col }, - {"expires_column", PARAM_STR, &ul_expires_col }, - {"q_column", PARAM_STR, &ul_q_col }, - {"callid_column", PARAM_STR, &ul_callid_col }, - {"cseq_column", PARAM_STR, &ul_cseq_col }, - {"flags_column", PARAM_STR, &ul_flags_col }, - {"cflags_column", PARAM_STR, &ul_cflags_col }, - {"db_url", PARAM_STR, &ul_db_url }, - {"timer_interval", INT_PARAM, &ul_timer_interval }, - {"db_mode", INT_PARAM, &ul_db_mode }, - {"db_load", INT_PARAM, &ul_db_load }, - {"db_insert_update", INT_PARAM, &ul_db_insert_update }, - {"use_domain", INT_PARAM, &ul_use_domain }, - {"desc_time_order", INT_PARAM, &ul_desc_time_order }, - {"user_agent_column", PARAM_STR, &ul_user_agent_col}, - {"received_column", PARAM_STR, &ul_received_col }, - {"path_column", PARAM_STR, &ul_path_col }, - {"socket_column", PARAM_STR, &ul_sock_col }, - {"methods_column", PARAM_STR, &ul_methods_col }, - {"instance_column", PARAM_STR, &ul_instance_col }, - {"reg_id_column", PARAM_STR, &ul_reg_id_col }, - {"server_id_column", PARAM_STR, &ul_srv_id_col }, - {"connection_id_column",PARAM_STR, &ul_con_id_col }, - {"keepalive_column", PARAM_STR, &ul_keepalive_col }, - {"partition_column", PARAM_STR, &ul_partition_col }, - {"matching_mode", INT_PARAM, &ul_matching_mode }, - {"cseq_delay", INT_PARAM, &ul_cseq_delay }, - {"fetch_rows", INT_PARAM, &ul_fetch_rows }, - {"hash_size", INT_PARAM, &ul_hash_size }, - {"nat_bflag", INT_PARAM, &ul_nat_bflag }, - {"handle_lost_tcp", INT_PARAM, &ul_handle_lost_tcp }, - {"close_expired_tcp", INT_PARAM, &ul_close_expired_tcp }, - {"skip_remote_socket", INT_PARAM, &ul_skip_remote_socket }, - {"preload", PARAM_STRING|USE_FUNC_PARAM, (void*)ul_preload_param}, - {"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert}, - {"timer_procs", INT_PARAM, &ul_timer_procs}, - {"db_check_update", INT_PARAM, &ul_db_check_update}, - {"xavp_contact", PARAM_STR, &ul_xavp_contact_name}, - {"db_ops_ruid", INT_PARAM, &ul_db_ops_ruid}, - {"expires_type", PARAM_INT, &ul_expires_type}, - {"db_raw_fetch_type", PARAM_INT, &ul_db_raw_fetch_type}, - {"db_insert_null", PARAM_INT, &ul_db_insert_null}, - {"server_id_filter", PARAM_INT, &ul_db_srvid}, - {"db_timer_clean", PARAM_INT, &ul_db_timer_clean}, - {"rm_expired_delay", PARAM_INT, &ul_rm_expired_delay}, - {"version_table", PARAM_INT, &ul_version_table}, - {"ka_mode", PARAM_INT, &ul_ka_mode}, - {"ka_from", PARAM_STR, &ul_ka_from}, - {"ka_domain", PARAM_STR, &ul_ka_domain}, - {"ka_method", PARAM_STR, &ul_ka_method}, - {"ka_filter", PARAM_INT, &ul_ka_filter}, - {"ka_timeout", PARAM_INT, &ul_keepalive_timeout}, - {"ka_loglevel", PARAM_INT, &ul_ka_loglevel}, - {"ka_logmsg", PARAM_STR, &ul_ka_logmsg}, - {"load_rank", PARAM_INT, &ul_load_rank}, - {"db_clean_tcp", PARAM_INT, &ul_db_clean_tcp}, - {0, 0, 0} -}; +static param_export_t params[] = {{"ruid_column", PARAM_STR, &ul_ruid_col}, + {"user_column", PARAM_STR, &ul_user_col}, + {"domain_column", PARAM_STR, &ul_domain_col}, + {"contact_column", PARAM_STR, &ul_contact_col}, + {"expires_column", PARAM_STR, &ul_expires_col}, + {"q_column", PARAM_STR, &ul_q_col}, + {"callid_column", PARAM_STR, &ul_callid_col}, + {"cseq_column", PARAM_STR, &ul_cseq_col}, + {"flags_column", PARAM_STR, &ul_flags_col}, + {"cflags_column", PARAM_STR, &ul_cflags_col}, + {"db_url", PARAM_STR, &ul_db_url}, + {"timer_interval", INT_PARAM, &ul_timer_interval}, + {"db_mode", INT_PARAM, &ul_db_mode}, + {"db_load", INT_PARAM, &ul_db_load}, + {"db_insert_update", INT_PARAM, &ul_db_insert_update}, + {"use_domain", INT_PARAM, &ul_use_domain}, + {"desc_time_order", INT_PARAM, &ul_desc_time_order}, + {"user_agent_column", PARAM_STR, &ul_user_agent_col}, + {"received_column", PARAM_STR, &ul_received_col}, + {"path_column", PARAM_STR, &ul_path_col}, + {"socket_column", PARAM_STR, &ul_sock_col}, + {"methods_column", PARAM_STR, &ul_methods_col}, + {"instance_column", PARAM_STR, &ul_instance_col}, + {"reg_id_column", PARAM_STR, &ul_reg_id_col}, + {"server_id_column", PARAM_STR, &ul_srv_id_col}, + {"connection_id_column", PARAM_STR, &ul_con_id_col}, + {"keepalive_column", PARAM_STR, &ul_keepalive_col}, + {"partition_column", PARAM_STR, &ul_partition_col}, + {"matching_mode", INT_PARAM, &ul_matching_mode}, + {"cseq_delay", INT_PARAM, &ul_cseq_delay}, + {"fetch_rows", INT_PARAM, &ul_fetch_rows}, + {"hash_size", INT_PARAM, &ul_hash_size}, + {"nat_bflag", INT_PARAM, &ul_nat_bflag}, + {"handle_lost_tcp", INT_PARAM, &ul_handle_lost_tcp}, + {"close_expired_tcp", INT_PARAM, &ul_close_expired_tcp}, + {"skip_remote_socket", INT_PARAM, &ul_skip_remote_socket}, + {"preload", PARAM_STRING | USE_FUNC_PARAM, (void *)ul_preload_param}, + {"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert}, + {"timer_procs", INT_PARAM, &ul_timer_procs}, + {"db_check_update", INT_PARAM, &ul_db_check_update}, + {"xavp_contact", PARAM_STR, &ul_xavp_contact_name}, + {"db_ops_ruid", INT_PARAM, &ul_db_ops_ruid}, + {"expires_type", PARAM_INT, &ul_expires_type}, + {"db_raw_fetch_type", PARAM_INT, &ul_db_raw_fetch_type}, + {"db_insert_null", PARAM_INT, &ul_db_insert_null}, + {"server_id_filter", PARAM_INT, &ul_db_srvid}, + {"db_timer_clean", PARAM_INT, &ul_db_timer_clean}, + {"rm_expired_delay", PARAM_INT, &ul_rm_expired_delay}, + {"version_table", PARAM_INT, &ul_version_table}, + {"ka_mode", PARAM_INT, &ul_ka_mode}, + {"ka_from", PARAM_STR, &ul_ka_from}, + {"ka_domain", PARAM_STR, &ul_ka_domain}, + {"ka_method", PARAM_STR, &ul_ka_method}, + {"ka_filter", PARAM_INT, &ul_ka_filter}, + {"ka_timeout", PARAM_INT, &ul_keepalive_timeout}, + {"ka_loglevel", PARAM_INT, &ul_ka_loglevel}, + {"ka_logmsg", PARAM_STR, &ul_ka_logmsg}, + {"load_rank", PARAM_INT, &ul_load_rank}, + {"db_clean_tcp", PARAM_INT, &ul_db_clean_tcp}, {0, 0, 0}}; stat_export_t mod_stats[] = { - {"registered_users" , STAT_IS_FUNC, (stat_var**)get_number_of_users }, - {0,0,0} -}; + {"registered_users", STAT_IS_FUNC, (stat_var **)get_number_of_users}, + {0, 0, 0}}; struct module_exports exports = { - "usrloc", /*!< module name */ - DEFAULT_DLFLAGS, /*!< dlopen flags */ - cmds, /*!< exported functions */ - params, /*!< exported parameters */ - 0, /*!< exported rpc functions */ - 0, /*!< exported pseudo-variables */ - ul_sip_reply_received, /*!< response handling function */ - mod_init, /*!< module init function */ - child_init, /*!< child init function */ - destroy /*!< destroy function */ + "usrloc", /*!< module name */ + DEFAULT_DLFLAGS, /*!< dlopen flags */ + cmds, /*!< exported functions */ + params, /*!< exported parameters */ + 0, /*!< exported rpc functions */ + 0, /*!< exported pseudo-variables */ + ul_sip_reply_received, /*!< response handling function */ + mod_init, /*!< module init function */ + child_init, /*!< child init function */ + destroy /*!< destroy function */ }; @@ -295,44 +327,44 @@ struct module_exports exports = { static int mod_init(void) { int i; - udomain_t* d; + udomain_t *d; - if(ul_rm_expired_delay!=0) { + if(ul_rm_expired_delay != 0) { if(ul_db_mode != DB_ONLY) { LM_ERR("rm expired delay feature is available for db only mode\n"); return -1; } } - if(ul_rm_expired_delay<0) { + if(ul_rm_expired_delay < 0) { LM_WARN("rm expired delay value is negative (%d) - setting it to 0\n", ul_rm_expired_delay); ul_rm_expired_delay = 0; } - if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0) { + if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC) < 0) { return -1; } #ifdef STATISTICS /* register statistics */ - if (register_module_stats(exports.name, mod_stats)!=0 ) { + if(register_module_stats(exports.name, mod_stats) != 0) { LM_ERR("failed to register core statistics\n"); return -1; } #endif - if (rpc_register_array(ul_rpc)!=0) { + if(rpc_register_array(ul_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } - if(ul_hash_size<=1) { + if(ul_hash_size <= 1) { ul_hash_size = 512; } else { - ul_hash_size = 1< 0) { + if(ul_timer_procs <= 0) { + if(ul_timer_interval > 0) { register_timer(ul_core_timer, 0, ul_timer_interval); } } else { @@ -352,63 +384,63 @@ static int mod_init(void) } /* init the callbacks list */ - if (init_ulcb_list() < 0) { + if(init_ulcb_list() < 0) { LM_ERR("usrloc/callbacks initialization failed\n"); return -1; } /* Shall we use database ? */ - switch (ul_db_mode) { + switch(ul_db_mode) { case DB_ONLY: case WRITE_THROUGH: case WRITE_BACK: - /* + /* * register the need to be called post-fork of all children * with the special rank PROC_POSTCHILDINIT */ - ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT); + ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT); } - if (ul_db_mode != NO_DB) { /* Yes */ - if (db_bind_mod(&ul_db_url, &ul_dbf) < 0) { /* Find database module */ + if(ul_db_mode != NO_DB) { /* Yes */ + if(db_bind_mod(&ul_db_url, &ul_dbf) < 0) { /* Find database module */ LM_ERR("failed to bind database module\n"); return -1; } - if (!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) { + if(!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) { LM_ERR("database module does not implement all functions" - " needed by the module\n"); + " needed by the module\n"); return -1; } - if(ul_fetch_rows<=0) { + if(ul_fetch_rows <= 0) { LM_ERR("invalid fetch_rows number '%d'\n", ul_fetch_rows); return -1; } } - if(ul_db_mode==WRITE_THROUGH || ul_db_mode==WRITE_BACK) { - if(ul_db_timer_clean!=0) { - if(sr_wtimer_add(ul_db_clean_timer, 0, ul_timer_interval)<0) { + if(ul_db_mode == WRITE_THROUGH || ul_db_mode == WRITE_BACK) { + if(ul_db_timer_clean != 0) { + if(sr_wtimer_add(ul_db_clean_timer, 0, ul_timer_interval) < 0) { LM_ERR("failed to add db clean timer routine\n"); return -1; } } } - if (ul_nat_bflag==(unsigned int)-1) { + if(ul_nat_bflag == (unsigned int)-1) { ul_nat_bflag = 0; - } else if (ul_nat_bflag>=8*sizeof(ul_nat_bflag) ) { + } else if(ul_nat_bflag >= 8 * sizeof(ul_nat_bflag)) { LM_ERR("bflag index (%d) too big!\n", ul_nat_bflag); return -1; } else { - ul_nat_bflag = 1< 1) { + if(ul_timer_procs > 1) { ul_set_max_partition((unsigned int)ul_timer_procs); } if(ul_ka_logmsg.len > 0) { @@ -436,18 +468,18 @@ static int mod_init(void) static int child_init(int _rank) { - dlist_t* ptr; + dlist_t *ptr; int i; - if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0) + if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC) < 0) return -1; - if(_rank==PROC_MAIN && ul_timer_procs>0) - { - for(i=0; i 0) { + for(i = 0; i < ul_timer_procs; i++) { if(fork_sync_timer(PROC_TIMER, "USRLOC Timer", 1 /*socks flag*/, - ul_local_timer, (void*)(long)i, ul_timer_interval /*sec*/)<0) { + ul_local_timer, (void *)(long)i, + ul_timer_interval /*sec*/) + < 0) { LM_ERR("failed to start timer routine as process\n"); return -1; /* error */ } @@ -455,43 +487,44 @@ static int child_init(int _rank) } /* connecting to DB ? */ - switch (ul_db_mode) { + switch(ul_db_mode) { case NO_DB: return 0; case DB_ONLY: case WRITE_THROUGH: /* connect to db only from SIP workers, TIMER and MAIN processes, * and RPC processes */ - if (_rank<=0 && _rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT - && _rank!=PROC_RPC) + if(_rank <= 0 && _rank != PROC_TIMER && _rank != PROC_POSTCHILDINIT + && _rank != PROC_RPC) return 0; break; case WRITE_BACK: /* connect to db only from TIMER (for flush), from MAIN (for * final flush() and from child 1 for preload */ - if (_rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT && _rank!=PROC_SIPINIT) + if(_rank != PROC_TIMER && _rank != PROC_POSTCHILDINIT + && _rank != PROC_SIPINIT) return 0; break; case DB_READONLY: /* connect to db only from child 1 for preload */ - ul_db_load=1; /* we always load from the db in this mode */ - if(_rank!=PROC_SIPINIT) + ul_db_load = 1; /* we always load from the db in this mode */ + if(_rank != PROC_SIPINIT) return 0; break; } ul_dbh = ul_dbf.init(&ul_db_url); /* Get a database connection per child */ - if (!ul_dbh) { + if(!ul_dbh) { LM_ERR("child(%d): failed to connect to database\n", _rank); return -1; } /* _rank==PROC_SIPINIT is used even when fork is disabled */ - if (_rank==ul_load_rank && ul_db_mode!=DB_ONLY && ul_db_load) { + if(_rank == ul_load_rank && ul_db_mode != DB_ONLY && ul_db_load) { /* if cache is used, populate domains from DB */ - for(ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) { - if (preload_udomain(ul_dbh, ptr->d) < 0) { - LM_ERR("child(%d): failed to preload domain '%.*s'\n", - _rank, ptr->name.len, ZSW(ptr->name.s)); + for(ptr = _ksr_ul_root; ptr; ptr = ptr->next) { + if(preload_udomain(ul_dbh, ptr->d) < 0) { + LM_ERR("child(%d): failed to preload domain '%.*s'\n", _rank, + ptr->name.len, ZSW(ptr->name.s)); return -1; } uldb_preload_attrs(ptr->d); @@ -508,8 +541,8 @@ static int child_init(int _rank) static void destroy(void) { /* we need to sync DB in order to flush the cache */ - if (ul_dbh) { - if (synchronize_all_udomains(0, 1) != 0) { + if(ul_dbh) { + if(synchronize_all_udomains(0, 1) != 0) { LM_ERR("flushing cache failed\n"); } ul_dbf.close(ul_dbh); @@ -536,9 +569,9 @@ static int ul_sip_reply_received(sip_msg_t *msg) /*! \brief * Core timer handler */ -static void ul_core_timer(unsigned int ticks, void* param) +static void ul_core_timer(unsigned int ticks, void *param) { - if (synchronize_all_udomains(0, 1) != 0) { + if(synchronize_all_udomains(0, 1) != 0) { LM_ERR("synchronizing cache failed\n"); } } @@ -546,9 +579,9 @@ static void ul_core_timer(unsigned int ticks, void* param) /*! \brief * Local timer handler */ -static void ul_local_timer(unsigned int ticks, void* param) +static void ul_local_timer(unsigned int ticks, void *param) { - if (synchronize_all_udomains((int)(long)param, ul_timer_procs) != 0) { + if(synchronize_all_udomains((int)(long)param, ul_timer_procs) != 0) { LM_ERR("synchronizing cache failed\n"); } } @@ -556,7 +589,7 @@ static void ul_local_timer(unsigned int ticks, void* param) /*! \brief * DB dlean timer handler */ -static void ul_db_clean_timer(unsigned int ticks, void* param) +static void ul_db_clean_timer(unsigned int ticks, void *param) { ul_db_clean_udomains(); } @@ -564,19 +597,17 @@ static void ul_db_clean_timer(unsigned int ticks, void* param) /*! \brief * preload module parameter handler */ -static int ul_preload_param(modparam_t type, void* val) +static int ul_preload_param(modparam_t type, void *val) { - if(val==NULL) - { + if(val == NULL) { LM_ERR("invalid parameter\n"); goto error; } - if(ul_preload_index>=UL_PRELOAD_SIZE) - { + if(ul_preload_index >= UL_PRELOAD_SIZE) { LM_ERR("too many preloaded tables\n"); goto error; } - ul_preload_list[ul_preload_index] = (char*)val; + ul_preload_list[ul_preload_index] = (char *)val; ul_preload_index++; return 0; error: diff --git a/src/modules/usrloc/usrloc_mod.h b/src/modules/usrloc/usrloc_mod.h index 8c24e1230b8..7192c9cf6d6 100644 --- a/src/modules/usrloc/usrloc_mod.h +++ b/src/modules/usrloc/usrloc_mod.h @@ -97,7 +97,7 @@ extern unsigned int ul_init_flag; extern str ul_xavp_contact_name; -extern db1_con_t* ul_dbh; /* Database connection handle */ +extern db1_con_t *ul_dbh; /* Database connection handle */ extern db_func_t ul_dbf; /* filter on load and during cleanup by server id */ @@ -106,10 +106,10 @@ extern unsigned int ul_db_srvid; /* * Matching algorithms */ -#define CONTACT_ONLY (0) -#define CONTACT_CALLID (1) -#define CONTACT_PATH (2) -#define CONTACT_CALLID_ONLY (3) +#define CONTACT_ONLY (0) +#define CONTACT_CALLID (1) +#define CONTACT_PATH (2) +#define CONTACT_CALLID_ONLY (3) extern int ul_matching_mode; @@ -117,16 +117,18 @@ extern int ul_db_ops_ruid; extern int ul_expires_type; -#define UL_DB_EXPIRES_SET(r, v) do { \ - if(ul_expires_type==1) { \ - (r)->type = DB1_BIGINT; \ - (r)->val.ll_val = (long long)(v); \ - } else { \ - (r)->type = DB1_DATETIME; \ - (r)->val.time_val = (time_t)(v); \ - } \ - } while(0) - -#define UL_DB_EXPIRES_GET(r) ((ul_expires_type==1)?(time_t)VAL_BIGINT(r):VAL_TIME(r)) +#define UL_DB_EXPIRES_SET(r, v) \ + do { \ + if(ul_expires_type == 1) { \ + (r)->type = DB1_BIGINT; \ + (r)->val.ll_val = (long long)(v); \ + } else { \ + (r)->type = DB1_DATETIME; \ + (r)->val.time_val = (time_t)(v); \ + } \ + } while(0) + +#define UL_DB_EXPIRES_GET(r) \ + ((ul_expires_type == 1) ? (time_t)VAL_BIGINT(r) : VAL_TIME(r)) #endif /* _USRLOC_MOD_H_ */