]> code.citadel.org Git - citadel.git/blob - webcit/serv_func.c
* Rewrote the HTTP engine and application coupling to run in a worker thread
[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         while (1) {
106                 if (fp == NULL)
107                         serv_gets(buf);
108                 if (fp != NULL) {
109                         if (fgets(buf, 256, fp) == NULL)
110                                 strcpy(buf, "000");
111                         buf[strlen(buf) - 1] = 0;
112                 }
113                 if (!strcmp(buf, "000")) {
114                         if (bq == 1)
115                                 wprintf("</I>");
116                         wprintf("<P>\n");
117                         return;
118                 }
119                 if ((intext == 1) && (isspace(buf[0]))) {
120                         wprintf("<BR>");
121                 }
122                 intext = 1;
123
124                 /* Quoted text should be displayed in italics and in a
125                  * different colour.  This code understands both Citadel/UX
126                  * style " >" quotes and FordBoard-style " :-)" quotes.
127                  */
128                 if ((bq == 0) &&
129                     ((!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
130                         wprintf("<FONT COLOR=\"000044\"><I>");
131                         bq = 1;
132                 } else if ((bq == 1) &&
133                   (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
134                         wprintf("</FONT></I>");
135                         bq = 0;
136                 }
137                 /* Activate embedded URL's */
138                 url(buf);
139
140                 escputs(buf);
141                 wprintf("\n");
142         }
143 }
144
145
146
147
148
149
150 /*
151  * transmit message text (in memory) to the server
152  */
153 void text_to_server(char *ptr)
154 {
155         char buf[256];
156         int ch, a, pos;
157
158         pos = 0;
159
160         strcpy(buf, "");
161         while (ptr[pos] != 0) {
162                 ch = ptr[pos++];
163                 if (ch == 10) {
164                         while (isspace(buf[strlen(buf) - 1]))
165                                 buf[strlen(buf) - 1] = 0;
166                         serv_puts(buf);
167                         strcpy(buf, "");
168                 } else {
169                         a = strlen(buf);
170                         buf[a + 1] = 0;
171                         buf[a] = ch;
172                         if ((ch == 32) && (strlen(buf) > 200)) {
173                                 buf[a] = 0;
174                                 serv_puts(buf);
175                                 strcpy(buf, "");
176                         }
177                         if (strlen(buf) > 250) {
178                                 serv_puts(buf);
179                                 strcpy(buf, "");
180                         }
181                 }
182         }
183         serv_puts(buf);
184 }
185
186
187
188
189
190
191 /*
192  * translate server message output to text
193  * (used for editing room info files and such)
194  */
195 void server_to_text()
196 {
197         char buf[256];
198
199         int count = 0;
200
201         while (serv_gets(buf), strcmp(buf, "000")) {
202                 if ((buf[0] == 32) && (count > 0)) {
203                         wprintf("\n");
204                 }
205                 wprintf("%s", buf);
206                 ++count;
207         }
208 }