[Asterisk-cvs] asterisk manager.c,1.118,1.119 utils.c,1.71,1.72
kpfleming
kpfleming
Sat Oct 1 11:45:18 CDT 2005
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv28615
Modified Files:
manager.c utils.c
Log Message:
add ast_build_string_va(), which accepts a varargs list directly
ensure the _entire_ manager_event() output is either queued or sent via ast_carefulwrite()
Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- manager.c 30 Sep 2005 23:52:04 -0000 1.118
+++ manager.c 1 Oct 2005 15:41:27 -0000 1.119
@@ -1473,13 +1473,16 @@
int manager_event(int category, char *event, char *fmt, ...)
{
struct mansession *s;
+ char auth[80];
char tmp[4096];
- char auth[256];
+ char *tmp_next = tmp;
+ size_t tmp_left = sizeof(tmp) - 2;
va_list ap;
- authority_to_str(category, auth, sizeof(auth));
+ ast_build_string(&tmp_next, &tmp_left, "Event: %s\r\nPrivilege: %s\r\n",
+ event, authority_to_str(category, auth, sizeof(auth)));
va_start(ap, fmt);
- vsnprintf(tmp, sizeof(tmp) - 3, fmt, ap);
+ ast_build_string_va(&tmp_next, &tmp_left, fmt, ap);
va_end(ap);
strcat(tmp, "\r\n");
@@ -1492,11 +1495,9 @@
continue;
ast_mutex_lock(&s->__lock);
- ast_cli(s->fd, "Event: %s\r\n", event);
- ast_cli(s->fd, "Privilege: %s\r\n", auth);
if (s->busy) {
append_event(s, tmp);
- } else if (ast_carefulwrite(s->fd, tmp, strlen(tmp), 100) < 0) {
+ } else if (ast_carefulwrite(s->fd, tmp, sizeof(tmp) - tmp_left + 1, 100) < 0) {
ast_log(LOG_WARNING, "Disconnecting slow (or gone) manager session!\n");
s->dead = 1;
pthread_kill(s->t, SIGURG);
Index: utils.c
===================================================================
RCS file: /usr/cvsroot/asterisk/utils.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- utils.c 29 Sep 2005 04:08:18 -0000 1.71
+++ utils.c 1 Oct 2005 15:41:27 -0000 1.72
@@ -522,17 +522,14 @@
return s;
}
-int ast_build_string(char **buffer, size_t *space, const char *fmt, ...)
+int ast_build_string_va(char **buffer, size_t *space, const char *fmt, va_list ap)
{
- va_list ap;
int result;
if (!buffer || !*buffer || !space || !*space)
return -1;
- va_start(ap, fmt);
result = vsnprintf(*buffer, *space, fmt, ap);
- va_end(ap);
if (result < 0)
return -1;
@@ -544,6 +541,18 @@
return 0;
}
+int ast_build_string(char **buffer, size_t *space, const char *fmt, ...)
+{
+ va_list ap;
+ int result;
+
+ va_start(ap, fmt);
+ result = ast_build_string_va(buffer, space, fmt, ap);
+ va_end(ap);
+
+ return result;
+}
+
int ast_true(const char *s)
{
if (!s || ast_strlen_zero(s))
More information about the svn-commits
mailing list