From 19384d35b64e626c5dbd54a066b04a9bf1b3a0d3 Mon Sep 17 00:00:00 2001 From: David Troy Date: Sun, 18 Jun 2006 06:44:59 +0000 Subject: git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.21pre@122 f02b47b9-160a-0410-81a6-dc3441afb0ec --- src/astmanproxy.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') 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 + Copyright (c) 2005-2006 David C. Troy 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; isin.sin_addr), m.headers[i]); + for(i=0; ihdrcount; 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) -- cgit