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