diff options
author | jcid <devnull@localhost> | 2008-03-26 15:46:46 +0100 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-03-26 15:46:46 +0100 |
commit | 072933308a1128555e6e56f519fdc9603d060d0f (patch) | |
tree | 2dddc7686d2209ad5392691dfcd362f494178735 /src/cache.c | |
parent | 5763bad3e2a95553ed799e73ffd640dfaf441ac0 (diff) |
- Added a_Capi_get_flags(). It requests a cache entry's status as flags.
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/cache.c b/src/cache.c index 13a56127..185c7846 100644 --- a/src/cache.c +++ b/src/cache.c @@ -209,7 +209,7 @@ static void Cache_entry_init(CacheEntry_t *NewEntry, const DilloUrl *Url) NewEntry->ContentDecoder = NULL; NewEntry->ExpectedSize = 0; NewEntry->TransferSize = 0; - NewEntry->Flags = 0; + NewEntry->Flags = CA_IsEmpty; } /* @@ -222,6 +222,30 @@ static CacheEntry_t *Cache_entry_search(const DilloUrl *Url) } /* + * Given a URL, find its cache entry, following redirections. + */ +static CacheEntry_t *Cache_entry_search_with_redirect(const DilloUrl *Url) +{ + int i; + CacheEntry_t *entry; + + for (i = 0; (entry = Cache_entry_search(Url)); ++i) { + + /* Test for a redirection loop */ + if (entry->Flags & CA_RedirectLoop || i == 3) { + _MSG_WARN("Redirect loop for URL: >%s<\n", URL_STR_(Url)); + break; + } + /* Test for a working redirection */ + if (entry && entry->Flags & CA_Redirect && entry->Location) { + Url = entry->Location; + } else + break; + } + return entry; +} + +/* * Allocate and set a new entry in the cache list */ static CacheEntry_t *Cache_entry_add(const DilloUrl *Url) @@ -250,6 +274,8 @@ void a_Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds) if (!(entry = Cache_entry_search(Url))) entry = Cache_entry_add(Url); entry->Flags |= CA_GotData + CA_GotHeader + CA_GotLength + CA_InternalUrl; + if (data_ds->len) + entry->Flags &= ~CA_IsEmpty; dStr_truncate(entry->Data, 0); dStr_append_l(entry->Data, data_ds->str, data_ds->len); dStr_fit(entry->Data); @@ -355,28 +381,21 @@ int a_Cache_open_url(void *web, CA_Callback_t Call, void *CbData) } /* + * Get cache entry status + */ +uint_t a_Cache_get_flags(const DilloUrl *url) +{ + CacheEntry_t *entry = Cache_entry_search_with_redirect(url); + return (entry ? entry->Flags : 0); +} + +/* * Get the pointer to the URL document, and its size, from the cache entry. * Return: 1 cached, 0 not cached. */ int a_Cache_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize) { - int i; - CacheEntry_t *entry; - - for (i = 0; (entry = Cache_entry_search(Url)); ++i) { - - /* Test for a redirection loop */ - if (entry->Flags & CA_RedirectLoop || i == 3) { - _MSG_WARN("Redirect loop for URL: >%s<\n", URL_STR_(Url)); - break; - } - /* Test for a working redirection */ - if (entry && entry->Flags & CA_Redirect && entry->Location) { - Url = entry->Location; - } else - break; - } - + CacheEntry_t *entry = Cache_entry_search_with_redirect(Url); *BufSize = (entry) ? entry->Data->len : 0; *PBuf = (entry) ? entry->Data->str : NULL; return (entry ? 1 : 0); @@ -686,6 +705,8 @@ void a_Cache_process_dbuf(int Op, const char *buf, size_t buf_size, } dStr_append_l(entry->Data, dbuf->str, dbuf->len); + if (entry->Data->len) + entry->Flags &= ~CA_IsEmpty; dStr_free(dbuf, 1); Cache_process_queue(entry); |