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.

349 lines
9.1 KiB

  1. /*
  2. File Miscdb.c
  3. Implementation of the miscellaneous settings database.
  4. Paul Mayfield, 10/8/97
  5. */
  6. #include "rassrv.h"
  7. #include "miscdb.h"
  8. #include <stdlib.h>
  9. // ===================================
  10. // Definitions of the database objects
  11. // ===================================
  12. #define FLAG_MULTILINK 1
  13. #define FLAG_SHOWICON 2
  14. typedef struct _RASSRV_MISCDB {
  15. BOOL bMultilinkEnabled;
  16. BOOL bShowIcons;
  17. BOOL bFlushOnClose;
  18. BOOL bIsServer;
  19. DWORD dwOrigFlags;
  20. DWORD dwLogLevel;
  21. BOOL bLogLevelDirty;
  22. } RASSRV_MISCDB;
  23. // Opens a handle to the database of general tab values
  24. DWORD miscOpenDatabase(HANDLE * hMiscDatabase) {
  25. RASSRV_MISCDB * This;
  26. DWORD dwErr, i;
  27. if (!hMiscDatabase)
  28. return ERROR_INVALID_PARAMETER;
  29. // Allocate the database cache
  30. if ((This = RassrvAlloc (sizeof(RASSRV_MISCDB), TRUE)) == NULL)
  31. return ERROR_NOT_ENOUGH_MEMORY;
  32. // Initialize the values from the system
  33. miscReloadDatabase((HANDLE)This);
  34. // Record the original flag state for efficiency
  35. This->dwOrigFlags = 0;
  36. if (This->bMultilinkEnabled)
  37. This->dwOrigFlags |= FLAG_MULTILINK;
  38. if (This->bShowIcons)
  39. This->dwOrigFlags |= FLAG_SHOWICON;
  40. // Return the handle
  41. *hMiscDatabase = (HANDLE)This;
  42. This->bFlushOnClose = FALSE;
  43. return NO_ERROR;
  44. }
  45. // Closes the general database and flushes any changes
  46. // to the system when bFlushOnClose is TRUE
  47. DWORD miscCloseDatabase(HANDLE hMiscDatabase) {
  48. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  49. // Flush if requested
  50. if (This->bFlushOnClose)
  51. miscFlushDatabase(hMiscDatabase);
  52. // Free up the database cache
  53. RassrvFree(This);
  54. return NO_ERROR;
  55. }
  56. BOOL miscFlagsAreSame(BOOL bVal, DWORD dwFlags, DWORD dwFlag) {
  57. if ((bVal != 0) && ((dwFlags & dwFlag) != 0))
  58. return TRUE;
  59. if ((bVal == 0) && ((dwFlags & dwFlag) == 0))
  60. return TRUE;
  61. return FALSE;
  62. }
  63. //for whistler bug 143344 gangz
  64. //
  65. DWORD
  66. miscTrayNotifyIconChangeCleanUp(
  67. IN OUT LPHNPMParams pInfo)
  68. {
  69. HnPMParamsConnectionCleanUp(pInfo);
  70. return NO_ERROR;
  71. }//miscTrayNotifyIconChangeCleanUp()
  72. //Notify that the "Show Icon in Notification area" has changed
  73. //Used by GenCommand() in GenTab.c
  74. //
  75. DWORD
  76. miscTrayNotifyIconChange()
  77. {
  78. INetConnectionSysTray * pSysTray = NULL;
  79. HNPMParams Info;
  80. LPHNPMParams pInfo;
  81. HRESULT hr;
  82. DWORD dwErr = NO_ERROR, i;
  83. static const CLSID CLSID_InboundConnection=
  84. {0xBA126AD9,0x2166,0x11D1,{0xB1,0xD0,0x00,0x80,0x5F,0xC1,0x27,0x0E}};
  85. TRACE("miscTrayNotifyIconChanged");
  86. ZeroMemory(&Info, sizeof(Info));
  87. pInfo = &Info;
  88. do{
  89. dwErr = HnPMConnectionEnum(pInfo);
  90. if ( NO_ERROR != dwErr )
  91. {
  92. TRACE("miscTrayNotifyIconChange: HnPMConnectionEnum failed!");
  93. break;
  94. }
  95. TRACE1("miscTrayNotifyIconChange: %l Connections detected", pInfo->ConnCount);
  96. //Set up PortMapping for each connection
  97. //
  98. for ( i = 0; i < pInfo->ConnCount; i++ )
  99. {
  100. //won't do PortMapping for Incoming connections
  101. //
  102. if ( pInfo->ConnPropTable )
  103. {
  104. //define the class id for Incoming connections
  105. // reference to /nt/net/config/shell/wanui/rasui.cpp
  106. if( IsEqualCLSID(
  107. &CLSID_InboundConnection,
  108. &(pInfo->ConnPropTable[i].clsidThisObject) ) )
  109. {
  110. hr = INetConnection_QueryInterface(
  111. pInfo->ConnArray[i],
  112. &IID_INetConnectionSysTray,
  113. &pSysTray);
  114. ASSERT(pSysTray);
  115. if ( !SUCCEEDED(hr))
  116. {
  117. TRACE("miscTrayNotifyIconChange: Query pSysTray failed!");
  118. dwErr = ERROR_CAN_NOT_COMPLETE;
  119. break;
  120. }
  121. if( !pSysTray )
  122. {
  123. TRACE("miscTrayNotifyIconChange: pSysTray get NULL pointer!");
  124. dwErr = ERROR_CAN_NOT_COMPLETE;
  125. break;
  126. }
  127. INetConnectionSysTray_IconStateChanged(pSysTray);
  128. break;
  129. }
  130. }
  131. }//end of for(;;)
  132. if(pSysTray)
  133. {
  134. INetConnectionSysTray_Release(pSysTray);
  135. }
  136. }
  137. while(FALSE);
  138. miscTrayNotifyIconChangeCleanUp(pInfo);
  139. return dwErr;
  140. }//end of miscTrayNotifyIconChange()
  141. // Commits any changes made to the general tab values
  142. DWORD miscFlushDatabase(HANDLE hMiscDatabase) {
  143. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  144. DWORD dwErr, dwRet = NO_ERROR;
  145. // Flush out the multilink value
  146. if (!miscFlagsAreSame(This->bMultilinkEnabled, This->dwOrigFlags, FLAG_MULTILINK)) {
  147. dwErr = RasSrvSetMultilink(This->bMultilinkEnabled);
  148. if (dwErr != NO_ERROR) {
  149. DbgOutputTrace("miscFlushDatabase: Can't commit multilink 0x%08x", dwErr);
  150. dwRet = dwErr;
  151. }
  152. }
  153. // Flush the show icon setting
  154. if (!miscFlagsAreSame(This->bShowIcons, This->dwOrigFlags, FLAG_SHOWICON))
  155. {
  156. DWORD dwErr = NO_ERROR;
  157. dwErr = RasSrvSetIconShow(This->bShowIcons);
  158. if (dwErr != NO_ERROR) {
  159. DbgOutputTrace("miscFlushDatabase: Can't commit show icons 0x%08x", dwErr);
  160. dwRet = dwErr;
  161. }
  162. //for whistler bug 143344 gangz
  163. //update the tray icon on the taskbar
  164. //This notification should be done after RasSrvSetIconShow()
  165. //
  166. dwErr = miscTrayNotifyIconChange();
  167. TRACE1("miscFlushDatabase: %s", NO_ERROR == dwErr ?
  168. "miscTrayNotifyIconChange succeeded!" :
  169. "miscTrayNotifyIconChange failed!");
  170. }
  171. // Flush the log level setting as appropriate
  172. if (This->bLogLevelDirty)
  173. {
  174. RasSrvSetLogLevel(This->dwLogLevel);
  175. }
  176. return dwRet;
  177. }
  178. // Rollsback any changes made to the general tab values
  179. DWORD miscRollbackDatabase(HANDLE hMiscDatabase) {
  180. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  181. This->bFlushOnClose = FALSE;
  182. return NO_ERROR;
  183. }
  184. // Reloads any values for the general tab from disk
  185. DWORD miscReloadDatabase(HANDLE hMiscDatabase) {
  186. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  187. DWORD dwRet = NO_ERROR, dwErr, dwFlags = 0;
  188. // Initialize the product type
  189. dwErr = RasSrvGetMachineFlags (&dwFlags);
  190. if (dwErr != NO_ERROR)
  191. {
  192. DbgOutputTrace("RasSrvGetMachineFlags: Failed %x", dwErr);
  193. dwRet = dwErr;
  194. }
  195. // Initialize what we can from the flags
  196. //
  197. This->bIsServer = !!(dwFlags & RASSRVUI_MACHINE_F_Server);
  198. // Initialize the show icons setting
  199. //
  200. dwErr = RasSrvGetIconShow(&This->bShowIcons);
  201. if (dwErr != NO_ERROR)
  202. {
  203. DbgOutputTrace("miscReloadDatabase: Can't get iconshow 0x%08x", dwErr);
  204. dwRet = dwErr;
  205. }
  206. // Initialize multilink setting
  207. //
  208. dwErr = RasSrvGetMultilink(&(This->bMultilinkEnabled));
  209. if (dwErr != NO_ERROR)
  210. {
  211. DbgOutputTrace("miscReloadDatabase: Can't get encryption 0x%08x", dwErr);
  212. dwRet = dwErr;
  213. }
  214. return dwRet;
  215. }
  216. // Gets the multilink enable status
  217. DWORD miscGetMultilinkEnable(HANDLE hMiscDatabase, BOOL * pbEnabled) {
  218. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  219. if (!This || !pbEnabled)
  220. return ERROR_INVALID_PARAMETER;
  221. if (!pbEnabled)
  222. return ERROR_INVALID_HANDLE;
  223. *pbEnabled = This->bMultilinkEnabled;
  224. return NO_ERROR;
  225. }
  226. // Sets the multilink enable status
  227. DWORD miscSetMultilinkEnable(HANDLE hMiscDatabase, BOOL bEnable) {
  228. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  229. if (!This)
  230. return ERROR_INVALID_PARAMETER;
  231. This->bMultilinkEnabled = bEnable;
  232. return NO_ERROR;
  233. }
  234. // Gets the enable status of the "Show icons in the task bar" check box
  235. DWORD miscGetIconEnable(HANDLE hMiscDatabase, BOOL * pbEnabled) {
  236. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  237. if (!This || !pbEnabled)
  238. return ERROR_INVALID_PARAMETER;
  239. *pbEnabled = This->bShowIcons;
  240. return NO_ERROR;
  241. }
  242. // Sets the enable status of the "Show icons in the task bar" check box
  243. DWORD miscSetIconEnable(HANDLE hMiscDatabase, BOOL bEnable) {
  244. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  245. if (!This)
  246. return ERROR_INVALID_PARAMETER;
  247. This->bShowIcons = bEnable;
  248. return NO_ERROR;
  249. }
  250. // Tells whether this is nt workstation or nt server
  251. DWORD miscGetProductType(HANDLE hMiscDatabase, PBOOL pbIsServer) {
  252. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  253. if (!This || !pbIsServer)
  254. return ERROR_INVALID_PARAMETER;
  255. *pbIsServer = This->bIsServer;
  256. return NO_ERROR;
  257. }
  258. // Turns on ras error and warning logging
  259. DWORD
  260. miscSetRasLogLevel(
  261. IN HANDLE hMiscDatabase,
  262. IN DWORD dwLevel)
  263. {
  264. RASSRV_MISCDB * This = (RASSRV_MISCDB*)hMiscDatabase;
  265. if (!This)
  266. {
  267. return ERROR_INVALID_PARAMETER;
  268. }
  269. This->dwLogLevel = dwLevel;
  270. This->bLogLevelDirty = TRUE;
  271. return NO_ERROR;
  272. }