/* * CallWeaver -- An open source telephony toolkit. * * Copyright (C) 1999 - 2005, Digium, Inc. * Copyright (C) 2003, Jefferson Noxon * * Mark Spencer * Jefferson Noxon * * See http://www.callweaver.org for more information about * the CallWeaver project. Please do not directly contact * any of the maintainers of this project for assistance; * the project provides a web site, mailing lists and IRC * channels for your use. * * This program is free software, distributed under the terms of * the GNU General Public License Version 2. See the LICENSE file * at the top of the source tree. * * This application written by Massimo Cetra */ /*! \file * * \brief Get extension state int * */ #ifdef HAVE_CONFIG_H #include "confdefs.h" #endif #include #include #include #include #include #include "callweaver.h" CALLWEAVER_FILE_VERSION("$HeadURL$", "$Revision$") #include "callweaver/options.h" #include "callweaver/file.h" #include "callweaver/logger.h" #include "callweaver/channel.h" #include "callweaver/pbx.h" #include "callweaver/module.h" #include "callweaver/callweaver_db.h" #include "callweaver/lock.h" #include "callweaver/devicestate.h" #include "callweaver/cli.h" //Needed to have RESULT_SUCCESS and RESULT_FAILURE static char *tdesc = "Get state for given extension in a context (show hints)"; static void *g_app; static char *g_name = "GetExtState"; static char *g_synopsis = "Get state for given extension in a context (show hints)"; static char *g_syntax = "GetExtState(extensions1[&extension2], context)"; static char *g_descrip = "Report the extension state for given extension in a context and saves it in EXTSTATE variable. \n" "Valid EXTSTATE values are:\n" "0 = idle, 1 = inuse; 2 = busy, \n" "4 = unavail, 8 = ringing; -1 unknown; \n" "Example: GetExtState(715&523, default)\n"; STANDARD_LOCAL_USER; LOCAL_USER_DECL; static int get_extstate(struct cw_channel *chan, int argc, char **argv) { struct localuser *u; int res=-1; char resc[8]="-1"; char hint[CW_MAX_EXTENSION] = ""; char hints[1024] = ""; char *cur, *rest; int allunavailable = 1, allbusy = 1, allfree = 1; int busy = 0, inuse = 0, ring = 0; if (argc != 2 || !argv[0][0] || !argv[1][0]) { cw_log(LOG_ERROR, "Syntax: %s\n", g_syntax); return -1; } LOCAL_USER_ADD(u); cur = argv[0]; do { rest = strchr(cur, '&'); if (rest) { *rest = 0; rest++; } cw_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, argv[1], cur); //cw_log(LOG_DEBUG,"HINT: %s Context: %s Exten: %s\n",hint,argv[1],cur); if (!cw_strlen_zero(hint)) { //let's concat hints! if ( strlen(hint)+strlen(hints)+2