Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
8.6 KiB

  1. // File: GAL.h
  2. #ifndef __GAL_h__
  3. #define __GAL_h__
  4. #include "richaddr.h"
  5. #include <mapix.h>
  6. // lst.h contains the template list class that we are using
  7. #include "lst.h"
  8. #include "calv.h"
  9. // Various debugging macros to facilitate testing
  10. // if the TESTING_CGAL macro is defined as non-zero there
  11. // is significant overhaed in exhaustively testing the CGAL stuff...
  12. #ifdef _DEBUG
  13. #define TESTING_CGAL 1
  14. #else
  15. #define TESTING_CGAL 0
  16. #endif // _DEBUG
  17. #if TESTING_CGAL
  18. #define VERIFYCACHE _VerifyCache( );
  19. #define TESTCGAL _Test();
  20. #else
  21. #define VERIFYCACHE
  22. #define TESTCGAL
  23. #endif // TESTING_CGAL
  24. #define CONSTANT( x ) enum{ x }
  25. #define MAKE_GAL_ERROR( e ) MAKE_HRESULT( SEVERITY_ERROR, FACILITY_ITF, e )
  26. #define GAL_E_GAL_NOT_FOUND MAKE_GAL_ERROR( 0x0001 )
  27. #define GAL_E_GETROWCOUNT_FAILED MAKE_GAL_ERROR( 0x0002 )
  28. #define GAL_E_SETCOLUMNS_FAILED MAKE_GAL_ERROR( 0x0003 )
  29. #define GAL_E_FINDROW_FAILED MAKE_GAL_ERROR( 0x0004 )
  30. #define GAL_E_SEEKROW_FAILED MAKE_GAL_ERROR( 0x0005 )
  31. #define GAL_E_SEEKROWAPPROX_FAILED MAKE_GAL_ERROR( 0x0006 )
  32. #define GAL_E_CREATEBOOKMARK_FAILED MAKE_GAL_ERROR( 0x0007 )
  33. #define GAL_E_QUERYROWS_FAILED MAKE_GAL_ERROR( 0x0008 )
  34. #define GAL_E_FREEBOOKMARK_FAILED MAKE_GAL_ERROR( 0x0009 )
  35. #define GAL_E_NOINSTANCEKEY MAKE_GAL_ERROR( 0x000a )
  36. #define GAL_E_NOENTRYID MAKE_GAL_ERROR( 0x000b )
  37. // CGAL is the Exchange Global Address List View....
  38. class CGAL : public CALV
  39. {
  40. public: // Data Types
  41. // A CGalEntry holds information about an individual entry in the GAL
  42. class CGalEntry {
  43. private:
  44. LPTSTR m_szName; // PR_DISPLAY_NAME
  45. LPTSTR m_szEMail; // PR_ACCOUNT
  46. SBinary m_EntryID; // PR_ENTRYID
  47. SBinary m_InstanceKey; // PR_INSTANCE_KEY
  48. ULONG m_ulDisplayType; // PR_DISPLAY_TYPE
  49. LPTSTR m_szBusinessTelephoneNum; // PR_BUSINESS_TELEPHONE_NUMBER;
  50. public: // Constructiors / destructiors / initializers / assignment
  51. CGalEntry( void );
  52. CGalEntry( const CGalEntry& r );
  53. CGalEntry( LPCTSTR szName, LPCTSTR szEMail, SBinary& rInstanceKey, SBinary& rEntryID, ULONG ulDisplayType, LPCTSTR szBusinessTelephoneNum );
  54. CGalEntry( LPCTSTR szName, LPCTSTR szEMail );
  55. ~CGalEntry( void );
  56. CGalEntry& operator=( const CGalEntry& r );
  57. // Get functions
  58. LPCTSTR GetName( void ) const { return m_szName; }
  59. LPCTSTR GetEMail( void ) const { return m_szEMail; }
  60. LPCTSTR GetBusinessTelephone( void ) const { return m_szBusinessTelephoneNum; }
  61. const SBinary& GetInstanceKey( void ) const { return m_InstanceKey; }
  62. const SBinary& GetEntryID( void ) const { return m_EntryID; }
  63. ULONG GetDisplayType( void ) const { return m_ulDisplayType; }
  64. // Comparison Operators
  65. bool operator==( const CGalEntry& r ) const;
  66. bool operator!=( const CGalEntry& r ) const { return !( *this == r ); }
  67. bool operator>=( LPCTSTR sz ) const;
  68. bool operator<=( LPCTSTR sz ) const;
  69. bool operator<( LPCTSTR sz ) const;
  70. };
  71. private: // Static Data
  72. enum ePropertyIndices {
  73. NAME_PROP_INDEX = 0,
  74. ACCOUNT_PROP_INDEX,
  75. INSTANCEKEY_PROP_INDEX,
  76. ENTRYID_PROP_INDEX,
  77. DISPLAY_TYPE_INDEX,
  78. BUSINESS_PHONE_NUM_PROP_INDEX,
  79. NUM_PROPS
  80. };
  81. enum eAsyncLogonState {
  82. AsyncLogonState_Idle,
  83. AsyncLogonState_LoggingOn,
  84. AsyncLogonState_LoggedOn,
  85. AsyncLogonState_Error
  86. };
  87. CONSTANT( NUM_LISTVIEW_PAGES_IN_CACHE = 15 );
  88. CONSTANT( INVALID_CACHE_INDEX = -1 );
  89. CONSTANT( DefaultMaxCacheSize = 1000 );
  90. CONSTANT( DefaultBlockSize = 50 );
  91. static LPCTSTR msc_szNoDisplayName;
  92. static LPCTSTR msc_szNoEMailName;
  93. static LPCTSTR msc_szNoBusinessTelephoneNum;
  94. static const char* msc_szNMExchangeAtrValue;
  95. static const char* msc_szNMPolRegKey;
  96. static const char* msc_szDefaultILSServerRegKey;
  97. static const char* msc_szDefaultILSServerValue;
  98. static const char* msc_szSMTPADDRESSNAME;
  99. private: // Data
  100. HRESULT m_hrGALError;
  101. CGalEntry msc_ErrorEntry_NoGAL;
  102. HWND m_hWndListView;
  103. // Cache Stuff
  104. int m_nBlockSize;
  105. lst< CGalEntry* > m_EntryCache;
  106. int m_IndexOfFirstItemInCache;
  107. int m_IndexOfLastItemInCache;
  108. bool m_bBeginningBookmarkIsValid;
  109. bool m_bEndBookmarkIsValid;
  110. BOOKMARK m_BookmarkOfFirstItemInCache;
  111. BOOKMARK m_BookmarkOfItemAfterLastItemInCache;
  112. int m_MaxCacheSize;
  113. int m_MaxJumpSize;
  114. public: // Async globals (public so they can be accessed by static functions)
  115. static HINSTANCE m_hInstMapi32DLL;
  116. static HANDLE m_hEventEndAsyncThread;
  117. static HANDLE m_hAsyncLogOntoGalThread;
  118. static eAsyncLogonState m_AsyncLogonState;
  119. // Mapi Interfaces
  120. static IAddrBook *m_pAddrBook;
  121. static IMAPITable *m_pContentsTable;
  122. static IMAPIContainer *m_pGAL;
  123. static ULONG m_nRows;
  124. static BOOL FLoadMapiFns(void);
  125. static VOID UnloadMapiFns(void);
  126. public:
  127. CGAL();
  128. ~CGAL();
  129. // CALV methods
  130. virtual VOID ShowItems( HWND hwnd );
  131. virtual VOID ClearItems(void);
  132. virtual BOOL GetSzAddress(LPTSTR psz, int cchMax, int iItem);
  133. virtual ULONG OnListFindItem( LPCTSTR szPartialMatchingString );
  134. virtual void OnListGetColumn1Data( int iItemIndex, int cchTextMax, LPTSTR szBuf );
  135. virtual void OnListGetColumn2Data( int iItemIndex, int cchTextMax, LPTSTR szBuf );
  136. virtual void OnListGetColumn3Data( int iItemIndex, int cchTextMax, TCHAR* szBuf );
  137. virtual VOID CmdProperties( void );
  138. virtual void OnListCacheHint( int indexFrom, int indexTo );
  139. virtual int OnListGetImageForItem( int iIndex );
  140. virtual bool IsItemBold( int index );
  141. virtual RAI * GetAddrInfo(void);
  142. private: // Helper Fns
  143. DWORD _GetExchangeAttribute( void );
  144. // Helper fns to get GAL Entries
  145. CGalEntry* _GetEntry( int index );
  146. CGalEntry* _GetItemFromCache( int index );
  147. CGalEntry* _GetEntriesAtBeginningOfList( int index );
  148. CGalEntry* _GetEntriesAtEndOfList( int index );
  149. CGalEntry* _LongJumpTo( int index );
  150. bool _CreateEndBookmark( int index, lst< CGalEntry* >::iterator& IEntry );
  151. bool _CreateBeginningBookmark( void );
  152. int _FindItemInCache( LPCTSTR szPartialMatchString );
  153. void _ResetCache( void );
  154. HRESULT _MakeGalEntry( SRow& rRow, CGalEntry** ppEntry );
  155. HRESULT _KillExcessItemsFromFrontOfCache( void );
  156. HRESULT _KillExcessItemsFromBackOfCache( void );
  157. bool _GetSzAddressFromExchangeServer(int iItem, LPTSTR psz, int cchMax);
  158. void _CopyPropertyString( LPTSTR psz, SPropValue& rProp, int cchMax );
  159. HRESULT _SetCursorTo( LPCTSTR szPartialMatch );
  160. HRESULT _SetCursorTo( const SBinary& rInstanceKey );
  161. HRESULT _SetCursorTo( const CGalEntry& rEntry );
  162. bool _IsLoggedOn( void ) const { return AsyncLogonState_LoggedOn == m_AsyncLogonState; }
  163. HRESULT _GetPhoneNumbers( const SBinary& rEntryID, int* pcPhoneNumbers, LPTSTR** ppszPhoneNums );
  164. HRESULT _GetEmailNames( int* pnEmailNames, LPTSTR** ppszEmailNames, int iItem );
  165. // Async logon/logoff
  166. HRESULT _AsyncLogOntoGAL(void);
  167. static HRESULT _sAsyncLogOntoGal(void);
  168. static HRESULT _sAsyncLogoffGal(void);
  169. static DWORD CALLBACK _sAsyncLogOntoGalThreadfn(LPVOID);
  170. static HRESULT _sInitListViewAndGalColumns(HWND hwnd);
  171. #if TESTING_CGAL
  172. void _VerifyCache( void );
  173. void _Test( void );
  174. #endif // #if TESTING_CGAL
  175. };
  176. // These should be removed...
  177. #define msc_ErrorEntry_FindRowFailed msc_ErrorEntry_NoGAL
  178. #define msc_ErrorEntry_SeekRowFailed msc_ErrorEntry_NoGAL
  179. #define msc_ErrorEntry_SeekRowApproxFailed msc_ErrorEntry_NoGAL
  180. #define msc_ErrorEntry_CreateBookmarkFailed msc_ErrorEntry_NoGAL
  181. #define msc_ErrorEntry_QueryRowsFailed msc_ErrorEntry_NoGAL
  182. #define msc_ErrorEntry_FreeBookmarkFailed msc_ErrorEntry_NoGAL
  183. #define msc_ErrorEntry_NoInstanceKeyFound msc_ErrorEntry_NoGAL
  184. #endif // __GAL_h__