@ -399,10 +399,8 @@ static void reset_global_eid(void)
if ( ioctl ( s , SIOCGIFHWADDR , & ifr ) )
if ( ioctl ( s , SIOCGIFHWADDR , & ifr ) )
continue ;
continue ;
memcpy ( & global_eid , ( ( unsigned char * ) & ifr . ifr_hwaddr ) + 2 , sizeof ( global_eid ) ) ;
memcpy ( & global_eid , ( ( unsigned char * ) & ifr . ifr_hwaddr ) + 2 , sizeof ( global_eid ) ) ;
if ( option_debug ) {
ast_debug ( 1 , " Seeding global EID '%s' from '%s' \n " ,
ast_log ( LOG_DEBUG , " Seeding global EID '%s' from '%s' \n " ,
dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & global_eid ) , ifr . ifr_name ) ;
dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & global_eid ) , ifr . ifr_name ) ;
}
close ( s ) ;
close ( s ) ;
return ;
return ;
}
}
@ -420,8 +418,7 @@ static void reset_global_eid(void)
memcpy (
memcpy (
& ( global_eid . eid ) ,
& ( global_eid . eid ) ,
sdp - > sdl_data + sdp - > sdl_nlen , 6 ) ;
sdp - > sdl_data + sdp - > sdl_nlen , 6 ) ;
if ( option_debug )
ast_debug ( 1 , " Seeding global EID '%s' from '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & global_eid ) , ifap - > ifa_name ) ;
ast_log ( LOG_DEBUG , " Seeding global EID '%s' from '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & global_eid ) , ifap - > ifa_name ) ;
freeifaddrs ( ifap ) ;
freeifaddrs ( ifap ) ;
return ;
return ;
}
}
@ -611,8 +608,7 @@ static void *dundi_lookup_thread(void *data)
int max = 999999 ;
int max = 999999 ;
int expiration = dundi_cache_time ;
int expiration = dundi_cache_time ;
if ( option_debug )
ast_debug ( 1 , " Whee, looking up '%s@%s' for '%s' \n " , st - > called_number , st - > called_context ,
ast_log ( LOG_DEBUG , " Whee, looking up '%s@%s' for '%s' \n " , st - > called_number , st - > called_context ,
st - > eids [ 0 ] ? dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , st - > eids [ 0 ] ) : " ourselves " ) ;
st - > eids [ 0 ] ? dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , st - > eids [ 0 ] ) : " ourselves " ) ;
memset ( & ied , 0 , sizeof ( ied ) ) ;
memset ( & ied , 0 , sizeof ( ied ) ) ;
memset ( & dr , 0 , sizeof ( dr ) ) ;
memset ( & dr , 0 , sizeof ( dr ) ) ;
@ -644,8 +640,7 @@ static void *dundi_lookup_thread(void *data)
if ( ! ast_test_flag_nonstd ( & hmd , DUNDI_HINT_DONT_ASK ) )
if ( ! ast_test_flag_nonstd ( & hmd , DUNDI_HINT_DONT_ASK ) )
hmd . exten [ 0 ] = ' \0 ' ;
hmd . exten [ 0 ] = ' \0 ' ;
if ( ast_test_flag ( st - > trans , FLAG_DEAD ) ) {
if ( ast_test_flag ( st - > trans , FLAG_DEAD ) ) {
if ( option_debug )
ast_debug ( 1 , " Our transaction went away! \n " ) ;
ast_log ( LOG_DEBUG , " Our transaction went away! \n " ) ;
st - > trans - > thread = 0 ;
st - > trans - > thread = 0 ;
destroy_trans ( st - > trans , 0 ) ;
destroy_trans ( st - > trans , 0 ) ;
} else {
} else {
@ -672,9 +667,8 @@ static void *dundi_precache_thread(void *data)
struct dundi_hint_metadata hmd ;
struct dundi_hint_metadata hmd ;
char eid_str [ 20 ] ;
char eid_str [ 20 ] ;
if ( option_debug )
ast_debug ( 1 , " Whee, precaching '%s@%s' for '%s' \n " , st - > called_number , st - > called_context ,
ast_log ( LOG_DEBUG , " Whee, precaching '%s@%s' for '%s' \n " , st - > called_number , st - > called_context ,
st - > eids [ 0 ] ? dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , st - > eids [ 0 ] ) : " ourselves " ) ;
st - > eids [ 0 ] ? dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , st - > eids [ 0 ] ) : " ourselves " ) ;
memset ( & ied , 0 , sizeof ( ied ) ) ;
memset ( & ied , 0 , sizeof ( ied ) ) ;
/* Now produce precache */
/* Now produce precache */
@ -685,8 +679,7 @@ static void *dundi_precache_thread(void *data)
if ( ! ast_test_flag_nonstd ( & hmd , DUNDI_HINT_DONT_ASK ) )
if ( ! ast_test_flag_nonstd ( & hmd , DUNDI_HINT_DONT_ASK ) )
hmd . exten [ 0 ] = ' \0 ' ;
hmd . exten [ 0 ] = ' \0 ' ;
if ( ast_test_flag ( st - > trans , FLAG_DEAD ) ) {
if ( ast_test_flag ( st - > trans , FLAG_DEAD ) ) {
if ( option_debug )
ast_debug ( 1 , " Our transaction went away! \n " ) ;
ast_log ( LOG_DEBUG , " Our transaction went away! \n " ) ;
st - > trans - > thread = 0 ;
st - > trans - > thread = 0 ;
destroy_trans ( st - > trans , 0 ) ;
destroy_trans ( st - > trans , 0 ) ;
} else {
} else {
@ -709,16 +702,14 @@ static void *dundi_query_thread(void *data)
char eid_str [ 20 ] ;
char eid_str [ 20 ] ;
int res ;
int res ;
if ( option_debug )
ast_debug ( 1 , " Whee, looking up '%s@%s' for '%s' \n " , st - > called_number , st - > called_context ,
ast_log ( LOG_DEBUG , " Whee, looking up '%s@%s' for '%s' \n " , st - > called_number , st - > called_context ,
st - > eids [ 0 ] ? dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , st - > eids [ 0 ] ) : " ourselves " ) ;
st - > eids [ 0 ] ? dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , st - > eids [ 0 ] ) : " ourselves " ) ;
memset ( & ied , 0 , sizeof ( ied ) ) ;
memset ( & ied , 0 , sizeof ( ied ) ) ;
memset ( & dei , 0 , sizeof ( dei ) ) ;
memset ( & dei , 0 , sizeof ( dei ) ) ;
memset ( & hmd , 0 , sizeof ( hmd ) ) ;
memset ( & hmd , 0 , sizeof ( hmd ) ) ;
if ( ! dundi_eid_cmp ( & st - > trans - > us_eid , & st - > reqeid ) ) {
if ( ! dundi_eid_cmp ( & st - > trans - > us_eid , & st - > reqeid ) ) {
/* Ooh, it's us! */
/* Ooh, it's us! */
if ( option_debug )
ast_debug ( 1 , " Neat, someone look for us! \n " ) ;
ast_log ( LOG_DEBUG , " Neat, someone look for us! \n " ) ;
ast_copy_string ( dei . orgunit , dept , sizeof ( dei . orgunit ) ) ;
ast_copy_string ( dei . orgunit , dept , sizeof ( dei . orgunit ) ) ;
ast_copy_string ( dei . org , org , sizeof ( dei . org ) ) ;
ast_copy_string ( dei . org , org , sizeof ( dei . org ) ) ;
ast_copy_string ( dei . locality , locality , sizeof ( dei . locality ) ) ;
ast_copy_string ( dei . locality , locality , sizeof ( dei . locality ) ) ;
@ -733,8 +724,7 @@ static void *dundi_query_thread(void *data)
}
}
AST_LIST_LOCK ( & peers ) ;
AST_LIST_LOCK ( & peers ) ;
if ( ast_test_flag ( st - > trans , FLAG_DEAD ) ) {
if ( ast_test_flag ( st - > trans , FLAG_DEAD ) ) {
if ( option_debug )
ast_debug ( 1 , " Our transaction went away! \n " ) ;
ast_log ( LOG_DEBUG , " Our transaction went away! \n " ) ;
st - > trans - > thread = 0 ;
st - > trans - > thread = 0 ;
destroy_trans ( st - > trans , 0 ) ;
destroy_trans ( st - > trans , 0 ) ;
} else {
} else {
@ -792,8 +782,7 @@ static int dundi_answer_entity(struct dundi_transaction *trans, struct dundi_ies
* st - > eids [ x - skipfirst ] = * ies - > eids [ x ] ;
* st - > eids [ x - skipfirst ] = * ies - > eids [ x ] ;
s + = sizeof ( dundi_eid ) ;
s + = sizeof ( dundi_eid ) ;
}
}
if ( option_debug )
ast_debug ( 1 , " Answering EID query for '%s@%s'! \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , ies - > reqeid ) , ies - > called_context ) ;
ast_log ( LOG_DEBUG , " Answering EID query for '%s@%s'! \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , ies - > reqeid ) , ies - > called_context ) ;
trans - > thread = 1 ;
trans - > thread = 1 ;
if ( ast_pthread_create_detached ( & lookupthread , NULL , dundi_query_thread , st ) ) {
if ( ast_pthread_create_detached ( & lookupthread , NULL , dundi_query_thread , st ) ) {
@ -843,11 +832,9 @@ static int cache_save_hint(dundi_eid *eidpeer, struct dundi_request *req, struct
snprintf ( data , sizeof ( data ) , " %ld| " , ( long ) ( timeout ) ) ;
snprintf ( data , sizeof ( data ) , " %ld| " , ( long ) ( timeout ) ) ;
ast_db_put ( " dundi/cache " , key1 , data ) ;
ast_db_put ( " dundi/cache " , key1 , data ) ;
if ( option_debug )
ast_debug ( 1 , " Caching hint at '%s' \n " , key1 ) ;
ast_log ( LOG_DEBUG , " Caching hint at '%s' \n " , key1 ) ;
ast_db_put ( " dundi/cache " , key2 , data ) ;
ast_db_put ( " dundi/cache " , key2 , data ) ;
if ( option_debug )
ast_debug ( 1 , " Caching hint at '%s' \n " , key2 ) ;
ast_log ( LOG_DEBUG , " Caching hint at '%s' \n " , key2 ) ;
return 0 ;
return 0 ;
}
}
@ -1018,8 +1005,7 @@ static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies
}
}
}
}
st - > nummaps = mapcount ;
st - > nummaps = mapcount ;
if ( option_debug )
ast_debug ( 1 , " Forwarding precache for '%s@%s'! \n " , ies - > called_number , ies - > called_context ) ;
ast_log ( LOG_DEBUG , " Forwarding precache for '%s@%s'! \n " , ies - > called_number , ies - > called_context ) ;
trans - > thread = 1 ;
trans - > thread = 1 ;
if ( ast_pthread_create_detached ( & lookupthread , NULL , dundi_precache_thread , st ) ) {
if ( ast_pthread_create_detached ( & lookupthread , NULL , dundi_precache_thread , st ) ) {
trans - > thread = 0 ;
trans - > thread = 0 ;
@ -1102,8 +1088,7 @@ static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies
}
}
}
}
st - > nummaps = mapcount ;
st - > nummaps = mapcount ;
if ( option_debug )
ast_debug ( 1 , " Answering query for '%s@%s'! \n " , ies - > called_number , ies - > called_context ) ;
ast_log ( LOG_DEBUG , " Answering query for '%s@%s'! \n " , ies - > called_number , ies - > called_context ) ;
trans - > thread = 1 ;
trans - > thread = 1 ;
if ( ast_pthread_create_detached ( & lookupthread , NULL , dundi_lookup_thread , st ) ) {
if ( ast_pthread_create_detached ( & lookupthread , NULL , dundi_lookup_thread , st ) ) {
trans - > thread = 0 ;
trans - > thread = 0 ;
@ -1142,8 +1127,7 @@ static int cache_lookup_internal(time_t now, struct dundi_request *req, char *ke
if ( ! ast_get_time_t ( ptr , & timeout , 0 , & length ) ) {
if ( ! ast_get_time_t ( ptr , & timeout , 0 , & length ) ) {
int expiration = timeout - now ;
int expiration = timeout - now ;
if ( expiration > 0 ) {
if ( expiration > 0 ) {
if ( option_debug )
ast_debug ( 1 , " Found cache expiring in %d seconds! \n " , expiration ) ;
ast_log ( LOG_DEBUG , " Found cache expiring in %d seconds! \n " , expiration ) ;
ptr + = length + 1 ;
ptr + = length + 1 ;
while ( ( sscanf ( ptr , " %d/%d/%d/%n " , & ( flags . flags ) , & weight , & tech , & length ) = = 3 ) ) {
while ( ( sscanf ( ptr , " %d/%d/%d/%n " , & ( flags . flags ) , & weight , & tech , & length ) = = 3 ) ) {
ptr + = length ;
ptr + = length ;
@ -1156,9 +1140,8 @@ static int cache_lookup_internal(time_t now, struct dundi_request *req, char *ke
src + + ;
src + + ;
} else
} else
src = " " ;
src = " " ;
if ( option_debug )
ast_debug ( 1 , " Found cached answer '%s/%s' originally from '%s' with flags '%s' on behalf of '%s' \n " ,
ast_log ( LOG_DEBUG , " Found cached answer '%s/%s' originally from '%s' with flags '%s' on behalf of '%s' \n " ,
tech2str ( tech ) , ptr , src , dundi_flags2str ( fs , sizeof ( fs ) , flags . flags ) , eid_str_full ) ;
tech2str ( tech ) , ptr , src , dundi_flags2str ( fs , sizeof ( fs ) , flags . flags ) , eid_str_full ) ;
/* Make sure it's not already there */
/* Make sure it's not already there */
for ( z = 0 ; z < req - > respcount ; z + + ) {
for ( z = 0 ; z < req - > respcount ; z + + ) {
if ( ( req - > dr [ z ] . techint = = tech ) & &
if ( ( req - > dr [ z ] . techint = = tech ) & &
@ -1279,8 +1262,7 @@ static int do_register_expire(const void *data)
{
{
struct dundi_peer * peer = ( struct dundi_peer * ) data ;
struct dundi_peer * peer = ( struct dundi_peer * ) data ;
char eid_str [ 20 ] ;
char eid_str [ 20 ] ;
if ( option_debug )
ast_debug ( 1 , " Register expired for '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & peer - > eid ) ) ;
ast_log ( LOG_DEBUG , " Register expired for '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & peer - > eid ) ) ;
peer - > registerexpire = - 1 ;
peer - > registerexpire = - 1 ;
peer - > lastms = 0 ;
peer - > lastms = 0 ;
memset ( & peer - > addr , 0 , sizeof ( peer - > addr ) ) ;
memset ( & peer - > addr , 0 , sizeof ( peer - > addr ) ) ;
@ -1374,8 +1356,7 @@ static struct dundi_hdr *dundi_decrypt(struct dundi_transaction *trans, unsigned
* h = * ohdr ;
* h = * ohdr ;
bytes = space - 6 ;
bytes = space - 6 ;
if ( uncompress ( dst + 6 , & bytes , decrypt_space , srclen ) ! = Z_OK ) {
if ( uncompress ( dst + 6 , & bytes , decrypt_space , srclen ) ! = Z_OK ) {
if ( option_debug )
ast_debug ( 1 , " Ouch, uncompress failed :( \n " ) ;
ast_log ( LOG_DEBUG , " Ouch, uncompress failed :( \n " ) ;
return NULL ;
return NULL ;
}
}
/* Update length */
/* Update length */
@ -1401,8 +1382,7 @@ static int dundi_encrypt(struct dundi_transaction *trans, struct dundi_packet *p
bytes = len ;
bytes = len ;
res = compress ( compress_space , & bytes , pack - > data + 6 , pack - > datalen - 6 ) ;
res = compress ( compress_space , & bytes , pack - > data + 6 , pack - > datalen - 6 ) ;
if ( res ! = Z_OK ) {
if ( res ! = Z_OK ) {
if ( option_debug )
ast_debug ( 1 , " Ouch, compression failed! \n " ) ;
ast_log ( LOG_DEBUG , " Ouch, compression failed! \n " ) ;
return - 1 ;
return - 1 ;
}
}
memset ( & ied , 0 , sizeof ( ied ) ) ;
memset ( & ied , 0 , sizeof ( ied ) ) ;
@ -1458,8 +1438,7 @@ static int check_key(struct dundi_peer *peer, unsigned char *newkey, unsigned ch
int res ;
int res ;
struct ast_key * key , * skey ;
struct ast_key * key , * skey ;
char eid_str [ 20 ] ;
char eid_str [ 20 ] ;
if ( option_debug )
ast_debug ( 1 , " Expected '%08lx' got '%08lx' \n " , peer - > them_keycrc32 , keycrc32 ) ;
ast_log ( LOG_DEBUG , " Expected '%08lx' got '%08lx' \n " , peer - > them_keycrc32 , keycrc32 ) ;
if ( peer - > them_keycrc32 & & ( peer - > them_keycrc32 = = keycrc32 ) ) {
if ( peer - > them_keycrc32 & & ( peer - > them_keycrc32 = = keycrc32 ) ) {
/* A match */
/* A match */
return 1 ;
return 1 ;
@ -1497,8 +1476,7 @@ static int check_key(struct dundi_peer *peer, unsigned char *newkey, unsigned ch
return 0 ;
return 0 ;
}
}
/* Decrypted, passes signature */
/* Decrypted, passes signature */
if ( option_debug )
ast_debug ( 1 , " Wow, new key combo passed signature and decrypt! \n " ) ;
ast_log ( LOG_DEBUG , " Wow, new key combo passed signature and decrypt! \n " ) ;
memcpy ( peer - > rxenckey , newkey , 128 ) ;
memcpy ( peer - > rxenckey , newkey , 128 ) ;
memcpy ( peer - > rxenckey + 128 , newsig , 128 ) ;
memcpy ( peer - > rxenckey + 128 , newsig , 128 ) ;
peer - > them_keycrc32 = crc32 ( 0L , peer - > rxenckey , 128 ) ;
peer - > them_keycrc32 = crc32 ( 0L , peer - > rxenckey , 128 ) ;
@ -1560,8 +1538,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
return - 1 ;
return - 1 ;
/* Make a copy for parsing */
/* Make a copy for parsing */
memcpy ( bufcpy , hdr - > ies , datalen ) ;
memcpy ( bufcpy , hdr - > ies , datalen ) ;
if ( option_debug )
ast_debug ( 1 , " Got canonical message %d (%d), %d bytes data%s \n " , cmd , hdr - > oseqno , datalen , final ? " (Final) " : " " ) ;
ast_log ( LOG_DEBUG , " Got canonical message %d (%d), %d bytes data%s \n " , cmd , hdr - > oseqno , datalen , final ? " (Final) " : " " ) ;
if ( dundi_parse_ies ( & ies , bufcpy , datalen ) < 0 ) {
if ( dundi_parse_ies ( & ies , bufcpy , datalen ) < 0 ) {
ast_log ( LOG_WARNING , " Failed to parse DUNDI information elements! \n " ) ;
ast_log ( LOG_WARNING , " Failed to parse DUNDI information elements! \n " ) ;
return - 1 ;
return - 1 ;
@ -1690,8 +1667,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
/* A dialplan response, lets see what we got... */
/* A dialplan response, lets see what we got... */
if ( ies . cause < 1 ) {
if ( ies . cause < 1 ) {
/* Success of some sort */
/* Success of some sort */
if ( option_debug )
ast_debug ( 1 , " Looks like success of some sort (%d), %d answers \n " , ies . cause , ies . anscount ) ;
ast_log ( LOG_DEBUG , " Looks like success of some sort (%d), %d answers \n " , ies . cause , ies . anscount ) ;
if ( ast_test_flag ( trans , FLAG_ENCRYPT ) ) {
if ( ast_test_flag ( trans , FLAG_ENCRYPT ) ) {
authpass = encrypted ;
authpass = encrypted ;
} else
} else
@ -1775,8 +1751,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
/* A dialplan response, lets see what we got... */
/* A dialplan response, lets see what we got... */
if ( ies . cause < 1 ) {
if ( ies . cause < 1 ) {
/* Success of some sort */
/* Success of some sort */
if ( option_debug )
ast_debug ( 1 , " Looks like success of some sort (%d) \n " , ies . cause ) ;
ast_log ( LOG_DEBUG , " Looks like success of some sort (%d) \n " , ies . cause ) ;
if ( ast_test_flag ( trans , FLAG_ENCRYPT ) ) {
if ( ast_test_flag ( trans , FLAG_ENCRYPT ) ) {
authpass = encrypted ;
authpass = encrypted ;
} else
} else
@ -1842,9 +1817,8 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
dundi_send ( trans , DUNDI_COMMAND_CANCEL , 0 , 1 , & ied ) ;
dundi_send ( trans , DUNDI_COMMAND_CANCEL , 0 , 1 , & ied ) ;
}
}
} else {
} else {
if ( option_debug )
ast_debug ( 1 , " Yay, we've registered as '%s' to '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & trans - > us_eid ) ,
ast_log ( LOG_DEBUG , " Yay, we've registered as '%s' to '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & trans - > us_eid ) ,
dundi_eid_to_str ( eid_str2 , sizeof ( eid_str2 ) , & trans - > them_eid ) ) ;
dundi_eid_to_str ( eid_str2 , sizeof ( eid_str2 ) , & trans - > them_eid ) ) ;
/* Close connection if not final */
/* Close connection if not final */
if ( ! final )
if ( ! final )
dundi_send ( trans , DUNDI_COMMAND_CANCEL , 0 , 1 , NULL ) ;
dundi_send ( trans , DUNDI_COMMAND_CANCEL , 0 , 1 , NULL ) ;
@ -1927,8 +1901,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
hdr - > cmdresp | = dhdr - > cmdresp & 0x80 ;
hdr - > cmdresp | = dhdr - > cmdresp & 0x80 ;
break ;
break ;
} else {
} else {
if ( option_debug )
ast_debug ( 1 , " Ouch, decrypt failed :( \n " ) ;
ast_log ( LOG_DEBUG , " Ouch, decrypt failed :( \n " ) ;
}
}
}
}
}
}
@ -2021,8 +1994,7 @@ static int handle_frame(struct dundi_hdr *h, struct sockaddr_in *sin, int datale
dundi_ack ( trans , 0 ) ;
dundi_ack ( trans , 0 ) ;
} else {
} else {
/* Out of window -- simply drop */
/* Out of window -- simply drop */
if ( option_debug )
ast_debug ( 1 , " Dropping packet out of window! \n " ) ;
ast_log ( LOG_DEBUG , " Dropping packet out of window! \n " ) ;
}
}
return 0 ;
return 0 ;
}
}
@ -3280,8 +3252,7 @@ static int precache_transactions(struct dundi_request *dr, struct dundi_mapping
AST_LIST_TRAVERSE_SAFE_BEGIN ( & dr - > trans , trans , parentlist ) {
AST_LIST_TRAVERSE_SAFE_BEGIN ( & dr - > trans , trans , parentlist ) {
trans - > thread = 0 ;
trans - > thread = 0 ;
if ( ast_test_flag ( trans , FLAG_DEAD ) ) {
if ( ast_test_flag ( trans , FLAG_DEAD ) ) {
if ( option_debug )
ast_debug ( 1 , " Our transaction went away! \n " ) ;
ast_log ( LOG_DEBUG , " Our transaction went away! \n " ) ;
/* This is going to remove the transaction from the dundi_request's list, as well
/* This is going to remove the transaction from the dundi_request's list, as well
* as the global transactions list */
* as the global transactions list */
destroy_trans ( trans , 0 ) ;
destroy_trans ( trans , 0 ) ;
@ -3375,12 +3346,10 @@ static int append_transaction(struct dundi_request *dr, struct dundi_peer *p, in
if ( p - > maxms & & ( ( p - > lastms < 0 ) | | ( p - > lastms > = p - > maxms ) ) )
if ( p - > maxms & & ( ( p - > lastms < 0 ) | | ( p - > lastms > = p - > maxms ) ) )
return 0 ;
return 0 ;
if ( option_debug ) {
if ( ast_strlen_zero ( dr - > number ) )
if ( ast_strlen_zero ( dr - > number ) )
ast_debug ( 1 , " Will query peer '%s' for '%s' (context '%s') \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & p - > eid ) , dundi_eid_to_str ( eid_str2 , sizeof ( eid_str2 ) , & dr - > query_eid ) , dr - > dcontext ) ;
ast_log ( LOG_DEBUG , " Will query peer '%s' for '%s' (context '%s') \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & p - > eid ) , dundi_eid_to_str ( eid_str2 , sizeof ( eid_str2 ) , & dr - > query_eid ) , dr - > dcontext ) ;
else
else
ast_debug ( 1 , " Will query peer '%s' for '%s@%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & p - > eid ) , dr - > number , dr - > dcontext ) ;
ast_log ( LOG_DEBUG , " Will query peer '%s' for '%s@%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & p - > eid ) , dr - > number , dr - > dcontext ) ;
}
trans = create_transaction ( p ) ;
trans = create_transaction ( p ) ;
if ( ! trans )
if ( ! trans )
@ -3467,8 +3436,7 @@ static void build_transactions(struct dundi_request *dr, int ttl, int order, int
/* Check for a matching or 0 cache entry */
/* Check for a matching or 0 cache entry */
append_transaction ( dr , p , ttl , avoid ) ;
append_transaction ( dr , p , ttl , avoid ) ;
} else {
} else {
if ( option_debug )
ast_debug ( 1 , " Avoiding '%s' in transaction \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , avoid [ x ] ) ) ;
ast_log ( LOG_DEBUG , " Avoiding '%s' in transaction \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , avoid [ x ] ) ) ;
}
}
}
}
}
}
@ -3487,24 +3455,21 @@ static int register_request(struct dundi_request *dr, struct dundi_request **pen
char eid_str [ 20 ] ;
char eid_str [ 20 ] ;
AST_LIST_LOCK ( & peers ) ;
AST_LIST_LOCK ( & peers ) ;
AST_LIST_TRAVERSE ( & requests , cur , list ) {
AST_LIST_TRAVERSE ( & requests , cur , list ) {
if ( option_debug )
ast_debug ( 1 , " Checking '%s@%s' vs '%s@%s' \n " , cur - > dcontext , cur - > number ,
ast_log ( LOG_DEBUG , " Checking '%s@%s' vs '%s@%s' \n " , cur - > dcontext , cur - > number ,
dr - > dcontext , dr - > number ) ;
dr - > dcontext , dr - > number ) ;
if ( ! strcasecmp ( cur - > dcontext , dr - > dcontext ) & &
if ( ! strcasecmp ( cur - > dcontext , dr - > dcontext ) & &
! strcasecmp ( cur - > number , dr - > number ) & &
! strcasecmp ( cur - > number , dr - > number ) & &
( ! dundi_eid_cmp ( & cur - > root_eid , & dr - > root_eid ) | | ( cur - > crc32 = = dr - > crc32 ) ) ) {
( ! dundi_eid_cmp ( & cur - > root_eid , & dr - > root_eid ) | | ( cur - > crc32 = = dr - > crc32 ) ) ) {
if ( option_debug )
ast_debug ( 1 , " Found existing query for '%s@%s' for '%s' crc '%08lx' \n " ,
ast_log ( LOG_DEBUG , " Found existing query for '%s@%s' for '%s' crc '%08lx' \n " ,
cur - > dcontext , cur - > number , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & cur - > root_eid ) , cur - > crc32 ) ;
cur - > dcontext , cur - > number , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & cur - > root_eid ) , cur - > crc32 ) ;
* pending = cur ;
* pending = cur ;
res = 1 ;
res = 1 ;
break ;
break ;
}
}
}
}
if ( ! res ) {
if ( ! res ) {
if ( option_debug )
ast_debug ( 1 , " Registering request for '%s@%s' on behalf of '%s' crc '%08lx' \n " ,
ast_log ( LOG_DEBUG , " Registering request for '%s@%s' on behalf of '%s' crc '%08lx' \n " ,
dr - > number , dr - > dcontext , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & dr - > root_eid ) , dr - > crc32 ) ;
dr - > number , dr - > dcontext , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & dr - > root_eid ) , dr - > crc32 ) ;
/* Go ahead and link us in since nobody else is searching for this */
/* Go ahead and link us in since nobody else is searching for this */
AST_LIST_INSERT_HEAD ( & requests , dr , list ) ;
AST_LIST_INSERT_HEAD ( & requests , dr , list ) ;
* pending = NULL ;
* pending = NULL ;
@ -3593,17 +3558,15 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
if ( rooteid & & ! dundi_eid_cmp ( & dr . root_eid , & pending - > root_eid ) ) {
if ( rooteid & & ! dundi_eid_cmp ( & dr . root_eid , & pending - > root_eid ) ) {
/* This is on behalf of someone else. Go ahead and close this out since
/* This is on behalf of someone else. Go ahead and close this out since
they ' ll get their answer anyway . */
they ' ll get their answer anyway . */
if ( option_debug )
ast_debug ( 1 , " Oooh, duplicate request for '%s@%s' for '%s' \n " ,
ast_log ( LOG_DEBUG , " Oooh, duplicate request for '%s@%s' for '%s' \n " ,
dr . number , dr . dcontext , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & dr . root_eid ) ) ;
dr . number , dr . dcontext , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & dr . root_eid ) ) ;
close ( dr . pfds [ 0 ] ) ;
close ( dr . pfds [ 0 ] ) ;
close ( dr . pfds [ 1 ] ) ;
close ( dr . pfds [ 1 ] ) ;
return - 2 ;
return - 2 ;
} else {
} else {
/* Wait for the cache to populate */
/* Wait for the cache to populate */
if ( option_debug )
ast_debug ( 1 , " Waiting for similar request for '%s@%s' for '%s' \n " ,
ast_log ( LOG_DEBUG , " Waiting for similar request for '%s@%s' for '%s' \n " ,
dr . number , dr . dcontext , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & pending - > root_eid ) ) ;
dr . number , dr . dcontext , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & pending - > root_eid ) ) ;
start = ast_tvnow ( ) ;
start = ast_tvnow ( ) ;
while ( check_request ( pending ) & & ( ast_tvdiff_ms ( ast_tvnow ( ) , start ) < ttlms ) & & ( ! chan | | ! ast_check_hangup ( chan ) ) ) {
while ( check_request ( pending ) & & ( ast_tvdiff_ms ( ast_tvnow ( ) , start ) < ttlms ) & & ( ! chan | | ! ast_check_hangup ( chan ) ) ) {
/* XXX Would be nice to have a way to poll/select here XXX */
/* XXX Would be nice to have a way to poll/select here XXX */
@ -3642,8 +3605,8 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
ms = 100 ;
ms = 100 ;
ast_waitfor_n_fd ( dr . pfds , 1 , & ms , NULL ) ;
ast_waitfor_n_fd ( dr . pfds , 1 , & ms , NULL ) ;
}
}
if ( chan & & ast_check_hangup ( chan ) & & option_debug )
if ( chan & & ast_check_hangup ( chan ) )
ast_ log( LOG_DEBUG , " Hrm, '%s' hungup before their query for %s@%s finished \n " , chan - > name , dr . number , dr . dcontext ) ;
ast_ debug( 1 , " Hrm, '%s' hungup before their query for %s@%s finished \n " , chan - > name , dr . number , dr . dcontext ) ;
cancel_request ( & dr ) ;
cancel_request ( & dr ) ;
unregister_request ( & dr ) ;
unregister_request ( & dr ) ;
res = dr . respcount ;
res = dr . respcount ;
@ -3736,8 +3699,7 @@ static int dundi_precache_internal(const char *context, const char *number, int
int foundcache , skipped , ttlms , ms ;
int foundcache , skipped , ttlms , ms ;
if ( ! context )
if ( ! context )
context = " e164 " ;
context = " e164 " ;
if ( option_debug )
ast_debug ( 1 , " Precache internal (%s@%s)! \n " , number , context ) ;
ast_log ( LOG_DEBUG , " Precache internal (%s@%s)! \n " , number , context ) ;
AST_LIST_LOCK ( & peers ) ;
AST_LIST_LOCK ( & peers ) ;
AST_LIST_TRAVERSE ( & mappings , cur , list ) {
AST_LIST_TRAVERSE ( & mappings , cur , list ) {
@ -4295,8 +4257,7 @@ static int do_register(const void *data)
struct dundi_peer * peer = ( struct dundi_peer * ) data ;
struct dundi_peer * peer = ( struct dundi_peer * ) data ;
char eid_str [ 20 ] ;
char eid_str [ 20 ] ;
char eid_str2 [ 20 ] ;
char eid_str2 [ 20 ] ;
if ( option_debug )
ast_debug ( 1 , " Register us as '%s' to '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & peer - > us_eid ) , dundi_eid_to_str ( eid_str2 , sizeof ( eid_str2 ) , & peer - > eid ) ) ;
ast_log ( LOG_DEBUG , " Register us as '%s' to '%s' \n " , dundi_eid_to_str ( eid_str , sizeof ( eid_str ) , & peer - > us_eid ) , dundi_eid_to_str ( eid_str2 , sizeof ( eid_str2 ) , & peer - > eid ) ) ;
peer - > registerid = ast_sched_add ( sched , default_expiration * 1000 , do_register , data ) ;
peer - > registerid = ast_sched_add ( sched , default_expiration * 1000 , do_register , data ) ;
/* Destroy old transaction if there is one */
/* Destroy old transaction if there is one */
if ( peer - > regtrans )
if ( peer - > regtrans )