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.

126 lines
3.0 KiB

  1. /*
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. blbsdp.cpp
  5. Abstract:
  6. Author:
  7. */
  8. #include "stdafx.h"
  9. #include "blbgen.h"
  10. #include "blbsdp.h"
  11. const CHAR g_CharSetString[] = "\na=charset:";
  12. HRESULT
  13. SDP_BLOB::SetBstr(
  14. IN BSTR SdpPacketBstr
  15. )
  16. {
  17. // convert string to ANSI using the optional bstr base class
  18. HRESULT HResult = SDP_BSTRING::SetBstr(SdpPacketBstr);
  19. BAIL_ON_FAILURE(HResult);
  20. // parse the ANSI character string
  21. if ( !ParseSdpPacket(
  22. SDP_BSTRING::GetCharacterString(),
  23. SDP_BSTRING::GetCharacterSet()
  24. ) )
  25. {
  26. return HRESULT_FROM_ERROR_CODE(GetLastError());
  27. }
  28. return S_OK;
  29. }
  30. HRESULT
  31. SDP_BLOB::SetTstr(
  32. IN TCHAR *SdpPacketTstr
  33. )
  34. {
  35. ASSERT(NULL != SdpPacketTstr);
  36. #ifdef _UNICODE // TCHAR is WCHAR
  37. BSTR SdpPacketBstr = SysAllocString(SdpPacketTstr);
  38. BAIL_IF_NULL(SdpPacketBstr, E_OUTOFMEMORY);
  39. HRESULT HResult = SetBstr(SdpPacketBstr);
  40. SysFreeString(SdpPacketBstr);
  41. return HResult;
  42. #else // TCHAR is CHAR
  43. // parse the ANSI character string
  44. if ( !ParseSdpPacket(SdpPacketTstr) )
  45. {
  46. return HRESULT_FROM_ERROR_CODE(GetLastError());
  47. }
  48. // associate the character string with the SDP_BSTRING base instance
  49. // *** need a SetCharacterStringByPtr for optimizing this copy
  50. if ( !SDP_BSTRING::SetCharacterStringByCopy(SdpPacketTstr) )
  51. {
  52. return HRESULT_FROM_ERROR_CODE(GetLastError());
  53. }
  54. return S_OK;
  55. #endif // _UNICODE
  56. // should never reach here
  57. ASSERT(FALSE);
  58. return S_OK;
  59. }
  60. HRESULT
  61. SDP_BLOB::GetBstr(
  62. OUT BSTR *SdpPacketBstr
  63. )
  64. {
  65. if ( !SDP::IsValid() )
  66. {
  67. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  68. }
  69. // keep track of the old SDP packet pointer for a check below because we may reallocate m_SdpPacket
  70. // in the call to GenerateSdpPacket, but we may have a pointer to the old SDP packet stored as a
  71. // string by reference. If this is the case we need to be sure to SetCharacterStringByReference(m_SdpPacket).
  72. CHAR * OldSdpPacket = m_SdpPacket;
  73. // generate the character string SDP packet
  74. if ( !SDP::GenerateSdpPacket() )
  75. {
  76. return HRESULT_FROM_ERROR_CODE(GetLastError());
  77. }
  78. // check if the sdp packet has changed since last time
  79. // ZoltanS: if the pointers are equal, we have no way of knowing
  80. // without doing Unicode-to-ASCII conversion; always reassociate.
  81. char * pszBstrVersion = SDP_BSTRING::GetCharacterString();
  82. if( NULL == pszBstrVersion )
  83. {
  84. return E_OUTOFMEMORY;
  85. }
  86. if ( ( pszBstrVersion == m_SdpPacket ) || ( pszBstrVersion == OldSdpPacket ) || strcmp(pszBstrVersion, m_SdpPacket) )
  87. {
  88. // associate the optional bstr instance with the sdp packet character string
  89. SDP_BSTRING::SetCharacterStringByReference(m_SdpPacket);
  90. }
  91. return SDP_BSTRING::GetBstr(SdpPacketBstr);
  92. }