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.

364 lines
8.9 KiB

  1. #include "stdafx.h"
  2. #if !defined(BITS_V12_ON_NT4)
  3. #include "cerror.tmh"
  4. #endif
  5. void
  6. CJobError::Set(
  7. CJob * job,
  8. ULONG FileIndex,
  9. QMErrInfo * ErrInfo
  10. )
  11. {
  12. m_ErrorSet = true;
  13. m_job = job;
  14. m_FileIndex = FileIndex;
  15. m_ErrInfo = *ErrInfo;
  16. }
  17. void
  18. CJobError::ClearError()
  19. {
  20. m_ErrorSet = false;
  21. m_job = 0;
  22. m_FileIndex = 0;
  23. memset( &m_ErrInfo, 0, sizeof(m_ErrInfo));
  24. }
  25. CJobError::CJobError()
  26. {
  27. ClearError();
  28. }
  29. CFileExternal *
  30. CJobError::CreateFileExternal() const
  31. {
  32. return m_job->_GetFileIndex( m_FileIndex )->CreateExternalInterface();
  33. }
  34. void
  35. CJobError::GetOldInterfaceErrors(
  36. DWORD *pdwWin32Result,
  37. DWORD *pdwTransportResult ) const
  38. {
  39. if (!IsErrorSet())
  40. {
  41. *pdwWin32Result = *pdwTransportResult = 0;
  42. return;
  43. }
  44. if ( GetStyle() == ERROR_STYLE_WIN32 )
  45. {
  46. *pdwWin32Result = GetCode();
  47. }
  48. else if ( GetStyle() == ERROR_STYLE_HRESULT &&
  49. ( (GetCode() & 0xffff0000) == 0x80070000 ) )
  50. {
  51. // If this is a win32 wrapped as an HRESULT, unwrap it.
  52. *pdwWin32Result = (GetCode() & 0x0000ffff);
  53. }
  54. if ( (GetSource() & COMPONENT_MASK) == COMPONENT_TRANS )
  55. {
  56. *pdwTransportResult = GetCode();
  57. }
  58. else
  59. {
  60. *pdwTransportResult = 0;
  61. }
  62. }
  63. HRESULT
  64. CJobError::Serialize(
  65. HANDLE hFile
  66. ) const
  67. {
  68. //
  69. // If this function changes, be sure that the metadata extension
  70. // constants are adequate.
  71. //
  72. if (!m_ErrorSet)
  73. {
  74. BOOL TrueBool = FALSE;
  75. SafeWriteFile( hFile, TrueBool );
  76. return S_OK;
  77. }
  78. BOOL FalseBool = TRUE;
  79. SafeWriteFile( hFile, FalseBool );
  80. SafeWriteFile( hFile, m_FileIndex );
  81. SafeWriteFile( hFile, m_ErrInfo.Code );
  82. SafeWriteFile( hFile, m_ErrInfo.Style );
  83. SafeWriteFile( hFile, m_ErrInfo.Source );
  84. SafeWriteFile( hFile, m_ErrInfo.result );
  85. SafeWriteFile( hFile, m_ErrInfo.Description );
  86. return S_OK;
  87. }
  88. void
  89. CJobError::Unserialize(
  90. HANDLE hFile,
  91. CJob * job
  92. )
  93. {
  94. BOOL ReadBool;
  95. SafeReadFile( hFile, &ReadBool );
  96. if (!ReadBool)
  97. {
  98. ClearError();
  99. return;
  100. }
  101. m_ErrorSet = true;
  102. SafeReadFile( hFile, &m_FileIndex );
  103. SafeReadFile( hFile, &m_ErrInfo.Code );
  104. SafeReadFile( hFile, &m_ErrInfo.Style );
  105. SafeReadFile( hFile, &m_ErrInfo.Source );
  106. SafeReadFile( hFile, &m_ErrInfo.result );
  107. SafeReadFile( hFile, &m_ErrInfo.Description );
  108. CFile * file = job->_GetFileIndex( m_FileIndex );
  109. if (!file)
  110. {
  111. throw ComError( HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER) );
  112. }
  113. m_job = job;
  114. }
  115. //------------------------------------------------------------------------
  116. CJobErrorExternal::CJobErrorExternal() :
  117. m_Context(BG_ERROR_CONTEXT_NONE),
  118. m_Code(S_OK),
  119. m_FileExternal(NULL)
  120. {
  121. }
  122. CJobErrorExternal::CJobErrorExternal( CJobError const * JobError ) :
  123. m_Context( BG_ERROR_CONTEXT_UNKNOWN ),
  124. m_Code( S_OK ),
  125. m_FileExternal( NULL )
  126. {
  127. try
  128. {
  129. m_FileExternal = JobError->CreateFileExternal();
  130. // Map source into a context
  131. ERROR_SOURCE Source = JobError->GetSource();
  132. switch(Source & COMPONENT_MASK)
  133. {
  134. case COMPONENT_QMGR:
  135. switch(Source & SUBCOMP_MASK)
  136. {
  137. case SUBCOMP_QMGR_FILE:
  138. m_Context = BG_ERROR_CONTEXT_LOCAL_FILE;
  139. break;
  140. case SUBCOMP_QMGR_QUEUE:
  141. m_Context = BG_ERROR_CONTEXT_GENERAL_QUEUE_MANAGER;
  142. break;
  143. case SUBCOMP_QMGR_NOTIFY:
  144. m_Context = BG_ERROR_CONTEXT_QUEUE_MANAGER_NOTIFICATION;
  145. break;
  146. default:
  147. ASSERT(0);
  148. }
  149. break;
  150. case COMPONENT_TRANS:
  151. if (Source == SOURCE_HTTP_SERVER_APP)
  152. {
  153. m_Context = BG_ERROR_CONTEXT_REMOTE_APPLICATION;
  154. }
  155. else
  156. {
  157. m_Context = BG_ERROR_CONTEXT_REMOTE_FILE;
  158. }
  159. break;
  160. default:
  161. m_Context = BG_ERROR_CONTEXT_NONE;
  162. break;
  163. }
  164. // map code into a HRESULT
  165. switch( JobError->GetStyle() )
  166. {
  167. case ERROR_STYLE_NONE:
  168. ASSERT(0);
  169. m_Code = JobError->GetCode();
  170. break;;
  171. case ERROR_STYLE_HRESULT:
  172. m_Code = JobError->GetCode();
  173. break;
  174. case ERROR_STYLE_WIN32:
  175. m_Code = HRESULT_FROM_WIN32( JobError->GetCode() );
  176. break;
  177. case ERROR_STYLE_HTTP:
  178. m_Code = MAKE_HRESULT( SEVERITY_ERROR, 0x19, JobError->GetCode() );
  179. break;
  180. default:
  181. ASSERT(0);
  182. m_Code = JobError->GetCode();
  183. break;
  184. }
  185. }
  186. catch (ComError err)
  187. {
  188. SafeRelease( m_FileExternal );
  189. }
  190. }
  191. CJobErrorExternal::~CJobErrorExternal()
  192. {
  193. SafeRelease( m_FileExternal );
  194. }
  195. STDMETHODIMP
  196. CJobErrorExternal::GetErrorInternal(
  197. BG_ERROR_CONTEXT *pContext,
  198. HRESULT *pCode
  199. )
  200. {
  201. HRESULT Hr = S_OK;
  202. LogPublicApiBegin( "pContext %p, pCode %p", pContext, pCode );
  203. ASSERT( pContext );
  204. ASSERT( pCode );
  205. *pContext = m_Context;
  206. *pCode = m_Code;
  207. LogPublicApiEnd( "pContext %p(%u), pCode %p(%u)", pContext, pContext ? *pContext : 0, pCode, pCode ? *pCode : 0 );
  208. return Hr;
  209. }
  210. STDMETHODIMP
  211. CJobErrorExternal::GetFileInternal(
  212. IBackgroundCopyFile ** pVal
  213. )
  214. {
  215. HRESULT Hr = S_OK;
  216. LogPublicApiBegin( "pVal %p", pVal );
  217. if (!m_FileExternal)
  218. {
  219. *pVal = NULL;
  220. Hr = BG_E_FILE_NOT_AVAILABLE;
  221. }
  222. else
  223. {
  224. m_FileExternal->AddRef();
  225. *pVal = m_FileExternal;
  226. }
  227. LogPublicApiEnd( "pVal %p(%p)", pVal, *pVal );
  228. return Hr;
  229. }
  230. STDMETHODIMP
  231. CJobErrorExternal::GetProtocolInternal( LPWSTR *pProtocol )
  232. {
  233. HRESULT Hr = S_OK;
  234. LogPublicApiBegin( "pProtocol %p", pProtocol );
  235. *pProtocol = NULL;
  236. if ( !m_FileExternal )
  237. {
  238. Hr = BG_E_PROTOCOL_NOT_AVAILABLE;
  239. }
  240. else
  241. {
  242. Hr = m_FileExternal->GetRemoteName( pProtocol );
  243. if (SUCCEEDED(Hr))
  244. {
  245. // replace the : with a '\0'
  246. WCHAR *pColon = wcsstr( *pProtocol, L":" );
  247. // Shouldn't happen since the name should have been verified
  248. // during the AddFile.
  249. ASSERT( pColon );
  250. if ( pColon )
  251. {
  252. *pColon = L'\0';
  253. }
  254. }
  255. }
  256. LogPublicApiEnd( "pProtocol %p(%p,%S)", pProtocol, *pProtocol, (*pProtocol ? *pProtocol : L"NULL") );
  257. return Hr;
  258. }
  259. STDMETHODIMP
  260. CJobErrorExternal::GetErrorDescriptionInternal(
  261. DWORD LanguageId,
  262. LPWSTR *pErrorDescription
  263. )
  264. {
  265. HRESULT Hr = S_OK;
  266. LogPublicApiBegin( "LanguageId %u, pErrorDescription %p", LanguageId, pErrorDescription );
  267. Hr = g_Manager->GetErrorDescription( m_Code, LanguageId, pErrorDescription );
  268. LogPublicApiEnd( "LanguageId %u, pErrorDescription %p(%S)", LanguageId, pErrorDescription,
  269. (*pErrorDescription ? *pErrorDescription : L"NULL") );
  270. return Hr;
  271. }
  272. STDMETHODIMP
  273. CJobErrorExternal::GetErrorContextDescriptionInternal(
  274. DWORD LanguageId,
  275. LPWSTR *pContextDescription
  276. )
  277. {
  278. HRESULT Hr = S_OK;
  279. LogPublicApiBegin( "LanguageId %u, pErrorDescription %p", LanguageId, pContextDescription );
  280. HRESULT hMappedError = BG_E_ERROR_CONTEXT_UNKNOWN;
  281. switch( m_Context )
  282. {
  283. case BG_ERROR_CONTEXT_NONE:
  284. hMappedError = BG_S_ERROR_CONTEXT_NONE;
  285. break;
  286. case BG_ERROR_CONTEXT_UNKNOWN:
  287. hMappedError = BG_E_ERROR_CONTEXT_UNKNOWN;
  288. break;
  289. case BG_ERROR_CONTEXT_GENERAL_QUEUE_MANAGER:
  290. hMappedError = BG_E_ERROR_CONTEXT_GENERAL_QUEUE_MANAGER;
  291. break;
  292. case BG_ERROR_CONTEXT_QUEUE_MANAGER_NOTIFICATION:
  293. hMappedError = BG_E_ERROR_CONTEXT_QUEUE_MANAGER_NOTIFICATION;
  294. case BG_ERROR_CONTEXT_LOCAL_FILE:
  295. hMappedError = BG_E_ERROR_CONTEXT_LOCAL_FILE;
  296. break;
  297. case BG_ERROR_CONTEXT_REMOTE_FILE:
  298. hMappedError = BG_E_ERROR_CONTEXT_REMOTE_FILE;
  299. break;
  300. case BG_ERROR_CONTEXT_GENERAL_TRANSPORT:
  301. hMappedError = BG_E_ERROR_CONTEXT_GENERAL_TRANSPORT;
  302. break;
  303. default:
  304. ASSERT(0);
  305. break;
  306. }
  307. Hr = g_Manager->GetErrorDescription( hMappedError, LanguageId, pContextDescription );
  308. LogPublicApiEnd( "LanguageId %u, pContextDescription %p(%S)",
  309. LanguageId, pContextDescription,
  310. (*pContextDescription ? *pContextDescription : L"NULL" ) );
  311. return Hr;
  312. }