changeset 1531:4810e433ed3f

dpi send response when setting cookies
author Jorge Arellano Cid <jcid@dillo.org>
date Sun, 24 Jan 2010 19:07:39 +0000
parents 356c339d0761
children 8829d3f15f13
files dpi/cookies.c
diffstat 1 files changed, 30 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/cookies.c	Sun Jan 24 18:45:51 2010 +0100
+++ b/dpi/cookies.c	Sun Jan 24 19:07:39 2010 +0000
@@ -979,36 +979,42 @@
 
 /*
  * Set the value corresponding to the cookie string
+ * Return value: 0 set OK, -1 disabled, -2 denied, -3 rejected.
  */
-static void Cookies_set(char *cookie_string, char *url_host,
-                        char *url_path, char *server_date)
+static int Cookies_set(char *cookie_string, char *url_host,
+                       char *url_path, char *server_date)
 {
    CookieControlAction action;
    CookieData_t *cookie;
+   int ret = -1;
 
    if (disabled)
-      return;
+      return ret;
 
    action = Cookies_control_check_domain(url_host);
    if (action == COOKIE_DENY) {
       MSG("denied SET for %s\n", url_host);
-      return;
+      ret = -2;
+
+   } else {
+      MSG("%s SETTING: %s\n", url_host, cookie_string);
+      ret = -3;
+      if ((cookie = Cookies_parse(cookie_string, server_date))) {
+         if (Cookies_validate_domain(cookie, url_host)) {
+            Cookies_validate_path(cookie, url_path);
+            if (action == COOKIE_ACCEPT_SESSION)
+               cookie->session_only = TRUE;
+            Cookies_add_cookie(cookie);
+            ret = 0;
+         } else {
+            MSG("Rejecting cookie for domain %s from host %s path %s\n",
+                cookie->domain, url_host, url_path);
+            Cookies_free_cookie(cookie);
+         }
+      }
    }
 
-   MSG("%s SETTING: %s\n", url_host, cookie_string);
-
-   if ((cookie = Cookies_parse(cookie_string, server_date))) {
-      if (Cookies_validate_domain(cookie, url_host)) {
-         Cookies_validate_path(cookie, url_path);
-         if (action == COOKIE_ACCEPT_SESSION)
-            cookie->session_only = TRUE;
-         Cookies_add_cookie(cookie);
-      } else {
-         MSG("Rejecting cookie for domain %s from host %s path %s\n",
-             cookie->domain, url_host, url_path);
-         Cookies_free_cookie(cookie);
-      }
-   }
+   return ret;
 }
 
 /*
@@ -1288,6 +1294,7 @@
       exit(0);
 
    } else if (cmd && strcmp(cmd, "set_cookie") == 0) {
+      int st;
       char *date;
 
       dFree(cmd);
@@ -1296,8 +1303,12 @@
       path = a_Dpip_get_attr_l(Buf, BufSize, "path");
       date = a_Dpip_get_attr_l(Buf, BufSize, "date");
 
-      Cookies_set(cookie, host, path, date);
+      st = Cookies_set(cookie, host, path, date);
+      cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "set_cookie_answer",
+                             st == 0 ? "ok" : "not set");
+      a_Dpip_dsh_write_str(sh, 1, cmd);
 
+      dFree(cmd);
       dFree(date);
       dFree(path);
       dFree(host);