changeset 174:67e98a1211f0

- Fixed a cookies-related dillo freeze bug happening at: http://www.fltk.org/newsgroups.php?gfltk.general+v:24912
author jcid
date Fri, 11 Apr 2008 21:45:14 +0200
parents e6c3455abb1c
children 873266a14661
files ChangeLog dpi/cookies.c src/IO/http.c src/cookies.c
diffstat 4 files changed, 30 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 11 15:12:06 2008 +0200
+++ b/ChangeLog	Fri Apr 11 21:45:14 2008 +0200
@@ -102,6 +102,9 @@
  - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
  - Switched URL_DATA type from char* to a dStr.
    Patch: place, Jorge Arellano Cid
++- Fixed a cookies-related dillo freeze bug happening at:
+     http://www.fltk.org/newsgroups.php?gfltk.general+v:24912
+   Patch: Andreas Kemnade, Jorge Arellano Cid
 +- Fixed a va_list-related SEGFAULT on 64bit-arch in dStr_vsprintfa().
    Added const declarations in html parser.
    Patch: Vincent Thomasset
--- a/dpi/cookies.c	Fri Apr 11 15:12:06 2008 +0200
+++ b/dpi/cookies.c	Fri Apr 11 21:45:14 2008 +0200
@@ -195,14 +195,16 @@
          close(fd);
 
          MSG("Created file: %s\n", filename);
-         F_in = Cookies_fopen(filename, NULL);
+         F_in = fopen(filename, "r+");
       } else {
          MSG("Could not create file: %s!\n", filename);
       }
    }
 
-   /* set close on exec */
-   fcntl(fileno(F_in), F_SETFD, FD_CLOEXEC | fcntl(fileno(F_in), F_GETFD));
+   if (F_in) {
+      /* set close on exec */
+      fcntl(fileno(F_in), F_SETFD, FD_CLOEXEC | fcntl(fileno(F_in), F_GETFD));
+   }
 
    return F_in;
 }
@@ -1327,7 +1329,7 @@
 static int srv_parse_buf(SockHandler *sh, char *Buf, size_t BufSize)
 {
    char *p, *cmd, *cookie, *host, *path, *scheme;
-   int port;
+   int port, ret;
 
    if (!(p = strchr(Buf, '>'))) {
       /* Haven't got a full tag */
@@ -1375,14 +1377,15 @@
       cmd = a_Dpip_build_cmd("cmd=%s cookie=%s", "get_cookie_answer", cookie);
 
       if (sock_handler_write_str(sh, 1, cmd)) {
-          dFree(cookie);
-          dFree(cmd);
-          return 1;
+          ret = 1;
+      } else {
+          _MSG("sock_handler_write_str: SUCCESS cmd={%s}\n", cmd);
+          ret = 2;
       }
       dFree(cookie);
       dFree(cmd);
 
-      return 2;
+      return ret;
    }
 
    return 0;
@@ -1455,8 +1458,10 @@
          code = 1;
          if ((buf = sock_handler_read(sh)) != NULL) {
             /* Let's see what we fished... */
+            _MSG(" buf = {%s}\n", buf);
             code = srv_parse_buf(sh, buf, strlen(buf));
          }
+         _MSG(" code = %d %s\n", code, code == 1 ? "EXIT" : "BREAK");
          if (code == 1)
             exit(1);
          else if (code == 2)
@@ -1468,6 +1473,8 @@
       sock_handler_free(sh);
 
    }/*while*/
+
+   return 0;
 }
 
 #endif /* !DISABLE_COOKIES */
--- a/src/IO/http.c	Fri Apr 11 15:12:06 2008 +0200
+++ b/src/IO/http.c	Fri Apr 11 21:45:14 2008 +0200
@@ -278,7 +278,7 @@
    dStr_free(s_port, TRUE);
    dStr_free(full_path, TRUE);
    dStr_free(proxy_auth, TRUE);
-   DEBUG_MSG(4, "Query:\n%s\n", dStr_printable(query, 8192));
+   _MSG("Query: {%s}\n", dStr_printable(query, 8192));
    return query;
 }
 
--- a/src/cookies.c	Fri Apr 11 15:12:06 2008 +0200
+++ b/src/cookies.c	Fri Apr 11 21:45:14 2008 +0200
@@ -95,7 +95,7 @@
          close(fd);
 
          DEBUG_MSG(10, "Cookies: Created file: %s\n", filename);
-         F_in = Cookies_fopen(filename, NULL);
+         F_in = fopen(filename, "r");
       } else {
          DEBUG_MSG(10, "Cookies: Could not create file: %s!\n", filename);
       }
@@ -141,7 +141,7 @@
 void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url)
 {
    CookieControlAction action;
-   char *cmd, *cookie_string, numstr[16];
+   char *cmd, *cookie_string, *dpip_tag, numstr[16];
    const char *path;
    int i;
 
@@ -162,7 +162,13 @@
                              path ? path : "/", numstr);
 
       DEBUG_MSG(5, "Cookies.c: a_Cookies_set \n\t \"%s\" \n",cmd );
-      a_Capi_dpi_send_cmd(NULL, NULL, cmd, "cookies", 1);
+      /* This call is commented because it doesn't guarantee the order
+       * in which cookies are set and got. (It may deadlock too) */
+      //a_Capi_dpi_send_cmd(NULL, NULL, cmd, "cookies", 1);
+
+      dpip_tag = a_Dpi_send_blocking_cmd("cookies", cmd);
+      _MSG("a_Cookies_set: dpip_tag = {%s}\n", dpip_tag);
+      dFree(dpip_tag);
       dFree(cmd);
    }
 }
@@ -192,7 +198,9 @@
                          URL_HOST(request_url), path ? path : "/", numstr);
 
    /* Get the answer from cookies.dpi */
+   _MSG("cookies.c: a_Dpi_send_blocking_cmd cmd = {%s}\n", cmd);
    dpip_tag = a_Dpi_send_blocking_cmd("cookies", cmd);
+   _MSG("cookies.c: after a_Dpi_send_blocking_cmd resp={%s}\n", dpip_tag);
    dFree(cmd);
 
    query = dStrdup("Cookie2: $Version=\"1\"\r\n");