Dillo v3.1.1-95-g3af05307
Loading...
Searching...
No Matches
dpid.h File Reference
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/un.h>
#include <signal.h>
#include <netinet/in.h>
#include "d_size.h"
Include dependency graph for dpid.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dp
 
struct  service
 

Macros

#define IPPORT_USERRESERVED   5000
 
#define PATH_LEN   50
 
#define CMDLEN   20
 
#define MSGLEN   50
 
#define DPID_BASE_PORT   (IPPORT_USERRESERVED + 20)
 
#define SRS_NAME   "dpid.srs"
 

Functions

void rm_dpi_sockets (struct dp *dpi_attr_list, int numdpis)
 
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)
 
enum file_type get_file_type (char *file_name)
 
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)
 
int fill_services_list (struct dp *attlist, int numdpis, Dlist **services_list)
 
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)
 
void est_dpi_terminator (void)
 
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, 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

char * srs_name
 
int srs_fd
 
int numdpis
 
int numsocks
 
struct dpdpi_attr_list
 
Dlistservices_list
 
fd_set sock_set
 
volatile sig_atomic_t caught_sigchld
 

Detailed Description

Main functions to set-up dpi information and to initialise sockets

Definition in file dpid.h.

Macro Definition Documentation

◆ CMDLEN

#define CMDLEN   20

Definition at line 22 of file dpid.h.

◆ DPID_BASE_PORT

#define DPID_BASE_PORT   (IPPORT_USERRESERVED + 20)

Definition at line 24 of file dpid.h.

◆ IPPORT_USERRESERVED

#define IPPORT_USERRESERVED   5000

Definition at line 18 of file dpid.h.

◆ MSGLEN

#define MSGLEN   50

Definition at line 23 of file dpid.h.

◆ PATH_LEN

#define PATH_LEN   50

Definition at line 21 of file dpid.h.

◆ SRS_NAME

#define SRS_NAME   "dpid.srs"

\TODO: Should read this from dillorc

Definition at line 27 of file dpid.h.

Function Documentation

◆ cleanup()

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().

◆ dpi_sigchld()

void dpi_sigchld ( int  sig)

SIGCHLD handler

Definition at line 687 of file dpid.c.

References caught_sigchld.

Referenced by est_dpi_sigchld().

◆ est_dpi_sigchld()

void est_dpi_sigchld ( void  )

Establish SIGCHLD handler

Definition at line 717 of file dpid.c.

References dpi_sigchld(), and ERRMSG.

Referenced by main().

◆ est_dpi_terminator()

void est_dpi_terminator ( void  )

Establish handler for termination signals and register cleanup with atexit

Definition at line 117 of file dpid.c.

References cleanup(), ERRMSG, MSG_ERR, and terminator().

Referenced by main().

◆ fill_services_list()

int fill_services_list ( struct dp attlist,
int  numdpis,
Dlist **  services_list 
)

Add services reading a dpidrc file each non empty or commented line has the form service = path_relative_to_dpidir \Return:

  • Returns number of available services on success
  • -1 on failure

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().

◆ free_dpi_attr()

void free_dpi_attr ( struct dp dpi_attr)

Free memory used to describe a set of dpi attributes

Definition at line 63 of file dpid.c.

References dFree(), dp::id, and dp::path.

Referenced by free_plugin_list().

◆ free_plugin_list()

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().

◆ free_services_list()

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().

◆ get_dpi_attr()

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

  • 0 on success
  • -1 on failure
    Todo:
    Add other file types, but first we need to add files associated with a dpi to the design.

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().

◆ get_file_type()

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().

◆ get_message()

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().

◆ handle_sigchld()

void handle_sigchld ( void  )

Called by main loop when caught_sigchld == 1

Definition at line 694 of file dpid.c.

References dpi_attr_list, numdpis, numsocks, dp::pid, and sock_set.

Referenced by main().

◆ ignore_dpi_sockets()

void ignore_dpi_sockets ( struct dp dpi_attr_list,
int  numdpis 
)

Removes dpis in dpi_attr_list from the set of sockets watched by select and closes their sockets.

Definition at line 794 of file dpid.c.

References dClose(), dpi_attr_list, numdpis, and sock_set.

◆ init_all_dpi_sockets()

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

  • Number of sockets on success
  • -1 on failure \Modifies dpi_attr_list.sa, dpi_attr_list.socket, numsocks, sock_set, srs \Uses numdpis, srs, srs_name

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().

◆ init_dpi_socket()

int init_dpi_socket ( struct dp dpi_attr)

Initialize a single dpi socket \Return

  • 1 on success
  • -1 on failure

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().

◆ init_ids_srs_socket()

int init_ids_srs_socket ( void  )

Initialise the service request socket (IDS) \Return:

  • Number of sockets (1 == success)
  • -1 on failure

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().

◆ register_all()

int register_all ( struct dp **  attlist)

Create dpi directory for available plugins and create plugin list. \Return

  • Returns number of available plugins on success
  • -1 on failure

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().

◆ 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().

◆ register_service()

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

  • 0 on success
  • -1 on failure

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.

◆ rm_dpi_sockets()

void rm_dpi_sockets ( struct dp dpi_attr_list,
int  numdpis 
)

◆ send_sockport()

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().

◆ service_match()

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().

◆ stop_active_dpis()

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().

Variable Documentation

◆ caught_sigchld

volatile sig_atomic_t caught_sigchld
extern

Set to 1 by the SIGCHLD handler dpi_sigchld

Definition at line 218 of file downloads.cc.

Referenced by cleanup_cb(), dpi_sigchld(), main(), and raw_sigchld().

◆ dpi_attr_list

struct dp* dpi_attr_list
extern

◆ numdpis

◆ numsocks

int numsocks
extern

Number of sockets being watched

Definition at line 49 of file main.c.

Referenced by handle_sigchld(), init_all_dpi_sockets(), main(), and register_all_cmd().

◆ services_list

Dlist* services_list
extern

service served for each plugin

Definition at line 48 of file main.c.

Referenced by fill_services_list(), main(), register_all_cmd(), and send_sockport().

◆ sock_set

fd_set sock_set
extern

Set of sockets watched for connections

Definition at line 46 of file main.c.

Referenced by handle_sigchld(), ignore_dpi_sockets(), init_dpi_socket(), init_ids_srs_socket(), main(), and register_all_cmd().

◆ srs_fd

int srs_fd
extern

dpid's service request socket file descriptor

Definition at line 50 of file main.c.

Referenced by init_ids_srs_socket(), main(), and register_all_cmd().

◆ srs_name

char* srs_name
extern

Definition at line 44 of file main.c.

Referenced by a_Dpi_srs().