@ -4421,25 +4421,11 @@ static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_i
return peer ;
return peer ;
}
}
/*! \brief Locate device by name or ip address
/* Function to assist finding peers by name only */
* This is used on find matching device on name or ip / port .
static int find_by_name ( void * obj , void * arg , void * data , int flags )
If the device was declared as type = peer , we don ' t match on peer name on incoming INVITEs .
\ note Avoid using this function in new functions if there is a way to avoid it ,
since it might cause a database lookup .
*/
static struct sip_peer * find_peer ( const char * peer , struct sockaddr_in * sin , int realtime , int forcenamematch , int devstate_only )
{
{
struct sip_peer * p = NULL ;
struct sip_peer tmp_peer ;
/* Inline function to assist finding peers by name only */
auto int find_by_name ( void * obj , void * arg , void * data , int flags ) ;
int find_by_name ( void * obj , void * arg , void * data , int flags )
{
struct sip_peer * search = obj , * match = arg ;
struct sip_peer * search = obj , * match = arg ;
int * forcenamematch = data ;
/* Usernames in SIP uri's are case sensitive. Domains are not */
/* Usernames in SIP uri's are case sensitive. Domains are not */
if ( strcmp ( search - > name , match - > name ) ) {
if ( strcmp ( search - > name , match - > name ) ) {
@ -4448,16 +4434,29 @@ static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int
/* If we're only looking for name matches, we should avoid type=peer devices,
/* If we're only looking for name matches, we should avoid type=peer devices,
since these should not match on any name - based search */
since these should not match on any name - based search */
if ( forcenamematch & & search - > onlymatchonip ) {
if ( * forcenamematch & & search - > onlymatchonip ) {
return 0 ;
return 0 ;
}
}
return CMP_MATCH | CMP_STOP ;
return CMP_MATCH | CMP_STOP ;
}
}
/*! \brief Locate device by name or ip address
* This is used on find matching device on name or ip / port .
If the device was declared as type = peer , we don ' t match on peer name on incoming INVITEs .
\ note Avoid using this function in new functions if there is a way to avoid it ,
since it might cause a database lookup .
*/
static struct sip_peer * find_peer ( const char * peer , struct sockaddr_in * sin , int realtime , int forcenamematch , int devstate_only )
{
struct sip_peer * p = NULL ;
struct sip_peer tmp_peer ;
if ( peer ) {
if ( peer ) {
ast_copy_string ( tmp_peer . name , peer , sizeof ( tmp_peer . name ) ) ;
ast_copy_string ( tmp_peer . name , peer , sizeof ( tmp_peer . name ) ) ;
p = ao2_t_callback ( peers , OBJ_POINTER , find_by_name , & tmp_peer , NULL , " ao2_find in peers table " ) ;
p = ao2_t_callback ( peers , OBJ_POINTER , find_by_name , & tmp_peer , & forcenamematch , " ao2_find in peers table " ) ;
} else if ( sin ) { /* search by addr? */
} else if ( sin ) { /* search by addr? */
tmp_peer . addr . sin_addr . s_addr = sin - > sin_addr . s_addr ;
tmp_peer . addr . sin_addr . s_addr = sin - > sin_addr . s_addr ;
tmp_peer . addr . sin_port = sin - > sin_port ;
tmp_peer . addr . sin_port = sin - > sin_port ;
@ -9874,6 +9873,19 @@ static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi)
return 0 ;
return 0 ;
}
}
struct caller_criteria {
const char * exten ;
const char * context ;
} ;
static int find_calling_channel ( struct ast_channel * c , void * data ) {
struct caller_criteria * info = data ;
return ( c - > pbx & &
( ! strcasecmp ( c - > macroexten , info - > exten ) | | ! strcasecmp ( c - > exten , info - > exten ) ) & &
! strcasecmp ( c - > context , info - > context ) ) ;
}
/*! \brief Used in the SUBSCRIBE notification subsystem (RFC3265) */
/*! \brief Used in the SUBSCRIBE notification subsystem (RFC3265) */
static int transmit_state_notify ( struct sip_pvt * p , int state , int full , int timeout )
static int transmit_state_notify ( struct sip_pvt * p , int state , int full , int timeout )
{
{
@ -10039,14 +10051,13 @@ static int transmit_state_notify(struct sip_pvt *p, int state, int full, int tim
callee must be dialing the same extension that is being monitored . Simply dialing
callee must be dialing the same extension that is being monitored . Simply dialing
the hint ' d device is not sufficient . */
the hint ' d device is not sufficient . */
if ( global_notifycid ) {
if ( global_notifycid ) {
auto int find_calling_channel ( struct ast_channel * c ) ;
struct ast_channel * caller = NULL ;
int find_calling_channel ( struct ast_channel * c ) {
struct caller_criteria data = {
return ( c - > pbx & &
. exten = p - > exten ,
( ! strcasecmp ( c - > macroexten , p - > exten ) | | ! strcasecmp ( c - > exten , p - > exten ) ) & &
. context = p - > context ,
! strcasecmp ( c - > context , p - > context ) ) ;
} ;
}
struct ast_channel * caller = ast_channel_search_locked ( find_calling_channel ) ;
caller = ast_channel_search_locked ( find_calling_channel , & data ) ;
if ( caller ) {
if ( caller ) {
local_display = ast_strdupa ( caller - > cid . cid_name ) ;
local_display = ast_strdupa ( caller - > cid . cid_name ) ;