@@ -95,7 +95,6 @@ static inline int _th_no_dlg_onrequest(struct sip_msg *, uint16_t);
9595static void th_no_dlg_onreply (struct cell * , int , struct tmcb_params * );
9696static int th_no_dlg_seq_handling (struct sip_msg * , str * , decode_info_fn );
9797static inline int th_no_dlg_one_way_hiding (const struct socket_info * );
98- static inline int topo_no_dlg_classify_route (rr_t [static 1 ]);
9998static int th_no_dlg_add_auto_record_route (struct sip_msg * , int , char []);
10099static int th_no_dlg_match_record_route_or_route_uris (struct sip_msg * , struct sip_msg * , hdr_types_t );
101100
@@ -150,7 +149,7 @@ static int th_no_dlg_auto_route_seq_handling(struct sip_msg *msg, rr_t auto_rout
150149
151150 if (dec_len <= 0 ) {
152151 LM_ERR ("Failed to decode\n" );
153- return -1 ;
152+ return TOPOH_MATCH_FAILURE ;
154153 }
155154
156155 LM_DBG ("Size of base64 decoded length %d and size of param len %d\n" , dec_len , thinfo -> len );
@@ -160,7 +159,7 @@ static int th_no_dlg_auto_route_seq_handling(struct sip_msg *msg, rr_t auto_rout
160159
161160 if (get_uri_count (& decoded_uri_buf ) != 0 ) {
162161 LM_ERR ("Encoded URI count is invalid, can only be 0 in auto Route\n" );
163- return -1 ;
162+ return TOPOH_MATCH_FAILURE ;
164163 }
165164
166165 flags = get_flags (& decoded_uri_buf );
@@ -186,17 +185,17 @@ static int th_no_dlg_auto_route_seq_handling(struct sip_msg *msg, rr_t auto_rout
186185
187186 if (topo_delete_record_route_uris (msg , 0 ) < 0 ) {
188187 LM_ERR ("Failed to remove Record Route header \n" );
189- return -1 ;
188+ return TOPOH_MATCH_FAILURE ;
190189 }
191190
192191 if (topo_delete_vias (msg ) < 0 ) {
193192 LM_ERR ("Failed to remove via headers\n" );
194- return -1 ;
193+ return TOPOH_MATCH_FAILURE ;
195194 }
196195
197196 if (th_no_dlg_encode_contact (msg , flags , NULL , 0 ) < 0 ) {
198197 LM_ERR ("Failed to encode contact header\n" );
199- return -1 ;
198+ return TOPOH_MATCH_FAILURE ;
200199 }
201200
202201 after_auto = auto_route -> next ;
@@ -208,7 +207,7 @@ static int th_no_dlg_auto_route_seq_handling(struct sip_msg *msg, rr_t auto_rout
208207
209208 if (after_auto != NULL && set_dst_uri (msg , & after_auto -> nameaddr .uri ) != 0 ) {
210209 LM_ERR ("Error set_dst_uri\n" );
211- return -1 ;
210+ return TOPOH_MATCH_FAILURE ;
212211 }
213212
214213 tm_api .set_tmcb_flags (flags );
@@ -926,38 +925,12 @@ static inline void topo_no_dlg_seq_free(void *p) {
926925 shm_free (p );
927926}
928927
929- static inline int topo_no_dlg_classify_route (rr_t * head ) {
930- struct sip_uri rr_uri ;
931- int flags = 0 ;
932-
933- if (parse_uri (head -> nameaddr .uri .s , head -> nameaddr .uri .len , & rr_uri ) < 0 ) {
934- LM_ERR ("Failed to parse SIP uri\n" );
935- return -1 ;
936- }
937-
938- if (!is_strict (& rr_uri .params )) {
939- flags |= ROUTE_LOOSE ;
940- } else {
941- flags |= ROUTE_STRICT ;
942- }
943-
944- // TODO refactor this
945- if (check_self (& rr_uri .host , rr_uri .port_no ? rr_uri .port_no : SIP_PORT , 0 ) == 1 ) {
946- flags |= ROUTE_SELF ;
947- }
948-
949- if (is_2rr (& rr_uri .params )) {
950- flags |= ROUTE_DOUBLE_RR ;
951- }
952-
953- return flags ;
954- }
955-
956928static inline int topo_no_dlg_route (struct sip_msg * msg , str rr_buf [static 1 ]) {
957929 rr_t * head = NULL , * rrp = NULL ;
930+ struct sip_uri rr_uri ;
958931 char * route = NULL , * hdrs = NULL ;
959932 int size = 0 , start_index = 0 ;
960- int route_flags ;
933+ int route_flags = 0 ;
961934 struct lump * lmp = NULL ;
962935
963936 if (parse_rr_body (rr_buf -> s , rr_buf -> len , & head ) != 0 ) {
@@ -967,7 +940,21 @@ static inline int topo_no_dlg_route(struct sip_msg *msg, str rr_buf[static 1]) {
967940 }
968941
969942 rrp = head ;
970- route_flags = topo_no_dlg_classify_route (rrp );
943+
944+ if (parse_uri (head -> nameaddr .uri .s , head -> nameaddr .uri .len , & rr_uri ) < 0 ) {
945+ LM_ERR ("Failed to parse SIP uri\n" );
946+ return -1 ;
947+ }
948+
949+ if (!is_strict (& rr_uri .params )) {
950+ route_flags |= ROUTE_LOOSE ;
951+ } else {
952+ route_flags |= ROUTE_STRICT ;
953+ }
954+
955+ if (is_2rr (& rr_uri .params )) {
956+ route_flags |= ROUTE_DOUBLE_RR ;
957+ }
971958
972959 if (route_flags & (ROUTE_STRICT | ROUTE_SELF )) {
973960 LM_DBG ("First Route header is a strict router\n" );
@@ -1026,8 +1013,9 @@ static inline int topo_no_dlg_route(struct sip_msg *msg, str rr_buf[static 1]) {
10261013 return route_flags ;
10271014}
10281015
1029- static inline int topo_no_dlg_rewrite_contact_as_next_route (struct sip_msg * msg , const str contact_buf [static 1 ], struct lump lmp [ static 1 ] ) {
1016+ static inline int topo_no_dlg_rewrite_contact_as_next_route (struct sip_msg * msg , const str contact_buf [static 1 ]) {
10301017 char * remote_contact = NULL ;
1018+ struct lump * lmp = NULL ;
10311019 int size = 0 ;
10321020
10331021 size = contact_buf -> len + ROUTE_PREF_LEN + ROUTE_SUFF_LEN ;
@@ -1045,6 +1033,8 @@ static inline int topo_no_dlg_rewrite_contact_as_next_route(struct sip_msg *msg,
10451033 LM_DBG ("Adding remote contact route header : [%.*s]\n" ,
10461034 size , remote_contact );
10471035
1036+ lmp = anchor_lump (msg , msg -> headers -> name .s - msg -> buf , HDR_ROUTE_T );
1037+
10481038 if (insert_new_lump_after (lmp , remote_contact , size , HDR_ROUTE_T ) == 0 ) {
10491039 LM_ERR ("failed inserting remote contact route\n" );
10501040 pkg_free (remote_contact );
@@ -1261,29 +1251,27 @@ static int th_no_dlg_seq_handling(struct sip_msg *msg, str *info, decode_info_fn
12611251 return -1 ;
12621252 }
12631253
1264- if (rr_buf .len ) {
1254+ if (rr_buf .s && rr_buf . len ) {
12651255 route_flags = topo_no_dlg_route (msg , & rr_buf );
12661256 if (route_flags & ROUTE_FAILURE ) {
12671257 LM_ERR ("Failure to Route\n" );
12681258 goto err_fail_early ;
12691259 }
1270- }
12711260
1272- if (!(route_flags & ROUTE_FAILURE ) && !(route_flags & ROUTE_STRICT ) && ct_buf . len && ct_buf . s ) {
1273- LM_DBG ("Setting new URI to <%.*s> \n" , ct_buf .len , ct_buf .s );
1261+ if (!(route_flags & ROUTE_FAILURE ) && !(route_flags & ROUTE_STRICT )) {
1262+ LM_DBG ("Setting new URI to <%.*s> \n" , ct_buf .len , ct_buf .s );
12741263
1275- if (set_ruri (msg , & ct_buf ) != 0 ) {
1276- LM_ERR ("failed setting ruri\n" );
1277- goto err_fail_early ;
1264+ if (set_ruri (msg , & ct_buf ) != 0 ) {
1265+ LM_ERR ("failed setting ruri\n" );
1266+ goto err_fail_early ;
1267+ }
1268+ } else if (!(route_flags & ROUTE_FAILURE ) && (route_flags & ROUTE_STRICT )) {
1269+ if (topo_no_dlg_rewrite_contact_as_next_route (msg , & ct_buf ) != 1 ) {
1270+ LM_ERR ("Failure to rewrite Contact header as next Route\n" );
1271+ goto err_fail_early ;
1272+ }
12781273 }
1279- } else if (!(route_flags & ROUTE_FAILURE ) && (route_flags & ROUTE_STRICT ) && ct_buf .len && ct_buf .s ) {
1280- // if (topo_no_dlg_rewrite_contact_as_next_route(msg, &ct_buf, lmp) != 1) {
1281- // LM_ERR("Failure to rewrite Contact header as next Route\n");
1282- // goto err_fail_early;
1283- // }
1284- }
12851274
1286- if (rr_buf .s && rr_buf .len ) {
12871275 route_s = shm_malloc (sizeof * route_s + rr_buf .len );
12881276 if (route_s ) {
12891277 route_s -> s = (char * )(route_s + 1 );
@@ -1332,7 +1320,7 @@ static int th_no_dlg_seq_handling(struct sip_msg *msg, str *info, decode_info_fn
13321320
13331321static inline int th_no_dlg_match_socket_tag (const struct socket_info * socket , str socket_tag_to_match [static 1 ]) {
13341322 if (socket != NULL && socket -> tag .len > 0 ) {
1335- LM_DBG ("Socket tag %.*s tag to match %.s\n" , socket -> tag .len , socket -> tag .s , socket_tag_to_match -> len , socket_tag_to_match -> s );
1323+ LM_DBG ("Socket tag %.*s tag to match %.* s\n" , socket -> tag .len , socket -> tag .s , socket_tag_to_match -> len , socket_tag_to_match -> s );
13361324
13371325 return socket -> tag .len == socket_tag_to_match -> len &&
13381326 strncmp (socket -> tag .s , socket_tag_to_match -> s , socket_tag_to_match -> len ) == 0 ;
0 commit comments