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.

483 lines
14 KiB

  1. #ifdef WIN16
  2. typedef int WCHAR;
  3. #include <memory.h>
  4. #include <ietapi.h>
  5. #endif
  6. #include "isignup.h"
  7. #include <tapi.h>
  8. #include "dialutil.h"
  9. #define CANONICAL_CAP TEXT("+%d (%s) %s")
  10. #define CANONICAL_CXP TEXT("+%d %s")
  11. #define TAPI_VERSION 0x00010004
  12. #define SMALLBUFLEN 80
  13. #define ASSERT(c)
  14. #define TRACE_OUT(c)
  15. #define lstrnicmp(sz1, sz2, cch) (CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, sz1, cch, sz2, cch) - 2)
  16. #define lstrncmp(sz1, sz2, cch) (CompareString(LOCALE_USER_DEFAULT, 0, sz1, cch, sz2, cch) - 2)
  17. static const TCHAR szRnaAppWindowClass[] = TEXT("#32770"); // hard coded dialog class name
  18. #ifdef WIN16
  19. #define NORM_IGNORECASE 0x00000001 /* ignore case */
  20. #define LOCALE_USER_DEFAULT 0
  21. int CompareString(
  22. LCID Locale, // locale identifier
  23. DWORD dwCmpFlags, // comparison-style options
  24. LPCTSTR lpString1, // pointer to first string
  25. int cchCount1, // size, in bytes or characters, of first string
  26. LPCTSTR lpString2, // pointer to second string
  27. int cchCount2 // size, in bytes or characters, of second string
  28. )
  29. {
  30. //
  31. // This is kind of tricky, but it should work. We'll save the
  32. // characters at the end of the strings, put a NULL in their
  33. // place, use lstrcmp and lstrcmpi, and then replace the
  34. // characters.
  35. //
  36. TCHAR cSave1, cSave2;
  37. int iRet;
  38. cSave1 = lpString1[cchCount1];
  39. lpString1[cchCount1] = '\0';
  40. cSave2 = lpString2[cchCount2];
  41. lpString2[cchCount2] = '\0';
  42. if (dwCmpFlags & NORM_IGNORECASE)
  43. iRet = lstrcmpi(lpString1, lpString2) + 2;
  44. else
  45. iRet = lstrcmp(lpString1, lpString2) + 2;
  46. lpString1[cchCount1] = cSave1;
  47. lpString2[cchCount2] = cSave2;
  48. return iRet;
  49. }
  50. #endif
  51. void CALLBACK LineCallbackProc (DWORD handle, DWORD dwMsg, DWORD dwInst,
  52. DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
  53. static HWND hwndFound = NULL;
  54. static BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam)
  55. {
  56. TCHAR szTemp[SMALLBUFLEN+2];
  57. LPTSTR pszTitle;
  58. UINT uLen1, uLen2;
  59. if(!IsWindowVisible(hwnd))
  60. return TRUE;
  61. if(GetClassName(hwnd, szTemp, SMALLBUFLEN)==0)
  62. return TRUE; // continue enumerating
  63. if(lstrcmp(szTemp, szRnaAppWindowClass)!=0)
  64. return TRUE;
  65. if(GetWindowText(hwnd, szTemp, SMALLBUFLEN)==0)
  66. return TRUE;
  67. szTemp[SMALLBUFLEN] = 0;
  68. uLen1 = lstrlen(szTemp);
  69. if (uLen1 > 5)
  70. uLen1 -= 5; // skip last 5 chars of title (avoid "...")
  71. pszTitle = (LPTSTR)lparam;
  72. ASSERT(pszTitle);
  73. uLen2 = lstrlen(pszTitle);
  74. TRACE_OUT(("Title=(%s), len=%d, Window=(%s), len=%d\r\n", pszTitle, uLen2, szTemp, uLen1));
  75. if(uLen2 < uLen1)
  76. return TRUE;
  77. if(lstrnicmp(pszTitle, szTemp, uLen1)!=0)
  78. return TRUE;
  79. hwndFound = hwnd;
  80. return FALSE;
  81. }
  82. static HWND MyFindRNAWindow(LPTSTR pszTitle)
  83. {
  84. DWORD dwRet;
  85. hwndFound = NULL;
  86. dwRet = EnumWindows((WNDENUMPROC)(&MyEnumWindowsProc), (LPARAM)pszTitle);
  87. TRACE_OUT(("EnumWindows returned %d\r\n", dwRet));
  88. return hwndFound;
  89. }
  90. /*******************************************************************
  91. NAME: MinimizeRNAWindow
  92. SYNOPSIS: Finds and minimizes the annoying RNA window
  93. ENTRY: pszConnectoidName - name of connectoid launched
  94. ********************************************************************/
  95. BOOL MinimizeRNAWindow(LPTSTR pszConnectoidName)
  96. {
  97. HWND hwndRNAApp;
  98. TCHAR szFmt[SMALLBUFLEN + 1];
  99. TCHAR szTitle[RAS_MaxEntryName + SMALLBUFLEN + 1];
  100. // load the title format ("connected to <connectoid name>" from resource
  101. LoadString(ghInstance, IDS_CONNECTED_TO, szFmt, SIZEOF_TCHAR_BUFFER(szFmt));
  102. // build the title
  103. wsprintf(szTitle, szFmt, pszConnectoidName);
  104. hwndRNAApp=MyFindRNAWindow((LPTSTR)szTitle);
  105. if(hwndRNAApp)
  106. {
  107. // minimize the RNA window
  108. ShowWindow(hwndRNAApp,SW_MINIMIZE);
  109. return TRUE;
  110. }
  111. return FALSE;
  112. }
  113. //****************************************************************************
  114. // static LPTSTR NEAR PASCAL GetDisplayPhone (LPTSTR)
  115. //
  116. // This function returns the pointer to displayable phone number. It stripped
  117. // all the prefixes we do not want to show to the user.
  118. //
  119. // History:
  120. // Tue 26-Jul-1994 16:07:00 -by- Viroon Touranachun [viroont]
  121. // Created.
  122. //****************************************************************************
  123. LPTSTR NEAR PASCAL GetDisplayPhone (LPTSTR szPhoneNum)
  124. {
  125. // Check whether the first string is the know prefix
  126. //
  127. if ((*szPhoneNum == 'T') || (*szPhoneNum == 'P'))
  128. {
  129. // It is the prefix
  130. //
  131. szPhoneNum++;
  132. // The first displayable number is not white space after prefix
  133. //
  134. while ((*szPhoneNum == ' ') || (*szPhoneNum == '\t'))
  135. szPhoneNum++;
  136. };
  137. return szPhoneNum;
  138. }
  139. void CALLBACK LineCallbackProc (DWORD handle, DWORD dwMsg, DWORD dwInst,
  140. DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
  141. {
  142. }
  143. //****************************************************************************
  144. // TranslateCanonicalAddress()
  145. //
  146. // Function: This function translate a canonical address to a dialable address.
  147. //
  148. // Returns: SUCCESS or an error code
  149. //
  150. //****************************************************************************
  151. static DWORD NEAR PASCAL TranslateCanonicalAddress(DWORD dwID, LPTSTR szCanonical,
  152. LPTSTR szDialable, DWORD cb)
  153. {
  154. DWORD dwRet;
  155. #ifdef WIN16
  156. char szBuffer[1024];
  157. LPLINETRANSLATEOUTPUT lpLine;
  158. memset(&szBuffer[0], 0, sizeof(szBuffer));
  159. lpLine = (LPLINETRANSLATEOUTPUT) & szBuffer[0];
  160. lpLine->dwTotalSize = sizeof(szBuffer);
  161. dwRet = IETapiTranslateAddress(NULL, szCanonical, 0L, 0L, lpLine);
  162. if (0 == dwRet)
  163. lstrcpy(szDialable, &szBuffer[lpLine->dwDialableStringOffset+3]);
  164. #else //WIN16
  165. LINETRANSLATEOUTPUT lto, FAR* lplto;
  166. DWORD cDevices;
  167. HLINEAPP hApp;
  168. if ((dwRet = lineInitialize(&hApp, ghInstance,
  169. (LINECALLBACK)LineCallbackProc,
  170. NULL, &cDevices)) == SUCCESS)
  171. {
  172. // Get the actual buffer size
  173. lto.dwTotalSize = sizeof(lto);
  174. if ((dwRet = lineTranslateAddress(hApp, dwID,
  175. TAPI_VERSION, szCanonical, 0,
  176. LINETRANSLATEOPTION_CANCELCALLWAITING,
  177. &lto)) == SUCCESS)
  178. {
  179. // Allocate the dialable number buffer
  180. if ((lplto = (LPLINETRANSLATEOUTPUT)LocalAlloc(LMEM_FIXED, lto.dwNeededSize))
  181. != NULL)
  182. {
  183. // Translate the phone number
  184. lplto->dwTotalSize = lto.dwNeededSize;
  185. if ((dwRet = lineTranslateAddress(hApp, dwID,
  186. TAPI_VERSION, szCanonical, 0,
  187. LINETRANSLATEOPTION_CANCELCALLWAITING,
  188. lplto)) == SUCCESS)
  189. {
  190. LPTSTR szPhone;
  191. szPhone = (LPTSTR)(((LPBYTE)lplto)+lplto->dwDialableStringOffset);
  192. lstrcpyn(szDialable, szPhone, (int)cb);
  193. }
  194. else
  195. dwRet = ERROR_TAPI_CONFIGURATION;
  196. LocalFree(lplto);
  197. }
  198. else
  199. dwRet = ERROR_OUTOFMEMORY;
  200. }
  201. else
  202. dwRet = ERROR_TAPI_CONFIGURATION;
  203. }
  204. else
  205. dwRet = ERROR_TAPI_CONFIGURATION;
  206. lineShutdown(hApp);
  207. #endif // #ifdef WIN16 ... #else ...
  208. return dwRet;
  209. }
  210. //****************************************************************************
  211. // DWORD NEAR PASCAL BuildPhoneString (LPBYTE, LPPHONENUM)
  212. //
  213. // This function builds a phone number string from the phone number struct
  214. //
  215. // History:
  216. // Mon 14-Mar-1994 13:10:44 -by- Viroon Touranachun [viroont]
  217. // Created.
  218. //****************************************************************************
  219. static DWORD NEAR PASCAL BuildPhoneString (LPTSTR szPhoneNum, LPRASENTRY lpRasEntry)
  220. {
  221. if (*lpRasEntry->szAreaCode != '\0')
  222. {
  223. wsprintf(szPhoneNum, CANONICAL_CAP, lpRasEntry->dwCountryCode,
  224. lpRasEntry->szAreaCode, lpRasEntry->szLocalPhoneNumber);
  225. }
  226. else
  227. {
  228. wsprintf(szPhoneNum, CANONICAL_CXP, lpRasEntry->dwCountryCode,
  229. lpRasEntry->szLocalPhoneNumber);
  230. };
  231. return SUCCESS;
  232. };
  233. //****************************************************************************
  234. // BOOL NEAR PASCAL TranslatePhoneNumber(LPTSTR, LPPHONENUM, LPTSTR)
  235. //
  236. // Translate phone number into a dialble string.
  237. //
  238. // Returns TRUE if successful, FALSE if use default.
  239. //
  240. // History:
  241. // Fri 17-Jun-1994 08:42:49 -by- Viroon Touranachun [viroont]
  242. // Created
  243. //****************************************************************************
  244. static BOOL NEAR PASCAL TranslatePhoneNumber(LPRASENTRY lpRasEntry, LPTSTR szPhoneNumber)
  245. {
  246. TCHAR szOrgPhone[RAS_MaxPhoneNumber+1];
  247. // Do we need to use the addrees book phone number?
  248. //
  249. if (lpRasEntry != NULL)
  250. {
  251. // Yes! Do we need to translate anything?
  252. //
  253. if (lpRasEntry->dwCountryID == 0)
  254. {
  255. // No! we dial as is.
  256. //
  257. lstrcpyn(szOrgPhone, lpRasEntry->szLocalPhoneNumber, SIZEOF_TCHAR_BUFFER(szOrgPhone));
  258. }
  259. else
  260. {
  261. // Yes! build the phone number
  262. //
  263. BuildPhoneString (szOrgPhone, lpRasEntry);
  264. };
  265. }
  266. else
  267. {
  268. // No! we have a overwritten phone number
  269. //
  270. ASSERT(lstrlen(szPhoneNumber) != 0);
  271. lstrcpyn(szOrgPhone, szPhoneNumber, SIZEOF_TCHAR_BUFFER(szOrgPhone));
  272. };
  273. // Attempt address translation
  274. //
  275. if (TranslateCanonicalAddress(0, szOrgPhone,
  276. szPhoneNumber, RAS_MaxPhoneNumber+1)
  277. != ERROR_SUCCESS)
  278. {
  279. // Translation fails, use default phone number
  280. //
  281. if (lpRasEntry != NULL)
  282. {
  283. // Use entry's local phone number
  284. //
  285. lstrcpy(szPhoneNumber, lpRasEntry->szLocalPhoneNumber);
  286. }
  287. else
  288. {
  289. // Restore the original phone number
  290. //
  291. lstrcpy(szPhoneNumber, szOrgPhone);
  292. };
  293. return FALSE;
  294. };
  295. return TRUE;
  296. }
  297. DWORD GetPhoneNumber(LPTSTR lpszEntryName, LPTSTR lpszPhoneNumber)
  298. {
  299. DWORD dwEntrySize = 0;
  300. DWORD dwSize = 0;
  301. DWORD dwRet;
  302. LPRASENTRY lpRasEntry = NULL;
  303. // get size needed for RASENTRY struct
  304. lpfnRasGetEntryProperties(
  305. NULL,
  306. lpszEntryName,
  307. NULL,
  308. &dwEntrySize,
  309. NULL,
  310. &dwSize);
  311. lpRasEntry = (LPRASENTRY)LocalAlloc(LPTR, dwEntrySize + dwSize);
  312. if (NULL == lpRasEntry)
  313. {
  314. dwRet = ERROR_OUTOFMEMORY;
  315. }
  316. else
  317. {
  318. lpRasEntry->dwSize = dwEntrySize;
  319. dwRet = lpfnRasGetEntryProperties(
  320. NULL,
  321. lpszEntryName,
  322. (LPBYTE)lpRasEntry,
  323. &dwEntrySize,
  324. ((LPBYTE)lpRasEntry) + dwEntrySize,
  325. &dwSize);
  326. if (ERROR_SUCCESS == dwRet)
  327. {
  328. TranslatePhoneNumber(lpRasEntry, lpszPhoneNumber);
  329. }
  330. LocalFree(lpRasEntry);
  331. }
  332. return dwRet;
  333. }
  334. DWORD _RasGetStateString(RASCONNSTATE state, LPTSTR lpszState, DWORD cb)
  335. {
  336. UINT idString;
  337. switch(state)
  338. {
  339. case RASCS_OpenPort:
  340. idString = IDS_OPENPORT;
  341. break;
  342. case RASCS_PortOpened:
  343. idString = IDS_PORTOPENED;
  344. break;
  345. case RASCS_ConnectDevice:
  346. idString = IDS_CONNECTDEVICE;
  347. break;
  348. case RASCS_DeviceConnected:
  349. idString = IDS_DEVICECONNECTED;
  350. break;
  351. case RASCS_AllDevicesConnected:
  352. idString = IDS_ALLDEVICESCONNECTED;
  353. break;
  354. case RASCS_Authenticate:
  355. idString = IDS_AUTHENTICATE;
  356. break;
  357. case RASCS_AuthNotify:
  358. idString = IDS_AUTHNOTIFY;
  359. break;
  360. case RASCS_AuthRetry:
  361. idString = IDS_AUTHRETRY;
  362. break;
  363. case RASCS_AuthCallback:
  364. idString = IDS_AUTHCALLBACK;
  365. break;
  366. case RASCS_AuthChangePassword:
  367. idString = IDS_AUTHCHANGEPASSWORD;
  368. break;
  369. case RASCS_AuthProject:
  370. idString = IDS_AUTHPROJECT;
  371. break;
  372. case RASCS_AuthLinkSpeed:
  373. idString = IDS_AUTHLINKSPEED;
  374. break;
  375. case RASCS_AuthAck:
  376. idString = IDS_AUTHACK;
  377. break;
  378. case RASCS_ReAuthenticate:
  379. idString = IDS_REAUTHENTICATE;
  380. break;
  381. case RASCS_Authenticated:
  382. idString = IDS_AUTHENTICATED;
  383. break;
  384. case RASCS_PrepareForCallback:
  385. idString = IDS_PREPAREFORCALLBACK;
  386. break;
  387. case RASCS_WaitForModemReset:
  388. idString = IDS_WAITFORMODEMRESET;
  389. break;
  390. case RASCS_WaitForCallback:
  391. idString = IDS_WAITFORCALLBACK;
  392. break;
  393. case RASCS_Interactive:
  394. idString = IDS_INTERACTIVE;
  395. break;
  396. case RASCS_RetryAuthentication:
  397. idString = IDS_RETRYAUTHENTICATION;
  398. break;
  399. case RASCS_CallbackSetByCaller:
  400. idString = IDS_CALLBACKSETBYCALLER;
  401. break;
  402. case RASCS_PasswordExpired:
  403. idString = IDS_PASSWORDEXPIRED;
  404. break;
  405. case RASCS_Connected:
  406. idString = IDS_CONNECTED;
  407. break;
  408. case RASCS_Disconnected:
  409. idString = IDS_DISCONNECTED;
  410. break;
  411. default:
  412. idString = IDS_UNDEFINED_ERROR;
  413. break;
  414. }
  415. if (LoadString(ghInstance, idString, lpszState, (int)cb))
  416. {
  417. return GetLastError();
  418. }
  419. return ERROR_SUCCESS;
  420. }