9 void DeleteServInfo(ServInfo **FreeMe)
11 FreeStrBuf(&(*FreeMe)->serv_nodename);
12 FreeStrBuf(&(*FreeMe)->serv_humannode);
13 FreeStrBuf(&(*FreeMe)->serv_fqdn);
14 FreeStrBuf(&(*FreeMe)->serv_software);
15 FreeStrBuf(&(*FreeMe)->serv_bbs_city);
16 FreeStrBuf(&(*FreeMe)->serv_sysadm);
17 FreeStrBuf(&(*FreeMe)->serv_moreprompt);
18 FreeStrBuf(&(*FreeMe)->serv_default_cal_zone);
19 FreeStrBuf(&(*FreeMe)->serv_svn_revision);
25 * get info about the server we've connected to
27 * browser_host the citadell we want to connect to
28 * user_agent which browser uses our client?
30 ServInfo *get_serv_info(StrBuf *browser_host, char *user_agent)
37 /** Tell the server what kind of client is connecting */
38 serv_printf("IDEN %d|%d|%d|%s|%s",
45 serv_getln(buf, sizeof buf);
47 /** Tell the server what kind of richtext we prefer */
48 serv_puts("MSGP text/calendar|text/html|text/plain");
49 serv_getln(buf, sizeof buf);
52 * Tell the server that when we save a calendar event, we
53 * want invitations to be generated by the Citadel server
54 * instead of by the client.
56 serv_puts("ICAL sgi|1");
57 serv_getln(buf, sizeof buf);
59 /** Now ask the server to tell us a little bit about itself... */
61 serv_getln(buf, sizeof buf);
65 info = (ServInfo*)malloc(sizeof(ServInfo));
66 memset(info, 0, sizeof(ServInfo));
69 while (StrBuf_ServGetln(Buf), (strcmp(ChrPtr(Buf), "000")!= 0)) {
70 /* lprintf (1, "a: %d [%s]", a, ChrPtr(Buf));*/
73 info->serv_pid = StrToi(Buf);
74 WC->ctdl_pid = info->serv_pid;
77 info->serv_nodename = NewStrBufDup(Buf);
80 info->serv_humannode = NewStrBufDup(Buf);
83 info->serv_fqdn = NewStrBufDup(Buf);
86 info->serv_software = NewStrBufDup(Buf);
89 info->serv_rev_level = StrToi(Buf);
92 info->serv_bbs_city = NewStrBufDup(Buf);
95 info->serv_sysadm = NewStrBufDup(Buf);
98 info->serv_moreprompt = NewStrBufDup(Buf);
101 info->serv_supports_ldap = StrToi(Buf);
104 info->serv_newuser_disabled = StrToi(Buf);
107 info->serv_default_cal_zone = NewStrBufDup(Buf);
110 info->serv_supports_sieve = StrToi(Buf);
113 info->serv_fulltext_enabled = StrToi(Buf);
116 info->serv_svn_revision = NewStrBufDup(Buf);
119 info->serv_supports_openid = StrToi(Buf);
131 * Read Citadel variformat text and spit it out as HTML.
132 * align html align string
134 inline void fmout(char *align)
136 _fmout(WC->WBuf, align);
139 void _fmout(StrBuf *Target, char *align)
145 StrBufAppendPrintf(Target, "<div align=%s>\n", align);
146 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
148 if ((intext == 1) && (isspace(buf[0]))) {
154 * Quoted text should be displayed in italics and in a
155 * different colour. This code understands Citadel-style
156 * " >" quotes and will convert to <BLOCKQUOTE> tags.
158 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
159 StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
161 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
162 StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
165 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
166 strcpy(buf, &buf[2]);
168 /** Activate embedded URL's */
169 url(buf, sizeof(buf));
171 escputs(buf);/*/ TODO: Target */
172 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
177 wprintf("</div><br />\n");
180 void FmOut(StrBuf *Target, char *align, StrBuf *Source)
182 const char *ptr, *pte;
183 const char *BufPtr = NULL;
184 StrBuf *Line = NewStrBuf();
185 StrBuf *Line1 = NewStrBuf();
186 StrBuf *Line2 = NewStrBuf();
193 StrBufAppendPrintf(Target, "<div class=\"fmout\">\n", align);
194 while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
200 len = StrLength(Line);
203 if ((intext == 1) && (isspace(*ptr))) {
204 StrBufAppendBufPlain(Target, HKEY("<br>"), 0);
207 if (isspace(*ptr)) while ((ptr < pte) &&
218 * Quoted text should be displayed in italics and in a
219 * different colour. This code understands Citadel-style
220 * " >" quotes and will convert to <BLOCKQUOTE> tags.
222 if (i > 0) StrBufCutLeft(Line, i);
225 for (i = bn; i < bq; i++)
226 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
227 for (i = bq; i < bn; i++)
228 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
231 if (StrLength(Line) == 0)
233 /** Activate embedded URL's */
234 UrlizeText(Line1, Line, Line2);
236 StrEscAppend(Target, Line1, NULL, 0, 0);
238 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
240 for (i = 0; i < bn; i++)
241 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
242 StrBufAppendBufPlain(Target, HKEY("</div><br>\n"), 0);
252 * Read Citadel variformat text and spit it out as HTML in a form
253 * suitable for embedding in another message (forward/quote).
254 * (NO LINEBREAKS ALLOWED HERE!)
256 void pullquote_fmout(void) {
261 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
263 if ((intext == 1) && (isspace(buf[0]))) {
269 * Quoted text should be displayed in italics and in a
270 * different colour. This code understands Citadel-style
271 * " >" quotes and will convert to <BLOCKQUOTE> tags.
273 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
274 wprintf("<BLOCKQUOTE>");
276 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
277 wprintf("</BLOCKQUOTE>");
280 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
281 strcpy(buf, &buf[2]);
295 * Transmit message text (in memory) to the server.
297 * ptr Pointer to the message being transmitted
299 void text_to_server(char *ptr)
307 while (ptr[pos] != 0) {
311 while ( (isspace(buf[len - 1]))
313 && (buf[1] != '\0') )
317 if (ptr[pos] != 0) strcat(buf, " ");
322 if ((ch == 32) && (strlen(buf) > 200)) {
327 if (strlen(buf) > 250) {
338 * Transmit message text (in memory) to the server,
339 * converting to Quoted-Printable encoding as we go.
341 * ptr Pointer to the message being transmitted
343 void text_to_server_qp(char *ptr)
345 unsigned char ch, buf[256];
353 while (ptr[pos] != 0) {
354 ch = (unsigned char)(ptr[pos++]);
357 /* ignore carriage returns */
360 /* hard line break */
361 if (output_len > 0) {
362 if (isspace(buf[output_len-1])) {
363 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
367 buf[output_len++] = 0;
368 serv_puts((char *)buf);
372 buf[output_len++] = ch;
374 else if ( (ch >= 32) && (ch <= 60) ) {
375 buf[output_len++] = ch;
377 else if ( (ch >= 62) && (ch <= 126) ) {
378 buf[output_len++] = ch;
381 sprintf((char *)&buf[output_len], "=%02X", ch);
385 if (output_len > 72) {
386 /* soft line break */
387 if (isspace(buf[output_len-1])) {
388 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
391 buf[output_len++] = '=';
392 buf[output_len++] = 0;
393 serv_puts((char *)buf);
398 /* end of data - transmit anything that's left */
399 if (output_len > 0) {
400 if (isspace(buf[output_len-1])) {
401 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
404 buf[output_len++] = 0;
405 serv_puts((char *)buf);
414 * translate server message output to text
415 * (used for editing room info files and such)
417 void server_to_text()
423 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
424 if ((buf[0] == 32) && (count > 0)) {
435 * Read binary data from server into memory using a series of
436 * server READ commands.
437 * \return the read content as StrBuf
439 int read_server_binary(StrBuf *Ret, size_t total_len)
443 size_t thisblock = 0;
450 while (bytes < total_len) {
452 if ((total_len - bytes) < thisblock) {
453 thisblock = total_len - bytes;
454 if (thisblock == 0) {
460 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
461 if (StrBuf_ServGetln(Buf) > 0)
463 if (GetServerStatus(Buf, NULL) == 6)
465 StrBufCutLeft(Buf, 4); /*/ TODO : thisblock = (size_t)atoi(&buf[4]); */
466 thisblock = StrTol(Buf);
467 if (!WC->connected) {
472 StrBuf_ServGetBLOB(Ret, thisblock);
477 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)
535 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_nodename, 0);
538 void tmplput_serv_humannode(StrBuf *Target, WCTemplputParams *TP)
540 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_humannode, 0);
543 void tmplput_serv_fqdn(StrBuf *Target, WCTemplputParams *TP)
545 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_fqdn, 0);
548 void tmplput_serv_software(StrBuf *Target, WCTemplputParams *TP)
550 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_software, 0);
553 void tmplput_serv_rev_level(StrBuf *Target, WCTemplputParams *TP)
555 StrBufAppendPrintf(Target, "%d.%02d",
556 WC->serv_info->serv_rev_level / 100,
557 WC->serv_info->serv_rev_level % 100);
559 int conditional_serv_newuser_disabled(StrBuf *Target, WCTemplputParams *TP)
561 return WC->serv_info->serv_newuser_disabled != 0;
563 int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
565 return WC->serv_info->serv_supports_openid != 0;
568 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
570 StrBufAppendTemplate(Target, TP, WC->serv_info->serv_bbs_city, 0);
574 void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
583 serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
584 StrBuf_ServGetln(Line);
585 while (!Done && (StrBuf_ServGetln(Line)>=0)) {
586 if ( (StrLength(Line)==3) &&
587 !strcmp(ChrPtr(Line), "000"))
592 StrBufAppendBufPlain(Buf, "\n", 1, 0);
593 StrBufAppendBuf(Buf, Line, 0);
598 FmOut(Line, "center", Buf);
599 StrBufAppendTemplate(Target, TP, Line, 1);
609 RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
610 RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
611 RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
612 RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, CTX_NONE);
613 RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, CTX_NONE);
614 RegisterNamespace("SERV:FQDN", 0, 1, tmplput_serv_fqdn, CTX_NONE);
615 RegisterNamespace("SERV:SOFTWARE", 0, 1, tmplput_serv_software, CTX_NONE);
616 RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
617 RegisterNamespace("SERV:BBS_CITY", 0, 1, tmplput_serv_bbs_city, CTX_NONE);
618 RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
619 /*TODO // RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0); */