From: Wilfried Göesgens Date: Mon, 20 Apr 2009 22:34:09 +0000 (+0000) Subject: * migrate http read logic to the strbuf controlled readbuffered internal fast mode X-Git-Tag: v7.86~1236 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=5bc5607198f7d7629d451eacfb2cbe662aa7473f * migrate http read logic to the strbuf controlled readbuffered internal fast mode --- diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 856d93ee1..c844f65a7 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -329,8 +329,6 @@ void context_loop(int *sock) LastLine = Line; } while (LineLen > 0); FreeStrBuf(&HeaderName); - /* finish linebuffered fast reading, cut the read part: */ - StrBufCutLeft(Buf, Pos - ChrPtr(Buf)); /* dbg_PrintHash(HTTPHeaders, nix, NULL); */ @@ -550,7 +548,7 @@ void context_loop(int *sock) } go_selected_language(); /* set locale */ #endif - session_loop(HTTPHeaders, ReqLine, ReqType, Buf); /* do transaction */ + session_loop(HTTPHeaders, ReqLine, ReqType, Buf, &Pos); /* do transaction */ #ifdef ENABLE_NLS stop_selected_language(); /* unset locale */ #endif diff --git a/webcit/webcit.c b/webcit/webcit.c index 21dfdd391..ad2d501f9 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -540,7 +540,11 @@ int is_mobile_ua(char *user_agent) { /* * Entry point for WebCit transaction */ -void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method, StrBuf *ReadBuf) +void session_loop(HashList *HTTPHeaders, + StrBuf *ReqLine, + StrBuf *request_method, + StrBuf *ReadBuf, + const char **Pos) { StrBuf *Buf; const char *pch, *pchs, *pche; @@ -694,7 +698,11 @@ void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *request_method body_start = StrLength(content); /** Read the entire input data at once. */ - client_read(&WCC->http_sock, content, ReadBuf, ContentLength + body_start); + client_read_to(&WCC->http_sock, + content, + ReadBuf, Pos, + ContentLength, + SLEEPING); if (!strncasecmp(ChrPtr(ContentType), "application/x-www-form-urlencoded", 33)) { StrBufCutLeft(content, body_start); diff --git a/webcit/webcit.h b/webcit/webcit.h index 2035e61e4..dfb00d813 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -621,7 +621,11 @@ void shutdown_sessions(void); void do_housekeeping(void); void smart_goto(const StrBuf *); void worker_entry(void); -void session_loop(HashList *HTTPHeaders, StrBuf *ReqLine, StrBuf *ReqType, StrBuf *ReadBuf); +void session_loop(HashList *HTTPHeaders, + StrBuf *ReqLine, + StrBuf *ReqType, + StrBuf *ReadBuf, + const char **Pos); size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm); void fmt_time(char *buf, size_t siz, time_t thetime); void httpdate(char *buf, time_t thetime); diff --git a/webcit/webserver.c b/webcit/webserver.c index 72d090c16..ed9188ffa 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -199,13 +199,18 @@ int ig_uds_server(char *sockpath, int queue_len) * 0 Request timed out. * -1 Connection is broken, or other error. */ -int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeout) +int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, const char **Pos, int bytes, int timeout) { const char *Error; int retval = 0; #ifdef HAVE_OPENSSL if (is_https) { + long bufremain = StrLength(Buf) - (*Pos - ChrPtr(Buf)); + StrBufAppendBufPlain(Target, *Pos, bufremain, 0); + *Pos = NULL; + FlushStrBuf(Buf); + while ((StrLength(Buf) + StrLength(Target) < bytes) && (retval >= 0)) retval = client_read_sslbuffer(Buf, timeout); @@ -225,14 +230,12 @@ int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeou } #endif - if (StrLength(Buf) > 0) {/*/// todo: what if Buf > bytes?*/ - StrBufAppendBuf(Target, Buf, 0); - } - retval = StrBufReadBLOB(Target, - sock, - (StrLength(Target) > 0), - bytes - StrLength(Target), - &Error); + retval = StrBufReadBLOBBuffered(Target, + Buf, Pos, + sock, + 1, + bytes, + &Error); if (retval < 0) { lprintf(2, "client_read() failed: %s\n", Error); @@ -359,23 +362,6 @@ long end_burst(void) } - -/* - * Read data from the client socket with default timeout. - * (This is implemented in terms of client_read_to() and could be - * justifiably moved out of sysdep.c) - * - * sock the socket fd to read from - * buf the buffer to write to - * bytes Number of bytes to read - */ -int client_read(int *sock, StrBuf *Target, StrBuf *buf, int bytes) -{ - return (client_read_to(sock, Target, buf, bytes, SLEEPING)); -} - - - /* * Shut us down the regular way. * signum is the signal we want to forward diff --git a/webcit/webserver.h b/webcit/webserver.h index 62a02bf96..ddb3fb797 100644 --- a/webcit/webserver.h +++ b/webcit/webserver.h @@ -7,8 +7,7 @@ extern char socket_dir[PATH_MAX]; int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf, const char **Pos); int client_getln(int *sock, char *buf, int bufsiz); -int client_read(int *sock, StrBuf *Target, StrBuf *buf, int bytes); -int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeout); +int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, const char **Pos, int bytes, int timeout); int lprintf(int loglevel, const char *format, ...); void wc_backtrace(void); void ShutDownWebcit(void);