0ae80c787b8e81b9a84f01b916b8bf74a932df3c
[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 _kCFURLConnectionPropertyShouldSniff;
198 extern const CFStringRef _kCFURLStorageSessionIsPrivate;
199
200 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
201 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromFile(CFAllocatorRef, CFURLRef, CFHTTPCookieStorageRef);
202 void CFHTTPCookieStorageScheduleWithRunLoop(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef);
203 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
204 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
205 CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
206
207 typedef void (*CFHTTPCookieStorageChangedProcPtr)(CFHTTPCookieStorageRef, void*);
208 void CFHTTPCookieStorageAddObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
209 void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
210
211 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
212 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
213 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
214 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
215 void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
216 void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
217 void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
218 void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
219 CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
220 CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
221 CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
222 CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
223 CFURLRef CFURLResponseGetURL(CFURLResponseRef);
224 void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
225 CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
226 CFArrayRef _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inURL, CFURLRef inMainDocumentURL, Boolean sendSecureCookies);
227 CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef);
228 SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef);
229 CFTypeID CFURLResponseGetTypeID();
230 Boolean CFURLRequestShouldHandleHTTPCookies(CFURLRequestRef);
231 CFURLRef CFURLRequestGetURL(CFURLRequestRef);
232 CFURLResponseRef CFURLResponseCreate(CFAllocatorRef, CFURLRef, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy);
233 void CFURLResponseSetExpectedContentLength(CFURLResponseRef, SInt64 length);
234 CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef, CFURLRef, CFHTTPMessageRef, CFURLCacheStoragePolicy);
235 CFArrayRef CFHTTPCookieStorageCopyCookies(CFHTTPCookieStorageRef);
236 void CFHTTPCookieStorageSetCookies(CFHTTPCookieStorageRef, CFArrayRef cookies, CFURLRef, CFURLRef mainDocumentURL);
237 void CFHTTPCookieStorageDeleteCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
238 CFMutableURLRequestRef CFURLRequestCreateMutableCopy(CFAllocatorRef, CFURLRequestRef);
239
240 #endif // !PLATFORM(WIN)
241
242 WTF_EXTERN_C_END
243
244 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
245
246 enum : NSUInteger {
247     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
248 };
249
250 @interface NSCachedURLResponse ()
251 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
252 -(CFCachedURLResponseRef)_CFCachedURLResponse;
253 @end
254
255 #endif
256
257 WTF_EXTERN_C_BEGIN
258
259 CFDataRef _CFNetworkCopyATSContext(void);
260 Boolean _CFNetworkSetATSContext(CFDataRef);
261
262 #if PLATFORM(COCOA)
263 void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
264 #endif
265
266 CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
267 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
268 CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
269
270 WTF_EXTERN_C_END
271
272 #if defined(__OBJC__)
273
274 @interface NSHTTPCookie ()
275 #if PLATFORM(MAC)
276 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
277 #endif
278 + (NSArray *)_cf2nsCookies:(CFArrayRef)cfCookies;
279 @end
280
281 #if !USE(APPLE_INTERNAL_SDK)
282 @interface NSHTTPCookieStorage ()
283 - (void)removeCookiesSinceDate:(NSDate *)date;
284 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
285 - (CFHTTPCookieStorageRef)_cookieStorage;
286 - (void)_saveCookies;
287 @end
288 #endif
289
290 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
291 @interface NSHTTPCookieStorage ()
292 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
293 @end
294
295 @interface NSURLResponse ()
296 - (void)_setMIMEType:(NSString *)type;
297 @end
298
299 #endif // defined(__OBJC__)