Dillo v3.1.1-98-g318d1f14
|
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"
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_t * | ValidConns = NULL |
static char | SharedKey [32] |
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.
#define D_SUN_LEN | ( | ptr | ) |
void a_Dpi_ccc | ( | int | Op, |
int | Branch, | ||
int | Dir, | ||
ChainLink * | Info, | ||
void * | Data1, | ||
void * | Data2 | ||
) |
CCC function for the Dpi module.
Definition at line 646 of file dpi.c.
References a_Chain_bcb(), a_Chain_check(), a_Chain_fcb(), a_Chain_link_new(), a_Dpi_ccc(), a_IO_ccc(), BCK, dFree(), dNew, Dpi_blocking_start_dpid(), Dpi_conn_free(), Dpi_conn_new(), Dpi_connect_socket(), Dpi_process_dbuf(), dReturn_if_fail, FWD, IORead, ChainLink::LocalKey, MSG_ERR, MSG_WARN, OpAbort, OpEnd, OpSend, and OpStart.
Referenced by a_Capi_ccc(), and a_Dpi_ccc().
void a_Dpi_dillo_exit | ( | void | ) |
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
static |
Definition at line 79 of file dpi.c.
Referenced by Dpi_connect_socket(), and Dpi_read_comm_keys().
|
static |
Definition at line 77 of file dpi.c.
Referenced by Dpi_conn_free(), Dpi_conn_new(), and Dpi_conn_valid().