Browse code

posops: added posops_set_char() function

Daniel-Constantin Mierla authored on 07/11/2021 17:17:21
Showing 1 changed files
... ...
@@ -41,6 +41,7 @@ static void mod_destroy(void);
41 41
 static int w_posops_pos_append(sip_msg_t* msg, char* p1idx, char* p2val);
42 42
 static int w_posops_pos_insert(sip_msg_t* msg, char* p1idx, char* p2val);
43 43
 static int w_posops_pos_rm(sip_msg_t* msg, char* p1idx, char* p2len);
44
+static int w_posops_pos_set_char(sip_msg_t* msg, char* p1idx, char* p2val);
44 45
 static int w_posops_pos_headers_start(sip_msg_t* msg, char* p1, char* p2);
45 46
 static int w_posops_pos_headers_end(sip_msg_t* msg, char* p1, char* p2);
46 47
 static int w_posops_pos_body_start(sip_msg_t* msg, char* p1, char* p2);
... ...
@@ -83,6 +84,8 @@ static cmd_export_t cmds[]={
83 84
 		fixup_free_igp_spve, ANY_ROUTE},
84 85
 	{"pos_rm", (cmd_function)w_posops_pos_rm, 2, fixup_igp_igp,
85 86
 		fixup_free_igp_igp, ANY_ROUTE},
87
+	{"pos_set_char", (cmd_function)w_posops_pos_set_char, 2, fixup_igp_spve,
88
+		fixup_free_igp_spve, ANY_ROUTE},
86 89
 	{"pos_headers_start", (cmd_function)w_posops_pos_headers_start, 0, 0,
87 90
 		0, ANY_ROUTE},
88 91
 	{"pos_headers_end", (cmd_function)w_posops_pos_headers_end, 0, 0,
... ...
@@ -342,6 +345,56 @@ static int w_posops_pos_rm(sip_msg_t* msg, char* p1idx, char* p2len)
342 345
 	return ki_posops_pos_rm(msg, idx, len);
343 346
 }
344 347
 
348
+/**
349
+ *
350
+ */
351
+static int ki_posops_pos_set_char(sip_msg_t *msg, int idx, str *val)
352
+{
353
+	int offset;
354
+
355
+	posops_data_init();
356
+	if(val==NULL || val->s==NULL || val->len<=0) {
357
+		LM_ERR("invalid val parameter\n");
358
+		return -1;
359
+	}
360
+
361
+	if(idx<0) {
362
+		offset = msg->len + idx;
363
+	} else {
364
+		offset = idx;
365
+	}
366
+	if(offset>msg->len) {
367
+		LM_ERR("offset invalid: %d (msg-len: %d)\n", offset, msg->len);
368
+		return -1;
369
+	}
370
+
371
+	msg->buf[offset] = val->s[0];
372
+
373
+	return 1;
374
+}
375
+
376
+/**
377
+ *
378
+ */
379
+static int w_posops_pos_set_char(sip_msg_t* msg, char* p1idx, char* p2val)
380
+{
381
+	int idx = 0;
382
+	str val = STR_NULL;
383
+
384
+	posops_data_init();
385
+	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
386
+		LM_ERR("unable to get idx parameter\n");
387
+		return -1;
388
+	}
389
+
390
+	if(fixup_get_svalue(msg, (gparam_t*)p2val, &val)!=0) {
391
+		LM_ERR("unable to get val parameter\n");
392
+		return -1;
393
+	}
394
+
395
+	return ki_posops_pos_set_char(msg, idx, &val);
396
+}
397
+
345 398
 /**
346 399
  *
347 400
  */
... ...
@@ -878,6 +931,11 @@ static sr_kemi_t sr_kemi_posops_exports[] = {
878 931
 		{ SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE,
879 932
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
880 933
 	},
934
+	{ str_init("posops"), str_init("pos_set_char"),
935
+		SR_KEMIP_INT, ki_posops_pos_set_char,
936
+		{ SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_NONE,
937
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
938
+	},
881 939
 	{ str_init("posops"), str_init("pos_headers_start"),
882 940
 		SR_KEMIP_INT, ki_posops_pos_headers_start,
883 941
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,