Source code of Windows XP (NT5)
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.

297 lines
7.2 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: refs.cpp
  4. //
  5. // Module: CMDIAL32.DLL
  6. //
  7. // Synopsis: The module contains the code for profile referencing.
  8. //
  9. // Copyright (c) 1996-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb created Header 08/16/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #include "pbk_str.h"
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Function: ValidTopLevelPBK()
  19. //
  20. // Synopsis: Checks to see if the toplevel phone book is valid.
  21. //
  22. // Arguments: pArgs [the ptr to ArgsStruct]
  23. //
  24. // Returns: BOOL [True if there are valid phone books]
  25. //
  26. // History: henryt Created 4/7/97
  27. //
  28. //----------------------------------------------------------------------------
  29. BOOL ValidTopLevelPBK(
  30. ArgsStruct *pArgs
  31. )
  32. {
  33. LPTSTR pszTmp;
  34. LPTSTR pszFullPath;
  35. BOOL fValid = TRUE;
  36. //
  37. // First check the top level service profile pbk
  38. //
  39. pszTmp = pArgs->piniService->GPPS(c_pszCmSectionIsp, c_pszCmEntryIspPbFile);
  40. if (!*pszTmp)
  41. {
  42. fValid = FALSE;
  43. }
  44. else
  45. {
  46. pszFullPath = CmBuildFullPathFromRelative(pArgs->piniProfile->GetFile(), pszTmp);
  47. if (!pszFullPath || (FALSE == FileExists(pszFullPath)))
  48. {
  49. fValid = FALSE;
  50. }
  51. CmFree(pszFullPath);
  52. }
  53. CmFree(pszTmp);
  54. //
  55. // If PBK failed, we're done
  56. //
  57. if (FALSE == fValid)
  58. {
  59. return fValid;
  60. }
  61. //
  62. // Now check the region file
  63. //
  64. pszTmp = pArgs->piniService->GPPS(c_pszCmSectionIsp, c_pszCmEntryIspRegionFile);
  65. if (!*pszTmp)
  66. {
  67. fValid = FALSE;
  68. }
  69. else
  70. {
  71. pszFullPath = CmBuildFullPathFromRelative(pArgs->piniProfile->GetFile(), pszTmp);
  72. if (!pszFullPath || (FALSE == FileExists(pszFullPath)))
  73. {
  74. fValid = FALSE;
  75. }
  76. CmFree(pszFullPath);
  77. }
  78. CmFree(pszTmp);
  79. return fValid;
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Function: ValidReferencedPBKs()
  84. //
  85. // Synopsis: Checks to see if the phone books used by the referenced
  86. // service profile(s) exist.
  87. //
  88. // Arguments: pArgs [the ptr to ArgsStruct]
  89. //
  90. // Returns: BOOL [True if there are valid phone books]
  91. //
  92. // History: henryt Created 4/7/97
  93. //
  94. //----------------------------------------------------------------------------
  95. BOOL ValidReferencedPBKs(
  96. ArgsStruct *pArgs
  97. )
  98. {
  99. LPTSTR pszTmp, pszTmp2;
  100. LPTSTR pszRef, pszNext;
  101. CIni iniRef(g_hInst);
  102. CIni iniFile(g_hInst, pArgs->piniService->GetFile());
  103. LPTSTR pszRefFile;
  104. BOOL fValid = TRUE;
  105. BOOL fValidPairFound = FALSE;
  106. LPTSTR pszFullPath;
  107. //
  108. // Now check the references.
  109. //
  110. pszTmp2 = iniFile.GPPS(c_pszCmSectionIsp, c_pszCmEntryIspReferences);
  111. pszRef = NULL;
  112. pszNext = pszTmp2;
  113. while (1)
  114. {
  115. if (!(pszRef = CmStrtok(pszNext, TEXT(" \t,"))))
  116. {
  117. break;
  118. }
  119. fValid = TRUE;
  120. pszNext = pszRef + lstrlenU(pszRef) + 1;
  121. iniFile.SetEntry(pszRef);
  122. //
  123. // Make sure that each referenced service has a valid pbk and pbr
  124. //
  125. pszRefFile = iniFile.GPPS(c_pszCmSectionIsp, c_pszCmEntryIspCmsFile);
  126. if (*pszRefFile)
  127. {
  128. //
  129. // Ensure a full path to the RefFile
  130. //
  131. pszFullPath = CmBuildFullPathFromRelative(pArgs->piniProfile->GetFile(), pszRefFile);
  132. if (!pszFullPath)
  133. {
  134. fValid = FALSE;
  135. }
  136. else
  137. {
  138. iniRef.SetFile(pszFullPath);
  139. }
  140. CmFree(pszFullPath);
  141. if (fValid)
  142. {
  143. //
  144. // Test existence of phonebook
  145. //
  146. pszTmp = iniRef.GPPS(c_pszCmSectionIsp, c_pszCmEntryIspPbFile);
  147. if (!*pszTmp)
  148. {
  149. fValid = FALSE;
  150. }
  151. else
  152. {
  153. pszFullPath = CmBuildFullPathFromRelative(pArgs->piniProfile->GetFile(), pszTmp);
  154. if (!pszFullPath || (FALSE == FileExists(pszFullPath)))
  155. {
  156. fValid = FALSE;
  157. }
  158. CmFree(pszFullPath);
  159. }
  160. CmFree(pszTmp);
  161. //
  162. // Now check the region file
  163. //
  164. pszTmp = iniRef.GPPS(c_pszCmSectionIsp, c_pszCmEntryIspRegionFile);
  165. if (!*pszTmp)
  166. {
  167. fValid = FALSE;
  168. }
  169. else
  170. {
  171. pszFullPath = CmBuildFullPathFromRelative(pArgs->piniProfile->GetFile(), pszTmp);
  172. if (!pszFullPath || (FALSE == FileExists(pszFullPath)))
  173. {
  174. fValid = FALSE;
  175. }
  176. CmFree(pszFullPath);
  177. }
  178. CmFree(pszTmp);
  179. }
  180. }
  181. else
  182. {
  183. fValid = FALSE;
  184. }
  185. CmFree(pszRefFile);
  186. if (fValid)
  187. {
  188. fValidPairFound = TRUE;
  189. break;
  190. }
  191. }
  192. CmFree(pszTmp2);
  193. return fValidPairFound;
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Function: GetAppropriateIniService
  198. //
  199. // Synopsis: Depending on:
  200. // 1. whether we're referencing or not,
  201. // 2. the pbk from which the user selected the phone #
  202. //
  203. // this func creates a CIni obj with the correct cms file
  204. //
  205. // Arguments: pArgs Pointer to ArgsStruct
  206. // dwEntry phone index
  207. //
  208. // Returns: CIni* - the ptr to the new object
  209. //
  210. // History: henryt Created 5/14/97
  211. //----------------------------------------------------------------------------
  212. CIni* GetAppropriateIniService(
  213. ArgsStruct *pArgs,
  214. DWORD dwEntry
  215. )
  216. {
  217. CIni* piniService = new CIni(g_hInst);
  218. if (!piniService)
  219. {
  220. CMTRACE(TEXT("GetAppropriateIniService() : alloc mem failed"));
  221. return NULL;
  222. }
  223. //
  224. // we need to work with the correct service file(the top-level service
  225. // or a referenced service).
  226. //
  227. // according to the spec, we will always use the DUN settings from the cms
  228. // associated w/ the phone book from which the user selected the POP. i.e.
  229. // if the user switches the picked from a different pbk, we need to update
  230. // the RAS connectoid.
  231. //
  232. if (IsBlankString(pArgs->aDialInfo[dwEntry].szPhoneBookFile) ||
  233. lstrcmpiU(pArgs->aDialInfo[dwEntry].szPhoneBookFile, pArgs->piniService->GetFile()) == 0)
  234. {
  235. //
  236. // the user either typed in the phone # or selected a phone # from the
  237. // top level phone book
  238. //
  239. piniService->SetFile(pArgs->piniService->GetFile());
  240. }
  241. else
  242. {
  243. //
  244. // the user picked the phone # from a referenced phone book.
  245. //
  246. piniService->SetFile(pArgs->aDialInfo[dwEntry].szPhoneBookFile);
  247. }
  248. return piniService;
  249. }