lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lynx-dev [patch] cookie domain handling (bugfix)


From: brian j pardy
Subject: Re: lynx-dev [patch] cookie domain handling (bugfix)
Date: Sat, 13 Feb 1999 00:08:47 -0800

On Tue, Feb 09, 1999, I wrote:
> * Added cookie_domain_flags enum to LYCookie.h, usage should be
>   apparent with patch applied
> * Replaced cookie_add_acceptlist, cookie_add_rejectlist and 
>   cookie_set_invcheck functions with cookie_domain_set_flag
> * Saved a bit of memory by dropping useless pointer memory initialization
>   (exactly WHAT was I thinking?)
> * Changed LYrcFile.c, LYReadCFG.c to call cookie_domain_set_flag

Here's a second try at this patch if you haven't applied it yet, Tom.

The original left an artifact where de->bv was being set to 0 (I think
within HTList_add()) when setting an INVCHECK flag on a domain.  The
changes from the first patch are down in the bottom of LYCookie.c, but
I've included the whole patch against a clean dev.16.  This led to a
domain being inadvertantly flagged as "accept always" when an invcheck
flag was set.  Not what we want at all.  So now I'm setting bv flags
to QUERY when the other flag is first set for a new domain.  

Note that invcheck_bv flags don't do anything yet, that's coming.

Updating a Slackware 3.5 box to glibc-2.1 and egcs-1.1.1 is a chore.
But I'm functional again. :)


diff -cr 2.8.2dev.16/src/LYCookie.c 2.8.2dev.16.bri/src/LYCookie.c
*** 2.8.2dev.16/src/LYCookie.c  Mon Feb  8 02:32:59 1999
--- 2.8.2dev.16.bri/src/LYCookie.c      Fri Feb 12 23:59:42 1999
***************
*** 2598,2626 ****
  }
  
  
! /*      cookie_add_acceptlist
! **      ---------------------
! **
! **   Is passed a comma-delimited string of domains to add to the
! **   "always accept" list for cookies.  The domains need to be identical
! **   to the form from which the cookie is received, with or without a
! **   leading ".".  - BJP
  */
  
! PUBLIC void cookie_add_acceptlist ARGS1(
!       char *,         acceptstr)
  {
      domain_entry *de = NULL;
      domain_entry *de2 = NULL;
      HTList *hl = NULL;
!     char **str = (char **)calloc(1, sizeof(acceptstr));
!     char *astr = NULL;
      char *strsmall = NULL;
      int isexisting = FALSE;
  
-     if (str == NULL)
-       outofmem(__FILE__, "cookie_add_acceptlist");
- 
      /*
       * Is this the first domain we're handling?  If so, initialize
       * domain_list.
--- 2598,2621 ----
  }
  
  
! /*      cookie_domain_flag_set
! **      ----------------------
! **      All purpose function to handle setting domain flags for a 
! **      comma-delimited list of domains.  cookie_domain_flags handles
! **      invcheck behavior, as well as accept/reject behavior. - BJP
  */
  
! PUBLIC void cookie_domain_flag_set ARGS2(
!       char *,         domainstr,
!       int,    flag)
  {
      domain_entry *de = NULL;
      domain_entry *de2 = NULL;
      HTList *hl = NULL;
!     char *dstr = NULL;
      char *strsmall = NULL;
      int isexisting = FALSE;
  
      /*
       * Is this the first domain we're handling?  If so, initialize
       * domain_list.
***************
*** 2632,2642 ****
        total_cookies = 0;
      }
  
!     StrAllocCopy(astr, acceptstr);
  
!     *str = astr;
! 
!     while ((strsmall = LYstrsep(str, ",")) != 0) {
  
        /*
         * Check the list of existing domains to see if this is a
--- 2627,2635 ----
        total_cookies = 0;
      }
  
!     StrAllocCopy(dstr, domainstr);
  
!     while ((strsmall = LYstrsep(&dstr, ",")) != 0) {
  
        /*
         * Check the list of existing domains to see if this is a
***************
*** 2659,2832 ****
            de = (domain_entry *)calloc(1, sizeof(domain_entry));
  
            if (de == NULL)
!                   outofmem(__FILE__, "cookie_add_acceptlist");
! 
!           de->bv = ACCEPT_ALWAYS;
! 
!           StrAllocCopy(de->domain, strsmall);
!           de->cookie_list = HTList_new();
!           HTList_addObject(domain_list, de);
!       } else {
!           de2->bv = ACCEPT_ALWAYS;
!       }
!     }
! 
!     FREE(str);
!     FREE(strsmall);
!     FREE(astr);
! }
! 
! 
! /*      cookie_add_rejectlist
! **      ---------------------
! **
! **   Is passed a comma-delimited string of domains to add to the
! **   "always reject" list for cookies.  The domains need to be identical
! **   to the form from which the cookie is received, with or without a
! **   leading ".".  - BJP
! */
! 
! PUBLIC void cookie_add_rejectlist ARGS1(
!       char *,         rejectstr)
! {
!     domain_entry *de = NULL;
!     domain_entry *de2 = NULL;
!     HTList *hl = NULL;
!     char **str = (char **)calloc(1, sizeof(rejectstr));
!     char *rstr = NULL;
!     char *strsmall = NULL;
!     int isexisting = FALSE;
! 
!     if (str == NULL)
!       outofmem(__FILE__, "cookie_add_rejectlist");
! 
!     /*
!      * Is this the first domain we're handling?  If so, initialize
!      * domain_list.
!      */
! 
!     if (domain_list == NULL) {
!       atexit(LYCookieJar_free);
!       domain_list = HTList_new();
!       total_cookies = 0;
!     }
! 
!     StrAllocCopy(rstr, rejectstr);
! 
!     *str = rstr;
! 
!     while ((strsmall = LYstrsep(str, ",")) != 0) {
! 
!       /*
!        * Check the list of existing domains to see if this is a
!        * re-setting of an already existing domains -- if so, just
!        * change the behavior, if not, create a new domain entry.
!        */
  
!       for (hl = domain_list; hl != NULL; hl = hl->next) {
!           de2 = (domain_entry *)hl->object;
!           if ((de2 != NULL && de2->domain != NULL) &&
!               !strcmp(strsmall, de2->domain)) {
!                       isexisting = TRUE;
!                       break;
!           } else {
!               isexisting = FALSE;
            }
-       }
- 
-       if(!isexisting) {
-           de = (domain_entry *)calloc(1, sizeof(domain_entry));
- 
-           if (de == NULL)
-                   outofmem(__FILE__, "cookie_add_rejectlist");
- 
-           de->bv = REJECT_ALWAYS;
  
            StrAllocCopy(de->domain, strsmall);
            de->cookie_list = HTList_new();
            HTList_addObject(domain_list, de);
        } else {
!           de2->bv = REJECT_ALWAYS;
!       }
!     }
! 
!     FREE(str);
!     FREE(strsmall);
!     FREE(rstr);
! }
! 
! /*      cookie_set_invcheck
! **      -------------------
! **
! **   Is passed a comma-delimited string of domains and a particular
! **   behaviour to set their invcheck_bv to. - BJP
! */
! 
! PUBLIC void cookie_set_invcheck ARGS2(
!       char *,         domains,
!         invcheck_behaviour,           setting)
! {
!     domain_entry *de = NULL;
!     domain_entry *de2 = NULL;
!     HTList *hl = NULL;
!     char **str = (char **)calloc(1, sizeof(domains));
!     char *dstr = NULL;
!     char *strsmall = NULL;
!     int isexisting = FALSE;
! 
!     if (str == NULL)
!       outofmem(__FILE__, "cookie_set_invcheck");
! 
!     /*
!      * Is this the first cookie we're handling?  If so, initialize
!      * domain_list.
!      */
! 
!     if (domain_list == NULL) {
!       atexit(LYCookieJar_free);
!       domain_list = HTList_new();
!       total_cookies = 0;
!     }
! 
!     StrAllocCopy(dstr, domains);
! 
!     *str = dstr;
! 
!     while ((strsmall = LYstrsep(str, ",")) != 0) {
! 
!       /*
!        * Check the list of existing cookies to see if this is a
!        * re-setting of an already existing cookie -- if so, just
!        * change the behavior, if not, create a new domain entry.
!        */
!       for (hl = domain_list; hl != NULL; hl = hl->next) {
!           de2 = (domain_entry *)hl->object;
!           if ((de2 != NULL && de2->domain != NULL)
!            && !strcmp(strsmall, de2->domain)) {
!               isexisting = TRUE;
!               break;
!           } else {
!               isexisting = FALSE;
            }
        }
- 
-       if (!isexisting) {
-           de = (domain_entry *)calloc(1, sizeof(domain_entry));
- 
-           if (de == NULL)
-               outofmem(__FILE__, "cookie_set_invcheck");
- 
-           de->invcheck_bv = setting;
- 
-           StrAllocCopy(de->domain, strsmall);
-           de->cookie_list = HTList_new();
-           HTList_addObject(domain_list, de);
-       } else {
-           de2->invcheck_bv = setting;
-       }
      }
  
-     FREE(str);
      FREE(strsmall);
      FREE(dstr);
  }
--- 2652,2706 ----
            de = (domain_entry *)calloc(1, sizeof(domain_entry));
  
            if (de == NULL)
!                   outofmem(__FILE__, "cookie_domain_flag_set");
  
!             switch(flag) {
!               case (FLAG_ACCEPT_ALWAYS): de->bv = ACCEPT_ALWAYS;
!                                          de->invcheck_bv = INVCHECK_QUERY;
!                                          break;
!               case (FLAG_REJECT_ALWAYS): de->bv = REJECT_ALWAYS;
!                                          de->invcheck_bv = INVCHECK_QUERY;
!                                          break;
!               case (FLAG_QUERY_USER):    de->bv = QUERY_USER;
!                                          de->invcheck_bv = INVCHECK_QUERY;
!                                          break;
!               case (FLAG_FROM_FILE):     de->bv = FROM_FILE;
!                                          de->invcheck_bv = INVCHECK_QUERY;
!                                          break;
!               case (FLAG_INVCHECK_QUERY): de->invcheck_bv = INVCHECK_QUERY;
!                                           de->bv = QUERY_USER;
!                                           break;
!               case (FLAG_INVCHECK_STRICT): de->invcheck_bv = INVCHECK_STRICT;
!                                            de->bv = QUERY_USER;
!                                           break;
!               case (FLAG_INVCHECK_LOOSE): de->invcheck_bv = INVCHECK_LOOSE;
!                                           de->bv = QUERY_USER;
!                                           break;
            }
  
            StrAllocCopy(de->domain, strsmall);
            de->cookie_list = HTList_new();
            HTList_addObject(domain_list, de);
        } else {
!             switch(flag) {
!               case (FLAG_ACCEPT_ALWAYS): de2->bv = ACCEPT_ALWAYS;
!                                          break;
!               case (FLAG_REJECT_ALWAYS): de2->bv = REJECT_ALWAYS;
!                                          break;
!               case (FLAG_QUERY_USER): de2->bv = QUERY_USER;
!                                          break;
!               case (FLAG_FROM_FILE): de2->bv = FROM_FILE;
!                                          break;
!               case (FLAG_INVCHECK_QUERY): de2->invcheck_bv = INVCHECK_QUERY;
!                                          break;
!               case (FLAG_INVCHECK_STRICT): de2->invcheck_bv = INVCHECK_STRICT;
!                                          break;
!               case (FLAG_INVCHECK_LOOSE): de2->invcheck_bv = INVCHECK_LOOSE;
!                                          break;
            }
        }
      }
  
      FREE(strsmall);
      FREE(dstr);
  }
diff -cr 2.8.2dev.16/src/LYCookie.h 2.8.2dev.16.bri/src/LYCookie.h
*** 2.8.2dev.16/src/LYCookie.h  Mon Feb  8 02:32:59 1999
--- 2.8.2dev.16.bri/src/LYCookie.h      Fri Feb 12 23:59:01 1999
***************
*** 8,13 ****
--- 8,20 ----
  typedef enum {INVCHECK_QUERY,
              INVCHECK_STRICT,
              INVCHECK_LOOSE} invcheck_behaviour;
+ typedef enum {FLAG_ACCEPT_ALWAYS,
+             FLAG_REJECT_ALWAYS,
+             FLAG_QUERY_USER,
+             FLAG_FROM_FILE,
+             FLAG_INVCHECK_QUERY,
+             FLAG_INVCHECK_STRICT,
+             FLAG_INVCHECK_LOOSE} cookie_domain_flags;
  
  struct _domain_entry {
      char *    domain;  /* Domain for which these cookies are valid */
diff -cr 2.8.2dev.16/src/LYReadCFG.c 2.8.2dev.16.bri/src/LYReadCFG.c
*** 2.8.2dev.16/src/LYReadCFG.c Mon Feb  8 02:32:59 1999
--- 2.8.2dev.16.bri/src/LYReadCFG.c     Fri Feb 12 23:59:01 1999
***************
*** 1293,1315 ****
       */
  
      if (LYCookieAcceptDomains != NULL) {
!       cookie_add_acceptlist(LYCookieAcceptDomains);
      }
  
      if (LYCookieRejectDomains != NULL) {
!       cookie_add_rejectlist(LYCookieRejectDomains);
      }
  
      if (LYCookieStrictCheckDomains != NULL) {
!       cookie_set_invcheck(LYCookieStrictCheckDomains, INVCHECK_STRICT);
      }
  
      if (LYCookieLooseCheckDomains != NULL) {
!       cookie_set_invcheck(LYCookieLooseCheckDomains, INVCHECK_LOOSE);
      }
  
      if (LYCookieQueryCheckDomains != NULL) {
!       cookie_set_invcheck(LYCookieQueryCheckDomains, INVCHECK_QUERY);
      }
  
  }
--- 1293,1315 ----
       */
  
      if (LYCookieAcceptDomains != NULL) {
!       cookie_domain_flag_set(LYCookieAcceptDomains, FLAG_ACCEPT_ALWAYS);
      }
  
      if (LYCookieRejectDomains != NULL) {
!       cookie_domain_flag_set(LYCookieRejectDomains, FLAG_REJECT_ALWAYS);
      }
  
      if (LYCookieStrictCheckDomains != NULL) {
!       cookie_domain_flag_set(LYCookieStrictCheckDomains, 
FLAG_INVCHECK_STRICT);
      }
  
      if (LYCookieLooseCheckDomains != NULL) {
!       cookie_domain_flag_set(LYCookieLooseCheckDomains, FLAG_INVCHECK_LOOSE);
      }
  
      if (LYCookieQueryCheckDomains != NULL) {
!       cookie_domain_flag_set(LYCookieQueryCheckDomains, FLAG_INVCHECK_QUERY);
      }
  
  }
diff -cr 2.8.2dev.16/src/LYrcFile.c 2.8.2dev.16.bri/src/LYrcFile.c
*** 2.8.2dev.16/src/LYrcFile.c  Mon Feb  8 02:32:59 1999
--- 2.8.2dev.16.bri/src/LYrcFile.c      Fri Feb 12 23:59:01 1999
***************
*** 408,414 ****
         */
        } else if (FIND_KEYWORD(cp, "cookie_accept_domains")) {
            cp = SkipEquals(cp);
!           cookie_add_acceptlist(cp);
            if(LYCookieAcceptDomains != NULL) { 
                StrAllocCat(LYCookieAcceptDomains, ","); 
            } 
--- 408,414 ----
         */
        } else if (FIND_KEYWORD(cp, "cookie_accept_domains")) {
            cp = SkipEquals(cp);
!           cookie_domain_flag_set(cp, FLAG_ACCEPT_ALWAYS);
            if(LYCookieAcceptDomains != NULL) { 
                StrAllocCat(LYCookieAcceptDomains, ","); 
            } 
***************
*** 420,426 ****
         */
        } else if (FIND_KEYWORD(cp, "cookie_reject_domains")) {
            cp = SkipEquals(cp);
!           cookie_add_rejectlist(cp);
            if(LYCookieRejectDomains != NULL) { 
                StrAllocCat(LYCookieRejectDomains, ","); 
            } 
--- 420,426 ----
         */
        } else if (FIND_KEYWORD(cp, "cookie_reject_domains")) {
            cp = SkipEquals(cp);
!           cookie_domain_flag_set(cp, FLAG_REJECT_ALWAYS);
            if(LYCookieRejectDomains != NULL) { 
                StrAllocCat(LYCookieRejectDomains, ","); 
            } 
***************
*** 432,438 ****
        } else if (FIND_KEYWORD(cp, "cookie_loose_invalid_domains")) {
            cp = SkipEquals(cp);
            StrAllocCopy(LYCookieLooseCheckDomains, cp);
!           cookie_set_invcheck(LYCookieLooseCheckDomains, INVCHECK_LOOSE);
  
        /*
         *  Cookie domains to perform strict checks?
--- 432,438 ----
        } else if (FIND_KEYWORD(cp, "cookie_loose_invalid_domains")) {
            cp = SkipEquals(cp);
            StrAllocCopy(LYCookieLooseCheckDomains, cp);
!           cookie_domain_flag_set(cp, FLAG_INVCHECK_LOOSE); 
  
        /*
         *  Cookie domains to perform strict checks?
***************
*** 440,446 ****
        } else if (FIND_KEYWORD(cp, "cookie_strict_invalid_domains")) {
            cp = SkipEquals(cp);
            StrAllocCopy(LYCookieStrictCheckDomains, cp);
!           cookie_set_invcheck(LYCookieStrictCheckDomains, INVCHECK_STRICT);
  
        /*
         *  Cookie domains to query user over invalid cookies?
--- 440,446 ----
        } else if (FIND_KEYWORD(cp, "cookie_strict_invalid_domains")) {
            cp = SkipEquals(cp);
            StrAllocCopy(LYCookieStrictCheckDomains, cp);
!           cookie_domain_flag_set(cp, FLAG_INVCHECK_STRICT);
  
        /*
         *  Cookie domains to query user over invalid cookies?
***************
*** 448,454 ****
        } else if (FIND_KEYWORD(cp, "cookie_query_invalid_domains")) {
            cp = SkipEquals(cp);
            StrAllocCopy(LYCookieQueryCheckDomains, cp);
!           cookie_set_invcheck(LYCookieQueryCheckDomains, INVCHECK_QUERY);
  
  #ifdef EXP_PERSISTENT_COOKIES
        /*
--- 448,454 ----
        } else if (FIND_KEYWORD(cp, "cookie_query_invalid_domains")) {
            cp = SkipEquals(cp);
            StrAllocCopy(LYCookieQueryCheckDomains, cp);
!           cookie_domain_flag_set(cp, FLAG_INVCHECK_QUERY);
  
  #ifdef EXP_PERSISTENT_COOKIES
        /*


-- 
We are anthill men upon an anthill world.
                -- Ray Bradbury

reply via email to

[Prev in Thread] Current Thread [Next in Thread]