8 struct serv_info serv_info; /**< our connection data to the server */
10 * get info about the server we've connected to
12 * browser_host the citadell we want to connect to
13 * user_agent which browser uses our client?
15 void get_serv_info(char *browser_host, char *user_agent)
21 /** Tell the server what kind of client is connecting */
22 serv_printf("IDEN %d|%d|%d|%s|%s",
29 serv_getln(buf, sizeof buf);
31 /** Tell the server what kind of richtext we prefer */
32 serv_puts("MSGP text/calendar|text/html|text/plain");
33 serv_getln(buf, sizeof buf);
36 * Tell the server that when we save a calendar event, we
37 * want invitations to be generated by the Citadel server
38 * instead of by the client.
40 serv_puts("ICAL sgi|1");
41 serv_getln(buf, sizeof buf);
43 /** Now ask the server to tell us a little bit about itself... */
45 serv_getln(buf, sizeof buf);
51 while (StrBuf_ServGetln(Buf), (strcmp(ChrPtr(Buf), "000")!= 0)) {
52 /* lprintf (1, "a: %d [%s]", a, ChrPtr(Buf));*/
55 serv_info.serv_pid = StrToi(Buf);
56 WC->ctdl_pid = serv_info.serv_pid;
59 serv_info.serv_nodename = NewStrBufDup(Buf);
62 serv_info.serv_humannode = NewStrBufDup(Buf);
65 serv_info.serv_fqdn = NewStrBufDup(Buf);
68 serv_info.serv_software = NewStrBufDup(Buf);
71 serv_info.serv_rev_level = StrToi(Buf);
74 serv_info.serv_bbs_city = NewStrBufDup(Buf);
77 serv_info.serv_sysadm = NewStrBufDup(Buf);
80 serv_info.serv_moreprompt = NewStrBufDup(Buf);
83 serv_info.serv_supports_ldap = StrToi(Buf);
86 serv_info.serv_newuser_disabled = StrToi(Buf);
89 serv_info.serv_default_cal_zone = NewStrBufDup(Buf);
92 serv_info.serv_supports_sieve = StrToi(Buf);
95 serv_info.serv_fulltext_enabled = StrToi(Buf);
98 serv_info.serv_svn_revision = NewStrBufDup(Buf);
101 serv_info.serv_supports_openid = StrToi(Buf);
111 * Read Citadel variformat text and spit it out as HTML.
112 * align html align string
114 inline void fmout(char *align)
116 _fmout(WC->WBuf, align);
119 void _fmout(StrBuf *Target, char *align)
125 StrBufAppendPrintf(Target, "<div align=%s>\n", align);
126 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
128 if ((intext == 1) && (isspace(buf[0]))) {
134 * Quoted text should be displayed in italics and in a
135 * different colour. This code understands Citadel-style
136 * " >" quotes and will convert to <BLOCKQUOTE> tags.
138 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
139 StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
141 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
142 StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
145 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
146 strcpy(buf, &buf[2]);
148 /** Activate embedded URL's */
149 url(buf, sizeof(buf));
151 escputs(buf);/*/ TODO: Target */
152 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
157 wprintf("</div><br />\n");
160 void FmOut(StrBuf *Target, char *align, StrBuf *Source)
162 const char *ptr, *pte;
163 const char *BufPtr = NULL;
164 StrBuf *Line = NewStrBuf();
165 StrBuf *Line1 = NewStrBuf();
166 StrBuf *Line2 = NewStrBuf();
173 StrBufAppendPrintf(Target, "<div align=\"%s\">\n", align);
174 while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
180 len = StrLength(Line);
183 if ((intext == 1) && (isspace(*ptr))) {
184 StrBufAppendBufPlain(Target, HKEY("<br />"), 0);
187 if (isspace(*ptr)) while ((ptr < pte) &&
198 * Quoted text should be displayed in italics and in a
199 * different colour. This code understands Citadel-style
200 * " >" quotes and will convert to <BLOCKQUOTE> tags.
202 if (i > 0) StrBufCutLeft(Line, i);
205 for (i = bn; i < bq; i++)
206 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
207 for (i = bq; i < bn; i++)
208 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
211 if (StrLength(Line) == 0)
213 /** Activate embedded URL's */
214 UrlizeText(Line1, Line, Line2);
216 StrEscAppend(Target, Line1, NULL, 0, 0);
218 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
220 for (i = 0; i < bn; i++)
221 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
222 StrBufAppendBufPlain(Target, HKEY("</div><br />\n"), 0);
232 * Read Citadel variformat text and spit it out as HTML in a form
233 * suitable for embedding in another message (forward/quote).
234 * (NO LINEBREAKS ALLOWED HERE!)
236 void pullquote_fmout(void) {
241 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
243 if ((intext == 1) && (isspace(buf[0]))) {
249 * Quoted text should be displayed in italics and in a
250 * different colour. This code understands Citadel-style
251 * " >" quotes and will convert to <BLOCKQUOTE> tags.
253 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
254 wprintf("<BLOCKQUOTE>");
256 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
257 wprintf("</BLOCKQUOTE>");
260 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
261 strcpy(buf, &buf[2]);
275 * Transmit message text (in memory) to the server.
277 * ptr Pointer to the message being transmitted
279 void text_to_server(char *ptr)
287 while (ptr[pos] != 0) {
291 while ( (isspace(buf[len - 1]))
293 && (buf[1] != '\0') )
297 if (ptr[pos] != 0) strcat(buf, " ");
302 if ((ch == 32) && (strlen(buf) > 200)) {
307 if (strlen(buf) > 250) {
318 * Transmit message text (in memory) to the server,
319 * converting to Quoted-Printable encoding as we go.
321 * ptr Pointer to the message being transmitted
323 void text_to_server_qp(char *ptr)
325 unsigned char ch, buf[256];
333 while (ptr[pos] != 0) {
334 ch = (unsigned char)(ptr[pos++]);
337 /* ignore carriage returns */
340 /* hard line break */
341 if (output_len > 0) {
342 if (isspace(buf[output_len-1])) {
343 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
347 buf[output_len++] = 0;
348 serv_puts((char *)buf);
352 buf[output_len++] = ch;
354 else if ( (ch >= 32) && (ch <= 60) ) {
355 buf[output_len++] = ch;
357 else if ( (ch >= 62) && (ch <= 126) ) {
358 buf[output_len++] = ch;
361 sprintf((char *)&buf[output_len], "=%02X", ch);
365 if (output_len > 72) {
366 /* soft line break */
367 if (isspace(buf[output_len-1])) {
368 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
371 buf[output_len++] = '=';
372 buf[output_len++] = 0;
373 serv_puts((char *)buf);
378 /* end of data - transmit anything that's left */
379 if (output_len > 0) {
380 if (isspace(buf[output_len-1])) {
381 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
384 buf[output_len++] = 0;
385 serv_puts((char *)buf);
394 * translate server message output to text
395 * (used for editing room info files and such)
397 void server_to_text()
403 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
404 if ((buf[0] == 32) && (count > 0)) {
415 * Read binary data from server into memory using a series of
416 * server READ commands.
417 * \return the read content as StrBuf
419 int read_server_binary(StrBuf *Ret, size_t total_len)
423 size_t thisblock = 0;
430 while (bytes < total_len) {
432 if ((total_len - bytes) < thisblock) {
433 thisblock = total_len - bytes;
434 if (thisblock == 0) {
440 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
441 if (StrBuf_ServGetln(Buf) > 0)
443 if (GetServerStatus(Buf, NULL) == 6)
445 StrBufCutLeft(Buf, 4); /*/ TODO : thisblock = (size_t)atoi(&buf[4]); */
446 thisblock = StrTol(Buf);
447 if (!WC->connected) {
452 StrBuf_ServGetBLOB(Ret, thisblock);
457 lprintf(3, "Error: %s\n", &buf[4]);
463 return StrLength(Ret);
468 * Read text from server, appending to a string buffer until the
469 * usual 000 terminator is found. Caller is responsible for freeing
470 * the returned pointer.
472 int read_server_text(StrBuf *Buf, long *nLines)
480 while ((WCC->serv_sock!=-1) &&
481 (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
483 if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
484 StrBufCutRight(Buf, nRead);
500 int GetServerStatus(StrBuf *Line, long* FullState)
502 if (FullState != NULL)
503 *FullState = StrTol(Line);
504 return ChrPtr(Line)[0] - 48;
508 void tmplput_serv_ip(StrBuf *Target, WCTemplputParams *TP)
510 StrBufAppendPrintf(Target, "%d", WC->ctdl_pid);
513 void tmplput_serv_nodename(StrBuf *Target, WCTemplputParams *TP)
515 StrBufAppendTemplate(Target, TP, serv_info.serv_nodename, 0);
518 void tmplput_serv_humannode(StrBuf *Target, WCTemplputParams *TP)
520 StrBufAppendTemplate(Target, TP, serv_info.serv_humannode, 0);
523 void tmplput_serv_fqdn(StrBuf *Target, WCTemplputParams *TP)
525 StrBufAppendTemplate(Target, TP, serv_info.serv_fqdn, 0);
528 void tmplput_serv_software(StrBuf *Target, WCTemplputParams *TP)
530 StrBufAppendTemplate(Target, TP, serv_info.serv_software, 0);
533 void tmplput_serv_rev_level(StrBuf *Target, WCTemplputParams *TP)
535 StrBufAppendPrintf(Target, "%d.%02d",
536 serv_info.serv_rev_level / 100,
537 serv_info.serv_rev_level % 100);
539 int conditional_serv_newuser_disabled(StrBuf *Target, WCTemplputParams *TP)
541 return serv_info.serv_newuser_disabled != 0;
543 int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
545 return serv_info.serv_supports_openid != 0;
548 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
550 StrBufAppendTemplate(Target, TP, serv_info.serv_bbs_city, 0);
554 void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
563 serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
564 StrBuf_ServGetln(Line);
565 while (!Done && (StrBuf_ServGetln(Line)>=0)) {
566 if ( (StrLength(Line)==3) &&
567 !strcmp(ChrPtr(Line), "000"))
572 StrBufAppendBufPlain(Buf, "\n", 1, 0);
573 StrBufAppendBuf(Buf, Line, 0);
578 FmOut(Line, "center", Buf);
579 StrBufAppendTemplate(Target, TP, Line, 1);
589 RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
590 RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
591 RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
592 RegisterNamespace("SERV:NODENAME", 0, 1, tmplput_serv_nodename, CTX_NONE);
593 RegisterNamespace("SERV:HUMANNODE", 0, 1, tmplput_serv_humannode, CTX_NONE);
594 RegisterNamespace("SERV:FQDN", 0, 1, tmplput_serv_fqdn, CTX_NONE);
595 RegisterNamespace("SERV:SOFTWARE", 0, 1, tmplput_serv_software, CTX_NONE);
596 RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
597 RegisterNamespace("SERV:BBS_CITY", 0, 1, tmplput_serv_bbs_city, CTX_NONE);
598 RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
599 /*TODO // RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0); */