0acc89fbf9b64516965671a9681eab916a610437
[WebKit-https.git] / Source / WebCore / PAL / pal / spi / cf / CFNetworkSPI.h
1 /*
2  * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma clang system_header
27
28 #pragma once
29
30 #include <CFNetwork/CFNetwork.h>
31 #include <pal/spi/cf/CFNetworkConnectionCacheSPI.h>
32
33 #if PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
34
35 #include <CFNetwork/CFHTTPCookiesPriv.h>
36 #include <CFNetwork/CFProxySupportPriv.h>
37 #include <CFNetwork/CFURLCachePriv.h>
38 #include <CFNetwork/CFURLConnectionPriv.h>
39 #include <CFNetwork/CFURLCredentialStorage.h>
40 #include <CFNetwork/CFURLProtocolPriv.h>
41 #include <CFNetwork/CFURLRequestPriv.h>
42 #include <CFNetwork/CFURLResponsePriv.h>
43 #include <CFNetwork/CFURLStorageSession.h>
44
45 // FIXME: Remove the defined(__OBJC__)-guard once we fix <rdar://problem/19033610>.
46 #if defined(__OBJC__) && PLATFORM(COCOA)
47 #import <CFNetwork/CFNSURLConnection.h>
48 #endif
49
50 #else // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
51
52 typedef CF_ENUM(int64_t, _TimingDataOptions)
53 {
54     _TimingDataOptionsEnableW3CNavigationTiming = (1 << 0)
55 };
56
57 enum CFURLCacheStoragePolicy {
58     kCFURLCacheStorageAllowed = 0,
59     kCFURLCacheStorageAllowedInMemoryOnly = 1,
60     kCFURLCacheStorageNotAllowed = 2
61 };
62 typedef enum CFURLCacheStoragePolicy CFURLCacheStoragePolicy;
63
64 typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
65 typedef const struct _CFURLCache* CFURLCacheRef;
66 typedef const struct _CFURLCredential* CFURLCredentialRef;
67 typedef const struct _CFURLRequest* CFURLRequestRef;
68 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
69 typedef const struct __CFData* CFDataRef;
70 typedef const struct OpaqueCFHTTPCookie* CFHTTPCookieRef;
71 typedef struct _CFURLConnection* CFURLConnectionRef;
72 typedef struct _CFURLCredentialStorage* CFURLCredentialStorageRef;
73 typedef struct _CFURLProtectionSpace* CFURLProtectionSpaceRef;
74 typedef struct _CFURLRequest* CFMutableURLRequestRef;
75 typedef struct _CFURLResponse* CFURLResponseRef;
76 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
77 typedef CFIndex CFURLRequestPriority;
78 typedef int CFHTTPCookieStorageAcceptPolicy;
79
80 #ifdef __BLOCKS__
81 typedef void (^CFCachedURLResponseCallBackBlock)(CFCachedURLResponseRef);
82 #endif
83
84 #if defined(__OBJC__)
85
86 @interface NSURLCache ()
87 -(instancetype)_initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity relativePath:(NSString *)path;
88 - (CFURLCacheRef)_CFURLCache;
89 @end
90
91 @interface NSURLRequest ()
92 + (NSArray *)allowsSpecificHTTPSCertificateForHost:(NSString *)host;
93 + (void)setAllowsSpecificHTTPSCertificate:(NSArray *)allow forHost:(NSString *)host;
94 + (void)setDefaultTimeoutInterval:(NSTimeInterval)seconds;
95 - (NSArray *)contentDispositionEncodingFallbackArray;
96 - (CFURLRequestRef)_CFURLRequest;
97 - (id)_initWithCFURLRequest:(CFURLRequestRef)request;
98 - (id)_propertyForKey:(NSString *)key;
99 - (void)_setProperty:(id)value forKey:(NSString *)key;
100 @end
101
102 @interface NSMutableURLRequest ()
103 - (void)setContentDispositionEncodingFallbackArray:(NSArray *)theEncodingFallbackArray;
104 - (void)setBoundInterfaceIdentifier:(NSString *)identifier;
105 @end
106
107 @interface NSURLResponse ()
108 + (NSURLResponse *)_responseWithCFURLResponse:(CFURLResponseRef)response;
109 - (CFURLResponseRef)_CFURLResponse;
110 - (NSDate *)_lastModifiedDate;
111 @end
112
113 @interface NSURLSessionTask (TimingData)
114 - (NSDictionary *)_timingData;
115 @end
116
117 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
118 @interface NSURLSessionTask (ResourceHints)
119 @property (nonatomic, assign) BOOL _preconnect;
120 @end
121 #endif
122
123 @interface NSHTTPCookie ()
124 - (CFHTTPCookieRef)_CFHTTPCookie;
125 + (CFArrayRef __nullable)_ns2cfCookies:(NSArray * __nullable)nsCookies CF_RETURNS_RETAINED;
126 - (CFHTTPCookieRef __nullable)_GetInternalCFHTTPCookie;
127 @end
128
129 @interface NSURLSessionConfiguration ()
130 @property (assign) _TimingDataOptions _timingDataOptions;
131 @property (copy) NSData *_sourceApplicationAuditTokenData;
132 @property (nullable, copy) NSString *_sourceApplicationBundleIdentifier;
133 @property (nullable, copy) NSString *_sourceApplicationSecondaryIdentifier;
134 @property BOOL _shouldSkipPreferredClientCertificateLookup NS_AVAILABLE(10_10, 8_0);
135 #if PLATFORM(IOS)
136 @property (nullable, copy) NSString *_CTDataConnectionServiceType;
137 #endif
138 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
139 @property (nullable, copy) NSSet *_suppressedAutoAddedHTTPHeaders;
140 #endif
141 @end
142
143 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
144 @interface NSURLSessionTaskTransactionMetrics ()
145 @property (copy, readonly) NSString* _remoteAddressAndPort;
146 @property (copy, readonly) NSUUID* _connectionIdentifier;
147 @property (assign, readonly) NSInteger _requestHeaderBytesSent;
148 @property (assign, readonly) NSInteger _responseHeaderBytesReceived;
149 @property (assign, readonly) int64_t _responseBodyBytesReceived;
150 @property (assign, readonly) int64_t _responseBodyBytesDecoded;
151 @end
152 #endif
153
154 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || PLATFORM(IOS)
155 @interface NSHTTPCookie ()
156 @property (nullable, readonly, copy) NSString *_storagePartition;
157 @end
158
159 @interface NSHTTPCookieStorage ()
160 - (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
161 @end
162
163 @interface NSURLSessionTask ()
164 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
165 @property (copy) NSString *_storagePartitionIdentifier;
166 @end
167 #endif
168
169 #endif // defined(__OBJC__)
170
171 #endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
172
173 WTF_EXTERN_C_BEGIN
174
175 #if !PLATFORM(WIN)
176
177 CFURLStorageSessionRef _CFURLStorageSessionCreate(CFAllocatorRef, CFStringRef, CFDictionaryRef);
178 CFURLCacheRef _CFURLStorageSessionCopyCache(CFAllocatorRef, CFURLStorageSessionRef);
179
180 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
181
182 CFURLCacheRef CFURLCacheCopySharedURLCache();
183 void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
184 CFIndex CFURLCacheMemoryCapacity(CFURLCacheRef);
185 void CFURLCacheSetDiskCapacity(CFURLCacheRef, CFIndex);
186 CFCachedURLResponseRef CFURLCacheCopyResponseForRequest(CFURLCacheRef, CFURLRequestRef);
187
188 #if PLATFORM(COCOA)
189 Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
190 void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
191 #endif
192
193 void CFHTTPCookieStorageDeleteAllCookies(CFHTTPCookieStorageRef);
194 void _CFHTTPCookieStorageFlushCookieStores();
195
196 #if PLATFORM(COCOA)
197 CFDataRef _CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef);
198 #endif
199
200 #if PLATFORM(COCOA) && defined(__BLOCKS__)
201 void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
202 #endif
203
204 extern CFStringRef const kCFHTTPCookieLocalFileDomain;
205 extern const CFStringRef kCFHTTPVersion1_1;
206 extern const CFStringRef kCFURLRequestAllowAllPOSTCaching;
207 extern const CFStringRef _kCFURLCachePartitionKey;
208 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
209 extern const CFStringRef _kCFURLStorageSessionIsPrivate;
210
211 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101302
212 extern const CFStringRef kCFURLRequestContentDecoderSkipURLCheck;
213 #endif
214
215 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
216 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromFile(CFAllocatorRef, CFURLRef, CFHTTPCookieStorageRef);
217 void CFHTTPCookieStorageScheduleWithRunLoop(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef);
218 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
219 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
220 CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
221
222 typedef void (*CFHTTPCookieStorageChangedProcPtr)(CFHTTPCookieStorageRef, void*);
223 void CFHTTPCookieStorageAddObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
224 void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
225
226 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
227 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
228 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
229 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
230 void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
231 void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
232 void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
233 void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
234 CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
235 CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
236 CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
237 CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
238 CFURLRef CFURLResponseGetURL(CFURLResponseRef);
239 void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
240 CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
241 CFArrayRef _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inURL, CFURLRef inMainDocumentURL, Boolean sendSecureCookies);
242 CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef);
243 SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef);
244 CFTypeID CFURLResponseGetTypeID();
245 Boolean CFURLRequestShouldHandleHTTPCookies(CFURLRequestRef);
246 CFURLRef CFURLRequestGetURL(CFURLRequestRef);
247 CFURLResponseRef CFURLResponseCreate(CFAllocatorRef, CFURLRef, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy);
248 void CFURLResponseSetExpectedContentLength(CFURLResponseRef, SInt64 length);
249 CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef, CFURLRef, CFHTTPMessageRef, CFURLCacheStoragePolicy);
250 CFArrayRef CFHTTPCookieStorageCopyCookies(CFHTTPCookieStorageRef);
251 void CFHTTPCookieStorageSetCookies(CFHTTPCookieStorageRef, CFArrayRef cookies, CFURLRef, CFURLRef mainDocumentURL);
252 void CFHTTPCookieStorageDeleteCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
253 CFMutableURLRequestRef CFURLRequestCreateMutableCopy(CFAllocatorRef, CFURLRequestRef);
254 CFStringRef _CFURLCacheCopyCacheDirectory(CFURLCacheRef);
255 Boolean _CFHostIsDomainTopLevel(CFStringRef domain);
256 void _CFURLRequestCreateArchiveList(CFAllocatorRef, CFURLRequestRef, CFIndex* version, CFTypeRef** objects, CFIndex* objectCount, CFDictionaryRef* protocolProperties);
257 CFMutableURLRequestRef _CFURLRequestCreateFromArchiveList(CFAllocatorRef, CFIndex version, CFTypeRef* objects, CFIndex objectCount, CFDictionaryRef protocolProperties);
258
259 #endif // !PLATFORM(WIN)
260
261 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxy;
262 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyHost;
263 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyPort;
264 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTAdditionalHeaders;
265 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTResponse;
266
267 CFN_EXPORT void _CFHTTPMessageSetResponseURL(CFHTTPMessageRef, CFURLRef);
268 CFN_EXPORT void _CFHTTPMessageSetResponseProxyURL(CFHTTPMessageRef, CFURLRef);
269
270 WTF_EXTERN_C_END
271
272 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
273
274 enum : NSUInteger {
275     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
276 };
277
278 @interface NSCachedURLResponse ()
279 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
280 -(CFCachedURLResponseRef)_CFCachedURLResponse;
281 @end
282
283 #endif
284
285 WTF_EXTERN_C_BEGIN
286
287 CFDataRef _CFNetworkCopyATSContext(void);
288 Boolean _CFNetworkSetATSContext(CFDataRef);
289
290 #if PLATFORM(COCOA)
291 void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
292 #endif
293
294 CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
295 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
296 CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
297
298 WTF_EXTERN_C_END
299
300 #if defined(__OBJC__)
301
302 @interface NSHTTPCookie ()
303 #if PLATFORM(MAC)
304 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
305 #endif
306 + (NSArray *)_cf2nsCookies:(CFArrayRef)cfCookies;
307 @end
308
309 #if !USE(APPLE_INTERNAL_SDK)
310 @interface NSHTTPCookieStorage ()
311 - (void)removeCookiesSinceDate:(NSDate *)date;
312 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
313 - (CFHTTPCookieStorageRef)_cookieStorage;
314 - (void)_saveCookies;
315 @end
316 #endif
317
318 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
319 @interface NSHTTPCookieStorage ()
320 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
321 @end
322
323 @interface NSURLResponse ()
324 - (void)_setMIMEType:(NSString *)type;
325 @end
326
327 #endif // defined(__OBJC__)