Skip to content

Commit

Permalink
proto_hep: port script functions to new param interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu authored and liviuchircu committed Apr 4, 2019
1 parent da3f105 commit ae762c3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 78 deletions.
79 changes: 13 additions & 66 deletions modules/proto_hep/hep.c
Expand Up @@ -1511,7 +1511,7 @@ int add_hep_chunk(trace_message message, void* data, int len, int type, int data
return 0;
}

int add_hep_correlation(trace_message message, char* corr_name, str* corr_value)
int add_hep_correlation(trace_message message, str* corr_name, str* corr_value)
{
cJSON* root;
struct hep_desc* hep_msg;
Expand Down Expand Up @@ -1542,9 +1542,9 @@ int add_hep_correlation(trace_message message, char* corr_name, str* corr_value)
hep_msg->correlation = root;
}

cJSON_AddStrToObject( root, corr_name, corr_value->s, corr_value->len);
_cJSON_AddStrToObject( root, corr_name, corr_value->s, corr_value->len);
} else {
if ( !memcmp( corr_name, "sip", sizeof("sip") ) ) {
if ( !memcmp( corr_name->s, "sip", sizeof("sip") ) ) {
/* we'll save sip correlation id as the actual correlation */
sip_correlation = pkg_malloc( sizeof(str) + corr_value->len );
if ( !sip_correlation ) {
Expand Down Expand Up @@ -1859,64 +1859,21 @@ int hep_bind_trace_api(trace_proto_t* prot)
/***************************************************************
********************* HEP CORRELATE script function ***********
***************************************************************/
int correlate_fixup(void** param, int param_no)
int correlate_w(struct sip_msg* msg, str* hep_id,
str* type1, str* corr_s1,
str* type2, str* corr_s2)
{
gparam_p gp;

if ( param_no < 1 || param_no > 5 ) {
LM_ERR("bad param number %d\n", param_no);
return -1;
}

fixup_spve( param );
gp = *param;

if ( param_no == 2 || param_no == 4 ) {
if ( gp->type != GPARAM_TYPE_STR ) {
LM_ERR("only strings allowed for param %d\n", param_no);
return -1;
}

*param = gp->v.sval.s;

return 0;
}

if ( gp->type != GPARAM_TYPE_PVS && gp->type != GPARAM_TYPE_STR ) {
LM_ERR("only strings or single variables allowed to this function!\n");
return -1;
}

return 0;
}

int correlate_w(struct sip_msg* msg, char* hep_id,
char* type1, char* correlation1,
char* type2, char* correlation2)
{
str corr_s1, corr_s2;
hid_list_p h;

str value;
trace_message message;

if ( !msg ) {
LM_ERR("null sip msg!\n");
return -1;
}

if ( !hep_id || !type1 || !type2 || !correlation1 || !correlation2 ) {
LM_ERR("all parameters are mandatory for correlate function!\n");
return -1;
}

if ( fixup_get_svalue( msg, (gparam_p)hep_id, &value) < 0 ) {
LM_ERR("failed to fetch hep destination name!\n");
return -1;
}
h = get_hep_id_by_name( &value );
h = get_hep_id_by_name(hep_id);
if ( h == NULL ) {
LM_ERR("no hep id with name <%.*s>\n", value.len, value.s );
LM_ERR("no hep id with name <%.*s>\n", hep_id->len, hep_id->s );
return -1;
}

Expand All @@ -1925,17 +1882,6 @@ int correlate_w(struct sip_msg* msg, char* hep_id,
return -1;
}


if ( fixup_get_svalue( msg, (gparam_p)correlation1, &corr_s1 ) < 0 ) {
LM_ERR("failed to fetch hep destination name!\n");
return -1;
}

if ( fixup_get_svalue( msg, (gparam_p)correlation2, &corr_s2 ) < 0 ) {
LM_ERR("failed to fetch hep destination name!\n");
return -1;
}

if ( control_id < 0 ) {
control_id = get_hep_message_id( "control" );
}
Expand All @@ -1946,13 +1892,14 @@ int correlate_w(struct sip_msg* msg, char* hep_id,
return -1;
}

if ( strcmp( type1, type2 ) ) {
LM_ERR("Type1 <%s> must be different from type2!\n", type1);
if ( str_strcmp( type1, type2 ) ) {
LM_ERR("Type1 <%.*s> must be different from type2!\n",
type1->len, type1->s);
return -1;
}

add_hep_correlation( message, type1, &corr_s1 );
add_hep_correlation( message, type2, &corr_s2 );
add_hep_correlation( message, type1, corr_s1 );
add_hep_correlation( message, type2, corr_s2 );

if ( send_hep_message( message, h, 0) < 0 ) {
LM_ERR(" failed to send hep message to destination!\n");
Expand Down
6 changes: 3 additions & 3 deletions modules/proto_hep/hep.h
Expand Up @@ -275,9 +275,9 @@ int hep_bind_trace_api(trace_proto_t* prot);
typedef int (*get_hep_ctx_id_t)(void);
unsigned char* generate_hep_gid(char* cookie);

int correlate_w(struct sip_msg*, char* hep_id,
char* type1, char* correlation1,
char* type2, char* correlation2);
int correlate_w(struct sip_msg*, str* hep_id,
str* type1, str* correlation1,
str* type2, str* correlation2);
int correlate_fixup(void** param, int param_no);
#endif

2 changes: 1 addition & 1 deletion modules/proto_hep/hep_cb.h
Expand Up @@ -69,7 +69,7 @@ static inline int load_hep_api(proto_hep_api_t* api )
load_hep_f load_hep;

/* import the TM auto-loading function */
if ( !(load_hep=(load_hep_f)find_export("load_hep", 0, 0))) {
if ( !(load_hep=(load_hep_f)find_export("load_hep", 0))) {
LM_ERR("failed to import load_hep\n");
return -1;
}
Expand Down
17 changes: 9 additions & 8 deletions modules/proto_hep/proto_hep.c
Expand Up @@ -110,15 +110,16 @@ struct hep_data {
int oldest_chunk;
};


static cmd_export_t cmds[] = {
{"proto_init", (cmd_function)proto_hep_init_udp, 0, 0, 0, 0},
{"proto_init", (cmd_function)proto_hep_init_tcp, 0, 0, 0, 0},
{"load_hep", (cmd_function)bind_proto_hep, 1, 0, 0, 0},
{"trace_bind_api", (cmd_function)hep_bind_trace_api, 1, 0, 0, 0},
{"correlate", (cmd_function)correlate_w, 5, correlate_fixup, 0,
{"proto_init", (cmd_function)proto_hep_init_udp, {{0,0,0}}, 0},
{"proto_init", (cmd_function)proto_hep_init_tcp, {{0,0,0}}, 0},
{"load_hep", (cmd_function)bind_proto_hep, {{0,0,0}}, 0},
{"trace_bind_api", (cmd_function)hep_bind_trace_api, {{0,0,0}}, 0},
{"correlate", (cmd_function)correlate_w, {
{CMD_PARAM_STR,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{0,0,0,0,0,0}
{0,0,{{0,0,0}},0}
};

static param_export_t params[] = {
Expand Down Expand Up @@ -195,7 +196,7 @@ static int mod_init(void)

if (payload_compression) {
load_compression =
(load_compression_f)find_export("load_compression", 1, 0);
(load_compression_f)find_export("load_compression", 0);
if (!load_compression) {
LM_ERR("can't bind compression module!\n");
return -1;
Expand Down

0 comments on commit ae762c3

Please sign in to comment.