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.

365 lines
9.3 KiB

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