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 * \brief Read Citadel variformat text and spit it out as HTML.
110 * \param 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");
162 * \brief Read Citadel variformat text and spit it out as HTML in a form
163 * suitable for embedding in another message (forward/quote).
164 * (NO LINEBREAKS ALLOWED HERE!)
166 void pullquote_fmout(void) {
171 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
173 if ((intext == 1) && (isspace(buf[0]))) {
179 * Quoted text should be displayed in italics and in a
180 * different colour. This code understands Citadel-style
181 * " >" quotes and will convert to <BLOCKQUOTE> tags.
183 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
184 wprintf("<BLOCKQUOTE>");
186 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
187 wprintf("</BLOCKQUOTE>");
190 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
191 strcpy(buf, &buf[2]);
205 * \brief Transmit message text (in memory) to the server.
207 * \param ptr Pointer to the message being transmitted
209 void text_to_server(char *ptr)
217 while (ptr[pos] != 0) {
221 while ( (isspace(buf[len - 1]))
223 && (buf[1] != '\0') )
227 if (ptr[pos] != 0) strcat(buf, " ");
232 if ((ch == 32) && (strlen(buf) > 200)) {
237 if (strlen(buf) > 250) {
248 * \brief Transmit message text (in memory) to the server,
249 * converting to Quoted-Printable encoding as we go.
251 * \param ptr Pointer to the message being transmitted
253 void text_to_server_qp(char *ptr)
255 unsigned char ch, buf[256];
263 while (ptr[pos] != 0) {
264 ch = (unsigned char)(ptr[pos++]);
267 /* ignore carriage returns */
270 /* hard line break */
271 if (output_len > 0) {
272 if (isspace(buf[output_len-1])) {
273 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
277 buf[output_len++] = 0;
278 serv_puts((char *)buf);
282 buf[output_len++] = ch;
284 else if ( (ch >= 32) && (ch <= 60) ) {
285 buf[output_len++] = ch;
287 else if ( (ch >= 62) && (ch <= 126) ) {
288 buf[output_len++] = ch;
291 sprintf((char *)&buf[output_len], "=%02X", ch);
295 if (output_len > 72) {
296 /* soft line break */
297 if (isspace(buf[output_len-1])) {
298 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
301 buf[output_len++] = '=';
302 buf[output_len++] = 0;
303 serv_puts((char *)buf);
308 /* end of data - transmit anything that's left */
309 if (output_len > 0) {
310 if (isspace(buf[output_len-1])) {
311 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
314 buf[output_len++] = 0;
315 serv_puts((char *)buf);
324 * \brief translate server message output to text
325 * (used for editing room info files and such)
327 void server_to_text()
333 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
334 if ((buf[0] == 32) && (count > 0)) {
345 * Read binary data from server into memory using a series of
346 * server READ commands.
347 * \return the read content as StrBuf
349 int read_server_binary(StrBuf *Ret, size_t total_len)
353 size_t thisblock = 0;
360 while (bytes < total_len) {
362 if ((total_len - bytes) < thisblock) {
363 thisblock = total_len - bytes;
364 if (thisblock == 0) {
370 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
371 if (StrBuf_ServGetln(Buf) > 0)
373 if (ChrPtr(Buf)[0] == '6')
375 StrBufCutLeft(Buf, 4); //thisblock = (size_t)atoi(&buf[4]);
376 thisblock = StrTol(Buf);
377 if (!WC->connected) {
382 StrBuf_ServGetBLOB(Ret, thisblock);
387 lprintf(3, "Error: %s\n", &buf[4]);
393 return StrLength(Ret);
398 * \brief Read text from server, appending to a string buffer until the
399 * usual 000 terminator is found. Caller is responsible for freeing
400 * the returned pointer.
402 int read_server_text(StrBuf *Buf, long *nLines)
404 struct wcsession *WCC = WC;
410 while ((WCC->serv_sock!=-1) &&
411 (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
413 if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
414 StrBufCutRight(Buf, nRead);