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.

345 lines
7.5 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. */
  4. #include "sdppch.h"
  5. #include <strstrea.h>
  6. #include "sdpmedia.h"
  7. #include "sdpltran.h"
  8. #include "sdp.h"
  9. // line transition states
  10. enum MEDIA_TRANSITION_STATES
  11. {
  12. MEDIA_START,
  13. MEDIA_NAME,
  14. MEDIA_PORT,
  15. MEDIA_PORT_NUM_PORTS,
  16. MEDIA_NUM_PORTS,
  17. MEDIA_PROTOCOL,
  18. MEDIA_FORMAT_CODE,
  19. MEDIA_FORMAT_CODE_END
  20. };
  21. // table for media line transitions
  22. const LINE_TRANSITION g_MediaStartTransitions[] = {
  23. {CHAR_BLANK, MEDIA_NAME}
  24. };
  25. const LINE_TRANSITION g_MediaNameTransitions[] = {
  26. {CHAR_BLANK, MEDIA_PORT},
  27. {CHAR_BACK_SLASH, MEDIA_PORT_NUM_PORTS}
  28. };
  29. const LINE_TRANSITION g_MediaPortTransitions[] = {
  30. {CHAR_BLANK, MEDIA_PROTOCOL}
  31. };
  32. const LINE_TRANSITION g_MediaPortNumPortsTransitions[]= {
  33. {CHAR_BLANK, MEDIA_NUM_PORTS}
  34. };
  35. const LINE_TRANSITION g_MediaNumPortsTransitions[] = {
  36. {CHAR_BLANK, MEDIA_PROTOCOL}
  37. };
  38. const LINE_TRANSITION g_MediaProtocolTransitions[] = {
  39. {CHAR_BLANK, MEDIA_FORMAT_CODE},
  40. {CHAR_NEWLINE, MEDIA_FORMAT_CODE_END}
  41. };
  42. const LINE_TRANSITION g_MediaFormatCodeTransitions[]= {
  43. {CHAR_BLANK, MEDIA_FORMAT_CODE},
  44. {CHAR_NEWLINE, MEDIA_FORMAT_CODE_END}
  45. };
  46. /* no transitions */
  47. const LINE_TRANSITION *g_MediaFormatCodeEndTransitions = NULL;
  48. LINE_TRANSITION_INFO g_MediaTransitionInfo[] = {
  49. LINE_TRANSITION_ENTRY(MEDIA_START, g_MediaStartTransitions),
  50. LINE_TRANSITION_ENTRY(MEDIA_NAME, g_MediaNameTransitions),
  51. LINE_TRANSITION_ENTRY(MEDIA_PORT, g_MediaPortTransitions),
  52. LINE_TRANSITION_ENTRY(MEDIA_PORT_NUM_PORTS, g_MediaPortNumPortsTransitions),
  53. LINE_TRANSITION_ENTRY(MEDIA_NUM_PORTS, g_MediaNumPortsTransitions),
  54. LINE_TRANSITION_ENTRY(MEDIA_PROTOCOL, g_MediaProtocolTransitions),
  55. LINE_TRANSITION_ENTRY(MEDIA_FORMAT_CODE, g_MediaFormatCodeTransitions),
  56. LINE_TRANSITION_ENTRY(MEDIA_FORMAT_CODE_END,g_MediaFormatCodeEndTransitions)
  57. };
  58. SDP_LINE_TRANSITION g_MediaTransition(
  59. g_MediaTransitionInfo,
  60. sizeof(g_MediaTransitionInfo)/sizeof(LINE_TRANSITION_INFO)
  61. );
  62. SDP_MEDIA::SDP_MEDIA(
  63. )
  64. : SDP_VALUE(SDP_INVALID_MEDIA_FIELD, MEDIA_STRING, &g_MediaTransition),
  65. m_Title(SDP_INVALID_MEDIA_TITLE, MEDIA_TITLE_STRING),
  66. m_AttributeList(MEDIA_ATTRIBUTE_STRING)
  67. {
  68. m_NumPorts.SetValue(1);
  69. }
  70. void
  71. SDP_MEDIA::InternalReset(
  72. )
  73. {
  74. m_Name.Reset();
  75. m_StartPort.Reset();
  76. m_NumPorts.Reset();
  77. m_TransportProtocol.Reset();
  78. m_FormatCodeList.Reset();
  79. m_Title.Reset();
  80. m_Connection.Reset();
  81. m_Bandwidth.Reset();
  82. m_EncryptionKey.Reset();
  83. m_AttributeList.Reset();
  84. }
  85. BOOL
  86. SDP_MEDIA::CalcIsModified(
  87. ) const
  88. {
  89. ASSERT(IsValid());
  90. return
  91. m_Title.IsModified() ||
  92. m_Connection.IsModified() ||
  93. m_Bandwidth.IsModified() ||
  94. SDP_VALUE::CalcIsModified() ||
  95. m_EncryptionKey.IsModified() ||
  96. m_AttributeList.IsModified();
  97. }
  98. DWORD
  99. SDP_MEDIA::CalcCharacterStringSize(
  100. )
  101. {
  102. ASSERT(IsValid());
  103. return (
  104. m_Title.GetCharacterStringSize() +
  105. m_Connection.GetCharacterStringSize() +
  106. m_Bandwidth.GetCharacterStringSize() +
  107. SDP_VALUE::CalcCharacterStringSize() +
  108. m_EncryptionKey.GetCharacterStringSize() +
  109. m_AttributeList.GetCharacterStringSize()
  110. );
  111. }
  112. BOOL
  113. SDP_MEDIA::CopyValue(
  114. OUT ostrstream &OutputStream
  115. )
  116. {
  117. ASSERT(IsValid());
  118. return (
  119. SDP_VALUE::CopyValue(OutputStream) &&
  120. m_Title.PrintValue(OutputStream) &&
  121. m_Connection.PrintValue(OutputStream) &&
  122. m_Bandwidth.PrintValue(OutputStream) &&
  123. m_EncryptionKey.PrintValue(OutputStream) &&
  124. m_AttributeList.PrintValue(OutputStream)
  125. );
  126. }
  127. // this is a workaround/hack for reusing the base class SDP_VALUE code for PrintValue().
  128. // it replaces the separator char for the last read field with a newline, so that when
  129. // PrintValue() executes and prints the time period list, it puts the newline character at
  130. // the end of the list (rather than CHAR_BLANK)
  131. BOOL
  132. SDP_MEDIA::InternalParseLine(
  133. IN OUT CHAR *&Line
  134. )
  135. {
  136. if ( !SDP_VALUE::InternalParseLine(Line) )
  137. {
  138. return FALSE;
  139. }
  140. m_SeparatorCharArray[m_SeparatorCharArray.GetSize()-1] = CHAR_NEWLINE;
  141. return TRUE;
  142. }
  143. BOOL
  144. SDP_MEDIA::GetField(
  145. OUT SDP_FIELD *&Field,
  146. OUT BOOL &AddToArray
  147. )
  148. {
  149. // add in all cases by default
  150. AddToArray = TRUE;
  151. switch(m_LineState)
  152. {
  153. case MEDIA_NAME:
  154. {
  155. Field = &m_Name;
  156. }
  157. break;
  158. case MEDIA_PORT:
  159. {
  160. Field = &m_StartPort;
  161. }
  162. break;
  163. case MEDIA_PORT_NUM_PORTS:
  164. {
  165. Field = &m_StartPort;
  166. }
  167. break;
  168. case MEDIA_NUM_PORTS:
  169. {
  170. Field = &m_NumPorts;
  171. }
  172. break;
  173. case MEDIA_PROTOCOL:
  174. {
  175. Field = &m_TransportProtocol;
  176. }
  177. break;
  178. case MEDIA_FORMAT_CODE:
  179. case MEDIA_FORMAT_CODE_END:
  180. {
  181. if ( m_FormatCodeList.GetSize() > 0 )
  182. {
  183. AddToArray = FALSE;
  184. }
  185. Field = &m_FormatCodeList;
  186. }
  187. break;
  188. default:
  189. {
  190. SetLastError(m_ErrorCode);
  191. return FALSE;
  192. }
  193. break;
  194. };
  195. return TRUE;
  196. }
  197. HRESULT
  198. SDP_MEDIA::SetPortInfo(
  199. IN USHORT StartPort,
  200. IN USHORT NumPorts
  201. )
  202. {
  203. ASSERT(IsValid());
  204. // validate parameters
  205. // num ports or start port cannot be 0
  206. if ( (0 == StartPort) || (0 == NumPorts) )
  207. {
  208. return E_INVALIDARG;
  209. }
  210. // set member variables to the start port
  211. m_StartPort.SetValue(StartPort);
  212. // if the number of ports field is already valid, then
  213. if ( m_NumPorts.IsValid() )
  214. {
  215. // set the value and return, no changes required in the
  216. // field/separator arrays
  217. m_NumPorts.SetValue(NumPorts);
  218. return S_OK;
  219. }
  220. else // ports field is not in the field array
  221. {
  222. // if the number of ports is 1, no changes are required
  223. if ( 1 == NumPorts )
  224. {
  225. return S_OK;
  226. }
  227. // set the value and flag for the num ports field
  228. m_NumPorts.SetValueAndFlag(NumPorts);
  229. // insert the num ports field/separator after the the
  230. // media name and port fields/separators
  231. // the new port separator must be CHAR_BACK_SLASH
  232. ASSERT(m_FieldArray.GetSize() == m_SeparatorCharArray.GetSize());
  233. m_SeparatorCharArray.SetAt(1, CHAR_BACK_SLASH);
  234. m_FieldArray.InsertAt(2, &m_NumPorts);
  235. m_SeparatorCharArray.InsertAt(2, CHAR_BLANK);
  236. }
  237. return S_OK;
  238. }
  239. SDP_VALUE *
  240. SDP_MEDIA_LIST::CreateElement(
  241. )
  242. {
  243. SDP_MEDIA *SdpMedia;
  244. try
  245. {
  246. SdpMedia = new SDP_MEDIA();
  247. }
  248. catch(...)
  249. {
  250. SdpMedia = NULL;
  251. }
  252. if( NULL == SdpMedia )
  253. {
  254. return NULL;
  255. }
  256. SdpMedia->GetTitle().GetBstring().SetCharacterSet(m_CharacterSet);
  257. return SdpMedia;
  258. }