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.

140 lines
3.3 KiB

  1. /*
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. blbatt.cpp
  5. Abstract:
  6. Author:
  7. */
  8. #include "stdafx.h"
  9. #include "blbgen.h"
  10. #include "blbatt.h"
  11. // variants are validated in the get/set safearray methods
  12. // bstrs are validated in the GetBstrCopy and SetBstr methods. they may also
  13. // be optionally validated before taking any action, if there is a possibility
  14. // of having to roll back some of the work done on finding them invalid
  15. STDMETHODIMP ITAttributeListImpl::get_Count(LONG * pVal)
  16. {
  17. BAIL_IF_NULL(pVal, E_INVALIDARG);
  18. CLock Lock(g_DllLock);
  19. ASSERT(NULL != m_SdpAttributeList);
  20. *pVal = (LONG)m_SdpAttributeList->GetSize();
  21. return S_OK;
  22. }
  23. STDMETHODIMP ITAttributeListImpl::get_Item(LONG Index, BSTR * pVal)
  24. {
  25. CLock Lock(g_DllLock);
  26. ASSERT(NULL != m_SdpAttributeList);
  27. // vb indices are in the range [1..GetSize()]
  28. if ( !((1 <= Index) && (Index <= m_SdpAttributeList->GetSize())) )
  29. {
  30. return E_INVALIDARG;
  31. }
  32. // adjust the index to the range [0..(GetSize()-1)]
  33. return ((SDP_REQD_BSTRING_LINE *)m_SdpAttributeList->GetAt(Index-1))->GetBstrCopy(pVal);
  34. }
  35. STDMETHODIMP ITAttributeListImpl::Add(LONG Index, BSTR Attribute)
  36. {
  37. BAIL_IF_NULL(Attribute, E_INVALIDARG);
  38. CLock Lock(g_DllLock);
  39. ASSERT(NULL != m_SdpAttributeList);
  40. // index should be in the range [1..GetSize()+1]
  41. if ( !((1 <= Index) && (Index <= (m_SdpAttributeList->GetSize()+1))) )
  42. {
  43. return E_INVALIDARG;
  44. }
  45. // create an attribute line
  46. SDP_REQD_BSTRING_LINE *AttributeLine =
  47. (SDP_REQD_BSTRING_LINE *)m_SdpAttributeList->CreateElement();
  48. if( NULL == AttributeLine )
  49. {
  50. return E_OUTOFMEMORY;
  51. }
  52. // set the passed in attribute in the attribute line
  53. HRESULT ToReturn = AttributeLine->SetBstr(Attribute);
  54. if ( FAILED(ToReturn) )
  55. {
  56. delete AttributeLine;
  57. return ToReturn;
  58. }
  59. // insert the attribute line, shift elements with equal or higher indices forwards
  60. m_SdpAttributeList->InsertAt(Index-1, AttributeLine);
  61. return S_OK;
  62. }
  63. STDMETHODIMP ITAttributeListImpl::Delete(LONG Index)
  64. {
  65. CLock Lock(g_DllLock);
  66. ASSERT(NULL != m_SdpAttributeList);
  67. // vb indices are in the range [1..GetSize()]
  68. if ( !((1 <= Index) && (Index <= m_SdpAttributeList->GetSize())) )
  69. {
  70. return E_INVALIDARG;
  71. }
  72. // adjust the index to the range [0..(GetSize()-1)]
  73. // delete the attribute line, remove the ptr from the array; shifting elements with higher
  74. // index lower
  75. delete m_SdpAttributeList->GetAt(Index-1);
  76. m_SdpAttributeList->RemoveAt(Index-1);
  77. return S_OK;
  78. }
  79. STDMETHODIMP ITAttributeListImpl::get_AttributeList(VARIANT /*SAFEARRAY(BSTR)*/ * pVal)
  80. {
  81. CLock Lock(g_DllLock);
  82. ASSERT(NULL != m_SdpAttributeList);
  83. return m_SdpAttributeList->GetSafeArray(pVal);
  84. }
  85. STDMETHODIMP ITAttributeListImpl::put_AttributeList(VARIANT /*SAFEARRAY(BSTR)*/ newVal)
  86. {
  87. CLock Lock(g_DllLock);
  88. ASSERT(NULL != m_SdpAttributeList);
  89. if ( NULL == V_ARRAY(&newVal) )
  90. {
  91. m_SdpAttributeList->Reset();
  92. return S_OK;
  93. }
  94. return m_SdpAttributeList->SetSafeArray(newVal);
  95. }