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