43 #include <sys/ioctl.h>
49 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__)
50 #include <net/if_dl.h>
153 #define MAX_RESULTS 64
155 #define MAX_PACKET_SIZE 8192
157 #define MAX_WEIGHT 59999
159 #define DUNDI_MODEL_INBOUND (1 << 0)
160 #define DUNDI_MODEL_OUTBOUND (1 << 1)
161 #define DUNDI_MODEL_SYMMETRIC (DUNDI_MODEL_INBOUND | DUNDI_MODEL_OUTBOUND)
164 #define DUNDI_TIMING_HISTORY 10
176 #define DUNDI_FLAG_INTERNAL_NOPARTIAL (1 << 17)
179 #define DUNDI_SECRET_TIME 15
181 #define DUNDI_SECRET_TIME DUNDI_DEFAULT_CACHE_TIME
191 static unsigned int tos = 0;
247 struct timeval
start;
373 if (!strcasecmp(perm->
name,
"all") || !strcasecmp(perm->
name, cont))
398 if (!strcasecmp(
str,
"IAX") || !strcasecmp(
str,
"IAX2"))
400 else if (!strcasecmp(
str,
"SIP"))
402 else if (!strcasecmp(
str,
"H323"))
408 static int dundi_lookup_internal(
struct dundi_result *
result,
int maxret,
struct ast_channel *chan,
const char *dcontext,
const char *
number,
int ttl,
int blockempty,
struct dundi_hint_metadata *md,
int *expiration,
int cybpass,
int modeselect,
dundi_eid *skip,
dundi_eid *avoid[],
int direct[]);
465 memset(&
tmp, 0,
sizeof(
tmp));
466 memset(&trans, 0,
sizeof(trans));
473 tmp.hdr.cmdflags = 0;
476 tmp.pack.parent = &trans;
493 tid = (tid % 32766) + 1;
494 }
while (tid != stid);
536 unsigned int *fluffy;
538 fluffy = (
unsigned int *)(iv);
605 dr[anscnt].techint = map->
tech;
608 dr[anscnt].eid = *us_eid;
629 dr[anscnt].dest[0] =
'\0';
637 for (x = 0; x < (
sizeof(
tmp) - 1); x++) {
638 tmp[x] = called_number[x];
644 if (strlen(
tmp) > strlen(hmd->
exten)) {
671 memset(&ied, 0,
sizeof(ied));
672 memset(&
dr, 0,
sizeof(
dr));
673 memset(&hmd, 0,
sizeof(hmd));
680 for (x=0;x<ouranswers;x++) {
687 res =
dundi_lookup_internal(
dr + ouranswers,
MAX_RESULTS - ouranswers,
NULL, st->
called_context, st->
called_number, st->
ttl, 1, &hmd, &expiration, st->
nocache, 0,
NULL, st->
eids, st->
directs);
692 if ((res < -1) && (!ouranswers))
701 ast_debug(1,
"Our transaction went away!\n");
705 for (x=0;x<ouranswers;x++) {
707 if (
dr[x].expiration && (expiration >
dr[x].expiration))
708 expiration =
dr[x].expiration;
730 memset(&ied, 0,
sizeof(ied));
740 ast_debug(1,
"Our transaction went away!\n");
765 memset(&ied, 0,
sizeof(ied));
766 memset(&dei, 0,
sizeof(dei));
767 memset(&hmd, 0,
sizeof(hmd));
770 ast_debug(1,
"Neat, someone look for us!\n");
785 ast_debug(1,
"Our transaction went away!\n");
817 pthread_t lookupthread;
838 for (x=skipfirst;ies->
eids[x];x++) {
840 *st->
eids[x-skipfirst] = *ies->
eids[x];
869 char eidpeer_str[20];
870 char eidroot_str[20];
885 snprintf(key1,
sizeof(key1),
"hint/%s/%s/%s/e%08x", eidpeer_str, hint->
data, req->
dcontext, unaffected ? 0 : req->
crc32);
886 snprintf(key2,
sizeof(key2),
"hint/%s/%s/%s/r%s", eidpeer_str, hint->
data, req->
dcontext, eidroot_str);
889 timeout += expiration;
890 snprintf(data,
sizeof(data),
"%ld|", (
long)(timeout));
893 ast_debug(1,
"Caching hint at '%s'\n", key1);
895 ast_debug(1,
"Caching hint at '%s'\n", key2);
905 char eidpeer_str[20];
906 char eidroot_str[20];
921 snprintf(key1,
sizeof(key1),
"%s/%s/%s/e%08x", eidpeer_str, req->
number, req->
dcontext, unaffected ? 0 : req->
crc32);
922 snprintf(key2,
sizeof(key2),
"%s/%s/%s/r%s", eidpeer_str, req->
number, req->
dcontext, eidroot_str);
925 timeout += expiration;
926 snprintf(data,
sizeof(data),
"%ld|", (
long)(timeout));
929 if (strchr(req->
dr[x].
dest,
'|'))
931 snprintf(data + strlen(data),
sizeof(data) - strlen(data),
"%u/%d/%d/%s/%s|",
955 pthread_t lookupthread;
957 memset(&dr2, 0,
sizeof(dr2));
958 memset(&
dr, 0,
sizeof(
dr));
959 memset(&hmd, 0,
sizeof(hmd));
967 dr.pfds[0] =
dr.pfds[1] = -1;
1017 if (!strcasecmp(cur->
dcontext, ccontext))
1047 for (x=skipfirst;ies->
eids[x];x++) {
1049 *st->
eids[x-skipfirst] = *ies->
eids[x];
1057 if (!strcasecmp(cur->
dcontext, ccontext)) {
1072 memset(&ied, 0,
sizeof(ied));
1079 memset(&ied, 0,
sizeof(ied));
1098 pthread_t lookupthread;
1102 if (!strcasecmp(cur->
dcontext, ccontext))
1130 for (x=skipfirst;ies->
eids[x];x++) {
1132 *st->
eids[x-skipfirst] = *ies->
eids[x];
1140 if (!strcasecmp(cur->
dcontext, ccontext)) {
1155 memset(&ied, 0,
sizeof(ied));
1162 memset(&ied, 0,
sizeof(ied));
1173 char *ptr, *term, *src;
1182 if (!
ast_db_get(
"dundi/cache", key, data,
sizeof(data))) {
1186 int expiration = timeout - now;
1187 if (expiration > 0) {
1188 ast_debug(1,
"Found cache expiring in %d seconds!\n", expiration);
1190 while((sscanf(ptr,
"%30d/%30d/%30d/%n", (
int *)&(
flags.flags), &
weight, &tech, &length) == 3)) {
1192 term = strchr(ptr,
'|');
1195 src = strrchr(ptr,
'/');
1201 ast_debug(1,
"Found cached answer '%s/%s' originally from '%s' with flags '%s' on behalf of '%s'\n",
1206 !strcmp(req->
dr[z].
dest, ptr))
1230 if (expiration < *lowexpiration)
1231 *lowexpiration = expiration;
1245 char eidroot_str[20];
1249 char eid_str_full[20];
1252 char key[
sizeof(eid_str) +
sizeof(
tmp) +
sizeof(req->
dcontext) +
sizeof(eidroot_str) +
sizeof(
"hint////r")];
1259 snprintf(key,
sizeof(key),
"%s/%s/%s/e%08x", eid_str, req->
number, req->
dcontext, crc);
1261 snprintf(key,
sizeof(key),
"%s/%s/%s/e%08x", eid_str, req->
number, req->
dcontext, (
unsigned)0);
1263 snprintf(key,
sizeof(key),
"%s/%s/%s/r%s", eid_str, req->
number, req->
dcontext, eidroot_str);
1274 snprintf(key,
sizeof(key),
"hint/%s/%s/%s/e%08x", eid_str,
tmp, req->
dcontext, crc);
1276 snprintf(key,
sizeof(key),
"hint/%s/%s/%s/e%08x", eid_str,
tmp, req->
dcontext, (
unsigned)0);
1278 snprintf(key,
sizeof(key),
"hint/%s/%s/%s/r%s", eid_str,
tmp, req->
dcontext, eidroot_str);
1336 unsigned char key[16];
1346 ast_log(
LOG_NOTICE,
"No such key '%s' for creating RSA encrypted shared key for '%s'!\n",
1352 ast_log(
LOG_NOTICE,
"No such key '%s' for signing RSA encrypted shared key for '%s'!\n",
1375 unsigned char curblock[16];
1377 memcpy(curblock, iv,
sizeof(curblock));
1380 curblock[x] ^= src[x];
1382 memcpy(curblock, dst,
sizeof(curblock));
1391 unsigned char lastblock[16];
1393 memcpy(lastblock, iv,
sizeof(lastblock));
1397 dst[x] ^= lastblock[x];
1398 memcpy(lastblock, src,
sizeof(lastblock));
1408 int space = *dstlen;
1409 unsigned long bytes;
1411 unsigned char *decrypt_space;
1418 if (uncompress(dst + 6, &bytes, decrypt_space, srclen) != Z_OK) {
1419 ast_debug(1,
"Ouch, uncompress failed :(\n");
1423 *dstlen = bytes + 6;
1430 unsigned char *compress_space;
1433 unsigned long bytes;
1436 unsigned char iv[16];
1439 memset(compress_space, 0,
len);
1442 res = compress(compress_space, &bytes, pack->
data + 6, pack->
datalen - 6);
1444 ast_debug(1,
"Ouch, compression failed!\n");
1447 memset(&ied, 0,
sizeof(ied));
1477 if ((ied.
pos + bytes) >=
sizeof(ied.
buf)) {
1482 ied.
pos += ((bytes + 15) / 16) * 16;
1492 static int check_key(
struct dundi_peer *peer,
unsigned char *newkey,
unsigned char *newsig, uint32_t keycrc32)
1494 unsigned char dst[128];
1502 }
else if (!newkey || !newsig)
1504 if (!memcmp(peer->
rxenckey, newkey, 128) &&
1505 !memcmp(peer->
rxenckey + 128, newsig, 128)) {
1536 ast_debug(1,
"Wow, new key combo passed signature and decrypt!\n");
1537 memcpy(peer->
rxenckey, newkey, 128);
1538 memcpy(peer->
rxenckey + 128, newsig, 128);
1549 *peer_dst = *peer_src;
1562 memset(&peer_dst->
permit, 0,
sizeof(peer_dst->
permit));
1566 if (!(perm =
ast_calloc(1,
sizeof(*perm) + strlen(cur->
name) + 1)))
1576 if (!(perm =
ast_calloc(1,
sizeof(*perm) + strlen(cur->
name) + 1)))
1589 int final = hdr->
cmdresp & 0x80;
1590 int cmd = hdr->
cmdresp & 0x7f;
1595 unsigned char *bufcpy;
1619 memcpy(bufcpy, hdr->
ies, datalen);
1620 ast_debug(1,
"Got canonical message %d (%d), %d bytes data%s\n", cmd, hdr->
oseqno, datalen,
final ?
" (Final)" :
"");
1623 goto return_cleanup;
1644 if (strlen(peer->
inkey)) {
1645 hasauth = encrypted;
1710 if (!peer || !peer->
dynamic) {
1717 hasauth = encrypted;
1729 ast_verb(3,
"Registered DUNDi peer '%s' at '%s'\n",
1745 if (ies.
cause < 1) {
1749 authpass = encrypted;
1829 if (ies.
cause < 1) {
1831 ast_debug(1,
"Looks like success of some sort (%d)\n", ies.
cause);
1833 authpass = encrypted;
1882 if (ies.
cause < 1) {
1886 hasauth = encrypted;
1934 memset(&ies, 0,
sizeof(ies));
1937 memset(ied, 0,
sizeof(*ied));
1970 ddatalen =
sizeof(decoded);
1981 ast_debug(1,
"Ouch, decrypt failed :(\n");
2027 if ((pack->
h->
oseqno + 1) % 255 == iseqno) {
2078 ast_debug(1,
"Dropping packet out of window!\n");
2092 if (
errno != ECONNREFUSED)
2112 unsigned char tmp[16];
2118 while((s = strchr(secret,
';'))) *s =
'+';
2119 while((s = strchr(secret,
'/'))) *s =
'+';
2120 while((s = strchr(secret,
':'))) *s =
'+';
2121 while((s = strchr(secret,
'@'))) *s =
'+';
2129 snprintf(
tmp,
sizeof(
tmp),
"%s;%s", oldkey, newkey);
2131 snprintf(
tmp,
sizeof(
tmp),
"%s", newkey);
2155 if ((time(
NULL) - expired) < 0) {
2201 int *socket_read_id2 =
NULL;
2208 if ((res > 1000) || (res < 0))
2221 if (socket_read_id2) {
2231 int striplen =
sizeof(
"/dundi/cache");
2235 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,
NULL);
2240 for (; db_entry; db_entry = db_entry->
next) {
2245 ast_debug(1,
"clearing expired DUNDI cache entry: %s\n", db_entry->
key);
2252 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,
NULL);
2253 pthread_testcancel();
2255 pthread_testcancel();
2308 e->
command =
"dundi set debug {on|off}";
2310 "Usage: dundi set debug {on|off}\n"
2311 " Enables/Disables dumping of DUNDi packets for debugging purposes\n";
2317 if (
a->argc != e->
args) {
2320 if (!strncasecmp(
a->argv[e->
args -1],
"on", 2)) {
2322 ast_cli(
a->fd,
"DUNDi Debugging Enabled\n");
2325 ast_cli(
a->fd,
"DUNDi Debugging Disabled\n");
2334 e->
command =
"dundi store history {on|off}";
2336 "Usage: dundi store history {on|off}\n"
2337 " Enables/Disables storing of DUNDi requests and times for debugging\n"
2344 if (
a->argc != e->
args) {
2347 if (!strncasecmp(
a->argv[e->
args -1],
"on", 2)) {
2349 ast_cli(
a->fd,
"DUNDi History Storage Enabled\n");
2352 ast_cli(
a->fd,
"DUNDi History Storage Disabled\n");
2362 e->
command =
"dundi flush [stats]";
2364 "Usage: dundi flush [stats]\n"
2365 " Flushes DUNDi answer cache, used primarily for debug. If\n"
2366 "'stats' is present, clears timer statistics instead of normal\n"
2372 if ((
a->argc < 2) || (
a->argc > 3)) {
2376 if (!strcasecmp(
a->argv[2],
"stats")) {
2398 ast_cli(
a->fd,
"DUNDi Cache Flushed\n");
2453 qsort(results, count,
sizeof(results[0]),
rescomp);
2465 struct timeval start;
2470 "Usage: dundi lookup <number>[@context] [bypass]\n"
2471 " Lookup the given number within the given DUNDi context\n"
2472 "(or e164 if none is specified). Bypasses cache if 'bypass'\n"
2473 "keyword is specified.\n";
2479 if ((
a->argc < 3) || (
a->argc > 4)) {
2483 if (!strcasecmp(
a->argv[3],
"bypass")) {
2499 ast_cli(
a->fd,
"DUNDi lookup returned error.\n");
2501 ast_cli(
a->fd,
"DUNDi lookup returned no results.\n");
2504 for (x=0;x<res;x++) {
2506 ast_cli(
a->fd,
" from %s, expires in %d s\n",
dr[x].eid_str,
dr[x].expiration);
2517 struct timeval start;
2520 e->
command =
"dundi precache";
2522 "Usage: dundi precache <number>[@context]\n"
2523 " Lookup the given number within the given DUNDi context\n"
2524 "(or e164 if none is specified) and precaches the results to any\n"
2525 "upstream DUNDi push servers.\n";
2530 if ((
a->argc < 3) || (
a->argc > 3)) {
2543 ast_cli(
a->fd,
"DUNDi precache returned error.\n");
2545 ast_cli(
a->fd,
"DUNDi precache returned no error.\n");
2561 "Usage: dundi query <entity>[@context]\n"
2562 " Attempts to retrieve contact information for a specific\n"
2563 "DUNDi entity identifier (EID) within a given DUNDi context (or\n"
2564 "e164 if none is specified).\n";
2569 if ((
a->argc < 3) || (
a->argc > 3)) {
2573 ast_cli(
a->fd,
"'%s' is not a valid EID!\n",
a->argv[2]);
2584 ast_cli(
a->fd,
"DUNDi Query EID returned error.\n");
2586 ast_cli(
a->fd,
"DUNDi Query EID returned no results.\n");
2588 ast_cli(
a->fd,
"DUNDi Query EID succeeded:\n");
2604 return "(Unspecified)";
2630 e->
command =
"dundi show peer";
2632 "Usage: dundi show peer [peer]\n"
2633 " Provide a detailed description of a specifid DUNDi peer.\n";
2647 switch(peer->
order) {
2652 order =
"Secondary";
2658 order =
"Quartiary";
2684 ast_cli(
a->fd,
"Last few query times:\n");
2692 ast_cli(
a->fd,
"No such peer '%s'\n",
a->argv[3]);
2699 #define FORMAT2 "%-20.20s %-41s %-6.6s %-10.10s %-8.8s %-15.15s\n"
2700 #define FORMAT "%-20.20s %-41s %s %-6d %-10.10s %-8.8s %-15.15s\n"
2702 int registeredonly=0;
2705 int online_peers = 0;
2706 int offline_peers = 0;
2707 int unmonitored_peers = 0;
2708 int total_peers = 0;
2711 e->
command =
"dundi show peers [registered|include|exclude|begin]";
2713 "Usage: dundi show peers [registered|include|exclude|begin]\n"
2714 " Lists all known DUNDi peers.\n"
2715 " If 'registered' is present, only registered peers are shown.\n";
2721 if ((
a->argc != 3) && (
a->argc != 4) && (
a->argc != 5)) {
2724 if ((
a->argc == 4)) {
2725 if (!strcasecmp(
a->argv[3],
"registered")) {
2732 ast_cli(
a->fd,
FORMAT2,
"EID",
"Host",
"Port",
"Model",
"AvgTime",
"Status");
2735 int print_line = -1;
2744 strcpy(
status,
"UNREACHABLE");
2756 strcpy(
status,
"UNKNOWN");
2760 strcpy(
status,
"Unmonitored");
2761 unmonitored_peers++;
2766 strcpy(
avgms,
"Unavail");
2772 if (!strcasecmp(
a->argv[3],
"include") && strstr(srch,
a->argv[4])) {
2774 }
else if (!strcasecmp(
a->argv[3],
"exclude") && !strstr(srch,
a->argv[4])) {
2776 }
else if (!strcasecmp(
a->argv[3],
"begin") && !strncasecmp(srch,
a->argv[4],strlen(
a->argv[4]))) {
2789 ast_cli(
a->fd,
"%d dundi peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers);
2798 #define FORMAT2 "%-47s %-5.5s %-5.5s %-3.3s %-3.3s %-3.3s\n"
2799 #define FORMAT "%-41s:%5d %-5.5d %-5.5d %-3.3d %-3.3d %-3.3d\n"
2803 e->
command =
"dundi show trans";
2805 "Usage: dundi show trans\n"
2806 " Lists all known DUNDi transactions.\n";
2832 e->
command =
"dundi show entityid";
2834 "Usage: dundi show entityid\n"
2835 " Displays the global entityid for this host.\n";
2846 ast_cli(
a->fd,
"Global EID for this system is '%s'\n", eid_str);
2852 #define FORMAT2 "%-15s %-15s %-15s %-3.3s %-3.3s\n"
2853 #define FORMAT "%-15s %-15s %-15s %-3.3d %-3.3d\n"
2858 e->
command =
"dundi show requests";
2860 "Usage: dundi show requests\n"
2861 " Lists all known pending DUNDi requests.\n";
2885 #define FORMAT2 "%-12.12s %-7.7s %-12.12s %-10.10s %-5.5s %-25.25s\n"
2886 #define FORMAT "%-12.12s %-7s %-12.12s %-10.10s %-5.5s %-25.25s\n"
2892 e->
command =
"dundi show mappings";
2894 "Usage: dundi show mappings\n"
2895 " Lists all known DUNDi mappings.\n";
2904 ast_cli(
a->fd,
FORMAT2,
"DUNDi Cntxt",
"Weight",
"Local Cntxt",
"Options",
"Tech",
"Destination");
2919 #define FORMAT2 "%-12.12s %-12.12s %-10.10s\n"
2920 #define FORMAT "%-12.12s %-12.12s %02d:%02d:%02d\n"
2926 e->
command =
"dundi show precache";
2928 "Usage: dundi show precache\n"
2929 " Lists all known DUNDi scheduled precache updates.\n";
2957 #define FORMAT2 "%-12.12s %-16.16s %-10.10s %-18s %-7s %s\n"
2958 #define FORMAT "%-12.12s %-16.16s %6d sec %-18s %-7d %s/%s (%s)\n"
2963 char src_eid_str[20];
2964 int expiry, tech,
weight;
2972 e->
command =
"dundi show cache";
2974 "Usage: dundi show cache\n"
2975 " Lists all DUNDi cache entries.\n";
2987 ast_cli(
a->fd,
FORMAT2,
"Number",
"Context",
"Expiration",
"From",
"Weight",
"Destination (Flags)");
2988 for (db_entry = db_tree; db_entry; db_entry = db_entry->
next) {
2991 if ((strncmp(db_entry->
key,
"/dundi/cache/hint/", 18) == 0) ||
ast_get_time_t(db_entry->
data, &ts, 0, &length)) {
3001 ptr = db_entry->
key +
sizeof(
"/dundi/cache");
3002 strtok_r(ptr,
"/", &rest);
3005 ptr = strtok_r(
NULL,
"/", &rest);
3011 ptr = db_entry->
data + length + 1;
3013 if ((sscanf(ptr,
"%30u/%30d/%30d/%n", &(
flags.flags), &
weight, &tech, &length) != 3)) {
3019 term = strchr(ptr,
'|');
3029 src = strrchr(ptr,
'/');
3039 ast_cli(
a->fd,
FORMAT,
number,
context, expiry, src_eid_str,
weight,
tech2str(tech), dst,
dundi_flags2str(fs,
sizeof(fs),
flags.flags));
3042 ast_cli(
a->fd,
"Number of entries: %d\n", cnt);
3052 #define FORMAT2 "%-12.12s %-16.16s %-10.10s %-18s\n"
3053 #define FORMAT "%-12.12s %-16.16s %6d sec %-18s\n"
3058 char src_eid_str[20];
3065 e->
command =
"dundi show hints";
3067 "Usage: dundi show hints\n"
3068 " Lists all DUNDi 'DONTASK' hints in the cache.\n";
3082 for (db_entry = db_tree; db_entry; db_entry = db_entry->
next) {
3095 ptr = db_entry->
key +
sizeof(
"/dundi/cache/hint");
3096 src = strtok_r(ptr,
"/", &rest);
3099 ptr = strtok_r(
NULL,
"/", &rest);
3111 ast_cli(
a->fd,
"Number of entries: %d\n", cnt);
3149 if (!(trans =
ast_calloc(1,
sizeof(*trans))))
3223 if (ms < peer->
maxms) {
3267 if (write(trans->
parent->
pfds[1],
"killa!", 6) < 0) {
3316 if (ast_test_flag(trans, FLAG_ENCRYPT))
3421 memset(&ied, 0,
sizeof(ied));
3445 int direct[1] = { 0, };
3452 memset(&hmd, 0,
sizeof(hmd));
3453 memset(&
dr, 0,
sizeof(
dr));
3455 for (x=0;x<mapcount;x++)
3459 for (x=0;x<ouranswers;x++) {
3465 res =
dundi_lookup_internal(
dr + ouranswers,
MAX_RESULTS - ouranswers,
NULL, trans->
parent->
dcontext, trans->
parent->
number, trans->
ttl, 1, &hmd, &expiration, 0, 1, &trans->
them_eid, avoid, direct);
3472 if (ouranswers > 0) {
3473 *foundanswers += ouranswers;
3474 memset(&ied, 0,
sizeof(ied));
3483 for (x=0;x<ouranswers;x++) {
3485 if (
dr[x].expiration && (expiration >
dr[x].expiration))
3486 expiration =
dr[x].expiration;
3493 if (expiration < *minexp)
3494 *minexp = expiration;
3511 memset(&ied, 0,
sizeof(ied));
3559 ast_debug(1,
"Our transaction went away!\n");
3667 trans->
eids[x] = *avoid[x];
3700 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[])
3710 if (modeselect == 1) {
3732 for (x=0;avoid[x];x++) {
3735 if (directs && !directs[x])
3751 }
else if (!*skipped || (p->
order < *skipped))
3752 *skipped = p->
order;
3766 dr->dcontext,
dr->number);
3767 if (!strcasecmp(cur->
dcontext,
dr->dcontext) &&
3768 !strcasecmp(cur->
number,
dr->number) &&
3770 ast_debug(1,
"Found existing query for '%s@%s' for '%s' crc '%08x'\n",
3778 ast_debug(1,
"Registering request for '%s@%s' on behalf of '%s' crc '%08x'\n",
3813 uint32_t acrc32 = 0;
3815 for (x=0;avoid[x];x++) {
3818 acrc32 ^=
crc32(0L, (
unsigned char *)avoid[x],
sizeof(
dundi_eid));
3824 static int dundi_lookup_internal(
struct dundi_result *
result,
int maxret,
struct ast_channel *chan,
const char *
dcontext,
const char *
number,
int ttl,
int blockempty,
struct dundi_hint_metadata *
hmd,
int *
expiration,
int cbypass,
int modeselect,
dundi_eid *skip,
dundi_eid *avoid[],
int direct[])
3836 struct timeval start;
3844 for (x=0;avoid[x];x++)
3847 memset(&
dr, 0,
sizeof(
dr));
3848 if (pipe(
dr.pfds)) {
3854 dr.maxcount = maxret;
3855 dr.expiration = *expiration;
3856 dr.cbypass = cbypass;
3861 dr.root_eid = *rooteid;
3868 ast_debug(1,
"Oooh, duplicate request for '%s@%s' for '%s'\n",
3875 ast_debug(1,
"Waiting for similar request for '%s@%s' for '%s'\n",
3891 build_transactions(&
dr, ttl,
order, &foundcache, &skipped, blockempty, cbypass, modeselect, skip, avoid, direct);
3920 *expiration =
dr.expiration;
3930 int direct[1] = { 0, };
3932 memset(&hmd, 0,
sizeof(hmd));
3934 return dundi_lookup_internal(
result, maxret, chan, dcontext,
number,
dundi_ttl, 0, &hmd, &expiration, cbypass, 0,
NULL, avoid, direct);
3950 int len =
sizeof(*qe);
3951 int num_len = strlen(
number) + 1;
3952 int context_len = strlen(
context) + 1;
4001 struct timeval start;
4005 int foundcache, skipped, ttlms, ms;
4012 if (!strcasecmp(cur->dcontext,
context))
4019 if (!strcasecmp(cur->dcontext,
context))
4020 maps[nummaps++] = *cur;
4028 memset(&dr2, 0,
sizeof(dr2));
4029 memset(&
dr, 0,
sizeof(
dr));
4030 memset(&hmd, 0,
sizeof(hmd));
4037 dr.pfds[0] =
dr.pfds[1] = -1;
4038 if (pipe(
dr.pfds) < 0) {
4042 build_transactions(&
dr, ttl, 0, &foundcache, &skipped, 0, 1, 1,
NULL, avoids,
NULL);
4047 if (
dr.expiration > 0)
4050 ast_log(
LOG_NOTICE,
"Weird, expiration = %d, but need to precache for %s@%s?!\n",
dr.expiration,
dr.number,
dr.dcontext);
4054 if (
dr.pfds[0] > -1) {
4061 if (
dr.pfds[0] > -1) {
4083 struct timeval start;
4087 for (x=0;avoid[x];x++)
4090 memset(&
dr, 0,
sizeof(
dr));
4093 dr.pfds[0] =
dr.pfds[1] = -1;
4095 memcpy(&
dr.query_eid, eid,
sizeof(
dr.query_eid));
4097 dr.root_eid = *rooteid;
4099 build_transactions(&
dr, ttl, 9999, &foundcache, &skipped, blockempty, 0, 0,
NULL, avoid,
NULL);
4125 memset(&hmd, 0,
sizeof(hmd));