Fri Aug 24 02:22:15 2007

Asterisk developer's documentation


func_enum.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  * Oleksiy Krivoshey <oleksiyk@gmail.com>
00008  * Russell Bryant <russelb@clemson.edu>
00009  *
00010  * See http://www.asterisk.org for more information about
00011  * the Asterisk project. Please do not directly contact
00012  * any of the maintainers of this project for assistance;
00013  * the project provides a web site, mailing lists and IRC
00014  * channels for your use.
00015  *
00016  * This program is free software, distributed under the terms of
00017  * the GNU General Public License Version 2. See the LICENSE file
00018  * at the top of the source tree.
00019  */
00020 
00021 /*! \file
00022  *
00023  * \brief ENUM Functions
00024  *
00025  * \author Mark Spencer <markster@digium.com>
00026  * \author Oleksiy Krivoshey <oleksiyk@gmail.com>
00027  * \author Russell Bryant <russelb@clemson.edu>
00028  *
00029  * \arg See also AstENUM
00030  *
00031  * \ingroup functions
00032  */
00033 
00034 #include "asterisk.h"
00035 
00036 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00037 
00038 #include <stdlib.h>
00039 #include <stdio.h>
00040 
00041 #include "asterisk/module.h"
00042 #include "asterisk/channel.h"
00043 #include "asterisk/pbx.h"
00044 #include "asterisk/utils.h"
00045 #include "asterisk/lock.h"
00046 #include "asterisk/file.h"
00047 #include "asterisk/logger.h"
00048 #include "asterisk/pbx.h"
00049 #include "asterisk/options.h"
00050 #include "asterisk/enum.h"
00051 #include "asterisk/app.h"
00052 
00053  static char *synopsis = "Syntax: ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])\n";
00054 
00055 static int function_enum(struct ast_channel *chan, char *cmd, char *data,
00056           char *buf, size_t len)
00057 {
00058    AST_DECLARE_APP_ARGS(args,
00059       AST_APP_ARG(number);
00060       AST_APP_ARG(tech);
00061       AST_APP_ARG(options);
00062       AST_APP_ARG(record);
00063       AST_APP_ARG(zone);
00064    );
00065    int res = 0;
00066    char tech[80];
00067    char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
00068    struct ast_module_user *u;
00069    char *s, *p;
00070    unsigned int record = 1;
00071 
00072    buf[0] = '\0';
00073 
00074    if (ast_strlen_zero(data)) {
00075       ast_log(LOG_WARNING, synopsis);
00076       return -1;
00077    }
00078 
00079    AST_STANDARD_APP_ARGS(args, data);
00080 
00081    if (args.argc < 1) {
00082       ast_log(LOG_WARNING, synopsis);
00083       return -1;
00084    }
00085 
00086    u = ast_module_user_add(chan);
00087 
00088    ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
00089 
00090    if (!args.zone)
00091       args.zone = "e164.arpa";
00092 
00093    if (!args.options)
00094       args.options = "";
00095 
00096    if (args.record)
00097       record = atoi(args.record);
00098 
00099    /* strip any '-' signs from number */
00100    for (s = p = args.number; *s; s++) {
00101       if (*s != '-') {
00102          snprintf(tmp, sizeof(tmp), "%c", *s);
00103          strncat(num, tmp, sizeof(num));
00104       }
00105 
00106    }
00107 
00108    res = ast_get_enum(chan, num, dest, sizeof(dest), tech, sizeof(tech), args.zone,
00109             args.options, record);
00110 
00111    p = strchr(dest, ':');
00112    if (p && strcasecmp(tech, "ALL"))
00113       ast_copy_string(buf, p + 1, len);
00114    else
00115       ast_copy_string(buf, dest, len);
00116 
00117    ast_module_user_remove(u);
00118 
00119    return 0;
00120 }
00121 
00122 static struct ast_custom_function enum_function = {
00123    .name = "ENUMLOOKUP",
00124    .synopsis =
00125       "ENUMLOOKUP allows for general or specific querying of NAPTR records"
00126       " or counts of NAPTR types for ENUM or ENUM-like DNS pointers",
00127    .syntax =
00128       "ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])",
00129    .desc =
00130       "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n"
00131       "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n"
00132       "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n"
00133       "For more information, see doc/enum.txt",
00134    .read = function_enum,
00135 };
00136 
00137 static int function_txtcidname(struct ast_channel *chan, char *cmd,
00138                 char *data, char *buf, size_t len)
00139 {
00140    int res;
00141    char tech[80];
00142    char txt[256] = "";
00143    char dest[80];
00144    struct ast_module_user *u;
00145 
00146    buf[0] = '\0';
00147 
00148 
00149    if (ast_strlen_zero(data)) {
00150       ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n");
00151       return -1;
00152    }
00153 
00154    u = ast_module_user_add(chan);
00155 
00156    res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
00157            sizeof(txt));
00158 
00159    if (!ast_strlen_zero(txt))
00160       ast_copy_string(buf, txt, len);
00161 
00162    ast_module_user_remove(u);
00163 
00164    return 0;
00165 }
00166 
00167 static struct ast_custom_function txtcidname_function = {
00168    .name = "TXTCIDNAME",
00169    .synopsis = "TXTCIDNAME looks up a caller name via DNS",
00170    .syntax = "TXTCIDNAME(<number>)",
00171    .desc =
00172       "This function looks up the given phone number in DNS to retrieve\n"
00173       "the caller id name.  The result will either be blank or be the value\n"
00174       "found in the TXT record in DNS.\n",
00175    .read = function_txtcidname,
00176 };
00177 
00178 static int unload_module(void)
00179 {
00180    int res = 0;
00181 
00182    res |= ast_custom_function_unregister(&enum_function);
00183    res |= ast_custom_function_unregister(&txtcidname_function);
00184 
00185    ast_module_user_hangup_all();
00186 
00187    return res;
00188 }
00189 
00190 static int load_module(void)
00191 {
00192    int res = 0;
00193 
00194    res |= ast_custom_function_register(&enum_function);
00195    res |= ast_custom_function_register(&txtcidname_function);
00196 
00197    return res;
00198 }
00199 
00200 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ENUM related dialplan functions");

Generated on Fri Aug 24 02:22:15 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1