750ec7d2f4fbb0506731b82c37ab98580dabef70
[citadel.git] / webcit / serv_func.c
1 /* $Id$ */
2
3 #include <ctype.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #ifdef HAVE_UNISTD_H
7 #include <unistd.h>
8 #endif
9 #include <stdio.h>
10 #include "webcit.h"
11 #include "child.h"
12
13 struct serv_info serv_info;
14
15 /*
16  * get info about the server we've WC->connected to
17  */
18 void get_serv_info(char *browser_host, char *user_agent)
19 {
20         char buf[256];
21         int a;
22
23         serv_printf("IDEN %d|%d|%d|%s|%s",
24                 DEVELOPER_ID,
25                 CLIENT_ID,
26                 CLIENT_VERSION,
27                 user_agent,
28                 browser_host
29         );
30         serv_gets(buf);
31
32         serv_puts("INFO");
33         serv_gets(buf);
34         if (buf[0] != '1')
35                 return;
36
37         a = 0;
38         while (serv_gets(buf), strcmp(buf, "000")) {
39                 switch (a) {
40                 case 0:
41                         serv_info.serv_pid = atoi(buf);
42                         break;
43                 case 1:
44                         strcpy(serv_info.serv_nodename, buf);
45                         break;
46                 case 2:
47                         strcpy(serv_info.serv_humannode, buf);
48                         break;
49                 case 3:
50                         strcpy(serv_info.serv_fqdn, buf);
51                         break;
52                 case 4:
53                         strcpy(serv_info.serv_software, buf);
54                         break;
55                 case 5:
56                         serv_info.serv_rev_level = atoi(buf);
57                         break;
58                 case 6:
59                         strcpy(serv_info.serv_bbs_city, buf);
60                         break;
61                 case 7:
62                         strcpy(serv_info.serv_sysadm, buf);
63                         break;
64                 case 9:
65                         strcpy(serv_info.serv_moreprompt, buf);
66                         break;
67                 }
68                 ++a;
69         }
70 }
71
72
73
74 /* 
75  * Function to spit out Citadel variformat text in HTML
76  * If fp is non-null, it is considered to be the file handle to read the
77  * text from.  Otherwise, text is read from the server.
78  */
79 void fmout(FILE * fp)
80 {
81
82         int intext = 0;
83         int bq = 0;
84         char buf[256];
85
86         while (1) {
87                 if (fp == NULL)
88                         serv_gets(buf);
89                 if (fp != NULL) {
90                         if (fgets(buf, 256, fp) == NULL)
91                                 strcpy(buf, "000");
92                         buf[strlen(buf) - 1] = 0;
93                 }
94                 if (!strcmp(buf, "000")) {
95                         if (bq == 1)
96                                 wprintf("</I>");
97                         wprintf("<P>\n");
98                         return;
99                 }
100                 if ((intext == 1) && (isspace(buf[0]))) {
101                         wprintf("<BR>");
102                 }
103                 intext = 1;
104
105                 /* Quoted text should be displayed in italics and in a
106                  * different colour.  This code understands both Citadel/UX
107                  * style " >" quotes and FordBoard-style " :-)" quotes.
108                  */
109                 if ((bq == 0) &&
110                     ((!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
111                         wprintf("<FONT COLOR=\"000044\"><I>");
112                         bq = 1;
113                 } else if ((bq == 1) &&
114                   (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
115                         wprintf("</FONT></I>");
116                         bq = 0;
117                 }
118                 /* Activate embedded URL's */
119                 url(buf);
120
121                 escputs(buf);
122                 wprintf("\n");
123         }
124 }
125
126
127
128
129
130
131 /*
132  * transmit message text (in memory) to the server
133  */
134 void text_to_server(char *ptr)
135 {
136         char buf[256];
137         int ch, a, pos;
138
139         pos = 0;
140
141         strcpy(buf, "");
142         while (ptr[pos] != 0) {
143                 ch = ptr[pos++];
144                 if (ch == 10) {
145                         while (isspace(buf[strlen(buf) - 1]))
146                                 buf[strlen(buf) - 1] = 0;
147                         serv_puts(buf);
148                         strcpy(buf, "");
149                 } else {
150                         a = strlen(buf);
151                         buf[a + 1] = 0;
152                         buf[a] = ch;
153                         if ((ch == 32) && (strlen(buf) > 200)) {
154                                 buf[a] = 0;
155                                 serv_puts(buf);
156                                 strcpy(buf, "");
157                         }
158                         if (strlen(buf) > 250) {
159                                 serv_puts(buf);
160                                 strcpy(buf, "");
161                         }
162                 }
163         }
164         serv_puts(buf);
165 }
166
167
168
169
170
171
172 /*
173  * translate server message output to text
174  * (used for editing room info files and such)
175  */
176 void server_to_text()
177 {
178         char buf[256];
179
180         int count = 0;
181
182         while (serv_gets(buf), strcmp(buf, "000")) {
183                 if ((buf[0] == 32) && (count > 0)) {
184                         wprintf("\n");
185                 }
186                 wprintf("%s", buf);
187                 ++count;
188         }
189 }