aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-05-16 18:12:16 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-05-16 18:12:16 +0000
commit39b00dbd3960cc622ff48f9905368d23bb08afc3 (patch)
tree924686af38593fc5fc5098aafa2be51cbce3f805 /enum.c
parentc62ec7daf40ce29ee314bedbdf7beb32150211ae (diff)
Add ability to look up callerid name by txt (bug #1442)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2986 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'enum.c')
-rwxr-xr-xenum.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index a0fa98083..a4ffe3fa3 100755
--- a/enum.c
+++ b/enum.c
@@ -39,6 +39,11 @@
#define T_NAPTR 35
#endif
+#ifdef __APPLE__
+#undef T_TXT
+#define T_TXT 16
+#endif
+
#define TOPLEV "e164.arpa."
static struct enum_search {
@@ -226,9 +231,31 @@ struct enum_context {
int dstlen;
char *tech;
int techlen;
+ char *txt;
+ int txtlen;
char *naptrinput;
};
+static int txt_callback(void *context, u_char *answer, int len, u_char *fullanswer)
+{
+ struct enum_context *c = (struct enum_context *)context;
+#if 0
+ printf("ENUMTXT Called\n");
+#endif
+
+ if(answer != NULL)
+ {
+ c->txtlen = strlen(answer) - 2;
+ strncpy(c->txt, answer, 255);
+ c->txt[c->txtlen] = 0;
+ return 1;
+ } else {
+ c->txt = NULL;
+ c->txtlen = 0;
+ return 0;
+ }
+}
+
static int enum_callback(void *context, u_char *answer, int len, u_char *fullanswer)
{
struct enum_context *c = (struct enum_context *)context;
@@ -301,6 +328,65 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
return ret;
}
+int ast_get_txt(struct ast_channel *chan, const char *number, char *dst, int dstlen, char *tech, int techlen, char *txt, int txtlen)
+{
+ struct enum_context context;
+ char tmp[259 + 80];
+ char naptrinput[80] = "+";
+ int pos = strlen(number) - 1;
+ int newpos = 0;
+ int ret = -1;
+ struct enum_search *s = NULL;
+ int version = -1;
+
+ strncat(naptrinput, number, sizeof(naptrinput) - 2);
+
+ context.naptrinput = naptrinput;
+ context.dst = dst;
+ context.dstlen = dstlen;
+ context.tech = tech;
+ context.techlen = techlen;
+ context.txt = txt;
+ context.txtlen = txtlen;
+
+ if (pos > 128)
+ pos = 128;
+ while(pos >= 0) {
+ tmp[newpos++] = number[pos--];
+ tmp[newpos++] = '.';
+ }
+
+ if (chan && ast_autoservice_start(chan) < 0)
+ return -1;
+
+ for(;;) {
+ ast_mutex_lock(&enumlock);
+ if (version != enumver) {
+ /* Ooh, a reload... */
+ s = toplevs;
+ version = enumver;
+ } else {
+ s = s->next;
+ }
+ if (s) {
+ strcpy(tmp + newpos, s->toplev);
+ }
+ ast_mutex_unlock(&enumlock);
+ if (!s)
+ break;
+ ret = ast_search_dns(&context, tmp, C_IN, T_TXT, txt_callback);
+ if (ret > 0)
+ break;
+ }
+ if (ret < 0) {
+ ast_log(LOG_DEBUG, "No such number found: %s (%s)\n", tmp, strerror(errno));
+ ret = 0;
+ }
+ if (chan)
+ ret |= ast_autoservice_stop(chan);
+ return ret;
+}
+
static struct enum_search *enum_newtoplev(char *s)
{
struct enum_search *tmp;