[CF] Upstream CFNetwork-related WebKitSystemInterface functions
[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 @end
105
106 @interface NSURLResponse ()
107 + (NSURLResponse *)_responseWithCFURLResponse:(CFURLResponseRef)response;
108 - (CFURLResponseRef)_CFURLResponse;
109 - (NSDate *)_lastModifiedDate;
110 @end
111
112 @interface NSURLSessionTask (TimingData)
113 - (NSDictionary *)_timingData;
114 @end
115
116 @interface NSHTTPCookie ()
117 - (CFHTTPCookieRef)_CFHTTPCookie;
118 + (CFArrayRef __nullable)_ns2cfCookies:(NSArray * __nullable)nsCookies CF_RETURNS_RETAINED;
119 - (CFHTTPCookieRef __nullable)_GetInternalCFHTTPCookie;
120 @end
121
122 @interface NSURLSessionConfiguration ()
123 @property (assign) _TimingDataOptions _timingDataOptions;
124 @property (copy) NSData *_sourceApplicationAuditTokenData;
125 @property (nullable, copy) NSString *_sourceApplicationBundleIdentifier;
126 @property (nullable, copy) NSString *_sourceApplicationSecondaryIdentifier;
127 @property BOOL _shouldSkipPreferredClientCertificateLookup NS_AVAILABLE(10_10, 8_0);
128 #if PLATFORM(IOS)
129 @property (nullable, copy) NSString *_CTDataConnectionServiceType;
130 #endif
131 @end
132
133 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
134 @interface NSURLSessionTaskTransactionMetrics ()
135 @property (copy, readonly) NSString* _remoteAddressAndPort;
136 @property (copy, readonly) NSUUID* _connectionIdentifier;
137 @property (assign, readonly) NSInteger _requestHeaderBytesSent;
138 @property (assign, readonly) NSInteger _responseHeaderBytesReceived;
139 @property (assign, readonly) int64_t _responseBodyBytesReceived;
140 @property (assign, readonly) int64_t _responseBodyBytesDecoded;
141 @end
142 #endif
143
144 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || PLATFORM(IOS)
145 @interface NSHTTPCookie ()
146 @property (nullable, readonly, copy) NSString *_storagePartition;
147 @end
148
149 @interface NSHTTPCookieStorage ()
150 - (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
151 @end
152
153 @interface NSURLSessionTask ()
154 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
155 @property (copy) NSString *_storagePartitionIdentifier;
156 @end
157 #endif
158
159 #endif // defined(__OBJC__)
160
161 #endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
162
163 WTF_EXTERN_C_BEGIN
164
165 #if !PLATFORM(WIN)
166
167 CFURLStorageSessionRef _CFURLStorageSessionCreate(CFAllocatorRef, CFStringRef, CFDictionaryRef);
168 CFURLCacheRef _CFURLStorageSessionCopyCache(CFAllocatorRef, CFURLStorageSessionRef);
169
170 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
171
172 CFURLCacheRef CFURLCacheCopySharedURLCache();
173 void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
174 CFIndex CFURLCacheMemoryCapacity(CFURLCacheRef);
175 void CFURLCacheSetDiskCapacity(CFURLCacheRef, CFIndex);
176 CFCachedURLResponseRef CFURLCacheCopyResponseForRequest(CFURLCacheRef, CFURLRequestRef);
177
178 #if PLATFORM(COCOA)
179 Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
180 void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
181 #endif
182
183 void CFHTTPCookieStorageDeleteAllCookies(CFHTTPCookieStorageRef);
184 void _CFHTTPCookieStorageFlushCookieStores();
185
186 #if PLATFORM(COCOA)
187 CFDataRef _CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef);
188 #endif
189
190 #if PLATFORM(COCOA) && defined(__BLOCKS__)
191 void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
192 #endif
193
194 extern CFStringRef const kCFHTTPCookieLocalFileDomain;
195 extern const CFStringRef kCFHTTPVersion1_1;
196 extern const CFStringRef kCFURLRequestAllowAllPOSTCaching;
197 extern const CFStringRef _kCFURLCachePartitionKey;
198 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
199 extern const CFStringRef _kCFURLStorageSessionIsPrivate;
200
201 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
202 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromFile(CFAllocatorRef, CFURLRef, CFHTTPCookieStorageRef);
203 void CFHTTPCookieStorageScheduleWithRunLoop(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef);
204 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
205 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
206 CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
207
208 typedef void (*CFHTTPCookieStorageChangedProcPtr)(CFHTTPCookieStorageRef, void*);
209 void CFHTTPCookieStorageAddObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
210 void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
211
212 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
213 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
214 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
215 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
216 void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
217 void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
218 void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
219 void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
220 CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
221 CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
222 CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
223 CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
224 CFURLRef CFURLResponseGetURL(CFURLResponseRef);
225 void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
226 CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
227 CFArrayRef _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inURL, CFURLRef inMainDocumentURL, Boolean sendSecureCookies);
228 CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef);
229 SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef);
230 CFTypeID CFURLResponseGetTypeID();
231 Boolean CFURLRequestShouldHandleHTTPCookies(CFURLRequestRef);
232 CFURLRef CFURLRequestGetURL(CFURLRequestRef);
233 CFURLResponseRef CFURLResponseCreate(CFAllocatorRef, CFURLRef, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy);
234 void CFURLResponseSetExpectedContentLength(CFURLResponseRef, SInt64 length);
235 CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef, CFURLRef, CFHTTPMessageRef, CFURLCacheStoragePolicy);
236 CFArrayRef CFHTTPCookieStorageCopyCookies(CFHTTPCookieStorageRef);
237 void CFHTTPCookieStorageSetCookies(CFHTTPCookieStorageRef, CFArrayRef cookies, CFURLRef, CFURLRef mainDocumentURL);
238 void CFHTTPCookieStorageDeleteCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
239 CFMutableURLRequestRef CFURLRequestCreateMutableCopy(CFAllocatorRef, CFURLRequestRef);
240 CFStringRef _CFURLCacheCopyCacheDirectory(CFURLCacheRef);
241 Boolean _CFHostIsDomainTopLevel(CFStringRef domain);
242 void _CFURLRequestCreateArchiveList(CFAllocatorRef, CFURLRequestRef, CFIndex* version, CFTypeRef** objects, CFIndex* objectCount, CFDictionaryRef* protocolProperties);
243 CFMutableURLRequestRef _CFURLRequestCreateFromArchiveList(CFAllocatorRef, CFIndex version, CFTypeRef* objects, CFIndex objectCount, CFDictionaryRef protocolProperties);
244
245 #endif // !PLATFORM(WIN)
246
247 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxy;
248 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyHost;
249 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyPort;
250 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTAdditionalHeaders;
251 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTResponse;
252
253 CFN_EXPORT void _CFHTTPMessageSetResponseURL(CFHTTPMessageRef, CFURLRef);
254 CFN_EXPORT void _CFHTTPMessageSetResponseProxyURL(CFHTTPMessageRef, CFURLRef);
255
256 WTF_EXTERN_C_END
257
258 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
259
260 enum : NSUInteger {
261     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
262 };
263
264 @interface NSCachedURLResponse ()
265 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
266 -(CFCachedURLResponseRef)_CFCachedURLResponse;
267 @end
268
269 #endif
270
271 WTF_EXTERN_C_BEGIN
272
273 CFDataRef _CFNetworkCopyATSContext(void);
274 Boolean _CFNetworkSetATSContext(CFDataRef);
275
276 #if PLATFORM(COCOA)
277 void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
278 #endif
279
280 CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
281 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
282 CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
283
284 WTF_EXTERN_C_END
285
286 #if defined(__OBJC__)
287
288 @interface NSHTTPCookie ()
289 #if PLATFORM(MAC)
290 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
291 #endif
292 + (NSArray *)_cf2nsCookies:(CFArrayRef)cfCookies;
293 @end
294
295 #if !USE(APPLE_INTERNAL_SDK)
296 @interface NSHTTPCookieStorage ()
297 - (void)removeCookiesSinceDate:(NSDate *)date;
298 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
299 - (CFHTTPCookieStorageRef)_cookieStorage;
300 - (void)_saveCookies;
301 @end
302 #endif
303
304 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
305 @interface NSHTTPCookieStorage ()
306 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
307 @end
308
309 @interface NSURLResponse ()
310 - (void)_setMIMEType:(NSString *)type;
311 @end
312
313 #endif // defined(__OBJC__)