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.

212 lines
4.2 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. sdpcstrl.cpp
  5. Abstract:
  6. Author:
  7. */
  8. #include "sdppch.h"
  9. #include <strstrea.h>
  10. #include "sdpcstrl.h"
  11. #include "sdpgen.h"
  12. #include <winsock2.h>
  13. void
  14. SDP_CHAR_STRING::Reset(
  15. )
  16. {
  17. // perform the destructor actions (freeing ptrs) and the constructor actions (initializing
  18. // member variables to starting values)
  19. // check if there is a valid character string
  20. if (NULL != m_CharacterString)
  21. {
  22. // free the character string
  23. delete m_CharacterString;
  24. }
  25. m_CharacterString = NULL;
  26. m_CharacterStringLength = 0;
  27. m_LengthByReference = 0;
  28. m_CharacterStringByReference = NULL;
  29. m_BytesAllocated = 0;
  30. // call the base class Reset
  31. SDP_SINGLE_FIELD::Reset();
  32. }
  33. BOOL
  34. SDP_CHAR_STRING::InternalSetCharStrByRef(
  35. IN CHAR *CharacterStringByReference,
  36. IN DWORD Length
  37. )
  38. {
  39. // if pointing to a char string by copy, that can be released (though this is not necessary
  40. // and can be optimized away - speed vs. memory tradeoff)
  41. // check if there is a valid character string
  42. if (NULL != m_CharacterString)
  43. {
  44. // free the character string
  45. delete m_CharacterString;
  46. m_CharacterString = NULL;
  47. m_CharacterStringLength = 0;
  48. m_BytesAllocated = 0;
  49. }
  50. m_CharacterStringByReference = CharacterStringByReference;
  51. m_LengthByReference = Length;
  52. return TRUE;
  53. }
  54. BOOL
  55. SDP_CHAR_STRING::InternalSetCharStrByCopy(
  56. IN const CHAR *CharacterStringByCopy,
  57. IN DWORD Length
  58. )
  59. {
  60. // reallocate the char string buffer if required
  61. if ( !ReAllocCharacterString(Length+1) )
  62. {
  63. return FALSE;
  64. }
  65. strcpy(m_CharacterString, CharacterStringByCopy);
  66. return TRUE;
  67. }
  68. DWORD
  69. SDP_CHAR_STRING::CalcCharacterStringSize(
  70. )
  71. {
  72. IsModified(FALSE);
  73. m_PrintLength = GetLength();
  74. return m_PrintLength;
  75. }
  76. BOOL
  77. SDP_CHAR_STRING::CopyField(
  78. OUT ostrstream &OutputStream
  79. )
  80. {
  81. ASSERT(IsValid());
  82. ASSERT(NULL != GetCharacterString());
  83. if ( NULL != GetCharacterString() )
  84. {
  85. OutputStream << GetCharacterString();
  86. if( OutputStream.fail() )
  87. {
  88. SetLastError(SDP_OUTPUT_ERROR);
  89. return FALSE;
  90. }
  91. }
  92. return TRUE;
  93. }
  94. BOOL
  95. SDP_CHAR_STRING::InternalParseToken(
  96. IN CHAR *Token
  97. )
  98. {
  99. if ( !ReAllocCharacterString(strlen(Token)+1) )
  100. {
  101. return FALSE;
  102. }
  103. strcpy(m_CharacterString, Token);
  104. return TRUE;
  105. }
  106. SDP_CHAR_STRING::~SDP_CHAR_STRING(
  107. )
  108. {
  109. // check if there is a valid character string
  110. if (NULL != m_CharacterString)
  111. {
  112. // free the character string
  113. delete m_CharacterString;
  114. }
  115. }
  116. BOOL
  117. SDP_STRING_LINE::InternalParseLine(
  118. IN OUT CHAR *&Line
  119. )
  120. {
  121. CHAR SeparatorChar = '\0';
  122. // identify the token. if one of the the separator characters is found, replace
  123. // it by EOS and return the separator char. if none of the separator characters are
  124. // found, return NULL (ex. if EOS found first, return NULL)
  125. CHAR *Token = GetToken(Line, 1, NEWLINE_STRING, SeparatorChar);
  126. // when the block goes out of scope,
  127. // set the EOS character to the token separator character
  128. LINE_TERMINATOR LineTerminator(Token, SeparatorChar);
  129. // if there is no such token
  130. if ( !LineTerminator.IsLegal() )
  131. {
  132. SetLastError(m_ErrorCode);
  133. return FALSE;
  134. }
  135. // advance the line to the start of the next token
  136. Line += (LineTerminator.GetLength() + 1);
  137. BOOL ToReturn = GetParseField().ParseToken(Token);
  138. INT_PTR Index;
  139. // fill in the CArrays for separator char and field
  140. try
  141. {
  142. Index = m_SeparatorCharArray.Add(CHAR_NEWLINE);
  143. }
  144. catch(...)
  145. {
  146. SetLastError(ERROR_OUTOFMEMORY);
  147. return FALSE;
  148. }
  149. try
  150. {
  151. m_FieldArray.Add(&GetParseField());
  152. }
  153. catch(...)
  154. {
  155. m_SeparatorCharArray.RemoveAt(Index);
  156. SetLastError(ERROR_OUTOFMEMORY);
  157. return FALSE;
  158. }
  159. return ToReturn;
  160. }