📄 lycookie.c
字号:
*/ if (domain_list) { if (HTList_isEmpty(domain_list)) { HTList_delete(domain_list); domain_list = NULL; } } return(NULL);}/* LYHandleCookies - F.Macrides (macrides@sci.wfeb.edu)** ---------------**** Lists all cookies by domain, and allows deletions of** individual cookies or entire domains, and changes of** 'allow' settings. The list is invoked via the COOKIE_JAR** command (Ctrl-K), and deletions or changes of 'allow'** settings are done by activating links in that list.** The procedure uses a LYNXCOOKIE: internal URL scheme.**** Semantics:** LYNXCOOKIE:/ Create and load the Cookie Jar Page.** LYNXCOOKIE://domain Manipulate the domain.** LYNXCOOKIE://domain/lynxID Delete cookie with lynxID in domain.**** New functions can be added as extensions to the path, and/or by** assigning meanings to ;parameters, a ?searchpart, and/or #fragments.*/PRIVATE int LYHandleCookies ARGS4 ( CONST char *, arg, HTParentAnchor *, anAnchor, HTFormat, format_out, HTStream*, sink){ HTFormat format_in = WWW_HTML; HTStream *target = NULL; char buf[1024]; 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;#ifdef VMS extern BOOLEAN HadVMSInterrupt;#endif /* VMS */ /* * Check whether we have something to do. - FM */ if (domain_list == NULL) { 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)) { /* * 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) 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); de = NULL; 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 = QUERY_USER; _user_message(ALWAYS_ALLOWING_COOKIES, de->domain); sleep(MessageSecs); return(HT_NO_DATA); case 'C': case 7: /* Ctrl-G */ case 3: /* Ctrl-C */ /* * Cancelled. - FM */ _statusline(CANCELLED); sleep(MessageSecs); 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); de = NULL; 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); de = NULL; HTProgress(DOMAIN_EATEN); sleep(MessageSecs); } break; case 'P': /* * Set to prompt for cookie acceptence * from this domain. - FM */ de->bv = QUERY_USER; _user_message(PROMTING_TO_ALLOW_COOKIES, de->domain); sleep(MessageSecs); return(HT_NO_DATA); case 'V': /* * Set to reject all cookies * from this domain. - FM */ de->bv = REJECT_ALWAYS; _user_message(NEVER_ALLOWING_COOKIES, de->domain); sleep(MessageSecs); 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, * so delete the domain_list. - FM */ HTList_delete(domain_list); domain_list = NULL; HTProgress(ALL_COOKIES_EATEN); sleep(MessageSecs); } 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) { sprintf(buf, CANNOT_CONVERT_I_TO_O, HTAtom_name(format_in), HTAtom_name(format_out)); HTAlert(buf); return(HT_NOT_LOADED); } /* * Load HTML strings into buf and pass buf * to the target for parsing and rendering. - FM */ sprintf(buf, "<HEAD>\n<TITLE>%s</title>\n</HEAD>\n<BODY>\n", COOKIE_JAR_TITLE); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf, "<H1>%s</H1>\n", REACHED_COOKIE_JAR_PAGE); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf, "<H2>%s Version %s</H2>\n", LYNX_NAME, LYNX_VERSION); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf, "<NOTE>%s\n", ACTIVATE_TO_GOBBLE); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf, "%s</NOTE>\n", OR_CHANGE_ALLOW); (*target->isa->put_block)(target, buf, strlen(buf)); sprintf(buf, "<DL COMPACT>\n"); (*target->isa->put_block)(target, buf, strlen(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 */ sprintf(buf, "<DT><A HREF=\"LYNXCOOKIE://%s/\">Domain=%s</A>\n", de->domain, de->domain); (*target->isa->put_block)(target, buf, strlen(buf)); switch (de->bv) { case (ACCEPT_ALWAYS): sprintf(buf, COOKIES_ALWAYS_ALLOWED); break; case (REJECT_ALWAYS): sprintf(buf, COOKIES_NEVER_ALLOWED); break; case (QUERY_USER): sprintf(buf, COOKIES_ALLOWED_VIA_PROMPT); break; } (*target->isa->put_block)(target, buf, strlen(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); } sprintf(buf, "<DD><A HREF=\"LYNXCOOKIE://%s/%s\">%s=%s</A>\n", de->domain, co->lynxID, name, value); FREE(name); FREE(value); (*target->isa->put_block)(target, buf, strlen(buf)); /* * Show the path, port, secure and discard setting. - FM */ if (co->path) { StrAllocCopy(path, co->path); LYEntify(&path, TRUE); } else { StrAllocCopy(path, "/"); } sprintf(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); (*target->isa->put_block)(target, buf, strlen(buf)); /* * Show the list of acceptable ports, if present. - FM */ if (co->PortList) { sprintf(buf, "<DD>PortList=\"%s\"\n", co->PortList); (*target->isa->put_block)(target, buf, strlen(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); sprintf(buf, "<DD>CommentURL: <A href=\"%s\">%s</A>\n", Address, Title); FREE(Address); FREE(Title); (*target->isa->put_block)(target, buf, strlen(buf)); } /* * Show the comment, if we have one. - FM */ if (co->comment) { StrAllocCopy(comment, co->comment); LYEntify(&comment, TRUE); sprintf(buf, "<DD>Comment: %s\n", comment); FREE(comment); (*target->isa->put_block)(target, buf, strlen(buf)); } /* * Show the Maximum Gobble Date. - FM */ sprintf(buf, "<DD><EM>Maximum Gobble Date:</EM> %s%s", ((co->expires > 0 && !(co->flags & COOKIE_FLAG_DISCARD)) ? ctime(&co->expires) : END_OF_SESSION), ((co->expires > 0 && !(co->flags & COOKIE_FLAG_DISCARD)) ? "" : "\n")); (*target->isa->put_block)(target, buf, strlen(buf)); } sprintf(buf, "</DT>\n"); (*target->isa->put_block)(target, buf, strlen(buf)); } sprintf(buf, "</DL>\n</BODY>\n"); (*target->isa->put_block)(target, buf, strlen(buf)); /* * Free the target to complete loading of the * Cookie Jar Page, and report a successful load. - FM */ (*target->isa->_free)(target); return(HT_LOADED);}#ifdef GLOBALDEF_IS_MACRO#define _LYCOOKIE_C_GLOBALDEF_1_INIT { "LYNXCOOKIE",LYHandleCookies,0}GLOBALDEF (HTProtocol,LYLynxCookies,_LYCOOKIE_C_GLOBALDEF_1_INIT);#elseGLOBALDEF PUBLIC HTProtocol LYLynxCookies = {"LYNXCOOKIE",LYHandleCookies,0};#endif /* GLOBALDEF_IS_MACRO */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -