Cleaned up some of the comments ... removed vestiges of last year's doxygen experiment
[citadel.git] / webcit / serv_func.c
index 188129e0dda0322585b61f80dbbbd6fa7567e935..29b0481760d082ffbeb76707b7e866d2e2c37613 100644 (file)
@@ -1,21 +1,17 @@
 /*
  * $Id$
  */
-/**
- * \defgroup ServFuncs Handles various types of data transfer operations with the Citadel service.
- * \ingroup CitadelCommunitacion
- */
 
-/*@{*/ 
 #include "webcit.h"
 #include "webserver.h"
 
 struct serv_info serv_info; /**< our connection data to the server */
-
-/**
- * \brief get info about the server we've connected to
- * \param browser_host the citadell we want to connect to
- * \param user_agent which browser uses our client?
+HashList *ServHash = NULL;//// TODO;
+/*
+ * get info about the server we've connected to
+ *
+ * browser_host                the citadell we want to connect to
+ * user_agent          which browser uses our client?
  */
 void get_serv_info(char *browser_host, char *user_agent)
 {
@@ -36,15 +32,13 @@ void get_serv_info(char *browser_host, char *user_agent)
        serv_puts("MSGP text/html|text/plain");
        serv_getln(buf, sizeof buf);
 
-#ifdef WEBCIT_WITH_CALENDAR_SERVICE
-       /**
+       /*
         * Tell the server that when we save a calendar event, we
         * want invitations to be generated by the Citadel server
         * instead of by the client.
         */
        serv_puts("ICAL sgi|1");
        serv_getln(buf, sizeof buf);
-#endif
 
        /** Now ask the server to tell us a little bit about itself... */
        serv_puts("INFO");
@@ -89,6 +83,21 @@ void get_serv_info(char *browser_host, char *user_agent)
                case 15:
                        serv_info.serv_newuser_disabled = atoi(buf);
                        break;
+               case 16:
+                       safestrncpy(serv_info.serv_default_cal_zone, buf, sizeof serv_info.serv_default_cal_zone);
+                       break;
+               case 20:
+                       serv_info.serv_supports_sieve = atoi(buf);
+                       break;
+               case 21:
+                       serv_info.serv_fulltext_enabled = atoi(buf);
+                       break;
+               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;
        }
@@ -97,16 +106,21 @@ void get_serv_info(char *browser_host, char *user_agent)
 
 
 /**
- * \brief Read Citadel variformat text and spit it out as HTML.
- * \param align html align string
+ *  Read Citadel variformat text and spit it out as HTML.
+ *  align html align string
  */
-void fmout(char *align)
+inline void fmout(char *align)
+{
+       _fmout(WC->WBuf, align);
+}
+
+void _fmout(StrBuf *Target, char *align)
 {
        int intext = 0;
        int bq = 0;
        char buf[SIZ];
 
-       wprintf("<div align=%s>\n", align);
+       StrBufAppendPrintf(Target, "<div align=%s>\n", align);
        while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
 
                if ((intext == 1) && (isspace(buf[0]))) {
@@ -120,20 +134,20 @@ void fmout(char *align)
                 * " >" quotes and will convert to <BLOCKQUOTE> tags.
                 */
                if ((bq == 0) && (!strncmp(buf, " >", 2))) {
-                       wprintf("<BLOCKQUOTE>");
+                       StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
                        bq = 1;
                } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
-                       wprintf("</BLOCKQUOTE>");
+                       StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
                        bq = 0;
                }
                if ((bq == 1) && (!strncmp(buf, " >", 2))) {
                        strcpy(buf, &buf[2]);
                }
                /** Activate embedded URL's */
-               url(buf);
+               url(buf, sizeof(buf));
 
-               escputs(buf);
-               wprintf("\n");
+               escputs(buf);//// TODO: Target
+               StrBufAppendBufPlain(Target, HKEY("\n"), 0);
        }
        if (bq == 1) {
                wprintf("</I>");
@@ -145,7 +159,7 @@ void fmout(char *align)
 
 
 /**
- * \brief Read Citadel variformat text and spit it out as HTML in a form
+ *  Read Citadel variformat text and spit it out as HTML in a form
  * suitable for embedding in another message (forward/quote).
  * (NO LINEBREAKS ALLOWED HERE!)
  */
@@ -188,14 +202,14 @@ void pullquote_fmout(void) {
 
 
 /**
- * \brief Transmit message text (in memory) to the server.
+ *  Transmit message text (in memory) to the server.
  *
- * \param ptr Pointer to the message being transmitted
+ *  ptr Pointer to the message being transmitted
  */
 void text_to_server(char *ptr)
 {
        char buf[256];
-       int ch, a, pos;
+       int ch, a, pos, len;
 
        pos = 0;
        buf[0] = 0;
@@ -203,9 +217,11 @@ void text_to_server(char *ptr)
        while (ptr[pos] != 0) {
                ch = ptr[pos++];
                if (ch == 10) {
-                       while ( (isspace(buf[strlen(buf) - 1]))
-                         && (strlen(buf) > 1) )
-                               buf[strlen(buf) - 1] = 0;
+                       len = strlen(buf);
+                       while ( (isspace(buf[len - 1]))
+                               && (buf[0] !=  '\0') 
+                               && (buf[1] !=  '\0') )
+                               buf[--len] = 0;
                        serv_puts(buf);
                        buf[0] = 0;
                        if (ptr[pos] != 0) strcat(buf, " ");
@@ -229,10 +245,10 @@ void text_to_server(char *ptr)
 
 
 /**
- * \brief Transmit message text (in memory) to the server,
+ *  Transmit message text (in memory) to the server,
  *        converting to Quoted-Printable encoding as we go.
  *
- * \param ptr Pointer to the message being transmitted
+ *  ptr Pointer to the message being transmitted
  */
 void text_to_server_qp(char *ptr)
 {
@@ -305,7 +321,7 @@ void text_to_server_qp(char *ptr)
 
 
 /**
- * \brief translate server message output to text
+ *  translate server message output to text
  * (used for editing room info files and such)
  */
 void server_to_text()
@@ -328,72 +344,82 @@ 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);
 }
 
 
 /**
- * \brief Read text from server, appending to a string buffer until the
+ *  Read text from server, appending to a string buffer until the
  * 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;
 }