X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/866f8763175ff60e4fa455b92b5eb660a12fe6c7..07691282a056c4efea71e1e505527601e8cc166b:/keychain/ckks/CKKSSQLDatabaseObject.h diff --git a/keychain/ckks/CKKSSQLDatabaseObject.h b/keychain/ckks/CKKSSQLDatabaseObject.h index d016e35d..efa8c45c 100644 --- a/keychain/ckks/CKKSSQLDatabaseObject.h +++ b/keychain/ckks/CKKSSQLDatabaseObject.h @@ -21,80 +21,106 @@ * @APPLE_LICENSE_HEADER_END@ */ -#ifndef DatabaseObject_h -#define DatabaseObject_h - -#include #include +#include -#define CKKSNilToNSNull(obj) ({ id o = (obj); o ? o : [NSNull null]; }) -#define CKKSNSNullToNil(obj) ({ id o = (obj); ([o isEqual: [NSNull null]]) ? nil : o; }) - -#define CKKSIsNull(x) ({ id y = (x); ((y == nil) || ([y isEqual: [NSNull null]])); }) +#define CKKSNilToNSNull(obj) \ + ({ \ + id o = (obj); \ + o ? o : [NSNull null]; \ + }) +#define CKKSNSNullToNil(obj) \ + ({ \ + id o = (obj); \ + ([o isEqual:[NSNull null]]) ? nil : o; \ + }) + +#define CKKSIsNull(x) \ + ({ \ + id y = (x); \ + ((y == nil) || ([y isEqual:[NSNull null]])); \ + }) #define CKKSUnbase64NullableString(x) (!CKKSIsNull(x) ? [[NSData alloc] initWithBase64EncodedString:x options:0] : nil) -@interface CKKSSQLDatabaseObject : NSObject { +NS_ASSUME_NONNULL_BEGIN -} +@interface CKKSSQLDatabaseObject : NSObject -@property (copy) NSDictionary* originalSelfWhereClause; +@property (copy) NSDictionary* originalSelfWhereClause; -- (bool) saveToDatabase: (NSError * __autoreleasing *) error; -- (bool) saveToDatabaseWithConnection: (SecDbConnectionRef) conn error: (NSError * __autoreleasing *) error; -- (bool) deleteFromDatabase: (NSError * __autoreleasing *) error; -+ (bool) deleteAll: (NSError * __autoreleasing *) error; +- (bool)saveToDatabase:(NSError* _Nullable __autoreleasing* _Nullable)error; +- (bool)saveToDatabaseWithConnection:(SecDbConnectionRef _Nullable)conn + error:(NSError* _Nullable __autoreleasing* _Nullable)error; +- (bool)deleteFromDatabase:(NSError* _Nullable __autoreleasing* _Nullable)error; ++ (bool)deleteAll:(NSError* _Nullable __autoreleasing* _Nullable)error; // Load the object from the database, and error if it doesn't exist -+ (instancetype) fromDatabaseWhere: (NSDictionary*) whereDict error: (NSError * __autoreleasing *) error; ++ (instancetype _Nullable)fromDatabaseWhere:(NSDictionary*)whereDict error:(NSError* _Nullable __autoreleasing* _Nullable)error; // Load the object from the database, and return nil if it doesn't exist -+ (instancetype) tryFromDatabaseWhere: (NSDictionary*) whereDict error: (NSError * __autoreleasing *) error; ++ (instancetype _Nullable)tryFromDatabaseWhere:(NSDictionary*)whereDict + error:(NSError* _Nullable __autoreleasing* _Nullable)error; -+ (NSArray*) all: (NSError * __autoreleasing *) error; -+ (NSArray*) allWhere: (NSDictionary*) whereDict error: (NSError * __autoreleasing *) error; ++ (NSArray*)all:(NSError* _Nullable __autoreleasing* _Nullable)error; ++ (NSArray*)allWhere:(NSDictionary* _Nullable)whereDict error:(NSError* _Nullable __autoreleasing* _Nullable)error; // Like all() above, but with limits on how many will return -+ (NSArray*)fetch:(size_t)count error: (NSError * __autoreleasing *) error; -+ (NSArray*)fetch:(size_t)count where:(NSDictionary*)whereDict error: (NSError * __autoreleasing *) error; -+ (NSArray*)fetch: (size_t)count where:(NSDictionary*)whereDict orderBy:(NSArray*) orderColumns error: (NSError * __autoreleasing *) error; - - -+ (bool) saveToDatabaseTable: (NSString*) table row: (NSDictionary*) row connection: (SecDbConnectionRef) dbconn error: (NSError * __autoreleasing *) error; -+ (bool) deleteFromTable: (NSString*) table where: (NSDictionary*) whereDict connection:(SecDbConnectionRef) dbconn error: (NSError * __autoreleasing *) error; - -+ (bool) queryDatabaseTable:(NSString*) table - where:(NSDictionary*) whereDict - columns:(NSArray*) names - groupBy:(NSArray*) groupColumns - orderBy:(NSArray*) orderColumns - limit:(ssize_t)limit - processRow:(void (^)(NSDictionary*)) processRow - error:(NSError * __autoreleasing *) error; - -+ (bool)queryMaxValueForField:(NSString*)maxField inTable:(NSString*)table where:(NSDictionary*)whereDict columns:(NSArray*)names processRow:(void (^)(NSDictionary*))processRow; ++ (NSArray*)fetch:(size_t)count error:(NSError* _Nullable __autoreleasing* _Nullable)error; ++ (NSArray*)fetch:(size_t)count + where:(NSDictionary* _Nullable)whereDict + error:(NSError* _Nullable __autoreleasing* _Nullable)error; ++ (NSArray*)fetch:(size_t)count + where:(NSDictionary* _Nullable)whereDict + orderBy:(NSArray* _Nullable)orderColumns + error:(NSError* _Nullable __autoreleasing* _Nullable)error; + + ++ (bool)saveToDatabaseTable:(NSString*)table + row:(NSDictionary*)row + connection:(SecDbConnectionRef _Nullable)dbconn + error:(NSError* _Nullable __autoreleasing* _Nullable)error; ++ (bool)deleteFromTable:(NSString*)table + where:(NSDictionary* _Nullable)whereDict + connection:(SecDbConnectionRef _Nullable)dbconn + error:(NSError* _Nullable __autoreleasing* _Nullable)error; + ++ (bool)queryDatabaseTable:(NSString*)table + where:(NSDictionary* _Nullable)whereDict + columns:(NSArray*)names + groupBy:(NSArray* _Nullable)groupColumns + orderBy:(NSArray* _Nullable)orderColumns + limit:(ssize_t)limit + processRow:(void (^)(NSDictionary*))processRow + error:(NSError* _Nullable __autoreleasing* _Nullable)error; + ++ (bool)queryMaxValueForField:(NSString*)maxField + inTable:(NSString*)table + where:(NSDictionary* _Nullable)whereDict + columns:(NSArray*)names + processRow:(void (^)(NSDictionary*))processRow; // Note: if you don't use the SQLDatabase methods of loading yourself, // make sure you call this directly after loading. -- (instancetype) memoizeOriginalSelfWhereClause; +- (instancetype)memoizeOriginalSelfWhereClause; #pragma mark - Subclasses must implement the following: // Given a row from the database, make this object -+ (instancetype) fromDatabaseRow: (NSDictionary*) row; ++ (instancetype _Nullable)fromDatabaseRow:(NSDictionary*)row; // Return the columns, in order, that this row wants to fetch -+ (NSArray*) sqlColumns; ++ (NSArray*)sqlColumns; // Return the table name for objects of this class -+ (NSString*) sqlTable; ++ (NSString*)sqlTable; // Return the columns and values, in order, that this row wants to save -- (NSDictionary*) sqlValues; +- (NSDictionary*)sqlValues; // Return a set of key-value pairs that will uniquely find This Row in the table -- (NSDictionary*) whereClauseToFindSelf; +- (NSDictionary*)whereClauseToFindSelf; -- (instancetype)copyWithZone:(NSZone *)zone; +//- (instancetype)copyWithZone:(NSZone* _Nullable)zone; @end // Helper class to use with where clauses @@ -102,9 +128,9 @@ @interface CKKSSQLWhereObject : NSObject @property NSString* sqlOp; @property NSString* contents; -- (instancetype) initWithOperation:(NSString*)op string: (NSString*) str; -+ (instancetype) op:(NSString*)op string:(NSString*) str; -+ (instancetype)op:(NSString*) op stringValue: (NSString*) str; // Will add single quotes around your value. +- (instancetype)initWithOperation:(NSString*)op string:(NSString*)str; ++ (instancetype)op:(NSString*)op string:(NSString*)str; ++ (instancetype)op:(NSString*)op stringValue:(NSString*)str; // Will add single quotes around your value. @end -#endif /* DatabaseObject_h */ +NS_ASSUME_NONNULL_END