]> code.citadel.org Git - citadel.git/blobdiff - webcit/webserver.c
* temporary solution to our ser_readln migration: have a buffer on the session, read...
[citadel.git] / webcit / webserver.c
index c999062414fef13ee3bf6cab854125b6dc441f8d..74bff8c4812c2627fd3c88e7d5103c813ffa6d7d 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,13 @@ 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,
+                                       O_TERM,
+                                       &Error);
        if (retval < 0) {
                lprintf(2, "client_read() failed: %s\n",
                        Error);
@@ -271,13 +275,10 @@ long end_burst(void)
         fd_set wset;
         int fdflags;
 
-       //#ifdef HAVE_ZLIB
-       /* Perform gzip compression, if enabled and supported by client */
        if (!DisableGzip && (WCC->gzip_ok) && CompressBuffer(WCC->WBuf))
        {
                hprintf("Content-encoding: gzip\r\n");
        }
-       //#endif        /* HAVE_ZLIB */
 
        hprintf("Content-length: %d\r\n\r\n", StrLength(WCC->WBuf));
 
@@ -359,23 +360,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
@@ -389,11 +373,12 @@ void graceful_shutdown_watcher(int signum) {
 }
 
 
-int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf)
+int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf, const char **Pos)
 {
        const char *Error, *pch, *pchs;
        int rlen, len, retval = 0;
 
+#ifdef HAVE_OPENSSL
        if (is_https) {
                int ntries = 0;
                if (StrLength(CLineBuf) > 0) {
@@ -441,12 +426,14 @@ int ClientGetLine(int *sock, StrBuf *Target, StrBuf *CLineBuf)
                        return -1;
        }
        else 
-               return StrBufTCP_read_buffered_line(Target, 
-                                                   CLineBuf,
-                                                   sock,
-                                                   5,
-                                                   1,
-                                                   &Error);
+#endif
+               return StrBufTCP_read_buffered_line_fast(Target, 
+                                                        CLineBuf,
+                                                        Pos,
+                                                        sock,
+                                                        5,
+                                                        1,
+                                                        &Error);
 }
 
 
@@ -642,7 +629,7 @@ int main(int argc, char **argv)
        char *mo = NULL;
 #endif /* ENABLE_NLS */
        char uds_listen_path[PATH_MAX]; /* listen on a unix domain socket? */
-       const char *I18nDumpFile;
+       const char *I18nDumpFile = NULL;
 
        WildFireInitBacktrace(argv[0], 2);
 
@@ -793,6 +780,7 @@ int main(int argc, char **argv)
 #ifdef ENABLE_NLS
        initialize_locales();
 
+
        locale = setlocale(LC_ALL, "");
 
        mo = malloc(strlen(webcitdir) + 20);
@@ -800,7 +788,6 @@ int main(int argc, char **argv)
        free(mo);
        lprintf(9, "Text domain: %s\n", textdomain("webcit"));
        lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8"));
-       preset_locale();
 #endif