diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/IO/Makefile.am | 1 | ||||
-rw-r--r-- | src/IO/dpi.c | 21 | ||||
-rw-r--r-- | src/cache.c | 11 | ||||
-rw-r--r-- | src/cookies.c | 42 | ||||
-rw-r--r-- | src/cookies.h | 3 | ||||
-rw-r--r-- | src/css.cc | 8 | ||||
-rw-r--r-- | src/doctree.hh | 48 | ||||
-rw-r--r-- | src/styleengine.cc | 61 | ||||
-rw-r--r-- | src/styleengine.hh | 20 |
9 files changed, 121 insertions, 94 deletions
diff --git a/src/IO/Makefile.am b/src/IO/Makefile.am index 98d8d43a..b168073c 100644 --- a/src/IO/Makefile.am +++ b/src/IO/Makefile.am @@ -1,3 +1,4 @@ +AM_CPPFLAGS=-DDILLO_BINDIR='"$(bindir)/"' AM_CFLAGS = @LIBFLTK_CFLAGS@ AM_CXXFLAGS = @LIBFLTK_CXXFLAGS@ diff --git a/src/IO/dpi.c b/src/IO/dpi.c index 6491ea27..6f46b2ba 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -30,6 +30,7 @@ #include <sys/socket.h> #include <sys/un.h> #include <netinet/in.h> +#include <netinet/tcp.h> #include <arpa/inet.h> #include <netdb.h> @@ -364,13 +365,17 @@ static int Dpi_start_dpid(void) Dpi_close_fd(st_pipe[0]); if (execl(path1, "dpid", (char*)NULL) == -1) { dFree(path1); - if (execlp("dpid", "dpid", (char*)NULL) == -1) { - MSG("Dpi_start_dpid (child): %s\n", dStrerror(errno)); - if (Dpi_blocking_write(st_pipe[1], "ERROR", 5) == -1) { - MSG("Dpi_start_dpid (child): can't write to pipe.\n"); + path1 = dStrconcat(DILLO_BINDIR, "dpid", NULL); + if (execl(path1, "dpid", (char*)NULL) == -1) { + dFree(path1); + if (execlp("dpid", "dpid", (char*)NULL) == -1) { + MSG("Dpi_start_dpid (child): %s\n", dStrerror(errno)); + if (Dpi_blocking_write(st_pipe[1], "ERROR", 5) == -1) { + MSG("Dpi_start_dpid (child): can't write to pipe.\n"); + } + Dpi_close_fd(st_pipe[1]); + _exit (EXIT_FAILURE); } - Dpi_close_fd(st_pipe[1]); - _exit (EXIT_FAILURE); } } } else if (pid < 0) { @@ -430,9 +435,11 @@ static int Dpi_read_comm_keys(int *port) */ static int Dpi_make_socket_fd() { - int fd, ret = -1; + int fd, one = 1, ret = -1; if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) { + /* avoid delays when sending small pieces of data */ + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); ret = fd; } return ret; diff --git a/src/cache.c b/src/cache.c index 3341388c..6df062b3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -728,15 +728,14 @@ static void Cache_parse_header(CacheEntry_t *entry) dFree(encoding); /* free Transfer-Encoding */ #ifndef DISABLE_COOKIES - /* BUG: If a server feels like mixing Set-Cookie2 and Set-Cookie - * responses which aren't identical, then we have a problem. I don't - * know if that is a real issue though. */ - if ((Cookies = Cache_parse_multiple_fields(header, "Set-Cookie2")) || - (Cookies = Cache_parse_multiple_fields(header, "Set-Cookie"))) { - a_Cookies_set(Cookies, entry->Url); + if ((Cookies = Cache_parse_multiple_fields(header, "Set-Cookie"))) { + char *server_date = Cache_parse_field(header, "Date"); + + a_Cookies_set(Cookies, entry->Url, server_date); for (i = 0; (data = dList_nth_data(Cookies, i)); ++i) dFree(data); dList_free(Cookies); + dFree(server_date); } #endif /* !DISABLE_COOKIES */ diff --git a/src/cookies.c b/src/cookies.c index a25138cd..ea386be5 100644 --- a/src/cookies.c +++ b/src/cookies.c @@ -10,10 +10,9 @@ * (at your option) any later version. */ -/* Handling of cookies takes place here. - * This implementation aims to follow RFC 2965: - * http://www.ietf.org/rfc/rfc2965.txt - */ +/* Handling of cookies takes place here. */ + +#include "msg.h" #ifdef DISABLE_COOKIES @@ -37,7 +36,6 @@ void a_Cookies_init(void) #include <ctype.h> #include <errno.h> -#include "msg.h" #include "IO/Url.h" #include "list.h" #include "cookies.h" @@ -138,10 +136,11 @@ void a_Cookies_freeall() /* * Set the value corresponding to the cookie string */ -void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url) +void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url, + const char *date) { CookieControlAction action; - char *cmd, *cookie_string, *dpip_tag, numstr[16]; + char *cmd, *cookie_string, *dpip_tag; const char *path; int i; @@ -156,10 +155,14 @@ void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url) for (i = 0; (cookie_string = dList_nth_data(cookie_strings, i)); ++i) { path = URL_PATH_(set_url); - snprintf(numstr, 16, "%d", URL_PORT(set_url)); - cmd = a_Dpip_build_cmd("cmd=%s cookie=%s host=%s path=%s port=%s", - "set_cookie", cookie_string, URL_HOST_(set_url), - path ? path : "/", numstr); + if (date) + cmd = a_Dpip_build_cmd("cmd=%s cookie=%s host=%s path=%s date=%s", + "set_cookie", cookie_string, + URL_HOST_(set_url), path ? path : "/", date); + else + cmd = a_Dpip_build_cmd("cmd=%s cookie=%s host=%s path=%s", + "set_cookie", cookie_string, + URL_HOST_(set_url), path ? path : "/"); _MSG("Cookies.c: a_Cookies_set \n\t \"%s\" \n",cmd ); /* This call is commented because it doesn't guarantee the order @@ -178,7 +181,7 @@ void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url) */ char *a_Cookies_get_query(const DilloUrl *request_url) { - char *cmd, *dpip_tag, *query, numstr[16]; + char *cmd, *dpip_tag, *query; const char *path; CookieControlAction action; @@ -192,10 +195,9 @@ char *a_Cookies_get_query(const DilloUrl *request_url) } path = URL_PATH_(request_url); - snprintf(numstr, 16, "%d", URL_PORT(request_url)); - cmd = a_Dpip_build_cmd("cmd=%s scheme=%s host=%s path=%s port=%s", + cmd = a_Dpip_build_cmd("cmd=%s scheme=%s host=%s path=%s", "get_cookie", URL_SCHEME(request_url), - URL_HOST(request_url), path ? path : "/", numstr); + URL_HOST(request_url), path ? path : "/"); /* Get the answer from cookies.dpi */ _MSG("cookies.c: a_Dpi_send_blocking_cmd cmd = {%s}\n", cmd); @@ -203,15 +205,11 @@ char *a_Cookies_get_query(const DilloUrl *request_url) _MSG("cookies.c: after a_Dpi_send_blocking_cmd resp={%s}\n", dpip_tag); dFree(cmd); - query = dStrdup("Cookie2: $Version=\"1\"\r\n"); - if (dpip_tag != NULL) { - char *cookie = a_Dpip_get_attr(dpip_tag, "cookie"); - char *old_query = query; - query = dStrconcat(old_query, cookie, NULL); - dFree(old_query); + query = a_Dpip_get_attr(dpip_tag, "cookie"); dFree(dpip_tag); - dFree(cookie); + } else { + query = dStrdup(""); } return query; } diff --git a/src/cookies.h b/src/cookies.h index 6f9f77e0..482aa5ae 100644 --- a/src/cookies.h +++ b/src/cookies.h @@ -12,7 +12,8 @@ extern "C" { # define a_Cookies_freeall() ; #else char *a_Cookies_get_query(const DilloUrl *request_url); - void a_Cookies_set(Dlist *cookie_string, const DilloUrl *set_url); + void a_Cookies_set(Dlist *cookie_string, const DilloUrl *set_url, + const char *server_date); void a_Cookies_init( void ); void a_Cookies_freeall( void ); #endif @@ -584,7 +584,13 @@ void CssContext::buildUserAgentStyle () { "td, th {border-style: inset; padding: 2px}" "thead, tbody, tfoot {vertical-align: middle}" "th {font-weight: bolder; text-align: center}" - "code, tt, pre, samp, kbd {font-family: monospace}"; + "code, tt, pre, samp, kbd {font-family: monospace}" + /* WORKAROUND: Reset font properties in tables as some + * some pages rely on it (e.g. gmail). + * http://developer.mozilla.org/En/Fixing_Table_Inheritance_in_Quirks_Mode + * has a detailed description of the issue. + */ + "table, caption {font-size: medium; font-weight: normal}"; CssParser::parse (NULL, NULL, this, cssBuf, strlen (cssBuf), CSS_ORIGIN_USER_AGENT); diff --git a/src/doctree.hh b/src/doctree.hh index 30762e44..ef7faa7c 100644 --- a/src/doctree.hh +++ b/src/doctree.hh @@ -5,12 +5,20 @@ class DoctreeNode { public: + DoctreeNode *parent; int num; // unique ascending id - int depth; int element; lout::misc::SimpleVector<char*> *klass; const char *pseudo; const char *id; + + DoctreeNode () { + parent = NULL; + klass = NULL; + pseudo = NULL; + id = NULL; + element = 0; + }; }; /** @@ -23,10 +31,42 @@ class DoctreeNode { * be extended to a real tree. */ class Doctree { + private: + DoctreeNode *topNode; + int num; + public: - virtual ~Doctree () {}; - virtual const DoctreeNode *top () = 0; - virtual const DoctreeNode *parent (const DoctreeNode *node) = 0; + Doctree () { + topNode = NULL; + num = 0; + }; + ~Doctree () { while (top ()) pop (); }; + DoctreeNode *push () { + DoctreeNode *dn = new DoctreeNode (); + dn->parent = topNode; + dn->num = num++; + topNode = dn; + return dn; + }; + void pop () { + DoctreeNode *dn = topNode; + if (dn) { + dFree ((void*) dn->id); + if (dn->klass) { + for (int i = 0; i < dn->klass->size (); i++) + dFree (dn->klass->get(i)); + delete dn->klass; + } + topNode = dn->parent; + delete dn; + } + }; + inline DoctreeNode *top () { + return topNode; + }; + inline DoctreeNode *parent (const DoctreeNode *node) { + return node->parent; + }; }; #endif diff --git a/src/styleengine.cc b/src/styleengine.cc index 1ca57054..f0f70bf6 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -21,14 +21,14 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) { StyleAttrs style_attrs; FontAttrs font_attrs; + doctree = new Doctree (); stack = new lout::misc::SimpleVector <Node> (1); cssContext = new CssContext (); this->layout = layout; - num = 0; importDepth = 0; stack->increase (); - Node *n = stack->getRef (stack->size () - 1); + Node *n = stack->getRef (stack->size () - 1); /* Create a dummy font, attribute, and tag for the bottom of the stack. */ font_attrs.name = prefs.font_sans_serif; @@ -46,21 +46,17 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) { style_attrs.color = Color::create (layout, 0); style_attrs.backgroundColor = Color::create (layout, 0xffffff); - n->num = num++; n->style = Style::create (layout, &style_attrs); n->wordStyle = NULL; - n->element = 0; - n->id = NULL; - n->klass = NULL; - n->pseudo = NULL; n->styleAttribute = NULL; n->inheritBackgroundColor = false; } StyleEngine::~StyleEngine () { - while (stack->size () > 0) - endElement (stack->getRef (stack->size () - 1)->element); + while (doctree->top ()) + endElement (doctree->top ()->element); delete stack; + delete doctree; delete cssContext; } @@ -72,17 +68,14 @@ void StyleEngine::startElement (int element) { style0 (); stack->increase (); - Node *n = stack->getRef (stack->size () - 1); - n->num = num++; + Node *n = stack->getRef (stack->size () - 1); n->style = NULL; n->wordStyle = NULL; - n->depth = stack->size () - 1; - n->element = element; - n->id = NULL; - n->klass = NULL; - n->pseudo = NULL; n->styleAttribute = NULL; n->inheritBackgroundColor = false; + + DoctreeNode *dn = doctree->push (); + dn->element = element; } void StyleEngine::startElement (const char *tagname) { @@ -90,9 +83,9 @@ void StyleEngine::startElement (const char *tagname) { } void StyleEngine::setId (const char *id) { - Node *n = stack->getRef (stack->size () - 1); - assert (n->id == NULL); - n->id = dStrdup (id); + DoctreeNode *dn = doctree->top (); + assert (dn->id == NULL); + dn->id = dStrdup (id); }; /** @@ -121,13 +114,13 @@ static lout::misc::SimpleVector<char *> *splitStr (const char *str, char sep) { } void StyleEngine::setClass (const char *klass) { - Node *n = stack->getRef (stack->size () - 1); - assert (n->klass == NULL); - n->klass = splitStr (klass, ' '); + DoctreeNode *dn = doctree->top (); + assert (dn->klass == NULL); + dn->klass = splitStr (klass, ' '); }; void StyleEngine::setStyle (const char *style) { - Node *n = stack->getRef (stack->size () - 1); + Node *n = stack->getRef (stack->size () - 1); assert (n->styleAttribute == NULL); n->styleAttribute = dStrdup (style); }; @@ -156,16 +149,16 @@ void StyleEngine::inheritBackgroundColor () { * \brief set the CSS pseudo class :link. */ void StyleEngine::setPseudoLink () { - Node *n = stack->getRef (stack->size () - 1); - n->pseudo = "link"; + DoctreeNode *dn = doctree->top (); + dn->pseudo = "link"; } /** * \brief set the CSS pseudo class :visited. */ void StyleEngine::setPseudoVisited () { - Node *n = stack->getRef (stack->size () - 1); - n->pseudo = "visited"; + DoctreeNode *dn = doctree->top (); + dn->pseudo = "visited"; } /** @@ -173,24 +166,18 @@ void StyleEngine::setPseudoVisited () { */ void StyleEngine::endElement (int element) { assert (stack->size () > 0); - assert (element == stack->getRef (stack->size () - 1)->element); + assert (element == doctree->top ()->element); - Node *n = stack->getRef (stack->size () - 1); + Node *n = stack->getRef (stack->size () - 1); if (n->style) n->style->unref (); if (n->wordStyle) n->wordStyle->unref (); - if (n->id) - dFree ((void*) n->id); - if (n->klass) { - for (int i = 0; i < n->klass->size (); i++) - dFree (n->klass->get(i)); - delete n->klass; - } if (n->styleAttribute) dFree ((void*) n->styleAttribute); + doctree->pop (); stack->setSize (stack->size () - 1); } @@ -622,7 +609,7 @@ Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) { strlen (styleAttribute)); // merge style information - cssContext->apply (&props, this, styleAttributeProps, nonCssProperties); + cssContext->apply (&props, doctree, styleAttributeProps, nonCssProperties); // apply style apply (&attrs, &props); diff --git a/src/styleengine.hh b/src/styleengine.hh index 8b5dd1fd..66f28cee 100644 --- a/src/styleengine.hh +++ b/src/styleengine.hh @@ -17,9 +17,9 @@ class StyleEngine; * HTML elements and their attributes via the startElement() / endElement() * methods. */ -class StyleEngine : public Doctree { +class StyleEngine { private: - class Node : public DoctreeNode { + class Node { public: dw::core::style::Style *style; dw::core::style::Style *wordStyle; @@ -30,7 +30,7 @@ class StyleEngine : public Doctree { dw::core::Layout *layout; lout::misc::SimpleVector <Node> *stack; CssContext *cssContext; - int num; + Doctree *doctree; int importDepth; dw::core::style::Style *style0 (CssPropertyList *nonCssHints = NULL); @@ -49,24 +49,12 @@ class StyleEngine : public Doctree { StyleEngine (dw::core::Layout *layout); ~StyleEngine (); - /* Doctree interface */ - inline const DoctreeNode *top () { - return stack->getRef (stack->size () - 1); - }; - - inline const DoctreeNode *parent (const DoctreeNode *n) { - if (n->depth > 1) - return stack->getRef (n->depth - 1); - else - return NULL; - }; - void parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen, CssOrigin origin); void startElement (int tag); void startElement (const char *tagname); void setId (const char *id); - const char * getId () { return top ()->id; }; + const char * getId () { return doctree->top ()->id; }; void setClass (const char *klass); void setStyle (const char *style); void endElement (int tag); |