From: Michal Voců Date: Thu, 8 Mar 2007 10:39:56 +0000 (+0000) Subject: * more parsing X-Git-Tag: glite-lb-server-bones_R_2_2_4_1~13 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=da898c1f57afc6e83f966d528ebc9bf62599e2ad;p=jra1mw.git * more parsing --- diff --git a/org.glite.lb.logger/src-nt/HTTPTransport.cpp b/org.glite.lb.logger/src-nt/HTTPTransport.cpp index 9847beb..a60162f 100644 --- a/org.glite.lb.logger/src-nt/HTTPTransport.cpp +++ b/org.glite.lb.logger/src-nt/HTTPTransport.cpp @@ -1,4 +1,5 @@ #include "HTTPTransport.H" +#include "Exception.H" #include #include @@ -28,8 +29,10 @@ HTTPTransport::onReady() len = conn->read(pos, sizeof(buffer) - (pos - buffer)); if(len < 0) { // error during request + state = NONE; } else if(len == 0) { // other side closed connection + state = NONE; } else { char *cr = NULL, *p = buffer, *s = buffer; bool crlf_seen = false; @@ -104,9 +107,13 @@ HTTPTransport::onReady() if(s < buffer + len) { memmove(body, s, buffer + len - s); pos = body + (buffer + len - s); + } else { + pos = body; } } else { // report error + std::cout << "Wrong content length" << std::endl; + throw new Exception(); } } else { // move the trailing characters to the front @@ -119,9 +126,31 @@ HTTPTransport::onReady() break; case IN_BODY: + len = conn->read(pos, content_length - (pos - body)); + if(len < 0) { + // error reading + state = NONE; + } else if(len == 0) { + // no more data + state = NONE; + } else { + pos += len; + if(pos - body == content_length) { + // finished reading + state = NONE; + } + } break; } + if(state != NONE) + ThreadPool::theThreadPool.queueWorkRead(this); + else { + std::cout << request << std::endl << headers << std::endl; + std::cout.write(body, content_length); + std::cout.flush(); + } + } @@ -140,6 +169,24 @@ HTTPTransport::onError() int HTTPTransport::parseHeader(const char *s, unsigned int len) { + char *p; + char tmp[256]; + + std::cout << "header: "; std::cout.write(s, len); + std::cout << std::endl; + std::cout.flush(); + if(!strncasecmp(s, "Content-Length", 14)) { + int l; + + p = (char*)memccpy((void*)s, (void*)s, ':', len); + if(p) { + l = (p - s < sizeof(tmp) - 1) ? p - s : sizeof(tmp) - 1; + memcpy(tmp, p, l); + tmp[l] = 0; + std::cout << "length " << tmp << std::endl; + content_length = atoi(tmp); + } + } return(0); }