[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev [patch] cookie domain handling (cleanup)
From: |
brian j pardy |
Subject: |
lynx-dev [patch] cookie domain handling (cleanup) |
Date: |
Tue, 9 Feb 1999 19:41:14 -0800 |
I started to realize how extremely ugly I was making the end of
LYCookie.c by putting in these three functions that were fundamentally
identical, so I decided to condense them all into a single function.
It saves a few bytes in source, saves all of 313 bytes in my binary,
and might speed things up (or might not).
* 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
This looks like a really ugly diff, but it makes the end of LYCookie.c
look a lot nicer IMO.
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 Tue Feb 9 19:31:18 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,2699 ----
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;
! break;
! case (FLAG_REJECT_ALWAYS): de->bv = REJECT_ALWAYS;
! break;
! case (FLAG_QUERY_USER): de->bv = QUERY_USER;
! break;
! case (FLAG_FROM_FILE): de->bv = FROM_FILE;
! break;
! case (FLAG_INVCHECK_QUERY): de->invcheck_bv = INVCHECK_QUERY;
! break;
! case (FLAG_INVCHECK_STRICT): de->invcheck_bv = INVCHECK_STRICT;
! break;
! case (FLAG_INVCHECK_LOOSE): de->invcheck_bv = INVCHECK_LOOSE;
! 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 Tue Feb 9 19:27:21 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 Tue Feb 9 18:59:00 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 Tue Feb 9 19:24:13 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
/*
--
Veni, Vidi, Visa.
- lynx-dev [patch] cookie domain handling (cleanup),
brian j pardy <=