]> code.citadel.org Git - citadel.git/blobdiff - webcit/serv_func.c
* several memoryleaks
[citadel.git] / webcit / serv_func.c
index edff5ebd43a6ceee1a3d13b718f0972958d21d58..a9ff29458403911fba1438fd61841caa65a80bf1 100644 (file)
@@ -6,7 +6,7 @@
 #include "webserver.h"
 
 struct serv_info serv_info; /**< our connection data to the server */
-
+HashList *ServHash = NULL;//// TODO;
 /*
  * get info about the server we've connected to
  *
@@ -95,6 +95,9 @@ void get_serv_info(char *browser_host, char *user_agent)
                case 22:
                        safestrncpy(serv_info.serv_svn_revision, buf, sizeof serv_info.serv_svn_revision);
                        break;
+               case 23:
+                       serv_info.serv_supports_openid = atoi(buf);
+                       break;
                }
                ++a;
        }
@@ -336,34 +339,53 @@ void server_to_text()
 /**
  * Read binary data from server into memory using a series of
  * server READ commands.
- * \param buffer the output buffer
- * \param total_len the maximal length of buffer
+ * \return the read content as StrBuf
  */
-void read_server_binary(char *buffer, size_t total_len) {
+int read_server_binary(StrBuf *Ret, size_t total_len) 
+{
        char buf[SIZ];
        size_t bytes = 0;
        size_t thisblock = 0;
+       StrBuf *Buf;
+       
+       Buf = NewStrBuf();
+       if (Ret == NULL)
+           return -1;
 
-       memset(buffer, 0, total_len);
        while (bytes < total_len) {
                thisblock = 4095;
                if ((total_len - bytes) < thisblock) {
                        thisblock = total_len - bytes;
-                       if (thisblock == 0) return;
+                       if (thisblock == 0) {
+                               FlushStrBuf(Ret); 
+                               FreeStrBuf(&Buf);
+                               return -1; 
+                       }
                }
                serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '6') {
-                       thisblock = (size_t)atoi(&buf[4]);
-                       if (!WC->connected) return;
-                       serv_read(&buffer[bytes], thisblock);
-                       bytes += thisblock;
-               }
-               else {
-                       lprintf(3, "Error: %s\n", &buf[4]);
-                       return;
+               if (StrBuf_ServGetln(Buf) > 0)
+               {
+                   if (ChrPtr(Buf)[0] == '6')
+                   {
+                           StrBufCutLeft(Buf, 4); //thisblock = (size_t)atoi(&buf[4]);
+                           thisblock = StrTol(Buf);
+                           if (!WC->connected) {
+                                   FlushStrBuf(Ret); 
+                                   FreeStrBuf(&Buf); 
+                                   return -1; 
+                           }
+                           StrBuf_ServGetBLOB(Ret, thisblock);
+                           bytes += thisblock;
+                   }
+                   else {
+                           FreeStrBuf(&Buf);
+                           lprintf(3, "Error: %s\n", &buf[4]);
+                           return -1;
+                   }
                }
        }
+       FreeStrBuf(&Buf);
+       return StrLength(Ret);
 }
 
 
@@ -372,36 +394,27 @@ void read_server_binary(char *buffer, size_t total_len) {
  * usual 000 terminator is found.  Caller is responsible for freeing
  * the returned pointer.
  */
-char *read_server_text(void) {
-       char *text = NULL;
-       size_t bytes_allocated = 0;
-       size_t bytes_read = 0;
-       int linelen;
-       char buf[SIZ];
-
-       text = malloc(SIZ);
-       if (text == NULL) {
-               return(NULL);
-       }
-       text[0] = 0;
-       bytes_allocated = SIZ;
-
-       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-               linelen = strlen(buf);
-               buf[linelen] = '\n';
-               buf[linelen+1] = 0;
-               ++linelen;
-
-               if ((bytes_read + linelen) >= (bytes_allocated - 2)) {
-                       bytes_allocated = 2 * bytes_allocated;
-                       text = realloc(text, bytes_allocated);
+int read_server_text(StrBuf *Buf, long *nLines)
+{
+       struct wcsession *WCC = WC;
+       long nRead;
+       long nTotal = 0;
+       long nlines;
+       
+       nlines = 0;
+       while ((WCC->serv_sock!=-1) &&
+              (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
+       {
+               if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
+                       StrBufCutRight(Buf, nRead);
+                       break;
                }
-
-               strcpy(&text[bytes_read], buf);
-               bytes_read += linelen;
+               nTotal += nRead;
+               nlines ++;
        }
 
-       return(text);
+       *nLines = nlines;
+       return nTotal;
 }