Browse code

nathelper: use set_alias_to_pv() for kemi export name

- same as for config export
- helper functions renamed to reflect better their purpose

Daniel-Constantin Mierla authored on 27/11/2019 19:15:39
Showing 1 changed files
... ...
@@ -127,8 +127,8 @@ static int test_sdp_cline(struct sip_msg *msg);
127 127
 
128 128
 static int w_set_alias_to_pv(struct sip_msg *msg, char *uri_avp, char *hollow);
129 129
 static int ki_set_alias_to_pv(struct sip_msg *msg, str *uri_avp);
130
-static int alias_to_uri(str *contact_header, str *alias_uri);
131
-static int write_to_avp(struct sip_msg *msg, str *data, str *uri_avp);
130
+static int nh_alias_to_uri(str *contact_header, str *alias_uri);
131
+static int nh_write_to_pv(struct sip_msg *msg, str *data, str *pvname);
132 132
 
133 133
 static void nh_timer(unsigned int, void *);
134 134
 static int mod_init(void);
... ...
@@ -2460,7 +2460,8 @@ static int sel_rewrite_contact(str *res, select_t *s, struct sip_msg *msg)
2460 2460
 *
2461 2461
 * @result 1 successful  , -1 fail
2462 2462
 */
2463
-static int w_set_alias_to_pv(struct sip_msg *msg, char *uri_avp, char *hollow){
2463
+static int w_set_alias_to_pv(struct sip_msg *msg, char *uri_avp, char *hollow)
2464
+{
2464 2465
 	str dest_avp={0,0};
2465 2466
 
2466 2467
 	if(!uri_avp)
... ...
@@ -2481,7 +2482,8 @@ static int w_set_alias_to_pv(struct sip_msg *msg, char *uri_avp, char *hollow){
2481 2481
 *
2482 2482
 * @result 1 successful  , -1 fail
2483 2483
 */
2484
-static int ki_set_alias_to_pv(struct sip_msg *msg, str *uri_avp){
2484
+static int ki_set_alias_to_pv(struct sip_msg *msg, str *pvname)
2485
+{
2485 2486
 	str contact;
2486 2487
 	str alias_uri={0,0};
2487 2488
 
... ...
@@ -2503,10 +2505,10 @@ static int ki_set_alias_to_pv(struct sip_msg *msg, str *uri_avp){
2503 2503
 	contact.s = ((contact_body_t *)msg->contact->parsed)->contacts->name.s;
2504 2504
 	contact.len = ((contact_body_t *)msg->contact->parsed)->contacts->len;
2505 2505
 
2506
-	if(alias_to_uri(&contact,&alias_uri)<0)
2506
+	if(nh_alias_to_uri(&contact, &alias_uri)<0)
2507 2507
 		return -1;
2508 2508
 
2509
-	if(write_to_avp(msg, &alias_uri, uri_avp)<0)
2509
+	if(nh_write_to_pv(msg, &alias_uri, pvname)<0)
2510 2510
 		goto error;
2511 2511
 
2512 2512
 	if(alias_uri.s)
... ...
@@ -2518,19 +2520,20 @@ static int ki_set_alias_to_pv(struct sip_msg *msg, str *uri_avp){
2518 2518
 		if(alias_uri.s)
2519 2519
 			pkg_free(alias_uri.s);
2520 2520
 
2521
-		return -1;
2521
+	return -1;
2522 2522
 }
2523 2523
 /*!
2524
-* @function write_to_avp
2525
-* @abstract write_to_avp function writes data to given avp
2524
+* @function nh_write_to_pv
2525
+* @abstract nh_write_to_pv function writes data to given avp
2526 2526
 * @param data  source data
2527 2527
 * @param uri_avp destination avp name
2528 2528
 * @result 1 successful  , -1 fail
2529 2529
 */
2530
-static int write_to_avp(struct sip_msg *msg, str *data, str *uri_avp){
2530
+static int nh_write_to_pv(struct sip_msg *msg, str *data, str *pvname)
2531
+{
2531 2532
 	pv_spec_t *pvresult = NULL;
2532 2533
 	pv_value_t valx;
2533
-	pvresult = pv_cache_get(uri_avp);
2534
+	pvresult = pv_cache_get(pvname);
2534 2535
 
2535 2536
 	if(pvresult == NULL) {
2536 2537
 		LM_ERR("Failed to malloc destination pseudo-variable \n");
... ...
@@ -2538,7 +2541,8 @@ static int write_to_avp(struct sip_msg *msg, str *data, str *uri_avp){
2538 2538
 	}
2539 2539
 
2540 2540
 	if(pvresult->setf==NULL) {
2541
-		LM_ERR("Destination pseudo-variable is not writable: [%.*s] \n",uri_avp->len, uri_avp->s);
2541
+		LM_ERR("Destination pseudo-variable is not writable: [%.*s] \n",
2542
+				pvname->len, pvname->s);
2542 2543
 		return -1;
2543 2544
 	}
2544 2545
 	memset(&valx, 0, sizeof(pv_value_t));
... ...
@@ -2557,14 +2561,15 @@ static int write_to_avp(struct sip_msg *msg, str *data, str *uri_avp){
2557 2557
 	return 1;
2558 2558
 }
2559 2559
 /*!
2560
-* @function alias_to_uri
2560
+* @function nh_alias_to_uri
2561 2561
 * @abstract select alias paramter from contact_header
2562 2562
 * 					then writes to alias_uri
2563 2563
 * @param contact_header  Source contact header
2564 2564
 * @param alias_uri Destination string
2565 2565
 * @result 1 successful  , -1 fail
2566 2566
 */
2567
-static int alias_to_uri(str *contact_header, str *alias_uri){
2567
+static int nh_alias_to_uri(str *contact_header, str *alias_uri)
2568
+{
2568 2569
 	int i=0; // index
2569 2570
 	str host={0,0};
2570 2571
 	str port={0,0};
... ...
@@ -2700,7 +2705,7 @@ static sr_kemi_t sr_kemi_nathelper_exports[] = {
2700 2700
 		{ SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_NONE,
2701 2701
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2702 2702
 	},
2703
-	{ str_init("nathelper"), str_init("set_alias_to_avp"),
2703
+	{ str_init("nathelper"), str_init("set_alias_to_pv"),
2704 2704
 		SR_KEMIP_INT, ki_set_alias_to_pv,
2705 2705
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
2706 2706
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }