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.

525 lines
13 KiB

  1. /****************************************************************************
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name: rules.cpp
  4. Abstract: Rules Object implementation
  5. Author: noela - 09/11/98
  6. Notes:
  7. Rev History:
  8. ****************************************************************************/
  9. //#define unicode
  10. #include <windows.h>
  11. #include <objbase.h>
  12. #include "tapi.h"
  13. #include "tspi.h"
  14. #include "utils.h"
  15. #include "client.h"
  16. #include "rules.h"
  17. /****************************************************************************
  18. Class : CRuleSet
  19. Method : Constructer
  20. ****************************************************************************/
  21. CRuleSet::CRuleSet()
  22. {
  23. m_pszInternationalRule = NULL;
  24. m_pszLongDistanceRule = NULL;
  25. m_pszLocalRule = NULL;
  26. }
  27. /****************************************************************************
  28. Class : CRuleSet
  29. Method : Destructer
  30. Clean up memory allocations
  31. ****************************************************************************/
  32. CRuleSet::~CRuleSet()
  33. {
  34. if ( m_pszInternationalRule != NULL )
  35. {
  36. ClientFree(m_pszInternationalRule);
  37. }
  38. if ( m_pszLongDistanceRule != NULL )
  39. {
  40. ClientFree(m_pszLongDistanceRule);
  41. }
  42. if ( m_pszLocalRule != NULL )
  43. {
  44. ClientFree(m_pszLocalRule);
  45. }
  46. }
  47. /****************************************************************************
  48. Class : CRuleSet
  49. Method : Initialize
  50. ****************************************************************************/
  51. STDMETHODIMP CRuleSet::Initialize
  52. (
  53. PWSTR pszInternationalRule,
  54. PWSTR pszLongDistanceRule,
  55. PWSTR pszLocalRule
  56. )
  57. {
  58. //////////////////////////////////////////////////
  59. // copy the international Rule
  60. //
  61. m_pszInternationalRule = ClientAllocString( pszInternationalRule );
  62. if (m_pszInternationalRule == NULL)
  63. {
  64. LOG(( TL_ERROR, "Initialize create m_pszInternationalRule failed" ));
  65. return E_OUTOFMEMORY;
  66. }
  67. //////////////////////////////////////////////////
  68. // copy the long Distance Rule
  69. //
  70. m_pszLongDistanceRule = ClientAllocString( pszLongDistanceRule );
  71. if (m_pszLongDistanceRule == NULL)
  72. {
  73. ClientFree(m_pszInternationalRule);
  74. LOG(( TL_ERROR, "Initialize create m_pszLongDistanceRule failed" ));
  75. return E_OUTOFMEMORY;
  76. }
  77. //////////////////////////////////////////////////
  78. // copy the local Rule
  79. //
  80. m_pszLocalRule = ClientAllocString( pszLocalRule );
  81. if (m_pszLocalRule == NULL)
  82. {
  83. ClientFree(m_pszInternationalRule);
  84. ClientFree(m_pszLongDistanceRule);
  85. LOG(( TL_ERROR, "Initialize create m_pszLocalRule failed" ));
  86. return E_OUTOFMEMORY;
  87. }
  88. return S_OK;
  89. }
  90. /****************************************************************************
  91. /****************************************************************************
  92. /****************************************************************************
  93. Class : CAreaCodeRule
  94. Method : Constructer
  95. ****************************************************************************/
  96. CAreaCodeRule::CAreaCodeRule()
  97. {
  98. m_pszAreaCode = NULL;
  99. m_pszNumberToDial = NULL;
  100. m_pszzPrefixList = NULL;
  101. }
  102. /****************************************************************************
  103. Class : CAreaCodeRule
  104. Method : Destructer
  105. Clean up memory allocations
  106. ****************************************************************************/
  107. CAreaCodeRule::~CAreaCodeRule()
  108. {
  109. if ( m_pszAreaCode != NULL )
  110. {
  111. ClientFree(m_pszAreaCode);
  112. }
  113. if ( m_pszNumberToDial != NULL )
  114. {
  115. ClientFree(m_pszNumberToDial);
  116. }
  117. if ( m_pszzPrefixList != NULL )
  118. {
  119. ClientFree(m_pszzPrefixList);
  120. }
  121. }
  122. /****************************************************************************
  123. Class : CAreaCodeRule
  124. Method : Initialize
  125. ****************************************************************************/
  126. STDMETHODIMP CAreaCodeRule::Initialize
  127. (
  128. PWSTR pszAreaCode,
  129. PWSTR pszNumberToDial,
  130. DWORD dwOptions,
  131. PWSTR pszzPrefixList,
  132. DWORD dwPrefixListSize
  133. )
  134. {
  135. HRESULT hr = S_OK;
  136. //////////////////////////////////////////////////
  137. // copy the AreaCode
  138. //
  139. m_pszAreaCode = ClientAllocString( pszAreaCode );
  140. if (m_pszAreaCode == NULL)
  141. {
  142. LOG(( TL_ERROR, "Initialize create m_pszAreaCode failed" ));
  143. return E_OUTOFMEMORY;
  144. }
  145. m_pszNumberToDial = ClientAllocString( pszNumberToDial );
  146. if (m_pszNumberToDial == NULL)
  147. {
  148. LOG(( TL_ERROR, "Initialize create m_pszNumberToDial failed" ));
  149. return E_OUTOFMEMORY;
  150. }
  151. m_dwOptions = dwOptions;
  152. SetPrefixList(pszzPrefixList, dwPrefixListSize);
  153. return hr;
  154. }
  155. /****************************************************************************
  156. Class : CAreaCodeRule
  157. Method : SetAreaCode
  158. ****************************************************************************/
  159. STDMETHODIMP CAreaCodeRule::SetAreaCode(PWSTR pszAreaCode)
  160. {
  161. HRESULT hr = S_OK;
  162. if (m_pszAreaCode != NULL)
  163. {
  164. ClientFree(m_pszAreaCode);
  165. m_pszAreaCode = NULL;
  166. }
  167. if(pszAreaCode != NULL)
  168. {
  169. m_pszAreaCode = ClientAllocString( pszAreaCode );
  170. if (m_pszAreaCode == NULL)
  171. {
  172. LOG(( TL_ERROR, "SetAreaCode - alloc failed" ));
  173. hr = E_OUTOFMEMORY;
  174. }
  175. }
  176. return hr;
  177. }
  178. /****************************************************************************
  179. Class : CAreaCodeRule
  180. Method : SetAreaCode
  181. ****************************************************************************/
  182. STDMETHODIMP CAreaCodeRule::SetNumberToDial(PWSTR pszNumberToDial)
  183. {
  184. HRESULT hr = S_OK;
  185. if (m_pszNumberToDial != NULL)
  186. {
  187. ClientFree(m_pszNumberToDial);
  188. m_pszNumberToDial = NULL;
  189. }
  190. if(pszNumberToDial != NULL)
  191. {
  192. m_pszNumberToDial = ClientAllocString( pszNumberToDial );
  193. if (m_pszNumberToDial == NULL)
  194. {
  195. LOG(( TL_ERROR, "SetNumberToDial - alloc failed" ));
  196. hr = E_OUTOFMEMORY;
  197. }
  198. }
  199. return hr;
  200. }
  201. /****************************************************************************
  202. Class : CAreaCodeRule
  203. Method : SetPrefixList
  204. ****************************************************************************/
  205. STDMETHODIMP CAreaCodeRule::SetPrefixList(PWSTR pszzPrefixList, DWORD dwSize)
  206. {
  207. HRESULT hr = S_OK;
  208. if (m_pszzPrefixList != NULL)
  209. {
  210. ClientFree(m_pszzPrefixList);
  211. m_pszzPrefixList = NULL;
  212. m_dwPrefixListSize = 0;
  213. }
  214. if(pszzPrefixList != NULL)
  215. {
  216. m_pszzPrefixList = (PWSTR) ClientAlloc(dwSize);
  217. if (m_pszzPrefixList != NULL)
  218. {
  219. CopyMemory(m_pszzPrefixList, pszzPrefixList, dwSize);
  220. // set the size !
  221. m_dwPrefixListSize = dwSize;
  222. }
  223. else
  224. {
  225. LOG(( TL_ERROR, "SetPrefixList - alloc failed" ));
  226. hr = E_OUTOFMEMORY;
  227. }
  228. }
  229. return hr;
  230. }
  231. /****************************************************************************
  232. Class : CAreaCodeRule
  233. Method : UseCallingCard
  234. ****************************************************************************/
  235. void CAreaCodeRule::SetDialAreaCode(BOOL bDa)
  236. {
  237. if(bDa)
  238. {
  239. m_dwOptions |= RULE_DIALAREACODE;
  240. }
  241. else
  242. {
  243. m_dwOptions &= ~RULE_DIALAREACODE;
  244. }
  245. }
  246. /****************************************************************************
  247. Class : CAreaCodeRule
  248. Method : UseCallingCard
  249. ****************************************************************************/
  250. void CAreaCodeRule::SetDialNumber(BOOL bDn)
  251. {
  252. if(bDn)
  253. {
  254. m_dwOptions |= RULE_DIALNUMBER;
  255. }
  256. else
  257. {
  258. m_dwOptions &= ~RULE_DIALNUMBER;
  259. }
  260. }
  261. /****************************************************************************
  262. Class : CAreaCodeRule
  263. Method : UseCallingCard
  264. ****************************************************************************/
  265. void CAreaCodeRule::SetAppliesToAllPrefixes(BOOL bApc)
  266. {
  267. if(bApc)
  268. {
  269. m_dwOptions |= RULE_APPLIESTOALLPREFIXES;
  270. }
  271. else
  272. {
  273. m_dwOptions &= ~RULE_APPLIESTOALLPREFIXES;
  274. }
  275. }
  276. /****************************************************************************
  277. Class : CAreaCodeRule
  278. Method : TapiSize
  279. Number of bytes needed to pack this into a TAPI structure to send
  280. to TAPISRV
  281. ****************************************************************************/
  282. DWORD CAreaCodeRule::TapiSize()
  283. {
  284. DWORD dwSize=0;
  285. // Calc size ofArea Code Rule
  286. dwSize = ALIGN(sizeof(AREACODERULE));
  287. dwSize += ALIGN((lstrlenW(m_pszAreaCode) + 1) * sizeof(WCHAR));
  288. dwSize += ALIGN((lstrlenW(m_pszNumberToDial) + 1) * sizeof(WCHAR));
  289. dwSize += ALIGN(m_dwPrefixListSize);
  290. return dwSize;
  291. }
  292. /****************************************************************************
  293. /****************************************************************************
  294. /****************************************************************************
  295. Function : CreateDialingRule
  296. Create TAPI dialing rule - "xxxxFG" from number to dial
  297. & area code if required & subcriber number
  298. ****************************************************************************/
  299. STDMETHODIMP CreateDialingRule
  300. (
  301. PWSTR * pszRule,
  302. PWSTR pszNumberToDial,
  303. BOOL bDialAreaCode
  304. )
  305. {
  306. HRESULT hr = S_OK;
  307. PWSTR pszRule1= NULL;
  308. //////////////////////////////////////////////////
  309. // Create the dialing Rule
  310. // alloc enough space for number + "FG"
  311. //
  312. pszRule1 = (PWSTR) ClientAlloc(
  313. (lstrlenW(pszNumberToDial) + 3 )
  314. * sizeof (WCHAR)
  315. );
  316. if (pszRule1 != NULL)
  317. {
  318. // copy number "xxxx"
  319. if(pszNumberToDial != NULL)
  320. {
  321. lstrcpyW(pszRule1, pszNumberToDial);
  322. }
  323. // Area code ? "xxxxF"
  324. if (bDialAreaCode)
  325. {
  326. lstrcatW(pszRule1, L"F");
  327. }
  328. // Subcriber Nmber "xxxxFG" or "xxxxG"
  329. lstrcatW(pszRule1, L"G");
  330. }
  331. else
  332. {
  333. LOG(( TL_ERROR, "CreateDialingRule - Alloc pszRule failed" ));
  334. hr = E_OUTOFMEMORY;
  335. }
  336. *pszRule = pszRule1;
  337. return hr;
  338. }
  339. /****************************************************************************
  340. Function : ClientAllocString
  341. Copys string.
  342. Allocate space for new string using ClientAlloc
  343. Returns pointer to new string or NULL
  344. ****************************************************************************/
  345. #if DBG
  346. PWSTR ClientAllocStringReal(PCWSTR psz,
  347. DWORD dwLine,
  348. PSTR pszFile
  349. )
  350. #else
  351. PWSTR ClientAllocStringReal(PCWSTR psz )
  352. #endif
  353. {
  354. PWSTR pszNewString = NULL;
  355. if (psz != NULL)
  356. {
  357. #if DBG
  358. pszNewString = (PWSTR) ClientAllocReal((lstrlenW(psz)+1)* sizeof (WCHAR),dwLine,pszFile );
  359. #else
  360. pszNewString = (PWSTR) ClientAlloc((lstrlenW(psz)+1)* sizeof (WCHAR) );
  361. #endif
  362. if (pszNewString != NULL)
  363. {
  364. lstrcpyW(pszNewString, psz);
  365. }
  366. else
  367. {
  368. LOG(( TL_ERROR, "ClientAllocString Alloc string failed" ));
  369. }
  370. }
  371. return pszNewString;
  372. }