4 * Handles various types of data transfer operations with the Citadel service.
11 struct serv_info serv_info;
14 * get info about the server we've connected to
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
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);
44 /* Now ask the server to tell us a little bit about itself... */
46 serv_getln(buf, sizeof buf);
51 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
54 serv_info.serv_pid = atoi(buf);
55 WC->ctdl_pid = serv_info.serv_pid;
58 safestrncpy(serv_info.serv_nodename, buf, sizeof serv_info.serv_nodename);
61 safestrncpy(serv_info.serv_humannode, buf, sizeof serv_info.serv_humannode);
64 safestrncpy(serv_info.serv_fqdn, buf, sizeof serv_info.serv_fqdn);
67 safestrncpy(serv_info.serv_software, buf, sizeof serv_info.serv_software);
70 serv_info.serv_rev_level = atoi(buf);
73 safestrncpy(serv_info.serv_bbs_city, buf, sizeof serv_info.serv_bbs_city);
76 safestrncpy(serv_info.serv_sysadm, buf, sizeof serv_info.serv_sysadm);
79 safestrncpy(serv_info.serv_moreprompt, buf, sizeof serv_info.serv_moreprompt);
82 serv_info.serv_supports_ldap = atoi(buf);
92 * Read Citadel variformat text and spit it out as HTML.
94 void fmout(char *align)
100 wprintf("<div align=%s>\n", align);
101 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
103 if ((intext == 1) && (isspace(buf[0]))) {
108 /* Quoted text should be displayed in italics and in a
109 * different colour. This code understands Citadel-style
110 * " >" quotes and will convert to <BLOCKQUOTE> tags.
112 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
113 wprintf("<BLOCKQUOTE>");
115 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
116 wprintf("</BLOCKQUOTE>");
119 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
120 strcpy(buf, &buf[2]);
122 /* Activate embedded URL's */
131 wprintf("</div><br />\n");
138 * Read Citadel variformat text and spit it out as HTML in a form
139 * suitable for embedding in another message (forward/quote).
140 * (NO LINEBREAKS ALLOWED HERE!)
142 void pullquote_fmout(void) {
147 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
149 if ((intext == 1) && (isspace(buf[0]))) {
154 /* Quoted text should be displayed in italics and in a
155 * different colour. This code understands Citadel-style
156 * " >" quotes and will convert to <BLOCKQUOTE> tags.
158 if ((bq == 0) && (!strncmp(buf, " >", 2))) {
159 wprintf("<BLOCKQUOTE>");
161 } else if ((bq == 1) && (strncmp(buf, " >", 2))) {
162 wprintf("</BLOCKQUOTE>");
165 if ((bq == 1) && (!strncmp(buf, " >", 2))) {
166 strcpy(buf, &buf[2]);
180 * Transmit message text (in memory) to the server.
181 * If convert_to_html is set to 1, the message is converted into something
182 * which kind of resembles HTML.
184 void text_to_server(char *ptr, int convert_to_html)
193 while (ptr[pos] != 0) {
196 while ( (isspace(buf[strlen(buf) - 1]))
197 && (strlen(buf) > 1) )
198 buf[strlen(buf) - 1] = 0;
201 if (convert_to_html) {
202 strcat(buf, "<br />");
205 if (ptr[pos] != 0) strcat(buf, " ");
207 } else if ((convert_to_html)&&(strchr("#&;`'|*?-~<>^()[]{}$\\", ch) != NULL)) {
208 sprintf(conv, "%c", ch);
209 stresc(&buf[strlen(buf)], conv, 0, 0);
214 if ((ch == 32) && (strlen(buf) > 200)) {
219 if (strlen(buf) > 250) {
232 * translate server message output to text
233 * (used for editing room info files and such)
235 void server_to_text()
241 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
242 if ((buf[0] == 32) && (count > 0)) {
253 * Read binary data from server into memory using a series of
254 * server READ commands.
256 void read_server_binary(char *buffer, size_t total_len) {
259 size_t thisblock = 0;
261 memset(buffer, 0, total_len);
262 while (bytes < total_len) {
264 if ((total_len - bytes) < thisblock) {
265 thisblock = total_len - bytes;
266 if (thisblock == 0) return;
268 serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
269 serv_getln(buf, sizeof buf);
271 thisblock = (size_t)atoi(&buf[4]);
272 if (!WC->connected) return;
273 serv_read(&buffer[bytes], thisblock);
277 lprintf(3, "Error: %s\n", &buf[4]);
285 * Read text from server, appending to a string buffer until the
286 * usual 000 terminator is found. Caller is responsible for freeing
287 * the returned pointer.
289 char *read_server_text(void) {
291 size_t bytes_allocated = 0;
292 size_t bytes_read = 0;
301 bytes_allocated = SIZ;
303 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
304 linelen = strlen(buf);
309 if ((bytes_read + linelen) >= (bytes_allocated - 2)) {
310 bytes_allocated = 2 * bytes_allocated;
311 text = realloc(text, bytes_allocated);
314 strcpy(&text[bytes_read], buf);
315 bytes_read += linelen;