diff options
author | David Troy <dave@popvox.com> | 2006-04-02 21:24:16 +0000 |
---|---|---|
committer | David Troy <dave@popvox.com> | 2006-04-02 21:24:16 +0000 |
commit | 09255fbd6f7e0bd81f5de30f580928a94e1834d7 (patch) | |
tree | c12d708d993f3f7c9f4aca4cb0177c1ee08b3479 | |
parent | 7885ebaa4f79cf908adb9e2a7fb252493c10026b (diff) | |
download | astmanproxy-09255fbd6f7e0bd81f5de30f580928a94e1834d7.tar.gz astmanproxy-09255fbd6f7e0bd81f5de30f580928a94e1834d7.tar.xz astmanproxy-09255fbd6f7e0bd81f5de30f580928a94e1834d7.zip |
git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/branches/1.20pre@68 f02b47b9-160a-0410-81a6-dc3441afb0ec
-rw-r--r-- | src/astmanproxy.c | 6 | ||||
-rw-r--r-- | src/common.c | 3 | ||||
-rw-r--r-- | src/http.c | 49 |
3 files changed, 24 insertions, 34 deletions
diff --git a/src/astmanproxy.c b/src/astmanproxy.c index 29259d3..282a33e 100644 --- a/src/astmanproxy.c +++ b/src/astmanproxy.c @@ -153,8 +153,8 @@ void destroy_session(struct mansession *s) else sessions = cur->next; debugmsg("Connection closed: %s", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr)); - if (s->fd > -1) - close_sock(s->fd); /* close tcp & ssl socket */ + + close_sock(s->fd); /* close tcp/ssl socket */ pthread_mutex_destroy(&s->lock); free(s); } else @@ -183,7 +183,7 @@ int WriteClients(struct message *m) { } else c->output->write(c, m); if ( c->input->autodisconnect && c->input->autodisconnect() ) - close_sock(c->fd); /* close tcp & ssl socket */ + destroy_session(c); } c = c->next; } diff --git a/src/common.c b/src/common.c index 0855ac9..39b5c93 100644 --- a/src/common.c +++ b/src/common.c @@ -59,10 +59,11 @@ int get_input(struct mansession *s, char *output) if (res < 1) return -1; } + + /* We have some input, but it's not ready for processing */ s->inlen += res; s->inbuf[s->inlen] = '\0'; return 0; - /* We have some input, but it's not ready for processing */ } char *astman_get_header(struct message *m, char *var) @@ -16,8 +16,6 @@ int ParseHTTPInput(char *buf, struct message *m) { if ( !(*buf) ) return 0; */ - debugmsg("Parsing http input: %s", buf); - /* initialize message block */ memset(m, 0, sizeof (struct message) ); @@ -82,11 +80,19 @@ int _read(struct mansession *s, struct message *m) { memset(line, 0, sizeof line); res = get_input(s, line); - if (res > 0) { - if (*line == '\0' ) { - if (*method == '\0') - break; - else { + if (res > 0 && *line) { + debugmsg("Got http: %s", line); + /* Do meaningful things here */ + if ( !strncmp(line,"POST",4) ) { + strncpy(method, line, 4); + } else if ( !strncmp(line,"GET",3) ) { + /* GET /?Action=Ping&ActionID=Foo HTTP/1.1 */ + strncpy(method, line, 3); + memcpy(formdata, line+6, strstr(line, " HTTP")-line-6); + } else if ( !strncasecmp(line, "Content-Length: ", 16) ) { + clength = atoi(line+16); + } + } else if (res == 0 && *method && clength && *s->inbuf && strlen(s->inbuf)==clength) { if ( !strcasecmp(method, "POST") ) { pthread_mutex_lock(&s->lock); strncpy(formdata, s->inbuf, clength); @@ -95,13 +101,11 @@ int _read(struct mansession *s, struct message *m) { s->inlen -= clength; pthread_mutex_unlock(&s->lock); } - if (debug) { - debugmsg("method: %s", method); - debugmsg("clength: %d", clength); - debugmsg("formdata: %s", formdata); - debugmsg("s->inbuf: %s", s->inbuf); - debugmsg("s->inlen: %d", s->inlen); - } + debugmsg("method: %s", method); + debugmsg("clength: %d", clength); + debugmsg("formdata: %s", formdata); + debugmsg("s->inbuf: %s", s->inbuf); + debugmsg("s->inlen: %d", s->inlen); BuildHTTPHeader(header); pthread_mutex_lock(&s->lock); @@ -113,23 +117,8 @@ 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 { - debugmsg("Got http: %s", line); - /* Do meaningful things here */ - if ( !strncmp(line,"POST",4) ) { - strncpy(method, line, 4); - } else if ( !strncmp(line,"GET",3) ) { - /* GET /?Action=Ping&ActionID=Foo HTTP/1.1 */ - strncpy(method, line, 3); - memcpy(formdata, line+6, strstr(line, " HTTP")-line-6); - } else if ( !strncasecmp(line, "Content-Length: ", 16) ) { - clength = atoi(line+16); - debugmsg("clength=%d", clength); - } - } } else if (res < 0) - return res; + break; } return -1; |