Skip to content

Commit

Permalink
tm: migrated some old log macros to new style
Browse files Browse the repository at this point in the history
- coherent indentation across those files
  • Loading branch information
miconda committed Jan 11, 2017
1 parent d081ee4 commit 11f9a91
Show file tree
Hide file tree
Showing 6 changed files with 672 additions and 576 deletions.
91 changes: 47 additions & 44 deletions src/modules/tm/callid.c
Expand Up @@ -13,16 +13,16 @@
* 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
* 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
*
*/

/*!
* \file
* \file
* \brief TM :: Fast Call-ID generator
*
*
* Fast Call-ID generator. The Call-ID has the following form: \<callid_nr>-\<pid\>\@\<ip\>
* - callid_nr is initialized as a random number and continually increases
* - \<pid\>\@\<ip\> is kept in callid_suffix
Expand All @@ -47,13 +47,12 @@
/**
* \brief Length of the Call-ID suffix
*/
#define CALLID_SUFFIX_LEN ( 1 /* - */ + \
5 /* pid */ + \
42 /* embedded v4inv6 address can be looong '128.' */ + \
2 /* parenthesis [] */ + \
1 /* ZT 0 */ + \
16 /* one never knows ;-) */ \
)
#define CALLID_SUFFIX_LEN \
(1 /* - */ + 5 /* pid */ \
+ 42 /* embedded v4inv6 address can be looong '128.' */ \
+ 2 /* parenthesis [] */ + 1 /* ZT 0 */ \
+ 16 /* one never knows ;-) */ \
)


static unsigned long callid_nr;
Expand All @@ -71,36 +70,40 @@ int init_callid(void)
{
int rand_bits, i;

/* calculate the initial call-id */
/* how many bits and chars do we need to display the
/* calculate the initial call-id */
/* how many bits and chars do we need to display the
* whole ULONG number */
callid_prefix.len = sizeof(unsigned long) * 2;
callid_prefix.s = callid_buf;

if (callid_prefix.len > CALLID_NR_LEN) {
LOG(L_ERR, "ERROR: Too small callid buffer\n");
if(callid_prefix.len > CALLID_NR_LEN) {
LM_ERR("too small callid buffer\n");
return -1;
}

for(rand_bits = 1, i = KAM_RAND_MAX; i; i >>= 1, rand_bits++); /* how long are the rand()s ? */
i = callid_prefix.len * 4 / rand_bits; /* how many rands() fit in the ULONG ? */

/* now fill in the callid with as many random
* numbers as you can + 1 */
callid_nr = kam_rand(); /* this is the + 1 */
for(rand_bits = 1, i = KAM_RAND_MAX; i; i >>= 1, rand_bits++)
; /* how long are the rand()s ? */
i = callid_prefix.len * 4
/ rand_bits; /* how many rands() fit in the ULONG ? */

/* now fill in the callid with as many random
* numbers as you can + 1 */
callid_nr = kam_rand(); /* this is the + 1 */

while(i--) {
callid_nr <<= rand_bits;
callid_nr |= kam_rand();
}

i = snprintf(callid_prefix.s, callid_prefix.len + 1, "%0*lx", callid_prefix.len, callid_nr);
if ((i == -1) || (i > callid_prefix.len)) {
LOG(L_CRIT, "BUG: SORRY, callid calculation failed\n");
i = snprintf(callid_prefix.s, callid_prefix.len + 1, "%0*lx",
callid_prefix.len, callid_nr);
if((i == -1) || (i > callid_prefix.len)) {
LM_CRIT("callid calculation failed\n");
return -2;
}

DBG("Call-ID initialization: '%.*s'\n", callid_prefix.len, callid_prefix.s);

LM_DBG("Call-ID initialization: '%.*s'\n", callid_prefix.len,
callid_prefix.s);
return 0;
}

Expand All @@ -110,29 +113,28 @@ int init_callid(void)
* \param rank not used
* \return 0 on success, -1 on error
*/
int child_init_callid(int rank)
int child_init_callid(int rank)
{
struct socket_info *si;

/* on tcp/tls bind_address is 0 so try to get the first address we listen
* on no matter the protocol */
si=bind_address?bind_address:get_first_socket();
if (si==0){
LOG(L_CRIT, "BUG: child_init_callid: null socket list\n");
si = bind_address ? bind_address : get_first_socket();
if(si == 0) {
LM_CRIT("null socket list\n");
return -1;
}
callid_suffix.s = callid_buf + callid_prefix.len;

callid_suffix.len = snprintf(callid_suffix.s, CALLID_SUFFIX_LEN,
"%c%d@%.*s", '-', my_pid(),
si->address_str.len,
si->address_str.s);
if ((callid_suffix.len == -1) || (callid_suffix.len > CALLID_SUFFIX_LEN)) {
LOG(L_ERR, "ERROR: child_init_callid: buffer too small\n");
"%c%d@%.*s", '-', my_pid(), si->address_str.len, si->address_str.s);
if((callid_suffix.len == -1) || (callid_suffix.len > CALLID_SUFFIX_LEN)) {
LM_ERR("buffer too small\n");
return -1;
}

DBG("DEBUG: callid: '%.*s'\n", callid_prefix.len + callid_suffix.len, callid_prefix.s);
LM_DBG("callid: '%.*s'\n", callid_prefix.len + callid_suffix.len,
callid_prefix.s);
return 0;
}

Expand All @@ -142,14 +144,14 @@ int child_init_callid(int rank)
* \param _c input character
* \return carry flag
*/
static inline int inc_hexchar(char* _c)
static inline int inc_hexchar(char *_c)
{
if (*_c == '9') {
if(*_c == '9') {
*_c = 'a';
return 0;
}

if (*_c == 'f') {
if(*_c == 'f') {
*_c = '0';
return 1;
}
Expand All @@ -163,12 +165,13 @@ static inline int inc_hexchar(char* _c)
* \brief Get a unique Call-ID
* \param callid returned Call-ID
*/
void tm_generate_callid(str* callid)
void tm_generate_callid(str *callid)
{
int i;

for(i = callid_prefix.len; i; i--) {
if (!inc_hexchar(callid_prefix.s + i - 1)) break;
if(!inc_hexchar(callid_prefix.s + i - 1))
break;
}
callid->s = callid_prefix.s;
callid->len = callid_prefix.len + callid_suffix.len;
Expand All @@ -178,10 +181,10 @@ void tm_generate_callid(str* callid)
* \brief Wrapper to get a unique Call-ID based on tm or core callback
* \param callid returned Call-ID
*/
void generate_callid(str* callid)
void generate_callid(str *callid)
{
sr_generate_callid_f cf;
if((cf=sr_get_callid_func())!=NULL) {
if((cf = sr_get_callid_func()) != NULL) {
cf(callid);
} else {
tm_generate_callid(callid);
Expand Down
13 changes: 5 additions & 8 deletions src/modules/tm/callid.h
Expand Up @@ -13,17 +13,14 @@
* 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
* 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
*
* History:
* ----------
* 2003-04-09 Created by janakj
*/

/*!
* \file
* \file
* \brief TM :: Fast Call-ID generator
* \ingroup tm
*/
Expand Down Expand Up @@ -53,14 +50,14 @@ int child_init_callid(int rank);
/**
* \brief TM API export
*/
typedef void (*generate_callid_f)(str*);
typedef void (*generate_callid_f)(str *);


/**
* \brief Get a unique Call-ID
* \param callid returned Call-ID
*/
void generate_callid(str* callid);
void generate_callid(str *callid);


#endif /* CALLID_H */
14 changes: 7 additions & 7 deletions src/modules/tm/config.h
Expand Up @@ -13,8 +13,8 @@
* 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
* 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
*/

Expand All @@ -31,10 +31,10 @@

/* this is where table size is defined now -- sort of
ugly, core should not be bothered by TM table size,
but on the other, core's stateless forwarding should
but on the other, core's stateless forwarding should
have consistent branch generation with stateful mode
and needs to calculate branch/hash, for which table size
is needed
is needed
*/
#include "../../core/hash_func.h"

Expand All @@ -59,15 +59,15 @@
/* DELETE timer ... tells how long should the transaction persist in memory
after it was removed from the hash table and before it will be deleted */
#define DEL_TIME_OUT 200 /* ms, obsoleted */

/* retransmission timers */
#define RETR_T1 500 /* ms */
#define RETR_T2 4000 /* ms */

/* maximum total lifetime for an INVITE or non-INVITE transaction
* Note: after this time the transaction will not be deleted
* immediately, but forced to go in the wait state or in wait for ack state
* and then wait state, so it will still be alive for either WT_TIME_OUT in
* immediately, but forced to go in the wait state or in wait for ack state
* and then wait state, so it will still be alive for either WT_TIME_OUT in
* the non-inv or "silent" inv. case and for FR_TIME_OUT + WT_TIME_OUT for an
* invite transaction (for which we must wait for the neg. reply ack)*/
#define MAX_INV_LIFETIME 180000 /* ms, rfc min. C-timer value */
Expand Down
6 changes: 3 additions & 3 deletions src/modules/tm/defs.h
Expand Up @@ -14,14 +14,14 @@
* 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
* 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
*
*/

/*!
* \file
* \file
* \brief TM :: Definitions
* \ingroup tm
*/
Expand Down

0 comments on commit 11f9a91

Please sign in to comment.