........ r369001 | kpfleming | 2012-06-15 10:56:08 -0500 (Fri, 15 Jun 2012) | 11 lines Add support-level indications to many more source files. Since we now have tools that scan through the source tree looking for files with specific support levels, we need to ensure that every file that is a component of a 'core' or 'extended' module (or the main Asterisk binary) is explicitly marked with its support level. This patch adds support-level indications to many more source files in tree, but avoids adding them to third-party libraries that are included in the tree and to source files that don't end up involved in Asterisk itself. ........ r369002 | kpfleming | 2012-06-15 10:57:14 -0500 (Fri, 15 Jun 2012) | 3 lines Add a script to enable finding source files without support-levels defined. ........ Merged revisions 369001-369002 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 369005 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369013 65c4cc65-6c06-0410-ace0-fbb531ad65f3
163 lines
4.5 KiB
C
163 lines
4.5 KiB
C
/*
|
|
* Asterisk -- An open source telephony toolkit.
|
|
*
|
|
* Copyright (C) 2008, Digium, Inc.
|
|
*
|
|
* Tilghman Lesher <tlesher@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 String manipulation API
|
|
*
|
|
* \author Tilghman Lesher <tilghman@digium.com>
|
|
*/
|
|
|
|
/*** MAKEOPTS
|
|
<category name="MENUSELECT_CFLAGS" displayname="Compiler Flags" positive_output="yes">
|
|
<member name="DEBUG_OPAQUE" displayname="Change ast_str internals to detect improper usage" touch_on_change="include/asterisk/strings.h">
|
|
<defaultenabled>yes</defaultenabled>
|
|
</member>
|
|
</category>
|
|
***/
|
|
|
|
/*** MODULEINFO
|
|
<support_level>core</support_level>
|
|
***/
|
|
|
|
#include "asterisk.h"
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
#include "asterisk/strings.h"
|
|
#include "asterisk/pbx.h"
|
|
|
|
/*!
|
|
* core handler for dynamic strings.
|
|
* This is not meant to be called directly, but rather through the
|
|
* various wrapper macros
|
|
* ast_str_set(...)
|
|
* ast_str_append(...)
|
|
* ast_str_set_va(...)
|
|
* ast_str_append_va(...)
|
|
*/
|
|
|
|
#if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
|
|
int __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,
|
|
int append, const char *fmt, va_list ap, const char *file, int lineno, const char *function)
|
|
#else
|
|
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 offset = (append && (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_USED : 0;
|
|
va_list aq;
|
|
|
|
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);
|
|
|
|
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.
|
|
*/
|
|
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 (0) { /* debugging */
|
|
ast_verbose("extend from %d to %d\n", len, need);
|
|
}
|
|
if (
|
|
#if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
|
|
_ast_str_make_space(buf, need, file, lineno, function)
|
|
#else
|
|
ast_str_make_space(buf, need)
|
|
#endif
|
|
) {
|
|
ast_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. */
|
|
|
|
/* Restart va_copy before calling vsnprintf() again. */
|
|
va_end(aq);
|
|
continue;
|
|
}
|
|
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;
|
|
|
|
return res;
|
|
}
|
|
|
|
char *__ast_str_helper2(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas)
|
|
{
|
|
int dynamic = 0;
|
|
char *ptr = append ? &((*buf)->__AST_STR_STR[(*buf)->__AST_STR_USED]) : (*buf)->__AST_STR_STR;
|
|
|
|
if (maxlen < 1) {
|
|
if (maxlen == 0) {
|
|
dynamic = 1;
|
|
}
|
|
maxlen = (*buf)->__AST_STR_LEN;
|
|
}
|
|
|
|
while (*src && maxsrc && maxlen && (!escapecommas || (maxlen - 1))) {
|
|
if (escapecommas && (*src == '\\' || *src == ',')) {
|
|
*ptr++ = '\\';
|
|
maxlen--;
|
|
(*buf)->__AST_STR_USED++;
|
|
}
|
|
*ptr++ = *src++;
|
|
maxsrc--;
|
|
maxlen--;
|
|
(*buf)->__AST_STR_USED++;
|
|
|
|
if ((ptr >= (*buf)->__AST_STR_STR + (*buf)->__AST_STR_LEN - 3) ||
|
|
(dynamic && (!maxlen || (escapecommas && !(maxlen - 1))))) {
|
|
char *oldbase = (*buf)->__AST_STR_STR;
|
|
size_t old = (*buf)->__AST_STR_LEN;
|
|
if (ast_str_make_space(buf, (*buf)->__AST_STR_LEN * 2)) {
|
|
/* If the buffer can't be extended, end it. */
|
|
break;
|
|
}
|
|
/* What we extended the buffer by */
|
|
maxlen = old;
|
|
|
|
ptr += (*buf)->__AST_STR_STR - oldbase;
|
|
}
|
|
}
|
|
if (__builtin_expect(!maxlen, 0)) {
|
|
ptr--;
|
|
}
|
|
*ptr = '\0';
|
|
return (*buf)->__AST_STR_STR;
|
|
}
|
|
|