summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorLuigi Rizzo <rizzo@icir.org>2006-12-15 23:10:42 +0000
committerLuigi Rizzo <rizzo@icir.org>2006-12-15 23:10:42 +0000
commit055abfe9d96e884c12dc41884e9472f41c5b8591 (patch)
tree67a2fe73762b64d378d6a34cb489de4ff4492a60 /main
parent961754d4b12da98e84aa43992ebb2c578d94ca30 (diff)
simplify the ast_dynamic_str_*.... routines by
renaming them to ast_str ... and putting the struct ast_threadstorage pointer into the struct ast_str. This makes the code a lot more readable. At this point we can use these routines also to replace ast_build_string(). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48510 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/cli.c6
-rw-r--r--main/logger.c20
-rw-r--r--main/manager.c22
-rw-r--r--main/utils.c20
4 files changed, 34 insertions, 34 deletions
diff --git a/main/cli.c b/main/cli.c
index 895b8b855..acc003e4c 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -59,14 +59,14 @@ AST_THREADSTORAGE(ast_cli_buf);
void ast_cli(int fd, char *fmt, ...)
{
int res;
- struct ast_dynamic_str *buf;
+ struct ast_str *buf;
va_list ap;
- if (!(buf = ast_dynamic_str_thread_get(&ast_cli_buf, AST_CLI_INITLEN)))
+ if (!(buf = ast_str_thread_get(&ast_cli_buf, AST_CLI_INITLEN)))
return;
va_start(ap, fmt);
- res = ast_dynamic_str_thread_set_va(&buf, 0, &ast_cli_buf, fmt, ap);
+ res = ast_str_set_va(&buf, 0, fmt, ap);
va_end(ap);
if (res != AST_DYNSTR_BUILD_FAILED)
diff --git a/main/logger.c b/main/logger.c
index 660fb2f74..440c7dea2 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -695,14 +695,14 @@ static void ast_log_vsyslog(int level, const char *file, int line, const char *f
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
{
struct logchannel *chan;
- struct ast_dynamic_str *buf;
+ struct ast_str *buf;
time_t t;
struct tm tm;
char date[256];
va_list ap;
- if (!(buf = ast_dynamic_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
+ if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
return;
if (AST_LIST_EMPTY(&logchannels))
@@ -714,7 +714,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
if (level != __LOG_VERBOSE) {
int res;
va_start(ap, fmt);
- res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
+ res = ast_str_set_va(&buf, BUFSIZ, fmt, ap); /* XXX BUFSIZ ? */
va_end(ap);
if (res != AST_DYNSTR_BUILD_FAILED) {
term_filter_escapes(buf->str);
@@ -775,7 +775,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
if (level != __LOG_VERBOSE) {
int res;
sprintf(linestr, "%d", line);
- ast_dynamic_str_thread_set(&buf, BUFSIZ, &log_buf,
+ ast_str_set(&buf, BUFSIZ,
"[%s] %s[%ld]: %s:%s %s: ",
date,
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
@@ -788,7 +788,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
ast_console_puts_mutable(buf->str);
va_start(ap, fmt);
- res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
+ res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
va_end(ap);
if (res != AST_DYNSTR_BUILD_FAILED)
ast_console_puts_mutable(buf->str);
@@ -796,7 +796,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
/* File channels */
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
int res;
- ast_dynamic_str_thread_set(&buf, BUFSIZ, &log_buf,
+ ast_str_set(&buf, BUFSIZ,
"[%s] %s[%ld] %s: ",
date, levels[level], (long)GETTID(), file);
res = fprintf(chan->fileptr, "%s", buf->str);
@@ -812,7 +812,7 @@ void ast_log(int level, const char *file, int line, const char *function, const
int res;
/* No error message, continue printing */
va_start(ap, fmt);
- res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
+ res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
va_end(ap);
if (res != AST_DYNSTR_BUILD_FAILED) {
term_strip(buf->str, buf->str, buf->len);
@@ -868,7 +868,7 @@ void ast_backtrace(void)
void ast_verbose(const char *fmt, ...)
{
struct verb *v;
- struct ast_dynamic_str *buf;
+ struct ast_str *buf;
int res;
va_list ap;
@@ -886,11 +886,11 @@ void ast_verbose(const char *fmt, ...)
fmt = datefmt;
}
- if (!(buf = ast_dynamic_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
+ if (!(buf = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
return;
va_start(ap, fmt);
- res = ast_dynamic_str_thread_set_va(&buf, 0, &verbose_buf, fmt, ap);
+ res = ast_str_set_va(&buf, 0, fmt, ap);
va_end(ap);
if (res == AST_DYNSTR_BUILD_FAILED)
diff --git a/main/manager.c b/main/manager.c
index 5ce5fa98a..4247e2241 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -769,13 +769,13 @@ static int send_string(struct mansession *s, char *string)
void astman_append(struct mansession *s, const char *fmt, ...)
{
va_list ap;
- struct ast_dynamic_str *buf;
+ struct ast_str *buf;
- if (!(buf = ast_dynamic_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE)))
+ if (!(buf = ast_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE)))
return;
va_start(ap, fmt);
- ast_dynamic_str_thread_set_va(&buf, 0, &astman_append_buf, fmt, ap);
+ ast_str_set_va(&buf, 0, fmt, ap);
va_end(ap);
if (s->f != NULL)
@@ -2277,39 +2277,39 @@ int __manager_event(int category, const char *event,
char tmp[4096] = "";
va_list ap;
struct timeval now;
- struct ast_dynamic_str *buf;
+ struct ast_str *buf;
/* Abort if there aren't any manager sessions */
if (!num_sessions)
return 0;
- if (!(buf = ast_dynamic_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE)))
+ if (!(buf = ast_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE)))
return -1;
- ast_dynamic_str_thread_set(&buf, 0, &manager_event_buf,
+ ast_str_set(&buf, 0,
"Event: %s\r\nPrivilege: %s\r\n",
event, authority_to_str(category, auth, sizeof(auth)));
if (timestampevents) {
now = ast_tvnow();
- ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
+ ast_str_append(&buf, 0,
"Timestamp: %ld.%06lu\r\n",
now.tv_sec, (unsigned long) now.tv_usec);
}
if (manager_debug) {
static int seq;
- ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
+ ast_str_append(&buf, 0,
"SequenceNumber: %d\r\n",
ast_atomic_fetchadd_int(&seq, 1));
- ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf,
+ ast_str_append(&buf, 0,
"File: %s\r\nLine: %d\r\nFunc: %s\r\n", file, line, func);
}
va_start(ap, fmt);
- ast_dynamic_str_thread_append_va(&buf, 0, &manager_event_buf, fmt, ap);
+ ast_str_append_va(&buf, 0, fmt, ap);
va_end(ap);
- ast_dynamic_str_thread_append(&buf, 0, &manager_event_buf, "\r\n");
+ ast_str_append(&buf, 0, "\r\n");
append_event(buf->str, category);
diff --git a/main/utils.c b/main/utils.c
index 9e51dcde1..65d6d20d6 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -976,13 +976,13 @@ int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
* core handler for dynamic strings.
* This is not meant to be called directly, but rather through the
* various wrapper macros
- * ast_dynamic_str_set(...)
- * ast_dynamic_str_append(...)
- * ast_dynamic_str_thread_set(...)
- * ast_dynamic_str_thread_append(...)
+ * ast_str_set(...)
+ * ast_str_append(...)
+ * ast_str_set_va(...)
+ * ast_str_append_va(...)
*/
-int __ast_dyn_str_helper(struct ast_dynamic_str **buf, size_t max_len,
- struct ast_threadstorage *ts, int append, const char *fmt, va_list ap)
+int __ast_str_helper(struct ast_str **buf, size_t max_len,
+ int append, const char *fmt, va_list ap)
{
int res, need;
int offset = (append && (*buf)->len) ? (*buf)->used : 0;
@@ -1005,17 +1005,17 @@ int __ast_dyn_str_helper(struct ast_dynamic_str **buf, size_t max_len,
need = max_len;
/* We can only realloc malloc'ed space. */
- if ((*buf)->type != DS_MALLOC)
+ if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC)
return AST_DYNSTR_BUILD_FAILED;
- *buf = ast_realloc(*buf, need + sizeof(struct ast_dynamic_str));
+ *buf = ast_realloc(*buf, need + sizeof(struct ast_str));
if (*buf == NULL) /* XXX watch out, we leak memory here */
return AST_DYNSTR_BUILD_FAILED;
(*buf)->len = need;
(*buf)->str[offset] = '\0'; /* Truncate the partial write. */
- if (ts)
- pthread_setspecific(ts->key, *buf);
+ if ((*buf)->ts != DS_ALLOCA)
+ pthread_setspecific((*buf)->ts->key, *buf);
/* va_end() and va_start() must be done before calling
* vsnprintf() again. */