annotate dpid/dpid.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 34251a0d774e
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 Copyright (C) 2003 Ferdi Franceschini <ferdif@optusnet.com.au>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 GNU General Public License for more details.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
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: 930
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 /*! \file
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 * Main functions to set-up dpi information and to initialise sockets
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include <errno.h>
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
22 #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
23 #include <fcntl.h> /* for F_SETFD, F_GETFD, FD_CLOEXEC */
1223
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
24
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include <sys/stat.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include <sys/wait.h>
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
27 #include <sys/socket.h>
1515
a7ee9f9a8283 use TCP_NODELAY for DPI communication
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1467
diff changeset
28 #include <netinet/tcp.h>
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
29
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 #include <unistd.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 #include "dpid_common.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 #include "dpid.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 #include "dpi.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 #include "dpi_socket_dir.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 #include "misc_new.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 #include "../dpip/dpip.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 #define QUEUE 5
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 volatile sig_atomic_t caught_sigchld = 0;
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
42 char *SharedKey = NULL;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
44 /*! Remove dpid_comm_keys file.
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
45 * This avoids that dillo instances connect to a stale port after dpid
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
46 * has exited (e.g. after a reboot).
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
48 void cleanup()
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 {
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
50 char *fname;
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
51 fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL);
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
52 unlink(fname);
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
53 dFree(fname);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 /*! Free memory used to describe
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 * a set of dpi attributes
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 void free_dpi_attr(struct dp *dpi_attr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 if (dpi_attr->id != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 dFree(dpi_attr->id);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 dpi_attr->id = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 if (dpi_attr->path != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 dFree(dpi_attr->path);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 dpi_attr->path = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 /*! Free memory used by the plugin list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 void free_plugin_list(struct dp **dpi_attr_list_ptr, int numdpis)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 struct dp *dpi_attr_list = *dpi_attr_list_ptr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 if (dpi_attr_list == NULL)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 for (i = 0; i < numdpis; i++)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 free_dpi_attr(dpi_attr_list + i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 dFree(dpi_attr_list);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 *dpi_attr_list_ptr = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
88 /*! Free memory used by the services list
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
89 */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
90 void free_services_list(Dlist *s_list)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
91 {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
92 int i = 0;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
93 struct service *s;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
94
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
95 for (i=0; i < dList_length(s_list) ; i++) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
96 s = dList_nth_data(s_list, i);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
97 dFree(s->name);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
98 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
99 dList_free(s_list);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
100 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
101
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 /*! Signal handler for SIGINT, SIGQUIT, and SIGTERM. Calls cleanup
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 */
1553
9ec23e9c41f3 suppress unused parameter warning
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1550
diff changeset
104 static void terminator(int sig)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 {
1553
9ec23e9c41f3 suppress unused parameter warning
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1550
diff changeset
106 (void) sig; /* suppress unused parameter warning */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 cleanup();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 _exit(0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 /*! Establish handler for termination signals
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 * and register cleanup with atexit */
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
113 void est_dpi_terminator()
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 struct sigaction act;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 sigset_t block;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
118 sigemptyset(&block);
1554
17b0b8845212 call dpid cleanup handler on SIGHUP
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1553
diff changeset
119 sigaddset(&block, SIGHUP);
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
120 sigaddset(&block, SIGINT);
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
121 sigaddset(&block, SIGQUIT);
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
122 sigaddset(&block, SIGTERM);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 act.sa_handler = terminator;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 act.sa_mask = block;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126 act.sa_flags = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127
1554
17b0b8845212 call dpid cleanup handler on SIGHUP
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1553
diff changeset
128 if (sigaction(SIGHUP, &act, NULL) ||
17b0b8845212 call dpid cleanup handler on SIGHUP
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1553
diff changeset
129 sigaction(SIGINT, &act, NULL) ||
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 sigaction(SIGQUIT, &act, NULL) ||
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
131 sigaction(SIGTERM, &act, NULL)) {
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
132 ERRMSG("est_dpi_terminator", "sigaction", errno);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
136 if (atexit(cleanup) != 0) {
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
137 ERRMSG("est_dpi_terminator", "atexit", 0);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138 MSG_ERR("Hey! atexit failed, how did that happen?\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
141 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 /*! Identify a given file
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 * Currently there is only one file type associated with dpis.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145 * More file types will be added as needed
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
146 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
147 enum file_type get_file_type(char *file_name)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 char *dot = strrchr(file_name, '.');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 if (dot && !strcmp(dot, ".dpi"))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 return DPI_FILE; /* Any filename ending in ".dpi" */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 MSG_ERR("get_file_type: Unknown file type for %s\n", file_name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155 return UNKNOWN_FILE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158
1223
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
159 /*! Get dpi directory path from dpidrc
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
160 * \Return
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
161 * dpi directory on success, NULL on failure
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
162 * \Important
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
163 * The dpi_dir definition in dpidrc must have no leading white space.
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
164 */
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
165 char *get_dpi_dir(char *dpidrc)
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
166 {
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
167 FILE *In;
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
168 int len;
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
169 char *rcline = NULL, *value = NULL, *p;
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
170
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
171 if ((In = fopen(dpidrc, "r")) == NULL) {
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
172 ERRMSG("dpi_dir", "fopen", errno);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
173 MSG_ERR(" - %s\n", dpidrc);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
174 return (NULL);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
175 }
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
176
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
177 while ((rcline = dGetline(In)) != NULL) {
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
178 if (strncmp(rcline, "dpi_dir", 7) == 0)
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
179 break;
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
180 dFree(rcline);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
181 }
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
182 fclose(In);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
183
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
184 if (!rcline) {
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
185 ERRMSG("dpi_dir", "Failed to find a dpi_dir entry in dpidrc", 0);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
186 MSG_ERR("Put your dillo plugins path in %s\n", dpidrc);
1467
corvid <corvid@lavabit.com>
parents: 1389
diff changeset
187 MSG_ERR("e.g. dpi_dir=/usr/local/lib/dillo/dpi\n");
1223
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
188 MSG_ERR("with no leading spaces.\n");
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
189 value = NULL;
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
190 } else {
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
191 len = (int) strlen(rcline);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
192 if (len && rcline[len - 1] == '\n')
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
193 rcline[len - 1] = 0;
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
194
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
195 if ((p = strchr(rcline, '='))) {
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
196 while (*++p == ' ');
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
197 value = dStrdup(p);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
198 } else {
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
199 ERRMSG("dpi_dir", "strchr", 0);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
200 MSG_ERR(" - '=' not found in %s\n", rcline);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
201 value = NULL;
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
202 }
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
203 }
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
204
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
205 dFree(rcline);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
206 return (value);
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
207 }
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
208
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
209 /*! Scans a service directory in dpi_dir and fills dpi_attr
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 * \Note
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
211 * Caller must allocate memory for dpi_attr.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
213 * \li 0 on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
215 * \todo
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
216 * Add other file types, but first we need to add files associated with a dpi
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
217 * to the design.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
218 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
219 int get_dpi_attr(char *dpi_dir, char *service, struct dp *dpi_attr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
220 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
221 char *service_dir = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
222 struct stat statinfo;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
223 enum file_type ftype;
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
224 int ret = -1;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
225 DIR *dir_stream;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
226 struct dirent *dir_entry = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
227
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
228 service_dir = dStrconcat(dpi_dir, "/", service, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
229 if (stat(service_dir, &statinfo) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
230 ERRMSG("get_dpi_attr", "stat", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
231 MSG_ERR("file=%s\n", service_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
232 } else if ((dir_stream = opendir(service_dir)) == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
233 ERRMSG("get_dpi_attr", "opendir", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
234 } else {
10
f30c923e31aa Fixed a problem with locally-installed dpis.
jcid
parents: 0
diff changeset
235 /* Scan the directory looking for dpi files.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
236 * (currently there's only the dpi program, but in the future
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
237 * there may also be helper scripts.) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
238 while ( (dir_entry = readdir(dir_stream)) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
239 if (dir_entry->d_name[0] == '.')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
240 continue;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
241
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
242 ftype = get_file_type(dir_entry->d_name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
243 switch (ftype) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
244 case DPI_FILE:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
245 dpi_attr->path =
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
246 dStrconcat(service_dir, "/", dir_entry->d_name, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
247 dpi_attr->id = dStrdup(service);
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
248 dpi_attr->port = 0;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
249 dpi_attr->pid = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
250 if (strstr(dpi_attr->path, ".filter") != NULL)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
251 dpi_attr->filter = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
252 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
253 dpi_attr->filter = 0;
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
254 ret = 0;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
255 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
256 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
257 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
258 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
259 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
260 closedir(dir_stream);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
262 if (ret != 0)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
263 MSG_ERR("get_dpi_attr: No dpi plug-in in %s/%s\n",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
264 dpi_dir, service);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
265 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266 dFree(service_dir);
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
267 return ret;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
269
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
270 /*! Register a service
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
271 * Retrieves attributes for "service" and stores them
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
272 * in dpi_attr. It looks for "service" in ~/.dillo/dpi
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273 * first, and then in the system wide dpi directory.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
274 * Caller must allocate memory for dpi_attr.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
275 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
276 * \li 0 on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
277 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
278 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
279 int register_service(struct dp *dpi_attr, char *service)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
280 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
281 char *user_dpi_dir, *dpidrc, *user_service_dir, *dir = NULL;
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
282 int ret = -1;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
283
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
284 user_dpi_dir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
285 user_service_dir =
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
286 dStrconcat(dGethomedir(), "/", dotDILLO_DPI, "/", service, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
287
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
288 dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
289 if (access(dpidrc, F_OK) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
290 if (access(DPIDRC_SYS, F_OK) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
291 ERRMSG("register_service", "Error ", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
292 MSG_ERR("\n - There is no %s or %s file\n", dpidrc,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
293 DPIDRC_SYS);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
294 dFree(user_dpi_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
295 dFree(user_service_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
296 dFree(dpidrc);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
297 return(-1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
298 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
299 dFree(dpidrc);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
300 dpidrc = dStrdup(DPIDRC_SYS);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
301 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
302
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
303 /* Check home dir for dpis */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
304 if (access(user_service_dir, F_OK) == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
305 get_dpi_attr(user_dpi_dir, service, dpi_attr);
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
306 ret = 0;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
307 } else { /* Check system wide dpis */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
308 if ((dir = get_dpi_dir(dpidrc)) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
309 if (access(dir, F_OK) == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
310 get_dpi_attr(dir, service, dpi_attr);
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
311 ret = 0;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
312 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
313 ERRMSG("register_service", "get_dpi_attr failed", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
314 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
315 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
316 ERRMSG("register_service", "dpi_dir: Error getting dpi dir.", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
317 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
318 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
319 dFree(user_dpi_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
320 dFree(user_service_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
321 dFree(dpidrc);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
322 dFree(dir);
1386
8f6d5a94ac0e s/retval/ret/g
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
323 return ret;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
324 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
325
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
326 /*!
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
327 * Create dpi directory for available
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
328 * plugins and create plugin list.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
329 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
330 * \li Returns number of available plugins on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
331 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
332 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
333 int register_all(struct dp **attlist)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
334 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
335 DIR *user_dir_stream, *sys_dir_stream;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
336 char *user_dpidir = NULL, *sys_dpidir = NULL, *dpidrc = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
337 struct dirent *user_dirent, *sys_dirent;
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
338 int st;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
339 int snum, usr_srv_num;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
340 size_t dp_sz = sizeof(struct dp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
341
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
342 if (*attlist != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
343 ERRMSG("register_all", "attlist parameter should be NULL", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
344 return -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
345 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
346
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
347 user_dpidir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
348 if (access(user_dpidir, F_OK) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
349 /* no dpis in user's space */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
350 dFree(user_dpidir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
351 user_dpidir = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
352 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
353 dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
354 if (access(dpidrc, F_OK) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
355 dFree(dpidrc);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
356 dpidrc = dStrdup(DPIDRC_SYS);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
357 if (access(dpidrc, F_OK) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
358 dFree(dpidrc);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
359 dpidrc = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
360 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
361 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
362 if (!dpidrc || (sys_dpidir = get_dpi_dir(dpidrc)) == NULL)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
363 sys_dpidir = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
364 dFree(dpidrc);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
365
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
366 if (!user_dpidir && !sys_dpidir) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
367 ERRMSG("register_all", "Fatal error ", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
368 MSG_ERR("\n - Can't find the directory for dpis.\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
369 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
370 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
371
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
372 /* Get list of services in user's .dillo/dpi directory */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
373 snum = usr_srv_num = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
374 if (user_dpidir && (user_dir_stream = opendir(user_dpidir)) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
375 while ((user_dirent = readdir(user_dir_stream)) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
376 if (user_dirent->d_name[0] == '.')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
377 continue;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
378 *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
379 st=get_dpi_attr(user_dpidir, user_dirent->d_name, &(*attlist)[snum]);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
380 if (st == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
381 snum++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
382 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
383 usr_srv_num = snum;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
384 closedir(user_dir_stream);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
385 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
386 if (sys_dpidir && (sys_dir_stream = opendir(sys_dpidir)) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
387 /* if system service is not in user list then add it */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
388 while ((sys_dirent = readdir(sys_dir_stream)) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
389 if (sys_dirent->d_name[0] == '.')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
390 continue;
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
391 *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
392 st=get_dpi_attr(sys_dpidir, sys_dirent->d_name, &(*attlist)[snum]);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
393 if (st == 0)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
394 snum++;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
395 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
396 closedir(sys_dir_stream);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
397 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
398
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
399 dFree(sys_dpidir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
400 dFree(user_dpidir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
401
368
2242da885677 - s/todo:/TODO:/g
jcid
parents: 335
diff changeset
402 /* TODO: do we consider snum == 0 an error?
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
403 * (if so, we should return -1 ) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
404 return (snum);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
405 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
406
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
407 /*
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
408 * Compare two struct service pointers
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
409 * This function is used for sorting services
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
410 */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
411 static int services_alpha_comp(const struct service *s1,
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
412 const struct service *s2)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
413 {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
414 return -strcmp(s1->name, s2->name);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
415 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
416
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
417 /*! Add services reading a dpidrc file
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
418 * each non empty or commented line has the form
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
419 * service = path_relative_to_dpidir
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
420 * \Return:
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
421 * \li Returns number of available services on success
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
422 * \li -1 on failure
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
423 */
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
424 int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
425 {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
426 FILE *dpidrc_stream;
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
427 char *p, *line = NULL, *service, *path;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
428 int i, st;
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
429 struct service *s;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
430 char *user_dpidir = NULL, *sys_dpidir = NULL, *dpidrc = NULL;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
431
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
432 user_dpidir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
433 if (access(user_dpidir, F_OK) == -1) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
434 /* no dpis in user's space */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
435 dFree(user_dpidir);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
436 user_dpidir = NULL;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
437 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
438 dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
439 if (access(dpidrc, F_OK) == -1) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
440 dFree(dpidrc);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
441 dpidrc = dStrdup(DPIDRC_SYS);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
442 if (access(dpidrc, F_OK) == -1) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
443 dFree(dpidrc);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
444 dpidrc = NULL;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
445 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
446 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
447 if (!dpidrc || (sys_dpidir = get_dpi_dir(dpidrc)) == NULL)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
448 sys_dpidir = NULL;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
449
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
450 if (!user_dpidir && !sys_dpidir) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
451 ERRMSG("fill_services_list", "Fatal error ", 0);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
452 MSG_ERR("\n - Can't find the directory for dpis.\n");
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
453 exit(1);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
454 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
455
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
456 if ((dpidrc_stream = fopen(dpidrc, "r")) == NULL) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
457 ERRMSG("fill_services_list", "popen failed", errno);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
458 dFree(dpidrc);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
459 dFree(sys_dpidir);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
460 dFree(user_dpidir);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
461 return (-1);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
462 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
463
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
464 if (*services_list != NULL) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
465 ERRMSG("fill_services_list", "services_list parameter is not NULL", 0);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
466 return -1;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
467 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
468 *services_list = dList_new(8);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
469
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
470 /* dpidrc parser loop */
1595
34251a0d774e fix dpid line leak
corvid <corvid@lavabit.com>
parents: 1567
diff changeset
471 for (;(line = dGetline(dpidrc_stream)) != NULL; dFree(line)) {
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
472 st = dParser_parse_rc_line(&line, &service, &path);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
473 if (st < 0) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
474 MSG_ERR("dpid: Syntax error in %s: service=\"%s\" path=\"%s\"\n",
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
475 dpidrc, service, path);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
476 continue;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
477 } else if (st != 0) {
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
478 continue;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
479 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
480
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
481 _MSG("dpid: service=%s, path=%s\n", service, path);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 972
diff changeset
482
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
483 /* ignore dpi_dir silently */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
484 if (strcmp(service, "dpi_dir") == 0)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
485 continue;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
486
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
487 s = dNew(struct service, 1);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
488 /* init services list entry */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
489 s->name = dStrdup(service);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
490 s->dp_index = -1;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
491
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
492 dList_append(*services_list, s);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
493 /* search the dpi for a service by its path */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
494 for (i = 0; i < numdpis; i++)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
495 if ((p = strstr(attlist[i].path, path)) && *(p - 1) == '/' &&
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
496 strlen(p) == strlen(path))
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
497 break;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
498 /* if the dpi exist bind service and dpi */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
499 if (i < numdpis)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
500 s->dp_index = i;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
501 }
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 445
diff changeset
502 fclose(dpidrc_stream);
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
503
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
504 dList_sort(*services_list, (dCompareFunc)services_alpha_comp);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
505
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
506 dFree(dpidrc);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
507 dFree(sys_dpidir);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
508 dFree(user_dpidir);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
509
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
510 return (dList_length(*services_list));
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
511 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
512
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
513 /*
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
514 * Return a socket file descriptor
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
515 * (useful to set socket options in a uniform way)
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
516 */
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
517 static int make_socket_fd()
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
518 {
1515
a7ee9f9a8283 use TCP_NODELAY for DPI communication
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1467
diff changeset
519 int ret, one = 1;
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
520
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
521 if ((ret = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
522 ERRMSG("make_socket_fd", "socket", errno);
1515
a7ee9f9a8283 use TCP_NODELAY for DPI communication
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1467
diff changeset
523 } else {
a7ee9f9a8283 use TCP_NODELAY for DPI communication
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1467
diff changeset
524 /* avoid delays when sending small pieces of data */
a7ee9f9a8283 use TCP_NODELAY for DPI communication
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1467
diff changeset
525 setsockopt(ret, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
526 }
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
527
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
528 /* set some buffering to increase the transfer's speed */
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
529 //setsockopt(sock_fd, SOL_SOCKET, SO_SNDBUF,
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
530 // &sock_buflen, (socklen_t)sizeof(sock_buflen));
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
531
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
532 return ret;
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
533 }
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
534
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
535 /*! Bind a socket port on localhost. Try to be close to base_port.
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
536 * \Return
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
537 * \li listening socket file descriptor on success
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
538 * \li -1 on failure
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
539 */
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
540 int bind_socket_fd(int base_port, int *p_port)
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
541 {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
542 int sock_fd, port;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
543 struct sockaddr_in sin;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
544 int ok = 0, last_port = base_port + 50;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
545
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
546 if ((sock_fd = make_socket_fd()) == -1) {
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
547 return (-1); /* avoids nested ifs */
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
548 }
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
549 /* Set the socket FD to close on exec */
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
550 fcntl(sock_fd, F_SETFD, FD_CLOEXEC | fcntl(sock_fd, F_GETFD));
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
551
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
552
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
553 memset(&sin, 0, sizeof(sin));
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
554 sin.sin_family = AF_INET;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
555 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
556
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
557 /* Try to bind a port on localhost */
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
558 for (port = base_port; port <= last_port; ++port) {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
559 sin.sin_port = htons(port);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
560 if ((bind(sock_fd, (struct sockaddr *)&sin, sizeof(sin))) == -1) {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
561 if (errno == EADDRINUSE || errno == EADDRNOTAVAIL)
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
562 continue;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
563 ERRMSG("bind_socket_fd", "bind", errno);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
564 } else if (listen(sock_fd, QUEUE) == -1) {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
565 ERRMSG("bind_socket_fd", "listen", errno);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
566 } else {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
567 *p_port = port;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
568 ok = 1;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
569 break;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
570 }
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
571 }
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
572 if (port > last_port) {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
573 MSG_ERR("Hey! Can't find an available port from %d to %d\n",
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
574 base_port, last_port);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
575 }
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
576
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
577 return ok ? sock_fd : -1;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
578 }
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
579
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
580 /*! Save the current port and a shared secret in a file so dillo can find it.
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
581 * \Return:
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
582 * \li -1 on failure
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
583 */
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
584 int save_comm_keys(int srs_port)
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
585 {
1550
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
586 int fd, ret = -1;
3a159d7e5098 remove ~/.dillo/dpid_comm_keys on exit of dpid
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1515
diff changeset
587 char *fname, port_str[32];
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
588
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
589 fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
590 fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
591 dFree(fname);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
592 if (fd == -1) {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
593 MSG("save_comm_keys: open %s\n", dStrerror(errno));
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
594 } else {
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
595 snprintf(port_str, 16, "%d %s\n", srs_port, SharedKey);
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
596 if (CKD_WRITE(fd, port_str) != -1 && CKD_CLOSE(fd) != -1) {
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
597 ret = 1;
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
598 }
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
599 }
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
600
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
601 return ret;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
602 }
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
603
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
604 /*! Initialise the service request socket (IDS)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
605 * \Return:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
606 * \li Number of sockets (1 == success)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
607 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
608 */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
609 int init_ids_srs_socket()
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
610 {
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
611 int srs_port, ret = -1;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
612
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
613 FD_ZERO(&sock_set);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
614
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
615 if ((srs_fd = bind_socket_fd(DPID_BASE_PORT, &srs_port)) != -1) {
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
616 /* create the shared secret */
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
617 SharedKey = a_Misc_mksecret(8);
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
618 /* save port number and SharedKey */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
619 if (save_comm_keys(srs_port) != -1) {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
620 FD_SET(srs_fd, &sock_set);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
621 ret = 1;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
622 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
623 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
624
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
625 return ret;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
626 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
627
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
628 /*! Initialize a single dpi socket
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
629 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
630 * \li 1 on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
631 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
632 */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
633 int init_dpi_socket(struct dp *dpi_attr)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
634 {
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
635 int s_fd, port, ret = -1;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
636
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
637 if ((s_fd = bind_socket_fd(DPID_BASE_PORT, &port)) != -1) {
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
638 dpi_attr->sock_fd = s_fd;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
639 dpi_attr->port = port;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
640 FD_SET(s_fd, &sock_set);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
641 ret = 1;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
642 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
643
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
644 return ret;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
645 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
646
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
647 /*! Setup sockets for the plugins and add them to
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
648 * the set of sockets (sock_set) watched by select.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
649 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
650 * \li Number of sockets on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
651 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
652 * \Modifies
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
653 * dpi_attr_list.sa, dpi_attr_list.socket, numsocks, sock_set, srs
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
654 * \Uses
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
655 * numdpis, srs, srs_name
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
656 */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
657 int init_all_dpi_sockets(struct dp *dpi_attr_list)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
658 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
659 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
660
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
661 /* Initialise sockets for each dpi */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
662 for (i = 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
663 if (init_dpi_socket(dpi_attr_list + i) == -1)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
664 return (-1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
665 numsocks++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
666 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
667
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
668 return (numsocks);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
669 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
670
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
671 /*! SIGCHLD handler
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
672 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
673 void dpi_sigchld(int sig)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
674 {
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 88
diff changeset
675 if (sig == SIGCHLD)
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 88
diff changeset
676 caught_sigchld = 1;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
677 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
678
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
679 /*! Called by main loop when caught_sigchld == 1 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
680 void handle_sigchld(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
681 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
682 // pid_t pid;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
683 int i, status; //, num_active;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
684
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
685 /* For all of the dpis in the current list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
686 * add the ones that have exited to the set of sockets being
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
687 * watched by 'select'.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
688 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
689 for (i = 0; i < numdpis; i++) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
690 if (waitpid(dpi_attr_list[i].pid, &status, WNOHANG) > 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
691 dpi_attr_list[i].pid = 1;
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
692 FD_SET(dpi_attr_list[i].sock_fd, &sock_set);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
693 numsocks++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
694 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
695 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
696
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
697 /* Wait for any old dpis that have exited */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
698 while (waitpid(-1, &status, WNOHANG) > 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
699 ;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
700 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
701
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
702 /*! Establish SIGCHLD handler */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
703 void est_dpi_sigchld(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
704 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
705 struct sigaction sigact;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
706 sigset_t set;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
707
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
708 (void) sigemptyset(&set);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
709 sigact.sa_handler = dpi_sigchld;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
710 sigact.sa_mask = set;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
711 sigact.sa_flags = SA_NOCLDSTOP;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
712 if (sigaction(SIGCHLD, &sigact, NULL) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
713 ERRMSG("est_dpi_sigchld", "sigaction", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
714 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
715 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
716 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
717
1387
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
718 /*! EINTR aware connect() call */
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
719 int ckd_connect (int sock_fd, struct sockaddr *addr, socklen_t len)
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
720 {
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
721 ssize_t ret;
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
722
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
723 do {
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
724 ret = connect(sock_fd, addr, len);
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
725 } while (ret == -1 && errno == EINTR);
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
726 if (ret == -1) {
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
727 ERRMSG("dpid.c", "connect", errno);
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
728 }
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
729 return ret;
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
730 }
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
731
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
732 /*! Send DpiBye command to all active non-filter dpis
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
733 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
734 void stop_active_dpis(struct dp *dpi_attr_list, int numdpis)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
735 {
1387
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
736 char *bye_cmd, *auth_cmd;
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
737 int i, sock_fd;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
738 struct sockaddr_in sin;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
739
1387
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
740 bye_cmd = a_Dpip_build_cmd("cmd=%s", "DpiBye");
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
741 auth_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "auth", SharedKey);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
742
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
743 memset(&sin, 0, sizeof(sin));
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
744 sin.sin_family = AF_INET;
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
745 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
746
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
747 for (i = 0; i < numdpis; i++) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
748 /* Skip inactive dpis and filters */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
749 if (dpi_attr_list[i].pid == 1 || dpi_attr_list[i].filter)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
750 continue;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
751
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
752 if ((sock_fd = make_socket_fd()) == -1) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
753 ERRMSG("stop_active_dpis", "socket", errno);
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
754 continue;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
755 }
1389
c1c822f70582 Removed the write/fwrite mix in dpip. Introduced a_Dpip_dsh_trywrite()
Jorge Arellano Cid <jcid@dillo.org>
parents: 1387
diff changeset
756
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
757 sin.sin_port = htons(dpi_attr_list[i].port);
1387
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
758 if (ckd_connect(sock_fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
759 ERRMSG("stop_active_dpis", "connect", errno);
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
760 MSG_ERR("%s\n", dpi_attr_list[i].path);
1387
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
761 } else if (CKD_WRITE(sock_fd, auth_cmd) == -1) {
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
762 ERRMSG("stop_active_dpis", "write", errno);
1387
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
763 } else if (CKD_WRITE(sock_fd, bye_cmd) == -1) {
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1382
diff changeset
764 ERRMSG("stop_active_dpis", "write", errno);
1200
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1053
diff changeset
765 }
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
766 a_Misc_close_fd(sock_fd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
767 }
1387
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
768
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
769 dFree(auth_cmd);
16cf380cd04c Convert dpid, file dpi and cookies dpi to dsh API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1386
diff changeset
770 dFree(bye_cmd);
1565
abef1063a449 Fix a race condition for "dpid stop" command.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1550
diff changeset
771
abef1063a449 Fix a race condition for "dpid stop" command.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1550
diff changeset
772 /* Allow child dpis some time to read dpid_comm_keys before erasing it */
abef1063a449 Fix a race condition for "dpid stop" command.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1550
diff changeset
773 sleep (1);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
774 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
775
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
776 /*! Removes dpis in dpi_attr_list from the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
777 * set of sockets watched by select and
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
778 * closes their sockets.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
779 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
780 void ignore_dpi_sockets(struct dp *dpi_attr_list, int numdpis)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
781 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
782 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
783
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
784 for (i = 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
785 FD_CLR(dpi_attr_list[i].sock_fd, &sock_set);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
786 a_Misc_close_fd(dpi_attr_list[i].sock_fd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
787 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
788 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
789
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
790 /*! Registers available dpis and stops active non-filter dpis.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
791 * Called when dpid receives
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
792 * cmd='register' service='all'
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
793 * command
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
794 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
795 * Number of available dpis
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
796 */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
797 int register_all_cmd()
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
798 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
799 stop_active_dpis(dpi_attr_list, numdpis);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
800 free_plugin_list(&dpi_attr_list, numdpis);
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
801 free_services_list(services_list);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
802 services_list = NULL;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
803 numdpis = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
804 numsocks = 1; /* the srs socket */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
805 FD_ZERO(&sock_set);
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
806 FD_SET(srs_fd, &sock_set);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
807 numdpis = register_all(&dpi_attr_list);
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
808 fill_services_list(dpi_attr_list, numdpis, &services_list);
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
809 numsocks = init_all_dpi_sockets(dpi_attr_list);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
810 return (numdpis);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
811 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
812
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
813 /*!
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
814 * Get value of msg field from dpi_tag
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
815 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
816 * message on success, NULL on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
817 */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
818 char *get_message(int sock_fd, char *dpi_tag)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
819 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
820 char *msg, *d_cmd;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
821
1236
b912173aecd1 Added a_Dpip_get_attr_l() to DPIP's API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
822 msg = a_Dpip_get_attr(dpi_tag, "msg");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
823 if (msg == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
824 ERRMSG("get_message", "failed to parse msg", 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
825 d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
826 "DpiError", "Failed to parse request");
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
827 (void) CKD_WRITE(sock_fd, d_cmd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
828 dFree(d_cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
829 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
830 return (msg);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
831 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
832
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
833 /*
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
834 * Compare a struct service pointer and a service name
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
835 * This function is used for searching services by name
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
836 */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
837 int service_match(const struct service *A, const char *B)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
838 {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
839 int A_len, B_len, len;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
840
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
841 A_len = strlen(A->name);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
842 B_len = strlen(B);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
843 len = MAX (A_len, B_len);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
844
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
845 if (A->name[A_len - 1] == '*')
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
846 len = A_len - 1;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
847
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
848 return(dStrncasecmp(A->name, B, len));
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
849 }
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
850
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
851 /*!
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
852 * Send socket port that matches dpi_id to client
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
853 */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
854 void send_sockport(int sock_fd, char *dpi_tag, struct dp *dpi_attr_list)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
855 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
856 int i;
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
857 char *dpi_id, *d_cmd, port_str[16];
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
858 struct service *serv;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
859
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
860 dReturn_if_fail((dpi_id = get_message(sock_fd, dpi_tag)) != NULL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
861
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
862 serv = dList_find_custom(services_list,dpi_id,(dCompareFunc)service_match);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
863
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
864 if (serv == NULL || (i = serv->dp_index) == -1)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
865 for (i = 0; i < numdpis; i++)
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
866 if (!strncmp(dpi_attr_list[i].id, dpi_id,
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
867 dpi_attr_list[i].id - strchr(dpi_attr_list[i].id, '.')))
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
868 break;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 10
diff changeset
869
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
870 if (i < numdpis) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
871 /* found */
1382
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
872 snprintf(port_str, 8, "%d", dpi_attr_list[i].port);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
873 d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "send_data", port_str);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
874 (void) CKD_WRITE(sock_fd, d_cmd);
7faa2c7a544f Switch the DPI framework from Unix sockets to Internet sockets
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
875 dFree(d_cmd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
876 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
877
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
878 dFree(dpi_id);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
879 }