manager_channels: Fix throwing of HangupHandler manager events
[asterisk/asterisk.git] / main / manager_channels.c
index b6eeb60..646bbd7 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include "asterisk/callerid.h"
 #include "asterisk/channel.h"
 #include "asterisk/manager.h"
@@ -42,60 +40,31 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a new channel is created.</synopsis>
                        <syntax>
-                               <parameter name="Channel">
-                               </parameter>
-                               <parameter name="ChannelState">
-                                       <para>A numeric code for the channel's current state, related to ChannelStateDesc</para>
-                               </parameter>
-                               <parameter name="ChannelStateDesc">
-                                       <enumlist>
-                                               <enum name="Down"/>
-                                               <enum name="Rsrvd"/>
-                                               <enum name="OffHook"/>
-                                               <enum name="Dialing"/>
-                                               <enum name="Ring"/>
-                                               <enum name="Ringing"/>
-                                               <enum name="Up"/>
-                                               <enum name="Busy"/>
-                                               <enum name="Dialing Offhook"/>
-                                               <enum name="Pre-ring"/>
-                                               <enum name="Unknown"/>
-                                       </enumlist>
-                               </parameter>
-                               <parameter name="CallerIDNum">
-                               </parameter>
-                               <parameter name="CallerIDName">
-                               </parameter>
-                               <parameter name="ConnectedLineNum">
-                               </parameter>
-                               <parameter name="ConnectedLineName">
-                               </parameter>
-                               <parameter name="AccountCode">
-                               </parameter>
-                               <parameter name="Context">
-                               </parameter>
-                               <parameter name="Exten">
-                               </parameter>
-                               <parameter name="Priority">
-                               </parameter>
-                               <parameter name="Uniqueid">
-                               </parameter>
+                               <channel_snapshot/>
                        </syntax>
+                       <see-also>
+                               <ref type="managerEvent">Newstate</ref>
+                               <ref type="managerEvent">Hangup</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="Newstate">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a channel's state changes.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                        </syntax>
+                       <see-also>
+                               <ref type="managerEvent">Newchannel</ref>
+                               <ref type="managerEvent">Hangup</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="Hangup">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a channel is hung up.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="Cause">
                                        <para>A numeric cause code for why the channel was hung up.</para>
                                </parameter>
@@ -103,31 +72,45 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                        <para>A description of why the channel was hung up.</para>
                                </parameter>
                        </syntax>
+                       <see-also>
+                               <ref type="managerEvent">Newchannel</ref>
+                               <ref type="managerEvent">SoftHangupRequest</ref>
+                               <ref type="managerEvent">HangupRequest</ref>
+                               <ref type="managerEvent">Newstate</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="HangupRequest">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a hangup is requested.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
                        </syntax>
+                       <see-also>
+                               <ref type="managerEvent">SoftHangupRequest</ref>
+                               <ref type="managerEvent">Hangup</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="SoftHangupRequest">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a soft hangup is requested with a specific cause code.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
                        </syntax>
+                       <see-also>
+                               <ref type="managerEvent">HangupRequest</ref>
+                               <ref type="managerEvent">Hangup</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="NewExten">
                <managerEventInstance class="EVENT_FLAG_DIALPLAN">
                        <synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="Extension">
                                        <para>Deprecated in 12, but kept for
                                        backward compatability. Please use
@@ -146,85 +129,139 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a channel receives new Caller ID information.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="CID-CallingPres">
                                        <para>A description of the Caller ID presentation.</para>
                                </parameter>
                        </syntax>
+                       <see-also>
+                               <ref type="function">CALLERID</ref>
+                       </see-also>
+               </managerEventInstance>
+       </managerEvent>
+       <managerEvent language="en_US" name="NewConnectedLine">
+               <managerEventInstance class="EVENT_FLAG_CALL">
+                       <synopsis>Raised when a channel's connected line information is changed.</synopsis>
+                       <syntax>
+                               <channel_snapshot/>
+                       </syntax>
+                       <see-also>
+                               <ref type="function">CONNECTEDLINE</ref>
+                       </see-also>
+               </managerEventInstance>
+       </managerEvent>
+       <managerEvent language="en_US" name="NewAccountCode">
+               <managerEventInstance class="EVENT_FLAG_CALL">
+                       <synopsis>Raised when a Channel's AccountCode is changed.</synopsis>
+                       <syntax>
+                               <channel_snapshot/>
+                               <parameter name="OldAccountCode">
+                                       <para>The channel's previous account code</para>
+                               </parameter>
+                       </syntax>
+                       <see-also>
+                               <ref type="function">CHANNEL</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="DialBegin">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a dial action has started.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-                               <parameter name="DestChannel">
-                               </parameter>
-                               <parameter name="DestChannelState">
-                                       <para>A numeric code for the channel's current state, related to DestChannelStateDesc</para>
-                               </parameter>
-                               <parameter name="DestChannelStateDesc">
-                                       <enumlist>
-                                               <enum name="Down"/>
-                                               <enum name="Rsrvd"/>
-                                               <enum name="OffHook"/>
-                                               <enum name="Dialing"/>
-                                               <enum name="Ring"/>
-                                               <enum name="Ringing"/>
-                                               <enum name="Up"/>
-                                               <enum name="Busy"/>
-                                               <enum name="Dialing Offhook"/>
-                                               <enum name="Pre-ring"/>
-                                               <enum name="Unknown"/>
-                                       </enumlist>
-                               </parameter>
-                               <parameter name="DestCallerIDNum">
-                               </parameter>
-                               <parameter name="DestCallerIDName">
-                               </parameter>
-                               <parameter name="DestConnectedLineNum">
-                               </parameter>
-                               <parameter name="DestConnectedLineName">
-                               </parameter>
-                               <parameter name="DestAccountCode">
-                               </parameter>
-                               <parameter name="DestContext">
-                               </parameter>
-                               <parameter name="DestExten">
-                               </parameter>
-                               <parameter name="DestPriority">
-                               </parameter>
-                               <parameter name="DestUniqueid">
-                               </parameter>
+                               <channel_snapshot/>
+                               <channel_snapshot prefix="Dest"/>
                                <parameter name="DialString">
                                        <para>The non-technology specific device being dialed.</para>
                                </parameter>
                        </syntax>
                        <see-also>
                                <ref type="application">Dial</ref>
+                               <ref type="application">Originate</ref>
+                               <ref type="manager">Originate</ref>
+                               <ref type="managerEvent">DialEnd</ref>
                        </see-also>
                </managerEventInstance>
        </managerEvent>
+       <managerEvent language="en_US" name="DialState">
+               <managerEventInstance class="EVENT_FLAG_CALL">
+                       <synopsis>Raised when dial status has changed.</synopsis>
+                       <syntax>
+                               <channel_snapshot/>
+                               <channel_snapshot prefix="Dest"/>
+                               <parameter name="DialStatus">
+                                       <para> The new state of the outbound dial attempt.</para>
+                                       <enumlist>
+                                               <enum name="RINGING">
+                                                       <para>The outbound channel is ringing.</para>
+                                               </enum>
+                                               <enum name="PROCEEDING">
+                                                       <para>The call to the outbound channel is proceeding.</para>
+                                               </enum>
+                                               <enum name="PROGRESS">
+                                                       <para>Progress has been received on the outbound channel.</para>
+                                               </enum>
+                                       </enumlist>
+                               </parameter>
+                               <parameter name="Forward" required="false">
+                                       <para>If the call was forwarded, where the call was
+                                       forwarded to.</para>
+                               </parameter>
+                       </syntax>
+               </managerEventInstance>
+       </managerEvent>
        <managerEvent language="en_US" name="DialEnd">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a dial action has completed.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='DialBegin']/managerEventInstance/syntax/parameter[contains(@name, 'Dest')])" />
+                               <channel_snapshot/>
+                               <channel_snapshot prefix="Dest"/>
                                <parameter name="DialStatus">
                                        <para>The result of the dial operation.</para>
                                        <enumlist>
-                                               <enum name="ANSWER" />
-                                               <enum name="BUSY" />
-                                               <enum name="CANCEL" />
-                                               <enum name="CHANUNAVAIL" />
-                                               <enum name="CONGESTION" />
-                                               <enum name="NOANSWER" />
+                                               <enum name="ABORT">
+                                                       <para>The call was aborted.</para>
+                                               </enum>
+                                               <enum name="ANSWER">
+                                                       <para>The caller answered.</para>
+                                               </enum>
+                                               <enum name="BUSY">
+                                                       <para>The caller was busy.</para>
+                                               </enum>
+                                               <enum name="CANCEL">
+                                                       <para>The caller cancelled the call.</para>
+                                               </enum>
+                                               <enum name="CHANUNAVAIL">
+                                                       <para>The requested channel is unavailable.</para>
+                                               </enum>
+                                               <enum name="CONGESTION">
+                                                       <para>The called party is congested.</para>
+                                               </enum>
+                                               <enum name="CONTINUE">
+                                                       <para>The dial completed, but the caller elected
+                                                       to continue in the dialplan.</para>
+                                               </enum>
+                                               <enum name="GOTO">
+                                                       <para>The dial completed, but the caller jumped to
+                                                       a dialplan location.</para>
+                                                       <para>If known, the location the caller is jumping
+                                                       to will be appended to the result following a
+                                                       ":".</para>
+                                               </enum>
+                                               <enum name="NOANSWER">
+                                                       <para>The called party failed to answer.</para>
+                                               </enum>
                                        </enumlist>
                                </parameter>
+                               <parameter name="Forward" required="false">
+                                       <para>If the call was forwarded, where the call was
+                                       forwarded to.</para>
+                               </parameter>
                        </syntax>
                        <see-also>
                                <ref type="application">Dial</ref>
+                               <ref type="application">Originate</ref>
+                               <ref type="manager">Originate</ref>
+                               <ref type="managerEvent">DialBegin</ref>
                        </see-also>
                </managerEventInstance>
        </managerEvent>
@@ -232,106 +269,37 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a channel goes on hold.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="MusicClass">
                                        <para>The suggested MusicClass, if provided.</para>
                                </parameter>
                        </syntax>
+                       <see-also>
+                               <ref type="managerEvent">Unhold</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="Unhold">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a channel goes off hold.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                        </syntax>
+                       <see-also>
+                               <ref type="managerEvent">Hold</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="ChanSpyStart">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when one channel begins spying on another channel.</synopsis>
                        <syntax>
-                               <parameter name="SpyerChannel">
-                                       <para>The channel performing the spying.</para>
-                               </parameter>
-                               <parameter name="SpyerChannelState">
-                                       <para>A numeric code for the channel's current state, related to SpyerChannelStateDesc</para>
-                               </parameter>
-                               <parameter name="SpyerChannelStateDesc">
-                                       <enumlist>
-                                               <enum name="Down"/>
-                                               <enum name="Rsrvd"/>
-                                               <enum name="OffHook"/>
-                                               <enum name="Dialing"/>
-                                               <enum name="Ring"/>
-                                               <enum name="Ringing"/>
-                                               <enum name="Up"/>
-                                               <enum name="Busy"/>
-                                               <enum name="Dialing Offhook"/>
-                                               <enum name="Pre-ring"/>
-                                               <enum name="Unknown"/>
-                                       </enumlist>
-                               </parameter>
-                               <parameter name="SpyerCallerIDNum">
-                               </parameter>
-                               <parameter name="SpyerCallerIDName">
-                               </parameter>
-                               <parameter name="SpyerConnectedLineNum">
-                               </parameter>
-                               <parameter name="SpyerConnectedLineName">
-                               </parameter>
-                               <parameter name="SpyerAccountCode">
-                               </parameter>
-                               <parameter name="SpyerContext">
-                               </parameter>
-                               <parameter name="SpyerExten">
-                               </parameter>
-                               <parameter name="SpyerPriority">
-                               </parameter>
-                               <parameter name="SpyerUniqueid">
-                               </parameter>
-                               <parameter name="SpyeeChannel">
-                                       <para>The channel being spied upon.</para>
-                               </parameter>
-                               <parameter name="SpyeeChannelState">
-                                       <para>A numeric code for the channel's current state, related to SpyeeChannelStateDesc</para>
-                               </parameter>
-                               <parameter name="SpyeeChannelStateDesc">
-                                       <enumlist>
-                                               <enum name="Down"/>
-                                               <enum name="Rsrvd"/>
-                                               <enum name="OffHook"/>
-                                               <enum name="Dialing"/>
-                                               <enum name="Ring"/>
-                                               <enum name="Ringing"/>
-                                               <enum name="Up"/>
-                                               <enum name="Busy"/>
-                                               <enum name="Dialing Offhook"/>
-                                               <enum name="Pre-ring"/>
-                                               <enum name="Unknown"/>
-                                       </enumlist>
-                               </parameter>
-                               <parameter name="SpyeeCallerIDNum">
-                               </parameter>
-                               <parameter name="SpyeeCallerIDName">
-                               </parameter>
-                               <parameter name="SpyeeConnectedLineNum">
-                               </parameter>
-                               <parameter name="SpyeeConnectedLineName">
-                               </parameter>
-                               <parameter name="SpyeeAccountCode">
-                               </parameter>
-                               <parameter name="SpyeeContext">
-                               </parameter>
-                               <parameter name="SpyeeExten">
-                               </parameter>
-                               <parameter name="SpyeePriority">
-                               </parameter>
-                               <parameter name="SpyeeUniqueid">
-                               </parameter>
+                               <channel_snapshot prefix="Spyer"/>
+                               <channel_snapshot prefix="Spyee"/>
                        </syntax>
                        <see-also>
-                               <ref type="application">ChanSpyStop</ref>
+                               <ref type="managerEvent">ChanSpyStop</ref>
+                               <ref type="application">ChanSpy</ref>
                        </see-also>
                </managerEventInstance>
        </managerEvent>
@@ -339,10 +307,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a channel has stopped spying.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='ChanSpyStart']/managerEventInstance/syntax/parameter[contains(@name, 'Spyer')])" />
+                               <channel_snapshot prefix="Spyer"/>
+                               <channel_snapshot prefix="Spyee"/>
                        </syntax>
                        <see-also>
-                               <ref type="application">ChanSpyStart</ref>
+                               <ref type="managerEvent">ChanSpyStart</ref>
+                               <ref type="application">ChanSpy</ref>
                        </see-also>
                </managerEventInstance>
        </managerEvent>
@@ -350,11 +320,14 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_DIALPLAN">
                        <synopsis>Raised when a hangup handler is about to be called.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="Handler">
                                        <para>Hangup handler parameter string passed to the Gosub application.</para>
                                </parameter>
                        </syntax>
+                       <see-also>
+                               <ref type="function">CHANNEL</ref>
+                       </see-also>
                </managerEventInstance>
        </managerEvent>
        <managerEvent language="en_US" name="HangupHandlerPop">
@@ -364,6 +337,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                by the CHANNEL() function.
                        </synopsis>
                        <syntax>
+                               <channel_snapshot/>
                                <xi:include xpointer="xpointer(/docs/managerEvent[@name='HangupHandlerRun']/managerEventInstance/syntax/parameter)" />
                        </syntax>
                        <see-also>
@@ -379,6 +353,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                the CHANNEL() function.
                        </synopsis>
                        <syntax>
+                               <channel_snapshot/>
                                <xi:include xpointer="xpointer(/docs/managerEvent[@name='HangupHandlerRun']/managerEventInstance/syntax/parameter)" />
                        </syntax>
                        <see-also>
@@ -393,7 +368,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                Raised periodically during a fax transmission.
                        </synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="Operation">
                                        <enumlist>
                                                <enum name="gateway"/>
@@ -415,7 +390,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                Raised when a receive fax operation has completed.
                        </synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="LocalStationID">
                                        <para>The value of the <variable>LOCALSTATIONID</variable> channel variable</para>
                                </parameter>
@@ -443,7 +418,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                Raised when a send fax operation has completed.
                        </synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <xi:include xpointer="xpointer(/docs/managerEvent[@name='ReceiveFAX']/managerEventInstance/syntax/parameter)" />
                        </syntax>
                </managerEventInstance>
@@ -452,13 +427,14 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when music on hold has started on a channel.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                                <parameter name="Class">
                                        <para>The class of music being played on the channel</para>
                                </parameter>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">MusicOnHoldStop</ref>
+                               <ref type="application">StartMusicOnHold</ref>
                                <ref type="application">MusicOnHold</ref>
                        </see-also>
                </managerEventInstance>
@@ -467,7 +443,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when music on hold has stopped on a channel.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">MusicOnHoldStart</ref>
@@ -479,7 +455,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when monitoring has started on a channel.</synopsis>
                        <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <channel_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">MonitorStop</ref>
@@ -492,7 +468,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                <managerEventInstance class="EVENT_FLAG_CALL">
                <synopsis>Raised when monitoring has stopped on a channel.</synopsis>
                <syntax>
-                       <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                       <channel_snapshot/>
                </syntax>
                <see-also>
                        <ref type="managerEvent">MonitorStart</ref>
@@ -506,53 +482,76 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 /*! \brief The \ref stasis subscription returned by the forwarding of the channel topic
  * to the manager topic
  */
-static struct stasis_subscription *topic_forwarder;
+static struct stasis_forward *topic_forwarder;
 
 struct ast_str *ast_manager_build_channel_state_string_prefix(
                const struct ast_channel_snapshot *snapshot,
                const char *prefix)
 {
-       struct ast_str *out = ast_str_create(1024);
-       int res = 0;
+       struct ast_str *out;
+       char *caller_name;
+       char *connected_name;
+       int res;
+
+       if (snapshot->base->tech_properties & AST_CHAN_TP_INTERNAL) {
+               return NULL;
+       }
+
+       out = ast_str_create(1024);
        if (!out) {
                return NULL;
        }
+
+       caller_name = ast_escape_c_alloc(snapshot->caller->name);
+       connected_name = ast_escape_c_alloc(snapshot->connected->name);
+
        res = ast_str_set(&out, 0,
                "%sChannel: %s\r\n"
-               "%sChannelState: %d\r\n"
+               "%sChannelState: %u\r\n"
                "%sChannelStateDesc: %s\r\n"
                "%sCallerIDNum: %s\r\n"
                "%sCallerIDName: %s\r\n"
                "%sConnectedLineNum: %s\r\n"
                "%sConnectedLineName: %s\r\n"
+               "%sLanguage: %s\r\n"
                "%sAccountCode: %s\r\n"
                "%sContext: %s\r\n"
                "%sExten: %s\r\n"
                "%sPriority: %d\r\n"
-               "%sUniqueid: %s\r\n",
-               prefix, snapshot->name,
+               "%sUniqueid: %s\r\n"
+               "%sLinkedid: %s\r\n",
+               prefix, snapshot->base->name,
                prefix, snapshot->state,
                prefix, ast_state2str(snapshot->state),
-               prefix, S_OR(snapshot->caller_number, "<unknown>"),
-               prefix, S_OR(snapshot->caller_name, "<unknown>"),
-               prefix, S_OR(snapshot->connected_number, "<unknown>"),
-               prefix, S_OR(snapshot->connected_name, "<unknown>"),
-               prefix, snapshot->accountcode,
-               prefix, snapshot->context,
-               prefix, snapshot->exten,
-               prefix, snapshot->priority,
-               prefix, snapshot->uniqueid);
+               prefix, S_OR(snapshot->caller->number, "<unknown>"),
+               prefix, S_OR(caller_name, "<unknown>"),
+               prefix, S_OR(snapshot->connected->number, "<unknown>"),
+               prefix, S_OR(connected_name, "<unknown>"),
+               prefix, snapshot->base->language,
+               prefix, snapshot->base->accountcode,
+               prefix, snapshot->dialplan->context,
+               prefix, snapshot->dialplan->exten,
+               prefix, snapshot->dialplan->priority,
+               prefix, snapshot->base->uniqueid,
+               prefix, snapshot->peer->linkedid);
+
+       ast_free(caller_name);
+       ast_free(connected_name);
 
        if (!res) {
+               ast_free(out);
                return NULL;
        }
 
        if (snapshot->manager_vars) {
                struct ast_var_t *var;
+               char *val;
                AST_LIST_TRAVERSE(snapshot->manager_vars, var, entries) {
+                       val = ast_escape_c_alloc(var->value);
                        ast_str_append(&out, 0, "%sChanVariable: %s=%s\r\n",
                                       prefix,
-                                      var->name, var->value);
+                                      var->name, S_OR(val, ""));
+                       ast_free(val);
                }
        }
 
@@ -577,11 +576,6 @@ static struct ast_manager_event_blob *channel_state_change(
 {
        int is_hungup, was_hungup;
 
-       if (!new_snapshot) {
-               /* Ignore cache clearing events; we'll see the hangup first */
-               return NULL;
-       }
-
        /* The Newchannel, Newstate and Hangup events are closely related, in
         * in that they are mutually exclusive, basically different flavors
         * of a new channel state event.
@@ -592,16 +586,16 @@ static struct ast_manager_event_blob *channel_state_change(
                        EVENT_FLAG_CALL, "Newchannel", NO_EXTRA_FIELDS);
        }
 
-       was_hungup = ast_test_flag(&old_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
-       is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
+       was_hungup = ast_test_flag(&old_snapshot->flags, AST_FLAG_DEAD) ? 1 : 0;
+       is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_DEAD) ? 1 : 0;
 
        if (!was_hungup && is_hungup) {
                return ast_manager_event_blob_create(
                        EVENT_FLAG_CALL, "Hangup",
                        "Cause: %d\r\n"
                        "Cause-txt: %s\r\n",
-                       new_snapshot->hangupcause,
-                       ast_cause2str(new_snapshot->hangupcause));
+                       new_snapshot->hangup->cause,
+                       ast_cause2str(new_snapshot->hangup->cause));
        }
 
        if (old_snapshot->state != new_snapshot->state) {
@@ -617,37 +611,41 @@ static struct ast_manager_event_blob *channel_newexten(
        struct ast_channel_snapshot *old_snapshot,
        struct ast_channel_snapshot *new_snapshot)
 {
-       /* No Newexten event on cache clear */
-       if (!new_snapshot) {
+       /* Empty application is not valid for a Newexten event */
+       if (ast_strlen_zero(new_snapshot->dialplan->appl)) {
                return NULL;
        }
 
-       /* Empty application is not valid for a Newexten event */
-       if (ast_strlen_zero(new_snapshot->appl)) {
+       /* Ignore any updates if we're hungup */
+       if (ast_test_flag(&new_snapshot->flags, AST_FLAG_DEAD)) {
                return NULL;
        }
 
+       /* Ignore updates if the CEP is unchanged */
        if (old_snapshot && ast_channel_snapshot_cep_equal(old_snapshot, new_snapshot)) {
                return NULL;
        }
 
        /* DEPRECATED: Extension field deprecated in 12; remove in 14 */
        return ast_manager_event_blob_create(
-               EVENT_FLAG_CALL, "Newexten",
+               EVENT_FLAG_DIALPLAN, "Newexten",
                "Extension: %s\r\n"
                "Application: %s\r\n"
                "AppData: %s\r\n",
-               new_snapshot->exten,
-               new_snapshot->appl,
-               new_snapshot->data);
+               new_snapshot->dialplan->exten,
+               new_snapshot->dialplan->appl,
+               new_snapshot->dialplan->data);
 }
 
 static struct ast_manager_event_blob *channel_new_callerid(
        struct ast_channel_snapshot *old_snapshot,
        struct ast_channel_snapshot *new_snapshot)
 {
-       /* No NewCallerid event on cache clear or first event */
-       if (!old_snapshot || !new_snapshot) {
+       struct ast_manager_event_blob *res;
+       char *callerid;
+
+       /* No NewCallerid event on first channel snapshot */
+       if (!old_snapshot) {
                return NULL;
        }
 
@@ -655,41 +653,75 @@ static struct ast_manager_event_blob *channel_new_callerid(
                return NULL;
        }
 
-       return ast_manager_event_blob_create(
+       if (!(callerid = ast_escape_c_alloc(
+                     ast_describe_caller_presentation(new_snapshot->caller->pres)))) {
+               return NULL;
+       }
+
+       res = ast_manager_event_blob_create(
                EVENT_FLAG_CALL, "NewCallerid",
                "CID-CallingPres: %d (%s)\r\n",
-               new_snapshot->caller_pres,
-               ast_describe_caller_presentation(new_snapshot->caller_pres));
+               new_snapshot->caller->pres,
+               callerid);
+
+       ast_free(callerid);
+       return res;
+}
+
+static struct ast_manager_event_blob *channel_new_connected_line(
+       struct ast_channel_snapshot *old_snapshot,
+       struct ast_channel_snapshot *new_snapshot)
+{
+       /* No NewConnectedLine event on first channel snapshot */
+       if (!old_snapshot) {
+               return NULL;
+       }
+
+       if (ast_channel_snapshot_connected_line_equal(old_snapshot, new_snapshot)) {
+               return NULL;
+       }
+
+       return ast_manager_event_blob_create(
+               EVENT_FLAG_CALL, "NewConnectedLine", "%s", "");
+}
+
+static struct ast_manager_event_blob *channel_new_accountcode(
+       struct ast_channel_snapshot *old_snapshot,
+       struct ast_channel_snapshot *new_snapshot)
+{
+       if (!old_snapshot) {
+               return NULL;
+       }
+
+       if (!strcmp(old_snapshot->base->accountcode, new_snapshot->base->accountcode)) {
+               return NULL;
+       }
+
+       return ast_manager_event_blob_create(
+               EVENT_FLAG_CALL, "NewAccountCode",
+               "OldAccountCode: %s\r\n", old_snapshot->base->accountcode);
 }
 
 channel_snapshot_monitor channel_monitors[] = {
        channel_state_change,
        channel_newexten,
-       channel_new_callerid
+       channel_new_callerid,
+       channel_new_accountcode,
+       channel_new_connected_line,
 };
 
 static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
-                                   struct stasis_topic *topic,
                                    struct stasis_message *message)
 {
        RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-       struct stasis_cache_update *update;
-       struct ast_channel_snapshot *old_snapshot;
-       struct ast_channel_snapshot *new_snapshot;
+       struct ast_channel_snapshot_update *update;
        size_t i;
 
        update = stasis_message_data(message);
 
-       if (ast_channel_snapshot_type() != update->type) {
-               return;
-       }
-
-       old_snapshot = stasis_message_data(update->old_snapshot);
-       new_snapshot = stasis_message_data(update->new_snapshot);
-
        for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) {
                RAII_VAR(struct ast_manager_event_blob *, ev, NULL, ao2_cleanup);
-               ev = channel_monitors[i](old_snapshot, new_snapshot);
+               ev = channel_monitors[i](update->old_snapshot, update->new_snapshot);
 
                if (!ev) {
                        continue;
@@ -698,7 +730,7 @@ static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
                /* If we haven't already, build the channel event string */
                if (!channel_event_string) {
                        channel_event_string =
-                               ast_manager_build_channel_state_string(new_snapshot);
+                               ast_manager_build_channel_state_string(update->new_snapshot);
                        if (!channel_event_string) {
                                return;
                        }
@@ -710,97 +742,6 @@ static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
        }
 }
 
-static void channel_varset_cb(void *data, struct stasis_subscription *sub,
-       struct stasis_topic *topic, struct stasis_message *message)
-{
-       struct ast_channel_blob *obj = stasis_message_data(message);
-       RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-       const char *variable = ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
-       const char *value = ast_json_string_get(ast_json_object_get(obj->blob, "value"));
-
-       if (obj->snapshot) {
-               channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
-       } else {
-               channel_event_string = ast_str_create(35);
-               ast_str_set(&channel_event_string, 0,
-                           "Channel: none\r\n"
-                           "Uniqueid: none\r\n");
-       }
-
-       if (!channel_event_string) {
-               return;
-       }
-
-       /*** DOCUMENTATION
-               <managerEventInstance>
-                       <synopsis>Raised when a variable is set to a particular value.</synopsis>
-                       <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-                               <parameter name="Variable">
-                                       <para>The variable being set.</para>
-                               </parameter>
-                               <parameter name="Value">
-                                       <para>The new value of the variable.</para>
-                               </parameter>
-                       </syntax>
-               </managerEventInstance>
-       ***/
-       manager_event(EVENT_FLAG_DIALPLAN, "VarSet",
-                     "%s"
-                     "Variable: %s\r\n"
-                     "Value: %s\r\n",
-                     ast_str_buffer(channel_event_string),
-                     variable, value);
-}
-
-static int userevent_exclusion_cb(const char *key)
-{
-       if (!strcmp("type", key)) {
-               return 1;
-       }
-       if (!strcmp("eventname", key)) {
-               return 1;
-       }
-       return 0;
-}
-
-static void channel_user_event_cb(void *data, struct stasis_subscription *sub,
-       struct stasis_topic *topic, struct stasis_message *message)
-{
-       struct ast_channel_blob *obj = stasis_message_data(message);
-       RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-       RAII_VAR(struct ast_str *, body, NULL, ast_free);
-       const char *eventname;
-
-       eventname = ast_json_string_get(ast_json_object_get(obj->blob, "eventname"));
-       body = ast_manager_str_from_json_object(obj->blob, userevent_exclusion_cb);
-       channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
-
-       if (!channel_event_string || !body) {
-               return;
-       }
-
-       /*** DOCUMENTATION
-               <managerEventInstance>
-                       <synopsis>A user defined event raised from the dialplan.</synopsis>
-                       <syntax>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-                               <parameter name="UserEvent">
-                                       <para>The event name, as specified in the dialplan.</para>
-                               </parameter>
-                       </syntax>
-                       <see-also>
-                               <ref type="application">UserEvent</ref>
-                       </see-also>
-               </managerEventInstance>
-       ***/
-       manager_event(EVENT_FLAG_USER, "UserEvent",
-                     "%s"
-                     "UserEvent: %s\r\n"
-                     "%s",
-                     ast_str_buffer(channel_event_string), eventname, ast_str_buffer(body));
-}
-
 static void publish_basic_channel_event(const char *event, int class, struct ast_channel_snapshot *snapshot)
 {
        RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
@@ -816,32 +757,37 @@ static void publish_basic_channel_event(const char *event, int class, struct ast
 }
 
 static void channel_hangup_request_cb(void *data,
-       struct stasis_subscription *sub, struct stasis_topic *topic,
+       struct stasis_subscription *sub,
        struct stasis_message *message)
 {
        struct ast_channel_blob *obj = stasis_message_data(message);
-       RAII_VAR(struct ast_str *, extra, NULL, ast_free);
-       RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+       struct ast_str *extra;
+       struct ast_str *channel_event_string;
        struct ast_json *cause;
        int is_soft;
        char *manager_event = "HangupRequest";
 
+       if (!obj->snapshot) {
+               /* No snapshot?  Likely an earlier allocation failure creating it. */
+               return;
+       }
+
        extra = ast_str_create(20);
        if (!extra) {
                return;
        }
 
        channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
-
        if (!channel_event_string) {
+               ast_free(extra);
                return;
        }
 
        cause = ast_json_object_get(obj->blob, "cause");
        if (cause) {
                ast_str_append(&extra, 0,
-                              "Cause: %jd\r\n",
-                              ast_json_integer_get(cause));
+                       "Cause: %jd\r\n",
+                       ast_json_integer_get(cause));
        }
 
        is_soft = ast_json_is_true(ast_json_object_get(obj->blob, "soft"));
@@ -850,13 +796,16 @@ static void channel_hangup_request_cb(void *data,
        }
 
        manager_event(EVENT_FLAG_CALL, manager_event,
-                     "%s%s",
-                     ast_str_buffer(channel_event_string),
-                     ast_str_buffer(extra));
+               "%s%s",
+               ast_str_buffer(channel_event_string),
+               ast_str_buffer(extra));
+
+       ast_free(channel_event_string);
+       ast_free(extra);
 }
 
 static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        RAII_VAR(struct ast_str *, spyer_channel_string, NULL, ast_free);
        struct ast_channel_snapshot *spyer;
@@ -879,7 +828,7 @@ static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub,
 }
 
 static void channel_chanspy_start_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        RAII_VAR(struct ast_str *, spyer_channel_string, NULL, ast_free);
        RAII_VAR(struct ast_str *, spyee_channel_string, NULL, ast_free);
@@ -914,7 +863,7 @@ static void channel_chanspy_start_cb(void *data, struct stasis_subscription *sub
 }
 
 static void channel_dtmf_begin_cb(void *data, struct stasis_subscription *sub,
-       struct stasis_topic *topic, struct stasis_message *message)
+       struct stasis_message *message)
 {
        struct ast_channel_blob *obj = stasis_message_data(message);
        RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
@@ -933,7 +882,7 @@ static void channel_dtmf_begin_cb(void *data, struct stasis_subscription *sub,
                <managerEventInstance>
                        <synopsis>Raised when a DTMF digit has started on a channel.</synopsis>
                                <syntax>
-                                       <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                                       <channel_snapshot/>
                                        <parameter name="Digit">
                                                <para>DTMF digit received or transmitted (0-9, A-E, # or *</para>
                                        </parameter>
@@ -944,6 +893,9 @@ static void channel_dtmf_begin_cb(void *data, struct stasis_subscription *sub,
                                                </enumlist>
                                        </parameter>
                                </syntax>
+                               <see-also>
+                                       <ref type="managerEvent">DTMFEnd</ref>
+                               </see-also>
                </managerEventInstance>
        ***/
        manager_event(EVENT_FLAG_DTMF, "DTMFBegin",
@@ -955,7 +907,7 @@ static void channel_dtmf_begin_cb(void *data, struct stasis_subscription *sub,
 }
 
 static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub,
-       struct stasis_topic *topic, struct stasis_message *message)
+       struct stasis_message *message)
 {
        struct ast_channel_blob *obj = stasis_message_data(message);
        RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
@@ -976,7 +928,7 @@ static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub,
                <managerEventInstance>
                        <synopsis>Raised when a DTMF digit has ended on a channel.</synopsis>
                                <syntax>
-                                       <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                                       <channel_snapshot/>
                                        <parameter name="Digit">
                                                <para>DTMF digit received or transmitted (0-9, A-E, # or *</para>
                                        </parameter>
@@ -990,6 +942,9 @@ static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub,
                                                </enumlist>
                                        </parameter>
                                </syntax>
+                               <see-also>
+                                       <ref type="managerEvent">DTMFBegin</ref>
+                               </see-also>
                </managerEventInstance>
        ***/
        manager_event(EVENT_FLAG_DTMF, "DTMFEnd",
@@ -1002,7 +957,7 @@ static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub,
 }
 
 static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
        struct ast_channel_blob *payload = stasis_message_data(message);
@@ -1016,11 +971,11 @@ static void channel_hangup_handler_cb(void *data, struct stasis_subscription *su
                return;
        }
 
-       if (!strcmp(action, "type")) {
+       if (!strcmp(action, "run")) {
                event = "HangupHandlerRun";
-       } else if (!strcmp(action, "type")) {
+       } else if (!strcmp(action, "pop")) {
                event = "HangupHandlerPop";
-       } else if (!strcmp(action, "type")) {
+       } else if (!strcmp(action, "push")) {
                event = "HangupHandlerPush";
        } else {
                return;
@@ -1033,7 +988,7 @@ static void channel_hangup_handler_cb(void *data, struct stasis_subscription *su
 }
 
 static void channel_fax_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
        RAII_VAR(struct ast_str *, event_buffer, ast_str_create(256), ast_free);
@@ -1106,7 +1061,7 @@ static void channel_fax_cb(void *data, struct stasis_subscription *sub,
 }
 
 static void channel_moh_start_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        struct ast_channel_blob *payload = stasis_message_data(message);
        struct ast_json *blob = payload->blob;
@@ -1126,7 +1081,7 @@ static void channel_moh_start_cb(void *data, struct stasis_subscription *sub,
 }
 
 static void channel_moh_stop_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        struct ast_channel_blob *payload = stasis_message_data(message);
 
@@ -1134,7 +1089,7 @@ static void channel_moh_stop_cb(void *data, struct stasis_subscription *sub,
 }
 
 static void channel_monitor_start_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        struct ast_channel_blob *payload = stasis_message_data(message);
 
@@ -1142,22 +1097,30 @@ static void channel_monitor_start_cb(void *data, struct stasis_subscription *sub
 }
 
 static void channel_monitor_stop_cb(void *data, struct stasis_subscription *sub,
-               struct stasis_topic *topic, struct stasis_message *message)
+               struct stasis_message *message)
 {
        struct ast_channel_blob *payload = stasis_message_data(message);
 
        publish_basic_channel_event("MonitorStop", EVENT_FLAG_CALL, payload->snapshot);
 }
 
+static int dial_status_end(const char *dialstatus)
+{
+       return (strcmp(dialstatus, "RINGING") &&
+                       strcmp(dialstatus, "PROCEEDING") &&
+                       strcmp(dialstatus, "PROGRESS"));
+}
+
 /*!
  * \brief Callback processing messages for channel dialing
  */
 static void channel_dial_cb(void *data, struct stasis_subscription *sub,
-       struct stasis_topic *topic, struct stasis_message *message)
+       struct stasis_message *message)
 {
        struct ast_multi_channel_blob *obj = stasis_message_data(message);
        const char *dialstatus;
        const char *dialstring;
+       const char *forward;
        struct ast_channel_snapshot *caller;
        struct ast_channel_snapshot *peer;
        RAII_VAR(struct ast_str *, caller_event_string, NULL, ast_free);
@@ -1179,6 +1142,7 @@ static void channel_dial_cb(void *data, struct stasis_subscription *sub,
 
        dialstatus = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "dialstatus"));
        dialstring = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "dialstring"));
+       forward = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "forward"));
        if (ast_strlen_zero(dialstatus)) {
                manager_event(EVENT_FLAG_CALL, "DialBegin",
                                "%s"
@@ -1188,32 +1152,41 @@ static void channel_dial_cb(void *data, struct stasis_subscription *sub,
                                ast_str_buffer(peer_event_string),
                                S_OR(dialstring, "unknown"));
        } else {
-               manager_event(EVENT_FLAG_CALL, "DialEnd",
+               int forwarded = !ast_strlen_zero(forward);
+
+               manager_event(EVENT_FLAG_CALL, dial_status_end(dialstatus) ? "DialEnd" : "DialState",
                                "%s"
                                "%s"
+                               "%s%s%s"
                                "DialStatus: %s\r\n",
                                caller_event_string ? ast_str_buffer(caller_event_string) : "",
                                ast_str_buffer(peer_event_string),
+                               forwarded ? "Forward: " : "", S_OR(forward, ""), forwarded ? "\r\n" : "",
                                S_OR(dialstatus, "unknown"));
        }
 
 }
 
 static void channel_hold_cb(void *data, struct stasis_subscription *sub,
-       struct stasis_topic *topic, struct stasis_message *message)
+       struct stasis_message *message)
 {
        struct ast_channel_blob *obj = stasis_message_data(message);
-       const char *musicclass;
-       RAII_VAR(struct ast_str *, musicclass_string, NULL, ast_free);
-       RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+       struct ast_str *musicclass_string = ast_str_create(32);
+       struct ast_str *channel_event_string;
 
-       if (!(musicclass_string = ast_str_create(32))) {
+       if (!musicclass_string) {
                return;
        }
 
        channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+       if (!channel_event_string) {
+               ast_free(musicclass_string);
+               return;
+       }
 
        if (obj->blob) {
+               const char *musicclass;
+
                musicclass = ast_json_string_get(ast_json_object_get(obj->blob, "musicclass"));
 
                if (!ast_strlen_zero(musicclass)) {
@@ -1226,24 +1199,32 @@ static void channel_hold_cb(void *data, struct stasis_subscription *sub,
                "%s",
                ast_str_buffer(channel_event_string),
                ast_str_buffer(musicclass_string));
+
+       ast_free(musicclass_string);
+       ast_free(channel_event_string);
 }
 
 static void channel_unhold_cb(void *data, struct stasis_subscription *sub,
-       struct stasis_topic *topic, struct stasis_message *message)
+       struct stasis_message *message)
 {
        struct ast_channel_blob *obj = stasis_message_data(message);
-       RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+       struct ast_str *channel_event_string;
 
        channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+       if (!channel_event_string) {
+               return;
+       }
 
        manager_event(EVENT_FLAG_CALL, "Unhold",
                "%s",
                ast_str_buffer(channel_event_string));
+
+       ast_free(channel_event_string);
 }
 
 static void manager_channels_shutdown(void)
 {
-       stasis_unsubscribe(topic_forwarder);
+       stasis_forward_cancel(topic_forwarder);
        topic_forwarder = NULL;
 }
 
@@ -1262,7 +1243,7 @@ int manager_channels_init(void)
        if (!message_router) {
                return -1;
        }
-       channel_topic = stasis_caching_get_topic(ast_channel_topic_all_cached());
+       channel_topic = ast_channel_topic_all();
        if (!channel_topic) {
                return -1;
        }
@@ -1272,92 +1253,56 @@ int manager_channels_init(void)
                return -1;
        }
 
-       ast_register_atexit(manager_channels_shutdown);
-
-       ret |= stasis_message_router_add(message_router,
-                                        stasis_cache_update_type(),
-                                        channel_snapshot_update,
-                                        NULL);
+       ast_register_cleanup(manager_channels_shutdown);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_varset_type(),
-                                        channel_varset_cb,
-                                        NULL);
+               ast_channel_snapshot_type(), channel_snapshot_update, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_user_event_type(),
-                                        channel_user_event_cb,
-                                        NULL);
+               ast_channel_dtmf_begin_type(), channel_dtmf_begin_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_dtmf_begin_type(),
-                                        channel_dtmf_begin_cb,
-                                        NULL);
+               ast_channel_dtmf_end_type(), channel_dtmf_end_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_dtmf_end_type(),
-                                        channel_dtmf_end_cb,
-                                        NULL);
+               ast_channel_hangup_request_type(), channel_hangup_request_cb,
+               NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_hangup_request_type(),
-                                        channel_hangup_request_cb,
-                                        NULL);
+               ast_channel_dial_type(), channel_dial_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_dial_type(),
-                                        channel_dial_cb,
-                                        NULL);
+               ast_channel_hold_type(), channel_hold_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_hold_type(),
-                                        channel_hold_cb,
-                                        NULL);
+               ast_channel_unhold_type(), channel_unhold_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_unhold_type(),
-                                        channel_unhold_cb,
-                                        NULL);
+               ast_channel_fax_type(), channel_fax_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_fax_type(),
-                                        channel_fax_cb,
-                                        NULL);
+               ast_channel_chanspy_start_type(), channel_chanspy_start_cb,
+               NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_chanspy_start_type(),
-                                        channel_chanspy_start_cb,
-                                        NULL);
+               ast_channel_chanspy_stop_type(), channel_chanspy_stop_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_chanspy_stop_type(),
-                                        channel_chanspy_stop_cb,
-                                        NULL);
+               ast_channel_hangup_handler_type(), channel_hangup_handler_cb,
+               NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_hangup_handler_type(),
-                                        channel_hangup_handler_cb,
-                                        NULL);
+               ast_channel_moh_start_type(), channel_moh_start_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_moh_start_type(),
-                                        channel_moh_start_cb,
-                                        NULL);
+               ast_channel_moh_stop_type(), channel_moh_stop_cb, NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_moh_stop_type(),
-                                        channel_moh_stop_cb,
-                                        NULL);
+               ast_channel_monitor_start_type(), channel_monitor_start_cb,
+               NULL);
 
        ret |= stasis_message_router_add(message_router,
-                                        ast_channel_monitor_start_type(),
-                                        channel_monitor_start_cb,
-                                        NULL);
-
-       ret |= stasis_message_router_add(message_router,
-                                        ast_channel_monitor_stop_type(),
-                                        channel_monitor_stop_cb,
-                                        NULL);
+               ast_channel_monitor_stop_type(), channel_monitor_stop_cb, NULL);
 
        /* If somehow we failed to add any routes, just shut down the whole
         * thing and fail it.
@@ -1369,4 +1314,3 @@ int manager_channels_init(void)
 
        return 0;
 }
-