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.

439 lines
11 KiB

  1. // File: speedial.cpp
  2. #include "precomp.h"
  3. #include "resource.h"
  4. #include "dirutil.h"
  5. #include "speedial.h"
  6. #include "nameres.h" // for old transports
  7. #include "callto.h"
  8. static const TCHAR g_cszConfLinkExt[] = TEXT(".cnf");
  9. static const TCHAR g_cszConfLinkFilter[] = TEXT("*.cnf");
  10. static const TCHAR g_cszConferenceShortcutSection[] = TEXT("ConferenceShortcut");
  11. static const TCHAR g_cszNameKey[] = TEXT("ConfName");
  12. static const TCHAR g_cszAddressKey[] = TEXT("Address");
  13. static const TCHAR g_cszTransportKey[] = TEXT("Transport");
  14. static const TCHAR g_cszRemoteConfNameKey[] = TEXT("RemoteConfName");
  15. static const TCHAR g_cszCallFlagsKey[] = TEXT("CallFlags");
  16. static const TCHAR g_cszPasswordKey[] = TEXT("Password");
  17. static const int _rgIdMenu[] = {
  18. IDM_DLGCALL_DELETE,
  19. 0
  20. };
  21. inline VOID DwToSz(DWORD dw, LPTSTR psz)
  22. {
  23. wsprintf(psz, TEXT("%d"), dw);
  24. }
  25. /* C S P E E D D I A L */
  26. /*-------------------------------------------------------------------------
  27. %%Function: CSPEEDDIAL
  28. -------------------------------------------------------------------------*/
  29. CSPEEDDIAL::CSPEEDDIAL() :
  30. CALV(IDS_DLGCALL_SPEEDDIAL, II_SPEEDDIAL, _rgIdMenu)
  31. {
  32. DbgMsg(iZONE_OBJECTS, "CSPEEDDIAL - Constructed(%08X)", this);
  33. // Check the path to the speed dial folder
  34. if (!FGetSpeedDialFolder(m_szFile, CCHMAX(m_szFile)))
  35. return;
  36. int cchSpeedDialFolder = lstrlen(m_szFile);
  37. m_szFile[cchSpeedDialFolder++] = _T('\\');
  38. m_pszFileName = &m_szFile[cchSpeedDialFolder];
  39. m_cchFileNameMax = CCHMAX(m_szFile) - cchSpeedDialFolder;
  40. ASSERT(m_cchFileNameMax >= MAX_PATH);
  41. lstrcpyn(m_pszFileName, g_cszConfLinkFilter, m_cchFileNameMax);
  42. WIN32_FIND_DATA wfd;
  43. HANDLE hFind = ::FindFirstFile(m_szFile, &wfd);
  44. if (INVALID_HANDLE_VALUE == hFind)
  45. return;
  46. ::FindClose(hFind);
  47. SetAvailable(TRUE); // we found at least one file
  48. }
  49. CSPEEDDIAL::~CSPEEDDIAL()
  50. {
  51. DbgMsg(iZONE_OBJECTS, "CSPEEDDIAL - Destroyed(%08X)", this);
  52. }
  53. ///////////////////////////////////////////////////////////////////////////
  54. // CALV methods
  55. /* S H O W I T E M S */
  56. /*-------------------------------------------------------------------------
  57. %%Function: ShowItems
  58. -------------------------------------------------------------------------*/
  59. VOID CSPEEDDIAL::ShowItems(HWND hwnd)
  60. {
  61. CALV::SetHeader(hwnd, IDS_ADDRESS);
  62. if (!FAvailable())
  63. return;
  64. lstrcpyn(m_pszFileName, g_cszConfLinkFilter, m_cchFileNameMax);
  65. WIN32_FIND_DATA wfd;
  66. HANDLE hFind = ::FindFirstFile(m_szFile, &wfd);
  67. if (INVALID_HANDLE_VALUE == hFind)
  68. return;
  69. for ( ; ; )
  70. {
  71. lstrcpyn(m_pszFileName, wfd.cFileName, m_cchFileNameMax);
  72. TCHAR szAddress[CCHMAXSZ_ADDRESS];
  73. if (0 != GetPrivateProfileString(g_cszConferenceShortcutSection,
  74. g_cszAddressKey, g_cszEmpty, szAddress, CCHMAX(szAddress), m_szFile))
  75. {
  76. TCHAR szName[MAX_PATH];
  77. lstrcpyn(szName, wfd.cFileName, lstrlen(wfd.cFileName) - CCHEXT); // no .cnf extension
  78. DlgCallAddItem(hwnd, szName, szAddress, II_COMPUTER);
  79. }
  80. if (FALSE == ::FindNextFile(hFind, &wfd))
  81. {
  82. ::FindClose(hFind);
  83. break;
  84. }
  85. }
  86. }
  87. VOID CSPEEDDIAL::OnCommand(WPARAM wParam, LPARAM lParam)
  88. {
  89. switch (GET_WM_COMMAND_ID(wParam, lParam))
  90. {
  91. case IDM_DLGCALL_DELETE:
  92. CmdDelete();
  93. break;
  94. default:
  95. CALV::OnCommand(wParam, lParam);
  96. break;
  97. }
  98. }
  99. BOOL CSPEEDDIAL::FGetSelectedFilename(LPTSTR pszFile)
  100. {
  101. int iItem = GetSelection();
  102. if (-1 == iItem)
  103. return FALSE;
  104. if (!FGetSpeedDialFolder(pszFile, MAX_PATH))
  105. return FALSE;
  106. LPTSTR psz = pszFile + lstrlen(pszFile);
  107. *psz++ = _T('\\');
  108. int cchMax = (INT)(MAX_PATH - (CCHMAX(g_cszConfLinkExt) + psz - pszFile));
  109. if (!GetSzData(psz, cchMax, iItem, IDI_DLGCALL_NAME))
  110. return FALSE;
  111. lstrcat(pszFile, g_cszConfLinkExt);
  112. return TRUE;
  113. }
  114. VOID CSPEEDDIAL::CmdDelete(void)
  115. {
  116. int iItem = GetSelection();
  117. if (-1 == iItem)
  118. return;
  119. TCHAR szFile[MAX_PATH];
  120. if (!FGetSelectedFilename(szFile))
  121. return;
  122. if (::DeleteFile(szFile))
  123. {
  124. DeleteItem(iItem);
  125. }
  126. }
  127. /* G E T A D D R I N F O */
  128. /*-------------------------------------------------------------------------
  129. %%Function: GetAddrInfo
  130. -------------------------------------------------------------------------*/
  131. RAI * CSPEEDDIAL::GetAddrInfo(void)
  132. {
  133. TCHAR szFile[MAX_PATH];
  134. if (!FGetSelectedFilename(szFile))
  135. return NULL;
  136. NM_ADDR_TYPE addrType;
  137. int iTransport = GetPrivateProfileInt(g_cszConferenceShortcutSection,
  138. g_cszTransportKey, NAMETYPE_UNKNOWN, szFile);
  139. switch (iTransport)
  140. {
  141. case NAMETYPE_IP: addrType = NM_ADDR_IP; break;
  142. case NAMETYPE_PSTN: addrType = NM_ADDR_PSTN; break;
  143. case NAMETYPE_ULS: addrType = NM_ADDR_ULS; break;
  144. case NAMETYPE_H323GTWY: addrType = NM_ADDR_H323_GATEWAY; break;
  145. case NAMETYPE_UNKNOWN: addrType = NM_ADDR_ULS; break;
  146. default: addrType = NM_ADDR_UNKNOWN; break;
  147. }
  148. RichAddressInfo * pRai = CALV::GetAddrInfo( addrType );
  149. if( hasValidUserInfo( pRai ) && (addrType == NM_ADDR_IP) )
  150. {
  151. unsigned long ulDestination;
  152. if( GetIpAddress( pRai->rgDwStr[0].psz, ulDestination ) != S_OK )
  153. {
  154. pRai->rgDwStr[0].dw = NM_ADDR_MACHINENAME;
  155. }
  156. }
  157. return( pRai );
  158. }
  159. /* F C R E A T E S P E E D D I A L */
  160. /*-------------------------------------------------------------------------
  161. %%Function: FCreateSpeedDial
  162. Return TRUE if a new speed dial was created.
  163. If pcszPathPrefix is NULL the file will be created only if necessary.
  164. -------------------------------------------------------------------------*/
  165. BOOL FCreateSpeedDial(LPCTSTR pcszName, LPCTSTR pcszAddress,
  166. NM_ADDR_TYPE addrType, DWORD dwCallFlags,
  167. LPCTSTR pcszRemoteConfName, LPCTSTR pcszPassword,
  168. LPCTSTR pcszPathPrefix)
  169. {
  170. TCHAR sz[MAX_PATH];
  171. TCHAR szFileName[MAX_PATH*2];
  172. if (FEmptySz(pcszPathPrefix))
  173. {
  174. if (FExistingSpeedDial(pcszAddress, addrType))
  175. {
  176. WARNING_OUT(("Duplicate SpeedDial already exists - not creating"));
  177. return FALSE;
  178. }
  179. if (!FGetSpeedDialFolder(szFileName, CCHMAX(szFileName), TRUE))
  180. {
  181. ERROR_OUT(("FGetSpeedDialFolder failed!"));
  182. return FALSE;
  183. }
  184. }
  185. else
  186. {
  187. lstrcpyn(szFileName, pcszPathPrefix, CCHMAX(szFileName));
  188. }
  189. if (!FCreateNewFile(szFileName, pcszName, g_cszConfLinkExt, szFileName, CCHMAX(szFileName)))
  190. {
  191. return FALSE;
  192. }
  193. // Write the data to the file
  194. WritePrivateProfileString(g_cszConferenceShortcutSection, g_cszNameKey, pcszName, szFileName);
  195. WritePrivateProfileString(g_cszConferenceShortcutSection, g_cszAddressKey, pcszAddress, szFileName);
  196. // Call Flags (normally CRPCF_DEFAULT)
  197. DwToSz(dwCallFlags, sz);
  198. WritePrivateProfileString(g_cszConferenceShortcutSection, g_cszCallFlagsKey, sz, szFileName);
  199. // Transports
  200. DWORD dwTransport;
  201. switch (addrType)
  202. {
  203. case NM_ADDR_IP:
  204. dwTransport = NAMETYPE_IP;
  205. break;
  206. case NM_ADDR_PSTN:
  207. dwTransport = NAMETYPE_PSTN;
  208. break;
  209. case NM_ADDR_ULS:
  210. dwTransport = NAMETYPE_ULS;
  211. break;
  212. case NM_ADDR_H323_GATEWAY:
  213. dwTransport = NAMETYPE_H323GTWY;
  214. break;
  215. case NM_ADDR_UNKNOWN:
  216. default:
  217. dwTransport = NAMETYPE_UNKNOWN;
  218. break;
  219. }
  220. DwToSz(dwTransport, sz);
  221. WritePrivateProfileString(g_cszConferenceShortcutSection, g_cszTransportKey, sz, szFileName);
  222. // Remote conference name
  223. if (!FEmptySz(pcszRemoteConfName))
  224. {
  225. WritePrivateProfileString(g_cszConferenceShortcutSection, g_cszRemoteConfNameKey,
  226. pcszName, pcszRemoteConfName);
  227. // Remote conference name
  228. if (!FEmptySz(pcszPassword))
  229. {
  230. WritePrivateProfileString(g_cszConferenceShortcutSection, g_cszPasswordKey,
  231. pcszName, pcszPassword);
  232. }
  233. }
  234. return TRUE;
  235. }
  236. /* F E X I S T I N G S P E E D D I A L */
  237. /*-------------------------------------------------------------------------
  238. %%Function: FExistingSpeedDial
  239. -------------------------------------------------------------------------*/
  240. BOOL FExistingSpeedDial(LPCTSTR pcszAddress, NM_ADDR_TYPE addrType)
  241. {
  242. TCHAR szFile[MAX_PATH*2];
  243. if (!FGetSpeedDialFolder(szFile, CCHMAX(szFile)))
  244. return FALSE;
  245. lstrcat(szFile, "\\");
  246. int cchMax = lstrlen(szFile);
  247. LPTSTR pszFileName = &szFile[cchMax]; // points to the filename
  248. lstrcpy(pszFileName, g_cszConfLinkFilter);
  249. cchMax = CCHMAX(szFile) - cchMax; // The max length of a filename
  250. WIN32_FIND_DATA wfd;
  251. HANDLE hFind = ::FindFirstFile(szFile, &wfd);
  252. if (INVALID_HANDLE_VALUE == hFind)
  253. return FALSE;
  254. BOOL fFound = FALSE;
  255. for ( ; ; )
  256. {
  257. lstrcpyn(pszFileName, wfd.cFileName, cchMax);
  258. TCHAR szAddress[CCHMAXSZ_ADDRESS];
  259. if (0 != GetPrivateProfileString(g_cszConferenceShortcutSection,
  260. g_cszAddressKey, g_cszEmpty, szAddress, CCHMAX(szAddress), szFile))
  261. {
  262. if (0 == lstrcmp(szAddress, pcszAddress))
  263. {
  264. fFound = TRUE;
  265. break;
  266. }
  267. }
  268. if (!FindNextFile(hFind, &wfd))
  269. break;
  270. }
  271. ::FindClose(hFind);
  272. return fFound;
  273. }
  274. /*-------------------------------------------------------------------------
  275. %%Function: GetSpeedDialFolderName
  276. -------------------------------------------------------------------------*/
  277. bool GetSpeedDialFolderName(LPTSTR pszBuffer, int cbLength)
  278. {
  279. ASSERT( pszBuffer != NULL );
  280. ASSERT( cbLength > 0 );
  281. RegEntry re( CONFERENCING_KEY, HKEY_LOCAL_MACHINE );
  282. LPTSTR pszFolder = re.GetString( REGVAL_SPEED_DIAL_FOLDER );
  283. bool bResult = !FEmptySz( pszFolder );
  284. if( !bResult )
  285. {
  286. TCHAR szNewFolder[ MAX_PATH ];
  287. if( GetInstallDirectory( szNewFolder ) )
  288. {
  289. TCHAR szSDFolder[ MAX_PATH ];
  290. FLoadString( IDS_SPEEDDIAL_FOLDER, szSDFolder, CCHMAX( szSDFolder ) );
  291. ASSERT( (lstrlen( szNewFolder) + lstrlen( szSDFolder )) < CCHMAX( szNewFolder ) );
  292. lstrcat( szNewFolder, szSDFolder );
  293. pszFolder = szNewFolder;
  294. bResult = true;
  295. // Set the registry entry
  296. RegEntry re2( CONFERENCING_KEY, HKEY_LOCAL_MACHINE );
  297. re2.SetValue( REGVAL_SPEED_DIAL_FOLDER, szNewFolder );
  298. }
  299. }
  300. if( bResult )
  301. {
  302. lstrcpyn( pszBuffer, pszFolder, cbLength );
  303. }
  304. return( bResult );
  305. }
  306. /* C R E A T E S P E E D D I A L F O L D E R */
  307. /*-------------------------------------------------------------------------
  308. %%Function: CreateSpeedDialFolder
  309. -------------------------------------------------------------------------*/
  310. BOOL CreateSpeedDialFolder(LPTSTR pszBuffer, int cbLength)
  311. {
  312. BOOL bResult = FALSE;
  313. if( GetSpeedDialFolderName( pszBuffer, cbLength ) )
  314. {
  315. bResult = ::FEnsureDirExists( pszBuffer );
  316. }
  317. return( bResult );
  318. }
  319. /* F G E T S P E E D D I A L F O L D E R */
  320. /*-------------------------------------------------------------------------
  321. %%Function: FGetSpeedDialFolder
  322. -------------------------------------------------------------------------*/
  323. BOOL FGetSpeedDialFolder(LPTSTR pszBuffer, UINT cchMax, BOOL fCreate)
  324. {
  325. bool bResult = false;
  326. if( GetSpeedDialFolderName( pszBuffer, cchMax ) )
  327. {
  328. if( ::FDirExists( pszBuffer ) )
  329. {
  330. bResult = true;
  331. }
  332. else if( fCreate )
  333. {
  334. bResult = (CreateSpeedDialFolder( pszBuffer, cchMax ) != FALSE);
  335. }
  336. }
  337. return( (BOOL) bResult );
  338. }