Fri Jul 24 00:40:56 2009

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

Generated on Fri Jul 24 00:40:56 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7