Dillo v3.2.0-38-gb47de46f
Loading...
Searching...
No Matches
cache.c
Go to the documentation of this file.
1/*
2 * File: cache.c
3 *
4 * Copyright 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
5 * Copyright 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13/*
14 * @file
15 * Dillo's cache module
16 */
17
18#include <sys/types.h>
19
20#include <limits.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include "msg.h"
25#include "IO/Url.h"
26#include "IO/IO.h"
27#include "web.hh"
28#include "dicache.h"
29#include "nav.h"
30#include "cookies.h"
31#include "hsts.h"
32#include "misc.h"
33#include "capi.h"
34#include "decode.h"
35#include "auth.h"
36#include "domain.h"
37#include "timeout.hh"
38#include "uicmd.hh"
39
41#define MAX_INIT_BUF 1024*1024
43#define HUGE_FILESIZE 15*1024*1024
44
45/*
46 * Local data types
47 */
48
49typedef struct {
50 const DilloUrl *Url;
51 char *TypeDet;
52 char *TypeHdr;
53 char *TypeMeta;
54 char *TypeNorm;
55 char *ContentDisposition;
56 Dstr *Header;
57 const DilloUrl *Location;
58 Dlist *Auth;
59 Dstr *Data;
60 Dstr *UTF8Data;
61 int DataRefcount;
62 DecodeTransfer *TransferDecoder;
63 Decode *ContentDecoder;
64 Decode *CharsetDecoder;
65 int ExpectedSize;
66 int TransferSize;
67 uint_t Flags;
68} CacheEntry_t;
69
70
71/*
72 * Local data
73 */
76
80
85
86
87/*
88 * Forward declarations
89 */
90static CacheEntry_t *Cache_process_queue(CacheEntry_t *entry);
91static void Cache_delayed_process_queue(CacheEntry_t *entry);
92static void Cache_auth_entry(CacheEntry_t *entry, BrowserWindow *bw);
93
97static int Cache_entry_cmp(const void *v1, const void *v2)
98{
99 const CacheEntry_t *d1 = v1, *d2 = v2;
100
101 return a_Url_cmp(d1->Url, d2->Url);
102}
103
107static int Cache_entry_by_url_cmp(const void *v1, const void *v2)
108{
109 const DilloUrl *u1 = ((CacheEntry_t*)v1)->Url;
110 const DilloUrl *u2 = v2;
111
112 return a_Url_cmp(u1, u2);
113}
114
118void a_Cache_init(void)
119{
122 CachedURLs = dList_new(256);
123
124 /* inject the splash screen in the cache */
125 {
126 DilloUrl *url = a_Url_new("about:splash", NULL);
128 a_Cache_entry_inject(url, ds);
129 dStr_free(ds, 1);
130 a_Url_free(url);
131 }
132}
133
134/* Client operations ------------------------------------------------------ */
135
141static int Cache_client_enqueue(const DilloUrl *Url, DilloWeb *Web,
142 CA_Callback_t Callback, void *CbData)
143{
144 static int ClientKey = 0; /* Provide a primary key for each client */
145 CacheClient_t *NewClient;
146
147 if (ClientKey < INT_MAX) /* check for integer overflow */
148 ClientKey++;
149 else
150 ClientKey = 1;
151
152 NewClient = dNew(CacheClient_t, 1);
153 NewClient->Key = ClientKey;
154 NewClient->Url = Url;
155 NewClient->Version = 0;
156 NewClient->Buf = NULL;
157 NewClient->BufSize = 0;
158 NewClient->Callback = Callback;
159 NewClient->CbData = CbData;
160 NewClient->Web = Web;
161
162 dList_append(ClientQueue, NewClient);
163
164 return ClientKey;
165}
166
170static int Cache_client_by_key_cmp(const void *client, const void *key)
171{
172 return ((CacheClient_t *)client)->Key - VOIDP2INT(key);
173}
174
179{
180 if (Client) {
181 dList_remove(ClientQueue, Client);
182 a_Web_free(Client->Web);
183 dFree(Client);
184 }
185}
186
187
188/* Entry operations ------------------------------------------------------- */
189
193static void Cache_entry_init(CacheEntry_t *NewEntry, const DilloUrl *Url)
194{
195 NewEntry->Url = a_Url_dup(Url);
196 NewEntry->TypeDet = NULL;
197 NewEntry->TypeHdr = NULL;
198 NewEntry->TypeMeta = NULL;
199 NewEntry->TypeNorm = NULL;
200 NewEntry->ContentDisposition = NULL;
201 NewEntry->Header = dStr_new("");
202 NewEntry->Location = NULL;
203 NewEntry->Auth = NULL;
204 NewEntry->Data = dStr_sized_new(8*1024);
205 NewEntry->UTF8Data = NULL;
206 NewEntry->DataRefcount = 0;
207 NewEntry->TransferDecoder = NULL;
208 NewEntry->ContentDecoder = NULL;
209 NewEntry->CharsetDecoder = NULL;
210 NewEntry->ExpectedSize = 0;
211 NewEntry->TransferSize = 0;
212 NewEntry->Flags = CA_IsEmpty | CA_InProgress | CA_KeepAlive;
213}
214
219static CacheEntry_t *Cache_entry_search(const DilloUrl *Url)
220{
222}
223
227static CacheEntry_t *Cache_entry_search_with_redirect(const DilloUrl *Url)
228{
229 int i;
230 CacheEntry_t *entry;
231
232 for (i = 0; (entry = Cache_entry_search(Url)); ++i) {
233
234 /* Test for a redirection loop */
235 if (entry->Flags & CA_RedirectLoop || i == 3) {
236 _MSG_WARN("Redirect loop for URL: >%s<\n", URL_STR_(Url));
237 break;
238 }
239 /* Test for a working redirection */
240 if (entry->Flags & CA_Redirect && entry->Location) {
241 Url = entry->Location;
242 } else
243 break;
244 }
245 return entry;
246}
247
251static CacheEntry_t *Cache_entry_add(const DilloUrl *Url)
252{
253 CacheEntry_t *old_entry, *new_entry;
254
255 if ((old_entry = Cache_entry_search(Url))) {
256 MSG_WARN("Cache_entry_add, leaking an entry.\n");
257 dList_remove(CachedURLs, old_entry);
258 }
259
260 new_entry = dNew(CacheEntry_t, 1);
261 Cache_entry_init(new_entry, Url); /* Set safe values */
263 return new_entry;
264}
265
270void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds)
271{
272 CacheEntry_t *entry;
273
274 if (!(entry = Cache_entry_search(Url)))
275 entry = Cache_entry_add(Url);
276 entry->Flags = CA_GotHeader + CA_GotLength + CA_InternalUrl;
277 if (data_ds->len)
278 entry->Flags &= ~CA_IsEmpty;
279 dStr_truncate(entry->Data, 0);
280 dStr_append_l(entry->Data, data_ds->str, data_ds->len);
281 dStr_fit(entry->Data);
282 entry->ExpectedSize = entry->TransferSize = entry->Data->len;
283}
284
288static void Cache_auth_free(Dlist *auth)
289{
290 int i;
291 void *auth_field;
292 for (i = 0; (auth_field = dList_nth_data(auth, i)); ++i)
293 dFree(auth_field);
294 dList_free(auth);
295}
296
300static void Cache_entry_free(CacheEntry_t *entry)
301{
302 a_Url_free((DilloUrl *)entry->Url);
303 dFree(entry->TypeDet);
304 dFree(entry->TypeHdr);
305 dFree(entry->TypeMeta);
306 dFree(entry->TypeNorm);
307 dFree(entry->ContentDisposition);
308 dStr_free(entry->Header, TRUE);
309 a_Url_free((DilloUrl *)entry->Location);
310 Cache_auth_free(entry->Auth);
311 dStr_free(entry->Data, 1);
312 dStr_free(entry->UTF8Data, 1);
313 if (entry->CharsetDecoder)
314 a_Decode_free(entry->CharsetDecoder);
315 if (entry->TransferDecoder)
316 a_Decode_transfer_free(entry->TransferDecoder);
317 if (entry->ContentDecoder)
318 a_Decode_free(entry->ContentDecoder);
319 dFree(entry);
320}
321
327static void Cache_entry_remove(CacheEntry_t *entry, DilloUrl *url)
328{
329 int i;
330 CacheClient_t *Client;
331
332 if (!entry && !(entry = Cache_entry_search(url)))
333 return;
334 if (entry->Flags & CA_InternalUrl)
335 return;
336
337 /* remove all clients for this entry */
338 for (i = 0; (Client = dList_nth_data(ClientQueue, i)); ++i) {
339 if (Client->Url == entry->Url) {
340 a_Cache_stop_client(Client->Key);
341 --i;
342 }
343 }
344
345 /* remove from DelayedQueue */
347
348 /* remove from dicache */
349 a_Dicache_invalidate_entry(entry->Url);
350
351 /* remove from cache */
352 dList_remove(CachedURLs, entry);
353 Cache_entry_free(entry);
354}
355
360{
361 Cache_entry_remove(NULL, url);
362}
363
364/* Misc. operations ------------------------------------------------------- */
365
378int a_Cache_open_url(void *web, CA_Callback_t Call, void *CbData)
379{
380 int ClientKey;
381 CacheEntry_t *entry;
382 DilloWeb *Web = web;
383 DilloUrl *Url = Web->url;
384
385 if (URL_FLAGS(Url) & URL_E2EQuery) {
386 /* remove current entry */
387 Cache_entry_remove(NULL, Url);
388 }
389
390 if ((entry = Cache_entry_search(Url))) {
391 /* URL is cached: feed our client with cached data */
392 ClientKey = Cache_client_enqueue(entry->Url, Web, Call, CbData);
394
395 } else {
396 /* URL not cached: create an entry, send our client to the queue,
397 * and open a new connection */
398 entry = Cache_entry_add(Url);
399 ClientKey = Cache_client_enqueue(entry->Url, Web, Call, CbData);
400 }
401
402 return ClientKey;
403}
404
409{
410 CacheEntry_t *entry = Cache_entry_search(url);
411 return (entry ? entry->Flags : 0);
412}
413
418{
419 CacheEntry_t *entry = Cache_entry_search_with_redirect(url);
420 return (entry ? entry->Flags : 0);
421}
422
426static void Cache_ref_data(CacheEntry_t *entry)
427{
428 if (entry) {
429 entry->DataRefcount++;
430 _MSG("DataRefcount++: %d\n", entry->DataRefcount);
431 if (entry->CharsetDecoder &&
432 (!entry->UTF8Data || entry->DataRefcount == 1)) {
433 dStr_free(entry->UTF8Data, 1);
434 entry->UTF8Data = a_Decode_process(entry->CharsetDecoder,
435 entry->Data->str,
436 entry->Data->len);
437 }
438 }
439}
440
444static void Cache_unref_data(CacheEntry_t *entry)
445{
446 if (entry) {
447 entry->DataRefcount--;
448 _MSG("DataRefcount--: %d\n", entry->DataRefcount);
449
450 if (entry->CharsetDecoder) {
451 if (entry->DataRefcount == 0) {
452 dStr_free(entry->UTF8Data, 1);
453 entry->UTF8Data = NULL;
454 } else if (entry->DataRefcount < 0) {
455 MSG_ERR("Cache_unref_data: negative refcount\n");
456 entry->DataRefcount = 0;
457 }
458 }
459 }
460}
461
465static const char *Cache_current_content_type(CacheEntry_t *entry)
466{
467 return entry->TypeNorm ? entry->TypeNorm : entry->TypeMeta ? entry->TypeMeta
468 : entry->TypeHdr ? entry->TypeHdr : entry->TypeDet;
469}
470
474const char *a_Cache_get_content_type(const DilloUrl *url)
475{
476 CacheEntry_t *entry = Cache_entry_search_with_redirect(url);
477
478 return (entry) ? Cache_current_content_type(entry) : NULL;
479}
480
484static Dstr *Cache_data(CacheEntry_t *entry)
485{
486 return entry->UTF8Data ? entry->UTF8Data : entry->Data;
487}
488
494const char *a_Cache_set_content_type(const DilloUrl *url, const char *ctype,
495 const char *from)
496{
497 const char *curr;
498 char *major, *minor, *charset;
499 CacheEntry_t *entry = Cache_entry_search(url);
500
501 dReturn_val_if_fail (entry != NULL, NULL);
502
503 _MSG("a_Cache_set_content_type {%s} {%s}\n", ctype, URL_STR(url));
504
505 curr = Cache_current_content_type(entry);
506 if (entry->TypeMeta || (*from == 'h' && entry->TypeHdr) ) {
507 /* Type is already been set. Do nothing.
508 * BTW, META overrides TypeHdr */
509 } else {
510 if (*from == 'h') {
511 /* Content-Type from HTTP header */
512 entry->TypeHdr = dStrdup(ctype);
513 } else {
514 /* Content-Type from META */
515 entry->TypeMeta = dStrdup(ctype);
516 }
517 if (a_Misc_content_type_cmp(curr, ctype)) {
518 /* ctype gives one different from current */
519 a_Misc_parse_content_type(ctype, &major, &minor, &charset);
520 if (*from == 'm' && charset &&
521 ((!major || !*major) && (!minor || !*minor))) {
522 /* META only gives charset; use detected MIME type too */
523 entry->TypeNorm = dStrconcat(entry->TypeDet, ctype, NULL);
524 } else if (*from == 'm' &&
525 !dStrnAsciiCasecmp(ctype, "text/xhtml", 10)) {
526 /* WORKAROUND: doxygen uses "text/xhtml" in META */
527 if (charset) {
528 entry->TypeNorm = dStrconcat("application/xhtml+xml",
529 "; charset=", charset, NULL);
530 } else {
531 entry->TypeNorm = dStrdup("application/xhtml+xml");
532 }
533 }
534 if (charset) {
535 if (entry->CharsetDecoder)
536 a_Decode_free(entry->CharsetDecoder);
537 entry->CharsetDecoder = a_Decode_charset_init(charset);
538 curr = Cache_current_content_type(entry);
539
540 /* Invalidate UTF8Data */
541 dStr_free(entry->UTF8Data, 1);
542 entry->UTF8Data = NULL;
543 }
544 dFree(major); dFree(minor); dFree(charset);
545 }
546 }
547 return curr;
548}
549
554int a_Cache_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize)
555{
556 CacheEntry_t *entry = Cache_entry_search_with_redirect(Url);
557 if (entry) {
558 Dstr *data;
559 Cache_ref_data(entry);
560 data = Cache_data(entry);
561 *PBuf = data->str;
562 *BufSize = data->len;
563 } else {
564 *PBuf = NULL;
565 *BufSize = 0;
566 }
567 return (entry ? 1 : 0);
568}
569
577
578
585static char *Cache_parse_field(const char *header, const char *fieldname)
586{
587 char *field;
588 uint_t i, j;
589
590 for (i = 0; header[i]; i++) {
591 /* Search fieldname */
592 for (j = 0; fieldname[j]; j++)
593 if (D_ASCII_TOLOWER(fieldname[j]) != D_ASCII_TOLOWER(header[i + j]))
594 break;
595 if (fieldname[j]) {
596 /* skip to next line */
597 for ( i += j; header[i] != '\n'; i++);
598 continue;
599 }
600
601 i += j;
602 if (header[i] == ':') {
603 /* Field found! */
604 while (header[++i] == ' ' || header[i] == '\t');
605 for (j = 0; header[i + j] != '\n'; j++);
606 while (j && (header[i + j - 1] == ' ' || header[i + j - 1] == '\t'))
607 j--;
608 field = dStrndup(header + i, j);
609 return field;
610 }
611 while (header[i] != '\n') i++;
612 }
613 return NULL;
614}
615
619static Dlist *Cache_parse_multiple_fields(const char *header,
620 const char *fieldname)
621{
622 uint_t i, j;
623 Dlist *fields = dList_new(8);
624 char *field;
625
626 for (i = 0; header[i]; i++) {
627 /* Search fieldname */
628 for (j = 0; fieldname[j]; j++)
629 if (D_ASCII_TOLOWER(fieldname[j]) != D_ASCII_TOLOWER(header[i + j]))
630 break;
631 if (fieldname[j]) {
632 /* skip to next line */
633 for (i += j; header[i] != '\n'; i++);
634 continue;
635 }
636
637 i += j;
638 if (header[i] == ':') {
639 /* Field found! */
640 while (header[++i] == ' ' || header[i] == '\t');
641 for (j = 0; header[i + j] != '\n'; j++);
642 while (j && (header[i + j - 1] == ' ' || header[i + j - 1] == '\t'))
643 j--;
644 field = dStrndup(header + i, j);
645 dList_append(fields, field);
646 } else {
647 while (header[i] != '\n') i++;
648 }
649 }
650
651 if (dList_length(fields) == 0) {
652 dList_free(fields);
653 fields = NULL;
654 }
655 return fields;
656}
657
662static void Cache_parse_header(CacheEntry_t *entry)
663{
664 char *header = entry->Header->str;
665 bool_t server1point0 = !strncmp(entry->Header->str, "HTTP/1.0", 8);
666 char *Length, *Type, *location_str, *encoding, *connection, *hsts;
667#ifndef DISABLE_COOKIES
668 Dlist *Cookies;
669#endif
670 Dlist *warnings;
671 void *data;
672 int i;
673
674 _MSG("Cache_parse_header\n");
675
676 if (entry->Header->len > 12) {
677 if (header[9] == '1' && header[10] == '0' && header[11] == '0') {
678 /* 100: Continue. The "real" header has not come yet. */
679 MSG("An actual 100 Continue header!\n");
680 entry->Flags &= ~CA_GotHeader;
681 dStr_free(entry->Header, 1);
682 entry->Header = dStr_new("");
683 return;
684 }
685 if (header[9] == '3' && header[10] == '0' &&
686 (location_str = Cache_parse_field(header, "Location"))) {
687 /* 30x: URL redirection */
688 entry->Location = a_Url_new(location_str, URL_STR_(entry->Url));
689
690 if (!a_Domain_permit(entry->Url, entry->Location) ||
691 (URL_FLAGS(entry->Location) & (URL_Post + URL_Get) &&
692 dStrAsciiCasecmp(URL_SCHEME(entry->Location), "dpi") == 0 &&
693 dStrAsciiCasecmp(URL_SCHEME(entry->Url), "dpi") != 0)) {
694 /* Domain test, and forbid dpi GET and POST from non dpi-generated
695 * urls.
696 */
697 MSG("Redirection not followed from %s to %s\n",
698 URL_HOST(entry->Url), URL_STR(entry->Location));
699 } else {
700 entry->Flags |= CA_Redirect;
701 if (header[11] == '1')
702 entry->Flags |= CA_ForceRedirect; /* 301 Moved Permanently */
703 else if (header[11] == '2')
704 entry->Flags |= CA_TempRedirect; /* 302 Temporary Redirect */
705 }
706 dFree(location_str);
707 } else if (strncmp(header + 9, "401", 3) == 0) {
708 entry->Auth =
709 Cache_parse_multiple_fields(header, "WWW-Authenticate");
710 } else if (strncmp(header + 9, "404", 3) == 0) {
711 entry->Flags |= CA_NotFound;
712 }
713 }
714
715 if ((warnings = Cache_parse_multiple_fields(header, "Warning"))) {
716 for (i = 0; (data = dList_nth_data(warnings, i)); ++i) {
717 MSG_HTTP("%s\n", (char *)data);
718 dFree(data);
719 }
720 dList_free(warnings);
721 }
722
723 if (server1point0)
724 entry->Flags &= ~CA_KeepAlive;
725
726 if ((connection = Cache_parse_field(header, "Connection"))) {
727 if (!dStrAsciiCasecmp(connection, "close"))
728 entry->Flags &= ~CA_KeepAlive;
729 else if (server1point0 && !dStrAsciiCasecmp(connection, "keep-alive"))
730 entry->Flags |= CA_KeepAlive;
731 dFree(connection);
732 }
733
735 !dStrAsciiCasecmp(URL_SCHEME(entry->Url), "https") &&
736 a_Url_host_type(URL_HOST(entry->Url)) == URL_HOST_NAME &&
737 (hsts = Cache_parse_field(header, "Strict-Transport-Security"))) {
738 a_Hsts_set(hsts, entry->Url);
739 dFree(hsts);
740 }
741
742 /*
743 * Get Transfer-Encoding and initialize decoder
744 */
745 encoding = Cache_parse_field(header, "Transfer-Encoding");
746 entry->TransferDecoder = a_Decode_transfer_init(encoding);
747
748
749 if ((Length = Cache_parse_field(header, "Content-Length")) != NULL) {
750 if (encoding) {
751 /*
752 * If Transfer-Encoding is present, Content-Length must be ignored.
753 * If the Transfer-Encoding is non-identity, it is an error.
754 */
755 if (dStrAsciiCasecmp(encoding, "identity"))
756 MSG_HTTP("Content-Length and non-identity Transfer-Encoding "
757 "headers both present.\n");
758 } else {
759 entry->Flags |= CA_GotLength;
760 entry->ExpectedSize = MAX(strtol(Length, NULL, 10), 0);
761 }
762 dFree(Length);
763 }
764
765 dFree(encoding); /* free Transfer-Encoding */
766
767#ifndef DISABLE_COOKIES
768 if ((Cookies = Cache_parse_multiple_fields(header, "Set-Cookie"))) {
769 CacheClient_t *client;
770
771 for (i = 0; (client = dList_nth_data(ClientQueue, i)); ++i) {
772 if (client->Url == entry->Url) {
773 DilloWeb *web = client->Web;
774
775 if (!web->requester ||
776 a_Url_same_organization(entry->Url, web->requester)) {
777 /* If cookies are third party, don't even consider them. */
778 char *server_date = Cache_parse_field(header, "Date");
779
780 a_Cookies_set(Cookies, entry->Url, server_date);
781 dFree(server_date);
782 break;
783 }
784 }
785 }
786 for (i = 0; (data = dList_nth_data(Cookies, i)); ++i)
787 dFree(data);
788 dList_free(Cookies);
789 }
790#endif /* !DISABLE_COOKIES */
791
792 /*
793 * Get Content-Encoding and initialize decoder
794 */
795 encoding = Cache_parse_field(header, "Content-Encoding");
796 entry->ContentDecoder = a_Decode_content_init(encoding);
797 dFree(encoding);
798
799 if (entry->ExpectedSize > 0) {
800 if (entry->ExpectedSize > HUGE_FILESIZE) {
801 entry->Flags |= CA_HugeFile;
802 }
803 /* Avoid some reallocs. With MAX_INIT_BUF we avoid a SEGFAULT
804 * with huge files (e.g. iso files).
805 * Note: the buffer grows automatically. */
806 dStr_free(entry->Data, 1);
807 entry->Data = dStr_sized_new(MIN(entry->ExpectedSize, MAX_INIT_BUF));
808 }
809
810 /* Get Content-Type */
811 if ((Type = Cache_parse_field(header, "Content-Type"))) {
812 /* This HTTP Content-Type is not trusted. It's checked against real data
813 * in Cache_process_queue(); only then CA_GotContentType becomes true. */
814 a_Cache_set_content_type(entry->Url, Type, "http");
815 _MSG("TypeHdr {%s} {%s}\n", Type, URL_STR(entry->Url));
816 _MSG("TypeMeta {%s}\n", entry->TypeMeta);
817 dFree(Type);
818 }
819
820 entry->ContentDisposition = Cache_parse_field(header, "Content-Disposition");
821
822 Cache_ref_data(entry);
823}
824
829static int Cache_get_header(CacheEntry_t *entry,
830 const char *buf, size_t buf_size)
831{
832 size_t N, i;
833 Dstr *hdr = entry->Header;
834
835 /* Header finishes when N = 2 */
836 N = (hdr->len && hdr->str[hdr->len - 1] == '\n');
837 for (i = 0; i < buf_size && N < 2; ++i) {
838 if (buf[i] == '\r' || !buf[i])
839 continue;
840 if (N == 1 && (buf[i] == ' ' || buf[i] == '\t')) {
841 /* unfold multiple-line header */
842 _MSG("Multiple-line header!\n");
843 dStr_erase(hdr, hdr->len - 1, 1);
844 }
845 N = (buf[i] == '\n') ? N + 1 : 0;
846 dStr_append_c(hdr, buf[i]);
847 }
848
849 if (N == 2) {
850 /* Got whole header */
851 _MSG("Header [buf_size=%d]\n%s", i, hdr->str);
852 entry->Flags |= CA_GotHeader;
853 dStr_fit(hdr);
854 /* Return number of header bytes in 'buf' [1 based] */
855 return i;
856 }
857 return 0;
858}
859
860static void Cache_finish_msg(CacheEntry_t *entry)
861{
862 if (!(entry->Flags & CA_InProgress)) {
863 /* already finished */
864 return;
865 }
866
867 if ((entry->ExpectedSize || entry->TransferSize) &&
868 entry->TypeHdr == NULL) {
869 MSG_HTTP("Message with a body lacked Content-Type header.\n");
870 }
871 if ((entry->Flags & CA_GotLength) &&
872 (entry->ExpectedSize != entry->TransferSize)) {
873 MSG_HTTP("Content-Length (%d) does NOT match message body (%d) for %s\n",
874 entry->ExpectedSize, entry->TransferSize, URL_STR_(entry->Url));
875 }
876 entry->Flags &= ~CA_InProgress;
877 if (entry->TransferDecoder) {
878 a_Decode_transfer_free(entry->TransferDecoder);
879 entry->TransferDecoder = NULL;
880 }
881 if (entry->ContentDecoder) {
882 a_Decode_free(entry->ContentDecoder);
883 entry->ContentDecoder = NULL;
884 }
885 dStr_fit(entry->Data); /* fit buffer size! */
886
887 if ((entry = Cache_process_queue(entry))) {
888 if (entry->Flags & CA_GotHeader) {
889 Cache_unref_data(entry);
890 }
891 }
892}
893
902bool_t a_Cache_process_dbuf(int Op, const char *buf, size_t buf_size,
903 const DilloUrl *Url)
904{
905 int offset, len;
906 const char *str;
907 Dstr *dstr1, *dstr2, *dstr3;
908 bool_t done = FALSE;
909 CacheEntry_t *entry = Cache_entry_search(Url);
910
911 /* Assert a valid entry (not aborted) */
912 dReturn_val_if_fail (entry != NULL, FALSE);
913
914 _MSG("__a_Cache_process_dbuf__\n");
915
916 if (Op == IORead) {
917 /*
918 * Cache_get_header() will set CA_GotHeader if it has a full header, and
919 * Cache_parse_header() will unset it if the header ends being
920 * merely an informational response from the server (i.e., 100 Continue)
921 */
922 for (offset = 0; !(entry->Flags & CA_GotHeader) &&
923 (len = Cache_get_header(entry, buf + offset, buf_size - offset));
924 Cache_parse_header(entry) ) {
925 offset += len;
926 }
927
928 if (entry->Flags & CA_GotHeader) {
929 str = buf + offset;
930 len = buf_size - offset;
931 entry->TransferSize += len;
932 dstr1 = dstr2 = dstr3 = NULL;
933
934 /* Decode arrived data (<= 3 stages) */
935 if (entry->TransferDecoder) {
936 dstr1 = a_Decode_transfer_process(entry->TransferDecoder, str,len);
937 done = a_Decode_transfer_finished(entry->TransferDecoder);
938 str = dstr1->str;
939 len = dstr1->len;
940 }
941 if (entry->ContentDecoder) {
942 dstr2 = a_Decode_process(entry->ContentDecoder, str, len);
943 str = dstr2->str;
944 len = dstr2->len;
945 }
946 dStr_append_l(entry->Data, str, len);
947 if (entry->CharsetDecoder && entry->UTF8Data) {
948 dstr3 = a_Decode_process(entry->CharsetDecoder, str, len);
949 dStr_append_l(entry->UTF8Data, dstr3->str, dstr3->len);
950 }
951 dStr_free(dstr1, 1);
952 dStr_free(dstr2, 1);
953 dStr_free(dstr3, 1);
954
955 if (entry->Data->len)
956 entry->Flags &= ~CA_IsEmpty;
957
958 if ((entry->Flags & CA_GotLength) &&
959 (entry->TransferSize >= entry->ExpectedSize)) {
960 done = TRUE;
961 }
962 if (!(entry->Flags & CA_KeepAlive)) {
963 /* Let IOClose finish it later */
964 done = FALSE;
965 }
966
967 entry = Cache_process_queue(entry);
968
969 if (entry && done)
970 Cache_finish_msg(entry);
971 }
972 } else if (Op == IOClose) {
973 Cache_finish_msg(entry);
974 } else if (Op == IOAbort) {
975 entry->Flags |= CA_Aborted;
976 if (entry->Data->len) {
977 MSG("Premature close for %s\n", URL_STR(entry->Url));
978 Cache_finish_msg(entry);
979 } else {
980 int i;
981 CacheClient_t *Client;
982
983 for (i = 0; (Client = dList_nth_data(ClientQueue, i)); ++i) {
984 if (Client->Url == entry->Url) {
985 DilloWeb *web = (DilloWeb *)Client->Web;
986
987 a_Bw_remove_client(web->bw, Client->Key);
988 Cache_client_dequeue(Client);
989 --i; /* Keep the index value in the next iteration */
990 }
991 }
992 }
993 }
994 return done;
995}
996
1001static int Cache_redirect(CacheEntry_t *entry, int Flags, BrowserWindow *bw)
1002{
1003 DilloUrl *NewUrl;
1004
1005 _MSG(" Cache_redirect: redirect_level = %d\n", bw->redirect_level);
1006
1007 /* Don't allow redirection for SpamSafe/local URLs */
1008 if (URL_FLAGS(entry->Url) & URL_SpamSafe) {
1009 a_UIcmd_set_msg(bw, "WARNING: local URL with redirection. Aborting.");
1010 return 0;
1011 }
1012
1013 /* if there's a redirect loop, stop now */
1014 if (bw->redirect_level >= 5)
1015 entry->Flags |= CA_RedirectLoop;
1016
1017 if (entry->Flags & CA_RedirectLoop) {
1018 a_UIcmd_set_msg(bw, "ERROR: redirect loop for: %s", URL_STR_(entry->Url));
1019 bw->redirect_level = 0;
1020 return 0;
1021 }
1022
1023 if ((entry->Flags & CA_Redirect && entry->Location) &&
1024 (entry->Flags & CA_ForceRedirect || entry->Flags & CA_TempRedirect ||
1025 !entry->Data->len || entry->Data->len < 1024)) {
1026
1027 _MSG(">>>> Redirect from: %s\n to %s <<<<\n",
1028 URL_STR_(entry->Url), URL_STR_(entry->Location));
1029 _MSG("%s", entry->Header->str);
1030
1031 if (Flags & WEB_RootUrl) {
1032 /* Redirection of the main page */
1033 NewUrl = a_Url_new(URL_STR_(entry->Location), URL_STR_(entry->Url));
1034 if (entry->Flags & CA_TempRedirect)
1035 a_Url_set_flags(NewUrl, URL_FLAGS(NewUrl) | URL_E2EQuery);
1036 a_Nav_push(bw, NewUrl, entry->Url);
1037 a_Url_free(NewUrl);
1038 } else {
1039 /* Sub entity redirection (most probably an image) */
1040 if (!entry->Data->len) {
1041 _MSG(">>>> Image redirection without entity-content <<<<\n");
1042 } else {
1043 _MSG(">>>> Image redirection with entity-content <<<<\n");
1044 }
1045 }
1046 }
1047 return 0;
1048}
1049
1050typedef struct {
1051 Dlist *auth;
1052 DilloUrl *url;
1053 BrowserWindow *bw;
1054} CacheAuthData_t;
1055
1059static void Cache_auth_callback(void *vdata)
1060{
1061 CacheAuthData_t *data = (CacheAuthData_t *)vdata;
1062 if (a_Auth_do_auth(data->auth, data->url))
1063 a_Nav_reload(data->bw);
1064 Cache_auth_free(data->auth);
1065 a_Url_free(data->url);
1066 dFree(data);
1067 Cache_auth_entry(NULL, NULL);
1069}
1070
1074static void Cache_auth_entry(CacheEntry_t *entry, BrowserWindow *bw)
1075{
1076 static int busy = 0;
1077 CacheAuthData_t *data;
1078
1079 if (!entry) {
1080 busy = 0;
1081 } else if (busy) {
1082 MSG_WARN("Cache_auth_entry: caught busy!\n");
1083 } else if (entry->Auth) {
1084 busy = 1;
1085 data = dNew(CacheAuthData_t, 1);
1086 data->auth = entry->Auth;
1087 data->url = a_Url_dup(entry->Url);
1088 data->bw = bw;
1089 entry->Auth = NULL;
1091 }
1092}
1093
1099{
1100 if (!dStrAsciiCasecmp(URL_SCHEME(url), "http") ||
1101 !dStrAsciiCasecmp(URL_SCHEME(url), "https") ||
1102 !dStrAsciiCasecmp(URL_SCHEME(url), "ftp"))
1103 return 1;
1104 return 0;
1105}
1106
1112static void Cache_null_client(int Op, CacheClient_t *Client)
1113{
1114 DilloWeb *Web = Client->Web;
1115
1116 /* make the stop button insensitive when done */
1117 if (Op == CA_Close) {
1118 if (Web->flags & WEB_RootUrl) {
1119 /* Remove this client from our active list */
1120 a_Bw_close_client(Web->bw, Client->Key);
1121 }
1122 }
1123
1124 /* else ignore */
1125
1126 return;
1127}
1128
1129typedef struct {
1130 BrowserWindow *bw;
1131 DilloUrl *url;
1132 char* filename;
1133} Cache_savelink_t;
1134
1139static void Cache_savelink_cb(void *vdata)
1140{
1141 Cache_savelink_t *data = (Cache_savelink_t*) vdata;
1142
1143 a_UIcmd_save_link(data->bw, data->url, data->filename);
1144 a_Url_free(data->url);
1145 dFree(data);
1146}
1147
1151static void Cache_provide_redirection_blocked_page(CacheEntry_t *entry,
1152 CacheClient_t *client)
1153{
1154 DilloWeb *clientWeb = client->Web;
1155
1156 a_Web_dispatch_by_type("text/html", clientWeb, &client->Callback,
1157 &client->CbData);
1158 client->Buf = dStrconcat("<!doctype html><html><body>"
1159 "Dillo blocked a redirection from <a href=\"",
1160 URL_STR(entry->Url), "\">", URL_STR(entry->Url),
1161 "</a> to <a href=\"", URL_STR(entry->Location), "\">",
1162 URL_STR(entry->Location), "</a> based on your domainrc "
1163 "settings.</body></html>", NULL);
1164 client->BufSize = strlen(client->Buf);
1165 (client->Callback)(CA_Send, client);
1166 dFree(client->Buf);
1167}
1168
1181static CacheEntry_t *Cache_process_queue(CacheEntry_t *entry)
1182{
1183 uint_t i;
1184 int st;
1185 const char *Type;
1186 Dstr *data;
1187 CacheClient_t *Client;
1188 DilloWeb *ClientWeb;
1189 BrowserWindow *Client_bw = NULL;
1190 static bool_t Busy = FALSE;
1191 bool_t AbortEntry = FALSE;
1192 bool_t OfferDownload = FALSE;
1193 bool_t TypeMismatch = FALSE;
1194 char *dtype = NULL;
1195 char *dfilename = NULL;
1196
1197 if (Busy)
1198 MSG_ERR("FATAL!: >>>> Cache_process_queue Caught busy!!! <<<<\n");
1199 if (!(entry->Flags & CA_GotHeader))
1200 return entry;
1201 if (!(entry->Flags & CA_GotContentType)) {
1203 entry->Data->str, entry->Data->len, &Type);
1204 _MSG("Cache: detected Content-Type '%s'\n", Type);
1205 if (st == 0 || !(entry->Flags & CA_InProgress)) {
1206 if (a_Misc_content_type_check(entry->TypeHdr, Type) < 0) {
1207 MSG_HTTP("Content-Type '%s' doesn't match the real data.\n",
1208 entry->TypeHdr);
1209 TypeMismatch = TRUE;
1210 }
1211 entry->TypeDet = dStrdup(Type);
1212 entry->Flags |= CA_GotContentType;
1213 } else
1214 return entry; /* i.e., wait for more data */
1215 }
1216 if (entry->ContentDisposition) {
1217 a_Misc_parse_content_disposition(entry->ContentDisposition, &dtype, &dfilename);
1218 }
1219
1220 Busy = TRUE;
1221 for (i = 0; (Client = dList_nth_data(ClientQueue, i)); ++i) {
1222 if (Client->Url == entry->Url) {
1223 ClientWeb = Client->Web; /* It was a (void*) */
1224 Client_bw = ClientWeb->bw; /* 'bw' in a local var */
1225
1226 if (ClientWeb->flags & WEB_RootUrl) {
1227 if (!(entry->Flags & CA_MsgErased)) {
1228 /* clear the "expecting for reply..." message */
1229 a_UIcmd_set_msg(Client_bw, "");
1230 entry->Flags |= CA_MsgErased;
1231 }
1232 if (TypeMismatch) {
1233 a_UIcmd_set_msg(Client_bw,"HTTP warning: Content-Type '%s' "
1234 "doesn't match the real data.", entry->TypeHdr);
1235 OfferDownload = TRUE;
1236 }
1237 if (entry->Flags & CA_Redirect) {
1238 if (!Client->Callback) {
1239 Client->Callback = Cache_null_client;
1240 Client_bw->redirect_level++;
1241 }
1242 } else {
1243 Client_bw->redirect_level = 0;
1244 }
1245 if (entry->Flags & CA_HugeFile) {
1246 a_UIcmd_set_msg(Client_bw, "Huge file! (%d MB)",
1247 entry->ExpectedSize / (1024*1024));
1248 AbortEntry = OfferDownload = TRUE;
1249 }
1250 } else {
1251 /* For non root URLs, ignore redirections and 404 answers */
1252 if (entry->Flags & CA_Redirect || entry->Flags & CA_NotFound)
1253 Client->Callback = Cache_null_client;
1254 }
1255
1256 /* Set the client function */
1257 if (!Client->Callback) {
1258 Client->Callback = Cache_null_client;
1259
1260 if (entry->Location && !(entry->Flags & CA_Redirect)) {
1261 /* Not following redirection, so don't display page body. */
1262 } else {
1263 if (TypeMismatch) {
1264 AbortEntry = TRUE;
1265 } else {
1266 const char *curr_type = Cache_current_content_type(entry);
1267 st = a_Web_dispatch_by_type(curr_type, ClientWeb,
1268 &Client->Callback,
1269 &Client->CbData);
1270 if (st == -1) {
1271 /* MIME type is not viewable */
1272 if (ClientWeb->flags & WEB_RootUrl) {
1273 MSG("Content-Type '%s' not viewable.\n", curr_type);
1274 /* prepare a download offer... */
1275 AbortEntry = OfferDownload = TRUE;
1276 } else {
1277 /* TODO: Resource Type not handled.
1278 * Not aborted to avoid multiple connections on the
1279 * same resource. A better idea is to abort the
1280 * connection and to keep a failed-resource flag in
1281 * the cache entry. */
1282 }
1283 } else if (dtype && dStrnAsciiCasecmp(dtype, "inline", 6) != 0) {
1284 AbortEntry = OfferDownload = TRUE;
1285 }
1286 }
1287 if (AbortEntry) {
1288 if (ClientWeb->flags & WEB_RootUrl)
1289 a_Nav_cancel_expect_if_eq(Client_bw, Client->Url);
1290 a_Bw_remove_client(Client_bw, Client->Key);
1291 Cache_client_dequeue(Client);
1292 --i; /* Keep the index value in the next iteration */
1293 continue;
1294 }
1295 }
1296 }
1297
1298 /* Send data to our client */
1299 if (ClientWeb->flags & WEB_Download) {
1300 /* for download, always provide original data, not translated */
1301 data = entry->Data;
1302 } else {
1303 data = Cache_data(entry);
1304 }
1305 if ((Client->BufSize = data->len) > 0) {
1306 Client->Buf = data->str;
1307 (Client->Callback)(CA_Send, Client);
1308 if (ClientWeb->flags & WEB_RootUrl) {
1309 /* show size of page received */
1310 a_UIcmd_set_page_prog(Client_bw, entry->Data->len, 1);
1311 }
1312 }
1313
1314 /* Remove client when done */
1315 if (!(entry->Flags & CA_InProgress)) {
1316 /* Copy flags to a local var */
1317 int flags = ClientWeb->flags;
1318
1319 if (ClientWeb->flags & WEB_RootUrl && entry->Location &&
1320 !(entry->Flags & CA_Redirect)) {
1322 }
1323 /* We finished sending data, let the client know */
1324 (Client->Callback)(CA_Close, Client);
1325 if (ClientWeb->flags & WEB_RootUrl) {
1326 if (entry->Flags & CA_Aborted) {
1327 a_UIcmd_set_msg(Client_bw, "ERROR: Connection closed early, "
1328 "read not complete.");
1329 }
1330 a_UIcmd_set_page_prog(Client_bw, 0, 0);
1331 }
1332 Cache_client_dequeue(Client);
1333 --i; /* Keep the index value in the next iteration */
1334
1335 /* we assert just one redirect call */
1336 if (entry->Flags & CA_Redirect)
1337 Cache_redirect(entry, flags, Client_bw);
1338 }
1339 }
1340 } /* for */
1341
1342 if (AbortEntry) {
1343 /* Abort the entry, remove it from cache, and maybe offer download. */
1344 DilloUrl *url = a_Url_dup(entry->Url);
1346 entry = NULL;
1347 if (OfferDownload) {
1348 /* Remove entry when 'conn' is already done */
1349 Cache_entry_remove(NULL, url);
1350 if (a_Cache_download_enabled(url)) {
1351 Cache_savelink_t *data = dNew(Cache_savelink_t, 1);
1352 data->bw = Client_bw;
1353 data->url = a_Url_dup(url);
1354 data->filename = dStrdup(dfilename);
1355 a_Timeout_add(0.0, Cache_savelink_cb, data);
1356 }
1357 }
1358 a_Url_free(url);
1359 } else if (entry->Auth && !(entry->Flags & CA_InProgress)) {
1360 Cache_auth_entry(entry, Client_bw);
1361 }
1362
1363 dFree(dtype); dFree(dfilename);
1364
1365 /* Trigger cleanup when there are no cache clients */
1366 if (dList_length(ClientQueue) == 0) {
1368 }
1369
1370 Busy = FALSE;
1371 _MSG("QueueSize ====> %d\n", dList_length(ClientQueue));
1372 return entry;
1373}
1374
1379{
1380 CacheEntry_t *entry;
1381 (void) ptr; /* Unused */
1382
1383 while ((entry = (CacheEntry_t *)dList_nth_data(DelayedQueue, 0))) {
1384 Cache_ref_data(entry);
1385 if ((entry = Cache_process_queue(entry))) {
1386 Cache_unref_data(entry);
1387 dList_remove(DelayedQueue, entry);
1388 }
1389 }
1392}
1393
1397static void Cache_delayed_process_queue(CacheEntry_t *entry)
1398{
1399 /* there's no need to repeat entries in the queue */
1400 if (!dList_find(DelayedQueue, entry))
1401 dList_append(DelayedQueue, entry);
1402
1403 if (DelayedQueueIdleId == 0) {
1404 _MSG(" Setting timeout callback\n");
1407 }
1408}
1409
1416{
1417 int i, n = 0;
1418 CacheClient_t *Client, *iClient;
1419
1420 if ((Client = dList_find_custom(ClientQueue, INT2VOIDP(Key),
1422 for (i = 0; (iClient = dList_nth_data(ClientQueue, i)); ++i) {
1423 if (iClient->Url == Client->Url) {
1424 ++n;
1425 }
1426 }
1427 }
1428 return (n == 1) ? Client : NULL;
1429}
1430
1436{
1437 CacheClient_t *Client;
1438 CacheEntry_t *entry;
1439 DICacheEntry *DicEntry;
1440
1441 /* The client can be in both queues at the same time */
1442 if ((Client = dList_find_custom(ClientQueue, INT2VOIDP(Key),
1444 /* Dicache */
1445 if ((DicEntry = a_Dicache_get_entry(Client->Url, Client->Version)))
1446 a_Dicache_unref(Client->Url, Client->Version);
1447
1448 /* DelayedQueue */
1449 if ((entry = Cache_entry_search(Client->Url)))
1450 dList_remove(DelayedQueue, entry);
1451
1452 /* Main queue */
1453 Cache_client_dequeue(Client);
1454
1455 } else {
1456 _MSG("WARNING: Cache_stop_client, nonexistent client\n");
1457 }
1458}
1459
1460
1465{
1466 CacheClient_t *Client;
1467 void *data;
1468
1469 /* free the client queue */
1470 while ((Client = dList_nth_data(ClientQueue, 0)))
1471 Cache_client_dequeue(Client);
1472
1473 /* Remove every cache entry */
1474 while ((data = dList_nth_data(CachedURLs, 0))) {
1476 Cache_entry_free(data);
1477 }
1478 /* Remove the cache list */
1480}
#define IORead
Definition IO.h:11
#define IOAbort
Definition IO.h:14
#define IOClose
Definition IO.h:13
const char *const AboutSplash
HTML text for startup screen.
Definition about.c:18
int a_Auth_do_auth(Dlist *challenges, const DilloUrl *url)
Given authentication challenge(s), prepare authorization.
Definition auth.c:671
#define _MSG(...)
Definition bookmarks.c:45
static char * Header
Definition bookmarks.c:86
#define MSG(...)
Definition bookmarks.c:46
int a_Bw_remove_client(BrowserWindow *bw, int ClientKey)
Remove the cache-client from the bw's list (client can be a image or a html page) Return: 0 if found,...
Definition bw.c:149
void a_Bw_close_client(BrowserWindow *bw, int ClientKey)
Close a cache-client upon successful retrieval.
Definition bw.c:167
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.
Definition cache.c:554
CacheClient_t * a_Cache_client_get_if_unique(int Key)
Last Client for this entry?
Definition cache.c:1415
static void Cache_savelink_cb(void *vdata)
Save link from behind a timeout so that Cache_process_queue() can get on with its work.
Definition cache.c:1139
static void Cache_entry_remove(CacheEntry_t *entry, DilloUrl *url)
Remove an entry, from the cache.
Definition cache.c:327
static void Cache_delayed_process_queue(CacheEntry_t *entry)
Set a call to Cache_process_queue from the main cycle.
Definition cache.c:1397
static void Cache_finish_msg(CacheEntry_t *entry)
Definition cache.c:860
static Dlist * ClientQueue
A list for cache clients.
Definition cache.c:79
uint_t a_Cache_get_flags_with_redirection(const DilloUrl *url)
Get cache entry status (following redirections).
Definition cache.c:417
static void Cache_parse_header(CacheEntry_t *entry)
Scan, allocate, and set things according to header info.
Definition cache.c:662
static int Cache_entry_by_url_cmp(const void *v1, const void *v2)
Determine if two cache entries are equal, using a URL as key.
Definition cache.c:107
static void Cache_auth_entry(CacheEntry_t *entry, BrowserWindow *bw)
Set a timeout function to ask for user/password.
Definition cache.c:1074
static CacheEntry_t * Cache_entry_search_with_redirect(const DilloUrl *Url)
Given a URL, find its cache entry, following redirections.
Definition cache.c:227
static Dlist * DelayedQueue
A list for delayed clients (it holds weak pointers to cache entries, which are used to make deferred ...
Definition cache.c:83
static uint_t DelayedQueueIdleId
Definition cache.c:84
static Dlist * CachedURLs
A sorted list for cached data.
Definition cache.c:75
static int Cache_get_header(CacheEntry_t *entry, const char *buf, size_t buf_size)
Consume bytes until the whole header is got (up to a "\r\n\r\n" sequence) (Also unfold multi-line fie...
Definition cache.c:829
static void Cache_entry_init(CacheEntry_t *NewEntry, const DilloUrl *Url)
Set safe values for a new cache entry.
Definition cache.c:193
static const char * Cache_current_content_type(CacheEntry_t *entry)
Get current content type.
Definition cache.c:465
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.
Definition cache.c:494
static void Cache_client_dequeue(CacheClient_t *Client)
Remove a client from the queue.
Definition cache.c:178
static void Cache_auth_free(Dlist *auth)
Free Authentication fields.
Definition cache.c:288
void a_Cache_unref_buf(const DilloUrl *Url)
Unreference the data buffer when no longer using it.
Definition cache.c:573
static void Cache_null_client(int Op, CacheClient_t *Client)
Don't process data any further, but let the cache fill the entry.
Definition cache.c:1112
static char * Cache_parse_field(const char *header, const char *fieldname)
Extract a single field from the header, allocating and storing the value in 'field'.
Definition cache.c:585
static void Cache_auth_callback(void *vdata)
Ask for user/password and reload the page.
Definition cache.c:1059
const char * a_Cache_get_content_type(const DilloUrl *url)
Get current Content-Type for cache entry found by URL.
Definition cache.c:474
static void Cache_ref_data(CacheEntry_t *entry)
Reference the cache data.
Definition cache.c:426
static CacheEntry_t * Cache_process_queue(CacheEntry_t *entry)
Update cache clients for a single cache-entry Tasks:
Definition cache.c:1181
static void Cache_provide_redirection_blocked_page(CacheEntry_t *entry, CacheClient_t *client)
Let the client know that we're not following a redirection.
Definition cache.c:1151
void a_Cache_entry_remove_by_url(DilloUrl *url)
Wrapper for capi.
Definition cache.c:359
static CacheEntry_t * Cache_entry_search(const DilloUrl *Url)
Get the data structure for a cached URL (using 'Url' as the search key) If 'Url' isn't cached,...
Definition cache.c:219
static Dstr * Cache_data(CacheEntry_t *entry)
Get pointer to entry's data.
Definition cache.c:484
static int Cache_client_enqueue(const DilloUrl *Url, DilloWeb *Web, CA_Callback_t Callback, void *CbData)
Add a client to ClientQueue.
Definition cache.c:141
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...
Definition cache.c:902
int a_Cache_download_enabled(const DilloUrl *url)
Check whether a URL scheme is downloadable.
Definition cache.c:1098
static void Cache_entry_free(CacheEntry_t *entry)
Free the components of a CacheEntry_t struct.
Definition cache.c:300
static void Cache_unref_data(CacheEntry_t *entry)
Unreference the cache data.
Definition cache.c:444
#define HUGE_FILESIZE
Maximum filesize for a URL, before offering a download.
Definition cache.c:43
static int Cache_entry_cmp(const void *v1, const void *v2)
Determine if two cache entries are equal (used by CachedURLs)
Definition cache.c:97
void a_Cache_init(void)
Initialize cache data.
Definition cache.c:118
static void Cache_delayed_process_queue_callback(void *ptr)
Callback function for Cache_delayed_process_queue.
Definition cache.c:1378
static CacheEntry_t * Cache_entry_add(const DilloUrl *Url)
Allocate and set a new entry in the cache list.
Definition cache.c:251
#define MAX_INIT_BUF
Maximum initial size for the automatically-growing data buffer.
Definition cache.c:41
static int Cache_client_by_key_cmp(const void *client, const void *key)
Compare function for searching a Client by its key.
Definition cache.c:170
void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds)
Inject full page content directly into the cache.
Definition cache.c:270
static int Cache_redirect(CacheEntry_t *entry, int Flags, BrowserWindow *bw)
Process redirections (HTTP 30x answers) (This is a work in progress –not finished yet)
Definition cache.c:1001
int a_Cache_open_url(void *web, CA_Callback_t Call, void *CbData)
Try finding the url in the cache.
Definition cache.c:378
static Dlist * Cache_parse_multiple_fields(const char *header, const char *fieldname)
Extract multiple fields from the header.
Definition cache.c:619
void a_Cache_freeall(void)
Memory deallocator (only called at exit time)
Definition cache.c:1464
uint_t a_Cache_get_flags(const DilloUrl *url)
Get cache entry status.
Definition cache.c:408
void a_Cache_stop_client(int Key)
Remove a client from the client queue TODO: notify the dicache and upper layers.
Definition cache.c:1435
#define CA_Send
Definition cache.h:27
#define CA_KeepAlive
Definition cache.h:48
#define CA_NotFound
Definition cache.h:41
#define CA_InternalUrl
Definition cache.h:45
void(* CA_Callback_t)(int Op, CacheClient_t *Client)
Callback type for cache clients.
Definition cache.h:55
#define CA_Redirect
Definition cache.h:38
#define CA_ForceRedirect
Definition cache.h:39
#define CA_RedirectLoop
Definition cache.h:44
#define CA_IsEmpty
Definition cache.h:47
#define CA_GotContentType
Definition cache.h:35
#define CA_Aborted
Definition cache.h:42
#define CA_Close
Definition cache.h:28
#define CA_HugeFile
Definition cache.h:46
#define CA_MsgErased
Definition cache.h:43
#define CA_TempRedirect
Definition cache.h:40
#define CA_InProgress
Definition cache.h:37
#define CA_GotHeader
Definition cache.h:34
#define CA_GotLength
Definition cache.h:36
void a_Capi_conn_abort_by_url(const DilloUrl *url)
Abort the connection for a given url, using its CCC.
Definition capi.c:200
unsigned int uint_t
Definition d_size.h:20
unsigned char bool_t
Definition d_size.h:21
Decode * a_Decode_charset_init(const char *format)
Initialize decoder to translate from any character set known to iconv() to UTF-8.
Definition decode.c:453
Dstr * a_Decode_transfer_process(DecodeTransfer *dc, const char *instr, int inlen)
Decode 'Transfer-Encoding: chunked' data.
Definition decode.c:33
void a_Decode_transfer_free(DecodeTransfer *dc)
Definition decode.c:97
Decode * a_Decode_content_init(const char *format)
Initialize content decoder.
Definition decode.c:410
DecodeTransfer * a_Decode_transfer_init(const char *format)
Initialize transfer decoder.
Definition decode.c:374
Dstr * a_Decode_process(Decode *dc, const char *instr, int inlen)
Decode data.
Definition decode.c:480
void a_Decode_free(Decode *dc)
Definition decode.c:488
bool_t a_Decode_transfer_finished(DecodeTransfer *dc)
Definition decode.c:92
DICacheEntry * a_Dicache_get_entry(const DilloUrl *Url, int version)
Search a particular version of a URL in the Dicache.
Definition dicache.c:150
void a_Dicache_cleanup(void)
Free the imgbuf (RGB data) of unused entries.
Definition dicache.c:560
void a_Dicache_invalidate_entry(const DilloUrl *Url)
Invalidate this entry.
Definition dicache.c:232
void a_Dicache_unref(const DilloUrl *Url, int version)
Unrefs the counter of a dicache entry (it counts cache clients).
Definition dicache.c:200
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
Definition dlib.c:102
void dList_insert_sorted(Dlist *lp, void *data, dCompareFunc func)
Insert an element into a sorted list.
Definition dlib.c:769
void dFree(void *mem)
Definition dlib.c:68
int dStrAsciiCasecmp(const char *s1, const char *s2)
Definition dlib.c:203
char * dStrdup(const char *s)
Definition dlib.c:77
Dlist * dList_new(int size)
Create a new empty list.
Definition dlib.c:548
Dstr * dStr_sized_new(int sz)
Create a new string with a given size.
Definition dlib.c:254
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)
Definition dlib.c:215
void dStr_erase(Dstr *ds, int pos_0, int len)
Erase a substring.
Definition dlib.c:388
int dList_length(Dlist *lp)
For completing the ADT.
Definition dlib.c:613
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
Definition dlib.c:662
void dList_remove_fast(Dlist *lp, const void *data)
Remove a data item without preserving order.
Definition dlib.c:623
void dStr_free(Dstr *ds, int all)
Free a dillo string.
Definition dlib.c:337
void dStr_append_l(Dstr *ds, const char *s, int l)
Append a C string to a Dstr (providing length).
Definition dlib.c:308
void dStr_append_c(Dstr *ds, int c)
Append one character.
Definition dlib.c:349
char * dStrndup(const char *s, size_t sz)
Definition dlib.c:88
Dstr * dStr_new(const char *s)
Create a new string.
Definition dlib.c:325
void dList_append(Dlist *lp, void *data)
Append a data item to the list.
Definition dlib.c:597
void * dList_find_sorted(Dlist *lp, const void *data, dCompareFunc func)
Search a sorted list.
Definition dlib.c:796
void dList_free(Dlist *lp)
Free a list (not its elements)
Definition dlib.c:564
void * dList_find_custom(Dlist *lp, const void *data, dCompareFunc func)
Search a data item using a custom function.
Definition dlib.c:704
void dStr_fit(Dstr *ds)
Return memory if there's too much allocated.
Definition dlib.c:269
void dStr_truncate(Dstr *ds, int len)
Truncate a Dstr to be 'len' bytes long.
Definition dlib.c:368
void dList_remove(Dlist *lp, const void *data)
Definition dlib.c:641
void * dList_find(Dlist *lp, const void *data)
Return the found data item, or NULL if not present.
Definition dlib.c:672
#define MIN(a, b)
Definition dlib.h:30
#define dReturn_val_if_fail(expr, val)
Definition dlib.h:76
#define D_ASCII_TOLOWER(c)
Definition dlib.h:37
#define VOIDP2INT(p)
Definition dlib.h:43
#define TRUE
Definition dlib.h:23
#define FALSE
Definition dlib.h:19
#define INT2VOIDP(i)
Definition dlib.h:44
#define MAX(a, b)
Definition dlib.h:27
#define dNew(type, count)
Definition dlib.h:49
bool_t a_Domain_permit(const DilloUrl *source, const DilloUrl *dest)
Is the resource at 'source' permitted to request the resource at 'dest'?
Definition domain.c:116
#define MSG_ERR(...)
Definition dpid_common.h:23
void a_Hsts_set(const char *header, const DilloUrl *url)
The response for this url had an HSTS header, so let's take action.
Definition hsts.c:201
#define _MSG_WARN(...)
Definition msg.h:15
#define MSG_WARN(...)
Definition msg.h:26
int a_Misc_content_type_check(const char *EntryType, const char *DetectedType)
Check the server-supplied 'Content-Type' against our detected type.
Definition misc.c:321
int a_Misc_content_type_cmp(const char *ct1, const char *ct2)
Compare two Content-Type strings.
Definition misc.c:274
int a_Misc_get_content_type_from_data(void *Data, size_t Size, const char **PT)
Detects 'Content-Type' from a data stream sample.
Definition misc.c:136
void a_Misc_parse_content_type(const char *type, char **major, char **minor, char **charset)
Parse Content-Type string, e.g., "text/html; charset=utf-8".
Definition misc.c:210
static void a_Misc_parse_content_disposition(const char *disposition, char **type, char **filename)
Parse Content-Disposition string, e.g., "attachment; filename="file name.jpg"".
Definition misc.h:30
void a_Nav_cancel_expect_if_eq(BrowserWindow *bw, const DilloUrl *url)
Definition nav.c:260
void a_Nav_reload(BrowserWindow *bw)
Definition nav.c:542
void a_Nav_push(BrowserWindow *bw, const DilloUrl *url, const DilloUrl *requester)
Definition nav.c:342
DilloPrefs prefs
Global Data.
Definition prefs.c:33
void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url, const char *date)
Set the value corresponding to the cookie string.
Definition cookies.c:142
#define MSG_HTTP(...)
Definition msg.h:25
Contains the specific data for a single window.
Definition bw.h:27
int redirect_level
Counter for the number of hops on a redirection.
Definition bw.h:63
Data structure for cache clients.
Definition cache.h:60
CA_Callback_t Callback
Client function.
Definition cache.h:66
const DilloUrl * Url
Pointer to a cache entry Url.
Definition cache.h:62
int Key
Primary Key for this client.
Definition cache.h:61
int Version
Dicache version of this Url (0 if not used)
Definition cache.h:63
void * CbData
Client function data.
Definition cache.h:67
uint_t BufSize
Valid size of cache-data.
Definition cache.h:65
void * Buf
Pointer to cache-data.
Definition cache.h:64
void * Web
Pointer to the Web structure of our client.
Definition cache.h:68
bool_t http_strict_transport_security
Definition prefs.h:105
Definition url.h:88
Definition dlib.h:131
Definition dlib.h:102
Dstr_char_t * str
Definition dlib.h:105
int len
Definition dlib.h:104
int flags
Additional info.
Definition web.hh:29
DilloUrl * url
Requested URL.
Definition web.hh:25
DilloUrl * requester
URL that caused this request, or < NULL if user-initiated.
Definition web.hh:26
BrowserWindow * bw
The requesting browser window [reference].
Definition web.hh:28
void a_Timeout_add(float t, TimeoutCb_t cb, void *cbdata)
Hook a one-time timeout function 'cb' after 't' seconds with 'cbdata" as its data.
Definition timeout.cc:25
void a_Timeout_remove()
Stop running a timeout function.
Definition timeout.cc:41
void a_UIcmd_set_msg(BrowserWindow *bw, const char *format,...)
Definition uicmd.cc:1591
void a_UIcmd_set_page_prog(BrowserWindow *bw, size_t nbytes, int cmd)
Definition uicmd.cc:1538
void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url, char *filename)
Definition uicmd.cc:1261
void a_Url_set_flags(DilloUrl *u, int flags)
Set DilloUrl flags.
Definition url.c:527
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.
Definition url.c:506
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
Definition url.c:208
bool_t a_Url_same_organization(const DilloUrl *u1, const DilloUrl *u2)
Definition url.c:798
DilloUrl * a_Url_new(const char *url_str, const char *base_url)
Transform (and resolve) an URL string into the respective DilloURL.
Definition url.c:371
int a_Url_host_type(const char *host)
What type of host is this?
Definition url.c:683
DilloUrl * a_Url_dup(const DilloUrl *ori)
Duplicate a Url structure.
Definition url.c:477
#define URL_HOST_NAME
Definition url.h:24
#define URL_E2EQuery
Definition url.h:35
#define URL_SpamSafe
Definition url.h:40
#define URL_FLAGS(u)
Definition url.h:79
#define URL_STR(u)
Definition url.h:76
#define URL_STR_(u)
Definition url.h:55
#define URL_SCHEME(u)
Definition url.h:70
#define URL_Post
Definition url.h:33
#define URL_Get
Definition url.h:32
#define URL_HOST(u)
Definition url.h:75
int a_Web_dispatch_by_type(const char *Type, DilloWeb *Web, CA_Callback_t *Call, void **Data)
Given the MIME content type, and a fd to read it from, this function connects the proper MIME viewer ...
Definition web.cc:50
void a_Web_free(DilloWeb *web)
Deallocate a DilloWeb structure.
Definition web.cc:152
#define WEB_RootUrl
Definition web.hh:16
#define WEB_Download
Definition web.hh:19