(cherry picked from commit aaec020b5cd033a7d7821dd4a3e447405bbbecad)
... | ... |
@@ -734,3 +734,95 @@ int remove_lump(sip_msg_t *msg, struct lump *l) |
734 | 734 |
} |
735 | 735 |
return 0; |
736 | 736 |
} |
737 |
+ |
|
738 |
+/** |
|
739 |
+ * |
|
740 |
+ */ |
|
741 |
+int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody) |
|
742 |
+{ |
|
743 |
+ struct lump* anchor; |
|
744 |
+ str h; |
|
745 |
+ str sname; |
|
746 |
+ str sbody; |
|
747 |
+ |
|
748 |
+ sname.s = hname; |
|
749 |
+ sname.len = strlen(sname.s); |
|
750 |
+ sbody.s = hbody; |
|
751 |
+ sbody.len = strlen(sbody.s); |
|
752 |
+ |
|
753 |
+ h.len = sname.len + 2 + sbody.len + 1 + CRLF_LEN; |
|
754 |
+ h.s = (char*)pkg_malloc(h.len+1); |
|
755 |
+ if(h.s == 0) { |
|
756 |
+ LM_ERR("no more pkg\n"); |
|
757 |
+ return -1; |
|
758 |
+ } |
|
759 |
+ anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0); |
|
760 |
+ if(anchor == 0) |
|
761 |
+ { |
|
762 |
+ LM_ERR("cannot get the anchor\n"); |
|
763 |
+ pkg_free(h.s); |
|
764 |
+ return -1; |
|
765 |
+ } |
|
766 |
+ memcpy(h.s, sname.s, sname.len); |
|
767 |
+ memcpy(h.s+sname.len, ": ", 2); |
|
768 |
+ memcpy(h.s+sname.len+2, sbody.s, sbody.len); |
|
769 |
+ memcpy(h.s+sname.len+2+sbody.len+1, CRLF, CRLF_LEN); |
|
770 |
+ h.s[h.len] = '\0'; |
|
771 |
+ if (insert_new_lump_before(anchor, h.s, h.len, 0) == 0) |
|
772 |
+ { |
|
773 |
+ LM_ERR("cannot insert lump\n"); |
|
774 |
+ pkg_free(h.s); |
|
775 |
+ return -1; |
|
776 |
+ } |
|
777 |
+ LM_DBG("added new header [%s]\n", h.s); |
|
778 |
+ return 0; |
|
779 |
+} |
|
780 |
+ |
|
781 |
+/** |
|
782 |
+ * |
|
783 |
+ */ |
|
784 |
+hdr_field_t *sr_hdr_get_z(sip_msg_t *msg, char *hname) |
|
785 |
+{ |
|
786 |
+ hdr_field_t *hf; |
|
787 |
+ str sname; |
|
788 |
+ |
|
789 |
+ sname.s = hname; |
|
790 |
+ sname.len = strlen(sname.s); |
|
791 |
+ |
|
792 |
+ for (hf=msg->headers; hf; hf=hf->next) { |
|
793 |
+ if (hf->name.len==sname.len |
|
794 |
+ && strncasecmp(hf->name.s, sname.s, |
|
795 |
+ sname.len)==0) { |
|
796 |
+ return hf; |
|
797 |
+ |
|
798 |
+ } |
|
799 |
+ } |
|
800 |
+ return NULL; |
|
801 |
+} |
|
802 |
+ |
|
803 |
+/** |
|
804 |
+ * |
|
805 |
+ */ |
|
806 |
+int sr_hdr_del_z(sip_msg_t *msg, char *hname) |
|
807 |
+{ |
|
808 |
+ hdr_field_t *hf; |
|
809 |
+ struct lump* l; |
|
810 |
+ str sname; |
|
811 |
+ |
|
812 |
+ sname.s = hname; |
|
813 |
+ sname.len = strlen(sname.s); |
|
814 |
+ |
|
815 |
+ for (hf=msg->headers; hf; hf=hf->next) { |
|
816 |
+ if (hf->name.len==sname.len |
|
817 |
+ && strncasecmp(hf->name.s, sname.s, |
|
818 |
+ sname.len)==0) { |
|
819 |
+ l=del_lump(msg, hf->name.s-msg->buf, hf->len, 0); |
|
820 |
+ if (l==0) { |
|
821 |
+ LM_ERR("unable to delete cookie header\n"); |
|
822 |
+ return -1; |
|
823 |
+ } |
|
824 |
+ return 0; |
|
825 |
+ } |
|
826 |
+ } |
|
827 |
+ return 0; |
|
828 |
+} |
... | ... |
@@ -86,4 +86,9 @@ void del_nonshm_lump( struct lump** lump_list ); |
86 | 86 |
|
87 | 87 |
/*! \brief remove the lump from the internal lists */ |
88 | 88 |
int remove_lump(sip_msg_t *msg, struct lump *l); |
89 |
+ |
|
90 |
+int sr_hdr_add_zz(sip_msg_t *msg, char *hname, char *hbody); |
|
91 |
+int sr_hdr_del_z(sip_msg_t *msg, char *hname); |
|
92 |
+hdr_field_t *sr_hdr_get_z(sip_msg_t *msg, char *hname); |
|
93 |
+ |
|
89 | 94 |
#endif |