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 serv_getln(buf, sizeof buf);
49 /** Tell the server what kind of richtext we prefer */
50 serv_puts("MSGP text/calendar|text/html|text/plain");
51 serv_getln(buf, sizeof 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 serv_getln(buf, sizeof buf);
61 /** Now ask the server to tell us a little bit about itself... */
63 serv_getln(buf, sizeof buf);
67 info = (ServInfo*)malloc(sizeof(ServInfo));
68 memset(info, 0, sizeof(ServInfo));
71 while (StrBuf_ServGetln(Buf), (strcmp(ChrPtr(Buf), "000")!= 0)) {
72 /* lprintf (1, "a: %d [%s]", a, ChrPtr(Buf));*/
75 info->serv_pid = StrToi(Buf);
76 WC->ctdl_pid = info->serv_pid;
79 info->serv_nodename = NewStrBufDup(Buf);
82 info->serv_humannode = NewStrBufDup(Buf);
85 info->serv_fqdn = NewStrBufDup(Buf);
88 info->serv_software = NewStrBufDup(Buf);
91 info->serv_rev_level = StrToi(Buf);
94 info->serv_bbs_city = NewStrBufDup(Buf);
97 info->serv_sysadm = NewStrBufDup(Buf);
100 info->serv_moreprompt = NewStrBufDup(Buf);
103 info->serv_supports_ldap = StrToi(Buf);
106 info->serv_newuser_disabled = StrToi(Buf);
109 info->serv_default_cal_zone = NewStrBufDup(Buf);
112 info->serv_supports_sieve = StrToi(Buf);
115 info->serv_fulltext_enabled = StrToi(Buf);
118 info->serv_svn_revision = NewStrBufDup(Buf);
121 info->serv_supports_openid = StrToi(Buf);
133 * Read Citadel variformat text and spit it out as HTML.
134 * align html align string
136 inline void fmout(char *align)
138 _fmout(WC->WBuf, align);
141 void _fmout(StrBuf *Target, char *align)
147 StrBufAppendPrintf(Target, "<div align=%s>\n", align);
148 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
150 if ((intext == 1) && (isspace(buf[0]))) {
156 * Quoted text should be displayed in italics and in a
157 * different colour. This code understands Citadel-style
158 * " >" quotes and will convert to <BLOCKQUOTE> tags.
160 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
161 StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
163 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
164 StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
167 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
168 strcpy(buf, &buf[2]);
170 /** Activate embedded URL's */
171 url(buf, sizeof(buf));
174 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
179 wprintf("</div><br />\n");
182 void FmOut(StrBuf *Target, char *align, StrBuf *Source)
184 const char *ptr, *pte;
185 const char *BufPtr = NULL;
186 StrBuf *Line = NewStrBuf();
187 StrBuf *Line1 = NewStrBuf();
188 StrBuf *Line2 = NewStrBuf();
195 StrBufAppendPrintf(Target, "<div class=\"fmout\">\n", align);
196 while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
202 len = StrLength(Line);
205 if ((intext == 1) && (isspace(*ptr))) {
206 StrBufAppendBufPlain(Target, HKEY("<br>"), 0);
209 if (isspace(*ptr)) while ((ptr < pte) &&
220 * Quoted text should be displayed in italics and in a
221 * different colour. This code understands Citadel-style
222 * " >" quotes and will convert to <BLOCKQUOTE> tags.
224 if (i > 0) StrBufCutLeft(Line, i);
227 for (i = bn; i < bq; i++)
228 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
229 for (i = bq; i < bn; i++)
230 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
233 if (StrLength(Line) == 0)
235 /** Activate embedded URL's */
236 UrlizeText(Line1, Line, Line2);
238 StrEscAppend(Target, Line1, NULL, 0, 0);
240 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
242 for (i = 0; i < bn; i++)
243 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
244 StrBufAppendBufPlain(Target, HKEY("</div><br>\n"), 0);
254 * Read Citadel variformat text and spit it out as HTML in a form
255 * suitable for embedding in another message (forward/quote).
256 * (NO LINEBREAKS ALLOWED HERE!)
258 void pullquote_fmout(void) {
263 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
265 if ((intext == 1) && (isspace(buf[0]))) {
271 * Quoted text should be displayed in italics and in a
272 * different colour. This code understands Citadel-style
273 * " >" quotes and will convert to <BLOCKQUOTE> tags.
275 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
276 wprintf("<BLOCKQUOTE>");
278 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
279 wprintf("</BLOCKQUOTE>");
282 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
283 strcpy(buf, &buf[2]);
297 * Transmit message text (in memory) to the server.
299 * ptr Pointer to the message being transmitted
301 void text_to_server(char *ptr)
309 while (ptr[pos] != 0) {
313 while ( (isspace(buf[len - 1]))
315 && (buf[1] != '\0') )
319 if (ptr[pos] != 0) strcat(buf, " ");
324 if ((ch == 32) && (strlen(buf) > 200)) {
329 if (strlen(buf) > 250) {
340 * Transmit message text (in memory) to the server,
341 * converting to Quoted-Printable encoding as we go.
343 * ptr Pointer to the message being transmitted
345 void text_to_server_qp(char *ptr)
347 unsigned char ch, buf[256];
355 while (ptr[pos] != 0) {
356 ch = (unsigned char)(ptr[pos++]);
359 /* ignore carriage returns */
362 /* hard line break */
363 if (output_len > 0) {
364 if (isspace(buf[output_len-1])) {
365 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
369 buf[output_len++] = 0;
370 serv_puts((char *)buf);
374 buf[output_len++] = ch;
376 else if ( (ch >= 32) && (ch <= 60) ) {
377 buf[output_len++] = ch;
379 else if ( (ch >= 62) && (ch <= 126) ) {
380 buf[output_len++] = ch;
383 sprintf((char *)&buf[output_len], "=%02X", ch);
387 if (output_len > 72) {
388 /* soft line break */
389 if (isspace(buf[output_len-1])) {
390 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
393 buf[output_len++] = '=';
394 buf[output_len++] = 0;
395 serv_puts((char *)buf);
400 /* end of data - transmit anything that's left */
401 if (output_len > 0) {
402 if (isspace(buf[output_len-1])) {
403 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
406 buf[output_len++] = 0;
407 serv_puts((char *)buf);
416 * translate server message output to text
417 * (used for editing room info files and such)
419 void server_to_text()
425 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
426 if ((buf[0] == 32) && (count > 0)) {
437 * Read binary data from server into memory using a series of
438 * server READ commands.
439 * \return the read content as StrBuf
441 int read_server_binary(StrBuf *Ret, size_t total_len)
445 size_t thisblock = 0;
452 while (bytes < total_len) {
454 if ((total_len - bytes) < thisblock) {
455 thisblock = total_len - bytes;
456 if (thisblock == 0) {
462 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
463 if (StrBuf_ServGetln(Buf) > 0)
465 if (GetServerStatus(Buf, NULL) == 6)
467 StrBufCutLeft(Buf, 4); /*/ TODO : thisblock = (size_t)atoi(&buf[4]); */
468 thisblock = StrTol(Buf);
469 if (!WC->connected) {
474 StrBuf_ServGetBLOB(Ret, thisblock);
479 lprintf(3, "Error: %s\n", &buf[4]);
485 return StrLength(Ret);
490 * Read text from server, appending to a string buffer until the
491 * usual 000 terminator is found. Caller is responsible for freeing
492 * the returned pointer.
494 int read_server_text(StrBuf *Buf, long *nLines)
502 while ((WCC->serv_sock!=-1) &&
503 (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
505 if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
506 StrBufCutRight(Buf, nRead);
522 int GetServerStatus(StrBuf *Line, long* FullState)
524 if (FullState != NULL)
525 *FullState = StrTol(Line);
526 return ChrPtr(Line)[0] - 48;
530 void tmplput_serv_ip(StrBuf *Target, WCTemplputParams *TP)
532 StrBufAppendPrintf(Target, "%d", WC->ctdl_pid);
535 void tmplput_serv_nodename(StrBuf *Target, WCTemplputParams *TP)
537 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_nodename, 0);
540 void tmplput_serv_humannode(StrBuf *Target, WCTemplputParams *TP)
542 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_humannode, 0);
545 void tmplput_serv_fqdn(StrBuf *Target, WCTemplputParams *TP)
547 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_fqdn, 0);
550 void tmplput_serv_software(StrBuf *Target, WCTemplputParams *TP)
552 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_software, 0);
555 void tmplput_serv_rev_level(StrBuf *Target, WCTemplputParams *TP)
557 StrBufAppendPrintf(Target, "%d.%02d",
558 WC->serv_info->serv_rev_level / 100,
559 WC->serv_info->serv_rev_level % 100);
561 int conditional_serv_newuser_disabled(StrBuf *Target, WCTemplputParams *TP)
563 return WC->serv_info->serv_newuser_disabled != 0;
565 int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
567 return WC->serv_info->serv_supports_openid != 0;
570 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
572 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_bbs_city, 0);
576 void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
585 serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
586 StrBuf_ServGetln(Line);
587 while (!Done && (StrBuf_ServGetln(Line)>=0)) {
588 if ( (StrLength(Line)==3) &&
589 !strcmp(ChrPtr(Line), "000"))
594 StrBufAppendBufPlain(Buf, "\n", 1, 0);
595 StrBufAppendBuf(Buf, Line, 0);
600 FmOut(Line, "center", Buf);
601 StrBufAppendTemplate(Target, TP, Line, 1);
611 RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
612 RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
613 RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
614 RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, CTX_NONE);
615 RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, CTX_NONE);
616 RegisterNamespace("SERV:FQDN", 0, 1, tmplput_serv_fqdn, CTX_NONE);
617 RegisterNamespace("SERV:SOFTWARE", 0, 1, tmplput_serv_software, CTX_NONE);
618 RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
619 RegisterNamespace("SERV:BBS_CITY", 0, 1, tmplput_serv_bbs_city, CTX_NONE);
620 RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
621 /*TODO // RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0); */