summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Troy <dave@popvox.com>2006-04-03 16:23:01 +0000
committerDavid Troy <dave@popvox.com>2006-04-03 16:23:01 +0000
commitbbf337d7f093d32703477f2722591ac08f8230bb (patch)
treef686336d5fdc65df4008a2fa57f5b861c3f5c780
parentdc56649b0e188704512719be80ecb6f544cef0e7 (diff)
downloadastmanproxy-bbf337d7f093d32703477f2722591ac08f8230bb.tar.gz
astmanproxy-bbf337d7f093d32703477f2722591ac08f8230bb.tar.xz
astmanproxy-bbf337d7f093d32703477f2722591ac08f8230bb.zip
git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@71 f02b47b9-160a-0410-81a6-dc3441afb0ec
-rw-r--r--src/astmanproxy.c3
-rw-r--r--src/common.c39
-rw-r--r--src/http.c18
-rw-r--r--src/include/astmanproxy.h2
-rw-r--r--src/ssl.c2
5 files changed, 37 insertions, 27 deletions
diff --git a/src/astmanproxy.c b/src/astmanproxy.c
index cc86859..853b8bf 100644
--- a/src/astmanproxy.c
+++ b/src/astmanproxy.c
@@ -541,6 +541,7 @@ static void *accept_thread()
/* SSL stuff below */
is_encrypted = is_encrypt_request(pc.sslclhellotimeout, as);
+ debugmsg("is_encrypted: %d", is_encrypted);
if (is_encrypted > 0) {
if (!pc.acceptencryptedconnection) {
if( debug )
@@ -619,7 +620,7 @@ int main(int argc, char *argv[])
{
switch( i ) {
case 'd':
- debug = 1;
+ debug++;
break;
case 'h':
Usage();
diff --git a/src/common.c b/src/common.c
index 39b5c93..98f33e0 100644
--- a/src/common.c
+++ b/src/common.c
@@ -43,22 +43,29 @@ int get_input(struct mansession *s, char *output)
fds[0].fd = get_real_fd(s->fd);
fds[0].events = POLLIN;
- res = poll(fds, 1, -1);
- if (debug > 3)
- debugmsg("returned from poll op");
-
- if (res < 0 && debug) {
- debugmsg("Select returned error");
- } 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);
- pthread_mutex_unlock(&s->lock);
- if (res < 1)
- return -1;
- }
+ do {
+ res = poll(fds, 1, -1);
+ if (res < 0) {
+ if (errno == EINTR) {
+ if (s->dead)
+ return -1;
+ continue;
+ }
+ if (debug)
+ 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);
+ pthread_mutex_unlock(&s->lock);
+ if (res < 1)
+ return -1;
+ break;
+
+ }
+ } while(1);
/* We have some input, but it's not ready for processing */
s->inlen += res;
diff --git a/src/http.c b/src/http.c
index 70cc2b9..3b271b9 100644
--- a/src/http.c
+++ b/src/http.c
@@ -12,12 +12,9 @@
int ParseHTTPInput(char *buf, struct message *m) {
char *n, *v;
- /* just an empty block; go home
- if ( !(*buf) )
- return 0; */
-
- /* initialize message block */
+ /* initialize message block
memset(m, 0, sizeof (struct message) );
+ */
n = buf;
while ( (v = strstr(n, "=")) ) {
@@ -80,8 +77,9 @@ int _read(struct mansession *s, struct message *m) {
for (;;) {
memset(line, 0, sizeof line);
res = get_input(s, line);
+ debugmsg("res=%d, line: %s",res, line);
- if (res > 0 && *line) {
+ if (res > 0) {
debugmsg("Got http: %s", line);
/* Do meaningful things here */
if ( !strncmp(line,"POST",4) ) {
@@ -93,13 +91,12 @@ int _read(struct mansession *s, struct message *m) {
} else if ( !strncasecmp(line, "Content-Length: ", 16) ) {
clength = atoi(line+16);
}
- } else if (res == 0 && *method && clength && *s->inbuf && strlen(s->inbuf)==clength) {
+
+ if (*method && s->inlen==clength) {
if ( !strcasecmp(method, "POST") ) {
pthread_mutex_lock(&s->lock);
strncpy(formdata, s->inbuf, clength);
- /* Move remaining data back to the front */
- memmove(s->inbuf, s->inbuf + clength+1, s->inlen - clength);
- s->inlen -= clength;
+ s->inlen = 0;
pthread_mutex_unlock(&s->lock);
}
debugmsg("method: %s", method);
@@ -118,6 +115,7 @@ int _read(struct mansession *s, struct message *m) {
/* now, let's transform and copy into a standard message block */
res = ParseHTTPInput(formdata, m);
return res;
+ }
} else if (res < 0)
break;
}
diff --git a/src/include/astmanproxy.h b/src/include/astmanproxy.h
index 6c4ef0b..11ca106 100644
--- a/src/include/astmanproxy.h
+++ b/src/include/astmanproxy.h
@@ -99,6 +99,8 @@ struct mansession {
int inputcomplete;
int authenticated;
int connected;
+ int dead; /* Whether we are dead */
+ int busy; /* Whether we are busy */
struct ast_server *server;
struct proxy_user user;
char actionid[MAX_LEN];
diff --git a/src/ssl.c b/src/ssl.c
index 7f57362..265c961 100644
--- a/src/ssl.c
+++ b/src/ssl.c
@@ -300,6 +300,8 @@ int is_encrypt_request(int sslclhellotimeout, int fd)
}
/* check for sslv2 and return -1 */
else if ((buf[0x02] == 0x01) && (buf[0x03] == 0x00) && (buf[0x04] == 0x02)) {
+ if (debug)
+ debugmsg("Received a SSLv2 request()");
return -1;
}
}