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