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.

394 lines
11 KiB

  1. // Message.cpp: implementation of the CArchiveMsg class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #define __FILE_ID__ 13
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. IMPLEMENT_DYNCREATE(CArchiveMsg, CObject)
  12. DWORD
  13. CArchiveMsg::Init (
  14. PFAX_MESSAGE pMsg,
  15. CServerNode* pServer
  16. )
  17. /*++
  18. Routine name : CArchiveMsg::Init
  19. Routine description:
  20. Constructs a new message from a FAX_MESSAGE structure
  21. Author:
  22. Eran Yariv (EranY), Jan, 2000
  23. Arguments:
  24. pMsg [in] - Pointer to FAX_MESSAGE structure
  25. pServer [in] - pointer to CServerNode object
  26. Return Value:
  27. Standard Win32 error code
  28. --*/
  29. {
  30. DWORD dwRes = ERROR_SUCCESS;
  31. DBG_ENTER(TEXT("CArchiveMsg::Init"), dwRes);
  32. ASSERTION(pServer);
  33. m_pServer = pServer;
  34. m_bValid = FALSE;
  35. try
  36. {
  37. m_dwValidityMask = pMsg->dwValidityMask;
  38. //
  39. // Message id
  40. //
  41. ASSERTION (m_dwValidityMask & FAX_JOB_FIELD_MESSAGE_ID);
  42. m_dwlMessageId = pMsg->dwlMessageId;
  43. //
  44. // Broadcast id
  45. //
  46. m_dwlBroadcastId = (m_dwValidityMask & FAX_JOB_FIELD_BROADCAST_ID) ?
  47. pMsg->dwlBroadcastId : 0;
  48. //
  49. // Job type
  50. //
  51. ASSERTION (m_dwValidityMask & FAX_JOB_FIELD_TYPE);
  52. m_dwJobType = pMsg->dwJobType;
  53. //
  54. // Extended status
  55. //
  56. m_dwExtendedStatus = (m_dwValidityMask & FAX_JOB_FIELD_STATUS_EX) ?
  57. pMsg->dwExtendedStatus : 0;
  58. //
  59. // Job size
  60. //
  61. m_dwSize = (m_dwValidityMask & FAX_JOB_FIELD_SIZE) ? pMsg->dwSize : 0;
  62. //
  63. // Page count
  64. //
  65. m_dwPageCount = (m_dwValidityMask & FAX_JOB_FIELD_PAGE_COUNT) ? pMsg->dwPageCount : 0;
  66. //
  67. // Original scheduled time
  68. //
  69. if (m_dwValidityMask & FAX_JOB_FIELD_ORIGINAL_SCHEDULE_TIME)
  70. {
  71. m_tmOriginalScheduleTime = pMsg->tmOriginalScheduleTime;
  72. }
  73. else
  74. {
  75. m_tmOriginalScheduleTime.Zero ();
  76. }
  77. //
  78. // Submission time
  79. //
  80. if (m_dwValidityMask & FAX_JOB_FIELD_SUBMISSION_TIME)
  81. {
  82. m_tmSubmissionTime = pMsg->tmOriginalScheduleTime;
  83. }
  84. else
  85. {
  86. m_tmSubmissionTime.Zero ();
  87. }
  88. //
  89. // Transmission start time
  90. //
  91. if (m_dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_START_TIME)
  92. {
  93. m_tmTransmissionStartTime = pMsg->tmTransmissionStartTime;
  94. }
  95. else
  96. {
  97. m_tmTransmissionStartTime.Zero ();
  98. }
  99. //
  100. // Transmission end time
  101. //
  102. if (m_dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_END_TIME)
  103. {
  104. m_tmTransmissionEndTime = pMsg->tmTransmissionEndTime;
  105. }
  106. else
  107. {
  108. m_tmTransmissionEndTime.Zero ();
  109. }
  110. //
  111. // Transmission duration
  112. //
  113. if ((m_dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_END_TIME) &&
  114. (m_dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_START_TIME))
  115. {
  116. m_tmTransmissionDuration = m_tmTransmissionEndTime - m_tmTransmissionStartTime;
  117. }
  118. else
  119. {
  120. m_tmTransmissionDuration.Zero ();
  121. }
  122. //
  123. // Priority
  124. //
  125. if (m_dwValidityMask & FAX_JOB_FIELD_PRIORITY)
  126. {
  127. m_Priority = pMsg->Priority;
  128. ASSERTION (m_Priority <= FAX_PRIORITY_TYPE_HIGH);
  129. }
  130. else
  131. {
  132. m_Priority = (FAX_ENUM_PRIORITY_TYPE)-1;
  133. }
  134. //
  135. // Retries
  136. //
  137. if (m_dwValidityMask & FAX_JOB_FIELD_RETRIES)
  138. {
  139. m_dwRetries = pMsg->dwRetries;
  140. }
  141. else
  142. {
  143. m_dwRetries = 0;
  144. }
  145. //
  146. // Recipient info
  147. //
  148. m_cstrRecipientNumber = pMsg->lpctstrRecipientNumber ?
  149. pMsg->lpctstrRecipientNumber : TEXT("");
  150. m_cstrRecipientName = pMsg->lpctstrRecipientName ?
  151. pMsg->lpctstrRecipientName : TEXT("");
  152. //
  153. // Sender info
  154. //
  155. m_cstrSenderNumber = pMsg->lpctstrSenderNumber ?
  156. pMsg->lpctstrSenderNumber : TEXT("");
  157. m_cstrSenderName = pMsg->lpctstrSenderName ?
  158. pMsg->lpctstrSenderName : TEXT("");
  159. //
  160. // TSID / CSID
  161. //
  162. m_cstrTsid = pMsg->lpctstrTsid ?
  163. pMsg->lpctstrTsid : TEXT("");
  164. m_cstrCsid = pMsg->lpctstrCsid ?
  165. pMsg->lpctstrCsid : TEXT("");
  166. //
  167. // User
  168. //
  169. m_cstrSenderUserName = pMsg->lpctstrSenderUserName ?
  170. pMsg->lpctstrSenderUserName : TEXT("");
  171. //
  172. // Billing
  173. //
  174. m_cstrBillingCode = pMsg->lpctstrBillingCode ?
  175. pMsg->lpctstrBillingCode : TEXT("");
  176. //
  177. // Device
  178. //
  179. m_cstrDeviceName = pMsg->lpctstrDeviceName ?
  180. pMsg->lpctstrDeviceName : TEXT("");
  181. //
  182. // Document
  183. //
  184. m_cstrDocumentName = pMsg->lpctstrDocumentName ?
  185. pMsg->lpctstrDocumentName : TEXT("");
  186. //
  187. // Subject
  188. //
  189. m_cstrSubject = pMsg->lpctstrSubject ?
  190. pMsg->lpctstrSubject : TEXT("");
  191. //
  192. // Caller id
  193. //
  194. m_cstrCallerID = pMsg->lpctstrCallerID ?
  195. pMsg->lpctstrCallerID : TEXT("");
  196. //
  197. // Routing info
  198. //
  199. m_cstrRoutingInfo = pMsg->lpctstrRoutingInfo ?
  200. pMsg->lpctstrRoutingInfo : TEXT("");
  201. //
  202. // Server name
  203. //
  204. m_cstrServerName = m_pServer->Machine();
  205. m_dwPossibleOperations = FAX_JOB_OP_VIEW | FAX_JOB_OP_DELETE | FAX_JOB_OP_PROPERTIES;
  206. }
  207. catch (CException *pException)
  208. {
  209. TCHAR wszCause[1024];
  210. pException->GetErrorMessage (wszCause, 1024);
  211. pException->Delete ();
  212. VERBOSE (EXCEPTION_ERR,
  213. TEXT("Init caused exception : %s"),
  214. wszCause);
  215. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  216. return dwRes;
  217. }
  218. ASSERTION (ERROR_SUCCESS == dwRes);
  219. m_bValid = TRUE;
  220. return dwRes;
  221. } // CArchiveMsg::Init
  222. DWORD
  223. CArchiveMsg::GetTiff (
  224. CString &cstrTiffLocation
  225. ) const
  226. /*++
  227. Routine name : CArchiveMsg::GetTiff
  228. Routine description:
  229. Retrieves the message's TIFF from the server
  230. Author:
  231. Eran Yariv (EranY), Jan, 2000
  232. Arguments:
  233. cstrTiffLocation [out] - Name of TIFF file
  234. Return Value:
  235. Standard Win32 error code
  236. --*/
  237. {
  238. DWORD dwRes = ERROR_SUCCESS;
  239. DBG_ENTER(TEXT("CArchiveMsg::GetTiff"), dwRes);
  240. dwRes = CopyTiffFromServer (m_pServer,
  241. m_dwlMessageId,
  242. (JT_SEND == m_dwJobType) ?
  243. FAX_MESSAGE_FOLDER_SENTITEMS :
  244. FAX_MESSAGE_FOLDER_INBOX,
  245. cstrTiffLocation);
  246. if (ERROR_SUCCESS != dwRes)
  247. {
  248. CALL_FAIL (GENERAL_ERR, TEXT("CopyTiffFromServer"), dwRes);
  249. }
  250. return dwRes;
  251. }
  252. DWORD
  253. CArchiveMsg::Delete ()
  254. /*++
  255. Routine name : CArchiveMsg::Delete
  256. Routine description:
  257. Deletes the message
  258. Author:
  259. Eran Yariv (EranY), Jan, 2000
  260. Return Value:
  261. Standard Win32 error code
  262. --*/
  263. {
  264. DWORD dwRes = ERROR_SUCCESS;
  265. DBG_ENTER(TEXT("CArchiveMsg::Delete"), dwRes);
  266. if (!(GetPossibleOperations() & FAX_JOB_OP_DELETE))
  267. {
  268. VERBOSE (DBG_MSG, TEXT("Message can no longer be deleted"));
  269. dwRes = ERROR_CAN_NOT_COMPLETE;
  270. return dwRes;
  271. }
  272. HANDLE hFax;
  273. dwRes = m_pServer->GetConnectionHandle (hFax);
  274. if (ERROR_SUCCESS != dwRes)
  275. {
  276. CALL_FAIL (GENERAL_ERR, TEXT("CServerNode::GetConnectionHandle"), dwRes);
  277. return dwRes;
  278. }
  279. START_RPC_TIME(TEXT("FaxRemoveMessage"));
  280. if (!FaxRemoveMessage (hFax,
  281. m_dwlMessageId,
  282. (JT_SEND == m_dwJobType) ?
  283. FAX_MESSAGE_FOLDER_SENTITEMS :
  284. FAX_MESSAGE_FOLDER_INBOX))
  285. {
  286. dwRes = GetLastError ();
  287. END_RPC_TIME(TEXT("FaxRemoveMessage"));
  288. m_pServer->SetLastRPCError (dwRes);
  289. CALL_FAIL (RPC_ERR, TEXT("FaxRemoveMessage"), dwRes);
  290. return dwRes;
  291. }
  292. END_RPC_TIME(TEXT("FaxRemoveMessage"));
  293. ASSERTION (ERROR_SUCCESS == dwRes);
  294. return dwRes;
  295. } // CArchiveMsg::Delete
  296. DWORD
  297. CArchiveMsg::Copy(
  298. const CArchiveMsg& other
  299. )
  300. {
  301. DWORD dwRes = ERROR_SUCCESS;
  302. DBG_ENTER(TEXT("CArchiveMsg::Copy"), dwRes);
  303. try
  304. {
  305. m_dwValidityMask = other.m_dwValidityMask;
  306. m_dwJobType = other.m_dwJobType;
  307. m_dwExtendedStatus = other.m_dwExtendedStatus;
  308. m_dwlMessageId = other.m_dwlMessageId;
  309. m_dwlBroadcastId = other.m_dwlBroadcastId;
  310. m_dwSize = other.m_dwSize;
  311. m_dwPageCount = other.m_dwPageCount;
  312. m_tmOriginalScheduleTime = other.m_tmOriginalScheduleTime;
  313. m_tmSubmissionTime = other.m_tmSubmissionTime;
  314. m_tmTransmissionStartTime = other.m_tmTransmissionStartTime;
  315. m_tmTransmissionEndTime = other.m_tmTransmissionEndTime;
  316. m_tmTransmissionDuration = other.m_tmTransmissionDuration;
  317. m_Priority = other.m_Priority;
  318. m_dwRetries = other.m_dwRetries;
  319. m_cstrRecipientNumber = other.m_cstrRecipientNumber;
  320. m_cstrRecipientName = other.m_cstrRecipientName;
  321. m_cstrSenderNumber = other.m_cstrSenderNumber;
  322. m_cstrSenderName = other.m_cstrSenderName;
  323. m_cstrTsid = other.m_cstrTsid;
  324. m_cstrCsid = other.m_cstrCsid;
  325. m_cstrSenderUserName = other.m_cstrSenderUserName;
  326. m_cstrBillingCode = other.m_cstrBillingCode;
  327. m_cstrDeviceName = other.m_cstrDeviceName;
  328. m_cstrDocumentName = other.m_cstrDocumentName;
  329. m_cstrSubject = other.m_cstrSubject;
  330. m_cstrCallerID = other.m_cstrCallerID;
  331. m_cstrRoutingInfo = other.m_cstrRoutingInfo;
  332. m_cstrServerName = other.m_cstrServerName;
  333. m_bValid = other.m_bValid;
  334. }
  335. catch(...)
  336. {
  337. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  338. }
  339. return dwRes;
  340. } // CArchiveMsg::Copy