aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/tex/asterisk-conf.tex5
-rw-r--r--doc/tex/channelvariables.tex1
-rw-r--r--include/asterisk/dundi.h117
-rw-r--r--include/asterisk/utils.h42
-rw-r--r--main/asterisk.c15
-rw-r--r--main/netsock.c81
-rw-r--r--main/pbx.c3
-rw-r--r--pbx/dundi-parser.c38
-rw-r--r--pbx/dundi-parser.h3
-rw-r--r--pbx/pbx_dundi.c180
10 files changed, 292 insertions, 193 deletions
diff --git a/doc/tex/asterisk-conf.tex b/doc/tex/asterisk-conf.tex
index e25bc996f..f39d4dc05 100644
--- a/doc/tex/asterisk-conf.tex
+++ b/doc/tex/asterisk-conf.tex
@@ -124,6 +124,11 @@ languageprefix = yes | no
; eh. on SMB/CIFS mounts
lockmode = lockfile | flock
+; Entity ID. This is in the form of a MAC address. It should be universally
+; unique. It must be unique between servers communicating with a protocol
+; that uses this value. The only thing that uses this currently is DUNDi,
+; but other things will use it in the future.
+; entityid=00:11:22:33:44:55
[files]
; Changing the following lines may compromise your security
diff --git a/doc/tex/channelvariables.tex b/doc/tex/channelvariables.tex
index 1c3220159..ae5b1974b 100644
--- a/doc/tex/channelvariables.tex
+++ b/doc/tex/channelvariables.tex
@@ -795,6 +795,7 @@ ${TRANSFER_CONTEXT} Context for transferred calls
${FORWARD_CONTEXT} Context for forwarded calls
${UNIQUEID} * Current call unique identifier
${SYSTEMNAME} * value of the systemname option of asterisk.conf
+${ENTITYID} * Global Entity ID set automatically, or from asterisk.conf
\end{verbatim}
\subsection{Application return values}
diff --git a/include/asterisk/dundi.h b/include/asterisk/dundi.h
index e588338ae..c2a85493e 100644
--- a/include/asterisk/dundi.h
+++ b/include/asterisk/dundi.h
@@ -25,15 +25,11 @@
#define _ASTERISK_DUNDI_H
#include "asterisk/channel.h"
+#include "asterisk/utils.h"
#define DUNDI_PORT 4520
-/*!\brief A DUNDi Entity ID is essentially a MAC address, brief and unique */
-struct _dundi_eid {
- unsigned char eid[6];
-} __attribute__ ((__packed__));
-
-typedef struct _dundi_eid dundi_eid;
+typedef struct ast_eid dundi_eid;
struct dundi_hdr {
unsigned short strans; /*!< Source transaction */
@@ -54,26 +50,49 @@ struct dundi_ie_hdr {
#define DUNDI_FLAG_RETRANS (1 << 16) /*!< Applies to dtrans */
#define DUNDI_FLAG_RESERVED (1 << 16) /*!< Applies to strans */
-#define DUNDI_PROTO_NONE 0 /*!< No answer yet */
-#define DUNDI_PROTO_IAX 1 /*!< IAX version 2 */
-#define DUNDI_PROTO_SIP 2 /*!< Session Initiation Protocol */
-#define DUNDI_PROTO_H323 3 /*!< ITU H.323 */
-
-#define DUNDI_FLAG_NONEXISTENT (0) /*!< Isn't and can't be a valid number */
-#define DUNDI_FLAG_EXISTS (1 << 0) /*!< Is a valid number */
-#define DUNDI_FLAG_MATCHMORE (1 << 1) /*!< Might be valid if you add more digits */
-#define DUNDI_FLAG_CANMATCH (1 << 2) /*!< Might be a match */
-#define DUNDI_FLAG_IGNOREPAT (1 << 3) /*!< Keep dialtone */
-#define DUNDI_FLAG_RESIDENTIAL (1 << 4) /*!< Destination known to be residential */
-#define DUNDI_FLAG_COMMERCIAL (1 << 5) /*!< Destination known to be commercial */
-#define DUNDI_FLAG_MOBILE (1 << 6) /*!< Destination known to be cellular/mobile */
-#define DUNDI_FLAG_NOUNSOLICITED (1 << 7) /*!< No unsolicited calls of any kind through this route */
-#define DUNDI_FLAG_NOCOMUNSOLICIT (1 << 8) /*!< No commercial unsolicited calls through this route */
-
-#define DUNDI_HINT_NONE (0)
-#define DUNDI_HINT_TTL_EXPIRED (1 << 0) /*!< TTL Expired */
-#define DUNDI_HINT_DONT_ASK (1 << 1) /*!< Don't ask for anything beginning with data */
-#define DUNDI_HINT_UNAFFECTED (1 << 2) /*!< Answer not affected by entity list */
+enum {
+ /*! No answer yet */
+ DUNDI_PROTO_NONE = 0,
+ /*! IAX, version 2 */
+ DUNDI_PROTO_IAX = 1,
+ /*! SIP - Session Initiation Protocol, RFC 3261 */
+ DUNDI_PROTO_SIP = 2,
+ /*! ITU H.323 */
+ DUNDI_PROTO_H323 = 3,
+};
+
+enum {
+ /*! Isn't and can't be a valid number */
+ DUNDI_FLAG_NONEXISTENT = (0),
+ /*! Is a valid number */
+ DUNDI_FLAG_EXISTS = (1 << 0),
+ /*! Might be valid if you add more digits */
+ DUNDI_FLAG_MATCHMORE = (1 << 1),
+ /*! Might be a match */
+ DUNDI_FLAG_CANMATCH = (1 << 2),
+ /*! Keep dialtone */
+ DUNDI_FLAG_IGNOREPAT = (1 << 3),
+ /*! Destination known to be residential */
+ DUNDI_FLAG_RESIDENTIAL = (1 << 4),
+ /*! Destination known to be commercial */
+ DUNDI_FLAG_COMMERCIAL = (1 << 5),
+ /*! Destination known to be cellular/mobile */
+ DUNDI_FLAG_MOBILE = (1 << 6),
+ /*! No unsolicited calls of any kind through this route */
+ DUNDI_FLAG_NOUNSOLICITED = (1 << 7),
+ /*! No commercial unsolicited calls through this route */
+ DUNDI_FLAG_NOCOMUNSOLICIT = (1 << 8),
+};
+
+enum {
+ DUNDI_HINT_NONE = (0),
+ /*! TTL Expired */
+ DUNDI_HINT_TTL_EXPIRED = (1 << 0),
+ /*! Don't ask for anything beginning with data */
+ DUNDI_HINT_DONT_ASK = (1 << 1),
+ /*! Answer not affected by entity list */
+ DUNDI_HINT_UNAFFECTED = (1 << 2),
+};
struct dundi_encblock { /*!< AES-128 encrypted block */
unsigned char iv[16]; /*!< Initialization vector of random data */
@@ -93,14 +112,24 @@ struct dundi_hint {
unsigned char data[0]; /*!< For data for hint */
} __attribute__ ((__packed__));
-#define DUNDI_CAUSE_SUCCESS 0 /*!< Success */
-#define DUNDI_CAUSE_GENERAL 1 /*!< General unspecified failure */
-#define DUNDI_CAUSE_DYNAMIC 2 /*!< Requested entity is dynamic */
-#define DUNDI_CAUSE_NOAUTH 3 /*!< No or improper authorization */
-#define DUNDI_CAUSE_DUPLICATE 4 /*!< Duplicate request */
-#define DUNDI_CAUSE_TTL_EXPIRED 5 /*!< Expired TTL */
-#define DUNDI_CAUSE_NEEDKEY 6 /*!< Need new session key to decode */
-#define DUNDI_CAUSE_BADENCRYPT 7 /*!< Badly encrypted data */
+enum {
+ /*! Success */
+ DUNDI_CAUSE_SUCCESS = 0,
+ /*! General unspecified failure */
+ DUNDI_CAUSE_GENERAL = 1,
+ /*! Requested entity is dynamic */
+ DUNDI_CAUSE_DYNAMIC = 2,
+ /*! No or improper authorization */
+ DUNDI_CAUSE_NOAUTH = 3,
+ /*! Duplicate request */
+ DUNDI_CAUSE_DUPLICATE = 4,
+ /*! Expired TTL */
+ DUNDI_CAUSE_TTL_EXPIRED = 5,
+ /*! Need new session key to decode */
+ DUNDI_CAUSE_NEEDKEY = 6,
+ /*! Badly encrypted data */
+ DUNDI_CAUSE_BADENCRYPT = 7,
+};
struct dundi_cause {
unsigned char causecode; /*!< Numerical cause (DUNDI_CAUSE_*) */
@@ -114,14 +143,16 @@ struct dundi_peer_status {
dundi_eid peereid;
} __attribute__ ((__packed__));
-#define DUNDI_PEER_PRIMARY (1 << 0)
-#define DUNDI_PEER_SECONDARY (1 << 1)
-#define DUNDI_PEER_UNAVAILABLE (1 << 2)
-#define DUNDI_PEER_REGISTERED (1 << 3)
-#define DUNDI_PEER_MOD_OUTBOUND (1 << 4)
-#define DUNDI_PEER_MOD_INBOUND (1 << 5)
-#define DUNDI_PEER_PCMOD_OUTBOUND (1 << 6)
-#define DUNDI_PEER_PCMOD_INBOUND (1 << 7)
+enum {
+ DUNDI_PEER_PRIMARY = (1 << 0),
+ DUNDI_PEER_SECONDARY = (1 << 1),
+ DUNDI_PEER_UNAVAILABLE = (1 << 2),
+ DUNDI_PEER_REGISTERED = (1 << 3),
+ DUNDI_PEER_MOD_OUTBOUND = (1 << 4),
+ DUNDI_PEER_MOD_INBOUND = (1 << 5),
+ DUNDI_PEER_PCMOD_OUTBOUND = (1 << 6),
+ DUNDI_PEER_PCMOD_INBOUND = (1 << 7),
+};
#define DUNDI_COMMAND_FINAL (0x80) /*!< Or'd with other flags */
@@ -163,7 +194,7 @@ struct dundi_peer_status {
#define DUNDI_IE_SHAREDKEY 17 /*!< RSA encrypted AES-128 key */
#define DUNDI_IE_SIGNATURE 18 /*!< RSA Signature of encrypted shared key */
#define DUNDI_IE_KEYCRC32 19 /*!< CRC32 of encrypted key (int) */
-#define DUNDI_IE_HINT 20 /*!< Answer hints (struct ast_hint) */
+#define DUNDI_IE_HINT 20 /*!< Answer hints */
#define DUNDI_IE_DEPARTMENT 21 /*!< Department, for EIDQUERY (string) */
#define DUNDI_IE_ORGANIZATION 22 /*!< Organization, for EIDQUERY (string) */
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 074bc085d..0735babf1 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -671,4 +671,46 @@ static void force_inline _ast_assert(int condition, const char *condition_str,
#include "asterisk/strings.h"
+/*!
+ * \brief An Entity ID is essentially a MAC address, brief and unique
+ */
+struct ast_eid {
+ unsigned char eid[6];
+} __attribute__ ((__packed__));
+
+/*!
+ * \brief Global EID
+ *
+ * This is set in asterisk.conf, or determined automatically by taking the mac
+ * address of an Ethernet interface on the system.
+ */
+extern struct ast_eid g_eid;
+
+/*!
+ * \brief Fill in an ast_eid with the default eid of this machine
+ */
+void ast_set_default_eid(struct ast_eid *eid);
+
+/*!
+ * /brief Convert an EID to a string
+ */
+char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid);
+
+/*!
+ * \brief Convert a string into an EID
+ *
+ * This function expects an EID in the format:
+ * 00:11:22:33:44:55
+ *
+ * \return 0 success, non-zero failure
+ */
+int ast_str_to_eid(struct ast_eid *eid, const char *s);
+
+/*!
+ * \brief Compare two EIDs
+ *
+ * \return 0 if the two are the same, non-zero otherwise
+ */
+int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2);
+
#endif /* _ASTERISK_UTILS_H */
diff --git a/main/asterisk.c b/main/asterisk.c
index 7d3079938..14fbbf98e 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -169,6 +169,8 @@ long option_minmemfree; /*!< Minimum amount of free system memory - stop acce
/*! @} */
+struct ast_eid g_eid;
+
/* XXX tmpdir is a subdir of the spool directory, and no way to remap it */
char record_cache_dir[AST_CACHE_DIR_LEN] = DEFAULT_TMP_DIR;
@@ -386,6 +388,7 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c
{
char buf[BUFSIZ];
struct ast_tm tm;
+ char eid_str[128];
switch (cmd) {
case CLI_INIT:
@@ -397,6 +400,8 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c
return NULL;
}
+ ast_eid_to_str(eid_str, sizeof(eid_str), &g_eid);
+
ast_cli(a->fd, "\nPBX Core settings\n");
ast_cli(a->fd, "-----------------\n");
ast_cli(a->fd, " Version: %s\n", ast_get_version());
@@ -425,6 +430,7 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c
}
ast_cli(a->fd, " System: %s/%s built by %s on %s %s\n", ast_build_os, ast_build_kernel, ast_build_user, ast_build_machine, ast_build_date);
ast_cli(a->fd, " System name: %s\n", ast_config_AST_SYSTEM_NAME);
+ ast_cli(a->fd, " Entity ID: %s\n", eid_str);
ast_cli(a->fd, " Default language: %s\n", defaultlanguage);
ast_cli(a->fd, " Language prefix: %s\n", ast_language_is_prefix ? "Enabled" : "Disabled");
ast_cli(a->fd, " User name and group: %s/%s\n", ast_config_AST_RUN_USER, ast_config_AST_RUN_GROUP);
@@ -2608,6 +2614,8 @@ static void ast_readconfig(void)
ast_copy_string(cfg_paths.socket_path, DEFAULT_SOCKET, sizeof(cfg_paths.socket_path));
ast_copy_string(cfg_paths.run_dir, DEFAULT_RUN_DIR, sizeof(cfg_paths.run_dir));
+ ast_set_default_eid(&g_eid);
+
/* no asterisk.conf? no problem, use buildtime config! */
if (!cfg) {
return;
@@ -2773,6 +2781,13 @@ static void ast_readconfig(void)
option_minmemfree = 0;
}
#endif
+ } else if (!strcasecmp(v->name, "entityid")) {
+ struct ast_eid tmp_eid;
+ if (!ast_str_to_eid(&tmp_eid, v->value)) {
+ ast_verbose("Successfully set global EID to '%s'\n", v->value);
+ g_eid = tmp_eid;
+ } else
+ ast_verbose("Invalid Entity ID '%s' provided\n", v->value);
}
}
for (v = ast_variable_browse(cfg, "compat"); v; v = v->next) {
diff --git a/main/netsock.c b/main/netsock.c
index eefec0833..58972781e 100644
--- a/main/netsock.c
+++ b/main/netsock.c
@@ -207,3 +207,84 @@ void ast_netsock_unref(struct ast_netsock *ns)
{
ASTOBJ_UNREF(ns, ast_netsock_destroy);
}
+
+char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
+{
+ int x;
+ char *os = s;
+ if (maxlen < 18) {
+ if (s && (maxlen > 0))
+ *s = '\0';
+ } else {
+ for (x = 0; x < 5; x++) {
+ sprintf(s, "%02x:", eid->eid[x]);
+ s += 3;
+ }
+ sprintf(s, "%02x", eid->eid[5]);
+ }
+ return os;
+}
+
+void ast_set_default_eid(struct ast_eid *eid)
+{
+#if defined(SIOCGIFHWADDR)
+ int s, x = 0;
+ char eid_str[20];
+ struct ifreq ifr;
+
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ return;
+ for (x = 0; x < 10; x++) {
+ memset(&ifr, 0, sizeof(ifr));
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x);
+ if (ioctl(s, SIOCGIFHWADDR, &ifr))
+ continue;
+ memcpy(eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(*eid));
+ ast_debug(1, "Seeding global EID '%s' from '%s' using 'siocgifhwaddr'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifr.ifr_name);
+ close(s);
+ return;
+ }
+ close(s);
+#else
+#if defined(ifa_broadaddr) && !defined(SOLARIS)
+ char eid_str[20];
+ struct ifaddrs *ifap;
+
+ if (getifaddrs(&ifap) == 0) {
+ struct ifaddrs *p;
+ for (p = ifap; p; p = p->ifa_next) {
+ if ((p->ifa_addr->sa_family == AF_LINK) && !(p->ifa_flags & IFF_LOOPBACK) && (p->ifa_flags & IFF_RUNNING)) {
+ struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
+ memcpy(&(eid->eid), sdp->sdl_data + sdp->sdl_nlen, 6);
+ ast_debug(1, "Seeding global EID '%s' from '%s' using 'getifaddrs'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), p->ifa_name);
+ freeifaddrs(ifap);
+ return;
+ }
+ }
+ freeifaddrs(ifap);
+ }
+#endif
+#endif
+ ast_log(LOG_NOTICE, "No ethernet interface found for seeding global EID. You will have to set it manually.\n");
+}
+
+int ast_str_to_eid(struct ast_eid *eid, const char *s)
+{
+ unsigned int eid_int[6];
+ int x;
+
+ if (sscanf(s, "%x:%x:%x:%x:%x:%x", &eid_int[0], &eid_int[1], &eid_int[2],
+ &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
+ return -1;
+
+ for (x = 0; x < 6; x++)
+ eid->eid[x] = eid_int[x];
+
+ return 0;
+}
+
+int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
+{
+ return memcmp(eid1, eid2, sizeof(*eid1));
+}
diff --git a/main/pbx.c b/main/pbx.c
index f49ead16e..b2aebbd9b 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -2314,6 +2314,9 @@ void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, c
s = workspace;
} else if (!strcmp(var, "SYSTEMNAME")) {
s = ast_config_AST_SYSTEM_NAME;
+ } else if (!strcmp(var, "ENTITYID")) {
+ ast_eid_to_str(workspace, workspacelen, &g_eid);
+ s = workspace;
}
}
/* if not found, look into chanvars or global vars */
diff --git a/pbx/dundi-parser.c b/pbx/dundi-parser.c
index bab1bfc91..aca902a3a 100644
--- a/pbx/dundi-parser.c
+++ b/pbx/dundi-parser.c
@@ -48,23 +48,6 @@ static void internalerror(const char *str)
static void (*outputf)(const char *str) = internaloutput;
static void (*errorf)(const char *str) = internalerror;
-char *dundi_eid_to_str(char *s, int maxlen, dundi_eid *eid)
-{
- int x;
- char *os = s;
- if (maxlen < 18) {
- if (s && (maxlen > 0))
- *s = '\0';
- } else {
- for (x=0;x<5;x++) {
- sprintf(s, "%02x:", eid->eid[x]);
- s += 3;
- }
- sprintf(s, "%02x", eid->eid[5]);
- }
- return os;
-}
-
char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid)
{
int x;
@@ -81,18 +64,6 @@ char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid)
return os;
}
-int dundi_str_to_eid(dundi_eid *eid, const char *s)
-{
- unsigned int eid_int[6];
- int x;
- if (sscanf(s, "%x:%x:%x:%x:%x:%x", &eid_int[0], &eid_int[1], &eid_int[2],
- &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
- return -1;
- for (x=0;x<6;x++)
- eid->eid[x] = eid_int[x];
- return 0;
-}
-
int dundi_str_short_to_eid(dundi_eid *eid, const char *s)
{
unsigned int eid_int[6];
@@ -113,11 +84,6 @@ int dundi_eid_zero(dundi_eid *eid)
return 1;
}
-int dundi_eid_cmp(dundi_eid *eid1, dundi_eid *eid2)
-{
- return memcmp(eid1, eid2, sizeof(dundi_eid));
-}
-
static void dump_string(char *output, int maxlen, void *value, int len)
{
if (maxlen > len + 1)
@@ -134,7 +100,7 @@ static void dump_cbypass(char *output, int maxlen, void *value, int len)
static void dump_eid(char *output, int maxlen, void *value, int len)
{
if (len == 6)
- dundi_eid_to_str(output, maxlen, (dundi_eid *)value);
+ ast_eid_to_str(output, maxlen, (dundi_eid *)value);
else
snprintf(output, maxlen, "Invalid EID len %d", len);
}
@@ -335,7 +301,7 @@ static void dump_answer(char *output, int maxlen, void *value, int len)
memcpy(tmp, answer->data, datalen);
tmp[datalen] = '\0';
- dundi_eid_to_str(eid_str, sizeof(eid_str), &answer->eid);
+ ast_eid_to_str(eid_str, sizeof(eid_str), &answer->eid);
snprintf(output, maxlen, "[%s] %d <%s/%s> from [%s]",
dundi_flags2str(flags, sizeof(flags), ntohs(answer->flags)),
ntohs(answer->weight),
diff --git a/pbx/dundi-parser.h b/pbx/dundi-parser.h
index 8ff772347..69a717e6f 100644
--- a/pbx/dundi-parser.h
+++ b/pbx/dundi-parser.h
@@ -77,12 +77,9 @@ extern int dundi_ie_append_encdata(struct dundi_ie_data *ied, unsigned char ie,
extern int dundi_ie_append_byte(struct dundi_ie_data *ied, unsigned char ie, unsigned char dat);
extern int dundi_ie_append(struct dundi_ie_data *ied, unsigned char ie);
extern int dundi_parse_ies(struct dundi_ies *ies, unsigned char *data, int datalen);
-extern char *dundi_eid_to_str(char *s, int maxlen, dundi_eid *eid);
extern char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid);
-extern int dundi_str_to_eid(dundi_eid *eid, const char *s);
extern int dundi_str_short_to_eid(dundi_eid *eid, const char *s);
extern int dundi_eid_zero(dundi_eid *eid);
-extern int dundi_eid_cmp(dundi_eid *eid1, dundi_eid *eid2);
extern char *dundi_flags2str(char *s, int maxlen, int flags);
extern char *dundi_hint2str(char *s, int maxlen, int flags);
#endif
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index b5bd58de3..28f745753 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -388,50 +388,6 @@ static void dundi_reject(struct dundi_hdr *h, struct sockaddr_in *sin)
dundi_xmit(&tmp.pack);
}
-static void reset_global_eid(void)
-{
-#if defined(SIOCGIFHWADDR)
- int s, x = 0;
- char eid_str[20];
- struct ifreq ifr;
-
- s = socket(AF_INET, SOCK_STREAM, 0);
- if (s < 0)
- return;
- for (x = 0; x < 10; x++) {
- memset(&ifr, 0, sizeof(ifr));
- snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x);
- if (ioctl(s, SIOCGIFHWADDR, &ifr))
- continue;
- memcpy(&global_eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(global_eid));
- ast_debug(1, "Seeding global EID '%s' from '%s' using 'siocgifhwaddr'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), ifr.ifr_name);
- close(s);
- return;
- }
- close(s);
-#else
-#if defined(ifa_broadaddr) && !defined(SOLARIS)
- char eid_str[20];
- struct ifaddrs *ifap;
-
- if (getifaddrs(&ifap) == 0) {
- struct ifaddrs *p;
- for (p = ifap; p; p = p->ifa_next) {
- if ((p->ifa_addr->sa_family == AF_LINK) && !(p->ifa_flags & IFF_LOOPBACK) && (p->ifa_flags & IFF_RUNNING)) {
- struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
- memcpy(&(global_eid.eid), sdp->sdl_data + sdp->sdl_nlen, 6);
- ast_debug(1, "Seeding global EID '%s' from '%s' using 'getifaddrs'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), p->ifa_name);
- freeifaddrs(ifap);
- return;
- }
- }
- freeifaddrs(ifap);
- }
-#endif
-#endif
- ast_log(LOG_NOTICE, "No ethernet interface found for seeding global EID. You will have to set it manually.\n");
-}
-
static int get_trans_id(void)
{
struct dundi_transaction *t;
@@ -475,7 +431,7 @@ static struct dundi_peer *find_peer(dundi_eid *eid)
eid = &empty_eid;
AST_LIST_TRAVERSE(&peers, cur, list) {
- if (!dundi_eid_cmp(&cur->eid,eid))
+ if (!ast_eid_cmp(&cur->eid,eid))
break;
}
@@ -557,7 +513,7 @@ static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map
dr[anscnt].expiration = dundi_cache_time;
ast_copy_string(dr[anscnt].tech, tech2str(map->tech), sizeof(dr[anscnt].tech));
dr[anscnt].eid = *us_eid;
- dundi_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid);
+ ast_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid);
if (ast_test_flag(&flags, DUNDI_FLAG_EXISTS)) {
AST_LIST_HEAD_INIT_NOLOCK(&headp);
newvariable = ast_var_assign("NUMBER", called_number);
@@ -611,7 +567,7 @@ static void *dundi_lookup_thread(void *data)
int expiration = dundi_cache_time;
ast_debug(1, "Whee, looking up '%s@%s' for '%s'\n", st->called_number, st->called_context,
- st->eids[0] ? dundi_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
+ st->eids[0] ? ast_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
memset(&ied, 0, sizeof(ied));
memset(&dr, 0, sizeof(dr));
memset(&hmd, 0, sizeof(hmd));
@@ -670,7 +626,7 @@ static void *dundi_precache_thread(void *data)
char eid_str[20];
ast_debug(1, "Whee, precaching '%s@%s' for '%s'\n", st->called_number, st->called_context,
- st->eids[0] ? dundi_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
+ st->eids[0] ? ast_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
memset(&ied, 0, sizeof(ied));
/* Now produce precache */
@@ -705,11 +661,11 @@ static void *dundi_query_thread(void *data)
int res;
ast_debug(1, "Whee, looking up '%s@%s' for '%s'\n", st->called_number, st->called_context,
- st->eids[0] ? dundi_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
+ st->eids[0] ? ast_eid_to_str(eid_str, sizeof(eid_str), st->eids[0]) : "ourselves");
memset(&ied, 0, sizeof(ied));
memset(&dei, 0, sizeof(dei));
memset(&hmd, 0, sizeof(hmd));
- if (!dundi_eid_cmp(&st->trans->us_eid, &st->reqeid)) {
+ if (!ast_eid_cmp(&st->trans->us_eid, &st->reqeid)) {
/* Ooh, it's us! */
ast_debug(1, "Neat, someone look for us!\n");
ast_copy_string(dei.orgunit, dept, sizeof(dei.orgunit));
@@ -765,7 +721,7 @@ static int dundi_answer_entity(struct dundi_transaction *trans, struct dundi_ies
and the last EID is the root, it is permissible that the first and last EID
could be the same. In that case, we should go ahead copy only the "root" section
since we will not need it for authentication. */
- if (!dundi_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
+ if (!ast_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
skipfirst = 1;
}
totallen = sizeof(struct dundi_query_state);
@@ -784,7 +740,7 @@ static int dundi_answer_entity(struct dundi_transaction *trans, struct dundi_ies
*st->eids[x-skipfirst] = *ies->eids[x];
s += sizeof(dundi_eid);
}
- ast_debug(1, "Answering EID query for '%s@%s'!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), ies->reqeid), ies->called_context);
+ ast_debug(1, "Answering EID query for '%s@%s'!\n", ast_eid_to_str(eid_str, sizeof(eid_str), ies->reqeid), ies->called_context);
trans->thread = 1;
if (ast_pthread_create_detached(&lookupthread, NULL, dundi_query_thread, st)) {
@@ -931,7 +887,7 @@ static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies
trans->parent->dr[trans->parent->respcount].expiration = ies->expiration;
else
trans->parent->dr[trans->parent->respcount].expiration = dundi_cache_time;
- dundi_eid_to_str(trans->parent->dr[trans->parent->respcount].eid_str,
+ ast_eid_to_str(trans->parent->dr[trans->parent->respcount].eid_str,
sizeof(trans->parent->dr[trans->parent->respcount].eid_str),
&ies->answers[x]->eid);
ast_copy_string(trans->parent->dr[trans->parent->respcount].dest, (char *)ies->answers[x]->data,
@@ -971,7 +927,7 @@ static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies
and the last EID is the root, it is permissible that the first and last EID
could be the same. In that case, we should go ahead copy only the "root" section
since we will not need it for authentication. */
- if (!dundi_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
+ if (!ast_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
skipfirst = 1;
}
@@ -1055,7 +1011,7 @@ static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies
and the last EID is the root, it is permissible that the first and last EID
could be the same. In that case, we should go ahead copy only the "root" section
since we will not need it for authentication. */
- if (!dundi_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
+ if (!ast_eid_cmp(ies->eids[0], ies->eids[ies->eidcount - 1]))
skipfirst = 1;
}
@@ -1157,7 +1113,7 @@ static int cache_lookup_internal(time_t now, struct dundi_request *req, char *ke
req->dr[req->respcount].techint = tech;
req->dr[req->respcount].expiration = expiration;
dundi_str_short_to_eid(&req->dr[req->respcount].eid, src);
- dundi_eid_to_str(req->dr[req->respcount].eid_str,
+ ast_eid_to_str(req->dr[req->respcount].eid_str,
sizeof(req->dr[req->respcount].eid_str), &req->dr[req->respcount].eid);
ast_copy_string(req->dr[req->respcount].dest, ptr,
sizeof(req->dr[req->respcount].dest));
@@ -1198,7 +1154,7 @@ static int cache_lookup(struct dundi_request *req, dundi_eid *peer_eid, unsigned
time(&now);
dundi_eid_to_str_short(eid_str, sizeof(eid_str), peer_eid);
dundi_eid_to_str_short(eidroot_str, sizeof(eidroot_str), &req->root_eid);
- dundi_eid_to_str(eid_str_full, sizeof(eid_str_full), peer_eid);
+ ast_eid_to_str(eid_str_full, sizeof(eid_str_full), peer_eid);
snprintf(key, sizeof(key), "%s/%s/%s/e%08lx", eid_str, req->number, req->dcontext, crc32);
res |= cache_lookup_internal(now, req, key, eid_str_full, lowexpiration);
snprintf(key, sizeof(key), "%s/%s/%s/e%08lx", eid_str, req->number, req->dcontext, 0L);
@@ -1264,7 +1220,7 @@ static int do_register_expire(const void *data)
{
struct dundi_peer *peer = (struct dundi_peer *)data;
char eid_str[20];
- ast_debug(1, "Register expired for '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_debug(1, "Register expired for '%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
peer->registerexpire = -1;
peer->lastms = 0;
memset(&peer->addr, 0, sizeof(peer->addr));
@@ -1284,13 +1240,13 @@ static int update_key(struct dundi_peer *peer)
ekey = ast_key_get(peer->inkey, AST_KEY_PUBLIC);
if (!ekey) {
ast_log(LOG_NOTICE, "No such key '%s' for creating RSA encrypted shared key for '%s'!\n",
- peer->inkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ peer->inkey, ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
return -1;
}
skey = ast_key_get(peer->outkey, AST_KEY_PRIVATE);
if (!skey) {
ast_log(LOG_NOTICE, "No such key '%s' for signing RSA encrypted shared key for '%s'!\n",
- peer->outkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ peer->outkey, ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
return -1;
}
if ((res = ast_encrypt_bin(peer->txenckey, key, sizeof(key), ekey)) != 128) {
@@ -1455,14 +1411,14 @@ static int check_key(struct dundi_peer *peer, unsigned char *newkey, unsigned ch
key = ast_key_get(peer->outkey, AST_KEY_PRIVATE);
if (!key) {
ast_log(LOG_NOTICE, "Unable to find key '%s' to decode shared key from '%s'\n",
- peer->outkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ peer->outkey, ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
return -1;
}
skey = ast_key_get(peer->inkey, AST_KEY_PUBLIC);
if (!skey) {
ast_log(LOG_NOTICE, "Unable to find key '%s' to verify shared key from '%s'\n",
- peer->inkey, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ peer->inkey, ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
return -1;
}
@@ -1651,7 +1607,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
ast_db_put("dundi/dpeers", dundi_eid_to_str_short(eid_str, sizeof(eid_str), &peer->eid), data);
if (inaddrcmp(&peer->addr, &trans->addr)) {
ast_verb(3, "Registered DUNDi peer '%s' at '%s:%d'\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
+ ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
ast_inet_ntoa(trans->addr.sin_addr), ntohs(trans->addr.sin_port));
needqual = 1;
}
@@ -1695,7 +1651,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
trans->parent->dr[trans->parent->respcount].expiration = ies.expiration;
else
trans->parent->dr[trans->parent->respcount].expiration = dundi_cache_time;
- dundi_eid_to_str(trans->parent->dr[trans->parent->respcount].eid_str,
+ ast_eid_to_str(trans->parent->dr[trans->parent->respcount].eid_str,
sizeof(trans->parent->dr[trans->parent->respcount].eid_str),
&ies.answers[x]->eid);
ast_copy_string(trans->parent->dr[trans->parent->respcount].dest, (char *)ies.answers[x]->data,
@@ -1778,7 +1734,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
ast_copy_string(trans->parent->dei->phone, ies.q_phone, sizeof(trans->parent->dei->phone));
if (ies.q_ipaddr)
ast_copy_string(trans->parent->dei->ipaddr, ies.q_ipaddr, sizeof(trans->parent->dei->ipaddr));
- if (!dundi_eid_cmp(&trans->them_eid, &trans->parent->query_eid)) {
+ if (!ast_eid_cmp(&trans->them_eid, &trans->parent->query_eid)) {
/* If it's them, update our address */
ast_copy_string(trans->parent->dei->ipaddr, ast_inet_ntoa(trans->addr.sin_addr), sizeof(trans->parent->dei->ipaddr));
}
@@ -1818,8 +1774,8 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, &ied);
}
} else {
- ast_debug(1, "Yay, we've registered as '%s' to '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &trans->us_eid),
- dundi_eid_to_str(eid_str2, sizeof(eid_str2), &trans->them_eid));
+ ast_debug(1, "Yay, we've registered as '%s' to '%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), &trans->us_eid),
+ ast_eid_to_str(eid_str2, sizeof(eid_str2), &trans->them_eid));
/* Close connection if not final */
if (!final)
dundi_send(trans, DUNDI_COMMAND_CANCEL, 0, 1, NULL);
@@ -2353,7 +2309,7 @@ static char *complete_peer_helper(const char *line, const char *word, int pos, i
AST_LIST_LOCK(&peers);
len = strlen(word);
AST_LIST_TRAVERSE(&peers, p, list) {
- const char *s = dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid);
+ const char *s = ast_eid_to_str(eid_str, sizeof(eid_str), &p->eid);
if (!strncasecmp(word, s, len) && ++which > state) {
ret = ast_strdup(s);
break;
@@ -2492,7 +2448,7 @@ static char *dundi_do_query(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
}
if ((a->argc < 3) || (a->argc > 3))
return CLI_SHOWUSAGE;
- if (dundi_str_to_eid(&eid, a->argv[2])) {
+ if (ast_str_to_eid(&eid, a->argv[2])) {
ast_cli(a->fd, "'%s' is not a valid EID!\n", a->argv[2]);
return CLI_SHOWUSAGE;
}
@@ -2542,7 +2498,7 @@ static char *dundi_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
return CLI_SHOWUSAGE;
AST_LIST_LOCK(&peers);
AST_LIST_TRAVERSE(&peers, peer, list) {
- if (!strcasecmp(dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), a->argv[3]))
+ if (!strcasecmp(ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), a->argv[3]))
break;
}
if (peer) {
@@ -2562,7 +2518,7 @@ static char *dundi_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
default:
order = "Unknown";
}
- ast_cli(a->fd, "Peer: %s\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_cli(a->fd, "Peer: %s\n", ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
ast_cli(a->fd, "Model: %s\n", model2str(peer->model));
ast_cli(a->fd, "Host: %s\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "<Unspecified>");
ast_cli(a->fd, "Dynamic: %s\n", peer->dynamic ? "yes" : "no");
@@ -2660,7 +2616,7 @@ static char *dundi_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_a
snprintf(avgms, sizeof(avgms), "%d ms", peer->avgms);
else
strcpy(avgms, "Unavail");
- snprintf(srch, sizeof(srch), FORMAT, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
+ snprintf(srch, sizeof(srch), FORMAT, ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : "(S)", model2str(peer->model), avgms, status);
@@ -2677,7 +2633,7 @@ static char *dundi_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_a
}
if (print_line) {
- ast_cli(a->fd, FORMAT, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
+ ast_cli(a->fd, FORMAT, ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : "(S)", model2str(peer->model), avgms, status);
}
@@ -2734,7 +2690,7 @@ static char *dundi_show_entityid(struct ast_cli_entry *e, int cmd, struct ast_cl
if (a->argc != 3)
return CLI_SHOWUSAGE;
AST_LIST_LOCK(&peers);
- dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid);
+ ast_eid_to_str(eid_str, sizeof(eid_str), &global_eid);
AST_LIST_UNLOCK(&peers);
ast_cli(a->fd, "Global EID for this system is '%s'\n", eid_str);
return CLI_SUCCESS;
@@ -2762,7 +2718,7 @@ static char *dundi_show_requests(struct ast_cli_entry *e, int cmd, struct ast_cl
ast_cli(a->fd, FORMAT2, "Number", "Context", "Root", "Max", "Rsp");
AST_LIST_TRAVERSE(&requests, req, list) {
ast_cli(a->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>" : ast_eid_to_str(eidstr, sizeof(eidstr), &req->root_eid), req->maxcount, req->respcount);
}
AST_LIST_UNLOCK(&peers);
return CLI_SUCCESS;
@@ -2930,7 +2886,7 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
if (peer->qualtrans == trans) {
if (fromtimeout) {
if (peer->lastms > -1)
- ast_log(LOG_NOTICE, "Peer '%s' has become UNREACHABLE!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_log(LOG_NOTICE, "Peer '%s' has become UNREACHABLE!\n", ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
peer->lastms = -1;
} else {
ms = ast_tvdiff_ms(ast_tvnow(), peer->qualtx);
@@ -2938,9 +2894,9 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
ms = 1;
if (ms < peer->maxms) {
if ((peer->lastms >= peer->maxms) || (peer->lastms < 0))
- ast_log(LOG_NOTICE, "Peer '%s' has become REACHABLE!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_log(LOG_NOTICE, "Peer '%s' has become REACHABLE!\n", ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
} else if (peer->lastms < peer->maxms) {
- ast_log(LOG_NOTICE, "Peer '%s' has become TOO LAGGED (%d ms)\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), ms);
+ ast_log(LOG_NOTICE, "Peer '%s' has become TOO LAGGED (%d ms)\n", ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), ms);
}
peer->lastms = ms;
}
@@ -2948,7 +2904,7 @@ static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
}
if (ast_test_flag(trans, FLAG_STOREHIST)) {
if (trans->parent && !ast_strlen_zero(trans->parent->number)) {
- if (!dundi_eid_cmp(&trans->them_eid, &peer->eid)) {
+ if (!ast_eid_cmp(&trans->them_eid, &peer->eid)) {
peer->avgms = 0;
cnt = 0;
if (peer->lookups[DUNDI_TIMING_HISTORY-1])
@@ -3082,7 +3038,7 @@ static int dundi_send(struct dundi_transaction *trans, int cmdresp, int flags, i
if (!res)
res = dundi_xmit(pack);
if (res)
- ast_log(LOG_NOTICE, "Failed to send packet to '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &trans->them_eid));
+ ast_log(LOG_NOTICE, "Failed to send packet to '%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), &trans->them_eid));
if (cmdresp == DUNDI_COMMAND_ACK)
ast_free(pack);
@@ -3096,7 +3052,7 @@ static int do_autokill(const void *data)
struct dundi_transaction *trans = (struct dundi_transaction *)data;
char eid_str[20];
ast_log(LOG_NOTICE, "Transaction to '%s' took too long to ACK, destroying\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &trans->them_eid));
+ ast_eid_to_str(eid_str, sizeof(eid_str), &trans->them_eid));
trans->autokillid = -1;
destroy_trans(trans, 0); /* We could actually set it to 1 instead of 0, but we won't ;-) */
return 0;
@@ -3105,13 +3061,13 @@ static int do_autokill(const void *data)
static void dundi_ie_append_eid_appropriately(struct dundi_ie_data *ied, char *context, dundi_eid *eid, dundi_eid *us)
{
struct dundi_peer *p;
- if (!dundi_eid_cmp(eid, us)) {
+ if (!ast_eid_cmp(eid, us)) {
dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
return;
}
AST_LIST_LOCK(&peers);
AST_LIST_TRAVERSE(&peers, p, list) {
- if (!dundi_eid_cmp(&p->eid, eid)) {
+ if (!ast_eid_cmp(&p->eid, eid)) {
if (has_permission(&p->include, context))
dundi_ie_append_eid(ied, DUNDI_IE_EID_DIRECT, eid);
else
@@ -3318,16 +3274,16 @@ static int optimize_transactions(struct dundi_request *dr, int order)
AST_LIST_TRAVERSE(&peers, peer, list) {
if (has_permission(&peer->include, dr->dcontext) &&
- dundi_eid_cmp(&peer->eid, &trans->them_eid) &&
+ ast_eid_cmp(&peer->eid, &trans->them_eid) &&
(peer->order <= order)) {
/* For each other transaction, make sure we don't
ask this EID about the others if they're not
already in the list */
- if (!dundi_eid_cmp(&tmp, &peer->eid))
+ if (!ast_eid_cmp(&tmp, &peer->eid))
x = -1;
else {
for (x=0;x<trans->eidcount;x++) {
- if (!dundi_eid_cmp(&trans->eids[x], &peer->eid))
+ if (!ast_eid_cmp(&trans->eids[x], &peer->eid))
break;
}
}
@@ -3365,9 +3321,9 @@ static int append_transaction(struct dundi_request *dr, struct dundi_peer *p, in
return 0;
if (ast_strlen_zero(dr->number))
- ast_debug(1, "Will query peer '%s' for '%s' (context '%s')\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid), dundi_eid_to_str(eid_str2, sizeof(eid_str2), &dr->query_eid), dr->dcontext);
+ ast_debug(1, "Will query peer '%s' for '%s' (context '%s')\n", ast_eid_to_str(eid_str, sizeof(eid_str), &p->eid), ast_eid_to_str(eid_str2, sizeof(eid_str2), &dr->query_eid), dr->dcontext);
else
- ast_debug(1, "Will query peer '%s' for '%s@%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &p->eid), dr->number, dr->dcontext);
+ ast_debug(1, "Will query peer '%s' for '%s@%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), &p->eid), dr->number, dr->dcontext);
trans = create_transaction(p);
if (!trans)
@@ -3428,7 +3384,7 @@ static void build_transactions(struct dundi_request *dr, int ttl, int order, int
allowconnect = p->model & DUNDI_MODEL_OUTBOUND;
}
if (skip) {
- if (!dundi_eid_cmp(skip, &p->eid))
+ if (!ast_eid_cmp(skip, &p->eid))
pass = 0;
}
if (pass) {
@@ -3441,7 +3397,7 @@ static void build_transactions(struct dundi_request *dr, int ttl, int order, int
/* Make sure we haven't already seen it and that it won't
affect our answer */
for (x=0;avoid[x];x++) {
- if (!dundi_eid_cmp(avoid[x], &p->eid) || !dundi_eid_cmp(avoid[x], &p->us_eid)) {
+ if (!ast_eid_cmp(avoid[x], &p->eid) || !ast_eid_cmp(avoid[x], &p->us_eid)) {
/* If not a direct connection, it affects our answer */
if (directs && !directs[x])
ast_clear_flag_nonstd(dr->hmd, DUNDI_HINT_UNAFFECTED);
@@ -3454,7 +3410,7 @@ static void build_transactions(struct dundi_request *dr, int ttl, int order, int
/* Check for a matching or 0 cache entry */
append_transaction(dr, p, ttl, avoid);
} else {
- ast_debug(1, "Avoiding '%s' in transaction\n", dundi_eid_to_str(eid_str, sizeof(eid_str), avoid[x]));
+ ast_debug(1, "Avoiding '%s' in transaction\n", ast_eid_to_str(eid_str, sizeof(eid_str), avoid[x]));
}
}
}
@@ -3477,9 +3433,9 @@ static int register_request(struct dundi_request *dr, struct dundi_request **pen
dr->dcontext, dr->number);
if (!strcasecmp(cur->dcontext, dr->dcontext) &&
!strcasecmp(cur->number, dr->number) &&
- (!dundi_eid_cmp(&cur->root_eid, &dr->root_eid) || (cur->crc32 == dr->crc32))) {
+ (!ast_eid_cmp(&cur->root_eid, &dr->root_eid) || (cur->crc32 == dr->crc32))) {
ast_debug(1, "Found existing query for '%s@%s' for '%s' crc '%08lx'\n",
- cur->dcontext, cur->number, dundi_eid_to_str(eid_str, sizeof(eid_str), &cur->root_eid), cur->crc32);
+ cur->dcontext, cur->number, ast_eid_to_str(eid_str, sizeof(eid_str), &cur->root_eid), cur->crc32);
*pending = cur;
res = 1;
break;
@@ -3487,7 +3443,7 @@ static int register_request(struct dundi_request *dr, struct dundi_request **pen
}
if (!res) {
ast_debug(1, "Registering request for '%s@%s' on behalf of '%s' crc '%08lx'\n",
- dr->number, dr->dcontext, dundi_eid_to_str(eid_str, sizeof(eid_str), &dr->root_eid), dr->crc32);
+ dr->number, dr->dcontext, ast_eid_to_str(eid_str, sizeof(eid_str), &dr->root_eid), dr->crc32);
/* Go ahead and link us in since nobody else is searching for this */
AST_LIST_INSERT_HEAD(&requests, dr, list);
*pending = NULL;
@@ -3573,18 +3529,18 @@ static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct
res = register_request(&dr, &pending);
if (res) {
/* Already a request */
- if (rooteid && !dundi_eid_cmp(&dr.root_eid, &pending->root_eid)) {
+ if (rooteid && !ast_eid_cmp(&dr.root_eid, &pending->root_eid)) {
/* This is on behalf of someone else. Go ahead and close this out since
they'll get their answer anyway. */
ast_debug(1, "Oooh, duplicate request for '%s@%s' for '%s'\n",
- dr.number,dr.dcontext,dundi_eid_to_str(eid_str, sizeof(eid_str), &dr.root_eid));
+ dr.number,dr.dcontext,ast_eid_to_str(eid_str, sizeof(eid_str), &dr.root_eid));
close(dr.pfds[0]);
close(dr.pfds[1]);
return -2;
} else {
/* Wait for the cache to populate */
ast_debug(1, "Waiting for similar request for '%s@%s' for '%s'\n",
- dr.number,dr.dcontext,dundi_eid_to_str(eid_str, sizeof(eid_str), &pending->root_eid));
+ dr.number,dr.dcontext,ast_eid_to_str(eid_str, sizeof(eid_str), &pending->root_eid));
start = ast_tvnow();
while(check_request(pending) && (ast_tvdiff_ms(ast_tvnow(), start) < ttlms) && (!chan || !ast_check_hangup(chan))) {
/* XXX Would be nice to have a way to poll/select here XXX */
@@ -4273,7 +4229,7 @@ static int do_register(const void *data)
struct dundi_peer *peer = (struct dundi_peer *)data;
char eid_str[20];
char eid_str2[20];
- ast_debug(1, "Register us as '%s' to '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->us_eid), dundi_eid_to_str(eid_str2, sizeof(eid_str2), &peer->eid));
+ ast_debug(1, "Register us as '%s' to '%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), &peer->us_eid), ast_eid_to_str(eid_str2, sizeof(eid_str2), &peer->eid));
peer->registerid = ast_sched_add(sched, default_expiration * 1000, do_register, data);
/* Destroy old transaction if there is one */
if (peer->regtrans)
@@ -4288,7 +4244,7 @@ static int do_register(const void *data)
dundi_send(peer->regtrans, DUNDI_COMMAND_REGREQ, 0, 0, &ied);
} else
- ast_log(LOG_NOTICE, "Unable to create new transaction for registering to '%s'!\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_log(LOG_NOTICE, "Unable to create new transaction for registering to '%s'!\n", ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
return 0;
}
@@ -4330,7 +4286,7 @@ static void populate_addr(struct dundi_peer *peer, dundi_eid *eid)
char *c;
int port, expire;
char eid_str[20];
- dundi_eid_to_str(eid_str, sizeof(eid_str), eid);
+ ast_eid_to_str(eid_str, sizeof(eid_str), eid);
if (!ast_db_get("dundi/dpeers", eid_str, data, sizeof(data))) {
c = strchr(data, ':');
if (c) {
@@ -4359,7 +4315,7 @@ static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode
AST_LIST_LOCK(&peers);
AST_LIST_TRAVERSE(&peers, peer, list) {
- if (!dundi_eid_cmp(&peer->eid, eid)) {
+ if (!ast_eid_cmp(&peer->eid, eid)) {
break;
}
}
@@ -4402,7 +4358,7 @@ static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode
}
}
} else if (!strcasecmp(v->name, "ustothem")) {
- if (!dundi_str_to_eid(&testeid, v->value))
+ if (!ast_str_to_eid(&testeid, v->value))
peer->us_eid = testeid;
else
ast_log(LOG_WARNING, "'%s' is not a valid DUNDi Entity Identifier at line %d\n", v->value, v->lineno);
@@ -4435,7 +4391,7 @@ static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode
peer->maxms = DEFAULT_MAXMS;
} else if (sscanf(v->value, "%d", &peer->maxms) != 1) {
ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of dundi.conf\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), v->lineno);
+ ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), v->lineno);
peer->maxms = 0;
}
} else if (!strcasecmp(v->name, "model")) {
@@ -4469,22 +4425,22 @@ static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode
(*globalpcmode) |= peer->pcmodel;
if (!peer->model && !peer->pcmodel) {
ast_log(LOG_WARNING, "Peer '%s' lacks a model or pcmodel, discarding!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
peer->dead = 1;
} else if ((peer->model & DUNDI_MODEL_INBOUND) && (peer->pcmodel & DUNDI_MODEL_OUTBOUND)) {
ast_log(LOG_WARNING, "Peer '%s' may not be both inbound/symmetric model and outbound/symmetric precache model, discarding!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
peer->dead = 1;
} else if ((peer->model & DUNDI_MODEL_OUTBOUND) && (peer->pcmodel & DUNDI_MODEL_INBOUND)) {
ast_log(LOG_WARNING, "Peer '%s' may not be both outbound/symmetric model and inbound/symmetric precache model, discarding!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
peer->dead = 1;
} else if (!AST_LIST_EMPTY(&peer->include) && !(peer->model & DUNDI_MODEL_OUTBOUND) && !(peer->pcmodel & DUNDI_MODEL_INBOUND)) {
ast_log(LOG_WARNING, "Peer '%s' is supposed to be included in outbound searches but isn't an outbound peer or inbound precache!\n",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
} else if (!AST_LIST_EMPTY(&peer->permit) && !(peer->model & DUNDI_MODEL_INBOUND) && !(peer->pcmodel & DUNDI_MODEL_OUTBOUND)) {
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",
- dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
} else {
if (needregister) {
peer->registerid = ast_sched_add(sched, 2000, do_register, peer);
@@ -4649,7 +4605,9 @@ static int set_config(char *config_file, struct sockaddr_in* sin, int reload)
} else
ast_log(LOG_WARNING, "Unable to get host name!\n");
AST_LIST_LOCK(&peers);
- reset_global_eid();
+
+ memcpy(&global_eid, &g_eid, sizeof(global_eid));
+
global_storehistory = 0;
ast_copy_string(secretpath, "dundi", sizeof(secretpath));
v = ast_variable_browse(cfg, "general");
@@ -4689,7 +4647,7 @@ static int set_config(char *config_file, struct sockaddr_in* sin, int reload)
global_autokilltimeout = 0;
}
} else if (!strcasecmp(v->name, "entityid")) {
- if (!dundi_str_to_eid(&testeid, v->value))
+ if (!ast_str_to_eid(&testeid, v->value))
global_eid = testeid;
else
ast_log(LOG_WARNING, "Invalid global endpoint identifier '%s' at line %d\n", v->value, v->lineno);
@@ -4735,7 +4693,7 @@ static int set_config(char *config_file, struct sockaddr_in* sin, int reload)
while(cat) {
if (strcasecmp(cat, "general") && strcasecmp(cat, "mappings")) {
/* Entries */
- if (!dundi_str_to_eid(&testeid, cat))
+ if (!ast_str_to_eid(&testeid, cat))
build_peer(&testeid, ast_variable_browse(cfg, cat), &globalpcmodel);
else if (!strcasecmp(cat, "*")) {
build_peer(&empty_eid, ast_variable_browse(cfg, cat), &globalpcmodel);