--- asterisk-1.4.10~dfsg.orig/pbx/pbx_dundi.c +++ asterisk-1.4.10~dfsg/pbx/pbx_dundi.c @@ -267,6 +267,7 @@ static AST_LIST_HEAD_NOLOCK_STATIC(alltrans, dundi_transaction); static int dundi_xmit(struct dundi_packet *pack); +static struct dundi_peer *any_peer; static void dundi_debug_output(const char *data) { @@ -486,7 +487,8 @@ if (!dundi_eid_cmp(&cur->eid,eid)) break; } - + if (!cur && any_peer) + cur = any_peer; return cur; } @@ -1505,7 +1507,7 @@ unsigned char *bufcpy; struct dundi_ie_data ied; struct dundi_ies ies; - struct dundi_peer *peer; + struct dundi_peer *peer = NULL; char eid_str[20]; char eid_str2[20]; memset(&ied, 0, sizeof(ied)); @@ -1589,6 +1591,21 @@ case DUNDI_COMMAND_REGREQ: /* A register request -- should only have one entity */ peer = find_peer(ies.eids[0]); + /** Dynamic Peering **/ + /* if the peer is not found and we have a valid 'any_peer' setting */ + if (peer == any_peer && any_peer != NULL) + { + /* copy any_peer into a new peer object */ + peer = ast_calloc(1, sizeof(*peer)); + memcpy(peer, any_peer, sizeof(*peer)); + /* set EID to remote EID */ + peer->eid = *ies.eids[0]; + /* add the peer the peer list */ + AST_LIST_LOCK(&peers); + AST_LIST_INSERT_HEAD(&peers, peer, list); + AST_LIST_UNLOCK(&peers); + } + /** End Dynamic Peering **/ if (!peer || !peer->dynamic) { dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_NOAUTH, NULL); dundi_send(trans, DUNDI_COMMAND_REGRESPONSE, 0, 1, &ied); @@ -1801,7 +1818,7 @@ dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL); break; case DUNDI_COMMAND_ENCREJ: - if ((ast_test_flag(trans, FLAG_SENDFULLKEY)) || AST_LIST_EMPTY(&trans->lasttrans) || !(peer = find_peer(&trans->them_eid))) { + if ((ast_test_flag(trans, FLAG_SENDFULLKEY)) || AST_LIST_EMPTY(&trans->lasttrans) || !(peer = find_peer(&trans->them_eid))) { /* No really, it's over at this point */ if (!final) dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL); @@ -4330,6 +4347,7 @@ dundi_ttl = DUNDI_DEFAULT_TTL; dundi_cache_time = DUNDI_DEFAULT_CACHE_TIME; cfg = ast_config_load(config_file); + any_peer = NULL; if (!cfg) { @@ -4453,8 +4471,14 @@ /* Entries */ if (!dundi_str_to_eid(&testeid, cat)) build_peer(&testeid, ast_variable_browse(cfg, cat), &globalpcmodel); - else - ast_log(LOG_NOTICE, "Ignoring invalid EID entry '%s'\n", cat); + else if (!strcasecmp(cat, "*")) + /* any peer */ + { + build_peer(&empty_eid, ast_variable_browse(cfg, cat), &globalpcmodel); + any_peer = find_peer(NULL); + } + else + ast_log(LOG_NOTICE, "Ignoring invalid EID entry '%s'\n", cat); } cat = ast_category_browse(cfg, cat); }