i wrote new version of sdp_content() test that does not parse the whole sdp like the current one does. instead it checks if request has a body and content type is either missing or it is application/sdp or content type is multipart/mixed and boxy has string application/sdp.
could this one replace the current one or do i need to invent a new name for it?
the implementation also includes new general purpose function strnistr, equivalent of which i did not find in kamailio source.
-- juha
------------------------------------------------------------------
/* * Find the first case insensitive occurrence of find in s, where the * search is limited to the first slen characters of s. Idea stolen from * FreeBSD. */ char* strnistr(const char *s, const char *find, size_t slen) { char c, sc; size_t len;
if ((c = *find++) != '\0') { len = strlen(find); do { do { if ((sc = *s++) == '\0' || slen-- < 1) return (NULL); } while (sc != c); if (len > slen) return (NULL); } while (strncasecmp(s, find, len) != 0); s--; } return ((char *)s); }
/** * */ static int w_sdp_content(sip_msg_t* msg, char* foo, char *bar) { str body; int mime;
body.s = get_body(msg); if (body.s == NULL) return -1; body.len = msg->len - (int)(body.s - msg->buf); if (body.len == 0) return -1;
mime = parse_content_type_hdr(msg); if (mime < 0) return -1; /* error */ if (mime == 0) return 1; /* default is application/sdp */
switch (((unsigned int)mime) >> 16) { case TYPE_APPLICATION: if ((mime & 0x00ff) == SUBTYPE_SDP) return 1; else return -1; case TYPE_MULTIPART: if ((mime & 0x00ff) == SUBTYPE_MIXED) { if (strnistr(body.s, "application/sdp", body.len) == NULL) { return -1; } else { return 1; } } else { return -1; } default: return -1; } }
Maybe the parsing or not of sdp can be done based on a parameter:
sdp_content(mode)
If missing or mode==0, then do one way and when is 1 do the other way.
I think still having the ability to parse is good, because it makes sure that the sdp is valid and it is quite common that later it will be parsed anyhow (e.g., for rtp proxying).
I would like to ask to change the comment for the strnistr() -- 'stolen from FreeBSD' sounds a bit rough, to reflect the origin of the code/idea, it would be better something like: code (or idea) taken (or borrowed) from FreeBSD.
Cheers, Daniel
On 12/11/15 14:21, Juha Heinanen wrote:
i wrote new version of sdp_content() test that does not parse the whole sdp like the current one does. instead it checks if request has a body and content type is either missing or it is application/sdp or content type is multipart/mixed and boxy has string application/sdp.
could this one replace the current one or do i need to invent a new name for it?
the implementation also includes new general purpose function strnistr, equivalent of which i did not find in kamailio source.
-- juha
/*
- Find the first case insensitive occurrence of find in s, where the
- search is limited to the first slen characters of s. Idea stolen from
- FreeBSD.
*/ char* strnistr(const char *s, const char *find, size_t slen) { char c, sc; size_t len;
if ((c = *find++) != '\0') { len = strlen(find); do { do { if ((sc = *s++) == '\0' || slen-- < 1) return (NULL); } while (sc != c); if (len > slen) return (NULL); } while (strncasecmp(s, find, len) != 0); s--; } return ((char *)s);
}
/**
*/ static int w_sdp_content(sip_msg_t* msg, char* foo, char *bar) { str body; int mime;
body.s = get_body(msg); if (body.s == NULL) return -1; body.len = msg->len - (int)(body.s - msg->buf); if (body.len == 0) return -1; mime = parse_content_type_hdr(msg); if (mime < 0) return -1; /* error */ if (mime == 0) return 1; /* default is application/sdp */ switch (((unsigned int)mime) >> 16) { case TYPE_APPLICATION: if ((mime & 0x00ff) == SUBTYPE_SDP) return 1; else return -1; case TYPE_MULTIPART: if ((mime & 0x00ff) == SUBTYPE_MIXED) { if (strnistr(body.s, "application/sdp", body.len) == NULL) { return -1; } else { return 1; } } else { return -1; } default: return -1; }
}
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Daniel-Constantin Mierla writes:
I think still having the ability to parse is good, because it makes sure that the sdp is valid and it is quite common that later it will be parsed anyhow (e.g., for rtp proxying).
based on my reading of rtpengine_offer/answer, they do not parse the body and that is the whole point of this exercise.
-- juha
ps. while reading rtpengine_offer/answer code, i found this:
if (!msg->content_type) { LM_WARN("the header Content-TYPE is absent!" "let's assume the content is text/plain ;-)\n"); return 1; }
my impression is that if content-type header is missing, the default is application/sdp.
On 12/11/15 15:08, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
I think still having the ability to parse is good, because it makes sure that the sdp is valid and it is quite common that later it will be parsed anyhow (e.g., for rtp proxying).
based on my reading of rtpengine_offer/answer, they do not parse the body and that is the whole point of this exercise.
-- juha
ps. while reading rtpengine_offer/answer code, i found this:
if (!msg->content_type) { LM_WARN("the header Content-TYPE is absent!" "let's assume the content is text/plain ;-)\n"); return 1; }
my impression is that if content-type header is missing, the default is application/sdp.
Haven't looked at rtpengine module, but rtpproxy module is using the sdp parser and that is still very common out there (including the default kamailio.cfg). I still see the need of a way to assert that sdp body is correct and I use it to be sure the entire invite is correct, along with checks from sanity module.
Also, there is another function that checks the type of the body:
has_body("application/sdp")
Not sure if that works for multi-part body.
Cheers, Daniel