SS7 marked the start of an open season for trunk again but here's something minor...
[asterisk/asterisk.git] / main / channel.c
index 8448524..3df9191 100644 (file)
@@ -288,18 +288,32 @@ static char *complete_channeltypes(const char *line, const char *word, int pos,
 }
 
 static char show_channeltypes_usage[] =
 }
 
 static char show_channeltypes_usage[] =
-"Usage: show channeltypes\n"
-"       Shows available channel types registered in your Asterisk server.\n";
+"Usage: channeltype list\n"
+"       Lists available channel types registered in your Asterisk server.\n";
 
 static char show_channeltype_usage[] =
 
 static char show_channeltype_usage[] =
-"Usage: show channeltype <name>\n"
+"Usage: channeltype show <name>\n"
 "      Show details about the specified channel type, <name>.\n";
 
 "      Show details about the specified channel type, <name>.\n";
 
-static struct ast_cli_entry cli_show_channeltypes =
-       { { "show", "channeltypes", NULL }, show_channeltypes, "Show available channel types", show_channeltypes_usage };
+static struct ast_cli_entry cli_show_channeltypes_deprecated = {
+       { "show", "channeltypes", NULL },
+       show_channeltypes, NULL,
+       NULL };
 
 
-static struct ast_cli_entry cli_show_channeltype =
-       { { "show", "channeltype", NULL }, show_channeltype, "Give more details on that channel type", show_channeltype_usage, complete_channeltypes };
+static struct ast_cli_entry cli_show_channeltype_deprecated = {
+       { "show", "channeltype", NULL },
+       show_channeltype, NULL,
+       NULL, complete_channeltypes };
+
+static struct ast_cli_entry cli_channel[] = {
+       { { "channeltype", "list", NULL },
+       show_channeltypes, "List available channel types",
+       show_channeltypes_usage, NULL, &cli_show_channeltypes_deprecated },
+
+       { { "channeltype", "show", NULL },
+       show_channeltype, "Give more details on that channel type",
+       show_channeltype_usage, complete_channeltypes, &cli_show_channeltype_deprecated },
+};
 
 /*! \brief Checks to see if a channel is needing hang up */
 int ast_check_hangup(struct ast_channel *chan)
 
 /*! \brief Checks to see if a channel is needing hang up */
 int ast_check_hangup(struct ast_channel *chan)
@@ -2614,7 +2628,7 @@ static int set_format(struct ast_channel *chan, int fmt, int *rawformat, int *fo
        /* Now we have a good choice for both. */
        ast_channel_lock(chan);
 
        /* Now we have a good choice for both. */
        ast_channel_lock(chan);
 
-       if ((*rawformat == native) && (*format == fmt)) {
+       if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) {
                /* the channel is already in these formats, so nothing to do */
                ast_channel_unlock(chan);
                return 0;
                /* the channel is already in these formats, so nothing to do */
                ast_channel_unlock(chan);
                return 0;
@@ -3154,6 +3168,8 @@ int ast_do_masquerade(struct ast_channel *original)
        void *t_pvt;
        struct ast_callerid tmpcid;
        struct ast_channel *clone = original->masq;
        void *t_pvt;
        struct ast_callerid tmpcid;
        struct ast_channel *clone = original->masq;
+       struct ast_channel_spy_list *spy_list = NULL;
+       struct ast_channel_spy *spy = NULL;
        int rformat = original->readformat;
        int wformat = original->writeformat;
        char newn[100];
        int rformat = original->readformat;
        int wformat = original->writeformat;
        char newn[100];
@@ -3232,6 +3248,27 @@ int ast_do_masquerade(struct ast_channel *original)
        original->rawwriteformat = clone->rawwriteformat;
        clone->rawwriteformat = x;
 
        original->rawwriteformat = clone->rawwriteformat;
        clone->rawwriteformat = x;
 
+       /* Swap the spies */
+       spy_list = original->spies;
+       original->spies = clone->spies;
+       clone->spies = spy_list;
+
+       /* Update channel on respective spy lists if present */
+       if (original->spies) {
+               AST_LIST_TRAVERSE(&original->spies->list, spy, list) {
+                       ast_mutex_lock(&spy->lock);
+                       spy->chan = original;
+                       ast_mutex_unlock(&spy->lock);
+               }
+       }
+       if (clone->spies) {
+               AST_LIST_TRAVERSE(&clone->spies->list, spy, list) {
+                       ast_mutex_lock(&spy->lock);
+                       spy->chan = clone;
+                       ast_mutex_unlock(&spy->lock);
+               }
+       }
+
        /* Save any pending frames on both sides.  Start by counting
         * how many we're going to need... */
        x = 0;
        /* Save any pending frames on both sides.  Start by counting
         * how many we're going to need... */
        x = 0;
@@ -3638,6 +3675,16 @@ static enum ast_bridge_result ast_generic_bridge(struct ast_channel *c0, struct
        return res;
 }
 
        return res;
 }
 
+/*! \brief Bridge two channels together (early) */
+int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
+{
+       /* Make sure we can early bridge, if not error out */
+       if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge)))
+               return -1;
+
+       return c0->tech->early_bridge(c0, c1);
+}
+
 /*! \brief Bridge two channels together */
 enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1,
                                          struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc)
 /*! \brief Bridge two channels together */
 enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1,
                                          struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc)
@@ -4126,8 +4173,7 @@ void ast_moh_cleanup(struct ast_channel *chan)
 
 void ast_channels_init(void)
 {
 
 void ast_channels_init(void)
 {
-       ast_cli_register(&cli_show_channeltypes);
-       ast_cli_register(&cli_show_channeltype);
+       ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry));
 }
 
 /*! \brief Print call group and pickup group ---*/
 }
 
 /*! \brief Print call group and pickup group ---*/