Skip to content

Commit

Permalink
When iterating through the parts for doing changes, avoid the new or …
Browse files Browse the repository at this point in the history
…deleted parts.
  • Loading branch information
bogdan-iancu committed Oct 28, 2016
1 parent cba64bc commit 15b12f5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
12 changes: 10 additions & 2 deletions modules/emergency/sip_emergency.c
Expand Up @@ -41,7 +41,6 @@ const char *LOCATION_TAG_BEGIN = "<location-key>";
const char *LOCATION_TAG_END = "</location-key>";
const char *NEW_LINE = "\n";

const char *CONTENT_TYPE_PIDF = "Content-Type: application/pidf+xml";
const char *PRESENCE_START = "<presence";
const char *PRESENCE_END = "/presence>";

Expand All @@ -52,6 +51,9 @@ const char *EVENT_TYPE = "dialog";
const char *CALLID_PARAM = "call-id=";
const char *FROMTAG_PARAM = ";from-tag=";


#define MIME_PIDF "application/pidf+xml"
#define MIME_PIDF_LEN (sizeof(MIME_PIDF)-1)
#define PAI_SUFFIX ";user=phone;CBN="
#define PAI_SUFFIX_LEN (sizeof(PAI_SUFFIX)-1)
#define PAI_SUFFIX_II ";user=phone>\n"
Expand Down Expand Up @@ -897,10 +899,16 @@ int find_body_pidf(struct sip_msg *msg, char** pidf_body) {

mbody_part = &msg->body->first;
while (mbody_part != NULL) {

/* skip body parts which were deleted or newly added */
if (!is_body_part_received(mbody_part))
continue;

LM_DBG(" --- PIDF BODY %.*s", mbody_part->body.len, mbody_part->body.s);
LM_DBG(" --- PIDF BODY COUNT %d", ++cont);

if (strstr(mbody_part->body.s, CONTENT_TYPE_PIDF) != NULL) {
if ( mbody_part->mime_s.len==MIME_PIDF_LEN &&
memcmp(mbody_part->mime_s.s, MIME_PIDF, mbody_part->mime_s.len)==0 ) {
body_start = strstr(mbody_part->body.s, PRESENCE_START);
body_end = strstr(mbody_part->body.s, PRESENCE_END);
size_body = body_end - body_start + 11;
Expand Down
8 changes: 8 additions & 0 deletions modules/nathelper/nathelper.c
Expand Up @@ -819,6 +819,10 @@ sdp_1918(struct sip_msg* msg)

for ( p=&msg->body->first ; p ; p=p->next) {

/* skip body parts which were deleted or newly added */
if (!is_body_part_received(p))
continue;

body = p->body;
trim_r(body);

Expand Down Expand Up @@ -1162,6 +1166,10 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)

for ( p=&msg->body->first ; p ; p=p->next )
{
/* skip body parts which were deleted or newly added */
if (!is_body_part_received(p))
continue;

body = p->body;
trim_r(body);
if( p->mime != ((TYPE_APPLICATION << 16) + SUBTYPE_SDP)
Expand Down
3 changes: 2 additions & 1 deletion modules/rtpengine/rtpengine.c
Expand Up @@ -321,7 +321,8 @@ int msg_has_sdp(struct sip_msg *msg)
}

for (p = &msg->body->first; p; p = p->next) {
if (p->mime == ((TYPE_APPLICATION << 16) + SUBTYPE_SDP))
if ( is_body_part_received(p) &&
p->mime == ((TYPE_APPLICATION << 16) + SUBTYPE_SDP) )
return 1;
}

Expand Down
4 changes: 4 additions & 0 deletions modules/rtpengine/rtpengine_funcs.c
Expand Up @@ -171,6 +171,10 @@ int extract_body(struct sip_msg *msg, str *body )

for ( p=&msg->body->first ; p ; p=p->next )
{
/* skip body parts which were deleted or newly added */
if (!is_body_part_received(p))
continue;

*body = p->body;
trim_r(*body);
if( p->mime != ((TYPE_APPLICATION << 16) + SUBTYPE_SDP)
Expand Down
8 changes: 7 additions & 1 deletion modules/rtpproxy/rtpproxy.c
Expand Up @@ -3001,7 +3001,8 @@ int msg_has_sdp(struct sip_msg *msg)
}

for (p = &msg->body->first; p; p = p->next) {
if (p->mime == ((TYPE_APPLICATION << 16) + SUBTYPE_SDP))
if ( is_body_part_received(p) &&
p->mime == ((TYPE_APPLICATION << 16) + SUBTYPE_SDP) )
return 1;
}

Expand Down Expand Up @@ -3293,6 +3294,11 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, char *setid,
for (p = &msg->body->first; p != NULL; p = p->next)
{
int ret = 0;

/* skip body parts which were deleted or newly added */
if (!is_body_part_received(p))
continue;

if (p->mime != ((TYPE_APPLICATION << 16) + SUBTYPE_SDP))
continue;
if (p->body.len == 0) {
Expand Down
5 changes: 5 additions & 0 deletions parser/parse_body.h
Expand Up @@ -71,6 +71,11 @@ struct body_part{
struct body_part * next;
};

#define is_body_part_received(_part) \
(((_part)->flags&(SIP_BODY_PART_FLAG_NEW|SIP_BODY_PART_FLAG_DELETED))==0)
#define is_body_part_deleted(_part) \
(((_part)->flags&SIP_BODY_PART_FLAG_DELETED)!=0)


#define SIP_BODY_FLAG_NEW (1<<0)

Expand Down
4 changes: 4 additions & 0 deletions parser/sdp/sdp.c
Expand Up @@ -570,6 +570,10 @@ sdp_info_t* parse_sdp(struct sip_msg* _m)
/* iterate all body parts and look for the SDP mime */
for( part=&_m->body->first ; part ; part=part->next) {

/* skip body parts which were deleted or newly added */
if (!is_body_part_received(part))
continue;

if ( part->mime != ((TYPE_APPLICATION<<16)+SUBTYPE_SDP) )
continue;

Expand Down

0 comments on commit 15b12f5

Please sign in to comment.