Wed Apr 6 11:29:45 2011

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 #include "asterisk.h"
00028 
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 276347 $")
00030 
00031 #include "asterisk/module.h"
00032 #include "asterisk/channel.h"
00033 #include "asterisk/pbx.h"
00034 #include "asterisk/app.h"
00035 
00036 /*** DOCUMENTATION
00037    <function name="DIALPLAN_EXISTS" language="en_US">
00038       <synopsis>
00039          Checks the existence of a dialplan target.
00040       </synopsis>
00041       <syntax>
00042          <parameter name="context" required="true" />
00043          <parameter name="extension" />
00044          <parameter name="priority" />
00045       </syntax>
00046       <description>
00047          <para>This function returns <literal>1</literal> if the target exits. Otherwise, it returns <literal>0</literal>.</para>
00048       </description>
00049    </function>
00050 
00051  ***/
00052 
00053 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data, 
00054    char *buf, size_t len) 
00055 {
00056    char *parse;
00057    AST_DECLARE_APP_ARGS(args,
00058       AST_APP_ARG(context);
00059       AST_APP_ARG(exten);
00060       AST_APP_ARG(priority);
00061    );
00062 
00063    strcpy(buf, "0");
00064 
00065    if (ast_strlen_zero(data)) {
00066       ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
00067       return -1;
00068    }
00069 
00070    parse = ast_strdupa(data);
00071    AST_STANDARD_APP_ARGS(args, parse);
00072 
00073    if (!ast_strlen_zero(args.priority)) {
00074       int priority_num;
00075       if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
00076          int res;
00077          res = ast_exists_extension(chan, args.context, args.exten, priority_num, 
00078             S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00079          if (res)
00080             strcpy(buf, "1");
00081       } else {
00082          int res;
00083          res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
00084             S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00085          if (res > 0)
00086             strcpy(buf, "1");
00087       }
00088    } else if (!ast_strlen_zero(args.exten)) {
00089       int res;
00090       res = ast_exists_extension(chan, args.context, args.exten, 1, 
00091          S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00092       if (res)
00093          strcpy(buf, "1");
00094    } else if (!ast_strlen_zero(args.context)) {
00095       if (ast_context_find(args.context))
00096          strcpy(buf, "1");
00097    } else {
00098       ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
00099       return -1;
00100    }
00101    
00102    return 0;
00103 }
00104 
00105 static struct ast_custom_function isexten_function = {
00106    .name = "DIALPLAN_EXISTS",
00107    .read = isexten_function_read,
00108    .read_max = 2,
00109 };
00110 
00111 static int unload_module(void)
00112 {
00113    return ast_custom_function_unregister(&isexten_function);
00114 }
00115 
00116 static int load_module(void)
00117 {
00118    return ast_custom_function_register(&isexten_function);
00119 }
00120 
00121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dialplan Context/Extension/Priority Checking Functions");

Generated on Wed Apr 6 11:29:45 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7