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.

399 lines
9.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: urlmon.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12-22-95 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef _URLMON_HXX_
  18. #define _URLMON_HXX_
  19. #include <urlint.h>
  20. #include <wininet.h>
  21. #include <sem.hxx>
  22. #include <debug.h>
  23. #define SZPROTOCOLROOT "PROTOCOLS\\Handler\\"
  24. #define SZCLASS "CLSID"
  25. #define SZALL "*"
  26. #define SZNAMESPACEROOT "PROTOCOLS\\Name-Space Handler\\"
  27. #define SZHANDLER "HANDLER"
  28. #define ULPROTOCOLLEN 32
  29. //extern char szMimeKey[] = "MIME\\Database\\Content Type\\";
  30. //const ULONG ulMimeKeyLen = ((sizeof(szMimeKey)/sizeof(char))-1);
  31. #define SZMIMEKEY "MIME\\Database\\Content Type\\"
  32. #define ULMIMEKEYLEN 32
  33. // move this to public header file
  34. #define S_NEEDMOREDATA ((HRESULT)0x00000002L)
  35. #define BSCF_ASYNCDATANOTIFICATION 0x00010000
  36. #define BSCF_DATAFULLYAVAILABLE 0x00020000
  37. #define BINDF_NEEDFILE ((BINDF) 0x00000040)
  38. #define BINDSTATUS_ERROR ((BINDSTATUS)0xf0000000)
  39. #define BINDSTATUS_INTERNAL ((BINDSTATUS)0xf1000000)
  40. #define BINDSTATUS_INTERNALASYNC ((BINDSTATUS)0xf2000000)
  41. // BUGBUG: find maximum mime size
  42. #define SZMIMESIZE_MAX 128
  43. // download buffer per request, can this
  44. #define DNLD_BUFFER_SIZE 8192
  45. #define SNIFFDATA_SIZE 2048
  46. #define MAX_URL_SIZE INTERNET_MAX_URL_LENGTH
  47. #define CU_NO_CANONICALIZE 0x00000000
  48. #define CU_CANONICALIZE 0x00000001
  49. STDAPI ConstructURL(LPBC pBC, LPMONIKER pmkContext, LPMONIKER pmkToLeft,
  50. LPWSTR pwzURLRelative, LPWSTR pwzURLFull, DWORD cURLSize,
  51. DWORD dwFlags);
  52. // global variable
  53. extern HINTERNET g_hSession;
  54. LPCSTR GetUserAgentString();
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Class: CRefCount ()
  58. //
  59. // Purpose: Safe class for refcounting
  60. //
  61. // Interface: CRefCount()
  62. // CRefCount(LONG lValue)
  63. // LONG operator++() prefix
  64. // LONG operator--() prefix
  65. // LONG operator++(int) postfix
  66. // LONG operator--(int) postfix
  67. // LONG operator++(int) cast operator
  68. //
  69. // History: 1-19-96 JohannP (Johann Posch) Created
  70. //
  71. // Notes:
  72. //
  73. //----------------------------------------------------------------------------
  74. class CRefCount
  75. {
  76. public:
  77. CRefCount()
  78. {
  79. _cRefs = 1;
  80. }
  81. CRefCount(LONG lVal)
  82. {
  83. _cRefs = lVal;
  84. }
  85. // prefix operators
  86. LONG operator++()
  87. {
  88. InterlockedIncrement(&_cRefs);
  89. return _cRefs;
  90. }
  91. LONG operator--()
  92. {
  93. InterlockedDecrement(&_cRefs);
  94. return _cRefs;
  95. }
  96. // postfix operators
  97. LONG operator++(int)
  98. {
  99. return InterlockedIncrement(&_cRefs);
  100. }
  101. LONG operator--(int)
  102. {
  103. return InterlockedDecrement(&_cRefs);
  104. }
  105. // LONG cast operator
  106. operator LONG()
  107. {
  108. return _cRefs;
  109. }
  110. private:
  111. LONG _cRefs;
  112. };
  113. #define DLD_PROTOCOL_NONE 0
  114. #define DLD_PROTOCOL_HTTP 1
  115. #define DLD_PROTOCOL_FTP 2
  116. #define DLD_PROTOCOL_GOPHER 3
  117. #define DLD_PROTOCOL_FILE 4
  118. #define DLD_PROTOCOL_LOCAL 5
  119. #define DLD_PROTOCOL_HTTPS 6
  120. #define DLD_PROTOCOL_STREAM 7
  121. // # of internal Protocols
  122. #define INTERNAL_PROTOCOL_MAX 8
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Class: CEnumFmtEtc ()
  126. //
  127. // Purpose: Class for formatetc enumerator
  128. //
  129. // Interface: Create --
  130. // QueryInterface --
  131. // AddRef --
  132. // Release --
  133. // Next --
  134. // Skip --
  135. // Reset --
  136. // Clone --
  137. // Initialize --
  138. //
  139. // History: 1-19-96 JohannP (Johann Posch) Created
  140. //
  141. // Notes:
  142. //
  143. //----------------------------------------------------------------------------
  144. class CEnumFmtEtc : public IEnumFORMATETC
  145. {
  146. public:
  147. // Create and return a IEnumFormatEtc object.
  148. // Return the object if successful, NULL otherwise.
  149. static CEnumFmtEtc * Create(UINT cfmtetc, FORMATETC* rgfmtetc);
  150. // *** IUnknown methods ***
  151. STDMETHODIMP QueryInterface(REFIID iid, void **ppvObj);
  152. STDMETHODIMP_(ULONG) AddRef(void);
  153. STDMETHODIMP_(ULONG) Release(void);
  154. // *** IEnumFormatEtc methods ***
  155. STDMETHODIMP Next(ULONG celt, FORMATETC * rgelt, ULONG * pceltFetched);
  156. STDMETHODIMP Skip(ULONG celt);
  157. STDMETHODIMP Reset(void);
  158. STDMETHODIMP Clone(IEnumFORMATETC ** ppenum);
  159. private:
  160. CEnumFmtEtc() : _CRefs()
  161. {
  162. _iNext = 0;
  163. _cElements = 0;
  164. _pFmtEtc = NULL;
  165. }
  166. ~CEnumFmtEtc()
  167. {
  168. if (_pFmtEtc)
  169. {
  170. delete _pFmtEtc;
  171. }
  172. }
  173. BOOL Initialize(UINT cfmtetc, FORMATETC* rgfmtetc, UINT iPos);
  174. private:
  175. CRefCount _CRefs; // refcount
  176. UINT _iNext; // zero-based item that will next be enumerated
  177. UINT _cElements;
  178. FORMATETC *_pFmtEtc; // has at least one item
  179. };
  180. class CMediaType;
  181. class CMediaTypeHolder;
  182. class CMediaTypeNode;
  183. typedef enum _tagDATAFORMAT
  184. {
  185. DATAFORMAT_UNKNOWN = 0
  186. ,DATAFORMAT_AMBIGUOUS
  187. ,DATAFORMAT_KNOWN
  188. ,DATAFORMAT_TEXT
  189. ,DATAFORMAT_BINARY
  190. ,DATAFORMAT_TEXTORBINARY
  191. } DATAFORMAT;
  192. typedef struct _tagMediaInfo
  193. {
  194. LPSTR _pszType;
  195. CLIPFORMAT _cfFormat;
  196. DWORD _dwDataFormat;
  197. CLSID _clsID;
  198. } MediaInfo;
  199. class CMediaType : public MediaInfo
  200. {
  201. public:
  202. CMediaType()
  203. {
  204. _pszType = 0;
  205. _cfFormat = 0;
  206. _clsID = CLSID_NULL;
  207. _dwDataFormat = 0;
  208. }
  209. void Initialize(LPSTR szType, CLIPFORMAT cfFormat);
  210. void Initialize(CLIPFORMAT cfFormat, CLSID *pClsID);
  211. LPSTR GetTypeString(void)
  212. {
  213. return _pszType;
  214. }
  215. CLIPFORMAT GetClipFormat(void)
  216. {
  217. return _cfFormat;
  218. }
  219. void SetClipFormat(CLIPFORMAT cf)
  220. {
  221. _cfFormat = cf;
  222. }
  223. DWORD GetDataFormat()
  224. {
  225. return _dwDataFormat;
  226. }
  227. void SetClsID(CLSID *pClsID)
  228. {
  229. _clsID = *pClsID;
  230. }
  231. void GetClsID(CLSID *pClsID)
  232. {
  233. *pClsID = _clsID;
  234. }
  235. private:
  236. // LPSTR _pszType;
  237. // CLIPFORMAT _cfFormat;
  238. // CLSID _clsID;
  239. // DWORD _dwDataFormat;
  240. };
  241. class CMediaTypeHolder : public IMediaHolder
  242. {
  243. public:
  244. CMediaTypeHolder();
  245. ~CMediaTypeHolder();
  246. // unknown methods
  247. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  248. STDMETHOD_(ULONG,AddRef) (void);
  249. STDMETHOD_(ULONG,Release) (void);
  250. // mediahoder methods
  251. STDMETHOD(RegisterClassMapping)(
  252. DWORD ctypes,
  253. LPCSTR rgszNames[],
  254. CLSID rgClsIDs[],
  255. DWORD dwReserved);
  256. STDMETHOD(FindClassMapping)(
  257. LPCSTR szMime,
  258. CLSID *pClassID,
  259. DWORD dwReserved);
  260. HRESULT RegisterW(UINT ctypes, const LPCWSTR* rgszTypes, CLIPFORMAT* rgcfTypes);
  261. HRESULT Register(UINT ctypes, const LPCSTR* rgszTypes, CLIPFORMAT* rgcfTypes);
  262. HRESULT RegisterMediaInfo(UINT ctypes, MediaInfo *pMediaInfo, BOOL fFree);
  263. HRESULT RegisterClass(UINT ctypes, const LPCSTR* rgszTypes, CLSID *rgclsID);
  264. HRESULT FindCMediaType(LPCSTR pszMimeStr, CMediaType **ppCMType);
  265. HRESULT FindCMediaType(CLIPFORMAT cfFormat, CMediaType **ppCMType);
  266. private: // methods
  267. private: // data
  268. CRefCount _CRefs; // refcount class
  269. CMediaTypeNode *_pCMTNode;
  270. };
  271. class CMediaTypeNode
  272. {
  273. public:
  274. CMediaTypeNode(CMediaType *pCMType, LPSTR pszTextBuffer, UINT cElements,
  275. CMediaTypeNode *pNext, BOOL fFree = TRUE)
  276. {
  277. _pCMType = pCMType;
  278. _pszTextBuffer = pszTextBuffer;
  279. _cElements = cElements;
  280. _pNext = pNext;
  281. _fFree = fFree;
  282. }
  283. ~CMediaTypeNode()
  284. {
  285. if (_pszTextBuffer)
  286. {
  287. delete _pszTextBuffer;
  288. }
  289. if (_fFree)
  290. {
  291. delete _pCMType;
  292. }
  293. }
  294. CMediaType *GetMediaTypeArray(void)
  295. {
  296. return _pCMType;
  297. }
  298. LPSTR GetTextBuffer(void)
  299. {
  300. return _pszTextBuffer;
  301. }
  302. UINT GetElementCount(void)
  303. {
  304. return _cElements;
  305. }
  306. CMediaTypeNode *GetNextNode()
  307. {
  308. return _pNext;
  309. }
  310. void SetNextNode(CMediaTypeNode *pNode)
  311. {
  312. _pNext = pNode;
  313. }
  314. private: // data
  315. CMediaType *_pCMType;
  316. LPSTR _pszTextBuffer;
  317. UINT _cElements;
  318. BOOL _fFree;
  319. CMediaTypeNode *_pNext;
  320. };
  321. CMediaTypeHolder *GetMediaTypeHolder();
  322. extern CMediaTypeHolder *g_pCMHolder;
  323. extern CMutexSem g_mxsMedia; // single access to media holder
  324. HRESULT FindMediaString(CLIPFORMAT cfFormat, LPSTR *ppStr);
  325. HRESULT FindMediaType(LPSTR pszType, CLIPFORMAT *cfType);
  326. HRESULT RegisterDefaultMediaType();
  327. inline HRESULT InternalRegisterDefaultMediaType();
  328. LPSTR FindFileExtension(LPSTR pszFileName);
  329. HRESULT GetMimeFromExt(LPSTR pszExt, LPSTR pszMime, DWORD *pcbMime);
  330. // helper routines
  331. LPSTR StringAFromCLSID(CLSID *pclsid);
  332. HRESULT CLSIDFromStringA(LPSTR pszClsid, CLSID *pclsid);
  333. #define GUIDSTR_MAX (1+ 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1 + 1)
  334. #define CLSIDSTR_MAX (GUIDSTR_MAX)
  335. #endif //_URLMON_HXX_