aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Database
diff options
context:
space:
mode:
authorGravatar Paul Beusterien <paulbeusterien@google.com>2017-06-30 10:47:37 -0700
committerGravatar VinayGuthal <vinayg@qhode.com>2017-06-30 13:47:37 -0400
commitddbfd4cc666f5227ab0e1f5a98c8a499ccbb32d1 (patch)
tree9c2ec4e15b6741f413d66f428c45f0278219d728 /Firebase/Database
parent925f4c8b7558373172dd9410b7844637afaa2424 (diff)
Add travis trailing whitespace check (#116)
* Add travis trailing whitespace check * Remove trailing white space
Diffstat (limited to 'Firebase/Database')
-rw-r--r--Firebase/Database/Api/FIRDatabaseQuery.m4
-rw-r--r--Firebase/Database/Core/FPersistentConnection.m14
-rw-r--r--Firebase/Database/Core/FRepo.h2
-rw-r--r--Firebase/Database/Core/FRepo.m4
-rw-r--r--Firebase/Database/Core/Utilities/FPath.m4
-rw-r--r--Firebase/Database/Core/Utilities/FTree.m4
-rw-r--r--Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBEmptyNode.m2
-rw-r--r--Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBValueNode.m22
-rw-r--r--Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FTreeSortedDictionaryEnumerator.m2
-rw-r--r--Firebase/Database/FViewProcessor.m2
-rw-r--r--Firebase/Database/Public/FIRDataSnapshot.h6
-rw-r--r--Firebase/Database/Public/FIRDatabase.h4
-rw-r--r--Firebase/Database/Public/FIRDatabaseReference.h38
-rw-r--r--Firebase/Database/Realtime/FConnection.m16
-rw-r--r--Firebase/Database/Realtime/FWebSocketConnection.m30
-rw-r--r--Firebase/Database/Snapshot/FChildrenNode.m4
-rw-r--r--Firebase/Database/Snapshot/FSnapshotUtilities.m4
-rw-r--r--Firebase/Database/Utilities/FAtomicNumber.m4
-rw-r--r--Firebase/Database/Utilities/FNextPushId.m14
-rw-r--r--Firebase/Database/Utilities/FUtilities.m8
-rw-r--r--Firebase/Database/Utilities/FValidation.m2
-rw-r--r--Firebase/Database/third_party/SocketRocket/FSRWebSocket.h4
-rw-r--r--Firebase/Database/third_party/SocketRocket/FSRWebSocket.m352
-rw-r--r--Firebase/Database/third_party/SocketRocket/fbase64.c56
-rw-r--r--Firebase/Database/third_party/SocketRocket/fbase64.h2
25 files changed, 302 insertions, 302 deletions
diff --git a/Firebase/Database/Api/FIRDatabaseQuery.m b/Firebase/Database/Api/FIRDatabaseQuery.m
index bcb1733..eedc735 100644
--- a/Firebase/Database/Api/FIRDatabaseQuery.m
+++ b/Firebase/Database/Api/FIRDatabaseQuery.m
@@ -44,11 +44,11 @@
// We use this shared queue across all of the FQueries so things happen FIFO (as opposed to dispatch_get_global_queue(0, 0) which is concurrent)
static dispatch_once_t pred;
static dispatch_queue_t sharedDispatchQueue;
-
+
dispatch_once(&pred, ^{
sharedDispatchQueue = dispatch_queue_create("FirebaseWorker", NULL);
});
-
+
return sharedDispatchQueue;
}
diff --git a/Firebase/Database/Core/FPersistentConnection.m b/Firebase/Database/Core/FPersistentConnection.m
index dc5877f..826b995 100644
--- a/Firebase/Database/Core/FPersistentConnection.m
+++ b/Firebase/Database/Core/FPersistentConnection.m
@@ -282,7 +282,7 @@ typedef enum {
if (firstConnection) {
[self sendConnectStats];
}
-
+
[self restoreAuth];
firstConnection = NO;
self.lastSessionID = sessionID;
@@ -564,7 +564,7 @@ static void reachabilityCallback(SCNetworkReachabilityRef ref, SCNetworkReachabi
FOutstandingPut* put = self.outstandingPuts[index];
assert(put != nil);
fbt_void_nsstring_nsstring onComplete = put.onCompleteBlock;
-
+
// Do not async this block; copying the block insinde sendAction: doesn't happen in time (or something) so coredumps
put.sent = YES;
[self sendAction:put.action
@@ -611,23 +611,23 @@ static void reachabilityCallback(SCNetworkReachabilityRef ref, SCNetworkReachabi
}
- (void) putInternal:(id)data forAction:(NSString *)action forPath:(NSString *)pathString withHash:(NSString *)hash withCallback:(fbt_void_nsstring_nsstring)onComplete {
-
+
NSMutableDictionary *request = [NSMutableDictionary dictionaryWithObjectsAndKeys:
pathString, kFWPRequestPath,
data, kFWPRequestData, nil];
if(hash) {
[request setObject:hash forKey:kFWPRequestHash];
}
-
+
FOutstandingPut *put = [[FOutstandingPut alloc] init];
put.action = action;
put.request = request;
put.onCompleteBlock = onComplete;
put.sent = NO;
-
+
NSNumber* index = [self.putCounter getAndIncrement];
self.outstandingPuts[index] = put;
-
+
if ([self canSendWrites]) {
FFLog(@"I-RDB034024", @"Was connected, and added as index: %@", index);
[self sendPut:index];
@@ -725,7 +725,7 @@ static void reachabilityCallback(SCNetworkReachabilityRef ref, SCNetworkReachabi
nil];
[self.realtime sendRequest:msg sensitive:sensitive];
-
+
if (onMessage) {
// Debug message without a callback; bump the rn, but don't hold onto the cb
[self.requestCBHash setObject:[onMessage copy] forKey:rn];
diff --git a/Firebase/Database/Core/FRepo.h b/Firebase/Database/Core/FRepo.h
index 69ec6bf..ab0b074 100644
--- a/Firebase/Database/Core/FRepo.h
+++ b/Firebase/Database/Core/FRepo.h
@@ -42,7 +42,7 @@
- (void) addEventRegistration:(id<FEventRegistration>)eventRegistration forQuery:(FQuerySpec *)query;
- (void) removeEventRegistration:(id<FEventRegistration>)eventRegistration forQuery:(FQuerySpec *)query;
- (void) keepQuery:(FQuerySpec *)query synced:(BOOL)synced;
-
+
- (NSString*)name;
- (NSTimeInterval)serverTime;
diff --git a/Firebase/Database/Core/FRepo.m b/Firebase/Database/Core/FRepo.m
index 17e7480..bb176c0 100644
--- a/Firebase/Database/Core/FRepo.m
+++ b/Firebase/Database/Core/FRepo.m
@@ -457,7 +457,7 @@
// For testing.
self.dataUpdateCount++;
-
+
FPath* path = [[FPath alloc] initWith:pathString];
data = self.interceptServerDataCallback ? self.interceptServerDataCallback(pathString, data) : data;
NSArray *events = nil;
@@ -543,7 +543,7 @@
- (void) didEnterBackground {
if (!self.config.persistenceEnabled)
return;
-
+
// Targetted compilation is ONLY for testing. UIKit is weak-linked in actual release build.
#if TARGET_OS_IOS
// The idea is to wait until any outstanding sets get written to disk. Since the sets might still be in our
diff --git a/Firebase/Database/Core/Utilities/FPath.m b/Firebase/Database/Core/Utilities/FPath.m
index 485b903..5215596 100644
--- a/Firebase/Database/Core/Utilities/FPath.m
+++ b/Firebase/Database/Core/Utilities/FPath.m
@@ -175,11 +175,11 @@
for (NSInteger i = self.pieceNum; i < self.pieces.count; i++) {
[newPieces addObject:[self.pieces objectAtIndex:i]];
}
-
+
for (NSInteger i = childPathObj.pieceNum; i < childPathObj.pieces.count; i++) {
[newPieces addObject:[childPathObj.pieces objectAtIndex:i]];
}
-
+
return [[FPath alloc] initWithPieces:newPieces andPieceNum:0];
}
diff --git a/Firebase/Database/Core/Utilities/FTree.m b/Firebase/Database/Core/Utilities/FTree.m
index 8576ffb..8e7a334 100644
--- a/Firebase/Database/Core/Utilities/FTree.m
+++ b/Firebase/Database/Core/Utilities/FTree.m
@@ -107,11 +107,11 @@
if(incSelf && !childFirst) {
action(self);
}
-
+
[self forEachChild:^(FTree* child) {
[child forEachDescendant:action includeSelf:YES childrenFirst:childFirst];
}];
-
+
if(incSelf && childFirst) {
action(self);
}
diff --git a/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBEmptyNode.m b/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBEmptyNode.m
index adbc6ca..5528285 100644
--- a/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBEmptyNode.m
+++ b/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBEmptyNode.m
@@ -44,7 +44,7 @@
return result;
}
-- (id<FLLRBNode>) remove:(id) key withComparator:(NSComparator)aComparator {
+- (id<FLLRBNode>) remove:(id) key withComparator:(NSComparator)aComparator {
return self;
}
diff --git a/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBValueNode.m b/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBValueNode.m
index f361278..fb0dc8d 100644
--- a/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBValueNode.m
+++ b/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FLLRBValueNode.m
@@ -95,7 +95,7 @@
- (id<FLLRBNode>) insertKey:(__unsafe_unretained id) aKey forValue:(__unsafe_unretained id)aValue withComparator:(NSComparator)aComparator {
NSComparisonResult cmp = aComparator(aKey, self.key);
FLLRBValueNode* n = self;
-
+
if(cmp == NSOrderedAscending) {
n = [n copyWith:nil withValue:nil withColor:nil withLeft:[n.left insertKey:aKey forValue:aValue withComparator:aComparator] withRight:nil];
}
@@ -105,7 +105,7 @@
else {
n = [n copyWith:nil withValue:nil withColor:nil withLeft:nil withRight:[n.right insertKey:aKey forValue:aValue withComparator:aComparator]];
}
-
+
return [n fixUp];
}
@@ -114,12 +114,12 @@
if([self.left isEmpty]) {
return [FLLRBEmptyNode emptyNode];
}
-
+
FLLRBValueNode* n = self;
if(! [n.left isRed] && ! [n.left.left isRed]) {
n = [n moveRedLeft];
}
-
+
n = [n copyWith:nil withValue:nil withColor:nil withLeft:[(FLLRBValueNode*)n.left removeMin] withRight:nil];
return [n fixUp];
}
@@ -165,14 +165,14 @@
- (id<FLLRBNode>) colorFlip {
id<FLLRBNode> nleft = [self.left copyWith:nil withValue:nil withColor:[NSNumber numberWithBool:![self.left.color boolValue]] withLeft:nil withRight:nil];
id<FLLRBNode> nright = [self.right copyWith:nil withValue:nil withColor:[NSNumber numberWithBool:![self.right.color boolValue]] withLeft:nil withRight:nil];
-
+
return [self copyWith:nil withValue:nil withColor:[NSNumber numberWithBool:![self.color boolValue]] withLeft:nleft withRight:nright];
}
- (id<FLLRBNode>) remove:(__unsafe_unretained id) aKey withComparator:(NSComparator)comparator {
id<FLLRBNode> smallest;
FLLRBValueNode* n = self;
-
+
if(comparator(aKey, n.key) == NSOrderedAscending) {
if(![n.left isEmpty] && ![n.left isRed] && ![n.left.left isRed]) {
n = [n moveRedLeft];
@@ -183,11 +183,11 @@
if([n.left isRed]) {
n = [n rotateRight];
}
-
+
if(![n.right isEmpty] && ![n.right isRed] && ![n.right.left isRed]) {
n = [n moveRedRight];
}
-
+
if(comparator(aKey, n.key) == NSOrderedSame) {
if([n.right isEmpty]) {
return [FLLRBEmptyNode emptyNode];
@@ -218,15 +218,15 @@
- (int) check {
int blackDepth = 0;
-
+
if([self isRed] && [self.left isRed]) {
@throw [[NSException alloc] initWithName:@"check" reason:@"Red node has a red child" userInfo:nil];
}
-
+
if([self.right isRed]) {
@throw [[NSException alloc] initWithName:@"check" reason:@"Right child is red" userInfo:nil];
}
-
+
blackDepth = [self.left check];
// NSLog(err);
if(blackDepth != [self.right check]) {
diff --git a/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FTreeSortedDictionaryEnumerator.m b/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FTreeSortedDictionaryEnumerator.m
index 6636d1e..8eb30be 100644
--- a/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FTreeSortedDictionaryEnumerator.m
+++ b/Firebase/Database/FImmutableSortedDictionary/FImmutableSortedDictionary/FTreeSortedDictionaryEnumerator.m
@@ -71,7 +71,7 @@
if([self.stack count] == 0) {
return nil;
}
-
+
id<FLLRBNode> node = nil;
@synchronized(self.stack) {
node = [self.stack lastObject];
diff --git a/Firebase/Database/FViewProcessor.m b/Firebase/Database/FViewProcessor.m
index 41ff91d..8acefb8 100644
--- a/Firebase/Database/FViewProcessor.m
+++ b/Firebase/Database/FViewProcessor.m
@@ -522,7 +522,7 @@
accumulator:accumulator];
}
}];
-
+
return curViewCache;
}
diff --git a/Firebase/Database/Public/FIRDataSnapshot.h b/Firebase/Database/Public/FIRDataSnapshot.h
index e615260..c3082df 100644
--- a/Firebase/Database/Public/FIRDataSnapshot.h
+++ b/Firebase/Database/Public/FIRDataSnapshot.h
@@ -38,7 +38,7 @@ FIR_SWIFT_NAME(DataSnapshot)
/**
* Gets a FIRDataSnapshot for the location at the specified relative path.
- * The relative path can either be a simple child key (e.g. 'fred')
+ * The relative path can either be a simple child key (e.g. 'fred')
* or a deeper slash-separated path (e.g. 'fred/name/first'). If the child
* location has no data, an empty FIRDataSnapshot is returned.
*
@@ -59,7 +59,7 @@ FIR_SWIFT_NAME(DataSnapshot)
/**
* Return YES if the DataSnapshot has any children.
- *
+ *
* @return YES if this snapshot has any children, else NO.
*/
- (BOOL) hasChildren;
@@ -78,7 +78,7 @@ FIR_SWIFT_NAME(DataSnapshot)
/**
* Returns the raw value at this location, coupled with any metadata, such as priority.
*
- * Priorities, where they exist, are accessible under the ".priority" key in instances of NSDictionary.
+ * Priorities, where they exist, are accessible under the ".priority" key in instances of NSDictionary.
* For leaf locations with priorities, the value will be under the ".value" key.
*/
- (id __nullable) valueInExportFormat;
diff --git a/Firebase/Database/Public/FIRDatabase.h b/Firebase/Database/Public/FIRDatabase.h
index ebdbf8a..fd4535f 100644
--- a/Firebase/Database/Public/FIRDatabase.h
+++ b/Firebase/Database/Public/FIRDatabase.h
@@ -29,9 +29,9 @@ NS_ASSUME_NONNULL_BEGIN
*/
FIR_SWIFT_NAME(Database)
@interface FIRDatabase : NSObject
-
+
/**
- * The NSObject initializer that has been marked as unavailable. Use the `database`
+ * The NSObject initializer that has been marked as unavailable. Use the `database`
* method instead
*
* @return An instancetype instance
diff --git a/Firebase/Database/Public/FIRDatabaseReference.h b/Firebase/Database/Public/FIRDatabaseReference.h
index eb3fecd..53d0cdd 100644
--- a/Firebase/Database/Public/FIRDatabaseReference.h
+++ b/Firebase/Database/Public/FIRDatabaseReference.h
@@ -74,8 +74,8 @@ FIR_SWIFT_NAME(DatabaseReference)
/** Write data to this Firebase Database location.
-This will overwrite any data at this location and all child locations.
-
+This will overwrite any data at this location and all child locations.
+
Data types that can be set are:
- NSString -- @"Hello World"
@@ -86,7 +86,7 @@ Data types that can be set are:
The effect of the write will be visible immediately and the corresponding
events will be triggered. Synchronization of the data to the Firebase Database
servers will also be started.
-
+
Passing null for the new value is equivalent to calling remove:;
all data at this location or any child location will be deleted.
@@ -131,7 +131,7 @@ is meant to be preserved, you should use setValue:andPriority: instead.
/**
* Remove the data at this Firebase Database location. Any data at child locations will also be deleted.
- *
+ *
* The effect of the delete will be visible immediately and the corresponding events
* will be triggered. Synchronization of the delete to the Firebase Database servers will
* also be started.
@@ -165,7 +165,7 @@ is meant to be preserved, you should use setValue:andPriority: instead.
* Children with a string as their priority come last. They are sorted lexicographically by priority.
* Whenever two children have the same priority (including no priority), they are sorted by key. Numeric
* keys come first (sorted numerically), followed by the remaining keys (sorted lexicographically).
- *
+ *
* Note that priorities are parsed and ordered as IEEE 754 double-precision floating-point numbers.
* Keys are always stored as strings and are treated as numbers only when they can be parsed as a
* 32-bit integer
@@ -193,7 +193,7 @@ is meant to be preserved, you should use setValue:andPriority: instead.
- (void) updateChildValues:(NSDictionary *)values;
/**
- * The same as update: with a block that is called once the update has been committed to the
+ * The same as update: with a block that is called once the update has been committed to the
* Firebase Database servers
*
* @param values A dictionary of the keys to change and their new values
@@ -553,7 +553,7 @@ is meant to be preserved, you should use setValue:andPriority: instead.
/**
* Cancel any operations that are set to run on disconnect. If you previously called onDisconnectSetValue:,
- * onDisconnectRemoveValue:, or onDisconnectUpdateChildValues:, and no longer want the values updated when the
+ * onDisconnectRemoveValue:, or onDisconnectUpdateChildValues:, and no longer want the values updated when the
* connection is lost, call cancelDisconnectOperations:
*/
- (void) cancelDisconnectOperations;
@@ -575,19 +575,19 @@ is meant to be preserved, you should use setValue:andPriority: instead.
* Manually disconnect the Firebase Database client from the server and disable automatic reconnection.
*
* The Firebase Database client automatically maintains a persistent connection to the Firebase Database server,
- * which will remain active indefinitely and reconnect when disconnected. However, the goOffline( )
- * and goOnline( ) methods may be used to manually control the client connection in cases where
+ * which will remain active indefinitely and reconnect when disconnected. However, the goOffline( )
+ * and goOnline( ) methods may be used to manually control the client connection in cases where
* a persistent connection is undesirable.
- *
+ *
* While offline, the Firebase Database client will no longer receive data updates from the server. However,
* all database operations performed locally will continue to immediately fire events, allowing
- * your application to continue behaving normally. Additionally, each operation performed locally
+ * your application to continue behaving normally. Additionally, each operation performed locally
* will automatically be queued and retried upon reconnection to the Firebase Database server.
- *
+ *
* To reconnect to the Firebase Database server and begin receiving remote events, see goOnline( ).
* Once the connection is reestablished, the Firebase Database client will transmit the appropriate data
* and fire the appropriate events so that your client "catches up" automatically.
- *
+ *
* Note: Invoking this method will impact all Firebase Database connections.
*/
+ (void) goOffline;
@@ -596,16 +596,16 @@ is meant to be preserved, you should use setValue:andPriority: instead.
* Manually reestablish a connection to the Firebase Database server and enable automatic reconnection.
*
* The Firebase Database client automatically maintains a persistent connection to the Firebase Database server,
- * which will remain active indefinitely and reconnect when disconnected. However, the goOffline( )
- * and goOnline( ) methods may be used to manually control the client connection in cases where
+ * which will remain active indefinitely and reconnect when disconnected. However, the goOffline( )
+ * and goOnline( ) methods may be used to manually control the client connection in cases where
* a persistent connection is undesirable.
- *
- * This method should be used after invoking goOffline( ) to disable the active connection.
+ *
+ * This method should be used after invoking goOffline( ) to disable the active connection.
* Once reconnected, the Firebase Database client will automatically transmit the proper data and fire
* the appropriate events so that your client "catches up" automatically.
- *
+ *
* To disconnect from the Firebase Database server, see goOffline( ).
- *
+ *
* Note: Invoking this method will impact all Firebase Database connections.
*/
+ (void) goOnline;
diff --git a/Firebase/Database/Realtime/FConnection.m b/Firebase/Database/Realtime/FConnection.m
index 1550bfc..53f434c 100644
--- a/Firebase/Database/Realtime/FConnection.m
+++ b/Firebase/Database/Realtime/FConnection.m
@@ -67,13 +67,13 @@ typedef enum {
if (state != REALTIME_STATE_DISCONNECTED) {
FFLog(@"I-RDB082002", @"Closing realtime connection.");
state = REALTIME_STATE_DISCONNECTED;
-
+
if (self.conn) {
FFLog(@"I-RDB082003", @"Calling close again.");
[self.conn close];
self.conn = nil;
}
-
+
[self.delegate onDisconnect:self withReason:reason];
}
}
@@ -123,7 +123,7 @@ typedef enum {
} else if (state == REALTIME_STATE_CONNECTED) {
FFLog(@"I-RDB082007", @"Realtime connection lost.");
}
-
+
[self close];
}
@@ -138,7 +138,7 @@ typedef enum {
[self onControl:[message objectForKey:kFWPAsyncServerEnvelopeData]];
}
else {
- FFLog(@"I-RDB082008", @"Unrecognized server packet type: %@", rawMessageType);
+ FFLog(@"I-RDB082008", @"Unrecognized server packet type: %@", rawMessageType);
}
}
else {
@@ -174,7 +174,7 @@ typedef enum {
- (void) onConnectionShutdownWithReason:(NSString *)reason {
FFLog(@"I-RDB082013", @"Connection shutdown command received. Shutting down...");
-
+
[self.delegate onKill:self withReason:reason];
[self close];
}
@@ -184,9 +184,9 @@ typedef enum {
// NSString* version = [handshake objectForKey:kFWPAsyncServerHelloVersion];
NSString* host = [handshake objectForKey:kFWPAsyncServerHelloConnectedHost];
NSString* sessionID = [handshake objectForKey:kFWPAsyncServerHelloSession];
-
+
self.repoInfo.internalHost = host;
-
+
if (state == REALTIME_STATE_CONNECTING) {
[self.conn start];
[self onConnection:self.conn readyAtTime:timestamp sessionID:sessionID];
@@ -196,7 +196,7 @@ typedef enum {
- (void) onConnection:(FWebSocketConnection *)conn readyAtTime:(NSNumber *)timestamp sessionID:(NSString *)sessionID {
FFLog(@"I-RDB082014", @"Realtime connection established");
state = REALTIME_STATE_CONNECTED;
-
+
[self.delegate onReady:self atTime:timestamp sessionID:sessionID];
}
diff --git a/Firebase/Database/Realtime/FWebSocketConnection.m b/Firebase/Database/Realtime/FWebSocketConnection.m
index c4ead9e..5cd8bb0 100644
--- a/Firebase/Database/Realtime/FWebSocketConnection.m
+++ b/Firebase/Database/Realtime/FWebSocketConnection.m
@@ -65,11 +65,11 @@
self.totalFrames = 0;
self.dispatchQueue = queue;
frame = nil;
-
+
NSString* connectionUrl = [repoInfo connectionURLWithLastSessionID:lastSessionID];
NSString* ua = [self userAgent];
FFLog(@"I-RDB083001", @"(wsc:%@) Connecting to: %@ as %@", self.connectionId, connectionUrl, ua);
-
+
NSURLRequest* req = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:connectionUrl]];
self.webSocket = [[FSRWebSocket alloc] initWithURLRequest:req queue:queue andUserAgent:ua];
[self.webSocket setDelegateDispatchQueue:queue];
@@ -82,7 +82,7 @@
NSString* systemVersion;
NSString* deviceName;
BOOL hasUiDeviceClass = NO;
-
+
// Targetted compilation is ONLY for testing. UIKit is weak-linked in actual release build.
#if TARGET_OS_IOS
Class uiDeviceClass = NSClassFromString(@"UIDevice");
@@ -92,7 +92,7 @@
hasUiDeviceClass = YES;
}
#endif
-
+
if (!hasUiDeviceClass) {
NSDictionary *systemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
systemVersion = [systemVersionDictionary objectForKey:@"ProductVersion"];
@@ -143,19 +143,19 @@
[self resetKeepAlive];
- NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dictionary
+ NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dictionary
options:kNilOptions error:nil];
-
+
NSString* data = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
-
+
NSArray* dataSegs = [FUtilities splitString:data intoMaxSize:kWebsocketMaxFrameSize];
// First send the header so the server knows how many segments are forthcoming
if (dataSegs.count > 1) {
[self.webSocket send:[NSString stringWithFormat:@"%u", (unsigned int)dataSegs.count]];
}
-
+
// Then, actually send the segments.
for(NSString * segment in dataSegs) {
[self.webSocket send:segment];
@@ -165,7 +165,7 @@
- (void) nop:(NSTimer *)timer {
if (!isClosed) {
FFLog(@"I-RDB083004", @"(wsc:%@) nop", self.connectionId);
- [self.webSocket send:@"0"];
+ [self.webSocket send:@"0"];
}
else {
FFLog(@"I-RDB083005", @"(wsc:%@) No more websocket; invalidating nop timer.", self.connectionId);
@@ -202,7 +202,7 @@
error:nil];
frame = nil;
FFLog(@"I-RDB083007", @"(wsc:%@) handleIncomingFrame sending complete frame: %d", self.connectionId, self.totalFrames);
-
+
@autoreleasepool {
[self.delegate onMessage:self withMessage:json];
}
@@ -231,9 +231,9 @@
- (void)webSocketDidOpen:(FSRWebSocket *)webSocket
{
FFLog(@"I-RDB083008", @"(wsc:%@) webSocketDidOpen", self.connectionId);
-
+
everConnected = YES;
-
+
dispatch_async(dispatch_get_main_queue(), ^{
self->keepAlive = [NSTimer scheduledTimerWithTimeInterval:kWebsocketKeepaliveInterval
target:self
@@ -261,8 +261,8 @@
/**
* Note that the close / onClosed / shutdown cycle here is a little different from the javascript client.
- * In order to properly handle deallocation, no close-related action is taken at a higher level until we
- * have received notification from the websocket itself that it is closed. Otherwise, we end up deallocating
+ * In order to properly handle deallocation, no close-related action is taken at a higher level until we
+ * have received notification from the websocket itself that it is closed. Otherwise, we end up deallocating
* this class and the FConnection class before the websocket has a change to call some of its delegate methods.
* So, since close is the external close handler, we just set a flag saying not to call our own delegate method
* and close the websocket. That will trigger a callback into this class that can then do things like clean up
@@ -278,7 +278,7 @@
- (void) shutdown {
isClosed = YES;
-
+
// Call delegate methods
[self.delegate onDisconnect:self wasEverConnected:everConnected];
diff --git a/Firebase/Database/Snapshot/FChildrenNode.m b/Firebase/Database/Snapshot/FChildrenNode.m
index b5598ad..d53ae80 100644
--- a/Firebase/Database/Snapshot/FChildrenNode.m
+++ b/Firebase/Database/Snapshot/FChildrenNode.m
@@ -157,7 +157,7 @@
if([self isEmpty]) {
return [NSNull null];
}
-
+
__block int numKeys = 0;
__block NSInteger maxKey = 0;
__block BOOL allIntegerKeys = YES;
@@ -208,7 +208,7 @@
if(exp && [self getPriority] != nil && !self.getPriority.isEmpty) {
obj[kPayloadPriority] = [self.getPriority val];
}
-
+
return obj;
}
}
diff --git a/Firebase/Database/Snapshot/FSnapshotUtilities.m b/Firebase/Database/Snapshot/FSnapshotUtilities.m
index 1b83430..c6012d3 100644
--- a/Firebase/Database/Snapshot/FSnapshotUtilities.m
+++ b/Firebase/Database/Snapshot/FSnapshotUtilities.m
@@ -52,7 +52,7 @@
+ (id<FNode>) internalNodeFrom:(id)val priority:(id)aPriority withValidationFrom:(NSString *)fn atDepth:(int)depth path:(NSMutableArray *)path {
-
+
if (depth > kFirebaseMaxObjectDepth) {
NSRange range;
range.location = 0;
@@ -179,7 +179,7 @@
[updatePaths addObject:path];
compoundWrite = [compoundWrite addWrite:node atPath:path];
}
-
+
// Check that the update paths are not descendants of each other.
[updatePaths sortUsingComparator:^NSComparisonResult(FPath* left, FPath* right) {
return [left compare:right];
diff --git a/Firebase/Database/Utilities/FAtomicNumber.m b/Firebase/Database/Utilities/FAtomicNumber.m
index be0e537..4a14caa 100644
--- a/Firebase/Database/Utilities/FAtomicNumber.m
+++ b/Firebase/Database/Utilities/FAtomicNumber.m
@@ -42,12 +42,12 @@
NSNumber* result;
// See: http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Multithreading/ThreadSafety/ThreadSafety.html#//apple_ref/doc/uid/10000057i-CH8-SW14 to improve, etc.
-
+
[self.lock lock];
result = [NSNumber numberWithUnsignedLong:number];
number = number + 1;
[self.lock unlock];
-
+
return result;
}
diff --git a/Firebase/Database/Utilities/FNextPushId.m b/Firebase/Database/Utilities/FNextPushId.m
index af54e3d..ee3ba13 100644
--- a/Firebase/Database/Utilities/FNextPushId.m
+++ b/Firebase/Database/Utilities/FNextPushId.m
@@ -26,20 +26,20 @@ static NSString *const PUSH_CHARS = @"-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcd
static int lastRandChars[12];
long long now = (long long)(currentTime * 1000);
-
+
BOOL duplicateTime = now == lastPushTime;
lastPushTime = now;
-
+
unichar timeStampChars[8];
for(int i = 7; i >= 0; i--) {
timeStampChars[i] = [PUSH_CHARS characterAtIndex:(now % 64)];
now = (long long)floor(now / 64);
}
-
+
NSMutableString* id = [[NSMutableString alloc] init];
[id appendString:[NSString stringWithCharacters:timeStampChars length:8]];
-
-
+
+
if(!duplicateTime) {
for(int i = 0; i < 12; i++) {
lastRandChars[i] = (int)floor(arc4random() % 64);
@@ -52,11 +52,11 @@ static NSString *const PUSH_CHARS = @"-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcd
}
lastRandChars[i]++;
}
-
+
for(int i = 0; i < 12; i++) {
[id appendFormat:@"%C", [PUSH_CHARS characterAtIndex:lastRandChars[i]]];
}
-
+
return [NSString stringWithString:id];
}
diff --git a/Firebase/Database/Utilities/FUtilities.m b/Firebase/Database/Utilities/FUtilities.m
index 7c25e3b..93b892a 100644
--- a/Firebase/Database/Utilities/FUtilities.m
+++ b/Firebase/Database/Utilities/FUtilities.m
@@ -41,7 +41,7 @@ void firebaseJobsTroll(void) {
#pragma mark Private property and singleton specification
@interface FUtilities() {
-
+
}
@property (nonatomic, strong) FAtomicNumber* localUid;
@@ -87,7 +87,7 @@ void firebaseJobsTroll(void) {
if(str.length <= size) {
return [NSArray arrayWithObject:str];
}
-
+
NSMutableArray* dataSegs = [[NSMutableArray alloc] init];
for(int c = 0; c < str.length; c += size) {
if (c + size > str.length) {
@@ -97,7 +97,7 @@ void firebaseJobsTroll(void) {
}
else {
int rangeStart = c;
- int rangeLength = size;
+ int rangeLength = size;
[dataSegs addObject:[str substringWithRange:NSMakeRange(rangeStart, rangeLength)]];
}
}
@@ -168,7 +168,7 @@ void firebaseJobsTroll(void) {
FRepoInfo* repoInfo = [[FRepoInfo alloc] initWithHost:host isSecure:secure withNamespace:namespace];
FFLog(@"I-RDB095002", @"---> Parsed (%@) to: (%@,%@); ns=(%@); path=(%@)", original, [repoInfo description], [repoInfo connectionURL], repoInfo.namespace, [path description]);
-
+
FParsedUrl* parsedUrl = [[FParsedUrl alloc] init];
parsedUrl.repoInfo = repoInfo;
parsedUrl.path = path;
diff --git a/Firebase/Database/Utilities/FValidation.m b/Firebase/Database/Utilities/FValidation.m
index c4c6b2b..f088da2 100644
--- a/Firebase/Database/Utilities/FValidation.m
+++ b/Firebase/Database/Utilities/FValidation.m
@@ -221,7 +221,7 @@ NSString *const kInvalidKeyCharacters = @"[].#$/";
[self validateFrom:fn isValidPriorityValue:value withPath:@[]];
} else {
keyNum++;
-
+
if (![FValidation isValidKey:key]) {
@throw [[NSException alloc] initWithName:@"InvalidFirebaseData" reason:[NSString stringWithFormat:@"(%@) Invalid key in object. Keys must be non-empty and cannot contain '.' '#' '$' '[' or ']'", fn] userInfo:nil];
}
diff --git a/Firebase/Database/third_party/SocketRocket/FSRWebSocket.h b/Firebase/Database/third_party/SocketRocket/FSRWebSocket.h
index dfda376..1ca1815 100644
--- a/Firebase/Database/third_party/SocketRocket/FSRWebSocket.h
+++ b/Firebase/Database/third_party/SocketRocket/FSRWebSocket.h
@@ -22,7 +22,7 @@ typedef enum {
SR_OPEN = 1,
SR_CLOSING = 2,
SR_CLOSED = 3,
-
+
} FSRReadyState;
@class FSRWebSocket;
@@ -74,7 +74,7 @@ extern NSString *const FSRWebSocketErrorDomain;
@protocol FSRWebSocketDelegate <NSObject>
-// message will either be an NSString if the server is using text
+// message will either be an NSString if the server is using text
// or NSData if the server is using binary
- (void)webSocket:(FSRWebSocket *)webSocket didReceiveMessage:(id)message;
diff --git a/Firebase/Database/third_party/SocketRocket/FSRWebSocket.m b/Firebase/Database/third_party/SocketRocket/FSRWebSocket.m
index f96d863..a2c857b 100644
--- a/Firebase/Database/third_party/SocketRocket/FSRWebSocket.m
+++ b/Firebase/Database/third_party/SocketRocket/FSRWebSocket.m
@@ -52,7 +52,7 @@
typedef enum {
SROpCodeTextFrame = 0x1,
SROpCodeBinaryFrame = 0x2,
- //3-7Reserved
+ //3-7Reserved
SROpCodeConnectionClose = 0x8,
SROpCodePing = 0x9,
SROpCodePong = 0xA,
@@ -117,13 +117,13 @@ static inline void SRFastLog(NSString *format, ...);
static NSString *newSHA1String(const char *bytes, size_t length) {
uint8_t md[CC_SHA1_DIGEST_LENGTH];
-
+
CC_SHA1(bytes, (int)length, md);
-
+
size_t buffer_size = ((sizeof(md) * 3 + 2) / 2);
-
+
char *buffer = (char *)malloc(buffer_size);
-
+
int len = f_b64_ntop(md, CC_SHA1_DIGEST_LENGTH, buffer, buffer_size);
if (len == -1) {
free(buffer);
@@ -232,10 +232,10 @@ typedef void (^data_callback)(FSRWebSocket *webSocket, NSData *data);
NSInputStream *_inputStream;
NSOutputStream *_outputStream;
-
+
NSMutableData *_readBuffer;
NSInteger _readBufferOffset;
-
+
NSMutableData *_outputBuffer;
NSInteger _outputBufferOffset;
@@ -244,18 +244,18 @@ typedef void (^data_callback)(FSRWebSocket *webSocket, NSData *data);
size_t _readOpCount;
uint32_t _currentStringScanPosition;
NSMutableData *_currentFrameData;
-
+
NSString *_closeReason;
-
+
NSString *_secKey;
-
+
BOOL _pinnedCertFound;
-
+
uint8_t _currentReadMaskKey[4];
size_t _currentReadMaskOffset;
BOOL _consumerStopped;
-
+
BOOL _closeWhenFinishedWriting;
BOOL _failed;
@@ -264,19 +264,19 @@ typedef void (^data_callback)(FSRWebSocket *webSocket, NSData *data);
NSString *_userAgent;
CFHTTPMessageRef _receivedHTTPHeaders;
-
+
BOOL _sentClose;
BOOL _didFail;
BOOL _cleanupScheduled;
int _closeCode;
-
+
BOOL _isPumping;
NSMutableSet *_scheduledRunloops;
-
+
// We use this to retain ourselves.
__strong FSRWebSocket *_selfRetain;
-
+
NSArray *_requestedProtocols;
FSRIOConsumerPool *_consumerPool;
}
@@ -300,26 +300,26 @@ static __strong NSData *CRLFCRLF;
assert(request.URL);
_url = request.URL;
NSString *scheme = [_url scheme];
-
+
_requestedProtocols = [protocols copy];
_userAgent = userAgent;
assert([scheme isEqualToString:@"ws"] || [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"wss"] || [scheme isEqualToString:@"https"]);
_urlRequest = request;
-
+
if ([scheme isEqualToString:@"wss"] || [scheme isEqualToString:@"https"]) {
_secure = YES;
}
-
+
if (!queue) {
_delegateDispatchQueue = dispatch_get_main_queue();
} else {
_delegateDispatchQueue = queue;
}
-
+
[self _SR_commonInit];
}
-
+
return self;
}
@@ -345,7 +345,7 @@ static __strong NSData *CRLFCRLF;
- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
{
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
+ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
return [self initWithURLRequest:request protocols:protocols];
}
@@ -354,9 +354,9 @@ static __strong NSData *CRLFCRLF;
_readyState = SR_CONNECTING;
_consumerStopped = YES;
-
+
_webSocketVersion = 13;
-
+
_workQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
// Going to set a specific on the queue so we can validate we're on the work queue
@@ -366,7 +366,7 @@ static __strong NSData *CRLFCRLF;
_readBuffer = [[NSMutableData alloc] init];
_outputBuffer = [[NSMutableData alloc] init];
-
+
_currentFrameData = [[NSMutableData alloc] init];
_consumers = [[NSMutableArray alloc] init];
@@ -376,7 +376,7 @@ static __strong NSData *CRLFCRLF;
_scheduledRunloops = [[NSMutableSet alloc] init];
[self _initializeStreams];
-
+
// default handlers
}
@@ -395,7 +395,7 @@ static __strong NSData *CRLFCRLF;
sr_dispatch_release(_workQueue);
_workQueue = NULL;
-
+
if (_receivedHTTPHeaders) {
CFRelease(_receivedHTTPHeaders);
_receivedHTTPHeaders = NULL;
@@ -460,29 +460,29 @@ static __strong NSData *CRLFCRLF;
if (acceptHeader == nil) {
return NO;
}
-
+
NSString *concattedString = [_secKey stringByAppendingString:SRWebSocketAppendToSecKeyString];
NSString *expectedAccept = [concattedString stringBySHA1ThenBase64Encoding];
-
+
return [acceptHeader isEqualToString:expectedAccept];
}
- (void)_HTTPHeadersDidFinish;
{
NSInteger responseCode = CFHTTPMessageGetResponseStatusCode(_receivedHTTPHeaders);
-
+
if (responseCode >= 400) {
SRFastLog(@"Request failed with response code %d", responseCode);
[self _failWithError:[NSError errorWithDomain:@"org.lolrus.SocketRocket" code:2132 userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"received bad response code from server %u", (int)responseCode] forKey:NSLocalizedDescriptionKey]]];
return;
}
-
+
if(![self _checkHandshake:_receivedHTTPHeaders]) {
[self _failWithError:[NSError errorWithDomain:FSRWebSocketErrorDomain code:2133 userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Invalid Sec-WebSocket-Accept response"] forKey:NSLocalizedDescriptionKey]]];
return;
}
-
+
NSString *negotiatedProtocol = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(_receivedHTTPHeaders, CFSTR("Sec-WebSocket-Protocol")));
if (negotiatedProtocol) {
// Make sure we requested the protocol
@@ -490,12 +490,12 @@ static __strong NSData *CRLFCRLF;
[self _failWithError:[NSError errorWithDomain:FSRWebSocketErrorDomain code:2133 userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Server specified Sec-WebSocket-Protocol that wasn't requested"] forKey:NSLocalizedDescriptionKey]]];
return;
}
-
+
_protocol = negotiatedProtocol;
}
-
+
self.readyState = SR_OPEN;
-
+
if (!_didFail) {
[self _readFrameNew];
}
@@ -513,10 +513,10 @@ static __strong NSData *CRLFCRLF;
if (_receivedHTTPHeaders == NULL) {
_receivedHTTPHeaders = CFHTTPMessageCreateEmpty(NULL, NO);
}
-
+
[self _readUntilHeaderCompleteWithCallback:^(FSRWebSocket *self, NSData *data) {
CFHTTPMessageAppendBytes(_receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length);
-
+
if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) {
SRFastLog(@"Finished reading headers %@", CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(_receivedHTTPHeaders)));
[self _HTTPHeadersDidFinish];
@@ -530,16 +530,16 @@ static __strong NSData *CRLFCRLF;
{
SRFastLog(@"Connected");
CFHTTPMessageRef request = CFHTTPMessageCreateRequest(NULL, CFSTR("GET"), (__bridge CFURLRef)_url, kCFHTTPVersion1_1);
-
+
// Set host first so it defaults
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Host"), (__bridge CFStringRef)(_url.port ? [NSString stringWithFormat:@"%@:%@", _url.host, _url.port] : _url.host));
-
+
NSMutableData *keyBytes = [[NSMutableData alloc] initWithLength:16];
int result = SecRandomCopyBytes(kSecRandomDefault, keyBytes.length, keyBytes.mutableBytes);
assert(result == 0);
_secKey = [FSRUtilities base64EncodedStringFromData:keyBytes];
assert([_secKey length] == 24);
-
+
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Upgrade"), CFSTR("websocket"));
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Connection"), CFSTR("Upgrade"));
if (_userAgent) {
@@ -548,9 +548,9 @@ static __strong NSData *CRLFCRLF;
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Sec-WebSocket-Key"), (__bridge CFStringRef)_secKey);
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Sec-WebSocket-Version"), (__bridge CFStringRef)[NSString stringWithFormat:@"%u", (int)_webSocketVersion]);
-
+
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Origin"), (__bridge CFStringRef)_url.SR_origin);
-
+
if (_requestedProtocols) {
CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Sec-WebSocket-Protocol"), (__bridge CFStringRef)[_requestedProtocols componentsJoinedByString:@", "]);
}
@@ -558,9 +558,9 @@ static __strong NSData *CRLFCRLF;
[_urlRequest.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
CFHTTPMessageSetHeaderFieldValue(request, (__bridge CFStringRef)key, (__bridge CFStringRef)obj);
}];
-
+
NSData *message = CFBridgingRelease(CFHTTPMessageCopySerializedMessage(request));
-
+
CFRelease(request);
[self _writeData:message];
@@ -582,34 +582,34 @@ static __strong NSData *CRLFCRLF;
CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
-
+
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)host, (int)port, &readStream, &writeStream);
-
+
// XXX
CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeBackground);
CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeBackground);
-
+
_outputStream = CFBridgingRelease(writeStream);
_inputStream = CFBridgingRelease(readStream);
-
-
+
+
if (_secure) {
NSMutableDictionary *SSLOptions = [[NSMutableDictionary alloc] init];
-
+
[_outputStream setProperty:(__bridge id)kCFStreamSocketSecurityLevelNegotiatedSSL forKey:(__bridge id)kCFStreamPropertySocketSecurityLevel];
-
+
// If we're using pinned certs, don't validate the certificate chain
if ([_urlRequest FSR_SSLPinnedCertificates].count) {
[SSLOptions setValue:[NSNumber numberWithBool:NO] forKey:(__bridge id)kCFStreamSSLValidatesCertificateChain];
}
-
+
[_outputStream setProperty:SSLOptions
forKey:(__bridge id)kCFStreamPropertySSLSettings];
}
-
+
_inputStream.delegate = self;
_outputStream.delegate = self;
-
+
[_outputStream open];
[_inputStream open];
}
@@ -653,7 +653,7 @@ static __strong NSData *CRLFCRLF;
if (self.readyState == SR_CLOSING || self.readyState == SR_CLOSED) {
return;
}
-
+
BOOL wasConnecting = self.readyState == SR_CONNECTING;
self.readyState = SR_CLOSING;
@@ -668,16 +668,16 @@ static __strong NSData *CRLFCRLF;
size_t maxMsgSize = [reason maximumLengthOfBytesUsingEncoding:NSUTF8StringEncoding];
NSMutableData *mutablePayload = [[NSMutableData alloc] initWithLength:sizeof(uint16_t) + maxMsgSize];
NSData *payload = mutablePayload;
-
+
((uint16_t *)mutablePayload.mutableBytes)[0] = EndianU16_BtoN(code);
-
+
if (reason) {
NSRange remainingRange = {0};
-
+
NSUInteger usedLength = 0;
-
+
BOOL success = [reason getBytes:(char *)mutablePayload.mutableBytes + sizeof(uint16_t) maxLength:payload.length - sizeof(uint16_t) usedLength:&usedLength encoding:NSUTF8StringEncoding options:NSStringEncodingConversionExternalRepresentation range:NSMakeRange(0, reason.length) remainingRange:&remainingRange];
-
+
assert(success);
assert(remainingRange.length == 0);
@@ -685,15 +685,15 @@ static __strong NSData *CRLFCRLF;
payload = [payload subdataWithRange:NSMakeRange(0, usedLength + sizeof(uint16_t))];
}
}
-
-
+
+
[self _sendFrameWithOpcode:SROpCodeConnectionClose data:payload];
});
}
- (void)_closeWithProtocolError:(NSString *)message;
{
- // Need to shunt this on the _callbackQueue first to see if they received any messages
+ // Need to shunt this on the _callbackQueue first to see if they received any messages
[self _performDelegateBlock:^{
[self closeWithCode:SRStatusCodeProtocolError reason:message];
dispatch_async(_workQueue, ^{
@@ -716,7 +716,7 @@ static __strong NSData *CRLFCRLF;
self.readyState = SR_CLOSED;
SRFastLog(@"Failing with error %@", error.localizedDescription);
-
+
[self _disconnect];
[self _scheduleCleanup];
}
@@ -724,7 +724,7 @@ static __strong NSData *CRLFCRLF;
}
- (void)_writeData:(NSData *)data;
-{
+{
[self assertOnWorkQueue];
if (_closeWhenFinishedWriting) {
@@ -782,7 +782,7 @@ static inline BOOL closeCodeIsValid(int closeCode) {
if (closeCode < 1000) {
return NO;
}
-
+
if (closeCode >= 1000 && closeCode <= 1011) {
if (closeCode == 1004 ||
closeCode == 1005 ||
@@ -791,11 +791,11 @@ static inline BOOL closeCodeIsValid(int closeCode) {
}
return YES;
}
-
+
if (closeCode >= 3000 && closeCode <= 3999) {
return YES;
}
-
+
if (closeCode >= 4000 && closeCode <= 4999) {
return YES;
}
@@ -816,9 +816,9 @@ static inline BOOL closeCodeIsValid(int closeCode) {
{
size_t dataSize = data.length;
__block uint16_t closeCode = 0;
-
+
SRFastLog(@"Received close frame");
-
+
if (dataSize == 1) {
// TODO handle error
[self _closeWithProtocolError:@"Payload for close must be larger than 2 bytes"];
@@ -840,9 +840,9 @@ static inline BOOL closeCodeIsValid(int closeCode) {
} else {
_closeCode = SRStatusNoStatusReceived;
}
-
+
[self assertOnWorkQueue];
-
+
if (self.readyState == SR_OPEN) {
[self closeWithCode:1000 reason:nil];
}
@@ -860,9 +860,9 @@ static inline BOOL closeCodeIsValid(int closeCode) {
}
- (void)_handleFrameWithData:(NSData *)frameData opCode:(NSInteger)opcode;
-{
+{
// Check that the current data is valid UTF8
-
+
BOOL isControlFrame = (opcode == SROpCodePing || opcode == SROpCodePong || opcode == SROpCodeConnectionClose);
if (!isControlFrame) {
[self _readFrameNew];
@@ -871,7 +871,7 @@ static inline BOOL closeCodeIsValid(int closeCode) {
[self _readFrameContinue];
});
}
-
+
switch (opcode) {
case SROpCodeTextFrame: {
NSString *str = [[NSString alloc] initWithData:frameData encoding:NSUTF8StringEncoding];
@@ -908,29 +908,29 @@ static inline BOOL closeCodeIsValid(int closeCode) {
- (void)_handleFrameHeader:(frame_header)frame_header curData:(NSData *)curData;
{
assert(frame_header.opcode != 0);
-
+
if (self.readyState != SR_OPEN) {
return;
}
-
-
+
+
BOOL isControlFrame = (frame_header.opcode == SROpCodePing || frame_header.opcode == SROpCodePong || frame_header.opcode == SROpCodeConnectionClose);
-
+
if (isControlFrame && !frame_header.fin) {
[self _closeWithProtocolError:@"Fragmented control frames not allowed"];
return;
}
-
+
if (isControlFrame && frame_header.payload_length >= 126) {
[self _closeWithProtocolError:@"Control frames cannot have payloads larger than 126 bytes"];
return;
}
-
+
if (!isControlFrame) {
_currentFrameOpcode = frame_header.opcode;
_currentFrameCount += 1;
}
-
+
if (frame_header.payload_length == 0) {
if (isControlFrame) {
[self _handleFrameWithData:curData opCode:frame_header.opcode];
@@ -953,7 +953,7 @@ static inline BOOL closeCodeIsValid(int closeCode) {
// TODO add assert that opcode is not a control;
[self _readFrameContinue];
}
-
+
}
} readToCurrentFrame:!isControlFrame unmaskBytes:frame_header.masked];
}
@@ -994,51 +994,51 @@ static const uint8_t SRPayloadLenMask = 0x7F;
[self _addConsumerWithDataLength:2 callback:^(FSRWebSocket *self, NSData *data) {
__block frame_header header = {0};
-
+
const uint8_t *headerBuffer = data.bytes;
assert(data.length >= 2);
-
+
if (headerBuffer[0] & SRRsvMask) {
[self _closeWithProtocolError:@"Server used RSV bits"];
return;
}
-
+
uint8_t receivedOpcode = (SROpCodeMask & headerBuffer[0]);
-
+
BOOL isControlFrame = (receivedOpcode == SROpCodePing || receivedOpcode == SROpCodePong || receivedOpcode == SROpCodeConnectionClose);
-
+
if (!isControlFrame && receivedOpcode != 0 && self->_currentFrameCount > 0) {
[self _closeWithProtocolError:@"all data frames after the initial data frame must have opcode 0"];
return;
}
-
+
if (receivedOpcode == 0 && self->_currentFrameCount == 0) {
[self _closeWithProtocolError:@"cannot continue a message"];
return;
}
-
+
header.opcode = receivedOpcode == 0 ? self->_currentFrameOpcode : receivedOpcode;
-
+
header.fin = !!(SRFinMask & headerBuffer[0]);
-
-
+
+
header.masked = !!(SRMaskMask & headerBuffer[1]);
header.payload_length = SRPayloadLenMask & headerBuffer[1];
-
+
headerBuffer = NULL;
-
+
if (header.masked) {
[self _closeWithProtocolError:@"Client must receive unmasked data"];
}
-
+
size_t extra_bytes_needed = header.masked ? sizeof(_currentReadMaskKey) : 0;
-
+
if (header.payload_length == 126) {
extra_bytes_needed += sizeof(uint16_t);
} else if (header.payload_length == 127) {
extra_bytes_needed += sizeof(uint64_t);
}
-
+
if (extra_bytes_needed == 0) {
[self _handleFrameHeader:header curData:self->_currentFrameData];
} else {
@@ -1046,7 +1046,7 @@ static const uint8_t SRPayloadLenMask = 0x7F;
size_t mapped_size = data.length;
const void *mapped_buffer = data.bytes;
size_t offset = 0;
-
+
if (header.payload_length == 126) {
assert(mapped_size >= sizeof(uint16_t));
uint16_t newLen = EndianU16_BtoN(*(uint16_t *)(mapped_buffer));
@@ -1059,13 +1059,13 @@ static const uint8_t SRPayloadLenMask = 0x7F;
} else {
assert(header.payload_length < 126 && header.payload_length >= 0);
}
-
-
+
+
if (header.masked) {
assert(mapped_size >= sizeof(_currentReadMaskOffset) + offset);
memcpy(self->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(self->_currentReadMaskKey));
}
-
+
[self _handleFrameHeader:header curData:self->_currentFrameData];
} readToCurrentFrame:NO unmaskBytes:NO];
}
@@ -1076,12 +1076,12 @@ static const uint8_t SRPayloadLenMask = 0x7F;
{
dispatch_async(_workQueue, ^{
[_currentFrameData setLength:0];
-
+
_currentFrameOpcode = 0;
_currentFrameCount = 0;
_readOpCount = 0;
_currentStringScanPosition = 0;
-
+
[self _readFrameContinue];
});
}
@@ -1097,17 +1097,17 @@ static const uint8_t SRPayloadLenMask = 0x7F;
[self _failWithError:[NSError errorWithDomain:@"org.lolrus.SocketRocket" code:2145 userInfo:[NSDictionary dictionaryWithObject:@"Error writing to stream" forKey:NSLocalizedDescriptionKey]]];
return;
}
-
+
_outputBufferOffset += bytesWritten;
-
+
if (_outputBufferOffset > 4096 && _outputBufferOffset > (_outputBuffer.length >> 1)) {
_outputBuffer = [[NSMutableData alloc] initWithBytes:(char *)_outputBuffer.bytes + _outputBufferOffset length:_outputBuffer.length - _outputBufferOffset];
_outputBufferOffset = 0;
}
}
-
- if (_closeWhenFinishedWriting &&
- _outputBuffer.length - _outputBufferOffset == 0 &&
+
+ if (_closeWhenFinishedWriting &&
+ _outputBuffer.length - _outputBufferOffset == 0 &&
(_inputStream.streamStatus != NSStreamStatusNotOpen &&
_inputStream.streamStatus != NSStreamStatusClosed) &&
!_sentClose) {
@@ -1119,7 +1119,7 @@ static const uint8_t SRPayloadLenMask = 0x7F;
// TODO: Why are we missing the SocketRocket code to call unscheduleFromRunLoop???
}
-
+
if (!_failed) {
[self _performDelegateBlock:^{
if ([self.delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)]) {
@@ -1138,7 +1138,7 @@ static const uint8_t SRPayloadLenMask = 0x7F;
}
- (void)_addConsumerWithDataLength:(size_t)dataLength callback:(data_callback)callback readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
-{
+{
[self assertOnWorkQueue];
assert(dataLength);
@@ -1147,7 +1147,7 @@ static const uint8_t SRPayloadLenMask = 0x7F;
}
- (void)_addConsumerWithScanner:(stream_scanner)consumer callback:(data_callback)callback dataLength:(size_t)dataLength;
-{
+{
[self assertOnWorkQueue];
[_consumers addObject:[_consumerPool consumerWithScanner:consumer handler:callback bytesNeeded:dataLength readToCurrentFrame:NO unmaskBytes:NO]];
[self _pumpScanner];
@@ -1202,7 +1202,7 @@ static const char CRLFCRLFBytes[] = {'\r', '\n', '\r', '\n'};
stream_scanner consumer = ^size_t(NSData *data) {
__block size_t found_size = 0;
__block size_t match_count = 0;
-
+
size_t size = data.length;
const unsigned char *buffer = data.bytes;
for (int i = 0; i < size; i++ ) {
@@ -1224,29 +1224,29 @@ static const char CRLFCRLFBytes[] = {'\r', '\n', '\r', '\n'};
// Returns true if did work
- (BOOL)_innerPumpScanner {
-
+
BOOL didWork = NO;
-
+
if (self.readyState >= SR_CLOSING) {
return didWork;
}
-
+
if (!_consumers.count) {
return didWork;
}
-
+
size_t curSize = _readBuffer.length - _readBufferOffset;
if (!curSize) {
return didWork;
}
-
+
FSRIOConsumer *consumer = [_consumers objectAtIndex:0];
-
+
size_t bytesNeeded = consumer.bytesNeeded;
-
+
size_t foundSize = 0;
if (consumer.consumer) {
- NSData *tempView = [NSData dataWithBytesNoCopy:(char *)_readBuffer.bytes + _readBufferOffset length:_readBuffer.length - _readBufferOffset freeWhenDone:NO];
+ NSData *tempView = [NSData dataWithBytesNoCopy:(char *)_readBuffer.bytes + _readBufferOffset length:_readBuffer.length - _readBufferOffset freeWhenDone:NO];
foundSize = consumer.consumer(tempView);
} else {
assert(consumer.bytesNeeded);
@@ -1256,48 +1256,48 @@ static const char CRLFCRLFBytes[] = {'\r', '\n', '\r', '\n'};
foundSize = curSize;
}
}
-
+
NSData *slice = nil;
if (consumer.readToCurrentFrame || foundSize) {
NSRange sliceRange = NSMakeRange(_readBufferOffset, foundSize);
slice = [_readBuffer subdataWithRange:sliceRange];
-
+
_readBufferOffset += foundSize;
-
+
if (_readBufferOffset > 4096 && _readBufferOffset > (_readBuffer.length >> 1)) {
_readBuffer = [[NSMutableData alloc] initWithBytes:(char *)_readBuffer.bytes + _readBufferOffset length:_readBuffer.length - _readBufferOffset]; _readBufferOffset = 0;
}
-
+
if (consumer.unmaskBytes) {
NSMutableData *mutableSlice = [slice mutableCopy];
-
+
NSUInteger len = mutableSlice.length;
uint8_t *bytes = mutableSlice.mutableBytes;
-
+
for (int i = 0; i < len; i++) {
bytes[i] = bytes[i] ^ _currentReadMaskKey[_currentReadMaskOffset % sizeof(_currentReadMaskKey)];
_currentReadMaskOffset += 1;
}
-
+
slice = mutableSlice;
}
-
+
if (consumer.readToCurrentFrame) {
[_currentFrameData appendData:slice];
-
+
_readOpCount += 1;
-
+
if (_currentFrameOpcode == SROpCodeTextFrame) {
// Validate UTF8 stuff.
size_t currentDataSize = _currentFrameData.length;
if (_currentFrameOpcode == SROpCodeTextFrame && currentDataSize > 0) {
// TODO: Optimize the crap out of this. Don't really have to copy all the data each time
-
+
size_t scanSize = currentDataSize - _currentStringScanPosition;
-
+
NSData *scan_data = [_currentFrameData subdataWithRange:NSMakeRange(_currentStringScanPosition, scanSize)];
int32_t valid_utf8_size = validate_dispatch_data_partial_string(scan_data);
-
+
if (valid_utf8_size == -1) {
[self closeWithCode:SRStatusCodeInvalidUTF8 reason:@"Text frames must be valid UTF-8"];
dispatch_async(_workQueue, ^{
@@ -1307,12 +1307,12 @@ static const char CRLFCRLFBytes[] = {'\r', '\n', '\r', '\n'};
} else {
_currentStringScanPosition += valid_utf8_size;
}
- }
-
+ }
+
}
-
+
consumer.bytesNeeded -= foundSize;
-
+
if (consumer.bytesNeeded == 0) {
[_consumers removeObjectAtIndex:0];
consumer.handler(self, nil);
@@ -1330,17 +1330,17 @@ static const char CRLFCRLFBytes[] = {'\r', '\n', '\r', '\n'};
-(void)_pumpScanner;
{
[self assertOnWorkQueue];
-
+
if (!_isPumping) {
_isPumping = YES;
} else {
return;
}
-
+
while ([self _innerPumpScanner]) {
-
+
}
-
+
_isPumping = NO;
}
@@ -1351,33 +1351,33 @@ static const size_t SRFrameHeaderOverhead = 32;
- (void)_sendFrameWithOpcode:(FSROpCode)opcode data:(id)data;
{
[self assertOnWorkQueue];
-
+
NSAssert(data == nil || [data isKindOfClass:[NSData class]] || [data isKindOfClass:[NSString class]], @"Function expects nil, NSString or NSData");
-
+
size_t payloadLength = [data isKindOfClass:[NSString class]] ? [(NSString *)data lengthOfBytesUsingEncoding:NSUTF8StringEncoding] : [data length];
-
+
NSMutableData *frame = [[NSMutableData alloc] initWithLength:payloadLength + SRFrameHeaderOverhead];
if (!frame) {
[self closeWithCode:SRStatusCodeMessageTooBig reason:@"Message too big"];
return;
}
uint8_t *frame_buffer = (uint8_t *)[frame mutableBytes];
-
+
// set fin
frame_buffer[0] = SRFinMask | opcode;
-
+
BOOL useMask = YES;
#ifdef NOMASK
useMask = NO;
#endif
-
+
if (useMask) {
// set the mask and header
frame_buffer[1] |= SRMaskMask;
}
-
+
size_t frame_buffer_size = 2;
-
+
const uint8_t *unmasked_payload = NULL;
if ([data isKindOfClass:[NSData class]]) {
unmasked_payload = (uint8_t *)[data bytes];
@@ -1386,7 +1386,7 @@ static const size_t SRFrameHeaderOverhead = 32;
} else {
assert(NO);
}
-
+
if (payloadLength < 126) {
frame_buffer[1] |= payloadLength;
} else if (payloadLength <= UINT16_MAX) {
@@ -1398,7 +1398,7 @@ static const size_t SRFrameHeaderOverhead = 32;
*((uint64_t *)(frame_buffer + frame_buffer_size)) = EndianU64_BtoN((uint64_t)payloadLength);
frame_buffer_size += sizeof(uint64_t);
}
-
+
if (!useMask) {
for (int i = 0; i < payloadLength; i++) {
frame_buffer[frame_buffer_size] = unmasked_payload[i];
@@ -1409,7 +1409,7 @@ static const size_t SRFrameHeaderOverhead = 32;
int result = SecRandomCopyBytes(kSecRandomDefault, sizeof(uint32_t), (uint8_t *)mask_key);
assert(result == 0);
frame_buffer_size += sizeof(uint32_t);
-
+
// TODO: could probably optimize this with SIMD
for (int i = 0; i < payloadLength; i++) {
frame_buffer[frame_buffer_size] = unmasked_payload[i] ^ mask_key[i % sizeof(uint32_t)];
@@ -1419,7 +1419,7 @@ static const size_t SRFrameHeaderOverhead = 32;
assert(frame_buffer_size <= [frame length]);
frame.length = frame_buffer_size;
-
+
[self _writeData:frame];
}
@@ -1445,7 +1445,7 @@ static const size_t SRFrameHeaderOverhead = 32;
}
if (_secure && !_pinnedCertFound && (eventCode == NSStreamEventHasBytesAvailable || eventCode == NSStreamEventHasSpaceAvailable)) {
-
+
NSArray *sslCerts = [_urlRequest FSR_SSLPinnedCertificates];
if (sslCerts) {
SecTrustRef secTrust = (__bridge SecTrustRef)[aStream propertyForKey:(__bridge id)kCFStreamPropertySSLPeerTrust];
@@ -1454,11 +1454,11 @@ static const size_t SRFrameHeaderOverhead = 32;
for (NSInteger i = 0; i < numCerts && !_pinnedCertFound; i++) {
SecCertificateRef cert = SecTrustGetCertificateAtIndex(secTrust, i);
NSData *certData = CFBridgingRelease(SecCertificateCopyData(cert));
-
+
for (id ref in sslCerts) {
SecCertificateRef trustedCert = (__bridge SecCertificateRef)ref;
NSData *trustedCertData = CFBridgingRelease(SecCertificateCopyData(trustedCert));
-
+
if ([trustedCertData isEqualToData:certData]) {
_pinnedCertFound = YES;
break;
@@ -1466,7 +1466,7 @@ static const size_t SRFrameHeaderOverhead = 32;
}
}
}
-
+
if (!_pinnedCertFound) {
dispatch_async(_workQueue, ^{
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : @"Invalid server cert" };
@@ -1669,13 +1669,13 @@ static const size_t SRFrameHeaderOverhead = 32;
- (NSString *)SR_origin;
{
NSString *scheme = [self.scheme lowercaseString];
-
+
if ([scheme isEqualToString:@"wss"]) {
scheme = @"https";
} else if ([scheme isEqualToString:@"ws"]) {
scheme = @"http";
}
-
+
if (self.port) {
return [NSString stringWithFormat:@"%@://%@:%@/", scheme, self.host, self.port];
} else {
@@ -1691,11 +1691,11 @@ static inline void SRFastLog(NSString *format, ...) {
#ifdef SR_ENABLE_LOG
__block va_list arg_list;
va_start (arg_list, format);
-
+
NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list];
-
+
va_end(arg_list);
-
+
NSLog(@"[SR] %@", formattedString);
#endif
}
@@ -1704,13 +1704,13 @@ static inline void SRFastLog(NSString *format, ...) {
#ifdef HAS_ICU
static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
-
+
const void * contents = [data bytes];
long size = [data length];
-
+
const uint8_t *str = (const uint8_t *)contents;
-
-
+
+
UChar32 codepoint = 1;
int32_t offset = 0;
int32_t lastOffset = 0;
@@ -1718,33 +1718,33 @@ static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
lastOffset = offset;
U8_NEXT(str, offset, size, codepoint);
}
-
+
if (codepoint == -1) {
// Check to see if the last byte is valid or whether it was just continuing
if (!U8_IS_LEAD(str[lastOffset]) || U8_COUNT_TRAIL_BYTES(str[lastOffset]) + lastOffset < (int32_t)size) {
-
+
size = -1;
} else {
uint8_t leadByte = str[lastOffset];
U8_MASK_LEAD_BYTE(leadByte, U8_COUNT_TRAIL_BYTES(leadByte));
-
+
for (int i = lastOffset + 1; i < offset; i++) {
-
+
if (U8_IS_SINGLE(str[i]) || U8_IS_LEAD(str[i]) || !U8_IS_TRAIL(str[i])) {
size = -1;
}
}
-
+
if (size != -1) {
size = lastOffset;
}
}
}
-
+
if (size != -1 && ![[NSString alloc] initWithBytesNoCopy:(char *)[data bytes] length:size encoding:NSUTF8StringEncoding freeWhenDone:NO]) {
size = -1;
}
-
+
return (int32_t)size;
}
@@ -1753,14 +1753,14 @@ static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
// This is a hack, and probably not optimal
static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
static const int maxCodepointSize = 3;
-
+
for (int i = 0; i < maxCodepointSize; i++) {
NSString *str = [[NSString alloc] initWithBytesNoCopy:(char *)data.bytes length:data.length - i encoding:NSUTF8StringEncoding freeWhenDone:NO];
if (str) {
return (int)(data.length - i);
}
}
-
+
return -1;
}
diff --git a/Firebase/Database/third_party/SocketRocket/fbase64.c b/Firebase/Database/third_party/SocketRocket/fbase64.c
index 1750673..238c23c 100644
--- a/Firebase/Database/third_party/SocketRocket/fbase64.c
+++ b/Firebase/Database/third_party/SocketRocket/fbase64.c
@@ -73,23 +73,23 @@ static const char Pad64 = '=';
The following encoding technique is taken from RFC 1521 by Borenstein
and Freed. It is reproduced here in a slightly edited form for
convenience.
-
+
A 65-character subset of US-ASCII is used, enabling 6 bits to be
represented per printable character. (The extra 65th character, "=",
is used to signify a special processing function.)
-
+
The encoding process represents 24-bit groups of input bits as output
strings of 4 encoded characters. Proceeding from left to right, a
24-bit input group is formed by concatenating 3 8-bit input groups.
These 24 bits are then treated as 4 concatenated 6-bit groups, each
of which is translated into a single digit in the base64 alphabet.
-
+
Each 6-bit group is used as an index into an array of 64 printable
characters. The character referenced by the index is placed in the
output string.
-
+
Table 1: The Base64 Alphabet
-
+
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
@@ -108,18 +108,18 @@ static const char Pad64 = '=';
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
-
+
Special processing is performed if fewer than 24 bits are available
at the end of the data being encoded. A full encoding quantum is
always completed at the end of a quantity. When fewer than 24 input
bits are available in an input group, zero bits are added (on the
right) to form an integral number of 6-bit groups. Padding at the
end of the data is performed using the '=' character.
-
+
Since all base64 input is an integral number of octets, only the
- -------------------------------------------------
+ -------------------------------------------------
following cases can arise:
-
+
(1) the final quantum of encoding input is an integral
multiple of 24 bits; here, the final unit of encoded
output will be an integral multiple of 4 characters
@@ -132,7 +132,7 @@ static const char Pad64 = '=';
characters followed by one "=" padding character.
*/
-#if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP)
+#if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP)
int
f_b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize)
{
@@ -140,18 +140,18 @@ f_b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize)
u_char input[3];
u_char output[4];
u_int i;
-
+
while (2 < srclength) {
input[0] = *src++;
input[1] = *src++;
input[2] = *src++;
srclength -= 3;
-
+
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
output[3] = input[2] & 0x3f;
-
+
if (datalength + 4 > targsize)
return (-1);
target[datalength++] = Base64[output[0]];
@@ -159,18 +159,18 @@ f_b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize)
target[datalength++] = Base64[output[2]];
target[datalength++] = Base64[output[3]];
}
-
+
/* Now we worry about padding. */
if (0 != srclength) {
/* Get what's left. */
input[0] = input[1] = input[2] = '\0';
for (i = 0; i < srclength; i++)
input[i] = *src++;
-
+
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
-
+
if (datalength + 4 > targsize)
return (-1);
target[datalength++] = Base64[output[0]];
@@ -202,21 +202,21 @@ f_b64_pton(char const *src, u_char *target, size_t targsize)
u_int tarindex, state;
int ch;
char *pos;
-
+
state = 0;
tarindex = 0;
-
+
while ((ch = *src++) != '\0') {
if (isspace(ch)) /* Skip whitespace anywhere. */
continue;
-
+
if (ch == Pad64)
break;
-
+
pos = strchr(Base64, ch);
if (pos == 0) /* A non-base64 character. */
return (-1);
-
+
switch (state) {
case 0:
if (target) {
@@ -259,19 +259,19 @@ f_b64_pton(char const *src, u_char *target, size_t targsize)
break;
}
}
-
+
/*
* We are done decoding Base-64 chars. Let's see if we ended
* on a byte boundary, and/or with erroneous trailing characters.
*/
-
+
if (ch == Pad64) { /* We got a pad char. */
ch = *src++; /* Skip it, get next. */
switch (state) {
case 0: /* Invalid = in first position */
case 1: /* Invalid = in second position */
return (-1);
-
+
case 2: /* Valid, means one byte of info */
/* Skip any number of spaces. */
for (; ch != '\0'; ch = *src++)
@@ -283,7 +283,7 @@ f_b64_pton(char const *src, u_char *target, size_t targsize)
ch = *src++; /* Skip the = */
/* Fall through to "single trailing =" case. */
/* FALLTHROUGH */
-
+
case 3: /* Valid, means two bytes of info */
/*
* We know this char is an =. Is there anything but
@@ -292,7 +292,7 @@ f_b64_pton(char const *src, u_char *target, size_t targsize)
for (; ch != '\0'; ch = *src++)
if (!isspace(ch))
return (-1);
-
+
/*
* Now make sure for cases 2 and 3 that the "extra"
* bits that slopped past the last full byte were
@@ -310,9 +310,9 @@ f_b64_pton(char const *src, u_char *target, size_t targsize)
if (state != 0)
return (-1);
}
-
+
return (tarindex);
}
#endif /* !defined(HAVE_B64_PTON) && !defined(HAVE___B64_PTON) */
-#endif \ No newline at end of file
+#endif
diff --git a/Firebase/Database/third_party/SocketRocket/fbase64.h b/Firebase/Database/third_party/SocketRocket/fbase64.h
index a9c55c9..a9bf142 100644
--- a/Firebase/Database/third_party/SocketRocket/fbase64.h
+++ b/Firebase/Database/third_party/SocketRocket/fbase64.h
@@ -26,7 +26,7 @@ f_b64_ntop(u_char const *src,
extern int
f_b64_pton(char const *src,
- u_char *target,
+ u_char *target,
size_t targsize);