Browse code

pv: added function to set the value for $ccp(key)

Daniel-Constantin Mierla authored on 16/05/2021 10:23:02
Showing 3 changed files
... ...
@@ -540,7 +540,7 @@ static pv_export_t mod_pvs[] = {
540 540
 		pv_parse_ksr_attrs_name, 0, 0, 0 },
541 541
 	{{"rpl", (sizeof("rpl")-1)}, PVT_OTHER, pv_get_rpl_attrs, 0,
542 542
 		pv_parse_rpl_attrs_name, 0, 0, 0},
543
-	{{"ccp", (sizeof("ccp")-1)}, PVT_OTHER, pv_get_ccp_attrs, 0,
543
+	{{"ccp", (sizeof("ccp")-1)}, PVT_OTHER, pv_get_ccp_attrs, pv_set_ccp_attrs,
544 544
 		pv_parse_ccp_attrs_name, 0, 0, 0},
545 545
 
546 546
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
... ...
@@ -4057,3 +4057,54 @@ int pv_get_ccp_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
4057 4057
 	LM_ERR("unknown type for variable [%.*s]\n", s.len, s.s);
4058 4058
 	return pv_get_null(msg, param, res);
4059 4059
 }
4060
+
4061
+/**
4062
+ *
4063
+ */
4064
+int pv_set_ccp_attrs(struct sip_msg* msg, pv_param_t *param,
4065
+		int op, pv_value_t *val)
4066
+{
4067
+	str gname = STR_NULL;
4068
+	str vname = STR_NULL;
4069
+	unsigned int *grpid = NULL;
4070
+	str s = STR_NULL;
4071
+	char *sep = NULL;
4072
+
4073
+	if(val == NULL || (val->flags&PV_VAL_NULL)) {
4074
+		LM_WARN("ignoring null asignment\n");
4075
+		return 0;
4076
+	}
4077
+
4078
+	s = param->pvn.u.isname.name.s;
4079
+
4080
+	sep = q_memrchr(s.s, '.', s.len);
4081
+	if(sep==NULL) {
4082
+		LM_ERR("invalid pv name [%.*s]\n", s.len, s.s);
4083
+		return -1;
4084
+	}
4085
+	gname.s = s.s;
4086
+	gname.len = sep - s.s;
4087
+	vname.s = sep + 1;
4088
+	vname.len = s.s + s.len - sep - 1;
4089
+
4090
+	if (cfg_get_group_id(&gname, &grpid)) {
4091
+		LM_ERR("wrong group syntax. Use either 'group', or 'group[id]'\n");
4092
+		return -1;
4093
+	}
4094
+
4095
+	LM_DBG("setting value for variable: %.*s.%.*s\n", gname.len, gname.s,
4096
+				vname.len, vname.s);
4097
+
4098
+	if(val->flags&PV_TYPE_INT) {
4099
+		if(cfg_set_now_int(_pv_ccp_ctx, &gname, grpid, &vname, val->ri)) {
4100
+			LM_ERR("failed to set int to the variable: [%.*s]\n", s.len, s.s);
4101
+			return -1;
4102
+		}
4103
+	} else {
4104
+		if(cfg_set_now_str(_pv_ccp_ctx, &gname, grpid, &vname, &val->rs)) {
4105
+			LM_ERR("failed to set str to the variable: [%.*s]\n", s.len, s.s);
4106
+			return -1;
4107
+		}
4108
+	}
4109
+	return 0;
4110
+}
... ...
@@ -402,6 +402,8 @@ int pv_ccp_ctx_init(void);
402 402
 int pv_parse_ccp_attrs_name(pv_spec_p sp, str *in);
403 403
 int pv_get_ccp_attrs(sip_msg_t *msg, pv_param_t *param,
404 404
 		pv_value_t *res);
405
+int pv_set_ccp_attrs(struct sip_msg* msg, pv_param_t *param,
406
+		int op, pv_value_t *val);
405 407
 
406 408
 #endif
407 409