9 void DeleteServInfo(ServInfo **FreeMe)
13 FreeStrBuf(&(*FreeMe)->serv_nodename);
14 FreeStrBuf(&(*FreeMe)->serv_humannode);
15 FreeStrBuf(&(*FreeMe)->serv_fqdn);
16 FreeStrBuf(&(*FreeMe)->serv_software);
17 FreeStrBuf(&(*FreeMe)->serv_bbs_city);
18 FreeStrBuf(&(*FreeMe)->serv_sysadm);
19 FreeStrBuf(&(*FreeMe)->serv_moreprompt);
20 FreeStrBuf(&(*FreeMe)->serv_default_cal_zone);
21 FreeStrBuf(&(*FreeMe)->serv_svn_revision);
27 * get info about the server we've connected to
29 * browser_host the citadell we want to connect to
30 * user_agent which browser uses our client?
32 ServInfo *get_serv_info(StrBuf *browser_host, char *user_agent)
39 /** Tell the server what kind of client is connecting */
40 serv_printf("IDEN %d|%d|%d|%s|%s",
47 StrBuf_ServGetln(Buf);
49 /** Tell the server what kind of richtext we prefer */
50 serv_puts("MSGP text/calendar|text/html|text/plain");
51 StrBuf_ServGetln(Buf);
54 * Tell the server that when we save a calendar event, we
55 * want invitations to be generated by the Citadel server
56 * instead of by the client.
58 serv_puts("ICAL sgi|1");
59 StrBuf_ServGetln(Buf);
61 /** Now ask the server to tell us a little bit about itself... */
63 StrBuf_ServGetln(Buf);
64 if (GetServerStatus(Buf, NULL) != 1) {
69 info = (ServInfo*)malloc(sizeof(ServInfo));
70 memset(info, 0, sizeof(ServInfo));
72 while (StrBuf_ServGetln(Buf), (strcmp(ChrPtr(Buf), "000")!= 0)) {
73 /* lprintf (1, "a: %d [%s]", a, ChrPtr(Buf));*/
76 info->serv_pid = StrToi(Buf);
77 WC->ctdl_pid = info->serv_pid;
80 info->serv_nodename = NewStrBufDup(Buf);
83 info->serv_humannode = NewStrBufDup(Buf);
86 info->serv_fqdn = NewStrBufDup(Buf);
89 info->serv_software = NewStrBufDup(Buf);
92 info->serv_rev_level = StrToi(Buf);
95 info->serv_bbs_city = NewStrBufDup(Buf);
98 info->serv_sysadm = NewStrBufDup(Buf);
101 info->serv_moreprompt = NewStrBufDup(Buf);
104 info->serv_supports_ldap = StrToi(Buf);
107 info->serv_newuser_disabled = StrToi(Buf);
110 info->serv_default_cal_zone = NewStrBufDup(Buf);
113 info->serv_supports_sieve = StrToi(Buf);
116 info->serv_fulltext_enabled = StrToi(Buf);
119 info->serv_svn_revision = NewStrBufDup(Buf);
122 info->serv_supports_openid = StrToi(Buf);
134 * Read Citadel variformat text and spit it out as HTML.
135 * align html align string
137 inline void fmout(char *align)
139 _fmout(WC->WBuf, align);
142 void _fmout(StrBuf *Target, char *align)
148 StrBufAppendPrintf(Target, "<div align=%s>\n", align);
149 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
151 if ((intext == 1) && (isspace(buf[0]))) {
157 * Quoted text should be displayed in italics and in a
158 * different colour. This code understands Citadel-style
159 * " >" quotes and will convert to <BLOCKQUOTE> tags.
161 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
162 StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
164 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
165 StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
168 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
169 strcpy(buf, &buf[2]);
171 /** Activate embedded URL's */
172 url(buf, sizeof(buf));
175 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
180 wprintf("</div><br />\n");
183 void FmOut(StrBuf *Target, char *align, StrBuf *Source)
185 const char *ptr, *pte;
186 const char *BufPtr = NULL;
187 StrBuf *Line = NewStrBuf();
188 StrBuf *Line1 = NewStrBuf();
189 StrBuf *Line2 = NewStrBuf();
196 StrBufAppendPrintf(Target, "<div class=\"fmout-%s\">\n", align);
197 while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
203 len = StrLength(Line);
206 if ((intext == 1) && (isspace(*ptr))) {
207 StrBufAppendBufPlain(Target, HKEY("<br>"), 0);
210 if (isspace(*ptr)) while ((ptr < pte) &&
221 * Quoted text should be displayed in italics and in a
222 * different colour. This code understands Citadel-style
223 * " >" quotes and will convert to <BLOCKQUOTE> tags.
225 if (i > 0) StrBufCutLeft(Line, i);
228 for (i = bn; i < bq; i++)
229 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
230 for (i = bq; i < bn; i++)
231 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
234 if (StrLength(Line) == 0)
236 /** Activate embedded URL's */
237 UrlizeText(Line1, Line, Line2);
239 StrEscAppend(Target, Line1, NULL, 0, 0);
241 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
243 for (i = 0; i < bn; i++)
244 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
245 StrBufAppendBufPlain(Target, HKEY("</div><br>\n"), 0);
255 * Read Citadel variformat text and spit it out as HTML in a form
256 * suitable for embedding in another message (forward/quote).
257 * (NO LINEBREAKS ALLOWED HERE!)
259 void pullquote_fmout(void) {
264 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
266 if ((intext == 1) && (isspace(buf[0]))) {
272 * Quoted text should be displayed in italics and in a
273 * different colour. This code understands Citadel-style
274 * " >" quotes and will convert to <BLOCKQUOTE> tags.
276 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
277 wprintf("<BLOCKQUOTE>");
279 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
280 wprintf("</BLOCKQUOTE>");
283 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
284 strcpy(buf, &buf[2]);
298 * Transmit message text (in memory) to the server.
300 * ptr Pointer to the message being transmitted
302 void text_to_server(char *ptr)
310 while (ptr[pos] != 0) {
314 while ( (isspace(buf[len - 1]))
316 && (buf[1] != '\0') )
320 if (ptr[pos] != 0) strcat(buf, " ");
325 if ((ch == 32) && (strlen(buf) > 200)) {
330 if (strlen(buf) > 250) {
341 * Transmit message text (in memory) to the server,
342 * converting to Quoted-Printable encoding as we go.
344 * ptr Pointer to the message being transmitted
346 void text_to_server_qp(char *ptr)
348 unsigned char ch, buf[256];
356 while (ptr[pos] != 0) {
357 ch = (unsigned char)(ptr[pos++]);
360 /* ignore carriage returns */
363 /* hard line break */
364 if (output_len > 0) {
365 if (isspace(buf[output_len-1])) {
366 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
370 buf[output_len++] = 0;
371 serv_puts((char *)buf);
375 buf[output_len++] = ch;
377 else if ( (ch >= 32) && (ch <= 60) ) {
378 buf[output_len++] = ch;
380 else if ( (ch >= 62) && (ch <= 126) ) {
381 buf[output_len++] = ch;
384 sprintf((char *)&buf[output_len], "=%02X", ch);
388 if (output_len > 72) {
389 /* soft line break */
390 if (isspace(buf[output_len-1])) {
391 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
394 buf[output_len++] = '=';
395 buf[output_len++] = 0;
396 serv_puts((char *)buf);
401 /* end of data - transmit anything that's left */
402 if (output_len > 0) {
403 if (isspace(buf[output_len-1])) {
404 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
407 buf[output_len++] = 0;
408 serv_puts((char *)buf);
417 * translate server message output to text
418 * (used for editing room info files and such)
420 void server_to_text()
426 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
427 if ((buf[0] == 32) && (count > 0)) {
438 * Read binary data from server into memory using a series of
439 * server READ commands.
440 * \return the read content as StrBuf
442 int read_server_binary(StrBuf *Ret, size_t total_len, StrBuf *Buf)
446 size_t thisblock = 0;
451 while (bytes < total_len) {
453 if ((total_len - bytes) < thisblock) {
454 thisblock = total_len - bytes;
455 if (thisblock == 0) {
461 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
462 if (StrBuf_ServGetln(Buf) > 0)
464 if (GetServerStatus(Buf, NULL) == 6)
466 StrBufCutLeft(Buf, 4);
467 thisblock = StrTol(Buf);
468 if (!WC->connected) {
473 StrBuf_ServGetBLOBBuffered(Ret, thisblock);
478 lprintf(3, "Error: %s\n", &buf[4]);
483 return StrLength(Ret);
488 * Read text from server, appending to a string buffer until the
489 * usual 000 terminator is found. Caller is responsible for freeing
490 * the returned pointer.
492 int read_server_text(StrBuf *Buf, long *nLines)
500 while ((WCC->serv_sock!=-1) &&
501 (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
503 if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
504 StrBufCutRight(Buf, nRead);
520 int GetServerStatus(StrBuf *Line, long* FullState)
522 if (FullState != NULL)
523 *FullState = StrTol(Line);
524 return ChrPtr(Line)[0] - 48;
528 void tmplput_serv_ip(StrBuf *Target, WCTemplputParams *TP)
530 StrBufAppendPrintf(Target, "%d", WC->ctdl_pid);
533 void tmplput_serv_nodename(StrBuf *Target, WCTemplputParams *TP)
536 if (WCC->serv_info == NULL)
538 StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_nodename, 0);
541 void tmplput_serv_humannode(StrBuf *Target, WCTemplputParams *TP)
544 if (WCC->serv_info == NULL)
546 StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_humannode, 0);
549 void tmplput_serv_fqdn(StrBuf *Target, WCTemplputParams *TP)
552 if (WCC->serv_info == NULL)
554 StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_fqdn, 0);
557 void tmplput_serv_software(StrBuf *Target, WCTemplputParams *TP)
560 if (WCC->serv_info == NULL)
562 StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_software, 0);
565 void tmplput_serv_rev_level(StrBuf *Target, WCTemplputParams *TP)
568 if (WCC->serv_info == NULL)
570 StrBufAppendPrintf(Target, "%d.%02d",
571 WCC->serv_info->serv_rev_level / 100,
572 WCC->serv_info->serv_rev_level % 100);
574 int conditional_serv_newuser_disabled(StrBuf *Target, WCTemplputParams *TP)
577 if (WCC->serv_info == NULL)
579 return WCC->serv_info->serv_newuser_disabled != 0;
581 int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
584 if (WCC->serv_info == NULL)
586 return WCC->serv_info->serv_supports_openid != 0;
589 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
592 if (WCC->serv_info == NULL)
594 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_bbs_city, 0);
598 void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
607 serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
609 StrBuf_ServGetln(Line);
610 if (GetServerStatus(Line, NULL) == 1) {
611 while (!Done && (StrBuf_ServGetln(Line)>=0)) {
612 if ( (StrLength(Line)==3) &&
613 !strcmp(ChrPtr(Line), "000"))
618 StrBufAppendBufPlain(Buf, "\n", 1, 0);
619 StrBufAppendBuf(Buf, Line, 0);
625 FmOut(Line, "center", Buf);
626 StrBufAppendTemplate(Target, TP, Line, 1);
637 RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
638 RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
639 RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
640 RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, CTX_NONE);
641 RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, CTX_NONE);
642 RegisterNamespace("SERV:FQDN", 0, 1, tmplput_serv_fqdn, CTX_NONE);
643 RegisterNamespace("SERV:SOFTWARE", 0, 1, tmplput_serv_software, CTX_NONE);
644 RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
645 RegisterNamespace("SERV:BBS_CITY", 0, 1, tmplput_serv_bbs_city, CTX_NONE);
646 RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
647 /*TODO // RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0); */
653 SessionDestroyModule_SERVFUNC
656 DeleteServInfo(&sess->serv_info);