HTSprintf0(&buf, "</DT>\n");
HTSprintf0(&buf, "</dt>\n");
PRIVATE int LYHandleCookies ARGS4 (	CONST char *,		arg,	HTParentAnchor *,	anAnchor,	HTFormat,		format_out,	HTStream*,		sink){    HTFormat format_in = WWW_HTML;    HTStream *target = NULL;    char *buf = NULL;    char *domain = NULL;    char *lynxID = NULL;    HTList *dl, *cl, *next;    domain_entry *de;    cookie *co;    char *name = NULL, *value = NULL, *path = NULL;    char *comment = NULL, *Address = NULL, *Title = NULL;    int ch;    /*     *	Check whether we have something to do. - FM     */    if (HTList_isEmpty(domain_list)) {	HTProgress(COOKIE_JAR_IS_EMPTY);	sleep(MessageSecs);	return(HT_NO_DATA);    }    /*     *	If there's a domain string in the "host" field of the     *	LYNXCOOKIE: URL, this is a request to delete something     *	or change and 'allow' setting. - FM     */    if ((domain = HTParse(arg, "", PARSE_HOST)) != NULL) {	if (*domain == '\0') {	    FREE(domain);	} else {	    /*	     *	If there is a path string (not just a slash) in the	     *	LYNXCOOKIE: URL, that's a cookie's lynxID and this	     *	is a request to delete it from the Cookie Jar. - FM	     */	    if ((lynxID = HTParse(arg, "", PARSE_PATH)) != NULL) {		if (*lynxID == '\0') {		    FREE(lynxID);		}	    }	}    }    if (domain) {	/*	 *  Seek the domain in the domain_list structure. - FM	 */	for (dl = domain_list; dl != NULL; dl = dl->next) {	    de = dl->object;	    if (!(de && de->domain))		/*		 *  First object in the list always is empty. - FM		 */		continue;	    if (!strcmp(domain, de->domain)) {		FREE(domain);		/*		 *  We found the domain.  Check		 *  whether a lynxID is present. - FM		 */		if (lynxID) {		    /*		     *	Seek and delete the cookie with this lynxID		     *	in the domain's cookie list. - FM		     */		    for (cl = de->cookie_list; cl != NULL; cl = cl->next) {			if ((co = (cookie *)cl->object) == NULL)			    /*			     *	First object is always empty. - FM			     */			    continue;			if (!strcmp(lynxID, co->lynxID)) {			    /*			     *	We found the cookie.			     *	Delete it if confirmed. - FM			     */			    if (HTConfirm(DELETE_COOKIE_CONFIRMATION) == FALSE)			    {				FREE(lynxID);				return(HT_NO_DATA);			    }			    HTList_removeObject(de->cookie_list, co);			    freeCookie(co);			    co = NULL;			    total_cookies--;			    if ((de->bv == QUERY_USER &&				 HTList_isEmpty(de->cookie_list)) &&				HTConfirm(DELETE_EMPTY_DOMAIN_CONFIRMATION)) {				/*				 *  No more cookies in this domain, no				 *  default accept/reject choice was set				 *  by the user, and got confirmation on				 *  deleting the domain, so do it. - FM				 */				FREE(de->domain);				HTList_delete(de->cookie_list);				de->cookie_list = NULL;				HTList_removeObject(domain_list, de);				FREE(de);				HTProgress(DOMAIN_EATEN);			    } else {				HTProgress(COOKIE_EATEN);			    }			    sleep(MessageSecs);			    break;			}		    }		} else {		    /*		     *	Prompt whether to delete all of the cookies in		     *	this domain, or the domain if no cookies in it,		     *	or to change its 'allow' setting, or to cancel,		     *	and then act on the user's response. - FM		     */		    if (HTList_isEmpty(de->cookie_list)) {			_statusline(DELETE_DOMAIN_SET_ALLOW_OR_CANCEL);		    } else {			_statusline(DELETE_COOKIES_SET_ALLOW_OR_CANCEL);		    }		    while (1) {			ch = LYgetch();#ifdef VMS			if (HadVMSInterrupt) {			    HadVMSInterrupt = FALSE;			    ch = 'C';			}#endif /* VMS */			switch(TOUPPER(ch)) {			    case 'A':				/*				 *  Set to accept all cookies				 *  from this domain. - FM				 */				de->bv = ACCEPT_ALWAYS;				HTUserMsg2(ALWAYS_ALLOWING_COOKIES,					      de->domain);				return(HT_NO_DATA);			    case 'C':			    case 7:	/* Ctrl-G */			    case 3:	/* Ctrl-C */				/*				 *  Cancelled. - FM				 */				HTUserMsg(CANCELLED);				return(HT_NO_DATA);			    case 'D':				if (HTList_isEmpty(de->cookie_list)) {				    /*				     *	We had an empty domain, so we				     *	were asked to delete it. - FM				     */				    FREE(de->domain);				    HTList_delete(de->cookie_list);				    de->cookie_list = NULL;				    HTList_removeObject(domain_list, de);				    FREE(de);				    HTProgress(DOMAIN_EATEN);				    sleep(MessageSecs);				    break;				}Delete_all_cookies_in_domain:				/*				 *  Delete all cookies in this domain. - FM				 */				cl = de->cookie_list;				while (cl) {				    next = cl->next;				    co = cl->object;				    if (co) {					HTList_removeObject(de->cookie_list,							    co);					freeCookie(co);					co = NULL;					total_cookies--;				    }				    cl = next;				}				HTProgress(DOMAIN_COOKIES_EATEN);				sleep(MessageSecs);				/*				 *  If a default accept/reject				 *  choice is set, we're done. - FM				 */				if (de->bv != QUERY_USER)				    return(HT_NO_DATA);				/*				 *  Check whether to delete				 *  the empty domain. - FM				 */				if(HTConfirm(					DELETE_EMPTY_DOMAIN_CONFIRMATION)) {				    FREE(de->domain);				    HTList_delete(de->cookie_list);				    de->cookie_list = NULL;				    HTList_removeObject(domain_list, de);				    FREE(de);				    HTProgress(DOMAIN_EATEN);				    sleep(MessageSecs);				}				break;			    case 'P':				/*				 *  Set to prompt for cookie acceptance				 *  from this domain. - FM				 */				de->bv = QUERY_USER;				HTUserMsg2(PROMPTING_TO_ALLOW_COOKIES,					   de->domain);				return(HT_NO_DATA);			    case 'V':				/*				 *  Set to reject all cookies				 *  from this domain. - FM				 */				de->bv = REJECT_ALWAYS;				HTUserMsg2(NEVER_ALLOWING_COOKIES,					   de->domain);				if ((!HTList_isEmpty(de->cookie_list)) &&				    HTConfirm(DELETE_ALL_COOKIES_IN_DOMAIN))				    goto Delete_all_cookies_in_domain;				return(HT_NO_DATA);			    default:				continue;			}			break;		    }		}		break;	    }	}	if (HTList_isEmpty(domain_list)) {	    /*	     *	There are no more domains left.	     *	Don't delete the domain_list, otherwise	     *  atexit may be called multiple times. - kw	     */	    HTProgress(ALL_COOKIES_EATEN);	    sleep(MessageSecs);	}	FREE(domain);	FREE(lynxID);	return(HT_NO_DATA);    }    /*     *	If we get to here, it was a LYNXCOOKIE:/ URL     *	for creating and displaying the Cookie Jar Page,     *	or we didn't find the domain or cookie in a     *	deletion request.  Set up an HTML stream and     *	return an updated Cookie Jar Page. - FM     */    target = HTStreamStack(format_in,			   format_out,			   sink, anAnchor);    if (!target || target == NULL) {	HTSprintf0(&buf, CANNOT_CONVERT_I_TO_O,		HTAtom_name(format_in), HTAtom_name(format_out));	HTAlert(buf);	FREE(buf);	return(HT_NOT_LOADED);    }    /*     *	Load HTML strings into buf and pass buf     *	to the target for parsing and rendering. - FM     */#define PUTS(buf)    (*target->isa->put_block)(target, buf, strlen(buf))    HTSprintf0(&buf, "<HEAD>\n<TITLE>%s</title>\n</HEAD>\n<BODY>\n",		 COOKIE_JAR_TITLE);    PUTS(buf);    HTSprintf0(&buf, "<h1>%s (%s)%s<a href=\"%s%s\">%s</a></h1>\n",	LYNX_NAME, LYNX_VERSION,	HELP_ON_SEGMENT,	helpfilepath, COOKIE_JAR_HELP, COOKIE_JAR_TITLE);    PUTS(buf);    HTSprintf0(&buf, "<NOTE>%s\n", ACTIVATE_TO_GOBBLE);    PUTS(buf);    HTSprintf0(&buf, "%s</NOTE>\n", OR_CHANGE_ALLOW);    PUTS(buf);    HTSprintf0(&buf, "<DL COMPACT>\n");    PUTS(buf);    for (dl = domain_list; dl != NULL; dl = dl->next) {	de = dl->object;	if (de == NULL)	    /*	     *	First object always is NULL. - FM	     */	    continue;	/*	 *  Show the domain link and 'allow' setting. - FM	 */	HTSprintf0(&buf, "<DT>%s<DD><A HREF=\"LYNXCOOKIE://%s/\">Domain=%s</A>\n",		      de->domain, de->domain, de->domain);	PUTS(buf);	switch (de->bv) {	    case (ACCEPT_ALWAYS):		HTSprintf0(&buf, COOKIES_ALWAYS_ALLOWED);		break;	    case (REJECT_ALWAYS):		HTSprintf0(&buf, COOKIES_NEVER_ALLOWED);		break;	    case (QUERY_USER):		HTSprintf0(&buf, COOKIES_ALLOWED_VIA_PROMPT);		break;	    case (FROM_FILE):#if 0 /* not used any more - kw */		HTSprintf0(&buf, COOKIES_READ_FROM_FILE);#endif		break;	}	PUTS(buf);	HTSprintf0(&buf, "\n");	PUTS(buf);	/*	 *  Show the domain's cookies. - FM	 */	for (cl = de->cookie_list; cl != NULL; cl = cl->next) {	    if ((co = (cookie *)cl->object) == NULL)		/*		 *  First object is always NULL. - FM		 */		continue;	    /*	     *	Show the name=value pair. - FM	     */	    if (co->name) {		StrAllocCopy(name, co->name);		LYEntify(&name, TRUE);	    } else {		StrAllocCopy(name, NO_NAME);	    }	    if (co->value) {		StrAllocCopy(value, co->value);		LYEntify(&value, TRUE);	    } else {		StrAllocCopy(value, NO_VALUE);	    }	    HTSprintf0(&buf, "<DD><A HREF=\"LYNXCOOKIE://%s/%s\">%s=%s</A>\n",			 de->domain, co->lynxID, name, value);	    FREE(name);	    FREE(value);	    PUTS(buf);	    if (co->flags & COOKIE_FLAG_FROM_FILE) {		HTSprintf0(&buf, "%s\n", gettext("(from a previous session)"));	        PUTS(buf);	    }	    /*	     *	Show the path, port, secure and discard setting. - FM	     */	    if (co->path) {		StrAllocCopy(path, co->path);		LYEntify(&path, TRUE);	    } else {		StrAllocCopy(path, "/");	    }	    HTSprintf0(&buf, "<DD>Path=%s\n<DD>Port: %d Secure: %s Discard: %s\n",			 path, co->port,			 ((co->flags & COOKIE_FLAG_SECURE) ? "YES" : "NO"),			 ((co->flags & COOKIE_FLAG_DISCARD) ? "YES" : "NO"));	    FREE(path);	    PUTS(buf);	    /*	     *	Show the list of acceptable ports, if present. - FM	     */	    if (co->PortList) {		HTSprintf0(&buf, "<DD>PortList=\"%s\"\n", co->PortList);		PUTS(buf);	    }	    /*	     *	Show the commentURL, if we have one. - FM	     */	    if (co->commentURL) {		StrAllocCopy(Address, co->commentURL);		LYEntify(&Address, FALSE);		StrAllocCopy(Title, co->commentURL);		LYEntify(&Title, TRUE);		HTSprintf0(&buf,			"<DD>CommentURL: <A href=\"%s\">%s</A>\n",			Address,			Title);		FREE(Address);		FREE(Title);		PUTS(buf);	    }	    /*	     *	Show the comment, if we have one. - FM	     */	    if (co->comment) {		StrAllocCopy(comment, co->comment);		LYEntify(&comment, TRUE);		HTSprintf0(&buf, "<DD>Comment: %s\n", comment);		FREE(comment);		PUTS(buf);	    }	    /*	     *	Show the Maximum Gobble Date. - FM	     */	    HTSprintf0(&buf, "<DD><EM>%s</EM> %s%s",	    		 gettext("Maximum Gobble Date:"),			 ((co->flags & COOKIE_FLAG_EXPIRES_SET)					    ?			ctime(&co->expires) : END_OF_SESSION),			 ((co->flags & COOKIE_FLAG_EXPIRES_SET)					    ?					 "" : "\n"));	    PUTS(buf);	}	HTSprintf0(&buf, "</DT>\n");	PUTS(buf);    }    HTSprintf0(&buf, "</DL>\n</BODY>\n");    PUTS(buf);    /*     *	Free the target to complete loading of the     *	Cookie Jar Page, and report a successful load. - FM     */    (*target->isa->_free)(target);    FREE(buf);    return(HT_LOADED);}