8 struct serv_info serv_info; /**< our connection data to the server */
9 HashList *ServHash = NULL;//// TODO;
11 * get info about the server we've connected to
13 * browser_host the citadell we want to connect to
14 * user_agent which browser uses our client?
16 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/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);
50 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
53 serv_info.serv_pid = atoi(buf);
54 WC->ctdl_pid = serv_info.serv_pid;
57 safestrncpy(serv_info.serv_nodename, buf, sizeof serv_info.serv_nodename);
60 safestrncpy(serv_info.serv_humannode, buf, sizeof serv_info.serv_humannode);
63 safestrncpy(serv_info.serv_fqdn, buf, sizeof serv_info.serv_fqdn);
66 safestrncpy(serv_info.serv_software, buf, sizeof serv_info.serv_software);
69 serv_info.serv_rev_level = atoi(buf);
72 safestrncpy(serv_info.serv_bbs_city, buf, sizeof serv_info.serv_bbs_city);
75 safestrncpy(serv_info.serv_sysadm, buf, sizeof serv_info.serv_sysadm);
78 safestrncpy(serv_info.serv_moreprompt, buf, sizeof serv_info.serv_moreprompt);
81 serv_info.serv_supports_ldap = atoi(buf);
84 serv_info.serv_newuser_disabled = atoi(buf);
87 safestrncpy(serv_info.serv_default_cal_zone, buf, sizeof serv_info.serv_default_cal_zone);
90 serv_info.serv_supports_sieve = atoi(buf);
93 serv_info.serv_fulltext_enabled = atoi(buf);
96 safestrncpy(serv_info.serv_svn_revision, buf, sizeof serv_info.serv_svn_revision);
99 serv_info.serv_supports_openid = atoi(buf);
109 * Read Citadel variformat text and spit it out as HTML.
110 * align html align string
112 inline void fmout(char *align)
114 _fmout(WC->WBuf, align);
117 void _fmout(StrBuf *Target, char *align)
123 StrBufAppendPrintf(Target, "<div align=%s>\n", align);
124 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
126 if ((intext == 1) && (isspace(buf[0]))) {
132 * Quoted text should be displayed in italics and in a
133 * different colour. This code understands Citadel-style
134 * " >" quotes and will convert to <BLOCKQUOTE> tags.
136 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
137 StrBufAppendBufPlain(Target, HKEY("<BLOCKQUOTE>"), 0);
139 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
140 StrBufAppendBufPlain(Target, HKEY("</BLOCKQUOTE>"), 0);
143 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
144 strcpy(buf, &buf[2]);
146 /** Activate embedded URL's */
147 url(buf, sizeof(buf));
149 escputs(buf);//// TODO: Target
150 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
155 wprintf("</div><br />\n");
158 void FmOut(StrBuf *Target, char *align, StrBuf *Source)
160 const char *ptr, *pte;
161 const char *BufPtr = NULL;
162 StrBuf *Line = NewStrBuf();
163 StrBuf *Line1 = NewStrBuf();
164 StrBuf *Line2 = NewStrBuf();
171 StrBufAppendPrintf(Target, "<div align=\"%s\">\n", align);
172 while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
178 len = StrLength(Line);
181 if ((intext == 1) && (isspace(*ptr))) {
182 StrBufAppendBufPlain(Target, HKEY("<br />"), 0);
185 if (isspace(*ptr)) while ((ptr < pte) &&
196 * Quoted text should be displayed in italics and in a
197 * different colour. This code understands Citadel-style
198 * " >" quotes and will convert to <BLOCKQUOTE> tags.
200 if (i > 0) StrBufCutLeft(Line, i);
203 for (i = bn; i < bq; i++)
204 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
205 for (i = bq; i < bn; i++)
206 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
209 if (StrLength(Line) == 0)
211 /** Activate embedded URL's */
212 UrlizeText(Line1, Line, Line2);
214 StrEscAppend(Target, Line1, NULL, 0, 0);
216 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
218 for (i = 0; i < bn; i++)
219 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
220 StrBufAppendBufPlain(Target, HKEY("</div><br />\n"), 0);
230 * Read Citadel variformat text and spit it out as HTML in a form
231 * suitable for embedding in another message (forward/quote).
232 * (NO LINEBREAKS ALLOWED HERE!)
234 void pullquote_fmout(void) {
239 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
241 if ((intext == 1) && (isspace(buf[0]))) {
247 * Quoted text should be displayed in italics and in a
248 * different colour. This code understands Citadel-style
249 * " >" quotes and will convert to <BLOCKQUOTE> tags.
251 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
252 wprintf("<BLOCKQUOTE>");
254 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
255 wprintf("</BLOCKQUOTE>");
258 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
259 strcpy(buf, &buf[2]);
273 * Transmit message text (in memory) to the server.
275 * ptr Pointer to the message being transmitted
277 void text_to_server(char *ptr)
285 while (ptr[pos] != 0) {
289 while ( (isspace(buf[len - 1]))
291 && (buf[1] != '\0') )
295 if (ptr[pos] != 0) strcat(buf, " ");
300 if ((ch == 32) && (strlen(buf) > 200)) {
305 if (strlen(buf) > 250) {
316 * Transmit message text (in memory) to the server,
317 * converting to Quoted-Printable encoding as we go.
319 * ptr Pointer to the message being transmitted
321 void text_to_server_qp(char *ptr)
323 unsigned char ch, buf[256];
331 while (ptr[pos] != 0) {
332 ch = (unsigned char)(ptr[pos++]);
335 /* ignore carriage returns */
338 /* hard line break */
339 if (output_len > 0) {
340 if (isspace(buf[output_len-1])) {
341 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
345 buf[output_len++] = 0;
346 serv_puts((char *)buf);
350 buf[output_len++] = ch;
352 else if ( (ch >= 32) && (ch <= 60) ) {
353 buf[output_len++] = ch;
355 else if ( (ch >= 62) && (ch <= 126) ) {
356 buf[output_len++] = ch;
359 sprintf((char *)&buf[output_len], "=%02X", ch);
363 if (output_len > 72) {
364 /* soft line break */
365 if (isspace(buf[output_len-1])) {
366 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
369 buf[output_len++] = '=';
370 buf[output_len++] = 0;
371 serv_puts((char *)buf);
376 /* end of data - transmit anything that's left */
377 if (output_len > 0) {
378 if (isspace(buf[output_len-1])) {
379 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
382 buf[output_len++] = 0;
383 serv_puts((char *)buf);
392 * translate server message output to text
393 * (used for editing room info files and such)
395 void server_to_text()
401 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
402 if ((buf[0] == 32) && (count > 0)) {
413 * Read binary data from server into memory using a series of
414 * server READ commands.
415 * \return the read content as StrBuf
417 int read_server_binary(StrBuf *Ret, size_t total_len)
421 size_t thisblock = 0;
428 while (bytes < total_len) {
430 if ((total_len - bytes) < thisblock) {
431 thisblock = total_len - bytes;
432 if (thisblock == 0) {
438 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
439 if (StrBuf_ServGetln(Buf) > 0)
441 if (ChrPtr(Buf)[0] == '6')
443 StrBufCutLeft(Buf, 4); //thisblock = (size_t)atoi(&buf[4]);
444 thisblock = StrTol(Buf);
445 if (!WC->connected) {
450 StrBuf_ServGetBLOB(Ret, thisblock);
455 lprintf(3, "Error: %s\n", &buf[4]);
461 return StrLength(Ret);
466 * Read text from server, appending to a string buffer until the
467 * usual 000 terminator is found. Caller is responsible for freeing
468 * the returned pointer.
470 int read_server_text(StrBuf *Buf, long *nLines)
478 while ((WCC->serv_sock!=-1) &&
479 (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
481 if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
482 StrBufCutRight(Buf, nRead);
498 int GetServerStatus(StrBuf *Line, long* FullState)
500 if (FullState != NULL)
501 *FullState = StrTol(Line);
502 return ChrPtr(Line)[0] - 48;
506 void tmplput_serv_ip(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
508 StrBufAppendPrintf(Target, "%d", WC->ctdl_pid);
511 void tmplput_serv_nodename(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
513 StrEscAppend(Target, NULL, serv_info.serv_nodename, 0, 0);
516 void tmplput_serv_humannode(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
518 StrEscAppend(Target, NULL, serv_info.serv_humannode, 0, 0);
521 void tmplput_serv_fqdn(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
523 StrEscAppend(Target, NULL, serv_info.serv_fqdn, 0, 0);
526 void tmplput_serv_software(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
528 StrEscAppend(Target, NULL, serv_info.serv_software, 0, 0);
531 void tmplput_serv_rev_level(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
533 StrBufAppendPrintf(Target, "%d.%02d",
534 serv_info.serv_rev_level / 100,
535 serv_info.serv_rev_level % 100);
537 int conditional_serv_newuser_disabled(WCTemplateToken *Tokens, void *Context, int ContextType)
539 return serv_info.serv_newuser_disabled != 0;
541 int conditional_serv_supports_openid(WCTemplateToken *Tokens, void *Context, int ContextType)
543 return serv_info.serv_supports_openid != 0;
546 void tmplput_serv_bbs_city(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
548 StrEscAppend(Target, NULL, serv_info.serv_bbs_city, 0, 0);
551 void tmplput_current_user(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
553 StrEscAppend(Target, NULL, WC->wc_fullname, 0, 0);
556 void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
558 StrEscAppend(Target, NULL, WC->wc_roomname, 0, 0);
562 void tmplput_mesg(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
571 serv_printf("MESG %s", Tokens->Params[0]->Start);
572 StrBuf_ServGetln(Line);
573 while (!Done && (StrBuf_ServGetln(Line)>=0)) {
574 if ( (StrLength(Line)==3) &&
575 !strcmp(ChrPtr(Line), "000"))
580 StrBufAppendBufPlain(Buf, "\n", 1, 0);
581 StrBufAppendBuf(Buf, Line, 0);
586 FmOut(Line, "center", Buf);
587 StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Line, 1);
597 RegisterConditional(HKEY("COND:SERV:OPENID"), 2, conditional_serv_supports_openid, CTX_NONE);
598 RegisterConditional(HKEY("COND:SERV:NEWU"), 2, conditional_serv_newuser_disabled, CTX_NONE);
599 RegisterNamespace("CURRENT_USER", 0, 0, tmplput_current_user, CTX_NONE);
600 RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room, CTX_NONE);
601 RegisterNamespace("SERV:PID", 0, 0, tmplput_serv_ip, CTX_NONE);
602 RegisterNamespace("SERV:NODENAME", 0, 0, tmplput_serv_nodename, CTX_NONE);
603 RegisterNamespace("SERV:HUMANNODE", 0, 0, tmplput_serv_humannode, CTX_NONE);
604 RegisterNamespace("SERV:FQDN", 0, 0, tmplput_serv_fqdn, CTX_NONE);
605 RegisterNamespace("SERV:SOFTWARE", 0, 0, tmplput_serv_software, CTX_NONE);
606 RegisterNamespace("SERV:REV_LEVEL", 0, 0, tmplput_serv_rev_level, CTX_NONE);
607 RegisterNamespace("SERV:BBS_CITY", 0, 0, tmplput_serv_bbs_city, CTX_NONE);
608 RegisterNamespace("SERV:MESG", 1, 2, tmplput_mesg, CTX_NONE);
609 /// RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmplput_serv_ldap_enabled, 0);