Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dpi.c File Reference

Dillo plugins (small programs that interact with dillo). More...

#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "../msg.h"
#include "../klist.h"
#include "IO.h"
#include "Url.h"
#include "../../dpip/dpip.h"
#include "dlib/dlib.h"
Include dependency graph for dpi.c:

Go to the source code of this file.

Macros

#define D_SUN_LEN(ptr)
 
#define AF_LOCAL   AF_UNIX
 

Functions

void a_Dpi_init (void)
 
static dpi_conn_t * Dpi_conn_new (ChainLink *Info)
 Create a new connection data structure.
 
static void Dpi_conn_free (dpi_conn_t *conn)
 Free a connection data structure.
 
static int Dpi_conn_valid (int key)
 Check whether a conn is still valid.
 
static void Dpi_append_dbuf (dpi_conn_t *conn, DataBuf *dbuf)
 Append the new buffer in 'dbuf' to Buf in 'conn'.
 
static int Dpi_get_token (dpi_conn_t *conn)
 Split the data stream into tokens.
 
static void Dpi_parse_token (dpi_conn_t *conn)
 Parse a dpi tag and take the appropriate actions.
 
static int Dpi_blocking_write (int fd, const char *msg, int msg_len)
 Write data into a file descriptor taking care of EINTR and possible data splits.
 
static char * Dpi_blocking_read (int fd)
 Read all the available data from a filedescriptor.
 
static void Dpi_process_dbuf (int Op, void *Data1, dpi_conn_t *conn)
 Get a new data buffer (within a 'dbuf'), save it into local data, split in tokens and parse the contents.
 
static int Dpi_start_dpid (void)
 Start dpid.
 
static int Dpi_read_comm_keys (int *port)
 Read dpid's communication keys from its saved file.
 
static int Dpi_make_socket_fd (void)
 Return a socket file descriptor.
 
static int Dpi_check_dpid_ids (void)
 Make a connection test for a IDS.
 
static int Dpi_check_dpid (int num_tries)
 Confirm that the dpid is running.
 
static int Dpi_blocking_start_dpid (void)
 Confirm that the dpid is running.
 
static int Dpi_get_server_port (const char *server_name)
 Return the dpi server's port number, or -1 on error.
 
static int Dpi_connect_socket (const char *server_name)
 Connect a socket to a dpi server and return the socket's FD.
 
void a_Dpi_ccc (int Op, int Branch, int Dir, ChainLink *Info, void *Data1, void *Data2)
 CCC function for the Dpi module.
 
void a_Dpi_dillo_exit (void)
 Let dpid know dillo is no longer running.
 
char * a_Dpi_send_blocking_cmd (const char *server_name, const char *cmd)
 Send a command to a dpi server, and block until the answer is got.
 

Variables

static Klist_tValidConns = NULL
 
static char SharedKey [32]
 

Detailed Description

Dillo plugins (small programs that interact with dillo).

Dillo plugins are designed to handle: bookmarks, cookies, FTP, downloads, files, preferences, https, datauri and a lot of any-to-html filters.

Definition in file dpi.c.

Macro Definition Documentation

◆ AF_LOCAL

#define AF_LOCAL   AF_UNIX

Definition at line 52 of file dpi.c.

◆ D_SUN_LEN

#define D_SUN_LEN (   ptr)
Value:
((size_t) (((struct sockaddr_un *) 0)->sun_path) \
+ strlen ((ptr)->sun_path))

Definition at line 47 of file dpi.c.

Function Documentation

◆ a_Dpi_ccc()

void a_Dpi_ccc ( int  Op,
int  Branch,
int  Dir,
ChainLink Info,
void *  Data1,
void *  Data2 
)

◆ a_Dpi_dillo_exit()

void a_Dpi_dillo_exit ( void  )

Let dpid know dillo is no longer running.

Note: currently disabled. It may serve to let the cookies dpi know when to expire session cookies.

Definition at line 761 of file dpi.c.

◆ a_Dpi_init()

void a_Dpi_init ( void  )

Definition at line 84 of file dpi.c.

Referenced by main().

◆ a_Dpi_send_blocking_cmd()

char * a_Dpi_send_blocking_cmd ( const char *  server_name,
const char *  cmd 
)

Send a command to a dpi server, and block until the answer is got.

Return value: the dpip tag answer as an string, NULL on error.

Definition at line 770 of file dpi.c.

References dClose(), Dpi_blocking_read(), Dpi_blocking_start_dpid(), Dpi_blocking_write(), Dpi_connect_socket(), and MSG_ERR.

Referenced by a_Cookies_get_query(), a_Cookies_get_query(), a_Cookies_set(), and a_Cookies_set().

◆ Dpi_append_dbuf()

static void Dpi_append_dbuf ( dpi_conn_t *  conn,
DataBuf dbuf 
)
static

Append the new buffer in 'dbuf' to Buf in 'conn'.

Definition at line 125 of file dpi.c.

References DataBuf::Buf, DataBuf::Code, dStr_append_l(), and DataBuf::Size.

Referenced by Dpi_process_dbuf().

◆ Dpi_blocking_read()

static char * Dpi_blocking_read ( int  fd)
static

Read all the available data from a filedescriptor.

This is intended for short answers, i.e. when we know the server will write it all before being preempted. For answers that may come as an stream with delays, non-blocking is better. Return value: read data, or NULL on error and no data.

Definition at line 283 of file dpi.c.

References dStr_append_l(), dStr_free(), dStr_sized_new(), dStrerror, FALSE, Dstr::len, MSG_ERR, Dstr::str, and TRUE.

Referenced by a_Dpi_send_blocking_cmd(), Dpi_get_server_port(), and Dpi_start_dpid().

◆ Dpi_blocking_start_dpid()

static int Dpi_blocking_start_dpid ( void  )
static

Confirm that the dpid is running.

If not, start it. Return: 0 running OK, 2 Error.

Definition at line 505 of file dpi.c.

References Dpi_check_dpid(), dUsleep(), and MSG.

Referenced by a_Dpi_ccc(), and a_Dpi_send_blocking_cmd().

◆ Dpi_blocking_write()

static int Dpi_blocking_write ( int  fd,
const char *  msg,
int  msg_len 
)
static

Write data into a file descriptor taking care of EINTR and possible data splits.

Return value: 1 on success, -1 on error.

Definition at line 256 of file dpi.c.

References dStrerror, and MSG_ERR.

Referenced by a_Dpi_send_blocking_cmd(), Dpi_connect_socket(), Dpi_get_server_port(), and Dpi_start_dpid().

◆ Dpi_check_dpid()

static int Dpi_check_dpid ( int  num_tries)
static

Confirm that the dpid is running.

If not, start it. Return: 0 running OK, 1 starting (EAGAIN), 2 Error.

Definition at line 468 of file dpi.c.

References _MSG, Dpi_check_dpid_ids(), and Dpi_start_dpid().

Referenced by Dpi_blocking_start_dpid().

◆ Dpi_check_dpid_ids()

static int Dpi_check_dpid_ids ( void  )
static

Make a connection test for a IDS.

Return: 1 OK, -1 Not working.

Definition at line 439 of file dpi.c.

References dClose(), Dpi_make_socket_fd(), Dpi_read_comm_keys(), dStrerror, and MSG.

Referenced by Dpi_check_dpid().

◆ Dpi_conn_free()

static void Dpi_conn_free ( dpi_conn_t *  conn)
static

Free a connection data structure.

Definition at line 106 of file dpi.c.

References a_Klist_remove(), dFree(), dStr_free(), and ValidConns.

Referenced by a_Dpi_ccc().

◆ Dpi_conn_new()

static dpi_conn_t * Dpi_conn_new ( ChainLink Info)
static

Create a new connection data structure.

Definition at line 92 of file dpi.c.

References a_Klist_insert(), dNew0, dStr_sized_new(), and ValidConns.

Referenced by a_Dpi_ccc().

◆ Dpi_conn_valid()

static int Dpi_conn_valid ( int  key)
static

Check whether a conn is still valid.

Return: 1 if found, 0 otherwise

Definition at line 117 of file dpi.c.

References a_Klist_get_data(), and ValidConns.

Referenced by Dpi_process_dbuf().

◆ Dpi_connect_socket()

static int Dpi_connect_socket ( const char *  server_name)
static

Connect a socket to a dpi server and return the socket's FD.

We have to ask 'dpid' (dpi daemon) for the port of the target dpi server. Once we have it, then the proper file descriptor is returned (-1 on error).

Definition at line 604 of file dpi.c.

References _MSG, a_Dpip_build_cmd(), dClose(), dFree(), Dpi_blocking_write(), Dpi_get_server_port(), Dpi_make_socket_fd(), dStrerror, MSG_ERR, and SharedKey.

Referenced by a_Dpi_ccc(), and a_Dpi_send_blocking_cmd().

◆ Dpi_get_server_port()

static int Dpi_get_server_port ( const char *  server_name)
static

Return the dpi server's port number, or -1 on error.

(A query is sent to dpid and then its answer parsed) note: as the available servers and/or the dpi socket directory can change at any time, we'll ask each time. If someday we find that connecting each time significantly degrades performance, an optimized approach can be tried.

Definition at line 526 of file dpi.c.

References _MSG, a_Dpip_build_cmd(), a_Dpip_get_attr(), dClose(), dFree(), Dpi_blocking_read(), Dpi_blocking_write(), Dpi_make_socket_fd(), Dpi_read_comm_keys(), dReturn_val_if_fail, dStrerror, and MSG.

Referenced by Dpi_connect_socket().

◆ Dpi_get_token()

static int Dpi_get_token ( dpi_conn_t *  conn)
static

Split the data stream into tokens.

Here, a token is either: a) a dpi tag b) a raw data chunk

Return Value: 0 upon a new token, -1 on not enough data.

TODO: define an API and move this function into libDpip.a.

Definition at line 142 of file dpi.c.

References _MSG, dStr_truncate(), and MSG_ERR.

Referenced by Dpi_process_dbuf().

◆ Dpi_make_socket_fd()

static int Dpi_make_socket_fd ( void  )
static

Return a socket file descriptor.

Definition at line 423 of file dpi.c.

Referenced by Dpi_check_dpid_ids(), Dpi_connect_socket(), and Dpi_get_server_port().

◆ Dpi_parse_token()

static void Dpi_parse_token ( dpi_conn_t *  conn)
static

Parse a dpi tag and take the appropriate actions.

Definition at line 199 of file dpi.c.

References _MSG, a_Chain_dbuf_new(), a_Chain_fcb(), a_Dpip_get_attr_l(), DataBuf::Buf, dFree(), dStrndup(), and OpSend.

Referenced by Dpi_process_dbuf().

◆ Dpi_process_dbuf()

static void Dpi_process_dbuf ( int  Op,
void *  Data1,
dpi_conn_t *  conn 
)
static

Get a new data buffer (within a 'dbuf'), save it into local data, split in tokens and parse the contents.

Definition at line 315 of file dpi.c.

References Dpi_append_dbuf(), Dpi_conn_valid(), Dpi_get_token(), Dpi_parse_token(), IOClose, and IORead.

Referenced by a_Dpi_ccc().

◆ Dpi_read_comm_keys()

static int Dpi_read_comm_keys ( int *  port)
static

Read dpid's communication keys from its saved file.

Return value: 1 on success, -1 on error.

Definition at line 394 of file dpi.c.

References dFree(), dGethomedir(), dGetline(), dStrconcat(), dStrerror, MSG_ERR, and SharedKey.

Referenced by Dpi_check_dpid_ids(), and Dpi_get_server_port().

◆ Dpi_start_dpid()

static int Dpi_start_dpid ( void  )
static

Start dpid.

Return: 0 starting now, 1 Error.

Definition at line 339 of file dpi.c.

References dClose(), dFree(), dGethomedir(), Dpi_blocking_read(), Dpi_blocking_write(), dStrconcat(), dStrerror, and MSG.

Referenced by Dpi_check_dpid().

Variable Documentation

◆ SharedKey

char SharedKey[32]
static

Definition at line 79 of file dpi.c.

Referenced by Dpi_connect_socket(), and Dpi_read_comm_keys().

◆ ValidConns

Klist_t* ValidConns = NULL
static

Definition at line 77 of file dpi.c.

Referenced by Dpi_conn_free(), Dpi_conn_new(), and Dpi_conn_valid().