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.

302 lines
7.0 KiB

  1. //============================================================================
  2. // Copyright (C) Microsoft Corporation, 1997 - 1999
  3. //
  4. // File: rtrcfg.h
  5. //
  6. // Router configuration property pages
  7. //
  8. //============================================================================
  9. #ifndef _ATLKENV_H
  10. #define _ATLKENV_H
  11. #ifndef _LIST_
  12. #include <list>
  13. using namespace std;
  14. #endif
  15. #ifndef __WINCRYPT_H__
  16. #include "wincrypt.h"
  17. #endif
  18. #ifndef __SCLOGON_H__
  19. #include "sclogon.h"
  20. #endif
  21. #ifndef _NDISPNP_
  22. #include "ndispnp.h"
  23. #endif
  24. #ifndef _CSERVICE_H_
  25. #include "cservice.h"
  26. #endif
  27. #ifndef _CSERVICE_H_
  28. #include "cservice.h"
  29. #endif
  30. //TODO; remove these two typdefs in favor of private\inc\???.h include (check w/ shirish)
  31. typedef enum
  32. {
  33. AT_PNP_SWITCH_ROUTING = 0,
  34. AT_PNP_SWITCH_DEFAULT_ADAPTER,
  35. AT_PNP_RECONFIGURE_PARMS
  36. } ATALK_PNP_MSGTYPE;
  37. typedef struct _ATALK_PNP_EVENT
  38. {
  39. ATALK_PNP_MSGTYPE PnpMessage;
  40. } ATALK_PNP_EVENT, *PATALK_PNP_EVENT;
  41. // Appletalk constants/boundary values
  42. const DWORD MAX_RANGE_ALLOWED= 65279;
  43. const DWORD MIN_RANGE_ALLOWED= 1;
  44. const DWORD MAX_ZONES= 255;
  45. const DWORD ZONELISTSIZE= 2048;
  46. const DWORD MAX_ZONE_NAME_LEN=32;
  47. const DWORD ZONEBUFFER_LEN=32*255;
  48. const DWORD PARM_BUF_LEN=512;
  49. // this definition is copied from c
  50. #define MEDIATYPE_ETHERNET 1
  51. #define MEDIATYPE_TOKENRING 2
  52. #define MEDIATYPE_FDDI 3
  53. #define MEDIATYPE_WAN 4
  54. #define MEDIATYPE_LOCALTALK 5
  55. // Define a structure for reading/writing all information necessary about an adapter
  56. typedef struct
  57. {
  58. DWORD m_dwRangeLower;
  59. DWORD m_dwRangeUpper;
  60. DWORD m_dwSeedingNetwork;
  61. DWORD m_dwMediaType;
  62. CString m_szDefaultZone;
  63. CString m_szAdapter;
  64. CString m_szDevAdapter;
  65. CString m_szPortName;
  66. CStringList m_listZones;
  67. bool m_fDefAdapter;
  68. } ATLK_REG_ADAPTER;
  69. typedef struct
  70. {
  71. DWORD m_dwRangeLower;
  72. DWORD m_dwRangeUpper;
  73. CString m_szDefaultZone;
  74. CStringList m_listZones;
  75. } ATLK_DYN_ADAPTER;
  76. struct CStop_StartAppleTalkPrint
  77. {
  78. CStop_StartAppleTalkPrint()
  79. {
  80. bStopedByMe = FALSE;
  81. if (SUCCEEDED( csm.HrOpen(SC_MANAGER_CONNECT, NULL, NULL)))
  82. {
  83. if (SUCCEEDED(csm.HrOpenService(&svr, c_szMacPrint)))
  84. {
  85. if (SUCCEEDED(svr.HrControl(SERVICE_CONTROL_STOP)))
  86. {
  87. bStopedByMe = TRUE;
  88. }
  89. }
  90. }
  91. /* change to use exisiting functions
  92. DWORD dwErr = 0;
  93. hScManager = NULL;
  94. hService = NULL;
  95. bStopedByMe = FALSE;
  96. bUsedToBePaused = FALSE;
  97. hScManager = OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT );
  98. if(hScManager != NULL)
  99. hService = OpenService(hScManager, L"MacPrint", SERVICE_ALL_ACCESS);
  100. else
  101. dwErr = GetLastError();
  102. if(hService != NULL)
  103. {
  104. SERVICE_STATUS ss;
  105. if(QueryServiceStatus(hService, &ss) != 0) // SUCC
  106. {
  107. if(ss.dwCurrentState == SERVICE_RUNNING || ss.dwCurrentState == SERVICE_PAUSED)
  108. {
  109. SERVICE_STATUS ss1;
  110. if(ControlService(hService, SERVICE_CONTROL_STOP, &ss1) == 0) // FAILED
  111. dwErr = GetLastError();
  112. else
  113. {
  114. bStopedByMe = TRUE;
  115. if( ss.dwCurrentState == SERVICE_PAUSED )
  116. bUsedToBePaused = TRUE;
  117. }
  118. }
  119. // not doing anything if not running
  120. }
  121. else
  122. dwErr = GetLastError();
  123. }
  124. else
  125. {
  126. dwErr = GetLastError();
  127. if(dwErr == ERROR_SERVICE_DOES_NOT_EXIST)
  128. dwErr = 0;
  129. }
  130. if(dwErr != 0) // something was wrong
  131. DisplayErrorMessage(NULL, HRESULT_FROM_WIN32(dwErr));
  132. */
  133. };
  134. ~CStop_StartAppleTalkPrint()
  135. {
  136. if(bStopedByMe) // start it
  137. {
  138. svr.HrStart ();
  139. /* change to use existing function
  140. ASSERT(hService != NULL);
  141. if(0 == StartService(hService, 0, NULL)) // FAILED
  142. {
  143. DisplayErrorMessage(NULL, HRESULT_FROM_WIN32(GetLastError()));
  144. }
  145. else
  146. {
  147. if(bUsedToBePaused == TRUE)
  148. {
  149. // if it was paused
  150. SERVICE_STATUS ss;
  151. if(ControlService(hService, SERVICE_CONTROL_PAUSE, &ss) == 0) // FAILED
  152. DisplayErrorMessage(NULL, HRESULT_FROM_WIN32(GetLastError()));
  153. }
  154. }
  155. }
  156. // close the handles
  157. if(hService != NULL)
  158. CloseServiceHandle(hService);
  159. if(hScManager != NULL)
  160. CloseServiceHandle(hScManager);
  161. hService = NULL;
  162. hScManager = NULL;
  163. */
  164. }
  165. }
  166. protected:
  167. /* change to use existing functions
  168. SC_HANDLE hScManager;
  169. SC_HANDLE hService;
  170. BOOL bUsedToBePaused;
  171. */
  172. CServiceManager csm;
  173. CService svr;
  174. BOOL bStopedByMe;
  175. };
  176. // Define a structure for reading/writing AppleTalk\Parameters values
  177. typedef struct
  178. {
  179. DWORD dwEnableRouter;
  180. TCHAR* szDefaultPort;
  181. TCHAR* szDesiredZone;
  182. } ATLK_PARAMS;
  183. class CAdapterInfo
  184. {
  185. public:
  186. CAdapterInfo() {m_fAlreadyShown = false;};
  187. ~CAdapterInfo() {};
  188. // m_AdapterInfo is the collection of values found under
  189. // AppleTalk\Parameters\Adapters\<adapter>
  190. ATLK_REG_ADAPTER m_regInfo;
  191. // fetched via sockets
  192. ATLK_DYN_ADAPTER m_dynInfo;
  193. bool m_fNotifyPnP; //need to notify PnP?
  194. bool m_fModified; //been modified?
  195. bool m_fReloadReg; //reload registry?
  196. bool m_fReloadDyn; //reload network values?
  197. bool m_fAlreadyShown; // is this adapter already in the UI?
  198. friend class CATLKEnv;
  199. };
  200. //*****************************************************************
  201. //
  202. //*****************************************************************
  203. class CATLKEnv
  204. {
  205. public:
  206. CATLKEnv() : m_dwF(0) {};
  207. ~CATLKEnv();
  208. enum {ATLK_ONLY_DEFADAPTER=0x1, ATLK_ONLY_ONADAPTER=0x2};
  209. list<CAdapterInfo* > m_adapterinfolist;
  210. typedef list<CAdapterInfo* > AL;
  211. typedef list<CAdapterInfo* >::iterator AI;
  212. void SetServerName(CString& szServerName)
  213. { m_szServerName = szServerName; }
  214. //this reloads registry (optional) and network values
  215. HRESULT GetAdapterInfo(bool fReloadReg=true);
  216. //for each adapter, loads values to registry
  217. HRESULT SetAdapterInfo();
  218. //this method is called for non-adapter (global) appletalk changes
  219. static HRESULT HrAtlkPnPSwithRouting();
  220. //this method is called for adapter specific PnP notifications
  221. HRESULT HrAtlkPnPReconfigParams(BOOL bForcePnP = FALSE);
  222. //find a specific adapter info
  223. CAdapterInfo* FindAdapter(CString& szAdapter);
  224. static HRESULT IsAdapterBoundToAtlk(LPWSTR szAdapter, BOOL* bBound);
  225. // registry value "MediaType" is added, so this function is not necessary.
  226. // HRESULT IsLocalTalkAdaptor(CAdapterInfo* pAdapterInfo, BOOL* pbIsLocalTalk);
  227. // S_OK: LOCALTALK
  228. // S_FALSE: Not
  229. // ERRORs
  230. //reloads reg and dynamic info for an adapterinfo
  231. HRESULT ReloadAdapter(CAdapterInfo* pAdapterInfo, bool fOnlyDyn =false);
  232. //set specific flags for loading (not multithread safe!)
  233. void SetFlags(DWORD dwF) {m_dwF=dwF;}
  234. //load adapter info
  235. HRESULT FetchRegInit();
  236. protected:
  237. CString m_szServerName;
  238. bool m_fATrunning;
  239. DWORD m_dwDefaultAdaptersMediaType;
  240. ATLK_PARAMS m_Params;
  241. DWORD m_dwF;
  242. HRESULT _HrGetAndSetNetworkInformation(SOCKET socket, CAdapterInfo* pAdapInfo);
  243. void _AddZones(CHAR * szZoneList, ULONG NumZones, CAdapterInfo* pAdapterinfo);
  244. };
  245. #endif _ATLKENV_H