58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
- (void)addCookie: (OFHTTPCookie *)cookie
forURL: (OFURL *)URL
{
void *pool = objc_autoreleasePoolPush();
OFString *cookieDomain, *URLHost;
size_t i;
if (![[cookie path] hasPrefix: @"/"])
[cookie setPath: @"/"];
if ([cookie isSecure] && ![[URL scheme] isEqual: @"https"]) {
objc_autoreleasePoolPop(pool);
return;
}
cookieDomain = [[cookie domain] lowercaseString];
[cookie setDomain: cookieDomain];
URLHost = [[URL host] lowercaseString];
if (![cookieDomain isEqual: URLHost]) {
URLHost = [@"." stringByAppendingString: URLHost];
if (![cookieDomain hasSuffix: URLHost]) {
objc_autoreleasePoolPop(pool);
return;
}
}
i = 0;
for (OFHTTPCookie *iter in _cookies) {
if ([[iter name] isEqual: [cookie name]] &&
[[iter domain] isEqual: [cookie domain]] &&
[[iter path] isEqual: [cookie path]]) {
[_cookies replaceObjectAtIndex: i
withObject: cookie];
objc_autoreleasePoolPop(pool);
return;
}
|
|
|
|
|
|
|
|
|
|
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
- (void)addCookie: (OFHTTPCookie *)cookie
forURL: (OFURL *)URL
{
void *pool = objc_autoreleasePoolPush();
OFString *cookieDomain, *URLHost;
size_t i;
if (![cookie.path hasPrefix: @"/"])
cookie.path = @"/";
if (cookie.secure && ![URL.scheme isEqual: @"https"]) {
objc_autoreleasePoolPop(pool);
return;
}
cookieDomain = cookie.domain.lowercaseString;
cookie.domain = cookieDomain;
URLHost = URL.host.lowercaseString;
if (![cookieDomain isEqual: URLHost]) {
URLHost = [@"." stringByAppendingString: URLHost];
if (![cookieDomain hasSuffix: URLHost]) {
objc_autoreleasePoolPop(pool);
return;
}
}
i = 0;
for (OFHTTPCookie *iter in _cookies) {
if ([iter.name isEqual: cookie.name] &&
[iter.domain isEqual: cookie.domain] &&
[iter.path isEqual: cookie.path]) {
[_cookies replaceObjectAtIndex: i
withObject: cookie];
objc_autoreleasePoolPop(pool);
return;
}
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
for (OFHTTPCookie *cookie in _cookies) {
void *pool;
OFDate *expires;
OFString *cookieDomain, *URLHost, *cookiePath, *URLPath;
bool match;
expires = [cookie expires];
if (expires != nil && [expires timeIntervalSinceNow] <= 0)
continue;
if ([cookie isSecure] && ![[URL scheme] isEqual: @"https"])
continue;
pool = objc_autoreleasePoolPush();
cookieDomain = [[cookie domain] lowercaseString];
URLHost = [[URL host] lowercaseString];
if ([cookieDomain hasPrefix: @"."]) {
if ([URLHost hasSuffix: cookieDomain])
match = true;
else {
cookieDomain = [cookieDomain substringWithRange:
of_range(1, [cookieDomain length] - 1)];
match = [cookieDomain isEqual: URLHost];
}
} else
match = [cookieDomain isEqual: URLHost];
if (!match) {
objc_autoreleasePoolPop(pool);
continue;
}
cookiePath = [cookie path];
URLPath = [URL path];
if (![cookiePath isEqual: @"/"]) {
if ([cookiePath isEqual: URLPath])
match = true;
else {
if (![cookiePath hasSuffix: @"/"])
cookiePath = [cookiePath
stringByAppendingString: @"/"];
|
|
|
|
|
|
|
|
|
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
for (OFHTTPCookie *cookie in _cookies) {
void *pool;
OFDate *expires;
OFString *cookieDomain, *URLHost, *cookiePath, *URLPath;
bool match;
expires = cookie.expires;
if (expires != nil && expires.timeIntervalSinceNow <= 0)
continue;
if (cookie.secure && ![URL.scheme isEqual: @"https"])
continue;
pool = objc_autoreleasePoolPush();
cookieDomain = cookie.domain.lowercaseString;
URLHost = URL.host.lowercaseString;
if ([cookieDomain hasPrefix: @"."]) {
if ([URLHost hasSuffix: cookieDomain])
match = true;
else {
cookieDomain = [cookieDomain substringWithRange:
of_range(1, cookieDomain.length - 1)];
match = [cookieDomain isEqual: URLHost];
}
} else
match = [cookieDomain isEqual: URLHost];
if (!match) {
objc_autoreleasePoolPop(pool);
continue;
}
cookiePath = cookie.path;
URLPath = URL.path;
if (![cookiePath isEqual: @"/"]) {
if ([cookiePath isEqual: URLPath])
match = true;
else {
if (![cookiePath hasSuffix: @"/"])
cookiePath = [cookiePath
stringByAppendingString: @"/"];
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
[ret makeImmutable];
return ret;
}
- (void)purgeExpiredCookies
{
for (size_t i = 0, count = [_cookies count]; i < count; i++) {
OFDate *expires = [[_cookies objectAtIndex: i] expires];
if (expires != nil && [expires timeIntervalSinceNow] <= 0) {
[_cookies removeObjectAtIndex: i];
i--;
count--;
continue;
}
}
}
@end
|
|
|
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
[ret makeImmutable];
return ret;
}
- (void)purgeExpiredCookies
{
for (size_t i = 0, count = _cookies.count; i < count; i++) {
OFDate *expires = [[_cookies objectAtIndex: i] expires];
if (expires != nil && expires.timeIntervalSinceNow <= 0) {
[_cookies removeObjectAtIndex: i];
i--;
count--;
continue;
}
}
}
@end
|