From f722ade2a59872cb8c62e81809ef4d83d11434e5 Mon Sep 17 00:00:00 2001 From: David Troy Date: Mon, 23 Jun 2008 11:37:23 -0400 Subject: added files to project --- src/standard.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/standard.c (limited to 'src/standard.c') diff --git a/src/standard.c b/src/standard.c new file mode 100644 index 0000000..f377bec --- /dev/null +++ b/src/standard.c @@ -0,0 +1,70 @@ +/* Asterisk Manager Proxy + Copyright (c) 2005-2006 David C. Troy + + This program is free software, distributed under the terms of + the GNU General Public License. + + standard.c + Standard I/O Handler +*/ + +#include "astmanproxy.h" + +extern struct mansession *sessions; + +/* Return a fully formed message block to session_do for processing */ +int _read(struct mansession *s, struct message *m) { + int res; + + for (;;) { + res = get_input(s, m->headers[m->hdrcount]); + + if (strstr(m->headers[m->hdrcount], "--END COMMAND--")) { + if (debug) debugmsg("Found END COMMAND"); + m->in_command = 0; + } + if (strstr(m->headers[m->hdrcount], "Response: Follows")) { + if (debug) debugmsg("Found Response Follows"); + m->in_command = 1; + } + if (res > 0) { + if (!m->in_command && *(m->headers[m->hdrcount]) == '\0' ) { + break; + } else if (m->hdrcount < MAX_HEADERS - 1) { + m->hdrcount++; + } else { + m->in_command = 0; // reset when block full + } + } else if (res < 0) + break; + } + + return res; +} + +int _write(struct mansession *s, struct message *m) { + int i; + + pthread_mutex_lock(&s->lock); + for (i=0; ihdrcount; i++) { + ast_carefulwrite(s->fd, m->headers[i], strlen(m->headers[i]) , s->writetimeout); + ast_carefulwrite(s->fd, "\r\n", 2, s->writetimeout); + } + ast_carefulwrite(s->fd, "\r\n", 2, s->writetimeout); + pthread_mutex_unlock(&s->lock); + + return 0; +} + +int _onconnect(struct mansession *s, struct message *m) { + + char banner[100]; + + sprintf(banner, "%s/%s\r\n", PROXY_BANNER, PROXY_VERSION); + pthread_mutex_lock(&s->lock); + ast_carefulwrite(s->fd, banner, strlen(banner), s->writetimeout); + pthread_mutex_unlock(&s->lock); + + return 0; +} + -- cgit