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.

259 lines
10 KiB

  1. /**
  2. * App.h header file
  3. *
  4. * Copyright (c) 2000 Microsoft Corporation
  5. */
  6. //#if _MSC_VER > 1000
  7. #pragma once
  8. //#endif
  9. #ifndef _AppAPP_H
  10. #define _AppAPP_H
  11. #include "wininet.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. #define PROTOCOL_NAME L"appx" //??????? get around app: in IE5
  14. #define PROTOCOL_NAME_LEN 4
  15. #define PROTOCOL_PREFIX PROTOCOL_NAME L":"
  16. #define PROTOCOL_SCHEME PROTOCOL_NAME L"://"
  17. #define HTTP_SCHEME L"http://"
  18. #define HTTP_RESPONSEOK "HTTP/1.1 200 OK\r\n"
  19. /////////////////////////////////////////////////////////////////////////////
  20. #define STORE_PATH L"\\Application Store"
  21. #define APPTYPE_IE 0
  22. #define APPTYPE_BYMANIFEST 1
  23. #define APPTYPE_ASM 2
  24. #define APPTYPE_MYWEB 3
  25. #define STATUS_CLEAR 0x0
  26. #define STATUS_OFFLINE_MODE 0x1
  27. #define STATUS_NOT_IN_CACHE 0x2
  28. #define MAX_URL_LENGTH 512 // some hardcoded #, for now
  29. /////////////////////////////////////////////////////////////////////////////
  30. /////////////////////////////////////////////////////////////////////////////
  31. /////////////////////////////////////////////////////////////////////////////
  32. // Global Objects
  33. extern CLSID CLSID_AppProtocol;
  34. extern BOOL g_fStarted;
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Imported WININET functions, setup in functions.cxx
  37. extern BOOL (WINAPI * g_pInternetSetCookieW ) (LPCTSTR, LPCTSTR, LPCTSTR);
  38. extern BOOL (WINAPI * g_pInternetGetCookieW ) (LPCTSTR, LPCTSTR, LPTSTR, LPDWORD);
  39. extern HINTERNET (WINAPI * g_pInternetOpen ) (LPCTSTR, DWORD, LPCTSTR, LPCTSTR, DWORD);
  40. extern void (WINAPI * g_pInternetCloseHandle ) (HINTERNET);
  41. extern HINTERNET (WINAPI * g_pInternetOpenUrl ) (HINTERNET, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD_PTR);
  42. extern BOOL (WINAPI * g_pInternetReadFile ) (HINTERNET, LPVOID, DWORD, LPDWORD);
  43. extern BOOL (WINAPI * g_pInternetQueryOption ) (HINTERNET, DWORD, LPVOID, LPDWORD); // for offline mode
  44. /////////////////////////////////////////////////////////////////////////////
  45. /////////////////////////////////////////////////////////////////////////////
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Data structures
  48. struct FILEINFOLIST
  49. {
  50. WCHAR _wzFilename[MAX_PATH]; // can have \ but not ..\ ; no path, should be much shorter than MAX_PATH
  51. WCHAR _wzHash[33]; // 32 + L'\0'
  52. FILEINFOLIST* _pNext;
  53. };
  54. struct APPINFO
  55. {
  56. WCHAR _wzNewRef[MAX_URL_LENGTH];
  57. WCHAR _wzEntryAssemblyFileName[MAX_PATH];
  58. FILEINFOLIST* _pFileList;
  59. };
  60. // + m_appRootTranslated
  61. /////////////////////////////////////////////////////////////////////////////
  62. /////////////////////////////////////////////////////////////////////////////
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Clases and interfaces
  65. interface IPrivateUnknown
  66. {
  67. public:
  68. STDMETHOD (PrivateQueryInterface) (REFIID riid, void ** ppv) = 0;
  69. STDMETHOD_ (ULONG, PrivateAddRef) () = 0;
  70. STDMETHOD_ (ULONG, PrivateRelease) () = 0;
  71. };
  72. /////////////////////////////////////////////////////////////////////////////
  73. /////////////////////////////////////////////////////////////////////////////
  74. /////////////////////////////////////////////////////////////////////////////
  75. class AppProtocol : public IPrivateUnknown, public IInternetProtocol, public IWinInetHttpInfo
  76. {
  77. public:
  78. AppProtocol (IUnknown *pUnkOuter);
  79. ~AppProtocol ();
  80. // IPrivateUnknown methods
  81. STDMETHOD_ (ULONG, PrivateAddRef) ();
  82. STDMETHOD_ (ULONG, PrivateRelease) ();
  83. STDMETHOD (PrivateQueryInterface) (REFIID, void **);
  84. // IUnknown methods
  85. STDMETHOD_ (ULONG, AddRef) ();
  86. STDMETHOD_ (ULONG, Release) ();
  87. STDMETHOD (QueryInterface) (REFIID, void **);
  88. // IInternetProtocol, IInternetProtocolRoot methods
  89. STDMETHOD (Start) (LPCWSTR, IInternetProtocolSink *, IInternetBindInfo *, DWORD, DWORD);
  90. STDMETHOD (Continue) (PROTOCOLDATA *pProtData);
  91. STDMETHOD (Abort) (HRESULT hrReason,DWORD );
  92. STDMETHOD (Terminate) (DWORD );
  93. STDMETHOD (Suspend) ();
  94. STDMETHOD (Resume) ();
  95. STDMETHOD (Read) (void *pv, ULONG cb, ULONG *pcbRead);
  96. STDMETHOD (Seek) (LARGE_INTEGER , DWORD , ULARGE_INTEGER *) ;
  97. STDMETHOD (LockRequest) (DWORD );
  98. STDMETHOD (UnlockRequest) ();
  99. // IWinInetHttpInfo
  100. STDMETHOD (QueryInfo) (DWORD dwOption, LPVOID pBuffer, DWORD *pcbBuf, DWORD *pdwFlags, DWORD *pdwReserved);
  101. STDMETHOD (QueryOption) (DWORD , LPVOID, DWORD *);
  102. // Public functions called by exported functions
  103. HRESULT WriteBytes (BYTE *buf, DWORD dwLength);
  104. HRESULT SendHeaders (LPSTR buffer);
  105. // HRESULT SaveCookie (LPSTR header);
  106. int GetString (int key, WCHAR *buf, int size);
  107. int GetStringLength (int key);
  108. // int MapPath (WCHAR *virtualPath, WCHAR *physicalPath, int length);
  109. HRESULT Finish ();
  110. // int GetKnownRequestHeader (LPCWSTR szHeader, LPWSTR buf, int size);
  111. private:
  112. // Private functions
  113. HRESULT SetupAndInstall (LPTSTR url, LPTSTR path);
  114. HRESULT ParseUrl (LPCTSTR url);
  115. // HRESULT GetAppBaseDir (LPCTSTR base, LPTSTR appRoot);
  116. WCHAR * MapString (int key);
  117. void Cleanup ();
  118. void FreeStrings ();
  119. HRESULT InstallInternetFile (LPTSTR url, LPTSTR path);
  120. HRESULT InstallInternetFile2 (LPTSTR url, LPTSTR path);
  121. HRESULT DealWithBuffer (LPWSTR szHeaders, LPCWSTR szHeader,
  122. DWORD dwOpt, DWORD dwOption,
  123. LPVOID pBuffer, LPDWORD pcbBuf);
  124. HRESULT ProcessAppManifest ();
  125. void ParseManifest (char* szManifest, APPINFO* pAppInfo);
  126. long m_refs;
  127. IUnknown * m_pUnkOuter;
  128. DWORD m_bindf;
  129. BINDINFO m_bindinfo;
  130. IInternetProtocolSink * m_pProtocolSink;
  131. CRITICAL_SECTION m_csOutputWriter;
  132. DWORD m_cbOutput;
  133. IStream * m_pOutputRead;
  134. IStream * m_pOutputWrite;
  135. BOOL m_started;
  136. BOOL m_aborted;
  137. BOOL m_done;
  138. BOOL m_redirect;
  139. DWORD m_inputDataSize;
  140. BYTE * m_inputData;
  141. IStream * m_pInputRead;
  142. WCHAR * m_verb;
  143. WCHAR * m_fullUri; // "myWeb://www.site.com/app/something/else"
  144. WCHAR * m_uriPath; // "/app/something/else"
  145. WCHAR * m_queryString; // "?aaa=bbb"
  146. WCHAR * m_appOrigin; // "www.site.com"
  147. WCHAR * m_appRoot; // "/app"
  148. WCHAR * m_appRootTranslated; // "c:\program files\site myweb app"
  149. WCHAR * m_extraHeaders;
  150. WCHAR * m_postedMimeType;
  151. WCHAR * m_responseMimeType;
  152. // WCHAR * m_cookie;
  153. WCHAR * m_extraHeadersUpr;
  154. WCHAR * m_strResponseHeader;
  155. WCHAR * m_localStoreFilePath;
  156. int m_appType;
  157. int m_status;
  158. };
  159. /////////////////////////////////////////////////////////////////////////////
  160. /////////////////////////////////////////////////////////////////////////////
  161. /////////////////////////////////////////////////////////////////////////////
  162. class AppProtocolFactory : public IClassFactory, public IInternetProtocolInfo
  163. {
  164. public:
  165. // IUnknown Methods
  166. STDMETHOD_ (ULONG, AddRef) ();
  167. STDMETHOD_ (ULONG, Release) ();
  168. STDMETHOD (QueryInterface) (REFIID, void **);
  169. // IClassFactory Moethods
  170. STDMETHOD (LockServer) (BOOL);
  171. STDMETHOD (CreateInstance) (IUnknown*,REFIID,void**);
  172. // IInternetProtocolInfo Methods
  173. STDMETHOD (CombineUrl) (LPCWSTR,LPCWSTR,DWORD,LPWSTR,DWORD,DWORD *,DWORD);
  174. STDMETHOD (CompareUrl) (LPCWSTR, LPCWSTR, DWORD);
  175. STDMETHOD (ParseUrl) (LPCWSTR, PARSEACTION, DWORD, LPWSTR, DWORD, DWORD *, DWORD);
  176. STDMETHOD (QueryInfo) (LPCWSTR, QUERYOPTION, DWORD, LPVOID, DWORD, DWORD *, DWORD);
  177. };
  178. /////////////////////////////////////////////////////////////////////////////
  179. /////////////////////////////////////////////////////////////////////////////
  180. /////////////////////////////////////////////////////////////////////////////
  181. // Gloabal functions
  182. //HRESULT
  183. //InstallInternetFile( LPTSTR url, LPTSTR path);
  184. void
  185. TerminateAppProtocol();
  186. HRESULT
  187. GetAppProtocolClassObject(REFIID iid, void **ppv);
  188. HRESULT
  189. InitializeAppProtocol();
  190. /*UINT WINAPI
  191. CabFileHandler( LPVOID context,
  192. UINT notification,
  193. UINT_PTR param1,
  194. UINT_PTR param2 );
  195. */
  196. LPWSTR
  197. DuplicateString ( LPCWSTR szString);
  198. /////////////////////////////////////////////////////////////////////////////
  199. /////////////////////////////////////////////////////////////////////////////
  200. /////////////////////////////////////////////////////////////////////////////
  201. extern AppProtocolFactory g_AppProtocolFactory; // ! not a pointer !
  202. /////////////////////////////////////////////////////////////////////////////
  203. /////////////////////////////////////////////////////////////////////////////
  204. /////////////////////////////////////////////////////////////////////////////
  205. // for AppProtocol.cxx
  206. #endif