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