SessionSettings.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. * Copyright (C) 2006-2010 Alfresco Software Limited.
  3. *
  4. * This file is part of Alfresco
  5. *
  6. * Alfresco is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Alfresco is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package org.alfresco.jlan.client;
  20. import java.net.*;
  21. import org.alfresco.jlan.netbios.NetBIOSSession;
  22. import org.alfresco.jlan.netbios.RFCNetBIOSProtocol;
  23. import org.alfresco.jlan.smb.DialectSelector;
  24. import org.alfresco.jlan.smb.Protocol;
  25. import org.alfresco.jlan.smb.TcpipSMB;
  26. /**
  27. * The session settings class holds the connection options for a new SMB session.
  28. *
  29. * <p>A SessionSettings object can be used with the various open session methods of the SessionFactory class to specify per
  30. * session overrides to the default settings, such as protocol order, remote ports, timeout values, debugging options.
  31. *
  32. * @author gkspencer
  33. */
  34. public class SessionSettings {
  35. // Primary and secondary protocols to connect with
  36. private int m_primaryProto = Protocol.TCPNetBIOS;
  37. private int m_secondaryProto = Protocol.NativeSMB;
  38. // SMB dialects to negotiate
  39. private DialectSelector m_dialects;
  40. // Session timeout, in milliseconds. Used for initial connection and send/receive.
  41. private int m_timeout = RFCNetBIOSProtocol.TMO;
  42. // NetBIOS session and native SMB session ports
  43. private int m_netbiosPort = RFCNetBIOSProtocol.PORT;
  44. private int m_nativeSMBPort = TcpipSMB.PORT;
  45. // NetBIOS name scope
  46. private String m_netbiosScopeId;
  47. // NetBIOS name port
  48. private int m_netbiosNamePort = RFCNetBIOSProtocol.NAME_PORT;
  49. // NetBIOS broadcast name lookup subnet mask
  50. private String m_subnetMask;
  51. // WINS server address
  52. private InetAddress m_WINSServer = NetBIOSSession.getDefaultWINSServer();
  53. // NetBIOS name lookup type and timeout, in milliseconds
  54. private int m_lookupType = NetBIOSSession.getDefaultLookupType();
  55. private int m_lookupTmo = NetBIOSSession.getDefaultLookupTimeout();
  56. // Use wildcard file server name when connecting to remote server
  57. private boolean m_useWildcardName = NetBIOSSession.getDefaultWildcardFileServerName();
  58. // Flag to indicate if the primary protocol should be updated from the secondary protocol
  59. // setting when the connection is successfully made using the secondary protocol.
  60. private boolean m_updateProtocol;
  61. // Virtual circuit, a value of zero may reset other connections from this name or address
  62. private int m_vcircuit;
  63. /**
  64. * Default constructor
  65. */
  66. public SessionSettings() {
  67. }
  68. /**
  69. * Class constructor
  70. *
  71. * @param primaryProto int
  72. * @param secondaryProto int
  73. */
  74. public SessionSettings(int primaryProto, int secondaryProto) {
  75. m_primaryProto = primaryProto;
  76. m_secondaryProto = secondaryProto;
  77. }
  78. /**
  79. * /** Class constructor
  80. *
  81. * @param primaryProto int
  82. * @param secondaryProto int
  83. * @param tmo int
  84. */
  85. public SessionSettings(int primaryProto, int secondaryProto, int tmo) {
  86. m_primaryProto = primaryProto;
  87. m_secondaryProto = secondaryProto;
  88. m_timeout = tmo;
  89. }
  90. /**
  91. * Return the primary protocol
  92. *
  93. * @return int
  94. */
  95. public final int getPrimaryProtocol() {
  96. return m_primaryProto;
  97. }
  98. /**
  99. * Return the secondary protocol
  100. *
  101. * @return int
  102. */
  103. public final int getSecondaryProtocol() {
  104. return m_secondaryProto;
  105. }
  106. /**
  107. * Return the session timeout
  108. *
  109. * @return int
  110. */
  111. public final int getSessionTimeout() {
  112. return m_timeout;
  113. }
  114. /**
  115. * Return the SMB dialect list to negotiate
  116. *
  117. * @return DialectSelector
  118. */
  119. public final DialectSelector getDialects() {
  120. return m_dialects;
  121. }
  122. /**
  123. * Return the NetBIOS session port
  124. *
  125. * @return int
  126. */
  127. public final int getNetBIOSSessionPort() {
  128. return m_netbiosPort;
  129. }
  130. /**
  131. * Return the NetBIOS name port
  132. *
  133. * @return int
  134. */
  135. public final int getNetBIOSNamePort() {
  136. return m_netbiosNamePort;
  137. }
  138. /**
  139. * Return the native SMB port
  140. *
  141. * @return int
  142. */
  143. public final int getNativeSMBPort() {
  144. return m_nativeSMBPort;
  145. }
  146. /**
  147. * Determine if the NetBIOS name scope is set
  148. *
  149. * @return boolean
  150. */
  151. public final boolean hasNetBIOSNameScope() {
  152. return m_netbiosScopeId != null ? true : false;
  153. }
  154. /**
  155. * Return the NetBIOS name scope
  156. *
  157. * @return String
  158. */
  159. public final String getNetBIOSNameScope() {
  160. return m_netbiosScopeId;
  161. }
  162. /**
  163. * Get the subnet mask to be used for NetBIOS name lookup broadcasts
  164. *
  165. * @return String
  166. */
  167. public final String getSubnetMask() {
  168. return m_subnetMask;
  169. }
  170. /**
  171. * Get the WINS server to be used for NetBIOS name lookups
  172. *
  173. * @return InetAddress
  174. */
  175. public final InetAddress getWINSServer() {
  176. return m_WINSServer;
  177. }
  178. /**
  179. * Get the NetBIOS name lookup type(s) to use
  180. *
  181. * @return int
  182. */
  183. public final int getLookupType() {
  184. return m_lookupType;
  185. }
  186. /**
  187. * Get the NetBIOS name lookup timeout, in milliseconds
  188. *
  189. * @return int
  190. */
  191. public final int getLookupTimeout() {
  192. return m_lookupTmo;
  193. }
  194. /**
  195. * Get the use wildcard file server name (*SMBSERVER) flag
  196. *
  197. * @return boolean
  198. */
  199. public final boolean useWildcardServerName() {
  200. return m_useWildcardName;
  201. }
  202. /**
  203. * Check if the update primary protocol flag is set
  204. *
  205. * @return boolean
  206. */
  207. public final boolean hasUpdateProtocol() {
  208. return m_updateProtocol;
  209. }
  210. /**
  211. * Return the virtual circuit for this session
  212. *
  213. * @return int
  214. */
  215. public final int getVirtualCircuit() {
  216. return m_vcircuit;
  217. }
  218. /**
  219. * Set the primary connection protocol
  220. *
  221. * @param proto int
  222. */
  223. public final void setPrimaryProtocol(int proto) {
  224. m_primaryProto = proto;
  225. }
  226. /**
  227. * Set the secondary connection protocol
  228. *
  229. * @param proto int
  230. */
  231. public final void setSecondaryProtocol(int proto) {
  232. m_secondaryProto = proto;
  233. }
  234. /**
  235. * Set the session connection timeout, in milliseconds
  236. *
  237. * @param tmo int
  238. */
  239. public final void setSessionTimeout(int tmo) {
  240. m_timeout = tmo;
  241. }
  242. /**
  243. * Set the negotiated dialect list
  244. *
  245. * @param dialects DialectSelector
  246. */
  247. public final void setDialects(DialectSelector dialects) {
  248. m_dialects = dialects;
  249. }
  250. /**
  251. * Set the NetBIOS session port
  252. *
  253. * @param port int
  254. */
  255. public final void setNetBIOSSessionPort(int port) {
  256. m_netbiosPort = port;
  257. }
  258. /**
  259. * Set the NetBIOS name port
  260. *
  261. * @param port int
  262. */
  263. public final void setNetBIOSNamePort(int port) {
  264. m_netbiosNamePort = port;
  265. }
  266. /**
  267. * Set the native SMB port
  268. *
  269. * @param port int
  270. */
  271. public final void setNativeSMBPort(int port) {
  272. m_nativeSMBPort = port;
  273. }
  274. /**
  275. * Set the NetBIOS name scope
  276. *
  277. * @param scope String
  278. */
  279. public final void setNetBIOSNameScope(String scope) {
  280. m_netbiosScopeId = scope;
  281. }
  282. /**
  283. * Set the subnet mask to be used for NetBIOS name lookup broadcasts
  284. *
  285. * @param mask String
  286. */
  287. public final void setSubnetMask(String mask) {
  288. m_subnetMask = mask;
  289. }
  290. /**
  291. * Set the WINS server to be used for NetBIOS name lookups
  292. *
  293. * @param addr InetAddress
  294. */
  295. public final void setWINSServer(InetAddress addr) {
  296. m_WINSServer = addr;
  297. }
  298. /**
  299. * Set the NetBIOS name lookup type(s) to use
  300. *
  301. * @param typ int
  302. */
  303. public final void setLookupType(int typ) {
  304. m_lookupType = typ;
  305. }
  306. /**
  307. * Set the NetBIOS name lookup timeout, in milliseconds
  308. *
  309. * @param tmo int
  310. */
  311. public final void setLookupTimeout(int tmo) {
  312. m_lookupTmo = tmo;
  313. }
  314. /**
  315. * Set/clear the use wildcard file server name (*SMBSERVER) flag
  316. *
  317. * @param ena boolean
  318. */
  319. public final void setUseWildcardServerName(boolean ena) {
  320. m_useWildcardName = ena;
  321. }
  322. /**
  323. * Set/clear the update protocol flag
  324. *
  325. * @param updateProto boolean
  326. */
  327. public final void setUpdateProtocol(boolean updateProto) {
  328. m_updateProtocol = updateProto;
  329. }
  330. /**
  331. * Set the virtual circuit
  332. *
  333. * @param vc int
  334. */
  335. public final void setVirtualCircuit(int vc) {
  336. m_vcircuit = vc;
  337. }
  338. /**
  339. * Return the session settings as a string
  340. *
  341. * @return String
  342. */
  343. public String toString() {
  344. StringBuffer str = new StringBuffer();
  345. str.append("[");
  346. str.append(Protocol.asString(getPrimaryProtocol()));
  347. str.append(",");
  348. str.append(Protocol.asString(getSecondaryProtocol()));
  349. str.append(",Tmo=");
  350. str.append(getSessionTimeout());
  351. str.append("ms,Dialects=");
  352. str.append(getDialects());
  353. if ( getNetBIOSSessionPort() != RFCNetBIOSProtocol.PORT) {
  354. str.append(",NB Port=");
  355. str.append(getNetBIOSSessionPort());
  356. }
  357. if ( getNativeSMBPort() != TcpipSMB.PORT) {
  358. str.append(",CIFS Port=");
  359. str.append(getNativeSMBPort());
  360. }
  361. if ( hasNetBIOSNameScope()) {
  362. str.append(",ScopeId=");
  363. str.append(getNetBIOSNameScope());
  364. }
  365. str.append(",VC=");
  366. str.append(getVirtualCircuit());
  367. str.append("]");
  368. return str.toString();
  369. }
  370. }