Browse code

- append_to_reply() has support for pseudo-variables

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@575 689a6050-402a-0410-94f2-e92a70836424

Daniel-Constantin Mierla authored on 30/01/2006 13:00:07
Showing 3 changed files
... ...
@@ -275,17 +275,18 @@ if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$
275 275
 
276 276
 1.3.8. append_to_reply(txt)
277 277
 
278
-   Append txt to the reply.
278
+   Append txt as header to the reply.
279 279
 
280 280
    Meaning of the parameters is as follows:
281 281
 
282
-     * txt - String.
282
+     * txt - String which may contains pseudo-variables.
283 283
 
284 284
    This function can be used from REQUEST_ROUTE, BRANCH_ROUTE.
285 285
 
286 286
    Example 1-8. append_to_reply usage
287 287
 ...
288 288
 append_to_reply("Foo: bar\r\n");
289
+append_to_reply("Foo: $rm at $Ts\r\n");
289 290
 ...
290 291
      _________________________________________________________
291 292
 
... ...
@@ -454,7 +455,7 @@ append_time();
454 455
      * name - SIP method name
455 456
 
456 457
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
457
-   FAILURE_ROUTE.
458
+   FAILURE_ROUTE, and BRANCH_ROUTE.
458 459
 
459 460
    Example 1-16. is_method usage
460 461
 ...
... ...
@@ -534,4 +535,4 @@ Chapter 3. Frequently Asked Questions
534 535
    3.3. How can I report a bug?
535 536
 
536 537
    Please follow the guidelines provided at:
537
-   http://openser.org/bugs.
538
+   http://sourceforge.net/tracker/?group_id=139143.
... ...
@@ -331,12 +331,13 @@ if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$
331 331
 		<function moreinfo="none">append_to_reply(txt)</function>
332 332
 		</title>
333 333
 		<para>
334
-		Append txt to the reply.
334
+		Append txt as header to the reply.
335 335
 		</para>
336 336
 		<para>Meaning of the parameters is as follows:</para>
337 337
 		<itemizedlist>
338 338
 		<listitem>
339
-			<para><emphasis>txt</emphasis> - String.
339
+			<para><emphasis>txt</emphasis> - String which may contains
340
+			pseudo-variables.
340 341
 			</para>
341 342
 		</listitem>
342 343
 		</itemizedlist>
... ...
@@ -348,6 +349,7 @@ if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$
348 349
 		<programlisting format="linespecific">
349 350
 ...
350 351
 append_to_reply("Foo: bar\r\n");
352
+append_to_reply("Foo: $rm at $Ts\r\n");
351 353
 ...
352 354
 </programlisting>
353 355
 		</example>
... ...
@@ -108,6 +108,7 @@ static int str_fixup(void** param, int param_no);
108 108
 static int hname_fixup(void** param, int param_no);
109 109
 static int fixup_method(void** param, int param_no);
110 110
 static int add_header_fixup(void** param, int param_no);
111
+static int it_list_fixup(void** param, int param_no);
111 112
 
112 113
 static int mod_init(void);
113 114
 
... ...
@@ -121,7 +122,7 @@ static cmd_export_t cmds[]={
121 122
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
122 123
 	{"replace_all",      replace_all_f,     2, fixup_regex, 
123 124
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE}, 
124
-	{"append_to_reply",  append_to_reply_f, 1, 0,
125
+	{"append_to_reply",  append_to_reply_f, 1, it_list_fixup,
125 126
 			REQUEST_ROUTE|BRANCH_ROUTE},
126 127
 	{"append_hf",        append_hf_1,       1, add_header_fixup,
127 128
 			REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
... ...
@@ -579,9 +580,38 @@ static int append_time_f(struct sip_msg* msg, char* p1, char *p2)
579 580
 	return 1;
580 581
 }
581 582
 
582
-static int append_to_reply_f(struct sip_msg* msg, char* key, char* str)
583
+#define ADD_HF_PRINTBUF_SIZE   1024
584
+static char printbuf[ADD_HF_PRINTBUF_SIZE];
585
+
586
+static int append_to_reply_f(struct sip_msg* msg, char* key, char* str0)
583 587
 {
584
-	if ( add_lump_rpl( msg, key, strlen(key), LUMP_RPL_HDR)==0 )
588
+	int printbuf_len;
589
+	xl_elem_t *model;
590
+	str s0;
591
+
592
+	if(key==NULL)
593
+	{
594
+		LOG(L_ERR,"ERROR:append_to_reply: error - bad parameters\n");
595
+		return -1;
596
+	}
597
+
598
+	model = (xl_elem_t*)key;
599
+	if(model->next==0 && model->spec.itf==0)
600
+	{
601
+		s0 = model->text;
602
+	} else {
603
+		printbuf_len = ADD_HF_PRINTBUF_SIZE-1;
604
+		if(xl_printf(msg, model, printbuf, &printbuf_len)<0)
605
+		{
606
+			LOG(L_ERR,
607
+			"textops:add_hf_helper: error - cannot print the format\n");
608
+			return -1;
609
+		}
610
+		s0.s   = printbuf;
611
+		s0.len = printbuf_len;
612
+	}
613
+	 
614
+	if ( add_lump_rpl( msg, s0.s, s0.len, LUMP_RPL_HDR)==0 )
585 615
 	{
586 616
 		LOG(L_ERR,"ERROR:append_to_reply : unable to add lump_rl\n");
587 617
 		return -1;
... ...
@@ -600,8 +630,6 @@ static int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
600 630
 	struct hdr_field *hf;
601 631
 	char *s;
602 632
 	int len;
603
-#define ADD_HF_PRINTBUF_SIZE   1024
604
-	static char printbuf[ADD_HF_PRINTBUF_SIZE];
605 633
 	int printbuf_len;
606 634
 	str s0;
607 635