Add Masquerade manager event which trips when a masquerade happens (issue #7840 repor...
[asterisk/asterisk.git] / funcs / func_channel.c
index 8d60f4c..2a377b5 100644 (file)
  * 
  */
 
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/module.h"
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
@@ -37,19 +39,26 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/app.h"
 #include "asterisk/indications.h"
 #include "asterisk/stringfields.h"
+
 #define locked_copy_string(chan, dest, source, len) \
        do { \
-               ast_mutex_lock(&chan->lock); \
+               ast_channel_lock(chan); \
                ast_copy_string(dest, source, len); \
-               ast_mutex_unlock(&chan->lock); \
+               ast_channel_unlock(chan); \
        } while (0)
 #define locked_string_field_set(chan, field, source) \
        do { \
-               ast_mutex_lock(&chan->lock); \
+               ast_channel_lock(chan); \
                ast_string_field_set(chan, field, source); \
-               ast_mutex_unlock(&chan->lock); \
+               ast_channel_unlock(chan); \
        } while (0)
 
+char *transfercapability_table[0x20] = {
+       "SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
+       "DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
+       "3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
+       "VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", };
+
 static int func_channel_read(struct ast_channel *chan, char *function,
                             char *data, char *buf, size_t len)
 {
@@ -77,6 +86,8 @@ static int func_channel_read(struct ast_channel *chan, char *function,
                locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
        else if (!strcasecmp(data, "channeltype"))
                locked_copy_string(chan, buf, chan->tech->type, len);
+       else if (!strcasecmp(data, "transfercapability"))
+               locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
        else if (!strcasecmp(data, "callgroup")) {
                char groupbuf[256];
                locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len);
@@ -93,14 +104,36 @@ static int func_channel_write(struct ast_channel *chan, char *function,
                              char *data, const char *value)
 {
        int ret = 0;
+       signed char gainset;
 
        if (!strcasecmp(data, "language"))
                locked_string_field_set(chan, language, value);
        else if (!strcasecmp(data, "musicclass"))
                locked_string_field_set(chan, musicclass, value);
-       else if (!strcasecmp(data, "callgroup"))
+       else if (!strcasecmp(data, "tonezone")) {
+               struct tone_zone *new_zone;
+               if (!(new_zone = ast_get_indication_zone(data))) {
+                       ast_log(LOG_ERROR, "Unknown country code for tonezone. Check indications.conf for available country codes.\n");
+                       ret = -1;       
+               } else 
+                       chan->zone = new_zone;
+       } else if (!strcasecmp(data, "callgroup"))
                chan->callgroup = ast_get_group(data);
-       else if (!chan->tech->func_channel_write
+       else if (!strcasecmp(data, "txgain")) {
+               sscanf(value, "%hhd", &gainset);
+               ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
+       } else if (!strcasecmp(data, "rxgain")) {
+               sscanf(value, "%hhd", &gainset);
+               ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
+       } else if (!strcasecmp(data, "transfercapability")) {
+               unsigned short i;
+               for (i = 0; i < 0x20; i++) {
+                       if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
+                               chan->transfercapability = i;
+                               break;
+                       }
+               }
+       } else if (!chan->tech->func_channel_write
                 || chan->tech->func_channel_write(chan, function, data, value)) {
                ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
                                data);
@@ -123,8 +156,10 @@ static struct ast_custom_function channel_function = {
                "R/O    channeltype             technology used for channel\n"
                "R/W    language                language for sounds played\n"
                "R/W    musicclass              class (from musiconhold.conf) for hold music\n"
+               "R/W    rxgain                  set rxgain level on channel drivers that support it\n"
                "R/O    state                   state for channel\n"
-               "R/O    tonezone                zone for indications played\n"
+               "R/W    tonezone                zone for indications played\n"
+               "R/W    txgain                  set txgain level on channel drivers that support it\n"
                "R/O    videonativeformat       format used natively for video\n"
                "\n"
                "Additional items may be available from the channel driver providing\n"
@@ -136,29 +171,14 @@ static struct ast_custom_function channel_function = {
        .write = func_channel_write,
 };
 
-static char *tdesc = "Channel information dialplan function";
-
-int unload_module(void)
+static int unload_module(void)
 {
        return ast_custom_function_unregister(&channel_function);
 }
 
-int load_module(void)
+static int load_module(void)
 {
        return ast_custom_function_register(&channel_function);
 }
 
-const char *description(void)
-{
-       return tdesc;
-}
-
-int usecount(void)
-{
-       return 0;
-}
-
-const char *key()
-{
-       return ASTERISK_GPL_KEY;
-}
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel information dialplan function");