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.

519 lines
14 KiB

  1. /*
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. sdpblob.h
  5. Abstract:
  6. Declaration of the CSdpConferenceBlob
  7. Author:
  8. */
  9. #ifndef __SDPCONFERENCEBLOB_H_
  10. #define __SDPCONFERENCEBLOB_H_
  11. #include <atlctl.h>
  12. #include "resource.h" // main symbols
  13. #include "blbcoen.h"
  14. #include "blbmeco.h"
  15. #include "blbtico.h"
  16. #include "blbsdp.h"
  17. #include "blbconn.h"
  18. #include "blbatt.h"
  19. #include "blbmedia.h"
  20. #include "blbtime.h"
  21. #include "rend.h"
  22. #include "rendp.h"
  23. #include "ObjectSafeImpl.h"
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CSdpConferenceBlob
  26. template <class T>
  27. class ITConferenceBlobVtbl : public ITConferenceBlob
  28. {
  29. };
  30. template <class T>
  31. class ITSdpVtbl : public ITSdp
  32. {
  33. };
  34. class ATL_NO_VTABLE CSdpConferenceBlob :
  35. public CComObjectRootEx<CComObjectThreadModel>,
  36. public CComCoClass<CSdpConferenceBlob, &CLSID_SdpConferenceBlob>,
  37. public IDispatchImpl<ITConferenceBlobVtbl<CSdpConferenceBlob>, &IID_ITConferenceBlob, &LIBID_SDPBLBLib>,
  38. public IDispatchImpl<ITSdpVtbl<CSdpConferenceBlob>, &IID_ITSdp, &LIBID_SDPBLBLib>,
  39. public ITConnectionImpl,
  40. public ITAttributeListImpl,
  41. public ITConfBlobPrivate,
  42. public SDP_BLOB,
  43. public CObjectSafeImpl
  44. {
  45. public:
  46. inline CSdpConferenceBlob();
  47. inline HRESULT FinalConstruct();
  48. inline ~CSdpConferenceBlob();
  49. public:
  50. STDMETHOD(get_TimeCollection)(/*[out, retval]*/ ITTimeCollection * *ppTimeCollection);
  51. STDMETHOD(get_MediaCollection)(/*[out, retval]*/ ITMediaCollection * *ppMediaCollection);
  52. STDMETHOD(get_Originator)(/*[out, retval]*/ BSTR *ppOriginator);
  53. STDMETHOD(put_Originator)(/*[in]*/ BSTR pOriginator);
  54. STDMETHOD(SetPhoneNumbers)(VARIANT /*SAFEARRAY(BSTR)*/ Numbers, VARIANT /*SAFEARRAY(BSTR)*/ Names);
  55. STDMETHOD(GetPhoneNumbers)(VARIANT /*SAFEARRAY(BSTR)*/ *pNumbers, VARIANT /*SAFEARRAY(BSTR)*/ *pNames);
  56. STDMETHOD(SetEmailNames)(VARIANT /*SAFEARRAY(BSTR)*/ Addresses, VARIANT /*SAFEARRAY(BSTR)*/ Names);
  57. STDMETHOD(GetEmailNames)(VARIANT /*SAFEARRAY(BSTR)*/ *pAddresses, VARIANT /*SAFEARRAY(BSTR)*/ *pNames);
  58. STDMETHOD(get_IsValid)(/*[out, retval]*/ VARIANT_BOOL *pfIsValid);
  59. STDMETHOD(get_Url)(/*[out, retval]*/ BSTR *ppUrl);
  60. STDMETHOD(put_Url)(/*[in]*/ BSTR pUrl);
  61. STDMETHOD(get_Description)(/*[out, retval]*/ BSTR *ppDescription);
  62. STDMETHOD(put_Description)(/*[in]*/ BSTR pDescription);
  63. STDMETHOD(get_Name)(/*[out, retval]*/ BSTR *ppName);
  64. STDMETHOD(put_Name)(/*[in]*/ BSTR pName);
  65. STDMETHOD(get_MachineAddress)(/*[out, retval]*/ BSTR *ppMachineAddress);
  66. STDMETHOD(put_MachineAddress)(/*[in]*/ BSTR pMachineAddress);
  67. STDMETHOD(get_SessionVersion)(/*[out, retval]*/ DOUBLE *pSessionVersion);
  68. STDMETHOD(put_SessionVersion)(/*[in]*/ DOUBLE SessionVersion);
  69. STDMETHOD(get_SessionId)(/*[out, retval]*/ DOUBLE *pVal);
  70. STDMETHOD(get_ProtocolVersion)(/*[out, retval]*/ BYTE *pProtocolVersion);
  71. // ITConferenceBlob
  72. STDMETHOD(Init)(
  73. /*[in]*/ BSTR pName,
  74. /*[in]*/ BLOB_CHARACTER_SET CharacterSet,
  75. /*[in]*/ BSTR pBlob
  76. );
  77. STDMETHOD(get_IsModified)(/*[out, retval]*/ VARIANT_BOOL *pfIsModified);
  78. STDMETHOD(get_CharacterSet)(/*[out, retval]*/ BLOB_CHARACTER_SET *pCharacterSet);
  79. STDMETHOD(get_ConferenceBlob)(/*[out, retval]*/ BSTR *ppBlob);
  80. STDMETHOD(SetConferenceBlob)(/*[in]*/ BLOB_CHARACTER_SET CharacterSet, /*[in]*/ BSTR pBlob);
  81. // ITConfBlobPrivate
  82. STDMETHOD(GetName)(OUT BSTR *pVal) { return get_Name(pVal); }
  83. STDMETHOD(SetName)(IN BSTR newVal) { return put_Name(newVal); }
  84. STDMETHOD(GetOriginator)(OUT BSTR *pVal) { return get_Originator(pVal); }
  85. STDMETHOD(SetOriginator)(IN BSTR newVal) { return put_Originator(newVal); }
  86. STDMETHOD(GetUrl)(OUT BSTR *pVal) { return get_Url(pVal); }
  87. STDMETHOD(SetUrl)(IN BSTR newVal) { return put_Url(newVal); }
  88. STDMETHOD(GetDescription)(OUT BSTR *pVal) { return get_Description(pVal); }
  89. STDMETHOD(SetDescription)(IN BSTR newVal) { return put_Description(newVal); }
  90. STDMETHOD(GetAdvertisingScope)(OUT RND_ADVERTISING_SCOPE *pVal)
  91. {
  92. // GetAdvertisingScope catches it, but it doesn't pass up an HRESULT.
  93. // Therefore we must check here as well.
  94. if ( IsBadWritePtr(pVal, sizeof(RND_ADVERTISING_SCOPE)) )
  95. {
  96. return E_POINTER;
  97. }
  98. // ZoltanS bugfix 5-4-98
  99. *pVal = GetAdvertisingScope(DetermineTtl());
  100. return S_OK;
  101. }
  102. STDMETHOD(SetAdvertisingScope)(IN RND_ADVERTISING_SCOPE newVal)
  103. { return WriteAdvertisingScope(newVal); }
  104. STDMETHOD(GetStartTime)(OUT DWORD *pVal)
  105. { return ((*pVal = DetermineStartTime()) != (DWORD)-1) ? S_OK : E_FAIL; }
  106. STDMETHOD(SetStartTime)(IN DWORD newVal) { return WriteStartTime(newVal); }
  107. STDMETHOD(GetStopTime)(OUT DWORD *pVal)
  108. { return ((*pVal = DetermineStopTime()) != (DWORD)-1) ? S_OK : E_FAIL; }
  109. STDMETHOD(SetStopTime)(IN DWORD newVal) { return WriteStopTime(newVal); }
  110. DECLARE_REGISTRY_RESOURCEID(IDR_SDPCONFERENCEBLOB)
  111. BEGIN_COM_MAP(CSdpConferenceBlob)
  112. COM_INTERFACE_ENTRY2(IDispatch, ITConferenceBlob)
  113. COM_INTERFACE_ENTRY(ITConferenceBlob)
  114. COM_INTERFACE_ENTRY(ITConfBlobPrivate)
  115. COM_INTERFACE_ENTRY(ITSdp)
  116. COM_INTERFACE_ENTRY(ITConnection)
  117. COM_INTERFACE_ENTRY(ITAttributeList)
  118. COM_INTERFACE_ENTRY(IObjectSafety)
  119. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pFTM)
  120. END_COM_MAP()
  121. DECLARE_GET_CONTROLLING_UNKNOWN()
  122. DECLARE_AGGREGATABLE(CSdpConferenceBlob)
  123. //
  124. // IDispatch methods
  125. //
  126. STDMETHOD(GetIDsOfNames)(REFIID riid,
  127. LPOLESTR* rgszNames,
  128. UINT cNames,
  129. LCID lcid,
  130. DISPID* rgdispid
  131. );
  132. STDMETHOD(Invoke)(DISPID dispidMember,
  133. REFIID riid,
  134. LCID lcid,
  135. WORD wFlags,
  136. DISPPARAMS* pdispparams,
  137. VARIANT* pvarResult,
  138. EXCEPINFO* pexcepinfo,
  139. UINT* puArgErr
  140. );
  141. protected:
  142. ITMediaCollection *m_MediaCollection;
  143. ITTimeCollection *m_TimeCollection;
  144. HRESULT CreateDefault(
  145. IN BSTR Name,
  146. IN SDP_CHARACTER_SET CharacterSet
  147. );
  148. // generate an sdp blob tstr using the sdp template read from the registry
  149. TCHAR *GenerateSdpBlob(
  150. IN BSTR Name,
  151. IN SDP_CHARACTER_SET CharacterSet
  152. );
  153. HRESULT WriteConferenceBlob(
  154. IN SDP_CHARACTER_SET SdpCharSet,
  155. IN BSTR newVal
  156. );
  157. inline HRESULT WriteName(
  158. IN BSTR newVal
  159. );
  160. inline HRESULT WriteOriginator(
  161. IN BSTR newVal
  162. );
  163. inline HRESULT WriteUrl(
  164. IN BSTR newVal
  165. );
  166. inline HRESULT WriteSessionTitle(
  167. IN BSTR newVal
  168. );
  169. // notification from owner with a minimum start time
  170. // update start time for each of the entries
  171. HRESULT WriteStartTime(
  172. IN DWORD MinStartTime
  173. );
  174. // notification from owner with a minimum stop time
  175. // update stop time for each of the entries
  176. HRESULT WriteStopTime(
  177. IN DWORD MaxStopTime
  178. );
  179. inline DWORD DetermineStartTime();
  180. inline DWORD DetermineStopTime();
  181. // notification from owner with a max advertising scope
  182. // update ttl for each of the connection ttl fields
  183. HRESULT WriteAdvertisingScope(
  184. IN DWORD MaxAdvertisingScope
  185. );
  186. inline BYTE GetTtl(
  187. IN RND_ADVERTISING_SCOPE AdvertisingScope
  188. );
  189. inline RND_ADVERTISING_SCOPE GetAdvertisingScope(
  190. IN BYTE Ttl
  191. );
  192. inline BYTE DetermineTtl();
  193. virtual CSdpConferenceBlob *GetConfBlob();
  194. HRESULT GetBlobCharSet(
  195. IN BLOB_CHARACTER_SET *pCharacterSet
  196. );
  197. BLOB_CHARACTER_SET GetBlobCharacterSet(
  198. IN BSTR bstrBlob
  199. );
  200. private :
  201. // BCS_UTF8 is the last value in the enumeration BLOB_CHARACTER_SET
  202. static SDP_CHARACTER_SET const gs_SdpCharSetMapping[BCS_UTF8];
  203. IUnknown * m_pFTM; // pointer to the free threaded marshaler
  204. };
  205. inline
  206. CSdpConferenceBlob::CSdpConferenceBlob(
  207. )
  208. : m_MediaCollection(NULL),
  209. m_TimeCollection(NULL),
  210. m_pFTM(NULL)
  211. {
  212. ITConnectionImpl::SuccessInit(*this);
  213. ITAttributeListImpl::SuccessInit(GetAttributeList());
  214. }
  215. inline HRESULT CSdpConferenceBlob::FinalConstruct()
  216. {
  217. HRESULT HResult = CoCreateFreeThreadedMarshaler( GetControllingUnknown(),
  218. & m_pFTM );
  219. if ( FAILED(HResult) )
  220. {
  221. return HResult;
  222. }
  223. return S_OK;
  224. }
  225. inline
  226. CSdpConferenceBlob::~CSdpConferenceBlob(
  227. )
  228. {
  229. CLock Lock(g_DllLock);
  230. if ( NULL != m_MediaCollection )
  231. {
  232. ((MEDIA_COLLECTION *)m_MediaCollection)->ClearSdpBlobRefs();
  233. m_MediaCollection->Release();
  234. }
  235. if ( NULL != m_TimeCollection )
  236. {
  237. ((TIME_COLLECTION *)m_TimeCollection)->ClearSdpBlobRefs();
  238. m_TimeCollection->Release();
  239. }
  240. if ( m_pFTM )
  241. {
  242. m_pFTM->Release();
  243. }
  244. }
  245. inline HRESULT
  246. CSdpConferenceBlob::WriteName(
  247. IN BSTR newVal
  248. )
  249. {
  250. CLock Lock(g_DllLock);
  251. return GetSessionName().SetBstr(newVal);
  252. }
  253. inline HRESULT
  254. CSdpConferenceBlob::WriteOriginator(
  255. IN BSTR newVal
  256. )
  257. {
  258. CLock Lock(g_DllLock);
  259. return GetOrigin().GetUserName().SetBstr(newVal);
  260. }
  261. inline HRESULT
  262. CSdpConferenceBlob::WriteUrl(
  263. IN BSTR newVal
  264. )
  265. {
  266. CLock Lock(g_DllLock);
  267. if (NULL == newVal) // Zoltans removed: || (WCHAR_EOS == newVal[0]) )
  268. {
  269. GetUri().Reset();
  270. return S_OK;
  271. }
  272. return GetUri().SetBstr(newVal);
  273. }
  274. inline HRESULT
  275. CSdpConferenceBlob::WriteSessionTitle(
  276. IN BSTR newVal
  277. )
  278. {
  279. CLock Lock(g_DllLock);
  280. if (NULL == newVal) // ZoltanS removed: || (WCHAR_EOS == newVal[0]) )
  281. {
  282. GetSessionTitle().Reset();
  283. return S_OK;
  284. }
  285. return GetSessionTitle().SetBstr(newVal);
  286. }
  287. inline DWORD
  288. CSdpConferenceBlob::DetermineStartTime(
  289. )
  290. {
  291. CLock Lock(g_DllLock);
  292. // if there is no time entry, 0 indicates an unbounded start time
  293. if ( GetTimeList().GetSize() == 0 )
  294. {
  295. return 0;
  296. }
  297. DWORD MinStartTime = DWORD(-1);
  298. // determine the minimum start time value
  299. for(UINT i = 0; (int)i < GetTimeList().GetSize(); i++ )
  300. {
  301. ULONG StartTime;
  302. HRESULT HResult = ((SDP_TIME *)GetTimeList().GetAt(i))->GetStartTime(StartTime);
  303. // ignore invalid values and continue
  304. if ( FAILED(HResult) )
  305. {
  306. continue;
  307. }
  308. if ( StartTime < MinStartTime )
  309. {
  310. MinStartTime = StartTime;
  311. }
  312. }
  313. return MinStartTime;
  314. }
  315. inline DWORD
  316. CSdpConferenceBlob::DetermineStopTime(
  317. )
  318. {
  319. CLock Lock(g_DllLock);
  320. // if there is no time entry, 0 indicates an unbounded stop time
  321. if ( GetTimeList().GetSize() == 0 )
  322. {
  323. return 0;
  324. }
  325. DWORD MaxStopTime = 0;
  326. // determine the max stop time value
  327. for(UINT i = 0; (int)i < GetTimeList().GetSize(); i++ )
  328. {
  329. ULONG StopTime;
  330. HRESULT HResult = ((SDP_TIME *)GetTimeList().GetAt(i))->GetStopTime(StopTime);
  331. // ignore invalid values and continue
  332. if ( FAILED(HResult) )
  333. {
  334. continue;
  335. }
  336. if ( StopTime > MaxStopTime )
  337. {
  338. MaxStopTime = StopTime;
  339. }
  340. }
  341. return MaxStopTime;
  342. }
  343. inline BYTE
  344. CSdpConferenceBlob::GetTtl(
  345. IN RND_ADVERTISING_SCOPE AdvertisingScope
  346. )
  347. {
  348. switch(AdvertisingScope)
  349. {
  350. case RAS_LOCAL:
  351. {
  352. return 1;
  353. }
  354. case RAS_SITE:
  355. {
  356. return 15;
  357. }
  358. case RAS_REGION:
  359. {
  360. return 63;
  361. }
  362. case RAS_WORLD:
  363. default:
  364. {
  365. return 127;
  366. }
  367. };
  368. }
  369. inline RND_ADVERTISING_SCOPE
  370. CSdpConferenceBlob::GetAdvertisingScope(
  371. IN BYTE Ttl
  372. )
  373. {
  374. // check if its local
  375. if ( 1 >= Ttl )
  376. {
  377. return RAS_LOCAL;
  378. }
  379. else if ( 15 >= Ttl )
  380. {
  381. return RAS_SITE;
  382. }
  383. else if ( 63 >= Ttl )
  384. {
  385. return RAS_REGION;
  386. }
  387. // world
  388. return RAS_WORLD;
  389. }
  390. inline BYTE
  391. CSdpConferenceBlob::DetermineTtl(
  392. )
  393. {
  394. CLock Lock(g_DllLock);
  395. // there has to be a default connection field, if its not valid, it must be 1 by default
  396. // since, by default, a value of 1 is not written into the sdp
  397. BYTE MaxTtl = (GetConnection().GetTtl().IsValid())? GetConnection().GetTtl().GetValue() : 1;
  398. // determine the maximum ttl value
  399. for(UINT i = 0; (int)i < GetMediaList().GetSize(); i++ )
  400. {
  401. // get the ttl field
  402. SDP_BYTE &SdpByte = ((SDP_MEDIA *)GetMediaList().GetAt(i))->GetConnection().GetTtl();
  403. // if the ttl field of the connection field is valid
  404. if ( SdpByte.IsValid() )
  405. {
  406. BYTE Ttl = SdpByte.GetValue();
  407. if ( Ttl > MaxTtl )
  408. {
  409. MaxTtl = Ttl;
  410. }
  411. }
  412. }
  413. return MaxTtl;
  414. }
  415. #endif //__SDPCONFERENCEBLOB_H_