Skip to content

Instantly share code, notes, and snippets.

@ionutrazvanionita
Created January 27, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionutrazvanionita/1857e3b27d5c1e4906c1 to your computer and use it in GitHub Desktop.
Save ionutrazvanionita/1857e3b27d5c1e4906c1 to your computer and use it in GitHub Desktop.
B2B_entities patchV3(fixed is_CT_present function HDR_CONTENTTYPE_T insted of HDR_CONTENTTYPE_F)
diff --git a/modules/b2b_entities/dlg.c b/modules/b2b_entities/dlg.c
index ce3927d..3aaaeee 100644
--- a/modules/b2b_entities/dlg.c
+++ b/modules/b2b_entities/dlg.c
@@ -2738,11 +2738,24 @@ error1:
}
+static inline int is_CT_present(struct hdr_field* headers)
+{
+ struct hdr_field* hf;
+ for (hf=headers; hf; hf=hf->next) {
+ if (hf->type == HDR_CONTENTTYPE_T) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
int b2breq_complete_ehdr(str* extra_headers, str* ehdr_out, str* body,
str* local_contact)
{
- static char buf[BUF_LEN];
str ehdr= {NULL,0};
+ static char buf[BUF_LEN];
+ static struct sip_msg foo_msg;
if((extra_headers?extra_headers->len:0) + 14 + local_contact->len > BUF_LEN)
{
@@ -2759,18 +2772,33 @@ int b2breq_complete_ehdr(str* extra_headers, str* ehdr_out, str* body,
ehdr.len += sprintf(ehdr.s+ ehdr.len, "Contact: <%.*s>\r\n",
local_contact->len, local_contact->s);
+
+
/* if not present and body present add content type */
- if(body && !strstr(ehdr.s, "Content-Type:"))
- {
- /* add content type header */
- if(ehdr.len + 32 > BUF_LEN)
- {
- LM_ERR("Buffer too small, can not add Content-Type header\n");
+ if(body) {
+ /* build a fake sip_msg to parse the headers sip-wisely */
+ memset(&foo_msg, 0, sizeof(struct sip_msg));
+ foo_msg.len = ehdr.len;
+ foo_msg.buf = foo_msg.unparsed = ehdr.s;
+
+ if (parse_headers( &foo_msg, HDR_EOH_F, 0) == -1) {
+ LM_ERR("Failed to parse headers\n");
return -1;
}
- memcpy(ehdr.s+ ehdr.len, "Content-Type: application/sdp\r\n", 31);
- ehdr.len += 31;
- ehdr.s[ehdr.len]= '\0';
+
+ if (!is_CT_present(foo_msg.headers)) {
+ /* add content type header */
+ if(ehdr.len + 32 > BUF_LEN)
+ {
+ LM_ERR("Buffer too small, can not add Content-Type header\n");
+ return -1;
+ }
+ memcpy(ehdr.s+ ehdr.len, "Content-Type: application/sdp\r\n", 31);
+ ehdr.len += 31;
+ ehdr.s[ehdr.len]= '\0';
+ }
+
+ if (foo_msg.headers) free_hdr_field_lst(foo_msg.headers);
}
*ehdr_out = ehdr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment