2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2007, Digium, Inc.
6 * Modified from func_devstate.c by Russell Bryant <russell@digium.com>
7 * Adam Gundy <adam@starsilk.net>
9 * See http://www.asterisk.org for more information about
10 * the Asterisk project. Please do not directly contact
11 * any of the maintainers of this project for assistance;
12 * the project provides a web site, mailing lists and IRC
13 * channels for your use.
15 * This program is free software, distributed under the terms of
16 * the GNU General Public License Version 2. See the LICENSE file
17 * at the top of the source tree.
22 * \brief Get the state of a hinted extension for dialplan control
24 * \author Adam Gundy <adam@starsilk.net>
31 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
33 #include "asterisk/module.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/pbx.h"
36 #include "asterisk/utils.h"
37 #include "asterisk/devicestate.h"
39 static const char *ast_extstate_str(int state
)
41 const char *res
= "UNKNOWN";
44 case AST_EXTENSION_NOT_INUSE
:
47 case AST_EXTENSION_INUSE
:
50 case AST_EXTENSION_BUSY
:
53 case AST_EXTENSION_UNAVAILABLE
:
56 case AST_EXTENSION_RINGING
:
59 case AST_EXTENSION_INUSE
| AST_EXTENSION_RINGING
:
62 case AST_EXTENSION_INUSE
| AST_EXTENSION_ONHOLD
:
65 case AST_EXTENSION_ONHOLD
:
73 static int extstate_read(struct ast_channel
*chan
, const char *cmd
, char *data
,
74 char *buf
, size_t len
)
76 char *exten
, *context
;
78 if (ast_strlen_zero(data
)) {
79 ast_log(LOG_WARNING
, "EXTENSION_STATE requires an extension\n");
83 context
= exten
= data
;
84 strsep(&context
, "@");
85 if (ast_strlen_zero(context
))
88 if (ast_strlen_zero(exten
)) {
89 ast_log(LOG_WARNING
, "EXTENSION_STATE requires an extension\n");
94 ast_extstate_str(ast_extension_state(chan
, context
, exten
)), len
);
99 static struct ast_custom_function extstate_function
= {
100 .name
= "EXTENSION_STATE",
101 .synopsis
= "Get an extension's state",
102 .syntax
= "EXTENSION_STATE(extension[@context])",
104 " The EXTENSION_STATE function can be used to retrieve the state from any\n"
105 "hinted extension. For example:\n"
106 " NoOp(1234@default has state ${EXTENSION_STATE(1234)})\n"
107 " NoOp(4567@home has state ${EXTENSION_STATE(4567@home)})\n"
109 " The possible values returned by this function are:\n"
110 "UNKNOWN | NOT_INUSE | INUSE | BUSY | INVALID | UNAVAILABLE | RINGING\n"
111 "RINGINUSE | HOLDINUSE | ONHOLD\n",
112 .read
= extstate_read
,
115 static int unload_module(void)
119 res
= ast_custom_function_unregister(&extstate_function
);
124 static int load_module(void)
128 res
= ast_custom_function_register(&extstate_function
);
130 return res
? AST_MODULE_LOAD_DECLINE
: AST_MODULE_LOAD_SUCCESS
;
133 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Gets an extension's state in the dialplan");