Dillo v3.1.1-119-g140d9ebd
|
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "dpid_common.h"
#include "dpid.h"
#include "dpi.h"
#include "dpi_socket_dir.h"
#include "misc_new.h"
#include "../dpip/dpip.h"
Go to the source code of this file.
Macros | |
#define | DPI_EXT (".dpi" EXEEXT) |
#define | QUEUE 5 |
Functions | |
void | cleanup (void) |
void | free_dpi_attr (struct dp *dpi_attr) |
void | free_plugin_list (struct dp **dpi_attr_list_ptr, int numdpis) |
void | free_services_list (Dlist *s_list) |
static void | terminator (int sig) |
void | est_dpi_terminator (void) |
static int | ends_with (const char *str, const char *suffix) |
enum file_type | get_file_type (char *file_name) |
char * | get_dpi_dir (char *dpidrc) |
int | get_dpi_attr (char *dpi_dir, char *service, struct dp *dpi_attr) |
int | register_service (struct dp *dpi_attr, char *service) |
int | register_all (struct dp **attlist) |
static int | services_alpha_comp (const struct service *s1, const struct service *s2) |
int | fill_services_list (struct dp *attlist, int numdpis, Dlist **services_list) |
static int | make_socket_fd (void) |
int | bind_socket_fd (int base_port, int *p_port) |
int | save_comm_keys (int srs_port) |
int | init_ids_srs_socket (void) |
int | init_dpi_socket (struct dp *dpi_attr) |
int | init_all_dpi_sockets (struct dp *dpi_attr_list) |
void | dpi_sigchld (int sig) |
void | handle_sigchld (void) |
void | est_dpi_sigchld (void) |
int | ckd_connect (int sock_fd, struct sockaddr *addr, socklen_t len) |
void | stop_active_dpis (struct dp *dpi_attr_list, int numdpis) |
void | ignore_dpi_sockets (struct dp *dpi_attr_list, int numdpis) |
int | register_all_cmd (void) |
char * | get_message (int sock_fd, char *dpi_tag) |
int | service_match (const struct service *A, const char *B) |
void | send_sockport (int sock_fd, char *dpi_tag, struct dp *dpi_attr_list) |
Variables | |
volatile sig_atomic_t | caught_sigchld = 0 |
char * | SharedKey = NULL |
Main functions to set-up dpi information and to initialise sockets
Definition in file dpid.c.
int bind_socket_fd | ( | int | base_port, |
int * | p_port | ||
) |
Bind a socket port on localhost. Try to be close to base_port. \Return
Definition at line 554 of file dpid.c.
References ERRMSG, make_socket_fd(), MSG_ERR, and QUEUE.
Referenced by init_dpi_socket(), and init_ids_srs_socket().
int ckd_connect | ( | int | sock_fd, |
struct sockaddr * | addr, | ||
socklen_t | len | ||
) |
EINTR aware connect() call
Definition at line 733 of file dpid.c.
References ERRMSG.
Referenced by stop_active_dpis().
void cleanup | ( | void | ) |
Remove dpid_comm_keys file. This avoids that dillo instances connect to a stale port after dpid has exited (e.g. after a reboot).
Definition at line 52 of file dpid.c.
References dFree(), dGethomedir(), dotDILLO_DPID_COMM_KEYS, and dStrconcat().
Referenced by est_dpi_terminator(), and terminator().
void dpi_sigchld | ( | int | sig | ) |
SIGCHLD handler
Definition at line 687 of file dpid.c.
References caught_sigchld.
Referenced by est_dpi_sigchld().
|
static |
Definition at line 147 of file dpid.c.
Referenced by get_file_type().
void est_dpi_sigchld | ( | void | ) |
Establish SIGCHLD handler
Definition at line 717 of file dpid.c.
References dpi_sigchld(), and ERRMSG.
Referenced by main().
void est_dpi_terminator | ( | void | ) |
Add services reading a dpidrc file each non empty or commented line has the form service = path_relative_to_dpidir \Return:
Definition at line 437 of file dpid.c.
References _MSG, dFree(), dGethomedir(), dGetline(), dList_append(), dList_length(), dList_new(), dList_sort(), dNew, dotDILLO_DPI, dotDILLO_DPIDRC, service::dp_index, dParser_parse_rc_line(), dStrconcat(), dStrdup(), ERRMSG, get_dpi_dir(), MSG_ERR, service::name, numdpis, path(), services_alpha_comp(), and services_list.
Referenced by main(), and register_all_cmd().
void free_dpi_attr | ( | struct dp * | dpi_attr | ) |
void free_plugin_list | ( | struct dp ** | dpi_attr_list_ptr, |
int | numdpis | ||
) |
Free memory used by the plugin list
Definition at line 77 of file dpid.c.
References dFree(), dpi_attr_list, free_dpi_attr(), and numdpis.
Referenced by register_all_cmd().
void free_services_list | ( | Dlist * | s_list | ) |
Free memory used by the services list
Definition at line 94 of file dpid.c.
References dFree(), dList_free(), dList_length(), dList_nth_data(), and service::name.
Referenced by register_all_cmd().
int get_dpi_attr | ( | char * | dpi_dir, |
char * | service, | ||
struct dp * | dpi_attr | ||
) |
Scans a service directory in dpi_dir and fills dpi_attr \Note Caller must allocate memory for dpi_attr. \Return
Definition at line 233 of file dpid.c.
References dFree(), DPI_FILE, dStrconcat(), dStrdup(), ERRMSG, dp::filter, get_file_type(), dp::id, MSG_ERR, dp::path, dp::pid, and dp::port.
Referenced by register_all(), and register_service().
char * get_dpi_dir | ( | char * | dpidrc | ) |
Get dpi directory path from dpidrc \Return dpi directory on success, NULL on failure \Important The dpi_dir definition in dpidrc must have no leading white space.
Definition at line 179 of file dpid.c.
References dFree(), dGetline(), dStrdup(), ERRMSG, and MSG_ERR.
Referenced by fill_services_list(), register_all(), and register_service().
enum file_type get_file_type | ( | char * | file_name | ) |
Identify a given file Currently there is only one file type associated with dpis. More file types will be added as needed
Definition at line 162 of file dpid.c.
References DPI_EXT, DPI_FILE, ends_with(), MSG_ERR, and UNKNOWN_FILE.
Referenced by get_dpi_attr().
char * get_message | ( | int | sock_fd, |
char * | dpi_tag | ||
) |
Get value of msg field from dpi_tag \Return message on success, NULL on failure
Definition at line 832 of file dpid.c.
References a_Dpip_build_cmd(), a_Dpip_get_attr(), CKD_WRITE, dFree(), and ERRMSG.
Referenced by send_sockport().
void handle_sigchld | ( | void | ) |
void ignore_dpi_sockets | ( | struct dp * | dpi_attr_list, |
int | numdpis | ||
) |
int init_all_dpi_sockets | ( | struct dp * | dpi_attr_list | ) |
Setup sockets for the plugins and add them to the set of sockets (sock_set) watched by select. \Return
Definition at line 671 of file dpid.c.
References dpi_attr_list, init_dpi_socket(), numdpis, and numsocks.
Referenced by main(), and register_all_cmd().
int init_dpi_socket | ( | struct dp * | dpi_attr | ) |
Initialize a single dpi socket \Return
Definition at line 647 of file dpid.c.
References bind_socket_fd(), DPID_BASE_PORT, dp::port, dp::sock_fd, and sock_set.
Referenced by init_all_dpi_sockets().
int init_ids_srs_socket | ( | void | ) |
Initialise the service request socket (IDS) \Return:
Definition at line 623 of file dpid.c.
References a_Misc_mksecret(), bind_socket_fd(), DPID_BASE_PORT, save_comm_keys(), SharedKey, sock_set, and srs_fd.
Referenced by main().
|
static |
Definition at line 531 of file dpid.c.
References ERRMSG.
Referenced by bind_socket_fd(), and stop_active_dpis().
int register_all | ( | struct dp ** | attlist | ) |
Create dpi directory for available plugins and create plugin list. \Return
Definition at line 347 of file dpid.c.
References dFree(), dGethomedir(), dotDILLO_DPI, dotDILLO_DPIDRC, dRealloc(), dStrconcat(), dStrdup(), ERRMSG, get_dpi_attr(), get_dpi_dir(), and MSG_ERR.
Referenced by main(), and register_all_cmd().
int register_all_cmd | ( | void | ) |
Registers available dpis and stops active non-filter dpis. Called when dpid receives cmd='register' service='all' command \Return Number of available dpis
Definition at line 811 of file dpid.c.
References dpi_attr_list, fill_services_list(), free_plugin_list(), free_services_list(), init_all_dpi_sockets(), numdpis, numsocks, register_all(), services_list, sock_set, srs_fd, and stop_active_dpis().
Referenced by main().
int register_service | ( | struct dp * | dpi_attr, |
char * | service | ||
) |
Register a service Retrieves attributes for "service" and stores them in dpi_attr. It looks for "service" in ~/.dillo/dpi first, and then in the system wide dpi directory. Caller must allocate memory for dpi_attr. \Return
Definition at line 293 of file dpid.c.
References dFree(), dGethomedir(), dotDILLO_DPI, dotDILLO_DPIDRC, dStrconcat(), dStrdup(), ERRMSG, get_dpi_attr(), get_dpi_dir(), and MSG_ERR.
int save_comm_keys | ( | int | srs_port | ) |
Save the current port and a shared secret in a file so dillo can find it. \Return:
Definition at line 598 of file dpid.c.
References CKD_CLOSE, CKD_WRITE, dFree(), dGethomedir(), dotDILLO_DPID_COMM_KEYS, dStrconcat(), dStrerror, MSG, and SharedKey.
Referenced by init_ids_srs_socket().
void send_sockport | ( | int | sock_fd, |
char * | dpi_tag, | ||
struct dp * | dpi_attr_list | ||
) |
Send socket port that matches dpi_id to client
Definition at line 868 of file dpid.c.
References a_Dpip_build_cmd(), CKD_WRITE, dFree(), dList_find_custom(), service::dp_index, dpi_attr_list, dReturn_if_fail, get_message(), numdpis, service_match(), and services_list.
Referenced by main().
int service_match | ( | const struct service * | A, |
const char * | B | ||
) |
Definition at line 851 of file dpid.c.
References dStrnAsciiCasecmp(), MAX, and service::name.
Referenced by send_sockport().
Definition at line 424 of file dpid.c.
References service::name.
Referenced by fill_services_list().
void stop_active_dpis | ( | struct dp * | dpi_attr_list, |
int | numdpis | ||
) |
Send DpiBye command to all active non-filter dpis
Definition at line 748 of file dpid.c.
References a_Dpip_build_cmd(), ckd_connect(), CKD_WRITE, dClose(), dFree(), dpi_attr_list, ERRMSG, make_socket_fd(), MSG_ERR, numdpis, path(), and SharedKey.
Referenced by main(), and register_all_cmd().
|
static |
Signal handler for SIGINT, SIGQUIT, and SIGTERM. Calls cleanup
Definition at line 108 of file dpid.c.
References cleanup().
Referenced by est_dpi_terminator().
volatile sig_atomic_t caught_sigchld = 0 |
Set to 1 by the SIGCHLD handler dpi_sigchld
Definition at line 45 of file dpid.c.
Referenced by dpi_sigchld().
char* SharedKey = NULL |
Definition at line 46 of file dpid.c.
Referenced by init_ids_srs_socket(), save_comm_keys(), and stop_active_dpis().