summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/astmanproxy.c11
-rw-r--r--src/common.c6
-rw-r--r--src/http.c14
-rw-r--r--src/include/astmanproxy.h2
-rw-r--r--src/standard.c2
5 files changed, 18 insertions, 17 deletions
diff --git a/src/astmanproxy.c b/src/astmanproxy.c
index 457a3bf..25aab23 100644
--- a/src/astmanproxy.c
+++ b/src/astmanproxy.c
@@ -181,8 +181,11 @@ int WriteClients(struct message *m) {
}
} else
c->output->write(c, m);
- if ( c->input->autodisconnect && c->input->autodisconnect() )
- c->dead = 1;
+ if (c->inputcomplete) {
+ pthread_mutex_lock(&c->lock);
+ c->outputcomplete = 1;
+ pthread_mutex_unlock(&c->lock);
+ }
}
c = c->next;
}
@@ -254,7 +257,11 @@ void *session_do(struct mansession *s)
for (;;) {
/* Get a complete message block from input handler */
memset(&m, 0, sizeof(struct message) );
+ if (debug > 3)
+ debugmsg("calling %s_read...", s->input->formatname);
res = s->input->read(s, &m);
+ if (debug > 3)
+ debugmsg("%s_read result =%d", s->input->formatname, res);
m.session = s;
if (res > 0) {
diff --git a/src/common.c b/src/common.c
index 98f33e0..f4b370e 100644
--- a/src/common.c
+++ b/src/common.c
@@ -11,9 +11,6 @@ int get_input(struct mansession *s, char *output)
struct pollfd fds[1];
char iabuf[INET_ADDRSTRLEN];
- if (debug > 3)
- debugmsg("in get_input");
-
/* Look for \r\n from the front, our preferred end of line */
for (x=0;x<s->inlen;x++) {
int xtra = 0;
@@ -37,8 +34,6 @@ int get_input(struct mansession *s, char *output)
debugmsg("Warning: Got long line with no end from %s: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr), s->inbuf);
s->inlen = 0;
}
- if (debug > 3)
- debugmsg("attempting poll operation");
/* get actual fd, even if a negative SSL fd */
fds[0].fd = get_real_fd(s->fd);
@@ -55,7 +50,6 @@ int get_input(struct mansession *s, char *output)
debugmsg("Select returned error");
return -1;
} else if (res > 0) {
- debugmsg("attempting socket read in get_input...");
pthread_mutex_lock(&s->lock);
/* read from socket; SSL or otherwise */
res = m_recv(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen, 0);
diff --git a/src/http.c b/src/http.c
index 91c3de0..fcc6bcc 100644
--- a/src/http.c
+++ b/src/http.c
@@ -12,10 +12,6 @@
int ParseHTTPInput(char *buf, struct message *m) {
char *n, *v;
- /* initialize message block
- memset(m, 0, sizeof (struct message) );
- */
-
n = buf;
while ( (v = strstr(n, "=")) ) {
v += 1;
@@ -66,15 +62,18 @@ int _read(struct mansession *s, struct message *m) {
char line[MAX_LEN], method[10], formdata[MAX_LEN], header[MAX_LEN];
int res, clength = 0;
- if (s->dead)
- return -1;
-
memset(method, 0, sizeof method);
memset(formdata, 0, sizeof formdata);
memset(header, 0, sizeof header);
/* for http, don't do get_input forever */
for (;;) {
+
+ if (s->inputcomplete && !s->outputcomplete)
+ continue;
+ else if (s->inputcomplete && s->outputcomplete)
+ return -1;
+
memset(line, 0, sizeof line);
res = get_input(s, line);
debugmsg("res=%d, line: %s",res, line);
@@ -107,6 +106,7 @@ int _read(struct mansession *s, struct message *m) {
BuildHTTPHeader(header);
pthread_mutex_lock(&s->lock);
+ s->inputcomplete = 1;
ast_carefulwrite(s->fd, header, strlen(header), s->writetimeout);
pthread_mutex_unlock(&s->lock);
debugmsg("header: %s", header);
diff --git a/src/include/astmanproxy.h b/src/include/astmanproxy.h
index fc80412..f888191 100644
--- a/src/include/astmanproxy.h
+++ b/src/include/astmanproxy.h
@@ -100,6 +100,8 @@ struct mansession {
int connected;
int dead; /* Whether we are dead */
int busy; /* Whether we are busy */
+ int inputcomplete; /* Whether we want any more input from this session (http) */
+ int outputcomplete; /* Whether output to this session is done (http) */
struct ast_server *server;
struct proxy_user user;
char actionid[MAX_LEN];
diff --git a/src/standard.c b/src/standard.c
index 26cd4a8..0b2bd17 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -15,7 +15,6 @@ extern struct mansession *sessions;
int _read(struct mansession *s, struct message *m) {
int res;
- if (debug) debugmsg("in standard_read module...");
for (;;) {
res = get_input(s, m->headers[m->hdrcount]);
@@ -46,7 +45,6 @@ int _read(struct mansession *s, struct message *m) {
int _write(struct mansession *s, struct message *m) {
int i;
- if (debug) debugmsg("in standard_write module...");
pthread_mutex_lock(&s->lock);
for (i=0; i<m->hdrcount; i++) {
ast_carefulwrite(s->fd, m->headers[i], strlen(m->headers[i]) , s->writetimeout);