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.

405 lines
8.4 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. sdpadtex.cpp
  5. Abstract:
  6. Author:
  7. */
  8. #include "sdppch.h"
  9. #include "sdpadtex.h"
  10. #include "sdpltran.h"
  11. #include <basetyps.h>
  12. #include <oleauto.h>
  13. // line transition states
  14. enum PHONE_TRANSITION_STATES
  15. {
  16. PHONE_START,
  17. PHONE_ONLY_ADDRESS,
  18. PHONE_OPEN_ADDRESS,
  19. PHONE_OPEN_TEXT,
  20. PHONE_CLOSED_ADDRESS,
  21. PHONE_CLOSED_TEXT
  22. };
  23. // table for phone number line transitions
  24. const LINE_TRANSITION g_PhoneStartTransitions[] = {
  25. {CHAR_NEWLINE, PHONE_ONLY_ADDRESS},
  26. {CHAR_LEFT_ANGLE, PHONE_OPEN_ADDRESS},
  27. {CHAR_LEFT_PAREN, PHONE_OPEN_TEXT}
  28. };
  29. /* no transitions */
  30. const LINE_TRANSITION *g_PhoneOnlyAddressTransitions = NULL;
  31. const LINE_TRANSITION g_PhoneOpenAddressTransitions[] = {
  32. {CHAR_RIGHT_ANGLE, PHONE_CLOSED_ADDRESS}
  33. };
  34. const LINE_TRANSITION g_PhoneOpenTextTransitions[] = {
  35. {CHAR_RIGHT_PAREN, PHONE_CLOSED_TEXT}
  36. };
  37. const LINE_TRANSITION g_PhoneClosedAddressTransitions[] = {
  38. {CHAR_NEWLINE, LINE_END}
  39. };
  40. const LINE_TRANSITION g_PhoneClosedTextTransitions[] = {
  41. {CHAR_NEWLINE, LINE_END}
  42. };
  43. LINE_TRANSITION_INFO g_PhoneTransitionInfo[] = {
  44. LINE_TRANSITION_ENTRY(PHONE_START, g_PhoneStartTransitions),
  45. LINE_TRANSITION_ENTRY(PHONE_ONLY_ADDRESS, g_PhoneOnlyAddressTransitions),
  46. LINE_TRANSITION_ENTRY(PHONE_OPEN_ADDRESS, g_PhoneOpenAddressTransitions),
  47. LINE_TRANSITION_ENTRY(PHONE_OPEN_TEXT, g_PhoneOpenTextTransitions),
  48. LINE_TRANSITION_ENTRY(PHONE_CLOSED_ADDRESS, g_PhoneClosedAddressTransitions),
  49. LINE_TRANSITION_ENTRY(PHONE_CLOSED_TEXT, g_PhoneClosedTextTransitions)
  50. };
  51. // line transition states
  52. enum EMAIL_TRANSITION_STATES
  53. {
  54. EMAIL_START,
  55. EMAIL_ONLY_ADDRESS,
  56. EMAIL_OPEN_ADDRESS,
  57. EMAIL_OPEN_TEXT,
  58. EMAIL_CLOSED_ADDRESS,
  59. EMAIL_CLOSED_TEXT
  60. };
  61. // table for email line transitions
  62. const LINE_TRANSITION g_EmailStartTransitions[] = {
  63. {CHAR_NEWLINE, EMAIL_ONLY_ADDRESS},
  64. {CHAR_LEFT_ANGLE, EMAIL_OPEN_ADDRESS},
  65. {CHAR_LEFT_PAREN, EMAIL_OPEN_TEXT}
  66. };
  67. /* no transitions */
  68. const LINE_TRANSITION *g_EmailOnlyAddressTransitions = NULL;
  69. const LINE_TRANSITION g_EmailOpenAddressTransitions[] = {
  70. {CHAR_RIGHT_ANGLE, EMAIL_CLOSED_ADDRESS}
  71. };
  72. const LINE_TRANSITION g_EmailOpenTextTransitions[] = {
  73. {CHAR_RIGHT_PAREN, EMAIL_CLOSED_TEXT}
  74. };
  75. const LINE_TRANSITION g_EmailClosedAddressTransitions[] = {
  76. {CHAR_NEWLINE, LINE_END}
  77. };
  78. const LINE_TRANSITION g_EmailClosedTextTransitions[] = {
  79. {CHAR_NEWLINE, LINE_END}
  80. };
  81. LINE_TRANSITION_INFO g_EmailTransitionInfo[] = {
  82. LINE_TRANSITION_ENTRY(EMAIL_START, g_EmailStartTransitions),
  83. LINE_TRANSITION_ENTRY(EMAIL_ONLY_ADDRESS, g_EmailOnlyAddressTransitions),
  84. LINE_TRANSITION_ENTRY(EMAIL_OPEN_ADDRESS, g_EmailOpenAddressTransitions),
  85. LINE_TRANSITION_ENTRY(EMAIL_OPEN_TEXT, g_EmailOpenTextTransitions),
  86. LINE_TRANSITION_ENTRY(EMAIL_CLOSED_ADDRESS, g_EmailClosedAddressTransitions),
  87. LINE_TRANSITION_ENTRY(EMAIL_CLOSED_TEXT, g_EmailClosedTextTransitions)
  88. };
  89. static SDP_LINE_TRANSITION g_EmailTransition(
  90. g_EmailTransitionInfo,
  91. sizeof(g_EmailTransitionInfo)/sizeof(LINE_TRANSITION_INFO)
  92. );
  93. static SDP_LINE_TRANSITION g_PhoneTransition(
  94. g_PhoneTransitionInfo,
  95. sizeof(g_PhoneTransitionInfo)/sizeof(LINE_TRANSITION_INFO)
  96. );
  97. void
  98. SDP_ADDRESS_TEXT::InternalReset(
  99. )
  100. {
  101. m_Address.Reset();
  102. m_Text.Reset();
  103. }
  104. HRESULT
  105. SDP_ADDRESS_TEXT::SetAddressTextValues(
  106. IN BSTR AddressBstr,
  107. IN BSTR TextBstr
  108. )
  109. {
  110. HRESULT HResult = m_Address.SetBstr(AddressBstr);
  111. if ( FAILED(HResult) )
  112. {
  113. return HResult;
  114. }
  115. // the text string can be NULL
  116. if ( NULL == TextBstr )
  117. {
  118. // check if the field and separator char arrays need to be modified
  119. if ( m_FieldArray.GetSize() != 1 )
  120. {
  121. // reset text
  122. m_Text.Reset();
  123. // clear the field and separator char arrays
  124. m_FieldArray.RemoveAll();
  125. m_SeparatorCharArray.RemoveAll();
  126. try
  127. {
  128. // set as (address, '\n')
  129. m_FieldArray.SetAtGrow(0, &m_Address);
  130. m_SeparatorCharArray.SetAtGrow(0, CHAR_NEWLINE);
  131. }
  132. catch(...)
  133. {
  134. m_FieldArray.RemoveAll();
  135. m_SeparatorCharArray.RemoveAll();
  136. return E_OUTOFMEMORY;
  137. }
  138. }
  139. }
  140. else
  141. {
  142. // try to set the text bstr
  143. HResult = m_Text.SetBstr(TextBstr);
  144. if ( FAILED(HResult) )
  145. {
  146. return HResult;
  147. }
  148. // check if field and separator char arrays need to be modified
  149. if ( m_FieldArray.GetSize() != 3 )
  150. {
  151. // clear the field and separator char arrays
  152. m_FieldArray.RemoveAll();
  153. m_SeparatorCharArray.RemoveAll();
  154. try
  155. {
  156. // set as (address, '('), (text, ')'), (NULL, '\n')
  157. m_FieldArray.Add(&m_Address);
  158. m_SeparatorCharArray.Add(CHAR_LEFT_PAREN);
  159. m_FieldArray.Add(&m_Text);
  160. m_SeparatorCharArray.Add(CHAR_RIGHT_PAREN);
  161. m_FieldArray.Add(NULL);
  162. m_SeparatorCharArray.Add(CHAR_NEWLINE);
  163. }
  164. catch(...)
  165. {
  166. m_FieldArray.RemoveAll();
  167. m_SeparatorCharArray.RemoveAll();
  168. return E_OUTOFMEMORY;
  169. }
  170. }
  171. }
  172. return S_OK;
  173. }
  174. SDP_EMAIL::SDP_EMAIL(
  175. )
  176. : SDP_ADDRESS_TEXT(SDP_INVALID_EMAIL_FIELD, EMAIL_STRING, &g_EmailTransition)
  177. {
  178. }
  179. BOOL
  180. SDP_EMAIL::GetField(
  181. OUT SDP_FIELD *&Field,
  182. OUT BOOL &AddToArray
  183. )
  184. {
  185. // add in all cases by default
  186. AddToArray = TRUE;
  187. switch(m_LineState)
  188. {
  189. case EMAIL_ONLY_ADDRESS:
  190. case EMAIL_OPEN_TEXT:
  191. case EMAIL_CLOSED_ADDRESS:
  192. {
  193. Field = &m_Address;
  194. }
  195. break;
  196. case EMAIL_OPEN_ADDRESS:
  197. case EMAIL_CLOSED_TEXT:
  198. {
  199. Field = &m_Text;
  200. }
  201. break;
  202. default:
  203. {
  204. SetLastError(m_ErrorCode);
  205. return FALSE;
  206. }
  207. break;
  208. };
  209. return TRUE;
  210. }
  211. SDP_PHONE::SDP_PHONE(
  212. )
  213. : SDP_ADDRESS_TEXT(SDP_INVALID_PHONE_FIELD, PHONE_STRING, &g_PhoneTransition)
  214. {
  215. }
  216. BOOL
  217. SDP_PHONE::GetField(
  218. OUT SDP_FIELD *&Field,
  219. OUT BOOL &AddToArray
  220. )
  221. {
  222. // add in all cases by default
  223. AddToArray = TRUE;
  224. switch(m_LineState)
  225. {
  226. case PHONE_ONLY_ADDRESS:
  227. case PHONE_OPEN_TEXT:
  228. case PHONE_CLOSED_ADDRESS:
  229. {
  230. Field = &m_Address;
  231. }
  232. break;
  233. case PHONE_OPEN_ADDRESS:
  234. case PHONE_CLOSED_TEXT:
  235. {
  236. Field = &m_Text;
  237. }
  238. break;
  239. default:
  240. {
  241. SetLastError(m_ErrorCode);
  242. return FALSE;
  243. }
  244. break;
  245. };
  246. return TRUE;
  247. }
  248. SDP_VALUE *
  249. SDP_PHONE_LIST::CreateElement(
  250. )
  251. {
  252. SDP_PHONE *SdpPhone;
  253. try
  254. {
  255. SdpPhone = new SDP_PHONE();
  256. }
  257. catch(...)
  258. {
  259. SdpPhone = NULL;
  260. }
  261. if (NULL == SdpPhone)
  262. {
  263. return NULL;
  264. }
  265. if ( !SdpPhone->SetCharacterSet(m_CharacterSet) )
  266. {
  267. delete SdpPhone;
  268. return NULL;
  269. }
  270. return SdpPhone;
  271. }
  272. SDP_VALUE *
  273. SDP_EMAIL_LIST::CreateElement(
  274. )
  275. {
  276. SDP_EMAIL *SdpEmail;
  277. try
  278. {
  279. SdpEmail = new SDP_EMAIL();
  280. }
  281. catch(...)
  282. {
  283. SdpEmail = NULL;
  284. }
  285. if(NULL == SdpEmail)
  286. {
  287. return NULL;
  288. }
  289. if ( !SdpEmail->SetCharacterSet(m_CharacterSet) )
  290. {
  291. delete SdpEmail;
  292. return NULL;
  293. }
  294. return SdpEmail;
  295. }