Rev 4821 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4821 | Rev 5043 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | #include "utils/utils.h" |
35 | #include "utils/utils.h" |
Line 36... | Line 36... | ||
36 | 36 | ||
37 | /** Define to enable tracing of llcache operations. */ |
37 | /** Define to enable tracing of llcache operations. */ |
Line -... | Line 38... | ||
- | 38 | #undef LLCACHE_TRACE |
|
- | 39 | ||
- | 40 | #ifdef DBG |
|
- | 41 | #undef DBG |
|
- | 42 | #endif |
|
- | 43 | //#define DBG(s) __menuet__debug_out(s) /* For the debug messages in BOARD */ |
|
- | 44 | #define DBG(s) LOG((s)) /* So that we see debug in Netsurf's LOG files */ |
|
38 | #undef LLCACHE_TRACE |
45 | |
39 | 46 | ||
40 | /** State of a low-level cache object fetch */ |
47 | /** State of a low-level cache object fetch */ |
41 | typedef enum { |
48 | typedef enum { |
42 | LLCACHE_FETCH_INIT, /**< Initial state, before fetch */ |
49 | LLCACHE_FETCH_INIT, /**< Initial state, before fetch */ |
Line 484... | Line 491... | ||
484 | /* Parse cache headers to populate cache control data */ |
491 | /* Parse cache headers to populate cache control data */ |
485 | #define SKIP_ST(p) while (*p != '\0' && (*p == ' ' || *p == '\t')) p++ |
492 | #define SKIP_ST(p) while (*p != '\0' && (*p == ' ' || *p == '\t')) p++ |
Line 486... | Line 493... | ||
486 | 493 | ||
487 | if (5 < len && strcasecmp(*name, "Date") == 0) { |
494 | if (5 < len && strcasecmp(*name, "Date") == 0) { |
488 | /* extract Date header */ |
495 | /* extract Date header */ |
- | 496 | /* TODO: object->cache.date = curl_getdate(*value, NULL); */ |
|
- | 497 | object->cache.date = (time_t) 12341234; |
|
489 | object->cache.date = curl_getdate(*value, NULL); |
498 | |
490 | } else if (4 < len && strcasecmp(*name, "Age") == 0) { |
499 | } else if (4 < len && strcasecmp(*name, "Age") == 0) { |
491 | /* extract Age header */ |
500 | /* extract Age header */ |
492 | if ('0' <= **value && **value <= '9') |
501 | if ('0' <= **value && **value <= '9') |
493 | object->cache.age = atoi(*value); |
502 | object->cache.age = atoi(*value); |
494 | } else if (8 < len && strcasecmp(*name, "Expires") == 0) { |
503 | } else if (8 < len && strcasecmp(*name, "Expires") == 0) { |
495 | /* extract Expires header */ |
504 | /* extract Expires header */ |
- | 505 | /* TODO: object->cache.expires = curl_getdate(*value, NULL); */ |
|
496 | object->cache.expires = curl_getdate(*value, NULL); |
506 | object->cache.expires = (time_t) 123412399; |
497 | } else if (14 < len && strcasecmp(*name, "Cache-Control") == 0) { |
507 | } else if (14 < len && strcasecmp(*name, "Cache-Control") == 0) { |
498 | /* extract and parse Cache-Control header */ |
508 | /* extract and parse Cache-Control header */ |
499 | const char *start = *value; |
509 | const char *start = *value; |
Line 541... | Line 551... | ||
541 | object->cache.etag = strdup(*value); |
551 | object->cache.etag = strdup(*value); |
542 | if (object->cache.etag == NULL) |
552 | if (object->cache.etag == NULL) |
543 | return NSERROR_NOMEM; |
553 | return NSERROR_NOMEM; |
544 | } else if (14 < len && strcasecmp(*name, "Last-Modified") == 0) { |
554 | } else if (14 < len && strcasecmp(*name, "Last-Modified") == 0) { |
545 | /* extract Last-Modified header */ |
555 | /* extract Last-Modified header */ |
546 | object->cache.last_modified = curl_getdate(*value, NULL); |
556 | /* TODO object->cache.last_modified = curl_getdate(*value, NULL); */ |
- | 557 | object->cache.last_modified = (time_t) 12341230; |
|
547 | } |
558 | } |
Line 548... | Line 559... | ||
548 | 559 | ||
Line 549... | Line 560... | ||
549 | #undef SKIP_ST |
560 | #undef SKIP_ST |
Line 1621... | Line 1632... | ||
1621 | static void llcache_fetch_callback(const fetch_msg *msg, void *p) |
1632 | static void llcache_fetch_callback(const fetch_msg *msg, void *p) |
1622 | { |
1633 | { |
1623 | nserror error = NSERROR_OK; |
1634 | nserror error = NSERROR_OK; |
1624 | llcache_object *object = p; |
1635 | llcache_object *object = p; |
1625 | llcache_event event; |
1636 | llcache_event event; |
1626 | __menuet__debug_out("Inside llcache_fetch_callback\n"); |
1637 | /* DBG("Inside llcache_fetch_callback\n"); */ |
Line 1627... | Line 1638... | ||
1627 | 1638 | ||
1628 | #ifdef LLCACHE_TRACE |
1639 | #ifdef LLCACHE_TRACE |
1629 | LOG(("Fetch event %d for %p", msg->type, object)); |
1640 | LOG(("Fetch event %d for %p", msg->type, object)); |
- | 1641 | #endif |
|
- | 1642 | if(!msg) |
|
Line 1630... | Line 1643... | ||
1630 | #endif |
1643 | LOG(("msg is NULL in llcache_fetch_callback\n")); |
1631 | 1644 | ||
- | 1645 | switch (msg->type) { |
|
1632 | switch (msg->type) { |
1646 | case FETCH_HEADER: |
1633 | case FETCH_HEADER: |
1647 | /* DBG("FETCH_HEADER in llcache\n"); */ |
Line 1634... | Line 1648... | ||
1634 | /* Received a fetch header */ |
1648 | /* Received a fetch header */ |
1635 | object->fetch.state = LLCACHE_FETCH_HEADERS; |
1649 | object->fetch.state = LLCACHE_FETCH_HEADERS; |
Line 1640... | Line 1654... | ||
1640 | break; |
1654 | break; |
Line 1641... | Line 1655... | ||
1641 | 1655 | ||
1642 | /* 3xx responses */ |
1656 | /* 3xx responses */ |
1643 | case FETCH_REDIRECT: |
1657 | case FETCH_REDIRECT: |
1644 | /* Request resulted in a redirect */ |
- | |
- | 1658 | /* Request resulted in a redirect */ |
|
1645 | 1659 | /* DBG("FETCH_REDIRECT in llcache\n"); */ |
|
1646 | /* Release candidate, if any */ |
1660 | /* Release candidate, if any */ |
1647 | if (object->candidate != NULL) { |
1661 | if (object->candidate != NULL) { |
1648 | object->candidate->candidate_count--; |
1662 | object->candidate->candidate_count--; |
1649 | object->candidate = NULL; |
1663 | object->candidate = NULL; |
Line 1652... | Line 1666... | ||
1652 | error = llcache_fetch_redirect(object, |
1666 | error = llcache_fetch_redirect(object, |
1653 | msg->data.redirect, &object); |
1667 | msg->data.redirect, &object); |
1654 | break; |
1668 | break; |
1655 | case FETCH_NOTMODIFIED: |
1669 | case FETCH_NOTMODIFIED: |
1656 | /* Conditional request determined that cached object is fresh */ |
1670 | /* Conditional request determined that cached object is fresh */ |
- | 1671 | /* DBG("FETCH_NOTMODIFIED in llcache\n"); */ |
|
1657 | error = llcache_fetch_notmodified(object, &object); |
1672 | error = llcache_fetch_notmodified(object, &object); |
1658 | break; |
1673 | break; |
Line 1659... | Line 1674... | ||
1659 | 1674 | ||
1660 | /* Normal 2xx state machine */ |
1675 | /* Normal 2xx state machine */ |
- | 1676 | case FETCH_DATA: |
|
1661 | case FETCH_DATA: |
1677 | /* DBG("FETCH_DATA in llcache\n"); */ |
1662 | /* Received some data */ |
1678 | /* Received some data */ |
1663 | if (object->fetch.state != LLCACHE_FETCH_DATA) { |
1679 | if (object->fetch.state != LLCACHE_FETCH_DATA) { |
1664 | /* On entry into this state, check if we need to |
1680 | /* On entry into this state, check if we need to |
1665 | * invalidate the cache control data. We are guaranteed |
1681 | * invalidate the cache control data. We are guaranteed |
Line 1699... | Line 1715... | ||
1699 | case FETCH_FINISHED: |
1715 | case FETCH_FINISHED: |
1700 | /* Finished fetching */ |
1716 | /* Finished fetching */ |
1701 | { |
1717 | { |
1702 | uint8_t *temp; |
1718 | uint8_t *temp; |
Line -... | Line 1719... | ||
- | 1719 | ||
1703 | 1720 | /* DBG("FETCH_FINISHED in llcache\n"); */ |
|
1704 | object->fetch.state = LLCACHE_FETCH_COMPLETE; |
1721 | object->fetch.state = LLCACHE_FETCH_COMPLETE; |
Line 1705... | Line 1722... | ||
1705 | object->fetch.fetch = NULL; |
1722 | object->fetch.fetch = NULL; |
1706 | 1723 | ||
Line 1719... | Line 1736... | ||
1719 | 1736 | ||
1720 | /* Out-of-band information */ |
1737 | /* Out-of-band information */ |
1721 | case FETCH_ERROR: |
1738 | case FETCH_ERROR: |
1722 | /* An error occurred while fetching */ |
1739 | /* An error occurred while fetching */ |
- | 1740 | /* The fetch has has already been cleaned up by the fetcher */ |
|
1723 | /* The fetch has has already been cleaned up by the fetcher */ |
1741 | /* DBG("FETCH_ERROR in llcache\n"); */ |
1724 | object->fetch.state = LLCACHE_FETCH_COMPLETE; |
1742 | object->fetch.state = LLCACHE_FETCH_COMPLETE; |
Line 1725... | Line 1743... | ||
1725 | object->fetch.fetch = NULL; |
1743 | object->fetch.fetch = NULL; |
1726 | 1744 | ||
Line 1740... | Line 1758... | ||
1740 | 1758 | ||
Line 1741... | Line 1759... | ||
1741 | error = llcache_send_event_to_users(object, &event); |
1759 | error = llcache_send_event_to_users(object, &event); |
1742 | 1760 | ||
- | 1761 | break; |
|
1743 | break; |
1762 | case FETCH_PROGRESS: |
1744 | case FETCH_PROGRESS: |
1763 | /* DBG("FETCH_PROGRESS in llcache\n"); */ |
1745 | /* Progress update */ |
1764 | /* Progress update */ |
Line 1746... | Line 1765... | ||
1746 | event.type = LLCACHE_EVENT_PROGRESS; |
1765 | event.type = LLCACHE_EVENT_PROGRESS; |
Line 1747... | Line 1766... | ||
1747 | event.data.msg = msg->data.progress; |
1766 | event.data.msg = msg->data.progress; |
Line 1748... | Line 1767... | ||
1748 | 1767 | ||
1749 | error = llcache_send_event_to_users(object, &event); |
1768 | error = llcache_send_event_to_users(object, &event); |
- | 1769 | ||
1750 | 1770 | break; |
|
Line 1751... | Line 1771... | ||
1751 | break; |
1771 | |
1752 | 1772 | /* Events requiring action */ |
|
1753 | /* Events requiring action */ |
1773 | case FETCH_AUTH: |
Line 1762... | Line 1782... | ||
1762 | 1782 | ||
1763 | error = llcache_fetch_auth(object, msg->data.auth.realm); |
1783 | error = llcache_fetch_auth(object, msg->data.auth.realm); |
1764 | break; |
1784 | break; |
1765 | case FETCH_CERT_ERR: |
1785 | case FETCH_CERT_ERR: |
1766 | /* Something went wrong when validating TLS certificates */ |
- | |
- | 1786 | /* Something went wrong when validating TLS certificates */ |
|
1767 | 1787 | /* DBG("FETCH_CERT_ERR\n"); */ |
|
1768 | /* Release candidate, if any */ |
1788 | /* Release candidate, if any */ |
1769 | if (object->candidate != NULL) { |
1789 | if (object->candidate != NULL) { |
1770 | object->candidate->candidate_count--; |
1790 | object->candidate->candidate_count--; |
1771 | object->candidate = NULL; |
1791 | object->candidate = NULL; |
Line 1775... | Line 1795... | ||
1775 | msg->data.cert_err.certs, |
1795 | msg->data.cert_err.certs, |
1776 | msg->data.cert_err.num_certs); |
1796 | msg->data.cert_err.num_certs); |
1777 | break; |
1797 | break; |
1778 | case FETCH_SSL_ERR: |
1798 | case FETCH_SSL_ERR: |
1779 | /* TLS connection setup failed */ |
1799 | /* TLS connection setup failed */ |
1780 | - | ||
- | 1800 | /* DBG("FETCH_SSL_ERR\n"); */ |
|
1781 | /* Release candidate, if any */ |
1801 | /* Release candidate, if any */ |
1782 | if (object->candidate != NULL) { |
1802 | if (object->candidate != NULL) { |
1783 | object->candidate->candidate_count--; |
1803 | object->candidate->candidate_count--; |
1784 | object->candidate = NULL; |
1804 | object->candidate = NULL; |
1785 | } |
1805 | } |
Line 1788... | Line 1808... | ||
1788 | break; |
1808 | break; |
1789 | } |
1809 | } |
Line 1790... | Line 1810... | ||
1790 | 1810 | ||
1791 | /* Deal with any errors reported by event handlers */ |
1811 | /* Deal with any errors reported by event handlers */ |
- | 1812 | if (error != NSERROR_OK) { |
|
1792 | if (error != NSERROR_OK) { |
1813 | /* DBG("Error is not NSERROR_OK!\n"); */ |
1793 | if (object->fetch.fetch != NULL) { |
1814 | if (object->fetch.fetch != NULL) { |
1794 | fetch_abort(object->fetch.fetch); |
1815 | fetch_abort(object->fetch.fetch); |
Line 1795... | Line 1816... | ||
1795 | object->fetch.fetch = NULL; |
1816 | object->fetch.fetch = NULL; |
1796 | 1817 | ||
Line 1797... | Line 1818... | ||
1797 | /* Invalidate cache control data */ |
1818 | /* Invalidate cache control data */ |
1798 | llcache_invalidate_cache_control_data(object); |
1819 | llcache_invalidate_cache_control_data(object); |
1799 | 1820 | ||
1800 | object->fetch.state = LLCACHE_FETCH_COMPLETE; |
1821 | object->fetch.state = LLCACHE_FETCH_COMPLETE; |
1801 | } |
1822 | } |
1802 | __menuet__debug_out("Returning from llcache_fetch_callback. (err != NS_OK)\n"); |
1823 | /* DBG("Returning llc_f_cb. (err != NS_OK)\n"); */ |
1803 | return; |
1824 | return; |
Line 1804... | Line 1825... | ||
1804 | } |
1825 | } |
1805 | __menuet__debug_out("Returning from llcache_fetch_callback.(err = NS_OK)\n"); |
1826 | /* DBG("Returning from llc_f_cb.(err = NS_OK)\n"); */ |
1806 | } |
1827 | } |
Line 2350... | Line 2371... | ||
2350 | 2371 | ||
2351 | /* See llcache.h for documentation */ |
2372 | /* See llcache.h for documentation */ |
2352 | nserror llcache_poll(void) |
2373 | nserror llcache_poll(void) |
2353 | { |
2374 | { |
2354 | llcache_object *object; |
- | |
2355 | 2375 | llcache_object *object; |
|
Line 2356... | Line 2376... | ||
2356 | fetch_poll(); |
2376 | fetch_poll(); |
2357 | 2377 | ||
2358 | /* Catch new users up with state of objects */ |
2378 | /* Catch new users up with state of objects */ |