Browse code

- added function to set the body for replies - renamed insert_body() to set_body() for coherence (it also deals with single-part body, not multi-part body) - functions accept pseudo-variables in parameters

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

Daniel-Constantin Mierla authored on 28/01/2009 08:18:51
Showing 3 changed files
... ...
@@ -51,24 +51,25 @@ Daniel-Constantin Mierla
51 51
               1.3.11. subst_uri('/re/repl/flags')
52 52
               1.3.12. subst_user('/re/repl/flags')
53 53
               1.3.13. subst_body('/re/repl/flags')
54
-              1.3.14. insert_body(txt,content_type)
55
-              1.3.15. filter_body(content_type)
56
-              1.3.16. append_to_reply(txt)
57
-              1.3.17. append_hf(txt)
58
-              1.3.18. append_hf(txt, hdr)
59
-              1.3.19. insert_hf(txt)
60
-              1.3.20. insert_hf(txt, hdr)
61
-              1.3.21. append_urihf(prefix, suffix)
62
-              1.3.22. is_present_hf(hf_name)
63
-              1.3.23. is_present_hf_re(hf_name_re)
64
-              1.3.24. append_time()
65
-              1.3.25. is_method(name)
66
-              1.3.26. remove_hf(hname)
67
-              1.3.27. remove_hf_re(re)
68
-              1.3.28. has_body(), has_body(mime)
69
-              1.3.29. is_privacy(privacy_type)
70
-              1.3.30. cmp_str(str1, str2)
71
-              1.3.31. cmp_istr(str1, str2)
54
+              1.3.14. set_body(txt,content_type)
55
+              1.3.15. set_rpl_body(txt,content_type)
56
+              1.3.16. filter_body(content_type)
57
+              1.3.17. append_to_reply(txt)
58
+              1.3.18. append_hf(txt)
59
+              1.3.19. append_hf(txt, hdr)
60
+              1.3.20. insert_hf(txt)
61
+              1.3.21. insert_hf(txt, hdr)
62
+              1.3.22. append_urihf(prefix, suffix)
63
+              1.3.23. is_present_hf(hf_name)
64
+              1.3.24. is_present_hf_re(hf_name_re)
65
+              1.3.25. append_time()
66
+              1.3.26. is_method(name)
67
+              1.3.27. remove_hf(hname)
68
+              1.3.28. remove_hf_re(re)
69
+              1.3.29. has_body(), has_body(mime)
70
+              1.3.30. is_privacy(privacy_type)
71
+              1.3.31. cmp_str(str1, str2)
72
+              1.3.32. cmp_istr(str1, str2)
72 73
 
73 74
         1.4. Known Limitations
74 75
 
... ...
@@ -93,24 +94,25 @@ Daniel-Constantin Mierla
93 94
    1.11. subst_uri usage
94 95
    1.12. subst usage
95 96
    1.13. subst_body usage
96
-   1.14. insert_body usage
97
-   1.15. filter_body usage
98
-   1.16. append_to_reply usage
99
-   1.17. append_hf usage
97
+   1.14. set_body usage
98
+   1.15. set_rpl_body usage
99
+   1.16. filter_body usage
100
+   1.17. append_to_reply usage
100 101
    1.18. append_hf usage
101
-   1.19. insert_hf usage
102
+   1.19. append_hf usage
102 103
    1.20. insert_hf usage
103
-   1.21. append_urihf usage
104
-   1.22. is_present_hf usage
105
-   1.23. is_present_hf_re usage
106
-   1.24. append_time usage
107
-   1.25. is_method usage
108
-   1.26. remove_hf usage
109
-   1.27. remove_hf_re usage
110
-   1.28. has_body usage
111
-   1.29. is_privacy usage
112
-   1.30. cmp_str usage
104
+   1.21. insert_hf usage
105
+   1.22. append_urihf usage
106
+   1.23. is_present_hf usage
107
+   1.24. is_present_hf_re usage
108
+   1.25. append_time usage
109
+   1.26. is_method usage
110
+   1.27. remove_hf usage
111
+   1.28. remove_hf_re usage
112
+   1.29. has_body usage
113
+   1.30. is_privacy usage
113 114
    1.31. cmp_str usage
115
+   1.32. cmp_str usage
114 116
 
115 117
 Chapter 1. Admin Guide
116 118
 
... ...
@@ -404,24 +406,41 @@ if ( subst_body('/^o=(.*) /o=$fU /') ) {};
404 406
 
405 407
 ...
406 408
 
407
-1.3.14.  insert_body(txt,content_type)
409
+1.3.14.  set_body(txt,content_type)
408 410
 
409
-   Insert body to a SIP message. If the body exists, the function
410
-   returns false as multi-part is not supported yet.
411
+   Set body to a SIP message.
411 412
 
412 413
    Meaning of the parameters is as follows:
413
-     * txt - text for the body.
414
-     * content_type - value of Content-Type header.
414
+     * txt - text for the body, can include pseudo-variables.
415
+     * content_type - value of Content-Type header, can include
416
+       pseudo-variables.
415 417
 
416 418
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
417 419
    FAILURE_ROUTE, BRANCH_ROUTE.
418 420
 
419
-   Example 1.14. insert_body usage
421
+   Example 1.14. set_body usage
420 422
 ...
421
-insert_body("test", "text/plain");
423
+set_body("test", "text/plain");
422 424
 ...
423 425
 
424
-1.3.15.  filter_body(content_type)
426
+1.3.15.  set_rpl_body(txt,content_type)
427
+
428
+   Set body to a SIP reply to be generated by Kamailio.
429
+
430
+   Meaning of the parameters is as follows:
431
+     * txt - text for the body, can include pseudo-variables.
432
+     * content_type - value of Content-Type header, can include
433
+       pseudo-variables.
434
+
435
+   This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
436
+   BRANCH_ROUTE.
437
+
438
+   Example 1.15. set_rpl_body usage
439
+...
440
+set_rpl_body("test", "text/plain");
441
+...
442
+
443
+1.3.16.  filter_body(content_type)
425 444
 
426 445
    Filters multipart body by leaving out all other body parts
427 446
    except the first body part of given type.
... ...
@@ -432,7 +451,7 @@ insert_body("test", "text/plain");
432 451
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
433 452
    FAILURE_ROUTE, BRANCH_ROUTE.
434 453
 
435
-   Example 1.15. filter_body usage
454
+   Example 1.16. filter_body usage
436 455
 ...
437 456
 if (has_body("multipart/mixed")) {
438 457
     if (filter_body("application/sdp") {
... ...
@@ -444,7 +463,7 @@ if (has_body("multipart/mixed")) {
444 463
 }
445 464
 ...
446 465
 
447
-1.3.16.  append_to_reply(txt)
466
+1.3.17.  append_to_reply(txt)
448 467
 
449 468
    Append txt as header to the reply.
450 469
 
... ...
@@ -454,13 +473,13 @@ if (has_body("multipart/mixed")) {
454 473
    This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
455 474
    FAILURE_ROUTE, ERROR_ROUTE.
456 475
 
457
-   Example 1.16. append_to_reply usage
476
+   Example 1.17. append_to_reply usage
458 477
 ...
459 478
 append_to_reply("Foo: bar\r\n");
460 479
 append_to_reply("Foo: $rm at $Ts\r\n");
461 480
 ...
462 481
 
463
-1.3.17.  append_hf(txt)
482
+1.3.18.  append_hf(txt)
464 483
 
465 484
    Appends 'txt' as header after the last header field.
466 485
 
... ...
@@ -477,13 +496,13 @@ append_to_reply("Foo: $rm at $Ts\r\n");
477 496
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
478 497
    FAILURE_ROUTE, BRANCH_ROUTE.
479 498
 
480
-   Example 1.17. append_hf usage
499
+   Example 1.18. append_hf usage
481 500
 ...
482 501
 append_hf("P-hint: VOICEMAIL\r\n");
483 502
 append_hf("From-username: $fU\r\n");
484 503
 ...
485 504
 
486
-1.3.18.  append_hf(txt, hdr)
505
+1.3.19.  append_hf(txt, hdr)
487 506
 
488 507
    Appends 'txt' as header after first 'hdr' header field.
489 508
 
... ...
@@ -495,13 +514,13 @@ append_hf("From-username: $fU\r\n");
495 514
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
496 515
    FAILURE_ROUTE, BRANCH_ROUTE.
497 516
 
498
-   Example 1.18. append_hf usage
517
+   Example 1.19. append_hf usage
499 518
 ...
500 519
 append_hf("P-hint: VOICEMAIL\r\n", "Call-ID");
501 520
 append_hf("From-username: $fU\r\n", "Call-ID");
502 521
 ...
503 522
 
504
-1.3.19.  insert_hf(txt)
523
+1.3.20.  insert_hf(txt)
505 524
 
506 525
    Inserts 'txt' as header before the first header field.
507 526
 
... ...
@@ -512,13 +531,13 @@ append_hf("From-username: $fU\r\n", "Call-ID");
512 531
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
513 532
    FAILURE_ROUTE, BRANCH_ROUTE.
514 533
 
515
-   Example 1.19. insert_hf usage
534
+   Example 1.20. insert_hf usage
516 535
 ...
517 536
 insert_hf("P-hint: VOICEMAIL\r\n");
518 537
 insert_hf("To-username: $tU\r\n");
519 538
 ...
520 539
 
521
-1.3.20.  insert_hf(txt, hdr)
540
+1.3.21.  insert_hf(txt, hdr)
522 541
 
523 542
    Inserts 'txt' as header before first 'hdr' header field.
524 543
 
... ...
@@ -530,13 +549,13 @@ insert_hf("To-username: $tU\r\n");
530 549
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
531 550
    FAILURE_ROUTE, BRANCH_ROUTE.
532 551
 
533
-   Example 1.20. insert_hf usage
552
+   Example 1.21. insert_hf usage
534 553
 ...
535 554
 insert_hf("P-hint: VOICEMAIL\r\n", "Call-ID");
536 555
 insert_hf("To-username: $tU\r\n", "Call-ID");
537 556
 ...
538 557
 
539
-1.3.21.  append_urihf(prefix, suffix)
558
+1.3.22.  append_urihf(prefix, suffix)
540 559
 
541 560
    Append header field name with original Request-URI in middle.
542 561
 
... ...
@@ -547,12 +566,12 @@ insert_hf("To-username: $tU\r\n", "Call-ID");
547 566
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
548 567
    BRANCH_ROUTE.
549 568
 
550
-   Example 1.21. append_urihf usage
569
+   Example 1.22. append_urihf usage
551 570
 ...
552 571
 append_urihf("CC-Diversion: ", "\r\n");
553 572
 ...
554 573
 
555
-1.3.22.  is_present_hf(hf_name)
574
+1.3.23.  is_present_hf(hf_name)
556 575
 
557 576
    Return true if a header field is present in message.
558 577
 
... ...
@@ -567,12 +586,12 @@ Note
567 586
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
568 587
    FAILURE_ROUTE, BRANCH_ROUTE.
569 588
 
570
-   Example 1.22. is_present_hf usage
589
+   Example 1.23. is_present_hf usage
571 590
 ...
572 591
 if (is_present_hf("From")) log(1, "From HF Present");
573 592
 ...
574 593
 
575
-1.3.23.  is_present_hf_re(hf_name_re)
594
+1.3.24.  is_present_hf_re(hf_name_re)
576 595
 
577 596
    Return true if a header field whose name matches regular
578 597
    expression 'hf_name_re' is present in message.
... ...
@@ -583,13 +602,13 @@ if (is_present_hf("From")) log(1, "From HF Present");
583 602
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
584 603
    FAILURE_ROUTE, BRANCH_ROUTE.
585 604
 
586
-   Example 1.23. is_present_hf_re usage
605
+   Example 1.24. is_present_hf_re usage
587 606
 ...
588 607
 if (is_present_hf_re("^P-")) log(1, "There are headers starting with P-\
589 608
 n");
590 609
 ...
591 610
 
592
-1.3.24.  append_time()
611
+1.3.25.  append_time()
593 612
 
594 613
    Adds a time header to the reply of the request. You must use it
595 614
    before functions that are likely to send a reply, e.g., save()
... ...
@@ -608,12 +627,12 @@ n");
608 627
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
609 628
    BRANCH_ROUTE.
610 629
 
611
-   Example 1.24. append_time usage
630
+   Example 1.25. append_time usage
612 631
 ...
613 632
 append_time();
614 633
 ...
615 634
 
616
-1.3.25.  is_method(name)
635
+1.3.26.  is_method(name)
617 636
 
618 637
    Check if the method of the message matches the name. If name is
619 638
    a known method (invite, cancel, ack, bye, options, info,
... ...
@@ -638,7 +657,7 @@ append_time();
638 657
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
639 658
    FAILURE_ROUTE, and BRANCH_ROUTE.
640 659
 
641
-   Example 1.25. is_method usage
660
+   Example 1.26. is_method usage
642 661
 ...
643 662
 if(is_method("INVITE"))
644 663
 {
... ...
@@ -650,7 +669,7 @@ if(is_method("OPTION|UPDATE"))
650 669
 }
651 670
 ...
652 671
 
653
-1.3.26.  remove_hf(hname)
672
+1.3.27.  remove_hf(hname)
654 673
 
655 674
    Remove from message all headers with name "hname"
656 675
 
... ...
@@ -662,7 +681,7 @@ if(is_method("OPTION|UPDATE"))
662 681
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
663 682
    FAILURE_ROUTE and BRANCH_ROUTE.
664 683
 
665
-   Example 1.26. remove_hf usage
684
+   Example 1.27. remove_hf usage
666 685
 ...
667 686
 if(remove_hf("User-Agent"))
668 687
 {
... ...
@@ -670,7 +689,7 @@ if(remove_hf("User-Agent"))
670 689
 }
671 690
 ...
672 691
 
673
-1.3.27.  remove_hf_re(re)
692
+1.3.28.  remove_hf_re(re)
674 693
 
675 694
    Remove from message all headers with name matching regular
676 695
    expression "re"
... ...
@@ -684,7 +703,7 @@ if(remove_hf("User-Agent"))
684 703
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
685 704
    FAILURE_ROUTE and BRANCH_ROUTE.
686 705
 
687
-   Example 1.27. remove_hf_re usage
706
+   Example 1.28. remove_hf_re usage
688 707
 ...
689 708
 if(remove_hf_re("^P-"))
690 709
 {
... ...
@@ -692,7 +711,7 @@ if(remove_hf_re("^P-"))
692 711
 }
693 712
 ...
694 713
 
695
-1.3.28.  has_body(), has_body(mime)
714
+1.3.29.  has_body(), has_body(mime)
696 715
 
697 716
    The function returns true if the SIP message has a body
698 717
    attached. The checked includes also the "Content-Lenght" header
... ...
@@ -708,7 +727,7 @@ if(remove_hf_re("^P-"))
708 727
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
709 728
    FAILURE_ROUTE and BRANCH_ROUTE.
710 729
 
711
-   Example 1.28. has_body usage
730
+   Example 1.29. has_body usage
712 731
 ...
713 732
 if(has_body("application/sdp"))
714 733
 {
... ...
@@ -716,7 +735,7 @@ if(has_body("application/sdp"))
716 735
 }
717 736
 ...
718 737
 
719
-1.3.29.  is_privacy(privacy_type)
738
+1.3.30.  is_privacy(privacy_type)
720 739
 
721 740
    The function returns true if the SIP message has a Privacy
722 741
    header field that includes the given privacy_type among its
... ...
@@ -727,7 +746,7 @@ if(has_body("application/sdp"))
727 746
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
728 747
    FAILURE_ROUTE and BRANCH_ROUTE.
729 748
 
730
-   Example 1.29. is_privacy usage
749
+   Example 1.30. is_privacy usage
731 750
 ...
732 751
 if(is_privacy("id"))
733 752
 {
... ...
@@ -735,7 +754,7 @@ if(is_privacy("id"))
735 754
 }
736 755
 ...
737 756
 
738
-1.3.30.  cmp_str(str1, str2)
757
+1.3.31.  cmp_str(str1, str2)
739 758
 
740 759
    The function returns true if the two parameters matches as
741 760
    string case sensitive comparison.
... ...
@@ -743,7 +762,7 @@ if(is_privacy("id"))
743 762
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
744 763
    FAILURE_ROUTE and BRANCH_ROUTE.
745 764
 
746
-   Example 1.30. cmp_str usage
765
+   Example 1.31. cmp_str usage
747 766
 ...
748 767
 if(cmp_str("$rU", "kamailio"))
749 768
 {
... ...
@@ -751,7 +770,7 @@ if(cmp_str("$rU", "kamailio"))
751 770
 }
752 771
 ...
753 772
 
754
-1.3.31.  cmp_istr(str1, str2)
773
+1.3.32.  cmp_istr(str1, str2)
755 774
 
756 775
    The function returns true if the two parameters matches as
757 776
    string case insensitive comparison.
... ...
@@ -759,7 +778,7 @@ if(cmp_str("$rU", "kamailio"))
759 778
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
760 779
    FAILURE_ROUTE and BRANCH_ROUTE.
761 780
 
762
-   Example 1.31. cmp_str usage
781
+   Example 1.32. cmp_str usage
763 782
 ...
764 783
 if(cmp_istr("$rU@you", "kamailio@YOU"))
765 784
 {
... ...
@@ -527,20 +527,21 @@ if ( subst_body('/^o=(.*) /o=$fU /') ) {};
527 527
 
528 528
 	<section>
529 529
 		<title>
530
-		<function moreinfo="none">insert_body(txt,content_type)</function>
530
+		<function moreinfo="none">set_body(txt,content_type)</function>
531 531
 		</title>
532 532
 		<para>
533
-		Insert body to a SIP message. If the body exists, the function returns
534
-		false as multi-part is not supported yet.
533
+		Set body to a SIP message.
535 534
 		</para>
536 535
 		<para>Meaning of the parameters is as follows:</para>
537 536
 		<itemizedlist>
538 537
 		<listitem>
539
-			<para><emphasis>txt</emphasis> - text for the body.
538
+			<para><emphasis>txt</emphasis> - text for the body, can include
539
+				pseudo-variables.
540 540
 			</para>
541 541
 		</listitem>
542 542
 		<listitem>
543
-			<para><emphasis>content_type</emphasis> - value of Content-Type header.
543
+			<para><emphasis>content_type</emphasis> - value of Content-Type header,
544
+				can include pseudo-variables.
544 545
 			</para>
545 546
 		</listitem>
546 547
 		</itemizedlist>
... ...
@@ -549,15 +550,47 @@ if ( subst_body('/^o=(.*) /o=$fU /') ) {};
549 550
 		FAILURE_ROUTE, BRANCH_ROUTE.
550 551
 		</para>
551 552
 		<example>
552
-		<title><function>insert_body</function> usage</title>
553
+		<title><function>set_body</function> usage</title>
553 554
 		<programlisting format="linespecific">
554 555
 ...
555
-insert_body("test", "text/plain");
556
+set_body("test", "text/plain");
556 557
 ...
557 558
 </programlisting>
558 559
 		</example>
559 560
 	</section>
560 561
 
562
+	<section>
563
+		<title>
564
+		<function moreinfo="none">set_rpl_body(txt,content_type)</function>
565
+		</title>
566
+		<para>
567
+		Set body to a SIP reply to be generated by &kamailio;.
568
+		</para>
569
+		<para>Meaning of the parameters is as follows:</para>
570
+		<itemizedlist>
571
+		<listitem>
572
+			<para><emphasis>txt</emphasis> - text for the body, can include
573
+				pseudo-variables.
574
+			</para>
575
+		</listitem>
576
+		<listitem>
577
+			<para><emphasis>content_type</emphasis> - value of Content-Type header,
578
+				can include pseudo-variables.
579
+			</para>
580
+		</listitem>
581
+		</itemizedlist>
582
+		<para>
583
+		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.
584
+		</para>
585
+		<example>
586
+		<title><function>set_rpl_body</function> usage</title>
587
+		<programlisting format="linespecific">
588
+...
589
+set_rpl_body("test", "text/plain");
590
+...
591
+</programlisting>
592
+		</example>
593
+	</section>
561 594
 
562 595
 	<section>
563 596
 		<title>
... ...
@@ -112,7 +112,8 @@ static int insert_hf_1(struct sip_msg* msg, char* str1, char* str2);
112 112
 static int insert_hf_2(struct sip_msg* msg, char* str1, char* str2);
113 113
 static int append_urihf(struct sip_msg* msg, char* str1, char* str2);
114 114
 static int append_time_f(struct sip_msg* msg, char* , char *);
115
-static int insert_body_f(struct sip_msg* msg, char*, char *);
115
+static int set_body_f(struct sip_msg* msg, char*, char *);
116
+static int set_rpl_body_f(struct sip_msg* msg, char*, char *);
116 117
 static int is_method_f(struct sip_msg* msg, char* , char *);
117 118
 static int has_body_f(struct sip_msg *msg, char *type, char *str2 );
118 119
 static int is_privacy_f(struct sip_msg *msg, char *privacy, char *str2 );
... ...
@@ -214,8 +215,11 @@ static cmd_export_t cmds[]={
214 215
 	{"append_time",      (cmd_function)append_time_f,     0,
215 216
 		0, 0,
216 217
 		REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
217
-	{"insert_body",      (cmd_function)insert_body_f,     2,
218
-		0, 0,
218
+	{"set_body",         (cmd_function)set_body_f,        2,
219
+		fixup_spve_spve, 0,
220
+		REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE },
221
+	{"set_rpl_body",     (cmd_function)set_rpl_body_f,    2,
222
+		fixup_spve_spve, 0,
219 223
 		REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
220 224
 	{"is_method",        (cmd_function)is_method_f,       1,
221 225
 		fixup_method, 0,
... ...
@@ -1077,14 +1081,16 @@ static int append_time_f(struct sip_msg* msg, char* p1, char *p2)
1077 1081
 }
1078 1082
 
1079 1083
 
1080
-static int insert_body_f(struct sip_msg* msg, char* p1, char* p2)
1084
+static int set_body_f(struct sip_msg* msg, char* p1, char* p2)
1081 1085
 {
1082 1086
 	struct lump *anchor;
1083 1087
 	char* buf;
1084 1088
 	int len;
1085 1089
 	char* value_s;
1086 1090
 	int value_len;
1087
-	str body;
1091
+	str body = {0,0};
1092
+	str nb = {0,0};
1093
+	str nc = {0,0};
1088 1094
 
1089 1095
 	if(p1==0 || p2==0)
1090 1096
 	{
... ...
@@ -1092,6 +1098,27 @@ static int insert_body_f(struct sip_msg* msg, char* p1, char* p2)
1092 1098
 		return -1;
1093 1099
 	}
1094 1100
 
1101
+	if(fixup_get_svalue(msg, (gparam_p)p1, &nb)!=0)
1102
+	{
1103
+		LM_ERR("unable to get p1\n");
1104
+		return -1;
1105
+	}
1106
+	if(nb.s==NULL || nb.len == 0)
1107
+	{
1108
+		LM_ERR("invalid body parameter\n");
1109
+		return -1;
1110
+	}
1111
+	if(fixup_get_svalue(msg, (gparam_p)p2, &nc)!=0)
1112
+	{
1113
+		LM_ERR("unable to get p2\n");
1114
+		return -1;
1115
+	}
1116
+	if(nc.s==NULL || nc.len == 0)
1117
+	{
1118
+		LM_ERR("invalid content-type parameter\n");
1119
+		return -1;
1120
+	}
1121
+
1095 1122
 	body.len = 0;
1096 1123
 	body.s = get_body(msg);
1097 1124
 	if (body.s==0)
... ...
@@ -1100,14 +1127,24 @@ static int insert_body_f(struct sip_msg* msg, char* p1, char* p2)
1100 1127
 		return -1;
1101 1128
 	}
1102 1129
 
1130
+	free_lump_list(msg->body_lumps);
1131
+	msg->body_lumps = NULL;
1132
+
1103 1133
 	if (msg->content_length) 
1104 1134
 	{
1105 1135
 		body.len = get_content_length( msg );
1106 1136
 		if(body.len > 0)
1107 1137
 		{
1108
-			LM_INFO("the sip message has a body"
1109
-				" - multipart not supported yet\n");
1110
-			return -1;
1138
+			if(body.s+body.len>msg->buf+msg->len)
1139
+			{
1140
+				LM_ERR("invalid content length: %d\n", body.len);
1141
+				return -1;
1142
+			}
1143
+			if(del_lump(msg, body.s - msg->buf, body.len, 0) == 0)
1144
+			{
1145
+				LM_ERR("cannot delete existing body");
1146
+				return -1;
1147
+			}
1111 1148
 		}
1112 1149
 	}
1113 1150
 
... ...
@@ -1122,7 +1159,7 @@ static int insert_body_f(struct sip_msg* msg, char* p1, char* p2)
1122 1159
 	if (msg->content_length==0)
1123 1160
 	{
1124 1161
 		/* need to add Content-Length */
1125
-		len = strlen(p1);
1162
+		len = nb.len;
1126 1163
 		value_s=int2str(len, &value_len);
1127 1164
 		LM_DBG("content-length: %d (%s)\n", value_len, value_s);
1128 1165
 
... ...
@@ -1147,57 +1184,126 @@ static int insert_body_f(struct sip_msg* msg, char* p1, char* p2)
1147 1184
 	}
1148 1185
 
1149 1186
 	/* add content-type */
1150
-	value_len = strlen(p2);
1151
-	len=sizeof("Content-Type: ") - 1 + value_len + CRLF_LEN;
1152
-	buf=pkg_malloc(sizeof(char)*(len));
1187
+	if(msg->content_type==NULL || msg->content_type->body.len!=nc.len
1188
+			|| strncmp(msg->content_type->body.s, nc.s, nc.len)!=0)
1189
+	{
1190
+		if(msg->content_type!=NULL)
1191
+			if(del_lump(msg, msg->content_type->name.s-msg->buf,
1192
+						msg->content_type->len, 0) == 0)
1193
+			{
1194
+				LM_ERR("failed to delete content type\n");
1195
+				return -1;
1196
+			}
1197
+		value_len = nc.len;
1198
+		len=sizeof("Content-Type: ") - 1 + value_len + CRLF_LEN;
1199
+		buf=pkg_malloc(sizeof(char)*(len));
1200
+
1201
+		if (buf==0)
1202
+		{
1203
+			LM_ERR("out of pkg memory\n");
1204
+			return -1;
1205
+		}
1206
+		memcpy(buf, "Content-Type: ", sizeof("Content-Type: ") - 1);
1207
+		memcpy(buf+sizeof("Content-Type: ") - 1, nc.s, value_len);
1208
+		memcpy(buf+sizeof("Content-Type: ") - 1 + value_len, CRLF, CRLF_LEN);
1209
+		if (insert_new_lump_after(anchor, buf, len, 0) == 0)
1210
+		{
1211
+			LM_ERR("failed to insert content-type lump\n");
1212
+			pkg_free(buf);
1213
+			return -1;
1214
+		}
1215
+	}	
1216
+	anchor = anchor_lump(msg, body.s - msg->buf, 0, 0);
1153 1217
 
1218
+	if (anchor == 0)
1219
+	{
1220
+		LM_ERR("failed to get body anchor\n");
1221
+		return -1;
1222
+	} 
1223
+
1224
+	buf=pkg_malloc(sizeof(char)*(nb.len));
1154 1225
 	if (buf==0)
1155 1226
 	{
1156 1227
 		LM_ERR("out of pkg memory\n");
1157 1228
 		return -1;
1158 1229
 	}
1159
-	memcpy(buf, "Content-Type: ", sizeof("Content-Type: ") - 1);
1160
-	memcpy(buf+sizeof("Content-Type: ") - 1, p2, value_len);
1161
-	memcpy(buf+sizeof("Content-Type: ") - 1 + value_len, CRLF, CRLF_LEN);
1162
-	if (insert_new_lump_after(anchor, buf, len, 0) == 0)
1230
+	memcpy(buf, nb.s, nb.len);
1231
+	if (insert_new_lump_after(anchor, buf, nb.len, 0) == 0)
1163 1232
 	{
1164
-		LM_ERR("failed to insert content-type lump\n");
1233
+		LM_ERR("failed to insert body lump\n");
1165 1234
 		pkg_free(buf);
1166 1235
 		return -1;
1167 1236
 	}
1237
+	LM_DBG("new body: [%.*s]", nb.len, nb.s);
1238
+	return 1;
1239
+}
1168 1240
 
1169
-		
1170
-	anchor = anchor_lump(msg, body.s - msg->buf, 0, 0);
1241
+static int set_rpl_body_f(struct sip_msg* msg, char* p1, char* p2)
1242
+{
1243
+	char* buf;
1244
+	int len;
1245
+	int value_len;
1246
+	str nb = {0,0};
1247
+	str nc = {0,0};
1171 1248
 
1172
-	if (anchor == 0)
1249
+	if(p1==0 || p2==0)
1173 1250
 	{
1174
-		LM_ERR("failed to get body anchor\n");
1251
+		LM_ERR("invalid parameters\n");
1175 1252
 		return -1;
1176
-	} 
1253
+	}
1177 1254
 
1178
-	len = strlen(p1);
1255
+	if(fixup_get_svalue(msg, (gparam_p)p1, &nb)!=0)
1256
+	{
1257
+		LM_ERR("unable to get p1\n");
1258
+		return -1;
1259
+	}
1260
+	if(nb.s==NULL || nb.len == 0)
1261
+	{
1262
+		LM_ERR("invalid body parameter\n");
1263
+		return -1;
1264
+	}
1265
+	if(fixup_get_svalue(msg, (gparam_p)p2, &nc)!=0)
1266
+	{
1267
+		LM_ERR("unable to get p2\n");
1268
+		return -1;
1269
+	}
1270
+	if(nc.s==NULL || nc.len == 0)
1271
+	{
1272
+		LM_ERR("invalid content-type parameter\n");
1273
+		return -1;
1274
+	}
1275
+
1276
+	/* add content-type */
1277
+	value_len = nc.len;
1278
+	len=sizeof("Content-Type: ") - 1 + value_len + CRLF_LEN;
1179 1279
 	buf=pkg_malloc(sizeof(char)*(len));
1280
+
1180 1281
 	if (buf==0)
1181 1282
 	{
1182 1283
 		LM_ERR("out of pkg memory\n");
1183 1284
 		return -1;
1184 1285
 	}
1185
-
1186
-	memcpy(buf, p1, len);
1187
-
1188
-	if (insert_new_lump_after(anchor, buf, len, 0) == 0)
1286
+	memcpy(buf, "Content-Type: ", sizeof("Content-Type: ") - 1);
1287
+	memcpy(buf+sizeof("Content-Type: ") - 1, nc.s, value_len);
1288
+	memcpy(buf+sizeof("Content-Type: ") - 1 + value_len, CRLF, CRLF_LEN);
1289
+	if (add_lump_rpl(msg, buf, len, LUMP_RPL_HDR) == 0)
1189 1290
 	{
1190
-		LM_ERR("failed to insert body lump\n");
1291
+		LM_ERR("failed to insert content-type lump\n");
1191 1292
 		pkg_free(buf);
1192 1293
 		return -1;
1193
-	} else {
1194
-		LM_DBG("inserted inserted body! [%s]", p1);
1195 1294
 	}
1295
+	pkg_free(buf);
1196 1296
 
1297
+	if (add_lump_rpl( msg, nb.s, nb.len, LUMP_RPL_BODY)==0) {
1298
+		LM_ERR("cannot add body lump\n");
1299
+		return -1;
1300
+	}
1301
+		
1197 1302
 	return 1;
1198 1303
 }
1199 1304
 
1200 1305
 
1306
+
1201 1307
 static int append_to_reply_f(struct sip_msg* msg, char* key, char* str0)
1202 1308
 {
1203 1309
 	str s0;