/****************************************************************************** Searches a CONDENSED directory for the specified name Allows case-insensitive & partial match Returns empty string if not found ******************************************************************************/ std::wstring RecipientsHandler::SearchCondensedDirectory(char* pszDirectoryPath, const std::wstring &name) { #define LOOKUP_VIEW "Users" // Column numbers counting from 0 #define SEARCH_COLUMN 1 // lookup column #define RETURN_COLUMN 3 // return column(@Subset(FullName;1) // lookup column must be < return column std::wstring result; std::wstring columnvalue; WORD wABCount = 0; WORD wABBufferLength = 0; WORD wSignalFlags; WORD wItemDataType; WORD wIVTLength; DWORD dwEntriesFound = 0; DWORD dwEntryIndex; HANDLE hABBuffer = 0; HANDLE hSummaryBuffer = 0; DBHANDLE hdbDirectory = 0; HCOLLECTION hCollection = 0; NOTEID nidLookupView; COLLECTIONPOSITION cp; ITEM_VALUE_TABLE* pivt; BYTE* pSummaryBuffer; WORD* pItemLengthTable; BYTE* pItem; int nColumnCount; char szBuffer[MAXUSERNAME] = {0}; STATUS status = NSFDbOpen(pszDirectoryPath, &hdbDirectory); if (NOERROR == status) { status = NIFFindView(hdbDirectory, LOOKUP_VIEW, &nidLookupView); if (NOERROR == status) { status = NIFOpenCollection( hdbDirectory, hdbDirectory, nidLookupView, 0, NULLHANDLE, &hCollection, NULLHANDLE, NULL, NULLHANDLE, NULLHANDLE); if (NOERROR == status) { cp.Level = 0; cp.Tumbler[0] = 0; do { status = NIFReadEntries(hCollection, &cp, NAVIGATE_NEXT, 1, NAVIGATE_NEXT, 0xffffffff, READ_MASK_SUMMARYVALUES, &hSummaryBuffer, NULL, NULL, &dwEntriesFound, &wSignalFlags); if (NOERROR == status && hSummaryBuffer != NULLHANDLE) { pSummaryBuffer = OSLock(BYTE, hSummaryBuffer); wIVTLength = 0; for (dwEntryIndex = 0; dwEntryIndex < dwEntriesFound; dwEntryIndex++) { pSummaryBuffer += wIVTLength; pivt = (ITEM_VALUE_TABLE*)pSummaryBuffer; wIVTLength = pivt->Length; if (pivt->Items > RETURN_COLUMN) { pItemLengthTable = (WORD*)++pivt; pivt--; pItem = (BYTE*)pItemLengthTable; pItem += (pivt->Items * sizeof(WORD)); // at this point pItemLengthTable -> 1st item length // pItem -> 1st item datatype WORD // bump up to the specified COLUMN_NUMBER for (nColumnCount = 0; nColumnCount < SEARCH_COLUMN; nColumnCount++) { pItem += *pItemLengthTable++; } wItemDataType = *((WORD*)pItem); pItem += sizeof(WORD); // pItem -> data if (wItemDataType == TYPE_TEXT) { strncpy_s(szBuffer, sizeof(szBuffer), (char*)pItem, pItemLengthTable[0] - sizeof(WORD)); columnvalue = Workshare::Conversions::LMBCS22W(szBuffer); if (_wcsnicmp(columnvalue.c_str(), name.c_str(), name.length()) == 0) { pItem -= sizeof(WORD); // bump up to the column to be returned for (nColumnCount = SEARCH_COLUMN; nColumnCount < RETURN_COLUMN; nColumnCount++) { pItem += *pItemLengthTable++; } wItemDataType = *((WORD*)pItem); pItem += sizeof(WORD); // pItem -> data if (wItemDataType == TYPE_TEXT) { strncpy_s(szBuffer, sizeof(szBuffer), (char*)pItem, pItemLengthTable[0] - sizeof(WORD)); result = Workshare::Conversions::LMBCS22W(szBuffer); wSignalFlags = 0; // exits do - while break; // exits for } } } } } // end for OSUnlock(hSummaryBuffer); OSMemFree(hSummaryBuffer); } } while (wSignalFlags & SIGNAL_MORE_TO_DO); NIFCloseCollection(hCollection); } } NSFDbClose(hdbDirectory); } return result; }
/****************************************************************************** Takes the fullpath to a Domino directory. Returns the first match to 'name' from the '($Users)' view. Allows case-insensitive & partial match Returns empty string if not found ******************************************************************************/ std::wstring RecipientsHandler::SearchDominoDirectory(char* pszDirectoryPath, const std::wstring &name) { std::wstring result; WORD wABCount = 0; WORD wABBufferLength = 0; WORD wSignalFlags; WORD wItemDataType; DWORD dwMatches = 0; DWORD dwEntriesFound = 0; HANDLE hABBuffer = 0; HANDLE hSummaryBuffer = 0; DBHANDLE hdbDirectory = 0; HCOLLECTION hCollection = 0; NOTEID nidLookupView; COLLECTIONPOSITION cp; ITEM_VALUE_TABLE* pivt; WORD* pItemLengthTable; BYTE* pItem; LIST* plHeader; char szBuffer[MAXUSERNAME] = {0}; STATUS status = NSFDbOpen(pszDirectoryPath, &hdbDirectory); if (NOERROR == status) { status = NIFFindView(hdbDirectory, USERNAMESSPACE_ALT, &nidLookupView); if (NOERROR == status) { status = NIFOpenCollection( hdbDirectory, hdbDirectory, nidLookupView, 0, NULLHANDLE, &hCollection, NULLHANDLE, NULL, NULLHANDLE, NULLHANDLE); if (NOERROR == status) { status = NIFFindByName( hCollection, Workshare::Conversions::W22LMBCS(name).c_str(), FIND_PARTIAL | FIND_CASE_INSENSITIVE, &cp, &dwMatches); if (NOERROR == status && dwMatches > 0) { do { status = NIFReadEntries(hCollection, &cp, NAVIGATE_CURRENT, 0, NAVIGATE_NEXT, dwMatches, READ_MASK_SUMMARYVALUES, &hSummaryBuffer, NULL, NULL, &dwEntriesFound, &wSignalFlags); if (NOERROR == status && hSummaryBuffer != NULLHANDLE) { pivt = OSLock(ITEM_VALUE_TABLE, hSummaryBuffer); if (dwEntriesFound > 0) { if (pivt->Items > 0) { pItemLengthTable = (WORD*)++pivt; pivt--; pItem = (BYTE*)pItemLengthTable; pItem += (pivt->Items * sizeof(WORD)); // at this point pItemLength -> 1st item length // pItem -> 1st item datatype WORD wItemDataType = *((WORD*)pItem); pItem += sizeof(WORD); // pItem -> data switch (wItemDataType) { case TYPE_TEXT: { strncpy_s(szBuffer, sizeof(szBuffer), (char*)pItem, pItemLengthTable[0]); result = Workshare::Conversions::LMBCS22W(szBuffer); break; } case TYPE_TEXT_LIST: { plHeader = (LIST*)pItem; if (plHeader->ListEntries > 0) { pItemLengthTable = (WORD*)++plHeader; plHeader--; pItem = (BYTE*)plHeader; pItem += sizeof(LIST) + plHeader->ListEntries * sizeof(WORD); strncpy_s(szBuffer, sizeof(szBuffer), (char*)pItem, pItemLengthTable[0]); result = Workshare::Conversions::LMBCS22W(szBuffer); } break; } default: { break; } } } } OSUnlock(hSummaryBuffer); OSMemFree(hSummaryBuffer); } wSignalFlags = 0; // to ensure we only go around once } while (wSignalFlags & SIGNAL_MORE_TO_DO); } NIFCloseCollection(hCollection); } } NSFDbClose(hdbDirectory); } return result; }
_declspec ( dllexport ) WORD GetServerNamesEx(char retServerNames[MAX_SERVERS][MAXPATH]) { BOOL status = NOERROR; char szLocation[MAXENVVALUE]; char szPAB[MAXENVVALUE]; HANDLE db; char full_netpath[MAXPATH-1]; NOTEID view_id; HCOLLECTION hCollection; COLLECTIONPOSITION pCollPosition; HANDLE hBuffer; DWORD NumberReturned = 0; NOTEID *IdList; NOTEHANDLE note; char szFieldName[80] = { 0 }; char szFieldType[80] = { 0 }; WORD retServerCount = 0; bool bUseLocal = false; // first, get the name of the current location status = OSGetEnvironmentString("Location", szLocation, MAXENVVALUE); if (status == TRUE) { char *pb = strchr(szLocation, ','); if (pb != NULL) *pb = 0 ; } status = OSGetEnvironmentString("MAILSERVER", szPAB, MAXENVVALUE); if (status == TRUE) { char *pb = strchr(szPAB, ','); if (pb != NULL) *pb = 0 ; } if (status = OSPathNetConstruct(NULL, szPAB, _T("names.nsf"), full_netpath)) { printf("unable to open the public NAB %s!!names.nsf\n", szFieldName); return 0; } if (status = NSFDbOpen (full_netpath, &db)) return 0; if (bUseLocal) { // choose local PAB view if (status = NIFFindView(db, _T("Connections"), &view_id)) { NSFDbClose(db); return 0; } } else { // choose server list from server Directory if (status = NIFFindView(db, _T("Servers"), &view_id)) { NSFDbClose(db); return 0; } } if (status = NIFOpenCollection( db, db, view_id, 0, NULLHANDLE, &hCollection, NULL, NULL, NULL, NULL )) { NSFDbClose(db); return 0; } pCollPosition.Level = 0; pCollPosition.Tumbler[0] = 1; if (status = NIFReadEntries(hCollection, &pCollPosition, NAVIGATE_CURRENT, 1L, NAVIGATE_NEXT, 0xFFFFFFFF, READ_MASK_NOTEID, &hBuffer, NULL, NULL, &NumberReturned, NULL)) { NIFCloseCollection(hCollection); NSFDbClose(db); return 0; } strcpy_s(retServerNames[retServerCount++], MAXPATH, _T("Local")); if (NumberReturned != 0) { if (hBuffer != NULLHANDLE) { IdList = (NOTEID far *)OSLockObject(hBuffer); for (DWORD i=0; i<(DWORD)NumberReturned; i++) { if (status = NSFNoteOpen( db, IdList[i], 0, ¬e)) { // skip categories } else { // scan documents WORD lenFieldName = NSFItemGetText(note, (bUseLocal) ? _T("Destination") : _T("ServerName"), szFieldName, sizeof(szFieldName)); strcpy_s(retServerNames[retServerCount++], MAXPATH, szFieldName); status = NSFNoteClose(note); } } OSUnlockObject(hBuffer); OSMemFree(hBuffer); } } if (status) { NIFCloseCollection(hCollection); NSFDbClose(db); return 0; } if (status = NIFCloseCollection(hCollection)) { NSFDbClose(db); return 0; } if (status = NSFDbClose(db)) return 0; return retServerCount; }