From 6ea356e2ef09ce0c9e27e12ba63bc191d648a9bb Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 17 May 2023 16:37:13 +0200 Subject: [PATCH] siptrace: clang-format for coherent indentation and coding style --- src/modules/siptrace/siptrace.c | 608 +++++++++++++++------------ src/modules/siptrace/siptrace_data.h | 22 +- src/modules/siptrace/siptrace_hep.c | 22 +- src/modules/siptrace/siptrace_send.c | 50 ++- src/modules/siptrace/siptrace_send.h | 62 +-- 5 files changed, 416 insertions(+), 348 deletions(-) diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c index 538e3b6a70b..1c129762314 100644 --- a/src/modules/siptrace/siptrace.c +++ b/src/modules/siptrace/siptrace.c @@ -62,17 +62,15 @@ MODULE_VERSION #define SIPTRACE_MODE_NONE 0 #define SIPTRACE_MODE_HEP (1) -#define SIPTRACE_MODE_DB (1<<1) -#define SIPTRACE_MODE_URI (1<<2) +#define SIPTRACE_MODE_DB (1 << 1) +#define SIPTRACE_MODE_URI (1 << 2) #define SIPTRACE_ANYADDR "any:255.255.255.255:5060" #define SIPTRACE_ANYADDR_LEN (sizeof(SIPTRACE_ANYADDR) - 1) -#define trace_is_off(_msg) \ - (((_msg)->msg_flags & FL_SIPTRACE) == 0) +#define trace_is_off(_msg) (((_msg)->msg_flags & FL_SIPTRACE) == 0) -#define is_null_pv(_str) \ - (!str_strcmp(&_str, pv_get_null_str())) +#define is_null_pv(_str) (!str_strcmp(&_str, pv_get_null_str())) struct tm_binds tmb; struct dlg_binds dlgb; @@ -89,15 +87,16 @@ static int sip_trace(sip_msg_t *msg, dest_info_t *, str *, char *); static int w_sip_trace0(struct sip_msg *, char *p1, char *p2); static int w_sip_trace1(struct sip_msg *, char *dest, char *p2); static int w_sip_trace2(struct sip_msg *, char *dest, char *correlation_id); -static int w_sip_trace3(struct sip_msg *, char *dest, char *correlation_id, char *trace_type); +static int w_sip_trace3( + struct sip_msg *, char *dest, char *correlation_id, char *trace_type); static int w_sip_trace_msg(sip_msg_t *msg, char *vmsg, char *saddr, char *taddr, char *duri, char *corrid); static int fixup_siptrace(void **param, int param_no); static int fixup_free_siptrace(void **param, int param_no); static int w_sip_trace_mode(sip_msg_t *msg, char *pmode, char *p2); -static int siptrace_parse_uri(str* duri, dest_info_t* dst); -static enum siptrace_type_t siptrace_parse_flag(str* sflags); +static int siptrace_parse_uri(str *duri, dest_info_t *dst); +static enum siptrace_type_t siptrace_parse_flag(str *sflags); static int w_hlog1(struct sip_msg *, char *message, char *); static int w_hlog2(struct sip_msg *, char *correlationid, char *message); @@ -108,17 +107,21 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps); static void trace_cancel_in(struct cell *t, int type, struct tmcb_params *ps); static void trace_onreply_in(struct cell *t, int type, struct tmcb_params *ps); static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps); -static void trace_tm_neg_ack_in(struct cell *t, int type, struct tmcb_params *ps); +static void trace_tm_neg_ack_in( + struct cell *t, int type, struct tmcb_params *ps); static void trace_sl_onreply_out(sl_cbp_t *slcb); static void trace_sl_ack_in(sl_cbp_t *slcb); -static void trace_transaction(sip_msg_t* msg, siptrace_info_t* info, int dlg_tran); -static void trace_dialog(struct dlg_cell* dlg, int type, struct dlg_cb_params *params); -static void trace_dialog_transaction(struct dlg_cell* dlg, int type, struct dlg_cb_params *params); -static void trace_free_info(void* trace_info); -static int trace_add_info_xavp(siptrace_info_t* info); -static inline int trace_parse_raw_uri(siptrace_info_t* info); +static void trace_transaction( + sip_msg_t *msg, siptrace_info_t *info, int dlg_tran); +static void trace_dialog( + struct dlg_cell *dlg, int type, struct dlg_cb_params *params); +static void trace_dialog_transaction( + struct dlg_cell *dlg, int type, struct dlg_cb_params *params); +static void trace_free_info(void *trace_info); +static int trace_add_info_xavp(siptrace_info_t *info); +static inline int trace_parse_raw_uri(siptrace_info_t *info); int siptrace_net_data_recv(sr_event_param_t *evp); int siptrace_net_data_sent(sr_event_param_t *evp); @@ -195,15 +198,14 @@ static str trace_table_avp_str = {NULL, 0}; static str trace_local_ip = {NULL, 0}; static db1_con_t *db_con = NULL; /*!< database connection */ -static db_func_t db_funcs; /*!< Database functions */ +static db_func_t db_funcs; /*!< Database functions */ int trace_dialog_ack = 1; int trace_dialog_spiral = 1; static int spiral_tracked; int pv_parse_siptrace_name(pv_spec_t *sp, str *in); -int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param, - pv_value_t *res); +int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param, pv_value_t *res); /*! \brief * Exported functions @@ -292,11 +294,10 @@ stat_export_t siptrace_stats[] = { static pv_export_t mod_pvs[] = { - { {"siptrace", (sizeof("siptrace")-1)}, PVT_OTHER, pv_get_siptrace, 0, - pv_parse_siptrace_name, 0, 0, 0 }, + {{"siptrace", (sizeof("siptrace") - 1)}, PVT_OTHER, pv_get_siptrace, 0, + pv_parse_siptrace_name, 0, 0, 0}, - { {0, 0}, 0, 0, 0, 0, 0, 0, 0 } -}; + {{0, 0}, 0, 0, 0, 0, 0, 0, 0}}; /*! \brief module exports */ /* clang-format off */ @@ -331,7 +332,7 @@ static int mod_init(void) _siptrace_evrt_msg_idx = route_lookup(&event_rt, "siptrace:msg"); - if(trace_db_delayed!=0) { + if(trace_db_delayed != 0) { trace_db_mode = 1; } @@ -360,19 +361,20 @@ static int mod_init(void) } if(!DB_CAPABILITY(db_funcs, DB_CAP_INSERT)) { LM_ERR("database modules does not provide all functions needed" - " by module\n"); + " by module\n"); return -1; } } if(trace_dup_uri_str.s != 0) { - trace_dup_uri = (sip_uri_t*)pkg_malloc(sizeof(sip_uri_t)); + trace_dup_uri = (sip_uri_t *)pkg_malloc(sizeof(sip_uri_t)); if(trace_dup_uri == 0) { LM_ERR("no more pkg memory left\n"); return -1; } memset(trace_dup_uri, 0, sizeof(sip_uri_t)); - if(parse_uri(trace_dup_uri_str.s, trace_dup_uri_str.len, trace_dup_uri) < 0) { + if(parse_uri(trace_dup_uri_str.s, trace_dup_uri_str.len, trace_dup_uri) + < 0) { LM_ERR("bad duplicate_uri\n"); return -1; } @@ -385,19 +387,20 @@ static int mod_init(void) } if(trace_send_sock_name_str.s != 0) { - trace_send_sock_info = ksr_get_socket_by_name(&trace_send_sock_name_str); + trace_send_sock_info = + ksr_get_socket_by_name(&trace_send_sock_name_str); trace_send_sock_str.s = NULL; trace_send_sock_str.len = 0; } else if(trace_send_sock_str.s != 0) { trace_send_sock_str.len = strlen(trace_send_sock_str.s); - trace_send_sock_uri = (sip_uri_t*)pkg_malloc(sizeof(sip_uri_t)); + trace_send_sock_uri = (sip_uri_t *)pkg_malloc(sizeof(sip_uri_t)); if(trace_send_sock_uri == 0) { LM_ERR("no more pkg memory left\n"); return -1; } memset(trace_send_sock_uri, 0, sizeof(sip_uri_t)); if(parse_uri(trace_send_sock_str.s, trace_send_sock_str.len, - trace_send_sock_uri) + trace_send_sock_uri) < 0) { LM_ERR("bad send sock address\n"); return -1; @@ -409,13 +412,12 @@ static int mod_init(void) trace_send_sock_uri->port_no = SIP_PORT; } trace_send_sock_info = grep_sock_info(&trace_send_sock_uri->host, - trace_send_sock_uri->port_no, - trace_send_sock_uri->proto); + trace_send_sock_uri->port_no, trace_send_sock_uri->proto); } - if(_siptrace_init_mode==SIPTRACE_INIT_MODE_ALL - || _siptrace_init_mode==SIPTRACE_INIT_MODE_SCRIPT) { - if(trace_flag_param!=-1) { + if(_siptrace_init_mode == SIPTRACE_INIT_MODE_ALL + || _siptrace_init_mode == SIPTRACE_INIT_MODE_SCRIPT) { + if(trace_flag_param != -1) { if(trace_flag_param < -1 || trace_flag_param > (int)MAX_FLAG) { LM_ERR("invalid trace flag %d\n", trace_flag_param); return -1; @@ -428,11 +430,14 @@ static int mod_init(void) LM_WARN("can't load tm api. Will not install tm callbacks.\n"); } - if (load_dlg_api(&dlgb) < 0) { + if(load_dlg_api(&dlgb) < 0) { LM_INFO("can't load dlg api. Will not install dialog callbacks.\n"); } else { - if (dlgb.register_dlgcb(NULL, DLGCB_CREATED, trace_dialog, NULL, NULL) != 0) { - LM_ERR("failed to register dialog callbacks! Tracing dialogs won't be available\n"); + if(dlgb.register_dlgcb( + NULL, DLGCB_CREATED, trace_dialog, NULL, NULL) + != 0) { + LM_ERR("failed to register dialog callbacks! Tracing dialogs " + "won't be available\n"); } } @@ -467,11 +472,11 @@ static int mod_init(void) return -1; } - if(pv_get_avp_name( - 0, &avp_spec.pvp, &traced_user_avp, &traced_user_avp_type) + if(pv_get_avp_name(0, &avp_spec.pvp, &traced_user_avp, + &traced_user_avp_type) != 0) { - LM_ERR("[%.*s] - invalid AVP definition\n", traced_user_avp_str.len, - traced_user_avp_str.s); + LM_ERR("[%.*s] - invalid AVP definition\n", + traced_user_avp_str.len, traced_user_avp_str.s); return -1; } } else { @@ -486,11 +491,11 @@ static int mod_init(void) return -1; } - if(pv_get_avp_name( - 0, &avp_spec.pvp, &trace_table_avp, &trace_table_avp_type) + if(pv_get_avp_name(0, &avp_spec.pvp, &trace_table_avp, + &trace_table_avp_type) != 0) { - LM_ERR("[%.*s] - invalid AVP definition\n", trace_table_avp_str.len, - trace_table_avp_str.s); + LM_ERR("[%.*s] - invalid AVP definition\n", + trace_table_avp_str.len, trace_table_avp_str.s); return -1; } } else { @@ -499,12 +504,12 @@ static int mod_init(void) } } - if(_siptrace_init_mode==SIPTRACE_INIT_MODE_ALL - || _siptrace_init_mode==SIPTRACE_INIT_MODE_CORECB) { + if(_siptrace_init_mode == SIPTRACE_INIT_MODE_ALL + || _siptrace_init_mode == SIPTRACE_INIT_MODE_CORECB) { if(_siptrace_mode != SIPTRACE_MODE_NONE) { sr_event_register_cb(SREV_NET_DATA_RECV, siptrace_net_data_recv); sr_event_register_cb(SREV_NET_DATA_SENT, siptrace_net_data_sent); - } else if(_siptrace_init_mode==SIPTRACE_INIT_MODE_CORECB) { + } else if(_siptrace_init_mode == SIPTRACE_INIT_MODE_CORECB) { LM_ERR("invalid config options for core callbacks tracing\n"); return -1; } @@ -522,13 +527,13 @@ static int child_init(int rank) db_con = db_funcs.init(&db_url); if(!db_con) { LM_ERR("unable to connect to database. Please check " - "configuration.\n"); + "configuration.\n"); return -1; } if(DB_CAPABILITY(db_funcs, DB_CAP_QUERY)) { - if(db_check_table_version( - &db_funcs, db_con, &siptrace_table, SIP_TRACE_TABLE_VERSION) - < 0) { + if(db_check_table_version(&db_funcs, db_con, &siptrace_table, + SIP_TRACE_TABLE_VERSION) + < 0) { DB_TABLE_VERSION_ERROR(siptrace_table); db_funcs.close(db_con); db_con = 0; @@ -567,8 +572,8 @@ static inline str *siptrace_get_table(void) return &avp_value.s; } -static int sip_trace_store(siptrace_data_t *sto, dest_info_t *dst, - str *correlation_id_str) +static int sip_trace_store( + siptrace_data_t *sto, dest_info_t *dst, str *correlation_id_str) { int ret = 1; @@ -603,8 +608,8 @@ static int sip_trace_store(siptrace_data_t *sto, dest_info_t *dst, return ret; } -static int sip_trace_insert_db(db_key_t *db_keys, db_val_t *db_vals, - int db_nkeys, char *dtext) +static int sip_trace_insert_db( + db_key_t *db_keys, db_val_t *db_vals, int db_nkeys, char *dtext) { LM_DBG("storing info - %s\n", dtext); if(trace_db_mode == 2 && db_funcs.insert_async != NULL) { @@ -738,34 +743,34 @@ static int sip_trace_store_db(siptrace_data_t *sto) return -1; } -enum siptrace_type_t siptrace_parse_flag(str* sflags) +enum siptrace_type_t siptrace_parse_flag(str *sflags) { int idx; enum siptrace_type_t trace_type = SIPTRACE_NONE; - if (sflags == NULL || sflags->s == NULL || sflags->len == 0) { + if(sflags == NULL || sflags->s == NULL || sflags->len == 0) { return SIPTRACE_NONE; } - for (idx = 0; idx < sflags->len; idx++) { - switch(sflags->s[idx]|0x20) { /*|0x20 - to lowercase */ + for(idx = 0; idx < sflags->len; idx++) { + switch(sflags->s[idx] | 0x20) { /*|0x20 - to lowercase */ case SIPTRACE_MESSAGE: case SIPTRACE_TRANSACTION: case SIPTRACE_DIALOG: - if (trace_type != SIPTRACE_NONE) { + if(trace_type != SIPTRACE_NONE) { LM_ERR("only one tracing flag can be used <%.*s>!\n", sflags->len, sflags->s); return SIPTRACE_NONE; } - trace_type = (sflags->s[idx]|0x20); + trace_type = (sflags->s[idx] | 0x20); break; case ' ': case '\t': break; default: - LM_ERR("Invalid character <%c> in <%.*s> at position <%d>!\n", sflags->s[idx], - sflags->len, sflags->s, idx); + LM_ERR("Invalid character <%c> in <%.*s> at position <%d>!\n", + sflags->s[idx], sflags->len, sflags->s, idx); return SIPTRACE_NONE; } } @@ -783,22 +788,22 @@ static int fixup_siptrace(void **param, int param_no) return 0; } - if (param_no == 1 || param_no == 2 || param_no == 4) { + if(param_no == 1 || param_no == 2 || param_no == 4) { /* correlation id */ return fixup_spve_all(param, param_no); - } else if (param_no == 3) { + } else if(param_no == 3) { /* tracing type; string only */ sflags.s = (char *)*param; sflags.len = strlen(sflags.s); trace_type = siptrace_parse_flag(&sflags); - if (trace_type == SIPTRACE_NONE) { + if(trace_type == SIPTRACE_NONE) { LM_ERR("Failed to parse trace type!\n"); return -1; } *param = pkg_malloc(sizeof(trace_type)); - if (*param == NULL) { + if(*param == NULL) { LM_ERR("no more pkg memory!\n"); return -1; } @@ -810,12 +815,13 @@ static int fixup_siptrace(void **param, int param_no) static int fixup_free_siptrace(void **param, int param_no) { - if (param_no == 1 || param_no == 2 || param_no == 4) { + if(param_no == 1 || param_no == 2 || param_no == 4) { /* correlation id */ return fixup_free_spve_all(param, param_no); - } if (param_no == 3) { + } + if(param_no == 3) { /* tracing type; string only */ - if (*param) { + if(*param) { pkg_free(*param); } } @@ -831,17 +837,17 @@ static int fixup_free_siptrace(void **param, int param_no) * */ -static int siptrace_parse_uri(str* duri, dest_info_t* dst) +static int siptrace_parse_uri(str *duri, dest_info_t *dst) { sip_uri_t uri; proxy_l_t *p = NULL; - if (dst == NULL) { + if(dst == NULL) { LM_ERR("bad destination!\n"); return -1; } - if (duri == NULL || duri->len <= 0) { + if(duri == NULL || duri->len <= 0) { if(trace_dup_uri) { uri = *trace_dup_uri; } else { @@ -889,13 +895,13 @@ static int siptrace_parse_uri(str* duri, dest_info_t* dst) static int sip_trace_helper(sip_msg_t *msg, dest_info_t *dst, str *duri, str *corid, char *dir, enum siptrace_type_t trace_type) { - siptrace_info_t* info = NULL; + siptrace_info_t *info = NULL; struct cell *t_invite, *orig_t; char *p = NULL; int canceled; int ret = 0; - if (trace_type == SIPTRACE_TRANSACTION || trace_type == SIPTRACE_DIALOG) { + if(trace_type == SIPTRACE_TRANSACTION || trace_type == SIPTRACE_DIALOG) { int alloc_size = sizeof(siptrace_info_t); /* @@ -904,18 +910,18 @@ static int sip_trace_helper(sip_msg_t *msg, dest_info_t *dst, str *duri, * dialog: it's an INVITE; dialog module is loaded * * */ - if (tmb.t_gett == NULL) { + if(tmb.t_gett == NULL) { LM_WARN("TM module not loaded! Tracing only current message!\n"); goto trace_current; } - /* if sip_trace is called over an incoming CANCEL, skip + /* if sip_trace is called over an incoming CANCEL, skip * capturing it if the cancelled transaction is already being traced */ - if (msg->REQ_METHOD==METHOD_CANCEL) { - t_invite=tmb.t_lookup_original(msg); - if (t_invite!=T_NULL_CELL) { - if (t_invite->uas.request->msg_flags & FL_SIPTRACE) { + if(msg->REQ_METHOD == METHOD_CANCEL) { + t_invite = tmb.t_lookup_original(msg); + if(t_invite != T_NULL_CELL) { + if(t_invite->uas.request->msg_flags & FL_SIPTRACE) { LM_DBG("Transaction is already been traced, skipping.\n"); tmb.t_unref(msg); return 1; @@ -928,48 +934,54 @@ static int sip_trace_helper(sip_msg_t *msg, dest_info_t *dst, str *duri, * capturing it if it's an ACK for a negative reply for * an already traced transaction */ - if (msg->REQ_METHOD==METHOD_ACK) { + if(msg->REQ_METHOD == METHOD_ACK) { orig_t = tmb.t_gett(); - if(tmb.t_lookup_request(msg,0,&canceled)) { + if(tmb.t_lookup_request(msg, 0, &canceled)) { t_invite = tmb.t_gett(); - if (t_invite!=T_NULL_CELL) { - if (t_invite->uas.request->msg_flags & FL_SIPTRACE) { - LM_DBG("Transaction is already been traced, skipping.\n"); + if(t_invite != T_NULL_CELL) { + if(t_invite->uas.request->msg_flags & FL_SIPTRACE) { + LM_DBG("Transaction is already been traced, " + "skipping.\n"); ret = 1; } - tmb.t_release_transaction( t_invite ); + tmb.t_release_transaction(t_invite); tmb.t_unref(msg); } } tmb.t_sett(orig_t, T_BR_UNDEFINED); - if (ret) + if(ret) return 1; } - if (trace_type == SIPTRACE_DIALOG && dlgb.get_dlg == NULL) { - LM_WARN("DIALOG module not loaded! Tracing only current message!\n"); + if(trace_type == SIPTRACE_DIALOG && dlgb.get_dlg == NULL) { + LM_WARN("DIALOG module not loaded! Tracing only current " + "message!\n"); goto trace_current; } - if (msg->first_line.type != SIP_REQUEST || - (trace_type == SIPTRACE_DIALOG - && msg->first_line.u.request.method_value != METHOD_INVITE)) { - LM_WARN("When tracing a %s sip_trace() has to be initiated on the %s\n", - trace_type == SIPTRACE_TRANSACTION ? "transaction" : "dialog", - trace_type == SIPTRACE_TRANSACTION ? "request message" : "initial invite"); + if(msg->first_line.type != SIP_REQUEST + || (trace_type == SIPTRACE_DIALOG + && msg->first_line.u.request.method_value + != METHOD_INVITE)) { + LM_WARN("When tracing a %s sip_trace() has to be initiated on the " + "%s\n", + trace_type == SIPTRACE_TRANSACTION ? "transaction" + : "dialog", + trace_type == SIPTRACE_TRANSACTION ? "request message" + : "initial invite"); return -1; } - if (corid) { + if(corid) { alloc_size += corid->len; } - if (duri) { + if(duri) { alloc_size += duri->len; } info = shm_malloc(alloc_size); - if (info == NULL) { + if(info == NULL) { LM_ERR("No more shm!\n"); return -1; } @@ -984,28 +996,32 @@ static int sip_trace_helper(sip_msg_t *msg, dest_info_t *dst, str *duri, info->correlation_id.len = corid->len; memcpy(info->correlation_id.s, corid->s, corid->len); } - if (duri) { + if(duri) { info->uriState = STRACE_RAW_URI; - info->u.dup_uri.s = p + ((info->correlation_id.s)?info->correlation_id.len:0); + info->u.dup_uri.s = + p + + ((info->correlation_id.s) ? info->correlation_id.len : 0); memcpy(info->u.dup_uri.s, duri->s, duri->len); info->u.dup_uri.len = duri->len; } else { info->uriState = STRACE_UNUSED_URI; } - if (trace_type == SIPTRACE_TRANSACTION) { + if(trace_type == SIPTRACE_TRANSACTION) { trace_transaction(msg, info, 0); - } else if (trace_type == SIPTRACE_DIALOG) { - if (unlikely(dlgb.set_dlg_var == NULL)) { + } else if(trace_type == SIPTRACE_DIALOG) { + if(unlikely(dlgb.set_dlg_var == NULL)) { /* FIXME should we abort tracing here? */ - LM_WARN("Dialog api not loaded! will trace only current transaction!\n"); + LM_WARN("Dialog api not loaded! will trace only current " + "transaction!\n"); } else { /* serialize what's in info */ /* save correlation id in siptrace_info avp * we want to have traced user avp value at the moment * of sip_trace function call */ - if (trace_add_info_xavp(info) < 0) { - LM_ERR("failed to serialize siptrace info! Won't trace dialog!\n"); + if(trace_add_info_xavp(info) < 0) { + LM_ERR("failed to serialize siptrace info! Won't trace " + "dialog!\n"); return -1; } else { msg->msg_flags |= FL_SIPTRACE; @@ -1035,28 +1051,30 @@ static int sip_trace_helper(sip_msg_t *msg, dest_info_t *dst, str *duri, * Send sip trace with destination and correlation id * and specify what messages to be traced */ -static int ki_sip_trace_dst_cid_flag(sip_msg_t *msg, str *duri, str *cid, str* sflag) +static int ki_sip_trace_dst_cid_flag( + sip_msg_t *msg, str *duri, str *cid, str *sflag) { dest_info_t dst; enum siptrace_type_t trace_type; if(duri) { - if (siptrace_parse_uri(duri, &dst) < 0) { + if(siptrace_parse_uri(duri, &dst) < 0) { LM_ERR("failed to parse siptrace uri!\n"); return -1; } } - if (sflag) { + if(sflag) { trace_type = siptrace_parse_flag(sflag); - if (trace_type == SIPTRACE_NONE) { + if(trace_type == SIPTRACE_NONE) { LM_ERR("Invalid flags <%.*s>\n", sflag->len, sflag->s); } } else { trace_type = SIPTRACE_MESSAGE; } - return sip_trace_helper(msg, (duri)?&dst:NULL, duri, cid, NULL, trace_type); + return sip_trace_helper( + msg, (duri) ? &dst : NULL, duri, cid, NULL, trace_type); } /** @@ -1108,7 +1126,8 @@ static int w_sip_trace2(sip_msg_t *msg, char *dest, char *correlation_id) } -static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char *trace_type_p) +static int w_sip_trace3( + sip_msg_t *msg, char *dest, char *correlation_id, char *trace_type_p) { str dup_uri_param_str = {0, 0}; str correlation_id_str = {0, 0}; @@ -1116,17 +1135,19 @@ static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char * enum siptrace_type_t trace_type; /* to support tracing to database without destination parameter - old mode */ - if (dest || trace_to_database == 0) { - if (dest) { - if(fixup_get_svalue(msg, (gparam_t *)dest, &dup_uri_param_str) != 0) { + if(dest || trace_to_database == 0) { + if(dest) { + if(fixup_get_svalue(msg, (gparam_t *)dest, &dup_uri_param_str) + != 0) { LM_ERR("unable to parse the dest URI string\n"); return -1; } } - if (dup_uri_param_str.s == 0 || (is_null_pv(dup_uri_param_str))) { - if (trace_dup_uri_str.s == 0 || trace_dup_uri_str.len == 0) { - LM_ERR("no duplicate_uri modparam nor duplicate uri sip_trace() argument provided!\n"); + if(dup_uri_param_str.s == 0 || (is_null_pv(dup_uri_param_str))) { + if(trace_dup_uri_str.s == 0 || trace_dup_uri_str.len == 0) { + LM_ERR("no duplicate_uri modparam nor duplicate uri " + "sip_trace() argument provided!\n"); return -1; } @@ -1134,7 +1155,7 @@ static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char * } /* if arg dest uri is null dup_uri_param_str will have length 0 and global dup_uri will be used */ - if (siptrace_parse_uri(&dup_uri_param_str, &dest_info) < 0) { + if(siptrace_parse_uri(&dup_uri_param_str, &dest_info) < 0) { LM_ERR("failed to parse uri!\n"); return -1; } @@ -1142,15 +1163,16 @@ static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char * memset(&dest_info, 0, sizeof(dest_info_t)); } - if (correlation_id) { - if(fixup_get_svalue(msg, (gparam_t *)correlation_id, &correlation_id_str) + if(correlation_id) { + if(fixup_get_svalue( + msg, (gparam_t *)correlation_id, &correlation_id_str) != 0) { LM_ERR("unable to parse the correlation id\n"); return -1; } } - if (trace_type_p != NULL) { + if(trace_type_p != NULL) { trace_type = *(enum siptrace_type_t *)(trace_type_p); } else { /* fallback to default - transaction tracking when flag is set, @@ -1162,9 +1184,9 @@ static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char * } } - return sip_trace_helper(msg, (dest)?&dest_info:NULL, - (dest)?&dup_uri_param_str:NULL, - (correlation_id)?&correlation_id_str:NULL, NULL, trace_type); + return sip_trace_helper(msg, (dest) ? &dest_info : NULL, + (dest) ? &dup_uri_param_str : NULL, + (correlation_id) ? &correlation_id_str : NULL, NULL, trace_type); } /** @@ -1180,47 +1202,48 @@ static int w_sip_trace_msg(sip_msg_t *msg, char *vmsg, char *saddr, char *taddr, str corrid_str = {0, 0}; dest_info_t dest; - if(fixup_get_svalue(msg, (gparam_t*)vmsg, &vmsg_str) != 0) { + if(fixup_get_svalue(msg, (gparam_t *)vmsg, &vmsg_str) != 0) { LM_ERR("unable to get the msg data parameter\n"); return -1; } - if(vmsg_str.s==NULL || vmsg_str.len<=0) { + if(vmsg_str.s == NULL || vmsg_str.len <= 0) { LM_ERR("invalid msg data parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)saddr, &saddr_str) != 0) { + if(fixup_get_svalue(msg, (gparam_t *)saddr, &saddr_str) != 0) { LM_ERR("unable to get the msg source address parameter\n"); return -1; } - if(saddr_str.s==NULL || saddr_str.len<=0) { + if(saddr_str.s == NULL || saddr_str.len <= 0) { LM_ERR("invalid msg source address parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)taddr, &taddr_str) != 0) { + if(fixup_get_svalue(msg, (gparam_t *)taddr, &taddr_str) != 0) { LM_ERR("unable to get the msg target address parameter\n"); return -1; } - if(taddr_str.s==NULL || taddr_str.len<=0) { + if(taddr_str.s == NULL || taddr_str.len <= 0) { LM_ERR("invalid msg target address parameter\n"); return -1; } - if(duri!=NULL) { - if(fixup_get_svalue(msg, (gparam_t*)duri, &duri_str) != 0) { + if(duri != NULL) { + if(fixup_get_svalue(msg, (gparam_t *)duri, &duri_str) != 0) { LM_ERR("unable to get mirroring destination uri parameter\n"); return -1; } - if (siptrace_parse_uri(&duri_str, &dest) < 0) { + if(siptrace_parse_uri(&duri_str, &dest) < 0) { LM_ERR("failed to parse mirroring destination uri\n"); return -1; } } - if(corrid!=NULL && fixup_get_svalue(msg, (gparam_t*)corrid, &corrid_str) != 0) { + if(corrid != NULL + && fixup_get_svalue(msg, (gparam_t *)corrid, &corrid_str) != 0) { LM_ERR("unable to get correlation id parameter\n"); return -1; } - trace_send_hep_duplicate(&vmsg_str, &saddr_str, &taddr_str, (duri)?&dest:NULL, - (corrid)?&corrid_str:NULL); + trace_send_hep_duplicate(&vmsg_str, &saddr_str, &taddr_str, + (duri) ? &dest : NULL, (corrid) ? &corrid_str : NULL); return 1; } @@ -1232,14 +1255,15 @@ static int ki_sip_trace_msg(sip_msg_t *msg, str *vmsg, str *saddr, str *taddr, str *duri, str *corrid) { dest_info_t dest; - if(duri && duri->len>0) { - if (siptrace_parse_uri(duri, &dest) < 0) { + if(duri && duri->len > 0) { + if(siptrace_parse_uri(duri, &dest) < 0) { LM_ERR("failed to parse mirroring destination uri\n"); return -1; } } - trace_send_hep_duplicate(vmsg, saddr, taddr, (duri && duri->len>0)?&dest:NULL, - (corrid && corrid->len>0)?corrid:NULL); + trace_send_hep_duplicate(vmsg, saddr, taddr, + (duri && duri->len > 0) ? &dest : NULL, + (corrid && corrid->len > 0) ? corrid : NULL); return 1; } @@ -1265,11 +1289,10 @@ static int sip_trace_msg_attrs(sip_msg_t *msg, siptrace_data_t *sto) sto->totag = get_to(msg)->tag_value; return 0; - } -static int sip_trace(sip_msg_t *msg, dest_info_t *dst, - str *correlation_id_str, char *dir) +static int sip_trace( + sip_msg_t *msg, dest_info_t *dst, str *correlation_id_str, char *dir) { siptrace_data_t sto; onsend_info_t *snd_inf = NULL; @@ -1312,10 +1335,10 @@ static int sip_trace(sip_msg_t *msg, dest_info_t *dst, && strncmp(sto.dir, "out", 3) == 0) { sto.fromip = trace_local_ip; } else { - sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(msg->rcv.proto), + sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, + "%s:%s:%d", siptrace_proto_name(msg->rcv.proto), ip_addr2a(&msg->rcv.src_ip), (int)msg->rcv.src_port); - if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) { + if(sto.fromip.len < 0 || sto.fromip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.fromip.len); sto.fromip.s = SIPTRACE_ANYADDR; sto.fromip.len = SIPTRACE_ANYADDR_LEN; @@ -1328,10 +1351,10 @@ static int sip_trace(sip_msg_t *msg, dest_info_t *dst, && strncmp(sto.dir, "in", 2) == 0) { sto.toip = trace_local_ip; } else { - sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(msg->rcv.proto), ip_addr2a(&msg->rcv.dst_ip), - (int)msg->rcv.dst_port); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, + "%s:%s:%d", siptrace_proto_name(msg->rcv.proto), + ip_addr2a(&msg->rcv.dst_ip), (int)msg->rcv.dst_port); + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -1346,7 +1369,7 @@ static int sip_trace(sip_msg_t *msg, dest_info_t *dst, if(trace_local_ip.s && trace_local_ip.len > 0) { sto.fromip = trace_local_ip; } else { - if(snd_inf->send_sock->sock_str.len>=SIPTRACE_ADDR_MAX-1) { + if(snd_inf->send_sock->sock_str.len >= SIPTRACE_ADDR_MAX - 1) { LM_WARN("local socket address is too large\n"); sto.fromip.s = SIPTRACE_ANYADDR; sto.fromip.len = SIPTRACE_ANYADDR_LEN; @@ -1362,7 +1385,7 @@ static int sip_trace(sip_msg_t *msg, dest_info_t *dst, siptrace_proto_name(snd_inf->send_sock->proto), suip2a(snd_inf->to, sizeof(*snd_inf->to)), (int)su_getport(snd_inf->to)); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -1391,7 +1414,7 @@ static int ki_sip_trace_mode(sip_msg_t *msg, str *smode) { enum siptrace_type_t trace_type; - if(smode==NULL || smode->s==NULL || smode->len<=0) { + if(smode == NULL || smode->s == NULL || smode->len <= 0) { LM_INFO("no tracing mode - trace message\n"); trace_type = SIPTRACE_MESSAGE; } else { @@ -1399,15 +1422,15 @@ static int ki_sip_trace_mode(sip_msg_t *msg, str *smode) case 'M': case 'm': trace_type = SIPTRACE_MESSAGE; - break; + break; case 'T': case 't': trace_type = SIPTRACE_TRANSACTION; - break; + break; case 'D': case 'd': trace_type = SIPTRACE_DIALOG; - break; + break; default: trace_type = SIPTRACE_MESSAGE; LM_INFO("unexpected tracing mode [%.*s] - trace message\n", @@ -1424,7 +1447,7 @@ static int ki_sip_trace_mode(sip_msg_t *msg, str *smode) static int w_sip_trace_mode(sip_msg_t *msg, char *pmode, char *p2) { str smode = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)pmode, &smode)<0) { + if(fixup_get_svalue(msg, (gparam_t *)pmode, &smode) < 0) { LM_ERR("failed to get tracing mode parameter\n"); return -1; } @@ -1433,7 +1456,7 @@ static int w_sip_trace_mode(sip_msg_t *msg, char *pmode, char *p2) static void trace_cancel_in(struct cell *t, int type, struct tmcb_params *ps) { - siptrace_info_t* info; + siptrace_info_t *info; sip_msg_t *msg; if(t == NULL || ps == NULL) { @@ -1448,7 +1471,9 @@ static void trace_cancel_in(struct cell *t, int type, struct tmcb_params *ps) info = (siptrace_info_t *)(*ps->param); msg = ps->req; - if(tmb.register_tmcb(msg, 0, TMCB_RESPONSE_READY, trace_onreply_out, info, 0) <= 0) { + if(tmb.register_tmcb( + msg, 0, TMCB_RESPONSE_READY, trace_onreply_out, info, 0) + <= 0) { LM_ERR("can't register trace_onreply_out\n"); return; } @@ -1459,7 +1484,7 @@ static void trace_cancel_in(struct cell *t, int type, struct tmcb_params *ps) static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps) { siptrace_data_t sto; - siptrace_info_t* info; + siptrace_info_t *info; sip_msg_t *msg; ip_addr_t to_ip; dest_info_t *dst; @@ -1508,7 +1533,7 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps) } if(sip_trace_msg_attrs(msg, &sto) < 0) { - return; + return; } if(ps->send_buf.len > 0) { @@ -1546,10 +1571,10 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps) sto.fromip = trace_local_ip; } else { if(dst == 0 || dst->send_sock == 0 || dst->send_sock->sock_str.s == 0) { - sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(msg->rcv.proto), + sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, + "%s:%s:%d", siptrace_proto_name(msg->rcv.proto), ip_addr2a(&msg->rcv.dst_ip), (int)msg->rcv.dst_port); - if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) { + if(sto.fromip.len < 0 || sto.fromip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.fromip.len); sto.fromip.s = SIPTRACE_ANYADDR; sto.fromip.len = SIPTRACE_ANYADDR_LEN; @@ -1567,9 +1592,9 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps) } else { su2ip_addr(&to_ip, &dst->to); sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(dst->proto), - ip_addr2a(&to_ip), (int)su_getport(&dst->to)); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + siptrace_proto_name(dst->proto), ip_addr2a(&to_ip), + (int)su_getport(&dst->to)); + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -1583,7 +1608,7 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps) * case - incoming CANCEL transactions; they were not traced before; TMCB_E2ECANCEL_IN * will throw the incoming request through this function and the callback in the beginning * will make sure the reply for this cancel is caught */ - if (unlikely(type == TMCB_E2ECANCEL_IN)) { + if(unlikely(type == TMCB_E2ECANCEL_IN)) { sto.dir = "in"; } else { sto.dir = "out"; @@ -1593,19 +1618,22 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps) sto.stat = siptrace_req; #endif - if (info->uriState == STRACE_RAW_URI) { - LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! Message won't be traced!\n"); + if(info->uriState == STRACE_RAW_URI) { + LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! " + "Message won't be traced!\n"); return; } - sip_trace_store(&sto, info->uriState == STRACE_PARSED_URI ? &info->u.dest_info : NULL, NULL); + sip_trace_store(&sto, + info->uriState == STRACE_PARSED_URI ? &info->u.dest_info : NULL, + NULL); return; } static void trace_onreply_in(struct cell *t, int type, struct tmcb_params *ps) { siptrace_data_t sto; - siptrace_info_t* info; + siptrace_info_t *info; sip_msg_t *msg; sip_msg_t *req; char statusbuf[INT2STR_MAX_LEN]; @@ -1641,16 +1669,17 @@ static void trace_onreply_in(struct cell *t, int type, struct tmcb_params *ps) sto.body.s = msg->buf; sto.body.len = msg->len; - sto.status.s = int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len); + sto.status.s = + int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len); if(sto.status.s == 0) { LM_ERR("failure to get the status string\n"); return; } sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(msg->rcv.proto), - ip_addr2a(&msg->rcv.src_ip), (int)msg->rcv.src_port); - if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) { + siptrace_proto_name(msg->rcv.proto), ip_addr2a(&msg->rcv.src_ip), + (int)msg->rcv.src_port); + if(sto.fromip.len < 0 || sto.fromip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format fromip buffer (%d)\n", sto.fromip.len); sto.fromip.s = SIPTRACE_ANYADDR; sto.fromip.len = SIPTRACE_ANYADDR_LEN; @@ -1664,7 +1693,7 @@ static void trace_onreply_in(struct cell *t, int type, struct tmcb_params *ps) sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", siptrace_proto_name(msg->rcv.proto), ip_addr2a(&msg->rcv.dst_ip), (int)msg->rcv.dst_port); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -1679,20 +1708,22 @@ static void trace_onreply_in(struct cell *t, int type, struct tmcb_params *ps) sto.stat = siptrace_rpl; #endif - if (info->uriState == STRACE_RAW_URI) { - LM_BUG("uriState must be either UNUSED or PARSED here - skip tracing!\n"); + if(info->uriState == STRACE_RAW_URI) { + LM_BUG("uriState must be either UNUSED or PARSED here - skip " + "tracing!\n"); return; } - sip_trace_store(&sto, (info->uriState == STRACE_PARSED_URI) - ? &info->u.dest_info : NULL, NULL); + sip_trace_store(&sto, + (info->uriState == STRACE_PARSED_URI) ? &info->u.dest_info : NULL, + NULL); return; } static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps) { siptrace_data_t sto; - siptrace_info_t* info; + siptrace_info_t *info; int faked = 0; int parsed_f = 0; struct sip_msg *msg; @@ -1717,7 +1748,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps) /* can't(don't know) set FL_SIPTRACE flag from trace_onreq_out because * there no access to CANCEL transaction there */ - if (likely(type != TMCB_RESPONSE_READY)) { + if(likely(type != TMCB_RESPONSE_READY)) { if(traced_user_avp.n != 0) sto.avp = search_first_avp(traced_user_avp_type, traced_user_avp, &sto.avp_value, &sto.state); @@ -1736,7 +1767,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps) /* check if from header has been already parsed. * If not we have to parse it in pkg memory and free it at the end. */ - if (msg->from && msg->from->parsed == NULL) + if(msg->from && msg->from->parsed == NULL) parsed_f = 1; } @@ -1772,10 +1803,10 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps) if(trace_local_ip.s && trace_local_ip.len > 0) { sto.fromip = trace_local_ip; } else { - sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(msg->rcv.proto), + sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, + "%s:%s:%d", siptrace_proto_name(msg->rcv.proto), ip_addr2a(&req->rcv.dst_ip), (int)req->rcv.dst_port); - if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) { + if(sto.fromip.len < 0 || sto.fromip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format fromip buffer (%d)\n", sto.fromip.len); sto.fromip.s = SIPTRACE_ANYADDR; sto.fromip.len = SIPTRACE_ANYADDR_LEN; @@ -1784,7 +1815,8 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps) } } - sto.status.s = int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len); + sto.status.s = + int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len); if(sto.status.s == 0) { LM_ERR("failure to get the status string\n"); goto end; @@ -1798,9 +1830,9 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps) } else { su2ip_addr(&to_ip, &dst->to); sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(dst->proto), - ip_addr2a(&to_ip), (int)su_getport(&dst->to)); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + siptrace_proto_name(dst->proto), ip_addr2a(&to_ip), + (int)su_getport(&dst->to)); + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -1815,38 +1847,44 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps) sto.stat = siptrace_rpl; #endif - if (info->uriState == STRACE_RAW_URI) { - LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! Message won't be traced!\n"); + if(info->uriState == STRACE_RAW_URI) { + LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! " + "Message won't be traced!\n"); goto end; } - sip_trace_store(&sto, info->uriState == STRACE_PARSED_URI ? &info->u.dest_info : NULL, NULL); + sip_trace_store(&sto, + info->uriState == STRACE_PARSED_URI ? &info->u.dest_info : NULL, + NULL); end: - if (faked && parsed_f) { + if(faked && parsed_f) { free_from(msg->from->parsed); msg->from->parsed = NULL; } } -static void trace_tm_neg_ack_in(struct cell *t, int type, struct tmcb_params *ps) +static void trace_tm_neg_ack_in( + struct cell *t, int type, struct tmcb_params *ps) { - siptrace_info_t* info = (siptrace_info_t *)(*ps->param); + siptrace_info_t *info = (siptrace_info_t *)(*ps->param); LM_DBG("storing negative ack...\n"); /* this condition should not exist but there seems to be a BUG in kamailio * letting requests other than the ACK inside */ - if (ps->req->first_line.u.request.method_value != METHOD_ACK) { + if(ps->req->first_line.u.request.method_value != METHOD_ACK) { return; } - if (info->uriState == STRACE_RAW_URI) { - LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! Message won't be traced!\n"); + if(info->uriState == STRACE_RAW_URI) { + LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! " + "Message won't be traced!\n"); return; } - sip_trace(ps->req, (info->uriState == STRACE_PARSED_URI) ? &info->u.dest_info : NULL, + sip_trace(ps->req, + (info->uriState == STRACE_PARSED_URI) ? &info->u.dest_info : NULL, NULL, NULL); } @@ -1862,16 +1900,16 @@ static void trace_tm_neg_ack_in(struct cell *t, int type, struct tmcb_params *ps * params marked with * are optional * */ -static int trace_add_info_xavp(siptrace_info_t* info) +static int trace_add_info_xavp(siptrace_info_t *info) { sr_xval_t xval; - if (info == NULL) { + if(info == NULL) { LM_ERR("Nothing to serialize!\n"); return -1; } - if (info->uriState != STRACE_RAW_URI) { + if(info->uriState != STRACE_RAW_URI) { LM_BUG("URI should be in raw format here\n"); return -1; } @@ -1881,7 +1919,7 @@ static int trace_add_info_xavp(siptrace_info_t* info) xval.v.vptr = (void *)info; /* save data into avp */ - if (xavp_add_value(&trace_xavp_info_name_s, &xval, NULL) == NULL) { + if(xavp_add_value(&trace_xavp_info_name_s, &xval, NULL) == NULL) { shm_free(info); LM_ERR("Failed to add xavp!\n"); return -1; @@ -1890,22 +1928,22 @@ static int trace_add_info_xavp(siptrace_info_t* info) return 0; } -static inline int trace_parse_raw_uri(siptrace_info_t* info) +static inline int trace_parse_raw_uri(siptrace_info_t *info) { dest_info_t dest_info; - if (info == NULL) { + if(info == NULL) { LM_ERR("bad function call\n"); return -1; } - if (info->uriState != STRACE_RAW_URI) { + if(info->uriState != STRACE_RAW_URI) { LM_ERR("Invalid call! siptrace_info must contain a sip uri string!\n"); return -1; } /* parse uri and get dest_info structure */ - if (siptrace_parse_uri(&info->u.dup_uri, &dest_info) < 0) { + if(siptrace_parse_uri(&info->u.dup_uri, &dest_info) < 0) { LM_ERR("failed to parse uri!\n"); return -1; } @@ -1960,10 +1998,10 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp) if(trace_local_ip.len > 0) { sto.fromip = trace_local_ip; } else { - sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(req->rcv.proto), + sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, + "%s:%s:%d", siptrace_proto_name(req->rcv.proto), ip_addr2a(&req->rcv.dst_ip), req->rcv.dst_port); - if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) { + if(sto.fromip.len < 0 || sto.fromip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.fromip.len); sto.fromip.s = SIPTRACE_ANYADDR; sto.fromip.len = SIPTRACE_ANYADDR_LEN; @@ -1972,7 +2010,8 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp) } } - sto.status.s = int2strbuf(slcbp->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len); + sto.status.s = int2strbuf( + slcbp->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len); if(sto.status.s == 0) { LM_ERR("failure to get the status string\n"); return; @@ -1987,7 +2026,7 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp) sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", siptrace_proto_name(req->rcv.proto), ip_addr2a(&to_ip), (int)su_getport(&slcbp->dst->to)); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -2006,7 +2045,8 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp) return; } -static void trace_transaction(sip_msg_t* msg, siptrace_info_t* info, int dlg_tran) +static void trace_transaction( + sip_msg_t *msg, siptrace_info_t *info, int dlg_tran) { if(msg == NULL) { LM_DBG("nothing to trace\n"); @@ -2015,27 +2055,29 @@ static void trace_transaction(sip_msg_t* msg, siptrace_info_t* info, int dlg_tra /* trace current message on out */ msg->msg_flags |= FL_SIPTRACE; - if (info->uriState == STRACE_RAW_URI) { - if (trace_parse_raw_uri(info) < 0) { + if(info->uriState == STRACE_RAW_URI) { + if(trace_parse_raw_uri(info) < 0) { LM_ERR("failed to parse trace destination uri!\n"); return; } } - if(tmb.register_tmcb(msg, 0, TMCB_REQUEST_SENT, trace_onreq_out, info, 0) <= 0) { + if(tmb.register_tmcb(msg, 0, TMCB_REQUEST_SENT, trace_onreq_out, info, 0) + <= 0) { LM_ERR("can't register trace_onreq_out\n"); return; } /* trace reply on in */ - if(tmb.register_tmcb(msg, 0, TMCB_RESPONSE_IN, trace_onreply_in, info, 0) <= 0) { + if(tmb.register_tmcb(msg, 0, TMCB_RESPONSE_IN, trace_onreply_in, info, 0) + <= 0) { LM_ERR("can't register trace_onreply_in\n"); return; } /* trace reply on out */ if(tmb.register_tmcb(msg, 0, TMCB_RESPONSE_SENT, trace_onreply_out, info, - dlg_tran ? 0 : trace_free_info) + dlg_tran ? 0 : trace_free_info) <= 0) { LM_ERR("can't register trace_onreply_out\n"); return; @@ -2044,72 +2086,82 @@ static void trace_transaction(sip_msg_t* msg, siptrace_info_t* info, int dlg_tra /* TODO */ /* check the following callbacks: TMCB_REQUEST_PENDING, TMCB_RESPONSE_READY, TMCB_ACK_NEG_IN */ /* trace reply on in */ - if(tmb.register_tmcb(msg, 0, TMCB_ACK_NEG_IN, trace_tm_neg_ack_in, info, 0) <= 0) { + if(tmb.register_tmcb(msg, 0, TMCB_ACK_NEG_IN, trace_tm_neg_ack_in, info, 0) + <= 0) { LM_ERR("can't register trace_onreply_in\n"); return; } - if(tmb.register_tmcb(msg, 0, TMCB_E2ECANCEL_IN, trace_cancel_in, info, 0) <= 0) { + if(tmb.register_tmcb(msg, 0, TMCB_E2ECANCEL_IN, trace_cancel_in, info, 0) + <= 0) { LM_ERR("can't register trace_onreply_in\n"); return; } } //static void trace_dialog(sip_msg_t* msg, siptrace_info_t* info) -static void trace_dialog(struct dlg_cell* dlg, int type, struct dlg_cb_params *params) +static void trace_dialog( + struct dlg_cell *dlg, int type, struct dlg_cb_params *params) { - sr_xavp_t* xavp; + sr_xavp_t *xavp; - if (!dlgb.get_dlg) { + if(!dlgb.get_dlg) { LM_ERR("Dialog API not loaded! Trace off...\n"); return; } /* request - params->req */ - if (params == NULL || (!trace_dialog_spiral && params->req == NULL)) { + if(params == NULL || (!trace_dialog_spiral && params->req == NULL)) { LM_ERR("Invalid args!\n"); return; } - if (trace_dialog_spiral && *params->param == NULL) { + if(trace_dialog_spiral && *params->param == NULL) { LM_DBG("Spiraled dialog!\n"); - if (dlgb.register_dlgcb(dlg, DLGCB_SPIRALED, trace_dialog, &spiral_tracked, NULL) != 0) { - LM_ERR("could not register consider_exporting() for dialog event DLGCB_SPIRALED\n"); + if(dlgb.register_dlgcb( + dlg, DLGCB_SPIRALED, trace_dialog, &spiral_tracked, NULL) + != 0) { + LM_ERR("could not register consider_exporting() for dialog event " + "DLGCB_SPIRALED\n"); } } - if (!trace_dialog_spiral && !(params->req->msg_flags & FL_SIPTRACE)) { + if(!trace_dialog_spiral && !(params->req->msg_flags & FL_SIPTRACE)) { LM_DBG("Trace is off for this request...\n"); return; } xavp = xavp_get(&trace_xavp_info_name_s, NULL); - if (!xavp) { + if(!xavp) { /* this actually happens when only the transaction is traced * FL_SIPTRACE is set from trace_onreq_out * but xavp is set only for dialogs so this will avoid * registering dialog callbacks which is the desired behavior */ LM_DBG("%.*s xavp not registered! " - "Probably incoming E2E CANCEL!\n", trace_xavp_info_name_s.len, - trace_xavp_info_name_s.s); + "Probably incoming E2E CANCEL!\n", + trace_xavp_info_name_s.len, trace_xavp_info_name_s.s); return; } - if(dlgb.register_dlgcb(dlg, DLGCB_REQ_WITHIN, - trace_dialog_transaction, xavp->val.v.vptr, 0) != 0) { + if(dlgb.register_dlgcb(dlg, DLGCB_REQ_WITHIN, trace_dialog_transaction, + xavp->val.v.vptr, 0) + != 0) { LM_ERR("Failed to register DLGCB_REQ_WITHIN callback!\n"); return; } /* this will trace in-dialog ACK */ - if(trace_dialog_ack && dlgb.register_dlgcb(dlg, DLGCB_CONFIRMED, - trace_dialog_transaction, xavp->val.v.vptr, 0) != 0) { + if(trace_dialog_ack + && dlgb.register_dlgcb(dlg, DLGCB_CONFIRMED, + trace_dialog_transaction, xavp->val.v.vptr, 0) + != 0) { LM_ERR("Failed to register DLGCB_CONFIRMED callback!\n"); return; } - if(dlgb.register_dlgcb(dlg, DLGCB_TERMINATED, - trace_dialog_transaction, xavp->val.v.vptr, trace_free_info) != 0) { + if(dlgb.register_dlgcb(dlg, DLGCB_TERMINATED, trace_dialog_transaction, + xavp->val.v.vptr, trace_free_info) + != 0) { LM_ERR("Failed to register DLGCB_TERMINATED callback!\n"); return; } @@ -2118,12 +2170,13 @@ static void trace_dialog(struct dlg_cell* dlg, int type, struct dlg_cb_params *p } -static void trace_dialog_transaction(struct dlg_cell* dlg, int type, struct dlg_cb_params *params) +static void trace_dialog_transaction( + struct dlg_cell *dlg, int type, struct dlg_cb_params *params) { - siptrace_info_t* info; + siptrace_info_t *info; /* coverity fix - there shouldn't be a scenario for this to happen */ - if (params == NULL || params->param == NULL) { + if(params == NULL || params->param == NULL) { LM_ERR("NULL dialog params!\n"); return; } @@ -2134,7 +2187,7 @@ static void trace_dialog_transaction(struct dlg_cell* dlg, int type, struct dlg_ * transaction callbacks to catch caller and callee BYEs and their * responses */ - if (params->req == NULL && params->rpl == NULL) { + if(params->req == NULL && params->rpl == NULL) { LM_DBG("dual bye!\n"); return; } @@ -2145,14 +2198,15 @@ static void trace_dialog_transaction(struct dlg_cell* dlg, int type, struct dlg_ sip_trace(params->req, &info->u.dest_info, &info->correlation_id, NULL); } -static void trace_free_info(void* trace_info) +static void trace_free_info(void *trace_info) { - if (!trace_info) return; + if(!trace_info) + return; shm_free(trace_info); } -static siptrace_data_t* siptrace_event_data = NULL; +static siptrace_data_t *siptrace_event_data = NULL; static int siptrace_exec_evcb_msg(siptrace_data_t *sto) { @@ -2163,7 +2217,7 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto) str evname = str_init("siptrace:msg"); sip_msg_t msg; - if(_siptrace_evrt_msg_idx < 0 && _siptrace_evcb_msg.len<=0) { + if(_siptrace_evrt_msg_idx < 0 && _siptrace_evcb_msg.len <= 0) { return 0; } @@ -2189,15 +2243,15 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto) init_run_actions_ctx(&ctx); siptrace_event_data = sto; - if(_siptrace_evrt_msg_idx>=0) { + if(_siptrace_evrt_msg_idx >= 0) { run_top_route(event_rt.rlist[_siptrace_evrt_msg_idx], &msg, &ctx); } else { keng = sr_kemi_eng_get(); - if (keng!=NULL) { + if(keng != NULL) { bctx = sr_kemi_act_ctx_get(); sr_kemi_act_ctx_set(&ctx); - (void)sr_kemi_route(keng, &msg, EVENT_ROUTE, - &_siptrace_evcb_msg, &evname); + (void)sr_kemi_route( + keng, &msg, EVENT_ROUTE, &_siptrace_evcb_msg, &evname); sr_kemi_act_ctx_set(bctx); } } @@ -2225,7 +2279,7 @@ int siptrace_net_data_recv(sr_event_param_t *evp) if(evp->data == 0) return -1; - if(trace_on_flag != NULL && *trace_on_flag==0) { + if(trace_on_flag != NULL && *trace_on_flag == 0) { return 0; } @@ -2240,9 +2294,9 @@ int siptrace_net_data_recv(sr_event_param_t *evp) sto.body.len = nd->data.len; sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(nd->rcv->proto), - ip_addr2strz(&nd->rcv->src_ip), (int)nd->rcv->src_port); - if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) { + siptrace_proto_name(nd->rcv->proto), ip_addr2strz(&nd->rcv->src_ip), + (int)nd->rcv->src_port); + if(sto.fromip.len < 0 || sto.fromip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.fromip.len); sto.fromip.s = SIPTRACE_ANYADDR; sto.fromip.len = SIPTRACE_ANYADDR_LEN; @@ -2253,7 +2307,7 @@ int siptrace_net_data_recv(sr_event_param_t *evp) sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", siptrace_proto_name(nd->rcv->proto), ip_addr2strz(&nd->rcv->dst_ip), (int)nd->rcv->dst_port); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -2263,7 +2317,7 @@ int siptrace_net_data_recv(sr_event_param_t *evp) sto.dir = "in"; - evcb_ret=siptrace_exec_evcb_msg(&sto); + evcb_ret = siptrace_exec_evcb_msg(&sto); if(evcb_ret < 0) { ret = -1; goto finish; @@ -2285,18 +2339,18 @@ int siptrace_net_data_recv(sr_event_param_t *evp) tmsg.buf = sto.body.s; tmsg.len = sto.body.len; - if (parse_msg(tmsg.buf, tmsg.len, &tmsg)!=0) { + if(parse_msg(tmsg.buf, tmsg.len, &tmsg) != 0) { LM_DBG("msg buffer parsing failed!\n"); goto afterdb; } - if(tmsg.first_line.type==SIP_REQUEST) { + if(tmsg.first_line.type == SIP_REQUEST) { if(!IS_SIP(&tmsg)) { LM_DBG("non sip request message\n"); free_sip_msg(&tmsg); goto afterdb; } - } else if(tmsg.first_line.type==SIP_REPLY) { + } else if(tmsg.first_line.type == SIP_REPLY) { if(!IS_SIP_REPLY(&tmsg)) { LM_DBG("non sip reply message\n"); free_sip_msg(&tmsg); @@ -2354,7 +2408,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp) if(evp->data == 0) return -1; - if(trace_on_flag != NULL && *trace_on_flag==0) { + if(trace_on_flag != NULL && *trace_on_flag == 0) { return 0; } @@ -2379,7 +2433,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp) sto.fromip.len = SIPTRACE_ANYADDR_LEN; proto = PROTO_UDP; } else { - if(new_dst.send_sock->sock_str.len>=SIPTRACE_ADDR_MAX-1) { + if(new_dst.send_sock->sock_str.len >= SIPTRACE_ADDR_MAX - 1) { LM_ERR("socket string is too large: %d\n", new_dst.send_sock->sock_str.len); return -1; @@ -2392,10 +2446,9 @@ int siptrace_net_data_sent(sr_event_param_t *evp) sto.fromip.s = sto.fromip_buff; sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d", - siptrace_proto_name(proto), - suip2a(&new_dst.to, sizeof(new_dst.to)), + siptrace_proto_name(proto), suip2a(&new_dst.to, sizeof(new_dst.to)), (int)su_getport(&new_dst.to)); - if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) { + if(sto.toip.len < 0 || sto.toip.len >= SIPTRACE_ADDR_MAX) { LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len); sto.toip.s = SIPTRACE_ANYADDR; sto.toip.len = SIPTRACE_ANYADDR_LEN; @@ -2405,7 +2458,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp) sto.dir = "out"; - evcb_ret=siptrace_exec_evcb_msg(&sto); + evcb_ret = siptrace_exec_evcb_msg(&sto); if(evcb_ret < 0) { ret = -1; goto finish; @@ -2427,18 +2480,18 @@ int siptrace_net_data_sent(sr_event_param_t *evp) tmsg.buf = sto.body.s; tmsg.len = sto.body.len; - if (parse_msg(tmsg.buf, tmsg.len, &tmsg)!=0) { + if(parse_msg(tmsg.buf, tmsg.len, &tmsg) != 0) { LM_DBG("msg buffer parsing failed!\n"); goto afterdb; } - if(tmsg.first_line.type==SIP_REQUEST) { + if(tmsg.first_line.type == SIP_REQUEST) { if(!IS_SIP(&tmsg)) { LM_DBG("non sip request message\n"); free_sip_msg(&tmsg); goto afterdb; } - } else if(tmsg.first_line.type==SIP_REPLY) { + } else if(tmsg.first_line.type == SIP_REPLY) { if(!IS_SIP_REPLY(&tmsg)) { LM_DBG("non sip reply message\n"); free_sip_msg(&tmsg); @@ -2561,14 +2614,11 @@ static void siptrace_rpc_status(rpc_t *rpc, void *c) } static const char *siptrace_status_doc[2] = { - "Get status or turn on/off siptrace. Parameters: on, off or check.", - 0 -}; + "Get status or turn on/off siptrace. Parameters: on, off or check.", 0}; rpc_export_t siptrace_rpc[] = { - {"siptrace.status", siptrace_rpc_status, siptrace_status_doc, 0}, - {0, 0, 0, 0} -}; + {"siptrace.status", siptrace_rpc_status, siptrace_status_doc, 0}, + {0, 0, 0, 0}}; static int siptrace_init_rpc(void) { diff --git a/src/modules/siptrace/siptrace_data.h b/src/modules/siptrace/siptrace_data.h index 13610b3ce89..bd846b8c7b5 100644 --- a/src/modules/siptrace/siptrace_data.h +++ b/src/modules/siptrace/siptrace_data.h @@ -58,11 +58,18 @@ typedef struct _siptrace_data #endif } siptrace_data_t; -enum UriState { STRACE_UNUSED_URI = 0, STRACE_RAW_URI = 1, STRACE_PARSED_URI = 2}; +enum UriState +{ + STRACE_UNUSED_URI = 0, + STRACE_RAW_URI = 1, + STRACE_PARSED_URI = 2 +}; -typedef struct { +typedef struct +{ str correlation_id; - union { + union + { str dup_uri; dest_info_t dest_info; } u; @@ -70,7 +77,12 @@ typedef struct { } siptrace_info_t; -enum siptrace_type_t {SIPTRACE_NONE=0, SIPTRACE_MESSAGE = 'm', - SIPTRACE_TRANSACTION = 't', SIPTRACE_DIALOG = 'd'}; +enum siptrace_type_t +{ + SIPTRACE_NONE = 0, + SIPTRACE_MESSAGE = 'm', + SIPTRACE_TRANSACTION = 't', + SIPTRACE_DIALOG = 'd' +}; #endif diff --git a/src/modules/siptrace/siptrace_hep.c b/src/modules/siptrace/siptrace_hep.c index 0643ca74c6f..cb054711206 100644 --- a/src/modules/siptrace/siptrace_hep.c +++ b/src/modules/siptrace/siptrace_hep.c @@ -109,7 +109,7 @@ int trace_send_hep3_duplicate(str *body, str *from, str *to, len += sizeof(struct hep_chunk_uint16); // destination port len += sizeof(struct hep_chunk_uint32); // timestamp len += sizeof(struct hep_chunk_uint32); // timestamp us - len += sizeof(struct hep_chunk_uint8); // proto_type (SIP) + len += sizeof(struct hep_chunk_uint8); // proto_type (SIP) len += sizeof(struct hep_chunk_uint32); // capture ID len += sizeof(struct hep_chunk); // payload @@ -165,7 +165,8 @@ int trace_send_hep3_duplicate(str *body, str *from, str *to, } } if(hep_auth_key_str.s && hep_auth_key_str.len > 0) { - HEP3_PACK_CHUNK_DATA(0, 0x000e, hep_auth_key_str.s, hep_auth_key_str.len); + HEP3_PACK_CHUNK_DATA( + 0, 0x000e, hep_auth_key_str.s, hep_auth_key_str.len); } HEP3_PACK_CHUNK_DATA(0, 0x000f, body->s, body->len); HEP3_PACK_FINALIZE(buffer, &len); @@ -201,8 +202,7 @@ int trace_send_hep3_duplicate(str *body, str *from, str *to, si = trace_send_sock_info; } else { si = grep_sock_info(&trace_send_sock_uri->host, - trace_send_sock_uri->port_no, - trace_send_sock_uri->proto); + trace_send_sock_uri->port_no, trace_send_sock_uri->proto); } } if(trace_send_sock_name_str.s || trace_send_sock_str.s) { @@ -332,8 +332,7 @@ int trace_send_hep2_duplicate( si = trace_send_sock_info; } else { si = grep_sock_info(&trace_send_sock_uri->host, - trace_send_sock_uri->port_no, - trace_send_sock_uri->proto); + trace_send_sock_uri->port_no, trace_send_sock_uri->proto); } } if(trace_send_sock_name_str.s || trace_send_sock_str.s) { @@ -567,8 +566,9 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message) struct socket_info *si; if(!correlationid) { - if(msg->callid == NULL && ((parse_headers(msg, HDR_CALLID_F, 0) == -1) - || (msg->callid == NULL))) { + if(msg->callid == NULL + && ((parse_headers(msg, HDR_CALLID_F, 0) == -1) + || (msg->callid == NULL))) { LM_ERR("cannot parse Call-Id header\n"); return -1; } @@ -630,8 +630,7 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message) si = trace_send_sock_info; } else { si = grep_sock_info(&trace_send_sock_uri->host, - trace_send_sock_uri->port_no, - trace_send_sock_uri->proto); + trace_send_sock_uri->port_no, trace_send_sock_uri->proto); } } if(trace_send_sock_name_str.s || trace_send_sock_str.s) { @@ -678,7 +677,8 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message) HEP3_PACK_CHUNK_UINT32(0, 0x000c, hep_capture_id); HEP3_PACK_CHUNK_DATA(0, 0x0011, correlationid->s, correlationid->len); if(hep_auth_key_str.s && hep_auth_key_str.len > 0) { - HEP3_PACK_CHUNK_DATA(0, 0x000e, hep_auth_key_str.s, hep_auth_key_str.len); + HEP3_PACK_CHUNK_DATA( + 0, 0x000e, hep_auth_key_str.s, hep_auth_key_str.len); } HEP3_PACK_CHUNK_DATA(0, 0x000f, message->s, message->len); HEP3_PACK_FINALIZE(buf, &len); diff --git a/src/modules/siptrace/siptrace_send.c b/src/modules/siptrace/siptrace_send.c index a2b53908387..bac4ad04779 100644 --- a/src/modules/siptrace/siptrace_send.c +++ b/src/modules/siptrace/siptrace_send.c @@ -67,8 +67,9 @@ int sip_trace_prepare(sip_msg_t *msg) goto error; } - if(msg->cseq == NULL && ((parse_headers(msg, HDR_CSEQ_F, 0) == -1) - || (msg->cseq == NULL))) { + if(msg->cseq == NULL + && ((parse_headers(msg, HDR_CSEQ_F, 0) == -1) + || (msg->cseq == NULL))) { LM_ERR("cannot parse cseq\n"); goto error; } @@ -115,16 +116,16 @@ int sip_trace_xheaders_write(struct _siptrace_data *sto) // Write the new headers a the end-of-header position. This overwrites // the \r\n terminating the old headers and the beginning of the message // body. Both will be recovered later. - bytes_written = - snprintf(eoh, XHEADERS_BUFSIZE, "X-Siptrace-Fromip: %.*s\r\n" - "X-Siptrace-Toip: %.*s\r\n" - "X-Siptrace-Time: %llu %llu\r\n" - "X-Siptrace-Method: %.*s\r\n" - "X-Siptrace-Dir: %s\r\n", - sto->fromip.len, sto->fromip.s, sto->toip.len, sto->toip.s, - (unsigned long long)sto->tv.tv_sec, - (unsigned long long)sto->tv.tv_usec, sto->method.len, - sto->method.s, sto->dir); + bytes_written = snprintf(eoh, XHEADERS_BUFSIZE, + "X-Siptrace-Fromip: %.*s\r\n" + "X-Siptrace-Toip: %.*s\r\n" + "X-Siptrace-Time: %llu %llu\r\n" + "X-Siptrace-Method: %.*s\r\n" + "X-Siptrace-Dir: %s\r\n", + sto->fromip.len, sto->fromip.s, sto->toip.len, sto->toip.s, + (unsigned long long)sto->tv.tv_sec, + (unsigned long long)sto->tv.tv_usec, sto->method.len, sto->method.s, + sto->dir); if(bytes_written >= XHEADERS_BUFSIZE) { LM_ERR("string too long\n"); goto error; @@ -201,12 +202,13 @@ int sip_trace_xheaders_read(struct _siptrace_data *sto) } // Parse the x-headers: scanf() - if(sscanf(xheaders, "\r\n" - "X-Siptrace-Fromip: %50s\r\n" - "X-Siptrace-Toip: %50s\r\n" - "X-Siptrace-Time: %llu %llu\r\n" - "X-Siptrace-Method: %50s\r\n" - "X-Siptrace-Dir: %3s", + if(sscanf(xheaders, + "\r\n" + "X-Siptrace-Fromip: %50s\r\n" + "X-Siptrace-Toip: %50s\r\n" + "X-Siptrace-Time: %llu %llu\r\n" + "X-Siptrace-Method: %50s\r\n" + "X-Siptrace-Dir: %3s", sto->fromip.s, sto->toip.s, &tv_sec, &tv_usec, sto->method.s, sto->dir) == EOF) { @@ -297,7 +299,8 @@ int trace_send_duplicate(char *buf, int len, dest_info_t *dst2) /* either modparam dup_uri or siptrace param dst2 */ if((trace_dup_uri_str.s == 0 || trace_dup_uri == NULL) && (dst2 == NULL)) { - LM_WARN("Neither dup_uri modparam or siptrace destination uri param used!\n"); + LM_WARN("Neither dup_uri modparam or siptrace destination uri param " + "used!\n"); return 0; } @@ -307,7 +310,8 @@ int trace_send_duplicate(char *buf, int len, dest_info_t *dst2) /* create a temporary proxy from dst param */ dst.proto = trace_dup_uri->proto; p = mk_proxy(&trace_dup_uri->host, - (trace_dup_uri->port_no) ? trace_dup_uri->port_no : SIP_PORT, dst.proto); + (trace_dup_uri->port_no) ? trace_dup_uri->port_no : SIP_PORT, + dst.proto); if(p == 0) { LM_ERR("bad host name in uri\n"); return -1; @@ -336,8 +340,8 @@ int trace_send_duplicate(char *buf, int len, dest_info_t *dst2) trace_send_sock_str.len, trace_send_sock_str.s); } else { LM_DBG("using local send socket: [%.*s] [%.*s]\n", - pdst->send_sock->name.len, - pdst->send_sock->name.s, pdst->send_sock->address_str.len, + pdst->send_sock->name.len, pdst->send_sock->name.s, + pdst->send_sock->address_str.len, pdst->send_sock->address_str.s); } } @@ -374,7 +378,7 @@ int trace_send_duplicate(char *buf, int len, dest_info_t *dst2) /** * */ -char* siptrace_proto_name(int vproto) +char *siptrace_proto_name(int vproto) { switch(vproto) { case PROTO_TCP: diff --git a/src/modules/siptrace/siptrace_send.h b/src/modules/siptrace/siptrace_send.h index 867d3995b07..5a0c252da5e 100644 --- a/src/modules/siptrace/siptrace_send.h +++ b/src/modules/siptrace/siptrace_send.h @@ -37,40 +37,42 @@ int trace_send_duplicate(char *buf, int len, struct dest_info *dst2); /** * */ -#define siptrace_copy_proto_olen(vproto, vbuf, vlen) do { \ - switch(vproto) { \ - case PROTO_TCP: \ - strcpy(vbuf, "tcp:"); \ - vlen = 4; \ - break; \ - case PROTO_TLS: \ - strcpy(vbuf, "tls:"); \ - vlen = 4; \ - break; \ - case PROTO_SCTP: \ - strcpy(vbuf, "sctp:"); \ - vlen = 5; \ - break; \ - case PROTO_WS: \ - strcpy(vbuf, "ws:"); \ - vlen = 3; \ - break; \ - case PROTO_WSS: \ - strcpy(vbuf, "wss:"); \ - vlen = 4; \ - break; \ - default: \ - strcpy(vbuf, "udp:"); \ - vlen = 4; \ - } \ +#define siptrace_copy_proto_olen(vproto, vbuf, vlen) \ + do { \ + switch(vproto) { \ + case PROTO_TCP: \ + strcpy(vbuf, "tcp:"); \ + vlen = 4; \ + break; \ + case PROTO_TLS: \ + strcpy(vbuf, "tls:"); \ + vlen = 4; \ + break; \ + case PROTO_SCTP: \ + strcpy(vbuf, "sctp:"); \ + vlen = 5; \ + break; \ + case PROTO_WS: \ + strcpy(vbuf, "ws:"); \ + vlen = 3; \ + break; \ + case PROTO_WSS: \ + strcpy(vbuf, "wss:"); \ + vlen = 4; \ + break; \ + default: \ + strcpy(vbuf, "udp:"); \ + vlen = 4; \ + } \ } while(0) -#define siptrace_copy_proto(vproto, vbuf) do { \ - int __olen; \ +#define siptrace_copy_proto(vproto, vbuf) \ + do { \ + int __olen; \ siptrace_copy_proto_olen(vproto, vbuf, __olen); \ - (void)__olen; \ + (void)__olen; \ } while(0) -char* siptrace_proto_name(int vproto); +char *siptrace_proto_name(int vproto); #endif