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