Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Mass renaming of "TD" classes to "TD_"

Preparing for the public API which will have non-underscored names;
for instance, TDDatabase will be the public class, while the existing internal
class is TD_Database.
  • Loading branch information...
commit 677ba7c11aecdbe9fe01cff9d42bc349f496b99e 1 parent 9b4fa47
@snej snej authored
Showing with 1,232 additions and 1,091 deletions.
  1. +3 −3 Demo-Mac/DemoAppController.m
  2. +1 −1  Demo-iOS/EmptyAppDelegate.m
  3. +1 −1  Listener/TDHTTPConnection.m
  4. +2 −2 Listener/TDHTTPResponse.m
  5. +3 −3 Listener/TDHTTPServer.h
  6. +4 −4 Listener/TDListener.h
  7. +2 −2 Listener/TDListener.m
  8. +7 −7 Listener/TouchServ.m
  9. +5 −5 Source/TDC.m
  10. +27 −27 Source/TDInternal.h
  11. +1 −1  Source/TDMisc.h
  12. +5 −5 Source/TDMultipartDocumentReader.h
  13. +4 −4 Source/TDMultipartDocumentReader.m
  14. +2 −2 Source/TDMultipartDownloader.h
  15. +2 −2 Source/TDMultipartDownloader.m
  16. +2 −2 Source/TDPuller.h
  17. +13 −13 Source/TDPuller.m
  18. +1 −1  Source/TDPusher.h
  19. +22 −22 Source/TDPusher.m
  20. +1 −1  Source/TDRemoteRequest.m
  21. +4 −4 Source/TDReplicator.h
  22. +5 −5 Source/TDReplicator.m
  23. +7 −7 Source/TDReplicatorManager.h
  24. +29 −29 Source/TDReplicatorManager.m
  25. +28 −28 Source/TDReplicator_Tests.m
  26. +86 −86 Source/TDRouter+Handlers.m
  27. +10 −10 Source/TDRouter.h
  28. +14 −14 Source/TDRouter.m
  29. +30 −30 Source/TDRouter_Tests.m
  30. +1 −1  Source/TDSequenceMap.h
  31. +11 −11 Source/TDURLProtocol.h
  32. +11 −11 Source/TDURLProtocol.m
  33. +3 −3 Source/{TDAttachment.h → TD_Attachment.h}
  34. +3 −3 Source/{TDAttachment.m → TD_Attachment.m}
  35. +4 −4 Source/{TDBody.h → TD_Body.h}
  36. +7 −7 Source/{TDBody.m → TD_Body.m}
  37. +10 −10 Source/{TDDatabase+Attachments.h → TD_Database+Attachments.h}
  38. +22 −22 Source/{TDDatabase+Attachments.m → TD_Database+Attachments.m}
  39. +13 −13 Source/{TDDatabase+Insertion.h → TD_Database+Insertion.h}
  40. +54 −54 Source/{TDDatabase+Insertion.m → TD_Database+Insertion.m}
  41. +5 −5 Source/{TDDatabase+LocalDocs.h → TD_Database+LocalDocs.h}
  42. +10 −10 Source/{TDDatabase+LocalDocs.m → TD_Database+LocalDocs.m}
  43. +4 −4 Source/{TDDatabase+Replication.h → TD_Database+Replication.h}
  44. +7 −7 Source/{TDDatabase+Replication.m → TD_Database+Replication.m}
  45. +27 −27 Source/{TDDatabase.h → TD_Database.h}
  46. +65 −65 Source/{TDDatabase.m → TD_Database.m}
  47. +11 −11 Source/{TDDatabaseManager.h → TD_DatabaseManager.h}
  48. +25 −25 Source/{TDDatabaseManager.m → TD_DatabaseManager.m}
  49. +151 −151 Source/{TDDatabase_Tests.m → TD_Database_Tests.m}
  50. +14 −14 Source/{TDRevision.h → TD_Revision.h}
  51. +21 −21 Source/{TDRevision.m → TD_Revision.m}
  52. +9 −9 Source/{TDServer.h → TD_Server.h}
  53. +21 −21 Source/{TDServer.m → TD_Server.m}
  54. +5 −5 Source/{TDView.h → TD_View.h}
  55. +5 −5 Source/{TDView.m → TD_View.m}
  56. +85 −85 Source/{TDView_Tests.m → TD_View_Tests.m}
  57. +10 −10 Source/TouchDB.exp
  58. +4 −4 Source/TouchDB.h
  59. +293 −152 TouchDB.xcodeproj/project.pbxproj
View
6 Demo-Mac/DemoAppController.m
@@ -102,9 +102,9 @@ - (void) applicationDidFinishLaunching: (NSNotification*)n {
#ifdef FOR_TESTING_PURPOSES
// Start a listener socket:
- [server tellTDServer: ^(TDServer* tdServer) {
+ [server tellTDServer: ^(TD_Server* tdServer) {
// Register support for handling certain JS functions used in the CouchDB unit tests:
- [TDView setCompiler: self];
+ [TD_View setCompiler: self];
sListener = [[TDListener alloc] initWithTDServer: tdServer port: 8888];
[sListener start];
@@ -344,7 +344,7 @@ - (TDReduceBlock) compileReduceFunction: (NSString*)reduceSource language:(NSStr
TDReduceBlock reduceBlock = NULL;
if ([reduceSource isEqualToString: @"(function (keys, values) {return sum(values);})"]) {
reduceBlock = ^(NSArray* keys, NSArray* values, BOOL rereduce) {
- return [TDView totalValues: values];
+ return [TD_View totalValues: values];
};
}
return [reduceBlock copy];
View
2  Demo-iOS/EmptyAppDelegate.m
@@ -15,7 +15,7 @@ @implementation EmptyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSError* error;
- TDServer* tdServer = [[TDServer alloc] initWithDirectory: @"/tmp/touchdb_empty_app"
+ TD_Server* tdServer = [[TD_Server alloc] initWithDirectory: @"/tmp/touchdb_empty_app"
error: &error];
NSAssert(tdServer, @"Couldn't create server: %@", error);
[TDURLProtocol setServer: tdServer];
View
2  Listener/TDHTTPConnection.m
@@ -19,7 +19,7 @@
#import "TDHTTPServer.h"
#import "TDHTTPResponse.h"
#import "TDListener.h"
-#import "TDServer.h"
+#import "TD_Server.h"
#import "TDRouter.h"
#import "HTTPMessage.h"
View
4 Listener/TDHTTPResponse.m
@@ -17,7 +17,7 @@
#import "TDHTTPConnection.h"
#import "TDListener.h"
#import "TDRouter.h"
-#import "TDBody.h"
+#import "TD_Body.h"
#import "Logging.h"
@@ -51,7 +51,7 @@ - (id) initWithRouter: (TDRouter*)router forConnection:(TDHTTPConnection*)connec
};
if (connection.listener.readOnly) {
- router.onAccessCheck = ^TDStatus(TDDatabase* db, NSString* docID, SEL action) {
+ router.onAccessCheck = ^TDStatus(TD_Database* db, NSString* docID, SEL action) {
NSString* method = router.request.HTTPMethod;
if ([method isEqualToString: @"GET"] || [method isEqualToString: @"HEAD"])
return kTDStatusOK;
View
6 Listener/TDHTTPServer.h
@@ -7,17 +7,17 @@
//
#import "HTTPServer.h"
-@class TDListener, TDServer;
+@class TDListener, TD_Server;
@interface TDHTTPServer : HTTPServer {
@private
TDListener* _listener;
- TDServer* _tdServer;
+ TD_Server* _tdServer;
}
@property (retain) TDListener* listener;
-@property (retain) TDServer* tdServer;
+@property (retain) TD_Server* tdServer;
@end
View
8 Listener/TDListener.h
@@ -7,14 +7,14 @@
//
#import <Foundation/Foundation.h>
-@class TDHTTPServer, TDServer;
+@class TDHTTPServer, TD_Server;
/** A simple HTTP server that provides remote access to the TouchDB REST API. */
@interface TDListener : NSObject
{
TDHTTPServer* _httpServer;
- TDServer* _tdServer;
+ TD_Server* _tdServer;
NSString* _realm;
BOOL _readOnly;
BOOL _requiresAuth;
@@ -22,9 +22,9 @@
}
/** Initializes a TDListener.
- @param server The TDServer whose databases to serve.
+ @param server The TD_Server whose databases to serve.
@param port The TCP port number to listen on. Use 0 to automatically pick an available port (you can get the port number after the server starts by getting the .port property.) */
-- (id) initWithTDServer: (TDServer*)server port: (UInt16)port;
+- (id) initWithTDServer: (TD_Server*)server port: (UInt16)port;
/** The TCP port number that the listener is listening on.
If the listener has not yet started, this will return 0. */
View
4 Listener/TDListener.m
@@ -16,7 +16,7 @@
#import "TDListener.h"
#import "TDHTTPServer.h"
#import "TDHTTPConnection.h"
-#import "TDServer.h"
+#import "TD_Server.h"
#import "HTTPServer.h"
@@ -27,7 +27,7 @@ @implementation TDListener
@synthesize readOnly=_readOnly, requiresAuth=_requiresAuth, realm=_realm;
-- (id) initWithTDServer: (TDServer*)server port: (UInt16)port {
+- (id) initWithTDServer: (TD_Server*)server port: (UInt16)port {
self = [super init];
if (self) {
_tdServer = server;
View
14 Listener/TouchServ.m
@@ -18,8 +18,8 @@
#import <TouchDB/TDRouter.h>
#import <TouchDBListener/TDListener.h>
#import <TouchDB/TDPusher.h>
-#import <TouchDB/TDDatabaseManager.h>
-#import <TouchDB/TDDatabase+Replication.h>
+#import <TouchDB/TD_DatabaseManager.h>
+#import <TouchDB/TD_Database+Replication.h>
#if DEBUG
#import "Logging.h"
@@ -53,7 +53,7 @@
}
-static bool doReplicate( TDServer* server, const char* replArg,
+static bool doReplicate( TD_Server* server, const char* replArg,
BOOL pull, BOOL createTarget, BOOL continuous,
const char *user, const char *password)
{
@@ -96,9 +96,9 @@ static bool doReplicate( TDServer* server, const char* replArg,
else
Log(@"Pushing %@ --> <%@> ...", dbName, remote);
- [server tellDatabaseManager: ^(TDDatabaseManager *dbm) {
+ [server tellDatabaseManager: ^(TD_DatabaseManager *dbm) {
TDReplicator* repl = nil;
- TDDatabase* db = [dbm existingDatabaseNamed: dbName];
+ TD_Database* db = [dbm existingDatabaseNamed: dbName];
if (pull) {
if (db) {
if (![db deleteDatabase: nil]) {
@@ -133,7 +133,7 @@ int main (int argc, const char * argv[])
EnableLogTo(TDListener, YES);
#endif
- TDDatabaseManagerOptions options = kTDDatabaseManagerDefaultOptions;
+ TD_DatabaseManagerOptions options = kTD_DatabaseManagerDefaultOptions;
const char* replArg = NULL, *user = NULL, *password = NULL;
BOOL auth = NO, pull = NO, createTarget = NO, continuous = NO;
@@ -159,7 +159,7 @@ int main (int argc, const char * argv[])
}
NSError* error;
- TDServer* server = [[TDServer alloc] initWithDirectory: GetServerPath()
+ TD_Server* server = [[TD_Server alloc] initWithDirectory: GetServerPath()
options: &options
error: &error];
if (error) {
View
10 Source/TDC.m
@@ -7,16 +7,16 @@
//
#import "TDC.h"
-#import "TDBody.h"
+#import "TD_Body.h"
#import "TDRouter.h"
-#import "TDServer.h"
+#import "TD_Server.h"
#import "Test.h"
#import <string.h>
static NSLock* sLock;
static NSString* sServerDir;
-static TDServer* sServer;
+static TD_Server* sServer;
static NSString* CToNSString(const char* str) {
@@ -159,11 +159,11 @@ void TDCInitialize(const char* dataDirectoryPath) {
assert(sLock);
[sLock lock];
@try {
- // Create TDServer on first call:
+ // Create TD_Server on first call:
if (!sServer) {
assert(sServerDir);
NSError* error;
- sServer = [[TDServer alloc] initWithDirectory: sServerDir error: &error];
+ sServer = [[TD_Server alloc] initWithDirectory: sServerDir error: &error];
if (!sServer) {
Warn(@"Unable to create TouchDB server: %@", error);
return nil;
View
54 Source/TDInternal.h
@@ -6,24 +6,24 @@
// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
//
-#import <TouchDB/TDDatabase.h>
-#import "TDDatabase+Attachments.h"
-#import "TDDatabaseManager.h"
-#import "TDView.h"
-#import "TDServer.h"
+#import <TouchDB/TD_Database.h>
+#import "TD_Database+Attachments.h"
+#import "TD_DatabaseManager.h"
+#import "TD_View.h"
+#import "TD_Server.h"
#import "TDRouter.h"
#import "TDReplicator.h"
#import "TDRemoteRequest.h"
#import "TDBlobStore.h"
-@class TDAttachment;
+@class TD_Attachment;
-@interface TDDatabase ()
+@interface TD_Database ()
@property (readwrite, copy) NSString* name; // make it settable
@property (readonly) FMDatabase* fmdb;
@property (readonly) TDBlobStore* attachmentStore;
- (SInt64) getDocNumericID: (NSString*)docID;
-- (TDRevisionList*) getAllRevisionsOfDocumentID: (NSString*)docID
+- (TD_RevisionList*) getAllRevisionsOfDocumentID: (NSString*)docID
numericID: (SInt64)docNumericID
onlyCurrent: (BOOL)onlyCurrent;
- (TDStatus) deleteViewNamed: (NSString*)name;
@@ -37,26 +37,26 @@
isDeleted: (BOOL*)outIsDeleted;
@end
-@interface TDDatabase (Insertion_Internal)
-- (NSData*) encodeDocumentJSON: (TDRevision*)rev;
-- (TDStatus) validateRevision: (TDRevision*)newRev previousRevision: (TDRevision*)oldRev;
+@interface TD_Database (Insertion_Internal)
+- (NSData*) encodeDocumentJSON: (TD_Revision*)rev;
+- (TDStatus) validateRevision: (TD_Revision*)newRev previousRevision: (TD_Revision*)oldRev;
@end
-@interface TDDatabase (Attachments_Internal)
+@interface TD_Database (Attachments_Internal)
- (void) rememberAttachmentWritersForDigests: (NSDictionary*)writersByDigests;
#if DEBUG
- (id) attachmentWriterForAttachment: (NSDictionary*)attachment;
#endif
- (BOOL) storeBlob: (NSData*)blob creatingKey: (TDBlobKey*)outKey;
-- (TDStatus) insertAttachment: (TDAttachment*)attachment
+- (TDStatus) insertAttachment: (TD_Attachment*)attachment
forSequence: (SequenceNumber)sequence;
- (TDStatus) copyAttachmentNamed: (NSString*)name
fromSequence: (SequenceNumber)fromSequence
toSequence: (SequenceNumber)toSequence;
-- (BOOL) inlineFollowingAttachmentsIn: (TDRevision*)rev error: (NSError**)outError;
+- (BOOL) inlineFollowingAttachmentsIn: (TD_Revision*)rev error: (NSError**)outError;
@end
-@interface TDDatabase (Replication_Internal)
+@interface TD_Database (Replication_Internal)
- (void) stopAndForgetReplicator: (TDReplicator*)repl;
- (NSString*) lastSequenceWithCheckpointID: (NSString*)checkpointID;
- (BOOL) setLastSequence: (NSString*)lastSequence withCheckpointID: (NSString*)checkpointID;
@@ -64,33 +64,33 @@
@end
-@interface TDView ()
-- (id) initWithDatabase: (TDDatabase*)db name: (NSString*)name;
+@interface TD_View ()
+- (id) initWithDatabase: (TD_Database*)db name: (NSString*)name;
@property (readonly) int viewID;
- (NSArray*) dump;
- (void) databaseClosing;
@end
-@interface TDServer ()
+@interface TD_Server ()
#if DEBUG
-+ (TDServer*) createEmptyAtPath: (NSString*)path; // for testing
-+ (TDServer*) createEmptyAtTemporaryPath: (NSString*)name; // for testing
++ (TD_Server*) createEmptyAtPath: (NSString*)path; // for testing
++ (TD_Server*) createEmptyAtTemporaryPath: (NSString*)name; // for testing
#endif
@end
-@interface TDDatabaseManager ()
+@interface TD_DatabaseManager ()
@property (readonly, nonatomic) TDReplicatorManager* replicatorManager;
#if DEBUG
-+ (TDDatabaseManager*) createEmptyAtPath: (NSString*)path; // for testing
-+ (TDDatabaseManager*) createEmptyAtTemporaryPath: (NSString*)name; // for testing
++ (TD_DatabaseManager*) createEmptyAtPath: (NSString*)path; // for testing
++ (TD_DatabaseManager*) createEmptyAtTemporaryPath: (NSString*)name; // for testing
#endif
@end
@interface TDRouter ()
-- (id) initWithDatabaseManager: (TDDatabaseManager*)dbManager request: (NSURLRequest*)request;
+- (id) initWithDatabaseManager: (TD_DatabaseManager*)dbManager request: (NSURLRequest*)request;
@end
@@ -100,9 +100,9 @@
@property (readwrite, nonatomic) NSUInteger changesProcessed, changesTotal;
- (void) maybeCreateRemoteDB;
- (void) beginReplicating;
-- (void) addToInbox: (TDRevision*)rev;
-- (void) addRevsToInbox: (TDRevisionList*)revs;
-- (void) processInbox: (TDRevisionList*)inbox; // override this
+- (void) addToInbox: (TD_Revision*)rev;
+- (void) addRevsToInbox: (TD_RevisionList*)revs;
+- (void) processInbox: (TD_RevisionList*)inbox; // override this
- (TDRemoteJSONRequest*) sendAsyncRequest: (NSString*)method
path: (NSString*)relativePath
body: (id)body
View
2  Source/TDMisc.h
@@ -7,7 +7,7 @@
//
#import <Foundation/Foundation.h>
-#import <TouchDB/TDRevision.h>
+#import <TouchDB/TD_Revision.h>
extern NSString* const TDHTTPErrorDomain;
View
10 Source/TDMultipartDocumentReader.h
@@ -8,7 +8,7 @@
#import "TDMultipartReader.h"
#import <TouchDB/TDStatus.h>
-@class TDDatabase, TDRevision, TDBlobStoreWriter, TDMultipartDocumentReader;
+@class TD_Database, TD_Revision, TDBlobStoreWriter, TDMultipartDocumentReader;
typedef void(^TDMultipartDocumentReaderCompletionBlock)(TDMultipartDocumentReader*);
@@ -17,7 +17,7 @@ typedef void(^TDMultipartDocumentReaderCompletionBlock)(TDMultipartDocumentReade
@interface TDMultipartDocumentReader : NSObject <TDMultipartReaderDelegate, NSStreamDelegate>
{
@private
- TDDatabase* _database;
+ TD_Database* _database;
TDStatus _status;
TDMultipartReader* _multipartReader;
NSMutableData* _jsonBuffer;
@@ -31,16 +31,16 @@ typedef void(^TDMultipartDocumentReaderCompletionBlock)(TDMultipartDocumentReade
// synchronous:
+ (NSDictionary*) readData: (NSData*)data
ofType: (NSString*)contentType
- toDatabase: (TDDatabase*)database
+ toDatabase: (TD_Database*)database
status: (TDStatus*)outStatus;
// asynchronous:
+ (TDStatus) readStream: (NSInputStream*)stream
ofType: (NSString*)contentType
- toDatabase: (TDDatabase*)database
+ toDatabase: (TD_Database*)database
then: (TDMultipartDocumentReaderCompletionBlock)completionBlock;
-- (id) initWithDatabase: (TDDatabase*)database;
+- (id) initWithDatabase: (TD_Database*)database;
@property (readonly, nonatomic) TDStatus status;
@property (readonly, nonatomic) NSDictionary* document;
View
8 Source/TDMultipartDocumentReader.m
@@ -14,7 +14,7 @@
// and limitations under the License.
#import "TDMultipartDocumentReader.h"
-#import "TDDatabase+Attachments.h"
+#import "TD_Database+Attachments.h"
#import "TDBlobStore.h"
#import "TDInternal.h"
#import "TDBase64.h"
@@ -28,7 +28,7 @@ @implementation TDMultipartDocumentReader
+ (NSDictionary*) readData: (NSData*)data
ofType: (NSString*)contentType
- toDatabase: (TDDatabase*)database
+ toDatabase: (TD_Database*)database
status: (TDStatus*)outStatus
{
if (data.length == 0) {
@@ -48,7 +48,7 @@ + (NSDictionary*) readData: (NSData*)data
}
-- (id) initWithDatabase: (TDDatabase*)database
+- (id) initWithDatabase: (TD_Database*)database
{
Assert(database);
self = [super init];
@@ -137,7 +137,7 @@ - (BOOL) finish {
+ (TDStatus) readStream: (NSInputStream*)stream
ofType: (NSString*)contentType
- toDatabase: (TDDatabase*)database
+ toDatabase: (TD_Database*)database
then: (TDMultipartDocumentReaderCompletionBlock)onCompletion
{
TDMultipartDocumentReader* reader = [[self alloc] initWithDatabase: database];
View
4 Source/TDMultipartDownloader.h
@@ -7,7 +7,7 @@
//
#import "TDRemoteRequest.h"
-@class TDMultipartDocumentReader, TDDatabase;
+@class TDMultipartDocumentReader, TD_Database;
/** Downloads a remote CouchDB document in multipart format.
@@ -19,7 +19,7 @@
}
- (id) initWithURL: (NSURL*)url
- database: (TDDatabase*)database
+ database: (TD_Database*)database
requestHeaders: (NSDictionary *) requestHeaders
onCompletion: (TDRemoteRequestCompletionBlock)onCompletion;
View
4 Source/TDMultipartDownloader.m
@@ -25,7 +25,7 @@ @implementation TDMultipartDownloader
- (id) initWithURL: (NSURL*)url
- database: (TDDatabase*)database
+ database: (TD_Database*)database
requestHeaders: (NSDictionary *) requestHeaders
onCompletion: (TDRemoteRequestCompletionBlock)onCompletion
{
@@ -115,7 +115,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
RequireTestCase(TDMultipartReader_Simple);
RequireTestCase(TDMultipartReader_Types);
- TDDatabase* db = [TDDatabase createEmptyDBAtPath: [NSTemporaryDirectory() stringByAppendingPathComponent: @"TDMultipartDownloader"]];
+ TD_Database* db = [TD_Database createEmptyDBAtPath: [NSTemporaryDirectory() stringByAppendingPathComponent: @"TDMultipartDownloader"]];
//NSString* urlStr = @"http://127.0.0.1:5984/demo-shopping-attachments/2F9078DF-3C72-44C2-8332-B07B3A29FFE4"
NSString* urlStr = @"http://127.0.0.1:5984/attach-test/oneBigAttachment";
urlStr = [urlStr stringByAppendingString: @"?revs=true&attachments=true"];
View
4 Source/TDPuller.h
@@ -7,7 +7,7 @@
//
#import "TDReplicator.h"
-#import <TouchDB/TDRevision.h>
+#import <TouchDB/TD_Revision.h>
@class TDChangeTracker, TDSequenceMap;
@@ -30,7 +30,7 @@
/** A revision received from a remote server during a pull. Tracks the opaque remote sequence ID. */
-@interface TDPulledRevision : TDRevision
+@interface TDPulledRevision : TD_Revision
{
@private
NSString* _remoteSequenceID;
View
26 Source/TDPuller.m
@@ -14,9 +14,9 @@
// and limitations under the License.
#import "TDPuller.h"
-#import "TDDatabase+Insertion.h"
-#import "TDDatabase+Replication.h"
-#import <TouchDB/TDRevision.h>
+#import "TD_Database+Insertion.h"
+#import "TD_Database+Replication.h"
+#import <TouchDB/TD_Revision.h>
#import "TDChangeTracker.h"
#import "TDAuthorizer.h"
#import "TDBatcher.h"
@@ -171,7 +171,7 @@ - (void) changeTrackerReceivedChanges: (NSArray*)changes {
// Process each change from the feed:
NSString* remoteSequenceID = [change[@"seq"] description];
NSString* docID = change[@"id"];
- if (!docID || ![TDDatabase isValidDocumentID: docID])
+ if (!docID || ![TD_Database isValidDocumentID: docID])
continue;
BOOL deleted = [change[@"deleted"] isEqual: (id)kCFBooleanTrue];
@@ -238,7 +238,7 @@ - (void) changeTrackerStopped:(TDChangeTracker *)tracker {
// Process a bunch of remote revisions from the _changes feed at once
-- (void) processInbox: (TDRevisionList*)inbox {
+- (void) processInbox: (TD_RevisionList*)inbox {
// Ask the local database which of the revs are not known to it:
LogTo(SyncVerbose, @"%@: Looking up %@", self, inbox);
NSString* lastInboxSequence = [inbox.allRevisions.lastObject remoteSequenceID];
@@ -286,7 +286,7 @@ - (void) processInbox: (TDRevisionList*)inbox {
// Add a revision to the appropriate queue of revs to individually GET
-- (void) queueRemoteRevision: (TDRevision*)rev {
+- (void) queueRemoteRevision: (TD_Revision*)rev {
if (rev.deleted)
{
if (!_deletedRevsToPull)
@@ -336,7 +336,7 @@ - (void) pullRemoteRevisions {
// Fetches the contents of a revision from the remote db, including its parent revision ID.
// The contents are stored into rev.properties.
-- (void) pullRemoteRevision: (TDRevision*)rev
+- (void) pullRemoteRevision: (TD_Revision*)rev
{
[self asyncTaskStarted];
++_httpConnectionCount;
@@ -370,7 +370,7 @@ - (void) pullRemoteRevision: (TDRevision*)rev
[strongSelf revisionFailed];
strongSelf.changesProcessed++;
} else {
- TDRevision* gotRev = [TDRevision revisionWithProperties: download.document];
+ TD_Revision* gotRev = [TD_Revision revisionWithProperties: download.document];
gotRev.sequence = rev.sequence;
// Add to batcher ... eventually it will be fed to -insertRevisions:.
[_downloadsToInsert queueObject: gotRev];
@@ -403,7 +403,7 @@ - (void) pullBulkRevisions: (NSArray*)bulkRevs {
[self asyncTaskStarted];
++_httpConnectionCount;
NSMutableArray* remainingRevs = [bulkRevs mutableCopy];
- NSArray* keys = [bulkRevs my_map: ^(TDRevision* rev) { return rev.docID; }];
+ NSArray* keys = [bulkRevs my_map: ^(TD_Revision* rev) { return rev.docID; }];
[self sendAsyncRequest: @"POST"
path: @"/_all_docs?include_docs=true"
body: $dict({@"keys", keys})
@@ -422,7 +422,7 @@ - (void) pullBulkRevisions: (NSArray*)bulkRevs {
for (NSDictionary* row in rows) {
NSDictionary* doc = $castIf(NSDictionary, row[@"doc"]);
if (doc && !doc[@"_attachments"]) {
- TDRevision* rev = [TDRevision revisionWithProperties: doc];
+ TD_Revision* rev = [TD_Revision revisionWithProperties: doc];
NSUInteger pos = [remainingRevs indexOfObject: rev];
if (pos != NSNotFound) {
rev.sequence = [remainingRevs[pos] sequence];
@@ -438,7 +438,7 @@ - (void) pullBulkRevisions: (NSArray*)bulkRevs {
if (remainingRevs.count) {
LogTo(Sync, @"%@ bulk-fetch didn't work for %u of %u revs; getting individually",
self, (unsigned)remainingRevs.count, (unsigned)nRevs);
- for (TDRevision* rev in remainingRevs)
+ for (TD_Revision* rev in remainingRevs)
[self queueRemoteRevision: rev];
[self pullRemoteRevisions];
}
@@ -462,10 +462,10 @@ - (void) insertDownloads:(NSArray *)downloads {
BOOL success = NO;
@try{
downloads = [downloads sortedArrayUsingSelector: @selector(compareSequences:)];
- for (TDRevision* rev in downloads) {
+ for (TD_Revision* rev in downloads) {
@autoreleasepool {
SequenceNumber fakeSequence = rev.sequence;
- NSArray* history = [TDDatabase parseCouchDBRevisionHistory: rev.properties];
+ NSArray* history = [TD_Database parseCouchDBRevisionHistory: rev.properties];
if (!history && rev.generation > 1) {
Warn(@"%@: Missing revision history in response for %@", self, rev);
self.error = TDStatusToNSError(kTDStatusUpstreamError, nil);
View
2  Source/TDPusher.h
@@ -7,7 +7,7 @@
//
#import "TDPuller.h"
-#import <TouchDB/TDDatabase.h>
+#import <TouchDB/TD_Database.h>
/** Replicator that pushes to a remote CouchDB. */
View
44 Source/TDPusher.m
@@ -14,9 +14,9 @@
// and limitations under the License.
#import "TDPusher.h"
-#import <TouchDB/TDDatabase.h>
-#import "TDDatabase+Insertion.h"
-#import <TouchDB/TDRevision.h>
+#import <TouchDB/TD_Database.h>
+#import "TD_Database+Insertion.h"
+#import <TouchDB/TD_Revision.h>
#import "TDBatcher.h"
#import "TDMultipartUploader.h"
#import "TDInternal.h"
@@ -24,11 +24,11 @@
#import "TDCanonicalJSON.h"
-static int findCommonAncestor(TDRevision* rev, NSArray* possibleIDs);
+static int findCommonAncestor(TD_Revision* rev, NSArray* possibleIDs);
@interface TDPusher ()
-- (BOOL) uploadMultipartRevision: (TDRevision*)rev;
+- (BOOL) uploadMultipartRevision: (TD_Revision*)rev;
@end
@@ -43,7 +43,7 @@ - (BOOL) isPush {
}
-- (TDFilterBlock) filter {
+- (TD_FilterBlock) filter {
return _filterName ? [_db filterNamed: _filterName] : NULL;
}
@@ -77,7 +77,7 @@ - (void) beginReplicating {
if (_creatingTarget)
return;
- TDFilterBlock filter = self.filter;
+ TD_FilterBlock filter = self.filter;
if (!filter && _filterName)
Warn(@"%@: No TDFilterBlock registered for filter '%@'; ignoring", self, _filterName);
@@ -95,7 +95,7 @@ - (void) beginReplicating {
if (_continuous && !_observing) {
_observing = YES;
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(dbChanged:)
- name: TDDatabaseChangeNotification object: _db];
+ name: TD_DatabaseChangeNotification object: _db];
}
#ifdef GNUSTEP // TODO: Multipart upload on GNUstep
@@ -108,7 +108,7 @@ - (void) stopObserving {
if (_observing) {
_observing = NO;
[[NSNotificationCenter defaultCenter] removeObserver: self
- name: TDDatabaseChangeNotification
+ name: TD_DatabaseChangeNotification
object: _db];
}
}
@@ -144,19 +144,19 @@ - (void) dbChanged: (NSNotification*)n {
// Skip revisions that originally came from the database I'm syncing to:
if ([userInfo[@"source"] isEqual: _remote])
return;
- TDRevision* rev = userInfo[@"rev"];
- TDFilterBlock filter = self.filter;
+ TD_Revision* rev = userInfo[@"rev"];
+ TD_FilterBlock filter = self.filter;
if (filter && !filter(rev, _filterParameters))
return;
[self addToInbox: rev];
}
-- (void) processInbox: (TDRevisionList*)changes {
+- (void) processInbox: (TD_RevisionList*)changes {
// Generate a set of doc/rev IDs in the JSON format that _revs_diff wants:
// <http://wiki.apache.org/couchdb/HttpPostRevsDiff>
NSMutableDictionary* diffs = $mdict();
- for (TDRevision* rev in changes) {
+ for (TD_Revision* rev in changes) {
NSString* docID = rev.docID;
NSMutableArray* revs = diffs[docID];
if (!revs) {
@@ -178,7 +178,7 @@ - (void) processInbox: (TDRevisionList*)changes {
// Go through the list of local changes again, selecting the ones the destination server
// said were missing and mapping them to a JSON dictionary in the form _bulk_docs wants:
__block SequenceNumber lastInboxSequence = 0;
- NSArray* docsToSend = [changes.allRevisions my_map: ^id(TDRevision* rev) {
+ NSArray* docsToSend = [changes.allRevisions my_map: ^id(TD_Revision* rev) {
NSDictionary* properties;
@autoreleasepool {
// Is this revision in the server's 'missing' list?
@@ -204,7 +204,7 @@ - (void) processInbox: (TDRevisionList*)changes {
// Look for the latest common ancestor and stub out older attachments:
NSArray* possible = revResults[@"possible_ancestors"];
int minRevPos = findCommonAncestor(rev, possible);
- [TDDatabase stubOutAttachmentsIn: rev beforeRevPos: minRevPos + 1
+ [TD_Database stubOutAttachmentsIn: rev beforeRevPos: minRevPos + 1
attachmentsFollow: NO];
properties = rev.properties;
// If the rev has huge attachments, send it under separate cover:
@@ -233,7 +233,7 @@ - (void) processInbox: (TDRevisionList*)changes {
// Post the revisions to the destination. "new_edits":false means that the server should
// use the given _rev IDs instead of making up new ones.
- (void) uploadBulkDocs: (NSArray*)docsToSend
- changes: (TDRevisionList*)changes
+ changes: (TD_RevisionList*)changes
lastSequence: (SequenceNumber)lastInboxSequence
{
NSUInteger numDocsToSend = docsToSend.count;
@@ -272,7 +272,7 @@ - (void) uploadBulkDocs: (NSArray*)docsToSend
}
-- (BOOL) uploadMultipartRevision: (TDRevision*)rev {
+- (BOOL) uploadMultipartRevision: (TD_Revision*)rev {
// Find all the attachments with "follows" instead of a body, and put 'em in a multipart stream.
// It's important to scan the _attachments entries in the same order in which they will appear
// in the JSON, because CouchDB expects the MIME bodies to appear in that same order (see #133).
@@ -349,7 +349,7 @@ - (BOOL) uploadMultipartRevision: (TDRevision*)rev {
// Fallback to upload a revision if uploadMultipartRevision failed due to the server's rejecting
// multipart format.
-- (void) uploadJSONRevision: (TDRevision*)rev {
+- (void) uploadJSONRevision: (TD_Revision*)rev {
// Get the revision's properties:
NSError* error;
if (![_db inlineFollowingAttachmentsIn: rev error: &error]) {
@@ -389,15 +389,15 @@ - (void) startNextUpload {
// Given a revision and an array of revIDs, finds the latest common ancestor revID
// and returns its generation #. If there is none, returns 0.
-static int findCommonAncestor(TDRevision* rev, NSArray* possibleRevIDs) {
+static int findCommonAncestor(TD_Revision* rev, NSArray* possibleRevIDs) {
if (possibleRevIDs.count == 0)
return 0;
- NSArray* history = [TDDatabase parseCouchDBRevisionHistory: rev.properties];
+ NSArray* history = [TD_Database parseCouchDBRevisionHistory: rev.properties];
NSString* ancestorID = [history firstObjectCommonWithArray: possibleRevIDs];
if (!ancestorID)
return 0;
int generation;
- if (![TDRevision parseRevID: ancestorID intoGeneration: &generation andSuffix: NULL])
+ if (![TD_Revision parseRevID: ancestorID intoGeneration: &generation andSuffix: NULL])
generation = 0;
return generation;
}
@@ -410,7 +410,7 @@ static int findCommonAncestor(TDRevision* rev, NSArray* possibleRevIDs) {
TestCase(TDPusher_findCommonAncestor) {
NSDictionary* revDict = $dict({@"ids", @[@"second", @"first"]}, {@"start", @2});
- TDRevision* rev = [TDRevision revisionWithProperties: $dict({@"_revisions", revDict})];
+ TD_Revision* rev = [TD_Revision revisionWithProperties: $dict({@"_revisions", revDict})];
CAssertEq(findCommonAncestor(rev, @[]), 0);
CAssertEq(findCommonAncestor(rev, @[@"3-noway", @"1-nope"]), 0);
CAssertEq(findCommonAncestor(rev, @[@"3-noway", @"1-first"]), 1);
View
2  Source/TDRemoteRequest.m
@@ -17,7 +17,7 @@
#import "TDAuthorizer.h"
#import "TDMisc.h"
#import "TDBlobStore.h"
-#import <TouchDB/TDDatabase.h>
+#import <TouchDB/TD_Database.h>
#import "TDRouter.h"
#import "TDReplicator.h"
#import "CollectionUtils.h"
View
8 Source/TDReplicator.h
@@ -8,7 +8,7 @@
#import <Foundation/Foundation.h>
-@class TDDatabase, TDRevisionList, TDBatcher, TDReachability;
+@class TD_Database, TD_RevisionList, TDBatcher, TDReachability;
@protocol TDAuthorizer;
@@ -24,7 +24,7 @@ extern NSString* TDReplicatorStoppedNotification;
{
@protected
NSThread* _thread;
- TDDatabase* __weak _db;
+ TD_Database* __weak _db;
NSURL* _remote;
TDReachability* _host;
BOOL _continuous;
@@ -51,12 +51,12 @@ extern NSString* TDReplicatorStoppedNotification;
+ (NSString *)progressChangedNotification;
+ (NSString *)stoppedNotification;
-- (id) initWithDB: (TDDatabase*)db
+- (id) initWithDB: (TD_Database*)db
remote: (NSURL*)remote
push: (BOOL)push
continuous: (BOOL)continuous;
-@property (weak, readonly) TDDatabase* db;
+@property (weak, readonly) TD_Database* db;
@property (readonly) NSURL* remote;
@property (readonly) BOOL isPush;
@property (readonly) BOOL continuous;
View
10 Source/TDReplicator.m
@@ -16,7 +16,7 @@
#import "TDReplicator.h"
#import "TDPusher.h"
#import "TDPuller.h"
-#import <TouchDB/TDDatabase.h>
+#import <TouchDB/TD_Database.h>
#import "TDRemoteRequest.h"
#import "TDAuthorizer.h"
#import "TDBatcher.h"
@@ -65,7 +65,7 @@ + (NSString *)stoppedNotification
}
-- (id) initWithDB: (TDDatabase*)db
+- (id) initWithDB: (TD_Database*)db
remote: (NSURL*)remote
push: (BOOL)push
continuous: (BOOL)continuous
@@ -203,7 +203,7 @@ - (void) start {
processor:^(NSArray *inbox) {
LogTo(SyncVerbose, @"*** %@: BEGIN processInbox (%u sequences)",
self, (unsigned)inbox.count);
- TDRevisionList* revs = [[TDRevisionList alloc] initWithArray: inbox];
+ TD_RevisionList* revs = [[TD_RevisionList alloc] initWithArray: inbox];
[self processInbox: revs];
LogTo(SyncVerbose, @"*** %@: END processInbox (lastSequence=%@)", self, _lastSequence);
[self updateActive];
@@ -385,7 +385,7 @@ - (void) asyncTasksFinished: (NSUInteger)numTasks {
}
-- (void) addToInbox: (TDRevision*)rev {
+- (void) addToInbox: (TD_Revision*)rev {
Assert(_running);
LogTo(SyncVerbose, @"%@: Received #%lld %@", self, rev.sequence, rev);
[_batcher queueObject: rev];
@@ -393,7 +393,7 @@ - (void) addToInbox: (TDRevision*)rev {
}
-- (void) addRevsToInbox: (TDRevisionList*)revs {
+- (void) addRevsToInbox: (TD_RevisionList*)revs {
Assert(_running);
LogTo(SyncVerbose, @"%@: Received %llu revs", self, (UInt64)revs.count);
[_batcher queueObjects: revs.allRevisions];
View
14 Source/TDReplicatorManager.h
@@ -6,8 +6,8 @@
// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
//
-#import <TouchDB/TDDatabase.h>
-@class TDDatabaseManager;
+#import <TouchDB/TD_Database.h>
+@class TD_DatabaseManager;
@protocol TDAuthorizer;
@@ -16,24 +16,24 @@ extern NSString* const kTDReplicatorDatabaseName;
/** Manages the _replicator database for persistent replications.
It doesn't really have an API; it works on its own by monitoring the '_replicator' database, and docs in it, for changes. Applications use the regular document APIs to manage replications.
- A TDServer owns an instance of this class. */
+ A TD_Server owns an instance of this class. */
@interface TDReplicatorManager : NSObject
{
- TDDatabaseManager* _dbManager;
- TDDatabase* _replicatorDB;
+ TD_DatabaseManager* _dbManager;
+ TD_Database* _replicatorDB;
NSThread* _thread;
NSMutableDictionary* _replicatorsByDocID;
BOOL _updateInProgress;
}
-- (id) initWithDatabaseManager: (TDDatabaseManager*)dbManager;
+- (id) initWithDatabaseManager: (TD_DatabaseManager*)dbManager;
- (void) start;
- (void) stop;
/** Examines the JSON object describing a replication and determines the local database and remote URL, and some of the other parameters. */
- (TDStatus) parseReplicatorProperties: (NSDictionary*)body
- toDatabase: (TDDatabase**)outDatabase
+ toDatabase: (TD_Database**)outDatabase
remote: (NSURL**)outRemote
isPush: (BOOL*)outIsPush
createTarget: (BOOL*)outCreateTarget
View
58 Source/TDReplicatorManager.m
@@ -17,13 +17,13 @@
// http://www.couchbase.com/docs/couchdb-release-1.1/index.html
#import "TDReplicatorManager.h"
-#import "TDServer.h"
-#import <TouchDB/TDDatabase.h>
-#import "TDDatabase+Insertion.h"
-#import "TDDatabase+Replication.h"
+#import "TD_Server.h"
+#import <TouchDB/TD_Database.h>
+#import "TD_Database+Insertion.h"
+#import "TD_Database+Replication.h"
#import "TDPusher.h"
#import "TDPuller.h"
-#import "TDView.h"
+#import "TD_View.h"
#import "TDOAuth1Authorizer.h"
#import "TDInternal.h"
#import "TDMisc.h"
@@ -38,7 +38,7 @@
@interface TDReplicatorManager ()
-- (BOOL) validateRevision: (TDRevision*)newRev context: (id<TDValidationContext>)context;
+- (BOOL) validateRevision: (TD_Revision*)newRev context: (id<TD_ValidationContext>)context;
- (void) processAllDocs;
@end
@@ -46,7 +46,7 @@ - (void) processAllDocs;
@implementation TDReplicatorManager
-- (id) initWithDatabaseManager: (TDDatabaseManager*)dbManager {
+- (id) initWithDatabaseManager: (TD_DatabaseManager*)dbManager {
self = [super init];
if (self) {
_dbManager = dbManager;
@@ -68,15 +68,15 @@ - (void)dealloc {
- (void) start {
[_replicatorDB defineValidation: @"TDReplicatorManager" asBlock:
- ^BOOL(TDRevision *newRevision, id<TDValidationContext> context) {
+ ^BOOL(TD_Revision *newRevision, id<TD_ValidationContext> context) {
return [self validateRevision: newRevision context: context];
}];
[self processAllDocs];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(dbChanged:)
- name: TDDatabaseChangeNotification
+ name: TD_DatabaseChangeNotification
object: _replicatorDB];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someDbDeleted:)
- name: TDDatabaseWillBeDeletedNotification
+ name: TD_DatabaseWillBeDeletedNotification
object: nil];
#if TARGET_OS_IPHONE
// Register for foreground/background transition notifications, on iOS:
@@ -89,7 +89,7 @@ - (void) start {
- (void) stop {
- LogTo(TDServer, @"STOP %@", self);
+ LogTo(TD_Server, @"STOP %@", self);
[_replicatorDB defineValidation: @"TDReplicatorManager" asBlock: nil];
[[NSNotificationCenter defaultCenter] removeObserver: self];
_replicatorsByDocID = nil;
@@ -114,7 +114,7 @@ - (NSString*) docIDForReplicator: (TDReplicator*)repl {
- (TDStatus) parseReplicatorProperties: (NSDictionary*)properties
- toDatabase: (TDDatabase**)outDatabase // may be NULL
+ toDatabase: (TD_Database**)outDatabase // may be NULL
remote: (NSURL**)outRemote // may be NULL
isPush: (BOOL*)outIsPush
createTarget: (BOOL*)outCreateTarget
@@ -131,15 +131,15 @@ - (TDStatus) parseReplicatorProperties: (NSDictionary*)properties
*outCreateTarget = [$castIf(NSNumber, properties[@"create_target"]) boolValue];
*outIsPush = NO;
- TDDatabase* db = nil;
+ TD_Database* db = nil;
NSDictionary* remoteDict = nil;
- if ([TDDatabaseManager isValidDatabaseName: source]) {
+ if ([TD_DatabaseManager isValidDatabaseName: source]) {
if (outDatabase)
db = [_dbManager existingDatabaseNamed: source];
remoteDict = targetDict;
*outIsPush = YES;
} else {
- if (![TDDatabaseManager isValidDatabaseName: target])
+ if (![TD_DatabaseManager isValidDatabaseName: target])
return kTDStatusBadID;
remoteDict = sourceDict;
if (outDatabase) {
@@ -193,7 +193,7 @@ - (TDStatus) parseReplicatorProperties: (NSDictionary*)properties
// Validation function for the _replicator database:
-- (BOOL) validateRevision: (TDRevision*)newRev context: (id<TDValidationContext>)context {
+- (BOOL) validateRevision: (TD_Revision*)newRev context: (id<TD_ValidationContext>)context {
// Ignore the change if it's one I'm making myself, or if it's a deletion:
if (_updateInProgress || newRev.deleted)
return YES;
@@ -252,7 +252,7 @@ - (BOOL) validateRevision: (TDRevision*)newRev context: (id<TDValidationContext>
// PUT a change to a replication document, retrying if there are conflicts:
-- (TDStatus) updateDoc: (TDRevision*)currentRev
+- (TDStatus) updateDoc: (TD_Revision*)currentRev
withProperties: (NSDictionary*)updates
{
LogTo(Sync, @"ReplicatorManager: Updating %@ with %@", currentRev, updates);
@@ -267,7 +267,7 @@ - (TDStatus) updateDoc: (TDRevision*)currentRev
status = kTDStatusOK; // this is a no-op change
break;
}
- TDRevision* updatedRev = [TDRevision revisionWithProperties: updatedProperties];
+ TD_Revision* updatedRev = [TD_Revision revisionWithProperties: updatedProperties];
// Attempt to PUT the updated revision:
_updateInProgress = YES;
@@ -295,7 +295,7 @@ - (TDStatus) updateDoc: (TDRevision*)currentRev
}
-- (void) updateDoc: (TDRevision*)rev forReplicator: (TDReplicator*)repl {
+- (void) updateDoc: (TD_Revision*)rev forReplicator: (TDReplicator*)repl {
NSString* state;
if (repl.running)
state = @"triggered";
@@ -314,12 +314,12 @@ - (void) updateDoc: (TDRevision*)rev forReplicator: (TDReplicator*)repl {
// A replication document has been created, so create the matching TDReplicator:
-- (void) processInsertion: (TDRevision*)rev {
+- (void) processInsertion: (TD_Revision*)rev {
if (_replicatorsByDocID[rev.docID])
return;
LogTo(Sync, @"ReplicatorManager: %@ was created", rev);
NSDictionary* properties = rev.properties;
- TDDatabase* localDb;
+ TD_Database* localDb;
NSURL* remote;
BOOL push, createTarget;
NSDictionary* headers;
@@ -367,7 +367,7 @@ - (void) processInsertion: (TDRevision*)rev {
// A replication document has been changed:
-- (void) processUpdate: (TDRevision*)rev {
+- (void) processUpdate: (TD_Revision*)rev {
if (!rev[@"_replication_state"]) {
// Client deleted the _replication_state property; restart the replicator:
LogTo(Sync, @"ReplicatorManager: Restarting replicator for %@", rev);
@@ -382,7 +382,7 @@ - (void) processUpdate: (TDRevision*)rev {
// A replication document has been deleted:
-- (void) processDeletion: (TDRevision*)rev ofReplicator: (TDReplicator*)repl {
+- (void) processDeletion: (TD_Revision*)rev ofReplicator: (TDReplicator*)repl {
LogTo(Sync, @"ReplicatorManager: %@ was deleted", rev);
[_replicatorsByDocID removeObjectForKey: rev.docID];
[repl stop];
@@ -392,7 +392,7 @@ - (void) processDeletion: (TDRevision*)rev ofReplicator: (TDReplicator*)repl {
#pragma mark - NOTIFICATIONS:
-- (void) processRevision: (TDRevision*)rev {
+- (void) processRevision: (TD_Revision*)rev {
if (rev.generation == 1)
[self processInsertion: rev];
else
@@ -414,7 +414,7 @@ - (void) processAllDocs {
NSString* state = docProps[@"_replication_state"];
if (state==nil || $equal(state, @"triggered") ||
[docProps[@"continuous"] boolValue]) {
- [self processInsertion: [TDRevision revisionWithProperties: docProps]];
+ [self processInsertion: [TD_Revision revisionWithProperties: docProps]];
}
}
LogTo(Sync, @"ReplicatorManager done scanning.");
@@ -434,7 +434,7 @@ - (void) appForegrounding: (NSNotification*)n {
- (void) dbChanged: (NSNotification*)n {
if (_updateInProgress)
return;
- TDRevision* rev = (n.userInfo)[@"rev"];
+ TD_Revision* rev = (n.userInfo)[@"rev"];
LogTo(SyncVerbose, @"ReplicatorManager: %@ %@", n.name, rev);
NSString* docID = rev.docID;
if ([docID hasPrefix: @"_"])
@@ -459,7 +459,7 @@ - (void) replicatorChanged: (NSNotification*)n {
NSString* docID = [self docIDForReplicator: repl];
if (!docID)
return; // If it's not a persistent replicator
- TDRevision* rev = [_replicatorDB getDocumentWithID: docID revisionID: nil];
+ TD_Revision* rev = [_replicatorDB getDocumentWithID: docID revisionID: nil];
[self updateDoc: rev forReplicator: repl];
@@ -475,7 +475,7 @@ - (void) replicatorChanged: (NSNotification*)n {
- (void) someDbDeleted: (NSNotification*)n {
if (!_replicatorDB.exists)
return;
- TDDatabase* db = n.object;
+ TD_Database* db = n.object;
if ([_dbManager.allOpenDatabases indexOfObjectIdenticalTo: db] == NSNotFound)
return;
NSString* dbName = db.name;
@@ -490,7 +490,7 @@ - (void) someDbDeleted: (NSNotification*)n {
if ([source isEqualToString: dbName] || [target isEqualToString: dbName]) {
// Replication doc involves this database -- delete it:
LogTo(Sync, @"ReplicatorManager deleting replication %@", docProps);
- TDRevision* delRev = [[TDRevision alloc] initWithDocID: docProps[@"_id"]
+ TD_Revision* delRev = [[TD_Revision alloc] initWithDocID: docProps[@"_id"]
revID: nil deleted: YES];
TDStatus status;
if (![_replicatorDB putRevision: delRev
View
56 Source/TDReplicator_Tests.m
@@ -16,9 +16,9 @@
#import "TDPuller.h"
#import "TDPusher.h"
#import "TDReplicatorManager.h"
-#import "TDServer.h"
-#import "TDDatabase+Replication.h"
-#import "TDDatabase+Insertion.h"
+#import "TD_Server.h"
+#import "TD_Database+Replication.h"
+#import "TD_Database+Insertion.h"
#import "TDOAuth1Authorizer.h"
#import "TDBase64.h"
#import "TDInternal.h"
@@ -72,7 +72,7 @@ static void deleteRemoteDB(void) {
}
-static NSString* replic8(TDDatabase* db, NSString* urlStr, BOOL push, NSString* filter) {
+static NSString* replic8(TD_Database* db, NSString* urlStr, BOOL push, NSString* filter) {
NSURL* remote = [NSURL URLWithString: urlStr];
TDReplicator* repl = [[TDReplicator alloc] initWithDB: db remote: remote
push: push continuous: NO];
@@ -98,13 +98,13 @@ static void deleteRemoteDB(void) {
TestCase(TDPusher) {
- RequireTestCase(TDDatabase);
- TDDatabaseManager* server = [TDDatabaseManager createEmptyAtTemporaryPath: @"TDPusherTest"];
- TDDatabase* db = [server databaseNamed: @"db"];
+ RequireTestCase(TD_Database);
+ TD_DatabaseManager* server = [TD_DatabaseManager createEmptyAtTemporaryPath: @"TDPusherTest"];
+ TD_Database* db = [server databaseNamed: @"db"];
[db open];
__block int filterCalls = 0;
- [db defineFilter: @"filter" asBlock: ^BOOL(TDRevision *revision, NSDictionary* params) {
+ [db defineFilter: @"filter" asBlock: ^BOOL(TD_Revision *revision, NSDictionary* params) {
Log(@"Test filter called with params = %@", params);
Log(@"Rev = %@, properties = %@", revision, revision.properties);
CAssert(revision.properties);
@@ -118,19 +118,19 @@ static void deleteRemoteDB(void) {
NSMutableDictionary* props = $mdict({@"_id", @"doc1"},
{@"foo", @1}, {@"bar", $false});
TDStatus status;
- TDRevision* rev1 = [db putRevision: [TDRevision revisionWithProperties: props]
+ TD_Revision* rev1 = [db putRevision: [TD_Revision revisionWithProperties: props]
prevRevisionID: nil allowConflict: NO status: &status];
CAssertEq(status, kTDStatusCreated);
props[@"_rev"] = rev1.revID;
props[@"UPDATED"] = $true;
- TDRevision* rev2 = [db putRevision: [TDRevision revisionWithProperties: props]
+ TD_Revision* rev2 = [db putRevision: [TD_Revision revisionWithProperties: props]
prevRevisionID: rev1.revID allowConflict: NO status: &status];
CAssertEq(status, kTDStatusCreated);
props = $mdict({@"_id", @"doc2"},
{@"baz", @(666)}, {@"fnord", $true});
- [db putRevision: [TDRevision revisionWithProperties: props]
+ [db putRevision: [TD_Revision revisionWithProperties: props]
prevRevisionID: nil allowConflict: NO status: &status];
CAssertEq(status, kTDStatusCreated);
#pragma unused(rev2)
@@ -147,8 +147,8 @@ static void deleteRemoteDB(void) {
TestCase(TDPuller) {
RequireTestCase(TDPusher);
- TDDatabaseManager* server = [TDDatabaseManager createEmptyAtTemporaryPath: @"TDPullerTest"];
- TDDatabase* db = [server databaseNamed: @"db"];
+ TD_DatabaseManager* server = [TD_DatabaseManager createEmptyAtTemporaryPath: @"TDPullerTest"];
+ TD_Database* db = [server databaseNamed: @"db"];
[db open];
id lastSeq = replic8(db, kRemoteDBURLStr, NO, nil);
@@ -162,7 +162,7 @@ static void deleteRemoteDB(void) {
replic8(db, kRemoteDBURLStr, NO, nil);
CAssertEq(db.lastSequence, 3);
- TDRevision* doc = [db getDocumentWithID: @"doc1" revisionID: nil];
+ TD_Revision* doc = [db getDocumentWithID: @"doc1" revisionID: nil];
CAssert(doc);
CAssert([doc.revID hasPrefix: @"2-"]);
CAssertEqual(doc[@"foo"], @1);
@@ -185,14 +185,14 @@ static void deleteRemoteDB(void) {
}
RequireTestCase(TDPuller);
- TDDatabaseManager* server = [TDDatabaseManager createEmptyAtTemporaryPath: @"TDPuller_FromCouchApp"];
- TDDatabase* db = [server databaseNamed: @"couchapp_helloworld"];
+ TD_DatabaseManager* server = [TD_DatabaseManager createEmptyAtTemporaryPath: @"TDPuller_FromCouchApp"];
+ TD_Database* db = [server databaseNamed: @"couchapp_helloworld"];
[db open];
replic8(db, @"http://127.0.0.1:5984/couchapp_helloworld", NO, nil);
TDStatus status;
- TDRevision* rev = [db getDocumentWithID: @"_design/helloworld" revisionID: nil options: kTDIncludeAttachments status: &status];
+ TD_Revision* rev = [db getDocumentWithID: @"_design/helloworld" revisionID: nil options: kTDIncludeAttachments status: &status];
NSDictionary* attachments = rev[@"_attachments"];
CAssertEq(attachments.count, 10u);
for (NSString* name in attachments) {
@@ -209,38 +209,38 @@ static void deleteRemoteDB(void) {
TestCase(TDReplicatorManager) {
RequireTestCase(ParseReplicatorProperties);
- TDDatabaseManager* server = [TDDatabaseManager createEmptyAtTemporaryPath: @"TDReplicatorManagerTest"];
+ TD_DatabaseManager* server = [TD_DatabaseManager createEmptyAtTemporaryPath: @"TDReplicatorManagerTest"];
CAssert([server replicatorManager]); // start the replicator
- TDDatabase* replicatorDb = [server databaseNamed: kTDReplicatorDatabaseName];
+ TD_Database* replicatorDb = [server databaseNamed: kTDReplicatorDatabaseName];
CAssert(replicatorDb);
CAssert([replicatorDb open]);
// Try some bogus validation docs that will fail the validator function:
- TDRevision* rev = [TDRevision revisionWithProperties: $dict({@"source", @"foo"},
+ TD_Revision* rev = [TD_Revision revisionWithProperties: $dict({@"source", @"foo"},
{@"target", @7})];
#pragma unused (rev) // some of the 'rev=' assignments below are unnecessary
TDStatus status;
rev = [replicatorDb putRevision: rev prevRevisionID: nil allowConflict: NO status: &status];
CAssertEq(status, kTDStatusForbidden);
- rev = [TDRevision revisionWithProperties: $dict({@"source", @"foo"},
+ rev = [TD_Revision revisionWithProperties: $dict({@"source", @"foo"},
{@"target", @"http://foo.com"},
{@"_internal", $true})]; // <--illegal prop
rev = [replicatorDb putRevision: rev prevRevisionID: nil allowConflict: NO status: &status];
CAssertEq(status, kTDStatusForbidden);
- TDDatabase* sourceDB = [server databaseNamed: @"foo"];
+ TD_Database* sourceDB = [server databaseNamed: @"foo"];
CAssert([sourceDB open]);
// Now try a valid replication document:
NSURL* remote = [NSURL URLWithString: @"http://localhost:5984/tdreplicator_test"];
- rev = [TDRevision revisionWithProperties: $dict({@"source", @"foo"},
+ rev = [TD_Revision revisionWithProperties: $dict({@"source", @"foo"},
{@"target", remote.absoluteString})];
rev = [replicatorDb putRevision: rev prevRevisionID: nil allowConflict: NO status: &status];
CAssertEq(status, kTDStatusCreated);
// Get back the document and verify it's been updated with replicator properties:
- TDRevision* newRev = [replicatorDb getDocumentWithID: rev.docID revisionID: nil];
+ TD_Revision* newRev = [replicatorDb getDocumentWithID: rev.docID revisionID: nil];
Log(@"Updated doc = %@", newRev.properties);
CAssert(!$equal(newRev.revID, rev.revID), @"Replicator doc wasn't updated");
NSString* sessionID = newRev[@"_replication_id"];
@@ -257,7 +257,7 @@ static void deleteRemoteDB(void) {
// Delete the _replication_state property:
NSMutableDictionary* updatedProps = [newRev.properties mutableCopy];
[updatedProps removeObjectForKey: @"_replication_state"];
- rev = [TDRevision revisionWithProperties: updatedProps];
+ rev = [TD_Revision revisionWithProperties: updatedProps];
rev = [replicatorDb putRevision: rev prevRevisionID: rev.revID allowConflict: NO status: &status];
CAssertEq(status, kTDStatusCreated);
@@ -285,11 +285,11 @@ static void deleteRemoteDB(void) {
TestCase(ParseReplicatorProperties) {
- TDDatabaseManager* dbManager = [TDDatabaseManager createEmptyAtTemporaryPath: @"TDReplicatorManagerTest"];
+ TD_DatabaseManager* dbManager = [TD_DatabaseManager createEmptyAtTemporaryPath: @"TDReplicatorManagerTest"];
TDReplicatorManager* replManager = [dbManager replicatorManager];
- TDDatabase* localDB = [dbManager databaseNamed: @"foo"];
+ TD_Database* localDB = [dbManager databaseNamed: @"foo"];
- TDDatabase* db = nil;
+ TD_Database* db = nil;
NSURL* remote = nil;
BOOL isPush = NO, createTarget = NO;
NSDictionary* headers = nil;
View
172 Source/TDRouter+Handlers.m
@@ -14,16 +14,16 @@
// and limitations under the License.
#import "TDRouter.h"
-#import <TouchDB/TDDatabase.h>
-#import "TDDatabase+Attachments.h"
-#import "TDDatabase+Insertion.h"
-#import "TDDatabase+LocalDocs.h"
-#import "TDDatabase+Replication.h"
-#import "TDView.h"
-#import "TDBody.h"
+#import <TouchDB/TD_Database.h>
+#import "TD_Database+Attachments.h"
+#import "TD_Database+Insertion.h"
+#import "TD_Database+LocalDocs.h"
+#import "TD_Database+Replication.h"
+#import "TD_View.h"
+#import "TD_Body.h"
#import "TDMultipartDocumentReader.h"
-#import <TouchDB/TDRevision.h>
-#import "TDServer.h"
+#import <TouchDB/TD_Revision.h>
+#import "TD_Server.h"
#import "TDReplicator.h"
#import "TDReplicatorManager.h"
#import "TDPusher.h"
@@ -47,20 +47,20 @@ - (TDStatus) do_GETRoot {
NSDictionary* info = $dict({@"TouchDB", @"Welcome"},
{@"couchdb", @"Welcome"}, // for compatibility
{@"version", [[self class] versionString]});
- _response.body = [TDBody bodyWithProperties: info];
+ _response.body = [TD_Body bodyWithProperties: info];
return kTDStatusOK;
}
- (TDStatus) do_GET_all_dbs {
NSArray* dbs = _dbManager.allDatabaseNames ?: @[];
- _response.body = [[TDBody alloc] initWithArray: dbs];
+ _response.body = [[TD_Body alloc] initWithArray: dbs];
return kTDStatusOK;
}
- (TDStatus) do_POST_replicate {
// Extract the parameters from the JSON request body:
// http://wiki.apache.org/couchdb/Replication
- TDDatabase* db;
+ TD_Database* db;
NSURL* remote;
BOOL push, createTarget;
NSDictionary* headers;
@@ -106,7 +106,7 @@ - (TDStatus) do_GET_uuids {
int count = MIN(1000, [self intQuery: @"count" defaultValue: 1]);
NSMutableArray* uuids = [NSMutableArray arrayWithCapacity: count];
for (int i=0; i<count; i++)
- [uuids addObject: [TDDatabase generateDocumentID]];
+ [uuids addObject: [TD_Database generateDocumentID]];
_response.bodyObject = $dict({@"uuids", uuids});
return kTDStatusOK;
}
@@ -115,7 +115,7 @@ - (TDStatus) do_GET_uuids {
- (TDStatus) do_GET_active_tasks {
// http://wiki.apache.org/couchdb/HttpGetActiveTasks
NSMutableArray* activity = $marray();
- for (TDDatabase* db in _dbManager.allOpenDatabases) {
+ for (TD_Database* db in _dbManager.allOpenDatabases) {
for (TDReplicator* repl in db.activeReplicators) {
NSString* source = repl.remote.absoluteString;
NSString* target = db.name;
@@ -155,7 +155,7 @@ - (TDStatus) do_GET_active_tasks {
{@"error", error})];
}
}
- _response.body = [[TDBody alloc] initWithArray: activity];
+ _response.body = [[TD_Body alloc] initWithArray: activity];
return kTDStatusOK;
}
@@ -173,7 +173,7 @@ - (TDStatus) do_GET_session {
#pragma mark - DATABASE REQUESTS:
-- (TDStatus) do_GET: (TDDatabase*)db {
+- (TDStatus) do_GET: (TD_Database*)db {
// http://wiki.apache.org/couchdb/HTTP_database_API#Database_Information
TDStatus status = [self openDB];
if (TDStatusIsError(status))
@@ -191,7 +191,7 @@ - (TDStatus) do_GET: (TDDatabase*)db {
}
-- (TDStatus) do_PUT: (TDDatabase*)db {
+- (TDStatus) do_PUT: (TD_Database*)db {
if (db.exists)
return kTDStatusDuplicate;
if (![db open])
@@ -201,14 +201,14 @@ - (TDStatus) do_PUT: (TDDatabase*)db {
}
-- (TDStatus) do_DELETE: (TDDatabase*)db {
+- (TDStatus) do_DELETE: (TD_Database*)db {
if ([self query: @"rev"])
return kTDStatusBadID; // CouchDB checks for this; probably meant to be a document deletion
return [_dbManager deleteDatabaseNamed: db.name] ? kTDStatusOK : kTDStatusNotFound;
}
-- (TDStatus) do_POST_purge: (TDDatabase*)db {
+- (TDStatus) do_POST_purge: (TD_Database*)db {
// <http://wiki.apache.org/couchdb/Purge_Documents>
NSDictionary* body = self.bodyAsDictionary;
if (!body)
@@ -222,7 +222,7 @@ - (TDStatus) do_POST_purge: (TDDatabase*)db {
}
-- (TDStatus) do_GET_all_docs: (TDDatabase*)db {
+- (TDStatus) do_GET_all_docs: (TD_Database*)db {
if ([self cacheWithEtag: $sprintf(@"%lld", db.lastSequence)])
return kTDStatusNotModified;
@@ -237,7 +237,7 @@ - (TDStatus) do_GET_all_docs: (TDDatabase*)db {
}
-- (TDStatus) do_POST_all_docs: (TDDatabase*)db {
+- (TDStatus) do_POST_all_docs: (TD_Database*)db {
// http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
TDQueryOptions options;
if (![self getQueryOptions: &options])
@@ -258,7 +258,7 @@ - (TDStatus) do_POST_all_docs: (TDDatabase*)db {
}
-- (TDStatus) do_POST_bulk_docs: (TDDatabase*)db {
+- (TDStatus) do_POST_bulk_docs: (TD_Database*)db {
// http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
NSDictionary* body = self.bodyAsDictionary;
NSArray* docs = $castIf(NSArray, body[@"docs"]);
@@ -275,12 +275,12 @@ - (TDStatus) do_POST_bulk_docs: (TDDatabase*)db {
for (NSDictionary* doc in docs) {
@autoreleasepool {
NSString* docID = doc[@"_id"];
- TDRevision* rev;
+ TD_Revision* rev;
TDStatus status;
- TDBody* docBody = [TDBody bodyWithProperties: doc];
+ TD_Body* docBody = [TD_Body bodyWithProperties: doc];
if (noNewEdits) {
- rev = [[TDRevision alloc] initWithBody: docBody];
- NSArray* history = [TDDatabase parseCouchDBRevisionHistory: doc];
+ rev = [[TD_Revision alloc] initWithBody: docBody];
+ NSArray* history = [TD_Database parseCouchDBRevisionHistory: doc];
status = rev ? [db forceInsert: rev revisionHistory: history source: nil] : kTDStatusBadParam;
} else {
status = [self update: db
@@ -318,10 +318,10 @@ - (TDStatus) do_POST_bulk_docs: (TDDatabase*)db {
}
-- (TDStatus) do_POST_revs_diff: (TDDatabase*)db {
+- (TDStatus) do_POST_revs_diff: (TD_Database*)db {
// http://wiki.apache.org/couchdb/HttpPostRevsDiff
- // Collect all of the input doc/revision IDs as TDRevisions:
- TDRevisionList* revs = [[TDRevisionList alloc] init];
+ // Collect all of the input doc/revision IDs as TD_Revisions:
+ TD_RevisionList* revs = [[TD_RevisionList alloc] init];
NSDictionary* body = self.bodyAsDictionary;
if (!body)
return kTDStatusBadJSON;
@@ -330,7 +330,7 @@ - (TDStatus) do_POST_revs_diff: (TDDatabase*)db {
if (![revIDs isKindOfClass: [NSArray class]])
return kTDStatusBadParam;
for (NSString* revID in revIDs) {
- TDRevision* rev = [[TDRevision alloc] initWithDocID: docID revID: revID deleted: NO];
+ TD_Revision* rev = [[TD_Revision alloc] initWithDocID: docID revID: revID deleted: NO];
[revs addRev: rev];
}
}
@@ -341,7 +341,7 @@ - (TDStatus) do_POST_revs_diff: (TDDatabase*)db {
// Return the missing revs in a somewhat different format:
NSMutableDictionary* diffs = $mdict();
- for (TDRevision* rev in revs) {
+ for (TD_Revision* rev in revs) {
NSString* docID = rev.docID;
NSMutableArray* revs = diffs[docID][@"missing"];
if (!revs) {
@@ -358,12 +358,12 @@ - (TDStatus) do_POST_revs_diff: (TDDatabase*)db {
NSString* maxRevID = nil;
for (NSString* revID in docInfo[@"missing"]) {
int gen;
- if ([TDRevision parseRevID: revID intoGeneration: &gen andSuffix: NULL] && gen > maxGen) {
+ if ([TD_Revision parseRevID: revID intoGeneration: &gen andSuffix: NULL] && gen > maxGen) {
maxGen = gen;
maxRevID = revID;
}
}
- TDRevision* rev = [[TDRevision alloc] initWithDocID: docID revID: maxRevID deleted: NO];
+ TD_Revision* rev = [[TD_Revision alloc] initWithDocID: docID revID: maxRevID deleted: NO];
NSArray* ancestors = [_db getPossibleAncestorRevisionIDs: rev limit: 0];
if (ancestors)
docInfo[@"possible_ancestors"] = ancestors;
@@ -374,12 +374,12 @@ - (TDStatus) do_POST_revs_diff: (TDDatabase*)db {
}
-- (TDStatus) do_POST_compact: (TDDatabase*)db {
+- (TDStatus) do_POST_compact: (TD_Database*)db {
TDStatus status = [db compact];
return status<300 ? kTDStatusAccepted : status; // CouchDB returns 202 'cause it's async
}
-- (TDStatus) do_POST_ensure_full_commit: (TDDatabase*)db {
+- (TDStatus) do_POST_ensure_full_commit: (TD_Database*)db {
return kTDStatusOK;
}
@@ -387,7 +387,7 @@ - (TDStatus) do_POST_ensure_full_commit: (TDDatabase*)db {
#pragma mark - CHANGES:
-- (NSDictionary*) changeDictForRev: (TDRevision*)rev {
+- (NSDictionary*) changeDictForRev: (TD_Revision*)rev {
return $dict({@"seq", @(rev.sequence)},
{@"id", rev.docID},
{@"changes", $marray($dict({@"rev", rev.revID}))},
@@ -411,7 +411,7 @@ - (NSDictionary*) responseBodyForChangesWithConflicts: (NSArray*)changes
NSMutableArray* entries = [NSMutableArray arrayWithCapacity: changes.count];
NSString* lastDocID = nil;
NSDictionary* lastEntry = nil;
- for (TDRevision* rev in changes) {
+ for (TD_Revision* rev in changes) {
NSString* docID = rev.docID;
if ($equal(docID, lastDocID)) {
[lastEntry[@"changes"] addObject: $dict({@"rev", rev.revID})];
@@ -433,7 +433,7 @@ - (NSDictionary*) responseBodyForChangesWithConflicts: (NSArray*)changes
}
-- (void) sendContinuousChange: (TDRevision*)rev {
+- (void) sendContinuousChange: (TD_Revision*)rev {
NSDictionary* changeDict = [self changeDictForRev: rev];
NSMutableData* json = [[TDJSON dataWithJSONObject: changeDict
options: 0 error: NULL] mutableCopy];
@@ -445,8 +445,8 @@ - (void) sendContinuousChange: (TDRevision*)rev {
- (void) dbChanged: (NSNotification*)n {
NSDictionary* userInfo = n.userInfo;
- TDRevision* rev = userInfo[@"rev"];
- TDRevision* winningRev = userInfo[@"winner"];
+ TD_Revision* rev = userInfo[@"rev"];
+ TD_Revision* winningRev = userInfo[@"winner"];
if (!_changesIncludeConflicts) {
if (!winningRev)
@@ -470,7 +470,7 @@ - (void) dbChanged: (NSNotification*)n {
Log(@"TDRouter: Sending longpoll response");
[self sendResponseHeaders];
NSDictionary* body = [self responseBodyForChanges: @[rev] since: 0];
- _response.body = [TDBody bodyWithProperties: body];
+ _response.body = [TD_Body bodyWithProperties: body];
[self sendResponseBodyAndFinish: YES];
} else {
Log(@"TDRouter: Sending continous change chunk");
@@ -479,7 +479,7 @@ - (void) dbChanged: (NSNotification*)n {
}
-- (TDStatus) do_GET_changes: (TDDatabase*)db {
+- (TDStatus) do_GET_changes: (TD_Database*)db {
// http://wiki.apache.org/couchdb/HTTP_database_API#Changes
NSString* feed = [self query: @"feed"];
@@ -509,7 +509,7 @@ - (TDStatus) do_GET_changes: (TDDatabase*)db {
_changesFilterParams = [self.jsonQueries copy];
}
- TDRevisionList* changes = [db changesSinceSequence: since
+ TD_RevisionList* changes = [db changesSinceSequence: since
options: &options
filter: _changesFilter
params: _changesFilterParams];
@@ -521,12 +521,12 @@ - (TDStatus) do_GET_changes: (TDDatabase*)db {
// Response is going to stay open (continuous, or hanging GET):
if (continuous) {
[self sendResponseHeaders];
- for (TDRevision* rev in changes)
+ for (TD_Revision* rev in changes)
[self sendContinuousChange: rev];
}
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(dbChanged:)
- name: TDDatabaseChangeNotification
+ name: TD_DatabaseChangeNotification
object: db];
// Don't close connection; more data to come
return 0;
@@ -557,7 +557,7 @@ - (TDStatus) do_GET_changes: (TDDatabase*)db {
}
-- (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID {
+- (TDStatus) do_GET: (TD_Database*)db docID: (NSString*)docID {
// http://wiki.apache.org/couchdb/HTTP_Document_API#GET
BOOL isLocalDoc = [docID hasPrefix: @"_local/"];
TDContentOptions options = [self contentOptions];
@@ -566,7 +566,7 @@ - (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID {
if (openRevsParam == nil || isLocalDoc) {
// Regular GET:
NSString* revID = [self query: @"rev"]; // often nil
- TDRevision* rev;
+ TD_Revision* rev;
BOOL includeAttachments = NO;
if (isLocalDoc) {
rev = [db getLocalDocumentWithID: docID revisionID: revID];
@@ -595,8 +595,8 @@ - (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID {
NSArray* attsSince = parseJSONRevArrayQuery([self query: @"atts_since"]);
NSString* ancestorID = [_db findCommonAncestorOf: rev withRevIDs: attsSince];
if (ancestorID)
- minRevPos = [TDRevision generationFromRevID: ancestorID] + 1;
- [TDDatabase stubOutAttachmentsIn: rev beforeRevPos: minRevPos
+ minRevPos = [TD_Revision generationFromRevID: ancestorID] + 1;
+ [TD_Database stubOutAttachmentsIn: rev beforeRevPos: minRevPos
attachmentsFollow: (acceptMultipart != nil)];
}
@@ -612,9 +612,9 @@ - (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID {
if ($equal(openRevsParam, @"all")) {
// Get all conflicting revisions:
BOOL includeDeleted = [self boolQuery: @"include_deleted"];
- TDRevisionList* allRevs = [_db getAllRevisionsOfDocumentID: docID onlyCurrent: YES];
+ TD_RevisionList* allRevs = [_db getAllRevisionsOfDocumentID: docID onlyCurrent: YES];
result = [NSMutableArray arrayWithCapacity: allRevs.count];
- for (TDRevision* rev in allRevs.allRevisions) {
+ for (TD_Revision* rev in allRevs.allRevisions) {
if (!includeDeleted && rev.deleted)
continue;
TDStatus status = [_db loadRevisionBody: rev options: options];
@@ -636,7 +636,7 @@ - (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID {
if (![revID isKindOfClass: [NSString class]])
return kTDStatusBadID;
TDStatus status;
- TDRevision* rev = [db getDocumentWithID: docID revisionID: revID
+ TD_Revision* rev = [db getDocumentWithID: docID revisionID: revID
options: options status: &status];
if (rev)
[result addObject: $dict({@"ok", rev.properties})];
@@ -653,9 +653,9 @@ - (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID {
}
-- (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID attachment: (NSString*)attachment {
+- (TDStatus) do_GET: (TD_Database*)db docID: (NSString*)docID attachment: (NSString*)attachment {
TDStatus status;
- TDRevision* rev = [db getDocumentWithID: docID
+ TD_Revision* rev = [db getDocumentWithID: docID
revisionID: [self query: @"rev"] // often nil
options: kTDNoBody
status: &status]; // all we need is revID & sequence
@@ -695,7 +695,7 @@ - (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID attachment: (NSStri
status: &status];
if (!contents)
return status;
- _response.body = [TDBody bodyWithJSON: contents]; //FIX: This is a lie, it's not JSON
+ _response.body = [TD_Body bodyWithJSON: contents]; //FIX: This is a lie, it's not JSON
}
if (type)
_response[@"Content-Type"] = type;
@@ -705,12 +705,12 @@ - (TDStatus) do_GET: (TDDatabase*)db docID: (NSString*)docID attachment: (NSStri
}
-- (TDStatus) update: (TDDatabase*)db
+- (TDStatus) update: (TD_Database*)db
docID: (NSString*)docID
- body: (TDBody*)body
+ body: (TD_Body*)body
deleting: (BOOL)deleting
allowConflict: (BOOL)allowConflict
- createdRev: (TDRevision**)outRev
+ createdRev: (TD_Revision**)outRev
{
if (body && !body.isValidJSON)
return kTDStatusBadJSON;
@@ -736,7 +736,7 @@ - (TDStatus) update: (TDDatabase*)db
if (!prevRevID)
prevRevID = self.ifMatch;
- TDRevision* rev = [[TDRevision alloc] initWithDocID: docID revID: nil deleted: deleting];
+ TD_Revision* rev = [[TD_Revision alloc] initWithDocID: docID revID: nil deleted: deleting];
if (!rev)
return kTDStatusBadID;
rev.body = body;
@@ -752,12 +752,12 @@ - (TDStatus) update: (TDDatabase*)db
}
-- (TDStatus) update: (TDDatabase*)db
+- (TDStatus) update: (TD_Database*)db
docID: (NSString*)docID
- body: (TDBody*)body
+ body: (TD_Body*)body
deleting: (BOOL)deleting
{
- TDRevision* rev;
+ TD_Revision* rev;
TDStatus status = [self update: db docID: docID body: body
deleting: deleting
allowConflict: NO
@@ -778,7 +778,7 @@ - (TDStatus) update: (TDDatabase*)db
}
-- (TDStatus) readDocumentBodyThen: (TDStatus(^)(TDBody*))block {
+- (TDStatus) readDocumentBodyThen: (TDStatus(^)(TD_Body*))block {
TDStatus status;
NSString* contentType = [_request valueForHTTPHeaderField: @"Content-Type"];
NSInputStream* bodyStream = _request.HTTPBodyStream;
@@ -793,7 +793,7 @@ - (TDStatus) readDocumentBodyThen: (TDStatus(^)(TDBody*))block {
if (!TDStatusIsError(status)) {
NSDictionary* properties = reader.document;
if (properties)
- status = block([TDBody bodyWithProperties: properties]);
+ status = block([TD_Body bodyWithProperties: properties]);
else
status = kTDStatusBadRequest;
}
@@ -815,48 +815,48 @@ - (TDStatus) readDocumentBodyThen: (TDStatus(^)(TDBody*))block {
return status;
else if (!properties)
return kTDStatusBadRequest;
- return block([TDBody bodyWithProperties: properties]);
+ return block([TD_Body bodyWithProperties: properties]);
}
}
-- (TDStatus) do_POST: (TDDatabase*)db {
+- (TDStatus) do_POST: (TD_Database*)db {
TDStatus status = [self openDB];
if (TDStatusIsError(status))
return status;
- return [self readDocumentBodyThen: ^(TDBody *body) {
+ return [self readDocumentBodyThen: ^(TD_Body *body) {
return [self update: db docID: nil body: body deleting: NO];
}];
}
-- (TDStatus) do_PUT: (TDDatabase*)db docID: (NSString*)docID {
- return [self readDocumentBodyThen: ^TDStatus(TDBody *body) {
+- (TDStatus) do_PUT: (TD_Database*)db docID: (NSString*)docID {
+ return [self readDocumentBodyThen: ^TDStatus(TD_Body *body) {
if (![self query: @"new_edits"] || [self boolQuery: @"new_edits"]) {
// Regular PUT:
return [self update: db docID: docID body: body deleting: NO];
} else {
// PUT with new_edits=false -- forcible insertion of existing revision:
- TDRevision* rev = [[TDRevision alloc] initWithBody: body];
+ TD_Revision* rev = [[TD_Revision alloc] initWithBody: body];
if (!rev)
return kTDStatusBadJSON;
if (!$equal(rev.docID, docID) || !rev.revID)
return kTDStatusBadID;
- NSArray* history = [TDDatabase parseCouchDBRevisionHistory: body.properties];
+ NSArray* history = [TD_Database parseCouchDBRevisionHistory: body.properties];
return [_db forceInsert: rev revisionHistory: history source: nil];
}
}];
}
-- (TDStatus) do_DELETE: (TDDatabase*)db docID: (NSString*)docID {
+- (TDStatus) do_DELETE: (TD_Database*)db docID: (NSString*)docID {
return [self update: db docID: docID body: nil deleting: YES];
}
- (TDStatus) updateAttachment: (NSString*)attachment docID: (NSString*)docID body: (NSData*)body {
TDStatus status;
- TDRevision* rev = [_db updateAttachment: attachment
+ TD_Revision* rev = [_db updateAttachment: attachment
body: body
type: [_request valueForHTTPHeaderField: @"Content-Type"]
encoding: kTDAttachmentEncodingNone
@@ -873,14 +873,14 @@ - (TDStatus) updateAttachment: (NSString*)attachment docID: (NSString*)docID bod
}
-- (TDStatus) do_PUT: (TDDatabase*)db docID: (NSString*)docID attachment: (NSString*)attachment {
+- (TDStatus) do_PUT: (TD_Database*)db docID: (NSString*)docID attachment: (NSString*)attachment {
return [self updateAttachment: attachment