Removed logging subsystem from webcit. It's all syslog now.
[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                 syslog(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                 syslog(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                 syslog(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                 FreeStrBuf(&WCC->ReadBuf);
171                 return 1;
172         }
173         else {
174                 long Status;
175                 int short_status;
176                 Buf = NewStrBuf();
177                 WCC->connected = 1;
178                 StrBuf_ServGetln(Buf);  /* get the server greeting */
179                 short_status = GetServerStatus(Buf, &Status);
180                 FreeStrBuf(&Buf);
181
182                 /* Server isn't ready for us? */
183                 if (short_status != 2) {
184                         if (Status == 571) {
185                                 hprintf("HTTP/1.1 503 Service Unavailable\r\n");
186                                 hprintf("Content-type: text/plain; charset=utf-8\r\n");
187                                 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."));
188                         }
189                         else {
190                                 wc_printf("%ld %s\n",
191                                         Status,
192                                         _("Received unexpected answer from Citadel server; bailing out.")
193                                 );
194                                 hprintf("HTTP/1.1 502 Bad Gateway\r\n");
195                                 hprintf("Content-type: text/plain; charset=utf-8\r\n");
196                         }
197                         end_burst();
198                         end_webcit_session();
199                         return 1;
200                 }
201
202                 /* 2010jun03: every now and then the connection to Citadel dies before this point.  why? */
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 502 Bad Gateway\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 int conditional_serv_ldap_enabled(StrBuf *Target, WCTemplputParams *TP)
665 {
666         wcsession *WCC = WC;
667         if (WCC->serv_info == NULL)
668                 return 0;
669         return WCC->serv_info->serv_supports_ldap != 0;
670 }
671
672 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
673 {
674         wcsession *WCC = WC;
675         if (WCC->serv_info == NULL)
676                 return;
677         StrBufAppendTemplate(Target, TP, WC->serv_info->serv_bbs_city, 0);
678 }
679
680 void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
681 {
682         int n = 0;
683         int Done = 0;
684         StrBuf *Line;
685         StrBuf *Buf;
686
687         Buf = NewStrBuf();
688         Line = NewStrBuf();
689         serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
690
691         StrBuf_ServGetln(Line);
692         if (GetServerStatus(Line, NULL) == 1) {
693                 while (!Done &&  (StrBuf_ServGetln(Line)>=0)) {
694                         if ( (StrLength(Line)==3) && 
695                              !strcmp(ChrPtr(Line), "000")) 
696                                 Done = 1;
697                         else
698                         {
699                                 if (n > 0)
700                                         StrBufAppendBufPlain(Buf, "\n", 1, 0);
701                                 StrBufAppendBuf(Buf, Line, 0);
702                         }
703                         n++;
704                 }
705         
706                 FlushStrBuf(Line);
707                 FmOut(Line, "center", Buf);
708                 StrBufAppendTemplate(Target, TP, Line, 1);
709         }
710         FreeStrBuf(&Buf);
711         FreeStrBuf(&Line);
712 }
713
714
715 void RegisterEmbeddableMimeType(const char *MimeType, long MTLen, int Priority)
716 {
717         StrBuf *MT;
718         MT = NewStrBufPlain(MimeType, MTLen);
719         Put(EmbeddableMimes, IKEY(Priority), MT, HFreeStrBuf);
720 }
721
722 void CreateMimeStr(void)
723 {
724         HashPos  *it;
725         void *vMime;
726         long len = 0;
727         const char *Key;
728
729         it = GetNewHashPos(EmbeddableMimes, 0);
730         while (GetNextHashPos(EmbeddableMimes, it, &len, &Key, &vMime) &&
731                (vMime != NULL)) {
732                 if (StrLength(EmbeddableMimeStrs) > 0)
733                         StrBufAppendBufPlain(EmbeddableMimeStrs, HKEY("|"), 0);
734                 else 
735                         StrBufAppendBufPlain(EmbeddableMimeStrs, HKEY("MSGP "), 0);
736                 StrBufAppendBuf(EmbeddableMimeStrs, (StrBuf*) vMime, 0);
737         }
738         DeleteHashPos(&it);
739 }
740
741 void
742 ServerStartModule_SERV_FUNC
743 (void)
744 {
745         EmbeddableMimes = NewHash(1, Flathash);
746         EmbeddableMimeStrs = NewStrBuf();
747 }
748
749
750 void
751 ServerShutdownModule_SERV_FUNC
752 (void)
753 {
754         FreeStrBuf(&EmbeddableMimeStrs);
755         DeleteHash(&EmbeddableMimes);
756 }
757
758 void 
759 InitModule_SERVFUNC
760 (void)
761 {
762         is_uds = strcasecmp(ctdlhost, "uds") == 0;
763         if (is_uds)
764                 snprintf(serv_sock_name, PATH_MAX, "%s/citadel.socket", ctdlport);
765
766         RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
767         RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
768         RegisterConditional(HKEY("COND:SERV:FULLTEXT_ENABLED"), 2, conditional_serv_fulltext_enabled, CTX_NONE);
769         RegisterConditional(HKEY("COND:SERV:LDAP_ENABLED"), 2, conditional_serv_ldap_enabled, CTX_NONE);
770         RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, NULL, CTX_NONE);
771         RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, NULL, CTX_NONE);
772         RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, NULL, CTX_NONE);
773         RegisterNamespace("SERV:FQDN", 0, 1, tmplput_serv_fqdn, NULL, CTX_NONE);
774         RegisterNamespace("SERV:SOFTWARE", 0, 1, tmplput_serv_software, NULL, CTX_NONE);
775         RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, NULL, CTX_NONE);
776         RegisterNamespace("SERV:BBS_CITY", 0, 1, tmplput_serv_bbs_city, NULL, CTX_NONE);
777         RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, NULL, CTX_NONE);
778 }
779
780
781
782 void 
783 SessionDestroyModule_SERVFUNC
784 (wcsession *sess)
785 {
786         DeleteServInfo(&sess->serv_info);
787 }