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.

154 lines
2.9 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. sdpbw.cpp
  5. Abstract:
  6. Author:
  7. */
  8. #include "sdppch.h"
  9. #include "sdpbw.h"
  10. #include "sdpltran.h"
  11. // line transition states
  12. enum BANDWIDTH_TRANSITION_STATES
  13. {
  14. BANDWIDTH_START,
  15. BANDWIDTH_TYPE,
  16. BANDWIDTH_VALUE
  17. };
  18. // table for bandwidth line transitions
  19. const LINE_TRANSITION g_BandwidthStartTransitions[] = {
  20. {CHAR_COLON, BANDWIDTH_TYPE}
  21. };
  22. const LINE_TRANSITION g_BandwidthTypeTransitions[] = {
  23. {CHAR_NEWLINE, BANDWIDTH_VALUE}
  24. };
  25. /* no transitions */
  26. const LINE_TRANSITION *g_BandwidthValueTransitions = NULL;
  27. LINE_TRANSITION_INFO g_BandwidthTransitionInfo[] = {
  28. LINE_TRANSITION_ENTRY(BANDWIDTH_START, g_BandwidthStartTransitions),
  29. LINE_TRANSITION_ENTRY(BANDWIDTH_TYPE, g_BandwidthTypeTransitions),
  30. LINE_TRANSITION_ENTRY(BANDWIDTH_VALUE, g_BandwidthValueTransitions)
  31. };
  32. SDP_LINE_TRANSITION g_BandwidthTransition(
  33. g_BandwidthTransitionInfo,
  34. sizeof(g_BandwidthTransitionInfo)/sizeof(LINE_TRANSITION_INFO)
  35. );
  36. SDP_BANDWIDTH::SDP_BANDWIDTH(
  37. )
  38. : SDP_VALUE(SDP_INVALID_BANDWIDTH_FIELD, BANDWIDTH_STRING, &g_BandwidthTransition)
  39. {
  40. }
  41. void
  42. SDP_BANDWIDTH::InternalReset(
  43. )
  44. {
  45. m_Modifier.Reset();
  46. m_Bandwidth.Reset();
  47. }
  48. HRESULT
  49. SDP_BANDWIDTH::SetBandwidth(
  50. IN BSTR Modifier,
  51. IN ULONG Value
  52. )
  53. {
  54. // set the modifier field
  55. BAIL_ON_FAILURE(m_Modifier.SetBstr(Modifier));
  56. // set the modifier field
  57. m_Bandwidth.SetValueAndFlag(Value);
  58. // if the field/separator char arrays are empty, fill them
  59. if ( 2 != m_FieldArray.GetSize() )
  60. {
  61. ASSERT(0 == m_FieldArray.GetSize());
  62. ASSERT(0 == m_SeparatorCharArray.GetSize());
  63. try
  64. {
  65. m_FieldArray.SetAtGrow(0, &m_Modifier);
  66. m_SeparatorCharArray.SetAtGrow(0, CHAR_COLON);
  67. m_FieldArray.SetAtGrow(1, &m_Bandwidth);
  68. m_SeparatorCharArray.SetAtGrow(1, CHAR_NEWLINE);
  69. }
  70. catch(...)
  71. {
  72. m_FieldArray.RemoveAll();
  73. m_SeparatorCharArray.RemoveAll();
  74. return E_OUTOFMEMORY;
  75. }
  76. }
  77. return S_OK;
  78. }
  79. BOOL
  80. SDP_BANDWIDTH::GetField(
  81. OUT SDP_FIELD *&Field,
  82. OUT BOOL &AddToArray
  83. )
  84. {
  85. // add in all cases by default
  86. AddToArray = TRUE;
  87. switch(m_LineState)
  88. {
  89. case BANDWIDTH_TYPE:
  90. {
  91. Field = &m_Modifier;
  92. }
  93. break;
  94. case BANDWIDTH_VALUE:
  95. {
  96. Field = &m_Bandwidth;
  97. }
  98. break;
  99. default:
  100. {
  101. SetLastError(m_ErrorCode);
  102. return FALSE;
  103. }
  104. break;
  105. };
  106. return TRUE;
  107. }