@ -4104,9 +4104,9 @@ static void set_destination(struct sip_pvt *p, char *uri)
+ + h ;
+ + h ;
else {
else {
h = uri ;
h = uri ;
if ( strnc mp( h , " sip: " , 4 ) = = 0 )
if ( strnc asec mp( h , " sip: " , 4 ) = = 0 )
h + = 4 ;
h + = 4 ;
else if ( strnc mp( h , " sips: " , 5 ) = = 0 )
else if ( strnc asec mp( h , " sips: " , 5 ) = = 0 )
h + = 5 ;
h + = 5 ;
}
}
hn = strcspn ( h , " :;> " ) + 1 ;
hn = strcspn ( h , " :;> " ) + 1 ;
@ -5330,7 +5330,7 @@ static int transmit_state_notify(struct sip_pvt *p, int state, int full, int sub
ast_copy_string ( from , get_header ( & p - > initreq , " From " ) , sizeof ( from ) ) ;
ast_copy_string ( from , get_header ( & p - > initreq , " From " ) , sizeof ( from ) ) ;
c = get_in_brackets ( from ) ;
c = get_in_brackets ( from ) ;
if ( strnc mp( c , " sip: " , 4 ) ) {
if ( strnc asec mp( c , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , c ) ;
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , c ) ;
return - 1 ;
return - 1 ;
}
}
@ -5340,7 +5340,7 @@ static int transmit_state_notify(struct sip_pvt *p, int state, int full, int sub
ast_copy_string ( to , get_header ( & p - > initreq , " To " ) , sizeof ( to ) ) ;
ast_copy_string ( to , get_header ( & p - > initreq , " To " ) , sizeof ( to ) ) ;
c = get_in_brackets ( to ) ;
c = get_in_brackets ( to ) ;
if ( strnc mp( c , " sip: " , 4 ) ) {
if ( strnc asec mp( c , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , c ) ;
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , c ) ;
return - 1 ;
return - 1 ;
}
}
@ -5838,7 +5838,7 @@ static int transmit_refer(struct sip_pvt *p, const char *dest)
ast_copy_string ( from , of , sizeof ( from ) ) ;
ast_copy_string ( from , of , sizeof ( from ) ) ;
of = get_in_brackets ( from ) ;
of = get_in_brackets ( from ) ;
ast_copy_string ( p - > from , of , sizeof ( p - > from ) ) ;
ast_copy_string ( p - > from , of , sizeof ( p - > from ) ) ;
if ( strnc mp( of , " sip: " , 4 ) ) {
if ( strnc asec mp( of , " sip: " , 4 ) ) {
ast_log ( LOG_NOTICE , " From address missing 'sip:', using it anyway \n " ) ;
ast_log ( LOG_NOTICE , " From address missing 'sip:', using it anyway \n " ) ;
} else
} else
of + = 4 ;
of + = 4 ;
@ -6700,7 +6700,7 @@ static int register_verify(struct sip_pvt *p, struct sockaddr_in *sin, struct si
if ( name )
if ( name )
* name = ' \0 ' ;
* name = ' \0 ' ;
if ( ! strnc mp( c , " sip: " , 4 ) ) {
if ( ! strnc asec mp( c , " sip: " , 4 ) ) {
name = c + 4 ;
name = c + 4 ;
} else {
} else {
name = c ;
name = c ;
@ -6729,10 +6729,12 @@ static int register_verify(struct sip_pvt *p, struct sockaddr_in *sin, struct si
if ( peer )
if ( peer )
ASTOBJ_UNREF ( peer , sip_destroy_peer ) ;
ASTOBJ_UNREF ( peer , sip_destroy_peer ) ;
peer = NULL ;
peer = NULL ;
res = - 4 ;
}
}
if ( peer ) {
if ( peer ) {
if ( ! ast_test_flag ( & peer - > flags_page2 , SIP_PAGE2_DYNAMIC ) ) {
if ( ! ast_test_flag ( & peer - > flags_page2 , SIP_PAGE2_DYNAMIC ) ) {
ast_log ( LOG_ERROR , " Peer '%s' is trying to register, but not configured as host=dynamic \n " , peer - > name ) ;
ast_log ( LOG_ERROR , " Peer '%s' is trying to register, but not configured as host=dynamic \n " , peer - > name ) ;
res = - 5 ;
} else {
} else {
ast_copy_flags ( p , peer , SIP_NAT ) ;
ast_copy_flags ( p , peer , SIP_NAT ) ;
transmit_response ( p , " 100 Trying " , req ) ;
transmit_response ( p , " 100 Trying " , req ) ;
@ -6806,22 +6808,20 @@ static int register_verify(struct sip_pvt *p, struct sockaddr_in *sin, struct si
proper authentication by digest auth name */
proper authentication by digest auth name */
transmit_response ( p , " 403 Authentication user name does not match account name " , & p - > initreq ) ;
transmit_response ( p , " 403 Authentication user name does not match account name " , & p - > initreq ) ;
break ;
break ;
case - 3 :
case - 3 : /* Unknown domain */
case - 4 : /* ACL error */
case - 5 : /* Peer is not supposed to register with us at all */
if ( global_alwaysauthreject ) {
if ( global_alwaysauthreject ) {
transmit_fake_auth_response ( p , & p - > initreq , p - > randdata , sizeof ( p - > randdata ) , 1 ) ;
transmit_fake_auth_response ( p , & p - > initreq , p - > randdata , sizeof ( p - > randdata ) , 1 ) ;
} else {
} else {
/* URI not found */
/* URI not found */
if ( res = = - 5 )
transmit_response ( p , " 403 Forbidden " , & p - > initreq ) ;
else
transmit_response ( p , " 404 Not found " , & p - > initreq ) ;
transmit_response ( p , " 404 Not found " , & p - > initreq ) ;
}
}
/* Set res back to -2 because we don't want to return an invalid domain message. That check already happened up above. */
res = - 2 ;
break ;
break ;
}
}
if ( option_debug > 1 ) {
ast_log ( LOG_DEBUG , " SIP REGISTER attempt failed for %s : %s \n " ,
peer - > name ,
( res = = - 1 ) ? " Bad password " : ( ( res = = - 2 ) ? " Bad digest user " : " Peer not found " ) ) ;
}
}
}
if ( peer )
if ( peer )
ASTOBJ_UNREF ( peer , sip_destroy_peer ) ;
ASTOBJ_UNREF ( peer , sip_destroy_peer ) ;
@ -6842,7 +6842,7 @@ static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq)
if ( ast_strlen_zero ( tmp ) )
if ( ast_strlen_zero ( tmp ) )
return 0 ;
return 0 ;
c = get_in_brackets ( tmp ) ;
c = get_in_brackets ( tmp ) ;
if ( strnc mp( c , " sip: " , 4 ) ) {
if ( strnc asec mp( c , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Huh? Not an RDNIS SIP header (%s)? \n " , c ) ;
ast_log ( LOG_WARNING , " Huh? Not an RDNIS SIP header (%s)? \n " , c ) ;
return - 1 ;
return - 1 ;
}
}
@ -6876,13 +6876,13 @@ static int get_destination(struct sip_pvt *p, struct sip_request *oreq)
from = get_in_brackets ( tmpf ) ;
from = get_in_brackets ( tmpf ) ;
if ( strnc mp( uri , " sip: " , 4 ) ) {
if ( strnc asec mp( uri , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , uri ) ;
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , uri ) ;
return - 1 ;
return - 1 ;
}
}
uri + = 4 ;
uri + = 4 ;
if ( ! ast_strlen_zero ( from ) ) {
if ( ! ast_strlen_zero ( from ) ) {
if ( strnc mp( from , " sip: " , 4 ) ) {
if ( strnc asec mp( from , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , from ) ;
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , from ) ;
return - 1 ;
return - 1 ;
}
}
@ -7024,12 +7024,12 @@ static int get_refer_info(struct sip_pvt *sip_pvt, struct sip_request *outgoing_
}
}
h_contact = get_header ( req , " Contact " ) ;
h_contact = get_header ( req , " Contact " ) ;
if ( strnc mp( refer_to , " sip: " , 4 ) ) {
if ( strnc asec mp( refer_to , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Refer-to: Huh? Not a SIP header (%s)? \n " , refer_to ) ;
ast_log ( LOG_WARNING , " Refer-to: Huh? Not a SIP header (%s)? \n " , refer_to ) ;
return - 1 ;
return - 1 ;
}
}
if ( strnc mp( referred_by , " sip: " , 4 ) ) {
if ( strnc asec mp( referred_by , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Referred-by: Huh? Not a SIP header (%s) Ignoring? \n " , referred_by ) ;
ast_log ( LOG_WARNING , " Referred-by: Huh? Not a SIP header (%s) Ignoring? \n " , referred_by ) ;
referred_by = NULL ;
referred_by = NULL ;
}
}
@ -7145,7 +7145,7 @@ static int get_also_info(struct sip_pvt *p, struct sip_request *oreq)
c = get_in_brackets ( tmp ) ;
c = get_in_brackets ( tmp ) ;
if ( strnc mp( c , " sip: " , 4 ) ) {
if ( strnc asec mp( c , " sip: " , 4 ) ) {
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , c ) ;
ast_log ( LOG_WARNING , " Huh? Not a SIP header (%s)? \n " , c ) ;
return - 1 ;
return - 1 ;
}
}
@ -7336,7 +7336,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme
of = get_in_brackets ( from ) ;
of = get_in_brackets ( from ) ;
if ( ast_strlen_zero ( p - > exten ) ) {
if ( ast_strlen_zero ( p - > exten ) ) {
t = uri2 ;
t = uri2 ;
if ( ! strnc mp( t , " sip: " , 4 ) )
if ( ! strnc asec mp( t , " sip: " , 4 ) )
t + = 4 ;
t + = 4 ;
ast_copy_string ( p - > exten , t , sizeof ( p - > exten ) ) ;
ast_copy_string ( p - > exten , t , sizeof ( p - > exten ) ) ;
t = strchr ( p - > exten , ' @ ' ) ;
t = strchr ( p - > exten , ' @ ' ) ;
@ -7347,7 +7347,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme
}
}
/* save the URI part of the From header */
/* save the URI part of the From header */
ast_copy_string ( p - > from , of , sizeof ( p - > from ) ) ;
ast_copy_string ( p - > from , of , sizeof ( p - > from ) ) ;
if ( strnc mp( of , " sip: " , 4 ) ) {
if ( strnc asec mp( of , " sip: " , 4 ) ) {
ast_log ( LOG_NOTICE , " From address missing 'sip:', using it anyway \n " ) ;
ast_log ( LOG_NOTICE , " From address missing 'sip:', using it anyway \n " ) ;
} else
} else
of + = 4 ;
of + = 4 ;
@ -11354,8 +11354,24 @@ static int handle_request_register(struct sip_pvt *p, struct sip_request *req, i
ast_verbose ( " Using latest REGISTER request as basis request \n " ) ;
ast_verbose ( " Using latest REGISTER request as basis request \n " ) ;
copy_request ( & p - > initreq , req ) ;
copy_request ( & p - > initreq , req ) ;
check_via ( p , req ) ;
check_via ( p , req ) ;
if ( ( res = register_verify ( p , sin , req , e , ignore ) ) < 0 )
if ( ( res = register_verify ( p , sin , req , e , ignore ) ) < 0 ) {
ast_log ( LOG_NOTICE , " Registration from '%s' failed for '%s' - %s \n " , get_header ( req , " To " ) , ast_inet_ntoa ( iabuf , sizeof ( iabuf ) , sin - > sin_addr ) , ( res = = - 1 ) ? " Wrong password " : ( res = = - 2 ? " Username/auth name mismatch " : " Not a local SIP domain " ) ) ;
const char * error ;
switch ( res ) {
case - 1 : error = " Wrong password " ;
break ;
case - 2 : error = " Username/auth name mismatch " ;
break ;
case - 3 : error = " Not a local SIP domain " ;
break ;
case - 4 : error = " ACL error (permit/deny) " ;
break ;
case - 5 : error = " Peer is not supposed to register " ;
break ;
default : error = " Unknown error " ;
break ;
}
ast_log ( LOG_NOTICE , " Registration from '%s' failed for '%s' - %s \n " , get_header ( req , " To " ) , ast_inet_ntoa ( iabuf , sizeof ( iabuf ) , sin - > sin_addr ) , error ) ;
}
if ( res < 1 ) {
if ( res < 1 ) {
/* Destroy the session, but keep us around for just a bit in case they don't
/* Destroy the session, but keep us around for just a bit in case they don't
get our 200 OK */
get our 200 OK */
@ -13497,7 +13513,7 @@ static int sip_sipredirect(struct sip_pvt *p, const char *dest)
ast_log ( LOG_ERROR , " Cannot retrieve the 'To' header from the original SIP request! \n " ) ;
ast_log ( LOG_ERROR , " Cannot retrieve the 'To' header from the original SIP request! \n " ) ;
return 0 ;
return 0 ;
}
}
if ( ( localtmp = str str( tmp , " sip: " ) ) & & ( localtmp = strchr ( localtmp , ' @ ' ) ) ) {
if ( ( localtmp = str case str( tmp , " sip: " ) ) & & ( localtmp = strchr ( localtmp , ' @ ' ) ) ) {
char lhost [ 80 ] , lport [ 80 ] ;
char lhost [ 80 ] , lport [ 80 ] ;
memset ( lhost , 0 , sizeof ( lhost ) ) ;
memset ( lhost , 0 , sizeof ( lhost ) ) ;
memset ( lport , 0 , sizeof ( lport ) ) ;
memset ( lport , 0 , sizeof ( lport ) ) ;