Browse code

posops: store len of matched string with search function

Daniel-Constantin Mierla authored on 29/09/2021 07:23:42
Showing 1 changed files
... ...
@@ -54,6 +54,7 @@ static int w_posops_pos_search(sip_msg_t* msg, char* p1idx, char* p2re);
54 54
 typedef struct posops_data {
55 55
 	int ret;
56 56
 	int idx;
57
+	int len;
57 58
 } posops_data_t;
58 59
 
59 60
 static int posops_idx0 = -255;
... ...
@@ -659,6 +660,7 @@ static int ki_posops_pos_search_helper(sip_msg_t *msg, int idx, regex_t *re)
659 660
 
660 661
 	_posops_data.idx = (int)(msg->buf + idx + pmatch.rm_so);
661 662
 	_posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
663
+	_posops_data.len = pmatch.rm_eo-pmatch.rm_so;
662 664
 
663 665
 	return _posops_data.ret;
664 666
 }
... ...
@@ -708,6 +710,8 @@ static int pv_posops_get_pos(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
708 710
 			return pv_get_sintval(msg, param, res, _posops_data.idx);
709 711
 		case 1: /* ret */
710 712
 			return pv_get_sintval(msg, param, res, _posops_data.ret);
713
+		case 2: /* len */
714
+			return pv_get_sintval(msg, param, res, _posops_data.len);
711 715
 	}
712 716
 	return pv_get_null(msg, param, res);
713 717
 }
... ...
@@ -723,6 +727,8 @@ static int pv_posops_parse_pos_name(pv_spec_t *sp, str *in)
723 727
 				sp->pvp.pvn.u.isname.name.n = 0;
724 728
 			else if(strncmp(in->s, "ret", 3)==0)
725 729
 				sp->pvp.pvn.u.isname.name.n = 1;
730
+			else if(strncmp(in->s, "len", 3)==0)
731
+				sp->pvp.pvn.u.isname.name.n = 2;
726 732
 			else goto error;
727 733
 		break;
728 734