Dillo v3.1.1-99-gf3103cc4
|
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"
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 Dlist * | CapiConns |
Data list for active dpi connections. | |
static DilloUrl * | CapiVsUrl = NULL |
Last URL asked for view source. | |
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.
anonymous enum |
void a_Capi_ccc | ( | int | Op, |
int | Branch, | ||
int | Dir, | ||
ChainLink * | Info, | ||
void * | Data1, | ||
void * | Data2 | ||
) |
CCC function for the CAPI module.
Definition at line 638 of file capi.c.
References a_Bookmarks_chat_add(), a_Cache_entry_remove_by_url(), a_Cache_process_dbuf(), a_Capi_ccc(), a_Chain_bcb(), a_Chain_check(), a_Chain_link_new(), a_Dpi_ccc(), a_Dpiapi_dialog(), a_Http_ccc(), a_Nav_cancel_expect_if_eq(), a_Nav_reload(), a_UIcmd_set_msg(), BCK, DataBuf::Buf, Capi_conn_ref(), Capi_conn_resume(), Capi_conn_unref(), Capi_conn_valid(), dFree(), dReturn_if_fail, IOAbort, IOClose, IORead, ChainLink::LocalKey, MSG_WARN, OpAbort, OpEnd, OpSend, OpStart, DataBuf::Size, and URL_SCHEME.
Referenced by a_Capi_ccc(), a_Capi_conn_abort_by_url(), a_Capi_dpi_send_data(), a_Capi_open_url(), and Capi_conn_resume().
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().
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().
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().
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().
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().
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().
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().
int a_Capi_get_flags_with_redirection | ( | const DilloUrl * | Url | ) |
Same as a_Capi_get_flags() but following redirections.
Definition at line 530 of file capi.c.
References a_Cache_get_flags_with_redirection(), and Capi_map_cache_flags().
Referenced by a_Capi_open_url(), a_Html_image_new(), a_Html_load_stylesheet(), Html_tag_open_a(), Html_tag_open_audio(), Html_tag_open_embed(), Html_tag_open_frame(), Html_tag_open_object(), Html_tag_open_source(), and Html_tag_open_video().
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().
int a_Capi_open_url | ( | DilloWeb * | web, |
CA_Callback_t | Call, | ||
void * | CbData | ||
) |
Most used function for requesting a URL.
TODO: clean up the ad-hoc bindings with an API that allows dynamic addition of new plugins.
Definition at line 392 of file capi.c.
References _MSG, a_Cache_download_enabled(), a_Cache_open_url(), a_Capi_ccc(), a_Capi_conn_abort_by_url(), a_Capi_dpi_send_cmd(), a_Capi_dpi_verify_request(), a_Capi_get_flags(), a_Capi_get_flags_with_redirection(), a_Chain_new(), a_UIcmd_set_msg(), a_Url_set_flags(), a_Web_free(), BCK, _DilloWeb::bw, Capi_conn_new(), Capi_conn_valid(), Capi_dpi_build_cmd(), Capi_dpi_send_source(), CAPI_IsCached, Capi_request_permitted(), Capi_url_uses_dpi(), dFree(), dStrAsciiCasecmp(), dStrerror, _DilloWeb::filename, _DilloWeb::flags, MSG_WARN, OpStart, _DilloWeb::stream, _DilloWeb::url, URL_E2EQuery, URL_FLAGS, URL_SCHEME, URL_STR, WEB_Download, and WEB_RootUrl.
Referenced by a_Html_load_stylesheet(), a_Nav_save_url(), StyleEngine::apply(), Html_load_image(), and Nav_open_url().
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().
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().
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().
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
static |
Validate a capi_conn_t pointer.
Definition at line 115 of file capi.c.
References CapiConns, and dList_find().
Referenced by a_Capi_ccc(), and a_Capi_open_url().
|
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().
|
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().
|
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().
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().
|
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().
|
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().
|
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().