- convert some comments to doxygen format
- convert the list of dundi peers to use the list macros - convert a use of malloc+memset to use ast_calloc git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@23463 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
835dfe67b3
commit
d66de679d9
258
pbx/pbx_dundi.c
258
pbx/pbx_dundi.c
|
@ -222,9 +222,9 @@ static struct dundi_mapping {
|
||||||
struct dundi_mapping *next;
|
struct dundi_mapping *next;
|
||||||
} *mappings = NULL;
|
} *mappings = NULL;
|
||||||
|
|
||||||
static struct dundi_peer {
|
struct dundi_peer {
|
||||||
dundi_eid eid;
|
dundi_eid eid;
|
||||||
struct sockaddr_in addr; /* Address of DUNDi peer */
|
struct sockaddr_in addr; /*!< Address of DUNDi peer */
|
||||||
struct permission *permit;
|
struct permission *permit;
|
||||||
struct permission *include;
|
struct permission *include;
|
||||||
struct permission *precachesend;
|
struct permission *precachesend;
|
||||||
|
@ -237,34 +237,35 @@ static struct dundi_peer {
|
||||||
int qualifyid;
|
int qualifyid;
|
||||||
int sentfullkey;
|
int sentfullkey;
|
||||||
int order;
|
int order;
|
||||||
unsigned char txenckey[256]; /* Transmitted encrypted key + sig */
|
unsigned char txenckey[256]; /*!< Transmitted encrypted key + sig */
|
||||||
unsigned char rxenckey[256]; /* Cache received encrypted key + sig */
|
unsigned char rxenckey[256]; /*!< Cache received encrypted key + sig */
|
||||||
unsigned long us_keycrc32; /* CRC-32 of our key */
|
unsigned long us_keycrc32; /*!< CRC-32 of our key */
|
||||||
aes_encrypt_ctx us_ecx; /* Cached AES 128 Encryption context */
|
aes_encrypt_ctx us_ecx; /*!< Cached AES 128 Encryption context */
|
||||||
aes_decrypt_ctx us_dcx; /* Cached AES 128 Decryption context */
|
aes_decrypt_ctx us_dcx; /*!< Cached AES 128 Decryption context */
|
||||||
unsigned long them_keycrc32;/* CRC-32 of our key */
|
unsigned long them_keycrc32; /*!< CRC-32 of our key */
|
||||||
aes_encrypt_ctx them_ecx; /* Cached AES 128 Encryption context */
|
aes_encrypt_ctx them_ecx; /*!< Cached AES 128 Encryption context */
|
||||||
aes_decrypt_ctx them_dcx; /* Cached AES 128 Decryption context */
|
aes_decrypt_ctx them_dcx; /*!< Cached AES 128 Decryption context */
|
||||||
time_t keyexpire; /* When to expire/recreate key */
|
time_t keyexpire; /*!< When to expire/recreate key */
|
||||||
int registerexpire;
|
int registerexpire;
|
||||||
int lookuptimes[DUNDI_TIMING_HISTORY];
|
int lookuptimes[DUNDI_TIMING_HISTORY];
|
||||||
char *lookups[DUNDI_TIMING_HISTORY];
|
char *lookups[DUNDI_TIMING_HISTORY];
|
||||||
int avgms;
|
int avgms;
|
||||||
struct dundi_transaction *regtrans; /* Registration transaction */
|
struct dundi_transaction *regtrans; /*!< Registration transaction */
|
||||||
struct dundi_transaction *qualtrans; /* Qualify transaction */
|
struct dundi_transaction *qualtrans; /*!< Qualify transaction */
|
||||||
struct dundi_transaction *keypending;
|
struct dundi_transaction *keypending;
|
||||||
int model; /* Pull model */
|
int model; /*!< Pull model */
|
||||||
int pcmodel; /* Push/precache model */
|
int pcmodel; /*!< Push/precache model */
|
||||||
int dynamic; /* Are we dynamic? */
|
int dynamic; /*!< Are we dynamic? */
|
||||||
int lastms; /* Last measured latency */
|
int lastms; /*!< Last measured latency */
|
||||||
int maxms; /* Max permissible latency */
|
int maxms; /*!< Max permissible latency */
|
||||||
struct timeval qualtx; /* Time of transmit */
|
struct timeval qualtx; /*!< Time of transmit */
|
||||||
struct dundi_peer *next;
|
AST_LIST_ENTRY(dundi_peer) list;
|
||||||
} *peers;
|
};
|
||||||
|
|
||||||
|
AST_LIST_HEAD_STATIC(peers, dundi_peer);
|
||||||
|
|
||||||
static struct dundi_precache_queue *pcq;
|
static struct dundi_precache_queue *pcq;
|
||||||
|
|
||||||
AST_MUTEX_DEFINE_STATIC(peerlock);
|
|
||||||
AST_MUTEX_DEFINE_STATIC(pclock);
|
AST_MUTEX_DEFINE_STATIC(pclock);
|
||||||
|
|
||||||
static int dundi_xmit(struct dundi_packet *pack);
|
static int dundi_xmit(struct dundi_packet *pack);
|
||||||
|
@ -477,16 +478,17 @@ static int reset_transaction(struct dundi_transaction *trans)
|
||||||
|
|
||||||
static struct dundi_peer *find_peer(dundi_eid *eid)
|
static struct dundi_peer *find_peer(dundi_eid *eid)
|
||||||
{
|
{
|
||||||
struct dundi_peer *cur;
|
struct dundi_peer *cur = NULL;
|
||||||
|
|
||||||
if (!eid)
|
if (!eid)
|
||||||
eid = &empty_eid;
|
eid = &empty_eid;
|
||||||
cur = peers;
|
|
||||||
while(cur) {
|
AST_LIST_TRAVERSE(&peers, cur, list) {
|
||||||
if (!dundi_eid_cmp(&cur->eid,eid))
|
if (!dundi_eid_cmp(&cur->eid,eid))
|
||||||
return cur;
|
break;
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
|
return cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void build_iv(unsigned char *iv)
|
static void build_iv(unsigned char *iv)
|
||||||
|
@ -627,7 +629,7 @@ static void *dundi_lookup_thread(void *data)
|
||||||
dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_DUPLICATE, "Duplicate Request Pending");
|
dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_DUPLICATE, "Duplicate Request Pending");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
/* Truncate if "don't ask" isn't present */
|
/* Truncate if "don't ask" isn't present */
|
||||||
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';
|
||||||
|
@ -647,7 +649,7 @@ static void *dundi_lookup_thread(void *data)
|
||||||
dundi_send(st->trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied);
|
dundi_send(st->trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied);
|
||||||
st->trans->thread = 0;
|
st->trans->thread = 0;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
free(st);
|
free(st);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -666,7 +668,7 @@ static void *dundi_precache_thread(void *data)
|
||||||
/* Now produce precache */
|
/* Now produce precache */
|
||||||
dundi_precache_internal(st->called_context, st->called_number, st->ttl, st->eids);
|
dundi_precache_internal(st->called_context, st->called_number, st->ttl, st->eids);
|
||||||
|
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
/* Truncate if "don't ask" isn't present */
|
/* Truncate if "don't ask" isn't present */
|
||||||
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';
|
||||||
|
@ -678,7 +680,7 @@ static void *dundi_precache_thread(void *data)
|
||||||
dundi_send(st->trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied);
|
dundi_send(st->trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied);
|
||||||
st->trans->thread = 0;
|
st->trans->thread = 0;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
free(st);
|
free(st);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -713,7 +715,7 @@ static void *dundi_query_thread(void *data)
|
||||||
/* If we do not have a canonical result, keep looking */
|
/* If we do not have a canonical result, keep looking */
|
||||||
res = dundi_query_eid_internal(&dei, st->called_context, &st->reqeid, &hmd, st->ttl, 1, st->eids);
|
res = dundi_query_eid_internal(&dei, st->called_context, &st->reqeid, &hmd, st->ttl, 1, st->eids);
|
||||||
}
|
}
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
if (ast_test_flag(st->trans, FLAG_DEAD)) {
|
if (ast_test_flag(st->trans, FLAG_DEAD)) {
|
||||||
ast_log(LOG_DEBUG, "Our transaction went away!\n");
|
ast_log(LOG_DEBUG, "Our transaction went away!\n");
|
||||||
st->trans->thread = 0;
|
st->trans->thread = 0;
|
||||||
|
@ -734,7 +736,7 @@ static void *dundi_query_thread(void *data)
|
||||||
dundi_send(st->trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied);
|
dundi_send(st->trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied);
|
||||||
st->trans->thread = 0;
|
st->trans->thread = 0;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
free(st);
|
free(st);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1269,11 +1271,11 @@ static void apply_peer(struct dundi_transaction *trans, struct dundi_peer *p)
|
||||||
trans->autokilltimeout = global_autokilltimeout;
|
trans->autokilltimeout = global_autokilltimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \note Called with the peers list already locked */
|
||||||
static int do_register_expire(void *data)
|
static int do_register_expire(void *data)
|
||||||
{
|
{
|
||||||
struct dundi_peer *peer = data;
|
struct dundi_peer *peer = data;
|
||||||
char eid_str[20];
|
char eid_str[20];
|
||||||
/* Called with peerlock already held */
|
|
||||||
ast_log(LOG_DEBUG, "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;
|
||||||
|
@ -1989,9 +1991,9 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
|
||||||
h = (struct dundi_hdr *)buf;
|
h = (struct dundi_hdr *)buf;
|
||||||
if (dundidebug)
|
if (dundidebug)
|
||||||
dundi_showframe(h, 1, &sin, res - sizeof(struct dundi_hdr));
|
dundi_showframe(h, 1, &sin, res - sizeof(struct dundi_hdr));
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
handle_frame(h, &sin, res - sizeof(struct dundi_hdr));
|
handle_frame(h, &sin, res - sizeof(struct dundi_hdr));
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2092,9 +2094,9 @@ static void *network_thread(void *ignore)
|
||||||
res = 1000;
|
res = 1000;
|
||||||
res = ast_io_wait(io, res);
|
res = ast_io_wait(io, res);
|
||||||
if (res >= 0) {
|
if (res >= 0) {
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
ast_sched_runq(sched);
|
ast_sched_runq(sched);
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
check_password();
|
check_password();
|
||||||
}
|
}
|
||||||
|
@ -2162,7 +2164,7 @@ static int dundi_do_store_history(int fd, int argc, char *argv[])
|
||||||
|
|
||||||
static int dundi_flush(int fd, int argc, char *argv[])
|
static int dundi_flush(int fd, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int stats=0;
|
int stats = 0;
|
||||||
if ((argc < 2) || (argc > 3))
|
if ((argc < 2) || (argc > 3))
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
|
@ -2175,19 +2177,17 @@ static int dundi_flush(int fd, int argc, char *argv[])
|
||||||
/* Flush statistics */
|
/* Flush statistics */
|
||||||
struct dundi_peer *p;
|
struct dundi_peer *p;
|
||||||
int x;
|
int x;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
p = peers;
|
AST_LIST_TRAVERSE(&peers, p, list) {
|
||||||
while(p) {
|
for (x = 0;x < DUNDI_TIMING_HISTORY; x++) {
|
||||||
for (x=0;x<DUNDI_TIMING_HISTORY;x++) {
|
|
||||||
if (p->lookups[x])
|
if (p->lookups[x])
|
||||||
free(p->lookups[x]);
|
free(p->lookups[x]);
|
||||||
p->lookups[x] = NULL;
|
p->lookups[x] = NULL;
|
||||||
p->lookuptimes[x] = 0;
|
p->lookuptimes[x] = 0;
|
||||||
}
|
}
|
||||||
p->avgms = 0;
|
p->avgms = 0;
|
||||||
p = p->next;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
} else {
|
} else {
|
||||||
ast_db_deltree("dundi/cache", NULL);
|
ast_db_deltree("dundi/cache", NULL);
|
||||||
ast_cli(fd, "DUNDi Cache Flushed\n");
|
ast_cli(fd, "DUNDi Cache Flushed\n");
|
||||||
|
@ -2236,14 +2236,14 @@ static char *complete_peer_helper(const char *line, const char *word, int pos, i
|
||||||
|
|
||||||
if (pos != rpos)
|
if (pos != rpos)
|
||||||
return NULL;
|
return NULL;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
len = strlen(word);
|
len = strlen(word);
|
||||||
for (p = peers; !ret && p; p = p->next) {
|
AST_LIST_TRAVERSE(&peers, p, list) {
|
||||||
const char *s = dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid);
|
const char *s = dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid);
|
||||||
if (!strncasecmp(word, s, len) && ++which > state)
|
if (!strncasecmp(word, s, len) && ++which > state)
|
||||||
ret = ast_strdup(s);
|
ret = ast_strdup(s);
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2384,12 +2384,10 @@ static int dundi_show_peer(int fd, int argc, char *argv[])
|
||||||
|
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
peer = peers;
|
AST_LIST_TRAVERSE(&peers, peer, list) {
|
||||||
while(peer) {
|
|
||||||
if (!strcasecmp(dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), argv[3]))
|
if (!strcasecmp(dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), argv[3]))
|
||||||
break;
|
break;
|
||||||
peer = peer->next;
|
|
||||||
}
|
}
|
||||||
if (peer) {
|
if (peer) {
|
||||||
switch(peer->order) {
|
switch(peer->order) {
|
||||||
|
@ -2445,7 +2443,7 @@ static int dundi_show_peer(int fd, int argc, char *argv[])
|
||||||
ast_cli(fd, "Average query time: %d ms\n", peer->avgms);
|
ast_cli(fd, "Average query time: %d ms\n", peer->avgms);
|
||||||
} else
|
} else
|
||||||
ast_cli(fd, "No such peer '%s'\n", argv[3]);
|
ast_cli(fd, "No such peer '%s'\n", argv[3]);
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2471,9 +2469,9 @@ static int dundi_show_peers(int fd, int argc, char *argv[])
|
||||||
} else
|
} else
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
}
|
}
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
ast_cli(fd, FORMAT2, "EID", "Host", "Model", "AvgTime", "Status");
|
ast_cli(fd, FORMAT2, "EID", "Host", "Model", "AvgTime", "Status");
|
||||||
for (peer = peers;peer;peer = peer->next) {
|
AST_LIST_TRAVERSE(&peers, peer, list) {
|
||||||
char status[20];
|
char status[20];
|
||||||
int print_line = -1;
|
int print_line = -1;
|
||||||
char srch[2000];
|
char srch[2000];
|
||||||
|
@ -2528,7 +2526,7 @@ static int dundi_show_peers(int fd, int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_cli(fd, "%d dundi peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers);
|
ast_cli(fd, "%d dundi peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers);
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
#undef FORMAT
|
#undef FORMAT
|
||||||
#undef FORMAT2
|
#undef FORMAT2
|
||||||
|
@ -2542,13 +2540,13 @@ static int dundi_show_trans(int fd, int argc, char *argv[])
|
||||||
char iabuf[INET_ADDRSTRLEN];
|
char iabuf[INET_ADDRSTRLEN];
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
ast_cli(fd, FORMAT2, "Remote", "Src", "Dst", "Tx", "Rx", "Ack");
|
ast_cli(fd, FORMAT2, "Remote", "Src", "Dst", "Tx", "Rx", "Ack");
|
||||||
for (trans = alltrans;trans;trans = trans->allnext) {
|
for (trans = alltrans;trans;trans = trans->allnext) {
|
||||||
ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), trans->addr.sin_addr),
|
ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), trans->addr.sin_addr),
|
||||||
ntohs(trans->addr.sin_port), trans->strans, trans->dtrans, trans->oseqno, trans->iseqno, trans->aseqno);
|
ntohs(trans->addr.sin_port), trans->strans, trans->dtrans, trans->oseqno, trans->iseqno, trans->aseqno);
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
#undef FORMAT
|
#undef FORMAT
|
||||||
#undef FORMAT2
|
#undef FORMAT2
|
||||||
|
@ -2559,9 +2557,9 @@ static int dundi_show_entityid(int fd, int argc, char *argv[])
|
||||||
char eid_str[20];
|
char eid_str[20];
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid);
|
dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid);
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
ast_cli(fd, "Global EID for this system is '%s'\n", eid_str);
|
ast_cli(fd, "Global EID for this system is '%s'\n", eid_str);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -2574,13 +2572,13 @@ static int dundi_show_requests(int fd, int argc, char *argv[])
|
||||||
char eidstr[20];
|
char eidstr[20];
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
ast_cli(fd, FORMAT2, "Number", "Context", "Root", "Max", "Rsp");
|
ast_cli(fd, FORMAT2, "Number", "Context", "Root", "Max", "Rsp");
|
||||||
for (req = requests;req;req = req->next) {
|
for (req = requests;req;req = req->next) {
|
||||||
ast_cli(fd, FORMAT, req->number, req->dcontext,
|
ast_cli(fd, FORMAT, req->number, req->dcontext,
|
||||||
dundi_eid_zero(&req->root_eid) ? "<unspecified>" : dundi_eid_to_str(eidstr, sizeof(eidstr), &req->root_eid), req->maxcount, req->respcount);
|
dundi_eid_zero(&req->root_eid) ? "<unspecified>" : dundi_eid_to_str(eidstr, sizeof(eidstr), &req->root_eid), req->maxcount, req->respcount);
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
#undef FORMAT
|
#undef FORMAT
|
||||||
#undef FORMAT2
|
#undef FORMAT2
|
||||||
|
@ -2596,14 +2594,14 @@ static int dundi_show_mappings(int fd, int argc, char *argv[])
|
||||||
char fs[256];
|
char fs[256];
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
ast_cli(fd, FORMAT2, "DUNDi Cntxt", "Weight", "Local Cntxt", "Options", "Tech", "Destination");
|
ast_cli(fd, FORMAT2, "DUNDi Cntxt", "Weight", "Local Cntxt", "Options", "Tech", "Destination");
|
||||||
for (map = mappings;map;map = map->next) {
|
for (map = mappings;map;map = map->next) {
|
||||||
ast_cli(fd, FORMAT, map->dcontext, map->weight,
|
ast_cli(fd, FORMAT, map->dcontext, map->weight,
|
||||||
ast_strlen_zero(map->lcontext) ? "<none>" : map->lcontext,
|
ast_strlen_zero(map->lcontext) ? "<none>" : map->lcontext,
|
||||||
dundi_flags2str(fs, sizeof(fs), map->options), tech2str(map->tech), map->dest);
|
dundi_flags2str(fs, sizeof(fs), map->options), tech2str(map->tech), map->dest);
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
#undef FORMAT
|
#undef FORMAT
|
||||||
#undef FORMAT2
|
#undef FORMAT2
|
||||||
|
@ -2839,8 +2837,7 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
|
||||||
int cnt;
|
int cnt;
|
||||||
char eid_str[20];
|
char eid_str[20];
|
||||||
if (ast_test_flag(trans, FLAG_ISREG | FLAG_ISQUAL | FLAG_STOREHIST)) {
|
if (ast_test_flag(trans, FLAG_ISREG | FLAG_ISQUAL | FLAG_STOREHIST)) {
|
||||||
peer = peers;
|
AST_LIST_TRAVERSE(&peers, peer, list) {
|
||||||
while (peer) {
|
|
||||||
if (peer->regtrans == trans)
|
if (peer->regtrans == trans)
|
||||||
peer->regtrans = NULL;
|
peer->regtrans = NULL;
|
||||||
if (peer->keypending == trans)
|
if (peer->keypending == trans)
|
||||||
|
@ -2891,7 +2888,6 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peer = peer->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trans->parent) {
|
if (trans->parent) {
|
||||||
|
@ -2949,7 +2945,7 @@ static int dundi_rexmit(void *data)
|
||||||
struct dundi_packet *pack;
|
struct dundi_packet *pack;
|
||||||
char iabuf[INET_ADDRSTRLEN];
|
char iabuf[INET_ADDRSTRLEN];
|
||||||
int res;
|
int res;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
pack = data;
|
pack = data;
|
||||||
if (pack->retrans < 1) {
|
if (pack->retrans < 1) {
|
||||||
pack->retransid = -1;
|
pack->retransid = -1;
|
||||||
|
@ -2965,7 +2961,7 @@ static int dundi_rexmit(void *data)
|
||||||
dundi_xmit(pack);
|
dundi_xmit(pack);
|
||||||
res = 1;
|
res = 1;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3060,9 +3056,8 @@ static void dundi_ie_append_eid_appropriately(struct dundi_ie_data *ied, char *c
|
||||||
dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
|
dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
p = peers;
|
AST_LIST_TRAVERSE(&peers, p, list) {
|
||||||
while(p) {
|
|
||||||
if (!dundi_eid_cmp(&p->eid, eid)) {
|
if (!dundi_eid_cmp(&p->eid, eid)) {
|
||||||
if (has_permission(p->include, context))
|
if (has_permission(p->include, context))
|
||||||
dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
|
dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
|
||||||
|
@ -3070,11 +3065,10 @@ static void dundi_ie_append_eid_appropriately(struct dundi_ie_data *ied, char *c
|
||||||
dundi_ie_append_eid(ied, DUNDI_IE_EID, eid);
|
dundi_ie_append_eid(ied, DUNDI_IE_EID, eid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p = p->next;
|
|
||||||
}
|
}
|
||||||
if (!p)
|
if (!p)
|
||||||
dundi_ie_append_eid(ied, DUNDI_IE_EID, eid);
|
dundi_ie_append_eid(ied, DUNDI_IE_EID, eid);
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dundi_discover(struct dundi_transaction *trans)
|
static int dundi_discover(struct dundi_transaction *trans)
|
||||||
|
@ -3192,13 +3186,13 @@ static int dundi_query(struct dundi_transaction *trans)
|
||||||
static int discover_transactions(struct dundi_request *dr)
|
static int discover_transactions(struct dundi_request *dr)
|
||||||
{
|
{
|
||||||
struct dundi_transaction *trans;
|
struct dundi_transaction *trans;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
trans = dr->trans;
|
trans = dr->trans;
|
||||||
while(trans) {
|
while(trans) {
|
||||||
dundi_discover(trans);
|
dundi_discover(trans);
|
||||||
trans = trans->next;
|
trans = trans->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3206,7 +3200,7 @@ static int precache_transactions(struct dundi_request *dr, struct dundi_mapping
|
||||||
{
|
{
|
||||||
struct dundi_transaction *trans, *transn;
|
struct dundi_transaction *trans, *transn;
|
||||||
/* Mark all as "in thread" so they don't disappear */
|
/* Mark all as "in thread" so they don't disappear */
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
trans = dr->trans;
|
trans = dr->trans;
|
||||||
while(trans) {
|
while(trans) {
|
||||||
if (trans->thread)
|
if (trans->thread)
|
||||||
|
@ -3214,7 +3208,7 @@ static int precache_transactions(struct dundi_request *dr, struct dundi_mapping
|
||||||
trans->thread = 1;
|
trans->thread = 1;
|
||||||
trans = trans->next;
|
trans = trans->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
|
|
||||||
trans = dr->trans;
|
trans = dr->trans;
|
||||||
while(trans) {
|
while(trans) {
|
||||||
|
@ -3224,7 +3218,7 @@ static int precache_transactions(struct dundi_request *dr, struct dundi_mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup any that got destroyed in the mean time */
|
/* Cleanup any that got destroyed in the mean time */
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
trans = dr->trans;
|
trans = dr->trans;
|
||||||
while(trans) {
|
while(trans) {
|
||||||
transn = trans->next;
|
transn = trans->next;
|
||||||
|
@ -3235,20 +3229,20 @@ static int precache_transactions(struct dundi_request *dr, struct dundi_mapping
|
||||||
}
|
}
|
||||||
trans = transn;
|
trans = transn;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int query_transactions(struct dundi_request *dr)
|
static int query_transactions(struct dundi_request *dr)
|
||||||
{
|
{
|
||||||
struct dundi_transaction *trans;
|
struct dundi_transaction *trans;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
trans = dr->trans;
|
trans = dr->trans;
|
||||||
while(trans) {
|
while(trans) {
|
||||||
dundi_query(trans);
|
dundi_query(trans);
|
||||||
trans = trans->next;
|
trans = trans->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3261,7 +3255,7 @@ static int optimize_transactions(struct dundi_request *dr, int order)
|
||||||
dundi_eid tmp;
|
dundi_eid tmp;
|
||||||
int x;
|
int x;
|
||||||
int needpush;
|
int needpush;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
trans = dr->trans;
|
trans = dr->trans;
|
||||||
while(trans) {
|
while(trans) {
|
||||||
/* Pop off the true root */
|
/* Pop off the true root */
|
||||||
|
@ -3273,8 +3267,7 @@ static int optimize_transactions(struct dundi_request *dr, int order)
|
||||||
needpush = 0;
|
needpush = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
peer = peers;
|
AST_LIST_TRAVERSE(&peers, peer, list) {
|
||||||
while(peer) {
|
|
||||||
if (has_permission(peer->include, dr->dcontext) &&
|
if (has_permission(peer->include, dr->dcontext) &&
|
||||||
dundi_eid_cmp(&peer->eid, &trans->them_eid) &&
|
dundi_eid_cmp(&peer->eid, &trans->them_eid) &&
|
||||||
(peer->order <= order)) {
|
(peer->order <= order)) {
|
||||||
|
@ -3299,14 +3292,13 @@ static int optimize_transactions(struct dundi_request *dr, int order)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peer = peer->next;
|
|
||||||
}
|
}
|
||||||
/* If necessary, push the true root back on the end */
|
/* If necessary, push the true root back on the end */
|
||||||
if (needpush)
|
if (needpush)
|
||||||
trans->eids[trans->eidcount++] = tmp;
|
trans->eids[trans->eidcount++] = tmp;
|
||||||
trans = trans->next;
|
trans = trans->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3342,7 +3334,7 @@ static void cancel_request(struct dundi_request *dr)
|
||||||
{
|
{
|
||||||
struct dundi_transaction *trans, *next;
|
struct dundi_transaction *trans, *next;
|
||||||
|
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
trans = dr->trans;
|
trans = dr->trans;
|
||||||
|
|
||||||
while(trans) {
|
while(trans) {
|
||||||
|
@ -3354,15 +3346,15 @@ static void cancel_request(struct dundi_request *dr)
|
||||||
dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
|
dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
|
||||||
trans = next;
|
trans = next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void abort_request(struct dundi_request *dr)
|
static void abort_request(struct dundi_request *dr)
|
||||||
{
|
{
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
while(dr->trans)
|
while(dr->trans)
|
||||||
destroy_trans(dr->trans, 0);
|
destroy_trans(dr->trans, 0);
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void build_transactions(struct dundi_request *dr, int ttl, int order, int *foundcache, int *skipped, int blockempty, int nocache, int modeselect, dundi_eid *skip, dundi_eid *avoid[], int directs[])
|
static void build_transactions(struct dundi_request *dr, int ttl, int order, int *foundcache, int *skipped, int blockempty, int nocache, int modeselect, dundi_eid *skip, dundi_eid *avoid[], int directs[])
|
||||||
|
@ -3373,9 +3365,8 @@ static void build_transactions(struct dundi_request *dr, int ttl, int order, int
|
||||||
int pass;
|
int pass;
|
||||||
int allowconnect;
|
int allowconnect;
|
||||||
char eid_str[20];
|
char eid_str[20];
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
p = peers;
|
AST_LIST_TRAVERSE(&peers, p, list) {
|
||||||
while(p) {
|
|
||||||
if (modeselect == 1) {
|
if (modeselect == 1) {
|
||||||
/* Send the precache to push upstreams only! */
|
/* Send the precache to push upstreams only! */
|
||||||
pass = has_permission(p->permit, dr->dcontext) && (p->pcmodel & DUNDI_MODEL_OUTBOUND);
|
pass = has_permission(p->permit, dr->dcontext) && (p->pcmodel & DUNDI_MODEL_OUTBOUND);
|
||||||
|
@ -3419,9 +3410,8 @@ static void build_transactions(struct dundi_request *dr, int ttl, int order, int
|
||||||
} else if (!*skipped || (p->order < *skipped))
|
} else if (!*skipped || (p->order < *skipped))
|
||||||
*skipped = p->order;
|
*skipped = p->order;
|
||||||
}
|
}
|
||||||
p = p->next;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int register_request(struct dundi_request *dr, struct dundi_request **pending)
|
static int register_request(struct dundi_request *dr, struct dundi_request **pending)
|
||||||
|
@ -3429,7 +3419,7 @@ static int register_request(struct dundi_request *dr, struct dundi_request **pen
|
||||||
struct dundi_request *cur;
|
struct dundi_request *cur;
|
||||||
int res=0;
|
int res=0;
|
||||||
char eid_str[20];
|
char eid_str[20];
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
cur = requests;
|
cur = requests;
|
||||||
while(cur) {
|
while(cur) {
|
||||||
if (option_debug)
|
if (option_debug)
|
||||||
|
@ -3454,14 +3444,14 @@ static int register_request(struct dundi_request *dr, struct dundi_request **pen
|
||||||
requests = dr;
|
requests = dr;
|
||||||
*pending = NULL;
|
*pending = NULL;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unregister_request(struct dundi_request *dr)
|
static void unregister_request(struct dundi_request *dr)
|
||||||
{
|
{
|
||||||
struct dundi_request *cur, *prev;
|
struct dundi_request *cur, *prev;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
cur = requests;
|
cur = requests;
|
||||||
while(cur) {
|
while(cur) {
|
||||||
|
@ -3475,14 +3465,14 @@ static void unregister_request(struct dundi_request *dr)
|
||||||
prev = cur;
|
prev = cur;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_request(struct dundi_request *dr)
|
static int check_request(struct dundi_request *dr)
|
||||||
{
|
{
|
||||||
struct dundi_request *cur;
|
struct dundi_request *cur;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
cur = requests;
|
cur = requests;
|
||||||
while(cur) {
|
while(cur) {
|
||||||
if (cur == dr) {
|
if (cur == dr) {
|
||||||
|
@ -3491,7 +3481,7 @@ static int check_request(struct dundi_request *dr)
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3709,7 +3699,7 @@ static int dundi_precache_internal(const char *context, const char *number, int
|
||||||
context = "e164";
|
context = "e164";
|
||||||
ast_log(LOG_DEBUG, "Precache internal (%s@%s)!\n", number, context);
|
ast_log(LOG_DEBUG, "Precache internal (%s@%s)!\n", number, context);
|
||||||
|
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
nummaps = 0;
|
nummaps = 0;
|
||||||
cur = mappings;
|
cur = mappings;
|
||||||
while(cur) {
|
while(cur) {
|
||||||
|
@ -3729,7 +3719,7 @@ static int dundi_precache_internal(const char *context, const char *number, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
if (!nummaps || !maps)
|
if (!nummaps || !maps)
|
||||||
return -1;
|
return -1;
|
||||||
ttlms = DUNDI_FLUFF_TIME + ttl * DUNDI_TTL_TIME;
|
ttlms = DUNDI_FLUFF_TIME + ttl * DUNDI_TTL_TIME;
|
||||||
|
@ -3900,25 +3890,23 @@ static struct ast_custom_function dundi_function = {
|
||||||
static void mark_peers(void)
|
static void mark_peers(void)
|
||||||
{
|
{
|
||||||
struct dundi_peer *peer;
|
struct dundi_peer *peer;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
peer = peers;
|
AST_LIST_TRAVERSE(&peers, peer, list) {
|
||||||
while(peer) {
|
|
||||||
peer->dead = 1;
|
peer->dead = 1;
|
||||||
peer = peer->next;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mark_mappings(void)
|
static void mark_mappings(void)
|
||||||
{
|
{
|
||||||
struct dundi_mapping *map;
|
struct dundi_mapping *map;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
map = mappings;
|
map = mappings;
|
||||||
while(map) {
|
while(map) {
|
||||||
map->dead = 1;
|
map->dead = 1;
|
||||||
map = map->next;
|
map = map->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy_permissions(struct permission *p)
|
static void destroy_permissions(struct permission *p)
|
||||||
|
@ -3953,29 +3941,23 @@ static void destroy_map(struct dundi_mapping *map)
|
||||||
|
|
||||||
static void prune_peers(void)
|
static void prune_peers(void)
|
||||||
{
|
{
|
||||||
struct dundi_peer *peer, *prev, *next;
|
struct dundi_peer *peer;
|
||||||
ast_mutex_lock(&peerlock);
|
|
||||||
peer = peers;
|
AST_LIST_LOCK(&peers);
|
||||||
prev = NULL;
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&peers, peer, list) {
|
||||||
while(peer) {
|
|
||||||
next = peer->next;
|
|
||||||
if (peer->dead) {
|
if (peer->dead) {
|
||||||
if (prev)
|
AST_LIST_REMOVE_CURRENT(&peers, list);
|
||||||
prev->next = peer->next;
|
|
||||||
else
|
|
||||||
peers = peer->next;
|
|
||||||
destroy_peer(peer);
|
destroy_peer(peer);
|
||||||
} else
|
}
|
||||||
prev = peer;
|
|
||||||
peer = next;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_TRAVERSE_SAFE_END
|
||||||
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prune_mappings(void)
|
static void prune_mappings(void)
|
||||||
{
|
{
|
||||||
struct dundi_mapping *map, *prev, *next;
|
struct dundi_mapping *map, *prev, *next;
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
map = mappings;
|
map = mappings;
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
while(map) {
|
while(map) {
|
||||||
|
@ -3990,7 +3972,7 @@ static void prune_mappings(void)
|
||||||
prev = map;
|
prev = map;
|
||||||
map = next;
|
map = next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct permission *append_permission(struct permission *p, char *s, int allow)
|
static struct permission *append_permission(struct permission *p, char *s, int allow)
|
||||||
|
@ -4093,13 +4075,13 @@ static void build_mapping(char *name, char *value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* \note Called with the peers list already locked */
|
||||||
static int do_register(void *data)
|
static int do_register(void *data)
|
||||||
{
|
{
|
||||||
struct dundi_ie_data ied;
|
struct dundi_ie_data ied;
|
||||||
struct dundi_peer *peer = data;
|
struct dundi_peer *peer = data;
|
||||||
char eid_str[20];
|
char eid_str[20];
|
||||||
char eid_str2[20];
|
char eid_str2[20];
|
||||||
/* Called with peerlock already held */
|
|
||||||
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));
|
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 */
|
||||||
|
@ -4187,27 +4169,23 @@ static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode
|
||||||
int needregister=0;
|
int needregister=0;
|
||||||
char eid_str[20];
|
char eid_str[20];
|
||||||
|
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
peer = peers;
|
AST_LIST_TRAVERSE(&peers, peer, list) {
|
||||||
while(peer) {
|
|
||||||
if (!dundi_eid_cmp(&peer->eid, eid)) {
|
if (!dundi_eid_cmp(&peer->eid, eid)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
peer = peer->next;
|
|
||||||
}
|
}
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
/* Add us into the list */
|
/* Add us into the list */
|
||||||
peer = malloc(sizeof(struct dundi_peer));
|
peer = ast_calloc(1, sizeof(*peer));
|
||||||
if (peer) {
|
if (peer) {
|
||||||
memset(peer, 0, sizeof(struct dundi_peer));
|
|
||||||
peer->registerid = -1;
|
peer->registerid = -1;
|
||||||
peer->registerexpire = -1;
|
peer->registerexpire = -1;
|
||||||
peer->qualifyid = -1;
|
peer->qualifyid = -1;
|
||||||
peer->addr.sin_family = AF_INET;
|
peer->addr.sin_family = AF_INET;
|
||||||
peer->addr.sin_port = htons(DUNDI_PORT);
|
peer->addr.sin_port = htons(DUNDI_PORT);
|
||||||
populate_addr(peer, eid);
|
populate_addr(peer, eid);
|
||||||
peer->next = peers;
|
AST_LIST_INSERT_HEAD(&peers, peer, list);
|
||||||
peers = peer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (peer) {
|
if (peer) {
|
||||||
|
@ -4331,7 +4309,7 @@ static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode
|
||||||
qualify_peer(peer, 1);
|
qualify_peer(peer, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dundi_helper(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *data, int flag)
|
static int dundi_helper(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *data, int flag)
|
||||||
|
@ -4484,7 +4462,7 @@ static int set_config(char *config_file, struct sockaddr_in* sin)
|
||||||
ast_log(LOG_WARNING, "Unable to look up host '%s'\n", hn);
|
ast_log(LOG_WARNING, "Unable to look up host '%s'\n", hn);
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Unable to get host name!\n");
|
ast_log(LOG_WARNING, "Unable to get host name!\n");
|
||||||
ast_mutex_lock(&peerlock);
|
AST_LIST_LOCK(&peers);
|
||||||
reset_global_eid();
|
reset_global_eid();
|
||||||
global_storehistory = 0;
|
global_storehistory = 0;
|
||||||
ast_copy_string(secretpath, "dundi", sizeof(secretpath));
|
ast_copy_string(secretpath, "dundi", sizeof(secretpath));
|
||||||
|
@ -4576,7 +4554,7 @@ static int set_config(char *config_file, struct sockaddr_in* sin)
|
||||||
}
|
}
|
||||||
v = v->next;
|
v = v->next;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&peerlock);
|
AST_LIST_UNLOCK(&peers);
|
||||||
mark_mappings();
|
mark_mappings();
|
||||||
v = ast_variable_browse(cfg, "mappings");
|
v = ast_variable_browse(cfg, "mappings");
|
||||||
while(v) {
|
while(v) {
|
||||||
|
|
Loading…
Reference in New Issue