Wed May 16 06:33:33 2012

Asterisk developer's documentation


func_dialplan.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2007, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief Dialplan group functions check if a dialplan entry exists
00020  *
00021  * \author Gregory Nietsky AKA irroot <gregory@networksentry.co.za>
00022  * \author Russell Bryant <russell@digium.com>
00023  * 
00024  * \ingroup functions
00025  */
00026 
00027 /*** MODULEINFO
00028    <support_level>core</support_level>
00029  ***/
00030 
00031 #include "asterisk.h"
00032 
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 358812 $")
00034 
00035 #include "asterisk/module.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/app.h"
00039 
00040 /*** DOCUMENTATION
00041    <function name="DIALPLAN_EXISTS" language="en_US">
00042       <synopsis>
00043          Checks the existence of a dialplan target.
00044       </synopsis>
00045       <syntax>
00046          <parameter name="context" required="true" />
00047          <parameter name="extension" />
00048          <parameter name="priority" />
00049       </syntax>
00050       <description>
00051          <para>This function returns <literal>1</literal> if the target exits. Otherwise, it returns <literal>0</literal>.</para>
00052       </description>
00053    </function>
00054    <function name="VALID_EXTEN" language="en_US">
00055       <synopsis>
00056          Determine whether an extension exists or not.
00057       </synopsis>
00058       <syntax>
00059          <parameter name="context">
00060             <para>Defaults to the current context</para>
00061          </parameter>
00062          <parameter name="extension" required="true" />
00063          <parameter name="priority">
00064             <para>Priority defaults to <literal>1</literal>.</para>
00065          </parameter>
00066       </syntax>
00067       <description>
00068          <para>Returns a true value if the indicated <replaceable>context</replaceable>,
00069          <replaceable>extension</replaceable>, and <replaceable>priority</replaceable> exist.</para>
00070          <warning><para>This function has been deprecated in favor of the <literal>DIALPLAN_EXISTS()</literal> function</para></warning>
00071       </description>
00072    </function>
00073  ***/
00074 
00075 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
00076    char *buf, size_t len)
00077 {
00078    char *parse;
00079    AST_DECLARE_APP_ARGS(args,
00080       AST_APP_ARG(context);
00081       AST_APP_ARG(exten);
00082       AST_APP_ARG(priority);
00083    );
00084 
00085    strcpy(buf, "0");
00086 
00087    if (ast_strlen_zero(data)) {
00088       ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
00089       return -1;
00090    }
00091 
00092    parse = ast_strdupa(data);
00093    AST_STANDARD_APP_ARGS(args, parse);
00094 
00095    if (!ast_strlen_zero(args.priority)) {
00096       int priority_num;
00097       if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
00098          int res;
00099          res = ast_exists_extension(chan, args.context, args.exten, priority_num, 
00100             S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00101          if (res)
00102             strcpy(buf, "1");
00103       } else {
00104          int res;
00105          res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
00106             S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00107          if (res > 0)
00108             strcpy(buf, "1");
00109       }
00110    } else if (!ast_strlen_zero(args.exten)) {
00111       int res;
00112       res = ast_exists_extension(chan, args.context, args.exten, 1, 
00113          S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00114       if (res)
00115          strcpy(buf, "1");
00116    } else if (!ast_strlen_zero(args.context)) {
00117       if (ast_context_find(args.context))
00118          strcpy(buf, "1");
00119    } else {
00120       ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
00121       return -1;
00122    }
00123 
00124    return 0;
00125 }
00126 
00127 static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
00128 {
00129    int priority_int;
00130    AST_DECLARE_APP_ARGS(args,
00131       AST_APP_ARG(context);
00132       AST_APP_ARG(extension);
00133       AST_APP_ARG(priority);
00134    );
00135 
00136    AST_STANDARD_APP_ARGS(args, parse);
00137 
00138    if (ast_strlen_zero(args.context)) {
00139       args.context = ast_strdupa(ast_channel_context(chan));
00140    }
00141 
00142    if (ast_strlen_zero(args.extension)) {
00143       ast_log(LOG_WARNING, "Syntax: VALID_EXTEN([<context>],<extension>[,<priority>]) - missing argument <extension>!\n");
00144       return -1;
00145    }
00146 
00147    if (ast_strlen_zero(args.priority)) {
00148       priority_int = 1;
00149    } else {
00150       priority_int = atoi(args.priority);
00151    }
00152 
00153    if (ast_exists_extension(chan, args.context, args.extension, priority_int,
00154       S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
00155        ast_copy_string(buffer, "1", buflen);
00156    } else {
00157        ast_copy_string(buffer, "0", buflen);
00158    }
00159 
00160    return 0;
00161 }
00162 
00163 static struct ast_custom_function isexten_function = {
00164    .name = "DIALPLAN_EXISTS",
00165    .read = isexten_function_read,
00166    .read_max = 2,
00167 };
00168 
00169 static struct ast_custom_function acf_isexten = {
00170    .name = "VALID_EXTEN",
00171    .read = acf_isexten_exec,
00172 };
00173 
00174 static int unload_module(void)
00175 {
00176    int res = ast_custom_function_unregister(&isexten_function);
00177    res |= ast_custom_function_unregister(&acf_isexten);
00178    return res;
00179 }
00180 
00181 static int load_module(void)
00182 {
00183    int res = ast_custom_function_register(&isexten_function);
00184    res |= ast_custom_function_register(&acf_isexten);
00185    return res;
00186 }
00187 
00188 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
00189    .load = load_module,
00190    .unload = unload_module,
00191    .load_pri = AST_MODPRI_APP_DEPEND,
00192    );

Generated on Wed May 16 06:33:34 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6