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.

358 lines
9.1 KiB

  1. /*
  2. * X M E T A . H
  3. *
  4. * XML push-model parsing for METADATA
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #ifndef _XMETA_H_
  9. #define _XMETA_H_
  10. #include <xprs.h>
  11. // Parsers -------------------------------------------------------------------
  12. //
  13. // METADATA ------------------------------------------------------------------
  14. //
  15. // The metadata processing for DAV is all done via the PROPFIND and PROPPATCH
  16. // (and to some extent, SEARCH) methods. In all of these cases, there is an
  17. // xml request that must be parsed to determine the state of type of request
  18. // being made. Once known, the request is applied to the resource and/or its
  19. // children. The response is generated and emitted back to the client.
  20. //
  21. // In some cases, the client may ask for the operation to be carried out for
  22. // a resource and for each of its children. In this scenario, we do not want
  23. // to reprocess the request for each resource, etc.
  24. //
  25. // In an effort to make this code simple, and extendable to each individual
  26. // DAV implementation, the processing uses four classes:
  27. //
  28. // a parsing class
  29. // a class describing the parsed context
  30. // a class that provides access to the properties
  31. // and a class that is used to generate the response
  32. //
  33. // Both the parser and emitter classes are common across all DAV impls. While
  34. // the context and the property access are provided by the impl.
  35. //
  36. // CFindContext/CPatchContext ------------------------------------------------
  37. //
  38. // The context for a PROPFIND and a PROPGET are not expected to be the same,
  39. // and as such can be implemented as different objects.
  40. //
  41. class CFindContext
  42. {
  43. // non-implemented operators
  44. //
  45. CFindContext( const CFindContext& );
  46. CFindContext& operator=( const CFindContext& );
  47. protected:
  48. typedef enum {
  49. FIND_NONE,
  50. FIND_SPECIFIC,
  51. FIND_ALL,
  52. FIND_NAMES,
  53. FIND_ALL_FULL,
  54. FIND_NAMES_FULL
  55. } FINDTYPE;
  56. FINDTYPE m_ft;
  57. public:
  58. CFindContext()
  59. : m_ft(FIND_NONE)
  60. {
  61. }
  62. virtual ~CFindContext() {}
  63. // When the parser finds an item that the client wants returned,
  64. // the item is added to the context via the following set context
  65. // methods. Each add is qualified by the resource on which the
  66. // request is made. Some propfind requests support editing of the
  67. // proplists: for example DAVEX implementation supports full-fidelity
  68. // retrieval with certain properties added or deleted from the response
  69. // that would have normally returned by the request. The BOOL flag is
  70. // used to indicate whether the prop needs to be excluded.
  71. //
  72. virtual SCODE ScAddProp(LPCWSTR pwszPath, LPCWSTR pwszProp, BOOL fExcludeProp) = 0;
  73. // defines for readability for the BOOL fExcludeProp param above.
  74. //
  75. enum {
  76. FIND_PROPLIST_INCLUDE = FALSE,
  77. FIND_PROPLIST_EXCLUDE = TRUE
  78. };
  79. virtual SCODE ScGetAllProps(LPCWSTR)
  80. {
  81. // If we have already specified a find method, and the
  82. // xml indicated another type was expected, then BTS
  83. // (by the spec) this should consititute an error.
  84. //
  85. if (m_ft != FIND_NONE)
  86. {
  87. DebugTrace ("Dav: multiple PROPFIND types indicated\n");
  88. return E_DAV_PROPFIND_TYPE_UNEXPECTED;
  89. }
  90. m_ft = FIND_ALL;
  91. return S_OK;
  92. }
  93. virtual SCODE ScGetAllNames (LPCWSTR)
  94. {
  95. // If we have already specified a find method, and the
  96. // xml indicated another type was expected, then BTS
  97. // (by the spec) this should consititute an error.
  98. //
  99. if (m_ft != FIND_NONE)
  100. {
  101. DebugTrace ("Dav: multiple PROPFIND types indicated\n");
  102. return E_DAV_PROPFIND_TYPE_UNEXPECTED;
  103. }
  104. m_ft = FIND_NAMES;
  105. return S_OK;
  106. }
  107. virtual SCODE ScGetFullFidelityProps ()
  108. {
  109. // If we have full fidelity node (it is a child node of
  110. // allprop or propname node) then we should allready
  111. // be in the state of FIND_ALL or FIND_NAMES. Do not
  112. // shift to full fidelity lookup, let the deriving classes
  113. // decide if they need that.
  114. //
  115. Assert((FIND_ALL == m_ft) || (FIND_NAMES == m_ft));
  116. return S_OK;
  117. }
  118. //$REVIEW: Make the default behavior of the following methods
  119. //$REVIEW: to ignore the report tags. it's up to the impl which understands
  120. //$REVIEW: reports to overwrite these methods
  121. //
  122. virtual SCODE ScEnumReport () { return S_OK; }
  123. virtual SCODE ScSetReportName (ULONG ulLen, LPCWSTR pwszName) { return S_OK; }
  124. virtual SCODE ScSetReportLimit (ULONG ulLen, LPCWSTR pwszLimit) { return S_OK; }
  125. };
  126. class CPatchContext
  127. {
  128. // non-implemented operators
  129. //
  130. CPatchContext( const CPatchContext& );
  131. CPatchContext& operator=( const CPatchContext& );
  132. public:
  133. CPatchContext() {}
  134. virtual ~CPatchContext() {}
  135. // When the parser finds an item that the client wants operated on,
  136. // the item is added to the context via the following set context
  137. // methods. Each request is qualified by the resource on which the
  138. // request is made.
  139. //
  140. virtual SCODE ScDeleteProp(LPCWSTR pwszPath, LPCWSTR pwszProp) = 0;
  141. virtual SCODE ScSetProp(LPCWSTR pwszPath,
  142. LPCWSTR pwszProp,
  143. auto_ref_ptr<CPropContext>& pPropCtx) = 0;
  144. // If parser finds a resourcetype prop set request, we use this function
  145. // to set correct behavior
  146. //
  147. virtual void SetCreateStructureddocument(void) {};
  148. };
  149. // class CNFFind -------------------------------------------------------------
  150. //
  151. class CNFFind : public CNodeFactory
  152. {
  153. protected:
  154. // The find context
  155. //
  156. CFindContext& m_cfc;
  157. // State tracking
  158. //
  159. typedef enum {
  160. ST_NODOC,
  161. ST_PROPFIND,
  162. ST_ALLPROP,
  163. ST_ALLNAMES,
  164. ST_PROPS,
  165. ST_INPROP,
  166. ST_ENUMREPORT,
  167. ST_INENUMREPORT,
  168. ST_ENUMLIMIT,
  169. ST_ALLPROPFULL,
  170. ST_ALLNAMESFULL,
  171. ST_ALLPROP_INCLUDE,
  172. ST_ALLPROP_INCLUDE_INPROP,
  173. ST_ALLPROP_EXCLUDE,
  174. ST_ALLPROP_EXCLUDE_INPROP
  175. } FIND_PARSE_STATE;
  176. FIND_PARSE_STATE m_state;
  177. private:
  178. // non-implemented
  179. //
  180. CNFFind(const CNFFind& p);
  181. CNFFind& operator=(const CNFFind& p);
  182. public:
  183. virtual ~CNFFind() {};
  184. CNFFind(CFindContext& cfc)
  185. : m_cfc(cfc),
  186. m_state(ST_NODOC)
  187. {
  188. }
  189. // CNodeFactory specific methods
  190. //
  191. virtual SCODE ScCompleteAttribute (void);
  192. virtual SCODE ScCompleteChildren (
  193. /* [in] */ BOOL fEmptyNode,
  194. /* [in] */ DWORD dwType,
  195. /* [in] */ const WCHAR __RPC_FAR *pwcText,
  196. /* [in] */ ULONG ulLen);
  197. virtual SCODE ScHandleNode (
  198. /* [in] */ DWORD dwType,
  199. /* [in] */ DWORD dwSubType,
  200. /* [in] */ BOOL fTerminal,
  201. /* [in] */ const WCHAR __RPC_FAR *pwcText,
  202. /* [in] */ ULONG ulLen,
  203. /* [in] */ ULONG ulNamespaceLen,
  204. /* [in] */ const WCHAR __RPC_FAR *pwcNamespace,
  205. /* [in] */ const ULONG ulNsPrefixLen);
  206. };
  207. // class CNFFind -------------------------------------------------------------
  208. //
  209. class CNFPatch : public CNodeFactory
  210. {
  211. protected:
  212. // The patch context
  213. //
  214. CPatchContext& m_cpc;
  215. // State tracking
  216. //
  217. typedef enum {
  218. ST_NODOC,
  219. ST_UPDATE,
  220. ST_SET,
  221. ST_DELETE,
  222. ST_PROPS,
  223. ST_INPROP,
  224. ST_INMVPROP,
  225. ST_SEARCHREQUEST,
  226. ST_RESOURCETYPE,
  227. ST_STRUCTUREDDOCUMENT,
  228. ST_LEXTYPE,
  229. ST_FLAGS
  230. } PATCH_PARSE_STATE;
  231. PATCH_PARSE_STATE m_state;
  232. // XML value echoing to m_xo object
  233. //
  234. typedef enum {
  235. VE_NOECHO,
  236. VE_NEEDNS,
  237. VE_INPROGRESS
  238. } PATCH_VALUE_ECHO;
  239. PATCH_VALUE_ECHO m_vestate;
  240. // Check if an element we are setting
  241. // if an XML valued property
  242. //
  243. BOOL FValueIsXML( const WCHAR *pwcTag );
  244. private:
  245. // Current property context
  246. //
  247. // Property context is only used in property set and it is NULL
  248. // when the prop to set is a reserved property
  249. //
  250. PATCH_PARSE_STATE m_sType;
  251. auto_ref_ptr<CPropContext> m_ppctx;
  252. // Values for properties (and attributes) can be
  253. // composed of mulitple items in the XML document
  254. // and thus need to be stored until they are complete
  255. // and can be handed off to the context
  256. //
  257. StringBuffer<WCHAR> m_sbValue;
  258. UINT m_cmvValues;
  259. CXMLOut m_xo;
  260. SCODE ScHandleElementNode (
  261. /* [in] */ DWORD dwType,
  262. /* [in] */ DWORD dwSubType,
  263. /* [in] */ BOOL fTerminal,
  264. /* [in] */ const WCHAR __RPC_FAR *pwcText,
  265. /* [in] */ ULONG ulLen,
  266. /* [in] */ ULONG ulNamespaceLen,
  267. /* [in] */ const WCHAR __RPC_FAR *pwcNamespace,
  268. /* [in] */ const ULONG ulNsPrefixLen);
  269. // non-implemented
  270. //
  271. CNFPatch(const CNFPatch& p);
  272. CNFPatch& operator=(const CNFPatch& p);
  273. public:
  274. virtual ~CNFPatch() {};
  275. CNFPatch(CPatchContext& cpc)
  276. : m_cpc(cpc),
  277. m_state(ST_NODOC),
  278. m_vestate(VE_NOECHO),
  279. m_cmvValues(0),
  280. m_xo(m_sbValue)
  281. {
  282. }
  283. // CNodeFactory specific methods
  284. //
  285. virtual SCODE ScCompleteAttribute (void);
  286. virtual SCODE ScCompleteChildren (
  287. /* [in] */ BOOL fEmptyNode,
  288. /* [in] */ DWORD dwType,
  289. /* [in] */ const WCHAR __RPC_FAR *pwcText,
  290. /* [in] */ ULONG ulLen);
  291. virtual SCODE ScHandleNode (
  292. /* [in] */ DWORD dwType,
  293. /* [in] */ DWORD dwSubType,
  294. /* [in] */ BOOL fTerminal,
  295. /* [in] */ const WCHAR __RPC_FAR *pwcText,
  296. /* [in] */ ULONG ulLen,
  297. /* [in] */ ULONG ulNamespaceLen,
  298. /* [in] */ const WCHAR __RPC_FAR *pwcNamespace,
  299. /* [in] */ const ULONG ulNsPrefixLen);
  300. virtual SCODE ScCompleteCreateNode (
  301. /* [in] */ DWORD dwType);
  302. };
  303. #endif // _XMETA_H_