Skip to content

Commit 41c8902

Browse files
committed
Fix codec handling functions when faulty streams are defined.
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
1 parent 16b63fd commit 41c8902

File tree

1 file changed

+40
-75
lines changed

1 file changed

+40
-75
lines changed

modules/sipmsgops/codecs.c

Lines changed: 40 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -331,24 +331,23 @@ static int do_for_all_streams(struct sip_msg* msg, str* str1,str * str2,
331331
}
332332

333333
cur_session = msg->sdp->sessions;
334-
rez = 0;
334+
rez = -1;
335335

336336
while(cur_session)
337337
{
338338
struct sdp_stream_cell * cur_cell = cur_session->streams;
339339

340340
while(cur_cell)
341341
{
342-
rez |= stream_process(msg,cur_cell,str1,str2,re,op,desc);
342+
if(stream_process(msg,cur_cell,str1,str2,re,op,desc)==1)
343+
rez = 1;
343344
cur_cell = cur_cell->next;
344345
}
345346

346347
cur_session = cur_session->next;
347348

348349
}
349350

350-
if( rez <0 )
351-
rez = 0;
352351
return rez;
353352
}
354353

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

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

688-
if( do_for_all_streams( msg, &res, NULL, NULL,
689-
FIND, DESC_NAME) == 0)
690-
return -1;
691-
692-
return 1;
693-
687+
return do_for_all_streams( msg, &res, NULL, NULL,
688+
FIND, DESC_NAME);
694689
}
695690

696691
int codec_find_re (struct sip_msg* msg, char* str1 )
697692
{
698693
regex_t *re;
699694
int do_free;
695+
int ret;
700696

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

707-
if( do_for_all_streams(msg, NULL, NULL, re,
708-
FIND, DESC_REGEXP) == 0) {
709-
if (do_free)
710-
fixup_free_regexp((void **)&re);
711-
return -1;
712-
}
713-
703+
ret = do_for_all_streams(msg, NULL, NULL, re,
704+
FIND, DESC_REGEXP);
705+
714706
if (do_free)
715707
fixup_free_regexp((void **)&re);
716-
return 1;
708+
return ret;
717709
}
718710

719711

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

739-
if( do_for_all_streams( msg, &codec, &clock, NULL,
740-
FIND, DESC_NAME_AND_CLOCK) == 0)
741-
return -1;
742-
743-
return 1;
731+
return do_for_all_streams( msg, &codec, &clock, NULL,
732+
FIND, DESC_NAME_AND_CLOCK);
744733
}
745734

746735

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

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

759-
if( do_for_all_streams( msg, &res, NULL, NULL,
760-
DELETE, DESC_NAME) == 0)
761-
return -1;
762-
return 1;
748+
return do_for_all_streams( msg, &res, NULL, NULL,
749+
DELETE, DESC_NAME);
763750
}
764751

765752

766753
int codec_delete_re (struct sip_msg* msg, char* str1 )
767754
{
768755
regex_t *re;
769756
int do_free;
757+
int ret;
770758

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

777-
if( do_for_all_streams( msg, NULL, NULL, re,
778-
DELETE, DESC_REGEXP) == 0) {
779-
if (do_free)
780-
fixup_free_regexp((void **)&re);
781-
return -1;
782-
}
765+
ret = do_for_all_streams( msg, NULL, NULL, re,
766+
DELETE, DESC_REGEXP);
783767

784768
if (do_free)
785769
fixup_free_regexp((void **)&re);
786-
return 1;
770+
return ret;
787771
}
788772

789773

790774
int codec_delete_except_re (struct sip_msg* msg, char* str1 )
791775
{
792776
regex_t *re;
793777
int do_free;
778+
int ret;
794779

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

801-
if( do_for_all_streams( msg, NULL, NULL, re,
802-
DELETE, DESC_REGEXP_COMPLEMENT) == 0) {
803-
if (do_free)
804-
fixup_free_regexp((void **)&re);
805-
return -1;
806-
}
786+
ret = do_for_all_streams( msg, NULL, NULL, re,
787+
DELETE, DESC_REGEXP_COMPLEMENT);
807788

808789
if (do_free)
809790
fixup_free_regexp((void **)&re);
810-
return 1;
791+
return ret;
811792
}
812793

813794

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

833-
if( do_for_all_streams( msg, &codec, &clock, NULL,
834-
DELETE, DESC_NAME_AND_CLOCK) == 0)
835-
return -1;
836-
return 1;
814+
return do_for_all_streams( msg, &codec, &clock, NULL,
815+
DELETE, DESC_NAME_AND_CLOCK);
837816
}
838817

839818

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

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

852-
if( do_for_all_streams( msg, &res, NULL, NULL,
853-
ADD_TO_FRONT, DESC_NAME) == 0)
854-
return -1;
855-
return 1;
831+
return do_for_all_streams( msg, &res, NULL, NULL,
832+
ADD_TO_FRONT, DESC_NAME);
856833
}
857834

858835

859836
int codec_move_up_re (struct sip_msg* msg, char* str1)
860837
{
861838
regex_t *re;
862839
int do_free;
840+
int ret;
863841

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

870-
if( do_for_all_streams( msg, NULL, NULL, re,
871-
ADD_TO_FRONT, DESC_REGEXP) == 0) {
872-
if (do_free)
873-
fixup_free_regexp((void **)&re);
874-
return -1;
875-
}
848+
ret = do_for_all_streams( msg, NULL, NULL, re,
849+
ADD_TO_FRONT, DESC_REGEXP);
876850

877851
if (do_free)
878852
fixup_free_regexp((void **)&re);
879-
return 1;
853+
return ret;
880854
}
881855

882856

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

902-
if( do_for_all_streams( msg, &codec, &clock, NULL,
903-
ADD_TO_FRONT, DESC_NAME_AND_CLOCK) == 0)
904-
return -1;
905-
return 1;
876+
return do_for_all_streams( msg, &codec, &clock, NULL,
877+
ADD_TO_FRONT, DESC_NAME_AND_CLOCK);
906878
}
907879

908880

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

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

921-
if( do_for_all_streams( msg, &res, NULL, NULL,
922-
ADD_TO_BACK, DESC_NAME) == 0)
923-
return -1;
924-
return 1;
893+
return do_for_all_streams( msg, &res, NULL, NULL,
894+
ADD_TO_BACK, DESC_NAME);
925895
}
926896

927897

928898
int codec_move_down_re (struct sip_msg* msg, char* str1)
929899
{
930900
regex_t *re;
931901
int do_free;
902+
int ret;
932903

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

939-
if( do_for_all_streams( msg, NULL, NULL, re,
940-
ADD_TO_BACK, DESC_REGEXP) == 0) {
941-
if (do_free)
942-
fixup_free_regexp((void **)&re);
943-
return -1;
944-
}
910+
ret = do_for_all_streams( msg, NULL, NULL, re,
911+
ADD_TO_BACK, DESC_REGEXP);
945912

946913
if (do_free)
947914
fixup_free_regexp((void **)&re);
948-
return 1;
915+
return ret;
949916
}
950917

951918

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

971-
if( do_for_all_streams( msg, &codec, &clock, NULL,
972-
ADD_TO_BACK, DESC_NAME_AND_CLOCK) == 0)
973-
return -1;
974-
return 1;
938+
return do_for_all_streams( msg, &codec, &clock, NULL,
939+
ADD_TO_BACK, DESC_NAME_AND_CLOCK);
975940
}
976941

977942

0 commit comments

Comments
 (0)