Cookie changes.

This commit is contained in:
guha 1998-05-21 19:08:38 +00:00
parent a1c7463f7a
commit 9572e18899
8 changed files with 241 additions and 110 deletions

View File

@ -484,6 +484,7 @@ PR_PUBLIC_API(char *) HT_HTMLPaneHeight(HT_View htView);
PR_PUBLIC_API(void) HT_AddSitemapFor(HT_Pane htPane, char *pUrl, char *pSitemapUrl, char* name);
PR_PUBLIC_API(void) HT_AddRelatedLinksFor(HT_Pane htPane, char *pUrl);
PR_PUBLIC_API(void) HT_ExitPage(HT_Pane htPane, char *pUrl);
PR_PUBLIC_API(void) RDF_AddCookieResource(char* name, char* path, char* host, char* expires) ;
NSPR_END_EXTERN_C

View File

@ -349,11 +349,11 @@ updateNewHistItem (DBT *key, DBT *data)
COPY_INT32(&first, (time_t *)((char *)data->data + 4));
COPY_INT32(&numaccess, (time_t *)((char *)data->data + 8));
if (hostHash) collateOneHist(grdf, gNavCenter->RDF_HistoryBySite,
if (hostHash) collateOneHist(grdf, gNavCenter->RDF_History,
(char*)key->data, /* url */
((char*)data->data + 16), /* title */
last, first, numaccess, 0);
if (ByDateOpened) collateOneHist(grdf, gNavCenter->RDF_HistoryByDate,
if (ByDateOpened) collateOneHist(grdf, gNavCenter->RDF_History,
(char*)key->data, /* url */
((char*)data->data + 16), /* title */
last, first, numaccess, 1);
@ -423,7 +423,7 @@ HistCreate (char* url, PRBool createp)
}
}
PRBool bySite = 0;
Assertion
histAddParent (RDF_Resource child, RDF_Resource parent)
@ -448,23 +448,33 @@ histAddParent (RDF_Resource child, RDF_Resource parent)
parent->rarg2 = newAs;
} else {
PRBool added = 0;
if (bySite) {
while (nextAs && !isSeparator(nextAs->u)) {
prevAs = nextAs;
nextAs = nextAs->invNext;
}
if (nextAs) {
prevAs = nextAs;
nextAs = nextAs->invNext;
}
}
while (nextAs != null) {
char* nid = resourceID(nextAs->u);
if (strcmp( resourceID(child), resourceID(nextAs->u)) > 0) {
if (prevAs == nextAs) {
newAs->invNext = prevAs;
parent->rarg2 = newAs;
added = 1;
break;
} else {
newAs->invNext = nextAs;
prevAs->invNext = newAs;
added = 1;
break;
}
}
prevAs = nextAs;
nextAs = nextAs->invNext;
if (strcmp(resourceID(child), resourceID(nextAs->u)) > 0) {
if (prevAs == nextAs) {
newAs->invNext = prevAs;
parent->rarg2 = newAs;
added = 1;
break;
} else {
newAs->invNext = nextAs;
prevAs->invNext = newAs;
added = 1;
break;
}
}
prevAs = nextAs;
nextAs = nextAs->invNext;
}
if (!added) prevAs->invNext = newAs;
}
@ -513,7 +523,7 @@ HistPossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inverse
{
if ((s == gCoreVocab->RDF_parent) && inversep && (rdf == gHistoryStore) &&
((u == gNavCenter->RDF_HistoryByDate) || (u == gNavCenter->RDF_HistoryBySite))) {
collateHistory(rdf, u, (u == gNavCenter->RDF_HistoryByDate));
/* collateHistory(rdf, gNavCenter->RDF_History, (u == gNavCenter->RDF_HistoryByDate)); */
}
}
@ -525,6 +535,7 @@ MakeHistoryStore (char* url)
if (startsWith("rdf:history", url)) {
if (gHistoryStore == 0) {
RDFT ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct));
RDF_Resource sep = createSeparator();
ntr->assert = NULL;
ntr->unassert = historyUnassert;
ntr->getSlotValue = remoteStoreGetSlotValue;
@ -535,6 +546,10 @@ MakeHistoryStore (char* url)
ntr->possiblyAccessFile = HistPossiblyAccessFile;
gHistoryStore = ntr;
ntr->url = copyString(url);
collateHistory(ntr, gNavCenter->RDF_History, 1);
remoteStoreAdd(ntr, sep, gCoreVocab->RDF_parent, gNavCenter->RDF_History, RDF_RESOURCE_TYPE, 1);
bySite = 1;
collateHistory(ntr, gNavCenter->RDF_History, 0);
return ntr;
} else return gHistoryStore;
} else return NULL;

View File

@ -2596,6 +2596,8 @@ htIsMenuCmdEnabled(HT_Pane pane, HT_MenuCmd menuCmd,
if (HT_IsContainer(node)) return(false);
if (HT_IsSeparator(node)) return(false);
if (resourceType(node->node) == LFS_RT) return(false);
if (resourceType(node->node) == COOKIE_RT)
return(false);
break;
case HT_CMD_OPEN_COMPOSER:
@ -2627,6 +2629,8 @@ htIsMenuCmdEnabled(HT_Pane pane, HT_MenuCmd menuCmd,
if (!HT_IsContainer(node)) return(false);
if (htIsOpLocked(node, gNavCenter->RDF_CopyLock))
return(false);
if (resourceType(node->node) == COOKIE_RT)
return(false);
break;
case HT_CMD_NEW_BOOKMARK:
@ -2708,11 +2712,15 @@ htIsMenuCmdEnabled(HT_Pane pane, HT_MenuCmd menuCmd,
if (HT_IsContainer(node))
{
if (node->node == bmFolder) return(false);
if (resourceType(node->node) == COOKIE_RT)
return(false);
}
else
{
if (node->parent->node == bmFolder)
return(false);
if (resourceType(node->parent->node) == COOKIE_RT)
return(false);
}
if (htIsOpLocked(node, gNavCenter->RDF_CopyLock))
return(false);
@ -2729,6 +2737,8 @@ htIsMenuCmdEnabled(HT_Pane pane, HT_MenuCmd menuCmd,
if (node == NULL) return(false);
if (HT_IsContainer(node)) return(false);
if (HT_IsSeparator(node)) return(false);
if (resourceType(node->node) == COOKIE_RT)
return(false);
break;
case HT_CMD_SET_TOOLBAR_FOLDER:
@ -2791,7 +2801,8 @@ htIsMenuCmdEnabled(HT_Pane pane, HT_MenuCmd menuCmd,
if (node->parent == NULL) return(false);
if (node->parent->node == NULL) return(false);
if ((resourceType(node->parent->node) != RDF_RT) &&
(resourceType(node->parent->node) != HISTORY_RT))
(resourceType(node->parent->node) != HISTORY_RT) &&
(resourceType(node->parent->node) != COOKIE_RT))
return(false);
if (HT_IsContainer(node))
{
@ -5489,6 +5500,9 @@ HT_Properties (HT_Resource node)
dynStr = constructHTML(dynStr, node, (void *)gWebData->RDF_URL, HT_COLUMN_STRING);
break;
case COOKIE_RT:
break;
case SEARCH_RT:
case LDAP_RT:
case PM_RT:

View File

@ -75,6 +75,7 @@
#define CACHE_RT 11
#define ATALK_RT 12
#define ATALKVIRTUAL_RT 13
#define COOKIE_RT 14
#define WILDCARD_RT 15
@ -367,6 +368,7 @@ PRBool remoteStoreHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void*
void* remoteStoreGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
RDF_Cursor remoteStoreGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
RDF_Cursor remoteStoreGetSlotValuesInt (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
RDF_Resource createSeparator(void);
void* remoteStoreNextValue (RDFT mcf, RDF_Cursor c) ;
RDF_Error remoteStoreDisposeCursor (RDFT mcf, RDF_Cursor c) ;

View File

@ -384,6 +384,10 @@ remoteStoreNextValue (RDFT mcf, RDF_Cursor c)
c->value = (c->inversep ? as->u : as->value);
}
c->pdata = (c->inversep ? as->invNext : as->next);
if (c->type == RDF_RESOURCE_TYPE) {
FE_Trace(resourceID(c->value));
FE_Trace("\n");
}
return c->value;
}
c->pdata = (c->inversep ? as->invNext : as->next);

View File

@ -312,7 +312,7 @@ urlEquals (const char* url1, const char* url2)
PRBool
isSeparator (RDF_Resource r)
{
return startsWith("separator", resourceID(r));
return (startsWith("separator", resourceID(r))) ;
}
@ -519,99 +519,169 @@ RDFUtil_SetDefaultSelectedView(RDF_Resource container)
RDFT gCookieStore = 0;
PUBLIC void
NET_InitRDFCookieResources (void) ;
void
AddCookieResource(char* name, char* path, char* host, char* expires)
{
PR_PUBLIC_API(void)
RDF_AddCookieResource(char* name, char* path, char* host, char* expires) {
char* url = getMem(strlen(name) + strlen(host));
RDF_Resource ru;
sprintf(url, "%s [%s]", host, name);
RDF_Resource hostUnit = RDF_GetResource(NULL, host, 0);
if (!hostUnit) {
hostUnit = RDF_GetResource(NULL, host, 1);
setContainerp(hostUnit, 1);
setResourceType(hostUnit, COOKIE_RT);
remoteStoreAdd(gCookieStore, hostUnit, gCoreVocab->RDF_parent, gNavCenter->RDF_Cookies,
RDF_RESOURCE_TYPE, 1);
}
sprintf(url, "[%s]%s",path, name);
ru = RDF_GetResource(NULL, url, 1);
remoteStoreAdd(gCookieStore, ru, gCoreVocab->RDF_parent, gNavCenter->RDF_Cookies, RDF_RESOURCE_TYPE, 1);
setResourceType(ru, COOKIE_RT);
remoteStoreAdd(gCookieStore, ru, gCoreVocab->RDF_parent, hostUnit, RDF_RESOURCE_TYPE, 1);
}
#define LINE_BUFFER_SIZE 4096
PRBool
CookieUnassert (RDFT r, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type) {
if (resourceType(u) == COOKIE_RT) {
/* delete the cookie */
remoteStoreRemove(r, u, s, v, type);
return 1;
} else return 0;
}
void
RDF_ReadCookies(char * filename)
RDF_Cursor
CookieGetSlotValues(RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv)
{
XP_File fp;
char buffer[LINE_BUFFER_SIZE];
char *host, *is_domain, *path, *secure, *expires, *name, *cookie;
Bool added_to_list;
if(!(fp = XP_FileOpen(filename, xpHTTPCookie, XP_FILE_READ)))
return;
/* format is:
*
* host \t is_domain \t path \t secure \t expires \t name \t cookie
*
* if this format isn't respected we move onto the next line in the file.
* is_domain is TRUE or FALSE -- defaulting to FALSE
* secure is TRUE or FALSE -- should default to TRUE
* expires is a time_t integer
* cookie can have tabs
*/
while(XP_FileReadLine(buffer, LINE_BUFFER_SIZE, fp))
{
added_to_list = FALSE;
if (*buffer == '#' || *buffer == '\n' || *buffer == '\r' || *buffer == 0)
continue;
host = buffer;
if( !(is_domain = XP_STRCHR(host, '\t')) )
continue;
*is_domain++ = '\0';
if(*is_domain == CR || *is_domain == LF || *is_domain == 0)
continue;
if( !(path = XP_STRCHR(is_domain, '\t')) )
continue;
*path++ = '\0';
if(*path == '\n' || *path == '\r' || *path == 0)
continue;
if( !(secure = XP_STRCHR(path, '\t')) )
continue;
*secure++ = '\0';
if(*secure == CR || *secure == LF || *secure == 0)
continue;
if( !(expires = XP_STRCHR(secure, '\t')) )
continue;
*expires++ = '\0';
if(*expires == '\r' || *expires == '\n' || *expires == 0)
continue;
if( !(name = XP_STRCHR(expires, '\t')) )
continue;
*name++ = '\0';
if(*name == CR || *name == LF || *name == 0)
continue;
if( !(cookie = XP_STRCHR(name, '\t')) )
continue;
*cookie++ = '\0';
if(*cookie == CR || *cookie == LF || *cookie == 0)
continue;
/* remove the '\n' from the end of the cookie
XP_StripLine(cookie); */
/* construct a new cookie resource
*/
AddCookieResource(name, path, host, expires);
}
XP_FileClose(fp);
RDF_Cursor c = NULL;
if ((resourceType(u) == COOKIE_RT) &&
(s == gNavCenter->RDF_Command) &&
(type == RDF_RESOURCE_TYPE) && (tv))
{
if ((c = (RDF_Cursor)getMem(sizeof(struct RDF_CursorStruct))) != NULL)
{
c->u = u;
c->s = s;
c->type = type;
c->inversep = inversep;
c->tv = tv;
c->count = 0;
c->pdata = NULL;
}
return(c);
}
else
{
c = remoteStoreGetSlotValues(rdf, u, s, type, inversep, tv);
}
return(c);
}
#define COOKIE_CMD_PREFIX "CookieCommand:"
#define COOKIE_CMD_HOSTS "CookieCommand:TBD" /* actual cmd name */
void *
CookieGetNextValue(RDFT rdf, RDF_Cursor c)
{
void *data = NULL;
if (c != NULL)
{
if ((resourceType(c->u) == COOKIE_RT) &&
(c->s == gNavCenter->RDF_Command) &&
(c->type == RDF_RESOURCE_TYPE))
{
/* return cookie commands here */
switch(c->count)
{
case 0:
if (containerp(c->u))
{
data = (void *)RDF_GetResource(NULL,
COOKIE_CMD_HOSTS, true);
}
break;
}
c->count++;
}
else
{
data = remoteStoreNextValue(rdf, c);
}
}
return(data);
}
RDF_Error
CookieDisposeCursor(RDFT rdf, RDF_Cursor c)
{
RDF_Error err;
if (c != NULL)
{
if ((c->s == gNavCenter->RDF_Command) &&
(c->type == RDF_RESOURCE_TYPE))
{
if (c->pdata != NULL)
{
/* free private data */
}
freeMem(c);
err = 0;
}
else
{
err = remoteStoreDisposeCursor(rdf, c);
}
}
return(err);
}
PRBool
CookieAssert(RDFT rdf, RDF_Resource u, RDF_Resource s, void *v,
RDF_ValueType type, PRBool tv)
{
PRBool retVal = false;
if ((resourceType(u) == COOKIE_RT) &&
(s == gNavCenter->RDF_Command) &&
(type == RDF_RESOURCE_TYPE) &&
(v != NULL) && (tv))
{
RDF_Resource vu = (RDF_Resource)v;
retVal = true;
/* handle command in 'v' on 'u' */
if (startsWith(COOKIE_CMD_PREFIX, resourceID(vu)))
{
if (!XP_STRCMP(resourceID(vu), COOKIE_CMD_HOSTS))
{
/* do whatever is appropriate for the cmd */
}
}
}
return(retVal);
}
void *
CookieGetSlotValue(RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv)
{
void *data = NULL;
if ((startsWith(COOKIE_CMD_PREFIX, resourceID(u))) &&
(s == gCoreVocab->RDF_name) &&
(type == RDF_STRING_TYPE) && (!inversep) && (tv))
{
data = copyString(resourceID(u) + strlen(COOKIE_CMD_PREFIX));
}
else
{
data = remoteStoreGetSlotValue(rdf, u, s, type, inversep, tv);
}
return(data);
}
RDFT
MakeCookieStore (char* url)
@ -619,16 +689,16 @@ MakeCookieStore (char* url)
if (startsWith("rdf:CookieStore", url)) {
if (gCookieStore == 0) {
RDFT ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct));
ntr->assert = NULL;
ntr->unassert = NULL;
ntr->getSlotValue = remoteStoreGetSlotValue;
ntr->getSlotValues = remoteStoreGetSlotValues;
ntr->assert = CookieAssert;
ntr->unassert = CookieUnassert;
ntr->getSlotValue = CookieGetSlotValue;
ntr->getSlotValues = CookieGetSlotValues;
ntr->hasAssertion = remoteStoreHasAssertion;
ntr->nextValue = remoteStoreNextValue;
ntr->disposeCursor = remoteStoreDisposeCursor;
ntr->nextValue = CookieGetNextValue;
ntr->disposeCursor = CookieDisposeCursor;
gCookieStore = ntr;
ntr->url = copyString(url);
RDF_ReadCookies("");
NET_InitRDFCookieResources ( ) ;
return ntr;
} else return gCookieStore;
} else return NULL;

View File

@ -69,6 +69,13 @@ char * resourceID(RDF_Resource r);
char * makeResourceName (RDF_Resource node);
void AddCookieResource(char* name, char* path, char* host, char* expires);
void RDF_ReadCookies(char * filename);
PRBool CookieUnassert (RDFT r, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
RDF_Cursor CookieGetSlotValues(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * CookieGetNextValue(RDFT rdf, RDF_Cursor c);
RDF_Error CookieDisposeCursor(RDFT rdf, RDF_Cursor c);
PRBool CookieAssert(RDFT rdf, RDF_Resource u, RDF_Resource s, void *v, RDF_ValueType type, PRBool tv);
void * CookieGetSlotValue(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
XP_END_PROTOS

View File

@ -1790,12 +1790,16 @@ net_IntSetCookieString(MWContext * context,
while((tmp_cookie_ptr = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0) {
if(new_len > PL_strlen(tmp_cookie_ptr->path)) {
XP_ListInsertObject(net_cookie_list, tmp_cookie_ptr, prev_cookie);
RDF_AddCookieResource(tmp_cookie_ptr->name, tmp_cookie_ptr->path,
tmp_cookie_ptr->host, tmp_cookie_ptr->expires) ;
net_unlock_cookie_list();
cookies_changed = TRUE;
return;
}
}
/* no shorter strings found in list */
/* no shorter strings found in list */
RDF_AddCookieResource(prev_cookie->name, prev_cookie->path,
prev_cookie->host, prev_cookie->expires);
XP_ListAddObjectToEnd(net_cookie_list, prev_cookie);
}
@ -2065,6 +2069,18 @@ NET_SaveCookies(char * filename)
return(0);
}
PUBLIC void
NET_InitRDFCookieResources (void) {
XP_List *tmpList = net_cookie_list;
net_CookieStruct * item=NULL;
net_lock_cookie_list();
while ( (item=XP_ListNextObject(tmpList)) ) {
RDF_AddCookieResource(item->name, item->path, item->host, item->expires) ;
}
net_unlock_cookie_list();
}
/* reads HTTP cookies from disk
*
@ -2217,6 +2233,8 @@ NET_ReadCookies(char * filename)
/* --- New stuff: General auth utils (currently used only by proxy auth) --- */
/*