Implemnted egw_source and added a "raw" option to the URL.
[egate.git] / www / wproto.c
index 5d3fc37..62448aa 100644 (file)
  * USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * $Log: wproto.c,v $
+ * Revision 1.22  1997/01/24 13:13:11  adam
+ * Implemnted egw_source and added a "raw" option to the URL.
+ * Fixed a bug in the buffering system of wproto; the macro wo_putc could
+ * override memory if it was the first HTML generating function called.
+ *
  * Revision 1.21  1996/05/23 15:53:11  adam
  * Bug fix: egw_enc failed on 8-bit chars.
  * New command: egw_parms.
 #include <stdarg.h>
 #include <ctype.h>
 #include <errno.h>
+#include <assert.h>
 
 #include "wproto.h"
 
@@ -150,12 +156,9 @@ void wo_write (WCLIENT wc, const char *s, size_t len)
 {
     if (wc->outbuffer_offset + len >= wc->outbuffer_size)
     {
-       if (!wc->outbuffer)
-           wc->outbuffer = malloc (wc->outbuffer_size += 
-              ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK));
-       else
-           wc->outbuffer = realloc(wc->outbuffer, wc->outbuffer_size +=
-              ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK));
+        assert (wc->outbuffer);
+        wc->outbuffer = realloc(wc->outbuffer, wc->outbuffer_size +=
+               ((len >= OUTBUFFER_CHUNK) ? len*2 : OUTBUFFER_CHUNK));
     }
     memcpy(wc->outbuffer + wc->outbuffer_offset, s, len);
     wc->outbuffer_offset += len;
@@ -179,6 +182,8 @@ void wo_printf (WCLIENT wc, const char *fmt, ...)
 
 void wo_clear (WCLIENT wc, const char *type)
 {
+    if (!wc->outbuffer)
+        wc->outbuffer = malloc (wc->outbuffer_size = OUTBUFFER_CHUNK);
     wc->outbuffer_offset = 0;
     if (type)
         wo_printf(wc, "Content-type: %s\n\n", type);