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.

730 lines
32 KiB

  1. // --------------------------------------------------------------------------------
  2. // Ixphttpm.h
  3. // Copyright (c)1998 Microsoft Corporation, All Rights Reserved
  4. // Greg Friedman
  5. // --------------------------------------------------------------------------------
  6. #ifndef __IXPHTTPM_H
  7. #define __IXPHTTPM_H
  8. // --------------------------------------------------------------------------------
  9. // Includes
  10. // --------------------------------------------------------------------------------
  11. #include <stddef.h> // for offsetof
  12. #include "wininet.h"
  13. #include "propfind.h"
  14. #include "xmlparser.h"
  15. #include "davparse.h"
  16. // --------------------------------------------------------------------------------
  17. // constants
  18. // --------------------------------------------------------------------------------
  19. #define ELE_STACK_CAPACITY 7
  20. #define HTTPMAIL_BUFSIZE 4048
  21. #define PCDATA_BUFSIZE 1024
  22. // optional headers added to http requests
  23. #define RH_NOROOT 0x00000001
  24. #define RH_ALLOWRENAME 0x00000002
  25. #define RH_TRANSLATEFALSE 0x00000004
  26. #define RH_TRANSLATETRUE 0x00000008
  27. #define RH_XMLCONTENTTYPE 0x00000010
  28. #define RH_MESSAGECONTENTTYPE 0x00000020
  29. #define RH_SMTPMESSAGECONTENTTYPE 0x00000040
  30. #define RH_BRIEF 0x00000080
  31. #define RH_SAVEINSENTTRUE 0x00000100
  32. #define RH_SAVEINSENTFALSE 0x00000200
  33. #define RH_ROOTTIMESTAMP 0x00000400
  34. #define RH_FOLDERTIMESTAMP 0x00000800
  35. #define RH_ADDCHARSET 0x00001000
  36. // --------------------------------------------------------------------------------
  37. // Forward declarations
  38. // --------------------------------------------------------------------------------
  39. class CHTTPMailTransport;
  40. // --------------------------------------------------------------------------------
  41. // root props
  42. // --------------------------------------------------------------------------------
  43. typedef struct tagROOTPROPS
  44. {
  45. LPSTR pszAdbar;
  46. LPSTR pszContacts;
  47. LPSTR pszInbox;
  48. LPSTR pszOutbox;
  49. LPSTR pszSendMsg;
  50. LPSTR pszSentItems;
  51. LPSTR pszDeletedItems;
  52. LPSTR pszDrafts;
  53. LPSTR pszMsgFolderRoot;
  54. LPSTR pszSig;
  55. DWORD dwMaxPollingInterval;
  56. } ROOTPROPS, *LPROOTPROPS;
  57. // --------------------------------------------------------------------------------
  58. // Schemas used for XML parsing
  59. // --------------------------------------------------------------------------------
  60. // --------------------------------------------------------------------------------
  61. // XPCOLUMNDATATYPE
  62. // --------------------------------------------------------------------------------
  63. typedef enum tagXPCOLUMNDATATYPE
  64. {
  65. XPCDT_STRA,
  66. XPCDT_DWORD,
  67. XPCDT_BOOL,
  68. XPCDT_IXPHRESULT,
  69. XPCDT_HTTPSPECIALFOLDER,
  70. XPCDT_HTTPCONTACTTYPE,
  71. XPCDT_LASTTYPE
  72. } XPCOLUMNDATATYPE;
  73. // --------------------------------------------------------------------------------
  74. // XPCOLUMN FLAGS
  75. // --------------------------------------------------------------------------------
  76. #define XPCF_PFREQUEST 0x00000001 // include in propfind request
  77. #define XPCF_MSVALIDMSRESPONSECHILD 0x00000002 // during parse - validate that the ele stack is correct for a child of a <response> in a <multistatus> response
  78. #define XPCF_MSVALIDPROP 0x00000004 // during parse - validate that the stack is correct for a propvalue in an ms response
  79. #define XPCF_DONTSETFLAG 0x00000008 // don't set the found flag when parsing
  80. #define XPFC_PROPFINDPROP (XPCF_PFREQUEST | XPCF_MSVALIDPROP)
  81. #define XPCF_PROPFINDHREF (XPCF_MSVALIDMSRESPONSECHILD | XPCF_DONTSETFLAG)
  82. // --------------------------------------------------------------------------------
  83. // XPCOLUMN
  84. // --------------------------------------------------------------------------------
  85. typedef struct tagXPCOLUMN
  86. {
  87. HMELE ele;
  88. DWORD dwFlags;
  89. XPCOLUMNDATATYPE cdt;
  90. DWORD offset;
  91. } XPCOLUMN, *LPXPCOLUMN;
  92. // --------------------------------------------------------------------------------
  93. // XP_BEGIN_SCHEMA
  94. // --------------------------------------------------------------------------------
  95. #define XP_BEGIN_SCHEMA(opName) \
  96. static const XPCOLUMN c_rg##opName##Schema[] = {
  97. // --------------------------------------------------------------------------------
  98. // XP_SCHEMA_COL
  99. // --------------------------------------------------------------------------------
  100. #define XP_SCHEMA_COL(ele, dwFlags, cdt, tyStruct, fieldName ) \
  101. { ele, dwFlags, cdt, offsetof(tyStruct, fieldName) },
  102. // --------------------------------------------------------------------------------
  103. // XP_END_SCHEMA
  104. // --------------------------------------------------------------------------------
  105. #define XP_END_SCHEMA \
  106. };
  107. // --------------------------------------------------------------------------------
  108. // XP_FREE_STRUCT
  109. // --------------------------------------------------------------------------------
  110. #define XP_FREE_STRUCT(opName, target, flags) \
  111. _FreeStruct(c_rg##opName##Schema, ARRAYSIZE(c_rg##opName##Schema), target, flags)
  112. // --------------------------------------------------------------------------------
  113. // XP_BIND_TO_STRUCT
  114. // --------------------------------------------------------------------------------
  115. #define XP_BIND_TO_STRUCT(opName, pwcText, ulLen, target, wasBound) \
  116. _BindToStruct(pwcText, ulLen, c_rg##opName##Schema, ARRAYSIZE(c_rg##opName##Schema), target, wasBound)
  117. // --------------------------------------------------------------------------------
  118. // XP_CREATE_PROPFIND_REQUEST
  119. // --------------------------------------------------------------------------------
  120. #define XP_CREATE_PROPFIND_REQUEST(opName, pRequest) \
  121. HrAddPropFindSchemaProps(pRequest, c_rg##opName##Schema, ARRAYSIZE(c_rg##opName##Schema))
  122. // --------------------------------------------------------------------------------
  123. // State Machine Funcs
  124. // --------------------------------------------------------------------------------
  125. typedef HRESULT (CHTTPMailTransport::*PFNHTTPMAILOPFUNC)(void);
  126. // --------------------------------------------------------------------------------
  127. // XML Parsing Funcs
  128. // --------------------------------------------------------------------------------
  129. typedef HRESULT (CHTTPMailTransport::*PFNCREATEELEMENT)(CXMLNamespace *pBaseNamespace, const WCHAR *pwcText, ULONG ulLen, ULONG ulNamespaceLen, BOOL fTerminal);
  130. typedef HRESULT (CHTTPMailTransport::*PFNHANDLETEXT)(const WCHAR *pwcText, ULONG ulLen);
  131. typedef HRESULT (CHTTPMailTransport::*PFNENDCHILDREN)(void);
  132. typedef struct tagXMLPARSEFUNCS
  133. {
  134. PFNCREATEELEMENT pfnCreateElement;
  135. PFNHANDLETEXT pfnHandleText;
  136. PFNENDCHILDREN pfnEndChildren;
  137. } XMLPARSEFUNCS, *LPXMLPARSEFUNCS;
  138. // --------------------------------------------------------------------------------
  139. // Utility functions
  140. // --------------------------------------------------------------------------------
  141. HRESULT HrParseHTTPStatus(LPSTR pszStatusStr, DWORD *pdwStatus);
  142. HRESULT HrAddPropFindProps(IPropFindRequest *pRequest, const HMELE *rgEle, DWORD cEle);
  143. HRESULT HrAddPropFindSchemaProps(IPropFindRequest *pRequest, const XPCOLUMN *prgCols, DWORD cCols);
  144. HRESULT _HrGenerateRfc821Stream(LPCSTR pszFrom, LPHTTPTARGETLIST pTargets, IStream **ppRfc821Stream);
  145. HRESULT HrGeneratePostContactXML(LPHTTPCONTACTINFO pciInfo, LPVOID *ppvXML, DWORD *pdwLen);
  146. HRESULT HrCreatePatchContactRequest(LPHTTPCONTACTINFO pciInfo, IPropPatchRequest **ppRequest);
  147. HRESULT HrGenerateSimpleBatchXML(LPCSTR pszRootName, LPHTTPTARGETLIST pTargets, LPVOID *ppvXML, DWORD *pdwLen);
  148. HRESULT HrGenerateMultiDestBatchXML(LPCSTR pszRootName, LPHTTPTARGETLIST pTargets, LPHTTPTARGETLIST pDestinations, LPVOID *ppvXML, DWORD *pdwLen);
  149. HRESULT HrCopyStringList(LPCSTR *rgszInList, LPCSTR **prgszOutList);
  150. void FreeStringList(LPCSTR *rgszInList);
  151. typedef struct tagHTTPQUEUEDOP
  152. {
  153. HTTPMAILCOMMAND command;
  154. const PFNHTTPMAILOPFUNC *pfnState;
  155. int cState;
  156. LPSTR pszUrl;
  157. LPSTR pszDestination;
  158. LPCSTR pszContentType;
  159. LPVOID pvData;
  160. ULONG cbDataLen;
  161. DWORD dwContext;
  162. DWORD dwDepth;
  163. DWORD dwRHFlags;
  164. MEMBERINFOFLAGS dwMIFlags;
  165. HTTPMAILPROPTYPE tyProp;
  166. BOOL fBatch;
  167. LPCSTR *rgszAcceptTypes;
  168. IPropFindRequest *pPropFindRequest;
  169. IPropPatchRequest *pPropPatchRequest;
  170. IStream *pHeaderStream;
  171. IStream *pBodyStream;
  172. const XMLPARSEFUNCS *pParseFuncs;
  173. struct tagHTTPQUEUEDOP *pNext;
  174. // Used with Folders PropFind and Inbox PropFind.
  175. LPSTR pszFolderTimeStamp;
  176. // Used only with Folders PropFind.
  177. LPSTR pszRootTimeStamp;
  178. } HTTPQUEUEDOP, *LPHTTPQUEUEDOP;
  179. typedef struct tagPCDATABUFFER
  180. {
  181. WCHAR *pwcText;
  182. ULONG ulLen;
  183. ULONG ulCapacity;
  184. } PCDATABUFFER, *LPPCDATABUFFER;
  185. typedef struct tagHMELESTACK
  186. {
  187. HMELE ele;
  188. CXMLNamespace *pBaseNamespace;
  189. BOOL fBeganChildren;
  190. LPPCDATABUFFER pTextBuffer;
  191. } HMELESTACK, *LPHMELESTACK;
  192. typedef struct tagHTTPMAILOPERATION
  193. {
  194. const PFNHTTPMAILOPFUNC *pfnState;
  195. int iState;
  196. int cState;
  197. BOOL fLoggedResponse;
  198. LPSTR pszUrl;
  199. LPSTR pszDestination;
  200. LPCSTR pszContentType;
  201. LPVOID pvData;
  202. ULONG cbDataLen;
  203. DWORD dwContext;
  204. DWORD dwHttpStatus; // http response status
  205. LPCSTR *rgszAcceptTypes;
  206. HINTERNET hRequest;
  207. BOOL fAborted;
  208. DWORD dwDepth;
  209. DWORD dwRHFlags;
  210. MEMBERINFOFLAGS dwMIFlags;
  211. HTTPMAILPROPTYPE tyProp;
  212. BOOL fBatch;
  213. IPropFindRequest *pPropFindRequest;
  214. IPropPatchRequest *pPropPatchRequest;
  215. LPPCDATABUFFER pTextBuffer;
  216. IStream *pHeaderStream;
  217. IStream *pBodyStream;
  218. // xml parsing
  219. const XMLPARSEFUNCS *pParseFuncs;
  220. CXMLNamespace *pTopNamespace;
  221. DWORD dwStackDepth;
  222. HMELESTACK rgEleStack[ELE_STACK_CAPACITY];
  223. // PropFind Parsing
  224. BOOL fFoundStatus;
  225. DWORD dwStatus;
  226. DWORD dwPropFlags;
  227. // response
  228. HTTPMAILRESPONSE rResponse;
  229. // Used with Folders PropFind and Inbox PropFind.
  230. LPSTR pszFolderTimeStamp;
  231. // Used only with Folders PropFind.
  232. LPSTR pszRootTimeStamp;
  233. } HTTPMAILOPERATION, *LPHTTPMAILOPERATION;
  234. class CHTTPMailTransport : public IHTTPMailTransport, public IXMLNodeFactory, public IHTTPMailTransport2
  235. {
  236. private:
  237. ULONG m_cRef; // Reference Count
  238. BOOL m_fHasServer; // Has been initialized with a server
  239. BOOL m_fHasRootProps; // Root props have been retrieved
  240. BOOL m_fTerminating; // in the terminating state...killing the iothread
  241. IXPSTATUS m_status; // Connection status
  242. HINTERNET m_hInternet; // Root wininet handle
  243. HINTERNET m_hConnection; // Connection handle
  244. LPSTR m_pszUserAgent; // user agent string
  245. ILogFile *m_pLogFile; // Logfile Object
  246. IHTTPMailCallback *m_pCallback; // Transport callback object
  247. IXMLParser *m_pParser; // xml parser
  248. HWND m_hwnd; // Window used for event synchronization
  249. HANDLE m_hevPendingCommand; // Event object that signals a pending command
  250. LPHTTPQUEUEDOP m_opPendingHead; // Pending operation - head of the queue
  251. LPHTTPQUEUEDOP m_opPendingTail; // Pending operation - tail of the queue
  252. CRITICAL_SECTION m_cs; // Thread Safety
  253. HTTPMAILOPERATION m_op; // current operation
  254. INETSERVER m_rServer; // Internet server
  255. LPSTR m_pszCurrentHost; // current server
  256. INTERNET_PORT m_nCurrentPort; // current port
  257. ROOTPROPS m_rootProps;
  258. public:
  259. // ----------------------------------------------------------------------------
  260. // Construction
  261. // ----------------------------------------------------------------------------
  262. CHTTPMailTransport(void);
  263. virtual ~CHTTPMailTransport(void);
  264. // ----------------------------------------------------------------------------
  265. // Unimplemented copy constructor and assignment operator
  266. // ----------------------------------------------------------------------------
  267. private:
  268. CHTTPMailTransport(const CHTTPMailTransport& other); // intentionally unimplemented
  269. CHTTPMailTransport& operator=(const CHTTPMailTransport& other); // intentionally unimplemented
  270. public:
  271. // ----------------------------------------------------------------------------
  272. // IUnknown methods
  273. // ----------------------------------------------------------------------------
  274. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  275. STDMETHODIMP_(ULONG) AddRef(void);
  276. STDMETHODIMP_(ULONG) Release(void);
  277. // ----------------------------------------------------------------------------
  278. // IInternetTransport methods
  279. // ----------------------------------------------------------------------------
  280. STDMETHODIMP Connect(LPINETSERVER pInetServer, boolean fAuthenticate, boolean fCommandLogging);
  281. STDMETHODIMP DropConnection(void);
  282. STDMETHODIMP Disconnect(void);
  283. STDMETHODIMP IsState(IXPISSTATE isstate);
  284. STDMETHODIMP GetServerInfo(LPINETSERVER pInetServer);
  285. STDMETHODIMP_(IXPTYPE) GetIXPType(void);
  286. STDMETHODIMP InetServerFromAccount(IImnAccount *pAccount, LPINETSERVER pInetServer);
  287. STDMETHODIMP HandsOffCallback(void);
  288. STDMETHODIMP GetStatus(IXPSTATUS *pCurrentStatus);
  289. // ----------------------------------------------------------------------------
  290. // IHTTPMailTransport methods
  291. // ----------------------------------------------------------------------------
  292. STDMETHODIMP InitNew(LPCSTR pszUserAgent, LPCSTR pszLogFilePath, IHTTPMailCallback *pCallback);
  293. STDMETHODIMP GetProperty(HTTPMAILPROPTYPE proptype, LPSTR *ppszProp);
  294. STDMETHODIMP GetPropertyDw(HTTPMAILPROPTYPE proptype, LPDWORD lpdwProp);
  295. STDMETHODIMP CommandGET(LPCSTR pszPath, LPCSTR *rgszAcceptTypes, BOOL fTranslate, DWORD dwContext);
  296. STDMETHODIMP CommandPUT(LPCSTR pszPath, LPVOID lpvData, ULONG cbData, DWORD dwContext);
  297. STDMETHODIMP CommandPOST(LPCSTR pszPath, IStream *pStream, LPCSTR pszContentType, DWORD dwContext);
  298. STDMETHODIMP CommandDELETE(LPCSTR pszPath, DWORD dwContext);
  299. STDMETHODIMP CommandBDELETE(LPCSTR pszPath, LPHTTPTARGETLIST pBatchTargets, DWORD dwContext);
  300. STDMETHODIMP CommandPROPFIND(LPCSTR pszUrl, IPropFindRequest *pRequest, DWORD dwDepth, DWORD dwContext);
  301. STDMETHODIMP CommandPROPPATCH(LPCSTR pszUrl, IPropPatchRequest *pRequest, DWORD dwContext);
  302. STDMETHODIMP CommandMKCOL(LPCSTR pszUrl, DWORD dwContext);
  303. STDMETHODIMP CommandCOPY(LPCSTR pszPath, LPCSTR pszDestination, BOOL fAllowRename, DWORD dwContext);
  304. STDMETHODIMP CommandBCOPY(LPCSTR pszSourceCollection, LPHTTPTARGETLIST pBatchTargets, LPCSTR pszDestCollection, LPHTTPTARGETLIST pBatchDests, BOOL fAllowRename, DWORD dwContext);
  305. STDMETHODIMP CommandMOVE(LPCSTR pszPath, LPCSTR pszDestination, BOOL fAllowRename, DWORD dwContext);
  306. STDMETHODIMP CommandBMOVE(LPCSTR pszSourceCollection, LPHTTPTARGETLIST pBatchTargets, LPCSTR pszDestCollection, LPHTTPTARGETLIST pBatchDests, BOOL fAllowRename, DWORD dwContext);
  307. STDMETHODIMP MemberInfo(LPCSTR pszPath, MEMBERINFOFLAGS flags, DWORD dwDepth, BOOL fIncludeRoot, DWORD dwContext);
  308. STDMETHODIMP FindFolders(LPCSTR pszPath, DWORD dwContext);
  309. STDMETHODIMP MarkRead(LPCSTR pszPath, LPHTTPTARGETLIST pTargets, BOOL fMarkRead, DWORD dwContext);
  310. STDMETHODIMP SendMessage(LPCSTR pszPath, LPCSTR pszFrom, LPHTTPTARGETLIST pTargets, BOOL fSaveInSent, IStream *pMessageStream, DWORD dwContext);
  311. STDMETHODIMP ListContacts(LPCSTR pszPath, DWORD dwContext);
  312. STDMETHODIMP ListContactInfos(LPCSTR pszCollectionPath, DWORD dwContext);
  313. STDMETHODIMP ContactInfo(LPCSTR pszPath, DWORD dwContext);
  314. STDMETHODIMP PostContact(LPCSTR pszPath, LPHTTPCONTACTINFO pciInfo, DWORD dwContext);
  315. STDMETHODIMP PatchContact(LPCSTR pszPath, LPHTTPCONTACTINFO pciInfo, DWORD dwContext);
  316. // ----------------------------------------------------------------------------
  317. // IXMLNodeFactory methods
  318. // ----------------------------------------------------------------------------
  319. STDMETHODIMP NotifyEvent(IXMLNodeSource* pSource, XML_NODEFACTORY_EVENT iEvt);
  320. STDMETHODIMP BeginChildren(IXMLNodeSource* pSource, XML_NODE_INFO *pNodeInfo);
  321. STDMETHODIMP EndChildren(IXMLNodeSource* pSource, BOOL fEmpty, XML_NODE_INFO *pNodeInfo);
  322. STDMETHODIMP Error(IXMLNodeSource* pSource, HRESULT hrErrorCode, USHORT cNumRecs, XML_NODE_INFO** apNodeInfo);
  323. STDMETHODIMP CreateNode(
  324. IXMLNodeSource* pSource,
  325. PVOID pNodeParent,
  326. USHORT cNumRecs,
  327. XML_NODE_INFO** apNodeInfo);
  328. // ----------------------------------------------------------------------------
  329. // IHTTPMailTransport2 methods
  330. // ----------------------------------------------------------------------------
  331. STDMETHODIMP RootMemberInfo( LPCSTR pszPath, MEMBERINFOFLAGS flags, DWORD dwDepth,
  332. BOOL fIncludeRoot, DWORD dwContext, LPSTR pszRootTimeStamp,
  333. LPSTR pszInboxTimeStamp);
  334. STDMETHODIMP FolderMemberInfo( LPCSTR pszPath, MEMBERINFOFLAGS flags, DWORD dwDepth, BOOL fIncludeRoot,
  335. DWORD dwContext, LPSTR pszFolderTimeStamp, LPSTR pszFolderName);
  336. // ----------------------------------------------------------------------------
  337. // New API
  338. // ----------------------------------------------------------------------------
  339. HRESULT HrConnectToHost(LPSTR pszHostName, INTERNET_PORT nPort, LPSTR pszUserName, LPSTR pszPassword);
  340. HRESULT DoLogonPrompt(void);
  341. HRESULT DoGetParentWindow(HWND *phwndParent);
  342. HINTERNET GetConnection(void) { return m_hConnection; }
  343. LPSTR GetServerName(void) { return m_rServer.szServerName; }
  344. LPSTR GetUserName(void) { return ('/0' == m_rServer.szUserName[0]) ? NULL : m_rServer.szUserName; }
  345. LPSTR GetPassword(void) { return ('/0' == m_rServer.szPassword[0]) ? NULL : m_rServer.szPassword; }
  346. IHTTPMailCallback* GetCallback(void) { return m_pCallback; }
  347. HWND GetWindow(void) { return m_hwnd; }
  348. BOOL GetHasRootProps(void) { return m_fHasRootProps; }
  349. void SetHasRootProps(BOOL fHasRootProps) { m_fHasRootProps = fHasRootProps; }
  350. LPSTR GetAdbar(void) { return m_rootProps.pszAdbar; }
  351. void AdoptAdbar(LPSTR pszAdbar) { SafeMemFree(m_rootProps.pszAdbar); m_rootProps.pszAdbar = pszAdbar; }
  352. LPSTR GetContacts(void) { return m_rootProps.pszContacts; }
  353. void AdoptContacts(LPSTR pszContacts) { SafeMemFree(m_rootProps.pszContacts); m_rootProps.pszContacts = pszContacts; }
  354. LPSTR GetInbox(void) { return m_rootProps.pszInbox; }
  355. void AdoptInbox(LPSTR pszInbox) { SafeMemFree(m_rootProps.pszInbox); m_rootProps.pszInbox = pszInbox; }
  356. LPSTR GetOutbox(void) { return m_rootProps.pszOutbox; }
  357. void AdoptOutbox(LPSTR pszOutbox) { SafeMemFree(m_rootProps.pszOutbox); m_rootProps.pszOutbox = pszOutbox; }
  358. LPSTR GetSendMsg(void) { return m_rootProps.pszSendMsg; }
  359. void AdoptSendMsg(LPSTR pszSendMsg) { SafeMemFree(m_rootProps.pszSendMsg); m_rootProps.pszSendMsg = pszSendMsg; }
  360. LPSTR GetSentItems(void) { return m_rootProps.pszSentItems; }
  361. void AdoptSentItems(LPSTR pszSentItems) { SafeMemFree(m_rootProps.pszSentItems); m_rootProps.pszSentItems = pszSentItems; }
  362. LPSTR GetDeletedItems(void) { return m_rootProps.pszDeletedItems; }
  363. void AdoptDeletedItems(LPSTR pszDeletedItems) { SafeMemFree(m_rootProps.pszDeletedItems); m_rootProps.pszDeletedItems = pszDeletedItems; }
  364. LPSTR GetDrafts(void) { return m_rootProps.pszDrafts; }
  365. void AdoptDrafts(LPSTR pszDrafts) { SafeMemFree(m_rootProps.pszDrafts); m_rootProps.pszDrafts = pszDrafts; }
  366. LPSTR GetMsgFolderRoot(void) { return m_rootProps.pszMsgFolderRoot; }
  367. void AdoptMsgFolderRoot(LPSTR pszMsgFolderRoot) { SafeMemFree(m_rootProps.pszMsgFolderRoot); m_rootProps.pszMsgFolderRoot = pszMsgFolderRoot; }
  368. LPSTR GetSig(void) { return m_rootProps.pszSig; }
  369. void AdoptSig(LPSTR pszSig) { SafeMemFree(m_rootProps.pszSig); m_rootProps.pszSig = pszSig; }
  370. BOOL WasAborted(void) { return m_op.fAborted; }
  371. private:
  372. // ----------------------------------------------------------------------------
  373. // CHTTPMailTransport private implementation
  374. // ----------------------------------------------------------------------------
  375. public:
  376. // Translate an HTTPCOMMAND constant into a string
  377. LPSTR CommandToVerb(HTTPMAILCOMMAND command);
  378. private:
  379. HRESULT UpdateLogonInfo(void);
  380. HRESULT GetParentWindow(HWND *phwndParent);
  381. BOOL ReadBytes(LPSTR pszBuffer, DWORD cbBufferSize, DWORD *pcbBytesRead);
  382. BOOL _GetStatusCode(DWORD *pdw);
  383. BOOL _GetContentLength(DWORD *pdw);
  384. HRESULT _GetRequestHeader(LPSTR *ppszHeader, DWORD dwHeader);
  385. HRESULT _AddRequestHeader(LPCSTR pszHeader);
  386. HRESULT _MemberInfo2(LPCSTR pszPath, MEMBERINFOFLAGS flags, DWORD dwDepth,
  387. BOOL fIncludeRoot, DWORD dwContext, LPHTTPQUEUEDOP *ppOp);
  388. HRESULT _HrParseAndCopy(LPCSTR pszToken, LPSTR *ppszDest, LPSTR lpszSrc);
  389. HRESULT _HrGetTimestampHeader(LPSTR *ppszHeader);
  390. BOOL _AuthCurrentRequest(DWORD dwStatus, BOOL fRetryAuth);
  391. void _LogRequest(LPVOID pvData, DWORD cbData);
  392. void _LogResponse(LPVOID pvData, DWORD cbData);
  393. HRESULT QueueGetPropOperation(HTTPMAILPROPTYPE type);
  394. // ----------------------------------------------------------------------------
  395. // Element Parsing
  396. // ----------------------------------------------------------------------------
  397. BOOL StackTop(HMELE hmEle) { return (m_op.dwStackDepth < ELE_STACK_CAPACITY) && (m_op.rgEleStack[m_op.dwStackDepth - 1].ele == hmEle); }
  398. BOOL ValidStack(const HMELE *prgEle, DWORD cEle);
  399. BOOL InValidElementChildren(void) { return ((m_op.dwStackDepth > 0) && (m_op.dwStackDepth <= ELE_STACK_CAPACITY) && (m_op.rgEleStack[m_op.dwStackDepth - 1].fBeganChildren)); }
  400. void PopNamespaces(CXMLNamespace *pBaseNamespace);
  401. HRESULT PushNamespaces(XML_NODE_INFO** apNodeInfo, USHORT cNumRecs);
  402. HRESULT StrNToBoolW(const WCHAR *pwcText, ULONG ulLen, BOOL *pb);
  403. HRESULT StatusStrNToIxpHr(const WCHAR *pwcText, DWORD ulLen, HRESULT *hr);
  404. HRESULT AllocStrFromStrNW(const WCHAR *pwcText, ULONG ulLen, LPSTR *ppszAlloc);
  405. HRESULT StrNToDwordW(const WCHAR *pwcText, ULONG ulLen, DWORD *pi);
  406. HRESULT StrNToSpecialFolderW(const WCHAR *pwcText, ULONG ulLen, HTTPMAILSPECIALFOLDER *ptySpecial);
  407. HRESULT StrNToContactTypeW(const WCHAR *pwcText, ULONG ulLen, HTTPMAILCONTACTTYPE *ptyContact);
  408. // ----------------------------------------------------------------------------
  409. // Misc.
  410. // ----------------------------------------------------------------------------
  411. // ----------------------------------------------------------------------------
  412. // Queue Management
  413. // ----------------------------------------------------------------------------
  414. HRESULT AllocQueuedOperation(
  415. LPCSTR pszUrl,
  416. LPVOID pvData,
  417. ULONG cbDataLen,
  418. LPHTTPQUEUEDOP *ppOp,
  419. BOOL fAdoptData = FALSE);
  420. void QueueOperation(LPHTTPQUEUEDOP pOp);
  421. BOOL DequeueNextOperation(void);
  422. void FlushQueue(void);
  423. void TerminateIOThread(void);
  424. BOOL IsTerminating(void)
  425. {
  426. BOOL fResult;
  427. EnterCriticalSection(&m_cs);
  428. fResult = m_fTerminating;
  429. LeaveCriticalSection(&m_cs);
  430. return fResult;
  431. }
  432. // Thread Entry Proxy
  433. static DWORD CALLBACK IOThreadFuncProxy(PVOID pv);
  434. DWORD IOThreadFunc();
  435. // Window Proc
  436. static LRESULT CALLBACK WndProc(
  437. HWND hwnd,
  438. UINT msg,
  439. WPARAM wParam,
  440. LPARAM lParam);
  441. HRESULT HrReadCompleted(void);
  442. // Reset the transport object
  443. void Reset(void);
  444. // Create a window handle for messaging between the client and i/o thread
  445. BOOL CreateWnd(void);
  446. // WinInet callback (proxies through StatusCallbackProxy)
  447. void OnStatusCallback(
  448. HINTERNET hInternet,
  449. DWORD dwInternetStatus,
  450. LPVOID pvStatusInformation,
  451. DWORD dwStatusInformationLength);
  452. // thunks the response to the calling thread
  453. HRESULT _HrThunkConnectionError(void);
  454. HRESULT _HrThunkConnectionError(DWORD dwStatus);
  455. HRESULT _HrThunkResponse(BOOL fDone);
  456. HRESULT InvokeResponseCallback(void);
  457. // Translate a WinInet status message to an IXPSTATUS message.
  458. // Returns true if the status was translated.
  459. BOOL TranslateWinInetMsg(DWORD dwInternetStatus, IXPSTATUS *pIxpStatus);
  460. // WinInet callback proxy, which calls through to non-static
  461. // OnStatusCallback method
  462. static void StatusCallbackProxy(
  463. HINTERNET hInternet,
  464. DWORD dwContext,
  465. DWORD dwInternetStatus,
  466. LPVOID pvStatusInformation,
  467. DWORD dwStatusInformationLength);
  468. // ----------------------------------------------------------------------------
  469. // Response Management
  470. // ----------------------------------------------------------------------------
  471. void FreeMemberInfoList(void);
  472. void FreeMemberErrorList();
  473. void FreeContactIdList(void);
  474. void FreeContactInfoList(void);
  475. void FreeBCopyMoveList(void);
  476. // ----------------------------------------------------------------------------
  477. // State Machine Functions
  478. // ----------------------------------------------------------------------------
  479. void DoOperation(void);
  480. void FreeOperation(void);
  481. // ----------------------------------------------------------------------------
  482. // Parser Utils
  483. // ----------------------------------------------------------------------------
  484. private:
  485. HRESULT _BindToStruct(const WCHAR *pwcText,
  486. ULONG ulLen,
  487. const XPCOLUMN *prgCols,
  488. DWORD cCols,
  489. LPVOID pTarget,
  490. BOOL *pfWasBound);
  491. void _FreeStruct(const XPCOLUMN *prgCols,
  492. DWORD cCols,
  493. LPVOID pTarget,
  494. DWORD *pdwFlags);
  495. HRESULT _GetTextBuffer(LPPCDATABUFFER *ppTextBuffer)
  496. {
  497. if (m_op.pTextBuffer)
  498. {
  499. *ppTextBuffer = m_op.pTextBuffer;
  500. m_op.pTextBuffer = NULL;
  501. return S_OK;
  502. }
  503. else
  504. return _AllocTextBuffer(ppTextBuffer);
  505. }
  506. HRESULT _AppendTextToBuffer(LPPCDATABUFFER pTextBuffer, const WCHAR *pwcText, ULONG ulLen);
  507. HRESULT _AllocTextBuffer(LPPCDATABUFFER *ppTextBuffer);
  508. void _ReleaseTextBuffer(LPPCDATABUFFER pTextBuffer)
  509. {
  510. IxpAssert(NULL != pTextBuffer);
  511. // if the buffer capacity is the original byte count, and there is
  512. // no buffer in the cache, then return this one to the cache
  513. if (NULL == m_op.pTextBuffer && PCDATA_BUFSIZE == pTextBuffer->ulCapacity)
  514. {
  515. pTextBuffer->ulLen = 0;
  516. m_op.pTextBuffer = pTextBuffer;
  517. }
  518. else
  519. _FreeTextBuffer(pTextBuffer);
  520. }
  521. void _FreeTextBuffer(LPPCDATABUFFER pTextBuffer);
  522. public:
  523. // common states
  524. HRESULT OpenRequest(void);
  525. HRESULT SendRequest(void);
  526. HRESULT AddCommonHeaders(void);
  527. HRESULT RequireMultiStatus(void);
  528. HRESULT FinalizeRequest(void);
  529. HRESULT AddCharsetLine(void);
  530. // GET states
  531. HRESULT ProcessGetResponse(void);
  532. // POST states
  533. HRESULT AddContentTypeHeader(void);
  534. HRESULT SendPostRequest(void);
  535. HRESULT ProcessPostResponse(void);
  536. // XML processing
  537. HRESULT ProcessXMLResponse(void);
  538. // PROPFIND states
  539. HRESULT GeneratePropFindXML(void);
  540. HRESULT AddDepthHeader(void);
  541. // PROPPATCH states
  542. HRESULT GeneratePropPatchXML(void);
  543. // MKCOL states
  544. HRESULT ProcessCreatedResponse(void);
  545. // COPY and MOVE states
  546. HRESULT AddDestinationHeader(void);
  547. HRESULT ProcessLocationResponse(void);
  548. // BCOPY and BMOVE states
  549. HRESULT InitBCopyMove(void);
  550. // RootProp states
  551. HRESULT InitRootProps(void);
  552. HRESULT FinalizeRootProps(void);
  553. // MemberInfo states
  554. HRESULT InitMemberInfo(void);
  555. // MemberError states
  556. HRESULT InitMemberError(void);
  557. // ListContacts
  558. HRESULT InitListContacts(void);
  559. // ContactInfo
  560. HRESULT InitContactInfo(void);
  561. // PostContact
  562. HRESULT ProcessPostContactResponse(void);
  563. // PatchContact
  564. HRESULT ProcessPatchContactResponse(void);
  565. // ----------------------------------------------------------------------------
  566. // XML Parsing Functions
  567. // ----------------------------------------------------------------------------
  568. HRESULT CreateElement(CXMLNamespace *pBaseNamespace, const WCHAR *pwcText, ULONG ulLen, ULONG ulNamespaceLen, BOOL fTerminal);
  569. HRESULT EndChildren(void);
  570. // BCOPY and BMOVE
  571. HRESULT BCopyMove_HandleText(const WCHAR *pwcText, ULONG ulLen);
  572. HRESULT BCopyMove_EndChildren(void);
  573. // PropFind
  574. HRESULT PropFind_HandleText(const WCHAR *pwcText, ULONG ulLen);
  575. // RootProps
  576. HRESULT RootProps_HandleText(const WCHAR *pwcText, ULONG ulLen);
  577. HRESULT RootProps_EndChildren(void);
  578. // MemberInfo
  579. HRESULT MemberInfo_HandleText(const WCHAR *pwcText, ULONG ulLen);
  580. HRESULT MemberInfo_EndChildren(void);
  581. // MemberError
  582. HRESULT MemberError_HandleText(const WCHAR *pwcText, ULONG ulLen);
  583. HRESULT MemberError_EndChildren(void);
  584. // ListContacts
  585. HRESULT ListContacts_HandleText(const WCHAR *pwcText, ULONG ulLen);
  586. HRESULT ListContacts_EndChildren(void);
  587. // ContactInfo
  588. HRESULT ContactInfo_HandleText(const WCHAR *pwcText, ULONG ulLen);
  589. HRESULT ContactInfo_EndChildren(void);
  590. // PostContact and PatchContact
  591. HRESULT PostOrPatchContact_HandleText(const WCHAR *pwcText, ULONG ulLen);
  592. HRESULT PostOrPatchContact_EndChildren(void);
  593. public:
  594. HRESULT _CreateXMLParser(void);
  595. };
  596. #endif // __IXPHTTPM_H