Browse code

textopsx: exported msg_set_buffer(data) function

- it was available to KEMI

Daniel-Constantin Mierla authored on 24/09/2021 10:16:37
Showing 2 changed files
... ...
@@ -46,6 +46,34 @@ if(msg_apply_changes())
46 46
     }
47 47
 }
48 48
 ...
49
+</programlisting>
50
+		</example>
51
+	</section>
52
+
53
+	<section id="textopsx.f.msg_set_buffer">
54
+		<title>
55
+			<function moreinfo="none">msg_set_buffer(data)</function>
56
+		</title>
57
+		<para>
58
+		Set the content of the SIP message buffer, replacing the exiting data.
59
+		The parameter can contain variables, its value must be a valid SIP
60
+		request or reply, a matter of what the old message is.
61
+		</para>
62
+		<para>
63
+		This function can be used from REQUEST_ROUTE or core REPLY_ROUTE.
64
+		</para>
65
+		<para>
66
+		Note: It must be used before the transaction is created in
67
+		request_route and not inside the onreply_route[name] executed by tm
68
+		module. Also, do not use after resuming a suspended request or reply,
69
+		at that moment the transaction is already created.
70
+		</para>
71
+		<example>
72
+		<title><function>msg_set_buffer()</function> usage</title>
73
+		<programlisting format="linespecific">
74
+...
75
+msg_set_buffer("INVITE sip:...");
76
+...
49 77
 </programlisting>
50 78
 		</example>
51 79
 	</section>
... ...
@@ -46,6 +46,7 @@
46 46
 MODULE_VERSION
47 47
 
48 48
 static int msg_apply_changes_f(sip_msg_t *msg, char *str1, char *str2);
49
+static int msg_set_buffer_f(sip_msg_t *msg, char *p1data, char *p2);
49 50
 
50 51
 static int change_reply_status_f(sip_msg_t *, char *, char *);
51 52
 static int change_reply_status_fixup(void **param, int param_no);
... ...
@@ -121,6 +122,9 @@ static pv_export_t mod_pvs[] = {
121 122
 static cmd_export_t cmds[] = {
122 123
 	{"msg_apply_changes", (cmd_function)msg_apply_changes_f, 0, 0, 0,
123 124
 			REQUEST_ROUTE | ONREPLY_ROUTE},
125
+	{"msg_set_buffer", (cmd_function)msg_set_buffer_f, 1,
126
+			fixup_spve_null, fixup_free_spve_null,
127
+			REQUEST_ROUTE | ONREPLY_ROUTE},
124 128
 	{"change_reply_status", change_reply_status_f, 2,
125 129
 			change_reply_status_fixup, 0, ONREPLY_ROUTE},
126 130
 	{"change_reply_status_code", change_reply_status_code_f, 1,
... ...
@@ -242,6 +246,21 @@ static int ki_msg_set_buffer(sip_msg_t *msg, str *obuf)
242 246
 	return ki_msg_update_buffer(msg, obuf);
243 247
 }
244 248
 
249
+/**
250
+ *
251
+ */
252
+static int msg_set_buffer_f(sip_msg_t *msg, char *p1data, char *p2)
253
+{
254
+	str data = STR_NULL;
255
+
256
+	if(fixup_get_svalue(msg, (gparam_t*)p1data, &data) < 0) {
257
+		LM_ERR("could not get string param value\n");
258
+		return -1;
259
+	}
260
+
261
+	return ki_msg_set_buffer(msg, &data);
262
+}
263
+
245 264
 /**
246 265
  *
247 266
  */