summaryrefslogtreecommitdiffstats
path: root/src/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http.c')
-rw-r--r--src/http.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/src/http.c b/src/http.c
index d8b081d..f14c722 100644
--- a/src/http.c
+++ b/src/http.c
@@ -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;