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);
106 * \brief Read Citadel variformat text and spit it out as HTML.
107 * \param align html align string
109 void fmout(char *align)
115 wprintf("<div align=%s>\n", align);
116 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
118 if ((intext == 1) && (isspace(buf[0]))) {
124 * Quoted text should be displayed in italics and in a
125 * different colour. This code understands Citadel-style
126 * " >" quotes and will convert to <BLOCKQUOTE> tags.
128 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
129 wprintf("<BLOCKQUOTE>");
131 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
132 wprintf("</BLOCKQUOTE>");
135 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
136 strcpy(buf, &buf[2]);
138 /** Activate embedded URL's */
139 url(buf, sizeof(buf));
147 wprintf("</div><br />\n");
154 * \brief Read Citadel variformat text and spit it out as HTML in a form
155 * suitable for embedding in another message (forward/quote).
156 * (NO LINEBREAKS ALLOWED HERE!)
158 void pullquote_fmout(void) {
163 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
165 if ((intext == 1) && (isspace(buf[0]))) {
171 * Quoted text should be displayed in italics and in a
172 * different colour. This code understands Citadel-style
173 * " >" quotes and will convert to <BLOCKQUOTE> tags.
175 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
176 wprintf("<BLOCKQUOTE>");
178 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
179 wprintf("</BLOCKQUOTE>");
182 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
183 strcpy(buf, &buf[2]);
197 * \brief Transmit message text (in memory) to the server.
199 * \param ptr Pointer to the message being transmitted
201 void text_to_server(char *ptr)
209 while (ptr[pos] != 0) {
213 while ( (isspace(buf[len - 1]))
215 && (buf[1] != '\0') )
219 if (ptr[pos] != 0) strcat(buf, " ");
224 if ((ch == 32) && (strlen(buf) > 200)) {
229 if (strlen(buf) > 250) {
240 * \brief Transmit message text (in memory) to the server,
241 * converting to Quoted-Printable encoding as we go.
243 * \param ptr Pointer to the message being transmitted
245 void text_to_server_qp(char *ptr)
247 unsigned char ch, buf[256];
255 while (ptr[pos] != 0) {
256 ch = (unsigned char)(ptr[pos++]);
259 /* ignore carriage returns */
262 /* hard line break */
263 if (output_len > 0) {
264 if (isspace(buf[output_len-1])) {
265 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
269 buf[output_len++] = 0;
270 serv_puts((char *)buf);
274 buf[output_len++] = ch;
276 else if ( (ch >= 32) && (ch <= 60) ) {
277 buf[output_len++] = ch;
279 else if ( (ch >= 62) && (ch <= 126) ) {
280 buf[output_len++] = ch;
283 sprintf((char *)&buf[output_len], "=%02X", ch);
287 if (output_len > 72) {
288 /* soft line break */
289 if (isspace(buf[output_len-1])) {
290 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
293 buf[output_len++] = '=';
294 buf[output_len++] = 0;
295 serv_puts((char *)buf);
300 /* end of data - transmit anything that's left */
301 if (output_len > 0) {
302 if (isspace(buf[output_len-1])) {
303 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
306 buf[output_len++] = 0;
307 serv_puts((char *)buf);
316 * \brief translate server message output to text
317 * (used for editing room info files and such)
319 void server_to_text()
325 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
326 if ((buf[0] == 32) && (count > 0)) {
337 * Read binary data from server into memory using a series of
338 * server READ commands.
339 * \param buffer the output buffer
340 * \param total_len the maximal length of buffer
342 void read_server_binary(char *buffer, size_t total_len) {
345 size_t thisblock = 0;
347 memset(buffer, 0, total_len);
348 while (bytes < total_len) {
350 if ((total_len - bytes) < thisblock) {
351 thisblock = total_len - bytes;
352 if (thisblock == 0) return;
354 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
355 serv_getln(buf, sizeof buf);
357 thisblock = (size_t)atoi(&buf[4]);
358 if (!WC->connected) return;
359 serv_read(&buffer[bytes], thisblock);
363 lprintf(3, "Error: %s\n", &buf[4]);
371 * \brief Read text from server, appending to a string buffer until the
372 * usual 000 terminator is found. Caller is responsible for freeing
373 * the returned pointer.
375 char *read_server_text(void) {
377 size_t bytes_allocated = 0;
378 size_t bytes_read = 0;
387 bytes_allocated = SIZ;
389 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
390 linelen = strlen(buf);
395 if ((bytes_read + linelen) >= (bytes_allocated - 2)) {
396 bytes_allocated = 2 * bytes_allocated;
397 text = realloc(text, bytes_allocated);
400 strcpy(&text[bytes_read], buf);
401 bytes_read += linelen;