Mercurial > dillo_port1.3
annotate dpid/main.c @ 2104:3e7e5395f0bc
non-ASCII keybindings
Alexander Voigt has kindly done some testing, and it seems that this
makes bindings to most keys on a German keyboard possible -- except
those that need AltGr don't work yet.
author | corvid <corvid@lavabit.com> |
---|---|
date | Thu, 23 Jun 2011 19:24:11 +0000 |
parents | 3a159d7e5098 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 Copyright (C) 2003 Ferdi Franceschini <ferdif@optusnet.com.au> | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
972
d7dbd3dcfa38
Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents:
368
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 16 */ |
17 | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
18 #include <errno.h> /* for ckd_write */ |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
19 #include <unistd.h> /* for ckd_write */ |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
20 #include <stdlib.h> /* for exit */ |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
21 #include <assert.h> /* for assert */ |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
22 #include <sys/stat.h> /* for umask */ |
1223
a09dbf132be6
Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents:
972
diff
changeset
|
23 |
0 | 24 #include "dpid_common.h" |
25 #include "dpid.h" | |
26 #include "dpi.h" | |
27 #include "dpi_socket_dir.h" | |
28 #include "misc_new.h" | |
29 #include "../dpip/dpip.h" | |
30 | |
31 sigset_t mask_sigchld; | |
32 | |
33 | |
34 /* Start a dpi filter plugin after accepting the pending connection | |
35 * \Return | |
36 * \li Child process ID on success | |
37 * \li 0 on failure | |
38 */ | |
39 static int start_filter_plugin(struct dp dpi_attr) | |
40 { | |
41 int newsock, old_stdout=-1, old_stdin=-1; | |
42 socklen_t csz; | |
43 struct sockaddr_un clnt_addr; | |
44 pid_t pid; | |
45 | |
46 csz = (socklen_t) sizeof(clnt_addr); | |
47 | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
48 newsock = accept(dpi_attr.sock_fd, (struct sockaddr *) &clnt_addr, &csz); |
0 | 49 if (newsock == -1) |
50 ERRMSG("start_plugin", "accept", errno); | |
51 | |
52 dup2(STDIN_FILENO, old_stdin); | |
53 if (dup2(newsock, STDIN_FILENO) == -1) { | |
54 ERRMSG("start_plugin", "dup2", errno); | |
55 MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path); | |
56 exit(1); | |
57 } | |
58 | |
59 dup2(STDOUT_FILENO, old_stdout); | |
60 if (dup2(newsock, STDOUT_FILENO) == -1) { | |
61 ERRMSG("start_plugin", "dup2", errno); | |
62 MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path); | |
63 exit(1); | |
64 } | |
65 if ((pid = fork()) == -1) { | |
66 ERRMSG("main", "fork", errno); | |
67 return 0; | |
68 } | |
69 if (pid == 0) { | |
70 /* Child, start plugin */ | |
1230
60fb2b1b6220
Cast NULL sentinel to (char*) for execl (fix for LP64 arch).
Jorge Arellano Cid <jcid@dillo.org>
parents:
1223
diff
changeset
|
71 if (execl(dpi_attr.path, dpi_attr.path, (char*)NULL) == -1) { |
0 | 72 ERRMSG("start_plugin", "execl", errno); |
73 MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path); | |
74 exit(1); | |
75 } | |
76 } | |
77 | |
78 /* Parent, Close sockets fix stdio and return pid */ | |
79 if (a_Misc_close_fd(newsock) == -1) { | |
80 ERRMSG("start_plugin", "close", errno); | |
81 MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path); | |
82 exit(1); | |
83 } | |
84 a_Misc_close_fd(STDIN_FILENO); | |
85 a_Misc_close_fd(STDOUT_FILENO); | |
86 dup2(old_stdin, STDIN_FILENO); | |
87 dup2(old_stdout, STDOUT_FILENO); | |
88 return pid; | |
89 } | |
90 | |
91 static void start_server_plugin(struct dp dpi_attr) | |
92 { | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
93 if (dup2(dpi_attr.sock_fd, STDIN_FILENO) == -1) { |
0 | 94 ERRMSG("start_plugin", "dup2", errno); |
95 MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path); | |
96 exit(1); | |
97 } | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
98 if (a_Misc_close_fd(dpi_attr.sock_fd) == -1) { |
0 | 99 ERRMSG("start_plugin", "close", errno); |
100 MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path); | |
101 exit(1); | |
102 } | |
1230
60fb2b1b6220
Cast NULL sentinel to (char*) for execl (fix for LP64 arch).
Jorge Arellano Cid <jcid@dillo.org>
parents:
1223
diff
changeset
|
103 if (execl(dpi_attr.path, dpi_attr.path, (char*)NULL) == -1) { |
0 | 104 ERRMSG("start_plugin", "execl", errno); |
105 MSG_ERR("ERROR in child proc for %s\n", dpi_attr.path); | |
106 exit(1); | |
107 } | |
108 } | |
109 | |
110 /*! | |
111 * Read service request from sock | |
112 * \Return | |
113 * pointer to dynamically allocated request tag | |
114 */ | |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
115 static char *get_request(Dsh *sh) |
0 | 116 { |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
117 char *dpip_tag; |
0 | 118 |
119 (void) sigprocmask(SIG_BLOCK, &mask_sigchld, NULL); | |
1388
eb35203124e4
Implemented the file dpi based on select() (removed its pthreads dependency)
Jorge Arellano Cid <jcid@dillo.org>
parents:
1387
diff
changeset
|
120 dpip_tag = a_Dpip_dsh_read_token(sh, 1); |
0 | 121 (void) sigprocmask(SIG_UNBLOCK, &mask_sigchld, NULL); |
122 | |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
123 return dpip_tag; |
0 | 124 } |
125 | |
126 /*! | |
127 * Get value of cmd field in dpi_tag | |
128 * \Return | |
129 * command code on success, -1 on failure | |
130 */ | |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
131 static int get_command(Dsh *sh, char *dpi_tag) |
0 | 132 { |
133 char *cmd, *d_cmd; | |
134 int COMMAND; | |
135 | |
136 if (dpi_tag == NULL) { | |
137 _ERRMSG("get_command", "dpid tag is NULL", 0); | |
138 return (-1); | |
139 } | |
140 | |
1236
b912173aecd1
Added a_Dpip_get_attr_l() to DPIP's API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1230
diff
changeset
|
141 cmd = a_Dpip_get_attr(dpi_tag, "cmd"); |
0 | 142 |
143 if (cmd == NULL) { | |
144 ERRMSG("get_command", "a_Dpip_get_attr", 0); | |
145 MSG_ERR(": dpid failed to parse cmd in %s\n", dpi_tag); | |
146 d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", | |
147 "DpiError", "Failed to parse request"); | |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
148 a_Dpip_dsh_write_str(sh, 1, d_cmd); |
0 | 149 dFree(d_cmd); |
150 COMMAND = -1; | |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
151 } else if (strcmp("auth", cmd) == 0) { |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
152 COMMAND = AUTH_CMD; |
0 | 153 } else if (strcmp("DpiBye", cmd) == 0) { |
154 COMMAND = BYE_CMD; | |
155 } else if (strcmp("check_server", cmd) == 0) { | |
156 COMMAND = CHECK_SERVER_CMD; | |
157 } else if (strcmp("register_all", cmd) == 0) { | |
158 COMMAND = REGISTER_ALL_CMD; | |
159 } else if (strcmp("register_service", cmd) == 0) { | |
160 COMMAND = REGISTER_SERVICE_CMD; | |
161 } else { /* Error unknown command */ | |
162 COMMAND = UNKNOWN_CMD; | |
163 } | |
164 | |
165 dFree(cmd); | |
166 return (COMMAND); | |
167 } | |
168 | |
169 /* | |
170 * Check whether a dpi server is running | |
171 */ | |
84 | 172 static int server_is_running(char *server_id) |
0 | 173 { |
174 int i; | |
175 | |
176 /* Search in the set of running servers */ | |
177 for (i = 0; i < numdpis; i++) { | |
178 if (!dpi_attr_list[i].filter && dpi_attr_list[i].pid > 1 && | |
179 strcmp(dpi_attr_list[i].id, server_id) == 0) | |
180 return 1; | |
181 } | |
182 return 0; | |
183 } | |
184 | |
185 | |
186 /* | |
187 * Get MAX open FD limit (yes, it's tricky --Jcid). | |
188 */ | |
189 static int get_open_max(void) | |
190 { | |
191 #ifdef OPEN_MAX | |
192 return OPEN_MAX; | |
193 #else | |
194 int ret = sysconf(_SC_OPEN_MAX); | |
195 if (ret < 0) | |
196 ret = 256; | |
197 return ret; | |
198 #endif | |
199 } | |
200 | |
201 /*! \todo | |
202 * \li Add a dpid_idle_timeout variable to dpidrc | |
203 * \bug Infinite loop if plugin crashes before it accepts a connection | |
204 */ | |
205 int main(void) | |
206 { | |
207 int i, n = 0, open_max; | |
208 int dpid_idle_timeout = 60 * 60; /* default, in seconds */ | |
209 struct timeval select_timeout; | |
210 sigset_t mask_none; | |
211 fd_set selected_set; | |
212 | |
213 dpi_attr_list = NULL; | |
67
ec671a7ea6e2
- * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents:
0
diff
changeset
|
214 services_list = NULL; |
0 | 215 //daemon(0,0); /* Use 0,1 for feedback */ |
368 | 216 /* TODO: call setsid() ?? */ |
0 | 217 |
218 /* Allow read and write access, but only for the user. | |
368 | 219 * TODO: can this cause trouble with umount? */ |
0 | 220 umask(0077); |
368 | 221 /* TODO: make dpid work on any directory. */ |
0 | 222 // chdir("/"); |
223 | |
224 /* close inherited file descriptors */ | |
225 open_max = get_open_max(); | |
226 for (i = 3; i < open_max; i++) | |
227 a_Misc_close_fd(i); | |
228 | |
229 /* this sleep used to unmask a race condition */ | |
230 // sleep(2); | |
231 | |
232 dpi_errno = no_errors; | |
233 | |
234 /* Get list of available dpis */ | |
235 numdpis = register_all(&dpi_attr_list); | |
236 | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
237 #if 0 |
0 | 238 /* Get name of socket directory */ |
239 dirname = a_Dpi_sockdir_file(); | |
240 if ((sockdir = init_sockdir(dirname)) == NULL) { | |
241 ERRMSG("main", "init_sockdir", 0); | |
242 MSG_ERR("Failed to create socket directory\n"); | |
243 exit(1); | |
244 } | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
245 #endif |
0 | 246 |
67
ec671a7ea6e2
- * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents:
0
diff
changeset
|
247 /* Init and get services list */ |
ec671a7ea6e2
- * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents:
0
diff
changeset
|
248 fill_services_list(dpi_attr_list, numdpis, &services_list); |
ec671a7ea6e2
- * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents:
0
diff
changeset
|
249 |
0 | 250 /* Remove any sockets that may have been leftover from a crash */ |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
251 //cleanup(); |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
252 |
0 | 253 /* Initialise sockets */ |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
254 if ((numsocks = init_ids_srs_socket()) == -1) { |
0 | 255 switch (dpi_errno) { |
256 case dpid_srs_addrinuse: | |
257 MSG_ERR("dpid refuses to start, possibly because:\n"); | |
258 MSG_ERR("\t1) An instance of dpid is already running.\n"); | |
259 MSG_ERR("\t2) A previous dpid didn't clean up on exit.\n"); | |
260 exit(1); | |
261 default: | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
262 //ERRMSG("main", "init_srs_socket failed", 0); |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
263 ERRMSG("main", "init_ids_srs_socket failed", 0); |
0 | 264 exit(1); |
265 } | |
266 } | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
267 numsocks = init_all_dpi_sockets(dpi_attr_list); |
1550
3a159d7e5098
remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1388
diff
changeset
|
268 est_dpi_terminator(); |
0 | 269 est_dpi_sigchld(); |
270 | |
271 (void) sigemptyset(&mask_sigchld); | |
272 (void) sigaddset(&mask_sigchld, SIGCHLD); | |
273 (void) sigemptyset(&mask_none); | |
274 (void) sigprocmask(SIG_SETMASK, &mask_none, NULL); | |
275 | |
276 printf("dpid started\n"); | |
277 /* Start main loop */ | |
278 while (1) { | |
279 do { | |
280 (void) sigprocmask(SIG_BLOCK, &mask_sigchld, NULL); | |
281 if (caught_sigchld) { | |
282 handle_sigchld(); | |
283 caught_sigchld = 0; | |
284 } | |
285 (void) sigprocmask(SIG_UNBLOCK, &mask_sigchld, NULL); | |
286 select_timeout.tv_sec = dpid_idle_timeout; | |
287 select_timeout.tv_usec = 0; | |
288 selected_set = sock_set; | |
289 n = select(FD_SETSIZE, &selected_set, NULL, NULL, &select_timeout); | |
290 if (n == 0) { /* select timed out, try to exit */ | |
291 /* BUG: This is a workaround for dpid not to exit when the | |
292 * downloads server is active. The proper way to handle it is with | |
293 * a dpip command that asks the server whether it's busy. | |
294 * Note: the cookies server may lose session info too. */ | |
295 if (server_is_running("downloads")) | |
296 continue; | |
297 | |
298 stop_active_dpis(dpi_attr_list, numdpis); | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
299 //cleanup(); |
0 | 300 exit(0); |
301 } | |
302 } while (n == -1 && errno == EINTR); | |
303 | |
304 if (n == -1) { | |
305 ERRMSG("main", "select", errno); | |
306 exit(1); | |
307 } | |
308 /* If the service req socket is selected then service the req. */ | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
309 if (FD_ISSET(srs_fd, &selected_set)) { |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
310 int sock_fd; |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
311 socklen_t sin_sz; |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
312 struct sockaddr_in sin; |
0 | 313 char *req = NULL; |
314 | |
315 --n; | |
316 assert(n >= 0); | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
317 sin_sz = (socklen_t) sizeof(sin); |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
318 sock_fd = accept(srs_fd, (struct sockaddr *)&sin, &sin_sz); |
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
319 if (sock_fd == -1) { |
0 | 320 ERRMSG("main", "accept", errno); |
321 MSG_ERR("accept on srs socket failed\n"); | |
322 MSG_ERR("service pending connections, and continue\n"); | |
323 } else { | |
324 int command; | |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
325 Dsh *sh; |
0 | 326 |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
327 sh = a_Dpip_dsh_new(sock_fd, sock_fd, 1024); |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
328 read_next: |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
329 req = get_request(sh); |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
330 command = get_command(sh, req); |
0 | 331 switch (command) { |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
332 case AUTH_CMD: |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
333 if (a_Dpip_check_auth(req) != -1) { |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
334 dFree(req); |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
335 goto read_next; |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
336 } |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
337 break; |
0 | 338 case BYE_CMD: |
339 stop_active_dpis(dpi_attr_list, numdpis); | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
340 //cleanup(); |
0 | 341 exit(0); |
342 break; | |
343 case CHECK_SERVER_CMD: | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
344 send_sockport(sock_fd, req, dpi_attr_list); |
0 | 345 break; |
346 case REGISTER_ALL_CMD: | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
347 register_all_cmd(); |
0 | 348 break; |
349 case UNKNOWN_CMD: | |
350 { | |
351 char *d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", | |
352 "DpiError", "Unknown command"); | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
353 (void) CKD_WRITE(sock_fd, d_cmd); |
0 | 354 dFree(d_cmd); |
355 ERRMSG("main", "Unknown command", 0); | |
356 MSG_ERR(" for request: %s\n", req); | |
357 break; | |
358 } | |
359 case -1: | |
360 _ERRMSG("main", "get_command failed", 0); | |
361 break; | |
362 } | |
363 if (req) | |
364 free(req); | |
1387
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
365 a_Dpip_dsh_close(sh); |
16cf380cd04c
Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents:
1382
diff
changeset
|
366 a_Dpip_dsh_free(sh); |
0 | 367 } |
368 } | |
369 | |
370 /* While there's a request on one of the plugin sockets | |
371 * find the matching plugin and start it. */ | |
372 for (i = 0; n > 0 && i < numdpis; i++) { | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
373 if (FD_ISSET(dpi_attr_list[i].sock_fd, &selected_set)) { |
0 | 374 --n; |
375 assert(n >= 0); | |
376 | |
377 if (dpi_attr_list[i].filter) { | |
378 /* start a dpi filter plugin and continue watching its socket | |
379 * for new connections */ | |
380 (void) sigprocmask(SIG_SETMASK, &mask_none, NULL); | |
381 start_filter_plugin(dpi_attr_list[i]); | |
382 } else { | |
383 /* start a dpi server plugin but don't wait for new connections | |
384 * on its socket */ | |
385 numsocks--; | |
386 assert(numsocks >= 0); | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
387 FD_CLR(dpi_attr_list[i].sock_fd, &sock_set); |
0 | 388 if ((dpi_attr_list[i].pid = fork()) == -1) { |
389 ERRMSG("main", "fork", errno); | |
390 /* exit(1); */ | |
391 } else if (dpi_attr_list[i].pid == 0) { | |
1382
7faa2c7a544f
Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents:
1236
diff
changeset
|
392 /* child */ |
0 | 393 (void) sigprocmask(SIG_SETMASK, &mask_none, NULL); |
394 start_server_plugin(dpi_attr_list[i]); | |
395 } | |
396 } | |
397 } | |
398 } | |
399 } | |
400 } |