* migrate http read logic to the strbuf controlled readbuffered internal fast mode
authorWilfried Göesgens <willi@citadel.org>
Mon, 20 Apr 2009 22:34:09 +0000 (22:34 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 20 Apr 2009 22:34:09 +0000 (22:34 +0000)
webcit/context_loop.c
webcit/webcit.c
webcit/webcit.h
webcit/webserver.c
webcit/webserver.h

index 856d93ee1028c5d27b3c0fd3a58cb091751e88bc..c844f65a74075df3f876029f66cd12ea26239dc2 100644 (file)
@@ -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
index 21dfdd3919d4dec585949c0cddc70d5897e01cbb..ad2d501f96aef251ed9c6bb0719b9876a5e9c16e 100644 (file)
@@ -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);
index 2035e61e4bf2f1098f70ad76ad77abd0d61b1752..dfb00d8137851692ef422922f6d25c2131f983c5 100644 (file)
@@ -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);
index 72d090c16485b21ed5460f24aea75588c2e1eb6c..ed9188ffa913a4f3a3fd92d8f9220596abed9fdb 100644 (file)
@@ -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
index 62a02bf96ea6df060dc864cf8d145f064931b041..ddb3fb797f16774d75689a88474269a4788ea3f0 100644 (file)
@@ -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);