Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
audacity::network_manager::Cookie Struct Referencefinal

#include <CookiesList.h>

Collaboration diagram for audacity::network_manager::Cookie:
[legend]

Public Member Functions

bool isSession () const noexcept
 
bool isExpired () const noexcept
 
std::string toString (bool fullString) const
 

Static Public Member Functions

static Cookie Parse (const std::string &cookieString)
 

Public Attributes

std::string Name
 
std::string Value
 
ExpiresTime Expires {}
 

Detailed Description

Definition at line 26 of file CookiesList.h.

Member Function Documentation

◆ isExpired()

bool Cookie::isExpired ( ) const
noexcept

Definition at line 99 of file CookiesList.cpp.

100{
101 return !isSession() &&
102 std::chrono::system_clock::now() >= Expires;
103}

References Expires, and isSession().

Here is the call graph for this function:

◆ isSession()

bool Cookie::isSession ( ) const
noexcept

Definition at line 79 of file CookiesList.cpp.

80{
81 return Expires == ExpiresTime {};
82}
std::chrono::system_clock::time_point ExpiresTime
Definition: CookiesList.h:24

References Expires.

Referenced by isExpired(), and toString().

Here is the caller graph for this function:

◆ Parse()

Cookie Cookie::Parse ( const std::string &  cookieString)
static

Definition at line 38 of file CookiesList.cpp.

39{
40 const size_t equalsPosition = cookieString.find ('=');
41
42 if (equalsPosition == std::string::npos)
43 return { cookieString, std::string () };
44
45 std::string name = cookieString.substr (0, equalsPosition);
46
47 const size_t firstValueIndex = equalsPosition + 1;
48
49 const size_t semicolonPosition = cookieString.find (';', firstValueIndex);
50
51 Cookie cookie;
52
53 cookie.Name = std::move (name);
54 cookie.Value = semicolonPosition == std::string::npos ?
55 cookieString.substr (firstValueIndex) :
56 cookieString.substr (firstValueIndex, semicolonPosition - firstValueIndex);
57
58 size_t expiresPosition = cookieString.find("Expires=");
59
60 if (expiresPosition != std::string::npos)
61 {
62 expiresPosition += std::strlen ("Expires=");
63
64 const size_t trailingSemicolon = cookieString.find (';', expiresPosition);
65
66 std::string expiresValue =
67 trailingSemicolon == std::string::npos ?
68 cookieString.substr (expiresPosition) :
69 cookieString.substr (expiresPosition, trailingSemicolon - expiresPosition);
70
71 // Hack around Yandex violating RFC
72 std::replace (expiresValue.begin(), expiresValue.end(), '-', ' ');
73 ParseRFC822Date (expiresValue, &cookie.Expires);
74 }
75
76 return cookie;
77}
const TranslatableString name
Definition: Distortion.cpp:76
constexpr size_t npos(-1)
bool ParseRFC822Date(const std::string &dateString, SystemTime *time)

References Expires, Name, name, Tuple::detail::npos(), audacity::ParseRFC822Date(), and Value.

Referenced by audacity::network_manager::CurlResponse::HeaderCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

std::string Cookie::toString ( bool  fullString) const

Definition at line 84 of file CookiesList.cpp.

85{
86 std::ostringstream stream;
87
88 stream << Name << "=" << Value;
89
90 if (fullString)
91 {
92 if (!isSession())
93 stream << "; " << "Expires=" << SerializeRFC822Date(Expires);
94 }
95
96 return stream.str ();
97}
std::string SerializeRFC822Date(SystemTime timePoint)

References Expires, isSession(), Name, audacity::SerializeRFC822Date(), and Value.

Here is the call graph for this function:

Member Data Documentation

◆ Expires

ExpiresTime audacity::network_manager::Cookie::Expires {}

Definition at line 31 of file CookiesList.h.

Referenced by isExpired(), isSession(), Parse(), and toString().

◆ Name

std::string audacity::network_manager::Cookie::Name

◆ Value

std::string audacity::network_manager::Cookie::Value

The documentation for this struct was generated from the following files: