├── .gitignore ├── .gitmodules ├── C ├── c4.c ├── c4.def ├── c4.exp ├── c4.h ├── c4Base.h ├── c4Database.cc ├── c4Database.h ├── c4DocEnumerator.cc ├── c4DocEnumerator.h ├── c4Document.cc ├── c4Document.h ├── c4ExpiryEnumerator.cc ├── c4ExpiryEnumerator.h ├── c4Impl.hh ├── c4Key.cc ├── c4Key.h ├── c4Private.h ├── c4View.cc ├── c4View.h └── tests │ ├── c4AllDocsPerformanceTest.cc │ ├── c4DatabaseTest.cc │ ├── c4GeoTest.cc │ ├── c4KeyTest.cc │ ├── c4Test.cc │ ├── c4Test.hh │ ├── c4ThreadingTest.cc │ └── c4ViewTest.cc ├── CBForest Tests ├── CBForest Tests-Info.plist ├── CBForest Tests-Prefix.pch ├── C_API_Test.mm ├── Collatable_Test.mm ├── Database_Test.mm ├── GeoHash_Test.mm ├── GeoIndex_Test.mm ├── Index_Test.mm ├── MapReduce_Test.mm ├── Slice_Test.mm ├── Tokenizer_Test.mm ├── VersionedDocument_Tests.mm ├── en.lproj │ └── InfoPlist.strings └── testutil.h ├── CBForest.VS2015 ├── CBForest.VS2015.sdf ├── CBForest.VS2015.sln ├── CBForest.VS2015.vcxproj ├── CBForest.VS2015.vcxproj.filters ├── LibLocations.props ├── asprintf.c ├── asprintf.h ├── memmem.c ├── memmem.cc ├── memmem.h ├── sqlite3.h ├── sqlite3ext.h └── vasprintf-msvc.c ├── CBForest.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ ├── All.xcscheme │ ├── CBForest static.xcscheme │ ├── CBForest-Interop.xcscheme │ ├── CBForest-iOS-Carthage.xcscheme │ ├── CBForestJNI.xcscheme │ ├── CppTests.xcscheme │ ├── Tokenizer-Interop Static.xcscheme │ ├── Tokenizer-Interop.xcscheme │ ├── Tokenizer.xcscheme │ └── forestdb.xcscheme ├── CBForest ├── CBForest-Prefix.pch ├── CBForest.hh ├── Collatable.cc ├── Collatable.hh ├── Collatable.mm ├── Database.cc ├── Database.hh ├── DocEnumerator.cc ├── DocEnumerator.hh ├── Document.cc ├── Document.hh ├── Error.cc ├── Error.hh ├── FullTextIndex.cc ├── FullTextIndex.hh ├── GeoIndex.cc ├── GeoIndex.hh ├── Geohash.cc ├── Geohash.hh ├── Index.cc ├── Index.hh ├── KeyStore.cc ├── KeyStore.hh ├── LogInternal.hh ├── MapReduceIndex.cc ├── MapReduceIndex.hh ├── RevID.cc ├── RevID.hh ├── RevID.mm ├── RevTree.cc ├── RevTree.hh ├── SecureDigest.hh ├── SecureRandomize.hh ├── Tokenizer.cc ├── Tokenizer.hh ├── VersionedDocument.cc ├── VersionedDocument.hh ├── VersionedDocument.mm ├── en.lproj │ └── InfoPlist.strings ├── english_stopwords.h ├── slice.cc ├── slice.hh ├── slice.mm ├── sqlite_glue.c ├── varint.cc └── varint.hh ├── CSharp ├── NativeBuild │ ├── Makefile │ ├── build-interop-ios-fat.sh │ ├── build-interop-osx.sh │ ├── gen_linux_symbol_list.sh │ └── jni │ │ ├── Android.mk │ │ └── Application.mk ├── README.md ├── Tests │ ├── cbforest-sharp-tests.Droid │ │ ├── Assets │ │ │ └── AboutAssets.txt │ │ ├── MainActivity.cs │ │ ├── Properties │ │ │ ├── AndroidManifest.xml │ │ │ └── AssemblyInfo.cs │ │ ├── Resources │ │ │ ├── AboutResources.txt │ │ │ ├── Resource.designer.cs │ │ │ ├── drawable-hdpi │ │ │ │ └── Icon.png │ │ │ ├── drawable-mdpi │ │ │ │ └── Icon.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── Icon.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── Icon.png │ │ │ └── drawable-xxxhdpi │ │ │ │ └── Icon.png │ │ └── cbforest-sharp-tests.Droid.csproj │ ├── cbforest-sharp-tests.Net45 │ │ ├── cbforest-sharp-tests.Net45.csproj │ │ └── packages.config │ ├── cbforest-sharp-tests.Shared │ │ ├── C4DatabaseTest.cs │ │ ├── C4GeoTest.cs │ │ ├── C4KeyTest.cs │ │ ├── C4Test.cs │ │ ├── C4ViewTest.cs │ │ ├── cbforest-sharp-tests.Shared.projitems │ │ └── cbforest-sharp-tests.Shared.shproj │ └── cbforest-sharp-tests.iOS │ │ ├── Entitlements.plist │ │ ├── Info.plist │ │ ├── Main.cs │ │ ├── UnitTestAppDelegate.cs │ │ └── cbforest-sharp-tests.iOS.csproj ├── cbforest-sharp.Droid │ ├── Resources │ │ ├── AboutResources.txt │ │ ├── Resource.designer.cs │ │ └── values │ │ │ └── Strings.xml │ ├── cbforest-sharp.Droid.csproj │ └── cbforest-sharp.dll.config ├── cbforest-sharp.Net35 │ ├── Extensions.cs │ ├── Makefile │ └── cbforest-sharp.Net35.csproj ├── cbforest-sharp.Net45 │ └── cbforest-sharp.Net45.csproj ├── cbforest-sharp.Shared │ ├── CBForestException.cs │ ├── Defines.cs │ ├── Native.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Types.cs │ ├── Utils │ │ ├── CBForestDocEnumerator.cs │ │ ├── CBForestExpiryEnumerator.cs │ │ ├── CBForestHistoryEnumerator.cs │ │ ├── CBForestQueryEnumerator.cs │ │ └── RetryHandler.cs │ ├── cbforest-sharp.Shared.projitems │ └── cbforest-sharp.Shared.shproj ├── cbforest-sharp.iOS │ └── cbforest-sharp.iOS.csproj ├── cbforest-sharp.sln ├── packages │ ├── NUnit.2.6.4 │ │ ├── NUnit.2.6.4.nupkg │ │ ├── lib │ │ │ ├── nunit.framework.dll │ │ │ └── nunit.framework.xml │ │ └── license.txt │ └── repositories.config └── prebuilt │ └── README.txt ├── CppTests ├── CppTests │ ├── CppTests.vcxproj │ ├── CppTests.vcxproj.filters │ └── packages.config └── main.cpp ├── Java ├── CBForestJNI.exp ├── jni.h ├── jni │ ├── native_database.cc │ ├── native_document.cc │ ├── native_documentiterator.cc │ ├── native_glue.cc │ ├── native_glue.hh │ ├── native_indexer.cc │ ├── native_queryIterator.cc │ └── native_view.cc └── src │ └── com │ └── couchbase │ └── cbforest │ ├── Constants.java │ ├── Database.java │ ├── Document.java │ ├── DocumentIterator.java │ ├── ForestException.java │ ├── FullTextResult.java │ ├── Indexer.java │ ├── Logger.java │ ├── QueryIterator.java │ └── View.java ├── README.md ├── vendor └── snappy │ ├── COPYING │ ├── README.md │ ├── config.h │ ├── snappy-c.cc │ ├── snappy-c.h │ ├── snappy-internal.h │ ├── snappy-sinksource.cc │ ├── snappy-sinksource.h │ ├── snappy-stubs-internal.cc │ ├── snappy-stubs-internal.h │ ├── snappy-stubs-public.h │ ├── snappy.cc │ └── snappy.h └── xcconfigs ├── CBForest Tests.xcconfig ├── CBForest static.xcconfig ├── CBForest-Interop.xcconfig ├── CBForestJNI.xcconfig ├── CppTests.xcconfig ├── Project.xcconfig ├── Project_Debug.xcconfig ├── Project_Release.xcconfig ├── SwiftForest.xcconfig ├── SwiftForestTests.xcconfig ├── SwiftForestTests_Debug.xcconfig ├── SwiftForestTests_Release.xcconfig ├── SwiftForest_Debug.xcconfig ├── SwiftForest_Release.xcconfig ├── Tokenizer.xcconfig ├── forestdb.xcconfig └── static_lib.xcconfig /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *~ 3 | *.xccheckout 4 | xcuserdata/ 5 | build/ 6 | DerivedData/ 7 | *.userprefs 8 | bin/ 9 | obj/ 10 | [dD]ebug 11 | *.o 12 | *.class 13 | packages/ 14 | *.sdf 15 | *.opensdf 16 | [Rr]elease 17 | *.xcscmblueprint 18 | CSharp/prebuilt/* 19 | !CSharp/prebuilt/README.txt 20 | stripopts 21 | Java/jni/com_couchbase_cbforest_*.h 22 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/forestdb"] 2 | path = vendor/forestdb 3 | url = https://github.com/couchbaselabs/forestdb.git 4 | [submodule "vendor/sqlite3-unicodesn"] 5 | path = vendor/sqlite3-unicodesn 6 | url = https://github.com/snej/sqlite3-unicodesn.git 7 | [submodule "vendor/openssl"] 8 | path = vendor/openssl 9 | url = https://github.com/couchbaselabs/couchbase-lite-libcrypto 10 | -------------------------------------------------------------------------------- /C/c4.c: -------------------------------------------------------------------------------- 1 | // 2 | // c4.c 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 9/8/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | // I'm just using this source file as a canary to make sure the headers parse as plain C. 10 | 11 | #include "c4.h" 12 | -------------------------------------------------------------------------------- /C/c4.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | c4SliceEqual 3 | c4slice_free 4 | c4log_register 5 | c4error_getMessage 6 | c4db_open 7 | c4db_free 8 | c4db_close 9 | c4db_delete 10 | c4db_deleteAtPath 11 | c4db_compact 12 | c4db_rekey 13 | c4db_getPath 14 | c4db_getDocumentCount 15 | c4db_getLastSequence 16 | c4db_beginTransaction 17 | c4db_endTransaction 18 | c4db_isInTransaction 19 | c4raw_free 20 | c4raw_get 21 | c4raw_put 22 | c4doc_free 23 | c4doc_get 24 | c4doc_getBySequence 25 | c4doc_getType 26 | c4db_purgeDoc 27 | c4doc_selectRevision 28 | c4doc_selectCurrentRevision 29 | c4doc_loadRevisionBody 30 | c4doc_hasRevisionBody 31 | c4doc_selectParentRevision 32 | c4doc_selectNextRevision 33 | c4doc_selectNextLeafRevision 34 | c4doc_generateRevID 35 | c4doc_generateOldStyleRevID 36 | c4doc_put 37 | c4doc_insertRevision 38 | c4doc_insertRevisionWithHistory 39 | c4doc_purgeRevision 40 | c4doc_setType 41 | c4doc_save 42 | c4doc_setExpiration 43 | c4doc_getExpiration 44 | c4db_nextDocExpiration 45 | c4rev_getGeneration 46 | c4db_enumerateChanges 47 | c4db_enumerateAllDocs 48 | c4db_enumerateSomeDocs 49 | c4db_enumerateExpired 50 | c4enum_next 51 | c4enum_nextDocument 52 | c4enum_getDocumentInfo 53 | c4enum_getDocument 54 | c4enum_close 55 | c4enum_free 56 | c4exp_free 57 | c4exp_close 58 | c4exp_getDocID 59 | c4exp_next 60 | c4exp_purgeExpired 61 | kC4DefaultEnumeratorOptions 62 | kC4DefaultQueryOptions 63 | c4key_new 64 | c4key_newFullTextString 65 | c4key_newGeoJSON 66 | c4key_withBytes 67 | c4key_free 68 | c4key_addNull 69 | c4key_addBool 70 | c4key_addNumber 71 | c4key_addString 72 | c4key_addMapKey 73 | c4key_beginArray 74 | c4key_endArray 75 | c4key_beginMap 76 | c4key_endMap 77 | c4key_read 78 | c4key_peek 79 | c4key_skipToken 80 | c4key_readBool 81 | c4key_readNumber 82 | c4key_readString 83 | c4key_toJSON 84 | c4key_setDefaultFullTextLanguage 85 | c4view_open 86 | c4view_free 87 | c4view_close 88 | c4view_eraseIndex 89 | c4view_delete 90 | c4view_getTotalRows 91 | c4view_getLastSequenceIndexed 92 | c4view_getLastSequenceChangedAt 93 | c4view_rekey 94 | c4indexer_begin 95 | c4indexer_triggerOnView 96 | c4indexer_enumerateDocuments 97 | c4indexer_shouldIndexDocument 98 | c4indexer_emit 99 | c4indexer_emitList 100 | c4indexer_end 101 | c4view_query 102 | c4view_fullTextQuery 103 | c4view_geoQuery 104 | c4view_fullTextMatched 105 | c4queryenum_next 106 | c4queryenum_fullTextMatched 107 | c4queryenum_close 108 | c4queryenum_free 109 | c4doc_getForPut 110 | c4_getObjectCount 111 | c4_shutdown 112 | -------------------------------------------------------------------------------- /C/c4.exp: -------------------------------------------------------------------------------- 1 | # c4.exp 2 | # CBForest 3 | # 4 | # Created by Jens Alfke on 9/15/15. 5 | # Copyright © 2015 Couchbase. All rights reserved. 6 | 7 | _c4SliceEqual 8 | _c4slice_free 9 | _c4log_register 10 | _c4error_getMessage 11 | 12 | _c4db_open 13 | _c4db_free 14 | _c4db_close 15 | _c4db_delete 16 | _c4db_deleteAtPath 17 | _c4db_compact 18 | _c4db_rekey 19 | _c4db_getPath 20 | _c4db_getDocumentCount 21 | _c4db_getLastSequence 22 | _c4db_beginTransaction 23 | _c4db_endTransaction 24 | _c4db_isInTransaction 25 | 26 | _c4raw_free 27 | _c4raw_get 28 | _c4raw_put 29 | 30 | _c4doc_free 31 | _c4doc_get 32 | _c4doc_getBySequence 33 | _c4doc_getType 34 | _c4db_purgeDoc 35 | _c4doc_selectRevision 36 | _c4doc_selectCurrentRevision 37 | _c4doc_loadRevisionBody 38 | _c4doc_hasRevisionBody 39 | _c4doc_selectParentRevision 40 | _c4doc_selectNextRevision 41 | _c4doc_selectNextLeafRevision 42 | _c4doc_getForPut 43 | _c4doc_generateRevID 44 | _c4doc_generateOldStyleRevID 45 | _c4doc_put 46 | _c4doc_insertRevision 47 | _c4doc_insertRevisionWithHistory 48 | _c4doc_purgeRevision 49 | _c4doc_setType 50 | _c4doc_save 51 | _c4doc_setExpiration 52 | _c4doc_getExpiration 53 | _c4db_nextDocExpiration 54 | 55 | _c4rev_getGeneration 56 | 57 | _c4db_enumerateChanges 58 | _c4db_enumerateAllDocs 59 | _c4db_enumerateSomeDocs 60 | _c4db_enumerateExpired 61 | _c4enum_next 62 | _c4enum_nextDocument 63 | _c4enum_getDocumentInfo 64 | _c4enum_getDocument 65 | _c4enum_close 66 | _c4enum_free 67 | _c4exp_free 68 | _c4exp_close 69 | _c4exp_getDocID 70 | _c4exp_next 71 | _c4exp_purgeExpired 72 | 73 | _kC4DefaultEnumeratorOptions 74 | _kC4DefaultQueryOptions 75 | 76 | _c4key_new 77 | _c4key_newFullTextString 78 | _c4key_newGeoJSON 79 | _c4key_withBytes 80 | _c4key_free 81 | _c4key_addNull 82 | _c4key_addBool 83 | _c4key_addNumber 84 | _c4key_addString 85 | _c4key_addMapKey 86 | _c4key_beginArray 87 | _c4key_endArray 88 | _c4key_beginMap 89 | _c4key_endMap 90 | 91 | _c4key_read 92 | _c4key_peek 93 | _c4key_skipToken 94 | _c4key_readBool 95 | _c4key_readNumber 96 | _c4key_readString 97 | _c4key_toJSON 98 | _c4key_setDefaultFullTextLanguage 99 | 100 | _c4view_open 101 | _c4view_free 102 | _c4view_close 103 | _c4view_eraseIndex 104 | _c4view_delete 105 | _c4view_getTotalRows 106 | _c4view_getLastSequenceIndexed 107 | _c4view_getLastSequenceChangedAt 108 | _c4view_rekey 109 | 110 | _c4indexer_begin 111 | _c4indexer_triggerOnView 112 | _c4indexer_enumerateDocuments 113 | _c4indexer_shouldIndexDocument 114 | _c4indexer_emit 115 | _c4indexer_emitList 116 | _c4indexer_end 117 | 118 | _c4view_query 119 | _c4view_fullTextQuery 120 | _c4view_geoQuery 121 | _c4view_fullTextMatched 122 | _c4queryenum_next 123 | _c4queryenum_fullTextMatched 124 | _c4queryenum_close 125 | _c4queryenum_free 126 | 127 | # Private API, only exposed for testing: 128 | _c4doc_getForPut 129 | _c4_getObjectCount 130 | _c4_shutdown 131 | -------------------------------------------------------------------------------- /C/c4.h: -------------------------------------------------------------------------------- 1 | // 2 | // c4.h 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 1/21/16. 6 | // Copyright © 2016 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef c4_h 10 | #define c4_h 11 | 12 | #include "c4Base.h" 13 | #include "c4Database.h" 14 | #include "c4Document.h" 15 | #include "c4DocEnumerator.h" 16 | #include "c4Key.h" 17 | #include "c4View.h" 18 | 19 | 20 | #endif /* c4_h */ 21 | -------------------------------------------------------------------------------- /C/c4ExpiryEnumerator.cc: -------------------------------------------------------------------------------- 1 | // 2 | // c4ExpiryEnumerator.c 3 | // CBForest 4 | // 5 | // Created by Jim Borden on 4/13/16. 6 | // Copyright © 2016 Couchbase. All rights reserved. 7 | // 8 | 9 | #include "c4Impl.hh" 10 | #include "c4ExpiryEnumerator.h" 11 | 12 | #include "DocEnumerator.hh" 13 | #include "KeyStore.hh" 14 | #include "varint.hh" 15 | #include "stdint.h" 16 | 17 | #ifdef _MSC_VER 18 | #include 19 | #endif 20 | using namespace cbforest; 21 | 22 | struct C4ExpiryEnumerator 23 | { 24 | public: 25 | C4ExpiryEnumerator(C4Database *database) : 26 | _db(database), 27 | _e(_db->getKeyStore("expiry"), slice::null, slice::null), 28 | _reader(slice::null) 29 | { 30 | _endTimestamp = time(NULL); 31 | reset(); 32 | } 33 | 34 | bool next() { 35 | if(!_e.next()) { 36 | return false; 37 | } 38 | 39 | _reader = CollatableReader(_e.doc().key()); 40 | _reader.skipTag(); 41 | _reader.readInt(); 42 | _current = _reader.readString(); 43 | 44 | return true; 45 | } 46 | 47 | slice docID() const 48 | { 49 | return _current; 50 | } 51 | 52 | slice key() const 53 | { 54 | return _e.doc().key(); 55 | } 56 | 57 | void reset() 58 | { 59 | CollatableBuilder c; 60 | c.beginArray(); 61 | c << (double)_endTimestamp; 62 | c.beginMap(); 63 | c.endMap(); 64 | c.endArray(); 65 | _e = DocEnumerator(_db->getKeyStore("expiry"), slice::null, c.data()); 66 | _reader = CollatableReader(slice::null); 67 | } 68 | 69 | void close() 70 | { 71 | _e.close(); 72 | } 73 | 74 | C4Database *getDatabase() const 75 | { 76 | return _db; 77 | } 78 | 79 | private: 80 | Retained _db; 81 | DocEnumerator _e; 82 | alloc_slice _current; 83 | CollatableReader _reader; 84 | uint64_t _endTimestamp; 85 | }; 86 | 87 | C4ExpiryEnumerator *c4db_enumerateExpired(C4Database *database, C4Error *outError) 88 | { 89 | try { 90 | WITH_LOCK(database); 91 | return new C4ExpiryEnumerator(database); 92 | } catchError(outError); 93 | 94 | return NULL; 95 | } 96 | 97 | bool c4exp_next(C4ExpiryEnumerator *e, C4Error *outError) 98 | { 99 | try { 100 | if (e->next()) 101 | return true; 102 | clearError(outError); 103 | } catchError(outError); 104 | return false; 105 | } 106 | 107 | C4SliceResult c4exp_getDocID(const C4ExpiryEnumerator *e) 108 | { 109 | slice result = e->docID().copy(); 110 | return { result.buf, result.size }; 111 | } 112 | 113 | bool c4exp_purgeExpired(C4ExpiryEnumerator *e, C4Error *outError) 114 | { 115 | if (!c4db_beginTransaction(e->getDatabase(), outError)) 116 | return false; 117 | bool commit = false; 118 | try { 119 | WITH_LOCK(e->getDatabase()); 120 | e->reset(); 121 | Transaction *t = e->getDatabase()->transaction(); 122 | KeyStore& expiry = e->getDatabase()->getKeyStore("expiry"); 123 | KeyStoreWriter writer(expiry, *t); 124 | while(e->next()) { 125 | writer.del(e->key()); 126 | writer.del(e->docID()); 127 | } 128 | commit = true; 129 | } catchError(outError); 130 | 131 | c4db_endTransaction(e->getDatabase(), commit, NULL); 132 | return commit; 133 | } 134 | 135 | void c4exp_close(C4ExpiryEnumerator *e) 136 | { 137 | if (e) { 138 | e->close(); 139 | } 140 | } 141 | 142 | void c4exp_free(C4ExpiryEnumerator *e) 143 | { 144 | delete e; 145 | } 146 | -------------------------------------------------------------------------------- /C/c4ExpiryEnumerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // c4ExpiryEnumerator.h 3 | // CBForest 4 | // 5 | // Created by Jim Borden on 4/13/16. 6 | // Copyright © 2016 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef c4ExpiryEnumerator_h 10 | #define c4ExpiryEnumerator_h 11 | 12 | #include "c4Database.h" 13 | #include "c4DocEnumerator.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /** Opaque handle to an enumerator that iterates through expired documents. */ 20 | typedef struct C4ExpiryEnumerator C4ExpiryEnumerator; 21 | 22 | /** Creates an enumerator for iterating over expired documents 23 | Caller is responsible for freeing the enumerator when finished with it. 24 | @param database The database. 25 | @param outError Error will be stored here on failure. 26 | @return A new enumerator, or NULL on failure. */ 27 | C4ExpiryEnumerator *c4db_enumerateExpired(C4Database *database, 28 | C4Error *outError); 29 | 30 | /** Advances the enumerator to the next document. 31 | Returns false at the end, or on error; look at the C4Error to determine which occurred, 32 | and don't forget to free the enumerator. */ 33 | bool c4exp_next(C4ExpiryEnumerator *e, C4Error *outError); 34 | 35 | /** Gets the document ID of the current doc being enumerated 36 | @param e The enumerator. 37 | @return A slice representing the doc ID (caller must free) 38 | */ 39 | C4SliceResult c4exp_getDocID(const C4ExpiryEnumerator *e); 40 | 41 | /** Purges the processed entries from the expiration key value store */ 42 | bool c4exp_purgeExpired(C4ExpiryEnumerator *e, C4Error *outError); 43 | 44 | /** Closes the enumeator and disallows further use */ 45 | void c4exp_close(C4ExpiryEnumerator *e); 46 | 47 | /** Frees a C4DocEnumerator handle */ 48 | void c4exp_free(C4ExpiryEnumerator *e); 49 | 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* c4ExpiryEnumerator_h */ 56 | -------------------------------------------------------------------------------- /C/c4Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // c4Private.h 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 1/21/16. 6 | // Copyright © 2016 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef c4Private_h 10 | #define c4Private_h 11 | #include "c4Document.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | C4Document* c4doc_getForPut(C4Database *database, 18 | C4Slice docID, 19 | C4Slice parentRevID, 20 | bool deleting, 21 | bool allowConflict, 22 | C4Error *outError); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* c4Private_h */ 29 | -------------------------------------------------------------------------------- /C/tests/c4AllDocsPerformanceTest.cc: -------------------------------------------------------------------------------- 1 | // 2 | // c4AllDocsPerformanceTest.cpp 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 11/16/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #include "c4Test.hh" 10 | #ifdef _MSC_VER 11 | #define random() rand() 12 | #include 13 | #endif 14 | 15 | class C4AllDocsPerformanceTest : public C4Test { 16 | public: 17 | 18 | static const size_t kSizeOfDocument = 1000; 19 | static const unsigned kNumDocuments = 100000; 20 | 21 | void setUp() { 22 | C4Test::setUp(); 23 | 24 | char content[kSizeOfDocument]; 25 | memset(content, 'a', sizeof(content)-1); 26 | content[sizeof(content)-1] = 0; 27 | 28 | 29 | C4Error error; 30 | Assert(c4db_beginTransaction(db, &error)); 31 | 32 | for (unsigned i = 0; i < kNumDocuments; i++) { 33 | char docID[50]; 34 | sprintf(docID, "doc-%08lx-%08lx-%08lx-%04x", random(), random(), random(), i); 35 | C4Document* doc = c4doc_get(db, c4str(docID), false, &error); 36 | Assert(doc); 37 | char revID[50]; 38 | sprintf(revID, "1-deadbeefcafebabe80081e50"); 39 | char json[kSizeOfDocument+100]; 40 | sprintf(json, "{\"content\":\"%s\"}", content); 41 | int revs = c4doc_insertRevision(doc, c4str(revID), c4str(json), false, false, false, &error); 42 | AssertEqual(revs, 1); 43 | Assert(c4doc_save(doc, 20, &error)); 44 | c4doc_free(doc); 45 | } 46 | 47 | Assert(c4db_endTransaction(db, true, &error)); 48 | fprintf(stderr, "Created %u docs\n", kNumDocuments); 49 | 50 | AssertEqual(c4db_getDocumentCount(db), (uint64_t)kNumDocuments); 51 | } 52 | 53 | void testAllDocsPerformance() { 54 | auto start = clock(); 55 | 56 | C4EnumeratorOptions options = kC4DefaultEnumeratorOptions; 57 | options.flags &= ~kC4IncludeBodies; 58 | C4Error error; 59 | auto e = c4db_enumerateAllDocs(db, kC4SliceNull, kC4SliceNull, &options, &error); 60 | Assert(e); 61 | C4Document* doc; 62 | unsigned i = 0; 63 | while (NULL != (doc = c4enum_nextDocument(e, &error))) { 64 | i++; 65 | c4doc_free(doc); 66 | } 67 | c4enum_free(e); 68 | Assert(i == kNumDocuments); 69 | 70 | double elapsed = (clock() - start) / (double)CLOCKS_PER_SEC; 71 | fprintf(stderr, "Enumerating %u docs took %.3f ms (%.3f ms/doc)\n", 72 | i, elapsed*1000.0, elapsed/i*1000.0); 73 | } 74 | 75 | CPPUNIT_TEST_SUITE( C4AllDocsPerformanceTest ); 76 | CPPUNIT_TEST( testAllDocsPerformance ); 77 | CPPUNIT_TEST_SUITE_END(); 78 | }; 79 | 80 | //CPPUNIT_TEST_SUITE_REGISTRATION(C4AllDocsPerformanceTest); 81 | -------------------------------------------------------------------------------- /C/tests/c4KeyTest.cc: -------------------------------------------------------------------------------- 1 | // 2 | // c4KeyTest.cc 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 9/16/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #include "c4Test.hh" 10 | #include "c4View.h" 11 | #include "c4Document.h" 12 | 13 | 14 | class C4KeyTest : public CppUnit::TestFixture { 15 | public: 16 | 17 | C4Key *key; 18 | 19 | virtual void setUp() { 20 | key = c4key_new(); 21 | } 22 | 23 | virtual void tearDown() { 24 | c4key_free(key); 25 | } 26 | 27 | void populateKey() { 28 | c4key_beginArray(key); 29 | c4key_addNull(key); 30 | c4key_addBool(key, false); 31 | c4key_addBool(key, true); 32 | c4key_addNumber(key, 0); 33 | c4key_addNumber(key, 12345); 34 | c4key_addNumber(key, -2468); 35 | c4key_addString(key, c4str("foo")); 36 | c4key_beginArray(key); 37 | c4key_endArray(key); 38 | c4key_endArray(key); 39 | } 40 | 41 | void testCreateKey() { 42 | populateKey(); 43 | AssertEqual(toJSON(key), std::string("[null,false,true,0,12345,-2468,\"foo\",[]]")); 44 | } 45 | 46 | void testReadKey() { 47 | populateKey(); 48 | C4KeyReader r = c4key_read(key); 49 | AssertEqual(c4key_peek(&r), (C4KeyToken)kC4Array); 50 | c4key_skipToken(&r); 51 | AssertEqual(c4key_peek(&r), (C4KeyToken)kC4Null); 52 | c4key_skipToken(&r); 53 | AssertEqual(c4key_peek(&r), (C4KeyToken)kC4Bool); 54 | AssertEqual(c4key_readBool(&r), false); 55 | AssertEqual(c4key_readBool(&r), true); 56 | AssertEqual(c4key_readNumber(&r), 0.0); 57 | AssertEqual(c4key_readNumber(&r), 12345.0); 58 | AssertEqual(c4key_readNumber(&r), -2468.0); 59 | AssertEqual(c4key_readString(&r), c4str("foo")); 60 | AssertEqual(c4key_peek(&r), (C4KeyToken)kC4Array); 61 | c4key_skipToken(&r); 62 | AssertEqual(c4key_peek(&r), (C4KeyToken)kC4EndSequence); 63 | c4key_skipToken(&r); 64 | AssertEqual(c4key_peek(&r), (C4KeyToken)kC4EndSequence); 65 | c4key_skipToken(&r); 66 | } 67 | 68 | 69 | CPPUNIT_TEST_SUITE( C4KeyTest ); 70 | CPPUNIT_TEST( testCreateKey ); 71 | CPPUNIT_TEST( testReadKey ); 72 | CPPUNIT_TEST_SUITE_END(); 73 | }; 74 | 75 | CPPUNIT_TEST_SUITE_REGISTRATION(C4KeyTest); 76 | -------------------------------------------------------------------------------- /C/tests/c4Test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // c4Test.cc 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 9/16/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #include "c4Test.hh" 10 | #ifndef _MSC_VER 11 | #include 12 | #endif 13 | 14 | bool operator== (C4Slice s1, C4Slice s2) { 15 | return s1.size == s2.size && memcmp(s1.buf, s2.buf, s1.size) == 0; 16 | } 17 | 18 | std::ostream& operator<< (std::ostream& o, C4Slice s) { 19 | o << "C4Slice["; 20 | if (s.buf == NULL) 21 | return o << "null]"; 22 | auto buf = (const uint8_t*)s.buf; 23 | for (size_t i = 0; i < s.size; i++) { 24 | if (buf[i] < 32 || buf[i] > 126) 25 | return o << "binary, " << s.size << " bytes]"; 26 | } 27 | return o << '"' << std::string((char*)s.buf, s.size) << "\"]"; 28 | } 29 | 30 | 31 | static void log(C4LogLevel level, C4Slice message) { 32 | static const char* kLevelNames[4] = {"debug", "info", "WARNING", "ERROR"}; 33 | fprintf(stderr, "CBForest-C %s: %*s\n", kLevelNames[level], (int)message.size, message.buf); 34 | } 35 | 36 | 37 | void C4Test::setUp() { 38 | c4_shutdown(NULL); 39 | 40 | objectCount = c4_getObjectCount(); 41 | c4log_register(kC4LogWarning, log); 42 | #ifdef _MSC_VER 43 | const char *dbPath = "C:\\tmp\\forest_temp.fdb"; 44 | ::unlink("C:\\tmp\\forest_temp.fdb"); 45 | ::unlink("C:\\tmp\\forest_temp.fdb.0"); 46 | ::unlink("C:\\tmp\\forest_temp.fdb.1"); 47 | ::unlink("C:\\tmp\\forest_temp.fdb.meta"); 48 | #else 49 | const char *dbPath = "/tmp/forest_temp.fdb"; 50 | ::unlink("/tmp/forest_temp.fdb"); 51 | ::unlink("/tmp/forest_temp.fdb.0"); 52 | ::unlink("/tmp/forest_temp.fdb.1"); 53 | ::unlink("/tmp/forest_temp.fdb.meta"); 54 | #endif 55 | 56 | C4Error error; 57 | db = c4db_open(c4str(dbPath), kC4DB_Create, encryptionKey(), &error); 58 | Assert(db != NULL); 59 | } 60 | 61 | 62 | void C4Test::tearDown() { 63 | C4Error error; 64 | c4db_delete(db, &error); 65 | c4db_free(db); 66 | 67 | // Check for leaks: 68 | AssertEqual(c4_getObjectCount() - objectCount, 0); 69 | } 70 | 71 | 72 | void C4Test::createRev(C4Slice docID, C4Slice revID, C4Slice body, bool isNew) { 73 | TransactionHelper t(db); 74 | C4Error error; 75 | C4Document *doc = c4doc_get(db, docID, false, &error); 76 | Assert(doc != NULL); 77 | bool deleted = (body.buf == NULL); 78 | AssertEqual(c4doc_insertRevision(doc, revID, body, deleted, false, false, &error), (int)isNew); 79 | Assert(c4doc_save(doc, 20, &error)); 80 | c4doc_free(doc); 81 | } 82 | 83 | 84 | const C4Slice C4Test::kDocID = C4STR("mydoc"); 85 | const C4Slice C4Test::kRevID = C4STR("1-abcdef"); 86 | const C4Slice C4Test::kRev2ID= C4STR("2-d00d3333"); 87 | const C4Slice C4Test::kBody = C4STR("{\"name\":007}"); 88 | 89 | 90 | // Dumps a C4Key to a C++ string 91 | std::string toJSON(C4KeyReader r) { 92 | C4SliceResult dump = c4key_toJSON(&r); 93 | std::string result((char*)dump.buf, dump.size); 94 | c4slice_free(dump); 95 | return result; 96 | } 97 | -------------------------------------------------------------------------------- /C/tests/c4Test.hh: -------------------------------------------------------------------------------- 1 | // 2 | // c4Test.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 9/16/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef c4Test_hh 10 | #define c4Test_hh 11 | 12 | #include "c4Database.h" 13 | #include "c4Document.h" 14 | #include "c4DocEnumerator.h" 15 | #include "c4View.h" 16 | #include 17 | #include 18 | #include "iostream" 19 | 20 | 21 | // Less-obnoxious names for assertions: 22 | #define Assert CPPUNIT_ASSERT 23 | #define AssertEqual(ACTUAL, EXPECTED) CPPUNIT_ASSERT_EQUAL(EXPECTED, ACTUAL) 24 | 25 | 26 | // Some operators to make C4Slice work with AssertEqual: 27 | bool operator== (C4Slice s1, C4Slice s2); 28 | std::ostream& operator<< (std::ostream& o, C4Slice s); 29 | 30 | std::string toJSON(C4KeyReader r); 31 | 32 | 33 | 34 | // This helper is necessary because it ends an open transaction if an assertion fails. 35 | // If the transaction isn't ended, the c4db_delete call in tearDown will deadlock. 36 | class TransactionHelper { 37 | public: 38 | TransactionHelper(C4Database* db) 39 | :_db(NULL) 40 | { 41 | C4Error error; 42 | Assert(c4db_beginTransaction(db, &error)); 43 | _db = db; 44 | } 45 | 46 | ~TransactionHelper() { 47 | if (_db) { 48 | C4Error error; 49 | Assert(c4db_endTransaction(_db, true, &error)); 50 | } 51 | } 52 | 53 | private: 54 | C4Database* _db; 55 | }; 56 | 57 | 58 | // Handy base class that creates a new empty C4Database in its setUp method, 59 | // and closes & deletes it in tearDown. 60 | class C4Test : public CppUnit::TestFixture { 61 | public: 62 | virtual void setUp(); 63 | virtual void tearDown(); 64 | 65 | protected: 66 | C4Database *db; 67 | 68 | virtual const C4EncryptionKey* encryptionKey() {return NULL;} 69 | 70 | // Creates a new document revision 71 | void createRev(C4Slice docID, C4Slice revID, C4Slice body, bool isNew = true); 72 | 73 | // Some handy constants to use 74 | static const C4Slice kDocID; // "mydoc" 75 | static const C4Slice kRevID; // "1-abcdef" 76 | static const C4Slice kRev2ID; // "2-d00d3333" 77 | static const C4Slice kBody; // "{\"name\":007}" 78 | 79 | private: 80 | int objectCount; 81 | }; 82 | 83 | 84 | // Dumps a C4Key to a C++ string 85 | std::string toJSON(C4KeyReader); 86 | 87 | static inline std::string toJSON(C4Key* key) {return toJSON(c4key_read(key));} 88 | 89 | static inline std::string toString(C4Slice s) {return std::string((char*)s.buf, s.size);} 90 | 91 | #endif /* c4Test_hh */ 92 | -------------------------------------------------------------------------------- /CBForest Tests/CBForest Tests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CBForest Tests/CBForest Tests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /CBForest Tests/C_API_Test.mm: -------------------------------------------------------------------------------- 1 | // 2 | // C_API_Test.mm 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 11/16/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "testutil.h" 11 | #import "c4Database.h" 12 | #import "c4Document.h" 13 | #import "c4DocEnumerator.h" 14 | 15 | 16 | @interface C_API_Test : XCTestCase 17 | @end 18 | 19 | 20 | @implementation C_API_Test 21 | { 22 | C4Database *db; 23 | } 24 | 25 | static const size_t kSizeOfDocument = 1000; 26 | static const unsigned kNumDocuments = 10000; 27 | 28 | - (void)setUp { 29 | [super setUp]; 30 | 31 | const char *dbPath = "/tmp/forest_temp.fdb"; 32 | ::unlink("/tmp/forest_temp.fdb"); 33 | ::unlink("/tmp/forest_temp.fdb.0"); 34 | ::unlink("/tmp/forest_temp.fdb.1"); 35 | ::unlink("/tmp/forest_temp.fdb.meta"); 36 | 37 | C4Error error; 38 | db = c4db_open(c4str(dbPath), kC4DB_Create, NULL, &error); 39 | Assert(db != NULL); 40 | } 41 | 42 | - (void)tearDown { 43 | if (db) 44 | c4db_delete(db, NULL); 45 | [super tearDown]; 46 | } 47 | 48 | - (void)testExample { 49 | // This is an example of a functional test case. 50 | // Use XCTAssert and related functions to verify your tests produce the correct results. 51 | } 52 | 53 | - (void)testPerformanceExample { 54 | char content[kSizeOfDocument]; 55 | memset(content, 'a', sizeof(content)-1); 56 | content[sizeof(content)-1] = 0; 57 | 58 | // Create documents: 59 | C4Error error; 60 | Assert(c4db_beginTransaction(db, &error)); 61 | 62 | for (unsigned i = 0; i < kNumDocuments; i++) { 63 | char docID[50]; 64 | sprintf(docID, "doc-%08lx-%08lx-%08lx-%04x", random(), random(), random(), i); 65 | C4Document* doc = c4doc_get(db, c4str(docID), false, &error); 66 | Assert(doc); 67 | char revID[50]; 68 | sprintf(revID, "1-deadbeefcafebabe80081e50"); 69 | char json[kSizeOfDocument+100]; 70 | sprintf(json, "{\"content\":\"%s\"}", content); 71 | int revs = c4doc_insertRevision(doc, c4str(revID), c4str(json), false, false, false, &error); 72 | AssertEq(revs, 1); 73 | Assert(c4doc_save(doc, 20, &error)); 74 | c4doc_free(doc); 75 | } 76 | 77 | Assert(c4db_endTransaction(db, true, &error)); 78 | AssertEq(c4db_getDocumentCount(db), (uint64_t)kNumDocuments); 79 | fprintf(stderr, "Created %u docs\n", kNumDocuments); 80 | 81 | [self measureBlock:^{ 82 | C4EnumeratorOptions options = kC4DefaultEnumeratorOptions; 83 | options.flags &= ~kC4IncludeBodies; 84 | C4Error enumError; 85 | auto e = c4db_enumerateAllDocs(db, kC4SliceNull, kC4SliceNull, &options, &enumError); 86 | Assert(e); 87 | C4Document* doc; 88 | unsigned i = 0; 89 | while (NULL != (doc = c4enum_nextDocument(e, &enumError))) { 90 | i++; 91 | c4doc_free(doc); 92 | } 93 | c4enum_free(e); 94 | Assert(i == kNumDocuments); 95 | }]; 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /CBForest Tests/Slice_Test.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Slice_Test.mm 3 | // CBForest 4 | // 5 | // Created by Pasin Suriyentrakorn on 8/14/15. 6 | // Copyright (c) 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "testutil.h" 11 | #import "slice.hh" 12 | 13 | using namespace cbforest; 14 | 15 | @interface Slice_Test : XCTestCase 16 | @end 17 | 18 | @implementation Slice_Test 19 | 20 | - (void) testHasPrefix { 21 | slice s = slice(); 22 | Assert(!s.hasPrefix(NULL)); 23 | Assert(!s.hasPrefix(slice())); 24 | Assert(!s.hasPrefix(slice(""))); 25 | Assert(!s.hasPrefix(slice("abc"))); 26 | 27 | s = slice(""); 28 | Assert(!s.hasPrefix(NULL)); 29 | Assert(!s.hasPrefix(slice())); 30 | Assert(!s.hasPrefix(slice(""))); 31 | Assert(!s.hasPrefix(slice("abc"))); 32 | 33 | s = slice("abc"); 34 | Assert(s.hasPrefix(slice("ab"))); 35 | Assert(s.hasPrefix(slice("abc"))); 36 | Assert(!s.hasPrefix(NULL)); 37 | Assert(!s.hasPrefix(slice())); 38 | Assert(!s.hasPrefix(slice(""))); 39 | Assert(!s.hasPrefix(slice("ac"))); 40 | Assert(!s.hasPrefix(slice("abcd"))); 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /CBForest Tests/Tokenizer_Test.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Tokenizer_Test.m 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 10/20/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "Tokenizer.hh" 11 | 12 | using namespace cbforest; 13 | 14 | 15 | @interface Tokenizer_Test : XCTestCase 16 | @end 17 | 18 | 19 | @implementation Tokenizer_Test 20 | { 21 | Tokenizer* tokenizer; 22 | } 23 | 24 | - (void) setUp { 25 | [super setUp]; 26 | } 27 | 28 | - (void) tearDown { 29 | delete tokenizer; 30 | [super tearDown]; 31 | } 32 | 33 | - (NSArray*) tokenize: (NSString*)string unique: (BOOL)unique { 34 | NSMutableArray* tokens = [NSMutableArray array]; 35 | for (TokenIterator i(*tokenizer, nsstring_slice(string), unique); i; ++i) { 36 | std::string tok = i.token(); 37 | NSString* token = [[NSString alloc] initWithBytes: tok.c_str() length: tok.size() encoding: NSUTF8StringEncoding]; 38 | XCTAssert(i.wordLength() > 0 && i.wordLength() < 20); 39 | XCTAssert(i.wordOffset() < string.length); 40 | [tokens addObject: token]; 41 | } 42 | return tokens; 43 | } 44 | 45 | - (NSArray*) tokenize: (NSString*)string { 46 | return [self tokenize: string unique: NO]; 47 | } 48 | 49 | - (void)testDefaultTokenizer { 50 | tokenizer = new Tokenizer("", false); 51 | XCTAssertEqualObjects(([self tokenize: @"Have a nice day, dude!"]), 52 | (@[@"have", @"a", @"nice", @"day", @"dude"])); 53 | XCTAssertEqualObjects(([self tokenize: @"Having,larger books. ¡Ça vä!"]), 54 | (@[@"having", @"larger", @"books", @"ça", @"vä"])); 55 | XCTAssertEqualObjects(([self tokenize: @"“Typographic ‘quotes’ aren’t optional”"]), 56 | (@[@"typographic", @"quotes", @"aren't", @"optional"])); 57 | XCTAssertEqualObjects(([self tokenize: @"seven eight seven nine" unique: YES]), 58 | (@[@"seven", @"eight", @"nine"])); 59 | } 60 | 61 | - (void)testEnglishTokenizer { 62 | tokenizer = new Tokenizer("english", true); 63 | 64 | XCTAssertEqualObjects(([self tokenize: @"Have a nice day, dude!"]), 65 | (@[@"nice", @"day", @"dude"])); 66 | XCTAssertEqualObjects(([self tokenize: @"Having,larger books. ¡Ça vä!"]), 67 | (@[@"larger", @"book", @"ca", @"va"])); 68 | XCTAssertEqualObjects(([self tokenize: @"\"Typographic 'quotes' can't be optional\""]), 69 | (@[@"typograph", @"quot", @"option"])); 70 | XCTAssertEqualObjects(([self tokenize: @"“Typographic ‘quotes’ can’t be optional”"]), 71 | (@[@"typograph", @"quot", @"option"])); 72 | XCTAssertEqualObjects(([self tokenize: @"seven can't nine"]), 73 | (@[@"seven", @"nine"])); 74 | XCTAssertEqualObjects(([self tokenize: @"seven can’t nine"]), // curly quote! 75 | (@[@"seven", @"nine"])); 76 | } 77 | 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /CBForest Tests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CBForest Tests/testutil.h: -------------------------------------------------------------------------------- 1 | // 2 | // testutil.h 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 5/13/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | 9 | #import "Database.hh" 10 | 11 | #define Assert XCTAssert 12 | #define AssertEq XCTAssertEqual 13 | #define AssertEqual XCTAssertEqualObjects 14 | 15 | void CreateTestDir(); 16 | std::string PathForDatabaseNamed(NSString *name); 17 | cbforest::Database::config TestDBConfig(); 18 | -------------------------------------------------------------------------------- /CBForest.VS2015/CBForest.VS2015.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CBForest.VS2015/CBForest.VS2015.sdf -------------------------------------------------------------------------------- /CBForest.VS2015/CBForest.VS2015.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CBForest.VS2015", "CBForest.VS2015.vcxproj", "{F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppTests", "..\CppTests\CppTests\CppTests.vcxproj", "{48A735B4-DF94-4292-ACD9-688B723B6034}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | Template|x64 = Template|x64 17 | Template|x86 = Template|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Debug|x64.ActiveCfg = Debug|x64 21 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Debug|x64.Build.0 = Debug|x64 22 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Debug|x86.ActiveCfg = Debug|Win32 23 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Debug|x86.Build.0 = Debug|Win32 24 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Release|x64.ActiveCfg = Release|x64 25 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Release|x64.Build.0 = Release|x64 26 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Release|x86.ActiveCfg = Release|Win32 27 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Release|x86.Build.0 = Release|Win32 28 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Template|x64.ActiveCfg = Release|x64 29 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Template|x64.Build.0 = Release|x64 30 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Template|x86.ActiveCfg = Release|Win32 31 | {F1A2DEDF-6C9A-4335-B7CB-91B83EA78100}.Template|x86.Build.0 = Release|Win32 32 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Debug|x64.ActiveCfg = Debug|x64 33 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Debug|x64.Build.0 = Debug|x64 34 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Debug|x86.ActiveCfg = Debug|Win32 35 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Debug|x86.Build.0 = Debug|Win32 36 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Release|x64.ActiveCfg = Release|x64 37 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Release|x64.Build.0 = Release|x64 38 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Release|x86.ActiveCfg = Release|Win32 39 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Release|x86.Build.0 = Release|Win32 40 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Template|x64.ActiveCfg = Release|x64 41 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Template|x64.Build.0 = Release|x64 42 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Template|x86.ActiveCfg = Release|Win32 43 | {48A735B4-DF94-4292-ACD9-688B723B6034}.Template|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /CBForest.VS2015/LibLocations.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | D:\Development\cppunit\include 7 | D:\Development\cppunit\lib\x64 8 | D:\Development\cppunit\lib\x86 9 | 10 | 11 | 12 | 13 | 14 | $(CppUnit_Include) 15 | 16 | 17 | $(CppUnit_Lib_x64) 18 | 19 | 20 | $(CppUnit_Lib_x86) 21 | 22 | 23 | -------------------------------------------------------------------------------- /CBForest.VS2015/asprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/) 3 | 4 | Permission to use, copy, modify, and distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "asprintf.h" 18 | 19 | int asprintf(char **strp, const char *fmt, ...) 20 | { 21 | int r; 22 | va_list ap; 23 | va_start(ap, fmt); 24 | r = vasprintf(strp, fmt, ap); 25 | va_end(ap); 26 | return(r); 27 | } 28 | -------------------------------------------------------------------------------- /CBForest.VS2015/asprintf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/) 3 | 4 | Permission to use, copy, modify, and distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef INSANE_ASPRINTF_H 18 | #define INSANE_ASPRINTF_H 19 | 20 | #ifndef __cplusplus 21 | #include 22 | #else 23 | #include 24 | extern "C" 25 | { 26 | #endif 27 | 28 | #define insane_free(ptr) { free(ptr); ptr = 0; } 29 | 30 | int vasprintf(char **strp, const char *fmt, va_list ap); 31 | int asprintf(char **strp, const char *fmt, ...); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /CBForest.VS2015/memmem.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * The memmem() function finds the start of the first occurrence of the 5 | * substring 'needle' of length 'nlen' in the memory area 'haystack' of 6 | * length 'hlen'. 7 | * 8 | * The return value is a pointer to the beginning of the sub-string, or 9 | * NULL if the substring is not found. 10 | */ 11 | void *memmem(const void *haystack, size_t hlen, const void *needle, size_t nlen) 12 | { 13 | int needle_first; 14 | const unsigned char *p = (const unsigned char *)haystack; 15 | size_t plen = hlen; 16 | 17 | if (!nlen) 18 | return NULL; 19 | 20 | needle_first = *(unsigned char *)needle; 21 | 22 | while (plen >= nlen && (p = memchr(p, needle_first, plen - nlen + 1))) 23 | { 24 | if (!memcmp(p, needle, nlen)) 25 | return (void *)p; 26 | 27 | p++; 28 | plen = hlen - (p - haystack); 29 | } 30 | 31 | return NULL; 32 | } -------------------------------------------------------------------------------- /CBForest.VS2015/memmem.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * The memmem() function finds the start of the first occurrence of the 6 | * substring 'needle' of length 'nlen' in the memory area 'haystack' of 7 | * length 'hlen'. 8 | */ 9 | const void* memmem(const void *l, size_t l_len, const void *s, size_t s_len) 10 | { 11 | register char *cur, *last; 12 | const char *cl = (const char *)l; 13 | const char *cs = (const char *)s; 14 | 15 | /* we need something to compare */ 16 | if (l_len == 0 || s_len == 0) 17 | return 0; 18 | 19 | /* "s" must be smaller or equal to "l" */ 20 | if (l_len < s_len) 21 | return 0; 22 | 23 | /* special case where s_len == 1 */ 24 | if (s_len == 1) 25 | return memchr(l, (int)*cs, l_len); 26 | 27 | /* the last position where its possible to find "s" in "l" */ 28 | last = (char *)cl + l_len - s_len; 29 | 30 | for (cur = (char *)cl; cur <= last; cur++) 31 | if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) 32 | return cur; 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /CBForest.VS2015/memmem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const void* memmem(const void *l, size_t l_len, const void *s, size_t s_len); -------------------------------------------------------------------------------- /CBForest.VS2015/vasprintf-msvc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/) 3 | 4 | Permission to use, copy, modify, and distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include "asprintf.h" 21 | 22 | int vasprintf(char **strp, const char *fmt, va_list ap) 23 | { 24 | int r = -1, size = _vscprintf(fmt, ap); 25 | 26 | if ((size >= 0) && (size < INT_MAX)) 27 | { 28 | *strp = (char *)malloc(size+1); //+1 for null 29 | if (*strp) 30 | { 31 | r = vsnprintf(*strp, size+1, fmt, ap); //+1 for null 32 | if ((r < 0) || (r > size)) 33 | { 34 | insane_free(*strp); 35 | r = -1; 36 | } 37 | } 38 | } 39 | else { *strp = 0; } 40 | 41 | return(r); 42 | } -------------------------------------------------------------------------------- /CBForest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/All.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 66 | 67 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/CBForest static.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/CBForest-Interop.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/CBForestJNI.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/CppTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 55 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 74 | 76 | 82 | 83 | 84 | 85 | 87 | 88 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/Tokenizer-Interop Static.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/Tokenizer-Interop.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/Tokenizer.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CBForest.xcodeproj/xcshareddata/xcschemes/forestdb.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CBForest/CBForest-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | #include 13 | #include 14 | #include 15 | #endif 16 | 17 | #ifdef __OBJC__ 18 | #import 19 | #endif 20 | 21 | // Enable encryption support 22 | #define CBFOREST_ENCRYPTION 23 | 24 | // Enable thread safety of C API: 25 | #ifndef C4DB_THREADSAFE 26 | #define C4DB_THREADSAFE 0 27 | #endif 28 | -------------------------------------------------------------------------------- /CBForest/CBForest.hh: -------------------------------------------------------------------------------- 1 | // 2 | // CBForest.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 5/27/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #ifndef CBForest_CBForest_hh 17 | #define CBForest_CBForest_hh 18 | 19 | #ifndef __cplusplus 20 | #error C++ only! 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /CBForest/Document.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Document.cc 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 11/11/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #include "Document.hh" 17 | 18 | namespace cbforest { 19 | 20 | const size_t Document::kMaxKeyLength = FDB_MAX_KEYLEN; 21 | const size_t Document::kMaxMetaLength = FDB_MAX_METALEN; 22 | const size_t Document::kMaxBodyLength = FDB_MAX_BODYLEN; 23 | 24 | Document::Document() { 25 | memset(&_doc, 0, sizeof(_doc)); 26 | } 27 | 28 | Document::Document(Document&& srcDoc) 29 | :_doc(srcDoc._doc) 30 | { 31 | // Copy key and meta so srcDoc remains minimally useful, but move body 32 | _doc.key = (void*)key().copy().buf; 33 | _doc.meta = (void*)meta().copy().buf; 34 | srcDoc._doc.body = NULL; // to prevent double-free 35 | srcDoc._doc.bodylen = 0; 36 | } 37 | 38 | Document::Document(slice key) { 39 | setKey(key); 40 | } 41 | 42 | Document::~Document() { 43 | key().free(); 44 | meta().free(); 45 | body().free(); 46 | } 47 | 48 | bool Document::valid() const { 49 | return _doc.key != NULL && _doc.keylen > 0 && _doc.keylen <= kMaxKeyLength 50 | && _doc.metalen <= kMaxMetaLength && !(_doc.metalen != 0 && _doc.meta == NULL) 51 | && _doc.bodylen <= kMaxBodyLength && !(_doc.bodylen != 0 && _doc.body == NULL); 52 | } 53 | 54 | void Document::clearMetaAndBody() { 55 | setMeta(slice::null); 56 | setBody(slice::null); 57 | _doc.deleted = false; 58 | _doc.seqnum = 0; 59 | _doc.offset = 0; 60 | _doc.size_ondisk = 0; 61 | } 62 | 63 | static inline void _assign(void* &buf, size_t &size, slice s) { 64 | ::free(buf); 65 | buf = (void*)s.copy().buf; 66 | size = s.size; 67 | } 68 | 69 | void Document::setKey(slice key) {_assign(_doc.key, _doc.keylen, key);} 70 | void Document::setMeta(slice meta) {_assign(_doc.meta, _doc.metalen, meta);} 71 | void Document::setBody(slice body) {_assign(_doc.body, _doc.bodylen, body);} 72 | 73 | slice Document::resizeMeta(size_t newSize) { 74 | if (newSize != _doc.metalen) { 75 | _doc.meta = slice::reallocBytes(_doc.meta, newSize); 76 | _doc.metalen = newSize; 77 | } 78 | return meta(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /CBForest/Document.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Document.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 11/11/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #ifndef __CBForest__Document__ 17 | #define __CBForest__Document__ 18 | 19 | #include "Database.hh" 20 | 21 | namespace cbforest { 22 | 23 | class DocEnumerator; 24 | 25 | /** Stores a document's key, metadata and body as slices. Memory is owned by the object and 26 | will be freed when it destructs. Setters copy, getters don't. */ 27 | class Document { 28 | public: 29 | Document(); 30 | Document(slice key); 31 | Document(Document&&); 32 | ~Document(); 33 | 34 | slice key() const {return slice(_doc.key, _doc.keylen);} 35 | slice meta() const {return slice(_doc.meta, _doc.metalen);} 36 | slice body() const {return slice(_doc.body, _doc.bodylen);} 37 | 38 | void setKey(slice key); 39 | void setMeta(slice meta); 40 | void setBody(slice body); 41 | 42 | slice resizeMeta(size_t); 43 | 44 | void clearMetaAndBody(); 45 | 46 | cbforest::sequence sequence() const {return _doc.seqnum;} 47 | uint64_t offset() const {return _doc.offset;} 48 | size_t sizeOnDisk() const {return _doc.size_ondisk;} 49 | bool deleted() const {return _doc.deleted;} 50 | bool exists() const {return !_doc.deleted && _doc.keylen > 0 51 | && (_doc.size_ondisk > 0 || _doc.offset > 0);} 52 | bool valid() const; 53 | 54 | void updateSequence(cbforest::sequence s) {_doc.seqnum = s;} 55 | 56 | typedef DocEnumerator enumerator; 57 | 58 | static const size_t kMaxKeyLength, kMaxMetaLength, kMaxBodyLength; 59 | 60 | operator fdb_doc*() {return &_doc;} 61 | 62 | private: 63 | friend class KeyStore; 64 | friend class KeyStoreWriter; 65 | friend class Transaction; 66 | 67 | Document(const Document&) = delete; 68 | Document& operator= (const Document&) = delete; 69 | 70 | fdb_doc _doc = {}; 71 | }; 72 | 73 | } 74 | 75 | #endif /* defined(__CBForest__Document__) */ 76 | -------------------------------------------------------------------------------- /CBForest/Error.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Error.cc 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 3/4/16. 6 | // Copyright © 2016 Couchbase. All rights reserved. 7 | // 8 | 9 | #include "Error.hh" 10 | #include "LogInternal.hh" 11 | #include "forestdb.h" 12 | #include 13 | 14 | 15 | namespace cbforest { 16 | 17 | const char* error::what() const noexcept { 18 | return fdb_error_msg((fdb_status)status); 19 | } 20 | 21 | 22 | void error::_throw(fdb_status status) { 23 | WarnError("%s (%d)\n", fdb_error_msg(status), status); 24 | throw error{status}; 25 | } 26 | 27 | 28 | void error::assertionFailed(const char *fn, const char *file, unsigned line, const char *expr) { 29 | if (LogLevel > kError || LogCallback == NULL) 30 | fprintf(stderr, "Assertion failed: %s (%s:%u, in %s)", expr, file, line, fn); 31 | WarnError("Assertion failed: %s (%s:%u, in %s)", expr, file, line, fn); 32 | throw error(error::AssertionFailed); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /CBForest/Error.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Error.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 6/15/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #ifndef CBForest_Error_h 17 | #define CBForest_Error_h 18 | 19 | #include "forestdb.h" 20 | #include 21 | 22 | #undef check 23 | 24 | namespace cbforest { 25 | 26 | #ifdef _MSC_VER 27 | #define expected(EXPR, VALUE) (EXPR) 28 | #else 29 | #define expected __builtin_expect 30 | #endif 31 | 32 | /** Most API calls can throw this. */ 33 | struct error : public std::exception { 34 | // Extra status codes not defined by fdb_errors.h 35 | enum CBForestError { 36 | BadRevisionID = -1000, 37 | CorruptRevisionData = -1001, 38 | CorruptIndexData = -1002, 39 | AssertionFailed = -1003, 40 | TokenizerError = -1004, // can't create tokenizer 41 | }; 42 | 43 | /** Either an fdb_status code, as defined in fdb_errors.h; or a CBForestError. */ 44 | int const status; 45 | 46 | error (fdb_status s) :status(s) {} 47 | error (CBForestError e) :status(e) {} 48 | 49 | virtual const char *what() const noexcept; 50 | 51 | [[noreturn]] static void _throw(fdb_status); 52 | 53 | [[noreturn]] static void assertionFailed(const char *func, const char *file, unsigned line, 54 | const char *expr); 55 | }; 56 | 57 | static inline void check(fdb_status status) { 58 | if (expected(status != FDB_RESULT_SUCCESS, false)) 59 | error::_throw(status); 60 | } 61 | 62 | 63 | // Like C assert() but throws an exception instead of aborting 64 | #define CBFAssert(e) \ 65 | (expected(!(e), 0) ? cbforest::error::assertionFailed(__func__, __FILE__, __LINE__, #e) \ 66 | : (void)0) 67 | 68 | // CBFDebugAssert is removed from release builds; use when 'e' test is too expensive 69 | #ifdef NDEBUG 70 | #define CBFDebugAssert(e) do{ }while(0) 71 | #else 72 | #define CBFDebugAssert(e) CBFAssert(e) 73 | #endif 74 | 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /CBForest/FullTextIndex.hh: -------------------------------------------------------------------------------- 1 | // 2 | // FullTextIndex.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 12/30/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef FullTextIndex_hh 10 | #define FullTextIndex_hh 11 | 12 | #include "MapReduceIndex.hh" 13 | #include 14 | 15 | 16 | namespace cbforest { 17 | 18 | struct TermMatch { 19 | uint32_t termIndex; ///< Index of the search term in the tokenized query 20 | uint32_t start, length; ///< *Byte* range of word in query string 21 | 22 | bool operator < (const TermMatch &other) const {return start < other.start;} 23 | }; 24 | 25 | 26 | /** Represents a match of a full-text query. */ 27 | class FullTextMatch { 28 | public: 29 | alloc_slice docID; ///< The document ID that produced the text 30 | cbforest::sequence sequence; ///< The sequence number of the document revision 31 | std::vector textMatches; ///< The positions in the query string of the matches 32 | 33 | alloc_slice value() const; ///< The emitted value 34 | 35 | unsigned fullTextID() const {return _fullTextID;} 36 | alloc_slice matchedText() const; ///< The emitted string that was matched 37 | 38 | static alloc_slice matchedText(MapReduceIndex *index, 39 | slice docID, 40 | cbforest::sequence seq, 41 | unsigned fullTextID) { 42 | return index->readFullText(docID, seq, fullTextID); 43 | } 44 | 45 | 46 | private: 47 | FullTextMatch(const IndexEnumerator&); 48 | unsigned readTermMatches(slice indexValue, unsigned termIndex); 49 | 50 | const MapReduceIndex *_index; 51 | unsigned _fullTextID; 52 | int _lastTermIndex; 53 | float _rank {0.0}; 54 | 55 | friend class FullTextIndexEnumerator; 56 | }; 57 | 58 | 59 | /** Enumerator for full-text queries. */ 60 | class FullTextIndexEnumerator { 61 | public: 62 | FullTextIndexEnumerator(Index*, 63 | slice queryString, 64 | slice queryStringLanguage, 65 | bool ranked, 66 | const DocEnumerator::Options&); 67 | 68 | bool next(); 69 | void close() {_e.close();} 70 | const FullTextMatch *match(); 71 | 72 | const std::vector& allMatches() {return _results;} 73 | 74 | private: 75 | void search(); 76 | 77 | std::vector _tokens; 78 | IndexEnumerator _e; 79 | bool _ranked; 80 | std::vector _results; 81 | int _curResultIndex; 82 | }; 83 | 84 | } 85 | 86 | #endif /* FullTextIndex_hh */ 87 | -------------------------------------------------------------------------------- /CBForest/GeoIndex.hh: -------------------------------------------------------------------------------- 1 | // 2 | // GeoIndex.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 11/3/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #ifndef __CBForest__GeoIndex__ 17 | #define __CBForest__GeoIndex__ 18 | #include "MapReduceIndex.hh" 19 | #include "Geohash.hh" 20 | #include "KeyStore.hh" 21 | #include 22 | 23 | 24 | namespace cbforest { 25 | 26 | CollatableBuilder& operator<< (CollatableBuilder&, const geohash::area&); 27 | geohash::area readGeoArea(CollatableReader&); 28 | 29 | 30 | class GeoIndexEnumerator : public IndexEnumerator { 31 | public: 32 | GeoIndexEnumerator(Index*, geohash::area); 33 | 34 | geohash::area keyBoundingBox() const {return _keyBBox;} 35 | slice keyGeoJSON() const {return _geoKey;} 36 | 37 | #if DEBUG 38 | virtual ~GeoIndexEnumerator(); 39 | #endif 40 | 41 | protected: 42 | virtual bool approve(slice key); // override 43 | 44 | private: 45 | typedef std::pair ItemID; 46 | 47 | const geohash::area _searchArea; 48 | geohash::area _keyBBox; 49 | alloc_slice _geoKey; 50 | alloc_slice _geoValue; 51 | std::set _alreadySeen; 52 | 53 | unsigned _hits {0}, _misses {0}, _dups {0}; // Only used for test/profiling purposes 54 | }; 55 | 56 | } 57 | 58 | #endif /* defined(__CBForest__GeoIndex__) */ 59 | -------------------------------------------------------------------------------- /CBForest/KeyStore.hh: -------------------------------------------------------------------------------- 1 | // 2 | // KeyStore.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 11/12/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef __CBForest__KeyStore__ 10 | #define __CBForest__KeyStore__ 11 | 12 | #include "Error.hh" 13 | #include "forestdb.h" 14 | #include "slice.hh" 15 | 16 | namespace cbforest { 17 | 18 | class Database; 19 | class Document; 20 | class KeyStoreWriter; 21 | class Transaction; 22 | 23 | typedef fdb_seqnum_t sequence; 24 | 25 | /** Provides read-only access to a key-value store inside a Database. 26 | (Just a wrapper around a fdb_kvs_handle*.) */ 27 | class KeyStore { 28 | public: 29 | typedef fdb_kvs_info kvinfo; 30 | 31 | void enableErrorLogs(bool enable); // defaults to true 32 | 33 | kvinfo getInfo() const; 34 | sequence lastSequence() const; 35 | std::string name() const; 36 | 37 | bool isOpen() {return _handle != NULL;} 38 | 39 | // Keys/values: 40 | 41 | enum contentOptions { 42 | kDefaultContent = 0, 43 | kMetaOnly = 0x01 44 | }; 45 | 46 | Document get(slice key, contentOptions = kDefaultContent) const; 47 | Document get(sequence, contentOptions = kDefaultContent) const; 48 | bool read(Document&, contentOptions = kDefaultContent) const; // key must already be set 49 | 50 | Document getByOffset(uint64_t offset, sequence) const; 51 | Document getByOffsetNoErrors(uint64_t offset, sequence) const; // doesn't throw or log 52 | 53 | void close(); 54 | void deleteKeyStore(Transaction& t); 55 | void erase(); 56 | 57 | protected: 58 | KeyStore(fdb_kvs_handle* handle) :_handle(handle) { } 59 | fdb_kvs_handle* handle() const {return _handle;} 60 | 61 | fdb_kvs_handle* _handle; 62 | 63 | private: 64 | KeyStore(const KeyStore&) = delete; 65 | KeyStore& operator=(const KeyStore&) = delete; 66 | 67 | friend class Database; 68 | friend class DocEnumerator; 69 | friend class KeyStoreWriter; 70 | }; 71 | 72 | 73 | /** Adds write access to a KeyStore. */ 74 | class KeyStoreWriter : public KeyStore { 75 | public: 76 | KeyStoreWriter(const KeyStore &store, Transaction&) :KeyStore(store._handle) { } 77 | 78 | sequence set(slice key, slice meta, slice value); 79 | sequence set(slice key, slice value) {return set(key, slice::null, value);} 80 | void write(Document&); 81 | 82 | bool del(slice key); 83 | bool del(sequence); 84 | bool del(Document&); 85 | 86 | void rollbackTo(sequence); 87 | 88 | friend class KeyStore; 89 | 90 | KeyStoreWriter(const KeyStoreWriter& k) :KeyStore(k._handle) { } 91 | KeyStoreWriter& operator=(const KeyStoreWriter &k) {_handle = k._handle; return *this;} 92 | 93 | private: 94 | KeyStoreWriter(KeyStore& store) :KeyStore(store._handle) { } 95 | friend class Transaction; 96 | friend class Database; 97 | }; 98 | 99 | } 100 | 101 | #endif /* defined(__CBForest__KeyStore__) */ 102 | -------------------------------------------------------------------------------- /CBForest/LogInternal.hh: -------------------------------------------------------------------------------- 1 | // 2 | // LogInternal.h 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 10/13/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | 17 | #ifndef CBForest_LogInternal_h 18 | #define CBForest_LogInternal_h 19 | 20 | #include "Database.hh" 21 | 22 | namespace cbforest { 23 | 24 | void _Log(logLevel, const char *message, ...) noexcept; 25 | 26 | #ifdef _MSC_VER 27 | // Apparently vararg macro syntax is slightly different in MSVC than in Clang/GCC 28 | #define LogAt(LEVEL, MESSAGE, ...) \ 29 | if (LogLevel <= LEVEL) _Log(LEVEL, MESSAGE, __VA_ARGS__); 30 | #define Debug(MESSAGE, ...) LogAt(kDebug, MESSAGE, __VA_ARGS__) 31 | #define Log(MESSAGE, ...) LogAt(kInfo, MESSAGE, __VA_ARGS__) 32 | #define Warn(MESSAGE, ...) LogAt(kWarning, MESSAGE, __VA_ARGS__) 33 | #define WarnError(MESSAGE, ...) LogAt(kError, MESSAGE, __VA_ARGS__) 34 | #else 35 | #define LogAt(LEVEL, MESSAGE...) \ 36 | ({if (__builtin_expect(LogLevel <= LEVEL, false)) _Log(LEVEL, MESSAGE);}) 37 | #define Debug(MESSAGE...) LogAt(kDebug, MESSAGE) 38 | #define Log(MESSAGE...) LogAt(kInfo, MESSAGE) 39 | #define Warn(MESSAGE...) LogAt(kWarning, MESSAGE) 40 | #define WarnError(MESSAGE...) LogAt(kError, MESSAGE) 41 | #endif 42 | 43 | // Debug(...) is stripped out of release builds 44 | #if !DEBUG 45 | #undef Debug 46 | #ifdef _MSC_VER 47 | #define Debug(MESSAGE, ...) 48 | #else 49 | #define Debug(MESSAGE...) ({ }) 50 | #endif 51 | #endif 52 | 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /CBForest/RevID.hh: -------------------------------------------------------------------------------- 1 | // 2 | // RevID.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 6/2/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #ifndef __CBForest__RevID__ 17 | #define __CBForest__RevID__ 18 | 19 | #include "slice.hh" 20 | 21 | namespace cbforest { 22 | 23 | /** A compressed revision ID. 24 | Since this is based on slice, it doesn't own the memory it points to. */ 25 | class revid : public slice { 26 | public: 27 | revid() :slice() {} 28 | revid(const void* b, size_t s) :slice(b,s) {} 29 | explicit revid(slice s) :slice(s) {} 30 | 31 | bool isCompressed() const {return !isdigit((*this)[0]);} 32 | 33 | alloc_slice expanded() const; 34 | size_t expandedSize() const; 35 | bool expandInto(slice &dst) const; 36 | 37 | unsigned generation() const; 38 | slice digest() const; 39 | bool operator< (const revid&) const; 40 | 41 | explicit operator std::string() const; 42 | #ifdef __OBJC__ 43 | explicit operator NSString*() const; // overrides slice method 44 | #endif 45 | 46 | private: 47 | uint64_t getGenAndDigest(slice &digest) const; 48 | void _expandInto(slice &dst) const; 49 | }; 50 | 51 | /** A self-contained revid that includes its own data buffer. */ 52 | class revidBuffer : public revid { 53 | public: 54 | revidBuffer() :revid(&_buffer, 0) {} 55 | explicit revidBuffer(slice s) :revid(&_buffer, 0) {parse(s);} 56 | revidBuffer(unsigned generation, slice digest); 57 | revidBuffer(const revidBuffer&); 58 | 59 | /** Parses a regular (uncompressed) revID and compresses it. 60 | Throws BadRevisionID if the revID isn't in the proper format.*/ 61 | void parse(slice); 62 | 63 | #ifdef __OBJC__ 64 | explicit revidBuffer(NSString* str); 65 | #endif 66 | 67 | private: 68 | uint8_t _buffer[42]; 69 | }; 70 | } 71 | 72 | #endif /* defined(__CBForest__RevID__) */ 73 | -------------------------------------------------------------------------------- /CBForest/RevID.mm: -------------------------------------------------------------------------------- 1 | // 2 | // RevID.mm 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 6/14/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #import 17 | #include "RevID.hh" 18 | #include "Error.hh" 19 | 20 | namespace cbforest { 21 | 22 | revid::operator NSString*() const { 23 | char expandedBuf[256]; 24 | cbforest::slice expanded(expandedBuf, sizeof(expandedBuf)); 25 | this->expandInto(expanded); 26 | return (NSString*)expanded; 27 | } 28 | 29 | revidBuffer::revidBuffer(__unsafe_unretained NSString* str) 30 | :revid(&_buffer, 0) 31 | { 32 | parse(nsstring_slice(str)); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /CBForest/SecureDigest.hh: -------------------------------------------------------------------------------- 1 | // 2 | // SecureDigest.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 12/29/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef SecureDigest_hh 10 | #define SecureDigest_hh 11 | 12 | 13 | #if defined(_CRYPTO_CC) 14 | 15 | // iOS and Mac OS implementation based on system-level CommonCrypto library: 16 | #include 17 | #include 18 | 19 | typedef CC_MD5_CTX md5Context; 20 | 21 | static inline void md5_begin(md5Context *ctx) { 22 | CC_MD5_Init(ctx); 23 | } 24 | static inline void md5_add(md5Context *ctx, const void *bytes, size_t length) { 25 | CC_MD5_Update(ctx, bytes, (CC_LONG)length); 26 | } 27 | static inline void md5_end(md5Context *ctx, void *outDigest) { 28 | CC_MD5_Final((uint8_t*)outDigest, ctx); 29 | } 30 | 31 | 32 | typedef CC_SHA1_CTX sha1Context; 33 | 34 | static inline void sha1_begin(sha1Context *ctx) { 35 | CC_SHA1_Init(ctx); 36 | } 37 | static inline void sha1_add(sha1Context *ctx, const void *bytes, size_t length) { 38 | CC_SHA1_Update(ctx, bytes, (CC_LONG)length); 39 | } 40 | static inline void sha1_end(sha1Context *ctx, void *outDigest) { 41 | CC_SHA1_Final((uint8_t*)outDigest, ctx); 42 | } 43 | 44 | #define SECURE_DIGEST_AVAILABLE 1 45 | 46 | #elif defined(_CRYPTO_LIBTOMCRYPT) 47 | 48 | #include 49 | // TODO 50 | #define SECURE_DIGEST_AVAILABLE 0 51 | 52 | #elif defined(_CRYPTO_OPENSSL) 53 | 54 | #include 55 | #include 56 | 57 | typedef MD5_CTX md5Context; 58 | 59 | static inline void md5_begin(md5Context *ctx) { 60 | MD5_Init(ctx); 61 | } 62 | static inline void md5_add(md5Context *ctx, const void *bytes, size_t length) { 63 | MD5_Update(ctx, bytes, length); 64 | } 65 | static inline void md5_end(md5Context *ctx, void *outDigest) { 66 | MD5_Final((unsigned char*)outDigest, ctx); 67 | } 68 | 69 | 70 | typedef SHA_CTX sha1Context; 71 | 72 | static inline void sha1_begin(sha1Context *ctx) { 73 | SHA1_Init(ctx); 74 | } 75 | static inline void sha1_add(sha1Context *ctx, const void *bytes, size_t length) { 76 | SHA1_Update(ctx, bytes, length); 77 | } 78 | static inline void sha1_end(sha1Context *ctx, void *outDigest) { 79 | SHA1_Final((unsigned char *)outDigest, ctx); 80 | } 81 | 82 | #define SECURE_DIGEST_AVAILABLE 1 83 | 84 | #else 85 | 86 | #define SECURE_DIGEST_AVAILABLE 0 87 | 88 | #endif 89 | 90 | 91 | #endif /* SecureDigest_hh */ 92 | -------------------------------------------------------------------------------- /CBForest/SecureRandomize.hh: -------------------------------------------------------------------------------- 1 | // 2 | // SecureRandomize.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 12/28/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #ifndef SecureRandomize_h 10 | #define SecureRandomize_h 11 | 12 | 13 | #if defined(_CRYPTO_CC) 14 | 15 | // iOS and Mac OS implementation based on system-level CommonCrypto library: 16 | #include 17 | #include 18 | 19 | static inline void SecureRandomize(slice s) { 20 | CCRandomGenerateBytes((void*)s.buf, s.size); 21 | } 22 | 23 | #define SECURE_RANDOMIZE_AVAILABLE 1 24 | 25 | #elif defined(_CRYPTO_LIBTOMCRYPT) 26 | 27 | #include 28 | // TODO 29 | #define SECURE_RANDOMIZE_AVAILABLE 0 30 | 31 | #elif defined(_CRYPTO_OPENSSL) 32 | 33 | #include 34 | 35 | static inline void SecureRandomize(slice s) { 36 | RAND_bytes((unsigned char *)s.buf, s.size); 37 | } 38 | 39 | #define SECURE_RANDOMIZE_AVAILABLE 1 40 | 41 | #else 42 | 43 | #define SECURE_RANDOMIZE_AVAILABLE 0 44 | 45 | #endif 46 | 47 | 48 | #endif /* SecureRandomize_h */ 49 | -------------------------------------------------------------------------------- /CBForest/VersionedDocument.hh: -------------------------------------------------------------------------------- 1 | // 2 | // VersionedDocument.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 5/14/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #ifndef __CBForest__VersionedDocument__ 17 | #define __CBForest__VersionedDocument__ 18 | #include "RevTree.hh" 19 | #include "Document.hh" 20 | 21 | namespace cbforest { 22 | 23 | /** Manages storage of a serialized RevTree in a Document. */ 24 | class VersionedDocument : public RevTree { 25 | public: 26 | 27 | /** Flags that apply to the document as a whole */ 28 | typedef uint8_t Flags; 29 | enum { 30 | kDeleted = 0x01, 31 | kConflicted = 0x02, 32 | kHasAttachments = 0x04 33 | }; 34 | 35 | VersionedDocument(KeyStore&, slice docID); 36 | VersionedDocument(KeyStore&, Document&&); 37 | 38 | #ifdef __OBJC__ 39 | VersionedDocument(KeyStore&, NSString* docID); 40 | #endif 41 | 42 | /** Reads and parses the body of the document. Useful if doc was read as meta-only. */ 43 | void read(); 44 | 45 | /** Returns false if the document was loaded metadata-only. Revision accessors will fail. */ 46 | bool revsAvailable() const {return !_unknown;} 47 | 48 | slice docID() const {return _doc.key();} 49 | revid revID() const {return _revID;} 50 | Flags flags() const {return _flags;} 51 | bool isDeleted() const {return (flags() & kDeleted) != 0;} 52 | bool isConflicted() const {return (flags() & kConflicted) != 0;} 53 | bool hasAttachments() const {return (flags() & kHasAttachments) != 0;} 54 | 55 | bool exists() const {return _doc.exists();} 56 | cbforest::sequence sequence() const {return _doc.sequence();} 57 | 58 | const Document& document() const {return _doc;} 59 | 60 | slice docType() const {return _docType;} 61 | void setDocType(slice type) {_docType = type;} 62 | 63 | bool changed() const {return _changed;} 64 | void save(Transaction& transaction); 65 | 66 | /** Gets the metadata of a document without having to instantiate a VersionedDocument */ 67 | static bool readMeta(const Document&, Flags&, revid&, slice& docType); 68 | 69 | void updateMeta(); 70 | 71 | #if DEBUG 72 | std::string dump() {return RevTree::dump();} 73 | #endif 74 | protected: 75 | virtual bool isBodyOfRevisionAvailable(const Revision*, uint64_t atOffset) const; 76 | virtual alloc_slice readBodyOfRevision(const Revision*, uint64_t atOffset) const; 77 | #if DEBUG 78 | virtual void dump(std::ostream&); 79 | #endif 80 | 81 | private: 82 | void decode(); 83 | VersionedDocument(const VersionedDocument&) = delete; 84 | 85 | KeyStore& _db; 86 | Document _doc; 87 | Flags _flags; 88 | revid _revID; 89 | alloc_slice _docType; 90 | }; 91 | } 92 | 93 | #endif /* defined(__CBForest__VersionedDocument__) */ 94 | -------------------------------------------------------------------------------- /CBForest/VersionedDocument.mm: -------------------------------------------------------------------------------- 1 | // 2 | // VersionedDocument.mm 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 6/26/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #include 17 | #include "VersionedDocument.hh" 18 | 19 | namespace cbforest { 20 | 21 | VersionedDocument::VersionedDocument(KeyStore &db, NSString* docID) 22 | :_db(db), _doc(nsstring_slice(docID)) 23 | { 24 | _db.read(_doc); 25 | decode(); 26 | } 27 | 28 | const Revision* RevTree::get(NSString* revID) const { 29 | return get(revidBuffer(revID)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /CBForest/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CBForest/english_stopwords.h: -------------------------------------------------------------------------------- 1 | // 2 | // english_stopwords.h 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 5/2/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | 9 | // Word list downloaded from http://jmlr.org/papers/volume5/lewis04a/a11-smart-stop-list/english.stop 10 | // on 2 May 2014. According to http://jmlr.org/papers/volume5/lewis04a/lewis04a.pdf, this is the 11 | // list from the SMART Retrieval System, dated 1971. 12 | 13 | // More lists for multiple languages are at https://code.google.com/p/stop-words/ 14 | 15 | static const char* kEnglishStopWords = 16 | "a \ 17 | about \ 18 | actually \ 19 | after \ 20 | again \ 21 | against \ 22 | ain't \ 23 | all \ 24 | also \ 25 | although \ 26 | am \ 27 | an \ 28 | and \ 29 | any \ 30 | anyway \ 31 | anyways \ 32 | are \ 33 | aren't \ 34 | as \ 35 | at \ 36 | be \ 37 | because \ 38 | been \ 39 | before \ 40 | being \ 41 | below \ 42 | both \ 43 | but \ 44 | by \ 45 | came \ 46 | can \ 47 | can't \ 48 | cannot \ 49 | com \ 50 | come \ 51 | comes \ 52 | could \ 53 | couldn't \ 54 | did \ 55 | didn't \ 56 | do \ 57 | does \ 58 | doesn't \ 59 | doing \ 60 | don't \ 61 | down \ 62 | during \ 63 | each \ 64 | either \ 65 | else \ 66 | etc \ 67 | ever \ 68 | except \ 69 | few \ 70 | for \ 71 | from \ 72 | go \ 73 | goes \ 74 | going \ 75 | gone \ 76 | got \ 77 | gotten \ 78 | had \ 79 | hadn't \ 80 | has \ 81 | hasn't \ 82 | have \ 83 | haven't \ 84 | having \ 85 | he \ 86 | he'd \ 87 | he'll \ 88 | he's \ 89 | hello \ 90 | her \ 91 | here \ 92 | here's \ 93 | hers \ 94 | herself \ 95 | hi \ 96 | him \ 97 | himself \ 98 | his \ 99 | hopefully \ 100 | how \ 101 | how's \ 102 | however \ 103 | i \ 104 | i'd \ 105 | i'll \ 106 | i'm \ 107 | i've \ 108 | if \ 109 | in \ 110 | into \ 111 | is \ 112 | isn't \ 113 | it \ 114 | it'd \ 115 | it'll \ 116 | it's \ 117 | its \ 118 | itself \ 119 | just \ 120 | let's \ 121 | like \ 122 | liked \ 123 | might \ 124 | me \ 125 | more \ 126 | most \ 127 | much \ 128 | must \ 129 | my \ 130 | myself \ 131 | no \ 132 | nor \ 133 | not \ 134 | now \ 135 | of \ 136 | off \ 137 | oh \ 138 | ok \ 139 | okay \ 140 | on \ 141 | once \ 142 | one \ 143 | ones \ 144 | only \ 145 | onto \ 146 | or \ 147 | other \ 148 | others \ 149 | ought \ 150 | our \ 151 | ours \ 152 | ourselves \ 153 | out \ 154 | over \ 155 | own \ 156 | please \ 157 | plus \ 158 | really \ 159 | said \ 160 | same \ 161 | saw \ 162 | say \ 163 | saying \ 164 | says \ 165 | see \ 166 | seeing \ 167 | seem \ 168 | seemed \ 169 | seeming \ 170 | seems \ 171 | sees \ 172 | shall \ 173 | shan't \ 174 | she \ 175 | she'd \ 176 | she'll \ 177 | she's \ 178 | should \ 179 | shouldn't \ 180 | so \ 181 | some \ 182 | such \ 183 | sure \ 184 | than \ 185 | thank \ 186 | thanks \ 187 | thanx \ 188 | that \ 189 | that's \ 190 | the \ 191 | their \ 192 | theirs \ 193 | them \ 194 | themselves \ 195 | then \ 196 | there \ 197 | there'd \ 198 | there'll \ 199 | there's \ 200 | these \ 201 | they \ 202 | they'd \ 203 | they'll \ 204 | they're \ 205 | they've \ 206 | this \ 207 | those \ 208 | though \ 209 | through \ 210 | thus \ 211 | to \ 212 | too \ 213 | under \ 214 | until \ 215 | up \ 216 | us \ 217 | very \ 218 | was \ 219 | wasn't \ 220 | we \ 221 | we'd \ 222 | we'll \ 223 | we're \ 224 | we've \ 225 | well \ 226 | went \ 227 | were \ 228 | weren't \ 229 | what \ 230 | what's \ 231 | when \ 232 | when's \ 233 | where \ 234 | where's \ 235 | which \ 236 | while \ 237 | who \ 238 | who's \ 239 | whoever \ 240 | whom \ 241 | whose \ 242 | why \ 243 | why's \ 244 | will \ 245 | with \ 246 | won't \ 247 | would \ 248 | wouldn't \ 249 | yes \ 250 | you \ 251 | you'd \ 252 | you'll \ 253 | you're \ 254 | you've \ 255 | your \ 256 | yours \ 257 | yourself \ 258 | yourselves"; 259 | -------------------------------------------------------------------------------- /CBForest/slice.cc: -------------------------------------------------------------------------------- 1 | // 2 | // slice.cc 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 5/12/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #include "slice.hh" 17 | #include 18 | #include 19 | 20 | namespace cbforest { 21 | 22 | int slice::compare(slice b) const { 23 | // Optimized for speed 24 | if (this->size < b.size) { 25 | int ret = memcmp(this->buf, b.buf, this->size); 26 | return ret ? ret : -1; 27 | } 28 | else if (this->size > b.size) { 29 | int ret = memcmp(this->buf, b.buf, b.size); 30 | return ret ? ret : 1; 31 | } 32 | else 33 | return memcmp(this->buf, b.buf, this->size); 34 | } 35 | 36 | slice slice::read(size_t nBytes) { 37 | if (nBytes > size) 38 | return null; 39 | slice result(buf, nBytes); 40 | moveStart(nBytes); 41 | return result; 42 | } 43 | 44 | bool slice::readInto(slice dst) { 45 | if (dst.size > size) 46 | return false; 47 | ::memcpy((void*)dst.buf, buf, dst.size); 48 | moveStart(dst.size); 49 | return true; 50 | } 51 | 52 | bool slice::writeFrom(slice src) { 53 | if (src.size > size) 54 | return false; 55 | ::memcpy((void*)buf, src.buf, src.size); 56 | moveStart(src.size); 57 | return true; 58 | } 59 | 60 | slice slice::copy() const { 61 | if (buf == NULL) 62 | return *this; 63 | void* copied = newBytes(size); 64 | ::memcpy(copied, buf, size); 65 | return slice(copied, size); 66 | } 67 | 68 | void slice::free() { 69 | ::free((void*)buf); 70 | buf = NULL; 71 | size = 0; 72 | } 73 | 74 | bool slice::hasPrefix(slice s) const { 75 | return s.size > 0 && size >= s.size && ::memcmp(buf, s.buf, s.size) == 0; 76 | } 77 | 78 | slice::operator std::string() const { 79 | return std::string((const char*)buf, size); 80 | } 81 | 82 | const slice slice::null; 83 | 84 | void* alloc_slice::alloc(const void* src, size_t s) { 85 | void* buf = newBytes(s); 86 | ::memcpy((void*)buf, src, s); 87 | return buf; 88 | } 89 | 90 | alloc_slice& alloc_slice::operator=(slice s) { 91 | s = s.copy(); 92 | buf = s.buf; 93 | size = s.size; 94 | reset((char*)buf); 95 | return *this; 96 | } 97 | 98 | 99 | std::string slice::hexString() const { 100 | static const char kDigits[17] = "0123456789abcdef"; 101 | std::string result; 102 | for (size_t i = 0; i < size; i++) { 103 | uint8_t byte = (*this)[(unsigned)i]; 104 | result += kDigits[byte >> 4]; 105 | result += kDigits[byte & 0xF]; 106 | } 107 | return result; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /CBForest/slice.mm: -------------------------------------------------------------------------------- 1 | // 2 | // slice.mm 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 5/14/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #include "slice.hh" 17 | #import 18 | 19 | namespace cbforest { 20 | 21 | nsstring_slice::nsstring_slice(__unsafe_unretained NSString* str) 22 | :_needsFree(false) 23 | { 24 | if (!str) 25 | return; 26 | // First try to use a direct pointer to the bytes: 27 | auto cstr = CFStringGetCStringPtr((__bridge CFStringRef)str, kCFStringEncodingUTF8); 28 | if (cstr) { 29 | size = strlen(cstr); 30 | buf = cstr; 31 | return; 32 | } 33 | 34 | NSUInteger byteCount; 35 | if (str.length <= sizeof(_local)) { 36 | // Next try to copy the UTF-8 into a smallish stack-based buffer: 37 | NSRange remaining; 38 | BOOL ok = [str getBytes: _local maxLength: sizeof(_local) usedLength: &byteCount 39 | encoding: NSUTF8StringEncoding options: 0 40 | range: NSMakeRange(0, str.length) remainingRange: &remaining]; 41 | if (ok && remaining.length == 0) { 42 | buf = &_local; 43 | size = byteCount; 44 | return; 45 | } 46 | } 47 | 48 | // Otherwise malloc a buffer to copy the UTF-8 into: 49 | NSUInteger maxByteCount = [str maximumLengthOfBytesUsingEncoding: NSUTF8StringEncoding]; 50 | buf = newBytes(maxByteCount); 51 | _needsFree = true; 52 | BOOL ok = [str getBytes: (void*)buf maxLength: maxByteCount usedLength: &byteCount 53 | encoding: NSUTF8StringEncoding options: 0 54 | range: NSMakeRange(0, str.length) remainingRange: NULL]; 55 | if (!ok) 56 | throw "couldn't get NSString bytes"; 57 | size = byteCount; 58 | } 59 | 60 | nsstring_slice::~nsstring_slice() { 61 | if (_needsFree) 62 | ::free((void*)buf); 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /CBForest/sqlite_glue.c: -------------------------------------------------------------------------------- 1 | // 2 | // sqlite_glue.c 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 10/6/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | 12 | // Implements the couple of sqlite functions called by the tokenizer (sqlite3-unicodesn) 13 | 14 | void* sqlite3_malloc(int size) {return malloc(size);} 15 | void* sqlite3_realloc(void *ptr, int size) {return realloc(ptr, size);} 16 | void sqlite3_free(void *ptr) {free(ptr);} 17 | -------------------------------------------------------------------------------- /CBForest/varint.cc: -------------------------------------------------------------------------------- 1 | // 2 | // varint.cc 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 3/31/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #include "varint.hh" 17 | #include 18 | #include "slice.hh" 19 | 20 | 21 | namespace cbforest { 22 | 23 | size_t SizeOfVarInt(uint64_t n) { 24 | size_t size = 1; 25 | while (n >= 0x80) { 26 | size++; 27 | n >>= 7; 28 | } 29 | return size; 30 | } 31 | 32 | 33 | size_t PutUVarInt(void *buf, uint64_t n) { 34 | uint8_t* dst = (uint8_t*)buf; 35 | while (n >= 0x80) { 36 | *dst++ = (n & 0xFF) | 0x80; 37 | n >>= 7; 38 | } 39 | *dst++ = (uint8_t)n; 40 | return dst - (uint8_t*)buf; 41 | } 42 | 43 | 44 | size_t GetUVarInt(slice buf, uint64_t *n) { 45 | uint64_t result = 0; 46 | int shift = 0; 47 | for (int i = 0; i < buf.size; i++) { 48 | uint8_t byte = ((const uint8_t*)buf.buf)[i]; 49 | result |= (uint64_t)(byte & 0x7f) << shift; 50 | if (byte >= 0x80) { 51 | shift += 7; 52 | } else { 53 | if (i > 9 || (i == 9 && byte > 1)) 54 | return 0; // Numeric overflow 55 | *n = result; 56 | return i + 1; 57 | } 58 | } 59 | return 0; // buffer too short 60 | } 61 | 62 | 63 | bool ReadUVarInt(slice *buf, uint64_t *n) { 64 | if (buf->size == 0) 65 | return false; 66 | size_t bytesRead = GetUVarInt(*buf, n); 67 | if (bytesRead == 0) 68 | return false; 69 | buf->moveStart(bytesRead); 70 | return true; 71 | } 72 | 73 | 74 | bool WriteUVarInt(slice *buf, uint64_t n) { 75 | if (buf->size < kMaxVarintLen64 && buf->size < SizeOfVarInt(n)) 76 | return false; 77 | size_t bytesWritten = PutUVarInt((void*)buf->buf, n); 78 | buf->moveStart(bytesWritten); 79 | return true; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /CBForest/varint.hh: -------------------------------------------------------------------------------- 1 | // 2 | // varint.hh 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 3/31/14. 6 | // Copyright (c) 2014 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #ifndef CBForest_varint_hh 17 | #define CBForest_varint_hh 18 | 19 | #include 20 | #include "slice.hh" 21 | 22 | namespace cbforest { 23 | 24 | // Based on varint implementation from the Go language (src/pkg/encoding/binary/varint.go) 25 | // This file implements "varint" encoding of 64-bit integers. 26 | // The encoding is: 27 | // - unsigned integers are serialized 7 bits at a time, starting with the 28 | // least significant bits 29 | // - the most significant bit (msb) in each output byte indicates if there 30 | // is a continuation byte (msb = 1) 31 | 32 | 33 | /** MaxVarintLenN is the maximum length of a varint-encoded N-bit integer. */ 34 | enum { 35 | kMaxVarintLen16 = 3, 36 | kMaxVarintLen32 = 5, 37 | kMaxVarintLen64 = 10, 38 | }; 39 | 40 | /** Returns the number of bytes needed to encode a specific integer. */ 41 | size_t SizeOfVarInt(uint64_t n); 42 | 43 | /** Encodes n as a varint, writing it to buf. Returns the number of bytes written. */ 44 | size_t PutUVarInt(void *buf, uint64_t n); 45 | 46 | /** Decodes a varint from the bytes in buf, storing it into *n. 47 | Returns the number of bytes read, or 0 if the data is invalid (buffer too short or number 48 | too long.) */ 49 | size_t GetUVarInt(slice buf, uint64_t *n); 50 | 51 | /** Decodes a varint from buf, and advances buf to the remaining space after it. 52 | Returns false if the end of the buffer is reached or there is a parse error. */ 53 | bool ReadUVarInt(slice *buf, uint64_t *n); 54 | 55 | /** Encodes a varint into buf, and advances buf to the remaining space after it. 56 | Returns false if there isn't enough room. */ 57 | bool WriteUVarInt(slice *buf, uint64_t n); 58 | 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /CSharp/NativeBuild/build-interop-ios-fat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | OUTPUT_DIR="`pwd`/../prebuilt" 6 | 7 | rm -f $OUTPUT_DIR/libCBForest-Interop.a 8 | 9 | pushd ../../ 10 | rm -rf build 11 | xcodebuild -scheme "CBForest static" -configuration Release -derivedDataPath build -sdk iphoneos 12 | xcodebuild -scheme "CBForest static" -configuration Release -derivedDataPath build -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' 13 | 14 | lipo -create -output $OUTPUT_DIR/libCBForest-Interop.a build/Build/Products/Release-iphoneos/libCBForest.a build/Build/Products/Release-iphonesimulator/libCBForest.a 15 | 16 | rm -rf build 17 | popd 18 | -------------------------------------------------------------------------------- /CSharp/NativeBuild/build-interop-osx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | OUTPUT_DIR="`pwd`/../prebuilt" 6 | 7 | rm -f $OUTPUT_DIR/libCBForest-Interop.dylib 8 | pushd ../../ 9 | rm -rf build 10 | xcodebuild ARCHS="i386 x86_64" -scheme "CBForest-Interop" -configuration Release -derivedDataPath build clean build 11 | 12 | mv build/Build/Products/Release/libCBForest-Interop.dylib $OUTPUT_DIR/libCBForest-Interop.dylib 13 | 14 | rm -rf build 15 | popd 16 | -------------------------------------------------------------------------------- /CSharp/NativeBuild/gen_linux_symbol_list.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "-s" > stripopts 4 | while read line; do 5 | if [[ "$line" != "" && "${line:0:1}" != "#" ]]; then 6 | echo "-K ${line:1}" >> stripopts 7 | fi 8 | done < ../../C/c4.exp 9 | 10 | echo "libCBForest-Interop.so" >> stripopts 11 | -------------------------------------------------------------------------------- /CSharp/NativeBuild/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi armeabi-v7a x86 arm64-v8a x86_64 #mips64 2 | APP_PLATFORM := android-19 3 | NDK_TOOLCHAIN_VERSION := clang 4 | APP_STL := gnustl_static 5 | #APP_OPTIM := release 6 | -------------------------------------------------------------------------------- /CSharp/README.md: -------------------------------------------------------------------------------- 1 | ###CBForest for CSharp 2 | ----- 3 | CBForest for CSharp can target Windows, OS X and Linux via Mono, and iOS and Android via Xamarin. There is a "prebuilt" folder in this directory where the native binaries for each platform need to go. These binaries are likely to change often so they will not be committed into the repo, but rather put out for each release. Do not assume that releases are binary compatible, as we make no such guarantee at this time. The only guarantee is that commits made affecting the C# portion will be compatible with the binaries generated at that commit. If you need to make a build not based off of a release, these are the instructions: 4 | 5 | ####Windows (only 64-bit will be released, but 32-bit should build and work identically) 6 | There is a visual studio project located [here](../CBForest.VS2015/). Copy the output files x86/CBForest-Interop.dll and x64/CBForest-Interop.dll to the prebuilt folder (maintaining the folder structure). 7 | 8 | ####OS X (64-bit and 32-bit fat binary) 9 | Simply run the `build-interop-osx.sh` script (you must have XCode installed). 10 | 11 | ####Linux (See note on Windows) 12 | The build process uses GNU make. In [this directory](NativeBuild/) simply run `make` to build and `make install` to copy the result to the correct location. 13 | 14 | ####iOS (armv7 arm64 fat binary) 15 | You can run the `build-interop-ios-fat.sh` to get a fat binary for simulator and device, or use the Xcode project directly to get a slimmer version (device OR simulator) 16 | 17 | ####Android (arm64-v8a armveabi-v7a x86 x86_64 mips64 [five files]) 18 | This requires the Android NDK. At the time of writing the version being used is r10, though if a new one comes out I'll upgrade it and keep doing so unless issues arise. The Android build process can be run concurrently. A good number is one job per logical core (this may be different from the amount of physical cores. My machine has an Intel Core i7, which has 4 physical cores but 8 logical ones). The command for running from the [NativeBuild directory](NativeBuild/) of this repo is `ndk-build -j 8 -C jni` where the number after `-j` is the number previously discussed. Copy the output of the libs folder to the prebuilt folder (i.e. the four folders with architecture names). 19 | 20 | Note: On Windows there is a nasty issue regarding file path lengths when building for Android. If you have even a moderately long path to the Android project, the ndk-build will fail because the maximum file path length on Windows will be exceeded (260). To workaround this, you can mount the project folder as a drive letter and build from there, or simply build from somewhere without a long path (i.e. C:/Project). 21 | 22 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | using Android.App; 4 | using Android.OS; 5 | using Xamarin.Android.NUnitLite; 6 | 7 | namespace cbforestsharptests.Droid 8 | { 9 | [Activity(Label = "cbforest-sharp-tests.Droid", MainLauncher = true)] 10 | public class MainActivity : TestSuiteActivity 11 | { 12 | protected override void OnCreate(Bundle bundle) 13 | { 14 | // tests can be inside the main assembly 15 | AddTest(Assembly.GetExecutingAssembly()); 16 | // or in any reference assemblies 17 | // AddTest (typeof (Your.Library.TestClass).Assembly); 18 | 19 | // Once you called base.OnCreate(), you cannot add more assemblies. 20 | base.OnCreate(bundle); 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using Android.App; 4 | 5 | // Information about this assembly is defined by the following attributes. 6 | // Change them to the values specific to your project. 7 | 8 | [assembly: AssemblyTitle("cbforest-sharp-tests.Droid")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Couchbase, Inc")] 12 | [assembly: AssemblyProduct("")] 13 | [assembly: AssemblyCopyright("Couchbase, Inc")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 18 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 19 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 20 | 21 | [assembly: AssemblyVersion("1.0.0")] 22 | 23 | // The following attributes are used to specify the signing key for the assembly, 24 | // if desired. See the Mono documentation for more information about signing. 25 | 26 | //[assembly: AssemblyDelaySign(false)] 27 | //[assembly: AssemblyKeyFile("")] 28 | 29 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.axml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.axml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.axml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. 45 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-hdpi/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-hdpi/Icon.png -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-mdpi/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-mdpi/Icon.png -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-xhdpi/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-xhdpi/Icon.png -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-xxhdpi/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-xxhdpi/Icon.png -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-xxxhdpi/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/Tests/cbforest-sharp-tests.Droid/Resources/drawable-xxxhdpi/Icon.png -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Net45/cbforest-sharp-tests.Net45.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {E1929D98-BF32-47E4-8E1E-897782DAED1F} 7 | Library 8 | cbforestsharptests.Net45 9 | cbforest-sharp-tests.Net45 10 | v4.5 11 | 12 | 13 | true 14 | full 15 | false 16 | bin\Debug 17 | DEBUG; 18 | prompt 19 | 4 20 | false 21 | true 22 | 5 23 | 24 | 25 | full 26 | true 27 | bin\Release 28 | prompt 29 | 4 30 | false 31 | true 32 | 5 33 | 34 | 35 | 36 | 37 | ..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | {20839831-948C-42BA-AAF1-75081209E6C5} 45 | cbforest-sharp.Net45 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Net45/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Shared/C4KeyTest.cs: -------------------------------------------------------------------------------- 1 | // 2 | // C4KeyTest.cs 3 | // 4 | // Author: 5 | // Jim Borden 6 | // 7 | // Copyright (c) 2015 Couchbase, Inc All rights reserved. 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | using System; 22 | using NUnit.Framework; 23 | 24 | namespace CBForest.Tests 25 | { 26 | [TestFixture] 27 | public unsafe class C4KeyTest : C4Test 28 | { 29 | private C4Key *_key; 30 | 31 | public override void SetUp() 32 | { 33 | _key = Native.c4key_new(); 34 | } 35 | 36 | public override void TearDown() 37 | { 38 | Native.c4key_free(_key); 39 | } 40 | 41 | [Test] 42 | public void TestCreateKey() 43 | { 44 | PopulateKey(); 45 | Assert.AreEqual("[null,false,true,0,12345,-2468,\"foo\",[]]", ToJSON(_key)); 46 | } 47 | 48 | [Test] 49 | public void TestReadKey() 50 | { 51 | PopulateKey(); 52 | var r = Native.c4key_read(_key); 53 | Assert.AreEqual(C4KeyToken.Array, Native.c4key_peek(&r)); 54 | Native.c4key_skipToken(&r); 55 | Assert.AreEqual(C4KeyToken.Null, Native.c4key_peek(&r)); 56 | Native.c4key_skipToken(&r); 57 | Assert.AreEqual(C4KeyToken.Bool, Native.c4key_peek(&r)); 58 | Assert.IsFalse(Native.c4key_readBool(&r)); 59 | Assert.IsTrue(Native.c4key_readBool(&r)); 60 | Assert.AreEqual(0.0, Native.c4key_readNumber(&r)); 61 | Assert.AreEqual(12345.0, Native.c4key_readNumber(&r)); 62 | Assert.AreEqual(-2468.0, Native.c4key_readNumber(&r)); 63 | Assert.AreEqual("foo", Native.c4key_readString(&r)); 64 | Assert.AreEqual(C4KeyToken.Array, Native.c4key_peek(&r)); 65 | Native.c4key_skipToken(&r); 66 | Assert.AreEqual(C4KeyToken.EndSequence, Native.c4key_peek(&r)); 67 | Native.c4key_skipToken(&r); 68 | Assert.AreEqual(C4KeyToken.EndSequence, Native.c4key_peek(&r)); 69 | Native.c4key_skipToken(&r); 70 | } 71 | 72 | private void PopulateKey() 73 | { 74 | Native.c4key_beginArray(_key); 75 | Native.c4key_addNull(_key); 76 | Native.c4key_addBool(_key, false); 77 | Native.c4key_addBool(_key, true); 78 | Native.c4key_addNumber(_key, 0); 79 | Native.c4key_addNumber(_key, 12345); 80 | Native.c4key_addNumber(_key, -2468); 81 | Native.c4key_addString(_key, "foo"); 82 | Native.c4key_beginArray(_key); 83 | Native.c4key_endArray(_key); 84 | Native.c4key_endArray(_key); 85 | } 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Shared/C4Test.cs: -------------------------------------------------------------------------------- 1 | // 2 | // C4Test.cs 3 | // 4 | // Author: 5 | // Jim Borden 6 | // 7 | // Copyright (c) 2015 Couchbase, Inc All rights reserved. 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | using System; 22 | using NUnit.Framework; 23 | using System.IO; 24 | 25 | 26 | namespace CBForest.Tests 27 | { 28 | public unsafe abstract class C4Test 29 | { 30 | protected const string BODY = "{\"name\":007}"; 31 | protected const string DOC_ID = "mydoc"; 32 | protected const string REV_ID = "1-abcdef"; 33 | protected const string REV_2_ID = "2-d00d3333"; 34 | 35 | protected virtual C4EncryptionKey* EncryptionKey 36 | { 37 | get { 38 | return null; 39 | } 40 | } 41 | 42 | protected C4Database *_db; 43 | 44 | [SetUp] 45 | public virtual void SetUp() 46 | { 47 | Native.c4log_register(C4LogLevel.Warning, Log); 48 | Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)); 49 | var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "forest_temp.fdb"); 50 | C4Error error; 51 | _db = Native.c4db_open(dbPath, C4DatabaseFlags.Create, EncryptionKey, &error); 52 | Assert.IsFalse(_db == null); 53 | } 54 | 55 | [TearDown] 56 | public virtual void TearDown() 57 | { 58 | C4Error error; 59 | Native.c4db_delete(_db, &error); 60 | } 61 | 62 | public string ToJSON(C4KeyReader r) 63 | { 64 | return Native.c4key_toJSON(&r); 65 | } 66 | 67 | public string ToJSON(C4Key *key) 68 | { 69 | return ToJSON(Native.c4key_read(key)); 70 | } 71 | 72 | protected void CreateRev(string docID, string revID, string body, bool isNew = true) 73 | { 74 | using(var t = new TransactionHelper(_db)) { 75 | C4Error error; 76 | var doc = Native.c4doc_get(_db, docID, false, &error); 77 | Assert.IsTrue(doc != null); 78 | var deleted = body == null; 79 | Assert.AreEqual(isNew ? 1 : 0, Native.c4doc_insertRevision(doc, revID, body, deleted, false, false, &error)); 80 | Assert.IsTrue(Native.c4doc_save(doc, 20, &error)); 81 | Native.c4doc_free(doc); 82 | } 83 | } 84 | 85 | private static void Log(C4LogLevel level, string message) 86 | { 87 | string[] levelNames = new[] { "debug", "info", "WARNING", "ERROR" }; 88 | Console.Error.WriteLineAsync(String.Format("CBForest-C {0}: {1}", levelNames[(int)level], message)); 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Shared/cbforest-sharp-tests.Shared.projitems: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {3EBFD1C4-63AB-4598-B15A-B2C28BAB5E9A} 7 | 8 | 9 | CBForest.Tests 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.Shared/cbforest-sharp-tests.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {3EBFD1C4-63AB-4598-B15A-B2C28BAB5E9A} 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.iOS/Info.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | CFBundleDisplayName 6 | C4Tests 7 | CFBundleIdentifier 8 | com.couchbase.cbforest-sharp-tests 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 6.0 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.iOS/Main.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Main.cs 3 | // 4 | // Author: 5 | // Jim Borden 6 | // 7 | // Copyright (c) 2015 Couchbase, Inc All rights reserved. 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | using System; 22 | using System.Linq; 23 | using System.Collections.Generic; 24 | 25 | using Foundation; 26 | using UIKit; 27 | 28 | namespace cbforestsharptests.iOS 29 | { 30 | public class Application 31 | { 32 | // This is the main entry point of the application. 33 | static void Main(string[] args) 34 | { 35 | // if you want to use a different Application Delegate class from "UnitTestAppDelegate" 36 | // you can specify it here. 37 | UIApplication.Main(args, null, "UnitTestAppDelegate"); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CSharp/Tests/cbforest-sharp-tests.iOS/UnitTestAppDelegate.cs: -------------------------------------------------------------------------------- 1 | // 2 | // UnitTestAppDelegate.cs 3 | // 4 | // Author: 5 | // Jim Borden 6 | // 7 | // Copyright (c) 2015 Couchbase, Inc All rights reserved. 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | using System; 22 | using System.Linq; 23 | using System.Collections.Generic; 24 | 25 | using Foundation; 26 | using UIKit; 27 | using MonoTouch.NUnit.UI; 28 | 29 | namespace cbforestsharptests.iOS 30 | { 31 | // The UIApplicationDelegate for the application. This class is responsible for launching the 32 | // User Interface of the application, as well as listening (and optionally responding) to 33 | // application events from iOS. 34 | [Register("UnitTestAppDelegate")] 35 | public partial class UnitTestAppDelegate : UIApplicationDelegate 36 | { 37 | // class-level declarations 38 | UIWindow window; 39 | TouchRunner runner; 40 | 41 | // 42 | // This method is invoked when the application has loaded and is ready to run. In this 43 | // method you should instantiate the window, load the UI into it and then make the window 44 | // visible. 45 | // 46 | // You have 17 seconds to return from this method, or iOS will terminate your application. 47 | // 48 | public override bool FinishedLaunching(UIApplication app, NSDictionary options) 49 | { 50 | // create a new window instance based on the screen size 51 | window = new UIWindow(UIScreen.MainScreen.Bounds); 52 | runner = new TouchRunner(window); 53 | 54 | // register every tests included in the main application/assembly 55 | runner.Add(System.Reflection.Assembly.GetExecutingAssembly()); 56 | 57 | window.RootViewController = new UINavigationController(runner.GetViewController()); 58 | 59 | // make the window visible 60 | window.MakeKeyAndVisible(); 61 | 62 | return true; 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Droid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.axml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.axml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.axml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. 45 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Droid/Resources/Resource.designer.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable 1591 2 | // ------------------------------------------------------------------------------ 3 | // 4 | // This code was generated by a tool. 5 | // Mono Runtime Version: 4.0.30319.17020 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | 12 | [assembly: Android.Runtime.ResourceDesignerAttribute("cbforestsharp.Droid.Resource", IsApplication=false)] 13 | 14 | namespace cbforestsharp.Droid 15 | { 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] 19 | public partial class Resource 20 | { 21 | 22 | static Resource() 23 | { 24 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 25 | } 26 | 27 | public partial class Attribute 28 | { 29 | 30 | static Attribute() 31 | { 32 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 33 | } 34 | 35 | private Attribute() 36 | { 37 | } 38 | } 39 | 40 | public partial class String 41 | { 42 | 43 | // aapt resource value: 0x7f020000 44 | public static int library_name = 2130837504; 45 | 46 | static String() 47 | { 48 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 49 | } 50 | 51 | private String() 52 | { 53 | } 54 | } 55 | } 56 | } 57 | #pragma warning restore 1591 58 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Droid/Resources/values/Strings.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | cbforest-sharp.Droid 4 | 5 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Droid/cbforest-sharp.dll.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Net35/Extensions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Extensions.cs 3 | // 4 | // Author: 5 | // Jim Borden 6 | // 7 | // Copyright (c) 2015 Couchbase, Inc All rights reserved. 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | using System; 22 | 23 | namespace CBForest.Extensions 24 | { 25 | internal static class Extensions 26 | { 27 | public static bool HasFlag(this Enum e, Enum value) 28 | { 29 | if (e == null) 30 | return false; 31 | 32 | if (value == null) 33 | throw new ArgumentNullException("value"); 34 | 35 | // Not as good as the .NET 4 version of this function, but should be good enough 36 | if (!Enum.IsDefined(e.GetType(), value)) 37 | { 38 | throw new ArgumentException(string.Format( 39 | "Enumeration type mismatch. The flag is of type '{0}', was expecting '{1}'.", 40 | value.GetType(), e.GetType())); 41 | } 42 | 43 | ulong num = Convert.ToUInt64(value); 44 | return ((Convert.ToUInt64(e) & num) == num); 45 | 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Net35/Makefile: -------------------------------------------------------------------------------- 1 | debug: 2 | xbuild cbforest-sharp.Net35.csproj 3 | 4 | release: 5 | xbuild /p:Configuration=Release cbforest-sharp.Net35.csproj 6 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Shared/CBForestException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // CBForestException.cs 3 | // 4 | // Author: 5 | // Jim Borden 6 | // 7 | // Copyright (c) 2015 Couchbase, Inc All rights reserved. 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | using System; 22 | 23 | namespace CBForest 24 | { 25 | /// 26 | /// An exception representing an error status from the native 27 | /// CBForest module 28 | /// 29 | public sealed class CBForestException : ApplicationException 30 | { 31 | 32 | #region Variables 33 | 34 | /// 35 | /// The error that caused the exception 36 | /// 37 | public readonly C4Error Error; 38 | 39 | #endregion 40 | 41 | #region Properties 42 | 43 | /// 44 | /// Gets the error code received from CBForest 45 | /// 46 | public int Code 47 | { 48 | get { 49 | return Error.code; 50 | } 51 | } 52 | 53 | /// 54 | /// Gets the domain of the error code received from CBForest 55 | /// 56 | /// The domain. 57 | public C4ErrorDomain Domain 58 | { 59 | get { 60 | return Error.domain; 61 | } 62 | } 63 | 64 | #endregion 65 | 66 | #region Constructors 67 | 68 | /// 69 | /// Constructor 70 | /// 71 | /// The code of the error that is the source of the exception. 72 | /// The domain of the error that is the source of the exception. 73 | public CBForestException(int code, C4ErrorDomain domain) 74 | : this(new C4Error { code = code, domain = domain }) 75 | { 76 | } 77 | 78 | /// 79 | /// Constructor 80 | /// 81 | /// The error that is the source of the exception. 82 | public CBForestException(C4Error error) 83 | : base(String.Format("{0} (Code: {1})", Native.c4error_getMessage(error), error)) 84 | { 85 | Error = error; 86 | } 87 | 88 | #endregion 89 | 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Shared/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // AssemblyInfo.cs 3 | // 4 | // Author: 5 | // Jim Borden 6 | // 7 | // Copyright (c) 2015 Couchbase, Inc All rights reserved. 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | // 21 | #if !CUSTOM_ASSEMBLY_INFO 22 | using System.Reflection; 23 | using System.Runtime.CompilerServices; 24 | 25 | // Information about this assembly is defined by the following attributes. 26 | // Change them to the values specific to your project. 27 | 28 | [assembly: AssemblyTitle("cbforest-sharp")] 29 | [assembly: AssemblyDescription("C# bindings into the CBForest project (Couchbase Logic on top of ForestDB)")] 30 | [assembly: AssemblyCompany("Couchbase, Inc")] 31 | [assembly: AssemblyCopyright("Couchbase, Inc")] 32 | 33 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 34 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 35 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 36 | 37 | [assembly: AssemblyVersion("1.0.0.0")] 38 | 39 | // The following attributes are used to specify the signing key for the assembly, 40 | // if desired. See the Mono documentation for more information about signing. 41 | 42 | //[assembly: AssemblyDelaySign(false)] 43 | //[assembly: AssemblyKeyFile("")] 44 | #endif 45 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Shared/cbforest-sharp.Shared.projitems: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {0BFC8B40-0659-4D45-B111-7CB4CCD22991} 7 | 8 | 9 | cbforest-sharp.Shared 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.Shared/cbforest-sharp.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {0BFC8B40-0659-4D45-B111-7CB4CCD22991} 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CSharp/cbforest-sharp.iOS/cbforest-sharp.iOS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 7 | {A5757777-CDFE-43BF-8260-D342BF83B773} 8 | Library 9 | CBForest.iOS 10 | Resources 11 | cbforest-sharp 12 | 8.0.30703 13 | 2.0 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug 20 | DEBUG;__IOS__; 21 | prompt 22 | 4 23 | false 24 | true 25 | 5 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release 31 | prompt 32 | 4 33 | false 34 | true 35 | __IOS__; 36 | true 37 | 5 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | libCBForest-Interop.a 53 | 54 | 55 | -------------------------------------------------------------------------------- /CSharp/packages/NUnit.2.6.4/NUnit.2.6.4.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/packages/NUnit.2.6.4/NUnit.2.6.4.nupkg -------------------------------------------------------------------------------- /CSharp/packages/NUnit.2.6.4/lib/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/packages/NUnit.2.6.4/lib/nunit.framework.dll -------------------------------------------------------------------------------- /CSharp/packages/NUnit.2.6.4/license.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbaselabs/cbforest/111629a9f96252c58629c95c53ed8e0f01b11500/CSharp/packages/NUnit.2.6.4/license.txt -------------------------------------------------------------------------------- /CSharp/packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /CSharp/prebuilt/README.txt: -------------------------------------------------------------------------------- 1 | Put CBForest native binaries in this directory 2 | You can find precompiled ones at https://github.com/couchbaselabs/cbforest/releases -------------------------------------------------------------------------------- /CppTests/CppTests/CppTests.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | -------------------------------------------------------------------------------- /CppTests/CppTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /CppTests/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // CppTests 4 | // 5 | // Created by Jens Alfke on 9/14/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | 12 | using namespace CppUnit; 13 | 14 | int main( int argc, char **argv) { 15 | TextTestRunner runner; 16 | TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry(); 17 | runner.addTest( registry.makeTest() ); 18 | return runner.run( "", false ) ? 0 : -1; 19 | } 20 | -------------------------------------------------------------------------------- /Java/CBForestJNI.exp: -------------------------------------------------------------------------------- 1 | # CBForestJNI.exp 2 | # CBForest 3 | # 4 | # Created by Jens Alfke on 9/14/15. 5 | # Copyright © 2015 Couchbase. All rights reserved. 6 | 7 | _JNI_OnLoad 8 | 9 | _Java_com_couchbase_cbforest_Database__1open 10 | _Java_com_couchbase_cbforest_Database_beginTransaction 11 | _Java_com_couchbase_cbforest_Database_endTransaction 12 | _Java_com_couchbase_cbforest_Database_free 13 | _Java_com_couchbase_cbforest_Database_getDocumentCount 14 | _Java_com_couchbase_cbforest_Database_getLastSequence 15 | _Java_com_couchbase_cbforest_Database_isInTransaction 16 | 17 | _Java_com_couchbase_cbforest_DocumentIterator_free 18 | _Java_com_couchbase_cbforest_DocumentIterator_next 19 | _Java_com_couchbase_cbforest_DocumentIterator_getDocumentHandle 20 | _Java_com_couchbase_cbforest_DocumentIterator_getDocumentInfo 21 | 22 | _Java_com_couchbase_cbforest_Document_free 23 | _Java_com_couchbase_cbforest_Document_getType 24 | _Java_com_couchbase_cbforest_Document_init 25 | _Java_com_couchbase_cbforest_Document_initWithDocHandle 26 | _Java_com_couchbase_cbforest_Document_insertRevision 27 | _Java_com_couchbase_cbforest_Document_insertRevisionWithHistory 28 | _Java_com_couchbase_cbforest_Document_readSelectedBody 29 | _Java_com_couchbase_cbforest_Document_save 30 | _Java_com_couchbase_cbforest_Document_selectCurrentRev 31 | _Java_com_couchbase_cbforest_Document_selectNextLeaf 32 | _Java_com_couchbase_cbforest_Document_selectNextRev 33 | _Java_com_couchbase_cbforest_Document_selectParentRev 34 | _Java_com_couchbase_cbforest_Document_selectRevID 35 | _Java_com_couchbase_cbforest_Document_setType 36 | 37 | _Java_com_couchbase_cbforest_View_close 38 | _Java_com_couchbase_cbforest_View_eraseIndex 39 | _Java_com_couchbase_cbforest_View_delete 40 | _Java_com_couchbase_cbforest_View_getTotalRows 41 | _Java_com_couchbase_cbforest_View_getLastSequenceIndexed 42 | _Java_com_couchbase_cbforest_View_getLastSequenceChangedAt 43 | _Java_com_couchbase_cbforest_View_newKey 44 | _Java_com_couchbase_cbforest_View_newFullTextKey 45 | _Java_com_couchbase_cbforest_View_newGeoKey 46 | _Java_com_couchbase_cbforest_View_freeKey 47 | _Java_com_couchbase_cbforest_View_keyAddNull 48 | _Java_com_couchbase_cbforest_View_keyAdd__JZ 49 | _Java_com_couchbase_cbforest_View_keyAdd__JD 50 | _Java_com_couchbase_cbforest_View_keyAdd__JLjava_lang_String_2 51 | _Java_com_couchbase_cbforest_View_keyBeginArray 52 | _Java_com_couchbase_cbforest_View_keyEndArray 53 | _Java_com_couchbase_cbforest_View_keyBeginMap 54 | _Java_com_couchbase_cbforest_View_keyEndMap 55 | _Java_com_couchbase_cbforest_View_query__JJJZZZJJLjava_lang_String_2Ljava_lang_String_2 56 | _Java_com_couchbase_cbforest_View_query__JJJZZZ_3J 57 | _Java_com_couchbase_cbforest_View_query__JLjava_lang_String_2Ljava_lang_String_2Z 58 | _Java_com_couchbase_cbforest_View_query__JDDDD 59 | _Java_com_couchbase_cbforest_View__1open 60 | 61 | _Java_com_couchbase_cbforest_QueryIterator_next 62 | _Java_com_couchbase_cbforest_QueryIterator_keyJSON 63 | _Java_com_couchbase_cbforest_QueryIterator_valueJSON 64 | _Java_com_couchbase_cbforest_QueryIterator_docID 65 | _Java_com_couchbase_cbforest_QueryIterator_fullTextID 66 | _Java_com_couchbase_cbforest_QueryIterator_fullTextTerms 67 | _Java_com_couchbase_cbforest_QueryIterator_geoBoundingBox 68 | _Java_com_couchbase_cbforest_QueryIterator_geoJSON 69 | _Java_com_couchbase_cbforest_QueryIterator_free 70 | 71 | _Java_com_couchbase_cbforest_View_00024TextKey_setDefaultLanguageCode 72 | 73 | _Java_com_couchbase_cbforest_FullTextResult_getFullText 74 | -------------------------------------------------------------------------------- /Java/jni.h: -------------------------------------------------------------------------------- 1 | // This header just works around the problem that, on OS X, the "#include " emitted by javah 2 | // doesn't work, because jni.h is in the JavaVM framework. 3 | #include 4 | -------------------------------------------------------------------------------- /Java/jni/native_indexer.cc: -------------------------------------------------------------------------------- 1 | // 2 | // native_indexer.cc 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 12/18/15. 6 | // Copyright © 2015 Couchbase. All rights reserved. 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 9 | // except in compliance with the License. You may obtain a copy of the License at 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // Unless required by applicable law or agreed to in writing, software distributed under the 12 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 | // either express or implied. See the License for the specific language governing permissions 14 | // and limitations under the License. 15 | 16 | #include "com_couchbase_cbforest_Indexer.h" 17 | #include "native_glue.hh" 18 | #include "c4View.h" 19 | #include 20 | #include 21 | 22 | 23 | using namespace cbforest::jni; 24 | 25 | 26 | JNIEXPORT jlong JNICALL Java_com_couchbase_cbforest_Indexer_beginIndex 27 | (JNIEnv *env, jclass clazz, jlong dbHandle, jlongArray viewHandles) 28 | { 29 | auto c4views = handlesToVector(env, viewHandles); 30 | C4Error error; 31 | C4Indexer* indexer = c4indexer_begin((C4Database*)dbHandle, c4views.data(), c4views.size(), &error); 32 | if (!indexer) 33 | throwError(env, error); 34 | return (jlong)indexer; 35 | } 36 | 37 | 38 | JNIEXPORT void JNICALL Java_com_couchbase_cbforest_Indexer_triggerOnView 39 | (JNIEnv *env, jclass clazz, jlong indexerHandle, jlong viewHandle) 40 | { 41 | auto indexer = (C4Indexer*)indexerHandle; 42 | auto view = (C4View*)viewHandle; 43 | c4indexer_triggerOnView(indexer, view); 44 | } 45 | 46 | 47 | JNIEXPORT jlong JNICALL Java_com_couchbase_cbforest_Indexer_iterateDocuments 48 | (JNIEnv *env, jclass clazz, jlong indexerHandle) 49 | { 50 | C4Error error; 51 | C4DocEnumerator* e = c4indexer_enumerateDocuments((C4Indexer*)indexerHandle, &error); 52 | if(!e && error.code != 0) 53 | throwError(env, error); 54 | return (jlong)e; 55 | } 56 | 57 | 58 | JNIEXPORT jboolean JNICALL Java_com_couchbase_cbforest_Indexer_shouldIndex 59 | (JNIEnv *env, jclass clazz, jlong indexerHandle, jlong docHandle, jint viewNumber) 60 | { 61 | auto indexer = (C4Indexer*)indexerHandle; 62 | auto doc = (C4Document*)docHandle; 63 | return c4indexer_shouldIndexDocument(indexer, viewNumber, doc); 64 | } 65 | 66 | 67 | JNIEXPORT void JNICALL Java_com_couchbase_cbforest_Indexer_emit 68 | (JNIEnv *env, jclass clazz, 69 | jlong indexerHandle, jlong documentHandler, jint viewNumber, jlongArray jkeys, jobjectArray jvalues) 70 | { 71 | auto c4keys = handlesToVector(env, jkeys); 72 | C4KeyValueList* kv = c4kv_new(); 73 | int i = 0; 74 | for (auto key = c4keys.begin(); key != c4keys.end(); ++key, ++i) { 75 | jbyteArray jvalue = (jbyteArray) env->GetObjectArrayElement(jvalues, i); 76 | jbyteArraySlice value(env, jvalue); 77 | c4kv_add(kv, *key, value); 78 | c4key_free(*key); 79 | } 80 | 81 | C4Indexer* indexer = (C4Indexer*)indexerHandle; 82 | C4Document* doc = (C4Document*)documentHandler; 83 | C4Error error; 84 | if (!c4indexer_emitList(indexer, doc, viewNumber, kv, &error)) 85 | throwError(env, error); 86 | 87 | c4kv_free(kv); 88 | } 89 | 90 | 91 | JNIEXPORT void JNICALL Java_com_couchbase_cbforest_Indexer_endIndex 92 | (JNIEnv *env, jclass clazz, jlong indexerHandle, jboolean commit) 93 | { 94 | C4Error error; 95 | if(!c4indexer_end((C4Indexer *)indexerHandle, commit, &error)) 96 | throwError(env, error); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /Java/src/com/couchbase/cbforest/ForestException.java: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Couchbase. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // Unless required by applicable law or agreed to in writing, software distributed under the 7 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 | // either express or implied. See the License for the specific language governing permissions 9 | // and limitations under the License. 10 | 11 | package com.couchbase.cbforest; 12 | 13 | public class ForestException extends Exception { 14 | public final int domain; // TODO: Should be an enum 15 | public final int code; 16 | 17 | public ForestException(int domain, int code, String message) { 18 | super(message); 19 | this.domain = domain; 20 | this.code = code; 21 | } 22 | 23 | public static void throwException(int domain, int code, String msg) throws ForestException { 24 | throw new ForestException(domain, code, msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java/src/com/couchbase/cbforest/FullTextResult.java: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Couchbase. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // Unless required by applicable law or agreed to in writing, software distributed under the 7 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 | // either express or implied. See the License for the specific language governing permissions 9 | // and limitations under the License. 10 | 11 | package com.couchbase.cbforest; 12 | 13 | public class FullTextResult { 14 | 15 | FullTextResult(View view, String docID, long sequence, int fullTextID, int[] terms) { 16 | _view = view; 17 | _docID = docID; 18 | _sequence = sequence; 19 | _fullTextID = fullTextID; 20 | _terms = terms; 21 | } 22 | 23 | public int getMatchCount() { 24 | return _terms.length / 3; 25 | } 26 | 27 | public int getTermNumber(int matchNumber) { 28 | return _terms[matchNumber / 3]; 29 | } 30 | 31 | public int getByteOffset(int matchNumber) { 32 | return _terms[matchNumber / 3 + 1]; 33 | } 34 | 35 | public int getByteLength(int matchNumber) { 36 | return _terms[matchNumber / 3 + 2]; 37 | } 38 | 39 | public String getFullText() throws ForestException { 40 | return getFullText(_view._handle, _docID, _sequence, _fullTextID); 41 | } 42 | 43 | private static native String getFullText(long viewHandle, String docID, long sequence, 44 | int fullTextID) throws ForestException; 45 | 46 | private final View _view; 47 | private final String _docID; 48 | private final long _sequence; 49 | private final int _fullTextID; 50 | private final int[] _terms; 51 | } 52 | -------------------------------------------------------------------------------- /Java/src/com/couchbase/cbforest/Indexer.java: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Couchbase. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // Unless required by applicable law or agreed to in writing, software distributed under the 7 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 | // either express or implied. See the License for the specific language governing permissions 9 | // and limitations under the License. 10 | 11 | package com.couchbase.cbforest; 12 | 13 | 14 | public class Indexer { 15 | 16 | public Indexer(View[] views) throws ForestException { 17 | assert(views.length > 0); 18 | _views = views; 19 | Database database = views[0].database(); 20 | long viewHandles[] = new long[views.length]; 21 | for (int i = 0; i < views.length; i++) { 22 | assert(views[i].database() == database); 23 | viewHandles[i] = views[i]._handle; 24 | } 25 | _handle = beginIndex(database._handle, viewHandles); 26 | } 27 | 28 | public void triggerOnView(View v) { 29 | triggerOnView(_handle, v._handle); 30 | } 31 | 32 | public DocumentIterator iterateDocuments() throws ForestException { 33 | long iterHandle = iterateDocuments(_handle); 34 | if (iterHandle == 0) 35 | return null; // means there's nothing new to iterate 36 | return new DocumentIterator(iterHandle, false); 37 | } 38 | 39 | public boolean shouldIndex(Document doc, int viewNumber) { 40 | return shouldIndex(_handle, doc._handle, viewNumber); 41 | } 42 | 43 | public void emit(Document doc, int viewNumber, Object[] keys, byte[][] values) throws ForestException { 44 | 45 | // initialize C4Key 46 | long keyHandles[] = new long[keys.length]; 47 | for (int i = 0; i < keys.length; i++) { 48 | keyHandles[i] = View.objectToKey(keys[i]); 49 | } 50 | 51 | emit(_handle, doc._handle, viewNumber, keyHandles, values); 52 | // C4Keys in keyHandles are freed by the native method 53 | } 54 | 55 | public void endIndex(boolean commit) throws ForestException { 56 | endIndex(_handle, commit); 57 | _handle = 0; 58 | } 59 | 60 | 61 | // internals: 62 | 63 | protected void finalize() { 64 | if (_handle != 0) { 65 | try { 66 | endIndex(false); 67 | } catch (Exception x) { } 68 | } 69 | } 70 | 71 | private static native long beginIndex(long dbHandle, long viewHandles[]) throws ForestException; 72 | private static native void triggerOnView(long handle, long viewHandle); 73 | private static native long iterateDocuments(long handle) throws ForestException; 74 | private static native boolean shouldIndex(long handle, long docHandle, int viewNumber); 75 | private static native void emit(long handle, long docHandle, int viewNumber, long[] keys, byte[][] values) throws ForestException; 76 | private static native void endIndex(long handle, boolean commit) throws ForestException; 77 | 78 | private long _handle; // handle to native C4Indexer* 79 | private View[] _views; // Must keep the View objects from being GC'd 80 | 81 | } 82 | -------------------------------------------------------------------------------- /Java/src/com/couchbase/cbforest/Logger.java: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Couchbase. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // Unless required by applicable law or agreed to in writing, software distributed under the 7 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 | // either express or implied. See the License for the specific language governing permissions 9 | // and limitations under the License. 10 | 11 | package com.couchbase.cbforest; 12 | 13 | public interface Logger { 14 | public static final int Debug = 0, Info = 1, Warning = 2, Error = 3, None = 4; 15 | 16 | public void log(int level, String message); 17 | } 18 | -------------------------------------------------------------------------------- /Java/src/com/couchbase/cbforest/QueryIterator.java: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Couchbase. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | // except in compliance with the License. You may obtain a copy of the License at 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // Unless required by applicable law or agreed to in writing, software distributed under the 7 | // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 8 | // either express or implied. See the License for the specific language governing permissions 9 | // and limitations under the License. 10 | 11 | package com.couchbase.cbforest; 12 | 13 | public class QueryIterator { 14 | 15 | QueryIterator(View view, long handle) { 16 | _view = view; 17 | _handle = handle; 18 | } 19 | 20 | public boolean next() throws ForestException { 21 | boolean ok = next(_handle); 22 | if (!ok) 23 | _handle = 0; 24 | return ok; 25 | } 26 | 27 | public byte[] keyJSON() {return keyJSON(_handle);} 28 | public byte[] valueJSON() {return valueJSON(_handle);} 29 | public String docID() {return docID(_handle);} 30 | public long sequence() {return sequence(_handle);} 31 | 32 | public FullTextResult fullTextResult() { 33 | return new FullTextResult(_view, docID(), sequence(), 34 | fullTextID(_handle), fullTextTerms(_handle)); 35 | } 36 | 37 | /** Returns the bounding box of a geo-query match as an array of coordinates, 38 | in the order (xmin, ymin, xmax, ymax). */ 39 | public double[] geoBoundingBox() {return geoBoundingBox(_handle);} 40 | 41 | /** Returns the GeoJSON of a geo-query match, exactly as it was emitted from the map function. */ 42 | public byte[] geoJSON() {return geoJSON(_handle);} 43 | 44 | protected void finalize() { 45 | if (_handle != 0) 46 | free(_handle); 47 | } 48 | 49 | private static native boolean next(long handle) throws ForestException; 50 | private static native byte[] keyJSON(long handle); 51 | private static native byte[] valueJSON(long handle); 52 | private static native String docID(long handle); 53 | private static native long sequence(long handle); 54 | private static native int fullTextID(long handle); 55 | private static native int[] fullTextTerms(long handle); 56 | private static native double[] geoBoundingBox(long handle); 57 | private static native byte[] geoJSON(long handle); 58 | private static native void free(long handle); 59 | 60 | private View _view; 61 | private long _handle; // Handle to native C4QueryEnumerator* 62 | } 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **CBForest** is a higher-level C and C++ wrapper around [ForestDB][FDB], a new key-value storage engine based on a hierarchical B+-tree trie data structure. ForestDB is similar in functionality to the [CouchStore][COUCHSTORE] engine that currently underlies Couchbase Server, but it should be faster and more space-efficient, especially on solid-state disks (SSDs). 2 | 3 | CBForest adds an idiomatic object-oriented C++ API for ForestDB, and also some new functionality (see below.) Recently a C API with the same functionality has been added, and Java and C# bindings to that C API. 4 | 5 | The immediate purpose of CBForest is to serve as the storage engine of the next generation of [Couchbase Lite][CBL] (on all platforms), replacing SQLite. But it may find other uses too, perhaps for applications that want a fast minimalist data store with map/reduce indexing, but don't need any of the fancy features of Couchbase Lite like replication. 6 | 7 | ## Features 8 | 9 | * ForestDB features, available via idiomatic C++, Java and C# APIs: 10 | * Fast key-value storage, where keys and values are both opaque blobs. 11 | * Extremely robust append-only file format with write-ahead log and automatic compaction. 12 | * Reads are never blocked, even while writes or transactions are in progress. 13 | * Iteration by key order. 14 | * Iteration by _sequence_, reflecting the order in which changes were made to the database. (This is useful for tasks like updating indexes and replication.) 15 | * Database encryption using AES-256. 16 | 17 | * New features implemented by CBForest: 18 | * Optional multi-version document format that keeps a revision tree of the history of each document (as in Couchbase Lite or CouchDB.) 19 | * Index API that uses a database as an index of an external data set. 20 | * Map-reduce indexes that update incrementally as documents are changed in the source DB (as in Couchbase Lite or CouchDB.) 21 | * Limited full-text indexing. 22 | * Limited geo-indexing. 23 | * Support for JSON-compatible structured keys in indexes, sorted according to CouchDB's JSON collation spec. 24 | 25 | ## Platform Support 26 | 27 | CBForest runs on Mac OS, iOS, tvOS, Android, various other flavors of Unix, and Windows. 28 | 29 | CBForest has been in use since mid-2015 in the iOS/Mac version of [Couchbase Lite][CBL] 1.1, and since early 2016 in the 1.2 release on all the above platforms. 30 | 31 | ## License 32 | 33 | Like all Couchbase source code, this is released under the Apache 2 license. 34 | 35 | [FDB]: https://github.com/couchbase/forestdb 36 | [CBL]: http://www.couchbase.com/nosql-databases/couchbase-mobile 37 | [COUCHSTORE]: https://github.com/couchbase/couchstore 38 | -------------------------------------------------------------------------------- /vendor/snappy/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2011, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | === 31 | 32 | Some of the benchmark data in util/zippy/testdata is licensed differently: 33 | 34 | - fireworks.jpeg is Copyright 2013 Steinar H. Gunderson, and 35 | is licensed under the Creative Commons Attribution 3.0 license 36 | (CC-BY-3.0). See https://creativecommons.org/licenses/by/3.0/ 37 | for more information. 38 | 39 | - kppkn.gtb is taken from the Gaviota chess tablebase set, and 40 | is licensed under the MIT License. See 41 | https://sites.google.com/site/gaviotachessengine/Home/endgame-tablebases-1 42 | for more information. 43 | 44 | - paper-100k.pdf is an excerpt (bytes 92160 to 194560) from the paper 45 | “Combinatorial Modeling of Chromatin Features Quantitatively Predicts DNA 46 | Replication Timing in _Drosophila_” by Federico Comoglio and Renato Paro, 47 | which is licensed under the CC-BY license. See 48 | http://www.ploscompbiol.org/static/license for more ifnormation. 49 | 50 | - alice29.txt, asyoulik.txt, plrabn12.txt and lcet10.txt are from Project 51 | Gutenberg. The first three have expired copyrights and are in the public 52 | domain; the latter does not have expired copyright, but is still in the 53 | public domain according to the license information 54 | (http://www.gutenberg.org/ebooks/53). 55 | -------------------------------------------------------------------------------- /vendor/snappy/README.md: -------------------------------------------------------------------------------- 1 | This is a copy of the source files needed to build Snappy 1.1.2. 2 | It was copied from https://github.com:google/snappy.git commit 1ff9be9b. 3 | The reasons for copying instead of using a submodule are twofold: 4 | 5 | 1. Snappy can't be built out of the box after checking it out; you have to run autogen.sh (which will fail on OS X because it runs `libtool` not `glibtool`) and then `configure`. This is a pain. 6 | 2. After doing the above, there will be unversioned generated files in the directory, which git will then keep pointing out whenever you try to commit. 7 | 8 | --Jens Alfke, April 2014 -------------------------------------------------------------------------------- /vendor/snappy/snappy-sinksource.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include 30 | 31 | #include "snappy-sinksource.h" 32 | 33 | namespace snappy { 34 | 35 | Source::~Source() { } 36 | 37 | Sink::~Sink() { } 38 | 39 | char* Sink::GetAppendBuffer(size_t length, char* scratch) { 40 | return scratch; 41 | } 42 | 43 | ByteArraySource::~ByteArraySource() { } 44 | 45 | size_t ByteArraySource::Available() const { return left_; } 46 | 47 | const char* ByteArraySource::Peek(size_t* len) { 48 | *len = left_; 49 | return ptr_; 50 | } 51 | 52 | void ByteArraySource::Skip(size_t n) { 53 | left_ -= n; 54 | ptr_ += n; 55 | } 56 | 57 | UncheckedByteArraySink::~UncheckedByteArraySink() { } 58 | 59 | void UncheckedByteArraySink::Append(const char* data, size_t n) { 60 | // Do no copying if the caller filled in the result of GetAppendBuffer() 61 | if (data != dest_) { 62 | memcpy(dest_, data, n); 63 | } 64 | dest_ += n; 65 | } 66 | 67 | char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) { 68 | return dest_; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /vendor/snappy/snappy-stubs-internal.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include 30 | #include 31 | 32 | #include "snappy-stubs-internal.h" 33 | 34 | namespace snappy { 35 | 36 | void Varint::Append32(string* s, uint32 value) { 37 | char buf[Varint::kMax32]; 38 | const char* p = Varint::Encode32(buf, value); 39 | s->append(buf, p - buf); 40 | } 41 | 42 | } // namespace snappy 43 | -------------------------------------------------------------------------------- /vendor/snappy/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 40 | #include 41 | #endif 42 | 43 | #if 1 44 | #include 45 | #endif 46 | 47 | #if 0 48 | #include 49 | #endif 50 | 51 | #define SNAPPY_MAJOR 1 52 | #define SNAPPY_MINOR 1 53 | #define SNAPPY_PATCHLEVEL 2 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif 80 | 81 | typedef std::string string; 82 | 83 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 84 | TypeName(const TypeName&); \ 85 | void operator=(const TypeName&) 86 | 87 | #if !0 88 | // Windows does not have an iovec type, yet the concept is universally useful. 89 | // It is simple to define it ourselves, so we put it inside our own namespace. 90 | struct iovec { 91 | void* iov_base; 92 | size_t iov_len; 93 | }; 94 | #endif 95 | 96 | } // namespace snappy 97 | 98 | #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 99 | -------------------------------------------------------------------------------- /xcconfigs/CBForest Tests.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // CBForest Tests_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | FRAMEWORK_SEARCH_PATHS = $(DEVELOPER_FRAMEWORKS_DIR) $(inherited) 9 | GCC_PRECOMPILE_PREFIX_HEADER = YES 10 | GCC_PREFIX_HEADER = CBForest/CBForest-Prefix.pch 11 | INFOPLIST_FILE = CBForest Tests/CBForest Tests-Info.plist 12 | PRODUCT_BUNDLE_IDENTIFIER = org.couchbase.${PRODUCT_NAME:rfc1034identifier} 13 | WRAPPER_EXTENSION = xctest -------------------------------------------------------------------------------- /xcconfigs/CBForest static.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // CBForest static_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "static_lib.xcconfig" 9 | 10 | DSTROOT = /tmp/CBForest_iOS.dst 11 | GCC_PRECOMPILE_PREFIX_HEADER = YES 12 | GCC_PREFIX_HEADER = CBForest/CBForest-Prefix.pch 13 | HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT)/vendor/forestdb/include/** 14 | PRODUCT_NAME = CBForest 15 | SKIP_INSTALL = YES 16 | STRIP_INSTALLED_PRODUCT = NO -------------------------------------------------------------------------------- /xcconfigs/CBForest-Interop.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // CBForest-Interop_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | ALWAYS_SEARCH_USER_PATHS = YES 9 | CLANG_WARN_UNREACHABLE_CODE = YES 10 | DYLIB_COMPATIBILITY_VERSION = 1 11 | DYLIB_CURRENT_VERSION = 1 12 | ENABLE_STRICT_OBJC_MSGSEND = YES 13 | EXECUTABLE_PREFIX = lib 14 | EXPORTED_SYMBOLS_FILE = C/c4.exp 15 | GCC_NO_COMMON_BLOCKS = YES 16 | GCC_PREFIX_HEADER = CBForest/CBForest-Prefix.pch 17 | HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT)/vendor/forestdb/include/** /usr/local/include 18 | PRODUCT_NAME = CBForest-Interop -------------------------------------------------------------------------------- /xcconfigs/CBForestJNI.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // CBForestJNI_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | SDKROOT = macosx 9 | SUPPORTED_PLATFORMS = macosx 10 | 11 | DYLIB_COMPATIBILITY_VERSION = 1 12 | DYLIB_CURRENT_VERSION = 1 13 | 14 | ALWAYS_SEARCH_USER_PATHS = YES 15 | 16 | CLANG_WARN_UNREACHABLE_CODE = YES 17 | 18 | EXECUTABLE_PREFIX = lib 19 | EXPORTED_SYMBOLS_FILE = java/CBForestJNI.exp 20 | -------------------------------------------------------------------------------- /xcconfigs/CppTests.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // CppTests_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | SDKROOT = macosx 9 | SUPPORTED_PLATFORMS = macosx 10 | 11 | HEADER_SEARCH_PATHS = $(inherited) /usr/local/include/ 12 | LIBRARY_SEARCH_PATHS = $(inherited) /usr/local/lib 13 | -------------------------------------------------------------------------------- /xcconfigs/Project.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Project_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | IPHONEOS_DEPLOYMENT_TARGET = 8.0 9 | MACOSX_DEPLOYMENT_TARGET = 10.8 10 | TVOS_DEPLOYMENT_TARGET = 9.0 11 | ONLY_ACTIVE_ARCH = NO 12 | SKIP_INSTALL = YES 13 | SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator 14 | 15 | COPY_PHASE_STRIP = NO 16 | DEBUG_INFORMATION_FORMAT = dwarf 17 | PRODUCT_NAME = $(TARGET_NAME) 18 | 19 | ALWAYS_SEARCH_USER_PATHS = NO 20 | 21 | CLANG_CXX_LANGUAGE_STANDARD = c++0x 22 | CLANG_CXX_LIBRARY = libc++ 23 | CLANG_ENABLE_MODULES = YES 24 | CLANG_ENABLE_OBJC_ARC = YES 25 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 26 | CLANG_WARN_BOOL_CONVERSION = YES 27 | CLANG_WARN_CONSTANT_CONVERSION = YES 28 | CLANG_WARN_CXX0X_EXTENSIONS = YES 29 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR 30 | CLANG_WARN_EMPTY_BODY = YES 31 | CLANG_WARN_ENUM_CONVERSION = YES 32 | CLANG_WARN_INFINITE_RECURSION = YES; 33 | CLANG_WARN_INT_CONVERSION = YES 34 | CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES 35 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR 36 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES 37 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 38 | CLANG_WARN_UNREACHABLE_CODE = YES; 39 | 40 | GCC_C_LANGUAGE_STANDARD = c99 41 | GCC_ENABLE_OBJC_EXCEPTIONS = YES 42 | GCC_NO_COMMON_BLOCKS = YES; 43 | GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES 44 | GCC_TREAT_WARNINGS_AS_ERRORS = YES 45 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES 46 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES 47 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR 48 | GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES 49 | GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES 50 | GCC_WARN_SHADOW = YES 51 | GCC_WARN_UNDECLARED_SELECTOR = YES 52 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE 53 | GCC_WARN_UNUSED_FUNCTION = YES 54 | GCC_WARN_UNUSED_VARIABLE = YES 55 | 56 | WARNING_CFLAGS = -Wall -Wformat-security -Wmissing-declarations -Woverriding-method-mismatch -Wbool-conversion -Wno-arc-retain-cycles -Weffc++ 57 | 58 | ENABLE_STRICT_OBJC_MSGSEND = YES; 59 | 60 | COMBINE_HIDPI_IMAGES = YES // Stop Xcode from complaining 61 | -------------------------------------------------------------------------------- /xcconfigs/Project_Debug.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Project_Debug.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "Project.xcconfig" 9 | 10 | GCC_DYNAMIC_NO_PIC = NO 11 | GCC_OPTIMIZATION_LEVEL = 0 12 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DEBUG=1 HAVE_GCC_ATOMICS=1 _CRYPTO_CC _DOC_COMP 13 | ENABLE_TESTABILITY = YES 14 | MTL_ENABLE_DEBUG_INFO = YES 15 | -------------------------------------------------------------------------------- /xcconfigs/Project_Release.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Project_Release.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "Project.xcconfig" 9 | 10 | ENABLE_NS_ASSERTIONS = NO 11 | GCC_OPTIMIZATION_LEVEL = fast 12 | DEAD_CODE_STRIPPING = YES 13 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) NDEBUG=1 HAVE_GCC_ATOMICS=1 _CRYPTO_CC _DOC_COMP 14 | MTL_ENABLE_DEBUG_INFO = NO 15 | -------------------------------------------------------------------------------- /xcconfigs/SwiftForest.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftForest_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 4/11/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | ALWAYS_SEARCH_USER_PATHS = NO 9 | CLANG_ANALYZER_NONNULL = YES 10 | CLANG_CXX_LANGUAGE_STANDARD = gnu++0x 11 | CLANG_CXX_LIBRARY = libc++ 12 | CLANG_ENABLE_MODULES = YES 13 | CLANG_ENABLE_OBJC_ARC = YES 14 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 15 | CLANG_WARN_BOOL_CONVERSION = YES 16 | CLANG_WARN_CONSTANT_CONVERSION = YES 17 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR 18 | CLANG_WARN_EMPTY_BODY = YES 19 | CLANG_WARN_ENUM_CONVERSION = YES 20 | CLANG_WARN_INT_CONVERSION = YES 21 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR 22 | CLANG_WARN_UNREACHABLE_CODE = YES 23 | CODE_SIGN_IDENTITY = - 24 | COMBINE_HIDPI_IMAGES = YES 25 | COPY_PHASE_STRIP = NO 26 | CURRENT_PROJECT_VERSION = 1 27 | DEFINES_MODULE = YES 28 | DYLIB_COMPATIBILITY_VERSION = 1 29 | DYLIB_CURRENT_VERSION = 1 30 | DYLIB_INSTALL_NAME_BASE = @rpath 31 | ENABLE_STRICT_OBJC_MSGSEND = YES 32 | FRAMEWORK_VERSION = A 33 | GCC_C_LANGUAGE_STANDARD = gnu99 34 | GCC_NO_COMMON_BLOCKS = YES 35 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES 36 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR 37 | GCC_WARN_UNDECLARED_SELECTOR = YES 38 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE 39 | GCC_WARN_UNUSED_FUNCTION = YES 40 | GCC_WARN_UNUSED_VARIABLE = YES 41 | INFOPLIST_FILE = Swift/Info.plist 42 | INSTALL_PATH = $(LOCAL_LIBRARY_DIR)/Frameworks 43 | LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/../Frameworks @loader_path/Frameworks 44 | MACOSX_DEPLOYMENT_TARGET = 10.11 45 | PRODUCT_BUNDLE_IDENTIFIER = org.couchbase.SwiftForest 46 | PRODUCT_NAME = $(TARGET_NAME) 47 | SDKROOT = macosx 48 | SKIP_INSTALL = YES 49 | SWIFT_OBJC_BRIDGING_HEADER = Swift/Swift-Bridging-Header.h 50 | VERSION_INFO_PREFIX = 51 | VERSIONING_SYSTEM = apple-generic -------------------------------------------------------------------------------- /xcconfigs/SwiftForestTests.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftForestTests_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 4/11/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | ALWAYS_SEARCH_USER_PATHS = NO 9 | CLANG_ANALYZER_NONNULL = YES 10 | CLANG_CXX_LANGUAGE_STANDARD = gnu++0x 11 | CLANG_CXX_LIBRARY = libc++ 12 | CLANG_ENABLE_MODULES = YES 13 | CLANG_ENABLE_OBJC_ARC = YES 14 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 15 | CLANG_WARN_BOOL_CONVERSION = YES 16 | CLANG_WARN_CONSTANT_CONVERSION = YES 17 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR 18 | CLANG_WARN_EMPTY_BODY = YES 19 | CLANG_WARN_ENUM_CONVERSION = YES 20 | CLANG_WARN_INT_CONVERSION = YES 21 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR 22 | CLANG_WARN_UNREACHABLE_CODE = YES 23 | CODE_SIGN_IDENTITY = - 24 | COMBINE_HIDPI_IMAGES = YES 25 | COPY_PHASE_STRIP = NO 26 | ENABLE_STRICT_OBJC_MSGSEND = YES 27 | GCC_C_LANGUAGE_STANDARD = gnu99 28 | GCC_NO_COMMON_BLOCKS = YES 29 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES 30 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR 31 | GCC_WARN_UNDECLARED_SELECTOR = YES 32 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE 33 | GCC_WARN_UNUSED_FUNCTION = YES 34 | GCC_WARN_UNUSED_VARIABLE = YES 35 | INFOPLIST_FILE = Swift/tests/Info.plist 36 | LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks 37 | MACOSX_DEPLOYMENT_TARGET = 10.11 38 | PRODUCT_BUNDLE_IDENTIFIER = org.couchbase.SwiftForestTests 39 | PRODUCT_NAME = $(TARGET_NAME) 40 | SDKROOT = macosx -------------------------------------------------------------------------------- /xcconfigs/SwiftForestTests_Debug.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftForestTests_Debug.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 4/11/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "SwiftForestTests.xcconfig" 9 | 10 | DEBUG_INFORMATION_FORMAT = dwarf 11 | ENABLE_TESTABILITY = YES 12 | GCC_DYNAMIC_NO_PIC = NO 13 | GCC_OPTIMIZATION_LEVEL = 0 14 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 $(inherited) 15 | MTL_ENABLE_DEBUG_INFO = YES 16 | ONLY_ACTIVE_ARCH = YES 17 | SWIFT_OPTIMIZATION_LEVEL = -Onone -------------------------------------------------------------------------------- /xcconfigs/SwiftForestTests_Release.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftForestTests_Release.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 4/11/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "SwiftForestTests.xcconfig" 9 | 10 | DEBUG_INFORMATION_FORMAT = dwarf-with-dsym 11 | ENABLE_NS_ASSERTIONS = NO 12 | MTL_ENABLE_DEBUG_INFO = NO -------------------------------------------------------------------------------- /xcconfigs/SwiftForest_Debug.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftForest_Debug.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 4/11/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "SwiftForest.xcconfig" 9 | 10 | DEBUG_INFORMATION_FORMAT = dwarf 11 | ENABLE_TESTABILITY = YES 12 | GCC_DYNAMIC_NO_PIC = NO 13 | GCC_OPTIMIZATION_LEVEL = 0 14 | GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 $(inherited) 15 | MTL_ENABLE_DEBUG_INFO = YES 16 | ONLY_ACTIVE_ARCH = YES 17 | SWIFT_OPTIMIZATION_LEVEL = -Onone -------------------------------------------------------------------------------- /xcconfigs/SwiftForest_Release.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftForest_Release.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 4/11/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "SwiftForest.xcconfig" 9 | 10 | DEBUG_INFORMATION_FORMAT = dwarf-with-dsym 11 | ENABLE_NS_ASSERTIONS = NO 12 | MTL_ENABLE_DEBUG_INFO = NO -------------------------------------------------------------------------------- /xcconfigs/Tokenizer.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Tokenizer_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "static_lib.xcconfig" 9 | 10 | EXECUTABLE_PREFIX = lib 11 | 12 | GCC_TREAT_WARNINGS_AS_ERRORS = NO 13 | GCC_WARN_SHADOW = NO 14 | GCC_WARN_UNINITIALIZED_AUTOS = YES 15 | 16 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) SQLITE_ENABLE_FTS4 SQLITE_ENABLE_FTS4_UNICODE61 17 | -------------------------------------------------------------------------------- /xcconfigs/forestdb.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // forestdb_Shared.xcconfig 3 | // 4 | // Generated by BuildSettingExtractor on 1/21/16 5 | // https://github.com/dempseyatgithub/BuildSettingExtractor 6 | // 7 | 8 | #include "static_lib.xcconfig" 9 | 10 | EXECUTABLE_PREFIX = lib 11 | 12 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = NO 13 | CLANG_WARN_UNREACHABLE_CODE = NO 14 | 15 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) FORESTDB_VERSION=\"internal\" 16 | 17 | GCC_WARN_64_TO_32_BIT_CONVERSION = NO 18 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO 19 | GCC_WARN_SHADOW = NO 20 | GCC_WARN_UNINITIALIZED_AUTOS = YES 21 | GCC_WARN_UNUSED_FUNCTION = NO 22 | GCC_WARN_UNUSED_VALUE = NO 23 | GCC_WARN_UNUSED_VARIABLE = NO 24 | 25 | HEADER_SEARCH_PATHS = $(inherited) vendor/forestdb/** 26 | 27 | WARNING_CFLAGS = -Wformat-security -Wmissing-declarations -Woverriding-method-mismatch -Wbool-conversion -Wno-arc-retain-cycles 28 | -------------------------------------------------------------------------------- /xcconfigs/static_lib.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // static_lib.xcconfig 3 | // CBForest 4 | // 5 | // Created by Jens Alfke on 1/30/16. 6 | // Copyright © 2016 Couchbase. All rights reserved. 7 | // 8 | 9 | // Build settings for static libraries that will be distributed. 10 | // These avoid problems like embedded filesystem paths that cause link warnings when they can't 11 | // be found on the computer doing the linking. 12 | 13 | CLANG_ENABLE_MODULES = NO; 14 | CLANG_ENABLE_MODULE_DEBUGGING = NO; 15 | 16 | DEBUG_INFORMATION_FORMAT = dwarf; 17 | 18 | GENERATE_MASTER_OBJECT_FILE = NO; 19 | --------------------------------------------------------------------------------