Технические вопросы и ответы QA1462

Программно выполняя открытый поиск каталога

Q: Как я программно ищу определенные записи путем соответствия атрибутов через Открыть Directory API?

A: Как я программно ищу определенные записи путем соответствия атрибутов через Открыть Directory API?

Необходимо будет использовать Платформу Служб каталогов, более в частности, dsDoAttributeValueSearchWithData функция найдена в нем.

Перечисление 1 ниже дает пример:

Перечисление 1  , Выполняющее тривиальное, Открывает Directory Search.

//  Begin variable declaration. 
tDirReference                 dirRef;
long                          status = eDSNoErr;
unsigned long                 numResults = 0;
tDataListPtr                  nodePath = NULL;
tDirNodeReference             nodeRef;
tDataList                     recordTypesToSearchFor;
tDataNodePtr                  patternToMatch = NULL;
tDataNodePtr                  matchType;
tDataListPtr                  requestedAttributes = NULL;
tDataBufferPtr                dataBuff = NULL;
tContextData                  context = NULL;

//  Initiate the Open Directory Service. 
status = dsOpenDirService(&dirRef);

//  Allocate a buffer. 
dataBuff = dsDataBufferAllocate(dirRef, 2*1024);

//  Find the default search node.
status = dsFindDirNodes(dirRef, dataBuff, NULL, eDSSearchNodeName, &numResults, &context);

//  Acquire a reference to the default search node.
status = dsGetDirNodeName(dirRef, dataBuff, 1, &nodePath);

//  Do some cleaning up.
dsDataBufferDeAllocate(dirRef, dataBuff);
dataBuff = NULL;
dataBuff = dsDataBufferAllocate(dirRef, 2*1024);

//  Open root level node for search. 
status = dsOpenDirNode(dirRef, nodePath, &nodeRef);

//  Build the tDataList containing the record type that you are searching for; 
//  in this case, the record type is "Users". 
status = dsBuildListFromStringsAlloc (dirRef, &recordTypesToSearchFor, kDSStdRecordTypeUsers, NULL); 
//  Return Records of Users. 

//  tDataNodePtr containing the string value to search for within all records. 
patternToMatch = dsDataNodeAllocateString(dirRef, "Michael");

//  tDataNodePtr containing the constant value that pertains to the scope of the search. 
matchType = dsDataNodeAllocateString(dirRef, kDSAttributesAll);

//  Build a list to contain the requested attributes of the records returned from your search. 
requestedAttributes = dsBuildListFromStrings(dirRef, kDS1AttrDistinguishedName, NULL);

//  The actual query. 
status = dsDoAttributeValueSearchWithData(nodeRef, dataBuff, &recordTypesToSearchFor, matchType, eDSContains,
                    patternToMatch, requestedAttributes, FALSE, &numResults, &context);

Необходимо будет также проверить возврат status и context переменные от dsFindDirNodes и dsDoAttributeValueSearchWithData вызовы с тех пор:

Было бы мудро проверить это numResults больше, чем 0 после dsFindDirNodes вызовите, так как возможно, что не мог быть возвращен никакой поисковый узел. Как только вышеупомянутый код выполняется, необходимо будет передать dataBuff и надлежащие параметры к dsGetRecordEntry, dsGetAttributeEntry, и dsGetAttributeValue для получения информации, в которой Вы нуждаетесь.



История версии документа


ДатаПримечания
11.09.2006

Новый документ, что краткий справочник о том, как программно искать, Открывает Directory для соответствия значений атрибута в записях.