Skip to content

Commit

Permalink
usrloc: Expose struct debugging functions to upper modules
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Mar 16, 2018
1 parent bd4a43a commit 6b21511
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 165 deletions.
4 changes: 4 additions & 0 deletions modules/registrar/lookup.c
Expand Up @@ -211,6 +211,10 @@ int lookup(struct sip_msg* _m, char* _t, char* _f, char* _s)


ptr = r->contacts;
#ifdef EXTRA_DEBUG
print_urecord(r);
#endif

ret = -1;
/* look first for an un-expired and suported contact */
search_valid_contact:
Expand Down
18 changes: 0 additions & 18 deletions modules/usrloc/dlist.c
Expand Up @@ -757,24 +757,6 @@ void free_all_udomains(void)
}


/*! \brief
* Just for debugging
*/
void print_all_udomains(FILE* _f)
{
dlist_t* ptr;

ptr = root;

fprintf(_f, "===Domain list===\n");
while(ptr) {
print_udomain(_f, ptr->d);
ptr = ptr->next;
}
fprintf(_f, "===/Domain list===\n");
}


/*! \brief
* Loops through all domains summing up the number of users.
*/
Expand Down
6 changes: 0 additions & 6 deletions modules/usrloc/dlist.h
Expand Up @@ -69,12 +69,6 @@ int register_udomain(const char* _n, udomain_t** _d);
void free_all_udomains(void);


/*
* Just for debugging
*/
void print_all_udomains(FILE* _f);


/*! \brief
* Called from timer
*/
Expand Down
62 changes: 0 additions & 62 deletions modules/usrloc/ucontact.c
Expand Up @@ -210,68 +210,6 @@ void free_ucontact(ucontact_t* _c)
}


/*! \brief
* Print contact, for debugging purposes only
*/
void print_ucontact(FILE* _f, ucontact_t* _c)
{
time_t t = time(0);
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;
}

fprintf(_f, "~~~Contact(%p)~~~\n", _c);
fprintf(_f, "domain : '%.*s'\n", _c->domain->len, ZSW(_c->domain->s));
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) {
fprintf(_f, "Permanent\n");
} else if (_c->expires == UL_EXPIRED_TIME) {
fprintf(_f, "Deleted\n");
} else if (t > _c->expires) {
fprintf(_f, "Expired\n");
} else {
fprintf(_f, "%u\n", (unsigned int)(_c->expires - t));
}
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, "State : %s\n", st);
fprintf(_f, "Flags : %u\n", _c->flags);
fprintf(_f, "Attrs : '%.*s'\n", _c->attr.len, _c->attr.s);
if (_c->sipping_latency) {
fprintf(_f, "sipping_latency : '%d \n", _c->sipping_latency);
}else{
fprintf(_f, "sipping_latency : NULL \n");

}
if (_c->sock) {
fprintf(_f, "Sock : %.*s (as %.*s )(%p)\n",
_c->sock->sock_str.len,_c->sock->sock_str.s,
_c->sock->adv_sock_str.len,ZSW(_c->sock->adv_sock_str.s),
_c->sock);
} else {
fprintf(_f, "Sock : none (null)\n");
}
fprintf(_f, "Methods : %u\n", _c->methods);
fprintf(_f, "next : %p\n", _c->next);
fprintf(_f, "prev : %p\n", _c->prev);
fprintf(_f, "~~~/Contact~~~~\n");
}


/*! \brief
* Update ucontact structure in memory
*/
Expand Down
6 changes: 0 additions & 6 deletions modules/usrloc/ucontact.h
Expand Up @@ -154,12 +154,6 @@ new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _ci);
void free_ucontact(ucontact_t* _c);


/*! \brief
* Print contact, for debugging purposes only
*/
void print_ucontact(FILE* _f, ucontact_t* _c);


/*! \brief
* Update existing contact in memory with new values
*/
Expand Down
34 changes: 0 additions & 34 deletions modules/usrloc/udomain.c
Expand Up @@ -456,40 +456,6 @@ get_static_urecord(const udomain_t* _d, const str* _aor, struct urecord** _r)
*_r = &r;
}

/*! \brief
* Just for debugging
*/
void print_udomain(FILE* _f, udomain_t* _d)
{
int i;
int max=0, slot=0, n=0,count;
map_iterator_t it;
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++)
{
count = map_size( _d->table[i].records);
n += count;
if(max<count){
max= count;
slot = i;
}

for ( map_first( _d->table[i].records, &it);
iterator_is_valid(&it);
iterator_next(&it) )
print_urecord(_f, (struct urecord *)*iterator_val(&it));

}

fprintf(_f, "\nMax slot: %d (%d/%d)\n", max, slot, n);
fprintf(_f, "\n---/Domain---\n");
}

/*! \brief
* expects (UL_COLS - 4) fields:
* contact, expires, q, callid, cseq, flags, cflags, ua,
Expand Down
6 changes: 0 additions & 6 deletions modules/usrloc/udomain.h
Expand Up @@ -82,12 +82,6 @@ int new_udomain(str* _n, int _s, udomain_t** _d);
void free_udomain(udomain_t* _d);


/*! \brief
* Just for debugging
*/
void print_udomain(FILE* _f, udomain_t* _d);


/*! \brief
* Load data from a database
*/
Expand Down
159 changes: 159 additions & 0 deletions modules/usrloc/ul_dbg.h
@@ -0,0 +1,159 @@
/*
* Usrloc struct debugging
*
* Copyright (C) 2018 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
*/

#ifndef USRLOC_DBG__
#define USRLOC_DBG__

/*! \brief
* Print contact, for debugging purposes only
*/
static inline void print_ucontact(ucontact_t* _c)
{
time_t t = time(0);
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;
}

LM_GEN1(L_DBG, "~~~Contact(%p)~~~\n", _c);
LM_GEN1(L_DBG, "domain : '%.*s'\n", _c->domain->len, ZSW(_c->domain->s));
LM_GEN1(L_DBG, "aor : '%.*s'\n", _c->aor->len, ZSW(_c->aor->s));
LM_GEN1(L_DBG, "Contact : '%.*s'\n", _c->c.len, ZSW(_c->c.s));
LM_GEN1(L_DBG, "Expires : ");
if (_c->expires == 0) {
LM_GEN1(L_DBG, "Permanent\n");
} else if (_c->expires == UL_EXPIRED_TIME) {
LM_GEN1(L_DBG, "Deleted\n");
} else if (t > _c->expires) {
LM_GEN1(L_DBG, "Expired\n");
} else {
LM_GEN1(L_DBG, "%u\n", (unsigned int)(_c->expires - t));
}
LM_GEN1(L_DBG, "q : %s\n", q2str(_c->q, 0));
LM_GEN1(L_DBG, "Call-ID : '%.*s'\n", _c->callid.len, ZSW(_c->callid.s));
LM_GEN1(L_DBG, "CSeq : %d\n", _c->cseq);
LM_GEN1(L_DBG, "User-Agent: '%.*s'\n",
_c->user_agent.len, ZSW(_c->user_agent.s));
LM_GEN1(L_DBG, "received : '%.*s'\n",
_c->received.len, ZSW(_c->received.s));
LM_GEN1(L_DBG, "Path : '%.*s'\n",
_c->path.len, ZSW(_c->path.s));
LM_GEN1(L_DBG, "State : %s\n", st);
LM_GEN1(L_DBG, "Flags : %u\n", _c->flags);
LM_GEN1(L_DBG, "Attrs : '%.*s'\n", _c->attr.len, _c->attr.s);
LM_GEN1(L_DBG, "Latency : %d\n", _c->sipping_latency);

if (_c->sock) {
LM_GEN1(L_DBG, "Sock : %.*s (as %.*s )(%p)\n",
_c->sock->sock_str.len,_c->sock->sock_str.s,
_c->sock->adv_sock_str.len,ZSW(_c->sock->adv_sock_str.s),
_c->sock);
} else {
LM_GEN1(L_DBG, "Sock : none (null)\n");
}

LM_GEN1(L_DBG, "Methods : %u\n", _c->methods);
LM_GEN1(L_DBG, "next : %p\n", _c->next);
LM_GEN1(L_DBG, "prev : %p\n", _c->prev);
LM_GEN1(L_DBG, "~~~/Contact~~~~\n");
}

/*! \brief
* Print a record
*/
static inline void print_urecord(urecord_t* _r)
{
ucontact_t* ptr;

LM_GEN1(L_DBG, "...Record(%p)...\n", _r);
LM_GEN1(L_DBG, "domain : '%.*s'\n", _r->domain->len, ZSW(_r->domain->s));
LM_GEN1(L_DBG, "aor : '%.*s'\n", _r->aor.len, ZSW(_r->aor.s));
LM_GEN1(L_DBG, "aorhash: '%u'\n", (unsigned)_r->aorhash);
LM_GEN1(L_DBG, "slot: '%d'\n",
_r->slot ? _r->aorhash&(_r->slot->d->size-1) : -1);

if (_r->contacts) {
ptr = _r->contacts;
while(ptr) {
print_ucontact(ptr);
ptr = ptr->next;
}
}

LM_GEN1(L_DBG, ".../Record...\n");
}

/*! \brief
* Just for debugging
*/
static inline void print_udomain(udomain_t* _d)
{
int i;
int max=0, slot=0, n=0,count;
map_iterator_t it;
LM_GEN1(L_DBG, "---Domain---\n");
LM_GEN1(L_DBG, "name : '%.*s'\n", _d->name->len, ZSW(_d->name->s));
LM_GEN1(L_DBG, "size : %d\n", _d->size);
LM_GEN1(L_DBG, "table: %p\n", _d->table);
/*LM_GEN1(L_DBG, "lock : %d\n", _d->lock); -- can be a structure --andrei*/
LM_GEN1(L_DBG, "\n");
for(i=0; i<_d->size; i++)
{
count = map_size( _d->table[i].records);
n += count;
if(max<count){
max= count;
slot = i;
}

for ( map_first( _d->table[i].records, &it);
iterator_is_valid(&it);
iterator_next(&it) )
print_urecord((struct urecord *)*iterator_val(&it));
}

LM_GEN1(L_DBG, "\nMax slot: %d (%d/%d)\n", max, slot, n);
LM_GEN1(L_DBG, "\n---/Domain---\n");
}

/*! \brief
* Just for debugging
*/
static inline void print_all_udomains(void)
{
dlist_t* ptr;

ptr = root;

LM_GEN1(L_DBG, "===Domain list===\n");
while (ptr) {
print_udomain(ptr->d);
ptr = ptr->next;
}
LM_GEN1(L_DBG, "===/Domain list===\n");
}

#endif /* USRLOC_DBG__ */
4 changes: 2 additions & 2 deletions modules/usrloc/ul_mod.c
Expand Up @@ -651,7 +651,7 @@ int check_runtime_config(void)
runtime_preset = "single-instance-sql-write-back";
break;
case DB_ONLY:
runtime_preset = "sql-only";
runtime_preset = "sql-only-cluster";
break;
}
} else if (db_mode != NOT_SET) {
Expand All @@ -673,7 +673,7 @@ int check_runtime_config(void)
cluster_mode = CM_NONE;
rr_persist = RRP_LOAD_FROM_SQL;
sql_wmode = SQL_WRITE_BACK;
} else if (!strcasecmp(runtime_preset, "sql-only")) {
} else if (!strcasecmp(runtime_preset, "sql-only-cluster")) {
cluster_mode = CM_SQL_ONLY;
rr_persist = RRP_NONE;
sql_wmode = SQL_NO_WRITE;
Expand Down
25 changes: 0 additions & 25 deletions modules/usrloc/urecord.c
Expand Up @@ -125,31 +125,6 @@ void free_urecord(urecord_t* _r)
}


/*! \brief
* Print a record
*/
void print_urecord(FILE* _f, urecord_t* _r)
{
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));

if (_r->contacts) {
ptr = _r->contacts;
while(ptr) {
print_ucontact(_f, ptr);
ptr = ptr->next;
}
}

fprintf(_f, ".../Record...\n");
}


/*! \brief
* Add a new contact
* Contacts are ordered by: 1) q
Expand Down

0 comments on commit 6b21511

Please sign in to comment.