Skip to content

Commit

Permalink
Fix codec handling functions when faulty streams are defined.
Browse files Browse the repository at this point in the history
Bogus test on the return code of stream_process() (using bitwise OR for -1, 0 and 1 values :O ), leads to a generic failure to find any codec in any stream if there is an invalid stream in the SDP.
For example, if a video stream is defined but with no codecs, stream_process() will return -1 for it (as it is a bogus stream). While iterating through all the stream (including the valid audio stream), the -1 ret code will discard any 1 future ret code due the bogus bitwise OR.

(cherry picked from commit ef82ca2)

Conflicts:
	modules/sipmsgops/codecs.c
  • Loading branch information
bogdan-iancu committed Jan 26, 2016
1 parent 16b63fd commit 41c8902
Showing 1 changed file with 40 additions and 75 deletions.
115 changes: 40 additions & 75 deletions modules/sipmsgops/codecs.c
Expand Up @@ -331,24 +331,23 @@ static int do_for_all_streams(struct sip_msg* msg, str* str1,str * str2,
}

cur_session = msg->sdp->sessions;
rez = 0;
rez = -1;

while(cur_session)
{
struct sdp_stream_cell * cur_cell = cur_session->streams;

while(cur_cell)
{
rez |= stream_process(msg,cur_cell,str1,str2,re,op,desc);
if(stream_process(msg,cur_cell,str1,str2,re,op,desc)==1)
rez = 1;
cur_cell = cur_cell->next;
}

cur_session = cur_session->next;

}

if( rez <0 )
rez = 0;
return rez;
}

Expand Down Expand Up @@ -685,35 +684,28 @@ int codec_find (struct sip_msg* msg, char* str1 )

LM_DBG("searching for codec <%.*s> \n",res.len,res.s);

if( do_for_all_streams( msg, &res, NULL, NULL,
FIND, DESC_NAME) == 0)
return -1;

return 1;

return do_for_all_streams( msg, &res, NULL, NULL,
FIND, DESC_NAME);
}

int codec_find_re (struct sip_msg* msg, char* str1 )
{
regex_t *re;
int do_free;
int ret;

re = fixup_get_regex(msg,(gparam_p)str1,&do_free);
if (!re) {
LM_ERR("Failed to get regular expression \n");
return -1;
}

if( do_for_all_streams(msg, NULL, NULL, re,
FIND, DESC_REGEXP) == 0) {
if (do_free)
fixup_free_regexp((void **)&re);
return -1;
}

ret = do_for_all_streams(msg, NULL, NULL, re,
FIND, DESC_REGEXP);

if (do_free)
fixup_free_regexp((void **)&re);
return 1;
return ret;
}


Expand All @@ -736,11 +728,8 @@ int codec_find_clock (struct sip_msg* msg, char* str1,char * str2 )
LM_DBG("searching for codec <%.*s> with clock <%.*s> \n",
codec.len,codec.s,clock.len,clock.s);

if( do_for_all_streams( msg, &codec, &clock, NULL,
FIND, DESC_NAME_AND_CLOCK) == 0)
return -1;

return 1;
return do_for_all_streams( msg, &codec, &clock, NULL,
FIND, DESC_NAME_AND_CLOCK);
}


Expand All @@ -756,58 +745,50 @@ int codec_delete (struct sip_msg* msg, char* str1 )

LM_DBG("deleting codec <%.*s> \n",res.len,res.s);

if( do_for_all_streams( msg, &res, NULL, NULL,
DELETE, DESC_NAME) == 0)
return -1;
return 1;
return do_for_all_streams( msg, &res, NULL, NULL,
DELETE, DESC_NAME);
}


int codec_delete_re (struct sip_msg* msg, char* str1 )
{
regex_t *re;
int do_free;
int ret;

re = fixup_get_regex(msg,(gparam_p)str1,&do_free);
if (!re) {
LM_ERR("Failed to get regular expression \n");
return -1;
}

if( do_for_all_streams( msg, NULL, NULL, re,
DELETE, DESC_REGEXP) == 0) {
if (do_free)
fixup_free_regexp((void **)&re);
return -1;
}
ret = do_for_all_streams( msg, NULL, NULL, re,
DELETE, DESC_REGEXP);

if (do_free)
fixup_free_regexp((void **)&re);
return 1;
return ret;
}


int codec_delete_except_re (struct sip_msg* msg, char* str1 )
{
regex_t *re;
int do_free;
int ret;

re = fixup_get_regex(msg,(gparam_p)str1,&do_free);
if (!re) {
LM_ERR("Failed to get regular expression \n");
return -1;
}

if( do_for_all_streams( msg, NULL, NULL, re,
DELETE, DESC_REGEXP_COMPLEMENT) == 0) {
if (do_free)
fixup_free_regexp((void **)&re);
return -1;
}
ret = do_for_all_streams( msg, NULL, NULL, re,
DELETE, DESC_REGEXP_COMPLEMENT);

if (do_free)
fixup_free_regexp((void **)&re);
return 1;
return ret;
}


Expand All @@ -830,10 +811,8 @@ int codec_delete_clock (struct sip_msg* msg, char* str1 ,char * str2)
LM_DBG("deleting codec <%.*s> with clock <%.*s> \n",
codec.len,codec.s,clock.len,clock.s);

if( do_for_all_streams( msg, &codec, &clock, NULL,
DELETE, DESC_NAME_AND_CLOCK) == 0)
return -1;
return 1;
return do_for_all_streams( msg, &codec, &clock, NULL,
DELETE, DESC_NAME_AND_CLOCK);
}


Expand All @@ -849,34 +828,29 @@ int codec_move_up (struct sip_msg* msg, char* str1)

LM_DBG("moving up codec <%.*s> \n",res.len,res.s);

if( do_for_all_streams( msg, &res, NULL, NULL,
ADD_TO_FRONT, DESC_NAME) == 0)
return -1;
return 1;
return do_for_all_streams( msg, &res, NULL, NULL,
ADD_TO_FRONT, DESC_NAME);
}


int codec_move_up_re (struct sip_msg* msg, char* str1)
{
regex_t *re;
int do_free;
int ret;

re = fixup_get_regex(msg,(gparam_p)str1,&do_free);
if (!re) {
LM_ERR("Failed to get regular expression \n");
return -1;
}

if( do_for_all_streams( msg, NULL, NULL, re,
ADD_TO_FRONT, DESC_REGEXP) == 0) {
if (do_free)
fixup_free_regexp((void **)&re);
return -1;
}
ret = do_for_all_streams( msg, NULL, NULL, re,
ADD_TO_FRONT, DESC_REGEXP);

if (do_free)
fixup_free_regexp((void **)&re);
return 1;
return ret;
}


Expand All @@ -899,10 +873,8 @@ int codec_move_up_clock (struct sip_msg* msg, char* str1 ,char * str2)
LM_DBG("moving up codec <%.*s> with clock <%.*s> \n",
codec.len,codec.s,clock.len,clock.s);

if( do_for_all_streams( msg, &codec, &clock, NULL,
ADD_TO_FRONT, DESC_NAME_AND_CLOCK) == 0)
return -1;
return 1;
return do_for_all_streams( msg, &codec, &clock, NULL,
ADD_TO_FRONT, DESC_NAME_AND_CLOCK);
}


Expand All @@ -918,34 +890,29 @@ int codec_move_down (struct sip_msg* msg, char* str1)

LM_DBG("moving down codec <%.*s> \n",res.len,res.s);

if( do_for_all_streams( msg, &res, NULL, NULL,
ADD_TO_BACK, DESC_NAME) == 0)
return -1;
return 1;
return do_for_all_streams( msg, &res, NULL, NULL,
ADD_TO_BACK, DESC_NAME);
}


int codec_move_down_re (struct sip_msg* msg, char* str1)
{
regex_t *re;
int do_free;
int ret;

re = fixup_get_regex(msg,(gparam_p)str1,&do_free);
if (!re) {
LM_ERR("Failed to get regular expression \n");
return -1;
}

if( do_for_all_streams( msg, NULL, NULL, re,
ADD_TO_BACK, DESC_REGEXP) == 0) {
if (do_free)
fixup_free_regexp((void **)&re);
return -1;
}
ret = do_for_all_streams( msg, NULL, NULL, re,
ADD_TO_BACK, DESC_REGEXP);

if (do_free)
fixup_free_regexp((void **)&re);
return 1;
return ret;
}


Expand All @@ -968,10 +935,8 @@ int codec_move_down_clock (struct sip_msg* msg, char* str1 ,char * str2)
LM_DBG("moving down codec <%.*s> with clock <%.*s> \n",
codec.len,codec.s,clock.len,clock.s);

if( do_for_all_streams( msg, &codec, &clock, NULL,
ADD_TO_BACK, DESC_NAME_AND_CLOCK) == 0)
return -1;
return 1;
return do_for_all_streams( msg, &codec, &clock, NULL,
ADD_TO_BACK, DESC_NAME_AND_CLOCK);
}


Expand Down

0 comments on commit 41c8902

Please sign in to comment.