Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
dpid.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 Ferdi Franceschini <ferdif@optusnet.com.au>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
21#include <errno.h>
22#include <stdlib.h> /* for exit */
23#include <fcntl.h> /* for F_SETFD, F_GETFD, FD_CLOEXEC */
24
25#include <sys/stat.h>
26#include <sys/wait.h>
27#include <sys/socket.h>
28#include <netinet/in.h>
29#include <netinet/tcp.h>
30#include <arpa/inet.h>
31
32#include <unistd.h>
33#include "dpid_common.h"
34#include "dpid.h"
35#include "dpi.h"
36#include "dpi_socket_dir.h"
37#include "misc_new.h"
38
39#include "../dpip/dpip.h"
40
41#define DPI_EXT (".dpi" EXEEXT)
42
43#define QUEUE 5
44
45volatile sig_atomic_t caught_sigchld = 0;
46char *SharedKey = NULL;
47
52void cleanup(void)
53{
54 char *fname;
55 fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL);
56 unlink(fname);
57 dFree(fname);
58}
59
63void free_dpi_attr(struct dp *dpi_attr)
64{
65 if (dpi_attr->id != NULL) {
66 dFree(dpi_attr->id);
67 dpi_attr->id = NULL;
68 }
69 if (dpi_attr->path != NULL) {
70 dFree(dpi_attr->path);
71 dpi_attr->path = NULL;
72 }
73}
74
77void free_plugin_list(struct dp **dpi_attr_list_ptr, int numdpis)
78{
79 int i;
80 struct dp *dpi_attr_list = *dpi_attr_list_ptr;
81
82 if (dpi_attr_list == NULL)
83 return;
84
85 for (i = 0; i < numdpis; i++)
87
89 *dpi_attr_list_ptr = NULL;
90}
91
95{
96 int i = 0;
97 struct service *s;
98
99 for (i=0; i < dList_length(s_list) ; i++) {
100 s = dList_nth_data(s_list, i);
101 dFree(s->name);
102 }
103 dList_free(s_list);
104}
105
108static void terminator(int sig)
109{
110 (void) sig; /* suppress unused parameter warning */
111 cleanup();
112 _exit(0);
113}
114
118{
119 struct sigaction act;
120 sigset_t block;
121
122 sigemptyset(&block);
123 sigaddset(&block, SIGHUP);
124 sigaddset(&block, SIGINT);
125 sigaddset(&block, SIGQUIT);
126 sigaddset(&block, SIGTERM);
127
128 act.sa_handler = terminator;
129 act.sa_mask = block;
130 act.sa_flags = 0;
131
132 if (sigaction(SIGHUP, &act, NULL) ||
133 sigaction(SIGINT, &act, NULL) ||
134 sigaction(SIGQUIT, &act, NULL) ||
135 sigaction(SIGTERM, &act, NULL)) {
136 ERRMSG("est_dpi_terminator", "sigaction", errno);
137 exit(1);
138 }
139
140 if (atexit(cleanup) != 0) {
141 ERRMSG("est_dpi_terminator", "atexit", 0);
142 MSG_ERR("Hey! atexit failed, how did that happen?\n");
143 exit(1);
144 }
145}
146
147static int ends_with(const char *str, const char *suffix)
148{
149 if (!str || !suffix)
150 return 0;
151 size_t lenstr = strlen(str);
152 size_t lensuffix = strlen(suffix);
153 if (lensuffix > lenstr)
154 return 0;
155 return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
156}
157
162enum file_type get_file_type(char *file_name)
163{
164 if (ends_with(file_name, DPI_EXT))
165 /* Any filename ending in ".dpi" (or ".dpi.exe" on Windows) */
166 return DPI_FILE;
167 else {
168 MSG_ERR("get_file_type: Unknown file type for %s\n", file_name);
169 return UNKNOWN_FILE;
170 }
171}
172
179char *get_dpi_dir(char *dpidrc)
180{
181 FILE *In;
182 int len;
183 char *rcline = NULL, *value = NULL, *p;
184
185 if ((In = fopen(dpidrc, "r")) == NULL) {
186 ERRMSG("dpi_dir", "fopen", errno);
187 MSG_ERR(" - %s\n", dpidrc);
188 return (NULL);
189 }
190
191 while ((rcline = dGetline(In)) != NULL) {
192 if (strncmp(rcline, "dpi_dir", 7) == 0)
193 break;
194 dFree(rcline);
195 }
196 fclose(In);
197
198 if (!rcline) {
199 ERRMSG("dpi_dir", "Failed to find a dpi_dir entry in dpidrc", 0);
200 MSG_ERR("Put your dillo plugins path in %s\n", dpidrc);
201 MSG_ERR("e.g. dpi_dir=/usr/local/lib/dillo/dpi\n");
202 MSG_ERR("with no leading spaces.\n");
203 value = NULL;
204 } else {
205 len = (int) strlen(rcline);
206 if (len && rcline[len - 1] == '\n')
207 rcline[len - 1] = 0;
208
209 if ((p = strchr(rcline, '='))) {
210 while (*++p == ' ');
211 value = dStrdup(p);
212 } else {
213 ERRMSG("dpi_dir", "strchr", 0);
214 MSG_ERR(" - '=' not found in %s\n", rcline);
215 value = NULL;
216 }
217 }
218
219 dFree(rcline);
220 return (value);
221}
222
233int get_dpi_attr(char *dpi_dir, char *service, struct dp *dpi_attr)
234{
235 char *service_dir = NULL;
236 struct stat statinfo;
237 enum file_type ftype;
238 int ret = -1;
239 DIR *dir_stream;
240 struct dirent *dir_entry = NULL;
241
242 service_dir = dStrconcat(dpi_dir, "/", service, NULL);
243 if (stat(service_dir, &statinfo) == -1) {
244 ERRMSG("get_dpi_attr", "stat", errno);
245 MSG_ERR("file=%s\n", service_dir);
246 } else if ((dir_stream = opendir(service_dir)) == NULL) {
247 ERRMSG("get_dpi_attr", "opendir", errno);
248 } else {
249 /* Scan the directory looking for dpi files.
250 * (currently there's only the dpi program, but in the future
251 * there may also be helper scripts.) */
252 while ( (dir_entry = readdir(dir_stream)) != NULL) {
253 if (dir_entry->d_name[0] == '.')
254 continue;
255
256 ftype = get_file_type(dir_entry->d_name);
257 switch (ftype) {
258 case DPI_FILE:
259 dpi_attr->path =
260 dStrconcat(service_dir, "/", dir_entry->d_name, NULL);
261 dpi_attr->id = dStrdup(service);
262 dpi_attr->port = 0;
263 dpi_attr->pid = 1;
264 if (strstr(dpi_attr->path, ".filter") != NULL)
265 dpi_attr->filter = 1;
266 else
267 dpi_attr->filter = 0;
268 ret = 0;
269 break;
270 default:
271 break;
272 }
273 }
274 closedir(dir_stream);
275
276 if (ret != 0)
277 MSG_ERR("get_dpi_attr: No dpi plug-in in %s/%s\n",
278 dpi_dir, service);
279 }
280 dFree(service_dir);
281 return ret;
282}
283
293int register_service(struct dp *dpi_attr, char *service)
294{
295 char *user_dpi_dir, *dpidrc, *user_service_dir, *dir = NULL;
296 int ret = -1;
297
298 user_dpi_dir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL);
299 user_service_dir =
300 dStrconcat(dGethomedir(), "/", dotDILLO_DPI, "/", service, NULL);
301
302 dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
303 if (access(dpidrc, F_OK) == -1) {
304 if (access(DPIDRC_SYS, F_OK) == -1) {
305 ERRMSG("register_service", "Error ", 0);
306 MSG_ERR("\n - There is no %s or %s file\n", dpidrc,
307 DPIDRC_SYS);
308 dFree(user_dpi_dir);
309 dFree(user_service_dir);
310 dFree(dpidrc);
311 return(-1);
312 }
313 dFree(dpidrc);
314 dpidrc = dStrdup(DPIDRC_SYS);
315 }
316
317 /* Check home dir for dpis */
318 if (access(user_service_dir, F_OK) == 0) {
319 get_dpi_attr(user_dpi_dir, service, dpi_attr);
320 ret = 0;
321 } else { /* Check system wide dpis */
322 if ((dir = get_dpi_dir(dpidrc)) != NULL) {
323 if (access(dir, F_OK) == 0) {
324 get_dpi_attr(dir, service, dpi_attr);
325 ret = 0;
326 } else {
327 ERRMSG("register_service", "get_dpi_attr failed", 0);
328 }
329 } else {
330 ERRMSG("register_service", "dpi_dir: Error getting dpi dir.", 0);
331 }
332 }
333 dFree(user_dpi_dir);
334 dFree(user_service_dir);
335 dFree(dpidrc);
336 dFree(dir);
337 return ret;
338}
339
347int register_all(struct dp **attlist)
348{
349 DIR *user_dir_stream, *sys_dir_stream;
350 char *user_dpidir = NULL, *sys_dpidir = NULL, *dpidrc = NULL;
351 struct dirent *user_dirent, *sys_dirent;
352 int st;
353 int snum;
354 size_t dp_sz = sizeof(struct dp);
355
356 if (*attlist != NULL) {
357 ERRMSG("register_all", "attlist parameter should be NULL", 0);
358 return -1;
359 }
360
361 user_dpidir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL);
362 if (access(user_dpidir, F_OK) == -1) {
363 /* no dpis in user's space */
364 dFree(user_dpidir);
365 user_dpidir = NULL;
366 }
367 dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
368 if (access(dpidrc, F_OK) == -1) {
369 dFree(dpidrc);
370 dpidrc = dStrdup(DPIDRC_SYS);
371 if (access(dpidrc, F_OK) == -1) {
372 dFree(dpidrc);
373 dpidrc = NULL;
374 }
375 }
376 if (!dpidrc || (sys_dpidir = get_dpi_dir(dpidrc)) == NULL)
377 sys_dpidir = NULL;
378 dFree(dpidrc);
379
380 if (!user_dpidir && !sys_dpidir) {
381 ERRMSG("register_all", "Fatal error ", 0);
382 MSG_ERR("\n - Can't find the directory for dpis.\n");
383 exit(1);
384 }
385
386 /* Get list of services in user's .dillo/dpi directory */
387 snum = 0;
388 if (user_dpidir && (user_dir_stream = opendir(user_dpidir)) != NULL) {
389 while ((user_dirent = readdir(user_dir_stream)) != NULL) {
390 if (user_dirent->d_name[0] == '.')
391 continue;
392 *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz);
393 st=get_dpi_attr(user_dpidir, user_dirent->d_name, &(*attlist)[snum]);
394 if (st == 0)
395 snum++;
396 }
397 closedir(user_dir_stream);
398 }
399 if (sys_dpidir && (sys_dir_stream = opendir(sys_dpidir)) != NULL) {
400 /* if system service is not in user list then add it */
401 while ((sys_dirent = readdir(sys_dir_stream)) != NULL) {
402 if (sys_dirent->d_name[0] == '.')
403 continue;
404 *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz);
405 st=get_dpi_attr(sys_dpidir, sys_dirent->d_name, &(*attlist)[snum]);
406 if (st == 0)
407 snum++;
408 }
409 closedir(sys_dir_stream);
410 }
411
412 dFree(sys_dpidir);
413 dFree(user_dpidir);
414
415 /* TODO: do we consider snum == 0 an error?
416 * (if so, we should return -1 ) */
417 return (snum);
418}
419
420/*
421 * Compare two struct service pointers
422 * This function is used for sorting services
423 */
424static int services_alpha_comp(const struct service *s1,
425 const struct service *s2)
426{
427 return -strcmp(s1->name, s2->name);
428}
429
437int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
438{
439 FILE *dpidrc_stream;
440 char *p, *line = NULL, *service, *path;
441 int i, st;
442 struct service *s;
443 char *user_dpidir = NULL, *sys_dpidir = NULL, *dpidrc = NULL;
444
445 user_dpidir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL);
446 if (access(user_dpidir, F_OK) == -1) {
447 /* no dpis in user's space */
448 dFree(user_dpidir);
449 user_dpidir = NULL;
450 }
451 dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL);
452 if (access(dpidrc, F_OK) == -1) {
453 dFree(dpidrc);
454 dpidrc = dStrdup(DPIDRC_SYS);
455 if (access(dpidrc, F_OK) == -1) {
456 dFree(dpidrc);
457 dpidrc = NULL;
458 }
459 }
460 if (!dpidrc || (sys_dpidir = get_dpi_dir(dpidrc)) == NULL)
461 sys_dpidir = NULL;
462
463 if (!user_dpidir && !sys_dpidir) {
464 ERRMSG("fill_services_list", "Fatal error ", 0);
465 MSG_ERR("\n - Can't find the directory for dpis.\n");
466 exit(1);
467 }
468
469 if ((dpidrc_stream = fopen(dpidrc, "r")) == NULL) {
470 ERRMSG("fill_services_list", "popen failed", errno);
471 dFree(dpidrc);
472 dFree(sys_dpidir);
473 dFree(user_dpidir);
474 return (-1);
475 }
476
477 if (*services_list != NULL) {
478 ERRMSG("fill_services_list", "services_list parameter is not NULL", 0);
479 fclose(dpidrc_stream);
480 return -1;
481 }
483
484 /* dpidrc parser loop */
485 for (;(line = dGetline(dpidrc_stream)) != NULL; dFree(line)) {
486 st = dParser_parse_rc_line(&line, &service, &path);
487 if (st < 0) {
488 MSG_ERR("dpid: Syntax error in %s: service=\"%s\" path=\"%s\"\n",
489 dpidrc, service, path);
490 continue;
491 } else if (st != 0) {
492 continue;
493 }
494
495 _MSG("dpid: service=%s, path=%s\n", service, path);
496
497 /* ignore dpi_dir silently */
498 if (strcmp(service, "dpi_dir") == 0)
499 continue;
500
501 s = dNew(struct service, 1);
502 /* init services list entry */
503 s->name = dStrdup(service);
504 s->dp_index = -1;
505
507 /* search the dpi for a service by its path */
508 for (i = 0; i < numdpis; i++)
509 if ((p = strstr(attlist[i].path, path)) && *(p - 1) == '/' &&
510 strlen(p) == strlen(path))
511 break;
512 /* if the dpi exist bind service and dpi */
513 if (i < numdpis)
514 s->dp_index = i;
515 }
516 fclose(dpidrc_stream);
517
519
520 dFree(dpidrc);
521 dFree(sys_dpidir);
522 dFree(user_dpidir);
523
524 return (dList_length(*services_list));
525}
526
527/*
528 * Return a socket file descriptor
529 * (useful to set socket options in a uniform way)
530 */
531static int make_socket_fd(void)
532{
533 int ret, one = 1;
534
535 if ((ret = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
536 ERRMSG("make_socket_fd", "socket", errno);
537 } else {
538 /* avoid delays when sending small pieces of data */
539 setsockopt(ret, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
540 }
541
542 /* set some buffering to increase the transfer's speed */
543 //setsockopt(sock_fd, SOL_SOCKET, SO_SNDBUF,
544 // &sock_buflen, (socklen_t)sizeof(sock_buflen));
545
546 return ret;
547}
548
554int bind_socket_fd(int base_port, int *p_port)
555{
556 int sock_fd, port;
557 struct sockaddr_in sin;
558 int ok = 0, last_port = base_port + 50;
559
560 if ((sock_fd = make_socket_fd()) == -1) {
561 return (-1); /* avoids nested ifs */
562 }
563 /* Set the socket FD to close on exec */
564 fcntl(sock_fd, F_SETFD, FD_CLOEXEC | fcntl(sock_fd, F_GETFD));
565
566
567 memset(&sin, 0, sizeof(sin));
568 sin.sin_family = AF_INET;
569 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
570
571 /* Try to bind a port on localhost */
572 for (port = base_port; port <= last_port; ++port) {
573 sin.sin_port = htons(port);
574 if ((bind(sock_fd, (struct sockaddr *)&sin, sizeof(sin))) == -1) {
575 if (errno == EADDRINUSE || errno == EADDRNOTAVAIL)
576 continue;
577 ERRMSG("bind_socket_fd", "bind", errno);
578 } else if (listen(sock_fd, QUEUE) == -1) {
579 ERRMSG("bind_socket_fd", "listen", errno);
580 } else {
581 *p_port = port;
582 ok = 1;
583 break;
584 }
585 }
586 if (port > last_port) {
587 MSG_ERR("Hey! Can't find an available port from %d to %d\n",
588 base_port, last_port);
589 }
590
591 return ok ? sock_fd : -1;
592}
593
598int save_comm_keys(int srs_port)
599{
600 int fd, ret = -1;
601 char *fname, port_str[32];
602
603 fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL);
604 fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
605 dFree(fname);
606 if (fd == -1) {
607 MSG("save_comm_keys: open %s\n", dStrerror(errno));
608 } else {
609 snprintf(port_str, 16, "%d %s\n", srs_port, SharedKey);
610 if (CKD_WRITE(fd, port_str) != -1 && CKD_CLOSE(fd) != -1) {
611 ret = 1;
612 }
613 }
614
615 return ret;
616}
617
624{
625 int srs_port, ret = -1;
626
627 FD_ZERO(&sock_set);
628
629 if ((srs_fd = bind_socket_fd(DPID_BASE_PORT, &srs_port)) != -1) {
630 /* create the shared secret */
632 /* save port number and SharedKey */
633 if (save_comm_keys(srs_port) != -1) {
634 FD_SET(srs_fd, &sock_set);
635 ret = 1;
636 }
637 }
638
639 return ret;
640}
641
647int init_dpi_socket(struct dp *dpi_attr)
648{
649 int s_fd, port, ret = -1;
650
651 if ((s_fd = bind_socket_fd(DPID_BASE_PORT, &port)) != -1) {
652 dpi_attr->sock_fd = s_fd;
653 dpi_attr->port = port;
654 FD_SET(s_fd, &sock_set);
655 ret = 1;
656 }
657
658 return ret;
659}
660
672{
673 int i;
674
675 /* Initialise sockets for each dpi */
676 for (i = 0; i < numdpis; i++) {
677 if (init_dpi_socket(dpi_attr_list + i) == -1)
678 return (-1);
679 numsocks++;
680 }
681
682 return (numsocks);
683}
684
687void dpi_sigchld(int sig)
688{
689 if (sig == SIGCHLD)
690 caught_sigchld = 1;
691}
692
695{
696 // pid_t pid;
697 int i, status; //, num_active;
698
699 /* For all of the dpis in the current list
700 * add the ones that have exited to the set of sockets being
701 * watched by 'select'.
702 */
703 for (i = 0; i < numdpis; i++) {
704 if (waitpid(dpi_attr_list[i].pid, &status, WNOHANG) > 0) {
705 dpi_attr_list[i].pid = 1;
706 FD_SET(dpi_attr_list[i].sock_fd, &sock_set);
707 numsocks++;
708 }
709 }
710
711 /* Wait for any old dpis that have exited */
712 while (waitpid(-1, &status, WNOHANG) > 0)
713 ;
714}
715
718{
719 struct sigaction sigact;
720 sigset_t set;
721
722 (void) sigemptyset(&set);
723 sigact.sa_handler = dpi_sigchld;
724 sigact.sa_mask = set;
725 sigact.sa_flags = SA_NOCLDSTOP;
726 if (sigaction(SIGCHLD, &sigact, NULL) == -1) {
727 ERRMSG("est_dpi_sigchld", "sigaction", errno);
728 exit(1);
729 }
730}
731
733int ckd_connect (int sock_fd, struct sockaddr *addr, socklen_t len)
734{
735 ssize_t ret;
736
737 do {
738 ret = connect(sock_fd, addr, len);
739 } while (ret == -1 && errno == EINTR);
740 if (ret == -1) {
741 ERRMSG("dpid.c", "connect", errno);
742 }
743 return ret;
744}
745
749{
750 char *bye_cmd, *auth_cmd;
751 int i, sock_fd;
752 struct sockaddr_in sin;
753
754 bye_cmd = a_Dpip_build_cmd("cmd=%s", "DpiBye");
755 auth_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "auth", SharedKey);
756
757 memset(&sin, 0, sizeof(sin));
758 sin.sin_family = AF_INET;
759 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
760
761 for (i = 0; i < numdpis; i++) {
762 /* Skip inactive dpis and filters */
763 if (dpi_attr_list[i].pid == 1 || dpi_attr_list[i].filter)
764 continue;
765
766 if ((sock_fd = make_socket_fd()) == -1) {
767 ERRMSG("stop_active_dpis", "socket", errno);
768 continue;
769 }
770
771 sin.sin_port = htons(dpi_attr_list[i].port);
772 if (ckd_connect(sock_fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
773 ERRMSG("stop_active_dpis", "connect", errno);
774 MSG_ERR("%s\n", dpi_attr_list[i].path);
775 } else if (CKD_WRITE(sock_fd, auth_cmd) == -1) {
776 ERRMSG("stop_active_dpis", "write", errno);
777 } else if (CKD_WRITE(sock_fd, bye_cmd) == -1) {
778 ERRMSG("stop_active_dpis", "write", errno);
779 }
780 dClose(sock_fd);
781 }
782
783 dFree(auth_cmd);
784 dFree(bye_cmd);
785
786 /* Allow child dpis some time to read dpid_comm_keys before erasing it */
787 sleep (1);
788}
789
795{
796 int i;
797
798 for (i = 0; i < numdpis; i++) {
799 FD_CLR(dpi_attr_list[i].sock_fd, &sock_set);
800 dClose(dpi_attr_list[i].sock_fd);
801 }
802}
803
826
832char *get_message(int sock_fd, char *dpi_tag)
833{
834 char *msg, *d_cmd;
835
836 msg = a_Dpip_get_attr(dpi_tag, "msg");
837 if (msg == NULL) {
838 ERRMSG("get_message", "failed to parse msg", 0);
839 d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s",
840 "DpiError", "Failed to parse request");
841 (void) CKD_WRITE(sock_fd, d_cmd);
842 dFree(d_cmd);
843 }
844 return (msg);
845}
846
847/*
848 * Compare a struct service pointer and a service name
849 * This function is used for searching services by name
850 */
851int service_match(const struct service *A, const char *B)
852{
853 int A_len, B_len, len;
854
855 A_len = strlen(A->name);
856 B_len = strlen(B);
857 len = MAX (A_len, B_len);
858
859 if (A->name[A_len - 1] == '*')
860 len = A_len - 1;
861
862 return(dStrnAsciiCasecmp(A->name, B, len));
863}
864
868void send_sockport(int sock_fd, char *dpi_tag, struct dp *dpi_attr_list)
869{
870 int i;
871 char *dpi_id, *d_cmd, port_str[16];
872 struct service *serv;
873
874 dReturn_if_fail((dpi_id = get_message(sock_fd, dpi_tag)) != NULL);
875
877
878 if (serv == NULL || (i = serv->dp_index) == -1)
879 for (i = 0; i < numdpis; i++)
880 if (!strncmp(dpi_attr_list[i].id, dpi_id,
881 dpi_attr_list[i].id - strchr(dpi_attr_list[i].id, '.')))
882 break;
883
884 if (i < numdpis) {
885 /* found */
886 snprintf(port_str, 8, "%d", dpi_attr_list[i].port);
887 d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "send_data", port_str);
888 (void) CKD_WRITE(sock_fd, d_cmd);
889 dFree(d_cmd);
890 }
891
892 dFree(dpi_id);
893}
#define _MSG(...)
Definition bookmarks.c:45
#define MSG(...)
Definition bookmarks.c:46
char * dGetline(FILE *stream)
Get a line from a FILE stream.
Definition dlib.c:928
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
Definition dlib.c:102
void dFree(void *mem)
Definition dlib.c:68
char * dStrdup(const char *s)
Definition dlib.c:77
Dlist * dList_new(int size)
Create a new empty list.
Definition dlib.c:548
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)
Definition dlib.c:215
int dList_length(Dlist *lp)
For completing the ADT.
Definition dlib.c:613
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
Definition dlib.c:662
int dClose(int fd)
Close a FD handling EINTR.
Definition dlib.c:951
void dList_sort(Dlist *lp, dCompareFunc func)
Sort the list using a custom function.
Definition dlib.c:758
void dList_append(Dlist *lp, void *data)
Append a data item to the list.
Definition dlib.c:597
void dList_free(Dlist *lp)
Free a list (not its elements)
Definition dlib.c:564
void * dList_find_custom(Dlist *lp, const void *data, dCompareFunc func)
Search a data item using a custom function.
Definition dlib.c:704
int dParser_parse_rc_line(char **line, char **name, char **value)
Take a dillo rc line and return 'name' and 'value' pointers to it.
Definition dlib.c:834
void * dRealloc(void *mem, size_t size)
Definition dlib.c:53
char * dGethomedir(void)
Return the home directory in a static string (don't free)
Definition dlib.c:906
#define dStrerror
Definition dlib.h:95
#define dReturn_if_fail(expr)
Definition dlib.h:72
int(* dCompareFunc)(const void *a, const void *b)
Definition dlib.h:144
#define MAX(a, b)
Definition dlib.h:27
#define dNew(type, count)
Definition dlib.h:49
void send_sockport(int sock_fd, char *dpi_tag, struct dp *dpi_attr_list)
Definition dpid.c:868
void free_services_list(Dlist *s_list)
Definition dpid.c:94
static void terminator(int sig)
Definition dpid.c:108
char * SharedKey
Definition dpid.c:46
void free_dpi_attr(struct dp *dpi_attr)
Definition dpid.c:63
int init_all_dpi_sockets(struct dp *dpi_attr_list)
Definition dpid.c:671
int bind_socket_fd(int base_port, int *p_port)
Definition dpid.c:554
volatile sig_atomic_t caught_sigchld
Definition dpid.c:45
int register_all_cmd(void)
Definition dpid.c:811
char * get_message(int sock_fd, char *dpi_tag)
Definition dpid.c:832
static int ends_with(const char *str, const char *suffix)
Definition dpid.c:147
int register_all(struct dp **attlist)
Definition dpid.c:347
int init_dpi_socket(struct dp *dpi_attr)
Definition dpid.c:647
int init_ids_srs_socket(void)
Definition dpid.c:623
int ckd_connect(int sock_fd, struct sockaddr *addr, socklen_t len)
Definition dpid.c:733
void est_dpi_sigchld(void)
Definition dpid.c:717
void handle_sigchld(void)
Definition dpid.c:694
int get_dpi_attr(char *dpi_dir, char *service, struct dp *dpi_attr)
Definition dpid.c:233
int service_match(const struct service *A, const char *B)
Definition dpid.c:851
void stop_active_dpis(struct dp *dpi_attr_list, int numdpis)
Definition dpid.c:748
#define DPI_EXT
Definition dpid.c:41
static int make_socket_fd(void)
Definition dpid.c:531
int register_service(struct dp *dpi_attr, char *service)
Definition dpid.c:293
void est_dpi_terminator(void)
Definition dpid.c:117
static int services_alpha_comp(const struct service *s1, const struct service *s2)
Definition dpid.c:424
#define QUEUE
Definition dpid.c:43
enum file_type get_file_type(char *file_name)
Definition dpid.c:162
int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
Definition dpid.c:437
char * get_dpi_dir(char *dpidrc)
Definition dpid.c:179
void free_plugin_list(struct dp **dpi_attr_list_ptr, int numdpis)
Definition dpid.c:77
void dpi_sigchld(int sig)
Definition dpid.c:687
void ignore_dpi_sockets(struct dp *dpi_attr_list, int numdpis)
Definition dpid.c:794
void cleanup(void)
Definition dpid.c:52
int save_comm_keys(int srs_port)
Definition dpid.c:598
Dlist * services_list
Definition main.c:48
#define DPID_BASE_PORT
Definition dpid.h:24
int numdpis
Definition main.c:45
int numsocks
Definition main.c:49
fd_set sock_set
Definition main.c:46
struct dp * dpi_attr_list
Definition main.c:47
int srs_fd
Definition main.c:50
#define CKD_WRITE(fd, msg)
Definition dpid_common.h:37
#define MSG_ERR(...)
Definition dpid_common.h:23
#define dotDILLO_DPI
Definition dpid_common.h:25
#define ERRMSG(CALLER, CALLED, ERR)
Definition dpid_common.h:29
#define CKD_CLOSE(fd)
Definition dpid_common.h:38
file_type
Definition dpid_common.h:43
@ DPI_FILE
Definition dpid_common.h:44
@ UNKNOWN_FILE
Definition dpid_common.h:45
#define dotDILLO_DPIDRC
Definition dpid_common.h:26
#define dotDILLO_DPID_COMM_KEYS
Definition dpid_common.h:27
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
Definition dpip.c:83
char * a_Dpip_get_attr(const char *tag, const char *attrname)
Task: given a tag and an attribute name, return its value.
Definition dpip.c:192
char * a_Misc_mksecret(int nchar)
Return a new, random hexadecimal string of 'nchar' characters.
Definition misc_new.c:181
Definition dlib.h:131
Definition dpid.h:35
int filter
Definition dpid.h:41
char * path
Definition dpid.h:37
int sock_fd
Definition dpid.h:38
char * id
Definition dpid.h:36
int port
Definition dpid.h:39
pid_t pid
Definition dpid.h:40
Definition dpid.h:46
int dp_index
Definition dpid.h:48
char * name
Definition dpid.h:47
static void path()
Definition cookies.c:859