Mon Aug 31 12:30:08 2015

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: 411313 $")
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 
00055  ***/
00056 
00057 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data, 
00058    char *buf, size_t len) 
00059 {
00060    char *parse;
00061    AST_DECLARE_APP_ARGS(args,
00062       AST_APP_ARG(context);
00063       AST_APP_ARG(exten);
00064       AST_APP_ARG(priority);
00065    );
00066 
00067    strcpy(buf, "0");
00068 
00069    if (ast_strlen_zero(data)) {
00070       ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
00071       return -1;
00072    }
00073 
00074    parse = ast_strdupa(data);
00075    AST_STANDARD_APP_ARGS(args, parse);
00076 
00077    if (!ast_strlen_zero(args.priority)) {
00078       int priority_num;
00079       if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
00080          int res;
00081          res = ast_exists_extension(chan, args.context, args.exten, priority_num,
00082             !chan ? NULL :
00083             S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00084          if (res)
00085             strcpy(buf, "1");
00086       } else {
00087          int res;
00088          res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
00089             !chan ? NULL :
00090             S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00091          if (res > 0)
00092             strcpy(buf, "1");
00093       }
00094    } else if (!ast_strlen_zero(args.exten)) {
00095       int res;
00096       res = ast_exists_extension(chan, args.context, args.exten, 1,
00097          !chan ? NULL :
00098          S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00099       if (res)
00100          strcpy(buf, "1");
00101    } else if (!ast_strlen_zero(args.context)) {
00102       if (ast_context_find(args.context))
00103          strcpy(buf, "1");
00104    } else {
00105       ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
00106       return -1;
00107    }
00108    
00109    return 0;
00110 }
00111 
00112 static struct ast_custom_function isexten_function = {
00113    .name = "DIALPLAN_EXISTS",
00114    .read = isexten_function_read,
00115    .read_max = 2,
00116 };
00117 
00118 static int unload_module(void)
00119 {
00120    return ast_custom_function_unregister(&isexten_function);
00121 }
00122 
00123 static int load_module(void)
00124 {
00125    return ast_custom_function_register(&isexten_function);
00126 }
00127 
00128 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
00129    .load = load_module,
00130    .unload = unload_module,
00131    .load_pri = AST_MODPRI_APP_DEPEND,
00132    );

Generated on 31 Aug 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1