]> code.citadel.org Git - citadel.git/blobdiff - webcit/serv_func.c
* register mimetypes and send them to citserver on _every_ connect.
[citadel.git] / webcit / serv_func.c
index ed53165aed3263169c25fa9cf700af9d9d1b4ab6..ddc94f9af91bc57f29be7da6fb17289590126c4b 100644 (file)
@@ -1,4 +1,4 @@
-/*
+  /*
  * $Id$
  */
 
@@ -8,6 +8,23 @@
 int is_uds = 0;
 char serv_sock_name[PATH_MAX] = "";
 
+HashList *EmbeddableMimes = NULL;
+StrBuf *EmbeddableMimeStrs = NULL;
+
+
+void SetInlinMimeRenderers(void)
+{
+       StrBuf *Buf;
+
+       Buf = NewStrBuf();
+       /** Tell the server what kind of richtext we prefer */
+       serv_putbuf(EmbeddableMimeStrs);
+       StrBuf_ServGetln(Buf);
+
+       FreeStrBuf(&Buf);
+}
+
+
 void DeleteServInfo(ServInfo **FreeMe)
 {
        if (*FreeMe == NULL)
@@ -48,10 +65,6 @@ ServInfo *get_serv_info(StrBuf *browser_host, StrBuf *user_agent)
        );
        StrBuf_ServGetln(Buf);
 
-       /** Tell the server what kind of richtext we prefer */
-       serv_puts("MSGP text/calendar|text/vnote|text/html|text/plain");
-       StrBuf_ServGetln(Buf);
-
        /*
         * Tell the server that when we save a calendar event, we
         * want invitations to be generated by the Citadel server
@@ -136,7 +149,7 @@ int GetConnected (void)
        wcsession *WCC = WC;
 
        if (WCC->ReadBuf == NULL)
-               WCC->ReadBuf = NewStrBuf();
+               WCC->ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
        if (is_uds) /* unix domain socket */
                WCC->serv_sock = uds_connectsock(serv_sock_name);
        else        /* tcp socket */
@@ -206,6 +219,7 @@ int GetConnected (void)
                        end_webcit_session();
                        return 1;
                }
+               SetInlinMimeRenderers();
        }
        return 0;
 }
@@ -264,62 +278,67 @@ void FmOut(StrBuf *Target, char *align, StrBuf *Source)
 {
        const char *ptr, *pte;
        const char *BufPtr = NULL;
-       StrBuf *Line = NewStrBuf();
-       StrBuf *Line1 = NewStrBuf();
-       StrBuf *Line2 = NewStrBuf();
+       StrBuf *Line = NewStrBufPlain(NULL, SIZ);
+       StrBuf *Line1 = NewStrBufPlain(NULL, SIZ);
+       StrBuf *Line2 = NewStrBufPlain(NULL, SIZ);
        int bn = 0;
        int bq = 0;
-       int i, n, done = 0;
+       int i;
        long len;
        int intext = 0;
 
        StrBufAppendPrintf(Target, "<div class=\"fmout-%s\">\n", align);
-       while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
-       {
-               done = n == 0;
-               bq = 0;
-               i = 0;
-               ptr = ChrPtr(Line);
-               len = StrLength(Line);
-               pte = ptr + len;
-
-               if ((intext == 1) && (isspace(*ptr))) {
-                       StrBufAppendBufPlain(Target, HKEY("<br>"), 0);
-               }
-               intext = 1;
-               if (isspace(*ptr)) while ((ptr < pte) &&
-                      ((*ptr == '>') ||
-                       isspace(*ptr)))
+
+       if (StrLength(Source) > 0) 
+               do 
                {
-                       if (*ptr == '>')
-                               bq++;
-                       ptr ++;
-                       i++;
-               }
+                       StrBufSipLine(Line, Source, &BufPtr);
+                       bq = 0;
+                       i = 0;
+                       ptr = ChrPtr(Line);
+                       len = StrLength(Line);
+                       pte = ptr + len;
 
-               /**
-                * Quoted text should be displayed in italics and in a
-                * different colour.  This code understands Citadel-style
-                * " >" quotes and will convert to <BLOCKQUOTE> tags.
-                */
-               if (i > 0) StrBufCutLeft(Line, i);
+                       if ((intext == 1) && (isspace(*ptr))) {
+                               StrBufAppendBufPlain(Target, HKEY("<br>"), 0);
+                       }
+                       intext = 1;
+                       if (isspace(*ptr)) while ((ptr < pte) &&
+                                                 ((*ptr == '>') ||
+                                                  isspace(*ptr)))
+                                          {
+                                                  if (*ptr == '>')
+                                                          bq++;
+                                                  ptr ++;
+                                                  i++;
+                                          }
+
+                       /**
+                        * Quoted text should be displayed in italics and in a
+                        * different colour.  This code understands Citadel-style
+                        * " >" quotes and will convert to <BLOCKQUOTE> tags.
+                        */
+                       if (i > 0) StrBufCutLeft(Line, i);
                
 
-               for (i = bn; i < bq; i++)                               
-                       StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
-               for (i = bq; i < bn; i++)                               
-                       StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
-               bn = bq;
+                       for (i = bn; i < bq; i++)                               
+                               StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
+                       for (i = bq; i < bn; i++)                               
+                               StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
+                       bn = bq;
 
-               if (StrLength(Line) == 0)
-                       continue;
-               /** Activate embedded URL's */
-               UrlizeText(Line1, Line, Line2);
+                       if (StrLength(Line) == 0)
+                               continue;
+                       /** Activate embedded URL's */
+                       UrlizeText(Line1, Line, Line2);
 
-               StrEscAppend(Target, Line1, NULL, 0, 0);
+                       StrEscAppend(Target, Line1, NULL, 0, 0);
+
+                       StrBufAppendBufPlain(Target, HKEY("\n"), 0);
+               }
+               while ((BufPtr != StrBufNOTNULL) &&
+                      (BufPtr != NULL));
 
-               StrBufAppendBufPlain(Target, HKEY("\n"), 0);
-       }
        for (i = 0; i < bn; i++)                                
                StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
        StrBufAppendBufPlain(Target, HKEY("</div><br>\n"), 0);
@@ -665,6 +684,15 @@ int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
                return 0;
        return WCC->serv_info->serv_supports_openid != 0;
 }
+int conditional_serv_fulltext_enabled(StrBuf *Target, WCTemplputParams *TP)
+{
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return 0;
+       return WCC->serv_info->serv_fulltext_enabled != 0;
+}
+
+
 
 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
 {
@@ -709,6 +737,52 @@ void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
        FreeStrBuf(&Line);
 }
 
+
+void RegisterEmbeddableMimeType(const char *MimeType, long MTLen, int Priority)
+{
+       StrBuf *MT;
+       printf("%s - %ld\n", MimeType, Priority);
+       MT = NewStrBufPlain(MimeType, MTLen);
+       Put(EmbeddableMimes, IKEY(Priority), MT, HFreeStrBuf);
+}
+
+void CreateMimeStr(void)
+{
+       HashPos  *it;
+       void *vMime;
+       long len = 0;
+       const char *Key;
+
+       it = GetNewHashPos(EmbeddableMimes, 0);
+       while (GetNextHashPos(EmbeddableMimes, it, &len, &Key, &vMime) &&
+               (vMime != NULL)) {
+               printf("%s - \n", ChrPtr((StrBuf*) vMime));
+               if (StrLength(EmbeddableMimeStrs) > 0)
+                       StrBufAppendBufPlain(EmbeddableMimeStrs, HKEY("|"), 0);
+               else 
+                       StrBufAppendBufPlain(EmbeddableMimeStrs, HKEY("MSGP "), 0);
+               StrBufAppendBuf(EmbeddableMimeStrs, (StrBuf*) vMime, 0);
+       }
+       printf("------%ld-------------%s------%s------------\n", len, ChrPtr(EmbeddableMimeStrs), ChrPtr((StrBuf*) vMime));
+}
+
+void
+ServerStartModule_SERV_FUNC
+(void)
+{
+       EmbeddableMimes = NewHash(1, Flathash);
+       EmbeddableMimeStrs = NewStrBuf();
+}
+
+
+void
+ServerShutdownModule_SERV_FUNC
+(void)
+{
+       FreeStrBuf(&EmbeddableMimeStrs);
+       DeleteHash(&EmbeddableMimes);
+}
+
 void 
 InitModule_SERVFUNC
 (void)
@@ -719,6 +793,7 @@ InitModule_SERVFUNC
 
        RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
        RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
+       RegisterConditional(HKEY("COND:SERV:HAVEFULLTEXT"), 2, conditional_serv_fulltext_enabled, CTX_NONE);
        RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
        RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, CTX_NONE);
        RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, CTX_NONE);