From a2a53cc306ea5fec65daf3630716a7c6ee13adad Mon Sep 17 00:00:00 2001 From: "David M. Lee" Date: Mon, 8 Apr 2013 13:27:45 +0000 Subject: Stasis application WebSocket support This is the API that binds the Stasis dialplan application to external Stasis applications. It also adds the beginnings of WebSocket application support. This module registers a dialplan function named Stasis, which is used to put a channel into the named Stasis app. As a channel enters and leaves the Stasis diaplan application, the Stasis app receives a 'stasis-start' and 'stasis-end' events. Stasis apps register themselves using the stasis_app_register and stasis_app_unregister functions. Messages are sent to an application using stasis_app_send. Finally, Stasis apps control channels through the use of the stasis_app_control object, and the family of stasis_app_control_* functions. Other changes along for the ride are: * An ast_frame_dtor function that's RAII_VAR safe * Some common JSON encoders for name/number, timeval, and context/extension/priority Review: https://reviewboard.asterisk.org/r/2361/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@384879 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/frame.c | 7 +++++++ main/json.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'main') diff --git a/main/frame.c b/main/frame.c index a3f67da61..b559d552d 100644 --- a/main/frame.c +++ b/main/frame.c @@ -351,6 +351,13 @@ void ast_frame_free(struct ast_frame *frame, int cache) } } +void ast_frame_dtor(struct ast_frame *f) +{ + if (f) { + ast_frfree(f); + } +} + /*! * \brief 'isolates' a frame by duplicating non-malloc'ed components * (header, src, data). diff --git a/main/json.c b/main/json.c index edffcc945..07d2c5e95 100644 --- a/main/json.c +++ b/main/json.c @@ -27,6 +27,7 @@ */ /*** MODULEINFO + jansson core ***/ @@ -35,10 +36,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/json.h" +#include "asterisk/localtime.h" #include "asterisk/module.h" #include "asterisk/utils.h" #include +#include /*! * \brief Function wrapper around ast_malloc macro. @@ -501,6 +504,37 @@ struct ast_json *ast_json_deep_copy(const struct ast_json *value) return (struct ast_json *)json_deep_copy((json_t *)value); } +struct ast_json *ast_json_name_number(const char *name, const char *number) +{ + return ast_json_pack("{s: s, s: s}", + "name", name, + "number", number); +} + +struct ast_json *ast_json_dialplan_cep(const char *context, const char *exten, int priority) +{ + return ast_json_pack("{s: o, s: o, s: o}", + "context", context ? ast_json_string_create(context) : ast_json_null(), + "exten", exten ? ast_json_string_create(exten) : ast_json_null(), + "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null()); +} + +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_strftime(buf, sizeof(buf),AST_ISO8601_FORMAT, &tm); + + return ast_json_string_create(buf); +} + void ast_json_init(void) { /* Setup to use Asterisk custom allocators */ -- cgit v1.2.3