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