diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/channel.c | 12 | ||||
-rw-r--r-- | main/cli.c | 2 | ||||
-rw-r--r-- | main/file.c | 2 | ||||
-rw-r--r-- | main/format_cap.c | 5 | ||||
-rw-r--r-- | main/manager.c | 2 | ||||
-rw-r--r-- | main/sorcery.c | 2 | ||||
-rw-r--r-- | main/taskprocessor.c | 11 | ||||
-rw-r--r-- | main/xmldoc.c | 164 |
8 files changed, 58 insertions, 142 deletions
diff --git a/main/channel.c b/main/channel.c index 9aeae5f74..67f0da8ba 100644 --- a/main/channel.c +++ b/main/channel.c @@ -339,7 +339,7 @@ static char *complete_channeltypes(struct ast_cli_args *a) static char *handle_cli_core_show_channeltype(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct chanlist *cl = NULL; - struct ast_str *codec_buf = ast_str_alloca(256); + struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); switch (cmd) { case CLI_INIT: @@ -5094,7 +5094,7 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr) f = fr; } else { if (ast_format_cmp(ast_channel_writeformat(chan), fr->subclass.format) != AST_FORMAT_CMP_EQUAL) { - struct ast_str *codec_buf = ast_str_alloca(256); + struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); /* * We are not setup to write this frame. Things may have changed @@ -5435,8 +5435,8 @@ static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set, res = ast_translator_best_choice(cap_native, cap_set, &best_native_fmt, &best_set_fmt); } if (res < 0) { - struct ast_str *codec_native = ast_str_alloca(256); - struct ast_str *codec_set = ast_str_alloca(256); + struct ast_str *codec_native = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); + struct ast_str *codec_set = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); ast_format_cap_get_names(cap_native, &codec_native); ast_channel_unlock(chan); @@ -5978,8 +5978,8 @@ struct ast_channel *ast_request(const char *type, struct ast_format_cap *request res = ast_translator_best_choice(tmp_cap, chan->tech->capabilities, &tmp_fmt, &best_audio_fmt); ao2_ref(tmp_cap, -1); if (res < 0) { - struct ast_str *tech_codecs = ast_str_alloca(64); - struct ast_str *request_codecs = ast_str_alloca(64); + struct ast_str *tech_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); + struct ast_str *request_codecs = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %s) to %s\n", type, ast_format_cap_get_names(chan->tech->capabilities, &tech_codecs), diff --git a/main/cli.c b/main/cli.c index 47c48d6b1..0d66f3e48 100644 --- a/main/cli.c +++ b/main/cli.c @@ -1528,7 +1528,7 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar struct ast_var_t *var; struct ast_str *write_transpath = ast_str_alloca(256); struct ast_str *read_transpath = ast_str_alloca(256); - struct ast_str *codec_buf = ast_str_alloca(64); + struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); struct ast_bridge *bridge; struct ast_callid *callid; char callid_buf[32]; diff --git a/main/file.c b/main/file.c index 64406bf85..7ce021340 100644 --- a/main/file.c +++ b/main/file.c @@ -1096,7 +1096,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p fs = ast_openstream(chan, filename, preflang); if (!fs) { - struct ast_str *codec_buf = ast_str_alloca(64); + struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); ast_log(LOG_WARNING, "Unable to open %s (format %s): %s\n", filename, ast_format_cap_get_names(ast_channel_nativeformats(chan), &codec_buf), strerror(errno)); return -1; diff --git a/main/format_cap.c b/main/format_cap.c index 1725e3862..4739efa0a 100644 --- a/main/format_cap.c +++ b/main/format_cap.c @@ -264,7 +264,10 @@ int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_typ continue; } - format = ast_format_create(codec); + format = ast_format_cache_get(codec->name); + if (!format || (codec != ast_format_get_codec(format))) { + format = ast_format_create(codec); + } ao2_ref(codec, -1); if (!format) { diff --git a/main/manager.c b/main/manager.c index 8295303c7..99c550275 100644 --- a/main/manager.c +++ b/main/manager.c @@ -4339,7 +4339,7 @@ static int action_status(struct mansession *s, const struct message *m) struct ast_str *write_transpath = ast_str_alloca(256); struct ast_str *read_transpath = ast_str_alloca(256); struct ast_channel *chan; - struct ast_str *codec_buf = ast_str_alloca(64); + struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); int channels = 0; int all = ast_strlen_zero(name); /* set if we want all channels */ char id_text[256]; diff --git a/main/sorcery.c b/main/sorcery.c index 43a395ad0..b75eb8ba7 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -304,7 +304,7 @@ static int chararray_handler_fn(const void *obj, const intptr_t *args, char **bu static int codec_handler_fn(const void *obj, const intptr_t *args, char **buf) { - struct ast_str *codec_buf = ast_str_alloca(64); + struct ast_str *codec_buf = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN); struct ast_format_cap **cap = (struct ast_format_cap **)(obj + args[0]); return !(*buf = ast_strdup(ast_format_cap_get_names(*cap, &codec_buf))); } diff --git a/main/taskprocessor.c b/main/taskprocessor.c index e8dc8f5f2..f382814af 100644 --- a/main/taskprocessor.c +++ b/main/taskprocessor.c @@ -83,6 +83,8 @@ struct ast_taskprocessor { pthread_t thread; /*! Indicates if the taskprocessor is currently executing a task */ unsigned int executing:1; + /*! Indicates that a high water warning has been issued on this task processor */ + unsigned int high_water_warned:1; }; /*! @@ -714,6 +716,8 @@ void *ast_taskprocessor_unreference(struct ast_taskprocessor *tps) return NULL; } +#define HIGH_WATER_LEVEL 100 + /* push the task into the taskprocessor queue */ static int taskprocessor_push(struct ast_taskprocessor *tps, struct tps_task *t) { @@ -733,6 +737,13 @@ static int taskprocessor_push(struct ast_taskprocessor *tps, struct tps_task *t) ao2_lock(tps); AST_LIST_INSERT_TAIL(&tps->tps_queue, t, list); previous_size = tps->tps_queue_size++; + + if (previous_size >= HIGH_WATER_LEVEL && !tps->high_water_warned) { + ast_log(LOG_WARNING, "The '%s' task processor queue reached %d scheduled tasks.\n", + tps->name, previous_size); + tps->high_water_warned = 1; + } + /* The currently executing task counts as still in queue */ was_empty = tps->executing ? 0 : previous_size == 0; ao2_unlock(tps); diff --git a/main/xmldoc.c b/main/xmldoc.c index 1a04e8168..da753cd15 100644 --- a/main/xmldoc.c +++ b/main/xmldoc.c @@ -45,18 +45,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") /*! \brief Default documentation language. */ static const char default_documentation_language[] = "en_US"; -/*! - * \brief Number of columns to print when showing the XML documentation with a - * 'core show application/function *' CLI command. Used in text wrapping. - */ -static const int xmldoc_text_columns = 74; - -/*! - * \brief This is a value that we will use to let the wrapping mechanism move the cursor - * backward and forward xmldoc_max_diff positions before cutting the middle of a - * word, trying to find a space or a \n. - */ -static const int xmldoc_max_diff = 5; +/*! \brief Number of columns to print when showing the XML documentation with a + * 'core show application/function *' CLI command. Used in text wrapping.*/ +static const int xmldoc_text_columns = 79; /*! \brief XML documentation language. */ static char documentation_language[6]; @@ -176,100 +167,22 @@ static void xmldoc_setpostbr(char *postbr, size_t len, const char *text) /*! * \internal - * \brief Try to find a space or a break in text starting at currentpost - * and moving at most maxdiff positions. - * Helper for xmldoc_string_wrap(). - * - * \param text Input string where it will search. - * \param currentpos Current position within text. - * \param maxdiff Not move more than maxdiff inside text. - * - * \retval 1 if a space or break is found inside text while moving. - * \retval 0 if no space or break is found. - */ -static int xmldoc_wait_nextspace(const char *text, int currentpos, int maxdiff) -{ - int i, textlen; - - if (!text) { - return 0; - } - - textlen = strlen(text); - for (i = currentpos; i < textlen; i++) { - if (text[i] == ESC) { - /* Move to the end of the escape sequence */ - while (i < textlen && text[i] != 'm') { - i++; - } - } else if (text[i] == ' ' || text[i] == '\n') { - /* Found the next space or linefeed */ - return 1; - } else if (i - currentpos > maxdiff) { - /* We have looked the max distance and didn't find it */ - return 0; - } - } - - /* Reached the end and did not find it */ - - return 0; -} - -/*! - * \internal - * \brief Helper function for xmldoc_string_wrap(). - * Try to found a space or a break inside text moving backward - * not more than maxdiff positions. - * - * \param text The input string where to search for a space. - * \param currentpos The current cursor position. - * \param maxdiff The max number of positions to move within text. - * - * \retval 0 If no space is found (Notice that text[currentpos] is not a space or a break) - * \retval > 0 If a space or a break is found, and the result is the position relative to - * currentpos. - */ -static int xmldoc_foundspace_backward(const char *text, int currentpos, int maxdiff) -{ - int i; - - for (i = currentpos; i > 0; i--) { - if (text[i] == ' ' || text[i] == '\n') { - return (currentpos - i); - } else if (text[i] == 'm' && (text[i - 1] >= '0' || text[i - 1] <= '9')) { - /* give up, we found the end of a possible ESC sequence. */ - return 0; - } else if (currentpos - i > maxdiff) { - /* give up, we can't move anymore. */ - return 0; - } - } - - /* we found the beginning of the text */ - - return 0; -} - -/*! - * \internal * \brief Justify a text to a number of columns. * * \param text Input text to be justified. * \param columns Number of columns to preserve in the text. - * \param maxdiff Try to not cut a word when goinf down. * * \retval NULL on error. * \retval The wrapped text. */ -static char *xmldoc_string_wrap(const char *text, int columns, int maxdiff) +static char *xmldoc_string_wrap(const char *text, int columns) { struct ast_str *tmp; char *ret, postbr[160]; - int count = 1, i, backspace, needtobreak = 0, colmax, textlen; + int count, i, textlen, postbrlen, lastbreak; /* sanity check */ - if (!text || columns <= 0 || maxdiff < 0) { + if (!text || columns <= 0) { ast_log(LOG_WARNING, "Passing wrong arguments while trying to wrap the text\n"); return NULL; } @@ -282,55 +195,44 @@ static char *xmldoc_string_wrap(const char *text, int columns, int maxdiff) /* Check for blanks and tabs and put them in postbr. */ xmldoc_setpostbr(postbr, sizeof(postbr), text); - colmax = columns - xmldoc_postbrlen(postbr); + postbrlen = xmldoc_postbrlen(postbr); + + count = 0; + lastbreak = 0; textlen = strlen(text); for (i = 0; i < textlen; i++) { - if (needtobreak || !(count % colmax)) { - if (text[i] == ' ') { - ast_str_append(&tmp, 0, "\n%s", postbr); - needtobreak = 0; - count = 1; - } else if (text[i] != '\n') { - needtobreak = 1; - if (xmldoc_wait_nextspace(text, i, maxdiff)) { - /* wait for the next space */ - ast_str_append(&tmp, 0, "%c", text[i]); - continue; - } - /* Try to look backwards */ - backspace = xmldoc_foundspace_backward(text, i, maxdiff); - if (backspace) { - needtobreak = 1; - ast_str_truncate(tmp, -backspace); - i -= backspace + 1; - continue; - } - ast_str_append(&tmp, 0, "\n%s", postbr); - needtobreak = 0; - count = 1; - } - /* skip blanks after a \n */ - while (text[i] == ' ') { - i++; - } - } if (text[i] == '\n') { xmldoc_setpostbr(postbr, sizeof(postbr), &text[i] + 1); - colmax = columns - xmldoc_postbrlen(postbr); - needtobreak = 0; - count = 1; - } - if (text[i] == ESC) { - /* Ignore Escape sequences. */ + postbrlen = xmldoc_postbrlen(postbr); + count = 0; + lastbreak = 0; + } else if (text[i] == ESC) { + /* Walk over escape sequences without counting them. */ do { ast_str_append(&tmp, 0, "%c", text[i]); i++; } while (i < textlen && text[i] != 'm'); } else { + if (text[i] == ' ') { + lastbreak = i; + } count++; } - ast_str_append(&tmp, 0, "%c", text[i]); + + if (count > columns) { + /* Seek backwards if it was at most 30 characters ago. */ + int back = i - lastbreak; + if (lastbreak && back > 0 && back < 30) { + ast_str_truncate(tmp, -back); + i = lastbreak; /* go back a bit */ + } + ast_str_append(&tmp, 0, "\n%s", postbr); + count = postbrlen; + lastbreak = 0; + } else { + ast_str_append(&tmp, 0, "%c", text[i]); + } } ret = ast_strdup(ast_str_buffer(tmp)); @@ -442,7 +344,7 @@ char *ast_xmldoc_printable(const char *bwinput, int withcolors) } /* Wrap the text, notice that string wrap will avoid cutting an ESC sequence. */ - wrapped = xmldoc_string_wrap(ast_str_buffer(colorized), xmldoc_text_columns, xmldoc_max_diff); + wrapped = xmldoc_string_wrap(ast_str_buffer(colorized), xmldoc_text_columns); ast_free(colorized); |