Dillo v3.1.1-99-gf3103cc4
Loading...
Searching...
No Matches
capi.c File Reference

Cache API. More...

#include <string.h>
#include <errno.h>
#include "config.h"
#include "msg.h"
#include "capi.h"
#include "IO/IO.h"
#include "IO/Url.h"
#include "chain.h"
#include "history.h"
#include "nav.h"
#include "dpiapi.h"
#include "uicmd.hh"
#include "domain.h"
#include "../dpip/dpip.h"
#include "bookmark.h"
Include dependency graph for capi.c:

Go to the source code of this file.

Enumerations

enum  { PENDING = 1 , TIMEOUT = 2 , ABORTED = 4 }
 Flags for conn. More...
 

Functions

void a_Capi_ccc (int Op, int Branch, int Dir, ChainLink *Info, void *Data1, void *Data2)
 CCC function for the CAPI module.
 
void a_Capi_init (void)
 Initialize capi&cache data.
 
static capi_conn_t * Capi_conn_new (const DilloUrl *url, void *bw, char *server, char *datastr)
 Create a new connection data structure.
 
static capi_conn_t * Capi_conn_valid (capi_conn_t *conn)
 Validate a capi_conn_t pointer.
 
static void Capi_conn_ref (capi_conn_t *conn)
 Increment the reference count and add to the list if not present.
 
static void Capi_conn_unref (capi_conn_t *conn)
 Decrement the reference count (and remove from list when zero)
 
static int Capi_conn_by_server_cmp (const void *v1, const void *v2)
 Compare function for searching a conn by server string.
 
static capi_conn_t * Capi_conn_find (char *server)
 Find connection data by server.
 
static void Capi_conn_resume (void)
 Resume connections that were waiting for dpid to start.
 
void a_Capi_conn_abort_by_url (const DilloUrl *url)
 Abort the connection for a given url, using its CCC.
 
void a_Capi_set_vsource_url (const DilloUrl *url)
 Store the last URL requested by "view source".
 
int a_Capi_dpi_verify_request (BrowserWindow *bw, DilloUrl *url)
 Safety test: only allow GET|POST dpi-urls from dpi-generated pages.
 
static int Capi_url_uses_dpi (DilloUrl *url, char **server_ptr)
 If the url belongs to a dpi server, return its name.
 
static char * Capi_dpi_build_cmd (DilloWeb *web, char *server)
 Build the dpip command tag, according to URL and server.
 
static void Capi_dpi_send_source (BrowserWindow *bw, DilloUrl *url)
 Send the requested URL's source to the "view source" dpi.
 
static bool_t Capi_request_permitted (DilloWeb *web)
 Shall we permit this request to open a URL?
 
int a_Capi_open_url (DilloWeb *web, CA_Callback_t Call, void *CbData)
 Most used function for requesting a URL.
 
static int Capi_map_cache_flags (uint_t flags)
 Convert cache-defined flags to Capi ones.
 
int a_Capi_get_flags (const DilloUrl *Url)
 Return status information of an URL's content-transfer process.
 
int a_Capi_get_flags_with_redirection (const DilloUrl *Url)
 Same as a_Capi_get_flags() but following redirections.
 
int a_Capi_get_buf (const DilloUrl *Url, char **PBuf, int *BufSize)
 Get the cache's buffer for the URL, and its size.
 
void a_Capi_unref_buf (const DilloUrl *Url)
 Unref the cache's buffer when no longer using it.
 
const char * a_Capi_get_content_type (const DilloUrl *url)
 Get the Content-Type associated with the URL.
 
const char * a_Capi_set_content_type (const DilloUrl *url, const char *ctype, const char *from)
 Set the Content-Type for the URL.
 
int a_Capi_dpi_send_data (const DilloUrl *url, void *bw, char *data, int data_sz, char *server, int flags)
 Send data to a dpi (e.g.
 
int a_Capi_dpi_send_cmd (DilloUrl *url, void *bw, char *cmd, char *server, int flags)
 Send a dpi cmd.
 
void a_Capi_stop_client (int Key, int force)
 Remove a client from the cache client queue.
 

Variables

static DlistCapiConns
 Data list for active dpi connections.
 
static DilloUrlCapiVsUrl = NULL
 Last URL asked for view source.
 

Detailed Description

Cache API.

This is the module that manages the cache and starts the CCC chains to get the requests served. Kind of a broker.

Definition in file capi.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Flags for conn.

Enumerator
PENDING 
TIMEOUT 
ABORTED 

Definition at line 53 of file capi.c.

Function Documentation

◆ a_Capi_ccc()

◆ a_Capi_conn_abort_by_url()

void a_Capi_conn_abort_by_url ( const DilloUrl url)

Abort the connection for a given url, using its CCC.

(OpAbort 2,BCK removes the cache entry) TODO: when conn is already done, the cache entry isn't removed. This may be wrong and needs a revision.

Definition at line 199 of file capi.c.

References a_Capi_ccc(), a_Url_cmp(), BCK, CapiConns, dList_length(), dList_nth_data(), and OpAbort.

Referenced by a_Capi_open_url(), a_Capi_stop_client(), and Cache_process_queue().

◆ a_Capi_dpi_send_cmd()

int a_Capi_dpi_send_cmd ( DilloUrl url,
void *  bw,
char *  cmd,
char *  server,
int  flags 
)

Send a dpi cmd.

(For instance: add_bookmark, open_url, send_preferences, ...)

Definition at line 611 of file capi.c.

References a_Capi_dpi_send_data().

Referenced by a_Bookmarks_chat_add(), a_Capi_open_url(), Capi_dpi_send_source(), and Dpiapi_dialog_answer_cb().

◆ a_Capi_dpi_send_data()

int a_Capi_dpi_send_data ( const DilloUrl url,
void *  bw,
char *  data,
int  data_sz,
char *  server,
int  flags 
)

Send data to a dpi (e.g.

add_bookmark, open_url, send_preferences, ...). Most of the time we send dpi commands, but it also serves for raw data as with "view source".

Definition at line 576 of file capi.c.

References a_Capi_ccc(), a_Chain_dbuf_new(), a_Chain_new(), BCK, Capi_conn_find(), Capi_conn_new(), dFree(), MSG, OpSend, and OpStart.

Referenced by a_Capi_dpi_send_cmd(), and Capi_dpi_send_source().

◆ a_Capi_dpi_verify_request()

int a_Capi_dpi_verify_request ( BrowserWindow bw,
DilloUrl url 
)

Safety test: only allow GET|POST dpi-urls from dpi-generated pages.

Definition at line 232 of file capi.c.

References a_History_get_url(), a_Nav_stack_size(), dStr_printable(), dStrAsciiCasecmp(), FALSE, MSG, NAV_TOP_UIDX, TRUE, URL_DATA, URL_FLAGS, URL_Get, URL_PATH, URL_Post, URL_SCHEME, and URL_STR.

Referenced by a_Capi_open_url(), and Html_tag_open_meta().

◆ a_Capi_get_buf()

int a_Capi_get_buf ( const DilloUrl Url,
char **  PBuf,
int *  BufSize 
)

Get the cache's buffer for the URL, and its size.

Return: 1 cached, 0 not cached.

Definition at line 541 of file capi.c.

References a_Cache_get_buf().

Referenced by a_Html_load_stylesheet(), a_Nav_get_buf(), and Capi_dpi_send_source().

◆ a_Capi_get_content_type()

const char * a_Capi_get_content_type ( const DilloUrl url)

Get the Content-Type associated with the URL.

Definition at line 557 of file capi.c.

References a_Cache_get_content_type().

Referenced by a_Nav_get_content_type().

◆ a_Capi_get_flags()

int a_Capi_get_flags ( const DilloUrl Url)

Return status information of an URL's content-transfer process.

Definition at line 520 of file capi.c.

References a_Cache_get_flags(), and Capi_map_cache_flags().

Referenced by a_Capi_open_url(), and Capi_request_permitted().

◆ a_Capi_get_flags_with_redirection()

◆ a_Capi_init()

void a_Capi_init ( void  )

Initialize capi&cache data.

Definition at line 80 of file capi.c.

References a_Cache_init(), CapiConns, and dList_new().

Referenced by main().

◆ a_Capi_open_url()

◆ a_Capi_set_content_type()

const char * a_Capi_set_content_type ( const DilloUrl url,
const char *  ctype,
const char *  from 
)

Set the Content-Type for the URL.

Definition at line 565 of file capi.c.

References a_Cache_set_content_type().

Referenced by a_Html_load_stylesheet(), and Html_update_content_type().

◆ a_Capi_set_vsource_url()

void a_Capi_set_vsource_url ( const DilloUrl url)

Store the last URL requested by "view source".

Definition at line 223 of file capi.c.

References a_Url_dup(), a_Url_free(), and CapiVsUrl.

Referenced by a_Nav_set_vsource_url().

◆ a_Capi_stop_client()

void a_Capi_stop_client ( int  Key,
int  force 
)

Remove a client from the cache client queue.

force = also abort the CCC if this is the last client.

Definition at line 621 of file capi.c.

References _MSG, a_Cache_client_get_if_unique(), a_Cache_stop_client(), a_Capi_conn_abort_by_url(), CacheClient::BufSize, and CacheClient::Url.

Referenced by a_Bw_stop_clients().

◆ a_Capi_unref_buf()

void a_Capi_unref_buf ( const DilloUrl Url)

Unref the cache's buffer when no longer using it.

Definition at line 549 of file capi.c.

References a_Cache_unref_buf().

Referenced by a_Html_load_stylesheet(), and a_Nav_unref_buf().

◆ Capi_conn_by_server_cmp()

static int Capi_conn_by_server_cmp ( const void *  v1,
const void *  v2 
)
static

Compare function for searching a conn by server string.

Definition at line 155 of file capi.c.

References dReturn_val_if_fail.

Referenced by Capi_conn_find().

◆ Capi_conn_find()

static capi_conn_t * Capi_conn_find ( char *  server)
static

Find connection data by server.

Definition at line 166 of file capi.c.

References Capi_conn_by_server_cmp(), CapiConns, and dList_find_custom().

Referenced by a_Capi_dpi_send_data().

◆ Capi_conn_new()

static capi_conn_t * Capi_conn_new ( const DilloUrl url,
void *  bw,
char *  server,
char *  datastr 
)
static

Create a new connection data structure.

Definition at line 94 of file capi.c.

References a_Url_dup(), dNew, dStrdup(), and PENDING.

Referenced by a_Capi_dpi_send_data(), and a_Capi_open_url().

◆ Capi_conn_ref()

static void Capi_conn_ref ( capi_conn_t *  conn)
static

Increment the reference count and add to the list if not present.

Definition at line 123 of file capi.c.

References _MSG, CapiConns, and dList_append().

Referenced by a_Capi_ccc().

◆ Capi_conn_resume()

static void Capi_conn_resume ( void  )
static

Resume connections that were waiting for dpid to start.

Definition at line 174 of file capi.c.

References a_Capi_ccc(), a_Chain_dbuf_new(), BCK, CapiConns, dFree(), dList_length(), dList_nth_data(), OpSend, and PENDING.

Referenced by a_Capi_ccc().

◆ Capi_conn_unref()

static void Capi_conn_unref ( capi_conn_t *  conn)
static

Decrement the reference count (and remove from list when zero)

Definition at line 135 of file capi.c.

References _MSG, a_Url_free(), CapiConns, dFree(), dList_length(), and dList_remove().

Referenced by a_Capi_ccc().

◆ Capi_conn_valid()

static capi_conn_t * Capi_conn_valid ( capi_conn_t *  conn)
static

Validate a capi_conn_t pointer.

Returns
NULL if not valid, conn otherwise.

Definition at line 115 of file capi.c.

References CapiConns, and dList_find().

Referenced by a_Capi_ccc(), and a_Capi_open_url().

◆ Capi_dpi_build_cmd()

static char * Capi_dpi_build_cmd ( DilloWeb web,
char *  server 
)
static

Build the dpip command tag, according to URL and server.

Definition at line 302 of file capi.c.

References a_Dpip_build_cmd(), _DilloWeb::filename, _DilloWeb::url, and URL_STR.

Referenced by a_Capi_open_url().

◆ Capi_dpi_send_source()

static void Capi_dpi_send_source ( BrowserWindow bw,
DilloUrl url 
)
static

Send the requested URL's source to the "view source" dpi.

Definition at line 321 of file capi.c.

References a_Capi_dpi_send_cmd(), a_Capi_dpi_send_data(), a_Capi_get_buf(), a_Dpip_build_cmd(), CapiVsUrl, dFree(), and URL_STR.

Referenced by a_Capi_open_url().

◆ Capi_map_cache_flags()

static int Capi_map_cache_flags ( uint_t  flags)
static

Convert cache-defined flags to Capi ones.

Definition at line 499 of file capi.c.

References CA_InProgress, CA_IsEmpty, CAPI_Completed, CAPI_InProgress, CAPI_IsCached, and CAPI_IsEmpty.

Referenced by a_Capi_get_flags(), and a_Capi_get_flags_with_redirection().

◆ Capi_request_permitted()

static bool_t Capi_request_permitted ( DilloWeb web)
static

Shall we permit this request to open a URL?

Definition at line 347 of file capi.c.

References a_Capi_get_flags(), a_Domain_permit(), CAPI_IsCached, dStrAsciiCasecmp(), FALSE, _DilloWeb::flags, MSG, _DilloWeb::requester, TRUE, _DilloWeb::url, URL_SCHEME, URL_STR, and WEB_RootUrl.

Referenced by a_Capi_open_url().

◆ Capi_url_uses_dpi()

static int Capi_url_uses_dpi ( DilloUrl url,
char **  server_ptr 
)
static

If the url belongs to a dpi server, return its name.

Definition at line 269 of file capi.c.

References dFree(), dStr_append_l(), dStr_free(), dStr_new(), dStrdup(), dStrnAsciiCasecmp(), dStrndup(), Dstr::str, and URL_STR.

Referenced by a_Capi_open_url().

Variable Documentation

◆ CapiConns

Dlist* CapiConns
static

Data list for active dpi connections.

Definition at line 63 of file capi.c.

Referenced by a_Capi_conn_abort_by_url(), a_Capi_init(), Capi_conn_find(), Capi_conn_ref(), Capi_conn_resume(), Capi_conn_unref(), and Capi_conn_valid().

◆ CapiVsUrl

DilloUrl* CapiVsUrl = NULL
static

Last URL asked for view source.

Definition at line 66 of file capi.c.

Referenced by a_Capi_set_vsource_url(), and Capi_dpi_send_source().