49#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__)
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
191static unsigned int tos = 0;
375 if (!strcasecmp(perm->
name,
"all") || !strcasecmp(perm->
name, cont))
402 if (!strcasecmp(
str,
"IAX") || !strcasecmp(
str,
"IAX2"))
404 else if (!strcasecmp(
str,
"SIP"))
406 else if (!strcasecmp(
str,
"H323"))
408 else if (!strcasecmp(
str,
"PJSIP"))
414static 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[]);
471 memset(&
tmp, 0,
sizeof(
tmp));
472 memset(&trans, 0,
sizeof(trans));
479 tmp.hdr.cmdflags = 0;
482 tmp.pack.parent = &trans;
499 tid = (tid % 32766) + 1;
500 }
while (tid != stid);
542 unsigned int *fluffy;
544 fluffy = (
unsigned int *)(iv);
611 dr[anscnt].techint = map->
tech;
614 dr[anscnt].eid = *us_eid;
635 dr[anscnt].dest[0] =
'\0';
643 for (x = 0; x < (
sizeof(
tmp) - 1); x++) {
644 tmp[x] = called_number[x];
650 if (strlen(
tmp) > strlen(hmd->
exten)) {
677 memset(&ied, 0,
sizeof(ied));
678 memset(&
dr, 0,
sizeof(
dr));
679 memset(&hmd, 0,
sizeof(hmd));
686 for (x=0;x<ouranswers;x++) {
693 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);
698 if ((res < -1) && (!ouranswers))
707 ast_debug(1,
"Our transaction went away!\n");
711 for (x=0;x<ouranswers;x++) {
713 if (
dr[x].expiration && (expiration >
dr[x].expiration))
714 expiration =
dr[x].expiration;
736 memset(&ied, 0,
sizeof(ied));
746 ast_debug(1,
"Our transaction went away!\n");
771 memset(&ied, 0,
sizeof(ied));
772 memset(&dei, 0,
sizeof(dei));
773 memset(&hmd, 0,
sizeof(hmd));
776 ast_debug(1,
"Neat, someone look for us!\n");
791 ast_debug(1,
"Our transaction went away!\n");
823 pthread_t lookupthread;
844 for (x=skipfirst;ies->
eids[x];x++) {
846 *st->
eids[x-skipfirst] = *ies->
eids[x];
875 char eidpeer_str[20];
876 char eidroot_str[20];
891 snprintf(key1,
sizeof(key1),
"hint/%s/%s/%s/e%08x", eidpeer_str, hint->
data, req->
dcontext, unaffected ? 0 : req->
crc32);
892 snprintf(key2,
sizeof(key2),
"hint/%s/%s/%s/r%s", eidpeer_str, hint->
data, req->
dcontext, eidroot_str);
895 timeout += expiration;
896 snprintf(data,
sizeof(data),
"%ld|", (
long)(timeout));
899 ast_debug(1,
"Caching hint at '%s'\n", key1);
901 ast_debug(1,
"Caching hint at '%s'\n", key2);
911 char eidpeer_str[20];
912 char eidroot_str[20];
927 snprintf(key1,
sizeof(key1),
"%s/%s/%s/e%08x", eidpeer_str, req->
number, req->
dcontext, unaffected ? 0 : req->
crc32);
928 snprintf(key2,
sizeof(key2),
"%s/%s/%s/r%s", eidpeer_str, req->
number, req->
dcontext, eidroot_str);
931 timeout += expiration;
932 snprintf(data,
sizeof(data),
"%ld|", (
long)(timeout));
935 if (strchr(req->
dr[x].
dest,
'|'))
937 snprintf(data + strlen(data),
sizeof(data) - strlen(data),
"%u/%d/%d/%s/%s|",
961 pthread_t lookupthread;
963 memset(&dr2, 0,
sizeof(dr2));
964 memset(&
dr, 0,
sizeof(
dr));
965 memset(&hmd, 0,
sizeof(hmd));
973 dr.pfds[0] =
dr.pfds[1] = -1;
1023 if (!strcasecmp(cur->
dcontext, ccontext))
1053 for (x=skipfirst;ies->
eids[x];x++) {
1055 *st->
eids[x-skipfirst] = *ies->
eids[x];
1063 if (!strcasecmp(cur->
dcontext, ccontext)) {
1078 memset(&ied, 0,
sizeof(ied));
1085 memset(&ied, 0,
sizeof(ied));
1104 pthread_t lookupthread;
1108 if (!strcasecmp(cur->
dcontext, ccontext))
1136 for (x=skipfirst;ies->
eids[x];x++) {
1138 *st->
eids[x-skipfirst] = *ies->
eids[x];
1146 if (!strcasecmp(cur->
dcontext, ccontext)) {
1161 memset(&ied, 0,
sizeof(ied));
1168 memset(&ied, 0,
sizeof(ied));
1179 char *ptr, *term, *src;
1188 if (!
ast_db_get(
"dundi/cache", key, data,
sizeof(data))) {
1192 int expiration = timeout - now;
1193 if (expiration > 0) {
1194 ast_debug(1,
"Found cache expiring in %d seconds!\n", expiration);
1196 while((sscanf(ptr,
"%30d/%30d/%30d/%n", (
int *)&(
flags.flags), &
weight, &tech, &length) == 3)) {
1198 term = strchr(ptr,
'|');
1201 src = strrchr(ptr,
'/');
1207 ast_debug(1,
"Found cached answer '%s/%s' originally from '%s' with flags '%s' on behalf of '%s'\n",
1212 !strcmp(req->
dr[z].
dest, ptr))
1236 if (expiration < *lowexpiration)
1237 *lowexpiration = expiration;
1251 char eidroot_str[20];
1255 char eid_str_full[20];
1258 char key[
sizeof(eid_str) +
sizeof(
tmp) +
sizeof(req->
dcontext) +
sizeof(eidroot_str) +
sizeof(
"hint////r")];
1265 snprintf(key,
sizeof(key),
"%s/%s/%s/e%08x", eid_str, req->
number, req->
dcontext, crc);
1267 snprintf(key,
sizeof(key),
"%s/%s/%s/e%08x", eid_str, req->
number, req->
dcontext, (
unsigned)0);
1269 snprintf(key,
sizeof(key),
"%s/%s/%s/r%s", eid_str, req->
number, req->
dcontext, eidroot_str);
1280 snprintf(key,
sizeof(key),
"hint/%s/%s/%s/e%08x", eid_str,
tmp, req->
dcontext, crc);
1282 snprintf(key,
sizeof(key),
"hint/%s/%s/%s/e%08x", eid_str,
tmp, req->
dcontext, (
unsigned)0);
1284 snprintf(key,
sizeof(key),
"hint/%s/%s/%s/r%s", eid_str,
tmp, req->
dcontext, eidroot_str);
1342 unsigned char key[16];
1352 ast_log(
LOG_NOTICE,
"No such key '%s' for creating RSA encrypted shared key for '%s'!\n",
1358 ast_log(
LOG_NOTICE,
"No such key '%s' for signing RSA encrypted shared key for '%s'!\n",
1381 unsigned char curblock[16];
1383 memcpy(curblock, iv,
sizeof(curblock));
1386 curblock[x] ^= src[x];
1388 memcpy(curblock, dst,
sizeof(curblock));
1397 unsigned char lastblock[16];
1399 memcpy(lastblock, iv,
sizeof(lastblock));
1403 dst[x] ^= lastblock[x];
1404 memcpy(lastblock, src,
sizeof(lastblock));
1414 int space = *dstlen;
1415 unsigned long bytes;
1417 unsigned char *decrypt_space;
1424 if (uncompress(dst + 6, &bytes, decrypt_space, srclen) != Z_OK) {
1425 ast_debug(1,
"Ouch, uncompress failed :(\n");
1429 *dstlen = bytes + 6;
1436 unsigned char *compress_space;
1439 unsigned long bytes;
1442 unsigned char iv[16];
1445 memset(compress_space, 0,
len);
1448 res = compress(compress_space, &bytes, pack->
data + 6, pack->
datalen - 6);
1450 ast_debug(1,
"Ouch, compression failed!\n");
1453 memset(&ied, 0,
sizeof(ied));
1483 if ((ied.
pos + bytes) >=
sizeof(ied.
buf)) {
1488 ied.
pos += ((bytes + 15) / 16) * 16;
1500 unsigned char dst[128];
1508 }
else if (!newkey || !newsig)
1510 if (!memcmp(peer->
rxenckey, newkey, 128) &&
1511 !memcmp(peer->
rxenckey + 128, newsig, 128)) {
1542 ast_debug(1,
"Wow, new key combo passed signature and decrypt!\n");
1543 memcpy(peer->
rxenckey, newkey, 128);
1544 memcpy(peer->
rxenckey + 128, newsig, 128);
1555 *peer_dst = *peer_src;
1568 memset(&peer_dst->
permit, 0,
sizeof(peer_dst->
permit));
1572 if (!(perm =
ast_calloc(1,
sizeof(*perm) + strlen(cur->
name) + 1)))
1582 if (!(perm =
ast_calloc(1,
sizeof(*perm) + strlen(cur->
name) + 1)))
1595 int final = hdr->
cmdresp & 0x80;
1596 int cmd = hdr->
cmdresp & 0x7f;
1601 unsigned char *bufcpy;
1625 memcpy(bufcpy, hdr->
ies, datalen);
1626 ast_debug(1,
"Got canonical message %d (%d), %d bytes data%s\n", cmd, hdr->
oseqno, datalen,
final ?
" (Final)" :
"");
1629 goto return_cleanup;
1650 if (strlen(peer->
inkey)) {
1651 hasauth = encrypted;
1716 if (!peer || !peer->
dynamic) {
1723 hasauth = encrypted;
1735 ast_verb(3,
"Registered DUNDi peer '%s' at '%s'\n",
1751 if (ies.
cause < 1) {
1755 authpass = encrypted;
1835 if (ies.
cause < 1) {
1837 ast_debug(1,
"Looks like success of some sort (%d)\n", ies.
cause);
1839 authpass = encrypted;
1888 if (ies.
cause < 1) {
1892 hasauth = encrypted;
1940 memset(&ies, 0,
sizeof(ies));
1943 memset(ied, 0,
sizeof(*ied));
1976 ddatalen =
sizeof(decoded);
1987 ast_debug(1,
"Ouch, decrypt failed :(\n");
2033 if ((pack->
h->
oseqno + 1) % 255 == iseqno) {
2084 ast_debug(1,
"Dropping packet out of window!\n");
2098 if (
errno != ECONNREFUSED)
2118 unsigned char tmp[16];
2124 while((s = strchr(secret,
';'))) *s =
'+';
2125 while((s = strchr(secret,
'/'))) *s =
'+';
2126 while((s = strchr(secret,
':'))) *s =
'+';
2127 while((s = strchr(secret,
'@'))) *s =
'+';
2135 snprintf(
tmp,
sizeof(
tmp),
"%s;%s", oldkey, newkey);
2137 snprintf(
tmp,
sizeof(
tmp),
"%s", newkey);
2161 if ((time(
NULL) - expired) < 0) {
2207 int *socket_read_id2 =
NULL;
2214 if ((res > 1000) || (res < 0))
2227 if (socket_read_id2) {
2237 int striplen =
sizeof(
"/dundi/cache");
2241 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,
NULL);
2246 for (; db_entry; db_entry = db_entry->
next) {
2251 ast_debug(1,
"clearing expired DUNDI cache entry: %s\n", db_entry->
key);
2258 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,
NULL);
2259 pthread_testcancel();
2261 pthread_testcancel();
2314 e->
command =
"dundi set debug {on|off}";
2316 "Usage: dundi set debug {on|off}\n"
2317 " Enables/Disables dumping of DUNDi packets for debugging purposes\n";
2323 if (
a->argc != e->
args) {
2326 if (!strncasecmp(
a->argv[e->
args -1],
"on", 2)) {
2328 ast_cli(
a->fd,
"DUNDi Debugging Enabled\n");
2331 ast_cli(
a->fd,
"DUNDi Debugging Disabled\n");
2340 e->
command =
"dundi store history {on|off}";
2342 "Usage: dundi store history {on|off}\n"
2343 " Enables/Disables storing of DUNDi requests and times for debugging\n"
2350 if (
a->argc != e->
args) {
2353 if (!strncasecmp(
a->argv[e->
args -1],
"on", 2)) {
2355 ast_cli(
a->fd,
"DUNDi History Storage Enabled\n");
2358 ast_cli(
a->fd,
"DUNDi History Storage Disabled\n");
2368 e->
command =
"dundi flush [stats]";
2370 "Usage: dundi flush [stats]\n"
2371 " Flushes DUNDi answer cache, used primarily for debug. If\n"
2372 "'stats' is present, clears timer statistics instead of normal\n"
2378 if ((
a->argc < 2) || (
a->argc > 3)) {
2382 if (!strcasecmp(
a->argv[2],
"stats")) {
2404 ast_cli(
a->fd,
"DUNDi Cache Flushed\n");
2459 qsort(results, count,
sizeof(results[0]),
rescomp);
2471 struct timeval start;
2476 "Usage: dundi lookup <number>[@context] [bypass]\n"
2477 " Lookup the given number within the given DUNDi context\n"
2478 "(or e164 if none is specified). Bypasses cache if 'bypass'\n"
2479 "keyword is specified.\n";
2485 if ((
a->argc < 3) || (
a->argc > 4)) {
2489 if (!strcasecmp(
a->argv[3],
"bypass")) {
2505 ast_cli(
a->fd,
"DUNDi lookup returned error.\n");
2507 ast_cli(
a->fd,
"DUNDi lookup returned no results.\n");
2510 for (x=0;x<res;x++) {
2512 ast_cli(
a->fd,
" from %s, expires in %d s\n",
dr[x].eid_str,
dr[x].expiration);
2523 struct timeval start;
2526 e->
command =
"dundi precache";
2528 "Usage: dundi precache <number>[@context]\n"
2529 " Lookup the given number within the given DUNDi context\n"
2530 "(or e164 if none is specified) and precaches the results to any\n"
2531 "upstream DUNDi push servers.\n";
2536 if ((
a->argc < 3) || (
a->argc > 3)) {
2549 ast_cli(
a->fd,
"DUNDi precache returned error.\n");
2551 ast_cli(
a->fd,
"DUNDi precache returned no error.\n");
2567 "Usage: dundi query <entity>[@context]\n"
2568 " Attempts to retrieve contact information for a specific\n"
2569 "DUNDi entity identifier (EID) within a given DUNDi context (or\n"
2570 "e164 if none is specified).\n";
2575 if ((
a->argc < 3) || (
a->argc > 3)) {
2579 ast_cli(
a->fd,
"'%s' is not a valid EID!\n",
a->argv[2]);
2590 ast_cli(
a->fd,
"DUNDi Query EID returned error.\n");
2592 ast_cli(
a->fd,
"DUNDi Query EID returned no results.\n");
2594 ast_cli(
a->fd,
"DUNDi Query EID succeeded:\n");
2610 return "(Unspecified)";
2636 e->
command =
"dundi show peer";
2638 "Usage: dundi show peer [peer]\n"
2639 " Provide a detailed description of a specifid DUNDi peer.\n";
2653 switch(peer->
order) {
2658 order =
"Secondary";
2664 order =
"Quartiary";
2690 ast_cli(
a->fd,
"Last few query times:\n");
2698 ast_cli(
a->fd,
"No such peer '%s'\n",
a->argv[3]);
2705#define FORMAT2 "%-20.20s %-41s %-6.6s %-10.10s %-8.8s %-15.15s\n"
2706#define FORMAT "%-20.20s %-41s %s %-6d %-10.10s %-8.8s %-15.15s\n"
2708 int registeredonly=0;
2711 int online_peers = 0;
2712 int offline_peers = 0;
2713 int unmonitored_peers = 0;
2714 int total_peers = 0;
2717 e->
command =
"dundi show peers [registered|include|exclude|begin]";
2719 "Usage: dundi show peers [registered|include|exclude|begin]\n"
2720 " Lists all known DUNDi peers.\n"
2721 " If 'registered' is present, only registered peers are shown.\n";
2727 if ((
a->argc != 3) && (
a->argc != 4) && (
a->argc != 5)) {
2730 if ((
a->argc == 4)) {
2731 if (!strcasecmp(
a->argv[3],
"registered")) {
2738 ast_cli(
a->fd,
FORMAT2,
"EID",
"Host",
"Port",
"Model",
"AvgTime",
"Status");
2741 int print_line = -1;
2750 strcpy(
status,
"UNREACHABLE");
2762 strcpy(
status,
"UNKNOWN");
2766 strcpy(
status,
"Unmonitored");
2767 unmonitored_peers++;
2772 strcpy(
avgms,
"Unavail");
2778 if (!strcasecmp(
a->argv[3],
"include") && strstr(srch,
a->argv[4])) {
2780 }
else if (!strcasecmp(
a->argv[3],
"exclude") && !strstr(srch,
a->argv[4])) {
2782 }
else if (!strcasecmp(
a->argv[3],
"begin") && !strncasecmp(srch,
a->argv[4],strlen(
a->argv[4]))) {
2795 ast_cli(
a->fd,
"%d dundi peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers);
2804#define FORMAT2 "%-47s %-5.5s %-5.5s %-3.3s %-3.3s %-3.3s\n"
2805#define FORMAT "%-41s:%5d %-5.5d %-5.5d %-3.3d %-3.3d %-3.3d\n"
2809 e->
command =
"dundi show trans";
2811 "Usage: dundi show trans\n"
2812 " Lists all known DUNDi transactions.\n";
2838 e->
command =
"dundi show entityid";
2840 "Usage: dundi show entityid\n"
2841 " Displays the global entityid for this host.\n";
2852 ast_cli(
a->fd,
"Global EID for this system is '%s'\n", eid_str);
2858#define FORMAT2 "%-15s %-15s %-15s %-3.3s %-3.3s\n"
2859#define FORMAT "%-15s %-15s %-15s %-3.3d %-3.3d\n"
2864 e->
command =
"dundi show requests";
2866 "Usage: dundi show requests\n"
2867 " Lists all known pending DUNDi requests.\n";
2891#define FORMAT2 "%-12.12s %-7.7s %-12.12s %-10.10s %-5.5s %-25.25s\n"
2892#define FORMAT "%-12.12s %-7s %-12.12s %-10.10s %-5.5s %-25.25s\n"
2898 e->
command =
"dundi show mappings";
2900 "Usage: dundi show mappings\n"
2901 " Lists all known DUNDi mappings.\n";
2910 ast_cli(
a->fd,
FORMAT2,
"DUNDi Cntxt",
"Weight",
"Local Cntxt",
"Options",
"Tech",
"Destination");
2925#define FORMAT2 "%-12.12s %-12.12s %-10.10s\n"
2926#define FORMAT "%-12.12s %-12.12s %02d:%02d:%02d\n"
2932 e->
command =
"dundi show precache";
2934 "Usage: dundi show precache\n"
2935 " Lists all known DUNDi scheduled precache updates.\n";
2963#define FORMAT2 "%-12.12s %-16.16s %-10.10s %-18s %-7s %s\n"
2964#define FORMAT "%-12.12s %-16.16s %6d sec %-18s %-7d %s/%s (%s)\n"
2969 char src_eid_str[20];
2970 int expiry, tech,
weight;
2978 e->
command =
"dundi show cache";
2980 "Usage: dundi show cache\n"
2981 " Lists all DUNDi cache entries.\n";
2993 ast_cli(
a->fd,
FORMAT2,
"Number",
"Context",
"Expiration",
"From",
"Weight",
"Destination (Flags)");
2994 for (db_entry = db_tree; db_entry; db_entry = db_entry->
next) {
2997 if ((strncmp(db_entry->
key,
"/dundi/cache/hint/", 18) == 0) ||
ast_get_time_t(db_entry->
data, &ts, 0, &length)) {
3007 ptr = db_entry->
key +
sizeof(
"/dundi/cache");
3008 strtok_r(ptr,
"/", &rest);
3011 ptr = strtok_r(
NULL,
"/", &rest);
3017 ptr = db_entry->
data + length + 1;
3019 if ((sscanf(ptr,
"%30u/%30d/%30d/%n", &(
flags.flags), &
weight, &tech, &length) != 3)) {
3025 term = strchr(ptr,
'|');
3035 src = strrchr(ptr,
'/');
3045 ast_cli(
a->fd,
FORMAT,
number,
context, expiry, src_eid_str,
weight,
tech2str(tech), dst,
dundi_flags2str(fs,
sizeof(fs),
flags.flags));
3048 ast_cli(
a->fd,
"Number of entries: %d\n", cnt);
3058#define FORMAT2 "%-12.12s %-16.16s %-10.10s %-18s\n"
3059#define FORMAT "%-12.12s %-16.16s %6d sec %-18s\n"
3064 char src_eid_str[20];
3071 e->
command =
"dundi show hints";
3073 "Usage: dundi show hints\n"
3074 " Lists all DUNDi 'DONTASK' hints in the cache.\n";
3088 for (db_entry = db_tree; db_entry; db_entry = db_entry->
next) {
3101 ptr = db_entry->
key +
sizeof(
"/dundi/cache/hint");
3102 src = strtok_r(ptr,
"/", &rest);
3105 ptr = strtok_r(
NULL,
"/", &rest);
3117 ast_cli(
a->fd,
"Number of entries: %d\n", cnt);
3155 if (!(trans =
ast_calloc(1,
sizeof(*trans))))
3229 if (ms < peer->
maxms) {
3273 if (write(trans->
parent->
pfds[1],
"killa!", 6) < 0) {
3322 if (ast_test_flag(trans, FLAG_ENCRYPT))
3427 memset(&ied, 0,
sizeof(ied));
3451 int direct[1] = { 0, };
3458 memset(&hmd, 0,
sizeof(hmd));
3459 memset(&
dr, 0,
sizeof(
dr));
3461 for (x=0;x<mapcount;x++)
3465 for (x=0;x<ouranswers;x++) {
3471 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);
3478 if (ouranswers > 0) {
3479 *foundanswers += ouranswers;
3480 memset(&ied, 0,
sizeof(ied));
3489 for (x=0;x<ouranswers;x++) {
3491 if (
dr[x].expiration && (expiration >
dr[x].expiration))
3492 expiration =
dr[x].expiration;
3499 if (expiration < *minexp)
3500 *minexp = expiration;
3517 memset(&ied, 0,
sizeof(ied));
3565 ast_debug(1,
"Our transaction went away!\n");
3673 trans->
eids[x] = *avoid[x];
3706static 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[])
3716 if (modeselect == 1) {
3738 for (x=0;avoid[x];x++) {
3741 if (directs && !directs[x])
3757 }
else if (!*skipped || (p->
order < *skipped))
3758 *skipped = p->
order;
3772 dr->dcontext,
dr->number);
3773 if (!strcasecmp(cur->
dcontext,
dr->dcontext) &&
3774 !strcasecmp(cur->
number,
dr->number) &&
3776 ast_debug(1,
"Found existing query for '%s@%s' for '%s' crc '%08x'\n",
3784 ast_debug(1,
"Registering request for '%s@%s' on behalf of '%s' crc '%08x'\n",
3819 uint32_t acrc32 = 0;
3821 for (x=0;avoid[x];x++) {
3824 acrc32 ^=
crc32(0L, (
unsigned char *)avoid[x],
sizeof(
dundi_eid));
3830static 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[])
3842 struct timeval start;
3850 for (x=0;avoid[x];x++)
3853 memset(&
dr, 0,
sizeof(
dr));
3854 if (pipe(
dr.pfds)) {
3860 dr.maxcount = maxret;
3861 dr.expiration = *expiration;
3862 dr.cbypass = cbypass;
3867 dr.root_eid = *rooteid;
3874 ast_debug(1,
"Oooh, duplicate request for '%s@%s' for '%s'\n",
3881 ast_debug(1,
"Waiting for similar request for '%s@%s' for '%s'\n",
3897 build_transactions(&
dr, ttl,
order, &foundcache, &skipped, blockempty, cbypass, modeselect, skip, avoid, direct);
3926 *expiration =
dr.expiration;
3936 int direct[1] = { 0, };
3938 memset(&hmd, 0,
sizeof(hmd));
3940 return dundi_lookup_internal(
result, maxret, chan, dcontext,
number,
dundi_ttl, 0, &hmd, &expiration, cbypass, 0,
NULL, avoid, direct);
3956 int len =
sizeof(*qe);
3957 int num_len = strlen(
number) + 1;
3958 int context_len = strlen(
context) + 1;
4007 struct timeval start;
4011 int foundcache, skipped, ttlms, ms;
4018 if (!strcasecmp(cur->dcontext,
context))
4025 if (!strcasecmp(cur->dcontext,
context))
4026 maps[nummaps++] = *cur;
4034 memset(&dr2, 0,
sizeof(dr2));
4035 memset(&
dr, 0,
sizeof(
dr));
4036 memset(&hmd, 0,
sizeof(hmd));
4043 dr.pfds[0] =
dr.pfds[1] = -1;
4044 if (pipe(
dr.pfds) < 0) {
4048 build_transactions(&
dr, ttl, 0, &foundcache, &skipped, 0, 1, 1,
NULL, avoids,
NULL);
4053 if (
dr.expiration > 0)
4056 ast_log(
LOG_NOTICE,
"Weird, expiration = %d, but need to precache for %s@%s?!\n",
dr.expiration,
dr.number,
dr.dcontext);
4060 if (
dr.pfds[0] > -1) {
4067 if (
dr.pfds[0] > -1) {
4089 struct timeval start;
4093 for (x=0;avoid[x];x++)
4096 memset(&
dr, 0,
sizeof(
dr));
4099 dr.pfds[0] =
dr.pfds[1] = -1;
4101 memcpy(&
dr.query_eid, eid,
sizeof(
dr.query_eid));
4103 dr.root_eid = *rooteid;
4105 build_transactions(&
dr, ttl, 9999, &foundcache, &skipped, blockempty, 0, 0,
NULL, avoid,
NULL);
4131 memset(&hmd, 0,
sizeof(hmd));
4171 args.context =
"e164";
4177 for (x = 0; x < results; x++) {
4179 snprintf(
buf,
len,
"%s/%s",
dr[x].tech,
dr[x].dest);
4193 .
name =
"DUNDILOOKUP",
4217 .
type =
"DUNDIQUERY",
4251 args.context =
"e164";
4253 if (!(drds =
ast_calloc(1,
sizeof(*drds)))) {
4258 snprintf(
buf,
len,
"%u", drds->
id);
4265 datastore->
data = drds;
4281 .
name =
"DUNDIQUERY",
4330 drds = datastore->
data;
4332 if (!strcasecmp(
args.resultnum,
"getnum")) {
4338 if (sscanf(
args.resultnum,
"%30u", &num) != 1) {
4344 if (num && drds->
num_results > 0 && num <= drds->num_results) {
4348 ast_log(
LOG_WARNING,
"Result number %u is not valid for DUNDi query results for ID %s!\n", num,
args.id);
4355 .
name =
"DUNDIRESULT",
4452 if (!(perm =
ast_calloc(1,
sizeof(*perm) + strlen(s) + 1)))
4455 strcpy(perm->
name, s);
4487 memset(fields, 0,
sizeof(fields));
4501 }
else if (x >= 4) {
4508 }
else if (!strncmp(fields[1],
"${", 2) && fields[1][strlen(fields[1]) - 1] ==
'}') {
4516 for (y = 4;y < x; y++) {
4517 if (!strcasecmp(fields[y],
"nounsolicited"))
4519 else if (!strcasecmp(fields[y],
"nocomunsolicit"))
4521 else if (!strcasecmp(fields[y],
"residential"))
4523 else if (!strcasecmp(fields[y],
"commercial"))
4525 else if (!strcasecmp(fields[y],
"mobile"))
4527 else if (!strcasecmp(fields[y],
"nopartial"))
4533 ast_log(
LOG_WARNING,
"Expected at least %d arguments in map, but got only %d\n", 4, x);
4551 memset(&ied, 0,
sizeof(ied));
4578 if (peer->
maxms > 0) {
4601 if (!
ast_db_get(
"dundi/dpeers", eid_str, data,
sizeof(data))) {
4618 if (sscanf(
c,
"%5d:%30d", &port, &expire) == 2) {
4650 if (!(peer =
ast_calloc(1,
sizeof(*peer)))) {
4666 for (; v; v = v->
next) {
4667 if (!strcasecmp(v->
name,
"inkey")) {
4669 }
else if (!strcasecmp(v->
name,
"outkey")) {
4671 }
else if (!strcasecmp(v->
name,
"port")) {
4672 port = atoi(v->
value);
4673 }
else if (!strcasecmp(v->
name,
"host")) {
4674 if (!strcasecmp(v->
value,
"dynamic")) {
4688 }
else if (!strcasecmp(v->
name,
"ustothem")) {
4693 }
else if (!strcasecmp(v->
name,
"include")) {
4695 }
else if (!strcasecmp(v->
name,
"permit")) {
4697 }
else if (!strcasecmp(v->
name,
"noinclude")) {
4699 }
else if (!strcasecmp(v->
name,
"deny")) {
4701 }
else if (!strcasecmp(v->
name,
"register")) {
4703 }
else if (!strcasecmp(v->
name,
"order")) {
4704 if (!strcasecmp(v->
value,
"primary"))
4706 else if (!strcasecmp(v->
value,
"secondary"))
4708 else if (!strcasecmp(v->
value,
"tertiary"))
4710 else if (!strcasecmp(v->
value,
"quartiary"))
4715 }
else if (!strcasecmp(v->
name,
"qualify")) {
4716 if (!strcasecmp(v->
value,
"no")) {
4718 }
else if (!strcasecmp(v->
value,
"yes")) {
4720 }
else if (sscanf(v->
value,
"%30d", &peer->
maxms) != 1) {
4721 ast_log(
LOG_WARNING,
"Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of dundi.conf\n",
4725 }
else if (!strcasecmp(v->
name,
"model")) {
4726 if (!strcasecmp(v->
value,
"inbound"))
4728 else if (!strcasecmp(v->
value,
"outbound"))
4730 else if (!strcasecmp(v->
value,
"symmetric"))
4732 else if (!strcasecmp(v->
value,
"none"))
4735 ast_log(
LOG_WARNING,
"Unknown model '%s', should be 'none', 'outbound', 'inbound', or 'symmetric' at line %d\n",
4738 }
else if (!strcasecmp(v->
name,
"precache")) {
4739 if (!strcasecmp(v->
value,
"inbound"))
4741 else if (!strcasecmp(v->
value,
"outbound"))
4743 else if (!strcasecmp(v->
value,
"symmetric"))
4745 else if (!strcasecmp(v->
value,
"none"))
4748 ast_log(
LOG_WARNING,
"Unknown pcmodel '%s', should be 'none', 'outbound', 'inbound', or 'symmetric' at line %d\n",
4758 (*globalpcmode) |= peer->
pcmodel;
4764 ast_log(
LOG_WARNING,
"Peer '%s' may not be both inbound/symmetric model and outbound/symmetric precache model, discarding!\n",
4768 ast_log(
LOG_WARNING,
"Peer '%s' may not be both outbound/symmetric model and inbound/symmetric precache model, discarding!\n",
4772 ast_log(
LOG_WARNING,
"Peer '%s' is supposed to be included in outbound searches but isn't an outbound peer or inbound precache!\n",
4775 ast_log(
LOG_WARNING,
"Peer '%s' is supposed to have permission for some inbound searches but isn't an inbound peer or outbound precache!\n",
4799 for (x=0;x<res;x++) {
4824 const char *dundiargs;
4832 for (x=0;x<res;x++) {
4846 if (!strcasecmp(results[x].
tech,
"SIP") || !strcasecmp(results[x].
tech,
"PJSIP")) {
4849 if (strcasecmp(results[x].
tech,
"SIP")) {
4850 ast_log(
LOG_WARNING,
"%s cannot be specified by DUNDi peers (peer should use SIP for DUNDi lookups instead)\n", results[x].
tech);
4860 ast_log(
LOG_WARNING,
"PJSIP calls require an endpoint to be specified explicitly (use the pjsip_outgoing_endpoint option in dundi.conf)\n");
4869 snprintf(req,
sizeof(req),
"%s/%s/sip:%s@%s,,%s", results[x].
tech,
pjsip_outgoing_endpoint,
S_OR(
number,
""), ip,
S_OR(dundiargs,
""));
4870 ast_debug(1,
"Finalized PJSIP Dial: %s\n", req);
4872 snprintf(req,
sizeof(req),
"%s/%s,,%s", results[x].
tech, results[x].
dest,
S_OR(dundiargs,
""));
4888 .description =
"DUNDi Discovered Dialplan Switch",
4912 struct addrinfo
hints;
4923 if (gethostname(hn,
sizeof(hn) - 1) < 0) {
4938 static int last_port = 0;
4940 int globalpcmodel = 0;
4942 char bind_addr[80]={0,};
4943 char bind_addr2[80]={0,};
4966 if (!strcasecmp(v->
name,
"port")){
4967 port = atoi(v->
value);
4968 }
else if (!strcasecmp(v->
name,
"bindaddr")) {
4974 }
else if (!strcasecmp(v->
name,
"bindaddr2")) {
4980 }
else if (!strcasecmp(v->
name,
"authdebug")) {
4982 }
else if (!strcasecmp(v->
name,
"ttl")) {
4986 ast_log(
LOG_WARNING,
"'%s' is not a valid TTL at line %d, must be number from 1 to %d\n",
4989 }
else if (!strcasecmp(v->
name,
"autokill")) {
4990 if (sscanf(v->
value,
"%30d", &x) == 1) {
5000 }
else if (!strcasecmp(v->
name,
"entityid")) {
5005 }
else if (!strcasecmp(v->
name,
"tos")) {
5008 }
else if (!strcasecmp(v->
name,
"department")) {
5010 }
else if (!strcasecmp(v->
name,
"organization")) {
5012 }
else if (!strcasecmp(v->
name,
"locality")) {
5014 }
else if (!strcasecmp(v->
name,
"stateprov")) {
5016 }
else if (!strcasecmp(v->
name,
"country")) {
5018 }
else if (!strcasecmp(v->
name,
"email")) {
5020 }
else if (!strcasecmp(v->
name,
"phone")) {
5022 }
else if (!strcasecmp(v->
name,
"storehistory")) {
5024 }
else if (!strcasecmp(v->
name,
"outgoing_sip_tech")) {
5031 }
else if (!strcasecmp(v->
name,
"pjsip_outgoing_endpoint")) {
5033 }
else if (!strcasecmp(v->
name,
"cachetime")) {
5034 if ((sscanf(v->
value,
"%30d", &x) == 1)) {
5037 ast_log(
LOG_WARNING,
"'%s' is not a valid cache time at line %d. Using default value '%d'.\n",
5049 sprintf(bind_addr,
"0.0.0.0:%d", port);
5055 if (last_port == 0) {
5057 }
else if (last_port != port) {
5082 if (strcasecmp(cat,
"general") && strcasecmp(cat,
"mappings")) {
5086 else if (!strcasecmp(cat,
"*")) {
5167 if (
set_config(
"dundi.conf", &sin, 1, &sin2))
5192 if (
set_config(
"dundi.conf", &sin, 0, &sin2)) {
5198 ast_log(
LOG_ERROR,
"bindaddr & bindaddr2 should be different IP protocols.\n");
5204 netsocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
5205 netsocket2 = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP);
5237 netsocket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP);
5239 netsocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
5281 .optional_modules =
"res_crypto",
Access Control of various sorts.
int ast_str2tos(const char *value, unsigned int *tos)
Convert a string to the appropriate TOS value.
static const struct adsi_event events[]
struct sla_ringing_trunk * last
Persistent data storage (akin to *doze registry)
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
Asterisk main include file. File version handling, generic pbx functions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_calloc(num, len)
A wrapper for calloc()
#define ast_malloc(len)
A wrapper for malloc()
static const char config_file[]
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
#define ast_channel_lock(chan)
int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception)
Waits for input on an fd.
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
#define ast_channel_unlock(chan)
#define AST_MAX_EXTENSION
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
#define ast_var_assign(name, value)
void ast_var_delete(struct ast_var_t *var)
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Provide cryptographic signature routines.
int ast_aes_set_encrypt_key(const unsigned char *key, ast_aes_encrypt_key *ctx)
Set an encryption key.
struct ast_key * ast_key_get(const char *kname, int ktype)
Retrieve a key.
int ast_check_signature_bin(struct ast_key *key, const char *msg, int msglen, const unsigned char *dsig)
Check the authenticity of a message signature using a given public key.
int ast_aes_set_decrypt_key(const unsigned char *key, ast_aes_decrypt_key *ctx)
Set a decryption key.
int ast_sign_bin(struct ast_key *key, const char *msg, int msglen, unsigned char *dsig)
Sign a message signature using a given private key.
int ast_aes_encrypt(const unsigned char *in, unsigned char *out, const ast_aes_encrypt_key *key)
AES encrypt data.
int ast_aes_decrypt(const unsigned char *in, unsigned char *out, const ast_aes_decrypt_key *key)
AES decrypt data.
int ast_encrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
Encrypt a message using a given private key.
int ast_decrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
Decrypt a message using a given private key.
#define ast_datastore_alloc(info, uid)
int dundi_ie_append_int(struct dundi_ie_data *ied, unsigned char ie, unsigned int value)
int dundi_ie_append_encdata(struct dundi_ie_data *ied, unsigned char ie, unsigned char *iv, void *data, int datalen)
void dundi_set_output(void(*func)(const char *))
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
int dundi_str_short_to_eid(dundi_eid *eid, const char *s)
int dundi_ie_append_answer(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid, unsigned char protocol, unsigned short flags, unsigned short weight, char *data)
int dundi_ie_append_eid(struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid)
int dundi_ie_append_byte(struct dundi_ie_data *ied, unsigned char ie, unsigned char dat)
int dundi_ie_append_short(struct dundi_ie_data *ied, unsigned char ie, unsigned short value)
int dundi_ie_append(struct dundi_ie_data *ied, unsigned char ie)
char * dundi_flags2str(char *buf, int bufsiz, int flags)
int dundi_parse_ies(struct dundi_ies *ies, unsigned char *data, int datalen)
void dundi_showframe(struct dundi_hdr *fhi, int rx, struct ast_sockaddr *sin, int datalen)
int dundi_ie_append_str(struct dundi_ie_data *ied, unsigned char ie, char *str)
char * dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid)
int dundi_eid_zero(dundi_eid *eid)
int dundi_ie_append_cause(struct dundi_ie_data *ied, unsigned char ie, unsigned char cause, char *data)
void dundi_set_error(void(*func)(const char *))
int dundi_ie_append_hint(struct dundi_ie_data *ied, unsigned char ie, unsigned short flags, char *data)
Distributed Universal Number Discovery (DUNDi) See also.
#define DUNDI_DEFAULT_VERSION
#define DUNDI_IE_CACHEBYPASS
#define DUNDI_COMMAND_NULL
#define DUNDI_IE_DEPARTMENT
#define DUNDI_IE_ORGANIZATION
#define DUNDI_COMMAND_PRECACHERQ
#define DUNDI_IE_LOCALITY
#define DUNDI_IE_SIGNATURE
#define DUNDI_IE_EXPIRATION
#define DUNDI_COMMAND_PRECACHERP
#define DUNDI_IE_CALLED_CONTEXT
#define DUNDI_COMMAND_ENCREJ
#define DUNDI_DEFAULT_TTL
#define DUNDI_COMMAND_EIDQUERY
#define DUNDI_IE_CALLED_NUMBER
#define DUNDI_COMMAND_DPRESPONSE
#define DUNDI_IE_EID_DIRECT
#define DUNDI_DEFAULT_RETRANS
#define DUNDI_IE_SHAREDKEY
#define DUNDI_COMMAND_CANCEL
#define DUNDI_COMMAND_INVALID
#define DUNDI_DEFAULT_CACHE_TIME
#define DUNDI_COMMAND_DPDISCOVER
#define DUNDI_DEFAULT_RETRANS_TIMER
#define DUNDI_COMMAND_EIDRESPONSE
#define DUNDI_IE_KEYCRC32
#define DUNDI_COMMAND_ACK
#define DUNDI_COMMAND_UNKNOWN
#define DUNDI_DEFAULT_KEY_EXPIRE
@ DUNDI_FLAG_NOCOMUNSOLICIT
@ DUNDI_FLAG_NOUNSOLICITED
#define DUNDI_COMMAND_FINAL
#define DUNDI_COMMAND_REGRESPONSE
#define DUNDI_COMMAND_ENCRYPT
#define DUNDI_COMMAND_REGREQ
#define DUNDI_IE_STATE_PROV
void ast_verbose(const char *fmt,...)
Generic File Format Support. Should be included by clients of the file handling routines....
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static struct ast_custom_function dundi_function
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
char * strsep(char **str, const char *delims)
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Asterisk internal frame definitions.
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
I/O Management (derived from Cheops-NG)
struct io_context * io_context_create(void)
Creates a context Create a context for I/O operations Basically mallocs an IO structure and sets up s...
int * ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data)
Adds an IO context.
void io_context_destroy(struct io_context *ioc)
Destroys a context.
int ast_io_wait(struct io_context *ioc, int howlong)
Waits for IO.
int ast_io_remove(struct io_context *ioc, int *id)
Removes an IO context.
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_HEAD_NOLOCK_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_LOCK(head)
Locks a list.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_INSERT_AFTER(head, listelm, elm, field)
Inserts a list entry after a given entry.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Asterisk locking-related definitions:
#define AST_PTHREADT_NULL
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_EXTENDED
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_FAILURE
Module could not be loaded properly.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
def ignore(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
int ast_bind(int sockfd, const struct ast_sockaddr *addr)
Wrapper around bind(2) that uses struct ast_sockaddr.
static char * ast_sockaddr_stringify_host(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brack...
ssize_t ast_sendto(int sockfd, const void *buf, size_t len, int flags, const struct ast_sockaddr *dest_addr)
Wrapper around sendto(2) that uses ast_sockaddr.
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
int ast_set_qos(int sockfd, int tos, int cos, const char *desc)
Set type of service.
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized,...
ssize_t ast_recvfrom(int sockfd, void *buf, size_t len, int flags, struct ast_sockaddr *src_addr)
Wrapper around recvfrom(2) that uses struct ast_sockaddr.
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
Wrapper for network related headers, masking differences between various operating systems....
Core PBX routines and definitions.
struct ast_context * ast_walk_contexts(struct ast_context *con)
void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count)
void ast_unregister_switch(struct ast_switch *sw)
Unregister an alternative switch.
int ast_register_switch(struct ast_switch *sw)
Register an alternative dialplan switch.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
int ast_pbx_exec_application(struct ast_channel *chan, const char *app_name, const char *app_args)
Execute an application.
int ast_unlock_context(struct ast_context *con)
const char * ast_get_context_name(struct ast_context *con)
#define ast_custom_function_register(acf)
Register a custom function.
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_rdlock_contexts(void)
Read locks the context list.
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
struct ast_exten * ast_walk_context_extensions(struct ast_context *con, struct ast_exten *priority)
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch)
int ast_unlock_contexts(void)
Unlocks contexts.
const char * ast_get_extension_name(struct ast_exten *exten)
int ast_rdlock_context(struct ast_context *con)
Read locks a given context.
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
static int cache_save_hint(dundi_eid *eidpeer, struct dundi_request *req, struct dundi_hint *hint, int expiration)
static int cache_lookup(struct dundi_request *req, dundi_eid *peer_eid, uint32_t crc, int *lowexpiration)
static int socket_read(int *id, int fd, short events, void *sock)
static char * dundi_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int encrypt_memcpy(unsigned char *dst, unsigned char *src, int len, unsigned char *iv, ast_aes_encrypt_key *ecx)
static int reset_transaction(struct dundi_transaction *trans)
static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
static void apply_peer(struct dundi_transaction *trans, struct dundi_peer *p)
static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies *ies, char *ccontext)
static struct dundi_transaction * create_transaction(struct dundi_peer *p)
static void load_password(void)
static void check_password(void)
#define DUNDI_MODEL_SYMMETRIC
static void reschedule_precache(const char *number, const char *context, int expiration)
static struct ast_switch dundi_switch
static int decrypt_memcpy(unsigned char *dst, unsigned char *src, int len, unsigned char *iv, ast_aes_decrypt_key *dcx)
static dundi_eid empty_eid
static char * dundi_show_hints(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void cancel_request(struct dundi_request *dr)
static int cache_lookup_internal(time_t now, struct dundi_request *req, char *key, char *eid_str_full, int *lowexpiration)
int dundi_precache(const char *context, const char *number)
Pre-cache to push upstream peers.
static void drds_destroy(struct dundi_result_datastore *drds)
static int handle_command_response(struct dundi_transaction *trans, struct dundi_hdr *hdr, int datalen, int encrypted)
static int dundi_precache_internal(const char *context, const char *number, int ttl, dundi_eid *avoids[])
static struct ast_sched_context * sched
static int optimize_transactions(struct dundi_request *dr, int order)
static int dundi_send(struct dundi_transaction *trans, int cmdresp, int flags, int final, struct dundi_ie_data *ied)
static char * dundi_store_history(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * dundi_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * dundi_show_requests(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies *ies, char *ccontext)
static void build_secret(char *secret, int seclen)
#define DUNDI_FLAG_INTERNAL_NOPARTIAL
static struct ast_custom_function dundi_query_function
static int dundi_encrypt(struct dundi_transaction *trans, struct dundi_packet *pack)
static int dundifunc_read(struct ast_channel *chan, const char *cmd, char *num, char *buf, size_t len)
static int do_register_expire(const void *data)
static int global_autokilltimeout
static int append_transaction(struct dundi_request *dr, struct dundi_peer *p, int ttl, dundi_eid *avoid[])
static int get_trans_id(void)
static int has_permission(struct permissionlist *permlist, char *cont)
static void save_secret(const char *newkey, const char *oldkey)
static int outgoing_sip_tech
static int check_request(struct dundi_request *dr)
static int check_key(struct dundi_peer *peer, unsigned char *newkey, unsigned char *newsig, uint32_t keycrc32)
static char cursecret[80]
static int dundi_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static char * dundi_do_lookup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void prune_peers(void)
int dundi_lookup(struct dundi_result *result, int maxret, struct ast_channel *chan, const char *dcontext, const char *number, int cbypass)
Lookup the given number in the given dundi context. Lookup number in a given dundi context (if unspec...
static struct dundi_peer * find_peer(dundi_eid *eid)
#define DUNDI_MODEL_INBOUND
static void build_iv(unsigned char *iv)
static int query_transactions(struct dundi_request *dr)
static void dundi_debug_output(const char *data)
static unsigned long avoid_crc32(dundi_eid *avoid[])
static void mark_mappings(void)
static int dundi_query_eid_internal(struct dundi_entity_info *dei, const char *dcontext, dundi_eid *eid, struct dundi_hint_metadata *hmd, int ttl, int blockempty, dundi_eid *avoid[])
static void * dundi_query_thread(void *data)
static int global_storehistory
static int set_config(char *config_file, struct ast_sockaddr *sin, int reload, struct ast_sockaddr *sin2)
static int cache_save(dundi_eid *eidpeer, struct dundi_request *req, int start, int unaffected, int expiration, int push)
static void dundi_ie_append_eid_appropriately(struct dundi_ie_data *ied, char *context, dundi_eid *eid, dundi_eid *us)
static char * dundi_show_entityid(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int dundi_ack(struct dundi_transaction *trans, int final)
static int dundi_cache_time
static struct dundi_hdr * dundi_decrypt(struct dundi_transaction *trans, unsigned char *dst, int *dstlen, struct dundi_hdr *ohdr, struct dundi_encblock *src, int srclen)
static void populate_addr(struct dundi_peer *peer, dundi_eid *eid)
static int dundi_result_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static void destroy_packets(struct packetlist *p)
static void sort_results(struct dundi_result *results, int count)
static void append_permission(struct permissionlist *permlist, const char *s, int allow)
static struct ast_custom_function dundi_result_function
static const struct ast_app_option dundi_query_opts[128]
static void dundi_error_output(const char *data)
static unsigned int dundi_result_id
static int register_request(struct dundi_request *dr, struct dundi_request **pending)
static int dundi_discover(struct dundi_transaction *trans)
static int get_ipaddress(char *ip, size_t size, const char *str, int family)
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[])
static const struct ast_datastore_info dundi_result_datastore_info
static pthread_t precachethreadid
static char * dundi_do_precache(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int ack_trans(struct dundi_transaction *trans, int iseqno)
static int dundi_helper(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *data, int flag)
static void set_host_ipaddr(struct ast_sockaddr *sin)
static char * dundi_show_cache(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void destroy_packet(struct dundi_packet *pack, int needfree)
static int dundi_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
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 int rescomp(const void *a, const void *b)
static int dundi_query_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static void mark_peers(void)
static uint16_t dundi_sockaddr_port(const struct ast_sockaddr *addr)
static void destroy_permissions(struct permissionlist *permlist)
static struct ast_cli_entry cli_dundi[]
static char * tech2str(int tech)
static void prune_mappings(void)
static char * dundi_do_query(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void qualify_peer(struct dundi_peer *peer, int schedonly)
#define DUNDI_MODEL_OUTBOUND
static int dundi_shutdown
static int dundi_query(struct dundi_transaction *trans)
static pthread_t netthreadid
static int precache_transactions(struct dundi_request *dr, struct dundi_mapping *maps, int mapcount, int *expiration, int *foundanswers)
static int precache_trans(struct dundi_transaction *trans, struct dundi_mapping *maps, int mapcount, int *minexp, int *foundanswers)
static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map, char *called_number, dundi_eid *us_eid, int anscnt, struct dundi_hint_metadata *hmd)
static int default_expiration
static int get_mapping_weight(struct dundi_mapping *map, struct varshead *headp)
static int do_autokill(const void *data)
static void deep_copy_peer(struct dundi_peer *peer_dst, const struct dundi_peer *peer_src)
int dundi_query_eid(struct dundi_entity_info *dei, const char *dcontext, dundi_eid eid)
Retrieve information on a specific EID.
static void * network_thread(void *ignore)
static char * dundi_show_trans(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct io_context * io
static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode)
static void unregister_request(struct dundi_request *dr)
static int dundi_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static int update_key(struct dundi_peer *peer)
#define DUNDI_SECRET_TIME
static int load_module(void)
static void build_mapping(const char *name, const char *value)
static void abort_request(struct dundi_request *dr)
static int dundi_answer_entity(struct dundi_transaction *trans, struct dundi_ies *ies, char *ccontext)
static char * dundi_show_mappings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * complete_peer_helper(const char *line, const char *word, int pos, int state, int rpos)
static char stateprov[80]
static struct dundi_peer * any_peer
Wildcard peer.
static char * dundi_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int str2tech(const char *str)
static int dundi_xmit(struct dundi_packet *pack)
static int unload_module(void)
static void * process_precache(void *ign)
static int dundi_rexmit(const void *data)
static void dundi_reject(struct dundi_hdr *h, struct ast_sockaddr *sin)
static void * dundi_lookup_thread(void *data)
static char * dundi_sockaddr_stringify_host(const struct ast_sockaddr *addr)
static char pjsip_outgoing_endpoint[80]
static char * dundi_flush(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct dundi_transaction * find_transaction(struct dundi_hdr *hdr, struct ast_sockaddr *sin)
static char * model2str(int model)
static void destroy_map(struct dundi_mapping *map)
static int do_qualify(const void *data)
#define DUNDI_TIMING_HISTORY
static void destroy_peer(struct dundi_peer *peer)
static void * process_clearcache(void *ignore)
static int start_network_thread(void)
static int handle_frame(struct dundi_hdr *h, struct ast_sockaddr *sin, int datalen)
static int do_register(const void *data)
static void dundi_precache_full(void)
static void drds_destroy_cb(void *data)
static char * dundi_show_precache(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static pthread_t clearcachethreadid
static void * dundi_precache_thread(void *data)
static int dundi_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static int discover_transactions(struct dundi_request *dr)
static dundi_eid global_eid
static char secretpath[80]
Scheduler Routines (derived from cheops)
#define AST_SCHED_DEL(sched, id)
Remove a scheduler entry.
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
Parse a time (integer) string.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Main Channel structure associated with a channel.
descriptor for a cli entry.
int args
This gets set in ast_cli_register()
ast_context: An extension context
Data structure associated with a custom dialplan function.
Structure for a data store type.
Structure for a data store object.
struct ast_db_entry * next
An Entity ID is essentially a MAC address, brief and unique.
ast_exten: An extension The dialplan is saved as a linked list with each context having it's own link...
Structure used to handle boolean flags.
Socket address structure.
struct ast_var_t::@211 entries
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
struct dundi_answer * answers[DUNDI_MAX_ANSWERS+1]
dundi_eid * eids[DUNDI_MAX_STACK+1]
int eid_direct[DUNDI_MAX_STACK+1]
unsigned char * encsharedkey
struct dundi_encblock * encblock
char lcontext[AST_MAX_EXTENSION]
struct dundi_mapping::@417 list
char dcontext[AST_MAX_EXTENSION]
struct dundi_mapping * next
struct dundi_packet::@411 list
struct dundi_transaction * parent
int lookuptimes[DUNDI_TIMING_HISTORY]
unsigned char txenckey[256]
char * lookups[DUNDI_TIMING_HISTORY]
unsigned char rxenckey[256]
ast_aes_encrypt_key us_ecx
struct dundi_peer::permissionlist permit
struct dundi_transaction * regtrans
ast_aes_decrypt_key them_dcx
struct dundi_peer::@418 list
struct dundi_transaction * qualtrans
ast_aes_encrypt_key them_ecx
struct permissionlist include
ast_aes_decrypt_key us_dcx
struct dundi_precache_queue::@412 list
char called_context[AST_MAX_EXTENSION]
struct dundi_mapping * maps
int directs[DUNDI_MAX_STACK+1]
dundi_eid * eids[DUNDI_MAX_STACK+1]
char called_number[AST_MAX_EXTENSION]
struct dundi_transaction * trans
struct dundi_entity_info * dei
struct dundi_request::@415 trans
struct dundi_hint_metadata * hmd
struct dundi_request::@416 list
char number[AST_MAX_EXTENSION]
char dcontext[AST_MAX_EXTENSION]
struct dundi_result results[MAX_RESULTS]
struct dundi_transaction::packetlist packets
struct dundi_transaction::@414 all
struct packetlist lasttrans
struct dundi_transaction::@413 parentlist
dundi_eid eids[DUNDI_MAX_STACK+1]
struct dundi_request * parent
Global IO variables are now in a struct in order to be made threadsafe.
struct permission::@410 list
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define ast_test_flag(p, flag)
#define ast_set_flag_nonstd(p, flag)
#define ast_clear_flag_nonstd(p, flag)
int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
Compare two EIDs.
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
#define ast_pthread_create_background(a, b, c, d)
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
#define ast_clear_flag(p, flag)
long int ast_random(void)
#define ast_pthread_create_detached(a, b, c, d)
int ast_eid_is_empty(const struct ast_eid *eid)
Check if EID is empty.
#define ast_test_flag_nonstd(p, flag)
#define ast_set_flag(p, flag)
#define ast_copy_flags(dest, src, flagz)
struct ast_eid ast_eid_default
Global EID.
int ast_str_to_eid(struct ast_eid *eid, const char *s)
Convert a string into an EID.