Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
func_extstate.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2007, Digium, Inc.
5 *
6 * Modified from func_devstate.c by Russell Bryant <russell@digium.com>
7 * Adam Gundy <adam@starsilk.net>
8
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.
14 *
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.
18 */
19
20/*! \file
21 *
22 * \brief Get the state of a hinted extension for dialplan control
23 *
24 * \author Adam Gundy <adam@starsilk.net>
25 *
26 * \ingroup functions
27 */
28
29/*** MODULEINFO
30 <support_level>core</support_level>
31 ***/
32
33#include "asterisk.h"
34
35#include "asterisk/module.h"
36#include "asterisk/channel.h"
37#include "asterisk/pbx.h"
38#include "asterisk/utils.h"
40
41/*** DOCUMENTATION
42 <function name="EXTENSION_STATE" language="en_US">
43 <since>
44 <version>1.6.0</version>
45 </since>
46 <synopsis>
47 Get an extension's state.
48 </synopsis>
49 <syntax argsep="@">
50 <parameter name="extension" required="true" />
51 <parameter name="context">
52 <para>If it is not specified defaults to <literal>default</literal>.</para>
53 </parameter>
54 </syntax>
55 <description>
56 <para>The EXTENSION_STATE function can be used to retrieve the state from any
57 hinted extension. For example:</para>
58 <para>NoOp(1234@default has state ${EXTENSION_STATE(1234)})</para>
59 <para>NoOp(4567@home has state ${EXTENSION_STATE(4567@home)})</para>
60 <para>The possible values returned by this function are:</para>
61 <para>UNKNOWN | NOT_INUSE | INUSE | BUSY | INVALID | UNAVAILABLE | RINGING |
62 RINGINUSE | HOLDINUSE | ONHOLD</para>
63 </description>
64 </function>
65 ***/
66
67static const char *ast_extstate_str(int state)
68{
69 const char *res = "UNKNOWN";
70
71 switch (state) {
73 res = "NOT_INUSE";
74 break;
76 res = "INUSE";
77 break;
79 res = "BUSY";
80 break;
82 res = "UNAVAILABLE";
83 break;
85 res = "RINGING";
86 break;
88 res = "RINGINUSE";
89 break;
91 res = "HOLDINUSE";
92 break;
94 res = "ONHOLD";
95 break;
96 }
97
98 return res;
99}
100
101static int extstate_read(struct ast_channel *chan, const char *cmd, char *data,
102 char *buf, size_t len)
103{
104 char *exten, *context;
105
106 if (ast_strlen_zero(data)) {
107 ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
108 return -1;
109 }
110
111 context = exten = data;
112 strsep(&context, "@");
114 context = "default";
115
116 if (ast_strlen_zero(exten)) {
117 ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
118 return -1;
119 }
120
123
124 return 0;
125}
126
128 .name = "EXTENSION_STATE",
129 .read = extstate_read,
130 .read_max = 12,
131};
132
133static int unload_module(void)
134{
135 int res;
136
138
139 return res;
140}
141
142static int load_module(void)
143{
144 int res;
145
147
149}
150
151AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Gets an extension's state in the dialplan");
char * strsep(char **str, const char *delims)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
Device state management.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int extstate_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int load_module(void)
static int unload_module(void)
static const char * ast_extstate_str(int state)
Definition: func_extstate.c:67
static struct ast_custom_function extstate_function
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_WARNING
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
Core PBX routines and definitions.
@ AST_EXTENSION_RINGING
Definition: pbx.h:68
@ AST_EXTENSION_NOT_INUSE
Definition: pbx.h:64
@ AST_EXTENSION_INUSE
Definition: pbx.h:65
@ AST_EXTENSION_UNAVAILABLE
Definition: pbx.h:67
@ AST_EXTENSION_ONHOLD
Definition: pbx.h:69
@ AST_EXTENSION_BUSY
Definition: pbx.h:66
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_extension_state(struct ast_channel *c, const char *context, const char *exten)
Uses hint and devicestate callback to get the state of an extension.
Definition: pbx.c:3185
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
Utility functions.