Remove places that say if no language is specified it will default to english......
[asterisk/asterisk.git] / funcs / func_channel.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2006, Digium, Inc.
5  *
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.
11  *
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.
15  */
16
17 /*! \file
18  *
19  * \brief Channel info dialplan function
20  *
21  * \author Kevin P. Fleming <kpfleming@digium.com>
22  * 
23  * \ingroup functions
24  */
25
26 #include "asterisk.h"
27
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <sys/types.h>
34
35 #include "asterisk/module.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/utils.h"
40 #include "asterisk/app.h"
41 #include "asterisk/indications.h"
42 #include "asterisk/stringfields.h"
43
44 #define locked_copy_string(chan, dest, source, len) \
45         do { \
46                 ast_channel_lock(chan); \
47                 ast_copy_string(dest, source, len); \
48                 ast_channel_unlock(chan); \
49         } while (0)
50 #define locked_string_field_set(chan, field, source) \
51         do { \
52                 ast_channel_lock(chan); \
53                 ast_string_field_set(chan, field, source); \
54                 ast_channel_unlock(chan); \
55         } while (0)
56
57 char *transfercapability_table[0x20] = {
58         "SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
59         "DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
60         "3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
61         "VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", };
62
63 static int func_channel_read(struct ast_channel *chan, const char *function,
64                              char *data, char *buf, size_t len)
65 {
66         int ret = 0;
67
68         if (!strcasecmp(data, "audionativeformat"))
69                 /* use the _multiple version when chan->nativeformats holds multiple formats */
70                 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
71                 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len);
72         else if (!strcasecmp(data, "videonativeformat"))
73                 /* use the _multiple version when chan->nativeformats holds multiple formats */
74                 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
75                 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len);
76         else if (!strcasecmp(data, "audioreadformat"))
77                 ast_copy_string(buf, ast_getformatname(chan->readformat), len);
78         else if (!strcasecmp(data, "audiowriteformat"))
79                 ast_copy_string(buf, ast_getformatname(chan->writeformat), len);
80         else if (!strcasecmp(data, "tonezone") && chan->zone)
81                 locked_copy_string(chan, buf, chan->zone->country, len);
82         else if (!strcasecmp(data, "language"))
83                 locked_copy_string(chan, buf, chan->language, len);
84         else if (!strcasecmp(data, "musicclass"))
85                 locked_copy_string(chan, buf, chan->musicclass, len);
86         else if (!strcasecmp(data, "state"))
87                 locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
88         else if (!strcasecmp(data, "channeltype"))
89                 locked_copy_string(chan, buf, chan->tech->type, len);
90         else if (!strcasecmp(data, "transfercapability"))
91                 locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
92         else if (!strcasecmp(data, "callgroup")) {
93                 char groupbuf[256];
94                 locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len);
95         } else if (!chan->tech->func_channel_read
96                  || chan->tech->func_channel_read(chan, function, data, buf, len)) {
97                 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
98                 ret = -1;
99         }
100
101         return ret;
102 }
103
104 static int func_channel_write(struct ast_channel *chan, const char *function,
105                               char *data, const char *value)
106 {
107         int ret = 0;
108         signed char gainset;
109
110         if (!strcasecmp(data, "language"))
111                 locked_string_field_set(chan, language, value);
112         else if (!strcasecmp(data, "musicclass"))
113                 locked_string_field_set(chan, musicclass, value);
114         else if (!strcasecmp(data, "tonezone")) {
115                 struct ind_tone_zone *new_zone;
116                 if (!(new_zone = ast_get_indication_zone(value))) {
117                         ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
118                         ret = -1;       
119                 } else 
120                         chan->zone = new_zone;
121         } else if (!strcasecmp(data, "callgroup"))
122                 chan->callgroup = ast_get_group(value);
123         else if (!strcasecmp(data, "txgain")) {
124                 sscanf(value, "%hhd", &gainset);
125                 ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
126         } else if (!strcasecmp(data, "rxgain")) {
127                 sscanf(value, "%hhd", &gainset);
128                 ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
129         } else if (!strcasecmp(data, "transfercapability")) {
130                 unsigned short i;
131                 for (i = 0; i < 0x20; i++) {
132                         if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
133                                 chan->transfercapability = i;
134                                 break;
135                         }
136                 }
137         } else if (!chan->tech->func_channel_write
138                  || chan->tech->func_channel_write(chan, function, data, value)) {
139                 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
140                                 data);
141                 ret = -1;
142         }
143
144         return ret;
145 }
146
147 static struct ast_custom_function channel_function = {
148         .name = "CHANNEL",
149         .synopsis = "Gets/sets various pieces of information about the channel.",
150         .syntax = "CHANNEL(item)",
151         .desc = "Gets/set various pieces of information about the channel.\n"
152                 "Standard items (provided by all channel technologies) are:\n"
153                 "R/O    audioreadformat    format currently being read\n"
154                 "R/O    audionativeformat  format used natively for audio\n"
155                 "R/O    audiowriteformat   format currently being written\n"
156                 "R/W    callgroup          call groups for call pickup\n"
157                 "R/O    channeltype        technology used for channel\n"
158                 "R/W    language           language for sounds played\n"
159                 "R/W    musicclass         class (from musiconhold.conf) for hold music\n"
160                 "R/W    rxgain             set rxgain level on channel drivers that support it\n"
161                 "R/O    state              state for channel\n"
162                 "R/W    tonezone           zone for indications played\n"
163                 "R/W    txgain             set txgain level on channel drivers that support it\n"
164                 "R/O    videonativeformat  format used natively for video\n"
165                 "\n"
166                 "chan_sip provides the following additional options:\n"
167                 "R/O    rtpqos             Get QOS information about the RTP stream\n"
168                 "       This option takes two additional arguments:\n"
169                 "  Argument 1:\n"
170                 "    audio                 Get data about the audio stream\n"
171                 "    video                 Get data about the video stream\n"
172                 "    text                  Get data about the text stream\n"
173                 "  Argument 2:\n"
174                 "    local_ssrc            Local SSRC (stream ID)\n"
175                 "    local_lostpackets     Local lost packets\n"
176                 "    local_jitter          Local calculated jitter\n"
177                 "    local_count           Number of received packets\n"
178                 "    remote_ssrc           Remote SSRC (stream ID)\n"
179                 "    remote_lostpackets    Remote lost packets\n"
180                 "    remote_jitter         Remote reported jitter\n"
181                 "    remote_count          Number of transmitted packets\n"
182                 "    rtt                   Round trip time\n"
183                 "    all                   All statistics (in a form suited to logging, but not for parsing)\n"
184                 "R/O    rtpdest            Get remote RTP destination information\n"
185                 "       This option takes one additional argument:\n"
186                 "  Argument 1:\n"
187                 "    audio                 Get audio destination\n"
188                 "    video                 Get video destination\n"
189                 "\n"
190                 "chan_iax2 provides the following additional options:\n"
191                 "R/W    osptoken           Get or set the OSP token information for a call\n"
192                 "\n"
193                 "Additional items may be available from the channel driver providing\n"
194                 "the channel; see its documentation for details.\n"
195                 "\n"
196                 "Any item requested that is not available on the current channel will\n"
197                 "return an empty string.\n",
198         .read = func_channel_read,
199         .write = func_channel_write,
200 };
201
202 static int unload_module(void)
203 {
204         return ast_custom_function_unregister(&channel_function);
205 }
206
207 static int load_module(void)
208 {
209         return ast_custom_function_register(&channel_function);
210 }
211
212 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel information dialplan function");