Mon Mar 20 08:25:37 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

app_txtcidname.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Caller*id name lookup - Look up the caller's name via DNS
00022  * 
00023  * \ingroup applications
00024  */
00025 
00026 #include <stdlib.h>
00027 #include <unistd.h>
00028 #include <string.h>
00029 #include <stdlib.h>
00030 #include <ctype.h>
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00035 
00036 #include "asterisk/logger.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/options.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/enum.h"
00042 #include "asterisk/utils.h"
00043 #include "asterisk/app.h"
00044 
00045 STANDARD_LOCAL_USER;
00046 
00047 LOCAL_USER_DECL;
00048 
00049 static char *tdesc = "TXTCIDName";
00050 
00051 static char *app = "TXTCIDName";
00052 
00053 static char *synopsis = "Lookup caller name from TXT record";
00054 
00055 static char *descrip = 
00056 "  TXTCIDName(<CallerIDNumber>[|options]):  Looks up a Caller Name via DNS and sets\n"
00057 "the variable 'TXTCIDNAME'. TXTCIDName will either be blank\n"
00058 "or return the value found in the TXT record in DNS.\n" 
00059 "The option string may contain the following character:\n"
00060 "'j' -- jump to n+101 priority if the lookup fails\n"
00061 "This application sets the following channel variable upon completion:\n"
00062 "  TXTCIDNAMESTATUS The status of the lookup as a text string, one of\n"
00063 "      SUCCESS | FAILED\n";
00064 
00065 static int txtcidname_exec(struct ast_channel *chan, void *data)
00066 {
00067    int res=0;
00068    char tech[80];
00069    char txt[256] = "";
00070    char dest[80];
00071    struct localuser *u;
00072    static int dep_warning = 0;
00073    char *parse = NULL;
00074    int priority_jump = 0;
00075    AST_DECLARE_APP_ARGS(args,
00076       AST_APP_ARG(cidnum);
00077       AST_APP_ARG(options);
00078    );
00079 
00080    LOCAL_USER_ADD(u);
00081    
00082    if (!dep_warning) {
00083       ast_log(LOG_WARNING, "The TXTCIDName application has been deprecated in favor of the TXTCIDNAME dialplan function.\n");
00084       dep_warning = 1;
00085    }
00086    
00087    if (ast_strlen_zero(data)) {
00088       ast_log(LOG_WARNING, "TXTCIDName requires an argument (extension[|options])\n");
00089       LOCAL_USER_REMOVE(u);
00090       return(0);
00091    }
00092 
00093    parse = ast_strdupa(data);
00094    if (!parse) {
00095       ast_log(LOG_ERROR, "Out of memory!\n");
00096       LOCAL_USER_REMOVE(u);
00097       return -1;
00098    }
00099 
00100    AST_STANDARD_APP_ARGS(args,parse);
00101 
00102    if (args.options) {
00103       if (strchr(args.options, 'j'))
00104          priority_jump = 1;
00105    }
00106    
00107    if (!res) {
00108       res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt));
00109    }
00110    
00111    /* Parse it out */
00112    if (res > 0) {
00113       if (!ast_strlen_zero(txt)) {
00114          pbx_builtin_setvar_helper(chan, "TXTCIDNAME", txt);
00115          pbx_builtin_setvar_helper(chan, "TXTCIDNAMESTATUS", "SUCCESS");
00116          if (option_debug > 1)
00117             ast_log(LOG_DEBUG, "TXTCIDNAME got '%s'\n", txt);
00118       }
00119    }
00120    if (!res) {
00121       /* Look for a "busy" place */
00122       if (priority_jump || option_priority_jumping)
00123          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00124       pbx_builtin_setvar_helper(chan, "TXTCIDNAMESTATUS", "FAILED");
00125    } else if (res > 0)
00126       res = 0;
00127 
00128    LOCAL_USER_REMOVE(u);
00129 
00130    return res;
00131 }
00132 
00133 int unload_module(void)
00134 {
00135    int res;
00136 
00137    res = ast_unregister_application(app);
00138    
00139    STANDARD_HANGUP_LOCALUSERS;
00140 
00141    return res; 
00142 }
00143 
00144 int load_module(void)
00145 {
00146    return ast_register_application(app, txtcidname_exec, synopsis, descrip);
00147 }
00148 
00149 char *description(void)
00150 {
00151    return tdesc;
00152 }
00153 
00154 int usecount(void)
00155 {
00156    int res;
00157    STANDARD_USECOUNT(res);
00158    return res;
00159 }
00160 
00161 char *key()
00162 {
00163    return ASTERISK_GPL_KEY;
00164 }

Generated on Mon Mar 20 08:25:37 2006 for Asterisk - the Open Source PBX by  doxygen 1.3.9.1