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