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.

289 lines
8.4 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // SOAPHelper.h
  4. //
  5. // Helper functions for SOAP
  6. //
  7. // This implementation aims to be SOAP 1.1 compliant. The spec can be
  8. // found here:
  9. // http://msdn.microsoft.com/xml/general/soapspec.asp
  10. //
  11. // Author: Wei Jiang
  12. //
  13. // 10/12/00 weijiang created
  14. // 01/10/01 weijiang update for SOAP 1.1, code clean up
  15. // 01/23/01 jeffstei Rename and add GetSOAPMethod(...)
  16. //
  17. // Copyright <cp> 2000-2001 Microsoft Corporation. All Rights Reserved.
  18. //
  19. //-----------------------------------------------------------------------------
  20. #if !defined(_SOAPHELPER_H_)
  21. #define _SOAPHELPER_H_
  22. #pragma once
  23. #ifndef Assert
  24. #define Assert ATLASSERT
  25. #endif
  26. // SOAP content type
  27. #define CZ_SOAP_CONTENTTYPE "text/xml; charset=\"utf-8\""
  28. #define CZ_SOAP_CONTENTTYPEBASIC "text/xml"
  29. #define ERR_XML_FORMAT "Incorrect xml data"
  30. #define ERR_SOAP_ENVELOPE "Incorrect SOAP envelope, or SOAP envelope is missing "
  31. #define ERR_SOAP_BODY "Incorrect SOAP body, or SOAP body is missing"
  32. #define ERR_SOAP_METHOD "Incorrect method, or SOAP method is missing"
  33. #define ERR_SOAP_PARAM "Incorrect parameter: "
  34. #define SOAP_FAULT "Fault"
  35. #define SOAP_FAULT_CODE "faultcode"
  36. #define SOAP_FAULT_STRING "faultstring"
  37. #define SOAP_FAULT_DETAIL "detail"
  38. #define SOAP_ENV_URI "http://schemas.xmlsoap.org/soap/envelope/"
  39. #define SOAP_ENC_URI "http://schemas.xmlsoap.org/soap/encoding/"
  40. #define SOAP_ENV_NS "SOAP-ENV"
  41. #define SOAP_ENV_NAME "Envelope"
  42. #define SOAP_ENV_BODY "Body"
  43. #define SOAP_ENV_NAME_TAG SOAP_ENV_NS ":" SOAP_ENV_NAME
  44. #define SOAP_ENV_BODY_TAG SOAP_ENV_NS ":" SOAP_ENV_BODY
  45. #define XML_V10 "<?xml version=\"1.0\"?>"
  46. /*
  47. xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  48. SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/
  49. */
  50. #define SOAP_NS_URI "xmlns:" SOAP_ENV_NS "=\'" SOAP_ENV_URI "\'\n" \
  51. SOAP_ENV_NS ":encodingStyle=\'" SOAP_ENC_URI "\'"
  52. // change string to unicode
  53. #define W(n) __WIDECHAR__(n)
  54. #define __WIDECHAR__(n) L ## n
  55. // open & close tag string macros
  56. #define OPENTAG_NS(nm,ns) "<" ## nm ## " " ## ns ">"
  57. #define OPENTAG(t) "<" ## t ## ">"
  58. #define CLOSETAG(t) "</" ## t ## ">"
  59. /*
  60. <?xml version="1.0"?>\r\n
  61. <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">\r\n
  62. <SOAP:Body>
  63. */
  64. #define SOAPEnvelope_Body_Open XML_V10 OPENTAG_NS(SOAP_ENV_NAME_TAG, SOAP_NS_URI) OPENTAG(SOAP_ENV_BODY_TAG)
  65. /*
  66. </SOAP:Body>
  67. </SOAP:Envelope>
  68. */
  69. #define SOAPEnvelope_Body_Close CLOSETAG(SOAP_ENV_BODY_TAG) CLOSETAG(SOAP_ENV_NAME_TAG)
  70. class SOAPHelper;
  71. #define MAX_PARAM_LENGTH 64
  72. #define MAX_PARAM_COUNT 64
  73. ///////////////////////////////////////////////////////////////////////////////////
  74. //
  75. // CLASS ParamMap
  76. //
  77. // Class to contain a mapping of parameters read from a SOAP Request and written
  78. // to a response.
  79. //
  80. ///////////////////////////////////////////////////////////////////////////////////
  81. class ParamMap
  82. {
  83. private:
  84. friend class SOAPHelper;
  85. struct Param
  86. {
  87. WCHAR name[MAX_PARAM_LENGTH + 1];
  88. VARIANT value;
  89. };
  90. public:
  91. UINT Size() { return cnt;};
  92. BOOL Get(UINT index, LPCWSTR* pName, VARIANT** pVal)
  93. {
  94. if ( index >= cnt ) return FALSE;
  95. *pName = params[index].name;
  96. *pVal = &params[index].value;
  97. return TRUE;
  98. };
  99. VARIANT* Find(LPCWSTR name)
  100. {
  101. for(UINT i = 0; i < cnt; ++i)
  102. {
  103. if(wcsncmp(params[i].name, name, MAX_PARAM_LENGTH) == 0)
  104. return &params[i].value;
  105. };
  106. return NULL;
  107. };
  108. public:
  109. // note: parameter pVar will be skin level copied, NOT VariantCopied ...
  110. // note: parameter pVar will be set to VT_EMPTY after this call
  111. HRESULT AddParam(LPCWSTR name, VARIANT* pVar)
  112. {
  113. Assert(name);
  114. Assert(pVar);
  115. if(cnt >= MAX_PARAM_COUNT) return S_FALSE;
  116. wcsncpy(params[cnt].name, name, MAX_PARAM_LENGTH);
  117. params[cnt].value = *pVar;
  118. ++cnt;
  119. VariantInit(pVar);
  120. return S_OK;
  121. };
  122. public:
  123. ParamMap() : cnt(0) { };
  124. virtual ~ParamMap()
  125. {
  126. for (UINT i = 0; i < cnt; ++i)
  127. {
  128. VariantClear(&params[i].value);
  129. }
  130. };
  131. private:
  132. Param params[MAX_PARAM_COUNT];
  133. UINT cnt;
  134. };
  135. ///////////////////////////////////////////////////////////////////////////////////
  136. ///////////////////////////////////////////////////////////////////////////////////
  137. //
  138. // CLASS SOAPHelper
  139. //
  140. // Class of static methods and definitions to help in processing
  141. // SOAP requests and responses
  142. //
  143. ///////////////////////////////////////////////////////////////////////////////////
  144. class SOAPHelper
  145. {
  146. public:
  147. //
  148. // GetParameters(...)
  149. //
  150. // retrieve the parameters from a given ECB
  151. //the method name, content type are checked
  152. //
  153. static HRESULT GetParameters(IN EXTENSION_CONTROL_BLOCK* pECB,
  154. IN LPCWSTR pcwszMethodName,
  155. OUT ParamMap& mapParams,
  156. OUT VARIANT_BOOL& bParsedOK,
  157. OUT CStringW& strParseErr);
  158. //
  159. // GenerateResponse(...)
  160. //
  161. // generate soap response package with given paramters
  162. // content type is returned from this call
  163. //
  164. static HRESULT GenerateResponse(
  165. IN LPCWSTR pcwszMethodName,
  166. IN ParamMap& mapParams,
  167. OUT CHeapPtr<char>& body,
  168. OUT CStringA& contentType);
  169. //
  170. // GenerateFaultSOAPEnvelope (...)
  171. //
  172. // generate soap fault package with the passed in parameters.
  173. //
  174. static HRESULT GenerateFaultSOAPEnvelope(IN DWORD dwFaultCode,
  175. IN LPCSTR pcszFaultString,
  176. IN LPCSTR pcszFaultActor,
  177. IN LPCSTR pcszDetail,
  178. OUT CStringA& faultEnvelope);
  179. //
  180. // GetFaultSOAPEnvelopeDetail(...)
  181. //
  182. // get error details from a soap fault package
  183. //
  184. static HRESULT GetFaultSOAPEnvelopeDetail(IN BSTR faultEnvelope,
  185. OUT CStringW& faultCode,
  186. OUT CStringW& faultString,
  187. OUT CStringW& faultDetail);
  188. //
  189. // GenerateSOAPEnvelope(...)
  190. //
  191. static HRESULT GenerateSOAPEnvelope(ParamMap& mapParams,
  192. LPCWSTR pcwszMethodName,
  193. BSTR* envelope);
  194. //
  195. // ParseSOAPEnvelope(...)
  196. //
  197. static HRESULT ParseSOAPEnvelope(ParamMap& mapParams,
  198. LPCWSTR pcwszMethodName,
  199. BSTR bstrSoapEnvelope,
  200. VARIANT_BOOL* pbParsedOK,
  201. BSTR* pbstrErrorMsg);
  202. //
  203. // GetSOAPMethod(...)
  204. //
  205. // Returns the full SOAP method name.
  206. //
  207. static HRESULT GetSOAPMethod(EXTENSION_CONTROL_BLOCK* pECB,
  208. LPCSTR path,
  209. CStringW& out_cszMethod);
  210. //
  211. // GetShortSOAPMethod(...)
  212. //
  213. // Returns the abbreviated method name, all in lowercase. The abbreviated name consists
  214. // of everything in the full name (see above function) after the "#"
  215. //
  216. static HRESULT GetShortSOAPMethod(EXTENSION_CONTROL_BLOCK* pECB,
  217. LPCSTR path,
  218. CStringW& out_cszMethod);
  219. //
  220. // CheckSOAPMethod(...)
  221. //
  222. // Checks to determine presence of the passed in method.
  223. // pRet will contain TRUE of the method exists, and FALSE otherwize.
  224. //
  225. static HRESULT CheckSOAPMethod(EXTENSION_CONTROL_BLOCK* pECB,
  226. LPCSTR pcszMethod,
  227. LPCSTR pcszPath,
  228. BOOL* pRet);
  229. // SOAP Fault codes. Taken from SOAP 1.1 specification.
  230. // The numbers associated are arbitrary (i think). Either way
  231. // they're never shown to the user
  232. static const UINT SOAP_FAULT_NONE = 0; // This is NOT a SOAP code, but we needed an "unset" value.
  233. static const UINT SOAP_FAULT_VERSIONMISMATCH = 100;
  234. static const UINT SOAP_FAULT_MUSTUNDERSTAND = 200;
  235. static const UINT SOAP_FAULT_CLIENT = 300;
  236. static const UINT SOAP_FAULT_SERVER = 400;
  237. };
  238. ///////////////////////////////////////////////////////////////////////////////////
  239. #endif //!defined(_SOAPHELPER_H_)