diff options
-rw-r--r-- | CHANGES | 13 | ||||
-rw-r--r-- | channels/chan_sip.c | 11 | ||||
-rw-r--r-- | funcs/func_holdintercept.c | 236 | ||||
-rw-r--r-- | include/asterisk/cdr.h | 30 | ||||
-rw-r--r-- | include/asterisk/res_pjsip.h | 5 | ||||
-rw-r--r-- | main/cdr.c | 56 | ||||
-rw-r--r-- | main/format_cap.c | 24 | ||||
-rw-r--r-- | main/manager.c | 12 | ||||
-rw-r--r-- | main/strings.c | 91 | ||||
-rw-r--r-- | main/xmldoc.c | 6 | ||||
-rw-r--r-- | res/res_pjsip.c | 18 | ||||
-rw-r--r-- | res/res_pjsip/location.c | 32 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_configuration.c | 30 | ||||
-rw-r--r-- | rest-api-templates/api.wiki.mustache | 2 | ||||
-rw-r--r-- | rest-api-templates/asterisk_processor.py | 2 |
15 files changed, 445 insertions, 123 deletions
@@ -193,6 +193,19 @@ cdr_adaptive_odbc ------------------------------------------------------------------------------ +--- Functionality changes from Asterisk 13.6.0 to Asterisk 13.7.0 ------------ +------------------------------------------------------------------------------ + +Dialplan Functions +------------------ + * The HOLD_INTERCEPT dialplan function now actually exists in the source tree. + While support for the events was added in Asterisk 13.4.0, the function + accidentally never made it in. That function is now present, and will cause + the 'hold' raised by a channel to be intercepted and converted into an + event instead. + + +------------------------------------------------------------------------------ --- Functionality changes from Asterisk 13.5.0 to Asterisk 13.6.0 ------------ ------------------------------------------------------------------------------ diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 3fdc3caae..8f76e9cc3 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -11095,7 +11095,7 @@ static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_ if (framing && p->autoframing) { ast_debug(1, "Setting framing to %ld\n", framing); - ast_rtp_codecs_set_framing(ast_rtp_instance_get_codecs(p->rtp), framing); + ast_format_cap_set_framing(p->caps, framing); } found = TRUE; } else if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) { @@ -13384,6 +13384,11 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int ast_str_append(&a_audio, 0, "a=maxptime:%d\r\n", max_audio_packet_size); } + if (!ast_test_flag(&p->flags[0], SIP_OUTGOING)) { + ast_debug(1, "Setting framing on incoming call: %u\n", min_audio_packet_size); + ast_rtp_codecs_set_framing(ast_rtp_instance_get_codecs(p->rtp), min_audio_packet_size); + } + if (!doing_directmedia) { if (ast_test_flag(&p->flags[2], SIP_PAGE3_ICE_SUPPORT)) { add_ice_to_sdp(p->rtp, &a_audio); @@ -13676,10 +13681,6 @@ static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const add_cc_call_info_to_response(p, &resp); } if (p->rtp) { - if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { - ast_debug(1, "Setting framing from config on incoming call\n"); - ast_rtp_codecs_set_framing(ast_rtp_instance_get_codecs(p->rtp), ast_format_cap_get_framing(p->caps)); - } ast_rtp_instance_activate(p->rtp); try_suggested_sip_codec(p); if (p->t38.state == T38_ENABLED) { diff --git a/funcs/func_holdintercept.c b/funcs/func_holdintercept.c new file mode 100644 index 000000000..3e348c1cf --- /dev/null +++ b/funcs/func_holdintercept.c @@ -0,0 +1,236 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2015, 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 Function that intercepts HOLD frames from channels and raises events + * + * \author Matt Jordan <mjordan@digium.com> + * + * \ingroup functions + */ + +/*** MODULEINFO + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_REGISTER_FILE() + +#include "asterisk/module.h" +#include "asterisk/channel.h" +#include "asterisk/pbx.h" +#include "asterisk/app.h" +#include "asterisk/frame.h" +#include "asterisk/stasis.h" +#include "asterisk/stasis_channels.h" + +/*** DOCUMENTATION + <function name="HOLD_INTERCEPT" language="en_US"> + <synopsis> + Intercepts hold frames on a channel and raises an event instead of passing the frame on + </synopsis> + <syntax> + <parameter name="action" required="true"> + <optionlist> + <option name="remove"> + <para>W/O. Removes the hold interception function.</para> + </option> + <option name="set"> + <para>W/O. Enable hold interception on the channel. When + enabled, the channel will intercept any hold action that + is signalled from the device, and instead simply raise an + event (AMI/ARI) indicating that the channel wanted to put other + parties on hold.</para> + </option> + </optionlist> + </parameter> + </syntax> + </function> +***/ + +/*! \brief Private data structure used with the function's datastore */ +struct hold_intercept_data { + int framehook_id; +}; + +/*! \brief The channel datastore the function uses to store state */ +static const struct ast_datastore_info hold_intercept_datastore = { + .type = "hold_intercept", +}; + +/*! \internal \brief Disable hold interception on the channel */ +static int remove_hold_intercept(struct ast_channel *chan) +{ + struct ast_datastore *datastore = NULL; + struct hold_intercept_data *data; + SCOPED_CHANNELLOCK(chan_lock, chan); + + datastore = ast_channel_datastore_find(chan, &hold_intercept_datastore, NULL); + if (!datastore) { + ast_log(AST_LOG_WARNING, "Cannot remove HOLD_INTERCEPT from %s: HOLD_INTERCEPT not currently enabled\n", + ast_channel_name(chan)); + return -1; + } + data = datastore->data; + + if (ast_framehook_detach(chan, data->framehook_id)) { + ast_log(AST_LOG_WARNING, "Failed to remove HOLD_INTERCEPT framehook from channel %s\n", + ast_channel_name(chan)); + return -1; + } + + if (ast_channel_datastore_remove(chan, datastore)) { + ast_log(AST_LOG_WARNING, "Failed to remove HOLD_INTERCEPT datastore from channel %s\n", + ast_channel_name(chan)); + return -1; + } + ast_datastore_free(datastore); + + return 0; +} + +/*! \brief Frame hook that is called to intercept hold/unhold */ +static struct ast_frame *hold_intercept_framehook(struct ast_channel *chan, + struct ast_frame *f, enum ast_framehook_event event, void *data) +{ + int frame_type; + + if (!f || (event != AST_FRAMEHOOK_EVENT_WRITE)) { + return f; + } + + if (f->frametype != AST_FRAME_CONTROL) { + return f; + } + + frame_type = f->subclass.integer; + if (frame_type != AST_CONTROL_HOLD && frame_type != AST_CONTROL_UNHOLD) { + return f; + } + + /* Munch munch */ + ast_frfree(f); + f = &ast_null_frame; + + ast_channel_publish_cached_blob(chan, + frame_type == AST_CONTROL_HOLD ? ast_channel_hold_type() : ast_channel_unhold_type(), + NULL); + + return f; +} + +/*! \brief Callback function which informs upstream if we are consuming a frame of a specific type */ +static int hold_intercept_framehook_consume(void *data, enum ast_frame_type type) +{ + return (type == AST_FRAME_CONTROL ? 1 : 0); +} + +/*! \internal \brief Enable hold interception on the channel */ +static int set_hold_intercept(struct ast_channel *chan) +{ + struct ast_datastore *datastore; + struct hold_intercept_data *data; + static struct ast_framehook_interface hold_framehook_interface = { + .version = AST_FRAMEHOOK_INTERFACE_VERSION, + .event_cb = hold_intercept_framehook, + .consume_cb = hold_intercept_framehook_consume, + .disable_inheritance = 1, + }; + SCOPED_CHANNELLOCK(chan_lock, chan); + + datastore = ast_channel_datastore_find(chan, &hold_intercept_datastore, NULL); + if (datastore) { + ast_log(AST_LOG_WARNING, "HOLD_INTERCEPT already set on '%s'\n", + ast_channel_name(chan)); + return 0; + } + + datastore = ast_datastore_alloc(&hold_intercept_datastore, NULL); + if (!datastore) { + return -1; + } + + data = ast_calloc(1, sizeof(*data)); + if (!data) { + ast_datastore_free(datastore); + return -1; + } + + data->framehook_id = ast_framehook_attach(chan, &hold_framehook_interface); + if (data->framehook_id < 0) { + ast_log(AST_LOG_WARNING, "Failed to attach HOLD_INTERCEPT framehook to '%s'\n", + ast_channel_name(chan)); + ast_datastore_free(datastore); + ast_free(data); + return -1; + } + datastore->data = data; + + ast_channel_datastore_add(chan, datastore); + + return 0; +} + +/*! \internal \brief HOLD_INTERCEPT write function callback */ +static int hold_intercept_fn_write(struct ast_channel *chan, const char *function, + char *data, const char *value) +{ + int res; + + if (!chan) { + return -1; + } + + if (ast_strlen_zero(data)) { + ast_log(AST_LOG_WARNING, "HOLD_INTERCEPT requires an argument\n"); + return -1; + } + + if (!strcasecmp(data, "set")) { + res = set_hold_intercept(chan); + } else if (!strcasecmp(data, "remove")) { + res = remove_hold_intercept(chan); + } else { + ast_log(AST_LOG_WARNING, "HOLD_INTERCEPT: unknown option %s\n", data); + res = -1; + } + + return res; +} + +/*! \brief Definition of the HOLD_INTERCEPT function */ +static struct ast_custom_function hold_intercept_function = { + .name = "HOLD_INTERCEPT", + .write = hold_intercept_fn_write, +}; + +/*! \internal \brief Unload the module */ +static int unload_module(void) +{ + return ast_custom_function_unregister(&hold_intercept_function); +} + +/*! \internal \brief Load the module */ +static int load_module(void) +{ + return ast_custom_function_register(&hold_intercept_function) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS; +} + +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hold interception dialplan function"); diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h index 5654c3847..f752f7f9f 100644 --- a/include/asterisk/cdr.h +++ b/include/asterisk/cdr.h @@ -536,6 +536,36 @@ int ast_cdr_backend_suspend(const char *name); int ast_cdr_backend_unsuspend(const char *name); /*! + * \brief Register a CDR modifier + * \param name name associated with the particular CDR modifier + * \param desc description of the CDR modifier + * \param be function pointer to a CDR modifier + * + * Used to register a Call Detail Record modifier. + * + * This gives modules a chance to modify CDR fields before they are dispatched + * to registered backends (odbc, syslog, etc). + * + * \note The *modified* CDR will be passed to **all** registered backends for + * logging. For instance, if cdr_manager changes the CDR data, cdr_adaptive_odbc + * will also get the modified CDR. + * + * \retval 0 on success. + * \retval -1 on error + */ +int ast_cdr_modifier_register(const char *name, const char *desc, ast_cdrbe be); + +/*! + * \brief Unregister a CDR modifier + * \param name name of CDR modifier to unregister + * Unregisters a CDR modifier by its name + * + * \retval 0 The modifier unregistered successfully + * \retval -1 The modifier could not be unregistered at this time + */ +int ast_cdr_modifier_unregister(const char *name); + +/*! * \brief Disposition to a string * \param disposition input binary form * Converts the binary form of a disposition to string form. diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index 29edbd230..f159a572e 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -1180,6 +1180,11 @@ int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void * cause a deadlock. If you are in a SIP servant thread, just call your function * in-line. * + * \warning \b Never hold locks that may be acquired by a SIP servant thread when + * calling this function. Doing so may cause a deadlock if all SIP servant threads + * are blocked waiting to acquire the lock while the thread holding the lock is + * waiting for a free SIP servant thread. + * * \param serializer The SIP serializer to which the task belongs. May be NULL. * \param sip_task The task to execute * \param task_data The parameter to pass to the task when it executes diff --git a/main/cdr.c b/main/cdr.c index 8d7f53f17..5e2407502 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -297,6 +297,9 @@ struct cdr_beitem { /*! \brief List of registered backends */ static AST_RWLIST_HEAD_STATIC(be_list, cdr_beitem); +/*! \brief List of registered modifiers */ +static AST_RWLIST_HEAD_STATIC(mo_list, cdr_beitem); + /*! \brief Queued CDR waiting to be batched */ struct cdr_batch_item { struct ast_cdr *cdr; @@ -2678,7 +2681,7 @@ int ast_cdr_backend_unsuspend(const char *name) return success; } -int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be) +static int cdr_generic_register(struct be_list *generic_list, const char *name, const char *desc, ast_cdrbe be) { struct cdr_beitem *i = NULL; @@ -2690,11 +2693,11 @@ int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be) return -1; } - AST_RWLIST_WRLOCK(&be_list); - AST_RWLIST_TRAVERSE(&be_list, i, list) { + AST_RWLIST_WRLOCK(generic_list); + AST_RWLIST_TRAVERSE(generic_list, i, list) { if (!strcasecmp(name, i->name)) { ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name); - AST_RWLIST_UNLOCK(&be_list); + AST_RWLIST_UNLOCK(generic_list); return -1; } } @@ -2706,40 +2709,50 @@ int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be) ast_copy_string(i->name, name, sizeof(i->name)); ast_copy_string(i->desc, desc, sizeof(i->desc)); - AST_RWLIST_INSERT_HEAD(&be_list, i, list); - AST_RWLIST_UNLOCK(&be_list); + AST_RWLIST_INSERT_HEAD(generic_list, i, list); + AST_RWLIST_UNLOCK(generic_list); return 0; } -int ast_cdr_unregister(const char *name) +int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be) +{ + return cdr_generic_register(&be_list, name, desc, be); +} + +int ast_cdr_modifier_register(const char *name, const char *desc, ast_cdrbe be) +{ + return cdr_generic_register((struct be_list *)&mo_list, name, desc, be); +} + +static int ast_cdr_generic_unregister(struct be_list *generic_list, const char *name) { struct cdr_beitem *match = NULL; int active_count; - AST_RWLIST_WRLOCK(&be_list); - AST_RWLIST_TRAVERSE(&be_list, match, list) { + AST_RWLIST_WRLOCK(generic_list); + AST_RWLIST_TRAVERSE(generic_list, match, list) { if (!strcasecmp(name, match->name)) { break; } } if (!match) { - AST_RWLIST_UNLOCK(&be_list); + AST_RWLIST_UNLOCK(generic_list); return 0; } active_count = ao2_container_count(active_cdrs_by_channel); if (!match->suspended && active_count != 0) { - AST_RWLIST_UNLOCK(&be_list); + AST_RWLIST_UNLOCK(generic_list); ast_log(AST_LOG_WARNING, "Unable to unregister CDR backend %s; %d CDRs are still active\n", name, active_count); return -1; } - AST_RWLIST_REMOVE(&be_list, match, list); - AST_RWLIST_UNLOCK(&be_list); + AST_RWLIST_REMOVE(generic_list, match, list); + AST_RWLIST_UNLOCK(generic_list); ast_verb(2, "Unregistered '%s' CDR backend\n", name); ast_free(match); @@ -2747,6 +2760,16 @@ int ast_cdr_unregister(const char *name) return 0; } +int ast_cdr_unregister(const char *name) +{ + return ast_cdr_generic_unregister(&be_list, name); +} + +int ast_cdr_modifier_unregister(const char *name) +{ + return ast_cdr_generic_unregister((struct be_list *)&mo_list, name); +} + struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr) { struct ast_cdr *newcdr; @@ -3262,6 +3285,13 @@ static void post_cdr(struct ast_cdr *cdr) continue; } + /* Modify CDR's */ + AST_RWLIST_RDLOCK(&mo_list); + AST_RWLIST_TRAVERSE(&mo_list, i, list) { + i->be(cdr); + } + AST_RWLIST_UNLOCK(&mo_list); + if (ast_test_flag(cdr, AST_CDR_FLAG_DISABLE)) { continue; } diff --git a/main/format_cap.c b/main/format_cap.c index 224fe331f..d486d5d8c 100644 --- a/main/format_cap.c +++ b/main/format_cap.c @@ -93,14 +93,27 @@ static void format_cap_destroy(void *obj) AST_VECTOR_FREE(&cap->preference_order); } -static inline void format_cap_init(struct ast_format_cap *cap, enum ast_format_cap_flags flags) +/* + * \brief Initialize values on an ast_format_cap + * + * \param cap ast_format_cap to initialize + * \param flags Unused. + * \retval 0 Success + * \retval -1 Failure + */ +static inline int format_cap_init(struct ast_format_cap *cap, enum ast_format_cap_flags flags) { - AST_VECTOR_INIT(&cap->formats, 0); + if (AST_VECTOR_INIT(&cap->formats, 0)) { + return -1; + } /* TODO: Look at common usage of this and determine a good starting point */ - AST_VECTOR_INIT(&cap->preference_order, 5); + if (AST_VECTOR_INIT(&cap->preference_order, 5)) { + return -1; + } cap->framing = UINT_MAX; + return 0; } struct ast_format_cap *__ast_format_cap_alloc(enum ast_format_cap_flags flags, @@ -114,7 +127,10 @@ struct ast_format_cap *__ast_format_cap_alloc(enum ast_format_cap_flags flags, return NULL; } - format_cap_init(cap, flags); + if (format_cap_init(cap, flags)) { + ao2_ref(cap, -1); + return NULL; + } return cap; } diff --git a/main/manager.c b/main/manager.c index 2ea6fae4c..6e9ae0010 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2819,6 +2819,7 @@ AST_THREADSTORAGE(userevent_buf); */ void astman_append(struct mansession *s, const char *fmt, ...) { + int res; va_list ap; struct ast_str *buf; @@ -2827,8 +2828,11 @@ void astman_append(struct mansession *s, const char *fmt, ...) } va_start(ap, fmt); - ast_str_set_va(&buf, 0, fmt, ap); + res = ast_str_set_va(&buf, 0, fmt, ap); va_end(ap); + if (res == AST_DYNSTR_BUILD_FAILED) { + return; + } if (s->f != NULL || s->session->f != NULL) { send_string(s, ast_str_buffer(buf)); @@ -2888,6 +2892,7 @@ void astman_send_error(struct mansession *s, const struct message *m, char *erro void astman_send_error_va(struct mansession *s, const struct message *m, const char *fmt, ...) { + int res; va_list ap; struct ast_str *buf; char *msg; @@ -2897,8 +2902,11 @@ void astman_send_error_va(struct mansession *s, const struct message *m, const c } va_start(ap, fmt); - ast_str_set_va(&buf, 0, fmt, ap); + res = ast_str_set_va(&buf, 0, fmt, ap); va_end(ap); + if (res == AST_DYNSTR_BUILD_FAILED) { + return; + } /* astman_append will use the same underlying buffer, so copy the message out * before sending the response */ diff --git a/main/strings.c b/main/strings.c index 7aaff7992..495011ec5 100644 --- a/main/strings.c +++ b/main/strings.c @@ -60,55 +60,78 @@ int __ast_str_helper(struct ast_str **buf, ssize_t max_len, int append, const char *fmt, va_list ap) #endif { - int res, need; + int res; + int added; + int need; int offset = (append && (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_USED : 0; va_list aq; + if (max_len < 0) { + max_len = (*buf)->__AST_STR_LEN; /* don't exceed the allocated space */ + } + do { - if (max_len < 0) { - max_len = (*buf)->__AST_STR_LEN; /* don't exceed the allocated space */ - } - /* - * Ask vsnprintf how much space we need. Remember that vsnprintf - * does not count the final <code>'\\0'</code> so we must add 1. - */ va_copy(aq, ap); res = vsnprintf((*buf)->__AST_STR_STR + offset, (*buf)->__AST_STR_LEN - offset, fmt, aq); + va_end(aq); + + if (res < 0) { + /* + * vsnprintf write to string failed. + * I don't think this is possible with a memory buffer. + */ + res = AST_DYNSTR_BUILD_FAILED; + added = 0; + break; + } - need = res + offset + 1; /* - * If there is not enough space and we are below the max length, - * reallocate the buffer and return a message telling to retry. + * vsnprintf returns how much space we used or would need. + * Remember that vsnprintf does not count the nil terminator + * so we must add 1. */ - if (need > (*buf)->__AST_STR_LEN && (max_len == 0 || (*buf)->__AST_STR_LEN < max_len) ) { - int len = (int)(*buf)->__AST_STR_LEN; - if (max_len && max_len < need) { /* truncate as needed */ - need = max_len; - } else if (max_len == 0) { /* if unbounded, give more room for next time */ - need += 16 + need / 4; - } - if ( + added = res; + need = offset + added + 1; + if (need <= (*buf)->__AST_STR_LEN + || (max_len && max_len <= (*buf)->__AST_STR_LEN)) { + /* + * There was enough room for the string or we are not + * allowed to try growing the string buffer. + */ + break; + } + + /* Reallocate the buffer and try again. */ + if (max_len == 0) { + /* unbounded, give more room for next time */ + need += 16 + need / 4; + } else if (max_len < need) { + /* truncate as needed */ + need = max_len; + } + + if ( #if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) - _ast_str_make_space(buf, need, file, lineno, function) + _ast_str_make_space(buf, need, file, lineno, function) #else - ast_str_make_space(buf, need) + ast_str_make_space(buf, need) #endif - ) { - ast_log_safe(LOG_VERBOSE, "failed to extend from %d to %d\n", len, need); - va_end(aq); - return AST_DYNSTR_BUILD_FAILED; - } - (*buf)->__AST_STR_STR[offset] = '\0'; /* Truncate the partial write. */ + ) { + ast_log_safe(LOG_VERBOSE, "failed to extend from %d to %d\n", + (int) (*buf)->__AST_STR_LEN, need); - /* Restart va_copy before calling vsnprintf() again. */ - va_end(aq); - continue; + res = AST_DYNSTR_BUILD_FAILED; + break; } - va_end(aq); - break; } while (1); - /* update space used, keep in mind the truncation */ - (*buf)->__AST_STR_USED = (res + offset > (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_LEN - 1: res + offset; + + /* Update space used, keep in mind truncation may be necessary. */ + (*buf)->__AST_STR_USED = ((*buf)->__AST_STR_LEN <= offset + added) + ? (*buf)->__AST_STR_LEN - 1 + : offset + added; + + /* Ensure that the string is terminated. */ + (*buf)->__AST_STR_STR[(*buf)->__AST_STR_USED] = '\0'; return res; } diff --git a/main/xmldoc.c b/main/xmldoc.c index 399a7be97..86c3f6512 100644 --- a/main/xmldoc.c +++ b/main/xmldoc.c @@ -2646,14 +2646,18 @@ struct ast_xml_xpath_results *__attribute__((format(printf, 1, 2))) ast_xmldoc_q struct documentation_tree *doctree; RAII_VAR(struct ast_str *, xpath_str, ast_str_create(128), ast_free); va_list ap; + int res; if (!xpath_str) { return NULL; } va_start(ap, fmt); - ast_str_set_va(&xpath_str, 0, fmt, ap); + res = ast_str_set_va(&xpath_str, 0, fmt, ap); va_end(ap); + if (res == AST_DYNSTR_BUILD_FAILED) { + return NULL; + } AST_RWLIST_RDLOCK(&xmldoc_tree); AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) { diff --git a/res/res_pjsip.c b/res/res_pjsip.c index 5fc59909f..cdaed4ee7 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -2559,6 +2559,8 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, pj_strdup2_with_null(dlg->pool, &tmp, outbound_proxy); if (!(route = pjsip_parse_hdr(dlg->pool, &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL))) { + ast_log(LOG_ERROR, "Could not create dialog to endpoint '%s' as outbound proxy URI '%s' is not valid\n", + ast_sorcery_object_get_id(endpoint), outbound_proxy); dlg->sess_count--; pjsip_dlg_terminate(dlg); return NULL; @@ -2752,6 +2754,7 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s pj_str_t from; pj_pool_t *pool; pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, }; + pjsip_uri *sip_uri; if (ast_strlen_zero(uri)) { if (!endpoint && (!contact || ast_strlen_zero(contact->uri))) { @@ -2788,6 +2791,16 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s return -1; } + sip_uri = pjsip_parse_uri(pool, remote_uri.ptr, remote_uri.slen, 0); + if (!sip_uri || (!PJSIP_URI_SCHEME_IS_SIP(sip_uri) && !PJSIP_URI_SCHEME_IS_SIPS(sip_uri))) { + ast_log(LOG_ERROR, "Unable to create outbound %.*s request to endpoint %s as URI '%s' is not valid\n", + (int) pj_strlen(&method->name), pj_strbuf(&method->name), + endpoint ? ast_sorcery_object_get_id(endpoint) : "<none>", + pj_strbuf(&remote_uri)); + pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); + return -1; + } + if (sip_dialog_create_from(pool, &from, endpoint ? endpoint->fromuser : NULL, endpoint ? endpoint->fromdomain : NULL, &remote_uri, &selector)) { ast_log(LOG_ERROR, "Unable to create From header for %.*s request to endpoint %s\n", @@ -2812,8 +2825,9 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s /* If an outbound proxy is specified on the endpoint apply it to this request */ if (endpoint && !ast_strlen_zero(endpoint->outbound_proxy) && ast_sip_set_outbound_proxy((*tdata), endpoint->outbound_proxy)) { - ast_log(LOG_ERROR, "Unable to apply outbound proxy on request %.*s to endpoint %s\n", - (int) pj_strlen(&method->name), pj_strbuf(&method->name), ast_sorcery_object_get_id(endpoint)); + ast_log(LOG_ERROR, "Unable to apply outbound proxy on request %.*s to endpoint %s as outbound proxy URI '%s' is not valid\n", + (int) pj_strlen(&method->name), pj_strbuf(&method->name), ast_sorcery_object_get_id(endpoint), + endpoint->outbound_proxy); pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); return -1; } diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c index 9625f04ef..331d839a1 100644 --- a/res/res_pjsip/location.c +++ b/res/res_pjsip/location.c @@ -319,32 +319,6 @@ static int expiration_struct2str(const void *obj, const intptr_t *args, char **b return (ast_asprintf(buf, "%ld", contact->expiration_time.tv_sec) < 0) ? -1 : 0; } -/*! \brief Helper function which validates a permanent contact */ -static int permanent_contact_validate(void *data) -{ - const char *value = data; - pj_pool_t *pool; - pj_str_t contact_uri; - static const pj_str_t HCONTACT = { "Contact", 7 }; - pjsip_contact_hdr *contact_hdr; - int rc = 0; - - pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Permanent Contact Validation", 256, 256); - if (!pool) { - return -1; - } - - pj_strdup2_with_null(pool, &contact_uri, value); - if (!(contact_hdr = pjsip_parse_hdr(pool, &HCONTACT, contact_uri.ptr, contact_uri.slen, NULL)) - || !(PJSIP_URI_SCHEME_IS_SIP(contact_hdr->uri) - || PJSIP_URI_SCHEME_IS_SIPS(contact_hdr->uri))) { - rc = -1; - } - - pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); - return rc; -} - static int permanent_uri_sort_fn(const void *obj_left, const void *obj_right, int flags) { const struct ast_sip_contact *object_left = obj_left; @@ -393,12 +367,6 @@ static int permanent_uri_handler(const struct aco_option *opt, struct ast_variab struct ast_sip_contact_status *status; char contact_id[strlen(aor_id) + strlen(contact_uri) + 2 + 1]; - if (ast_sip_push_task_synchronous(NULL, permanent_contact_validate, contact_uri)) { - ast_log(LOG_ERROR, "Permanent URI on aor '%s' with contact '%s' failed to parse\n", - ast_sorcery_object_get_id(aor), contact_uri); - return -1; - } - if (!aor->permanent_contacts) { aor->permanent_contacts = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, permanent_uri_sort_fn, NULL); diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index cfb17cd8d..57793c903 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -1084,29 +1084,6 @@ static struct ast_endpoint *persistent_endpoint_find_or_create(const struct ast_ return persistent->endpoint; } -/*! \brief Helper function which validates an outbound proxy */ -static int outbound_proxy_validate(void *data) -{ - const char *proxy = data; - pj_pool_t *pool; - pj_str_t tmp; - static const pj_str_t ROUTE_HNAME = { "Route", 5 }; - - pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound Proxy Validation", 256, 256); - if (!pool) { - return -1; - } - - pj_strdup2_with_null(pool, &tmp, proxy); - if (!pjsip_parse_hdr(pool, &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL)) { - pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); - return -1; - } - - pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); - return 0; -} - /*! \brief Callback function for when an object is finalized */ static int sip_endpoint_apply_handler(const struct ast_sorcery *sorcery, void *obj) { @@ -1116,12 +1093,7 @@ static int sip_endpoint_apply_handler(const struct ast_sorcery *sorcery, void *o return -1; } - if (!ast_strlen_zero(endpoint->outbound_proxy) && - ast_sip_push_task_synchronous(NULL, outbound_proxy_validate, (char*)endpoint->outbound_proxy)) { - ast_log(LOG_ERROR, "Invalid outbound proxy '%s' specified on endpoint '%s'\n", - endpoint->outbound_proxy, ast_sorcery_object_get_id(endpoint)); - return -1; - } else if (endpoint->extensions.timer.min_se < 90) { + if (endpoint->extensions.timer.min_se < 90) { ast_log(LOG_ERROR, "Session timer minimum expires time must be 90 or greater on endpoint '%s'\n", ast_sorcery_object_get_id(endpoint)); return -1; diff --git a/rest-api-templates/api.wiki.mustache b/rest-api-templates/api.wiki.mustache index 73aa2448a..0a54a64a7 100644 --- a/rest-api-templates/api.wiki.mustache +++ b/rest-api-templates/api.wiki.mustache @@ -67,7 +67,7 @@ h3. Header parameters h3. Error Responses {{#error_responses}} -* {{code}} - {{{reason}}} +* {{code}} - {{{wiki_reason}}} {{/error_responses}} {{/has_error_responses}} {{/operations}} diff --git a/rest-api-templates/asterisk_processor.py b/rest-api-templates/asterisk_processor.py index ab8a8afd2..68a679994 100644 --- a/rest-api-templates/asterisk_processor.py +++ b/rest-api-templates/asterisk_processor.py @@ -199,6 +199,8 @@ class AsteriskProcessor(SwaggerPostProcessor): raise SwaggerError("Summary should end with .", context) operation.wiki_summary = wikify(operation.summary or "") operation.wiki_notes = wikify(operation.notes or "") + for error_response in operation.error_responses: + error_response.wiki_reason = wikify(error_response.reason or "") operation.parse_body = (operation.body_parameter or operation.has_query_parameters) and True def process_parameter(self, parameter, context): |