Browse code

Merge 25c4d6a82e70350da0da4e5bf9aac83c1d466300 into 4168d7c55955a01c3a30c67d5e8a510be52120ff

sergey-safarov authored on 07/06/2021 13:21:42 • GitHub committed on 07/06/2021 13:21:42
Showing 1 changed files
... ...
@@ -195,6 +195,10 @@ static str trace_local_ip = {NULL, 0};
195 195
 static db1_con_t *db_con = NULL; /*!< database connection */
196 196
 static db_func_t db_funcs;		  /*!< Database functions */
197 197
 
198
+int pv_parse_siptrace_name(pv_spec_t *sp, str *in);
199
+int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param,
200
+		pv_value_t *res);
201
+
198 202
 /*! \brief
199 203
  * Exported functions
200 204
  */
... ...
@@ -276,6 +280,14 @@ stat_export_t siptrace_stats[] = {
276 280
 /* clang-format on */
277 281
 #endif
278 282
 
283
+static pv_export_t mod_pvs[] = {
284
+
285
+	{ {"siptrace", (sizeof("siptrace")-1)}, PVT_OTHER, pv_get_siptrace, 0,
286
+		pv_parse_siptrace_name, 0, 0, 0 },
287
+
288
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
289
+};
290
+
279 291
 /*! \brief module exports */
280 292
 /* clang-format off */
281 293
 struct module_exports exports = {
... ...
@@ -283,9 +295,9 @@ struct module_exports exports = {
283 295
 	DEFAULT_DLFLAGS, /*!< dlopen flags */
284 296
 	cmds,			/*!< exported functions */
285 297
 	params,			/*!< exported parameters */
286
-	0,				/*!< exported rpc functions */
287
-	0,				/*!< exported pseudo-variables */
288
-	0,				/*!< response function */
298
+	0,			/*!< exported rpc functions */
299
+	mod_pvs,		/*!< exported pseudo-variables */
300
+	0,			/*!< response function */
289 301
 	mod_init,		/*!< module initialization function */
290 302
 	child_init,		/*!< child initialization function */
291 303
 	destroy			/*!< destroy function */
... ...
@@ -2039,6 +2051,8 @@ static void trace_free_info(void* trace_info)
2039 2051
 	shm_free(trace_info);
2040 2052
 }
2041 2053
 
2054
+static siptrace_data_t* siptrace_event_data = NULL;
2055
+
2042 2056
 static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2043 2057
 {
2044 2058
 	int backup_rt;
... ...
@@ -2068,6 +2082,7 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2068 2082
 	set_route_type(EVENT_ROUTE);
2069 2083
 	init_run_actions_ctx(&ctx);
2070 2084
 
2085
+	siptrace_event_data = sto;
2071 2086
 	if(_siptrace_evrt_msg_idx>=0) {
2072 2087
 		run_top_route(event_rt.rlist[_siptrace_evrt_msg_idx], &msg, &ctx);
2073 2088
 	} else {
... ...
@@ -2080,6 +2095,7 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2080 2095
 			sr_kemi_act_ctx_set(bctx);
2081 2096
 		}
2082 2097
 	}
2098
+	siptrace_event_data = NULL;
2083 2099
 
2084 2100
 	free_sip_msg(&msg);
2085 2101
 	set_route_type(backup_rt);
... ...
@@ -2482,6 +2498,56 @@ static sr_kemi_t sr_kemi_siptrace_exports[] = {
2482 2498
 
2483 2499
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
2484 2500
 };
2501
+
2502
+/**
2503
+ *
2504
+ */
2505
+int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param,
2506
+		pv_value_t *res)
2507
+{
2508
+	if (siptrace_event_data==NULL) {
2509
+		return pv_get_null(msg, param, res);
2510
+	}
2511
+
2512
+	switch(param->pvn.u.isname.name.n) {
2513
+		case 1: /* dst_uri*/
2514
+			return pv_get_strval(msg, param, res, &siptrace_event_data->toip);
2515
+		default:
2516
+			/* 0 - src_uri */
2517
+			return pv_get_strval(msg, param, res, &siptrace_event_data->fromip);
2518
+	}
2519
+}
2520
+
2521
+/**
2522
+ *
2523
+ */
2524
+int pv_parse_siptrace_name(pv_spec_t *sp, str *in)
2525
+{
2526
+	if(sp==NULL || in==NULL || in->len<=0)
2527
+		return -1;
2528
+
2529
+	switch(in->len)
2530
+	{
2531
+		case 7:
2532
+			if(strncmp(in->s, "src_uri", 7)==0)
2533
+				sp->pvp.pvn.u.isname.name.n = 0;
2534
+			else if(strncmp(in->s, "dst_uri", 7)==0)
2535
+				sp->pvp.pvn.u.isname.name.n = 1;
2536
+			else goto error;
2537
+		break;
2538
+		default:
2539
+			goto error;
2540
+	}
2541
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
2542
+	sp->pvp.pvn.u.isname.type = 0;
2543
+
2544
+	return 0;
2545
+
2546
+error:
2547
+	LM_ERR("unknown PV snd name %.*s\n", in->len, in->s);
2548
+	return -1;
2549
+}
2550
+
2485 2551
 /* clang-format on */
2486 2552
 
2487 2553
 /**