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