1/* 2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#ifndef __LDAP_DL_MODULE_H__ 25#define __LDAP_DL_MODULE_H__ 26 27 28 29#include "Database.h" 30#include "DataStorageLibrary.h" 31#include "AttachedInstance.h" 32#include "TableRelation.h" 33#include "DSX509Relation.h" 34 35#include <map> 36 37/* 38 classes to implement the open directory DL 39*/ 40 41// implements the functionality for the open directory DL 42class LDAPDLModule : public DataStorageLibrary 43{ 44protected: 45 static TableRelation *mSchemaRelationRelation, 46 *mSchemaAttributeRelation, 47 *mSchemaIndexRelation, 48 *mSchemaParsingModuleRelation; // the "housekeeping" relations we support 49 static DSX509Relation *mX509Relation; // the open directory relation 50 51 static RelationMap *mRelationMap; // a map which enables efficient lookup of relations 52 53 // initialization functions 54 static void SetupSchemaRelationRelation (); 55 static void SetupSchemaAttributeRelation (); 56 static void SetupSchemaIndexRelation (); 57 static void SetupSchemaParsingModuleRelation (); 58 static void SetupX509Relation (); 59 static void InitializeRelations (); 60 61public: 62 LDAPDLModule (pthread_mutex_t *globalLock, CSSM_SPI_ModuleEventHandler CssmNotifyCallback, void* CssmNotifyCallbackCtx); 63 ~LDAPDLModule (); 64 65 AttachedInstance* MakeAttachedInstance (); // make an instance of this DL 66 static Relation* LookupRelation (CSSM_DB_RECORDTYPE relationID); // find a relation for this DL 67}; 68 69 70 71// holds an instance of the LDAPDatabase 72class LDAPAttachedInstance : public AttachedInstance 73{ 74public: 75 Database* MakeDatabaseObject (); 76}; 77 78 79// allows efficient lookup of queries 80typedef std::map<CSSM_HANDLE, Query*> QueryMap; 81 82 83 84// the open directory database instance 85class LDAPDatabase : public Database 86{ 87protected: 88 std::string mDatabaseName; // name of the database 89 QueryMap mQueryMap; // map of ongoing queries 90 CSSM_HANDLE mNextHandle; // next handle id that we will hand out 91 92 void CopyAttributes (Relation* r, Tuple *t, CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR attributes); // copy attributes into a realtion 93 void ExportUniqueID (UniqueIdentifier *id, CSSM_DB_UNIQUE_RECORD_PTR *uniqueID); // export a unique ID 94 void GetDataFromTuple (Tuple *t, CSSM_DATA &data); 95 void processNext(CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR attributes,CSSM_DATA_PTR data,CSSM_DB_UNIQUE_RECORD_PTR *uniqueID, Query *q, Relation *r); 96 97public: 98 LDAPDatabase (AttachedInstance *ai); 99 ~LDAPDatabase (); 100 101 // standard calls -- see the CDSA documentation for more info 102 103 virtual void DbOpen (const char* DbName, 104 const CSSM_NET_ADDRESS *dbLocation, 105 const CSSM_DB_ACCESS_TYPE accessRequest, 106 const CSSM_ACCESS_CREDENTIALS *accessCredentials, 107 const void* openParameters); 108 virtual void DbClose (); 109 110 virtual void DbGetDbNameFromHandle (char** dbName); 111 112 virtual CSSM_HANDLE DbDataGetFirst (const CSSM_QUERY *query, 113 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR attributes, 114 CSSM_DATA_PTR data, 115 CSSM_DB_UNIQUE_RECORD_PTR *uniqueID); 116 117 virtual bool DbDataGetNext (CSSM_HANDLE resultsHandle, 118 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR attributes, 119 CSSM_DATA_PTR data, 120 CSSM_DB_UNIQUE_RECORD_PTR *uniqueID); 121 122 virtual void DbDataAbortQuery (CSSM_HANDLE resultsHandle); 123 124 virtual void DbFreeUniqueRecord (CSSM_DB_UNIQUE_RECORD_PTR uniqueRecord); 125 126 virtual void DbDataGetFromUniqueRecordID (const CSSM_DB_UNIQUE_RECORD_PTR uniqueRecord, 127 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR attributes, 128 CSSM_DATA_PTR data); 129}; 130 131 132 133#endif 134