diff options
48 files changed, 1297 insertions, 1229 deletions
@@ -50,6 +50,14 @@ res_pjsip_endpoint_identifier_ip source IP addresses for requests. This is configurable using the "srv_lookups" option on the identify and defaults to "yes". +ARI +------------------ + * The 'ari set debug' command has been enhanced to accept 'all' as an + application name. This allows dumping of all apps even if an app + hasn't registered yet. + + * 'ari set debug' now displays requests and responses as well as events. + ------------------------------------------------------------------------------ --- Functionality changes from Asterisk 13.12.0 to Asterisk 13.13.0 ---------- ------------------------------------------------------------------------------ diff --git a/channels/chan_oss.c b/channels/chan_oss.c index 912a5ebbe..aa870dfc2 100644 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -727,7 +727,7 @@ static struct ast_frame *oss_read(struct ast_channel *c) return f; /* ok we can build and deliver the frame to the caller */ f->frametype = AST_FRAME_VOICE; - f->subclass.format = ao2_bump(ast_format_slin); + f->subclass.format = ast_format_slin; f->samples = FRAME_SIZE; f->datalen = FRAME_SIZE * 2; f->data.ptr = o->oss_read_buf + AST_FRIENDLY_OFFSET; diff --git a/include/asterisk/ari.h b/include/asterisk/ari.h index 1c54a694b..cad9b32c5 100644 --- a/include/asterisk/ari.h +++ b/include/asterisk/ari.h @@ -59,7 +59,8 @@ struct ast_ari_response; typedef void (*stasis_rest_callback)( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response); + struct ast_variable *headers, struct ast_json *body, + struct ast_ari_response *response); /*! * \brief Handler for a single RESTful path segment. @@ -134,7 +135,7 @@ int ast_ari_remove_handler(struct stasis_rest_handlers *handler); void ast_ari_invoke(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers, - struct ast_ari_response *response); + struct ast_json *body, struct ast_ari_response *response); /*! * \internal @@ -189,6 +190,25 @@ int ast_ari_websocket_session_write(struct ast_ari_websocket_session *session, struct ast_json *message); /*! + * \brief Get the Session ID for an ARI WebSocket. + * + * \param session Session to query. + * \return Session ID. + * \return \c NULL on error. + */ +const char *ast_ari_websocket_session_id( + const struct ast_ari_websocket_session *session); + +/*! + * \brief Get the remote address from an ARI WebSocket. + * + * \param session Session to write to. + * \return ast_sockaddr (does not have to be freed) + */ +struct ast_sockaddr *ast_ari_websocket_session_get_remote_addr( + struct ast_ari_websocket_session *session); + +/*! * \brief The stock message to return when out of memory. * * The refcount is NOT bumped on this object, so ast_json_ref() if you want to diff --git a/include/asterisk/mod_format.h b/include/asterisk/mod_format.h index 7f17741fa..d76be5eca 100644 --- a/include/asterisk/mod_format.h +++ b/include/asterisk/mod_format.h @@ -114,7 +114,11 @@ struct ast_filestream { int lasttimeout; struct ast_channel *owner; FILE *f; - struct ast_frame fr; /*!< frame produced by read, typically */ + /*! + * \brief frame produced by read, typically + * \note This frame holds a fr.subclass.format ref. + */ + struct ast_frame fr; char *buf; /*!< buffer pointed to by ast_frame; */ void *_private; /*!< pointer to private buffer */ const char *orig_chan_name; diff --git a/include/asterisk/options.h b/include/asterisk/options.h index 0f8c6f87e..950764e15 100644 --- a/include/asterisk/options.h +++ b/include/asterisk/options.h @@ -143,6 +143,33 @@ enum ast_option_flags { */ #define DEFAULT_PJ_LOG_MAX_LEVEL 2 +/*! + * \brief Get maximum log level pjproject was compiled with. + * + * \details + * Determine the maximum log level the pjproject we are running + * with supports. + * + * When pjproject is initially loaded the default log level in + * effect is the maximum log level the library was compiled to + * generate. We must save this value off somewhere before we + * change it to what we want to use as the default level. + * + * \note This must be done before calling pj_init() so the level + * we want to use as the default level is in effect while the + * library initializes. + */ +#define AST_PJPROJECT_INIT_LOG_LEVEL() \ + do { \ + if (ast_pjproject_max_log_level < 0) { \ + ast_pjproject_max_log_level = pj_log_get_level(); \ + } \ + pj_log_set_level(ast_option_pjproject_log_level); \ + } while (0) + +/*! Current linked pjproject maximum logging level */ +extern int ast_pjproject_max_log_level; + /*! Current pjproject logging level */ extern int ast_option_pjproject_log_level; diff --git a/include/asterisk/stasis_app.h b/include/asterisk/stasis_app.h index 53ce116a9..6f9897c09 100644 --- a/include/asterisk/stasis_app.h +++ b/include/asterisk/stasis_app.h @@ -891,6 +891,55 @@ int stasis_app_channel_unreal_set_internal(struct ast_channel *chan); */ int stasis_app_channel_set_internal(struct ast_channel *chan); +/*! + * \brief Enable/disable request/response and event logging on an application + * + * \param app The app to debug + * \param debug If non-zero, enable debugging. If zero, disable. + */ +void stasis_app_set_debug(struct stasis_app *app, int debug); + +/*! + * \brief Enable/disable request/response and event logging on an application + * + * \param app_name The app name to debug + * \param debug If non-zero, enable debugging. If zero, disable. + */ +void stasis_app_set_debug_by_name(const char *app_name, int debug); + +/*! + * \brief Get debug status of an application + * + * \param app The app to check + * \return The debug flag for the app || the global debug flag + */ +int stasis_app_get_debug(struct stasis_app *app); + +/*! + * \brief Get debug status of an application + * + * \param app_name The app_name to check + * \return The debug flag for the app || the global debug flag + */ +int stasis_app_get_debug_by_name(const char *app_name); + +/*! + * \brief Enable/disable request/response and event logging on all applications + * + * \param debug If non-zero, enable debugging. If zero, disable. + */ +void stasis_app_set_global_debug(int debug); + +struct ast_cli_args; + +/*! + * \brief Dump properties of a \c stasis_app to the CLI + * + * \param app The application + * \param a The CLI arguments + */ +void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a); + /*! @} */ #endif /* _ASTERISK_STASIS_APP_H */ diff --git a/include/asterisk/translate.h b/include/asterisk/translate.h index e2a4f300f..ce46cd083 100644 --- a/include/asterisk/translate.h +++ b/include/asterisk/translate.h @@ -208,7 +208,7 @@ struct ast_translator { */ struct ast_trans_pvt { struct ast_translator *t; - struct ast_frame f; /*!< used in frameout */ + struct ast_frame f; /*!< used in frameout. This frame holds a f.subclass.format ref. */ int samples; /*!< samples available in outbuf */ /*! \brief actual space used in outbuf */ int datalen; diff --git a/main/app.c b/main/app.c index 58aa3a0fd..ee7cef26b 100644 --- a/main/app.c +++ b/main/app.c @@ -1422,22 +1422,20 @@ static struct ast_frame *make_silence(const struct ast_frame *orig) size_t size; size_t datalen; size_t samples = 0; - struct ast_frame *next; if (!orig) { return NULL; } + do { + if (ast_format_cmp(orig->subclass.format, ast_format_slin) == AST_FORMAT_CMP_NOT_EQUAL) { + ast_log(LOG_WARNING, "Attempting to silence non-slin frame\n"); + return NULL; + } - if (ast_format_cmp(orig->subclass.format, ast_format_slin) == AST_FORMAT_CMP_NOT_EQUAL) { - ast_log(LOG_WARNING, "Attempting to silence non-slin frame\n"); - return NULL; - } - - for (next = AST_LIST_NEXT(orig, frame_list); - orig; - orig = next, next = orig ? AST_LIST_NEXT(orig, frame_list) : NULL) { samples += orig->samples; - } + + orig = AST_LIST_NEXT(orig, frame_list); + } while (orig); ast_verb(4, "Silencing %zu samples\n", samples); @@ -1455,7 +1453,7 @@ static struct ast_frame *make_silence(const struct ast_frame *orig) silence->samples = samples; silence->datalen = datalen; - silence->subclass.format = ast_format_slin; + silence->subclass.format = ao2_bump(ast_format_slin); return silence; } @@ -1661,14 +1659,13 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, /* It's all good */ res = 0; } else { - RAII_VAR(struct ast_frame *, silence, NULL, ast_frame_dtor); + struct ast_frame *silence = NULL; struct ast_frame *orig = f; if (muted) { silence = make_silence(orig); if (!silence) { - ast_log(LOG_WARNING, - "Error creating silence\n"); + ast_log(LOG_WARNING, "Error creating silence\n"); break; } f = silence; @@ -1679,6 +1676,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, } res = ast_writestream(others[x], f); } + ast_frame_dtor(silence); f = orig; } diff --git a/main/asterisk.c b/main/asterisk.c index 2236e8c69..994dfbeb7 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -325,6 +325,7 @@ int ast_verb_sys_level; int option_verbose; /*!< Verbosity level */ int option_debug; /*!< Debug level */ +int ast_pjproject_max_log_level = -1;/* Default to -1 to know if we have read the level from pjproject yet. */ int ast_option_pjproject_log_level; double ast_option_maxload; /*!< Max load avg on system */ int ast_option_maxcalls; /*!< Max number of active calls */ diff --git a/main/astobj2.c b/main/astobj2.c index 7320c5efb..569db0b7b 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -421,6 +421,19 @@ static int internal_ao2_ref(void *user_data, int delta, const char *file, int li if (0 < current_value) { /* The object still lives. */ +#define EXCESSIVE_REF_COUNT 100000 + + if (EXCESSIVE_REF_COUNT <= current_value && ret < EXCESSIVE_REF_COUNT) { + char excessive_ref_buf[100]; + + /* We just reached or went over the excessive ref count trigger */ + snprintf(excessive_ref_buf, sizeof(excessive_ref_buf), + "Excessive refcount %d reached on ao2 object %p", + current_value, user_data); + ast_log(__LOG_ERROR, file, line, func, "%s\n", excessive_ref_buf); + + __ast_assert_failed(0, excessive_ref_buf, file, line, func); + } return ret; } diff --git a/main/channel.c b/main/channel.c index 637488a9c..f305cc8bb 100644 --- a/main/channel.c +++ b/main/channel.c @@ -4889,16 +4889,18 @@ int ast_sendtext(struct ast_channel *chan, const char *text) if (ast_channel_tech(chan)->write_text && (ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_MEDIA_TYPE_TEXT))) { struct ast_frame f; + memset(&f, 0, sizeof(f)); f.frametype = AST_FRAME_TEXT; f.src = "DIALPLAN"; f.mallocd = AST_MALLOCD_DATA; f.datalen = strlen(text); f.data.ptr = ast_strdup(text); - f.offset = 0; - f.seqno = 0; - f.subclass.format = ast_format_t140; - res = ast_channel_tech(chan)->write_text(chan, &f); + + if (f.data.ptr) { + res = ast_channel_tech(chan)->write_text(chan, &f); + ast_frfree(&f); + } } else if (ast_channel_tech(chan)->send_text) { res = ast_channel_tech(chan)->send_text(chan, text); } diff --git a/main/format_compatibility.c b/main/format_compatibility.c index cf66af282..0f1dff7c8 100644 --- a/main/format_compatibility.c +++ b/main/format_compatibility.c @@ -264,10 +264,10 @@ struct ast_format *ast_format_compatibility_bitfield2format(uint64_t bitfield) /*! T.140 RED Text format RFC 4103 */ case AST_FORMAT_T140_RED: - return ast_format_t140; + return ast_format_t140_red; /*! T.140 Text format - ITU T.140, RFC 4103 */ case AST_FORMAT_T140: - return ast_format_t140_red; + return ast_format_t140; } return NULL; } diff --git a/main/frame.c b/main/frame.c index b5ab9853d..4261b04dd 100644 --- a/main/frame.c +++ b/main/frame.c @@ -84,9 +84,9 @@ static struct ast_frame *ast_frame_header_new(void) if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) { if ((f = AST_LIST_REMOVE_HEAD(&frames->list, frame_list))) { size_t mallocd_len = f->mallocd_hdr_len; + memset(f, 0, sizeof(*f)); f->mallocd_hdr_len = mallocd_len; - f->mallocd = AST_MALLOCD_HDR; frames->size--; return f; } @@ -141,12 +141,12 @@ static void __frame_free(struct ast_frame *fr, int cache) #endif if (fr->mallocd & AST_MALLOCD_DATA) { - if (fr->data.ptr) + if (fr->data.ptr) { ast_free(fr->data.ptr - fr->offset); + } } if (fr->mallocd & AST_MALLOCD_SRC) { - if (fr->src) - ast_free((void *) fr->src); + ast_free((void *) fr->src); } if (fr->mallocd & AST_MALLOCD_HDR) { if ((fr->frametype == AST_FRAME_VOICE) || (fr->frametype == AST_FRAME_VIDEO) || @@ -208,14 +208,14 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr) return NULL; } out->frametype = fr->frametype; + out->subclass = fr->subclass; if ((fr->frametype == AST_FRAME_VOICE) || (fr->frametype == AST_FRAME_VIDEO) || (fr->frametype == AST_FRAME_IMAGE)) { - out->subclass.format = ao2_bump(fr->subclass.format); - } else { - memcpy(&out->subclass, &fr->subclass, sizeof(out->subclass)); + ao2_bump(out->subclass.format); } out->datalen = fr->datalen; out->samples = fr->samples; + out->mallocd = AST_MALLOCD_HDR; out->offset = fr->offset; /* Copy the timing data */ ast_copy_flags(out, fr, AST_FLAGS_ALL); @@ -228,47 +228,64 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr) out = fr; } - if (!(fr->mallocd & AST_MALLOCD_SRC) && fr->src) { - if (!(out->src = ast_strdup(fr->src))) { - if (out != fr) { - ast_free(out); + if (fr->src) { + /* The original frame has a source string */ + if (!(fr->mallocd & AST_MALLOCD_SRC)) { + /* + * The original frame has a non-malloced source string. + * + * Duplicate the string and put it into the isolated frame + * which may also be the original frame. + */ + newdata = ast_strdup(fr->src); + if (!newdata) { + if (out != fr) { + ast_frame_free(out, 0); + } + return NULL; } - return NULL; + out->src = newdata; + out->mallocd |= AST_MALLOCD_SRC; + } else if (out != fr) { + /* Steal the source string from the original frame. */ + out->src = fr->src; + fr->src = NULL; + fr->mallocd &= ~AST_MALLOCD_SRC; + out->mallocd |= AST_MALLOCD_SRC; } - } else { - out->src = fr->src; - fr->src = NULL; - fr->mallocd &= ~AST_MALLOCD_SRC; } if (!(fr->mallocd & AST_MALLOCD_DATA)) { + /* The original frame has a non-malloced data buffer. */ if (!fr->datalen) { + /* Actually it's just an int so we can simply copy it. */ out->data.uint32 = fr->data.uint32; - out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC; return out; } - if (!(newdata = ast_malloc(fr->datalen + AST_FRIENDLY_OFFSET))) { - if (out->src != fr->src) { - ast_free((void *) out->src); - } + /* + * Duplicate the data buffer and put it into the isolated frame + * which may also be the original frame. + */ + newdata = ast_malloc(fr->datalen + AST_FRIENDLY_OFFSET); + if (!newdata) { if (out != fr) { - ast_free(out); + ast_frame_free(out, 0); } return NULL; } newdata += AST_FRIENDLY_OFFSET; out->offset = AST_FRIENDLY_OFFSET; - out->datalen = fr->datalen; memcpy(newdata, fr->data.ptr, fr->datalen); out->data.ptr = newdata; - } else { + out->mallocd |= AST_MALLOCD_DATA; + } else if (out != fr) { + /* Steal the data buffer from the original frame. */ out->data = fr->data; memset(&fr->data, 0, sizeof(fr->data)); fr->mallocd &= ~AST_MALLOCD_DATA; + out->mallocd |= AST_MALLOCD_DATA; } - out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA; - return out; } diff --git a/main/libasteriskpj.c b/main/libasteriskpj.c index 2d92b599d..80c4d1896 100644 --- a/main/libasteriskpj.c +++ b/main/libasteriskpj.c @@ -47,7 +47,7 @@ ASTERISK_REGISTER_FILE() int ast_pj_init(void) { #ifdef HAVE_PJPROJECT_BUNDLED - pj_log_set_level(ast_option_pjproject_log_level); + AST_PJPROJECT_INIT_LOG_LEVEL(); pj_init(); #endif return 0; diff --git a/main/strings.c b/main/strings.c index 7cb55def0..7f2025abe 100644 --- a/main/strings.c +++ b/main/strings.c @@ -186,15 +186,32 @@ static int str_hash(const void *obj, const int flags) return ast_str_hash(obj); } +static int str_sort(const void *lhs, const void *rhs, int flags) +{ + if ((flags & OBJ_SEARCH_MASK) == OBJ_SEARCH_PARTIAL_KEY) { + return strncmp(lhs, rhs, strlen(rhs)); + } else { + return strcmp(lhs, rhs); + } +} + static int str_cmp(void *lhs, void *rhs, int flags) { - return strcmp(lhs, rhs) ? 0 : CMP_MATCH; + int cmp = 0; + + if ((flags & OBJ_SEARCH_MASK) == OBJ_SEARCH_PARTIAL_KEY) { + cmp = strncmp(lhs, rhs, strlen(rhs)); + } else { + cmp = strcmp(lhs, rhs); + } + + return cmp ? 0 : CMP_MATCH; } //struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets) struct ao2_container *ast_str_container_alloc_options(enum ao2_alloc_opts opts, int buckets) { - return ao2_container_alloc_options(opts, buckets, str_hash, str_cmp); + return ao2_container_alloc_hash(opts, 0, buckets, str_hash, str_sort, str_cmp); } int ast_str_container_add(struct ao2_container *str_container, const char *add) diff --git a/res/ari/ari_websockets.c b/res/ari/ari_websockets.c index f06a66750..6a296dcf6 100644 --- a/res/ari/ari_websockets.c +++ b/res/ari/ari_websockets.c @@ -23,6 +23,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/ari.h" #include "asterisk/astobj2.h" #include "asterisk/http_websocket.h" +#include "asterisk/stasis_app.h" #include "internal.h" /*! \file @@ -139,6 +140,7 @@ struct ast_json *ast_ari_websocket_session_read( ast_log(LOG_WARNING, "WebSocket input failed to parse\n"); } + break; default: /* Ignore all other message types */ @@ -174,16 +176,20 @@ int ast_ari_websocket_session_write(struct ast_ari_websocket_session *session, return -1; } -#ifdef AST_DEVMODE - ast_debug(3, "Examining ARI event (length %u): \n%s\n", (unsigned int) strlen(str), str); -#endif if (ast_websocket_write_string(session->ws_session, str)) { - ast_log(LOG_NOTICE, "Problem occurred during websocket write, websocket closed\n"); + ast_log(LOG_NOTICE, "Problem occurred during websocket write to %s, websocket closed\n", + ast_sockaddr_stringify(ast_ari_websocket_session_get_remote_addr(session))); return -1; } return 0; } +struct ast_sockaddr *ast_ari_websocket_session_get_remote_addr( + struct ast_ari_websocket_session *session) +{ + return ast_websocket_remote_address(session->ws_session); +} + void ari_handle_websocket(struct ast_websocket_server *ws_server, struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *get_params, diff --git a/res/ari/cli.c b/res/ari/cli.c index 819407997..90c177306 100644 --- a/res/ari/cli.c +++ b/res/ari/cli.c @@ -28,6 +28,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/astobj2.h" #include "asterisk/cli.h" +#include "asterisk/stasis_app.h" #include "internal.h" static char *ari_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) @@ -251,11 +252,185 @@ static char *ari_mkpasswd(struct ast_cli_entry *e, int cmd, struct ast_cli_args return CLI_SUCCESS; } +static char *ari_show_apps(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + struct ao2_container *apps; + struct ao2_iterator it_apps; + char *app; + + switch (cmd) { + case CLI_INIT: + e->command = "ari show apps"; + e->usage = + "Usage: ari show apps\n" + " Lists all registered applications.\n" + ; + return NULL; + case CLI_GENERATE: + return NULL; + default: + break; + } + + if (a->argc != 3) { + return CLI_SHOWUSAGE; + } + + apps = stasis_app_get_all(); + if (!apps) { + ast_cli(a->fd, "Unable to retrieve registered applications!\n"); + return CLI_FAILURE; + } + + ast_cli(a->fd, "Application Name \n"); + ast_cli(a->fd, "=========================\n"); + it_apps = ao2_iterator_init(apps, 0); + while ((app = ao2_iterator_next(&it_apps))) { + ast_cli(a->fd, "%-25.25s\n", app); + ao2_ref(app, -1); + } + + ao2_iterator_destroy(&it_apps); + ao2_ref(apps, -1); + + return CLI_SUCCESS; +} + +struct app_complete { + /*! Nth app to search for */ + int state; + /*! Which app currently on */ + int which; +}; + +static int complete_ari_app_search(void *obj, void *arg, void *data, int flags) +{ + struct app_complete *search = data; + + if (++search->which > search->state) { + return CMP_MATCH; + } + return 0; +} + +static char *complete_ari_app(struct ast_cli_args *a, int include_all) +{ + RAII_VAR(struct ao2_container *, apps, stasis_app_get_all(), ao2_cleanup); + RAII_VAR(char *, app, NULL, ao2_cleanup); + + struct app_complete search = { + .state = a->n, + }; + + if (a->pos != 3) { + return NULL; + } + + if (!apps) { + ast_cli(a->fd, "Error getting ARI applications\n"); + return CLI_FAILURE; + } + + if (include_all && ast_strlen_zero(a->word)) { + ast_str_container_add(apps, " all"); + } + + app = ao2_callback_data(apps, + ast_strlen_zero(a->word) ? 0 : OBJ_SEARCH_PARTIAL_KEY, + complete_ari_app_search, (char*)a->word, &search); + + return app ? ast_strdup(app) : NULL; +} + +static char *ari_show_app(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + void *app; + + switch (cmd) { + case CLI_INIT: + e->command = "ari show app"; + e->usage = + "Usage: ari show app <application>\n" + " Provide detailed information about a registered application.\n" + ; + return NULL; + case CLI_GENERATE: + return complete_ari_app(a, 0); + default: + break; + } + + if (a->argc != 4) { + return CLI_SHOWUSAGE; + } + + app = stasis_app_get_by_name(a->argv[3]); + if (!app) { + return CLI_FAILURE; + } + + stasis_app_to_cli(app, a); + + ao2_ref(app, -1); + + return CLI_SUCCESS; +} + +static char *ari_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + void *app; + int debug; + + switch (cmd) { + case CLI_INIT: + e->command = "ari set debug"; + e->usage = + "Usage: ari set debug <application|all> <on|off>\n" + " Enable or disable debugging on a specific application.\n" + ; + return NULL; + case CLI_GENERATE: + return complete_ari_app(a, 1); + default: + break; + } + + if (a->argc != 5) { + return CLI_SHOWUSAGE; + } + + debug = !strcmp(a->argv[4], "on"); + + if (!strcmp(a->argv[3], "all")) { + stasis_app_set_global_debug(debug); + ast_cli(a->fd, "Debugging on all applications %s\n", + debug ? "enabled" : "disabled"); + return CLI_SUCCESS; + } + + app = stasis_app_get_by_name(a->argv[3]); + if (!app) { + return CLI_FAILURE; + } + + stasis_app_set_debug(app, debug); + ast_cli(a->fd, "Debugging on '%s' %s\n", + stasis_app_name(app), + debug ? "enabled" : "disabled"); + + ao2_ref(app, -1); + + return CLI_SUCCESS; +} + static struct ast_cli_entry cli_ari[] = { AST_CLI_DEFINE(ari_show, "Show ARI settings"), AST_CLI_DEFINE(ari_show_users, "List ARI users"), AST_CLI_DEFINE(ari_show_user, "List single ARI user"), AST_CLI_DEFINE(ari_mkpasswd, "Encrypts a password"), + AST_CLI_DEFINE(ari_show_apps, "List registered ARI applications"), + AST_CLI_DEFINE(ari_show_app, "Display details of a registered ARI application"), + AST_CLI_DEFINE(ari_set_debug, "Enable/disable debugging of an ARI application"), }; int ast_ari_cli_register(void) { diff --git a/res/ari/resource_events.c b/res/ari/resource_events.c index 71d54b494..535ce70ee 100644 --- a/res/ari/resource_events.c +++ b/res/ari/resource_events.c @@ -139,6 +139,15 @@ static void app_handler(void *data, const char *app_name, ao2_lock(session); if (session->ws_session) { + if (stasis_app_get_debug_by_name(app_name)) { + char *str = ast_json_dump_string_format(message, ast_ari_json_format()); + + ast_verbose("<--- Sending ARI event to %s --->\n%s\n", + ast_sockaddr_stringify(ast_ari_websocket_session_get_remote_addr(session->ws_session)), + str); + ast_json_free(str); + } + ast_ari_websocket_session_write(session->ws_session, message); } ao2_unlock(session); diff --git a/res/res_ari.c b/res/res_ari.c index 4ff98ce96..c6f81dcef 100644 --- a/res/res_ari.c +++ b/res/res_ari.c @@ -147,6 +147,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/astobj2.h" #include "asterisk/module.h" #include "asterisk/paths.h" +#include "asterisk/stasis_app.h" #include <string.h> #include <sys/stat.h> @@ -490,7 +491,7 @@ static void handle_options(struct stasis_rest_handlers *handler, void ast_ari_invoke(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers, - struct ast_ari_response *response) + struct ast_json *body, struct ast_ari_response *response) { RAII_VAR(struct stasis_rest_handlers *, root, NULL, ao2_cleanup); struct stasis_rest_handlers *handler; @@ -505,8 +506,10 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser, while ((path_segment = strsep(&path, "/")) && (strlen(path_segment) > 0)) { struct stasis_rest_handlers *found_handler = NULL; int i; + ast_uri_decode(path_segment, ast_uri_http_legacy); ast_debug(3, "Finding handler for %s\n", path_segment); + for (i = 0; found_handler == NULL && i < handler->num_children; ++i) { struct stasis_rest_handlers *child = handler->children[i]; @@ -568,7 +571,7 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser, return; } - callback(ser, get_params, path_vars, headers, response); + callback(ser, get_params, path_vars, headers, body, response); if (response->message == NULL && response->response_code == 0) { /* Really should not happen */ ast_log(LOG_ERROR, "ARI %s %s not implemented\n", @@ -878,6 +881,10 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser, RAII_VAR(struct ast_ari_conf_user *, user, NULL, ao2_cleanup); struct ast_ari_response response = {}; RAII_VAR(struct ast_variable *, post_vars, NULL, ast_variables_destroy); + struct ast_variable *var; + const char *app_name = NULL; + RAII_VAR(struct ast_json *, body, ast_json_null(), ast_json_free); + int debug_app = 0; if (!response_body) { ast_http_request_close_on_completion(ser); @@ -925,6 +932,25 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser, "Bad Request", "Error parsing request body"); goto request_failed; } + + /* Look for a JSON request entity only if there were no post_vars. + * If there were post_vars, then the request body would already have + * been consumed and can not be read again. + */ + body = ast_http_get_json(ser, headers); + if (!body) { + switch (errno) { + case EFBIG: + ast_ari_response_error(&response, 413, "Request Entity Too Large", "Request body too large"); + goto request_failed; + case ENOMEM: + ast_ari_response_error(&response, 500, "Internal Server Error", "Error processing request"); + goto request_failed; + case EIO: + ast_ari_response_error(&response, 400, "Bad Request", "Error parsing request body"); + goto request_failed; + } + } } if (get_params == NULL) { get_params = post_vars; @@ -941,6 +967,41 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser, get_params = post_vars; } + /* At this point, get_params will contain post_vars (if any) */ + app_name = ast_variable_find_in_list(get_params, "app"); + if (!app_name) { + struct ast_json *app = ast_json_object_get(body, "app"); + + app_name = (app ? ast_json_string_get(app) : NULL); + } + + /* stasis_app_get_debug_by_name returns an "||" of the app's debug flag + * and the global debug flag. + */ + debug_app = stasis_app_get_debug_by_name(app_name); + if (debug_app) { + struct ast_str *buf = ast_str_create(512); + char *str = ast_json_dump_string_format(body, ast_ari_json_format()); + + if (!buf) { + ast_http_request_close_on_completion(ser); + ast_http_error(ser, 500, "Server Error", "Out of memory"); + goto request_failed; + } + + ast_str_append(&buf, 0, "<--- ARI request received from: %s --->\n", + ast_sockaddr_stringify(&ser->remote_address)); + for (var = headers; var; var = var->next) { + ast_str_append(&buf, 0, "%s: %s\n", var->name, var->value); + } + for (var = get_params; var; var = var->next) { + ast_str_append(&buf, 0, "%s: %s\n", var->name, var->value); + } + ast_verbose("%sbody:\n%s\n\n", ast_str_buffer(buf), str); + ast_json_free(str); + ast_free(buf); + } + user = authenticate_user(get_params, headers); if (response.response_code > 0) { /* POST parameter processing error. Do nothing. */ @@ -979,7 +1040,7 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser, } } else { /* Other RESTful resources */ - ast_ari_invoke(ser, uri, method, get_params, headers, + ast_ari_invoke(ser, uri, method, get_params, headers, body, &response); } @@ -991,6 +1052,7 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser, } request_failed: + /* If you explicitly want to have no content, set message to * ast_json_null(). */ @@ -1013,8 +1075,13 @@ request_failed: } } - ast_debug(3, "Examining ARI response:\n%d %s\n%s\n%s\n", response.response_code, - response.response_text, ast_str_buffer(response.headers), ast_str_buffer(response_body)); + if (debug_app) { + ast_verbose("<--- Sending ARI response to %s --->\n%d %s\n%s%s\n\n", + ast_sockaddr_stringify(&ser->remote_address), response.response_code, + response.response_text, ast_str_buffer(response.headers), + ast_str_buffer(response_body)); + } + ast_http_send(ser, method, response.response_code, response.response_text, response.headers, response_body, 0, 0); diff --git a/res/res_ari_applications.c b/res/res_ari_applications.c index dd868a602..ac2c3ba42 100644 --- a/res/res_ari_applications.c +++ b/res/res_ari_applications.c @@ -62,10 +62,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_applications_list_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_applications_list_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -113,11 +112,10 @@ fin: __attribute__((unused)) static void ast_ari_applications_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_applications_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -210,11 +208,10 @@ int ast_ari_applications_subscribe_parse_body( static void ast_ari_applications_subscribe_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_applications_subscribe_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -272,21 +269,6 @@ static void ast_ari_applications_subscribe_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_applications_subscribe_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -376,11 +358,10 @@ int ast_ari_applications_unsubscribe_parse_body( static void ast_ari_applications_unsubscribe_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_applications_unsubscribe_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -438,21 +419,6 @@ static void ast_ari_applications_unsubscribe_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_applications_unsubscribe_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; diff --git a/res/res_ari_asterisk.c b/res/res_ari_asterisk.c index b52a2a722..b1680e300 100644 --- a/res/res_ari_asterisk.c +++ b/res/res_ari_asterisk.c @@ -62,11 +62,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_asterisk_get_object_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_get_object_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -135,11 +134,10 @@ int ast_ari_asterisk_update_object_parse_body( static void ast_ari_asterisk_update_object_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_update_object_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -157,21 +155,6 @@ static void ast_ari_asterisk_update_object_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } args.fields = body; ast_ari_asterisk_update_object(headers, &args, response); #if defined(AST_DEVMODE) @@ -218,11 +201,10 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_delete_object_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_delete_object_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -322,11 +304,10 @@ int ast_ari_asterisk_get_info_parse_body( static void ast_ari_asterisk_get_info_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_get_info_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -378,21 +359,6 @@ static void ast_ari_asterisk_get_info_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_asterisk_get_info_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -441,10 +407,9 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_list_modules_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_list_modules_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -492,11 +457,10 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_get_module_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_get_module_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -552,11 +516,10 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_load_module_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_load_module_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -611,11 +574,10 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_unload_module_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_unload_module_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -671,11 +633,10 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_reload_module_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_reload_module_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -731,10 +692,9 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_list_log_channels_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_list_log_channels_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -795,11 +755,10 @@ int ast_ari_asterisk_add_log_parse_body( static void ast_ari_asterisk_add_log_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_add_log_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -817,21 +776,6 @@ static void ast_ari_asterisk_add_log_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_asterisk_add_log_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -880,11 +824,10 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_delete_log_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_delete_log_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -939,11 +882,10 @@ fin: __attribute__((unused)) static void ast_ari_asterisk_rotate_log_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_rotate_log_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1011,11 +953,10 @@ int ast_ari_asterisk_get_global_var_parse_body( static void ast_ari_asterisk_get_global_var_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_get_global_var_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1027,21 +968,6 @@ static void ast_ari_asterisk_get_global_var_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_asterisk_get_global_var_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1106,11 +1032,10 @@ int ast_ari_asterisk_set_global_var_parse_body( static void ast_ari_asterisk_set_global_var_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_asterisk_set_global_var_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1125,21 +1050,6 @@ static void ast_ari_asterisk_set_global_var_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_asterisk_set_global_var_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c index 458192d88..2889c1515 100644 --- a/res/res_ari_bridges.c +++ b/res/res_ari_bridges.c @@ -62,10 +62,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_bridges_list_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_list_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -134,11 +133,10 @@ int ast_ari_bridges_create_parse_body( static void ast_ari_bridges_create_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_create_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -156,21 +154,6 @@ static void ast_ari_bridges_create_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_create_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -234,11 +217,10 @@ int ast_ari_bridges_create_with_id_parse_body( static void ast_ari_bridges_create_with_id_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_create_with_id_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -259,21 +241,6 @@ static void ast_ari_bridges_create_with_id_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_create_with_id_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -320,11 +287,10 @@ fin: __attribute__((unused)) static void ast_ari_bridges_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -379,11 +345,10 @@ fin: __attribute__((unused)) static void ast_ari_bridges_destroy_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_destroy_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -480,11 +445,10 @@ int ast_ari_bridges_add_channel_parse_body( static void ast_ari_bridges_add_channel_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_add_channel_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -545,21 +509,6 @@ static void ast_ari_bridges_add_channel_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_add_channel_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -650,11 +599,10 @@ int ast_ari_bridges_remove_channel_parse_body( static void ast_ari_bridges_remove_channel_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_remove_channel_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -712,21 +660,6 @@ static void ast_ari_bridges_remove_channel_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_remove_channel_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -779,11 +712,10 @@ fin: __attribute__((unused)) static void ast_ari_bridges_set_video_source_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_set_video_source_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -843,11 +775,10 @@ fin: __attribute__((unused)) static void ast_ari_bridges_clear_video_source_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_clear_video_source_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -915,11 +846,10 @@ int ast_ari_bridges_start_moh_parse_body( static void ast_ari_bridges_start_moh_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_start_moh_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -937,21 +867,6 @@ static void ast_ari_bridges_start_moh_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_start_moh_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1000,11 +915,10 @@ fin: __attribute__((unused)) static void ast_ari_bridges_stop_moh_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_stop_moh_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1089,11 +1003,10 @@ int ast_ari_bridges_play_parse_body( static void ast_ari_bridges_play_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_play_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1123,21 +1036,6 @@ static void ast_ari_bridges_play_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_play_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1211,11 +1109,10 @@ int ast_ari_bridges_play_with_id_parse_body( static void ast_ari_bridges_play_with_id_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_play_with_id_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1245,21 +1142,6 @@ static void ast_ari_bridges_play_with_id_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_play_with_id_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1345,11 +1227,10 @@ int ast_ari_bridges_record_parse_body( static void ast_ari_bridges_record_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_bridges_record_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1385,21 +1266,6 @@ static void ast_ari_bridges_record_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_bridges_record_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c index 8cb3388fe..fca0cef05 100644 --- a/res/res_ari_channels.c +++ b/res/res_ari_channels.c @@ -62,10 +62,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_channels_list_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_list_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -174,11 +173,10 @@ int ast_ari_channels_originate_parse_body( static void ast_ari_channels_originate_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_originate_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -226,21 +224,6 @@ static void ast_ari_channels_originate_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } args.variables = body; ast_ari_channels_originate(headers, &args, response); #if defined(AST_DEVMODE) @@ -286,11 +269,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -402,11 +384,10 @@ int ast_ari_channels_originate_with_id_parse_body( static void ast_ari_channels_originate_with_id_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_originate_with_id_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -457,21 +438,6 @@ static void ast_ari_channels_originate_with_id_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } args.variables = body; ast_ari_channels_originate_with_id(headers, &args, response); #if defined(AST_DEVMODE) @@ -530,11 +496,10 @@ int ast_ari_channels_hangup_parse_body( static void ast_ari_channels_hangup_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_hangup_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -552,21 +517,6 @@ static void ast_ari_channels_hangup_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_hangup_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -640,11 +590,10 @@ int ast_ari_channels_continue_in_dialplan_parse_body( static void ast_ari_channels_continue_in_dialplan_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_continue_in_dialplan_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -671,21 +620,6 @@ static void ast_ari_channels_continue_in_dialplan_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_continue_in_dialplan_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -747,11 +681,10 @@ int ast_ari_channels_redirect_parse_body( static void ast_ari_channels_redirect_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_redirect_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -769,21 +702,6 @@ static void ast_ari_channels_redirect_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_redirect_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -834,11 +752,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_answer_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_answer_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -894,11 +811,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_ring_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_ring_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -954,11 +870,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_ring_stop_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_ring_stop_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1043,11 +958,10 @@ int ast_ari_channels_send_dtmf_parse_body( static void ast_ari_channels_send_dtmf_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_send_dtmf_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1077,21 +991,6 @@ static void ast_ari_channels_send_dtmf_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_send_dtmf_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1154,11 +1053,10 @@ int ast_ari_channels_mute_parse_body( static void ast_ari_channels_mute_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_mute_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1176,21 +1074,6 @@ static void ast_ari_channels_mute_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_mute_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1252,11 +1135,10 @@ int ast_ari_channels_unmute_parse_body( static void ast_ari_channels_unmute_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_unmute_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1274,21 +1156,6 @@ static void ast_ari_channels_unmute_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_unmute_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1337,11 +1204,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_hold_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_hold_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1397,11 +1263,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_unhold_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_unhold_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1470,11 +1335,10 @@ int ast_ari_channels_start_moh_parse_body( static void ast_ari_channels_start_moh_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_start_moh_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1492,21 +1356,6 @@ static void ast_ari_channels_start_moh_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_start_moh_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1555,11 +1404,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_stop_moh_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_stop_moh_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1615,11 +1463,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_start_silence_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_start_silence_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1675,11 +1522,10 @@ fin: __attribute__((unused)) static void ast_ari_channels_stop_silence_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_stop_silence_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1764,11 +1610,10 @@ int ast_ari_channels_play_parse_body( static void ast_ari_channels_play_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_play_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1798,21 +1643,6 @@ static void ast_ari_channels_play_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_play_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -1886,11 +1716,10 @@ int ast_ari_channels_play_with_id_parse_body( static void ast_ari_channels_play_with_id_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_play_with_id_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -1920,21 +1749,6 @@ static void ast_ari_channels_play_with_id_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_play_with_id_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -2020,11 +1834,10 @@ int ast_ari_channels_record_parse_body( static void ast_ari_channels_record_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_record_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -2060,21 +1873,6 @@ static void ast_ari_channels_record_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_record_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -2138,11 +1936,10 @@ int ast_ari_channels_get_channel_var_parse_body( static void ast_ari_channels_get_channel_var_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_get_channel_var_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -2160,21 +1957,6 @@ static void ast_ari_channels_get_channel_var_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_get_channel_var_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -2241,11 +2023,10 @@ int ast_ari_channels_set_channel_var_parse_body( static void ast_ari_channels_set_channel_var_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_set_channel_var_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -2266,21 +2047,6 @@ static void ast_ari_channels_set_channel_var_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_set_channel_var_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -2359,11 +2125,10 @@ int ast_ari_channels_snoop_channel_parse_body( static void ast_ari_channels_snoop_channel_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_snoop_channel_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -2393,21 +2158,6 @@ static void ast_ari_channels_snoop_channel_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_snoop_channel_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -2481,11 +2231,10 @@ int ast_ari_channels_snoop_channel_with_id_parse_body( static void ast_ari_channels_snoop_channel_with_id_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_channels_snoop_channel_with_id_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -2515,21 +2264,6 @@ static void ast_ari_channels_snoop_channel_with_id_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_channels_snoop_channel_with_id_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; diff --git a/res/res_ari_device_states.c b/res/res_ari_device_states.c index 6d5d19f58..cf0b7a989 100644 --- a/res/res_ari_device_states.c +++ b/res/res_ari_device_states.c @@ -62,10 +62,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_device_states_list_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_device_states_list_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -113,11 +112,10 @@ fin: __attribute__((unused)) static void ast_ari_device_states_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_device_states_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -184,11 +182,10 @@ int ast_ari_device_states_update_parse_body( static void ast_ari_device_states_update_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_device_states_update_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -206,21 +203,6 @@ static void ast_ari_device_states_update_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_device_states_update_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -269,11 +251,10 @@ fin: __attribute__((unused)) static void ast_ari_device_states_delete_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_device_states_delete_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; diff --git a/res/res_ari_endpoints.c b/res/res_ari_endpoints.c index e3ade435d..4a5ddd9e2 100644 --- a/res/res_ari_endpoints.c +++ b/res/res_ari_endpoints.c @@ -62,10 +62,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_endpoints_list_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_endpoints_list_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -134,11 +133,10 @@ int ast_ari_endpoints_send_message_parse_body( static void ast_ari_endpoints_send_message_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_endpoints_send_message_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -156,21 +154,6 @@ static void ast_ari_endpoints_send_message_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } args.variables = body; ast_ari_endpoints_send_message(headers, &args, response); #if defined(AST_DEVMODE) @@ -216,11 +199,10 @@ fin: __attribute__((unused)) static void ast_ari_endpoints_list_by_tech_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_endpoints_list_by_tech_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -275,11 +257,10 @@ fin: __attribute__((unused)) static void ast_ari_endpoints_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_endpoints_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -355,11 +336,10 @@ int ast_ari_endpoints_send_message_to_endpoint_parse_body( static void ast_ari_endpoints_send_message_to_endpoint_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_endpoints_send_message_to_endpoint_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -383,21 +363,6 @@ static void ast_ari_endpoints_send_message_to_endpoint_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } args.variables = body; ast_ari_endpoints_send_message_to_endpoint(headers, &args, response); #if defined(AST_DEVMODE) diff --git a/res/res_ari_events.c b/res/res_ari_events.c index e85db4c45..d102428bb 100644 --- a/res/res_ari_events.c +++ b/res/res_ari_events.c @@ -288,11 +288,10 @@ int ast_ari_events_user_event_parse_body( static void ast_ari_events_user_event_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_events_user_event_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -353,21 +352,6 @@ static void ast_ari_events_user_event_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } args.variables = body; ast_ari_events_user_event(headers, &args, response); #if defined(AST_DEVMODE) diff --git a/res/res_ari_mailboxes.c b/res/res_ari_mailboxes.c index 6ed16a84e..8e0648b8a 100644 --- a/res/res_ari_mailboxes.c +++ b/res/res_ari_mailboxes.c @@ -62,10 +62,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_mailboxes_list_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_mailboxes_list_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -113,11 +112,10 @@ fin: __attribute__((unused)) static void ast_ari_mailboxes_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_mailboxes_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -189,11 +187,10 @@ int ast_ari_mailboxes_update_parse_body( static void ast_ari_mailboxes_update_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_mailboxes_update_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -214,21 +211,6 @@ static void ast_ari_mailboxes_update_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_mailboxes_update_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -276,11 +258,10 @@ fin: __attribute__((unused)) static void ast_ari_mailboxes_delete_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_mailboxes_delete_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; diff --git a/res/res_ari_playbacks.c b/res/res_ari_playbacks.c index 233603303..a0ebd66a3 100644 --- a/res/res_ari_playbacks.c +++ b/res/res_ari_playbacks.c @@ -62,11 +62,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_playbacks_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_playbacks_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -121,11 +120,10 @@ fin: __attribute__((unused)) static void ast_ari_playbacks_stop_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_playbacks_stop_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -193,11 +191,10 @@ int ast_ari_playbacks_control_parse_body( static void ast_ari_playbacks_control_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_playbacks_control_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -215,21 +212,6 @@ static void ast_ari_playbacks_control_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_playbacks_control_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; diff --git a/res/res_ari_recordings.c b/res/res_ari_recordings.c index 04ce0ac97..bdcf67681 100644 --- a/res/res_ari_recordings.c +++ b/res/res_ari_recordings.c @@ -62,10 +62,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_recordings_list_stored_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_list_stored_args args = {}; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -113,11 +112,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_get_stored_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_get_stored_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -172,11 +170,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_delete_stored_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_delete_stored_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -244,11 +241,10 @@ int ast_ari_recordings_copy_stored_parse_body( static void ast_ari_recordings_copy_stored_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_copy_stored_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -266,21 +262,6 @@ static void ast_ari_recordings_copy_stored_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_recordings_copy_stored_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -329,11 +310,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_get_live_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_get_live_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -388,11 +368,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_cancel_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_cancel_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -447,11 +426,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_stop_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_stop_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -506,11 +484,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_pause_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_pause_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -566,11 +543,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_unpause_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_unpause_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -626,11 +602,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_mute_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_mute_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -686,11 +661,10 @@ fin: __attribute__((unused)) static void ast_ari_recordings_unmute_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_recordings_unmute_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; diff --git a/res/res_ari_sounds.c b/res/res_ari_sounds.c index 935025dec..48fa204c5 100644 --- a/res/res_ari_sounds.c +++ b/res/res_ari_sounds.c @@ -79,11 +79,10 @@ int ast_ari_sounds_list_parse_body( static void ast_ari_sounds_list_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_sounds_list_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; @@ -98,21 +97,6 @@ static void ast_ari_sounds_list_cb( } else {} } - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } if (ast_ari_sounds_list_parse_body(body, &args)) { ast_ari_response_alloc_failed(response); goto fin; @@ -159,11 +143,10 @@ fin: __attribute__((unused)) static void ast_ari_sounds_get_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_sounds_get_args args = {}; struct ast_variable *i; - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 6f5182072..6b0f00abf 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -1433,6 +1433,7 @@ static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, con else if (!strcasecmp(tmp->name, "sort") && !strcasecmp(tmp->value, "alpha")) ast_set_flag(mohclass, MOH_SORTALPHA); else if (!strcasecmp(tmp->name, "format")) { + ao2_cleanup(mohclass->format); mohclass->format = ast_format_cache_get(tmp->value); if (!mohclass->format) { ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", tmp->value); @@ -1765,6 +1766,7 @@ static int load_moh_classes(int reload) } else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "alpha")) { ast_set_flag(class, MOH_SORTALPHA); } else if (!strcasecmp(var->name, "format")) { + ao2_cleanup(class->format); class->format = ast_format_cache_get(var->value); if (!class->format) { ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value); diff --git a/res/res_pjproject.c b/res/res_pjproject.c index cd562663b..e02515b48 100644 --- a/res/res_pjproject.c +++ b/res/res_pjproject.c @@ -412,18 +412,22 @@ static char *handle_pjproject_set_log_level(struct ast_cli_entry *e, int cmd, st } /* Update pjproject logging level */ + if (ast_pjproject_max_log_level < level_new) { + level_new = ast_pjproject_max_log_level; + ast_cli(a->fd, + "Asterisk built or linked with pjproject PJ_LOG_MAX_LEVEL=%d.\n" + "Lowering request to the max supported level.\n", + ast_pjproject_max_log_level); + } level_old = ast_option_pjproject_log_level; if (level_old == level_new) { ast_cli(a->fd, "pjproject log level is still %d.\n", level_old); } else { ast_cli(a->fd, "pjproject log level was %d and is now %d.\n", level_old, level_new); + ast_option_pjproject_log_level = level_new; pj_log_set_level(level_new); } - ast_option_pjproject_log_level = pj_log_get_level(); - if (ast_option_pjproject_log_level != level_new) { - ast_log(LOG_WARNING, "Asterisk built with pjproject PJ_LOG_MAX_LEVEL set too low.\n"); - } return CLI_SUCCESS; } @@ -497,7 +501,7 @@ static int load_module(void) ast_sorcery_load(pjproject_sorcery); - pj_log_set_level(ast_option_pjproject_log_level); + AST_PJPROJECT_INIT_LOG_LEVEL(); pj_init(); decor_orig = pj_log_get_decor(); @@ -514,12 +518,19 @@ static int load_module(void) pj_log_set_decor(0); pj_log_set_level(MAX_PJ_LOG_MAX_LEVEL);/* Set level to guarantee the dump output. */ pj_dump_config(); - pj_log_set_level(ast_option_pjproject_log_level); pj_log_set_decor(PJ_LOG_HAS_SENDER | PJ_LOG_HAS_INDENT); pj_log_set_log_func(log_forwarder); - if (!AST_VECTOR_SIZE(&buildopts) - || ast_option_pjproject_log_level != pj_log_get_level()) { - ast_log(LOG_WARNING, "Asterisk built or linked with pjproject PJ_LOG_MAX_LEVEL set too low.\n"); + if (ast_pjproject_max_log_level < ast_option_pjproject_log_level) { + ast_log(LOG_WARNING, + "Asterisk built or linked with pjproject PJ_LOG_MAX_LEVEL=%d which is too low for startup level: %d.\n", + ast_pjproject_max_log_level, ast_option_pjproject_log_level); + ast_option_pjproject_log_level = ast_pjproject_max_log_level; + } + pj_log_set_level(ast_option_pjproject_log_level); + if (!AST_VECTOR_SIZE(&buildopts)) { + ast_log(LOG_NOTICE, + "Asterisk built or linked with pjproject PJ_LOG_MAX_LEVEL=%d which is too low to get buildopts.\n", + ast_pjproject_max_log_level); } ast_cli_register_multiple(pjproject_cli, ARRAY_LEN(pjproject_cli)); diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index 89590689b..bfaf750d4 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -2070,6 +2070,8 @@ static void endpoint_destructor(void* obj) ast_variables_destroy(endpoint->channel_vars); AST_VECTOR_FREE(&endpoint->ident_method_order); ast_free(endpoint->contact_user); + ast_free_acl_list(endpoint->contact_acl); + ast_free_acl_list(endpoint->acl); } static int init_subscription_configuration(struct ast_sip_endpoint_subscription_configuration *subscription) diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c index 68922315e..6fc724a1e 100644 --- a/res/res_pjsip_endpoint_identifier_ip.c +++ b/res/res_pjsip_endpoint_identifier_ip.c @@ -247,7 +247,7 @@ static int ip_identify_match_handler(const struct aco_option *opt, struct ast_va while ((current_string = ast_strip(strsep(&input_string, ",")))) { char *mask = strrchr(current_string, '/'); - int error; + int error = 0; if (ast_strlen_zero(current_string)) { continue; @@ -323,9 +323,14 @@ static int ip_identify_apply(const struct ast_sorcery *sorcery, void *obj) } else if (results == -1) { ast_log(LOG_ERROR, "An error occurred when adding resolution results of '%s' on '%s'\n", current_string, ast_sorcery_object_get_id(obj)); + ao2_ref(current_string, -1); + ao2_iterator_destroy(&i); return -1; } + + ao2_ref(current_string, -1); } + ao2_iterator_destroy(&i); ao2_ref(identify->hosts, -1); identify->hosts = NULL; diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c index 7542bd686..f51558208 100644 --- a/res/res_pjsip_pubsub.c +++ b/res/res_pjsip_pubsub.c @@ -42,6 +42,7 @@ #include "asterisk/res_pjsip.h" #include "asterisk/callerid.h" #include "asterisk/manager.h" +#include "asterisk/cli.h" #include "asterisk/test.h" #include "res_pjsip/include/res_pjsip_private.h" #include "asterisk/res_pjsip_presence_xml.h" @@ -3754,6 +3755,541 @@ static int ami_show_resource_lists(struct mansession *s, const struct message *m #define AMI_SHOW_SUBSCRIPTIONS_INBOUND "PJSIPShowSubscriptionsInbound" #define AMI_SHOW_SUBSCRIPTIONS_OUTBOUND "PJSIPShowSubscriptionsOutbound" +#define MAX_REGEX_ERROR_LEN 128 + +struct cli_sub_parms { + /*! CLI handler entry e parameter */ + struct ast_cli_entry *e; + /*! CLI handler entry a parameter */ + struct ast_cli_args *a; + /*! CLI subscription entry output line(s) */ + struct ast_str *buf; + /*! Compiled regular expression to select if buf is written to CLI when not NULL. */ + regex_t *like; + int count; +}; + +struct cli_sub_complete_parms { + struct ast_cli_args *a; + /*! Found callid for search position */ + char *callid; + int wordlen; + int which; +}; + +static int cli_complete_subscription_common(struct sip_subscription_tree *sub_tree, struct cli_sub_complete_parms *cli) +{ + pj_str_t *callid; + + if (!sub_tree->dlg) { + return 0; + } + + callid = &sub_tree->dlg->call_id->id; + if (cli->wordlen <= pj_strlen(callid) + && !strncasecmp(cli->a->word, pj_strbuf(callid), cli->wordlen) + && (++cli->which > cli->a->n)) { + cli->callid = ast_malloc(pj_strlen(callid) + 1); + if (cli->callid) { + ast_copy_pj_str(cli->callid, callid, pj_strlen(callid) + 1); + } + return -1; + } + return 0; +} + +static int cli_complete_subscription_inbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_NOTIFIER + ? cli_complete_subscription_common(sub_tree, arg) : 0; +} + +static int cli_complete_subscription_outbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_SUBSCRIBER + ? cli_complete_subscription_common(sub_tree, arg) : 0; +} + +static char *cli_complete_subscription_callid(struct ast_cli_args *a) +{ + struct cli_sub_complete_parms cli; + on_subscription_t on_subscription; + + if (a->pos != 4) { + return NULL; + } + + if (!strcasecmp(a->argv[3], "inbound")) { + on_subscription = cli_complete_subscription_inbound; + } else if (!strcasecmp(a->argv[3], "outbound")) { + on_subscription = cli_complete_subscription_outbound; + } else { + /* Should never get here */ + ast_assert(0); + return NULL; + } + + cli.a = a; + cli.callid = NULL; + cli.wordlen = strlen(a->word); + cli.which = 0; + for_each_subscription(on_subscription, &cli); + + return cli.callid; +} + +static int cli_subscription_expiry(struct sip_subscription_tree *sub_tree) +{ + int expiry; + + expiry = sub_tree->persistence + ? ast_tvdiff_ms(sub_tree->persistence->expires, ast_tvnow()) / 1000 + : 0; + if (expiry < 0) { + /* Subscription expired */ + expiry = 0; + } + return expiry; +} + +static int cli_show_subscription_common(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli) +{ + const char *callid = (const char *) cli->buf;/* Member repurposed to pass in callid */ + pj_str_t *sub_callid; + struct ast_str *buf; + char *src; + char *dest; + char *key; + char *value; + char *value_end; + int key_len; + int key_filler_width; + int value_len; + + if (!sub_tree->dlg) { + return 0; + } + sub_callid = &sub_tree->dlg->call_id->id; + if (pj_strcmp2(sub_callid, callid)) { + return 0; + } + + buf = ast_str_create(512); + if (!buf) { + return -1; + } + + ast_cli(cli->a->fd, + "%-20s: %s\n" + "===========================================================================\n", + "ParameterName", "ParameterValue"); + + ast_str_append(&buf, 0, "Resource: %s\n", sub_tree->root->resource); + ast_str_append(&buf, 0, "Event: %s\n", sub_tree->root->handler->event_name); + ast_str_append(&buf, 0, "Expiry: %d\n", cli_subscription_expiry(sub_tree)); + + sip_subscription_to_ami(sub_tree, &buf); + + /* Convert AMI \r\n to \n line terminators. */ + src = strchr(ast_str_buffer(buf), '\r'); + if (src) { + dest = src; + ++src; + while (*src) { + if (*src == '\r') { + ++src; + continue; + } + *dest++ = *src++; + } + *dest = '\0'; + ast_str_update(buf); + } + + /* Reformat AMI key value pairs to pretty columns */ + key = ast_str_buffer(buf); + do { + value = strchr(key, ':'); + if (!value) { + break; + } + value_end = strchr(value, '\n'); + if (!value_end) { + break; + } + + /* Calculate field lengths */ + key_len = value - key; + key_filler_width = 20 - key_len; + if (key_filler_width < 0) { + key_filler_width = 0; + } + value_len = value_end - value; + + ast_cli(cli->a->fd, "%.*s%*s%.*s\n", + key_len, key, key_filler_width, "", + value_len, value); + + key = value_end + 1; + } while (*key); + ast_cli(cli->a->fd, "\n"); + + ast_free(buf); + + return -1; +} + +static int cli_show_subscription_inbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_NOTIFIER + ? cli_show_subscription_common(sub_tree, arg) : 0; +} + +static int cli_show_subscription_outbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_SUBSCRIBER + ? cli_show_subscription_common(sub_tree, arg) : 0; +} + +static char *cli_show_subscription_inout(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + on_subscription_t on_subscription; + struct cli_sub_parms cli; + + switch (cmd) { + case CLI_INIT: + e->command = "pjsip show subscription {inbound|outbound}"; + e->usage = "Usage:\n" + " pjsip show subscription inbound <call-id>\n" + " pjsip show subscription outbound <call-id>\n" + " Show active subscription with the dialog call-id\n"; + return NULL; + case CLI_GENERATE: + return cli_complete_subscription_callid(a); + } + + if (a->argc != 5) { + return CLI_SHOWUSAGE; + } + + if (!strcasecmp(a->argv[3], "inbound")) { + on_subscription = cli_show_subscription_inbound; + } else if (!strcasecmp(a->argv[3], "outbound")) { + on_subscription = cli_show_subscription_outbound; + } else { + /* Should never get here */ + ast_assert(0); + return NULL; + } + + /* Find the subscription with the specified call-id */ + cli.a = a; + cli.e = e; + cli.buf = (void *) a->argv[4];/* Repurpose the buf member to pass in callid */ + for_each_subscription(on_subscription, &cli); + + return CLI_SUCCESS; +} + +#define CLI_SHOW_SUB_FORMAT_HEADER \ + "Endpoint: <Endpoint/Caller-ID.............................................>\n" \ + "Resource: <Resource/Event.................................................>\n" \ + " Expiry: <Expiry> <Call-id..............................................>\n" \ + "===========================================================================\n\n" +#define CLI_SHOW_SUB_FORMAT_ENTRY \ + "Endpoint: %s/%s\n" \ + "Resource: %s/%s\n" \ + " Expiry: %8d %s\n\n" + +static int cli_show_subscriptions_detail(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli) +{ + char caller_id[256]; + char callid[256]; + + ast_callerid_merge(caller_id, sizeof(caller_id), + S_COR(sub_tree->endpoint->id.self.name.valid, + sub_tree->endpoint->id.self.name.str, NULL), + S_COR(sub_tree->endpoint->id.self.number.valid, + sub_tree->endpoint->id.self.number.str, NULL), + "<none>"); + + /* Call-id */ + if (sub_tree->dlg) { + ast_copy_pj_str(callid, &sub_tree->dlg->call_id->id, sizeof(callid)); + } else { + ast_copy_string(callid, "<unknown>", sizeof(callid)); + } + + ast_str_set(&cli->buf, 0, CLI_SHOW_SUB_FORMAT_ENTRY, + ast_sorcery_object_get_id(sub_tree->endpoint), caller_id, + sub_tree->root->resource, sub_tree->root->handler->event_name, + cli_subscription_expiry(sub_tree), callid); + + if (cli->like) { + if (regexec(cli->like, ast_str_buffer(cli->buf), 0, NULL, 0)) { + /* Output line did not match the regex */ + return 0; + } + } + + ast_cli(cli->a->fd, "%s", ast_str_buffer(cli->buf)); + ++cli->count; + + return 0; +} + +static int cli_show_subscriptions_inbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_NOTIFIER + ? cli_show_subscriptions_detail(sub_tree, arg) : 0; +} + +static int cli_show_subscriptions_outbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_SUBSCRIBER + ? cli_show_subscriptions_detail(sub_tree, arg) : 0; +} + +static char *cli_show_subscriptions_inout(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + on_subscription_t on_subscription; + struct cli_sub_parms cli; + regex_t like; + const char *regex; + + switch (cmd) { + case CLI_INIT: + e->command = "pjsip show subscriptions {inbound|outbound} [like]"; + e->usage = "Usage:\n" + " pjsip show subscriptions inbound [like <regex>]\n" + " Show active inbound subscriptions\n" + " pjsip show subscriptions outbound [like <regex>]\n" + " Show active outbound subscriptions\n" + "\n" + " The regex selects a subscriptions output that matches.\n" + " i.e., All output lines for a subscription are checked\n" + " as a block by the regex.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 4 && a->argc != 6) { + return CLI_SHOWUSAGE; + } + if (!strcasecmp(a->argv[3], "inbound")) { + on_subscription = cli_show_subscriptions_inbound; + } else if (!strcasecmp(a->argv[3], "outbound")) { + on_subscription = cli_show_subscriptions_outbound; + } else { + /* Should never get here */ + ast_assert(0); + return CLI_SHOWUSAGE; + } + if (a->argc == 6) { + int rc; + + if (strcasecmp(a->argv[4], "like")) { + return CLI_SHOWUSAGE; + } + + /* Setup regular expression */ + memset(&like, 0, sizeof(like)); + cli.like = &like; + regex = a->argv[5]; + rc = regcomp(cli.like, regex, REG_EXTENDED | REG_NOSUB); + if (rc) { + char *regerr = ast_alloca(MAX_REGEX_ERROR_LEN); + + regerror(rc, cli.like, regerr, MAX_REGEX_ERROR_LEN); + ast_cli(a->fd, "Regular expression '%s' failed to compile: %s\n", + regex, regerr); + return CLI_FAILURE; + } + } else { + cli.like = NULL; + regex = NULL; + } + + cli.a = a; + cli.e = e; + cli.count = 0; + cli.buf = ast_str_create(256); + if (!cli.buf) { + if (cli.like) { + regfree(cli.like); + } + return CLI_FAILURE; + } + + ast_cli(a->fd, CLI_SHOW_SUB_FORMAT_HEADER); + for_each_subscription(on_subscription, &cli); + ast_cli(a->fd, "%d active subscriptions%s%s%s\n", + cli.count, + regex ? " matched \"" : "", + regex ?: "", + regex ? "\"" : ""); + + ast_free(cli.buf); + if (cli.like) { + regfree(cli.like); + } + + return CLI_SUCCESS; +} + +#define CLI_LIST_SUB_FORMAT_HEADER "%-30.30s %-30.30s %6.6s %s\n" +#define CLI_LIST_SUB_FORMAT_ENTRY "%-30.30s %-30.30s %6d %s\n" + +static int cli_list_subscriptions_detail(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli) +{ + char ep_cid_buf[50]; + char res_evt_buf[50]; + char callid[256]; + + /* Endpoint/CID column */ + snprintf(ep_cid_buf, sizeof(ep_cid_buf), "%s/%s", + ast_sorcery_object_get_id(sub_tree->endpoint), + S_COR(sub_tree->endpoint->id.self.name.valid, sub_tree->endpoint->id.self.name.str, + S_COR(sub_tree->endpoint->id.self.number.valid, + sub_tree->endpoint->id.self.number.str, "<none>"))); + + /* Resource/Event column */ + snprintf(res_evt_buf, sizeof(res_evt_buf), "%s/%s", + sub_tree->root->resource, + sub_tree->root->handler->event_name); + + /* Call-id column */ + if (sub_tree->dlg) { + ast_copy_pj_str(callid, &sub_tree->dlg->call_id->id, sizeof(callid)); + } else { + ast_copy_string(callid, "<unknown>", sizeof(callid)); + } + + ast_str_set(&cli->buf, 0, CLI_LIST_SUB_FORMAT_ENTRY, + ep_cid_buf, + res_evt_buf, + cli_subscription_expiry(sub_tree), + callid); + + if (cli->like) { + if (regexec(cli->like, ast_str_buffer(cli->buf), 0, NULL, 0)) { + /* Output line did not match the regex */ + return 0; + } + } + + ast_cli(cli->a->fd, "%s", ast_str_buffer(cli->buf)); + ++cli->count; + + return 0; +} + +static int cli_list_subscriptions_inbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_NOTIFIER + ? cli_list_subscriptions_detail(sub_tree, arg) : 0; +} + +static int cli_list_subscriptions_outbound(struct sip_subscription_tree *sub_tree, void *arg) +{ + return sub_tree->role == AST_SIP_SUBSCRIBER + ? cli_list_subscriptions_detail(sub_tree, arg) : 0; +} + +static char *cli_list_subscriptions_inout(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + on_subscription_t on_subscription; + struct cli_sub_parms cli; + regex_t like; + const char *regex; + + switch (cmd) { + case CLI_INIT: + e->command = "pjsip list subscriptions {inbound|outbound} [like]"; + e->usage = "Usage:\n" + " pjsip list subscriptions inbound [like <regex>]\n" + " List active inbound subscriptions\n" + " pjsip list subscriptions outbound [like <regex>]\n" + " List active outbound subscriptions\n" + "\n" + " The regex selects output lines that match.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 4 && a->argc != 6) { + return CLI_SHOWUSAGE; + } + if (!strcasecmp(a->argv[3], "inbound")) { + on_subscription = cli_list_subscriptions_inbound; + } else if (!strcasecmp(a->argv[3], "outbound")) { + on_subscription = cli_list_subscriptions_outbound; + } else { + /* Should never get here */ + ast_assert(0); + return CLI_SHOWUSAGE; + } + if (a->argc == 6) { + int rc; + + if (strcasecmp(a->argv[4], "like")) { + return CLI_SHOWUSAGE; + } + + /* Setup regular expression */ + memset(&like, 0, sizeof(like)); + cli.like = &like; + regex = a->argv[5]; + rc = regcomp(cli.like, regex, REG_EXTENDED | REG_NOSUB); + if (rc) { + char *regerr = ast_alloca(MAX_REGEX_ERROR_LEN); + + regerror(rc, cli.like, regerr, MAX_REGEX_ERROR_LEN); + ast_cli(a->fd, "Regular expression '%s' failed to compile: %s\n", + regex, regerr); + return CLI_FAILURE; + } + } else { + cli.like = NULL; + regex = NULL; + } + + cli.a = a; + cli.e = e; + cli.count = 0; + cli.buf = ast_str_create(256); + if (!cli.buf) { + if (cli.like) { + regfree(cli.like); + } + return CLI_FAILURE; + } + + ast_cli(a->fd, CLI_LIST_SUB_FORMAT_HEADER, + "Endpoint/CLI", "Resource/Event", "Expiry", "Call-id"); + for_each_subscription(on_subscription, &cli); + ast_cli(a->fd, "\n%d active subscriptions%s%s%s\n", + cli.count, + regex ? " matched \"" : "", + regex ?: "", + regex ? "\"" : ""); + + ast_free(cli.buf); + if (cli.like) { + regfree(cli.like); + } + + return CLI_SUCCESS; +} + +static struct ast_cli_entry cli_commands[] = { + AST_CLI_DEFINE(cli_list_subscriptions_inout, "List active inbound/outbound subscriptions"), + AST_CLI_DEFINE(cli_show_subscription_inout, "Show active subscription details"), + AST_CLI_DEFINE(cli_show_subscriptions_inout, "Show active inbound/outbound subscriptions"), +}; + static int persistence_endpoint_str2struct(const struct aco_option *opt, struct ast_variable *var, void *obj) { struct subscription_persistence *persistence = obj; @@ -4695,6 +5231,8 @@ static int load_module(void) ast_manager_register_xml("PJSIPShowResourceLists", EVENT_FLAG_SYSTEM, ami_show_resource_lists); + ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands)); + AST_TEST_REGISTER(resource_tree); AST_TEST_REGISTER(complex_resource_tree); AST_TEST_REGISTER(bad_resource); @@ -4708,6 +5246,16 @@ static int load_module(void) static int unload_module(void) { + AST_TEST_UNREGISTER(resource_tree); + AST_TEST_UNREGISTER(complex_resource_tree); + AST_TEST_UNREGISTER(bad_resource); + AST_TEST_UNREGISTER(bad_branch); + AST_TEST_UNREGISTER(duplicate_resource); + AST_TEST_UNREGISTER(loop); + AST_TEST_UNREGISTER(bad_event); + + ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands)); + ast_manager_unregister(AMI_SHOW_SUBSCRIPTIONS_OUTBOUND); ast_manager_unregister(AMI_SHOW_SUBSCRIPTIONS_INBOUND); ast_manager_unregister("PJSIPShowResourceLists"); @@ -4717,14 +5265,6 @@ static int unload_module(void) ast_sched_context_destroy(sched); } - AST_TEST_UNREGISTER(resource_tree); - AST_TEST_UNREGISTER(complex_resource_tree); - AST_TEST_UNREGISTER(bad_resource); - AST_TEST_UNREGISTER(bad_branch); - AST_TEST_UNREGISTER(duplicate_resource); - AST_TEST_UNREGISTER(loop); - AST_TEST_UNREGISTER(bad_event); - return 0; } diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index 2409e3aee..43d0ae20a 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -232,6 +232,7 @@ struct dtls_details { /*! \brief RTP session description */ struct ast_rtp { int s; + /*! \note The f.subclass.format holds a ref. */ struct ast_frame f; unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET]; unsigned int ssrc; /*!< Synchronization source, RFC 3550, page 10. */ @@ -2767,6 +2768,7 @@ static int ast_rtp_destroy(struct ast_rtp_instance *instance) if (rtp->red) { AST_SCHED_DEL(rtp->sched, rtp->red->schedid); ast_free(rtp->red); + rtp->red = NULL; } #ifdef HAVE_PJPROJECT @@ -3487,7 +3489,8 @@ static int ast_rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame return 0; } -static struct ast_frame *red_t140_to_red(struct rtp_red *red) { +static struct ast_frame *red_t140_to_red(struct rtp_red *red) +{ unsigned char *data = red->t140red.data.ptr; int len = 0; int i; @@ -5062,22 +5065,21 @@ static int rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int struct ast_rtp *rtp = ast_rtp_instance_get_data(instance); int x; - if (!(rtp->red = ast_calloc(1, sizeof(*rtp->red)))) { + rtp->red = ast_calloc(1, sizeof(*rtp->red)); + if (!rtp->red) { return -1; } rtp->red->t140.frametype = AST_FRAME_TEXT; - ao2_replace(rtp->red->t140.subclass.format, ast_format_t140_red); + rtp->red->t140.subclass.format = ast_format_t140_red; rtp->red->t140.data.ptr = &rtp->red->buf_data; - rtp->red->t140.ts = 0; rtp->red->t140red = rtp->red->t140; rtp->red->t140red.data.ptr = &rtp->red->t140red_data; - rtp->red->t140red.datalen = 0; + rtp->red->ti = buffer_time; rtp->red->num_gen = generations; rtp->red->hdrlen = generations * 4 + 1; - rtp->red->prev_ts = 0; for (x = 0; x < generations; x++) { rtp->red->pt[x] = payloads[x]; @@ -5087,8 +5089,6 @@ static int rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int rtp->red->t140red_data[x*4] = rtp->red->pt[x] = payloads[x]; /* primary pt */ rtp->red->schedid = ast_sched_add(rtp->sched, generations, red_write, instance); - rtp->red->t140.datalen = 0; - return 0; } @@ -5216,7 +5216,7 @@ static void ast_rtp_stop(struct ast_rtp_instance *instance) if (rtp->red) { AST_SCHED_DEL(rtp->sched, rtp->red->schedid); - free(rtp->red); + ast_free(rtp->red); rtp->red = NULL; } @@ -5669,7 +5669,7 @@ static int load_module(void) #ifdef HAVE_PJPROJECT pj_lock_t *lock; - pj_log_set_level(ast_option_pjproject_log_level); + AST_PJPROJECT_INIT_LOG_LEVEL(); if (pj_init() != PJ_SUCCESS) { return AST_MODULE_LOAD_DECLINE; } diff --git a/res/res_stasis.c b/res/res_stasis.c index 72b536b52..55240bacc 100644 --- a/res/res_stasis.c +++ b/res/res_stasis.c @@ -67,7 +67,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "stasis/app.h" #include "stasis/control.h" #include "stasis/messaging.h" -#include "stasis/cli.h" #include "stasis/stasis_bridge.h" #include "asterisk/core_unreal.h" #include "asterisk/musiconhold.h" @@ -178,11 +177,6 @@ static struct ast_json *stasis_start_to_json(struct stasis_message *message, STASIS_MESSAGE_TYPE_DEFN_LOCAL(start_message_type, .to_json = stasis_start_to_json); -const char *stasis_app_name(const struct stasis_app *app) -{ - return app_name(app); -} - /*! AO2 hash function for \ref app */ static int app_hash(const void *obj, const int flags) { @@ -944,7 +938,7 @@ static int send_start_msg_snapshots(struct ast_channel *chan, struct stasis_app if (app_subscribe_channel(app, chan)) { ast_log(LOG_ERROR, "Error subscribing app '%s' to channel '%s'\n", - app_name(app), ast_channel_name(chan)); + stasis_app_name(app), ast_channel_name(chan)); return -1; } @@ -958,7 +952,7 @@ static int send_start_msg_snapshots(struct ast_channel *chan, struct stasis_app payload->replace_channel = ao2_bump(replace_channel_snapshot); json_blob = ast_json_pack("{s: s, s: o, s: []}", - "app", app_name(app), + "app", stasis_app_name(app), "timestamp", ast_json_timeval(ast_tvnow(), NULL), "args"); if (!json_blob) { @@ -1028,7 +1022,7 @@ int app_send_end_msg(struct stasis_app *app, struct ast_channel *chan) return 0; } - blob = ast_json_pack("{s: s}", "app", app_name(app)); + blob = ast_json_pack("{s: s}", "app", stasis_app_name(app)); if (!blob) { ast_log(LOG_ERROR, "Error packing JSON for StasisEnd message\n"); return -1; @@ -1474,10 +1468,6 @@ static struct stasis_app *find_app_by_name(const char *app_name) res = ao2_find(apps_registry, app_name, OBJ_SEARCH_KEY); } - if (!res) { - ast_log(LOG_WARNING, "Could not find app '%s'\n", - app_name ? : "(null)"); - } return res; } @@ -1958,8 +1948,6 @@ static int unload_module(void) { stasis_app_unregister_event_sources(); - cli_cleanup(); - messaging_cleanup(); cleanup(); @@ -2117,11 +2105,6 @@ static int load_module(void) return AST_MODULE_LOAD_FAILURE; } - if (cli_init()) { - unload_module(); - return AST_MODULE_LOAD_FAILURE; - } - bridge_stasis_init(); stasis_app_register_event_sources(); diff --git a/res/stasis/app.c b/res/stasis/app.c index 0bef0ee57..e122f34a4 100644 --- a/res/stasis/app.c +++ b/res/stasis/app.c @@ -43,6 +43,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define CHANNEL_ALL "__AST_CHANNEL_ALL_TOPIC" #define ENDPOINT_ALL "__AST_ENDPOINT_ALL_TOPIC" +/*! Global debug flag. No need for locking */ +int global_debug; + static int unsubscribe(struct stasis_app *app, const char *kind, const char *id, int terminate); struct stasis_app { @@ -843,15 +846,64 @@ static void bridge_default_handler(void *data, struct stasis_subscription *sub, } } -void app_set_debug(struct stasis_app *app, int debug) +void stasis_app_set_debug(struct stasis_app *app, int debug) { if (!app) { return; } - { - SCOPED_AO2LOCK(lock, app); - app->debug = debug; + app->debug = debug; +} + +void stasis_app_set_debug_by_name(const char *app_name, int debug) +{ + struct stasis_app *app = stasis_app_get_by_name(app_name); + + if (!app) { + return; + } + + app->debug = debug; + ao2_cleanup(app); +} + +int stasis_app_get_debug(struct stasis_app *app) +{ + return (app ? app->debug : 0) || global_debug; +} + +int stasis_app_get_debug_by_name(const char *app_name) +{ + RAII_VAR(struct stasis_app *, app, stasis_app_get_by_name(app_name), ao2_cleanup); + + return (app ? app->debug : 0) || global_debug; +} + +void stasis_app_set_global_debug(int debug) +{ + global_debug = debug; + if (!global_debug) { + struct ao2_container *app_names = stasis_app_get_all(); + struct ao2_iterator it_app_names; + char *app_name; + struct stasis_app *app; + + if (!app_names || !ao2_container_count(app_names)) { + ao2_cleanup(app_names); + return; + } + + it_app_names = ao2_iterator_init(app_names, 0); + while ((app_name = ao2_iterator_next(&it_app_names))) { + if ((app = stasis_app_get_by_name(app_name))) { + stasis_app_set_debug(app, 0); + } + + ao2_cleanup(app_name); + ao2_cleanup(app); + } + ao2_iterator_cleanup(&it_app_names); + ao2_cleanup(app_names); } } @@ -952,7 +1004,6 @@ struct stasis_topic *ast_app_get_topic(struct stasis_app *app) void app_send(struct stasis_app *app, struct ast_json *message) { stasis_app_cb handler; - int debug; char eid[20]; RAII_VAR(void *, data, NULL, ao2_cleanup); @@ -965,7 +1016,6 @@ void app_send(struct stasis_app *app, struct ast_json *message) /* Copy off mutable state with lock held */ { SCOPED_AO2LOCK(lock, app); - debug = app->debug; handler = app->handler; if (app->data) { ao2_ref(app->data, +1); @@ -974,13 +1024,6 @@ void app_send(struct stasis_app *app, struct ast_json *message) /* Name is immutable; no need to copy */ } - if (debug) { - char *dump = ast_json_dump_string_format(message, AST_JSON_PRETTY); - ast_verb(0, "Dispatching message to Stasis app '%s':\n%s\n", - app->name, dump); - ast_json_free(dump); - } - if (!handler) { ast_verb(3, "Inactive Stasis app '%s' missed message\n", app->name); @@ -1053,7 +1096,7 @@ void app_update(struct stasis_app *app, stasis_app_cb handler, void *data) app->data = data; } -const char *app_name(const struct stasis_app *app) +const char *stasis_app_name(const struct stasis_app *app) { return app->name; } @@ -1070,7 +1113,7 @@ static int forwards_filter_by_type(void *obj, void *arg, int flags) return 0; } -void app_to_cli(const struct stasis_app *app, struct ast_cli_args *a) +void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a) { struct ao2_iterator *channels; struct ao2_iterator *endpoints; diff --git a/res/stasis/app.h b/res/stasis/app.h index 6ed6a295b..ac4ac59fb 100644 --- a/res/stasis/app.h +++ b/res/stasis/app.h @@ -109,15 +109,6 @@ int app_is_finished(struct stasis_app *app); void app_update(struct stasis_app *app, stasis_app_cb handler, void *data); /*! - * \brief Return an application's name. - * - * \param app Application. - * \return Name of the application. - * \return \c NULL is \a app is \c NULL. - */ -const char *app_name(const struct stasis_app *app); - -/*! * \brief Send a message to an application. * * \param app Application. @@ -137,16 +128,6 @@ struct app_forwards; */ struct ast_json *app_to_json(const struct stasis_app *app); -struct ast_cli_args; - -/*! - * \brief Dump properties of a \c stasis_app to the CLI - * - * \param app The application - * \param a The CLI arguments - */ -void app_to_cli(const struct stasis_app *app, struct ast_cli_args *a); - /*! * \brief Subscribes an application to a channel. * @@ -300,12 +281,4 @@ char *app_get_replace_channel_app(struct ast_channel *chan); */ int app_send_end_msg(struct stasis_app *app, struct ast_channel *chan); -/*! - * \brief Enable/disable debugging on an application - * - * \param app The app to debug - * \param debug If non-zero, enable debugging. If zero, disable. - */ -void app_set_debug(struct stasis_app *app, int debug); - #endif /* _ASTERISK_RES_STASIS_APP_H */ diff --git a/res/stasis/cli.c b/res/stasis/cli.c deleted file mode 100644 index f1dee5521..000000000 --- a/res/stasis/cli.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 2016, Digium, Inc. - * - * Matt Jordan <mjordan@digium.com> - * - * See http://www.asterisk.org for more information about - * the Asterisk project. Please do not directly contact - * any of the maintainers of this project for assistance; - * the project provides a web site, mailing lists and IRC - * channels for your use. - * - * This program is free software, distributed under the terms of - * the GNU General Public License Version 2. See the LICENSE file - * at the top of the source tree. - */ - -/*! \file - * - * \brief Stasis CLI commands. - * - * \author Matt Jordan <mjordan@digium.com> - */ - -#include "asterisk.h" - -ASTERISK_FILE_VERSION(__FILE__, "$Revision$") - -#include "asterisk/cli.h" -#include "asterisk/astobj2.h" - -#include "cli.h" -#include "app.h" - - -static char *ari_show_apps(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) -{ - struct ao2_container *apps; - struct ao2_iterator it_apps; - char *app; - - switch (cmd) { - case CLI_INIT: - e->command = "ari show apps"; - e->usage = - "Usage: ari show apps\n" - " Lists all registered applications.\n" - ; - return NULL; - case CLI_GENERATE: - return NULL; - default: - break; - } - - if (a->argc != 3) { - return CLI_SHOWUSAGE; - } - - apps = stasis_app_get_all(); - if (!apps) { - ast_cli(a->fd, "Unable to retrieve registered applications!\n"); - return CLI_FAILURE; - } - - ast_cli(a->fd, "Application Name \n"); - ast_cli(a->fd, "=========================\n"); - it_apps = ao2_iterator_init(apps, 0); - while ((app = ao2_iterator_next(&it_apps))) { - ast_cli(a->fd, "%-25.25s\n", app); - ao2_ref(app, -1); - } - - ao2_iterator_destroy(&it_apps); - ao2_ref(apps, -1); - - return CLI_SUCCESS; -} - -struct app_complete { - /*! Nth app to search for */ - int state; - /*! Which app currently on */ - int which; -}; - -static int complete_ari_app_search(void *obj, void *arg, void *data, int flags) -{ - struct app_complete *search = data; - - if (++search->which > search->state) { - return CMP_MATCH; - } - return 0; -} - -static char *complete_ari_app(struct ast_cli_args *a) -{ - RAII_VAR(struct ao2_container *, apps, stasis_app_get_all(), ao2_cleanup); - RAII_VAR(char *, app, NULL, ao2_cleanup); - - struct app_complete search = { - .state = a->n, - }; - - if (!apps) { - ast_cli(a->fd, "Error getting ARI applications\n"); - return CLI_FAILURE; - } - - app = ao2_callback_data(apps, - ast_strlen_zero(a->word) ? 0 : OBJ_PARTIAL_KEY, - complete_ari_app_search, (char*)a->word, &search); - - return app ? ast_strdup(app) : NULL; -} - -static char *complete_ari_show_app(struct ast_cli_args *a) -{ - if (a->pos == 3) { - return complete_ari_app(a); - } - - return NULL; -} - -static char *ari_show_app(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) -{ - void *app; - - switch (cmd) { - case CLI_INIT: - e->command = "ari show app"; - e->usage = - "Usage: ari show app <application>\n" - " Provide detailed information about a registered application.\n" - ; - return NULL; - case CLI_GENERATE: - return complete_ari_show_app(a); - default: - break; - } - - if (a->argc != 4) { - return CLI_SHOWUSAGE; - } - - app = stasis_app_get_by_name(a->argv[3]); - if (!app) { - return CLI_FAILURE; - } - - app_to_cli(app, a); - - ao2_ref(app, -1); - - return CLI_SUCCESS; -} - -static char *ari_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) -{ - void *app; - int debug; - - switch (cmd) { - case CLI_INIT: - e->command = "ari set debug"; - e->usage = - "Usage: ari set debug <application> <on|off>\n" - " Enable or disable debugging on a specific application.\n" - ; - return NULL; - case CLI_GENERATE: - return complete_ari_show_app(a); - default: - break; - } - - if (a->argc != 5) { - return CLI_SHOWUSAGE; - } - - app = stasis_app_get_by_name(a->argv[3]); - if (!app) { - return CLI_FAILURE; - } - - debug = !strcmp(a->argv[4], "on"); - app_set_debug(app, debug); - ast_cli(a->fd, "Debugging on '%s' %s\n", - app_name(app), - debug ? "enabled" : "disabled"); - - ao2_ref(app, -1); - - return CLI_SUCCESS; -} - -static struct ast_cli_entry cli_ari[] = { - AST_CLI_DEFINE(ari_show_apps, "List registered ARI applications"), - AST_CLI_DEFINE(ari_show_app, "Display details of a registered ARI application"), - AST_CLI_DEFINE(ari_set_debug, "Enable/disable debugging of an ARI application"), -}; - - -int cli_init(void) -{ - return ast_cli_register_multiple(cli_ari, ARRAY_LEN(cli_ari)); -} - -void cli_cleanup(void) -{ - ast_cli_unregister_multiple(cli_ari, ARRAY_LEN(cli_ari)); -} diff --git a/res/stasis/cli.h b/res/stasis/cli.h deleted file mode 100644 index 49235c7b3..000000000 --- a/res/stasis/cli.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 2016, Digium, Inc. - * - * Matt Jordan <mjordan@digium.com> - * - * See http://www.asterisk.org for more information about - * the Asterisk project. Please do not directly contact - * any of the maintainers of this project for assistance; - * the project provides a web site, mailing lists and IRC - * channels for your use. - * - * This program is free software, distributed under the terms of - * the GNU General Public License Version 2. See the LICENSE file - * at the top of the source tree. - */ - -#ifndef _ASTERISK_RES_STASIS_CLI_H -#define _ASTERISK_RES_STASIS_CLI_H - -/*! \file - * - * \brief Internal API for Stasis application CLI commands - * - * \author Matt Jordan <mjordan@digium.com> - * \since 13.13.0 - */ - -/*! - * \brief Initialize the CLI commands - * - * \retval 0 on success - * \retval non-zero on error - */ -int cli_init(void); - -/*! - * \brief Cleanup the CLI commands - */ -void cli_cleanup(void); - -#endif /* _ASTERISK_RES_STASIS_CLI_H */ diff --git a/res/stasis/stasis_bridge.c b/res/stasis/stasis_bridge.c index 9ffc2d7be..81b35e308 100644 --- a/res/stasis/stasis_bridge.c +++ b/res/stasis/stasis_bridge.c @@ -157,13 +157,13 @@ static int bridge_stasis_push_peek(struct ast_bridge *self, struct ast_bridge_ch } to_be_replaced = ast_channel_snapshot_get_latest(ast_channel_uniqueid(swap->chan)); - ast_debug(3, "Copying stasis app name %s from %s to %s\n", app_name(control_app(swap_control)), + ast_debug(3, "Copying stasis app name %s from %s to %s\n", stasis_app_name(control_app(swap_control)), ast_channel_name(swap->chan), ast_channel_name(bridge_channel->chan)); ast_channel_lock(bridge_channel->chan); /* copy the app name from the swap channel */ - app_set_replace_channel_app(bridge_channel->chan, app_name(control_app(swap_control))); + app_set_replace_channel_app(bridge_channel->chan, stasis_app_name(control_app(swap_control))); /* set the replace channel snapshot */ app_set_replace_channel_snapshot(bridge_channel->chan, to_be_replaced); @@ -217,6 +217,7 @@ static int bridge_stasis_push(struct ast_bridge *self, struct ast_bridge_channel */ return -1; } + ao2_cleanup(control); /* * If going into a holding bridge, default the role to participant, if @@ -236,7 +237,6 @@ static int bridge_stasis_push(struct ast_bridge *self, struct ast_bridge_channel } } - ao2_cleanup(control); if (self->allowed_capabilities & STASIS_BRIDGE_MIXING_CAPABILITIES) { ast_bridge_channel_update_linkedids(bridge_channel, swap); if (ast_test_flag(&self->feature_flags, AST_BRIDGE_FLAG_SMART)) { diff --git a/rest-api-templates/param_parsing.mustache b/rest-api-templates/param_parsing.mustache index 247c121d9..d156ab799 100644 --- a/rest-api-templates/param_parsing.mustache +++ b/rest-api-templates/param_parsing.mustache @@ -85,21 +85,6 @@ {{/has_path_parameters}} {{^is_websocket}} {{#parse_body}} - /* Look for a JSON request entity */ - body = ast_http_get_json(ser, headers); - if (!body) { - switch (errno) { - case EFBIG: - ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large"); - goto fin; - case ENOMEM: - ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request"); - goto fin; - case EIO: - ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body"); - goto fin; - } - } {{#body_parameter}} args.{{c_name}} = body; {{/body_parameter}} diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache index 08f6204be..a59f63df5 100644 --- a/rest-api-templates/res_ari_resource.c.mustache +++ b/rest-api-templates/res_ari_resource.c.mustache @@ -78,13 +78,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") static void ast_ari_{{c_name}}_{{c_nickname}}_cb( struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, - struct ast_variable *headers, struct ast_ari_response *response) + struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response) { struct ast_ari_{{c_name}}_{{c_nickname}}_args args = {}; {{#has_parameters}} struct ast_variable *i; {{/has_parameters}} - RAII_VAR(struct ast_json *, body, NULL, ast_json_unref); #if defined(AST_DEVMODE) int is_valid; int code; diff --git a/tests/test_ari.c b/tests/test_ari.c index a61a1182d..e2c36fb38 100644 --- a/tests/test_ari.c +++ b/tests/test_ari.c @@ -62,6 +62,7 @@ static void handler(const char *name, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, + struct ast_json *body, struct ast_ari_response *response) { struct ast_json *message = ast_json_pack("{s: s, s: {}, s: {}, s: {}}", @@ -99,9 +100,10 @@ static void handler(const char *name, struct ast_variable *get_params, \ struct ast_variable *path_vars, \ struct ast_variable *headers, \ + struct ast_json *body, \ struct ast_ari_response *response) \ { \ - handler(#name, response_code, get_params, path_vars, headers, response); \ + handler(#name, response_code, get_params, path_vars, headers, body, response); \ } HANDLER(bang_get, 200) @@ -344,7 +346,8 @@ AST_TEST_DEFINE(invoke_get) "head2", "head-two", "path_vars"); - ast_ari_invoke(NULL, "foo", AST_HTTP_GET, get_params, headers, response); + ast_ari_invoke(NULL, "foo", AST_HTTP_GET, get_params, headers, + ast_json_null(), response); ast_test_validate(test, 1 == invocation_count); ast_test_validate(test, 200 == response->response_code); @@ -381,7 +384,8 @@ AST_TEST_DEFINE(invoke_wildcard) "path_vars", "bam", "foshizzle"); - ast_ari_invoke(NULL, "foo/foshizzle", AST_HTTP_GET, get_params, headers, response); + ast_ari_invoke(NULL, "foo/foshizzle", AST_HTTP_GET, get_params, headers, + ast_json_null(), response); ast_test_validate(test, 1 == invocation_count); ast_test_validate(test, 200 == response->response_code); @@ -418,7 +422,8 @@ AST_TEST_DEFINE(invoke_delete) "path_vars", "bam", "foshizzle"); - ast_ari_invoke(NULL, "foo/foshizzle/bang", AST_HTTP_DELETE, get_params, headers, response); + ast_ari_invoke(NULL, "foo/foshizzle/bang", AST_HTTP_DELETE, get_params, headers, + ast_json_null(), response); ast_test_validate(test, 1 == invocation_count); ast_test_validate(test, 204 == response->response_code); @@ -468,7 +473,8 @@ AST_TEST_DEFINE(invoke_post) "head2", "head-two", "path_vars"); - ast_ari_invoke(NULL, "foo/bar", AST_HTTP_POST, get_params, headers, response); + ast_ari_invoke(NULL, "foo/bar", AST_HTTP_POST, get_params, headers, + ast_json_null(), response); ast_test_validate(test, 1 == invocation_count); ast_test_validate(test, 200 == response->response_code); @@ -497,7 +503,8 @@ AST_TEST_DEFINE(invoke_bad_post) fixture = setup_invocation_test(); response = response_alloc(); - ast_ari_invoke(NULL, "foo", AST_HTTP_POST, get_params, headers, response); + ast_ari_invoke(NULL, "foo", AST_HTTP_POST, get_params, headers, + ast_json_null(), response); ast_test_validate(test, 0 == invocation_count); ast_test_validate(test, 405 == response->response_code); @@ -525,7 +532,8 @@ AST_TEST_DEFINE(invoke_not_found) fixture = setup_invocation_test(); response = response_alloc(); - ast_ari_invoke(NULL, "foo/fizzle/i-am-not-a-resource", AST_HTTP_GET, get_params, headers, response); + ast_ari_invoke(NULL, "foo/fizzle/i-am-not-a-resource", AST_HTTP_GET, get_params, headers, + ast_json_null(), response); ast_test_validate(test, 0 == invocation_count); ast_test_validate(test, 404 == response->response_code); diff --git a/tests/test_voicemail_api.c b/tests/test_voicemail_api.c index 1b03e5431..188db4af5 100644 --- a/tests/test_voicemail_api.c +++ b/tests/test_voicemail_api.c @@ -242,7 +242,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") return AST_TEST_FAIL; \ } \ VM_API_SNAPSHOT_CREATE((mailbox), (context), (folder), 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); \ - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 0); \ + VM_API_INT_VERIFY(0, test_mbox_snapshot->total_msg_num); \ test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); \ } while (0) @@ -1004,10 +1004,10 @@ AST_TEST_DEFINE(voicemail_api_nominal_move) test_vm_api_update_test_snapshots(test_mbox_snapshot); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); - VM_API_STRING_FIELD_VERIFY(test_snapshots[0]->folder_name, "Family"); - VM_API_STRING_FIELD_VERIFY(test_snapshots[1]->folder_name, "Family"); - VM_API_INT_VERIFY(test_snapshots[1]->msg_number, 0); - VM_API_INT_VERIFY(test_snapshots[0]->msg_number, 1); + VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[0]->folder_name); + VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[1]->folder_name); + VM_API_INT_VERIFY(0, test_snapshots[1]->msg_number); + VM_API_INT_VERIFY(1, test_snapshots[0]->msg_number); /* Move both of the 2345 messages to Family */ ast_test_status_update(test, "Test move of test_vm_api_2345 messages from Inbox to Family\n"); @@ -1018,8 +1018,8 @@ AST_TEST_DEFINE(voicemail_api_nominal_move) test_vm_api_update_test_snapshots(test_mbox_snapshot); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); - VM_API_STRING_FIELD_VERIFY(test_snapshots[2]->folder_name, "Family"); - VM_API_STRING_FIELD_VERIFY(test_snapshots[3]->folder_name, "Family"); + VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[2]->folder_name); + VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[3]->folder_name); ast_test_status_update(test, "Test move of test_vm_api_2345 message from Family to INBOX\n"); VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "Family", multi_msg_ids, "INBOX"); @@ -1028,8 +1028,8 @@ AST_TEST_DEFINE(voicemail_api_nominal_move) test_vm_api_update_test_snapshots(test_mbox_snapshot); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); - VM_API_STRING_FIELD_VERIFY(test_snapshots[2]->folder_name, "INBOX"); - VM_API_STRING_FIELD_VERIFY(test_snapshots[3]->folder_name, "INBOX"); + VM_API_STRING_FIELD_VERIFY("INBOX", test_snapshots[2]->folder_name); + VM_API_STRING_FIELD_VERIFY("INBOX", test_snapshots[3]->folder_name); VM_API_TEST_CLEANUP; @@ -1250,12 +1250,12 @@ AST_TEST_DEFINE(voicemail_api_nominal_forward) /* Make sure we didn't delete the message */ VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 1); + VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); /* We should now have a total of 3 messages in test_vm_api_2345 INBOX */ VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 3); + VM_API_INT_VERIFY(3, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX with default context to test_vm_api_2345 INBOX\n"); @@ -1263,12 +1263,12 @@ AST_TEST_DEFINE(voicemail_api_nominal_forward) /* Make sure we didn't delete the message */ VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 1); + VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); /* We should now have a total of 4 messages in test_vm_api_2345 INBOX */ VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 4); + VM_API_INT_VERIFY(4, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX with default context\n"); @@ -1276,12 +1276,12 @@ AST_TEST_DEFINE(voicemail_api_nominal_forward) /* Make sure we didn't delete the message */ VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 1); + VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); /* We should now have a total of 5 messages in test_vm_api_2345 INBOX */ VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 5); + VM_API_INT_VERIFY(5, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX, deleting original\n"); @@ -1289,12 +1289,12 @@ AST_TEST_DEFINE(voicemail_api_nominal_forward) /* Make sure we deleted the message */ VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 0); + VM_API_INT_VERIFY(0, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); /* We should now have a total of 6 messages in test_vm_api_2345 INBOX */ VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 6); + VM_API_INT_VERIFY(6, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); ast_test_status_update(test, "Test forwarding 2 messages from test_vm_api_2345 INBOX to test_vm_api_1234 INBOX"); @@ -1302,24 +1302,24 @@ AST_TEST_DEFINE(voicemail_api_nominal_forward) /* Make sure we didn't delete the messages */ VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 6); + VM_API_INT_VERIFY(6, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); /* We should now have a total of 2 messages in test_vm_api_1234 INBOX */ VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2); + VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); ast_test_status_update(test, "Test forwarding 2 messages from test_vm_api_2345 INBOX to test_vm_api_1234 Family, deleting original\n"); VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "Family", 2, multi_msg_ids, 1); /* Make sure we deleted the messages */ VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 4); + VM_API_INT_VERIFY(4, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); /* We should now have a total of 2 messages in test_vm_api_1234 Family */ VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2); + VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); VM_API_TEST_CLEANUP; @@ -1449,20 +1449,20 @@ AST_TEST_DEFINE(voicemail_api_nominal_msg_playback) ast_test_status_update(test, "Playing back message from test_vm_api_2345 to callback function\n"); VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", "default", "INBOX", message_id_2345[0], &message_playback_callback_fn); - VM_API_INT_VERIFY(global_entered_playback_callback, 1); + VM_API_INT_VERIFY(1, global_entered_playback_callback); global_entered_playback_callback = 0; ast_test_status_update(test, "Playing back message from test_vm_api_2345 to callback function with default context\n"); VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", NULL, "INBOX", message_id_2345[1], &message_playback_callback_fn); - VM_API_INT_VERIFY(global_entered_playback_callback, 1); + VM_API_INT_VERIFY(1, global_entered_playback_callback); global_entered_playback_callback = 0; VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2); + VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); - VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2); + VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num); test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); ast_hangup(test_channel); diff --git a/third-party/pjproject/Makefile b/third-party/pjproject/Makefile index 2398ec428..bfd1c27fc 100644 --- a/third-party/pjproject/Makefile +++ b/third-party/pjproject/Makefile @@ -187,13 +187,11 @@ source/pjsip-apps/lib/libasterisk_malloc_debug.a: source/pjsip-apps/lib/asterisk $(CMD_PREFIX) ar qs $@ $< >/dev/null 2>&1 $(apps): APP = $(filter pj%,$(subst -, ,$(notdir $@))) -$(apps): CFLAGS += -DPJ_LOG_MAX_LEVEL=2 $(apps): LDFLAGS += $(MALLOC_DEBUG_LDFLAGS) $(apps): $(MALLOC_DEBUG_LIBS) pjproject.symbols $(APP_THIRD_PARTY_LIB_FILES) $(ECHO_PREFIX) Compiling $(APP) $(CMD_PREFIX) +$(MAKE) -C source/pjsip-apps/build $(filter pj%,$(subst -, ,$(notdir $@))) $(REALLY_QUIET) -source/pjsip-apps/src/python/_pjsua.o: CFLAGS += -DPJ_LOG_MAX_LEVEL=2 source/pjsip-apps/src/python/_pjsua.o: source/pjsip-apps/src/python/_pjsua.c $(apps) $(ECHO_PREFIX) Compiling python bindings $(CMD_PREFIX) $(CC) -o $@ -c $< $(PYTHONDEV_INCLUDE) $(CFLAGS) $(PJ_CFLAGS) diff --git a/third-party/pjproject/patches/0000-set_apps_initial_log_level.patch b/third-party/pjproject/patches/0000-set_apps_initial_log_level.patch new file mode 100644 index 000000000..fc0f57023 --- /dev/null +++ b/third-party/pjproject/patches/0000-set_apps_initial_log_level.patch @@ -0,0 +1,39 @@ +diff --git a/pjsip-apps/src/pjsua/main.c b/pjsip-apps/src/pjsua/main.c +index 2baaf82..11831f2 100644 +--- a/pjsip-apps/src/pjsua/main.c ++++ b/pjsip-apps/src/pjsua/main.c +@@ -126,5 +126,7 @@ int main_func(int argc, char *argv[]) + + int main(int argc, char *argv[]) + { ++ pj_log_set_level(1); ++ + return pj_run_app(&main_func, argc, argv, 0); + } +diff --git a/pjsip-apps/src/pjsystest/main_console.c b/pjsip-apps/src/pjsystest/main_console.c +index 122cdc7..dc79eab 100644 +--- a/pjsip-apps/src/pjsystest/main_console.c ++++ b/pjsip-apps/src/pjsystest/main_console.c +@@ -133,6 +133,8 @@ void gui_sleep(unsigned sec) + + int main() + { ++ pj_log_set_level(1); ++ + if (systest_init() != PJ_SUCCESS) + return 1; + +diff --git a/pjsip-apps/src/python/_pjsua.c b/pjsip-apps/src/python/_pjsua.c +index fb80e23..c9b21d8 100644 +--- a/pjsip-apps/src/python/_pjsua.c ++++ b/pjsip-apps/src/python/_pjsua.c +@@ -4437,7 +4437,8 @@ init_pjsua(void) + PyObject* m = NULL; + #define ADD_CONSTANT(mod,name) PyModule_AddIntConstant(mod,#name,name) + +- ++ pj_log_set_level(1); ++ + PyEval_InitThreads(); + + if (PyType_Ready(&PyTyp_pjsua_callback) < 0) |