2004-05-16 18:12:16 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
2004-05-17 02:05:27 +00:00
|
|
|
* Caller*id name lookup - Look up the caller's name via DNS
|
2004-05-16 18:12:16 +00:00
|
|
|
*
|
2005-01-21 07:06:25 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
2004-05-16 18:12:16 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@linux-support.net>
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/options.h"
|
|
|
|
#include "asterisk/config.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/enum.h"
|
|
|
|
#include "asterisk/utils.h"
|
2004-05-16 18:12:16 +00:00
|
|
|
|
|
|
|
static char *tdesc = "TXTCIDName";
|
|
|
|
|
|
|
|
static char *app = "TXTCIDName";
|
|
|
|
|
|
|
|
static char *synopsis = "Lookup caller name from TXT record";
|
|
|
|
|
|
|
|
static char *descrip =
|
2005-06-23 22:00:10 +00:00
|
|
|
" TXTCIDName(<CallerIDNumber>): Looks up a Caller Name via DNS and sets\n"
|
2004-05-16 18:12:16 +00:00
|
|
|
"the variable 'TXTCIDNAME'. TXTCIDName will either be blank\n"
|
|
|
|
"or return the value found in the TXT record in DNS.\n" ;
|
|
|
|
|
|
|
|
#define ENUM_CONFIG "enum.conf"
|
|
|
|
|
2004-07-14 07:34:34 +00:00
|
|
|
static char h323driver[80] = "";
|
2004-05-16 18:12:16 +00:00
|
|
|
#define H323DRIVERDEFAULT "H323"
|
|
|
|
|
|
|
|
STANDARD_LOCAL_USER;
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int txtcidname_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res=0;
|
|
|
|
char tech[80];
|
2004-05-16 20:42:58 +00:00
|
|
|
char txt[256] = "";
|
2004-05-16 18:12:16 +00:00
|
|
|
char dest[80];
|
|
|
|
|
|
|
|
struct localuser *u;
|
|
|
|
if (!data || !strlen(data)) {
|
|
|
|
ast_log(LOG_WARNING, "TXTCIDName requires an argument (extension)\n");
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
if (!res) {
|
|
|
|
res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt));
|
|
|
|
}
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
/* Parse it out */
|
|
|
|
if (res > 0) {
|
2004-07-02 19:24:16 +00:00
|
|
|
if (!ast_strlen_zero(txt)) {
|
2004-05-16 18:12:16 +00:00
|
|
|
pbx_builtin_setvar_helper(chan, "TXTCIDNAME", txt);
|
2005-09-07 19:13:00 +00:00
|
|
|
if (option_debug > 1)
|
|
|
|
ast_log(LOG_DEBUG, "TXTCIDNAME got '%s'\n", txt);
|
2004-05-16 18:12:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!res) {
|
|
|
|
/* Look for a "busy" place */
|
2005-09-07 19:13:00 +00:00
|
|
|
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
|
2004-05-16 18:12:16 +00:00
|
|
|
} else if (res > 0)
|
|
|
|
res = 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_config(void)
|
|
|
|
{
|
|
|
|
struct ast_config *cfg;
|
|
|
|
char *s;
|
|
|
|
|
2005-01-25 06:10:20 +00:00
|
|
|
cfg = ast_config_load(ENUM_CONFIG);
|
2004-05-16 18:12:16 +00:00
|
|
|
if (cfg) {
|
|
|
|
if (!(s=ast_variable_retrieve(cfg, "general", "h323driver"))) {
|
2005-07-10 23:12:25 +00:00
|
|
|
ast_copy_string(h323driver, H323DRIVERDEFAULT, sizeof(h323driver));
|
2004-05-16 18:12:16 +00:00
|
|
|
} else {
|
2005-07-10 23:12:25 +00:00
|
|
|
ast_copy_string(h323driver, s, sizeof(h323driver));
|
2004-05-16 18:12:16 +00:00
|
|
|
}
|
2005-01-25 06:10:20 +00:00
|
|
|
ast_config_destroy(cfg);
|
2004-05-16 18:12:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ast_log(LOG_NOTICE, "No ENUM Config file, using defaults\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
|
|
|
return ast_unregister_application(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
res = ast_register_application(app, txtcidname_exec, synopsis, descrip);
|
|
|
|
if (res)
|
|
|
|
return(res);
|
|
|
|
if ((res=load_config())) {
|
|
|
|
return(res);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int reload(void)
|
|
|
|
{
|
|
|
|
return(load_config());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|
|
|
|
|