Exemple #1
0
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;
}
Exemple #2
0
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;
}
Exemple #3
0
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;
}
Exemple #4
0
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();
	}
}
Exemple #5
0
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();
	}
}
Exemple #6
0
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;
}
Exemple #7
0
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();
	}
}
Exemple #8
0
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();
	}
}
Exemple #9
0
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();
	}
}
Exemple #10
0
int	CookiePath::GetCookieRequest(
		time_t this_time,
		BOOL is_secure,
		BOOL is_server,
		unsigned short port,
		int &version,
		int &max_version,
		BOOL third_party_only,
		BOOL already_have_password,
		BOOL already_have_authentication,
		BOOL &have_password,
		BOOL &have_authentication,
		BOOL is_full_path,
		char* buf, int buf_len,
		BOOL for_http,
		BOOL allow_dollar_cookies,
		BOOL& seen_cookie2)
{
	int buf_used = 0;
	char* buf_p = buf;
	Cookie* ck = (Cookie*) cookie_list.First();
	while (ck)
	{
		Cookie* next_ck = ck->Suc();
		if (ck->Expires() && ck->Expires() < this_time)
		{
			OP_DELETE(ck);
		}
		else if ((is_secure || !ck->Secure())  &&
				(for_http || !ck->HTTPOnly()) &&
				(is_full_path || !ck->FullPathOnly())
				 && (is_server || !ck->SendOnlyToServer()) &&
				 (ck->Version() == 0 || ck->CheckPort(port)) &&
				 (!third_party_only || ck->GetAcceptedAsThirdParty()) &&
				 (allow_dollar_cookies || *ck->Name().CStr() != '$')
		)
		{

			int name_len = ck->Name().Length();
			int value_len = ck->Value().Length();

			int ver = ck->Version();
			if(version > ver)
				version = ver;

			if(ver > max_version)
				max_version = ver;

			if (ck->GetCookieType() == COOKIE2_COOKIE)
				seen_cookie2 = TRUE;

			int dom_len = (ver ? ck->Received_Domain().Length() : 0) ;
			int path_len = (ver && ck->Received_Path().HasContent() ? ck->Received_Path().Length()+1:  0) ;
			int port_len = (ver ? (ck->Port().HasContent() ? ck->Port().Length() : (ck->PortReceived() ? 1 : 0)) : 0) ;
			if ((name_len + value_len + 3 +
			    (dom_len ? dom_len + 10 : 0) +
			    (path_len ? path_len + 8 : 0) +
			    (port_len ? port_len + 8 : 0)) < buf_len - buf_used)
			{
				if (buf_used)
					BufferAppend(buf_p, "; ", 2);
				BufferAppend(buf_p, ck->Name().CStr());

				if (value_len > 0 || ck->Assigned())
				{
					*buf_p++ = '=';
					BufferAppend(buf_p, ck->Value().CStr());
				}

				if(ver > 0)
				{
					if(path_len)
					{
						BufferAppend(buf_p, "; $Path=\"");
						BufferAppend(buf_p, ck->Received_Path().CStr());
						*buf_p++ = '"';
						*buf_p = '\0';
					}
					if(dom_len)
					{
						BufferAppend(buf_p, "; $Domain=");
						BufferAppend(buf_p, ck->Received_Domain().CStr());
					}
					if(ck->PortReceived())
					{
						if(ck->Port().CStr())
						{
							BufferAppend(buf_p, "; $Port=\"");
							BufferAppend(buf_p, ck->Port().CStr());
							*buf_p++ = '"';
							*buf_p = '\0';
						}
						else
							BufferAppend(buf_p, "; $Port");
					}
				}
				if(g_pcnet->GetIntegerPref(PrefsCollectionNetwork::TagUrlsUsingPasswordRelatedCookies))
				{
					if(ck->GetHavePassword())
						have_password = TRUE;
					if(ck->GetHaveAuthentication())
						have_authentication = TRUE;
					if(already_have_password)
						ck->SetHavePassword(TRUE);
					if(already_have_authentication)
						ck->SetHaveAuthentication(TRUE);
				}
				buf_used = buf_p - buf;

				ck->SetLastUsed(this_time);
			}
		}
		ck = next_ck;
	}

	return buf_used;
}