changeset 138:a44a6214d4ac

- Added support for "charset" in the META element.
author jcid
date Thu, 13 Mar 2008 14:52:27 +0100
parents 2874325fb2a8
children de9404ce0668
files ChangeLog src/IO/http.c src/html.cc src/nav.c src/nav.h
diffstat 5 files changed, 68 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 12 20:19:42 2008 +0100
+++ b/ChangeLog	Thu Mar 13 14:52:27 2008 +0100
@@ -75,7 +75,6 @@
  - Added a MSG_HTTP for HTTP/1.1's warning headers.
  - Added support for multi-line header fields.
  - Added support for "charset" in the HTTP header field for Content-Type.
- - Added partial support for "charset" in the META element.
  - Added support for progressive display of progressive jpegs.
  - Fixed progressive display of interlaced pngs.
  - Enabled colspan=0 in tables parsing.
@@ -91,6 +90,7 @@
  - Implemented "Load Images" in the page menu and cleaned up html.hh.
  - Added shortcuts: PgDn=Spc, PgUp=b, Back=BackSpace, Forw=Shift+Backspace.
  - Made a cleanup in cache's parse header code.
+ - Added support for "charset" in the META element.
    Patch: place, Jorge Arellano Cid
 +- Fixed a va_list-related SEGFAULT on 64bit-arch in dStr_vsprintfa().
    Added const declarations in html parser.
--- a/src/IO/http.c	Wed Mar 12 20:19:42 2008 +0100
+++ b/src/IO/http.c	Thu Mar 13 14:52:27 2008 +0100
@@ -417,6 +417,7 @@
 /*
  * Callback function for the DNS resolver.
  * Continue connecting the socket, or abort upon error condition.
+ * S->web is checked to assert the operation wasn't aborted while waiting.
  */
 void a_Http_dns_cb(int Status, Dlist *addr_list, void *data)
 {
@@ -425,7 +426,12 @@
 
    S = a_Klist_get_data(ValidSocks, SKey);
    if (S) {
-      if (Status == 0 && addr_list) {
+      if (!a_Web_valid(S->web)) {
+         a_Chain_fcb(OpAbort, S->Info, NULL, NULL);
+         dFree(S->Info);
+         Http_socket_free(SKey);
+
+      } else if (Status == 0 && addr_list) {
          /* Successful DNS answer; save the IP */
          S->addr_list = addr_list;
          /* start connecting the socket */
--- a/src/html.cc	Wed Mar 12 20:19:42 2008 +0100
+++ b/src/html.cc	Thu Mar 13 14:52:27 2008 +0100
@@ -404,6 +404,10 @@
 } TagInfo;
 extern const TagInfo Tags[];
 
+/* todo: implement this as an URL/charset pair in a DList.
+ * chances of this bare-bones implementation to fail are minimal though:
+ * two ROOT pages using meta-charset, parsing HEAD section at the same time */
+static char *meta_charset = NULL;
 
 /*-----------------------------------------------------------------------------
  *-----------------------------------------------------------------------------
@@ -792,8 +796,17 @@
    if (charset) {
       MSG("HTTP Content-Type gave charset as: %s\n", charset);
    }
-   decoder = a_Decode_charset_init(charset);
-   this->charset = dStrdup(charset);
+   if (meta_charset) {
+      MSG("META Content-Type gave charset as: %s\n", meta_charset);
+   }
+   if (meta_charset) {
+      decoder = a_Decode_charset_init(meta_charset);
+      this->charset = meta_charset;
+      meta_charset = NULL;
+   } else {
+      decoder = a_Decode_charset_init(charset);
+      this->charset = dStrdup(charset);
+   }
 
    CurrTagOfs = 0;
    OldTagOfs = 0;
@@ -3667,12 +3680,12 @@
             if (charset) {
                if (!html->charset || dStrcasecmp(charset, html->charset)) {
                   MSG("META Content-Type changes charset to: %s\n", charset);
-                  a_Decode_free(html->decoder);
-                  html->decoder = a_Decode_charset_init(charset);
+                  dFree(meta_charset);
+                  meta_charset = dStrdup(charset);
+                  a_Nav_repush(html->bw);
                }
-               dFree(html->charset);
-               html->charset = charset;
             }
+            dFree(charset);
          }
       }   
    }
--- a/src/nav.c	Wed Mar 12 20:19:42 2008 +0100
+++ b/src/nav.c	Thu Mar 13 14:52:27 2008 +0100
@@ -21,6 +21,7 @@
 #include "dialog.hh"
 #include "prefs.h"
 #include "capi.h"
+#include "timeout.hh"
 
 //#define DEBUG_LEVEL 3
 #include "debug.h"
@@ -192,7 +193,8 @@
    bool_t MustLoad;
    int x, y, idx, ClientKey;
    DilloWeb *Web;
-   bool_t ForceReload = (URL_FLAGS(url) & URL_E2EReload);
+   bool_t ForceReload = (URL_FLAGS(url) &
+                         (URL_E2EReload + URL_ReloadFromCache));
 
    MSG("Nav_open_url: new url='%s'\n", URL_STR_(url));
 
@@ -272,6 +274,8 @@
       url = bw->nav_expect_url;
       /* unset E2EReload before adding this url to history */
       a_Url_set_flags(url, URL_FLAGS(url) & ~URL_E2EReload);
+      /* unset ReloadFromCache before adding this url to history */
+      a_Url_set_flags(url, URL_FLAGS(url) & ~URL_ReloadFromCache);
       url_idx = a_History_add_url(url);
       Nav_stack_add(bw, url_idx, 0, 0);
       /* Scroll to the origin unless there's a fragment part */
@@ -317,6 +321,40 @@
 }
 
 /*
+ * This one does a_Nav_repush's job.
+ */
+static void Nav_repush(BrowserWindow *bw)
+{
+   DilloUrl *ReqURL;
+
+   a_Nav_cancel_expect(bw);
+   if (a_Nav_stack_size(bw)) {
+      ReqURL = a_Url_dup(a_History_get_url(NAV_TOP_UIDX(bw)));
+      /* Let's make reload be from Cache */
+      a_Url_set_flags(ReqURL, URL_FLAGS(ReqURL) | URL_ReloadFromCache);
+      Nav_open_url(bw, ReqURL, 0);
+      a_Url_free(ReqURL);
+   }
+}
+
+static void Nav_repush_callback(void *data)
+{
+   Nav_repush(data);
+   a_Timeout_remove();
+}
+
+/*
+ * Repush current URL: not an end-to-end reload but from cache.
+ * - Currently used to switch to a charset decoder given by the META element.
+ * - Delayed to let dillo finish the call flow into a known state.
+ */
+void a_Nav_repush(BrowserWindow *bw)
+{
+   dReturn_if_fail (bw != NULL);
+   a_Timeout_add(0.0, Nav_repush_callback, (void*)bw);
+}
+
+/*
  * Same as a_Nav_push() but in a new window.
  */
 void a_Nav_push_nw(BrowserWindow *bw, const DilloUrl *url)
@@ -378,11 +416,10 @@
  */
 static void Nav_reload(BrowserWindow *bw)
 {
-   DilloUrl *url, *ReqURL;
+   DilloUrl *ReqURL;
 
    a_Nav_cancel_expect(bw);
    if (a_Nav_stack_size(bw)) {
-      url = a_History_get_url(NAV_TOP_UIDX(bw));
       ReqURL = a_Url_dup(a_History_get_url(NAV_TOP_UIDX(bw)));
       /* Let's make reload be end-to-end */
       a_Url_set_flags(ReqURL, URL_FLAGS(ReqURL) | URL_E2EReload);
--- a/src/nav.h	Wed Mar 12 20:19:42 2008 +0100
+++ b/src/nav.h	Thu Mar 13 14:52:27 2008 +0100
@@ -16,6 +16,7 @@
 void a_Nav_push(BrowserWindow *bw, const DilloUrl *url);
 void a_Nav_push_nw(BrowserWindow *bw, const DilloUrl *url);
 void a_Nav_vpush(void *vbw, const DilloUrl *url);
+void a_Nav_repush(BrowserWindow *bw);
 void a_Nav_back(BrowserWindow *bw);
 void a_Nav_forw(BrowserWindow *bw);
 void a_Nav_home(BrowserWindow *bw);