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.

353 lines
9.4 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: icwsupport.cpp
  4. //
  5. // Synopsis: holds the function which gets the list of
  6. // support phone numbers for ICW
  7. //
  8. // History: 5/8/97 MKarki Created
  9. //
  10. // Copyright (C) 1996-97 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "pch.hpp"
  15. #include <windows.h>
  16. #ifdef WIN16
  17. #include <win16def.h>
  18. #include <win32fn.h>
  19. #include <rasc.h>
  20. #include <raserr.h>
  21. #include <ietapi.h>
  22. extern "C" {
  23. #include "bmp.h"
  24. }
  25. #endif
  26. #include "phbk.h"
  27. #include "misc.h"
  28. #include "phbkrc.h"
  29. #include "suapi.h"
  30. #include "icwsupport.h"
  31. #include "ccsv.h"
  32. const TCHAR SUPPORT_FILE[] = TEXT("support.icw");
  33. const DWORD ALLOCATION_SIZE = 256;
  34. //++--------------------------------------------------------------
  35. //
  36. // Function: GetSupportNumsFromFile
  37. //
  38. // Synopsis: This is the function used to get the support
  39. // numbers
  40. //
  41. // Returns: HRESULT - success or error info
  42. //
  43. // Called By: by the GetSupportNumbers API
  44. //
  45. // History: MKarki Created 5/8/97
  46. //
  47. //----------------------------------------------------------------
  48. HRESULT
  49. GetSupportNumsFromFile (
  50. PSUPPORTNUM pSupportNumList,
  51. PDWORD pdwSize
  52. )
  53. {
  54. BOOL bReturnMemNeeded = FALSE;
  55. LPTSTR pszTemp = NULL;
  56. TCHAR szFilePath[MAX_PATH];
  57. BOOL bStatus = FALSE;
  58. CCSVFile *pcCSVFile = NULL;
  59. DWORD dwMemNeeded = 0;
  60. HRESULT hRetVal = ERROR_SUCCESS;
  61. DWORD dwCurrentIndex = 0;
  62. DWORD dwIndexAllocated = 0;
  63. const DWORD INFOSIZE = sizeof (SUPPORTNUM);
  64. PSUPPORTNUM pPhbkArray = NULL;
  65. PSUPPORTNUM pTemp = NULL;
  66. TraceMsg(TF_GENERAL, "Entering GetSupportNumsFromFile function\r\n");
  67. //
  68. // atleast a place where the size can be returned
  69. // should be provided
  70. //
  71. if (NULL == pdwSize)
  72. {
  73. TraceMsg (TF_GENERAL, "pdwSize == NULL\r\n");
  74. hRetVal = ERROR_INVALID_PARAMETER;
  75. goto Cleanup;
  76. }
  77. //
  78. // check if the user has provided the buffers
  79. //
  80. if (NULL == pSupportNumList)
  81. {
  82. TraceMsg (TF_GENERAL, "User justs wants the buffer size\r\n");
  83. bReturnMemNeeded = TRUE;
  84. }
  85. //
  86. // get the full path of the support.icw file
  87. //
  88. bStatus = SearchPath (
  89. NULL,
  90. (PTCHAR)SUPPORT_FILE,
  91. NULL,
  92. MAX_PATH,
  93. (PTCHAR)&szFilePath,
  94. (PTCHAR*)&pszTemp
  95. );
  96. if (FALSE == bStatus)
  97. {
  98. TraceMsg (TF_GENERAL,
  99. "Failed on SearchPath API call with error:%d\r\n",
  100. GetLastError ()
  101. );
  102. hRetVal = ERROR_FILE_NOT_FOUND;
  103. goto Cleanup;
  104. }
  105. //
  106. // now we can start processing the file
  107. //
  108. pcCSVFile = new CCSVFile;
  109. if (NULL == pcCSVFile)
  110. {
  111. TraceMsg (TF_GENERAL, "Could not allocate mem for CCSVFile\r\n");
  112. hRetVal = ERROR_OUTOFMEMORY;
  113. goto Cleanup;
  114. }
  115. //
  116. // open the file here
  117. //
  118. bStatus = pcCSVFile->Open (szFilePath);
  119. if (FALSE == bStatus)
  120. {
  121. TraceMsg (TF_GENERAL, "Filed on CCSVFile :: Open call\r\n");
  122. hRetVal = GetLastError ();
  123. goto Cleanup;
  124. }
  125. //
  126. // now we are ready to get the phone number out of the
  127. // file
  128. //
  129. dwCurrentIndex = 0;
  130. dwIndexAllocated = 0;
  131. do
  132. {
  133. //
  134. // check if we ned to allocate memory
  135. //
  136. if (dwIndexAllocated == dwCurrentIndex)
  137. {
  138. //
  139. // need to allocate memory
  140. //
  141. pTemp = (PSUPPORTNUM) GlobalAlloc (
  142. GPTR,
  143. (int)((dwIndexAllocated + ALLOCATION_SIZE)*INFOSIZE)
  144. );
  145. if (NULL == pTemp)
  146. {
  147. TraceMsg (TF_GENERAL,
  148. "Failed on GlobalAlloc API call with error:%d\r\n",
  149. GetLastError ()
  150. );
  151. hRetVal = ERROR_OUTOFMEMORY;
  152. goto Cleanup;
  153. }
  154. //
  155. // now copy over already allocated memory to this buffer
  156. //
  157. if (NULL != pPhbkArray)
  158. {
  159. CopyMemory (
  160. pTemp,
  161. pPhbkArray,
  162. (int)(dwIndexAllocated)*INFOSIZE
  163. );
  164. //
  165. // free the earlier memory
  166. //
  167. GlobalFree(pPhbkArray);
  168. }
  169. pPhbkArray = pTemp;
  170. dwIndexAllocated += ALLOCATION_SIZE;
  171. }
  172. //
  173. // get the phone number info
  174. //
  175. hRetVal = ReadOneLine (&pPhbkArray[dwCurrentIndex], pcCSVFile);
  176. if (ERROR_NO_MORE_ITEMS == hRetVal)
  177. {
  178. TraceMsg (TF_GENERAL, "we have read all the items from the file\r\n");
  179. break;
  180. }
  181. else if (ERROR_SUCCESS != hRetVal)
  182. {
  183. goto Cleanup;
  184. }
  185. dwCurrentIndex++;
  186. }
  187. while (TRUE);
  188. //
  189. // get the memory needed by the user
  190. //
  191. dwMemNeeded = (DWORD)(dwCurrentIndex)*INFOSIZE;
  192. //
  193. // check if the user wants the info, or just the size
  194. //
  195. if (FALSE == bReturnMemNeeded)
  196. {
  197. if (*pdwSize >= dwMemNeeded)
  198. {
  199. //
  200. // user wants us to copy over stuff to the memory
  201. // and there is enough space in user buffers.
  202. //
  203. CopyMemory (
  204. pSupportNumList,
  205. pPhbkArray,
  206. (int)dwMemNeeded
  207. );
  208. }
  209. else
  210. {
  211. TraceMsg (TF_GENERAL, "Caller did not allocate enough memory\r\n");
  212. hRetVal = ERROR_NOT_ENOUGH_MEMORY;
  213. goto Cleanup;
  214. }
  215. }
  216. //
  217. // if we reached here, then successfully got the info
  218. //
  219. hRetVal = ERROR_SUCCESS;
  220. Cleanup:
  221. //
  222. // copy the memory used/required to the user size param
  223. //
  224. *pdwSize = dwMemNeeded;
  225. if (NULL != pPhbkArray)
  226. GlobalFree (pPhbkArray);
  227. if (NULL != pcCSVFile)
  228. {
  229. pcCSVFile->Close ();
  230. delete pcCSVFile;
  231. }
  232. TraceMsg (TF_GENERAL, "Leaving GetSupportNumsFromFile function call\r\n");
  233. return (hRetVal);
  234. } // end of GetSupportNumsFromFile function
  235. //++--------------------------------------------------------------
  236. //
  237. // Function: ReadOneLine
  238. //
  239. // Synopsis: This is the function used to put the info
  240. // into the buffer, line by line
  241. //
  242. // Returns: HRESULT - success or error info
  243. //
  244. // Called By: GetSupportNumsFromFile function
  245. //
  246. // History: MKarki Created 5/8/97
  247. //
  248. //----------------------------------------------------------------
  249. HRESULT
  250. ReadOneLine (
  251. PSUPPORTNUM pPhbk,
  252. CCSVFile *pcCSVFile
  253. )
  254. {
  255. TCHAR szTempBuffer[PHONE_NUM_SIZE + 4];
  256. HRESULT hResult = ERROR_SUCCESS;
  257. BOOL bRetVal = FALSE;
  258. if ((NULL == pcCSVFile) || (NULL == pPhbk))
  259. {
  260. TraceMsg (TF_GENERAL, "ReadOneLine: Did not correctly pass args\r\n");
  261. hResult = ERROR_INVALID_PARAMETER;
  262. goto Cleanup;
  263. }
  264. //
  265. // get the country code first
  266. //
  267. bRetVal = pcCSVFile->ReadToken (szTempBuffer, PHONE_NUM_SIZE);
  268. if (FALSE == bRetVal)
  269. {
  270. hResult = ERROR_NO_MORE_ITEMS;
  271. goto Cleanup;
  272. }
  273. //
  274. // Convert the string obtained into a number
  275. //
  276. bRetVal = FSz2Dw (szTempBuffer, (PDWORD)&pPhbk->dwCountryCode);
  277. if (FALSE == bRetVal)
  278. {
  279. hResult = ERROR_INVALID_PARAMETER;
  280. goto Cleanup;
  281. }
  282. //
  283. // now get the phone number
  284. //
  285. bRetVal = pcCSVFile->ReadToken (szTempBuffer, PHONE_NUM_SIZE);
  286. if (FALSE == bRetVal)
  287. {
  288. hResult = ERROR_INVALID_PARAMETER;
  289. goto Cleanup;
  290. }
  291. //
  292. // copy this string into our struct
  293. //
  294. CopyMemory (
  295. pPhbk->szPhoneNumber,
  296. szTempBuffer,
  297. (int)PHONE_NUM_SIZE
  298. );
  299. //
  300. // if we have reached here then success
  301. //
  302. hResult = ERROR_SUCCESS;
  303. Cleanup:
  304. return (hResult);
  305. } // end of ReadOneLine function