[asterisk-commits] dlee: branch dlee/playback-rebase r388348 - in /team/dlee/playback-rebase: in...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 10 12:00:17 CDT 2013
Author: dlee
Date: Fri May 10 12:00:15 2013
New Revision: 388348
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388348
Log:
Merged playback-only changes from playback branch
Added:
team/dlee/playback-rebase/include/asterisk/stasis_app_playback.h
- copied unchanged from r388346, team/dlee/playback/include/asterisk/stasis_app_playback.h
team/dlee/playback-rebase/res/res_stasis_playback.c
- copied unchanged from r388346, team/dlee/playback/res/res_stasis_playback.c
team/dlee/playback-rebase/res/res_stasis_playback.exports.in
- copied unchanged from r388346, team/dlee/playback/res/res_stasis_playback.exports.in
Modified:
team/dlee/playback-rebase/include/asterisk/stasis_channels.h
team/dlee/playback-rebase/include/asterisk/stasis_http.h
team/dlee/playback-rebase/main/channel.c
team/dlee/playback-rebase/main/channel_internal_api.c
team/dlee/playback-rebase/main/stasis_channels.c
team/dlee/playback-rebase/res/res_stasis_http.c
team/dlee/playback-rebase/res/res_stasis_http_channels.c
team/dlee/playback-rebase/res/res_stasis_http_events.c
team/dlee/playback-rebase/res/stasis_http/resource_channels.c
team/dlee/playback-rebase/res/stasis_http/resource_channels.h
team/dlee/playback-rebase/res/stasis_http/resource_events.h
team/dlee/playback-rebase/res/stasis_http/resource_playback.c
team/dlee/playback-rebase/rest-api/api-docs/channels.json
team/dlee/playback-rebase/rest-api/api-docs/events.json
Modified: team/dlee/playback-rebase/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/include/asterisk/stasis_channels.h?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/include/asterisk/stasis_channels.h (original)
+++ team/dlee/playback-rebase/include/asterisk/stasis_channels.h Fri May 10 12:00:15 2013
@@ -54,6 +54,7 @@
AST_STRING_FIELD(caller_number); /*!< Caller ID Number */
AST_STRING_FIELD(connected_name); /*!< Connected Line Name */
AST_STRING_FIELD(connected_number); /*!< Connected Line Number */
+ AST_STRING_FIELD(language); /*!< The default spoken language for the channel */
);
struct timeval creationtime; /*!< The time of channel creation */
@@ -124,6 +125,17 @@
/*!
* \since 12
+ * \brief Get the most recent snapshot for channel with the given \a uniqueid.
+ *
+ * \param uniqueid Uniqueid of the snapshot to fetch.
+ * \return Most recent channel snapshot
+ * \return \c NULL on error
+ */
+struct ast_channel_snapshot *ast_channel_snapshot_get_latest(
+ const char *uniqueid);
+
+/*!
+ * \since 12
* \brief Creates a \ref ast_channel_blob message.
*
* The given \a blob should be treated as immutable and not modified after it is
@@ -139,6 +151,23 @@
*/
struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
struct stasis_message_type *type, struct ast_json *blob);
+
+/*!
+ * \since 12
+ * \brief Create a \ref ast_channel_blob message, pulling channel state from
+ * the cache.
+ *
+ * \param uniqueid Uniqueid of the channel.
+ * \param type Message type for this blob.
+ * \param blob JSON object representing the data, or \c NULL for no data. If
+ * \c NULL, ast_json_null() is put into the object.
+ *
+ * \return \ref ast_channel_blob message.
+ * \return \c NULL on error
+ */
+struct stasis_message *ast_channel_blob_create_from_cache(
+ const char *uniqueid, struct stasis_message_type *type,
+ struct ast_json *blob);
/*!
* \since 12
@@ -220,6 +249,14 @@
*/
void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj,
const char *role, struct ast_channel_snapshot *snapshot);
+
+/*!
+ * \since 12
+ * \brief Publish a \ref ast_channel_snapshot for a channel.
+ *
+ * \param chan Channel to publish.
+ */
+void ast_channel_publish_snapshot(struct ast_channel *chan);
/*!
* \since 12
Modified: team/dlee/playback-rebase/include/asterisk/stasis_http.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/include/asterisk/stasis_http.h?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/include/asterisk/stasis_http.h (original)
+++ team/dlee/playback-rebase/include/asterisk/stasis_http.h Fri May 10 12:00:15 2013
@@ -163,6 +163,12 @@
void stasis_http_response_no_content(struct stasis_http_response *response);
/*!
+ * \brief Fill in a <tt>Created</tt> (201) \a stasis_http_response.
+ */
+void stasis_http_response_created(struct stasis_http_response *response,
+ const char *url);
+
+/*!
* \brief Fill in \a response with a 500 message for allocation failures.
* \param response Response to fill in.
*/
Modified: team/dlee/playback-rebase/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/main/channel.c?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/main/channel.c (original)
+++ team/dlee/playback-rebase/main/channel.c Fri May 10 12:00:15 2013
@@ -814,26 +814,6 @@
return causes[x].cause;
return -1;
-}
-
-static void publish_channel_state(struct ast_channel *chan)
-{
- RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-
- snapshot = ast_channel_snapshot_create(chan);
- if (!snapshot) {
- ast_log(LOG_ERROR, "Allocation error\n");
- return;
- }
-
- message = stasis_message_create(ast_channel_snapshot_type(), snapshot);
- if (!message) {
- return;
- }
-
- ast_assert(ast_channel_topic(chan) != NULL);
- stasis_publish(ast_channel_topic(chan), message);
}
static void publish_cache_clear(struct ast_channel *chan)
@@ -1176,7 +1156,7 @@
* a lot of data into this func to do it here!
*/
if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) {
- publish_channel_state(tmp);
+ ast_channel_publish_snapshot(tmp);
}
ast_channel_internal_finalize(tmp);
@@ -2885,7 +2865,7 @@
ast_cc_offer(chan);
- publish_channel_state(chan);
+ ast_channel_publish_snapshot(chan);
publish_cache_clear(chan);
if (ast_channel_cdr(chan) && !ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_BRIDGED) &&
@@ -7144,7 +7124,7 @@
ast_channel_redirecting_set(original, ast_channel_redirecting(clonechan));
ast_channel_redirecting_set(clonechan, &exchange.redirecting);
- publish_channel_state(original);
+ ast_channel_publish_snapshot(original);
/* Restore original timing file descriptor */
ast_channel_set_fd(original, AST_TIMING_FD, ast_channel_timingfd(original));
@@ -7310,7 +7290,7 @@
ast_cdr_setcid(ast_channel_cdr(chan), chan);
}
- publish_channel_state(chan);
+ ast_channel_publish_snapshot(chan);
ast_channel_unlock(chan);
}
@@ -7336,7 +7316,7 @@
ast_channel_lock(chan);
ast_party_caller_set(ast_channel_caller(chan), caller, update);
- publish_channel_state(chan);
+ ast_channel_publish_snapshot(chan);
if (ast_channel_cdr(chan)) {
ast_cdr_setcid(ast_channel_cdr(chan), chan);
}
@@ -7363,7 +7343,7 @@
* we override what they are saying the state is and things go amuck. */
ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), name);
- publish_channel_state(chan);
+ ast_channel_publish_snapshot(chan);
return 0;
}
Modified: team/dlee/playback-rebase/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/main/channel_internal_api.c?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/main/channel_internal_api.c (original)
+++ team/dlee/playback-rebase/main/channel_internal_api.c Fri May 10 12:00:15 2013
@@ -412,15 +412,17 @@
/* ACCESSORS */
-#define DEFINE_STRINGFIELD_SETTERS_FOR(field) \
+#define DEFINE_STRINGFIELD_SETTERS_FOR(field, publish) \
void ast_channel_##field##_set(struct ast_channel *chan, const char *value) \
{ \
ast_string_field_set(chan, field, value); \
+ if (publish) ast_channel_publish_snapshot(chan); \
} \
\
void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) \
{ \
ast_string_field_build_va(chan, field, fmt, ap); \
+ if (publish) ast_channel_publish_snapshot(chan); \
} \
void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) \
{ \
@@ -428,19 +430,20 @@
va_start(ap, fmt); \
ast_channel_##field##_build_va(chan, fmt, ap); \
va_end(ap); \
-}
-
-DEFINE_STRINGFIELD_SETTERS_FOR(name);
-DEFINE_STRINGFIELD_SETTERS_FOR(language);
-DEFINE_STRINGFIELD_SETTERS_FOR(musicclass);
-DEFINE_STRINGFIELD_SETTERS_FOR(accountcode);
-DEFINE_STRINGFIELD_SETTERS_FOR(peeraccount);
-DEFINE_STRINGFIELD_SETTERS_FOR(userfield);
-DEFINE_STRINGFIELD_SETTERS_FOR(call_forward);
-DEFINE_STRINGFIELD_SETTERS_FOR(uniqueid);
-DEFINE_STRINGFIELD_SETTERS_FOR(parkinglot);
-DEFINE_STRINGFIELD_SETTERS_FOR(hangupsource);
-DEFINE_STRINGFIELD_SETTERS_FOR(dialcontext);
+ if (publish) ast_channel_publish_snapshot(chan); \
+}
+
+DEFINE_STRINGFIELD_SETTERS_FOR(name, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(language, 1);
+DEFINE_STRINGFIELD_SETTERS_FOR(musicclass, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(accountcode, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(peeraccount, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(userfield, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(call_forward, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(uniqueid, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(parkinglot, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(hangupsource, 0);
+DEFINE_STRINGFIELD_SETTERS_FOR(dialcontext, 0);
#define DEFINE_STRINGFIELD_GETTER_FOR(field) const char *ast_channel_##field(const struct ast_channel *chan) \
{ \
Modified: team/dlee/playback-rebase/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/main/stasis_channels.c?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/main/stasis_channels.c (original)
+++ team/dlee/playback-rebase/main/stasis_channels.c Fri May 10 12:00:15 2013
@@ -134,6 +134,7 @@
S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, ""));
ast_string_field_set(snapshot, connected_number,
S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, ""));
+ ast_string_field_set(snapshot, language, ast_channel_language(chan));
snapshot->creationtime = ast_channel_creationtime(chan);
snapshot->state = ast_channel_state(chan);
@@ -149,6 +150,28 @@
return snapshot;
}
+struct ast_channel_snapshot *ast_channel_snapshot_get_latest(
+ const char *uniqueid)
+{
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct ast_channel_snapshot *snapshot;
+
+ msg = stasis_cache_get(ast_channel_topic_all_cached(),
+ ast_channel_snapshot_type(), uniqueid);
+
+ if (!msg) {
+ return NULL;
+ }
+
+ snapshot = stasis_message_data(msg);
+ if (!snapshot) {
+ return NULL;
+ }
+
+ ao2_ref(snapshot, +1);
+ return snapshot;
+}
+
static void publish_message_for_channel_topics(struct stasis_message *message, struct ast_channel *chan)
{
if (chan) {
@@ -208,37 +231,65 @@
publish_message_for_channel_topics(msg, caller);
}
+static struct stasis_message *channel_blob_create(
+ struct ast_channel_snapshot *snapshot,
+ struct stasis_message_type *type, struct ast_json *blob)
+{
+ RAII_VAR(struct ast_channel_blob *, obj, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+ if (blob == NULL) {
+ blob = ast_json_null();
+ }
+
+ obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
+ if (!obj) {
+ return NULL;
+ }
+
+ if (snapshot) {
+ ao2_ref(snapshot, +1);
+ obj->snapshot = snapshot;
+ }
+
+ obj->blob = ast_json_ref(blob);
+
+ msg = stasis_message_create(type, obj);
+ if (!msg) {
+ return NULL;
+ }
+
+ ao2_ref(msg, +1);
+ return msg;
+}
+
struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
struct stasis_message_type *type, struct ast_json *blob)
{
- RAII_VAR(struct ast_channel_blob *, obj, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
- if (blob == NULL) {
- blob = ast_json_null();
- }
-
- obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
- if (!obj) {
- return NULL;
- }
-
- if (chan) {
- obj->snapshot = ast_channel_snapshot_create(chan);
- if (obj->snapshot == NULL) {
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+
+ if (chan != NULL) {
+ snapshot = ast_channel_snapshot_create(chan);
+ if (snapshot == NULL) {
return NULL;
}
}
- obj->blob = ast_json_ref(blob);
-
- msg = stasis_message_create(type, obj);
- if (!msg) {
- return NULL;
- }
-
- ao2_ref(msg, +1);
- return msg;
+ return channel_blob_create(snapshot, type, blob);
+}
+
+struct stasis_message *ast_channel_blob_create_from_cache(
+ const char *uniqueid, struct stasis_message_type *type,
+ struct ast_json *blob)
+{
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+
+ snapshot = ast_channel_snapshot_get_latest(uniqueid);
+ if (snapshot == NULL) {
+ return NULL;
+ }
+
+ return channel_blob_create(snapshot, type, blob);
}
/*! \brief A channel snapshot wrapper object used in \ref ast_multi_channel_blob objects */
@@ -389,6 +440,27 @@
}
return obj->blob;
}
+
+void ast_channel_publish_snapshot(struct ast_channel *chan)
+{
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+
+ snapshot = ast_channel_snapshot_create(chan);
+ if (!snapshot) {
+ ast_log(LOG_ERROR, "Allocation error\n");
+ return;
+ }
+
+ message = stasis_message_create(ast_channel_snapshot_type(), snapshot);
+ if (!message) {
+ return;
+ }
+
+ ast_assert(ast_channel_topic(chan) != NULL);
+ stasis_publish(ast_channel_topic(chan), message);
+}
+
void ast_channel_publish_varset(struct ast_channel *chan, const char *name, const char *value)
{
Modified: team/dlee/playback-rebase/res/res_stasis_http.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/res/res_stasis_http.c?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/res/res_stasis_http.c (original)
+++ team/dlee/playback-rebase/res/res_stasis_http.c Fri May 10 12:00:15 2013
@@ -329,6 +329,15 @@
response->message = ast_json_ref(alloc_failed_message);
response->response_code = 500;
response->response_text = "Internal Server Error";
+}
+
+void stasis_http_response_created(struct stasis_http_response *response,
+ const char *url)
+{
+ response->message = ast_json_null();
+ response->response_code = 201;
+ response->response_text = "Created";
+ ast_str_append(&response->headers, 0, "Location: %s\r\n", url);
}
static void add_allow_header(struct stasis_rest_handlers *handler,
Modified: team/dlee/playback-rebase/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/res/res_stasis_http_channels.c?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/res/res_stasis_http_channels.c (original)
+++ team/dlee/playback-rebase/res/res_stasis_http_channels.c Fri May 10 12:00:15 2013
@@ -325,6 +325,9 @@
if (strcmp(i->name, "media") == 0) {
args.media = (i->value);
} else
+ if (strcmp(i->name, "lang") == 0) {
+ args.lang = (i->value);
+ } else
{}
}
for (i = path_vars; i; i = i->next) {
Modified: team/dlee/playback-rebase/res/res_stasis_http_events.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/res/res_stasis_http_events.c?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/res/res_stasis_http_events.c (original)
+++ team/dlee/playback-rebase/res/res_stasis_http_events.c Fri May 10 12:00:15 2013
@@ -77,6 +77,38 @@
.children = { }
};
+struct ast_json *stasis_json_event_playback_finished_create(
+ struct ast_json *blob
+ )
+{
+ RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
+ struct ast_json *validator;
+
+ ast_assert(blob != NULL);
+ ast_assert(ast_json_object_get(blob, "type") == NULL);
+
+ validator = ast_json_object_get(blob, "playback");
+ if (validator) {
+ /* do validation? XXX */
+ } else {
+ /* fail message generation if the required parameter doesn't exist */
+ return NULL;
+ }
+
+ event = ast_json_deep_copy(blob);
+ if (!event) {
+ return NULL;
+ }
+
+ message = ast_json_pack("{s: o}", "playback_finished", ast_json_ref(event));
+ if (!message) {
+ return NULL;
+ }
+
+ return ast_json_ref(message);
+}
+
struct ast_json *stasis_json_event_channel_snapshot_create(
struct ast_channel_snapshot *channel_snapshot
)
@@ -106,6 +138,120 @@
return ast_json_ref(message);
}
+struct ast_json *stasis_json_event_channel_caller_id_create(
+ struct ast_channel_snapshot *channel_snapshot,
+ struct ast_json *blob
+ )
+{
+ RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
+ struct ast_json *validator;
+ int ret;
+
+ ast_assert(channel_snapshot != NULL);
+ ast_assert(blob != NULL);
+ ast_assert(ast_json_object_get(blob, "channel") == NULL);
+ ast_assert(ast_json_object_get(blob, "type") == NULL);
+
+ validator = ast_json_object_get(blob, "caller_presentation_txt");
+ if (validator) {
+ /* do validation? XXX */
+ } else {
+ /* fail message generation if the required parameter doesn't exist */
+ return NULL;
+ }
+
+ validator = ast_json_object_get(blob, "caller_presentation");
+ if (validator) {
+ /* do validation? XXX */
+ } else {
+ /* fail message generation if the required parameter doesn't exist */
+ return NULL;
+ }
+
+ event = ast_json_deep_copy(blob);
+ if (!event) {
+ return NULL;
+ }
+
+ ret = ast_json_object_set(event,
+ "channel", ast_channel_snapshot_to_json(channel_snapshot));
+ if (ret) {
+ return NULL;
+ }
+
+ message = ast_json_pack("{s: o}", "channel_caller_id", ast_json_ref(event));
+ if (!message) {
+ return NULL;
+ }
+
+ return ast_json_ref(message);
+}
+
+struct ast_json *stasis_json_event_playback_started_create(
+ struct ast_json *blob
+ )
+{
+ RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
+ struct ast_json *validator;
+
+ ast_assert(blob != NULL);
+ ast_assert(ast_json_object_get(blob, "type") == NULL);
+
+ validator = ast_json_object_get(blob, "playback");
+ if (validator) {
+ /* do validation? XXX */
+ } else {
+ /* fail message generation if the required parameter doesn't exist */
+ return NULL;
+ }
+
+ event = ast_json_deep_copy(blob);
+ if (!event) {
+ return NULL;
+ }
+
+ message = ast_json_pack("{s: o}", "playback_started", ast_json_ref(event));
+ if (!message) {
+ return NULL;
+ }
+
+ return ast_json_ref(message);
+}
+
+struct ast_json *stasis_json_event_application_replaced_create(
+ struct ast_json *blob
+ )
+{
+ RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
+ struct ast_json *validator;
+
+ ast_assert(blob != NULL);
+ ast_assert(ast_json_object_get(blob, "type") == NULL);
+
+ validator = ast_json_object_get(blob, "application");
+ if (validator) {
+ /* do validation? XXX */
+ } else {
+ /* fail message generation if the required parameter doesn't exist */
+ return NULL;
+ }
+
+ event = ast_json_deep_copy(blob);
+ if (!event) {
+ return NULL;
+ }
+
+ message = ast_json_pack("{s: o}", "application_replaced", ast_json_ref(event));
+ if (!message) {
+ return NULL;
+ }
+
+ return ast_json_ref(message);
+}
+
struct ast_json *stasis_json_event_channel_destroyed_create(
struct ast_channel_snapshot *channel_snapshot,
struct ast_json *blob
@@ -149,132 +295,6 @@
}
message = ast_json_pack("{s: o}", "channel_destroyed", ast_json_ref(event));
- if (!message) {
- return NULL;
- }
-
- return ast_json_ref(message);
-}
-
-struct ast_json *stasis_json_event_channel_caller_id_create(
- struct ast_channel_snapshot *channel_snapshot,
- struct ast_json *blob
- )
-{
- RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
- RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
- struct ast_json *validator;
- int ret;
-
- ast_assert(channel_snapshot != NULL);
- ast_assert(blob != NULL);
- ast_assert(ast_json_object_get(blob, "channel") == NULL);
- ast_assert(ast_json_object_get(blob, "type") == NULL);
-
- validator = ast_json_object_get(blob, "caller_presentation_txt");
- if (validator) {
- /* do validation? XXX */
- } else {
- /* fail message generation if the required parameter doesn't exist */
- return NULL;
- }
-
- validator = ast_json_object_get(blob, "caller_presentation");
- if (validator) {
- /* do validation? XXX */
- } else {
- /* fail message generation if the required parameter doesn't exist */
- return NULL;
- }
-
- event = ast_json_deep_copy(blob);
- if (!event) {
- return NULL;
- }
-
- ret = ast_json_object_set(event,
- "channel", ast_channel_snapshot_to_json(channel_snapshot));
- if (ret) {
- return NULL;
- }
-
- message = ast_json_pack("{s: o}", "channel_caller_id", ast_json_ref(event));
- if (!message) {
- return NULL;
- }
-
- return ast_json_ref(message);
-}
-
-struct ast_json *stasis_json_event_channel_hangup_request_create(
- struct ast_channel_snapshot *channel_snapshot,
- struct ast_json *blob
- )
-{
- RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
- RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
- struct ast_json *validator;
- int ret;
-
- ast_assert(channel_snapshot != NULL);
- ast_assert(blob != NULL);
- ast_assert(ast_json_object_get(blob, "channel") == NULL);
- ast_assert(ast_json_object_get(blob, "type") == NULL);
-
- validator = ast_json_object_get(blob, "soft");
- if (validator) {
- /* do validation? XXX */
- }
-
- validator = ast_json_object_get(blob, "cause");
- if (validator) {
- /* do validation? XXX */
- }
-
- event = ast_json_deep_copy(blob);
- if (!event) {
- return NULL;
- }
-
- ret = ast_json_object_set(event,
- "channel", ast_channel_snapshot_to_json(channel_snapshot));
- if (ret) {
- return NULL;
- }
-
- message = ast_json_pack("{s: o}", "channel_hangup_request", ast_json_ref(event));
- if (!message) {
- return NULL;
- }
-
- return ast_json_ref(message);
-}
-
-struct ast_json *stasis_json_event_application_replaced_create(
- struct ast_json *blob
- )
-{
- RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
- RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
- struct ast_json *validator;
-
- ast_assert(blob != NULL);
- ast_assert(ast_json_object_get(blob, "type") == NULL);
-
- validator = ast_json_object_get(blob, "application");
- if (validator) {
- /* do validation? XXX */
- } else {
- /* fail message generation if the required parameter doesn't exist */
- return NULL;
- }
-
- event = ast_json_deep_copy(blob);
- if (!event) {
- return NULL;
- }
-
- message = ast_json_pack("{s: o}", "application_replaced", ast_json_ref(event));
if (!message) {
return NULL;
}
@@ -517,6 +537,50 @@
}
message = ast_json_pack("{s: o}", "channel_state_change", ast_json_ref(event));
+ if (!message) {
+ return NULL;
+ }
+
+ return ast_json_ref(message);
+}
+
+struct ast_json *stasis_json_event_channel_hangup_request_create(
+ struct ast_channel_snapshot *channel_snapshot,
+ struct ast_json *blob
+ )
+{
+ RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
+ struct ast_json *validator;
+ int ret;
+
+ ast_assert(channel_snapshot != NULL);
+ ast_assert(blob != NULL);
+ ast_assert(ast_json_object_get(blob, "channel") == NULL);
+ ast_assert(ast_json_object_get(blob, "type") == NULL);
+
+ validator = ast_json_object_get(blob, "soft");
+ if (validator) {
+ /* do validation? XXX */
+ }
+
+ validator = ast_json_object_get(blob, "cause");
+ if (validator) {
+ /* do validation? XXX */
+ }
+
+ event = ast_json_deep_copy(blob);
+ if (!event) {
+ return NULL;
+ }
+
+ ret = ast_json_object_set(event,
+ "channel", ast_channel_snapshot_to_json(channel_snapshot));
+ if (ret) {
+ return NULL;
+ }
+
+ message = ast_json_pack("{s: o}", "channel_hangup_request", ast_json_ref(event));
if (!message) {
return NULL;
}
Modified: team/dlee/playback-rebase/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/res/stasis_http/resource_channels.c?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/res/stasis_http/resource_channels.c (original)
+++ team/dlee/playback-rebase/res/stasis_http/resource_channels.c Fri May 10 12:00:15 2013
@@ -24,6 +24,7 @@
*/
/*** MODULEINFO
+ <depend type="module">res_stasis_app_playback</depend>
<support_level>core</support_level>
***/
@@ -31,9 +32,13 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#include "asterisk/file.h"
#include "asterisk/stasis_app.h"
+#include "asterisk/stasis_app_playback.h"
#include "asterisk/stasis_channels.h"
#include "resource_channels.h"
+
+#include <limits.h>
/*!
* \brief Finds the control object for a channel, filling the response with an
@@ -131,9 +136,56 @@
{
ast_log(LOG_ERROR, "TODO: stasis_http_unhold_channel\n");
}
-void stasis_http_play_on_channel(struct ast_variable *headers, struct ast_play_on_channel_args *args, struct stasis_http_response *response)
-{
- ast_log(LOG_ERROR, "TODO: stasis_http_play_on_channel\n");
+
+void stasis_http_play_on_channel(struct ast_variable *headers,
+ struct ast_play_on_channel_args *args,
+ struct stasis_http_response *response)
+{
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
+ RAII_VAR(char *, playback_url, NULL, ast_free);
+ const char *language;
+
+ ast_assert(response != NULL);
+
+ ast_verb(1, "%s(%s, %s)\n", __func__, args->channel_id, args->media);
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ /* Response filled in by find_control */
+ return;
+ }
+
+ snapshot = stasis_app_control_get_snapshot(control);
+ if (!snapshot) {
+ stasis_http_response_error(
+ response, 404, "Not Found",
+ "Channel not found");
+ return;
+ }
+
+ language = S_OR(args->lang, snapshot->language);
+
+ playback = stasis_app_control_play_uri(control, args->media, language);
+ if (!playback) {
+ stasis_http_response_error(
+ response, 500, "Internal Server Error",
+ "Failed to answer channel");
+ return;
+ }
+
+ ast_asprintf(&playback_url, "/playback/%s",
+ stasis_app_playback_get_id(playback));
+ if (!playback_url) {
+ stasis_http_response_error(
+ response, 500, "Internal Server Error",
+ "Out of memory");
+ return;
+ }
+
+ stasis_http_response_created(response, playback_url);
+ ast_verb(1, " %s - done\n", __func__);
}
void stasis_http_record_channel(struct ast_variable *headers, struct ast_record_channel_args *args, struct stasis_http_response *response)
{
@@ -143,8 +195,8 @@
struct ast_get_channel_args *args,
struct stasis_http_response *response)
{
- RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct stasis_caching_topic *caching_topic;
struct ast_channel_snapshot *snapshot;
caching_topic = ast_channel_topic_all_cached();
@@ -154,7 +206,6 @@
"Message bus not initialized");
return;
}
- ao2_ref(caching_topic, +1);
msg = stasis_cache_get(caching_topic, ast_channel_snapshot_type(),
args->channel_id);
Modified: team/dlee/playback-rebase/res/stasis_http/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/res/stasis_http/resource_channels.h?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/res/stasis_http/resource_channels.h (original)
+++ team/dlee/playback-rebase/res/stasis_http/resource_channels.h Fri May 10 12:00:15 2013
@@ -200,6 +200,8 @@
const char *channel_id;
/*! \brief Media's URI to play. */
const char *media;
+ /*! \brief For sounds, selects language for sound */
+ const char *lang;
};
/*!
* \brief Start playback of media.
@@ -244,7 +246,17 @@
/*
* JSON models
*
+ * CallerID
+ * - name: string (required)
+ * - number: string (required)
+ * Dialed
* Originated
+ * Playback
+ * - language: string
+ * - media_uri: string (required)
+ * - id: string (required)
+ * - target_uri: string (required)
+ * - state: string (required)
* DialplanCEP
* - priority: long (required)
* - exten: string (required)
@@ -265,10 +277,6 @@
* - hangupsource: string (required)
* - dialplan: DialplanCEP (required)
* - data: string (required)
- * CallerID
- * - name: string (required)
- * - number: string (required)
- * Dialed
*/
#endif /* _ASTERISK_RESOURCE_CHANNELS_H */
Modified: team/dlee/playback-rebase/res/stasis_http/resource_events.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-rebase/res/stasis_http/resource_events.h?view=diff&rev=388348&r1=388347&r2=388348
==============================================================================
--- team/dlee/playback-rebase/res/stasis_http/resource_events.h (original)
+++ team/dlee/playback-rebase/res/stasis_http/resource_events.h Fri May 10 12:00:15 2013
@@ -59,6 +59,19 @@
struct ast_bridge_snapshot;
/*!
+ * \brief Event showing the completion of a media playback operation.
+ *
+ * \param blob JSON blob containing the following parameters:
+ * - playback: Playback - Playback control object (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_playback_finished_create(
+ struct ast_json *blob
+ );
+
+/*!
* \brief Some part of channel state changed.
*
* \param channel The channel to be used to generate this event
@@ -71,6 +84,48 @@
);
/*!
+ * \brief Channel changed Caller ID.
+ *
+ * \param channel The channel that changed Caller ID.
+ * \param blob JSON blob containing the following parameters:
+ * - caller_presentation_txt: string - The text representation of the Caller Presentation value. (required)
+ * - caller_presentation: integer - The integer representation of the Caller Presentation value. (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_channel_caller_id_create(
+ struct ast_channel_snapshot *channel_snapshot,
+ struct ast_json *blob
+ );
+
+/*!
+ * \brief Event showing the start of a media playback operation.
+ *
+ * \param blob JSON blob containing the following parameters:
+ * - playback: Playback - Playback control object (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_playback_started_create(
+ struct ast_json *blob
+ );
+
+/*!
+ * \brief Notification that another WebSocket has taken over for an application.
+ *
+ * \param blob JSON blob containing the following parameters:
+ * - application: string (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_application_replaced_create(
+ struct ast_json *blob
+ );
+
+/*!
* \brief Notification that a channel has been destroyed.
*
* \param channel The channel to be used to generate this event
@@ -87,19 +142,89 @@
);
/*!
- * \brief Channel changed Caller ID.
- *
- * \param channel The channel that changed Caller ID.
- * \param blob JSON blob containing the following parameters:
- * - caller_presentation_txt: string - The text representation of the Caller Presentation value. (required)
- * - caller_presentation: integer - The integer representation of the Caller Presentation value. (required)
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_channel_caller_id_create(
- struct ast_channel_snapshot *channel_snapshot,
- struct ast_json *blob
+ * \brief Channel variable changed.
+ *
+ * \param channel The channel on which the variable was set.
+ * \param blob JSON blob containing the following parameters:
+ * - variable: string - The variable that changed. (required)
+ * - value: string - The new value of the variable. (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_channel_varset_create(
+ struct ast_channel_snapshot *channel_snapshot,
+ struct ast_json *blob
+ );
+
+/*!
+ * \brief User-generated event with additional user-defined fields in the object.
+ *
+ * \param channel The channel that signaled the user event.
+ * \param blob JSON blob containing the following parameters:
+ * - eventname: string - The name of the user event. (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_channel_userevent_create(
+ struct ast_channel_snapshot *channel_snapshot,
+ struct ast_json *blob
+ );
+
+/*!
+ * \brief Notification that a channel has been created.
+ *
+ * \param channel The channel to be used to generate this event
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_channel_created_create(
+ struct ast_channel_snapshot *channel_snapshot
+ );
+
+/*!
+ * \brief Notification that a channel has entered a Stasis appliction.
+ *
+ * \param channel The channel to be used to generate this event
+ * \param blob JSON blob containing the following parameters:
+ * - args: List[string] - Arguments to the application (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_stasis_start_create(
+ struct ast_channel_snapshot *channel_snapshot,
+ struct ast_json *blob
+ );
+
+/*!
+ * \brief Channel changed location in the dialplan.
+ *
+ * \param channel The channel that changed dialplan location.
+ * \param blob JSON blob containing the following parameters:
+ * - application: string - The application that the channel is currently in. (required)
+ * - application_data: string - The data that was passed to the application when it was invoked. (required)
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_channel_dialplan_create(
+ struct ast_channel_snapshot *channel_snapshot,
+ struct ast_json *blob
+ );
+
+/*!
+ * \brief Notification of a channel's state change.
+ *
+ * \param channel The channel to be used to generate this event
+ *
+ * \retval NULL on error
+ * \retval JSON (ast_json) describing the event
+ */
+struct ast_json *stasis_json_event_channel_state_change_create(
+ struct ast_channel_snapshot *channel_snapshot
);
/*!
@@ -119,105 +244,6 @@
);
/*!
- * \brief Notification that another WebSocket has taken over for an application.
- *
- * \param blob JSON blob containing the following parameters:
- * - application: string (required)
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_application_replaced_create(
- struct ast_json *blob
- );
-
-/*!
- * \brief Channel variable changed.
- *
- * \param channel The channel on which the variable was set.
- * \param blob JSON blob containing the following parameters:
- * - variable: string - The variable that changed. (required)
- * - value: string - The new value of the variable. (required)
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_channel_varset_create(
- struct ast_channel_snapshot *channel_snapshot,
- struct ast_json *blob
- );
-
-/*!
- * \brief User-generated event with additional user-defined fields in the object.
- *
- * \param channel The channel that signaled the user event.
- * \param blob JSON blob containing the following parameters:
- * - eventname: string - The name of the user event. (required)
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_channel_userevent_create(
- struct ast_channel_snapshot *channel_snapshot,
- struct ast_json *blob
- );
-
-/*!
- * \brief Notification that a channel has been created.
- *
- * \param channel The channel to be used to generate this event
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_channel_created_create(
- struct ast_channel_snapshot *channel_snapshot
- );
-
-/*!
- * \brief Notification that a channel has entered a Stasis appliction.
- *
- * \param channel The channel to be used to generate this event
- * \param blob JSON blob containing the following parameters:
- * - args: List[string] - Arguments to the application (required)
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_stasis_start_create(
- struct ast_channel_snapshot *channel_snapshot,
- struct ast_json *blob
- );
-
-/*!
- * \brief Channel changed location in the dialplan.
- *
- * \param channel The channel that changed dialplan location.
- * \param blob JSON blob containing the following parameters:
- * - application: string - The application that the channel is currently in. (required)
- * - application_data: string - The data that was passed to the application when it was invoked. (required)
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_channel_dialplan_create(
- struct ast_channel_snapshot *channel_snapshot,
- struct ast_json *blob
- );
-
-/*!
- * \brief Notification of a channel's state change.
- *
- * \param channel The channel to be used to generate this event
- *
- * \retval NULL on error
- * \retval JSON (ast_json) describing the event
- */
-struct ast_json *stasis_json_event_channel_state_change_create(
- struct ast_channel_snapshot *channel_snapshot
- );
-
-/*!
* \brief DTMF received on a channel.
*
* \param channel The channel on which DTMF was received
@@ -247,18 +273,19 @@
/*
* JSON models
*
+ * PlaybackFinished
+ * - playback: Playback (required)
* ChannelSnapshot
+ * ChannelCallerId
+ * - caller_presentation_txt: string (required)
+ * - caller_presentation: integer (required)
+ * PlaybackStarted
+ * - playback: Playback (required)
+ * ApplicationReplaced
+ * - application: string (required)
* ChannelDestroyed
* - cause: integer (required)
* - cause_txt: string (required)
- * ChannelCallerId
- * - caller_presentation_txt: string (required)
- * - caller_presentation: integer (required)
- * ChannelHangupRequest
- * - soft: boolean
- * - cause: integer
- * ApplicationReplaced
- * - application: string (required)
* ChannelVarset
* - variable: string (required)
* - value: string (required)
@@ -271,11 +298,15 @@
* - application: string (required)
* - application_data: string (required)
* ChannelStateChange
+ * ChannelHangupRequest
+ * - soft: boolean
+ * - cause: integer
* ChannelDtmfReceived
* - digit: string (required)
* Event
* - channel_created: ChannelCreated
* - channel_destroyed: ChannelDestroyed
[... 149 lines stripped ...]
More information about the asterisk-commits
mailing list