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)
20 /** Tell the server what kind of client is connecting */
21 serv_printf("IDEN %d|%d|%d|%s|%s",
28 serv_getln(buf, sizeof buf);
30 /** Tell the server what kind of richtext we prefer */
31 serv_puts("MSGP text/html|text/plain");
32 serv_getln(buf, sizeof buf);
35 * Tell the server that when we save a calendar event, we
36 * want invitations to be generated by the Citadel server
37 * instead of by the client.
39 serv_puts("ICAL sgi|1");
40 serv_getln(buf, sizeof buf);
42 /** Now ask the server to tell us a little bit about itself... */
44 serv_getln(buf, sizeof buf);
49 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
52 serv_info.serv_pid = atoi(buf);
53 WC->ctdl_pid = serv_info.serv_pid;
56 safestrncpy(serv_info.serv_nodename, buf, sizeof serv_info.serv_nodename);
59 safestrncpy(serv_info.serv_humannode, buf, sizeof serv_info.serv_humannode);
62 safestrncpy(serv_info.serv_fqdn, buf, sizeof serv_info.serv_fqdn);
65 safestrncpy(serv_info.serv_software, buf, sizeof serv_info.serv_software);
68 serv_info.serv_rev_level = atoi(buf);
71 safestrncpy(serv_info.serv_bbs_city, buf, sizeof serv_info.serv_bbs_city);
74 safestrncpy(serv_info.serv_sysadm, buf, sizeof serv_info.serv_sysadm);
77 safestrncpy(serv_info.serv_moreprompt, buf, sizeof serv_info.serv_moreprompt);
80 serv_info.serv_supports_ldap = atoi(buf);
83 serv_info.serv_newuser_disabled = atoi(buf);
86 safestrncpy(serv_info.serv_default_cal_zone, buf, sizeof serv_info.serv_default_cal_zone);
89 serv_info.serv_supports_sieve = atoi(buf);
92 serv_info.serv_fulltext_enabled = atoi(buf);
95 safestrncpy(serv_info.serv_svn_revision, buf, sizeof serv_info.serv_svn_revision);
98 serv_info.serv_supports_openid = atoi(buf);
108 * Read Citadel variformat text and spit it out as HTML.
109 * align html align string
111 inline void fmout(char *align)
113 _fmout(WC->WBuf, align);
116 void _fmout(StrBuf *Target, char *align)
122 StrBufAppendPrintf(Target, "<div align=%s>\n", align);
123 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
125 if ((intext == 1) && (isspace(buf[0]))) {
131 * Quoted text should be displayed in italics and in a
132 * different colour. This code understands Citadel-style
133 * " >" quotes and will convert to <BLOCKQUOTE> tags.
135 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
136 StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
138 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
139 StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
142 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
143 strcpy(buf, &buf[2]);
145 /** Activate embedded URL's */
146 url(buf, sizeof(buf));
148 escputs(buf);/*/ TODO: Target */
149 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
154 wprintf("</div><br />\n");
157 void FmOut(StrBuf *Target, char *align, StrBuf *Source)
159 const char *ptr, *pte;
160 const char *BufPtr = NULL;
161 StrBuf *Line = NewStrBuf();
162 StrBuf *Line1 = NewStrBuf();
163 StrBuf *Line2 = NewStrBuf();
170 StrBufAppendPrintf(Target, "<div align=\"%s\">\n", align);
171 while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
177 len = StrLength(Line);
180 if ((intext == 1) && (isspace(*ptr))) {
181 StrBufAppendBufPlain(Target, HKEY("<br />"), 0);
184 if (isspace(*ptr)) while ((ptr < pte) &&
195 * Quoted text should be displayed in italics and in a
196 * different colour. This code understands Citadel-style
197 * " >" quotes and will convert to <BLOCKQUOTE> tags.
199 if (i > 0) StrBufCutLeft(Line, i);
202 for (i = bn; i < bq; i++)
203 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
204 for (i = bq; i < bn; i++)
205 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
208 if (StrLength(Line) == 0)
210 /** Activate embedded URL's */
211 UrlizeText(Line1, Line, Line2);
213 StrEscAppend(Target, Line1, NULL, 0, 0);
215 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
217 for (i = 0; i < bn; i++)
218 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
219 StrBufAppendBufPlain(Target, HKEY("</div><br />\n"), 0);
229 * Read Citadel variformat text and spit it out as HTML in a form
230 * suitable for embedding in another message (forward/quote).
231 * (NO LINEBREAKS ALLOWED HERE!)
233 void pullquote_fmout(void) {
238 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
240 if ((intext == 1) && (isspace(buf[0]))) {
246 * Quoted text should be displayed in italics and in a
247 * different colour. This code understands Citadel-style
248 * " >" quotes and will convert to <BLOCKQUOTE> tags.
250 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
251 wprintf("<BLOCKQUOTE>");
253 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
254 wprintf("</BLOCKQUOTE>");
257 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
258 strcpy(buf, &buf[2]);
272 * Transmit message text (in memory) to the server.
274 * ptr Pointer to the message being transmitted
276 void text_to_server(char *ptr)
284 while (ptr[pos] != 0) {
288 while ( (isspace(buf[len - 1]))
290 && (buf[1] != '\0') )
294 if (ptr[pos] != 0) strcat(buf, " ");
299 if ((ch == 32) && (strlen(buf) > 200)) {
304 if (strlen(buf) > 250) {
315 * Transmit message text (in memory) to the server,
316 * converting to Quoted-Printable encoding as we go.
318 * ptr Pointer to the message being transmitted
320 void text_to_server_qp(char *ptr)
322 unsigned char ch, buf[256];
330 while (ptr[pos] != 0) {
331 ch = (unsigned char)(ptr[pos++]);
334 /* ignore carriage returns */
337 /* hard line break */
338 if (output_len > 0) {
339 if (isspace(buf[output_len-1])) {
340 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
344 buf[output_len++] = 0;
345 serv_puts((char *)buf);
349 buf[output_len++] = ch;
351 else if ( (ch >= 32) && (ch <= 60) ) {
352 buf[output_len++] = ch;
354 else if ( (ch >= 62) && (ch <= 126) ) {
355 buf[output_len++] = ch;
358 sprintf((char *)&buf[output_len], "=%02X", ch);
362 if (output_len > 72) {
363 /* soft line break */
364 if (isspace(buf[output_len-1])) {
365 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
368 buf[output_len++] = '=';
369 buf[output_len++] = 0;
370 serv_puts((char *)buf);
375 /* end of data - transmit anything that's left */
376 if (output_len > 0) {
377 if (isspace(buf[output_len-1])) {
378 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
381 buf[output_len++] = 0;
382 serv_puts((char *)buf);
391 * translate server message output to text
392 * (used for editing room info files and such)
394 void server_to_text()
400 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
401 if ((buf[0] == 32) && (count > 0)) {
412 * Read binary data from server into memory using a series of
413 * server READ commands.
414 * \return the read content as StrBuf
416 int read_server_binary(StrBuf *Ret, size_t total_len)
420 size_t thisblock = 0;
427 while (bytes < total_len) {
429 if ((total_len - bytes) < thisblock) {
430 thisblock = total_len - bytes;
431 if (thisblock == 0) {
437 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
438 if (StrBuf_ServGetln(Buf) > 0)
440 if (ChrPtr(Buf)[0] == '6')
442 StrBufCutLeft(Buf, 4); /*/ TODO : thisblock = (size_t)atoi(&buf[4]); */
443 thisblock = StrTol(Buf);
444 if (!WC->connected) {
449 StrBuf_ServGetBLOB(Ret, thisblock);
454 lprintf(3, "Error: %s\n", &buf[4]);
460 return StrLength(Ret);
465 * Read text from server, appending to a string buffer until the
466 * usual 000 terminator is found. Caller is responsible for freeing
467 * the returned pointer.
469 int read_server_text(StrBuf *Buf, long *nLines)
477 while ((WCC->serv_sock!=-1) &&
478 (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
480 if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
481 StrBufCutRight(Buf, nRead);
497 int GetServerStatus(StrBuf *Line, long* FullState)
499 if (FullState != NULL)
500 *FullState = StrTol(Line);
501 return ChrPtr(Line)[0] - 48;
505 void tmplput_serv_ip(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
507 StrBufAppendPrintf(Target, "%d", WC->ctdl_pid);
510 void tmplput_serv_nodename(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
512 StrEscAppend(Target, NULL, serv_info.serv_nodename, 0, 0);
515 void tmplput_serv_humannode(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
517 StrEscAppend(Target, NULL, serv_info.serv_humannode, 0, 0);
520 void tmplput_serv_fqdn(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
522 StrEscAppend(Target, NULL, serv_info.serv_fqdn, 0, 0);
525 void tmplput_serv_software(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
527 StrEscAppend(Target, NULL, serv_info.serv_software, 0, 0);
530 void tmplput_serv_rev_level(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
532 StrBufAppendPrintf(Target, "%d.%02d",
533 serv_info.serv_rev_level / 100,
534 serv_info.serv_rev_level % 100);
536 int conditional_serv_newuser_disabled(WCTemplateToken *Tokens, void *Context, int ContextType)
538 return serv_info.serv_newuser_disabled != 0;
540 int conditional_serv_supports_openid(WCTemplateToken *Tokens, void *Context, int ContextType)
542 return serv_info.serv_supports_openid != 0;
545 void tmplput_serv_bbs_city(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
547 StrEscAppend(Target, NULL, serv_info.serv_bbs_city, 0, 0);
550 void tmplput_current_user(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
552 StrEscAppend(Target, NULL, WC->wc_fullname, 0, 0);
555 void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
557 StrEscAppend(Target, NULL, WC->wc_roomname, 0, 0);
561 void tmplput_mesg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
570 serv_printf("MESG %s", Tokens->Params[0]->Start);
571 StrBuf_ServGetln(Line);
572 while (!Done && (StrBuf_ServGetln(Line)>=0)) {
573 if ( (StrLength(Line)==3) &&
574 !strcmp(ChrPtr(Line), "000"))
579 StrBufAppendBufPlain(Buf, "\n", 1, 0);
580 StrBufAppendBuf(Buf, Line, 0);
585 FmOut(Line, "center", Buf);
586 StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Line, 1);
596 RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
597 RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
598 RegisterNamespace("CURRENT_USER", 0, 0, tmplput_current_user, CTX_NONE);
599 RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room, CTX_NONE);
600 RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
601 RegisterNamespace("SERV:NODENAME", 0, 0, tmplput_serv_nodename, CTX_NONE);
602 RegisterNamespace("SERV:HUMANNODE", 0, 0, tmplput_serv_humannode, CTX_NONE);
603 RegisterNamespace("SERV:FQDN", 0, 0, tmplput_serv_fqdn, CTX_NONE);
604 RegisterNamespace("SERV:SOFTWARE", 0, 0, tmplput_serv_software, CTX_NONE);
605 RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
606 RegisterNamespace("SERV:BBS_CITY", 0, 0, tmplput_serv_bbs_city, CTX_NONE);
607 RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
608 /*TODO // RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0); */