diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/astmanproxy.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/astmanproxy.c b/src/astmanproxy.c index 5a865ff..bb17935 100644 --- a/src/astmanproxy.c +++ b/src/astmanproxy.c @@ -1,5 +1,5 @@ /* Asterisk Manager Proxy - Copyright (c) 2005 David C. Troy <dave@popvox.com> + Copyright (c) 2005-2006 David C. Troy <dave@popvox.com> This program is free software, distributed under the terms of the GNU General Public License. @@ -311,41 +311,44 @@ void *session_do(struct mansession *s) void *HandleAsterisk(struct mansession *s) { - struct message m; + struct message *m; int res,i; char iabuf[INET_ADDRSTRLEN]; if (ConnectAsterisk(s)) goto leave; + if (! (m = malloc(sizeof(struct message))) ) + goto leave; + for (;;) { debugmsg("asterisk@%s: attempting read...", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr)); memset(&m, 0, sizeof(struct message) ); - res = s->input->read(s, &m); - m.session = s; + res = s->input->read(s, m); + m->session = s; if (res > 0) { if (debug) { - for(i=0; i<m.hdrcount; i++) { - debugmsg("asterisk@%s got: %s", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), m.headers[i]); + for(i=0; i<m->hdrcount; i++) { + debugmsg("asterisk@%s got: %s", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), m->headers[i]); } } if (!s->connected) { - if ( !strcmp("Authentication accepted", astman_get_header(&m, "Message")) ) { + if ( !strcmp("Authentication accepted", astman_get_header(m, "Message")) ) { s->connected = 1; if (debug) debugmsg("asterisk@%s: connected successfully!", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr) ); } - if ( !strcmp("Authentication failed", astman_get_header(&m, "Message")) ) { + if ( !strcmp("Authentication failed", astman_get_header(m, "Message")) ) { s->connected = -1; } } - m.session = s; - AddHeader(&m, "Server: %s", m.session->server->ast_host); + m->session = s; + AddHeader(m, "Server: %s", m->session->server->ast_host); - if (!WriteClients(&m)) + if (!WriteClients(m)) break; } else if (res < 0) { /* TODO: do we need to do more than this here? or something different? */ @@ -355,6 +358,7 @@ void *HandleAsterisk(struct mansession *s) break; } } + free(m); leave: if (debug) |