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 void fmout(char *align)
118 wprintf("<div align=%s>\n", align);
119 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
121 if ((intext == 1) && (isspace(buf[0]))) {
127 * Quoted text should be displayed in italics and in a
128 * different colour. This code understands Citadel-style
129 * " >" quotes and will convert to <BLOCKQUOTE> tags.
131 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
132 wprintf("<BLOCKQUOTE>");
134 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
135 wprintf("</BLOCKQUOTE>");
138 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
139 strcpy(buf, &buf[2]);
141 /** Activate embedded URL's */
142 url(buf, sizeof(buf));
150 wprintf("</div><br />\n");
157 * \brief Read Citadel variformat text and spit it out as HTML in a form
158 * suitable for embedding in another message (forward/quote).
159 * (NO LINEBREAKS ALLOWED HERE!)
161 void pullquote_fmout(void) {
166 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
168 if ((intext == 1) && (isspace(buf[0]))) {
174 * Quoted text should be displayed in italics and in a
175 * different colour. This code understands Citadel-style
176 * " >" quotes and will convert to <BLOCKQUOTE> tags.
178 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
179 wprintf("<BLOCKQUOTE>");
181 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
182 wprintf("</BLOCKQUOTE>");
185 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
186 strcpy(buf, &buf[2]);
200 * \brief Transmit message text (in memory) to the server.
202 * \param ptr Pointer to the message being transmitted
204 void text_to_server(char *ptr)
212 while (ptr[pos] != 0) {
216 while ( (isspace(buf[len - 1]))
218 && (buf[1] != '\0') )
222 if (ptr[pos] != 0) strcat(buf, " ");
227 if ((ch == 32) && (strlen(buf) > 200)) {
232 if (strlen(buf) > 250) {
243 * \brief Transmit message text (in memory) to the server,
244 * converting to Quoted-Printable encoding as we go.
246 * \param ptr Pointer to the message being transmitted
248 void text_to_server_qp(char *ptr)
250 unsigned char ch, buf[256];
258 while (ptr[pos] != 0) {
259 ch = (unsigned char)(ptr[pos++]);
262 /* ignore carriage returns */
265 /* hard line break */
266 if (output_len > 0) {
267 if (isspace(buf[output_len-1])) {
268 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
272 buf[output_len++] = 0;
273 serv_puts((char *)buf);
277 buf[output_len++] = ch;
279 else if ( (ch >= 32) && (ch <= 60) ) {
280 buf[output_len++] = ch;
282 else if ( (ch >= 62) && (ch <= 126) ) {
283 buf[output_len++] = ch;
286 sprintf((char *)&buf[output_len], "=%02X", ch);
290 if (output_len > 72) {
291 /* soft line break */
292 if (isspace(buf[output_len-1])) {
293 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
296 buf[output_len++] = '=';
297 buf[output_len++] = 0;
298 serv_puts((char *)buf);
303 /* end of data - transmit anything that's left */
304 if (output_len > 0) {
305 if (isspace(buf[output_len-1])) {
306 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
309 buf[output_len++] = 0;
310 serv_puts((char *)buf);
319 * \brief translate server message output to text
320 * (used for editing room info files and such)
322 void server_to_text()
328 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
329 if ((buf[0] == 32) && (count > 0)) {
340 * Read binary data from server into memory using a series of
341 * server READ commands.
342 * \param buffer the output buffer
343 * \param total_len the maximal length of buffer
345 void read_server_binary(char *buffer, size_t total_len) {
348 size_t thisblock = 0;
350 memset(buffer, 0, total_len);
351 while (bytes < total_len) {
353 if ((total_len - bytes) < thisblock) {
354 thisblock = total_len - bytes;
355 if (thisblock == 0) return;
357 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
358 serv_getln(buf, sizeof buf);
360 thisblock = (size_t)atoi(&buf[4]);
361 if (!WC->connected) return;
362 serv_read(&buffer[bytes], thisblock);
366 lprintf(3, "Error: %s\n", &buf[4]);
374 * \brief Read text from server, appending to a string buffer until the
375 * usual 000 terminator is found. Caller is responsible for freeing
376 * the returned pointer.
378 char *read_server_text(void) {
380 size_t bytes_allocated = 0;
381 size_t bytes_read = 0;
390 bytes_allocated = SIZ;
392 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
393 linelen = strlen(buf);
398 if ((bytes_read + linelen) >= (bytes_allocated - 2)) {
399 bytes_allocated = 2 * bytes_allocated;
400 text = realloc(text, bytes_allocated);
403 strcpy(&text[bytes_read], buf);
404 bytes_read += linelen;