FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
axstream_impl.h
1 /**********************************************************\
2 Original Author: Matthias (nitrogenycs)
3 
4 Created: Feb 28, 2010
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2010 Richard Bateman, Firebreath development team
13 \**********************************************************/
14 
15 #pragma once
16 #ifndef H_ACTIVEXSTREAM_IMPL
17 #define H_ACTIVEXSTREAM_IMPL
18 
19 #include "BrowserStream.h"
20 #include "urlmon.h"
21 #include "atlbase.h"
22 #include <boost/shared_ptr.hpp>
23 #include <boost/enable_shared_from_this.hpp>
24 
25 // includes parts of Microsoft examples:
26 // http://support.microsoft.com/kb/223500
27 // http://support.microsoft.com/kb/165800
28 
29 namespace FB { namespace ActiveX {
30  class ActiveXStream;
31  typedef boost::shared_ptr<ActiveXStream> ActiveXStreamPtr;
32  class ActiveXBindStatusCallback;
33 
34  class ActiveXStreamRequest : public boost::enable_shared_from_this<ActiveXStreamRequest>
35  {
36  public:
37  ActiveXStreamRequest( ActiveXStreamPtr stream );
38  ActiveXStreamRequest( ActiveXStreamPtr stream, const std::vector<FB::BrowserStream::Range>& ranges );
39 
40  bool start();
41  bool stop();
42 
43  public:
44  ActiveXStreamPtr stream;
45  CComPtr<IMoniker> FMoniker;
46  CComPtr<IBindCtx> FBindCtx;
47  CComPtr<ActiveXBindStatusCallback> bindStatusCallback;
48  CComPtr<IStream> fstream;
49  std::vector<FB::BrowserStream::Range> ranges;
50  };
51 
52  typedef boost::shared_ptr<ActiveXStreamRequest> ActiveXStreamRequestPtr;
53 
54  class ActiveXBindStatusCallback : public IBindStatusCallback, IHttpNegotiate
55  {
56  public:
57  // IUnknown methods
58  STDMETHODIMP QueryInterface(REFIID riid,void ** ppv);
59  STDMETHODIMP_(ULONG) AddRef() { return m_cRef++; }
60  STDMETHODIMP_(ULONG) Release() { if (--m_cRef == 0) { delete this; return 0; } return m_cRef; }
61 
62  // IBindStatusCallback methods
63  STDMETHODIMP OnStartBinding(DWORD dwReserved, IBinding* pbinding);
64  STDMETHODIMP GetPriority(LONG* pnPriority);
65  STDMETHODIMP OnLowResource(DWORD dwReserved);
66  STDMETHODIMP OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode,
67  LPCWSTR pwzStatusText);
68  STDMETHODIMP OnStopBinding(HRESULT hrResult, LPCWSTR szError);
69  STDMETHODIMP GetBindInfo(DWORD* pgrfBINDF, BINDINFO* pbindinfo);
70  STDMETHODIMP OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC *pfmtetc,
71  STGMEDIUM* pstgmed);
72  STDMETHODIMP OnObjectAvailable(REFIID riid, IUnknown* punk);
73 
74  // IHttpNegotiate methods
75  STDMETHODIMP BeginningTransaction(/* [in] */ LPCWSTR szURL,
76  /* [unique][in] */ LPCWSTR szHeaders,
77  /* [in] */ DWORD dwReserved,
78  /* [out] */ LPWSTR __RPC_FAR *pszAdditionalHeaders);
79 
80  STDMETHODIMP OnResponse(/* [in] */ DWORD dwResponseCode,
81  /* [unique][in] */ LPCWSTR szResponseHeaders,
82  /* [unique][in] */ LPCWSTR szRequestHeaders,
83  /* [out] */ LPWSTR __RPC_FAR *pszAdditionalRequestHeaders);
84 
85  // constructors/destructors
86  ActiveXBindStatusCallback();
87  virtual
88  ~ActiveXBindStatusCallback();
89 
90  static HRESULT Create(ActiveXBindStatusCallback** ppBindStatusCallback, ActiveXStreamRequestPtr request);
91  HRESULT Init(ActiveXStreamRequestPtr request);
92  HRESULT InitPostData(const char* szData);
93 
94  bool close();
95 
96  bool GetInfo(DWORD which, std::string& result);
97 
98  // data members
99  DWORD m_cRef;
100  LPBINDING m_pbinding;
101  CComPtr<IStream> m_pstm;
102  DWORD m_cbOld;
103  BOOL m_fRedirect; // need to be informed when we're being redirected by the server
104  BINDVERB m_dwAction;
105  HGLOBAL m_hDataToPost; // data that we're going to post
106  DWORD m_cbDataToPost;
107  ActiveXStreamRequestPtr m_request;
108  bool m_transactionStarted;
109  };
110 } }
111 
112 #endif
113