TEST(CookieDecoderTest, testDecodingWeirdNames2) { String src = "HTTPOnly="; Set<Cookie> cookies = CookieDecoder.decode(src); Cookie c = cookies.iterator().next(); assertEquals("HTTPOnly", c.getName()); assertEquals("", c.getValue()); }
bool SessionManager::getSessionFromAction( BtpAction* action, string& session, InternetAddress* ip) { bool rval = true; // get client cookies CookieJar jar; jar.readCookies(action->getRequest()->getHeader(), CookieJar::Client); // check for bitmunk-session cookie Cookie cookie = jar.getCookie("bitmunk-session"); if(cookie.isNull()) { ExceptionRef e = new Exception( "No 'bitmunk-session' cookie.", "bitmunk.webui.SessionManager.MissingCookie"); e->getDetails()["missingCookie"] = "bitmunk-session"; Exception::set(e); rval = false; } else { // get session ID session = cookie["value"]->getString(); } if(rval) { // get IP rval = action->getClientInternetAddress(ip); } return rval; }
BOOL CookiePath::CleanSmartCardAuthenticatedCookies() { Cookie *next_ck = (Cookie *) cookie_list.First(); while(next_ck ) { Cookie *ck = next_ck; next_ck = next_ck->Suc(); if(ck->GetHaveSmartCardAuthentication()) { OP_DELETE(ck); } } CookiePath *next_cp = LastChild(); while(next_cp) { CookiePath *cp = next_cp; next_cp = next_cp->Pred(); if(cp->CleanSmartCardAuthenticatedCookies()) { cp->Out(); OP_DELETE(cp); } } return cookie_list.Empty() && Empty(); }
int main() { while (FCGI_Accept() >= 0) { webapp::g_out = ""; //输出header webapp::http_head(); Cgi cgi; string username = cgi["username"]; string email = cgi["email"]; string password = cgi["password"]; Cookie cookie; DateTime now; DateTime expires = now + ( TIME_ONE_DAY*3 ); // Cookie有效期为三天 cookie.set_cookie("usercookie", username, expires.gmt_datetime()); string usercookie = cookie["usercookie"]; stringstream ss; ss <<"username: "******"\n" <<"email: "<<email<<"\n" <<"password: "******"\n" <<"usercookie: "<<usercookie<<"\n"; webapp::g_out += ss.str(); FCGI_printf("%s",webapp::g_out.c_str()); } return 0; }
TEST(CookieDecoderTest, testDecodingWeirdNames1) { String src = "path=; expires=Mon, 01-Jan-1990 00:00:00 GMT; path=/; domain=.www.google.com"; Set<Cookie> cookies = CookieDecoder.decode(src); Cookie c = cookies.iterator().next(); assertEquals("path", c.getName()); assertEquals("", c.getValue()); assertEquals("/", c.getPath()); }
static status_t nfs4_close_dir(fs_volume* volume, fs_vnode* vnode, void* _cookie) { TRACE("volume = %p, vnode = %" B_PRIi64 ", cookie = %p", volume, reinterpret_cast<VnodeToInode*>(vnode->private_node)->ID(), _cookie); Cookie* cookie = reinterpret_cast<Cookie*>(_cookie); return cookie->CancelAll(); }
size_t CookiePath::WriteCookiesL(DataFile &fp, time_t this_time, BOOL dry_run) { size_t size = 0; Cookie* ck = (Cookie*) cookie_list.First(); while (ck) { if(ck->Persistent(this_time)) { DataFile_Record rec(TAG_COOKIE_ENTRY); ANCHOR(DataFile_Record,rec); rec.SetRecordSpec(fp.GetRecordSpec()); ck->FillDataFileRecordL(rec); if (dry_run) size += rec.CalculateLength(); else rec.WriteRecordL(&fp); } ck = ck->Suc(); } CookiePath* cp = (CookiePath*) FirstChild(); while (cp) { if (cp->HasCookies(this_time)) { DataFile_Record rec(TAG_COOKIE_PATH_ENTRY); ANCHOR(DataFile_Record,rec); rec.SetRecordSpec(fp.GetRecordSpec()); rec.AddRecordL(TAG_COOKIE_PATH_NAME, cp->PathPart()); if (dry_run) size += rec.CalculateLength(); else rec.WriteRecordL(&fp); size += cp->WriteCookiesL(fp, this_time, dry_run); } cp = cp->Suc(); } { DataFile_Record rec(TAG_COOKIE_PATH_END); // spec is a pointer to existing field of object fp, there is no need to assert that it's not null const DataRecord_Spec *spec = fp.GetRecordSpec(); rec.SetRecordSpec(spec); if (dry_run) size += ((rec.GetTag() & MSB_VALUE) == MSB_VALUE) ? spec->idtag_len : rec.CalculateLength(); else rec.WriteRecordL(&fp); } return size; }
TEST(CookieDecoderTest, testDecodingValuesWithCommasAndEquals) { String src = "A=v=1&lg=en-US,it-IT,it&intl=it&np=1;T=z=E"; Set<Cookie> cookies = CookieDecoder.decode(src); Iterator<Cookie> i = cookies.iterator(); Cookie c = i.next(); assertEquals("A", c.getName()); assertEquals("v=1&lg=en-US,it-IT,it&intl=it&np=1", c.getValue()); c = i.next(); assertEquals("T", c.getName()); assertEquals("z=E", c.getValue()); }
Cookie* CookiePath::LocalGetCookie(const OpStringC8 &nme) { if (nme.IsEmpty()) return 0; Cookie* ck = (Cookie*) cookie_list.First(); while (ck && ck->Name().Compare(nme) != 0) ck = ck->Suc(); return ck; }
TEST(CookieDecoderTest, testDecodingLongDates) { Calendar cookieDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cookieDate.set(9999, Calendar.DECEMBER, 31, 23, 59, 59); long expectedMaxAge = (cookieDate.getTimeInMillis() - System.currentTimeMillis()) / 1000; String source = "Format=EU; expires=Fri, 31-Dec-9999 23:59:59 GMT; path=/"; Set<Cookie> cookies = CookieDecoder.decode(source); Cookie c = cookies.iterator().next(); assertTrue(Math.abs(expectedMaxAge - c.getMaxAge()) < 2); }
Cookie& HttpHeader::getCookie(const string &key) { auto cookieIt = _cookies.find(key); if (cookieIt != _cookies.end()) { return cookieIt->second; } Cookie cookie; cookie.setKey(key); _cookies[key] = cookie; return _cookies[key]; }
void CookieJar::deleteCookie(const char* name, bool secure) { Cookie cookie = getCookie(name); if(cookie.isNull()) { setCookie(name, "", 0, secure, false); } else { cookie["value"] = ""; cookie["maxAge"] = 0; cookie["httpOnly"] = true; } }
void Handshake::createCookie(PacketWriter& writer,HelloAttempt& attempt,const string& tag,const string& queryUrl) { // New Cookie Cookie* pCookie = attempt.pCookie; if(!pCookie) { if(attempt.pTarget) pCookie = new Cookie(*this,invoker,tag,*attempt.pTarget); else pCookie = new Cookie(*this,invoker,tag,queryUrl); _cookies[pCookie->value()] = pCookie; attempt.pCookie = pCookie; } writer.write8(COOKIE_SIZE); writer.writeRaw(pCookie->value(),COOKIE_SIZE); }
void CookiePath::BuildCookieEditorListL(CookieDomain* domain) { Cookie *ck = (Cookie*)cookie_list.First(); if( ck ) { ck->BuildCookieEditorListL(domain, this); } CookiePath *cp = (CookiePath*)FirstChild(); while(cp) { cp->BuildCookieEditorListL(domain); cp = cp->Suc(); } }
void CookiePath::IterateAllCookies() { Cookie* ck = static_cast<Cookie*>( cookie_list.First() ); OpCookieIteratorListener* listener = g_cookie_API->GetCookieIteratorListener(); while( ck ) { listener->OnIterateCookies(*ck); ck = ck->Suc(); } CookiePath* cp = static_cast<CookiePath*>( FirstChild() ); while (cp) { cp->IterateAllCookies(); cp = cp->Suc(); } }
OP_STATUS CookiePath::RemoveCookieList(char * pathstr, char * namestr) { char* pathstrcopy = pathstr; if(path.HasContent() && pathstr && *pathstr) { int p_len = path.Length(); if(path.Compare(pathstr,p_len) != 0) return OpStatus::OK; pathstr += p_len; // Remove first part, if path found if(*pathstr == '/') pathstr++; } Cookie *ck = (Cookie*)cookie_list.First(); while(ck) { Cookie * next = ck->Suc(); if(pathstr && *pathstr) // if a path was specified test against it, otherwise delete it { OpString8 fullpath; RETURN_IF_ERROR(GetFullPath(fullpath)); // get the full path //the internal root part does not start with /, so get rid of it fullpath.Delete(0,1); int pathlen = fullpath.Length(); if(pathlen && fullpath.Compare(pathstrcopy, pathlen) == 0) //compare against the full path length since we want subpaths { OP_DELETE(ck); } } else if((!namestr || !*namestr) || (ck->Name().Compare(namestr) == 0)) // remove it if no Name value was set or if the Name value equals { ck->Out(); OP_DELETE(ck); } ck = next; } CookiePath *cp = (CookiePath*)FirstChild(); while(cp) { cp->RemoveCookieList(pathstr, namestr); cp = cp->Suc(); } return OpStatus::OK; }
void CookiePath::GetMemUsed(DebugUrlMemory &debug) { debug.memory_cookies += sizeof(*this) + path.Length(); Cookie *ck = (Cookie *) cookie_list.First(); while(ck) { ck->GetMemUsed(debug); ck = ck->Suc(); } CookiePath *cp = (CookiePath *) FirstChild(); while(cp) { cp->GetMemUsed(debug); cp = cp->Suc(); } }
TEST(CookieDecoderTest, testDecodingValueWithComma) { String source = "UserCookie=timeZoneName=(GMT+04:00) Moscow, St. Petersburg, Volgograd&promocode=®ion=BE;" + " expires=Sat, 01-Dec-2012 10:53:31 GMT; path=/"; Set<Cookie> cookies = CookieDecoder.decode(source); Cookie c = cookies.iterator().next(); assertEquals("timeZoneName=(GMT+04:00) Moscow, St. Petersburg, Volgograd&promocode=®ion=BE", c.getValue()); }
BOOL CookiePath::HasCookies(time_t this_time) { Cookie* ck = (Cookie*) cookie_list.First(); while (ck) { if (!ck->DiscardAtExit() && ck->Expires() > this_time) return TRUE; ck = ck->Suc(); } CookiePath* cp = (CookiePath*) FirstChild(); while (cp) { if (cp->HasCookies(this_time)) return TRUE; cp = cp->Suc(); } return FALSE; }
Cookie* CookiePath::GetLeastRecentlyUsed(time_t last_used, time_t this_time) { time_t new_last_used = last_used; Cookie* ck = 0; Cookie *ck_unused = NULL; Cookie* new_ck = (Cookie*) cookie_list.First(); while (new_ck) { Cookie* next_ck = new_ck->Suc(); if (new_ck->Expires() && new_ck->Expires() < this_time) { OP_DELETE(new_ck); } else if (new_ck->GetLastUsed() <= new_last_used && !new_ck->ProtectedCookie()) { if(new_ck->GetLastUsed()) { new_last_used = new_ck->GetLastUsed(); ck = new_ck; } else if(!ck_unused) ck_unused = new_ck; } new_ck = next_ck; } CookiePath* cp = (CookiePath*) FirstChild(); while (cp) { new_ck = cp->GetLeastRecentlyUsed(new_last_used, this_time); if (new_ck) { if(new_ck->GetLastUsed()) { ck = new_ck; new_last_used = ck->GetLastUsed(); } else ck_unused = new_ck; } cp = cp->Suc(); } return (ck ? ck : ck_unused); }
void CookiePath::DeleteAllCookies() { Cookie* ck = (Cookie*) cookie_list.First(); while (ck) { Cookie *ck1 = ck->Suc(); OP_DELETE(ck); ck = ck1; } CookiePath* cp = (CookiePath*) FirstChild(); while (cp) { cp->DeleteAllCookies(); cp = cp->Suc(); } }
void CookiePath::DebugWriteCookies(FILE* fp) { fprintf(fp, " "); DebugWritePath(fp); fprintf(fp, ": \n"); Cookie* ck = (Cookie*) cookie_list.First(); while (ck) { fprintf(fp, " %s=%s; %lu; %d; %lu %s\n", ck->Name(), ck->Value(), ck->Expires(), ck->Secure(), ck->GetLastUsed(), (ck->DiscardAtExit() ? "; Discard on exit" : "")); ck = ck->Suc(); } CookiePath* cp = (CookiePath*) FirstChild(); while (cp) { cp->DebugWriteCookies(fp); cp = cp->Suc(); } }
void SessionManager::deleteSession(BtpAction* action) { // read session cookie from request header CookieJar jar; HttpHeader* header = action->getRequest()->getHeader(); jar.readCookies(header, CookieJar::Client); Cookie cookie = jar.getCookie("bitmunk-session"); if(!cookie.isNull()) { // get session value const char* session = cookie["value"]->getString(); // lock to modify sessions mSessionLock.lock(); { // ensure the session is valid before removing it from the session // manager (which is different from simply deleting the cookies on // the client ... which is always permitted) SessionMap::iterator i = mSessions.find(session); if(i != mSessions.end()) { InternetAddress ip; if(action->getClientInternetAddress(&ip) && strcmp(ip.getAddress(), i->second.ip.c_str()) == 0) { // session valid, IP matches, so remove it const char* tmp = i->first; mSessions.erase(i); free((char*)tmp); } } } mSessionLock.unlock(); } // delete cookies in response header jar.deleteCookie("bitmunk-session", COOKIES_SECURE); jar.deleteCookie("bitmunk-user-id", COOKIES_SECURE); jar.deleteCookie("bitmunk-username", COOKIES_SECURE); header = action->getResponse()->getHeader(); jar.writeCookies(header, CookieJar::Server, false); }
CGI* CGI::addCookie(QString strName, QString strValue, QDateTime qdtExpiration, QString strDomain, QString strPath, bool bHttpOnly, bool bSecure) { // Iterate over the existing new cookies for (int intCookie = 0; intCookie < this->mNewCookies.size(); ++intCookie) { // Localize the cookie Cookie structNewCookie = this->mNewCookies.at(intCookie); // Check the name if (structNewCookie.getName() == strName) { // Delete the cookie this->mNewCookies.removeAt(intCookie); // We're done break; } } // Create the new structure Cookie structNewCookie(strName, strValue, qdtExpiration, strDomain, strPath, bHttpOnly, bSecure); // Add the cookie to the instance this->mNewCookies.append(structNewCookie); // Return the instance return this; }
static status_t nfs4_close(fs_volume* volume, fs_vnode* vnode, void* _cookie) { VnodeToInode* vti = reinterpret_cast<VnodeToInode*>(vnode->private_node); TRACE("volume = %p, vnode = %" B_PRIi64 ", cookie = %p", volume, vti->ID(), _cookie); VnodeToInodeLocker _(vti); Inode* inode = vti->Get(); if (inode == NULL) return B_ENTRY_NOT_FOUND; if (inode->Type() == S_IFDIR || inode->Type() == S_IFLNK) return B_OK; Cookie* cookie = reinterpret_cast<Cookie*>(_cookie); return cookie->CancelAll(); }
void CookiePath::RemoveNonPersistentCookies() { time_t this_time = (time_t) (g_op_time_info->GetTimeUTC()/1000.0); Cookie* ck = (Cookie*) cookie_list.First(); while (ck) { Cookie *ck1 = ck->Suc(); if (!ck->Persistent(this_time)) { OP_DELETE(ck); } ck = ck1; } CookiePath* cp = (CookiePath*) FirstChild(); while (cp) { cp->RemoveNonPersistentCookies(); cp = cp->Suc(); } }
XtrazRequestPacket::XtrazRequestPacket(IcqContact *contact, const QString &query, const QString ¬ify) { QString body; { QXmlStreamWriter xml(&body); xml.writeStartElement("N"); xml.writeStartElement("QUERY"); xml.writeCharacters(query); xml.writeEndElement(); xml.writeStartElement("NOTIFY"); xml.writeCharacters(notify); xml.writeEndElement(); xml.writeEndElement(); } XtrazData data(body); Cookie cookie = data.cookie(); cookie.setContact(contact); setCookie(cookie); init(contact, 2, cookie); appendTLV(0x05, Channel2MessageData(1, data).data()); appendTLV(0x03); }
OP_STATUS CookiePath::BuildCookieList(Cookie ** cookieArray, int * pos, char * pathstr, CookieDomain *domainHolder, BOOL is_export, BOOL match_subpaths/*=FALSE*/) { char* pathstrcopy = pathstr; if(!match_subpaths && path.HasContent() && pathstr && *pathstr) { int p_len = path.Length(); if(path.Compare(pathstr,p_len) != 0) return OpStatus::OK; pathstr += p_len; // Remove first part, if path found if(*pathstr == '/') pathstr++; } Cookie *ck = (Cookie*)cookie_list.First(); if( ck ) { if(match_subpaths && pathstrcopy && *pathstrcopy) //if a path was specified { OpString8 fullpath; RETURN_IF_ERROR(GetFullPath(fullpath)); // get the full path //the internal root part does not start with /, so get rid of it fullpath.Delete(0,1); int pathlen = fullpath.Length(); if(!pathlen || (pathlen && fullpath.Compare(pathstrcopy, pathlen) == 0)) //compare against the full path length since we want subpaths, root has null length ck->BuildCookieList(cookieArray, pos, domainHolder, this, is_export); } else ck->BuildCookieList(cookieArray, pos, domainHolder, this, is_export); } CookiePath *cp = (CookiePath*)FirstChild(); while(cp) { cp->BuildCookieList(cookieArray, pos, pathstr, domainHolder, is_export, match_subpaths); cp = cp->Suc(); } return OpStatus::OK; }
string CookieList::escapeCookies() const { string cookie_parameter(""); bool first = true; auto it = cookie_list_.cbegin(); while(it != cookie_list_.cend()) { if(first == true) { first = false; } else { cookie_parameter += ";"; } Cookie cookie = (*it); cookie_parameter += (cookie.getName() + "=" + cookie.getValue()); ++it; } return cookie_parameter; }
// ----------------------------------- bool CookieList::add(Cookie &c) { if (contains(c)) return false; unsigned int oldestTime=(unsigned int)-1; int oldestIndex=0; for(int i=0; i<MAX_COOKIES; i++) if (list[i].time <= oldestTime) { oldestIndex = i; oldestTime = list[i].time; } c.logDebug("Added cookie",oldestIndex); c.time = sys->getTime(); list[oldestIndex]=c; return true; }