34#include "../dpip/dpip.h"
72 void *Data1,
void *Data2);
98 conn =
dNew(capi_conn_t, 1);
101 conn->server =
dStrdup(server);
102 conn->datastr =
dStrdup(datastr);
104 conn->Flags = (strcmp(server,
"http") != 0) ?
PENDING : 0;
105 conn->InfoSend = NULL;
106 conn->InfoRecv = NULL;
125 if (++conn->Ref == 1) {
129 _MSG(
" Capi_conn_ref #%d %p\n", conn->Ref, conn);
137 _MSG(
" Capi_conn_unref #%d %p\n", conn->Ref - 1, conn);
140 if (--conn->Ref == 0) {
146 dFree(conn->datastr);
157 const capi_conn_t *node = v1;
158 const char *server = v2;
160 return strcmp(node->server, server);
184 if (conn->InfoSend) {
188 conn->Flags &= ~PENDING;
207 if (conn->InfoSend) {
210 if (conn->InfoRecv) {
241 strncmp(
URL_PATH(url),
"/vsource/", 9) == 0) {
257 MSG(
"a_Capi_dpi_verify_request: Permission Denied!\n");
271 char *p, *server = NULL, *url_str =
URL_STR(url);
280 if ((p = strchr(url_str + 5,
'/')) != NULL) {
285 if (strcmp(server,
"bm") == 0) {
289 }
else if ((p = strchr(url_str,
':')) != NULL) {
296 return ((*server_ptr = server) ? 1 : 0);
306 if (strcmp(server,
"downloads") == 0) {
323 char *p, *buf, *cmd, size_str[32], *server=
"vsource";
326 if (!(p = strchr(
URL_STR(url),
':')) || !(p = strchr(p + 1,
':')))
331 snprintf(size_str, 32,
"%d", buf_size);
333 "start_send_page",
URL_STR(url), size_str);
338 "DpiError",
"Page is NOT cached");
371 MSG(
"capi: Blocked mixed content: %s -> %s\n",
396 capi_conn_t *conn = NULL;
398 int safe = 0, ret = 0, use_cache = 0;
413 MSG_WARN(
"Cannot open \"%s\" for writing: %s.\n",
418 server =
"downloads";
423 MSG_WARN(
"Ignoring download request for '%s': "
424 "not in cache and not downloadable.\n",
432 if (strcmp(server,
"vsource") == 0) {
447 if (strcmp(server,
"vsource") == 0) {
463 "HTTPS was disabled at compilation time.");
577 char *data,
int data_sz,
char *server,
int flags)
594 if (conn && conn->InfoSend) {
600 MSG(
" ERROR: [a_Capi_dpi_send_data] No open connection found\n");
625 _MSG(
"a_Capi_stop_client: force=%d\n", force);
628 if (Client && (force || Client->
BufSize == 0)) {
639 void *Data1,
void *Data2)
654 conn->InfoSend = Info;
655 if (strcmp(conn->server,
"http") == 0 ||
656 strcmp(conn->server,
"https") == 0) {
670 conn->InfoSend = NULL;
677 conn->InfoSend = NULL;
691 MSG_WARN(
"Capi.c: Opsend [1F] Data2 = NULL\n");
692 }
else if (strcmp(Data2,
"FD") == 0) {
694 conn->SockFD = *(
int*)Data1;
697 }
else if (strcmp(Data2,
"DpidOK") == 0) {
704 conn->InfoSend = NULL;
707 if (!strcmp(Data2,
"DpidERROR")) {
709 "ERROR: can't start dpid daemon "
710 "(URL scheme = '%s')!",
712 }
else if (!strcmp(Data2,
"Both") && conn->InfoRecv) {
729 }
else if (Branch == 2) {
738 conn->InfoRecv = Info;
739 if (strcmp(conn->server,
"http") == 0)
747 if (Data2 && strcmp(Data2,
"FD") == 0) {
753 conn->InfoRecv = NULL;
769 if (strcmp(Data2,
"send_page_2eof") == 0) {
773 dbuf->
Size, conn->url);
781 }
else if (strcmp(Data2,
"send_status_message") == 0) {
783 }
else if (strcmp(Data2,
"chat") == 0) {
786 }
else if (strcmp(Data2,
"dialog") == 0) {
788 }
else if (strcmp(Data2,
"reload_request") == 0) {
790 }
else if (strcmp(Data2,
"start_send_page") == 0) {
800 conn->InfoRecv = NULL;
804 if (conn->InfoSend) {
813 conn->InfoRecv = NULL;
816 if (!strcmp(Data2,
"Both") && conn->InfoSend) {
void a_Bookmarks_chat_add(BrowserWindow *Bw, char *Cmd, char *answer)
Have a short chat with the bookmarks server, and finally ask it to add a new bookmark.
int a_Cache_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize)
Get the pointer to the URL document, and its size, from the cache entry.
CacheClient_t * a_Cache_client_get_if_unique(int Key)
Last Client for this entry?
uint_t a_Cache_get_flags_with_redirection(const DilloUrl *url)
Get cache entry status (following redirections).
const char * a_Cache_set_content_type(const DilloUrl *url, const char *ctype, const char *from)
Change Content-Type for cache entry found by url.
void a_Cache_unref_buf(const DilloUrl *Url)
Unreference the data buffer when no longer using it.
const char * a_Cache_get_content_type(const DilloUrl *url)
Get current Content-Type for cache entry found by URL.
void a_Cache_entry_remove_by_url(DilloUrl *url)
Wrapper for capi.
bool_t a_Cache_process_dbuf(int Op, const char *buf, size_t buf_size, const DilloUrl *Url)
Receive new data, update the reception buffer (for next read), update the cache, and service the clie...
int a_Cache_download_enabled(const DilloUrl *url)
Check whether a URL scheme is downloadable.
void a_Cache_init(void)
Initialize cache data.
int a_Cache_open_url(void *web, CA_Callback_t Call, void *CbData)
Try finding the url in the cache.
uint_t a_Cache_get_flags(const DilloUrl *url)
Get cache entry status.
void a_Cache_stop_client(int Key)
Remove a client from the client queue TODO: notify the dicache and upper layers.
void(* CA_Callback_t)(int Op, CacheClient_t *Client)
Callback type for cache clients.
static void Capi_conn_resume(void)
Resume connections that were waiting for dpid to start.
int a_Capi_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize)
Get the cache's buffer for the URL, and its size.
static bool_t Capi_request_permitted(DilloWeb *web)
Shall we permit this request to open a URL?
static void Capi_conn_unref(capi_conn_t *conn)
Decrement the reference count (and remove from list when zero)
static Dlist * CapiConns
Data list for active dpi connections.
int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server, int flags)
Send a dpi cmd.
const char * a_Capi_set_content_type(const DilloUrl *url, const char *ctype, const char *from)
Set the Content-Type for the URL.
static char * Capi_dpi_build_cmd(DilloWeb *web, char *server)
Build the dpip command tag, according to URL and server.
static capi_conn_t * Capi_conn_valid(capi_conn_t *conn)
Validate a capi_conn_t pointer.
void a_Capi_set_vsource_url(const DilloUrl *url)
Store the last URL requested by "view source".
static int Capi_conn_by_server_cmp(const void *v1, const void *v2)
Compare function for searching a conn by server string.
int a_Capi_dpi_verify_request(BrowserWindow *bw, DilloUrl *url)
Safety test: only allow GET|POST dpi-urls from dpi-generated pages.
static capi_conn_t * Capi_conn_new(const DilloUrl *url, void *bw, char *server, char *datastr)
Create a new connection data structure.
static DilloUrl * CapiVsUrl
Last URL asked for view source.
static capi_conn_t * Capi_conn_find(char *server)
Find connection data by server.
void a_Capi_unref_buf(const DilloUrl *Url)
Unref the cache's buffer when no longer using it.
static int Capi_url_uses_dpi(DilloUrl *url, char **server_ptr)
If the url belongs to a dpi server, return its name.
void a_Capi_ccc(int Op, int Branch, int Dir, ChainLink *Info, void *Data1, void *Data2)
CCC function for the CAPI module.
int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData)
Most used function for requesting a URL.
int a_Capi_get_flags_with_redirection(const DilloUrl *Url)
Same as a_Capi_get_flags() but following redirections.
void a_Capi_stop_client(int Key, int force)
Remove a client from the cache client queue.
static void Capi_conn_ref(capi_conn_t *conn)
Increment the reference count and add to the list if not present.
static int Capi_map_cache_flags(uint_t flags)
Convert cache-defined flags to Capi ones.
static void Capi_dpi_send_source(BrowserWindow *bw, DilloUrl *url)
Send the requested URL's source to the "view source" dpi.
void a_Capi_init(void)
Initialize capi&cache data.
const char * a_Capi_get_content_type(const DilloUrl *url)
Get the Content-Type associated with 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.
void a_Capi_conn_abort_by_url(const DilloUrl *url)
Abort the connection for a given url, using its CCC.
int a_Capi_get_flags(const DilloUrl *Url)
Return status information of an URL's content-transfer process.
int a_Chain_bcb(int Op, ChainLink *Info, void *Data1, void *Data2)
Issue the backward callback of the 'Info' link.
DataBuf * a_Chain_dbuf_new(void *buf, int size, int code)
Allocate and initialize a new DataBuf structure.
ChainLink * a_Chain_link_new(ChainLink *AInfo, ChainFunction_t AFunc, int Direction, ChainFunction_t BFunc, int AtoB_branch, int BtoA_branch)
Create a new link from module A to module B.
int a_Chain_check(char *FuncStr, int Op, int Branch, int Dir, ChainLink *Info)
Check whether the CCC is operative.
ChainLink * a_Chain_new(void)
Create and initialize a new chain-link.
int dStrAsciiCasecmp(const char *s1, const char *s2)
char * dStrdup(const char *s)
Dlist * dList_new(int size)
Create a new empty list.
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)
int dList_length(Dlist *lp)
For completing the ADT.
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
void dStr_free(Dstr *ds, int all)
Free a dillo string.
void dStr_append_l(Dstr *ds, const char *s, int l)
Append a C string to a Dstr (providing length).
char * dStrndup(const char *s, size_t sz)
Dstr * dStr_new(const char *s)
Create a new string.
void dList_append(Dlist *lp, void *data)
Append a data item to the list.
void * dList_find_custom(Dlist *lp, const void *data, dCompareFunc func)
Search a data item using a custom function.
const char * dStr_printable(Dstr *in, int maxlen)
Return a printable representation of the provided Dstr, limited to a length of roughly maxlen.
void dList_remove(Dlist *lp, const void *data)
void * dList_find(Dlist *lp, const void *data)
Return the found data item, or NULL if not present.
#define dReturn_if_fail(expr)
#define dReturn_val_if_fail(expr, val)
#define dNew(type, count)
bool_t a_Domain_permit(const DilloUrl *source, const DilloUrl *dest)
Is the resource at 'source' permitted to request the resource at 'dest'?
void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag)
Process a dpip "dialog" command from any dpi.
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
const DilloUrl * a_History_get_url(int idx)
Return the DilloUrl field (by index)
void a_Http_ccc(int Op, int Branch, int Dir, ChainLink *Info, void *Data1, void *Data2)
CCC function for the HTTP module.
void a_Nav_cancel_expect_if_eq(BrowserWindow *bw, const DilloUrl *url)
void a_Nav_reload(BrowserWindow *bw)
int a_Nav_stack_size(BrowserWindow *bw)
void a_Dpi_ccc(int Op, int Branch, int Dir, ChainLink *Info, void *Data1, void *Data2)
CCC function for the Dpi module.
Contains the specific data for a single window.
Data structure for cache clients.
const DilloUrl * Url
Pointer to a cache entry Url.
uint_t BufSize
Valid size of cache-data.
Main data structure for CCC nodes.
A convenience data structure for passing data chunks between nodes.
char * filename
Variables for Local saving.
int flags
Additional info.
DilloUrl * url
Requested URL.
DilloUrl * requester
URL that caused this request, or < NULL if user-initiated.
BrowserWindow * bw
The requesting browser window [reference].
void a_UIcmd_set_msg(BrowserWindow *bw, const char *format,...)
void a_Url_set_flags(DilloUrl *u, int flags)
Set DilloUrl flags.
int a_Url_cmp(const DilloUrl *A, const DilloUrl *B)
Compare two Url's to check if they're the same, or which one is bigger.
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
DilloUrl * a_Url_dup(const DilloUrl *ori)
Duplicate a Url structure.
void a_Web_free(DilloWeb *web)
Deallocate a DilloWeb structure.