17 static inline void |
17 static inline void |
18 StrBlockCopy(const nsACString &aSource1, |
18 StrBlockCopy(const nsACString &aSource1, |
19 const nsACString &aSource2, |
19 const nsACString &aSource2, |
20 const nsACString &aSource3, |
20 const nsACString &aSource3, |
21 const nsACString &aSource4, |
21 const nsACString &aSource4, |
|
22 const nsACString &aSource5, |
22 char *&aDest1, |
23 char *&aDest1, |
23 char *&aDest2, |
24 char *&aDest2, |
24 char *&aDest3, |
25 char *&aDest3, |
25 char *&aDest4, |
26 char *&aDest4, |
|
27 char *&aDest5, |
26 char *&aDestEnd) |
28 char *&aDestEnd) |
27 { |
29 { |
28 char *toBegin = aDest1; |
30 char *toBegin = aDest1; |
29 nsACString::const_iterator fromBegin, fromEnd; |
31 nsACString::const_iterator fromBegin, fromEnd; |
30 |
32 |
33 *copy_string(aSource2.BeginReading(fromBegin), aSource2.EndReading(fromEnd), toBegin) = char(0); |
35 *copy_string(aSource2.BeginReading(fromBegin), aSource2.EndReading(fromEnd), toBegin) = char(0); |
34 aDest3 = ++toBegin; |
36 aDest3 = ++toBegin; |
35 *copy_string(aSource3.BeginReading(fromBegin), aSource3.EndReading(fromEnd), toBegin) = char(0); |
37 *copy_string(aSource3.BeginReading(fromBegin), aSource3.EndReading(fromEnd), toBegin) = char(0); |
36 aDest4 = ++toBegin; |
38 aDest4 = ++toBegin; |
37 *copy_string(aSource4.BeginReading(fromBegin), aSource4.EndReading(fromEnd), toBegin) = char(0); |
39 *copy_string(aSource4.BeginReading(fromBegin), aSource4.EndReading(fromEnd), toBegin) = char(0); |
|
40 aDest5 = ++toBegin; |
|
41 *copy_string(aSource5.BeginReading(fromBegin), aSource5.EndReading(fromEnd), toBegin) = char(0); |
38 aDestEnd = toBegin; |
42 aDestEnd = toBegin; |
39 } |
43 } |
40 |
44 |
41 /****************************************************************************** |
45 /****************************************************************************** |
42 * nsCookie: |
46 * nsCookie: |
68 |
72 |
69 nsCookie * |
73 nsCookie * |
70 nsCookie::Create(const nsACString &aName, |
74 nsCookie::Create(const nsACString &aName, |
71 const nsACString &aValue, |
75 const nsACString &aValue, |
72 const nsACString &aHost, |
76 const nsACString &aHost, |
|
77 const nsACString &aOrigin, |
73 const nsACString &aPath, |
78 const nsACString &aPath, |
74 int64_t aExpiry, |
79 int64_t aExpiry, |
75 int64_t aLastAccessed, |
80 int64_t aLastAccessed, |
76 int64_t aCreationTime, |
81 int64_t aCreationTime, |
77 bool aIsSession, |
82 bool aIsSession, |
82 // truncate the string after the first invalid octet. |
87 // truncate the string after the first invalid octet. |
83 nsUTF8ConverterService converter; |
88 nsUTF8ConverterService converter; |
84 nsAutoCString aUTF8Value; |
89 nsAutoCString aUTF8Value; |
85 converter.ConvertStringToUTF8(aValue, "UTF-8", false, true, 1, aUTF8Value); |
90 converter.ConvertStringToUTF8(aValue, "UTF-8", false, true, 1, aUTF8Value); |
86 |
91 |
87 // find the required string buffer size, adding 4 for the terminating nulls |
92 // find the required string buffer size, accommodating terminating nulls |
88 const uint32_t stringLength = aName.Length() + aUTF8Value.Length() + |
93 const uint32_t stringLength = aName.Length() + aUTF8Value.Length() + |
89 aHost.Length() + aPath.Length() + 4; |
94 aHost.Length() + aOrigin.Length() + |
|
95 aPath.Length() + 5; |
90 |
96 |
91 // allocate contiguous space for the nsCookie and its strings - |
97 // allocate contiguous space for the nsCookie and its strings - |
92 // we store the strings in-line with the nsCookie to save allocations |
98 // we store the strings in-line with the nsCookie to save allocations |
93 void *place = ::operator new(sizeof(nsCookie) + stringLength); |
99 void *place = ::operator new(sizeof(nsCookie) + stringLength); |
94 if (!place) |
100 if (!place) |
95 return nullptr; |
101 return nullptr; |
96 |
102 |
97 // assign string members |
103 // assign string members |
98 char *name, *value, *host, *path, *end; |
104 char *name, *value, *host, *origin, *path, *end; |
99 name = static_cast<char *>(place) + sizeof(nsCookie); |
105 name = static_cast<char *>(place) + sizeof(nsCookie); |
100 StrBlockCopy(aName, aUTF8Value, aHost, aPath, |
106 StrBlockCopy(aName, aUTF8Value, aHost, aOrigin, aPath, |
101 name, value, host, path, end); |
107 name, value, host, origin, path, end); |
102 |
108 |
103 // If the creationTime given to us is higher than the running maximum, update |
109 // If the creationTime given to us is higher than the running maximum, update |
104 // our maximum. |
110 // our maximum. |
105 if (aCreationTime > gLastCreationTime) |
111 if (aCreationTime > gLastCreationTime) |
106 gLastCreationTime = aCreationTime; |
112 gLastCreationTime = aCreationTime; |
107 |
113 |
108 // construct the cookie. placement new, oh yeah! |
114 // construct the cookie. placement new, oh yeah! |
109 return new (place) nsCookie(name, value, host, path, end, |
115 return new (place) nsCookie(name, value, host, origin, path, end, |
110 aExpiry, aLastAccessed, aCreationTime, |
116 aExpiry, aLastAccessed, aCreationTime, |
111 aIsSession, aIsSecure, aIsHttpOnly); |
117 aIsSession, aIsSecure, aIsHttpOnly); |
112 } |
118 } |
113 |
119 |
114 size_t |
120 size_t |
125 ******************************************************************************/ |
131 ******************************************************************************/ |
126 |
132 |
127 // xpcom getters |
133 // xpcom getters |
128 NS_IMETHODIMP nsCookie::GetName(nsACString &aName) { aName = Name(); return NS_OK; } |
134 NS_IMETHODIMP nsCookie::GetName(nsACString &aName) { aName = Name(); return NS_OK; } |
129 NS_IMETHODIMP nsCookie::GetValue(nsACString &aValue) { aValue = Value(); return NS_OK; } |
135 NS_IMETHODIMP nsCookie::GetValue(nsACString &aValue) { aValue = Value(); return NS_OK; } |
|
136 NS_IMETHODIMP nsCookie::GetOrigin(nsACString &aOrigin) { aOrigin = Origin(); return NS_OK; } |
130 NS_IMETHODIMP nsCookie::GetHost(nsACString &aHost) { aHost = Host(); return NS_OK; } |
137 NS_IMETHODIMP nsCookie::GetHost(nsACString &aHost) { aHost = Host(); return NS_OK; } |
131 NS_IMETHODIMP nsCookie::GetRawHost(nsACString &aHost) { aHost = RawHost(); return NS_OK; } |
138 NS_IMETHODIMP nsCookie::GetRawHost(nsACString &aHost) { aHost = RawHost(); return NS_OK; } |
132 NS_IMETHODIMP nsCookie::GetPath(nsACString &aPath) { aPath = Path(); return NS_OK; } |
139 NS_IMETHODIMP nsCookie::GetPath(nsACString &aPath) { aPath = Path(); return NS_OK; } |
133 NS_IMETHODIMP nsCookie::GetExpiry(int64_t *aExpiry) { *aExpiry = Expiry(); return NS_OK; } |
140 NS_IMETHODIMP nsCookie::GetExpiry(int64_t *aExpiry) { *aExpiry = Expiry(); return NS_OK; } |
134 NS_IMETHODIMP nsCookie::GetIsSession(bool *aIsSession) { *aIsSession = IsSession(); return NS_OK; } |
141 NS_IMETHODIMP nsCookie::GetIsSession(bool *aIsSession) { *aIsSession = IsSession(); return NS_OK; } |