2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2006, Digium, Inc.
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
19 * \brief Channel info dialplan function
21 * \author Kevin P. Fleming <kpfleming@digium.com>
27 #include <sys/types.h>
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision: $")
32 #include "asterisk/module.h"
33 #include "asterisk/channel.h"
34 #include "asterisk/pbx.h"
35 #include "asterisk/logger.h"
36 #include "asterisk/utils.h"
37 #include "asterisk/app.h"
38 #include "asterisk/indications.h"
39 #include "asterisk/stringfields.h"
40 #define locked_copy_string(chan, dest, source, len) \
42 ast_mutex_lock(&chan->lock); \
43 ast_copy_string(dest, source, len); \
44 ast_mutex_unlock(&chan->lock); \
46 #define locked_string_field_set(chan, field, source) \
48 ast_mutex_lock(&chan->lock); \
49 ast_string_field_set(chan, field, source); \
50 ast_mutex_unlock(&chan->lock); \
53 static int func_channel_read(struct ast_channel *chan, char *function,
54 char *data, char *buf, size_t len)
58 if (!strcasecmp(data, "audionativeformat"))
59 /* use the _multiple version when chan->nativeformats holds multiple formats */
60 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
61 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len);
62 else if (!strcasecmp(data, "videonativeformat"))
63 /* use the _multiple version when chan->nativeformats holds multiple formats */
64 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
65 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len);
66 else if (!strcasecmp(data, "audioreadformat"))
67 ast_copy_string(buf, ast_getformatname(chan->readformat), len);
68 else if (!strcasecmp(data, "audiowriteformat"))
69 ast_copy_string(buf, ast_getformatname(chan->writeformat), len);
70 else if (!strcasecmp(data, "tonezone") && chan->zone)
71 locked_copy_string(chan, buf, chan->zone->country, len);
72 else if (!strcasecmp(data, "language"))
73 locked_copy_string(chan, buf, chan->language, len);
74 else if (!strcasecmp(data, "musicclass"))
75 locked_copy_string(chan, buf, chan->musicclass, len);
76 else if (!chan->tech->func_channel_read
77 || chan->tech->func_channel_read(chan, function, data, buf, len)) {
78 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
85 static int func_channel_write(struct ast_channel *chan, char *function,
86 char *data, const char *value)
90 if (!strcasecmp(data, "language"))
91 locked_string_field_set(chan, language, value);
92 else if (!strcasecmp(data, "musicclass"))
93 locked_string_field_set(chan, musicclass, value);
94 else if (!chan->tech->func_channel_write
95 || chan->tech->func_channel_write(chan, function, data, value)) {
96 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
104 static struct ast_custom_function channel_function = {
106 .synopsis = "Gets/sets various pieces of information about the channel.",
107 .syntax = "CHANNEL(item)",
108 .desc = "Gets/set various pieces of information about the channel.\n"
109 "Standard items (provided by all channel technologies) are:\n"
110 "R/O audioreadformat format currently being read\n"
111 "R/O audionativeformat format used natively for audio\n"
112 "R/O audiowriteformat format currently being written\n"
113 "R/W language language for sounds played\n"
114 "R/W musicclass class (from musiconhold.conf) for hold music\n"
115 "R/O tonezone zone for indications played\n"
116 "R/O videonativeformat format used natively for video\n"
118 "Additional items may be available from the channel driver providing\n"
119 "the channel; see its documentation for details.\n"
121 "Any item requested that is not available on the current channel will\n"
122 "return an empty string.\n",
123 .read = func_channel_read,
124 .write = func_channel_write,
127 static char *tdesc = "Channel information dialplan function";
129 int unload_module(void)
131 return ast_custom_function_unregister(&channel_function);
134 int load_module(void)
136 return ast_custom_function_register(&channel_function);
139 char *description(void)
151 return ASTERISK_GPL_KEY;