Source code of Windows XP (NT5)
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.

350 lines
9.1 KiB

  1. /***********************************************************************
  2. *
  3. * TID.C
  4. *
  5. * Microsoft At Work Fax Address Book Template ID object
  6. * This file contains the code for implementing the Microsoft At Work Fax AB
  7. * TID object.
  8. *
  9. * Copyright 1992, 1993 Microsoft Corporation. All Rights Reserved.
  10. *
  11. * Revision History:
  12. *
  13. * When Who What
  14. * -------- ------------------ ---------------------------------------
  15. * MAPI Original source from MAPI(154) sample AB Provider
  16. * 3.7.94 Yoram Yaacovi Modifications to make it an At Work Fax ABP
  17. * 8.7.94 Yoram Yaacovi Update for MAPI 304
  18. *
  19. ***********************************************************************/
  20. #define _FAXAB_TID
  21. #include "faxab.h"
  22. /*
  23. * TID jump table is defined here...
  24. */
  25. static const TID_Vtbl vtblTID =
  26. {
  27. (TID_QueryInterface_METHOD *) WRAP_QueryInterface,
  28. (TID_AddRef_METHOD *) WRAP_AddRef,
  29. TID_Release,
  30. (TID_GetLastError_METHOD *) WRAP_GetLastError,
  31. (TID_SaveChanges_METHOD *) WRAP_SaveChanges,
  32. (TID_GetProps_METHOD *) WRAP_GetProps,
  33. (TID_GetPropList_METHOD *) WRAP_GetPropList,
  34. TID_OpenProperty,
  35. (TID_SetProps_METHOD *) WRAP_SetProps,
  36. (TID_DeleteProps_METHOD *) WRAP_DeleteProps,
  37. (TID_CopyTo_METHOD *) WRAP_CopyTo,
  38. (TID_CopyProps_METHOD *) WRAP_CopyProps,
  39. (TID_GetNamesFromIDs_METHOD *) WRAP_GetNamesFromIDs,
  40. (TID_GetIDsFromNames_METHOD *) WRAP_GetIDsFromNames,
  41. };
  42. /*************************************************************************
  43. *
  44. - HrNewTID
  45. -
  46. * Creates the TID object associated with a mail user.
  47. *
  48. *
  49. */
  50. HRESULT
  51. HrNewTID( LPMAPIPROP * lppMAPIPropNew,
  52. ULONG cbTemplateId,
  53. LPENTRYID lpTemplateId,
  54. ULONG ulTemplateFlags,
  55. LPMAPIPROP lpPropData,
  56. LPABLOGON lpABPLogon,
  57. LPCIID lpInterface,
  58. HINSTANCE hLibrary,
  59. LPALLOCATEBUFFER lpAllocBuff,
  60. LPALLOCATEMORE lpAllocMore,
  61. LPFREEBUFFER lpFreeBuff,
  62. LPMALLOC lpMalloc
  63. )
  64. {
  65. LPTID lpTID;
  66. SCODE sc;
  67. HRESULT hr = hrSuccess;
  68. LPMAILUSER lpABUser;
  69. ULONG ulObjType;
  70. /*
  71. * Create the user object corresponding to the template id
  72. */
  73. hr = HrNewFaxUser( &lpABUser,
  74. &ulObjType,
  75. cbTemplateId,
  76. lpTemplateId,
  77. lpABPLogon,
  78. lpInterface,
  79. hLibrary,
  80. lpAllocBuff,
  81. lpAllocMore,
  82. lpFreeBuff,
  83. lpMalloc
  84. );
  85. if (HR_FAILED(hr))
  86. {
  87. goto err;
  88. }
  89. /*
  90. * Allocate space for the TID structure
  91. */
  92. sc = lpAllocBuff(SIZEOF(TID), (LPVOID *) & lpTID);
  93. if (FAILED(sc))
  94. {
  95. DebugTrace("NewTID() - AllocBuffer failed %s\n",SzDecodeScode(sc));
  96. hr = ResultFromScode (sc);
  97. goto err;
  98. }
  99. /*
  100. * Initailize the TID structure
  101. */
  102. lpTID->lpVtbl = &vtblTID;
  103. lpTID->lcInit = 1;
  104. lpTID->hResult = hrSuccess;
  105. lpTID->idsLastError = 0;
  106. lpTID->hLibrary = hLibrary;
  107. lpTID->lpAllocBuff = lpAllocBuff;
  108. lpTID->lpAllocMore = lpAllocMore;
  109. lpTID->lpFreeBuff = lpFreeBuff;
  110. lpTID->lpMalloc = lpMalloc;
  111. lpTID->lpABLogon = lpABPLogon;
  112. lpTID->lpPropData = lpPropData;
  113. lpTID->lpABUser = lpABUser;
  114. /*
  115. * First time creation - must set the address type and template id.
  116. */
  117. if (ulTemplateFlags & FILL_ENTRY)
  118. {
  119. ULONG ulCount;
  120. LPSPropValue lpspv = NULL;
  121. /*
  122. * Copy all the properties from my object to the propdata
  123. */
  124. hr = lpABUser->lpVtbl->GetProps( lpABUser,
  125. NULL,
  126. 0, /* ansi */
  127. &ulCount,
  128. &lpspv
  129. );
  130. if (FAILED(hr))
  131. goto err;
  132. hr = lpPropData->lpVtbl->SetProps( lpPropData,
  133. ulCount,
  134. lpspv,
  135. NULL
  136. );
  137. lpFreeBuff(lpspv);
  138. if (FAILED(hr))
  139. goto err;
  140. }
  141. /*
  142. * AddRef lpPropData so we can use it after we return
  143. */
  144. (void)lpPropData->lpVtbl->AddRef(lpPropData);
  145. InitializeCriticalSection(&lpTID->cs);
  146. *lppMAPIPropNew = (LPVOID) lpTID;
  147. out:
  148. DebugTraceResult(NewTID, hr);
  149. return hr;
  150. err:
  151. if (lpABUser)
  152. lpABUser->lpVtbl->Release(lpABUser);
  153. lpFreeBuff(lpTID);
  154. goto out;
  155. }
  156. /*********************************************************************
  157. *********************************************************************
  158. *
  159. * The TID IMAPIProp methods
  160. *
  161. */
  162. STDMETHODIMP_(ULONG) TID_Release(LPTID lpTID)
  163. {
  164. LONG lcInit;
  165. /*
  166. * Check to see if it's large enough to hold this object
  167. */
  168. if (IsBadReadPtr(lpTID, SIZEOF(TID)))
  169. {
  170. /*
  171. * I'm not looking at an object that I expect to be.
  172. */
  173. return 1;
  174. }
  175. /*
  176. * Check to see that it's TIDs vtbl
  177. */
  178. if (lpTID->lpVtbl != &vtblTID)
  179. {
  180. /*
  181. * It's big enough but it's got the wrong vtbl.
  182. */
  183. return 1;
  184. }
  185. /*
  186. * Release the mapi property object
  187. */
  188. lpTID->lpPropData->lpVtbl->Release( lpTID->lpPropData );
  189. EnterCriticalSection(&lpTID->cs);
  190. lcInit = --lpTID->lcInit;
  191. LeaveCriticalSection(&lpTID->cs);
  192. if (lcInit == 0)
  193. {
  194. /*
  195. * Release the ABUser object
  196. */
  197. lpTID->lpABUser->lpVtbl->Release( lpTID->lpABUser );
  198. /*
  199. * Clean up the critical section
  200. */
  201. DeleteCriticalSection(&lpTID->cs);
  202. /*
  203. * Need to free the object
  204. */
  205. lpTID->lpFreeBuff(lpTID);
  206. return 0;
  207. }
  208. return lcInit;
  209. }
  210. /*
  211. - TID_OpenProperty
  212. -
  213. * Satisfies the object that are needed to support the "Options" details pane
  214. * associated with the MailUser object from ABUSER.C.
  215. *
  216. * Note: We are masking error strings that might be possible to get from the
  217. * lpABUser object. Since (for the most part) the only errors that can be returned
  218. * from this object are resource failure types, it wouldn't be of much use to the
  219. * user.
  220. */
  221. STDMETHODIMP
  222. TID_OpenProperty( LPTID lpTID,
  223. ULONG ulPropTag,
  224. LPCIID lpiid,
  225. ULONG ulInterfaceOptions,
  226. ULONG ulFlags,
  227. LPUNKNOWN * lppUnk
  228. )
  229. {
  230. HRESULT hResult;
  231. /*
  232. * Check to see if it's large enough to hold this object
  233. */
  234. if (IsBadReadPtr(lpTID, SIZEOF(TID)))
  235. {
  236. /*
  237. * No vtbl found
  238. */
  239. return ResultFromScode(E_INVALIDARG);
  240. }
  241. /*
  242. * Check to see that it's TIDs vtbl
  243. */
  244. if (lpTID->lpVtbl != &vtblTID)
  245. {
  246. /*
  247. * It's big enough but it's got the wrong vtbl.
  248. */
  249. return ResultFromScode(E_INVALIDARG);
  250. }
  251. if ( ulInterfaceOptions & ~MAPI_UNICODE )
  252. {
  253. DebugTraceArg( TID_OpenProperty, "unknown flags" );
  254. return ResultFromScode( MAPI_E_UNKNOWN_FLAGS );
  255. }
  256. if ( ulInterfaceOptions & MAPI_UNICODE )
  257. {
  258. DebugTraceArg( TID_OpenProperty, "bad character width" );
  259. return ResultFromScode( MAPI_E_BAD_CHARWIDTH );
  260. }
  261. /*
  262. * Don't want to check any other parameters here.
  263. * Calls down to wrapped objects will do this for
  264. * me.
  265. */
  266. switch (ulPropTag)
  267. {
  268. // For now, I just call the underlying (my) user object method to handle, which
  269. // means the template ID does not do anything.
  270. case PR_DETAILS_TABLE:
  271. case PR_DDLBX_COUNTRIES_TABLE:
  272. case PR_DIAL_HELPER_BUTTON:
  273. {
  274. hResult = lpTID->lpABUser->lpVtbl->OpenProperty(
  275. lpTID->lpABUser,
  276. ulPropTag,
  277. lpiid,
  278. ulInterfaceOptions,
  279. ulFlags,
  280. lppUnk);
  281. break;
  282. }
  283. default:
  284. {
  285. hResult = lpTID->lpPropData->lpVtbl->OpenProperty(
  286. lpTID->lpPropData,
  287. ulPropTag,
  288. lpiid,
  289. ulInterfaceOptions,
  290. ulFlags,
  291. lppUnk);
  292. break;
  293. }
  294. }
  295. DebugTraceResult(TID_OpenProperty, hResult);
  296. return hResult;
  297. }
  298. #undef _FAXAB_TID