8 struct serv_info serv_info; /**< our connection data to the server */
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);
35 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
37 * Tell the server that when we save a calendar event, we
38 * want invitations to be generated by the Citadel server
39 * instead of by the client.
41 serv_puts("ICAL sgi|1");
42 serv_getln(buf, sizeof buf);
45 /** Now ask the server to tell us a little bit about itself... */
47 serv_getln(buf, sizeof buf);
52 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
55 serv_info.serv_pid = atoi(buf);
56 WC->ctdl_pid = serv_info.serv_pid;
59 safestrncpy(serv_info.serv_nodename, buf, sizeof serv_info.serv_nodename);
62 safestrncpy(serv_info.serv_humannode, buf, sizeof serv_info.serv_humannode);
65 safestrncpy(serv_info.serv_fqdn, buf, sizeof serv_info.serv_fqdn);
68 safestrncpy(serv_info.serv_software, buf, sizeof serv_info.serv_software);
71 serv_info.serv_rev_level = atoi(buf);
74 safestrncpy(serv_info.serv_bbs_city, buf, sizeof serv_info.serv_bbs_city);
77 safestrncpy(serv_info.serv_sysadm, buf, sizeof serv_info.serv_sysadm);
80 safestrncpy(serv_info.serv_moreprompt, buf, sizeof serv_info.serv_moreprompt);
83 serv_info.serv_supports_ldap = atoi(buf);
86 serv_info.serv_newuser_disabled = atoi(buf);
89 safestrncpy(serv_info.serv_default_cal_zone, buf, sizeof serv_info.serv_default_cal_zone);
92 serv_info.serv_supports_sieve = atoi(buf);
95 serv_info.serv_fulltext_enabled = atoi(buf);
105 * \brief Read Citadel variformat text and spit it out as HTML.
106 * \param align html align string
108 void fmout(char *align)
114 wprintf("<div align=%s>\n", align);
115 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
117 if ((intext == 1) && (isspace(buf[0]))) {
123 * Quoted text should be displayed in italics and in a
124 * different colour. This code understands Citadel-style
125 * " >" quotes and will convert to <BLOCKQUOTE> tags.
127 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
128 wprintf("<BLOCKQUOTE>");
130 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
131 wprintf("</BLOCKQUOTE>");
134 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
135 strcpy(buf, &buf[2]);
137 /** Activate embedded URL's */
146 wprintf("</div><br />\n");
153 * \brief Read Citadel variformat text and spit it out as HTML in a form
154 * suitable for embedding in another message (forward/quote).
155 * (NO LINEBREAKS ALLOWED HERE!)
157 void pullquote_fmout(void) {
162 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
164 if ((intext == 1) && (isspace(buf[0]))) {
170 * Quoted text should be displayed in italics and in a
171 * different colour. This code understands Citadel-style
172 * " >" quotes and will convert to <BLOCKQUOTE> tags.
174 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
175 wprintf("<BLOCKQUOTE>");
177 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
178 wprintf("</BLOCKQUOTE>");
181 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
182 strcpy(buf, &buf[2]);
196 * \brief Transmit message text (in memory) to the server.
198 * \param ptr Pointer to the message being transmitted
200 void text_to_server(char *ptr)
208 while (ptr[pos] != 0) {
212 while ( (isspace(buf[len - 1]))
214 && (buf[1] != '\0') )
218 if (ptr[pos] != 0) strcat(buf, " ");
223 if ((ch == 32) && (strlen(buf) > 200)) {
228 if (strlen(buf) > 250) {
239 * \brief Transmit message text (in memory) to the server,
240 * converting to Quoted-Printable encoding as we go.
242 * \param ptr Pointer to the message being transmitted
244 void text_to_server_qp(char *ptr)
246 unsigned char ch, buf[256];
254 while (ptr[pos] != 0) {
255 ch = (unsigned char)(ptr[pos++]);
258 /* ignore carriage returns */
261 /* hard line break */
262 if (output_len > 0) {
263 if (isspace(buf[output_len-1])) {
264 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
268 buf[output_len++] = 0;
269 serv_puts((char *)buf);
273 buf[output_len++] = ch;
275 else if ( (ch >= 32) && (ch <= 60) ) {
276 buf[output_len++] = ch;
278 else if ( (ch >= 62) && (ch <= 126) ) {
279 buf[output_len++] = ch;
282 sprintf((char *)&buf[output_len], "=%02X", ch);
286 if (output_len > 72) {
287 /* soft line break */
288 if (isspace(buf[output_len-1])) {
289 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
292 buf[output_len++] = '=';
293 buf[output_len++] = 0;
294 serv_puts((char *)buf);
299 /* end of data - transmit anything that's left */
300 if (output_len > 0) {
301 if (isspace(buf[output_len-1])) {
302 sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
305 buf[output_len++] = 0;
306 serv_puts((char *)buf);
315 * \brief translate server message output to text
316 * (used for editing room info files and such)
318 void server_to_text()
324 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
325 if ((buf[0] == 32) && (count > 0)) {
336 * Read binary data from server into memory using a series of
337 * server READ commands.
338 * \param buffer the output buffer
339 * \param total_len the maximal length of buffer
341 void read_server_binary(char *buffer, size_t total_len) {
344 size_t thisblock = 0;
346 memset(buffer, 0, total_len);
347 while (bytes < total_len) {
349 if ((total_len - bytes) < thisblock) {
350 thisblock = total_len - bytes;
351 if (thisblock == 0) return;
353 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
354 serv_getln(buf, sizeof buf);
356 thisblock = (size_t)atoi(&buf[4]);
357 if (!WC->connected) return;
358 serv_read(&buffer[bytes], thisblock);
362 lprintf(3, "Error: %s\n", &buf[4]);
370 * \brief Read text from server, appending to a string buffer until the
371 * usual 000 terminator is found. Caller is responsible for freeing
372 * the returned pointer.
374 char *read_server_text(void) {
376 size_t bytes_allocated = 0;
377 size_t bytes_read = 0;
386 bytes_allocated = SIZ;
388 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
389 linelen = strlen(buf);
394 if ((bytes_read + linelen) >= (bytes_allocated - 2)) {
395 bytes_allocated = 2 * bytes_allocated;
396 text = realloc(text, bytes_allocated);
399 strcpy(&text[bytes_read], buf);
400 bytes_read += linelen;