Browse code

textopsx: added change_reply_status_code(vcode)

- function to change only the status code for non-2xx replies

Daniel-Constantin Mierla authored on 02/08/2020 15:04:34
Showing 1 changed files
... ...
@@ -50,6 +50,8 @@ static int msg_apply_changes_f(sip_msg_t *msg, char *str1, char *str2);
50 50
 static int change_reply_status_f(sip_msg_t *, char *, char *);
51 51
 static int change_reply_status_fixup(void **param, int param_no);
52 52
 
53
+static int change_reply_status_code_f(sip_msg_t *, char *, char *);
54
+
53 55
 static int w_keep_hf_f(sip_msg_t *, char *, char *);
54 56
 
55 57
 static int w_fnmatch2_f(sip_msg_t *, char *, char *);
... ...
@@ -84,6 +86,8 @@ static cmd_export_t cmds[] = {
84 86
 			REQUEST_ROUTE | ONREPLY_ROUTE},
85 87
 	{"change_reply_status", change_reply_status_f, 2,
86 88
 			change_reply_status_fixup, 0, ONREPLY_ROUTE},
89
+	{"change_reply_status_code", change_reply_status_code_f, 1,
90
+			fixup_igp_null, 0, ONREPLY_ROUTE},
87 91
 	{"remove_body", (cmd_function)w_remove_body_f, 0, 0, 0, ANY_ROUTE},
88 92
 	{"keep_hf", (cmd_function)w_keep_hf_f, 0, fixup_regexp_null, 0, ANY_ROUTE},
89 93
 	{"keep_hf", (cmd_function)w_keep_hf_f, 1, fixup_regexp_null, 0, ANY_ROUTE},
... ...
@@ -275,6 +279,49 @@ static int change_reply_status_f(
275 279
 }
276 280
 
277 281
 
282
+/**
283
+ *
284
+ */
285
+static int ki_change_reply_status_code(sip_msg_t *msg, int code)
286
+{
287
+	if((code < 100) || (code > 699)) {
288
+		LM_ERR("wrong status code: %d\n", code);
289
+		return -1;
290
+	}
291
+
292
+	if(((code < 300) || (msg->REPLY_STATUS < 300))
293
+			&& (code / 100 != msg->REPLY_STATUS / 100)) {
294
+		LM_ERR("the class of provisional or "
295
+				   "positive final replies cannot be changed\n");
296
+		return -1;
297
+	}
298
+
299
+	/* rewrite the status code directly in the message buffer */
300
+	msg->first_line.u.reply.statuscode = code;
301
+	msg->first_line.u.reply.status.s[2] = code % 10 + '0';
302
+	code /= 10;
303
+	msg->first_line.u.reply.status.s[1] = code % 10 + '0';
304
+	code /= 10;
305
+	msg->first_line.u.reply.status.s[0] = code + '0';
306
+
307
+	return 1l;
308
+}
309
+
310
+/**
311
+ *
312
+ */
313
+static int change_reply_status_code_f(sip_msg_t *msg, char *pcode, char *p2)
314
+{
315
+	int code;
316
+
317
+	if(fixup_get_ivalue(msg, (gparam_t*)pcode, &code)<0) {
318
+		LM_ERR("cannot get parameters\n");
319
+		return -1;
320
+	}
321
+
322
+	return ki_change_reply_status_code(msg, code);
323
+}
324
+
278 325
 /**
279 326
  *
280 327
  */
... ...
@@ -2195,6 +2242,11 @@ static sr_kemi_t sr_kemi_textopsx_exports[] = {
2195 2242
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
2196 2243
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2197 2244
 	},
2245
+	{ str_init("textopsx"), str_init("change_reply_status_code"),
2246
+		SR_KEMIP_INT, ki_change_reply_status_code,
2247
+		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
2248
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2249
+	},
2198 2250
 	{ str_init("textopsx"), str_init("keep_hf"),
2199 2251
 		SR_KEMIP_INT, ki_keep_hf,
2200 2252
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,