diff options
43 files changed, 274 insertions, 206 deletions
diff --git a/Example/Podfile b/Example/Podfile index a5ad33c..6213e4f 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -8,7 +8,7 @@ target 'Core_Example_iOS' do # The next line is the forcing function for the Firebase pod. The Firebase # version's subspecs should depend on the component versions in their # corresponding podspec's. - pod 'Firebase/Core', '4.6.0' + pod 'Firebase/Core', '4.7.0' target 'Core_Tests_iOS' do inherit! :search_paths diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m index d5116ff..7300fdd 100644 --- a/Firebase/Auth/Source/FIRAuth.m +++ b/Firebase/Auth/Source/FIRAuth.m @@ -1297,6 +1297,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName; if (token.length) { internalNotificationParameters[FIRAuthStateDidChangeInternalNotificationTokenKey] = token; } + internalNotificationParameters[FIRAuthStateDidChangeInternalNotificationUIDKey] = _currentUser.uid; NSNotificationCenter *notifications = [NSNotificationCenter defaultCenter]; dispatch_async(dispatch_get_main_queue(), ^{ [notifications postNotificationName:FIRAuthStateDidChangeInternalNotification diff --git a/Firebase/Core/FIRApp.m b/Firebase/Core/FIRApp.m index 5efaa2e..835a1a4 100644 --- a/Firebase/Core/FIRApp.m +++ b/Firebase/Core/FIRApp.m @@ -60,6 +60,8 @@ NSString *const FIRAuthStateDidChangeInternalNotificationAppKey = @"FIRAuthStateDidChangeInternalNotificationAppKey"; NSString *const FIRAuthStateDidChangeInternalNotificationTokenKey = @"FIRAuthStateDidChangeInternalNotificationTokenKey"; +NSString *const FIRAuthStateDidChangeInternalNotificationUIDKey = + @"FIRAuthStateDidChangeInternalNotificationUIDKey"; /** * The URL to download plist files. diff --git a/Firebase/Core/FIROptions.m b/Firebase/Core/FIROptions.m index bde5067..841c70b 100644 --- a/Firebase/Core/FIROptions.m +++ b/Firebase/Core/FIROptions.m @@ -42,7 +42,7 @@ NSString *const kFIRIsSignInEnabled = @"IS_SIGNIN_ENABLED"; NSString *const kFIRLibraryVersionID = @"4" // Major version (one or more digits) @"00" // Minor version (exactly 2 digits) - @"11" // Build number (exactly 2 digits) + @"12" // Build number (exactly 2 digits) @"000"; // Fixed "000" // Plist file name. NSString *const kServiceInfoFileName = @"GoogleService-Info"; diff --git a/Firebase/Core/Private/FIRAppInternal.h b/Firebase/Core/Private/FIRAppInternal.h index 2a98268..447d151 100644 --- a/Firebase/Core/Private/FIRAppInternal.h +++ b/Firebase/Core/Private/FIRAppInternal.h @@ -83,6 +83,13 @@ extern NSString *const FIRAuthStateDidChangeInternalNotificationTokenKey; */ extern NSString *const FIRAuthStateDidChangeInternalNotificationAppKey; +/** @var FIRAuthStateDidChangeInternalNotificationUIDKey + @brief A key present in the dictionary object parameter of the + @c FIRAuthStateDidChangeInternalNotification notification. The value associated with this + key will contain the new user's UID (or nil if there is no longer a user signed in). + */ +extern NSString *const FIRAuthStateDidChangeInternalNotificationUIDKey; + /** @typedef FIRTokenCallback @brief The type of block which gets called when a token is ready. */ diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m index 1c31961..64b1ef8 100644 --- a/Firebase/Messaging/FIRMessaging.m +++ b/Firebase/Messaging/FIRMessaging.m @@ -709,12 +709,8 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification = #pragma mark - IID dependencies -// FIRMessagingInternalUtilities.h to see usage. + (NSString *)FIRMessagingSDKVersion { - NSString *semanticVersion = FIRMessagingCurrentLibraryVersion(); - // Use prefix fcm for all FCM libs. This allows us to differentiate b/w - // the new and old FCM registrations. - return [NSString stringWithFormat:@"fcm-%@", semanticVersion]; + return FIRMessagingCurrentLibraryVersion(); } + (NSString *)FIRMessagingSDKCurrentLocale { diff --git a/FirebaseAuth.podspec b/FirebaseAuth.podspec index a65f67a..3ee4832 100644 --- a/FirebaseAuth.podspec +++ b/FirebaseAuth.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FirebaseAuth' - s.version = '4.3.2' + s.version = '4.4.0' s.summary = 'The official iOS client for Firebase Authentication' s.description = <<-DESC diff --git a/FirebaseCore.podspec b/FirebaseCore.podspec index a4ff9de..453518f 100644 --- a/FirebaseCore.podspec +++ b/FirebaseCore.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FirebaseCore' - s.version = '4.0.11' + s.version = '4.0.12' s.summary = 'Firebase Core for iOS' s.description = <<-DESC diff --git a/FirebaseDatabase.podspec b/FirebaseDatabase.podspec index bb7ccca..338a2f6 100644 --- a/FirebaseDatabase.podspec +++ b/FirebaseDatabase.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FirebaseDatabase' - s.version = '4.0.4' + s.version = '4.1.2' s.summary = 'Firebase Open Source Libraries for iOS.' s.description = <<-DESC diff --git a/FirebaseFirestore.podspec b/FirebaseFirestore.podspec index 6d1377c..35e5f5d 100644 --- a/FirebaseFirestore.podspec +++ b/FirebaseFirestore.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'FirebaseFirestore' - s.version = '0.9.2' + s.version = '0.9.3' s.summary = 'Google Cloud Firestore for iOS' s.description = <<-DESC @@ -32,8 +32,7 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling, 'Firestore/Source/**/*', 'Firestore/Port/**/*', 'Firestore/Protos/objc/**/*.[hm]', - 'Firestore/src/core/**/*.{h,cc}', - 'Firestore/src/support/**/*.{h,cc}', + 'Firestore/core/src/**/*.{h,cc}', 'Firestore/third_party/**/*.[mh]' ] s.requires_arc = [ @@ -47,7 +46,6 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling, s.public_header_files = 'Firestore/Source/Public/*.h' s.ios.dependency 'FirebaseAnalytics', '~> 4.0' - s.dependency 'FirebaseAuth', '~> 4.3' s.dependency 'FirebaseCore', '~> 4.0' s.dependency 'gRPC-ProtoRPC', '~> 1.0' s.dependency 'leveldb-library', '~> 1.18' diff --git a/FirebaseMessaging.podspec b/FirebaseMessaging.podspec index 88cb310..a26b0b9 100644 --- a/FirebaseMessaging.podspec +++ b/FirebaseMessaging.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FirebaseMessaging' - s.version = '2.0.6' + s.version = '2.0.7' s.summary = 'Firebase Messaging for iOS' s.description = <<-DESC diff --git a/FirebaseStorage.podspec b/FirebaseStorage.podspec index 009c738..af81620 100644 --- a/FirebaseStorage.podspec +++ b/FirebaseStorage.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FirebaseStorage' - s.version = '2.0.2' + s.version = '2.1.0' s.summary = 'Firebase Storage for iOS' s.description = <<-DESC diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md index 483146b..0c5bcdc 100644 --- a/Firestore/CHANGELOG.md +++ b/Firestore/CHANGELOG.md @@ -1,4 +1,7 @@ # Unreleased +- [changed] Firestore no longer has a direct dependency on FirebaseAuth. +- [fixed] Fixed a crash when using path names with international characters + with persistence enabled. - [fixed] Addressed race condition during the teardown of idle streams (#490). diff --git a/Firestore/CMakeLists.txt b/Firestore/CMakeLists.txt index 119af5e..82e1903 100644 --- a/Firestore/CMakeLists.txt +++ b/Firestore/CMakeLists.txt @@ -14,8 +14,5 @@ include(${PROJECT_SOURCE_DIR}/cmake/external/googletest.cmake) -add_subdirectory(src/support) -add_subdirectory(test/support) - -add_subdirectory(src/core/util) -add_subdirectory(test/core/util) +add_subdirectory(core/src/firebase/firestore/util) +add_subdirectory(core/test/firebase/firestore/util) diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index f56af4c..437b661 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -24,8 +24,8 @@ /* Begin PBXBuildFile section */ 3B843E4C1F3A182900548890 /* remote_store_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 3B843E4A1F3930A400548890 /* remote_store_spec_test.json */; }; - 5463926E1FBEDE28005031AA /* secure_random_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5463926D1FBEDE28005031AA /* secure_random_test.cc */; }; - 5471DCF91FBF99AC00656CD3 /* autoid_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5471DCF71FBF99A300656CD3 /* autoid_test.cc */; }; + 54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54740A531FC913E500713A1A /* secure_random_test.cc */; }; + 54740A581FC914F000713A1A /* autoid_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54740A521FC913E500713A1A /* autoid_test.cc */; }; 54764FAB1FAA0C320085E60A /* string_util_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54764FAA1FAA0C320085E60A /* string_util_test.cc */; }; 54764FAF1FAA21B90085E60A /* FSTGoogleTestTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */; }; 5491BC721FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5491BC711FB44593008B3588 /* FSTIntegrationTestCase.mm */; }; @@ -57,6 +57,7 @@ 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; }; + 61E1D8B11FCF6C5700753285 /* StringViewTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 61E1D8AF1FCF6AF500753285 /* StringViewTests.mm */; }; 6ED54761B845349D43DB6B78 /* Pods_Firestore_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */; }; 71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; }; 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; }; @@ -184,8 +185,8 @@ 3B843E4A1F3930A400548890 /* remote_store_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = remote_store_spec_test.json; sourceTree = "<group>"; }; 42491D7DC8C8CD245CC22B93 /* Pods-SwiftBuildTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftBuildTest.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftBuildTest/Pods-SwiftBuildTest.debug.xcconfig"; sourceTree = "<group>"; }; 4EBC5F5ABE1FD097EFE5E224 /* Pods-Firestore_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example/Pods-Firestore_Example.release.xcconfig"; sourceTree = "<group>"; }; - 5463926D1FBEDE28005031AA /* secure_random_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = secure_random_test.cc; path = ../../test/support/secure_random_test.cc; sourceTree = "<group>"; }; - 5471DCF71FBF99A300656CD3 /* autoid_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = autoid_test.cc; path = ../../test/core/util/autoid_test.cc; sourceTree = "<group>"; }; + 54740A521FC913E500713A1A /* autoid_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = autoid_test.cc; path = ../../core/test/firebase/firestore/util/autoid_test.cc; sourceTree = "<group>"; }; + 54740A531FC913E500713A1A /* secure_random_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = secure_random_test.cc; path = ../../core/test/firebase/firestore/util/secure_random_test.cc; sourceTree = "<group>"; }; 54764FAA1FAA0C320085E60A /* string_util_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = string_util_test.cc; path = ../../Port/string_util_test.cc; sourceTree = "<group>"; }; 54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = FSTGoogleTestTests.mm; path = GoogleTest/FSTGoogleTestTests.mm; sourceTree = "<group>"; }; 5491BC711FB44593008B3588 /* FSTIntegrationTestCase.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTIntegrationTestCase.mm; sourceTree = "<group>"; }; @@ -221,6 +222,7 @@ 6003F5AF195388D20070C39A /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 6003F5B7195388D20070C39A /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = "<group>"; }; 6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; + 61E1D8AF1FCF6AF500753285 /* StringViewTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringViewTests.mm; sourceTree = "<group>"; }; 69F6A10DBD6187489481CD76 /* Pods_Firestore_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 71719F9E1E33DC2100824A3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -366,26 +368,11 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 5463926F1FBEDE2F005031AA /* support */ = { + 54740A561FC913EB00713A1A /* util */ = { isa = PBXGroup; children = ( - 5463926D1FBEDE28005031AA /* secure_random_test.cc */, - ); - name = support; - sourceTree = "<group>"; - }; - 5471DCFA1FBF99B100656CD3 /* core */ = { - isa = PBXGroup; - children = ( - 5471DCFB1FBF99B800656CD3 /* util */, - ); - name = core; - sourceTree = "<group>"; - }; - 5471DCFB1FBF99B800656CD3 /* util */ = { - isa = PBXGroup; - children = ( - 5471DCF71FBF99A300656CD3 /* autoid_test.cc */, + 54740A521FC913E500713A1A /* autoid_test.cc */, + 54740A531FC913E500713A1A /* secure_random_test.cc */, ); name = util; sourceTree = "<group>"; @@ -393,9 +380,8 @@ 54764FAC1FAA0C390085E60A /* GoogleTests */ = { isa = PBXGroup; children = ( - 5471DCFA1FBF99B100656CD3 /* core */, 54764FAD1FAA0C650085E60A /* Port */, - 5463926F1FBEDE2F005031AA /* support */, + 54740A561FC913EB00713A1A /* util */, 54764FAE1FAA21B90085E60A /* FSTGoogleTestTests.mm */, ); name = GoogleTests; @@ -551,6 +537,7 @@ DE51B1621F0D48AC0013853F /* Local */ = { isa = PBXGroup; children = ( + 61E1D8AF1FCF6AF500753285 /* StringViewTests.mm */, DE51B16A1F0D48AC0013853F /* FSTLocalStoreTests.h */, DE51B1701F0D48AC0013853F /* FSTMutationQueueTests.h */, DE51B1721F0D48AC0013853F /* FSTPersistenceTestHelpers.h */, @@ -1183,7 +1170,6 @@ DE51B1F81F0D491F0013853F /* FSTWatchChange+Testing.m in Sources */, DE51B1EB1F0D490D0013853F /* FSTWriteGroupTests.mm in Sources */, DE51B2011F0D493E0013853F /* FSTHelpers.m in Sources */, - 5471DCF91FBF99AC00656CD3 /* autoid_test.cc in Sources */, DE51B1F61F0D491B0013853F /* FSTSerializerBetaTests.m in Sources */, DE51B1F01F0D49140013853F /* FSTFieldValueTests.m in Sources */, 5491BC721FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */, @@ -1192,6 +1178,7 @@ DE51B1EC1F0D49140013853F /* FSTDatabaseIDTests.m in Sources */, DE51B1ED1F0D49140013853F /* FSTDocumentKeyTests.m in Sources */, DE51B1D41F0D48CD0013853F /* FSTViewTests.m in Sources */, + 54740A581FC914F000713A1A /* autoid_test.cc in Sources */, DE51B1F41F0D491B0013853F /* FSTRemoteEventTests.m in Sources */, 54E928241F33953300C1953E /* FSTEventAccumulator.m in Sources */, DE51B1D11F0D48CD0013853F /* FSTTargetIDGeneratorTests.m in Sources */, @@ -1216,10 +1203,10 @@ DE51B1E91F0D490D0013853F /* FSTLevelDBMutationQueueTests.mm in Sources */, 54764FAF1FAA21B90085E60A /* FSTGoogleTestTests.mm in Sources */, DE51B1E61F0D490D0013853F /* FSTRemoteDocumentCacheTests.m in Sources */, + 61E1D8B11FCF6C5700753285 /* StringViewTests.mm in Sources */, DE51B1D91F0D490D0013853F /* FSTEagerGarbageCollectorTests.m in Sources */, DE51B1E21F0D490D0013853F /* FSTMutationQueueTests.m in Sources */, DE51B1E81F0D490D0013853F /* FSTLevelDBKeyTests.mm in Sources */, - 5463926E1FBEDE28005031AA /* secure_random_test.cc in Sources */, DE51B1E31F0D490D0013853F /* FSTPersistenceTestHelpers.m in Sources */, DE51B1CF1F0D48CD0013853F /* FSTQueryListenerTests.m in Sources */, DE51B1DA1F0D490D0013853F /* FSTLevelDBLocalStoreTests.m in Sources */, @@ -1230,6 +1217,7 @@ DE51B1E41F0D490D0013853F /* FSTQueryCacheTests.m in Sources */, DE51B1CD1F0D48CD0013853F /* FSTDatabaseInfoTests.m in Sources */, DE51B1F21F0D49140013853F /* FSTPathTests.m in Sources */, + 54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */, DE51B1DD1F0D490D0013853F /* FSTLocalStoreTests.m in Sources */, D5B25474286C9800CE42B8C2 /* FSTTestDispatchQueue.m in Sources */, ); diff --git a/Firestore/Example/Podfile b/Firestore/Example/Podfile index 923ab22..89af74f 100644 --- a/Firestore/Example/Podfile +++ b/Firestore/Example/Podfile @@ -1,7 +1,7 @@ # The next line is the forcing function for the Firebase pod. The Firebase # version's subspecs should depend on the component versions in their # corresponding podspec's. -pod 'Firebase/Core', '4.6.0' +pod 'Firebase/Core', '4.7.0' use_frameworks! platform :ios, '8.0' diff --git a/Firestore/Example/Tests/Local/StringViewTests.mm b/Firestore/Example/Tests/Local/StringViewTests.mm new file mode 100644 index 0000000..b30b43d --- /dev/null +++ b/Firestore/Example/Tests/Local/StringViewTests.mm @@ -0,0 +1,47 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "Firestore/Source/Local/StringView.h" + +#import <XCTest/XCTest.h> +#include <leveldb/slice.h> + +using Firestore::StringView; + +#define ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK(nsstr) \ + StringView sv(nsstr); \ + leveldb::Slice slice = sv; \ + NSString *afterConversion = [[NSString alloc] initWithBytes:slice.data() \ + length:slice.size() \ + encoding:NSUTF8StringEncoding]; \ + XCTAssertEqualObjects(afterConversion, nsstr); + +@interface StringViewTests : XCTestCase +@end + +@implementation StringViewTests + +- (void)testStringViewNSStringToSliceWithUSAscii { + NSString *usAsciiChars = @"abcdefg ABCDEFG 12345 !@#$%"; + ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK(usAsciiChars); +} + +- (void)testStringViewNSStringToSliceWithNonUSAscii { + NSString *nonUsAsciiChars = @"ó¹"; + ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK(nonUsAsciiChars); +} + +@end diff --git a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm index 2c29bf0..3d30a77 100644 --- a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm +++ b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm @@ -21,7 +21,7 @@ #import <GRPCClient/GRPCCall+ChannelArg.h> #import <GRPCClient/GRPCCall+Tests.h> -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Auth/FSTEmptyCredentialsProvider.h" @@ -32,6 +32,8 @@ #import "Firestore/Example/Tests/Util/FSTEventAccumulator.h" #import "Firestore/Example/Tests/Util/FSTTestDispatchQueue.h" +using firebase::firestore::util::CreateAutoId; + NS_ASSUME_NONNULL_BEGIN @interface FIRFirestore (Testing) @@ -165,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN } - (NSString *)documentPath { - std::string autoId = firestore::CreateAutoId(); + std::string autoId = CreateAutoId(); return [NSString stringWithFormat:@"test-collection/%s", autoId.c_str()]; } @@ -174,7 +176,7 @@ NS_ASSUME_NONNULL_BEGIN } - (FIRCollectionReference *)collectionRef { - std::string autoId = firestore::CreateAutoId(); + std::string autoId = CreateAutoId(); NSString *collectionName = [NSString stringWithFormat:@"test-collection-%s", autoId.c_str()]; return [self.db collectionWithPath:collectionName]; } diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm index 7b487c6..92cccc6 100644 --- a/Firestore/Source/API/FIRCollectionReference.mm +++ b/Firestore/Source/API/FIRCollectionReference.mm @@ -16,7 +16,7 @@ #import "FIRCollectionReference.h" -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/API/FIRQuery+Internal.h" @@ -27,6 +27,8 @@ #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTUsageValidation.h" +using firebase::firestore::util::CreateAutoId; + NS_ASSUME_NONNULL_BEGIN @interface FIRCollectionReference () @@ -103,7 +105,7 @@ NS_ASSUME_NONNULL_BEGIN } - (FIRDocumentReference *)documentWithAutoID { - NSString *autoID = [NSString stringWithUTF8String:firestore::CreateAutoId().c_str()]; + NSString *autoID = [NSString stringWithUTF8String:CreateAutoId().c_str()]; FSTDocumentKey *key = [FSTDocumentKey keyWithPath:[self.query.path pathByAppendingSegment:autoID]]; return [FIRDocumentReference referenceWithKey:key firestore:self.firestore]; diff --git a/Firestore/Source/Auth/FSTCredentialsProvider.h b/Firestore/Source/Auth/FSTCredentialsProvider.h index eb591ab..92d5fdc 100644 --- a/Firestore/Source/Auth/FSTCredentialsProvider.h +++ b/Firestore/Source/Auth/FSTCredentialsProvider.h @@ -66,7 +66,7 @@ typedef void (^FSTVoidUserBlock)(FSTUser *user); #pragma mark - FSTCredentialsProvider /** Provides methods for getting the uid and token for the current user and listen for changes. */ -@protocol FSTCredentialsProvider<NSObject> +@protocol FSTCredentialsProvider <NSObject> /** Requests token for the current user, optionally forcing a refreshed token to be fetched. */ - (void)getTokenForcingRefresh:(BOOL)forceRefresh completion:(FSTVoidGetTokenResultBlock)completion; @@ -95,7 +95,7 @@ typedef void (^FSTVoidUserBlock)(FSTUser *user); * backing our internal worker queue and the callbacks from FIRAuth will be executed on an * arbitrary different thread. */ -@interface FSTFirebaseCredentialsProvider : NSObject<FSTCredentialsProvider> +@interface FSTFirebaseCredentialsProvider : NSObject <FSTCredentialsProvider> /** * Initializes a new FSTFirebaseCredentialsProvider. diff --git a/Firestore/Source/Auth/FSTCredentialsProvider.m b/Firestore/Source/Auth/FSTCredentialsProvider.m index 821341e..653d7ff 100644 --- a/Firestore/Source/Auth/FSTCredentialsProvider.m +++ b/Firestore/Source/Auth/FSTCredentialsProvider.m @@ -16,17 +16,15 @@ #import "Firestore/Source/Auth/FSTCredentialsProvider.h" -#import <FirebaseAuth/FIRAuth.h> -#import <FirebaseAuth/FIRUser.h> #import <FirebaseCore/FIRApp.h> #import <FirebaseCore/FIRAppInternal.h> #import <GRPCClient/GRPCCall.h> #import "FIRFirestoreErrors.h" +#import "Firestore/Source/Auth/FSTUser.h" #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTClasses.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" -#import "Firestore/Source/Auth/FSTUser.h" NS_ASSUME_NONNULL_BEGIN @@ -43,17 +41,12 @@ NS_ASSUME_NONNULL_BEGIN @end #pragma mark - FSTFirebaseCredentialsProvider -// TODO(mikelehen): Currently, we have a strong dependency on FIRAuth but we should ideally use -// only internal APIs on FIRApp instead. However, currently the FIRApp internal APIs don't expose -// the uid of the current user and don't expose an auth state change listener. So we use FIRAuth. @interface FSTFirebaseCredentialsProvider () @property(nonatomic, strong, readonly) FIRApp *app; -@property(nonatomic, strong, readonly) FIRAuth *auth; /** Handle used to stop receiving auth changes once userChangeListener is removed. */ -@property(nonatomic, strong, nullable, readwrite) - FIRAuthStateDidChangeListenerHandle authListenerHandle; +@property(nonatomic, strong, nullable, readwrite) id<NSObject> authListenerHandle; /** The current user as reported to us via our AuthStateDidChangeListener. */ @property(nonatomic, strong, nonnull, readwrite) FSTUser *currentUser; @@ -74,28 +67,41 @@ NS_ASSUME_NONNULL_BEGIN self = [super init]; if (self) { _app = app; - _auth = [FIRAuth authWithApp:app]; - _currentUser = [[FSTUser alloc] initWithUID:self.auth.currentUser.uid]; + _currentUser = [[FSTUser alloc] initWithUID:[self.app getUID]]; _userCounter = 0; // Register for user changes so that we can internally track the current user. FSTWeakify(self); - _authListenerHandle = [self.auth addAuthStateDidChangeListener:^(FIRAuth *auth, FIRUser *user) { - FSTStrongify(self); - if (self) { - @synchronized(self) { - FSTUser *newUser = [[FSTUser alloc] initWithUID:user.uid]; - if (![newUser isEqual:self.currentUser]) { - self.currentUser = newUser; - self.userCounter++; - FSTVoidUserBlock listenerBlock = self.userChangeListener; - if (listenerBlock) { - listenerBlock(self.currentUser); - } - } - } - } - }]; + _authListenerHandle = [[NSNotificationCenter defaultCenter] + addObserverForName:FIRAuthStateDidChangeInternalNotification + object:nil + queue:nil + usingBlock:^(NSNotification *notification) { + FSTStrongify(self); + if (self) { + @synchronized(self) { + NSDictionary *userInfo = notification.userInfo; + + // ensure we're only notifiying for the current app. + FIRApp *notifiedApp = + userInfo[FIRAuthStateDidChangeInternalNotificationAppKey]; + if (![self.app isEqual:notifiedApp]) { + return; + } + + NSString *userID = userInfo[FIRAuthStateDidChangeInternalNotificationUIDKey]; + FSTUser *newUser = [[FSTUser alloc] initWithUID:userID]; + if (![newUser isEqual:self.currentUser]) { + self.currentUser = newUser; + self.userCounter++; + FSTVoidUserBlock listenerBlock = self.userChangeListener; + if (listenerBlock) { + listenerBlock(self.currentUser); + } + } + } + } + }]; } return self; } @@ -108,24 +114,24 @@ NS_ASSUME_NONNULL_BEGIN // FIRFirestoreErrorCodeAborted error) if there is a user change while the request is outstanding. int initialUserCounter = self.userCounter; - void (^getTokenCallback)(NSString *, NSError *) = ^(NSString *_Nullable token, - NSError *_Nullable error) { - @synchronized(self) { - if (initialUserCounter != self.userCounter) { - // Cancel the request since the user changed while the request was outstanding so the - // response is likely for a previous user (which user, we can't be sure). - NSDictionary *errorInfo = @{ @"details" : @"getToken aborted due to user change." }; - NSError *cancelError = [NSError errorWithDomain:FIRFirestoreErrorDomain - code:FIRFirestoreErrorCodeAborted - userInfo:errorInfo]; - completion(nil, cancelError); - } else { - FSTGetTokenResult *result = - [[FSTGetTokenResult alloc] initWithUser:self.currentUser token:token]; - completion(result, error); - } - }; - }; + void (^getTokenCallback)(NSString *, NSError *) = + ^(NSString *_Nullable token, NSError *_Nullable error) { + @synchronized(self) { + if (initialUserCounter != self.userCounter) { + // Cancel the request since the user changed while the request was outstanding so the + // response is likely for a previous user (which user, we can't be sure). + NSDictionary *errorInfo = @{@"details" : @"getToken aborted due to user change."}; + NSError *cancelError = [NSError errorWithDomain:FIRFirestoreErrorDomain + code:FIRFirestoreErrorCodeAborted + userInfo:errorInfo]; + completion(nil, cancelError); + } else { + FSTGetTokenResult *result = + [[FSTGetTokenResult alloc] initWithUser:self.currentUser token:token]; + completion(result, error); + } + }; + }; [self.app getTokenForcingRefresh:forceRefresh withCallback:getTokenCallback]; } @@ -140,8 +146,7 @@ NS_ASSUME_NONNULL_BEGIN } else { FSTAssert(self.authListenerHandle, @"UserChangeListener removed twice!"); FSTAssert(_userChangeListener, @"UserChangeListener removed without being set!"); - [self.auth removeAuthStateDidChangeListener:self.authListenerHandle]; - + [[NSNotificationCenter defaultCenter] removeObserver:self.authListenerHandle]; self.authListenerHandle = nil; } _userChangeListener = block; diff --git a/Firestore/Source/Auth/FSTEmptyCredentialsProvider.h b/Firestore/Source/Auth/FSTEmptyCredentialsProvider.h index 5783bcc..f805363 100644 --- a/Firestore/Source/Auth/FSTEmptyCredentialsProvider.h +++ b/Firestore/Source/Auth/FSTEmptyCredentialsProvider.h @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN /** `FSTEmptyCredentialsProvider` always yields an empty token. */ -@interface FSTEmptyCredentialsProvider : NSObject<FSTCredentialsProvider> +@interface FSTEmptyCredentialsProvider : NSObject <FSTCredentialsProvider> @end diff --git a/Firestore/Source/Auth/FSTUser.h b/Firestore/Source/Auth/FSTUser.h index 83b1962..68ecc4c 100644 --- a/Firestore/Source/Auth/FSTUser.h +++ b/Firestore/Source/Auth/FSTUser.h @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN * Simple wrapper around a nullable UID. Mostly exists to make code more readable and for use as * a key in dictionaries (since keys cannot be nil). */ -@interface FSTUser : NSObject<NSCopying> +@interface FSTUser : NSObject <NSCopying> /** Returns an FSTUser with a nil UID. */ + (instancetype)unauthenticatedUser; diff --git a/Firestore/Source/Local/StringView.h b/Firestore/Source/Local/StringView.h index 799baf8..b81b7b5 100644 --- a/Firestore/Source/Local/StringView.h +++ b/Firestore/Source/Local/StringView.h @@ -46,7 +46,8 @@ class StringView { // Creates a StringView from an NSString. When StringView is an argument type // into which an NSString* is passed, the caller should ensure that the // NSString is retained. - StringView(NSString *str) : data_([str UTF8String]), size_(str.length) { + StringView(NSString *str) + : data_([str UTF8String]), size_([str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) { } // Creates a StringView from the given char* pointer with an explicit size. diff --git a/Firestore/Source/Public/FIRCollectionReference.h b/Firestore/Source/Public/FIRCollectionReference.h index ba3389f..bc9a56a 100644 --- a/Firestore/Source/Public/FIRCollectionReference.h +++ b/Firestore/Source/Public/FIRCollectionReference.h @@ -81,7 +81,9 @@ NS_SWIFT_NAME(CollectionReference) * automatically. * * @param data An `NSDictionary` containing the data for the new document. - * @param completion A block to execute once the document has been successfully written. + * @param completion A block to execute once the document has been successfully written to + * the server. This block will not be called while the client is offline, though local + * changes will be visible immediately. * * @return A `FIRDocumentReference` pointing to the newly created document. */ diff --git a/Firestore/Source/Public/FIRDocumentReference.h b/Firestore/Source/Public/FIRDocumentReference.h index bd6d7b8..439e727 100644 --- a/Firestore/Source/Public/FIRDocumentReference.h +++ b/Firestore/Source/Public/FIRDocumentReference.h @@ -121,8 +121,10 @@ NS_SWIFT_NAME(DocumentReference) * is created. If a document already exists, it is overwritten. * * @param documentData An `NSDictionary` containing the fields that make up the document - * to be written. - * @param completion A block to execute once the document has been successfully written. + * to be written. + * @param completion A block to execute once the document has been successfully written to the + * server. This block will not be called while the client is offline, though local + * changes will be visible immediately. */ - (void)setData:(NSDictionary<NSString *, id> *)documentData completion:(nullable void (^)(NSError *_Nullable error))completion; @@ -135,7 +137,9 @@ NS_SWIFT_NAME(DocumentReference) * @param documentData An `NSDictionary` containing the fields that make up the document * to be written. * @param options A `FIRSetOptions` used to configure the set behavior. - * @param completion A block to execute once the document has been successfully written. + * @param completion A block to execute once the document has been successfully written to the + * server. This block will not be called while the client is offline, though local + * changes will be visible immediately. */ - (void)setData:(NSDictionary<NSString *, id> *)documentData options:(FIRSetOptions *)options @@ -146,7 +150,7 @@ NS_SWIFT_NAME(DocumentReference) * If the document does not exist, the update fails (specify a completion block to be notified). * * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or - * `FIRFieldPath`) and values with which to update the document. + * `FIRFieldPath`) and values with which to update the document. */ - (void)updateData:(NSDictionary<id, id> *)fields; @@ -155,9 +159,12 @@ NS_SWIFT_NAME(DocumentReference) * does not exist, the update fails and the specified completion block receives an error. * * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or - * `FIRFieldPath`) and values with which to update the document. + * `FIRFieldPath`) and values with which to update the document. * @param completion A block to execute when the update is complete. If the update is successful the - * error parameter will be nil, otherwise it will give an indication of how the update failed. + * error parameter will be nil, otherwise it will give an indication of how the update failed. + * This block will only execute when the client is online and the commit has completed against + * the server. The completion handler will not be called when the device is offline, though + * local changes will be visible immediately. */ - (void)updateData:(NSDictionary<id, id> *)fields completion:(nullable void (^)(NSError *_Nullable error))completion; @@ -171,7 +178,9 @@ NS_SWIFT_NAME(DocumentReference) /** * Deletes the document referred to by this `FIRDocumentReference`. * - * @param completion A block to execute once the document has been successfully deleted. + * @param completion A block to execute once the document has been successfully written to the + * server. This block will not be called while the client is offline, though local + * changes will be visible immediately. */ // clang-format off - (void)deleteDocumentWithCompletion:(nullable void (^)(NSError *_Nullable error))completion diff --git a/Firestore/Source/Public/FIRFirestore.h b/Firestore/Source/Public/FIRFirestore.h index 0935917..91a96a5 100644 --- a/Firestore/Source/Public/FIRFirestore.h +++ b/Firestore/Source/Public/FIRFirestore.h @@ -115,10 +115,11 @@ NS_SWIFT_NAME(Firestore) * and collections. Unlike other firestore access, data accessed with the transaction will not * reflect local changes that have not been committed. For this reason, it is required that all * reads are performed before any writes. Transactions must be performed while online. Otherwise, - * reads will fail, and the final commit will fail. + * reads will fail, the final commit will fail, and the completion block will return an error. * * @param updateBlock The block to execute within the transaction context. - * @param completion The block to call with the result or error of the transaction. + * @param completion The block to call with the result or error of the transaction. This + * block will run even if the client is offline, unless the process is killed. */ - (void)runTransactionWithBlock:(id _Nullable (^)(FIRTransaction *, NSError **))updateBlock completion:(void (^)(id _Nullable result, NSError *_Nullable error))completion; diff --git a/Firestore/Source/Public/FIRWriteBatch.h b/Firestore/Source/Public/FIRWriteBatch.h index a74d451..5f0034c 100644 --- a/Firestore/Source/Public/FIRWriteBatch.h +++ b/Firestore/Source/Public/FIRWriteBatch.h @@ -73,7 +73,7 @@ NS_SWIFT_NAME(WriteBatch) * If document does not exist, the write batch will fail. * * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or - * `FIRFieldPath`) and values with which to update the document. + * `FIRFieldPath`) and values with which to update the document. * @param document A reference to the document whose data should be updated. * @return This `FIRWriteBatch` instance. Used for chaining method calls. */ @@ -96,7 +96,10 @@ NS_SWIFT_NAME(WriteBatch) * Commits all of the writes in this write batch as a single atomic unit. * * @param completion A block to be called once all of the writes in the batch have been - * successfully written to the backend as an atomic unit. + * successfully written to the backend as an atomic unit. This block will only execute + * when the client is online and the commit has completed against the server. The + * completion handler will not be called when the device is offline, though local + * changes will be visible immediately. */ - (void)commitWithCompletion:(void (^)(NSError *_Nullable error))completion; diff --git a/Firestore/Source/Remote/FSTExponentialBackoff.mm b/Firestore/Source/Remote/FSTExponentialBackoff.mm index ad27c25..8077357 100644 --- a/Firestore/Source/Remote/FSTExponentialBackoff.mm +++ b/Firestore/Source/Remote/FSTExponentialBackoff.mm @@ -18,11 +18,13 @@ #include <random> -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" #import "Firestore/Source/Util/FSTLogger.h" +using firebase::firestore::util::SecureRandom; + @interface FSTExponentialBackoff () - (instancetype)initWithDispatchQueue:(FSTDispatchQueue *)dispatchQueue initialDelay:(NSTimeInterval)initialDelay @@ -37,7 +39,7 @@ @end @implementation FSTExponentialBackoff { - firestore::SecureRandom _secureRandom; + SecureRandom _secureRandom; } - (instancetype)initWithDispatchQueue:(FSTDispatchQueue *)dispatchQueue diff --git a/Firestore/src/.clang-format b/Firestore/core/.clang-format index 7a0e321..7a0e321 100644 --- a/Firestore/src/.clang-format +++ b/Firestore/core/.clang-format diff --git a/Firestore/src/support/port.h b/Firestore/core/src/firebase/firestore/base/port.h index 6af898a..37d1041 100644 --- a/Firestore/src/support/port.h +++ b/Firestore/core/src/firebase/firestore/base/port.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef FIRESTORE_SRC_SUPPORT_PORT_H_ -#define FIRESTORE_SRC_SUPPORT_PORT_H_ +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_BASE_PORT_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_BASE_PORT_H_ #if defined(__APPLE__) // On Apple platforms we support building via Cocoapods without CMake. When @@ -30,4 +30,4 @@ #error "Unknown platform." #endif // defined(__APPLE__) -#endif // FIRESTORE_SRC_SUPPORT_PORT_H_ +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_BASE_PORT_H_ diff --git a/Firestore/src/support/CMakeLists.txt b/Firestore/core/src/firebase/firestore/util/CMakeLists.txt index 8110c6f..ce81363 100644 --- a/Firestore/src/support/CMakeLists.txt +++ b/Firestore/core/src/firebase/firestore/util/CMakeLists.txt @@ -13,6 +13,7 @@ # limitations under the License. add_library( - firestore_support + firebase_firestore_util + autoid.cc secure_random_arc4random.cc ) diff --git a/Firestore/src/core/util/autoid.cc b/Firestore/core/src/firebase/firestore/util/autoid.cc index 762bbcc..10a2cde 100644 --- a/Firestore/src/core/util/autoid.cc +++ b/Firestore/core/src/firebase/firestore/util/autoid.cc @@ -14,12 +14,16 @@ * limitations under the License. */ -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #include <random> #include <string> -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" + +namespace firebase { +namespace firestore { +namespace util { namespace { @@ -27,12 +31,10 @@ const int kAutoIdLength = 20; const char kAutoIdAlphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; -firestore::SecureRandom shared_random; +SecureRandom shared_random; } // namespace -namespace firestore { - std::string CreateAutoId() { std::string auto_id; auto_id.reserve(kAutoIdLength); @@ -49,4 +51,6 @@ std::string CreateAutoId() { return auto_id; } +} // namespace util } // namespace firestore +} // namespace firebase diff --git a/Firestore/src/core/util/autoid.h b/Firestore/core/src/firebase/firestore/util/autoid.h index 13486af..22d7d7d 100644 --- a/Firestore/src/core/util/autoid.h +++ b/Firestore/core/src/firebase/firestore/util/autoid.h @@ -14,16 +14,20 @@ * limitations under the License. */ -#ifndef FIRESTORE_SRC_CORE_UTIL_AUTOID_H_ -#define FIRESTORE_SRC_CORE_UTIL_AUTOID_H_ +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_AUTOID_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_AUTOID_H_ #include <string> +namespace firebase { namespace firestore { +namespace util { // Generates a random ID suitable for use as a document ID. std::string CreateAutoId(); +} // namespace util } // namespace firestore +} // namespace firebase -#endif // FIRESTORE_SRC_CORE_UTIL_AUTOID_H_ +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_AUTOID_H_ diff --git a/Firestore/src/support/secure_random.h b/Firestore/core/src/firebase/firestore/util/secure_random.h index 92a3eaf..72be1bd 100644 --- a/Firestore/src/support/secure_random.h +++ b/Firestore/core/src/firebase/firestore/util/secure_random.h @@ -14,14 +14,16 @@ * limitations under the License. */ -#ifndef FIRESTORE_SRC_SUPPORT_SECURE_RANDOM_H_ -#define FIRESTORE_SRC_SUPPORT_SECURE_RANDOM_H_ +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ #include <stdint.h> #include <limits> +namespace firebase { namespace firestore { +namespace util { // A "secure" pseudorandom number generator, suitable for generating // unguessable identifiers. This exists because @@ -50,6 +52,8 @@ class SecureRandom { result_type operator()(); }; +} // namespace util } // namespace firestore +} // namespace firebase -#endif // FIRESTORE_SRC_SUPPORT_SECURE_RANDOM_H_ +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ diff --git a/Firestore/src/support/secure_random_arc4random.cc b/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc index 4cd7f9d..a76ade3 100644 --- a/Firestore/src/support/secure_random_arc4random.cc +++ b/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc @@ -14,20 +14,24 @@ * limitations under the License. */ -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" -#include "Firestore/src/support/port.h" +#include "Firestore/core/src/firebase/firestore/base/port.h" #if HAVE_ARC4RANDOM #include <stdlib.h> +namespace firebase { namespace firestore { +namespace util { SecureRandom::result_type SecureRandom::operator()() { return arc4random(); } +} // namespace util } // namespace firestore +} // namespace firebase #endif // HAVE_ARC4RANDOM diff --git a/Firestore/test/support/CMakeLists.txt b/Firestore/core/test/firebase/firestore/util/CMakeLists.txt index 7de5367..223fa41 100644 --- a/Firestore/test/support/CMakeLists.txt +++ b/Firestore/core/test/firebase/firestore/util/CMakeLists.txt @@ -13,10 +13,11 @@ # limitations under the License. cc_test( - firestore_support_test + firebase_firestore_util_test + autoid_test.cc secure_random_test.cc ) target_link_libraries( - firestore_support_test - firestore_support + firebase_firestore_util_test + firebase_firestore_util ) diff --git a/Firestore/test/core/util/autoid_test.cc b/Firestore/core/test/firebase/firestore/util/autoid_test.cc index b17a34e..730c683 100644 --- a/Firestore/test/core/util/autoid_test.cc +++ b/Firestore/core/test/firebase/firestore/util/autoid_test.cc @@ -14,20 +14,23 @@ * limitations under the License. */ -#include "Firestore/src/core/util/autoid.h" +#include "Firestore/core/src/firebase/firestore/util/autoid.h" #include <ctype.h> #include "gtest/gtest.h" +using firebase::firestore::util::CreateAutoId; + TEST(AutoId, IsSane) { for (int i = 0; i < 50; i++) { - std::string auto_id = firestore::CreateAutoId(); + std::string auto_id = CreateAutoId(); EXPECT_EQ(20, auto_id.length()); for (int pos = 0; pos < 20; pos++) { char c = auto_id[pos]; EXPECT_TRUE(isalpha(c) || isdigit(c)) - << "Should be printable ascii character: '" << c << "' in \"" << auto_id << "\""; + << "Should be printable ascii character: '" << c << "' in \"" + << auto_id << "\""; } } } diff --git a/Firestore/test/support/secure_random_test.cc b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc index 244227b..f96f3de 100644 --- a/Firestore/test/support/secure_random_test.cc +++ b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include "Firestore/src/support/secure_random.h" +#include "Firestore/core/src/firebase/firestore/util/secure_random.h" #include "gtest/gtest.h" -using firestore::SecureRandom; +using firebase::firestore::util::SecureRandom; TEST(SecureRandomTest, ResultsAreBounded) { SecureRandom rng; diff --git a/Firestore/src/core/util/CMakeLists.txt b/Firestore/src/core/util/CMakeLists.txt deleted file mode 100644 index 6b08d8e..0000000 --- a/Firestore/src/core/util/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2017 Google -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -add_library( - firestore_core_util - autoid.cc -) -target_link_libraries( - firestore_core_util - firestore_support -) diff --git a/Firestore/test/core/util/CMakeLists.txt b/Firestore/test/core/util/CMakeLists.txt deleted file mode 100644 index 1989c0e..0000000 --- a/Firestore/test/core/util/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2017 Google -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cc_test( - firestore_core_util_test - autoid_test.cc -) -target_link_libraries( - firestore_core_util_test - firestore_core_util -) @@ -105,11 +105,6 @@ To run the Database Integration tests, make your database authentication rules To run the Storage Integration tests, follow the instructions in [FIRStorageIntegrationTests.m](Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m). -### Firebase Messaging - -To use Messaging, include `pod 'FirebaseInstanceID'` in your Podfile, in addition to -`pod 'FirebaseCommunity/Messaging'`. - #### Push Notifications Push notifications can only be delivered to specially provisioned App IDs in the developer portal. diff --git a/scripts/style.sh b/scripts/style.sh index 7113177..494a937 100755 --- a/scripts/style.sh +++ b/scripts/style.sh @@ -11,16 +11,46 @@ # See the License for the specific language governing permissions and # limitations under the License. -find . \ - -name 'third_party' -prune -o \ - -name 'Auth' -prune -o \ - -name 'AuthSamples' -prune -o \ - -name 'Database' -prune -o \ - -name 'FirebaseCommunity.h' -prune -o \ - -name 'Messaging' -prune -o \ - -name 'Pods' -prune -o \ - -path '*/Firestore/Port/*' -prune -o \ - \( -name '*.[mh]' -o -name '*.mm' -o -name '*.cc' \) \ - -not -name '*.pbobjc.*' \ - -not -name '*.pbrpc.*' \ - -print0 | xargs -0 clang-format -style=file -i +# Usage: +# ./scripts/style.sh [branch-name | filenames] +# +# With no arguments, formats all eligible files in the repo +# Pass a branch name to format all eligible files changed since that branch +# Pass a specific file or directory name to format just files found there +# +# Commonly +# ./scripts/style.sh master + +set -euo pipefail + +( + if [[ $# -gt 0 ]]; then + if git rev-parse "$1" -- >& /dev/null; then + # Argument was a branch name show files changed since that branch + git diff --name-only --relative + else + # Otherwise assume the passed things are files or directories + find "$@" -type f + fi + else + # Do everything by default + find . -type f + fi +) | sed -E -n ' +# Build outputs +\%/Pods/% d +\%^./build/% d + +# Sources controlled outside this tree +\%/third_party/% d +\%/Firestore/Port/% d + +# Sources within the tree that are not subject to formatting +\%^./(Example|Firebase)/(Auth|AuthSamples|Database|Messaging)/% d + +# Checked-in generated code +\%\.pb(objc|rpc)\.% d + +# Format C-ish sources only +\%\.(h|m|mm|cc)$% p +' | xargs clang-format -style=file -i |