[asterisk-commits] kmoore: branch kmoore/stasis-bridge_events r385814 - in /team/kmoore/stasis-b...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 15 14:39:12 CDT 2013


Author: kmoore
Date: Mon Apr 15 14:39:08 2013
New Revision: 385814

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385814
Log:
Multiple revisions 385785,385813

........
  r385785 | kmoore | 2013-04-15 12:32:25 -0500 (Mon, 15 Apr 2013) | 75 lines
  
  Multiple revisions 385720,385747
  
  ........
    r385720 | root | 2013-04-15 11:17:21 -0500 (Mon, 15 Apr 2013) | 15 lines
    
    Fix the svn:keywords property on several files.
    
    Normally I think keyword expansion is silly, but the one time it would have
    been good, it didn't work because the property had quotes in it. This patch
    fixes obviously busted svn:keywords properties.
    ........
    
    Merged revisions 385683 from http://svn.asterisk.org/svn/asterisk/branches/1.8
    ........
    
    Merged revisions 385689 from http://svn.asterisk.org/svn/asterisk/branches/11
    ........
    
    Merged revisions 385718 from file:///srv/subversion/repos/asterisk/trunk
  ........
    r385747 | root | 2013-04-15 12:17:20 -0500 (Mon, 15 Apr 2013) | 50 lines
    
    Multiple revisions 385734,385742-385743
    
    ........
      r385734 | dlee | 2013-04-15 11:22:03 -0500 (Mon, 15 Apr 2013) | 16 lines
      
      DTMF events are now published on a channel's stasis_topic. AMI was
      refactored to use these events rather than producing the events directly
      in channel.c. Finally, the code was added to app_stasis to produce
      DTMF events on the WebSocket.
      
      The AMI events are completely backward compatible, including sending
      events on transmitted DTMF, and sending DTMF start events.
      
      The Stasis-HTTP events are somewhat simplified. Since DTMF start and
      DTMF send events are generally less useful, Stasis-HTTP will only send
      events on received DTMF end.
      
      (closes issue ASTERISK-21282)
      (closes issue ASTERISK-21359)
      Review: https://reviewboard.asterisk.org/r/2439
    ........
      r385742 | dlee | 2013-04-15 11:43:47 -0500 (Mon, 15 Apr 2013) | 20 lines
      
      Moved core logic from app_stasis to res_stasis
      
      After some discussion on asterisk-dev, it was decided that the bulk of
      the logic in app_stasis actually belongs in a resource module instead
      of the application module.
      
      This patch does that, leaves the app specific stuff in app_stasis, and
      fixes up everything else to be consistent with that change.
      
       * Renamed test_app_stasis to test_res_stasis
       * Renamed app_stasis.h to stasis_app.h
         * This is still stasis application support, even though it's no
           longer in an app_ module. The name should never have been tied to
           the type of module, anyways.
       * Now that json isn't a resource module anymore, moved the
         ast_channel_snapshot_to_json function to main/stasis_channels.c,
         where it makes more sense.
      
      Review: https://reviewboard.asterisk.org/r/2430/
    ........
      r385743 | dlee | 2013-04-15 11:47:25 -0500 (Mon, 15 Apr 2013) | 1 line
      
      Avoid unused variable warning when not in devmode
    ........
    
    Merged revisions 385734,385742-385743 from file:///srv/subversion/repos/asterisk/trunk
  ........
  
  Merged revisions 385720,385747 from http://svn.asterisk.org/svn/asterisk/team/group/bridge_construction
........
  r385813 | kmoore | 2013-04-15 14:35:28 -0500 (Mon, 15 Apr 2013) | 2 lines
  
  Re-apply changes from app_stasis to res_stasis with enhancements in dealing with channel blob messages
........

Merged revisions 385785,385813 from http://svn.asterisk.org/svn/asterisk/team/kmoore/stasis-bridging-channel_events

Added:
    team/kmoore/stasis-bridge_events/include/asterisk/stasis_app.h
      - copied unchanged from r385813, team/kmoore/stasis-bridging-channel_events/include/asterisk/stasis_app.h
    team/kmoore/stasis-bridge_events/res/res_stasis.c
      - copied unchanged from r385813, team/kmoore/stasis-bridging-channel_events/res/res_stasis.c
    team/kmoore/stasis-bridge_events/res/res_stasis.exports.in
      - copied unchanged from r385813, team/kmoore/stasis-bridging-channel_events/res/res_stasis.exports.in
    team/kmoore/stasis-bridge_events/tests/test_res_stasis.c
      - copied unchanged from r385813, team/kmoore/stasis-bridging-channel_events/tests/test_res_stasis.c
Removed:
    team/kmoore/stasis-bridge_events/apps/app_stasis.c
    team/kmoore/stasis-bridge_events/apps/app_stasis.exports.in
    team/kmoore/stasis-bridge_events/apps/stasis_json.c
    team/kmoore/stasis-bridge_events/include/asterisk/app_stasis.h
    team/kmoore/stasis-bridge_events/tests/test_app_stasis.c
Modified:
    team/kmoore/stasis-bridge_events/   (props changed)
    team/kmoore/stasis-bridge_events/BSDmakefile   (props changed)
    team/kmoore/stasis-bridge_events/apps/Makefile
    team/kmoore/stasis-bridge_events/apps/app_saycounted.c   (props changed)
    team/kmoore/stasis-bridge_events/build_tools/sha1sum-sh   (props changed)
    team/kmoore/stasis-bridge_events/channels/chan_multicast_rtp.c   (props changed)
    team/kmoore/stasis-bridge_events/channels/sig_ss7.c   (props changed)
    team/kmoore/stasis-bridge_events/channels/sig_ss7.h   (props changed)
    team/kmoore/stasis-bridge_events/channels/sip/include/security_events.h   (props changed)
    team/kmoore/stasis-bridge_events/channels/sip/security_events.c   (props changed)
    team/kmoore/stasis-bridge_events/configs/res_curl.conf.sample   (props changed)
    team/kmoore/stasis-bridge_events/contrib/realtime/mysql/musiconhold.sql   (props changed)
    team/kmoore/stasis-bridge_events/contrib/realtime/mysql/queue_log.sql   (props changed)
    team/kmoore/stasis-bridge_events/contrib/realtime/mysql/voicemail_data.sql   (props changed)
    team/kmoore/stasis-bridge_events/contrib/realtime/mysql/voicemail_messages.sql   (props changed)
    team/kmoore/stasis-bridge_events/doc/Makefile   (props changed)
    team/kmoore/stasis-bridge_events/include/asterisk/bridging_features.h   (props changed)
    team/kmoore/stasis-bridge_events/include/asterisk/bridging_technology.h   (props changed)
    team/kmoore/stasis-bridge_events/include/asterisk/cli.h
    team/kmoore/stasis-bridge_events/include/asterisk/json.h
    team/kmoore/stasis-bridge_events/include/asterisk/select.h   (props changed)
    team/kmoore/stasis-bridge_events/include/asterisk/stasis_channels.h
    team/kmoore/stasis-bridge_events/include/asterisk/strings.h
    team/kmoore/stasis-bridge_events/main/channel.c
    team/kmoore/stasis-bridge_events/main/json.c
    team/kmoore/stasis-bridge_events/main/manager_channels.c
    team/kmoore/stasis-bridge_events/main/stasis_channels.c
    team/kmoore/stasis-bridge_events/res/res_mutestream.c   (contents, props changed)
    team/kmoore/stasis-bridge_events/res/res_rtp_multicast.c   (props changed)
    team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c
    team/kmoore/stasis-bridge_events/res/res_timing_kqueue.c   (props changed)
    team/kmoore/stasis-bridge_events/tests/test_expr.c   (props changed)
    team/kmoore/stasis-bridge_events/tests/test_func_file.c   (props changed)
    team/kmoore/stasis-bridge_events/tests/test_json.c
    team/kmoore/stasis-bridge_events/tests/test_locale.c   (props changed)
    team/kmoore/stasis-bridge_events/tests/test_poll.c   (props changed)
    team/kmoore/stasis-bridge_events/tests/test_stasis_channels.c

Propchange: team/kmoore/stasis-bridge_events/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Propchange: team/kmoore/stasis-bridge_events/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-/team/kmoore/stasis-bridging-channel_events:1-385709
+/team/kmoore/stasis-bridging-channel_events:1-385813

Propchange: team/kmoore/stasis-bridge_events/BSDmakefile
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Modified: team/kmoore/stasis-bridge_events/apps/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/apps/Makefile?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/apps/Makefile (original)
+++ team/kmoore/stasis-bridge_events/apps/Makefile Mon Apr 15 14:39:08 2013
@@ -37,5 +37,3 @@
   LIBS+= -lres_features.so -lres_ael_share.so -lres_monitor.so -lres_speech.so
   LIBS+= -lres_smdi.so
 endif
-
-app_stasis.so: stasis_json.o

Propchange: team/kmoore/stasis-bridge_events/apps/app_saycounted.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/build_tools/sha1sum-sh
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/channels/chan_multicast_rtp.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Author Date Id Revision'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/channels/sig_ss7.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Author Date Id Revision'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/channels/sig_ss7.h
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Author Date Id Revision'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/channels/sip/include/security_events.h
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-"Author Date Id Rev URL"
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/channels/sip/security_events.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-"Author Date Id Rev URL"
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/configs/res_curl.conf.sample
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/contrib/realtime/mysql/musiconhold.sql
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/contrib/realtime/mysql/queue_log.sql
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/contrib/realtime/mysql/voicemail_data.sql
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/contrib/realtime/mysql/voicemail_messages.sql
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/doc/Makefile
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/include/asterisk/bridging_features.h
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Author Date Id Revision'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/include/asterisk/bridging_technology.h
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Author Date Id Revision'
+Author Date Id Revision

Modified: team/kmoore/stasis-bridge_events/include/asterisk/cli.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/include/asterisk/cli.h?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/cli.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/cli.h Mon Apr 15 14:39:08 2013
@@ -28,6 +28,7 @@
 #endif
 
 #include "asterisk/linkedlists.h"
+#include "asterisk/strings.h"
 
 void ast_cli(int fd, const char *fmt, ...)
 	__attribute__((format(printf, 2, 3)));
@@ -57,12 +58,17 @@
  */
 #define ESS(x) ((x) == 1 ? "" : "s")
 
-/*! \brief return Yes or No depending on the argument.
- * This is used in many places in CLI command, having a function to generate
- * this helps maintaining a consistent output (and possibly emitting the
- * output in other languages, at some point).
- */
-#define AST_CLI_YESNO(x) (x) ? "Yes" : "No"
+/*!
+ * \brief Return Yes or No depending on the argument.
+ *
+ * Note that this should probably still be used for CLI commands instead of
+ * AST_YESNO(), in the off chance we someday want to translate the CLI.
+ *
+ * \param x Boolean value
+ * \return "Yes" if x is true (non-zero)
+ * \return "No" if x is false (zero)
+ */
+#define AST_CLI_YESNO(x) AST_YESNO(x)
 
 /*! \brief return On or Off depending on the argument.
  * This is used in many places in CLI command, having a function to generate

Modified: team/kmoore/stasis-bridge_events/include/asterisk/json.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/include/asterisk/json.h?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/json.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/json.h Mon Apr 15 14:39:08 2013
@@ -791,7 +791,7 @@
  * \return JSON string with ISO 8601 formatted date/time.
  * \return \c NULL on error.
  */
-struct ast_json *ast_json_timeval(const struct timeval *tv, const char *zone);
+struct ast_json *ast_json_timeval(const struct timeval tv, const char *zone);
 
 /*!
  * \brief Construct a context/exten/priority as JSON.

Propchange: team/kmoore/stasis-bridge_events/include/asterisk/select.h
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Modified: team/kmoore/stasis-bridge_events/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/include/asterisk/stasis_channels.h?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/stasis_channels.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/stasis_channels.h Mon Apr 15 14:39:08 2013
@@ -292,6 +292,13 @@
 /*! @} */
 
 /*!
+ * \brief Build a JSON object from a \ref ast_channel_snapshot.
+ * \return JSON object representing channel snapshot.
+ * \return \c NULL on error
+ */
+struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot);
+
+/*!
  * \brief Dispose of the stasis channel topics and message types
  */
 void ast_stasis_channels_shutdown(void);

Modified: team/kmoore/stasis-bridge_events/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/include/asterisk/strings.h?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/strings.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/strings.h Mon Apr 15 14:39:08 2013
@@ -84,6 +84,18 @@
 #define S_COR(a, b, c) ({typeof(&((b)[0])) __x = (b); (a) && !ast_strlen_zero(__x) ? (__x) : (c);})
 
 /*!
+ * \brief return Yes or No depending on the argument.
+ *
+ * Note that this macro is used my AMI, where a literal "Yes" and "No" are
+ * expected, and translations would cause problems.
+ *
+ * \param x Boolean value
+ * \return "Yes" if x is true (non-zero)
+ * \return "No" if x is false (zero)
+ */
+#define AST_YESNO(x) ((x) ? "Yes" : "No")
+
+/*!
   \brief Gets a pointer to the first non-whitespace character in a string.
   \param str the input string
   \return a pointer to the first non-whitespace character

Modified: team/kmoore/stasis-bridge_events/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/channel.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/main/channel.c (original)
+++ team/kmoore/stasis-bridge_events/main/channel.c Mon Apr 15 14:39:08 2013
@@ -3717,42 +3717,56 @@
 	return 0; /* Time is up */
 }
 
-static void send_dtmf_event(struct ast_channel *chan, const char *direction, const char digit, const char *begin, const char *end)
-{
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a DTMF digit has started or ended on a channel.</synopsis>
-				<syntax>
-					<parameter name="Direction">
-						<enumlist>
-							<enum name="Received"/>
-							<enum name="Sent"/>
-						</enumlist>
-					</parameter>
-					<parameter name="Begin">
-						<enumlist>
-							<enum name="Yes"/>
-							<enum name="No"/>
-						</enumlist>
-					</parameter>
-					<parameter name="End">
-						<enumlist>
-							<enum name="Yes"/>
-							<enum name="No"/>
-						</enumlist>
-					</parameter>
-				</syntax>
-		</managerEventInstance>
-	***/
-	ast_manager_event(chan, EVENT_FLAG_DTMF,
-			"DTMF",
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"Digit: %c\r\n"
-			"Direction: %s\r\n"
-			"Begin: %s\r\n"
-			"End: %s\r\n",
-			ast_channel_name(chan), ast_channel_uniqueid(chan), digit, direction, begin, end);
+enum DtmfDirection {
+	DTMF_RECEIVED,
+	DTMF_SENT
+};
+
+static const char *dtmf_direction_to_string(enum DtmfDirection direction)
+{
+	switch (direction) {
+	case DTMF_RECEIVED:
+		return "Received";
+	case DTMF_SENT:
+		return "Sent";
+	}
+
+	return "?";
+}
+
+static void send_dtmf_begin_event(struct ast_channel *chan,
+	enum DtmfDirection direction, const char digit)
+{
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	char digit_str[] = { digit, '\0' };
+
+	blob = ast_json_pack("{ s: s, s: s, s: s }",
+		"type", "dtmf_begin",
+		"digit", digit_str,
+		"direction", dtmf_direction_to_string(direction));
+	if (!blob) {
+		return;
+	}
+
+	publish_channel_blob(chan, blob);
+}
+
+static void send_dtmf_end_event(struct ast_channel *chan,
+	enum DtmfDirection direction, const char digit, long duration_ms)
+{
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	char digit_str[] = { digit, '\0' };
+
+	blob = ast_json_pack("{ s: s, s: s, s: s, s: i }",
+		"type", "dtmf_end",
+		"digit", digit_str,
+		"direction", dtmf_direction_to_string(direction),
+		"duration_ms", duration_ms);
+	if (!blob) {
+		return;
+	}
+
+	publish_channel_blob(chan, blob);
 }
 
 static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
@@ -4107,7 +4121,7 @@
 			}
 			break;
 		case AST_FRAME_DTMF_END:
-			send_dtmf_event(chan, "Received", f->subclass.integer, "No", "Yes");
+			send_dtmf_end_event(chan, DTMF_RECEIVED, f->subclass.integer, f->len);
 			ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass.integer, ast_channel_name(chan), f->len);
 			/* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
 			if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF) || ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF)) {
@@ -4193,7 +4207,7 @@
 			}
 			break;
 		case AST_FRAME_DTMF_BEGIN:
-			send_dtmf_event(chan, "Received", f->subclass.integer, "Yes", "No");
+			send_dtmf_begin_event(chan, DTMF_RECEIVED, f->subclass.integer);
 			ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass.integer, ast_channel_name(chan));
 			if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) ||
 			    (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
@@ -5045,7 +5059,7 @@
 			if (old_frame != fr)
 				f = fr;
 		}
-		send_dtmf_event(chan, "Sent", fr->subclass.integer, "Yes", "No");
+		send_dtmf_begin_event(chan, DTMF_SENT, fr->subclass.integer);
 		ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
 		ast_channel_unlock(chan);
 		res = ast_senddigit_begin(chan, fr->subclass.integer);
@@ -5061,7 +5075,7 @@
 				ast_frfree(new_frame);
 			}
 		}
-		send_dtmf_event(chan, "Sent", fr->subclass.integer, "No", "Yes");
+		send_dtmf_end_event(chan, DTMF_SENT, fr->subclass.integer, fr->len);
 		ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
 		ast_channel_unlock(chan);
 		res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);

Modified: team/kmoore/stasis-bridge_events/main/json.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/json.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/main/json.c (original)
+++ team/kmoore/stasis-bridge_events/main/json.c Mon Apr 15 14:39:08 2013
@@ -519,16 +519,12 @@
 			     "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
 }
 
-struct ast_json *ast_json_timeval(const struct timeval *tv, const char *zone)
+struct ast_json *ast_json_timeval(const struct timeval tv, const char *zone)
 {
 	char buf[AST_ISO8601_LEN];
 	struct ast_tm tm = {};
 
-	if (tv == NULL) {
-		return NULL;
-	}
-
-	ast_localtime(tv, &tm, zone);
+	ast_localtime(&tv, &tm, zone);
 
 	ast_strftime(buf, sizeof(buf),AST_ISO8601_FORMAT, &tm);
 

Modified: team/kmoore/stasis-bridge_events/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/manager_channels.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/main/manager_channels.c (original)
+++ team/kmoore/stasis-bridge_events/main/manager_channels.c Mon Apr 15 14:39:08 2013
@@ -275,8 +275,8 @@
 		struct ast_var_t *var;
 		AST_LIST_TRAVERSE(snapshot->manager_vars, var, entries) {
 			ast_str_append(&out, 0, "ChanVariable%s: %s=%s\r\n",
-						   suffix,
-						   var->name, var->value);
+				       suffix,
+				       var->name, var->value);
 		}
 	}
 
@@ -592,6 +592,90 @@
 		      ast_str_buffer(extra));
 }
 
+static void channel_dtmf_begin(struct ast_channel_blob *obj)
+{
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	const char *digit =
+		ast_json_string_get(ast_json_object_get(obj->blob, "digit"));
+	const char *direction =
+		ast_json_string_get(ast_json_object_get(obj->blob, "direction"));
+
+	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+
+	if (!channel_event_string) {
+		return;
+	}
+
+	/*** DOCUMENTATION
+		<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)" />
+					<parameter name="Digit">
+						<para>DTMF digit received or transmitted (0-9, A-E, # or *</para>
+					</parameter>
+					<parameter name="Direction">
+						<enumlist>
+							<enum name="Received"/>
+							<enum name="Sent"/>
+						</enumlist>
+					</parameter>
+				</syntax>
+		</managerEventInstance>
+	***/
+	manager_event(EVENT_FLAG_DTMF, "DTMFBegin",
+		"%s"
+		"Digit: %s\r\n"
+		"Direction: %s\r\n",
+		ast_str_buffer(channel_event_string),
+		digit, direction);
+}
+
+static void channel_dtmf_end(struct ast_channel_blob *obj)
+{
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	const char *digit =
+		ast_json_string_get(ast_json_object_get(obj->blob, "digit"));
+	const char *direction =
+		ast_json_string_get(ast_json_object_get(obj->blob, "direction"));
+	long duration_ms =
+		ast_json_integer_get(ast_json_object_get(obj->blob, "duration_ms"));
+
+	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+
+	if (!channel_event_string) {
+		return;
+	}
+
+	/*** DOCUMENTATION
+		<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)" />
+					<parameter name="Digit">
+						<para>DTMF digit received or transmitted (0-9, A-E, # or *</para>
+					</parameter>
+					<parameter name="DurationMs">
+						<para>Duration (in milliseconds) DTMF was sent/received</para>
+					</parameter>
+					<parameter name="Direction">
+						<enumlist>
+							<enum name="Received"/>
+							<enum name="Sent"/>
+						</enumlist>
+					</parameter>
+				</syntax>
+		</managerEventInstance>
+	***/
+	manager_event(EVENT_FLAG_DTMF, "DTMFEnd",
+		"%s"
+		"Digit: %s\r\n"
+		"DurationMs: %ld\r\n"
+		"Direction: %s\r\n",
+		ast_str_buffer(channel_event_string),
+		digit, duration_ms, direction);
+}
+
 /*!
  * \brief Callback processing messages on the channel topic.
  */
@@ -607,6 +691,10 @@
 		channel_userevent(obj);
 	} else if (strcmp("hangup_request", ast_channel_blob_json_type(obj)) == 0) {
 		channel_hangup_request(obj);
+	} else if (strcmp("dtmf_begin", ast_channel_blob_json_type(obj)) == 0) {
+		channel_dtmf_begin(obj);
+	} else if (strcmp("dtmf_end", ast_channel_blob_json_type(obj)) == 0) {
+		channel_dtmf_end(obj);
 	}
 }
 

Modified: team/kmoore/stasis-bridge_events/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/stasis_channels.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/main/stasis_channels.c (original)
+++ team/kmoore/stasis-bridge_events/main/stasis_channels.c Mon Apr 15 14:39:08 2013
@@ -458,6 +458,37 @@
 	publish_message_for_channel_topics(msg, chan);
 }
 
+struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot)
+{
+	RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);
+
+	if (snapshot == NULL) {
+		return NULL;
+	}
+
+	json_chan = ast_json_pack("{ s: s, s: s, s: s, s: s, s: s, s: s, s: s,"
+				  "  s: s, s: s, s: s, s: s, s: o, s: o, s: o,"
+				  "  s: o"
+				  "}",
+				  "name", snapshot->name,
+				  "state", ast_state2str(snapshot->state),
+				  "accountcode", snapshot->accountcode,
+				  "peeraccount", snapshot->peeraccount,
+				  "userfield", snapshot->userfield,
+				  "uniqueid", snapshot->uniqueid,
+				  "linkedid", snapshot->linkedid,
+				  "parkinglot", snapshot->parkinglot,
+				  "hangupsource", snapshot->hangupsource,
+				  "appl", snapshot->appl,
+				  "data", snapshot->data,
+				  "dialplan", ast_json_dialplan_cep(snapshot->context, snapshot->exten, snapshot->priority),
+				  "caller", ast_json_name_number(snapshot->caller_name, snapshot->caller_number),
+				  "connected", ast_json_name_number(snapshot->connected_name, snapshot->connected_number),
+				  "creationtime", ast_json_timeval(snapshot->creationtime, NULL));
+
+	return ast_json_ref(json_chan);
+}
+
 void ast_stasis_channels_shutdown(void)
 {
 	ao2_cleanup(channel_snapshot_type);

Modified: team/kmoore/stasis-bridge_events/res/res_mutestream.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/res/res_mutestream.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/res/res_mutestream.c (original)
+++ team/kmoore/stasis-bridge_events/res/res_mutestream.c Mon Apr 15 14:39:08 2013
@@ -35,7 +35,7 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89545 $")
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/options.h"
 #include "asterisk/logger.h"

Propchange: team/kmoore/stasis-bridge_events/res/res_mutestream.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-"Author Date Id Revision"
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/res/res_rtp_multicast.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Author Date Id Revision'
+Author Date Id Revision

Modified: team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c (original)
+++ team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c Mon Apr 15 14:39:08 2013
@@ -24,7 +24,7 @@
  */
 
 /*** MODULEINFO
-	<depend type="module">app_stasis</depend>
+	<depend type="module">res_stasis</depend>
 	<depend type="module">res_http_websocket</depend>
 	<support_level>core</support_level>
  ***/
@@ -33,11 +33,11 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include "asterisk/app_stasis.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/http_websocket.h"
 #include "asterisk/json.h"
 #include "asterisk/module.h"
+#include "asterisk/stasis_app.h"
 #include "asterisk/strings.h"
 #include "asterisk/utils.h"
 
@@ -81,7 +81,9 @@
 
 static void session_dtor(void *obj)
 {
+#ifdef AST_DEVMODE /* Avoid unused variable warning */
 	struct stasis_ws_session_info *session = obj;
+#endif
 
 	/* session_shutdown should have been called before */
 	ast_assert(session->ws_session == NULL);
@@ -284,6 +286,6 @@
 AST_MODULE_INFO(ASTERISK_GPL_KEY, 0, "Stasis HTTP bindings",
                 .load = load_module,
                 .unload = unload_module,
-                .nonoptreq = "app_stasis,res_http_websocket",
+                .nonoptreq = "res_stasis,res_http_websocket",
                 .load_pri = AST_MODPRI_APP_DEPEND,
         );

Propchange: team/kmoore/stasis-bridge_events/res/res_timing_kqueue.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/tests/test_expr.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/tests/test_func_file.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Modified: team/kmoore/stasis-bridge_events/tests/test_json.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/tests/test_json.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/tests/test_json.c (original)
+++ team/kmoore/stasis-bridge_events/tests/test_json.c Mon Apr 15 14:39:08 2013
@@ -1659,12 +1659,11 @@
 		break;
 	}
 
-	ast_test_validate(test, NULL == ast_json_timeval(NULL, NULL));
 	expected = ast_json_string_create("2013-02-07T09:32:34.314-0600");
 
 	tv.tv_sec = 1360251154;
 	tv.tv_usec = 314159;
-	uut = ast_json_timeval(&tv, "America/Chicago");
+	uut = ast_json_timeval(tv, "America/Chicago");
 
 	ast_test_validate(test, ast_json_equal(expected, uut));
 

Propchange: team/kmoore/stasis-bridge_events/tests/test_locale.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/tests/test_poll.c
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Apr 15 14:39:08 2013
@@ -1,1 +1,1 @@
-'Date Author Id Revision Yoyo'
+Author Date Id Revision

Modified: team/kmoore/stasis-bridge_events/tests/test_stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/tests/test_stasis_channels.c?view=diff&rev=385814&r1=385813&r2=385814
==============================================================================
--- team/kmoore/stasis-bridge_events/tests/test_stasis_channels.c (original)
+++ team/kmoore/stasis-bridge_events/tests/test_stasis_channels.c Mon Apr 15 14:39:08 2013
@@ -199,11 +199,76 @@
 	return AST_TEST_PASS;
 }
 
+AST_TEST_DEFINE(channel_snapshot_json)
+{
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
+	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json *, actual, NULL, ast_json_unref);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = test_category;
+		info->summary = "Test creation of ast_channel_blob objects";
+		info->description = "Test creation of ast_channel_blob objects";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	ast_test_validate(test, NULL == ast_channel_snapshot_to_json(NULL));
+
+	chan = ast_channel_alloc(0, AST_STATE_DOWN, "cid_num", "cid_name", "acctcode", "exten", "context", NULL, 0, "TEST/name");
+	ast_test_validate(test, NULL != chan);
+	snapshot = ast_channel_snapshot_create(chan);
+	ast_test_validate(test, NULL != snapshot);
+
+	actual = ast_channel_snapshot_to_json(snapshot);
+	expected = ast_json_pack("{ s: s, s: s, s: s, s: s, s: s, s: s, s: s,"
+				 "  s: s, s: s, s: s, s: s,"
+				 "  s: { s: s, s: s, s: i },"
+				 "  s: { s: s, s: s },"
+				 "  s: { s: s, s: s },"
+				 "  s: o"
+				 "}",
+				 "name", "TEST/name",
+				 "state", "Down",
+				 "accountcode", "acctcode",
+				 "peeraccount", "",
+				 "userfield", "",
+				 "uniqueid", ast_channel_uniqueid(chan),
+				 "linkedid", ast_channel_uniqueid(chan),
+				 "parkinglot", "",
+				 "hangupsource", "",
+				 "appl", "",
+				 "data", "",
+				 "dialplan",
+				 "context", "context",
+				 "exten", "exten",
+				 "priority", 1,
+				 "caller",
+				 "name", "cid_name",
+				 "number", "cid_num",
+				 "connected",
+				 "name", "",
+				 "number", "",
+				 "creationtime",
+				 ast_json_timeval(
+					 ast_channel_creationtime(chan), NULL));
+
+	ast_test_validate(test, ast_json_equal(expected, actual));
+
+	return AST_TEST_PASS;
+}
+
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(channel_blob_create);
 	AST_TEST_UNREGISTER(multi_channel_blob_create);
 	AST_TEST_UNREGISTER(multi_channel_blob_snapshots);
+	AST_TEST_UNREGISTER(channel_snapshot_json);
 
 	return 0;
 }
@@ -213,6 +278,7 @@
 	AST_TEST_REGISTER(channel_blob_create);
 	AST_TEST_REGISTER(multi_channel_blob_create);
 	AST_TEST_REGISTER(multi_channel_blob_snapshots);
+	AST_TEST_REGISTER(channel_snapshot_json);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }




More information about the asterisk-commits mailing list