if StrBuf_ServGetln() is called in a loop, its return value has to be checked for...
[citadel.git] / webcit / serv_func.c
1 /*
2  * $Id$
3  */
4
5 #include "webcit.h"
6 #include "webserver.h"
7
8 int is_uds = 0;
9 char serv_sock_name[PATH_MAX] = "";
10
11 HashList *EmbeddableMimes = NULL;
12 StrBuf *EmbeddableMimeStrs = NULL;
13
14
15 void SetInlinMimeRenderers(void)
16 {
17         StrBuf *Buf;
18
19         Buf = NewStrBuf();
20
21         /* Tell the server what kind of richtext we prefer */
22         serv_putbuf(EmbeddableMimeStrs);
23         StrBuf_ServGetln(Buf);
24
25         FreeStrBuf(&Buf);
26 }
27
28
29 void DeleteServInfo(ServInfo **FreeMe)
30 {
31         if (*FreeMe == NULL)
32                 return;
33         FreeStrBuf(&(*FreeMe)->serv_nodename);
34         FreeStrBuf(&(*FreeMe)->serv_humannode);
35         FreeStrBuf(&(*FreeMe)->serv_fqdn);
36         FreeStrBuf(&(*FreeMe)->serv_software);
37         FreeStrBuf(&(*FreeMe)->serv_bbs_city);
38         FreeStrBuf(&(*FreeMe)->serv_sysadm);
39         FreeStrBuf(&(*FreeMe)->serv_moreprompt);
40         FreeStrBuf(&(*FreeMe)->serv_default_cal_zone);
41         FreeStrBuf(&(*FreeMe)->serv_svn_revision);
42         free(*FreeMe);
43         *FreeMe = NULL;
44 }
45
46 /*
47  * get info about the server we've connected to
48  *
49  * browser_host         the citadel we want to connect to
50  * user_agent           which browser uses our client?
51  */
52 ServInfo *get_serv_info(StrBuf *browser_host, StrBuf *user_agent)
53 {
54         ServInfo *info;
55         StrBuf *Buf;
56         int a;
57         int rc;
58
59         Buf = NewStrBuf();
60
61         /* Tell the server what kind of client is connecting */
62         serv_printf("IDEN %d|%d|%d|%s|%s",
63                     DEVELOPER_ID,
64                     CLIENT_ID,
65                     CLIENT_VERSION,
66                     ChrPtr(user_agent),
67                     ChrPtr(browser_host)
68         );
69         StrBuf_ServGetln(Buf);
70         if (GetServerStatus(Buf, NULL) != 2) {
71                 lprintf(0, "get_serv_info(IDEN): unexpected answer [%s]\n",
72                         ChrPtr(Buf));
73                 FreeStrBuf(&Buf);
74                 return NULL;
75         }
76
77         /*
78          * Tell the server that when we save a calendar event, we
79          * want invitations to be generated by the Citadel server
80          * instead of by the client.
81          */
82         serv_puts("ICAL sgi|1");
83         StrBuf_ServGetln(Buf);
84         if (GetServerStatus(Buf, NULL) != 2) {
85                 lprintf(0, "get_serv_info(ICAL sgi|1): unexpected answer [%s]\n",
86                         ChrPtr(Buf));
87                 FreeStrBuf(&Buf);
88                 return NULL;
89         }
90
91         /* Now ask the server to tell us a little bit about itself... */
92         serv_puts("INFO");
93         StrBuf_ServGetln(Buf);
94         if (GetServerStatus(Buf, NULL) != 1) {
95                 lprintf(0, "get_serv_info(INFO sgi|1): unexpected answer [%s]\n",
96                         ChrPtr(Buf));
97                 FreeStrBuf(&Buf);
98                 return NULL;
99         }
100
101         info = (ServInfo*)malloc(sizeof(ServInfo));
102         memset(info, 0, sizeof(ServInfo));
103         a = 0;
104         while (rc = StrBuf_ServGetln(Buf),
105                (rc >= 0) &&
106                ((rc != 3) || 
107                 strcmp(ChrPtr(Buf), "000")))
108         {
109                 switch (a) {
110                 case 0:
111                         info->serv_pid = StrToi(Buf);
112                         WC->ctdl_pid = info->serv_pid;
113                         break;
114                 case 1:
115                         info->serv_nodename = NewStrBufDup(Buf);
116                         break;
117                 case 2:
118                         info->serv_humannode = NewStrBufDup(Buf);
119                         break;
120                 case 3:
121                         info->serv_fqdn = NewStrBufDup(Buf);
122                         break;
123                 case 4:
124                         info->serv_software = NewStrBufDup(Buf);
125                         break;
126                 case 5:
127                         info->serv_rev_level = StrToi(Buf);
128                         break;
129                 case 6:
130                         info->serv_bbs_city = NewStrBufDup(Buf);
131                         break;
132                 case 7:
133                         info->serv_sysadm = NewStrBufDup(Buf);
134                         break;
135                 case 9:
136                         info->serv_moreprompt = NewStrBufDup(Buf);
137                         break;
138                 case 14:
139                         info->serv_supports_ldap = StrToi(Buf);
140                         break;
141                 case 15:
142                         info->serv_newuser_disabled = StrToi(Buf);
143                         break;
144                 case 16:
145                         info->serv_default_cal_zone = NewStrBufDup(Buf);
146                         break;
147                 case 20:
148                         info->serv_supports_sieve = StrToi(Buf);
149                         break;
150                 case 21:
151                         info->serv_fulltext_enabled = StrToi(Buf);
152                         break;
153                 case 22:
154                         info->serv_svn_revision = NewStrBufDup(Buf);
155                         break;
156                 case 23:
157                         info->serv_supports_openid = StrToi(Buf);
158                         break;
159                 }
160                 ++a;
161         }
162         FreeStrBuf(&Buf);
163         return info;
164 }
165
166 int GetConnected (void)
167 {
168         StrBuf *Buf;
169         wcsession *WCC = WC;
170
171         if (WCC->ReadBuf == NULL)
172                 WCC->ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
173         if (is_uds) /* unix domain socket */
174                 WCC->serv_sock = uds_connectsock(serv_sock_name);
175         else        /* tcp socket */
176                 WCC->serv_sock = tcp_connectsock(ctdlhost, atoi(ctdlport));
177         
178         if (WCC->serv_sock < 0) {
179                 do_logout();
180                 FreeStrBuf(&WCC->ReadBuf);
181                 return 1;
182         }
183         else {
184                 long Status;
185                 int short_status;
186                 Buf = NewStrBuf();
187                 WCC->connected = 1;
188                 StrBuf_ServGetln(Buf);  /* get the server greeting */
189                 short_status = GetServerStatus(Buf, &Status);
190                 FreeStrBuf(&Buf);
191
192                 /* Server isn't ready for us? */
193                 if (short_status != 2) {
194                         if (Status == 571) {
195                                 wc_printf(_("This server is already serving its maximum number of users and cannot accept any additional logins at this time.  Please try again later or contact your system administrator."));
196                         }
197                         else {
198                                 wc_printf("%ld %s\n",
199                                         Status,
200                                         _("Received unexpected answer from Citadel server; bailing out.")
201                                 );
202                         }
203                         end_burst();
204                         end_webcit_session();
205                         return 1;
206                 }
207
208                 /* 2010jun03: every now and then the connection to Citadel dies before this point.  why? */
209
210                 /*
211                  * From what host is our user connecting?  Go with
212                  * the host at the other end of the HTTP socket,
213                  * unless we are following X-Forwarded-For: headers
214                  * and such a header has already turned up something.
215                  */
216                 if ( (!follow_xff) || (StrLength(WCC->Hdr->HR.browser_host) == 0) ) {
217                         if (WCC->Hdr->HR.browser_host == NULL) {
218                                 WCC->Hdr->HR.browser_host = NewStrBuf();
219                                 Put(WCC->Hdr->HTTPHeaders, HKEY("FreeMeWithTheOtherHeaders"), 
220                                     WCC->Hdr->HR.browser_host, HFreeStrBuf);
221                         }
222                         locate_host(WCC->Hdr->HR.browser_host, WCC->Hdr->http_sock);
223                 }
224                 if (WCC->serv_info == NULL) {
225                         WCC->serv_info = get_serv_info(WCC->Hdr->HR.browser_host, WCC->Hdr->HR.user_agent);
226                 }
227                 if (WCC->serv_info == NULL){
228                         begin_burst();
229                         wc_printf(_("Received unexpected answer from Citadel server; bailing out."));
230                         hprintf("HTTP/1.1 200 OK\r\n");
231                         hprintf("Content-type: text/plain; charset=utf-8\r\n");
232                         end_burst();
233                         end_webcit_session();
234                         return 1;
235                 }
236                 if (WCC->serv_info->serv_rev_level < MINIMUM_CIT_VERSION) {
237                         begin_burst();
238                         wc_printf(_("You are connected to a Citadel "
239                                   "server running Citadel %d.%02d. \n"
240                                   "In order to run this version of WebCit "
241                                   "you must also have Citadel %d.%02d or"
242                                   " newer.\n\n\n"),
243                                 WCC->serv_info->serv_rev_level / 100,
244                                 WCC->serv_info->serv_rev_level % 100,
245                                 MINIMUM_CIT_VERSION / 100,
246                                 MINIMUM_CIT_VERSION % 100
247                                 );
248                         hprintf("HTTP/1.1 200 OK\r\n");
249                         hprintf("Content-type: text/plain; charset=utf-8\r\n");
250                         end_burst();
251                         end_webcit_session();
252                         return 1;
253                 }
254                 SetInlinMimeRenderers();
255         }
256         return 0;
257 }
258
259 /*
260  *  Read Citadel variformat text and spit it out as HTML.
261  *  align html align string
262  */
263 inline void fmout(char *align)
264 {
265         _fmout(WC->WBuf, align);
266 }
267
268 void _fmout(StrBuf *Target, char *align)
269 {
270         int intext = 0;
271         int bq = 0;
272         char buf[SIZ];
273
274         StrBufAppendPrintf(Target, "<div align=%s>\n", align);
275         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
276
277                 if ((intext == 1) && (isspace(buf[0]))) {
278                         wc_printf("<br />");
279                 }
280                 intext = 1;
281
282                 /*
283                  * Quoted text should be displayed in italics and in a
284                  * different colour.  This code understands Citadel-style
285                  * " >" quotes and will convert to <BLOCKQUOTE> tags.
286                  */
287                 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
288                         StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
289                         bq = 1;
290                 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
291                         StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
292                         bq = 0;
293                 }
294                 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
295                         strcpy(buf, &buf[2]);
296                 }
297                 /* Activate embedded URL's */
298                 url(buf, sizeof(buf));
299
300                 escputs(buf);
301                 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
302         }
303         if (bq == 1) {
304                 wc_printf("</I>");
305         }
306         wc_printf("</div><br />\n");
307 }
308
309 void FmOut(StrBuf *Target, char *align, StrBuf *Source)
310 {
311         const char *ptr, *pte;
312         const char *BufPtr = NULL;
313         StrBuf *Line = NewStrBufPlain(NULL, SIZ);
314         StrBuf *Line1 = NewStrBufPlain(NULL, SIZ);
315         StrBuf *Line2 = NewStrBufPlain(NULL, SIZ);
316         int bn = 0;
317         int bq = 0;
318         int i;
319         long len;
320         int intext = 0;
321
322         StrBufAppendPrintf(Target, "<div class=\"fmout-%s\">\n", align);
323
324         if (StrLength(Source) > 0) 
325                 do 
326                 {
327                         StrBufSipLine(Line, Source, &BufPtr);
328                         bq = 0;
329                         i = 0;
330                         ptr = ChrPtr(Line);
331                         len = StrLength(Line);
332                         pte = ptr + len;
333
334                         if ((intext == 1) && (isspace(*ptr))) {
335                                 StrBufAppendBufPlain(Target, HKEY("<br>"), 0);
336                         }
337                         intext = 1;
338                         if (isspace(*ptr)) while ((ptr < pte) &&
339                                                   ((*ptr == '>') ||
340                                                    isspace(*ptr)))
341                                            {
342                                                    if (*ptr == '>')
343                                                            bq++;
344                                                    ptr ++;
345                                                    i++;
346                                            }
347
348                         /*
349                          * Quoted text should be displayed in italics and in a
350                          * different colour.  This code understands Citadel-style
351                          * " >" quotes and will convert to <BLOCKQUOTE> tags.
352                          */
353                         if (i > 0) StrBufCutLeft(Line, i);
354                 
355
356                         for (i = bn; i < bq; i++)                               
357                                 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
358                         for (i = bq; i < bn; i++)                               
359                                 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
360                         bn = bq;
361
362                         if (StrLength(Line) == 0)
363                                 continue;
364
365                         /* Activate embedded URL's */
366                         UrlizeText(Line1, Line, Line2);
367
368                         StrEscAppend(Target, Line1, NULL, 0, 0);
369
370                         StrBufAppendBufPlain(Target, HKEY("\n"), 0);
371                 }
372                 while ((BufPtr != StrBufNOTNULL) &&
373                        (BufPtr != NULL));
374
375         for (i = 0; i < bn; i++) {
376                 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
377         }
378         StrBufAppendBufPlain(Target, HKEY("</div><br>\n"), 0);
379         FreeStrBuf(&Line);
380         FreeStrBuf(&Line1);
381         FreeStrBuf(&Line2);
382 }
383
384
385 /*
386  * Read Citadel variformat text and spit it out as HTML in a form
387  * suitable for embedding in another message (forward/quote).
388  * (NO LINEBREAKS ALLOWED HERE!)
389  */
390 void pullquote_fmout(void) {
391         int intext = 0;
392         int bq = 0;
393         char buf[SIZ];
394
395         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
396
397                 if ((intext == 1) && (isspace(buf[0]))) {
398                         wc_printf("<br />");
399                 }
400                 intext = 1;
401
402                 /*
403                  * Quoted text should be displayed in italics and in a
404                  * different colour.  This code understands Citadel-style
405                  * " >" quotes and will convert to <BLOCKQUOTE> tags.
406                  */
407                 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
408                         wc_printf("<BLOCKQUOTE>");
409                         bq = 1;
410                 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
411                         wc_printf("</BLOCKQUOTE>");
412                         bq = 0;
413                 }
414                 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
415                         strcpy(buf, &buf[2]);
416                 }
417
418                 msgescputs(buf);
419         }
420         if (bq == 1) {
421                 wc_printf("</I>");
422         }
423 }
424
425
426
427
428 /*
429  *  Transmit message text (in memory) to the server.
430  */
431 void text_to_server(char *ptr)
432 {
433         char buf[256];
434         int ch, a, pos, len;
435
436         pos = 0;
437         buf[0] = 0;
438
439         while (ptr[pos] != 0) {
440                 ch = ptr[pos++];
441                 if (ch == 10) {
442                         len = strlen(buf);
443                         while ( (isspace(buf[len - 1]))
444                                 && (buf[0] !=  '\0') 
445                                 && (buf[1] !=  '\0') )
446                                 buf[--len] = 0;
447                         serv_puts(buf);
448                         buf[0] = 0;
449                         if (ptr[pos] != 0) strcat(buf, " ");
450                 } else {
451                         a = strlen(buf);
452                         buf[a + 1] = 0;
453                         buf[a] = ch;
454                         if ((ch == 32) && (strlen(buf) > 200)) {
455                                 buf[a] = 0;
456                                 serv_puts(buf);
457                                 buf[0] = 0;
458                         }
459                         if (strlen(buf) > 250) {
460                                 serv_puts(buf);
461                                 buf[0] = 0;
462                         }
463                 }
464         }
465         serv_puts(buf);
466 }
467
468
469 /*
470  * Transmit message text (in memory) to the server, converting to Quoted-Printable encoding as we go.
471  */
472 void text_to_server_qp(char *ptr)
473 {
474         unsigned char ch, buf[256];
475         int pos;
476         int output_len = 0;
477
478         pos = 0;
479         buf[0] = 0;
480         output_len = 0;
481
482         while (ptr[pos] != 0) {
483                 ch = (unsigned char)(ptr[pos++]);
484
485                 if (ch == 13) {
486                         /* ignore carriage returns */
487                 }
488                 else if (ch == 10) {
489                         /* hard line break */
490                         if (output_len > 0) {
491                                 if (isspace(buf[output_len-1])) {
492                                         sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
493                                         output_len += 2;
494                                 }
495                         }
496                         buf[output_len++] = 0;
497                         serv_puts((char *)buf);
498                         output_len = 0;
499                 }
500                 else if (ch == 9) {
501                         buf[output_len++] = ch;
502                 }
503                 else if ( (ch >= 32) && (ch <= 60) ) {
504                         buf[output_len++] = ch;
505                 }
506                 else if ( (ch >= 62) && (ch <= 126) ) {
507                         buf[output_len++] = ch;
508                 }
509                 else {
510                         sprintf((char *)&buf[output_len], "=%02X", ch);
511                         output_len += 3;
512                 }
513                 
514                 if (output_len > 72) {
515                         /* soft line break */
516                         if (isspace(buf[output_len-1])) {
517                                 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
518                                 output_len += 2;
519                         }
520                         buf[output_len++] = '=';
521                         buf[output_len++] = 0;
522                         serv_puts((char *)buf);
523                         output_len = 0;
524                 }
525         }
526
527         /* end of data - transmit anything that's left */
528         if (output_len > 0) {
529                 if (isspace(buf[output_len-1])) {
530                         sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
531                         output_len += 2;
532                 }
533                 buf[output_len++] = 0;
534                 serv_puts((char *)buf);
535                 output_len = 0;
536         }
537 }
538
539
540
541
542 /*
543  * translate server message output to text (used for editing room info files and such)
544  */
545 void server_to_text()
546 {
547         char buf[SIZ];
548
549         int count = 0;
550
551         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
552                 if ((buf[0] == 32) && (count > 0)) {
553                         wc_printf("\n");
554                 }
555                 wc_printf("%s", buf);
556                 ++count;
557         }
558 }
559
560
561
562
563 /*
564  * Read text from server, appending to a string buffer until the
565  * usual 000 terminator is found.  Caller is responsible for freeing
566  * the returned pointer.
567  */
568 int read_server_text(StrBuf *Buf, long *nLines)
569 {
570         wcsession *WCC = WC;
571         long nRead;
572         long nTotal = 0;
573         long nlines;
574         
575         nlines = 0;
576         while ((WCC->serv_sock!=-1) &&
577                (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
578         {
579                 if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
580                         StrBufCutRight(Buf, nRead);
581                         break;
582                 }
583                 nTotal += nRead;
584                 nlines ++;
585         }
586
587         *nLines = nlines;
588         return nTotal;
589 }
590
591
592 int GetServerStatus(StrBuf *Line, long* FullState)
593 {
594         if (FullState != NULL)
595                 *FullState = StrTol(Line);
596         return ChrPtr(Line)[0] - 48;
597 }
598
599
600 void tmplput_serv_ip(StrBuf *Target, WCTemplputParams *TP)
601 {
602         StrBufAppendPrintf(Target, "%d", WC->ctdl_pid);
603 }
604
605 void tmplput_serv_nodename(StrBuf *Target, WCTemplputParams *TP)
606 {
607         wcsession *WCC = WC;
608         if (WCC->serv_info == NULL)
609                 return;
610         StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_nodename, 0);
611 }
612
613 void tmplput_serv_humannode(StrBuf *Target, WCTemplputParams *TP)
614 {
615         wcsession *WCC = WC;
616         if (WCC->serv_info == NULL)
617                 return;
618         StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_humannode, 0);
619 }
620
621 void tmplput_serv_fqdn(StrBuf *Target, WCTemplputParams *TP)
622 {
623         wcsession *WCC = WC;
624         if (WCC->serv_info == NULL)
625                 return;
626         StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_fqdn, 0);
627 }
628
629 void tmplput_serv_software(StrBuf *Target, WCTemplputParams *TP)
630 {
631         wcsession *WCC = WC;
632         if (WCC->serv_info == NULL)
633                 return;
634         StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_software, 0);
635 }
636
637 void tmplput_serv_rev_level(StrBuf *Target, WCTemplputParams *TP)
638 {
639         wcsession *WCC = WC;
640         if (WCC->serv_info == NULL)
641                 return;
642         StrBufAppendPrintf(Target, "%d.%02d",
643                             WCC->serv_info->serv_rev_level / 100,
644                             WCC->serv_info->serv_rev_level % 100);
645 }
646 int conditional_serv_newuser_disabled(StrBuf *Target, WCTemplputParams *TP)
647 {
648         wcsession *WCC = WC;
649         if (WCC->serv_info == NULL)
650                 return 0;
651         return WCC->serv_info->serv_newuser_disabled != 0;
652 }
653
654 int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
655 {
656         wcsession *WCC = WC;
657         if (WCC->serv_info == NULL)
658                 return 0;
659         return WCC->serv_info->serv_supports_openid != 0;
660 }
661
662 int conditional_serv_fulltext_enabled(StrBuf *Target, WCTemplputParams *TP)
663 {
664         wcsession *WCC = WC;
665         if (WCC->serv_info == NULL)
666                 return 0;
667         return WCC->serv_info->serv_fulltext_enabled != 0;
668 }
669
670 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
671 {
672         wcsession *WCC = WC;
673         if (WCC->serv_info == NULL)
674                 return;
675         StrBufAppendTemplate(Target, TP, WC->serv_info->serv_bbs_city, 0);
676 }
677
678 void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
679 {
680         int n = 0;
681         int Done = 0;
682         StrBuf *Line;
683         StrBuf *Buf;
684
685         Buf = NewStrBuf();
686         Line = NewStrBuf();
687         serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
688
689         StrBuf_ServGetln(Line);
690         if (GetServerStatus(Line, NULL) == 1) {
691                 while (!Done &&  (StrBuf_ServGetln(Line)>=0)) {
692                         if ( (StrLength(Line)==3) && 
693                              !strcmp(ChrPtr(Line), "000")) 
694                                 Done = 1;
695                         else
696                         {
697                                 if (n > 0)
698                                         StrBufAppendBufPlain(Buf, "\n", 1, 0);
699                                 StrBufAppendBuf(Buf, Line, 0);
700                         }
701                         n++;
702                 }
703         
704                 FlushStrBuf(Line);
705                 FmOut(Line, "center", Buf);
706                 StrBufAppendTemplate(Target, TP, Line, 1);
707         }
708         FreeStrBuf(&Buf);
709         FreeStrBuf(&Line);
710 }
711
712
713 void RegisterEmbeddableMimeType(const char *MimeType, long MTLen, int Priority)
714 {
715         StrBuf *MT;
716         MT = NewStrBufPlain(MimeType, MTLen);
717         Put(EmbeddableMimes, IKEY(Priority), MT, HFreeStrBuf);
718 }
719
720 void CreateMimeStr(void)
721 {
722         HashPos  *it;
723         void *vMime;
724         long len = 0;
725         const char *Key;
726
727         it = GetNewHashPos(EmbeddableMimes, 0);
728         while (GetNextHashPos(EmbeddableMimes, it, &len, &Key, &vMime) &&
729                (vMime != NULL)) {
730                 if (StrLength(EmbeddableMimeStrs) > 0)
731                         StrBufAppendBufPlain(EmbeddableMimeStrs, HKEY("|"), 0);
732                 else 
733                         StrBufAppendBufPlain(EmbeddableMimeStrs, HKEY("MSGP "), 0);
734                 StrBufAppendBuf(EmbeddableMimeStrs, (StrBuf*) vMime, 0);
735         }
736         DeleteHashPos(&it);
737 }
738
739 void
740 ServerStartModule_SERV_FUNC
741 (void)
742 {
743         EmbeddableMimes = NewHash(1, Flathash);
744         EmbeddableMimeStrs = NewStrBuf();
745 }
746
747
748 void
749 ServerShutdownModule_SERV_FUNC
750 (void)
751 {
752         FreeStrBuf(&EmbeddableMimeStrs);
753         DeleteHash(&EmbeddableMimes);
754 }
755
756 void 
757 InitModule_SERVFUNC
758 (void)
759 {
760         is_uds = strcasecmp(ctdlhost, "uds") == 0;
761         if (is_uds)
762                 snprintf(serv_sock_name, PATH_MAX, "%s/citadel.socket", ctdlport);
763
764         RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
765         RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
766         RegisterConditional(HKEY("COND:SERV:HAVEFULLTEXT"), 2, conditional_serv_fulltext_enabled, CTX_NONE);
767         RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, NULL, CTX_NONE);
768         RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, NULL, CTX_NONE);
769         RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, NULL, CTX_NONE);
770         RegisterNamespace("SERV:FQDN", 0, 1, tmplput_serv_fqdn, NULL, CTX_NONE);
771         RegisterNamespace("SERV:SOFTWARE", 0, 1, tmplput_serv_software, NULL, CTX_NONE);
772         RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, NULL, CTX_NONE);
773         RegisterNamespace("SERV:BBS_CITY", 0, 1, tmplput_serv_bbs_city, NULL, CTX_NONE);
774         RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, NULL, CTX_NONE);
775 }
776
777
778
779 void 
780 SessionDestroyModule_SERVFUNC
781 (wcsession *sess)
782 {
783         DeleteServInfo(&sess->serv_info);
784 }