/* ** Check the response to see if we got a cookie or more. ** If so then figure out what to do with it (prompt user, store, etc.) */ PRIVATE int HTCookie_afterFilter (HTRequest * request, HTResponse * response, void * param, int status) { if ((CookieMode & HT_COOKIE_ACCEPT) && SetCookie) { HTCookieHolder * holder = HTCookieHolder_find(request); if (holder) { HTList * cookies = holder->cookies; HTCookie * pres; while ((pres = (HTCookie *) HTAssocList_nextObject(cookies))) { /* Should we check to see if hosts match? */ if (CookieMode & (HT_COOKIE_SAME_HOST|HT_COOKIE_SAME_DOMAIN)) { char * cookie_host = HTCookie_domain(pres); if (cookie_host) { int res; char * addr = HTAnchor_address((HTAnchor *) HTRequest_anchor(request)); char * host = HTParse(addr, "", PARSE_HOST); if (CookieMode & HT_COOKIE_SAME_DOMAIN) res = tailcasecomp(cookie_host, host); else res = strcasecomp(cookie_host, host); if (res != 0) { HTTRACE(APP_TRACE, "Cookie...... Host `%s\' doesn't match what is sent in cookie `%s\'\n" _ host _ cookie_host); HT_FREE(addr); continue; } HT_FREE(addr); } } /* Should we prompt the user? */ if (CookieMode & HT_COOKIE_PROMPT) { HTAlertCallback * prompt = HTAlert_find(HT_A_CONFIRM); if (prompt) { if ((*prompt)(request, HT_A_CONFIRM, HT_MSG_ACCEPT_COOKIE, NULL, NULL, NULL) != YES) continue; } else continue; } /* Call the application with our new cookie */ (*SetCookie)(request, pres, SetCookieContext); } /* Delete cookie holder */ HTCookieHolder_delete(holder); } } return HT_OK; }
PRIVATE BOOL setCookie (HTRequest * request, HTCookie * cookie, void * param) { if (cookie) { char * addr = HTAnchor_address((HTAnchor *) HTRequest_anchor(request)); HTPrint("While accessing `%s\', we received a cookie with parameters:\n", addr); if (HTCookie_name(cookie)) HTPrint("\tName : `%s\'\n", HTCookie_name(cookie)); if (HTCookie_value(cookie)) HTPrint("\tValue : `%s\'\n", HTCookie_value(cookie)); if (HTCookie_domain(cookie)) HTPrint("\tDomain : `%s\'\n", HTCookie_domain(cookie)); if (HTCookie_path(cookie)) HTPrint("\tPath : `%s\'\n", HTCookie_path(cookie)); if (HTCookie_expiration(cookie) > 0) { time_t t = HTCookie_expiration(cookie); HTPrint("\tExpires: `%s\'\n", HTDateTimeStr(&t, NO)); } HTPrint("\tCookie is %ssecure\n\n", HTCookie_isSecure(cookie) ? "" : "not "); HT_FREE(addr); } return YES; }