| Source/RemObjects.InternetPack.VirtualFTP/VirtualFtpServer.cs |
| 5 | 5 | using RemObjects.InternetPack; |
| 6 | 6 | using RemObjects.InternetPack.CommandBased; |
| 7 | 7 | using RemObjects.InternetPack.Ftp; |
| 8 | | using RemObjects.DebugServer; |
| 9 | 8 | |
| 10 | 9 | namespace RemObjects.InternetPack.Ftp.VirtualFtp |
| 11 | 10 | { |
| 12 | 11 | #if FULLFRAMEWORK |
| 13 | 12 | [ System.Drawing.ToolboxBitmap(typeof(RemObjects.InternetPack.Server), "Glyphs.VirtualFtpServer.bmp") ] |
| 14 | 13 | #endif |
| 15 | | public class VirtualFtpServer : FtpServer |
| 16 | | { |
| 17 | | public VirtualFtpServer() |
| 18 | | { |
| 19 | | } |
| 20 | | |
| 21 | | #region Properties |
| 22 | | private IFtpFolder fRootFolder; |
| 23 | | public IFtpFolder RootFolder |
| 24 | | { |
| 25 | | get { return fRootFolder; } |
| 26 | | set { fRootFolder = value; } |
| 27 | | } |
| 14 | public class VirtualFtpServer : FtpServer |
| 15 | { |
| 16 | public VirtualFtpServer() |
| 17 | { |
| 18 | } |
| 28 | 19 | |
| 29 | | private IFtpUserManager fUserManager; |
| 30 | | public IFtpUserManager UserManager |
| 31 | | { |
| 32 | | get { return fUserManager; } |
| 33 | | set { fUserManager = value; } |
| 34 | | } |
| 35 | | #endregion |
| 20 | #region Properties |
| 21 | private IFtpFolder fRootFolder; |
| 22 | public IFtpFolder RootFolder |
| 23 | { |
| 24 | get { return fRootFolder; } |
| 25 | set { fRootFolder = value; } |
| 26 | } |
| 36 | 27 | |
| 37 | | protected override Type GetDefaultSessionClass() |
| 38 | | { |
| 39 | | return typeof(VirtualFtpSession); |
| 40 | | } |
| 28 | private IFtpUserManager fUserManager; |
| 29 | public IFtpUserManager UserManager |
| 30 | { |
| 31 | get { return fUserManager; } |
| 32 | set { fUserManager = value; } |
| 33 | } |
| 34 | #endregion |
| 41 | 35 | |
| 42 | | #region Login & IP Check |
| 43 | | protected override void InvokeOnUserLogin(FtpUserLoginEventArgs ea) |
| 44 | | { |
| 45 | | Debug.EnterMethod("Login({0})",ea.UserName); |
| 46 | | try |
| 47 | | { |
| 48 | | if (fUserManager == null) return; |
| 49 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 50 | | ea.LoginOk = fUserManager.CheckLogin(ea.UserName, ea.Password, lSession); |
| 51 | | |
| 52 | | Debug.Write("Login result "+ea.LoginOk); |
| 53 | | base.InvokeOnUserLogin(ea); |
| 54 | | } |
| 55 | | finally |
| 56 | | { |
| 57 | | Debug.ExitMethod("Login({0}):{1}",ea.UserName,ea.LoginOk); |
| 58 | | } |
| 59 | | } |
| 36 | protected override Type GetDefaultSessionClass() |
| 37 | { |
| 38 | return typeof(VirtualFtpSession); |
| 39 | } |
| 60 | 40 | |
| 61 | | protected override void InvokeOnClientConnected(SessionEventArgs ea) |
| 62 | | { |
| 63 | | ((VirtualFtpSession)ea.Session).CurrentFolder = fRootFolder; |
| 64 | | if (fUserManager == null) return; |
| 65 | | if (!fUserManager.CheckIP(ea.Connection.RemoteEndPoint, ea.Connection.LocalEndPoint)) |
| 66 | | { |
| 67 | | ea.Connection.Disconnect(); |
| 68 | | throw new Exception("Access not allowed from this IP."); |
| 69 | | } |
| 70 | | base.InvokeOnClientConnected(ea); |
| 71 | | } |
| 72 | | #endregion |
| 41 | #region Login & IP Check |
| 42 | protected override void InvokeOnUserLogin(FtpUserLoginEventArgs ea) |
| 43 | { |
| 44 | #if DEBUGSERVER |
| 45 | Debug.EnterMethod("Login({0})", ea.UserName); |
| 46 | try |
| 47 | { |
| 48 | #endif |
| 49 | if (fUserManager == null) return; |
| 50 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 51 | ea.LoginOk = fUserManager.CheckLogin(ea.UserName, ea.Password, lSession); |
| 52 | #if DEBUGSERVER |
| 53 | Debug.Write("Login result " + ea.LoginOk); |
| 54 | #endif |
| 55 | base.InvokeOnUserLogin(ea); |
| 56 | #if DEBUGSERVER |
| 57 | } |
| 58 | finally |
| 59 | { |
| 60 | Debug.ExitMethod("Login({0}):{1}", ea.UserName, ea.LoginOk); |
| 61 | } |
| 62 | #endif |
| 63 | } |
| 73 | 64 | |
| 74 | | #region Folder handling |
| 75 | | protected override void InvokeOnGetListing(FtpGetListingArgs ea) |
| 76 | | { |
| 77 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 78 | | Debug.Write("Getting Listing for {0}",lSession.CurrentFolder.FullPath); |
| 79 | | |
| 80 | | lSession.CurrentFolder.ListFolderItems(ea.Listing); |
| 65 | protected override void InvokeOnClientConnected(SessionEventArgs ea) |
| 66 | { |
| 67 | ((VirtualFtpSession)ea.Session).CurrentFolder = fRootFolder; |
| 68 | if (fUserManager == null) return; |
| 69 | if (!fUserManager.CheckIP(ea.Connection.RemoteEndPoint, ea.Connection.LocalEndPoint)) |
| 70 | { |
| 71 | ea.Connection.Disconnect(); |
| 72 | throw new Exception("Access not allowed from this IP."); |
| 73 | } |
| 74 | base.InvokeOnClientConnected(ea); |
| 75 | } |
| 76 | #endregion |
| 81 | 77 | |
| 82 | | base.InvokeOnGetListing(ea); |
| 83 | | } |
| 78 | #region Folder handling |
| 79 | protected override void InvokeOnGetListing(FtpGetListingArgs ea) |
| 80 | { |
| 81 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 82 | #if DEBUGSERVER |
| 83 | Debug.Write("Getting Listing for {0}", lSession.CurrentFolder.FullPath); |
| 84 | #endif |
| 85 | lSession.CurrentFolder.ListFolderItems(ea.Listing); |
| 84 | 86 | |
| 85 | | protected override void InvokeOnChangeDirectory(FtpChangeDirectoryArgs ea) |
| 86 | | { |
| 87 | | string lPath = ea.NewDirectory; |
| 87 | base.InvokeOnGetListing(ea); |
| 88 | } |
| 88 | 89 | |
| 89 | | if (lPath.IndexOf('/') != 0) |
| 90 | | throw new Exception(String.Format("Not an absolute path: \"{0}\"",lPath)); |
| 91 | | |
| 92 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 93 | | IFtpFolder lFolder = fRootFolder.DigForSubFolder(lPath.Substring(1), lSession); |
| 90 | protected override void InvokeOnChangeDirectory(FtpChangeDirectoryArgs ea) |
| 91 | { |
| 92 | string lPath = ea.NewDirectory; |
| 94 | 93 | |
| 95 | | if (lFolder != null) |
| 96 | | { |
| 97 | | ((VirtualFtpSession)ea.Session).CurrentFolder = lFolder; |
| 98 | | } |
| 99 | | ea.ChangeDirOk = (lFolder != null); |
| 100 | | base.InvokeOnChangeDirectory(ea); |
| 101 | | } |
| 94 | if (lPath.IndexOf('/') != 0) |
| 95 | throw new Exception(String.Format("Not an absolute path: \"{0}\"", lPath)); |
| 102 | 96 | |
| 103 | | protected override void InvokeOnMakeDirectory(FtpFileEventArgs ea) |
| 104 | | { |
| 105 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 97 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 98 | IFtpFolder lFolder = fRootFolder.DigForSubFolder(lPath.Substring(1), lSession); |
| 106 | 99 | |
| 107 | | IFtpFolder lFolder; |
| 108 | | string lFilename; |
| 100 | if (lFolder != null) |
| 101 | { |
| 102 | ((VirtualFtpSession)ea.Session).CurrentFolder = lFolder; |
| 103 | } |
| 104 | ea.ChangeDirOk = (lFolder != null); |
| 105 | base.InvokeOnChangeDirectory(ea); |
| 106 | } |
| 109 | 107 | |
| 110 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 111 | | lFolder.CreateFolder(lFilename,lSession); |
| 112 | | ea.Ok = true; |
| 108 | protected override void InvokeOnMakeDirectory(FtpFileEventArgs ea) |
| 109 | { |
| 110 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 113 | 111 | |
| 114 | | } |
| 112 | IFtpFolder lFolder; |
| 113 | string lFilename; |
| 115 | 114 | |
| 116 | | protected override void InvokeOnDeleteDirectory(FtpFileEventArgs ea) |
| 117 | | { |
| 118 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 119 | | IFtpFolder lFolder; |
| 120 | | string lFilename; |
| 115 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 116 | lFolder.CreateFolder(lFilename, lSession); |
| 117 | ea.Ok = true; |
| 121 | 118 | |
| 122 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 123 | | lFolder.DeleteFolder(lFilename,false,lSession); |
| 124 | | ea.Ok = true; |
| 125 | | } |
| 126 | | #endregion |
| 119 | } |
| 127 | 120 | |
| 128 | | #region File Handling |
| 129 | | protected override void InvokeOnCanStoreFile(FtpTransferEventArgs ea) |
| 130 | | { |
| 131 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 132 | | IFtpFolder lFolder; |
| 133 | | string lFilename; |
| 121 | protected override void InvokeOnDeleteDirectory(FtpFileEventArgs ea) |
| 122 | { |
| 123 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 124 | IFtpFolder lFolder; |
| 125 | string lFilename; |
| 134 | 126 | |
| 135 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 136 | | ea.Ok = lFolder.AllowPut(lSession); |
| 137 | | } |
| 127 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 128 | lFolder.DeleteFolder(lFilename, false, lSession); |
| 129 | ea.Ok = true; |
| 130 | } |
| 131 | #endregion |
| 138 | 132 | |
| 139 | | protected override void InvokeOnCanRetrieveFile(FtpTransferEventArgs ea) |
| 140 | | { |
| 141 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 142 | | IFtpFolder lFolder; |
| 143 | | string lFilename; |
| 133 | #region File Handling |
| 134 | protected override void InvokeOnCanStoreFile(FtpTransferEventArgs ea) |
| 135 | { |
| 136 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 137 | IFtpFolder lFolder; |
| 138 | string lFilename; |
| 144 | 139 | |
| 145 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 146 | | IFtpFile lFile = lFolder.GetFile(lFilename,lSession); |
| 147 | | ea.Ok = (lFile != null && lFile.AllowRead(lSession)); |
| 148 | | } |
| 140 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 141 | ea.Ok = lFolder.AllowPut(lSession); |
| 142 | } |
| 149 | 143 | |
| 150 | | protected override void InvokeOnStoreFile(FtpTransferEventArgs ea) |
| 151 | | { |
| 152 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 153 | | IFtpFolder lFolder; |
| 154 | | string lFilename; |
| 144 | protected override void InvokeOnCanRetrieveFile(FtpTransferEventArgs ea) |
| 145 | { |
| 146 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 147 | IFtpFolder lFolder; |
| 148 | string lFilename; |
| 155 | 149 | |
| 156 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 157 | | IFtpFile lFile = lFolder.CreateFile(lFilename,lSession); |
| 158 | | lFile.CreateFile(ea.DataChannel); |
| 159 | | ea.Ok = true; |
| 160 | | } |
| 150 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 151 | IFtpFile lFile = lFolder.GetFile(lFilename, lSession); |
| 152 | ea.Ok = (lFile != null && lFile.AllowRead(lSession)); |
| 153 | } |
| 161 | 154 | |
| 162 | | protected override void InvokeOnRetrieveFile(FtpTransferEventArgs ea) |
| 163 | | { |
| 164 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 165 | | IFtpFolder lFolder; |
| 166 | | string lFilename; |
| 155 | protected override void InvokeOnStoreFile(FtpTransferEventArgs ea) |
| 156 | { |
| 157 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 158 | IFtpFolder lFolder; |
| 159 | string lFilename; |
| 167 | 160 | |
| 168 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 169 | | IFtpFile lFile = lFolder.GetFile(lFilename,lSession); |
| 170 | | lFile.GetFile(ea.DataChannel); |
| 171 | | ea.Ok = true; |
| 172 | | } |
| 161 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 162 | IFtpFile lFile = lFolder.CreateFile(lFilename, lSession); |
| 163 | lFile.CreateFile(ea.DataChannel); |
| 164 | ea.Ok = true; |
| 165 | } |
| 173 | 166 | |
| 174 | | protected override void InvokeOnRename(FtpRenameEventArgs ea) |
| 175 | | { |
| 176 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 177 | | IFtpFolder lFolder; |
| 178 | | string lFilename; |
| 167 | protected override void InvokeOnRetrieveFile(FtpTransferEventArgs ea) |
| 168 | { |
| 169 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 170 | IFtpFolder lFolder; |
| 171 | string lFilename; |
| 179 | 172 | |
| 180 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 181 | | lFolder.RenameFileOrFolder(lFilename, ea.NewFileName, lSession); |
| 182 | | ea.Ok = true; |
| 183 | | } |
| 173 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 174 | IFtpFile lFile = lFolder.GetFile(lFilename, lSession); |
| 175 | lFile.GetFile(ea.DataChannel); |
| 176 | ea.Ok = true; |
| 177 | } |
| 184 | 178 | |
| 185 | | protected override void InvokeOnDelete(FtpFileEventArgs ea) |
| 186 | | { |
| 187 | | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 188 | | IFtpFolder lFolder; |
| 189 | | string lFilename; |
| 179 | protected override void InvokeOnRename(FtpRenameEventArgs ea) |
| 180 | { |
| 181 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 182 | IFtpFolder lFolder; |
| 183 | string lFilename; |
| 190 | 184 | |
| 191 | | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 192 | | lFolder.DeleteFile(lFilename, lSession); |
| 193 | | ea.Ok = true; |
| 194 | | } |
| 195 | | #endregion |
| 185 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 186 | lFolder.RenameFileOrFolder(lFilename, ea.NewFileName, lSession); |
| 187 | ea.Ok = true; |
| 188 | } |
| 196 | 189 | |
| 197 | | } |
| 190 | protected override void InvokeOnDelete(FtpFileEventArgs ea) |
| 191 | { |
| 192 | VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; |
| 193 | IFtpFolder lFolder; |
| 194 | string lFilename; |
| 198 | 195 | |
| 196 | lSession.CurrentFolder.FindBaseFolderForFilename(ea.FileName, out lFolder, out lFilename, lSession); |
| 197 | lFolder.DeleteFile(lFilename, lSession); |
| 198 | ea.Ok = true; |
| 199 | } |
| 200 | #endregion |
| 201 | |
| 202 | } |
| 203 | |
| 199 | 204 | } |
| Source/RemObjects.InternetPack/RemObjects.InternetPack.CF.2003.csdproj |
| 1 | <VisualStudioProject> |
| 2 | <ECSHARP |
| 3 | ProjectType = "Local" |
| 4 | ProductVersion = "7.10.3077" |
| 5 | SchemaVersion = "1.0" |
| 6 | ProjectGuid = "{67DA6880-E6C5-4C3A-B84F-80FBCC2FD5DB}" |
| 7 | > |
| 8 | <Build> |
| 9 | <Settings |
| 10 | ApplicationIcon = "" |
| 11 | AssemblyKeyContainerName = "" |
| 12 | AssemblyName = "RemObjects.InternetPack" |
| 13 | AssemblyOriginatorKeyFile = "" |
| 14 | DelaySign = "false" |
| 15 | OutputType = "Library" |
| 16 | OutputFileFolder = "\Program Files\RemObjects.InternetPack.CF" |
| 17 | RootNamespace = "RemObjects.InternetPack.Core" |
| 18 | StartupObject = "" |
| 19 | > |
| 20 | <Platform Name = "Pocket PC" /> |
| 21 | <Config |
| 22 | Name = "Debug|Pocket PC" |
| 23 | AllowUnsafeBlocks = "false" |
| 24 | BaseAddress = "0" |
| 25 | CheckForOverflowUnderflow = "false" |
| 26 | ConfigurationOverrideFile = "" |
| 27 | DefineConstants = "DEBUG;TRACE;COMPACTFRAMEWORK;REMOBJECTS_SIGN_ASSEMBLY" |
| 28 | DocumentationFile = "" |
| 29 | DebugSymbols = "true" |
| 30 | FileAlignment = "4096" |
| 31 | IncrementalBuild = "false" |
| 32 | Optimize = "false" |
| 33 | OutputPath = "bin\Debug\" |
| 34 | RegisterForComInterop = "false" |
| 35 | RemoveIntegerChecks = "false" |
| 36 | TreatWarningsAsErrors = "false" |
| 37 | WarningLevel = "4" |
| 38 | /> |
| 39 | <Config |
| 40 | Name = "Release|Pocket PC" |
| 41 | AllowUnsafeBlocks = "false" |
| 42 | BaseAddress = "0" |
| 43 | CheckForOverflowUnderflow = "false" |
| 44 | ConfigurationOverrideFile = "" |
| 45 | DefineConstants = "TRACE;COMPACTFRAMEWORK;REMOBJECTS_SIGN_ASSEMBLY" |
| 46 | DocumentationFile = "" |
| 47 | DebugSymbols = "true" |
| 48 | FileAlignment = "4096" |
| 49 | IncrementalBuild = "false" |
| 50 | Optimize = "true" |
| 51 | OutputPath = "..\..\Bin\CF\" |
| 52 | RegisterForComInterop = "false" |
| 53 | RemoveIntegerChecks = "false" |
| 54 | TreatWarningsAsErrors = "false" |
| 55 | WarningLevel = "4" |
| 56 | /> |
| 57 | </Settings> |
| 58 | <References> |
| 59 | <Reference |
| 60 | Platform = "Pocket PC" |
| 61 | Name = "MSCorLib" |
| 62 | AssemblyName = "mscorlib" |
| 63 | Private = "False" |
| 64 | /> |
| 65 | <Reference |
| 66 | Platform = "Pocket PC" |
| 67 | Name = "System" |
| 68 | AssemblyName = "System" |
| 69 | Private = "False" |
| 70 | /> |
| 71 | <Reference |
| 72 | Platform = "Pocket PC" |
| 73 | Name = "System.XML" |
| 74 | AssemblyName = "System.Xml" |
| 75 | Private = "False" |
| 76 | /> |
| 77 | <Reference |
| 78 | Platform = "Pocket PC" |
| 79 | Name = "System.Data" |
| 80 | AssemblyName = "System.Data" |
| 81 | Private = "False" |
| 82 | /> |
| 83 | <Reference |
| 84 | Platform = "Pocket PC" |
| 85 | Name = "RemObjects.DebugServer" |
| 86 | AssemblyName = "RemObjects.DebugServer" |
| 87 | /> |
| 88 | <Reference |
| 89 | Platform = "Pocket PC-Designer" |
| 90 | Name = "System.CF.Design" |
| 91 | AssemblyName = "System.CF.Design" |
| 92 | Private = "False" |
| 93 | /> |
| 94 | <Reference |
| 95 | Platform = "Pocket PC-Designer" |
| 96 | Name = "System.CF.Design.UI" |
| 97 | AssemblyName = "System.CF.Design.UI" |
| 98 | Private = "False" |
| 99 | /> |
| 100 | <Reference |
| 101 | Platform = "Pocket PC-Designer" |
| 102 | Name = "System.CF.Windows.Forms" |
| 103 | AssemblyName = "System.CF.Windows.Forms" |
| 104 | Private = "False" |
| 105 | /> |
| 106 | <Reference |
| 107 | Platform = "Pocket PC-Designer" |
| 108 | Name = "System.CF.Drawing" |
| 109 | AssemblyName = "System.CF.Drawing" |
| 110 | Private = "False" |
| 111 | /> |
| 112 | <Reference |
| 113 | Platform = "Pocket PC-Designer" |
| 114 | Name = "System" |
| 115 | AssemblyName = "System" |
| 116 | Private = "False" |
| 117 | /> |
| 118 | </References> |
| 119 | </Build> |
| 120 | <Files> |
| 121 | <Include> |
| 122 | <File |
| 123 | RelPath = "AssemblyInfo.cs" |
| 124 | SubType = "Code" |
| 125 | BuildAction = "Compile" |
| 126 | /> |
| 127 | <File |
| 128 | RelPath = "AsyncServer.cs" |
| 129 | SubType = "Code" |
| 130 | BuildAction = "Compile" |
| 131 | /> |
| 132 | <File |
| 133 | RelPath = "Bindings.cs" |
| 134 | SubType = "Code" |
| 135 | BuildAction = "Compile" |
| 136 | /> |
| 137 | <File |
| 138 | RelPath = "BoundIncomingStream.cs" |
| 139 | SubType = "Code" |
| 140 | BuildAction = "Compile" |
| 141 | /> |
| 142 | <File |
| 143 | RelPath = "CFCompatibility.cs" |
| 144 | SubType = "Code" |
| 145 | BuildAction = "Compile" |
| 146 | /> |
| 147 | <File |
| 148 | RelPath = "Client.cs" |
| 149 | SubType = "Code" |
| 150 | BuildAction = "Compile" |
| 151 | /> |
| 152 | <File |
| 153 | RelPath = "CommandBasedClient.cs" |
| 154 | SubType = "Code" |
| 155 | BuildAction = "Compile" |
| 156 | /> |
| 157 | <File |
| 158 | RelPath = "CommandBasedServer.cs" |
| 159 | SubType = "Code" |
| 160 | BuildAction = "Compile" |
| 161 | /> |
| 162 | <File |
| 163 | RelPath = "Connection.cs" |
| 164 | SubType = "Code" |
| 165 | BuildAction = "Compile" |
| 166 | /> |
| 167 | <File |
| 168 | RelPath = "ConnectionPool.cs" |
| 169 | SubType = "Code" |
| 170 | BuildAction = "Compile" |
| 171 | /> |
| 172 | <File |
| 173 | RelPath = "Debug.cs" |
| 174 | SubType = "Code" |
| 175 | BuildAction = "Compile" |
| 176 | /> |
| 177 | <File |
| 178 | RelPath = "Dns.cs" |
| 179 | SubType = "Code" |
| 180 | BuildAction = "Compile" |
| 181 | /> |
| 182 | <File |
| 183 | RelPath = "EchoServer.cs" |
| 184 | SubType = "Code" |
| 185 | BuildAction = "Compile" |
| 186 | /> |
| 187 | <File |
| 188 | RelPath = "Events.cs" |
| 189 | SubType = "Code" |
| 190 | BuildAction = "Compile" |
| 191 | /> |
| 192 | <File |
| 193 | RelPath = "FtpClient.cs" |
| 194 | SubType = "Code" |
| 195 | BuildAction = "Compile" |
| 196 | /> |
| 197 | <File |
| 198 | RelPath = "FtpListing.cs" |
| 199 | SubType = "Code" |
| 200 | BuildAction = "Compile" |
| 201 | /> |
| 202 | <File |
| 203 | RelPath = "FtpServer.cs" |
| 204 | SubType = "Code" |
| 205 | BuildAction = "Compile" |
| 206 | /> |
| 207 | <File |
| 208 | RelPath = "HttpClient.cs" |
| 209 | SubType = "Code" |
| 210 | BuildAction = "Compile" |
| 211 | /> |
| 212 | <File |
| 213 | RelPath = "HttpHeader.cs" |
| 214 | SubType = "Code" |
| 215 | BuildAction = "Compile" |
| 216 | /> |
| 217 | <File |
| 218 | RelPath = "HttpRequestResponse.cs" |
| 219 | SubType = "Code" |
| 220 | BuildAction = "Compile" |
| 221 | /> |
| 222 | <File |
| 223 | RelPath = "HttpServer.cs" |
| 224 | SubType = "Code" |
| 225 | BuildAction = "Compile" |
| 226 | /> |
| 227 | <File |
| 228 | RelPath = "Interfaces.cs" |
| 229 | SubType = "Code" |
| 230 | BuildAction = "Compile" |
| 231 | /> |
| 232 | <File |
| 233 | RelPath = "Message.cs" |
| 234 | SubType = "Code" |
| 235 | BuildAction = "Compile" |
| 236 | /> |
| 237 | <File |
| 238 | RelPath = "MessageAddress.cs" |
| 239 | SubType = "Code" |
| 240 | BuildAction = "Compile" |
| 241 | /> |
| 242 | <File |
| 243 | RelPath = "MessageAttachment.cs" |
| 244 | SubType = "Code" |
| 245 | BuildAction = "Compile" |
| 246 | /> |
| 247 | <File |
| 248 | RelPath = "MessageEncoder.cs" |
| 249 | SubType = "Code" |
| 250 | BuildAction = "Compile" |
| 251 | /> |
| 252 | <File |
| 253 | RelPath = "MessageHeaderField.cs" |
| 254 | SubType = "Code" |
| 255 | BuildAction = "Compile" |
| 256 | /> |
| 257 | <File |
| 258 | RelPath = "Pop3Client.cs" |
| 259 | SubType = "Code" |
| 260 | BuildAction = "Compile" |
| 261 | /> |
| 262 | <File |
| 263 | RelPath = "Server.cs" |
| 264 | SubType = "Code" |
| 265 | BuildAction = "Compile" |
| 266 | /> |
| 267 | <File |
| 268 | RelPath = "SimpleHttpServer.cs" |
| 269 | SubType = "Code" |
| 270 | BuildAction = "Compile" |
| 271 | /> |
| 272 | <File |
| 273 | RelPath = "SimpleServer.cs" |
| 274 | SubType = "Code" |
| 275 | BuildAction = "Compile" |
| 276 | /> |
| 277 | <File |
| 278 | RelPath = "SmtpClient.cs" |
| 279 | SubType = "Code" |
| 280 | BuildAction = "Compile" |
| 281 | /> |
| 282 | <File |
| 283 | RelPath = "TcpClient.cs" |
| 284 | SubType = "Code" |
| 285 | BuildAction = "Compile" |
| 286 | /> |
| 287 | <File |
| 288 | RelPath = "TcpServer.cs" |
| 289 | SubType = "Code" |
| 290 | BuildAction = "Compile" |
| 291 | /> |
| 292 | <File |
| 293 | RelPath = "UrlParser.cs" |
| 294 | SubType = "Code" |
| 295 | BuildAction = "Compile" |
| 296 | /> |
| 297 | <File |
| 298 | RelPath = "Worker.cs" |
| 299 | SubType = "Code" |
| 300 | BuildAction = "Compile" |
| 301 | /> |
| 302 | <File |
| 303 | RelPath = "WorkerCollection.cs" |
| 304 | SubType = "Code" |
| 305 | BuildAction = "Compile" |
| 306 | /> |
| 307 | </Include> |
| 308 | </Files> |
| 309 | </ECSHARP> |
| 310 | </VisualStudioProject> |
| 311 | |
| Source/RemObjects.InternetPack/RemObjects.InternetPack.2003.csproj |
| 1 | <VisualStudioProject> |
| 2 | <CSHARP |
| 3 | ProjectType = "Local" |
| 4 | ProductVersion = "7.10.3077" |
| 5 | SchemaVersion = "2.0" |
| 6 | ProjectGuid = "{7C02E26A-2522-4C8F-8CAC-4E65854A09DE}" |
| 7 | SccProjectName = "\\Internet Pack for .NET\Source\RemObjects.InternetPack" |
| 8 | SccLocalPath = "." |
| 9 | SccProvider = "MSSCCI:TeamCoherence" |
| 10 | > |
| 11 | <Build> |
| 12 | <Settings |
| 13 | ApplicationIcon = "" |
| 14 | AssemblyKeyContainerName = "" |
| 15 | AssemblyName = "RemObjects.InternetPack" |
| 16 | AssemblyOriginatorKeyFile = "" |
| 17 | DefaultClientScript = "JScript" |
| 18 | DefaultHTMLPageLayout = "Grid" |
| 19 | DefaultTargetSchema = "IE50" |
| 20 | DelaySign = "false" |
| 21 | OutputType = "Library" |
| 22 | PreBuildEvent = "" |
| 23 | PostBuildEvent = "" |
| 24 | RootNamespace = "RemObjects.InternetPack" |
| 25 | RunPostBuildEvent = "OnBuildSuccess" |
| 26 | StartupObject = "" |
| 27 | > |
| 28 | <Config |
| 29 | Name = "Debug" |
| 30 | AllowUnsafeBlocks = "false" |
| 31 | BaseAddress = "285212672" |
| 32 | CheckForOverflowUnderflow = "false" |
| 33 | ConfigurationOverrideFile = "" |
| 34 | DefineConstants = "DEBUG;TRACE;DEBUGSERVER;FULLFRAMEWORK;REMOBJECTS_SIGN_ASSEMBLY;DESIGN" |
| 35 | DocumentationFile = "" |
| 36 | DebugSymbols = "true" |
| 37 | FileAlignment = "4096" |
| 38 | IncrementalBuild = "false" |
| 39 | NoStdLib = "false" |
| 40 | NoWarn = "" |
| 41 | Optimize = "false" |
| 42 | OutputPath = "bin\debug\" |
| 43 | RegisterForComInterop = "false" |
| 44 | RemoveIntegerChecks = "false" |
| 45 | TreatWarningsAsErrors = "false" |
| 46 | WarningLevel = "4" |
| 47 | /> |
| 48 | <Config |
| 49 | Name = "Release" |
| 50 | AllowUnsafeBlocks = "false" |
| 51 | BaseAddress = "285212672" |
| 52 | CheckForOverflowUnderflow = "false" |
| 53 | ConfigurationOverrideFile = "" |
| 54 | DefineConstants = "FULLFRAMEWORK;REMOBJECTS_SIGN_ASSEMBLY;DESIGN" |
| 55 | DocumentationFile = "" |
| 56 | DebugSymbols = "true" |
| 57 | FileAlignment = "4096" |
| 58 | IncrementalBuild = "false" |
| 59 | NoStdLib = "false" |
| 60 | NoWarn = "" |
| 61 | Optimize = "true" |
| 62 | OutputPath = "..\..\Bin\" |
| 63 | RegisterForComInterop = "false" |
| 64 | RemoveIntegerChecks = "false" |
| 65 | TreatWarningsAsErrors = "false" |
| 66 | WarningLevel = "4" |
| 67 | /> |
| 68 | <Config |
| 69 | Name = "TRIAL" |
| 70 | AllowUnsafeBlocks = "false" |
| 71 | BaseAddress = "285212672" |
| 72 | CheckForOverflowUnderflow = "false" |
| 73 | ConfigurationOverrideFile = "" |
| 74 | DefineConstants = "FULLFRAMEWORK;REMOBJECTS_SIGN_ASSEMBLY;TRIAL" |
| 75 | DocumentationFile = "" |
| 76 | DebugSymbols = "false" |
| 77 | FileAlignment = "4096" |
| 78 | IncrementalBuild = "false" |
| 79 | NoStdLib = "false" |
| 80 | NoWarn = "" |
| 81 | Optimize = "true" |
| 82 | OutputPath = "..\..\Bin\Trial\" |
| 83 | RegisterForComInterop = "false" |
| 84 | RemoveIntegerChecks = "false" |
| 85 | TreatWarningsAsErrors = "false" |
| 86 | WarningLevel = "4" |
| 87 | /> |
| 88 | <Config |
| 89 | Name = "Mono" |
| 90 | AllowUnsafeBlocks = "false" |
| 91 | BaseAddress = "285212672" |
| 92 | CheckForOverflowUnderflow = "false" |
| 93 | ConfigurationOverrideFile = "" |
| 94 | DefineConstants = "FULLFRAMEWORK;REMOBJECTS_SIGN_ASSEMBLY;MONO" |
| 95 | DocumentationFile = "" |
| 96 | DebugSymbols = "false" |
| 97 | FileAlignment = "4096" |
| 98 | IncrementalBuild = "false" |
| 99 | NoStdLib = "false" |
| 100 | NoWarn = "" |
| 101 | Optimize = "true" |
| 102 | OutputPath = "..\..\Bin\Mono\" |
| 103 | RegisterForComInterop = "false" |
| 104 | RemoveIntegerChecks = "false" |
| 105 | TreatWarningsAsErrors = "false" |
| 106 | WarningLevel = "4" |
| 107 | /> |
| 108 | <Config |
| 109 | Name = "Mono TRIAL" |
| 110 | AllowUnsafeBlocks = "false" |
| 111 | BaseAddress = "285212672" |
| 112 | CheckForOverflowUnderflow = "false" |
| 113 | ConfigurationOverrideFile = "" |
| 114 | DefineConstants = "FULLFRAMEWORK;REMOBJECTS_SIGN_ASSEMBLY;TRIAL;MONO" |
| 115 | DocumentationFile = "" |
| 116 | DebugSymbols = "false" |
| 117 | FileAlignment = "4096" |
| 118 | IncrementalBuild = "false" |
| 119 | NoStdLib = "false" |
| 120 | NoWarn = "" |
| 121 | Optimize = "true" |
| 122 | OutputPath = "..\..\Bin\Trial\Mono\" |
| 123 | RegisterForComInterop = "false" |
| 124 | RemoveIntegerChecks = "false" |
| 125 | TreatWarningsAsErrors = "false" |
| 126 | WarningLevel = "4" |
| 127 | /> |
| 128 | </Settings> |
| 129 | <References> |
| 130 | <Reference |
| 131 | Name = "System" |
| 132 | AssemblyName = "System" |
| 133 | HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" |
| 134 | /> |
| 135 | <Reference |
| 136 | Name = "System.Data" |
| 137 | AssemblyName = "System.Data" |
| 138 | HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" |
| 139 | /> |
| 140 | <Reference |
| 141 | Name = "System.XML" |
| 142 | AssemblyName = "System.Xml" |
| 143 | HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" |
| 144 | /> |
| 145 | <Reference |
| 146 | Name = "System.Drawing" |
| 147 | AssemblyName = "System.Drawing" |
| 148 | HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll" |
| 149 | /> |
| 150 | <Reference |
| 151 | Name = "RemObjects.DebugServer" |
| 152 | AssemblyName = "RemObjects.DebugServer" |
| 153 | HintPath = "..\..\Bin\RemObjects.DebugServer.dll" |
| 154 | /> |
| 155 | </References> |
| 156 | </Build> |
| 157 | <Files> |
| 158 | <Include> |
| 159 | <File |
| 160 | RelPath = "AssemblyInfo.cs" |
| 161 | SubType = "Code" |
| 162 | BuildAction = "Compile" |
| 163 | /> |
| 164 | <File |
| 165 | RelPath = "AsyncServer.cs" |
| 166 | SubType = "Component" |
| 167 | BuildAction = "Compile" |
| 168 | /> |
| 169 | <File |
| 170 | RelPath = "Bindings.cs" |
| 171 | SubType = "Code" |
| 172 | BuildAction = "Compile" |
| 173 | /> |
| 174 | <File |
| 175 | RelPath = "BoundIncomingStream.cs" |
| 176 | SubType = "Code" |
| 177 | BuildAction = "Compile" |
| 178 | /> |
| 179 | <File |
| 180 | RelPath = "Client.cs" |
| 181 | SubType = "Component" |
| 182 | BuildAction = "Compile" |
| 183 | /> |
| 184 | <File |
| 185 | RelPath = "CommandBasedClient.cs" |
| 186 | SubType = "Component" |
| 187 | BuildAction = "Compile" |
| 188 | /> |
| 189 | <File |
| 190 | RelPath = "CommandBasedServer.cs" |
| 191 | SubType = "Component" |
| 192 | BuildAction = "Compile" |
| 193 | /> |
| 194 | <File |
| 195 | RelPath = "Connection.cs" |
| 196 | SubType = "Code" |
| 197 | BuildAction = "Compile" |
| 198 | /> |
| 199 | <File |
| 200 | RelPath = "ConnectionPool.cs" |
| 201 | SubType = "Code" |
| 202 | BuildAction = "Compile" |
| 203 | /> |
| 204 | <File |
| 205 | RelPath = "Debug.cs" |
| 206 | SubType = "Code" |
| 207 | BuildAction = "Compile" |
| 208 | /> |
| 209 | <File |
| 210 | RelPath = "Dns.cs" |
| 211 | SubType = "Code" |
| 212 | BuildAction = "Compile" |
| 213 | /> |
| 214 | <File |
| 215 | RelPath = "EchoServer.cs" |
| 216 | SubType = "Component" |
| 217 | BuildAction = "Compile" |
| 218 | /> |
| 219 | <File |
| 220 | RelPath = "Events.cs" |
| 221 | SubType = "Code" |
| 222 | BuildAction = "Compile" |
| 223 | /> |
| 224 | <File |
| 225 | RelPath = "FtpClient.cs" |
| 226 | SubType = "Component" |
| 227 | BuildAction = "Compile" |
| 228 | /> |
| 229 | <File |
| 230 | RelPath = "FtpListing.cs" |
| 231 | SubType = "Code" |
| 232 | BuildAction = "Compile" |
| 233 | /> |
| 234 | <File |
| 235 | RelPath = "FtpServer.cs" |
| 236 | SubType = "Component" |
| 237 | BuildAction = "Compile" |
| 238 | /> |
| 239 | <File |
| 240 | RelPath = "HttpClient.cs" |
| 241 | SubType = "Component" |
| 242 | BuildAction = "Compile" |
| 243 | /> |
| 244 | <File |
| 245 | RelPath = "HttpHeader.cs" |
| 246 | SubType = "Code" |
| 247 | BuildAction = "Compile" |
| 248 | /> |
| 249 | <File |
| 250 | RelPath = "HttpRequestResponse.cs" |
| 251 | SubType = "Code" |
| 252 | BuildAction = "Compile" |
| 253 | /> |
| 254 | <File |
| 255 | RelPath = "HttpServer.cs" |
| 256 | SubType = "Component" |
| 257 | BuildAction = "Compile" |
| 258 | /> |
| 259 | <File |
| 260 | RelPath = "Interfaces.cs" |
| 261 | SubType = "Code" |
| 262 | BuildAction = "Compile" |
| 263 | /> |
| 264 | <File |
| 265 | RelPath = "Message.cs" |
| 266 | SubType = "Code" |
| 267 | BuildAction = "Compile" |
| 268 | /> |
| 269 | <File |
| 270 | RelPath = "MessageAddress.cs" |
| 271 | SubType = "Code" |
| 272 | BuildAction = "Compile" |
| 273 | /> |
| 274 | <File |
| 275 | RelPath = "MessageAttachment.cs" |
| 276 | SubType = "Code" |
| 277 | BuildAction = "Compile" |
| 278 | /> |
| 279 | <File |
| 280 | RelPath = "MessageEncoder.cs" |
| 281 | SubType = "Code" |
| 282 | BuildAction = "Compile" |
| 283 | /> |
| 284 | <File |
| 285 | RelPath = "MessageHeaderField.cs" |
| 286 | SubType = "Code" |
| 287 | BuildAction = "Compile" |
| 288 | /> |
| 289 | <File |
| 290 | RelPath = "Pop3Client.cs" |
| 291 | SubType = "Component" |
| 292 | BuildAction = "Compile" |
| 293 | /> |
| 294 | <File |
| 295 | RelPath = "Server.cs" |
| 296 | SubType = "Component" |
| 297 | BuildAction = "Compile" |
| 298 | /> |
| 299 | <File |
| 300 | RelPath = "SimpleHttpServer.cs" |
| 301 | SubType = "Component" |
| 302 | BuildAction = "Compile" |
| 303 | /> |
| 304 | <File |
| 305 | RelPath = "SimpleServer.cs" |
| 306 | SubType = "Code" |
| 307 | BuildAction = "Compile" |
| 308 | /> |
| 309 | <File |
| 310 | RelPath = "SmtpClient.cs" |
| 311 | SubType = "Component" |
| 312 | BuildAction = "Compile" |
| 313 | /> |
| 314 | <File |
| 315 | RelPath = "TcpClient.cs" |
| 316 | SubType = "Component" |
| 317 | BuildAction = "Compile" |
| 318 | /> |
| 319 | <File |
| 320 | RelPath = "TcpServer.cs" |
| 321 | SubType = "Component" |
| 322 | BuildAction = "Compile" |
| 323 | /> |
| 324 | <File |
| 325 | RelPath = "UrlParser.cs" |
| 326 | SubType = "Code" |
| 327 | BuildAction = "Compile" |
| 328 | /> |
| 329 | <File |
| 330 | RelPath = "Worker.cs" |
| 331 | SubType = "Code" |
| 332 | BuildAction = "Compile" |
| 333 | /> |
| 334 | <File |
| 335 | RelPath = "WorkerCollection.cs" |
| 336 | SubType = "Code" |
| 337 | BuildAction = "Compile" |
| 338 | /> |
| 339 | <File |
| 340 | RelPath = "Glyphs\EchoServer.bmp" |
| 341 | BuildAction = "EmbeddedResource" |
| 342 | /> |
| 343 | <File |
| 344 | RelPath = "Glyphs\FtpClient.bmp" |
| 345 | BuildAction = "EmbeddedResource" |
| 346 | /> |
| 347 | <File |
| 348 | RelPath = "Glyphs\FtpServer.bmp" |
| 349 | BuildAction = "EmbeddedResource" |
| 350 | /> |
| 351 | <File |
| 352 | RelPath = "Glyphs\HttpClient.bmp" |
| 353 | BuildAction = "EmbeddedResource" |
| 354 | /> |
| 355 | <File |
| 356 | RelPath = "Glyphs\HttpServer.bmp" |
| 357 | BuildAction = "EmbeddedResource" |
| 358 | /> |
| 359 | <File |
| 360 | RelPath = "Glyphs\SimpleHttpServer.bmp" |
| 361 | BuildAction = "EmbeddedResource" |
| 362 | /> |
| 363 | <File |
| 364 | RelPath = "Glyphs\SmtpClient.bmp" |
| 365 | BuildAction = "EmbeddedResource" |
| 366 | /> |
| 367 | <File |
| 368 | RelPath = "Glyphs\TcpClient.bmp" |
| 369 | BuildAction = "EmbeddedResource" |
| 370 | /> |
| 371 | <File |
| 372 | RelPath = "Glyphs\TcpServer.bmp" |
| 373 | BuildAction = "EmbeddedResource" |
| 374 | /> |
| 375 | </Include> |
| 376 | </Files> |
| 377 | </CSHARP> |
| 378 | </VisualStudioProject> |
| 379 | |
| Source/RemObjects.InternetPack/SslConnection.cs |
| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.IO; |
| 4 | using System.Reflection; |
| 5 | using System.Text; |
| 6 | using System.Net.Sockets; |
| 7 | using System.Security; |
| 8 | using System.Net.Security; |
| 9 | using System.ComponentModel; |
| 10 | using System.Security.Cryptography; |
| 11 | using System.Security.Cryptography.X509Certificates; |
| 12 | |
| 13 | namespace RemObjects.InternetPack |
| 14 | { |
| 15 | public class SslValidateCertificateArgs : EventArgs |
| 16 | { |
| 17 | public SslValidateCertificateArgs(X509Certificate cert) |
| 18 | { |
| 19 | fCertificate = cert; |
| 20 | } |
| 21 | |
| 22 | private X509Certificate fCertificate; |
| 23 | public X509Certificate Certificate { get { return fCertificate; } } |
| 24 | |
| 25 | private bool fCancel; |
| 26 | public bool Cancel { get { return fCancel; } set { fCancel = value; } } |
| 27 | } |
| 28 | |
| 29 | public class SslNeedPasswordArgs : EventArgs |
| 30 | { |
| 31 | public SslNeedPasswordArgs() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | private SecureString fPassword; |
| 36 | public SecureString Password { get { return fPassword; } set { fPassword = value; } } |
| 37 | |
| 38 | public string PasswordString |
| 39 | { |
| 40 | get { return null; } |
| 41 | set |
| 42 | { |
| 43 | if (value == null) |
| 44 | { |
| 45 | fPassword = null; |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | fPassword = new SecureString(); |
| 50 | for (int i = 0; i < value.Length; i++) |
| 51 | fPassword.AppendChar(value[i]); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public class SslConnectionFactory: IConnectionFactory |
| 58 | { |
| 59 | private string fTargetHostName; |
| 60 | [DefaultValue(""), Category("Ssl Options")] |
| 61 | public string TargetHostName { get { return fTargetHostName; } set { fTargetHostName = value; } } |
| 62 | |
| 63 | private bool fUseMono; |
| 64 | [DefaultValue(false), Category("Ssl Options")] |
| 65 | public bool UseMono { get { return fUseMono; } set { fUseMono = value; } } |
| 66 | |
| 67 | private bool fEnabled; |
| 68 | [DefaultValue(false), Category("Ssl Options")] |
| 69 | public bool Enabled { get { return fEnabled; } set { fEnabled = value; } } |
| 70 | |
| 71 | private string fCertificateFileName; |
| 72 | [DefaultValue(null), Category("Ssl Options")] |
| 73 | public string CertificateFileName { get { return fCertificateFileName; } set { fCertificateFileName = value; } } |
| 74 | |
| 75 | [Category("Ssl Options")] |
| 76 | public event EventHandler<SslNeedPasswordArgs> NeedPassword; |
| 77 | |
| 78 | private X509Certificate2 fCertificate; |
| 79 | [Browsable(false)] |
| 80 | public X509Certificate2 Certificate { get { return fCertificate; } set { fCertificate = value; } } |
| 81 | |
| 82 | [Browsable(false)] |
| 83 | public bool HasCertificate |
| 84 | { |
| 85 | get |
| 86 | { |
| 87 | return fCertificate != null || !String.IsNullOrEmpty(fCertificateFileName); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | private void LoadCertificate() |
| 92 | { |
| 93 | lock (this) |
| 94 | { |
| 95 | if (fCertificate != null) return; |
| 96 | if (String.IsNullOrEmpty(fCertificateFileName)) |
| 97 | { |
| 98 | throw new Exception("Certificate not set and CertificateFileName is empty"); |
| 99 | } |
| 100 | SslNeedPasswordArgs lArgs = new SslNeedPasswordArgs(); |
| 101 | if (NeedPassword != null) NeedPassword(this, lArgs); |
| 102 | fCertificate = new X509Certificate2(fCertificateFileName, lArgs.Password, X509KeyStorageFlags.Exportable); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | internal Assembly fMonoAssembly; |
| 107 | internal Assembly GetMonoAssembly() |
| 108 | { |
| 109 | if (!fUseMono) return null; |
| 110 | |
| 111 | if (fMonoAssembly != null) return fMonoAssembly; |
| 112 | try |
| 113 | { |
| 114 | fMonoAssembly = Assembly.Load("Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); |
| 115 | } |
| 116 | catch |
| 117 | { |
| 118 | fUseMono = false; |
| 119 | } |
| 120 | return fMonoAssembly; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | [Category("Ssl Options")] |
| 125 | public event EventHandler<SslValidateCertificateArgs> ValidateRemoteCertificate; |
| 126 | |
| 127 | protected internal bool OnValidateRemoteCertificate(X509Certificate cert) |
| 128 | { |
| 129 | if (ValidateRemoteCertificate != null) |
| 130 | { |
| 131 | SslValidateCertificateArgs lArgs = new SslValidateCertificateArgs(cert); |
| 132 | ValidateRemoteCertificate(this, lArgs); |
| 133 | return !lArgs.Cancel; |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | #region IConnectionFactory Members |
| 139 | |
| 140 | public Connection CreateServerConnection(Socket aSocket) |
| 141 | { |
| 142 | if (!fEnabled) |
| 143 | { |
| 144 | return new Connection(aSocket); |
| 145 | } |
| 146 | if (fCertificate == null) LoadCertificate(); |
| 147 | return new SslConnection(this, aSocket); |
| 148 | } |
| 149 | |
| 150 | public Connection CreateClientConnection(Binding aBinding) |
| 151 | { |
| 152 | if (!fEnabled) |
| 153 | { |
| 154 | return new Connection(aBinding); |
| 155 | } |
| 156 | if (HasCertificate) LoadCertificate(); |
| 157 | return new SslConnection(this, aBinding); |
| 158 | } |
| 159 | |
| 160 | #endregion |
| 161 | } |
| 162 | public class SslConnection : Connection |
| 163 | { |
| 164 | protected internal class InnerConnection : Connection |
| 165 | { |
| 166 | public InnerConnection(Socket s) : base(s) { } |
| 167 | public InnerConnection(Binding b) : base(b) { } |
| 168 | |
| 169 | |
| 170 | public Socket IntDataSocket { get { return base.DataSocket; } } |
| 171 | public int IntDataSocketAvailable { get { return base.DataSocketAvailable; } } |
| 172 | |
| 173 | public override int Read(byte[] aBuffer, int aOffset, int aCount) |
| 174 | { |
| 175 | |
| 176 | return base.ReceiveWhatsAvailable(aBuffer, aOffset, aCount); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | private SslConnectionFactory fFactory; |
| 181 | private InnerConnection fInnerConnection; |
| 182 | private Stream fSsl; |
| 183 | |
| 184 | public SslConnection(SslConnectionFactory aFactory, Binding aBinding) |
| 185 | : base((Socket)null) |
| 186 | { |
| 187 | fFactory = aFactory; |
| 188 | fInnerConnection = new InnerConnection(aBinding); |
| 189 | fInnerConnection.BufferedAsync = false; |
| 190 | fInnerConnection.AsyncDisconnect += new EventHandler(InnerConnection_AsyncDisconnect); |
| 191 | fInnerConnection.AsyncHaveIncompleteData += new EventHandler(InnerConnection_AsyncHaveIncompleteData); |
| 192 | } |
| 193 | |
| 194 | public SslConnection(SslConnectionFactory aFactory, Socket aSocket) |
| 195 | : base((Socket)null) |
| 196 | { |
| 197 | fFactory = aFactory; |
| 198 | fInnerConnection = new InnerConnection(aSocket); |
| 199 | fInnerConnection.BufferedAsync = false; |
| 200 | fInnerConnection.AsyncDisconnect += new EventHandler(InnerConnection_AsyncDisconnect); |
| 201 | fInnerConnection.AsyncHaveIncompleteData += new EventHandler(InnerConnection_AsyncHaveIncompleteData); |
| 202 | } |
| 203 | |
| 204 | protected override int DataSocketAvailable |
| 205 | { |
| 206 | get |
| 207 | { |
| 208 | return fInnerConnection.IntDataSocketAvailable; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | public override Socket DataSocket |
| 213 | { |
| 214 | get |
| 215 | { |
| 216 | return fInnerConnection.DataSocket; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | public override bool DataSocketConnected |
| 221 | { |
| 222 | get |
| 223 | { |
| 224 | return fInnerConnection.Connected; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | public override bool EnableNagle |
| 229 | { |
| 230 | get |
| 231 | { |
| 232 | return fInnerConnection.EnableNagle; |
| 233 | } |
| 234 | set |
| 235 | { |
| 236 | fInnerConnection.EnableNagle = value; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | bool Ssl_RemoteCertificateValidation(object sender, X509Certificate aCertificate, X509Chain aChain, SslPolicyErrors aErrors) |
| 241 | { |
| 242 | return fFactory.OnValidateRemoteCertificate(aCertificate); |
| 243 | } |
| 244 | |
| 245 | AsymmetricAlgorithm MonoSsl_GetPrivateKey(X509Certificate aCert, string aTargetHost) |
| 246 | { |
| 247 | return fFactory.Certificate.PrivateKey; |
| 248 | } |
| 249 | |
| 250 | bool MonoSsl_RemoteCertificateValidation(X509Certificate aCert, int[] aErrors) |
| 251 | { |
| 252 | return fFactory.OnValidateRemoteCertificate(aCert); |
| 253 | } |
| 254 | |
| 255 | private void CreateMonoServerStream() |
| 256 | { |
| 257 | Type lType = fFactory.GetMonoAssembly().GetType("Mono.Security.Protocol.Tls.SslServerStream", true); |
| 258 | fSsl = (Stream)Activator.CreateInstance(lType, fInnerConnection, fFactory.Certificate, false, false); |
| 259 | |
| 260 | object o = Delegate.CreateDelegate(fFactory.GetMonoAssembly().GetType("Mono.Security.Protocol.Tls.PrivateKeySelectionCallback", true), this, "MonoSsl_GetPrivateKey", false, true); |
| 261 | lType.InvokeMember("set_PrivateKeyCertSelectionDelegate", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, fSsl, new object[] { o }); |
| 262 | |
| 263 | o = Delegate.CreateDelegate(fFactory.GetMonoAssembly().GetType("Mono.Security.Protocol.Tls.CertificateValidationCallback", true), this, "MonoSsl_RemoteCertificateValidation", false, true); |
| 264 | lType.InvokeMember("set_ClientCertValidationDelegate", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, fSsl, new object[] { o }); |
| 265 | } |
| 266 | |
| 267 | protected internal override void InitializeServerConnection() |
| 268 | { |
| 269 | if (fFactory.GetMonoAssembly() != null) |
| 270 | { |
| 271 | CreateMonoServerStream(); |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | fSsl = new SslStream(fInnerConnection, true, new RemoteCertificateValidationCallback(Ssl_RemoteCertificateValidation)); |
| 276 | ((SslStream)fSsl).AuthenticateAsServer(fFactory.Certificate); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | protected internal override IAsyncResult BeginInitializeServerConnection(AsyncCallback cb, object o) |
| 281 | { |
| 282 | if (fFactory.UseMono) |
| 283 | { |
| 284 | CreateMonoServerStream(); |
| 285 | return null; |
| 286 | } |
| 287 | else |
| 288 | { |
| 289 | fSsl = new SslStream(fInnerConnection, true, new RemoteCertificateValidationCallback(Ssl_RemoteCertificateValidation)); |
| 290 | return ((SslStream)fSsl).BeginAuthenticateAsServer(fFactory.Certificate, cb, o); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | protected internal override void EndInitializeServerConnection(IAsyncResult ar) |
| 295 | { |
| 296 | if (!fFactory.UseMono) |
| 297 | { |
| 298 | ((SslStream)fSsl).EndAuthenticateAsServer(ar); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | private void CreateMonoClientStream() |
| 303 | { |
| 304 | Type lType = fFactory.GetMonoAssembly().GetType("Mono.Security.Protocol.Tls.SslClientStream", true); |
| 305 | fSsl = (Stream)Activator.CreateInstance(lType, fInnerConnection, fFactory.TargetHostName, false); |
| 306 | |
| 307 | object o = Delegate.CreateDelegate(fFactory.GetMonoAssembly().GetType("Mono.Security.Protocol.Tls.PrivateKeySelectionCallback", true), this, "MonoSsl_GetPrivateKey", false, true); |
| 308 | lType.InvokeMember("set_PrivateKeyCertSelectionDelegate", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, fSsl, new object[] { o }); |
| 309 | |
| 310 | o = Delegate.CreateDelegate(fFactory.GetMonoAssembly().GetType("Mono.Security.Protocol.Tls.CertificateValidationCallback", true), this, "MonoSsl_RemoteCertificateValidation", false, true); |
| 311 | lType.InvokeMember("set_ServerCertValidationDelegate", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, fSsl, new object[] { o }); |
| 312 | } |
| 313 | |
| 314 | public override void Connect(System.Net.EndPoint aEndPoint) |
| 315 | { |
| 316 | fInnerConnection.Connect(aEndPoint); |
| 317 | if (fFactory.GetMonoAssembly() != null) |
| 318 | { |
| 319 | CreateMonoClientStream(); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | fSsl = new SslStream(fInnerConnection, true, new RemoteCertificateValidationCallback(Ssl_RemoteCertificateValidation)); |
| 324 | ((SslStream)fSsl).AuthenticateAsClient(fFactory.TargetHostName); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | public override void Connect(System.Net.IPAddress aIPAddress, int aPort) |
| 329 | { |
| 330 | Connect(new System.Net.IPEndPoint(aIPAddress, aPort)); |
| 331 | } |
| 332 | |
| 333 | private class ConnectWrapper : IAsyncResult |
| 334 | { |
| 335 | public ConnectWrapper(AsyncCallback aCallback, object aState) |
| 336 | { |
| 337 | fAsyncState = aState; |
| 338 | fCallback = aCallback; |
| 339 | } |
| 340 | private AsyncCallback fCallback; |
| 341 | private object fAsyncState; |
| 342 | private volatile System.Threading.ManualResetEvent fWaitHandle; |
| 343 | private volatile bool fComplete; |
| 344 | public object AsyncState |
| 345 | { |
| 346 | get { return fAsyncState; } |
| 347 | } |
| 348 | |
| 349 | public System.Threading.WaitHandle AsyncWaitHandle |
| 350 | { |
| 351 | get |
| 352 | { |
| 353 | if (fWaitHandle != null) return fWaitHandle; |
| 354 | lock (this) |
| 355 | { |
| 356 | if (fWaitHandle == null) |
| 357 | { |
| 358 | fWaitHandle = new System.Threading.ManualResetEvent(fComplete); |
| 359 | } |
| 360 | } |
| 361 | return fWaitHandle; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | public bool CompletedSynchronously |
| 366 | { |
| 367 | get { return false; } |
| 368 | } |
| 369 | |
| 370 | public bool IsCompleted |
| 371 | { |
| 372 | get { return fComplete; } |
| 373 | } |
| 374 | |
| 375 | public void Dispose() |
| 376 | { |
| 377 | if (fWaitHandle != null) fWaitHandle.Close(); |
| 378 | fWaitHandle = null; |
| 379 | } |
| 380 | public void ConnectionConnect(IAsyncResult ar) |
| 381 | { |
| 382 | SslConnection lOwner = (SslConnection)ar.AsyncState; |
| 383 | try |
| 384 | { |
| 385 | lOwner.fInnerConnection.EndConnect(ar); |
| 386 | } |
| 387 | catch (Exception ex) |
| 388 | { |
| 389 | fFailure = ex; |
| 390 | fComplete = true; |
| 391 | lock (this) |
| 392 | { |
| 393 | if (fWaitHandle != null) |
| 394 | fWaitHandle.Set(); |
| 395 | } |
| 396 | fCallback(ar); |
| 397 | return; |
| 398 | } |
| 399 | if (lOwner.fFactory.GetMonoAssembly() != null) |
| 400 | { |
| 401 | lOwner.CreateMonoClientStream(); |
| 402 | fComplete = true; |
| 403 | lock (this) |
| 404 | { |
| 405 | if (fWaitHandle != null) |
| 406 | fWaitHandle.Set(); |
| 407 | } |
| 408 | fCallback(ar); |
| 409 | return; |
| 410 | } |
| 411 | else |
| 412 | { |
| 413 | lOwner.fSsl = new SslStream(lOwner.fInnerConnection, true, new RemoteCertificateValidationCallback(lOwner.Ssl_RemoteCertificateValidation)); |
| 414 | ((SslStream)lOwner.fSsl).BeginAuthenticateAsClient(lOwner.fFactory.TargetHostName, new AsyncCallback(SslAuthenticateAsClient), lOwner); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | private void SslAuthenticateAsClient(IAsyncResult ar) |
| 419 | { |
| 420 | SslConnection lOwner = (SslConnection)ar.AsyncState; |
| 421 | try |
| 422 | { |
| 423 | ((SslStream)lOwner.fSsl).EndAuthenticateAsClient(ar); |
| 424 | } |
| 425 | catch (Exception ex) |
| 426 | { |
| 427 | fFailure = ex; |
| 428 | fComplete = true; |
| 429 | lock (this) |
| 430 | { |
| 431 | if (fWaitHandle != null) |
| 432 | fWaitHandle.Set(); |
| 433 | } |
| 434 | fCallback(ar); |
| 435 | return; |
| 436 | } |
| 437 | lOwner.CreateMonoClientStream(); |
| 438 | fComplete = true; |
| 439 | lock (this) |
| 440 | { |
| 441 | if (fWaitHandle != null) |
| 442 | fWaitHandle.Set(); |
| 443 | } |
| 444 | fCallback(ar); |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | private Exception fFailure; |
| 449 | public void EndConnect() |
| 450 | { |
| 451 | if (!fComplete) |
| 452 | { |
| 453 | AsyncWaitHandle.WaitOne(); |
| 454 | } |
| 455 | Dispose(); |
| 456 | if (fFailure != null) |
| 457 | throw fFailure; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | public override IAsyncResult BeginConnect(System.Net.EndPoint aEndPoint, AsyncCallback callback, object state) |
| 462 | { |
| 463 | ConnectWrapper lWrapper = new ConnectWrapper(callback, state); |
| 464 | fInnerConnection.BeginConnect(aEndPoint, new AsyncCallback(lWrapper.ConnectionConnect), this); |
| 465 | return lWrapper; |
| 466 | } |
| 467 | |
| 468 | public override IAsyncResult BeginConnect(System.Net.IPAddress anIPAddress, int aPort, AsyncCallback callback, object state) |
| 469 | { |
| 470 | return BeginConnect(new System.Net.IPEndPoint(anIPAddress, aPort), callback, state); |
| 471 | } |
| 472 | |
| 473 | public override void EndConnect(IAsyncResult asyncResult) |
| 474 | { |
| 475 | ConnectWrapper wr = (ConnectWrapper)asyncResult; |
| 476 | wr.EndConnect(); |
| 477 | } |
| 478 | |
| 479 | protected override void DataSocketClose() |
| 480 | { |
| 481 | fInnerConnection.Close(); |
| 482 | } |
| 483 | |
| 484 | protected override void DataSocketClose(bool aDispose) |
| 485 | { |
| 486 | fInnerConnection.Close(aDispose); |
| 487 | } |
| 488 | |
| 489 | void InnerConnection_AsyncHaveIncompleteData(object sender, EventArgs e) |
| 490 | { |
| 491 | TriggerAsyncHaveIncompleteData(); |
| 492 | } |
| 493 | |
| 494 | void InnerConnection_AsyncDisconnect(object sender, EventArgs e) |
| 495 | { |
| 496 | TriggerAsyncDisconnect(); |
| 497 | } |
| 498 | |
| 499 | protected override int DataSocketReceiveWhatsAvaiable(byte[] aBuffer, int aOffset, int aSize) |
| 500 | { |
| 501 | try |
| 502 | { |
| 503 | return fSsl.Read(aBuffer, aOffset, aSize); |
| 504 | } |
| 505 | catch (IOException) { throw new SocketException(); } |
| 506 | } |
| 507 | |
| 508 | protected override int DataSocketSendAsMuchAsPossible(byte[] aBuffer, int aOffset, int aSize) |
| 509 | { |
| 510 | try |
| 511 | { |
| 512 | fSsl.Write(aBuffer, aOffset, aSize); |
| 513 | return aSize; |
| 514 | } |
| 515 | catch (IOException) |
| 516 | { |
| 517 | throw new SocketException(); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | protected override IAsyncResult IntBeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) |
| 522 | { |
| 523 | return fSsl.BeginRead(buffer, offset, count, callback, state); |
| 524 | } |
| 525 | protected override int IntEndRead(IAsyncResult ar) |
| 526 | { |
| 527 | try |
| 528 | { |
| 529 | return fSsl.EndRead(ar); |
| 530 | } |
| 531 | catch (IOException) |
| 532 | { |
| 533 | throw new SocketException(); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | protected override IAsyncResult IntBeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) |
| 538 | { |
| 539 | return fSsl.BeginWrite(buffer, offset, count, callback, state); |
| 540 | } |
| 541 | protected override void IntEndWrite(IAsyncResult asyncResult) |
| 542 | { |
| 543 | try |
| 544 | { |
| 545 | fSsl.EndWrite(asyncResult); |
| 546 | } |
| 547 | catch (IOException) |
| 548 | { |
| 549 | throw new SocketException(); // SocketException is expected in all code that deals with Connection, not IOException |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | } |
| Source/RemObjects.InternetPack/CommandBasedServer.cs |
| 10 | 10 | using System.Collections; |
| 11 | 11 | using System.Net; |
| 12 | 12 | using System.Net.Sockets; |
| 13 | | using RemObjects.DebugServer; |
| 14 | 13 | using RemObjects.InternetPack; |
| 15 | 14 | |
| 16 | 15 | namespace RemObjects.InternetPack.CommandBased |
| 17 | 16 | { |
| 18 | 17 | |
| 19 | | public class SessionEventArgs : EventArgs |
| 20 | | { |
| 18 | public class SessionEventArgs : EventArgs |
| 19 | { |
| 21 | 20 | |
| 22 | | private object fSession; |
| 23 | | public object Session { get {return fSession;} } |
| 21 | private object fSession; |
| 22 | public object Session { get { return fSession; } } |
| 24 | 23 | |
| 25 | | private Connection fConnection; |
| 26 | | public Connection Connection { get { return fConnection; }} |
| 24 | private Connection fConnection; |
| 25 | public Connection Connection { get { return fConnection; } } |
| 27 | 26 | |
| 28 | | private Server fServer; |
| 29 | | public Server Server { get { return fServer; }} |
| 27 | private Server fServer; |
| 28 | public Server Server { get { return fServer; } } |
| 30 | 29 | |
| 31 | | public SessionEventArgs(object session, Connection connection, Server server) |
| 32 | | { |
| 33 | | this.fConnection = connection; |
| 34 | | this.fSession = session; |
| 35 | | this.fServer = server; |
| 36 | | } |
| 37 | | } |
| 30 | public SessionEventArgs(object session, Connection connection, Server server) |
| 31 | { |
| 32 | this.fConnection = connection; |
| 33 | this.fSession = session; |
| 34 | this.fServer = server; |
| 35 | } |
| 36 | } |
| 38 | 37 | |
| 39 | | public class CommandEventArgs : SessionEventArgs |
| 40 | | { |
| 38 | public class CommandEventArgs : SessionEventArgs |
| 39 | { |
| 41 | 40 | |
| 42 | | private String fCommand; |
| 43 | | public String Command { get { return fCommand; } set { fCommand = value; }} |
| 41 | private String fCommand; |
| 42 | public String Command { get { return fCommand; } set { fCommand = value; } } |
| 44 | 43 | |
| 45 | | private String fAllParameters; |
| 46 | | public String AllParameters { get { return fAllParameters; } set { fAllParameters = value; }} |
| 44 | private String fAllParameters; |
| 45 | public String AllParameters { get { return fAllParameters; } set { fAllParameters = value; } } |
| 47 | 46 | |
| 48 | | private String[] fParameters; |
| 49 | | public String[] Parameters { get { return fParameters; } set { fParameters = value; } } |
| 47 | private String[] fParameters; |
| 48 | public String[] Parameters { get { return fParameters; } set { fParameters = value; } } |
| 50 | 49 | |
| 51 | | public CommandEventArgs(object session, Connection connection, Server server) : base (session, connection, server) |
| 52 | | { |
| 53 | | } |
| 54 | | } |
| 50 | public CommandEventArgs(object session, Connection connection, Server server) |
| 51 | : base(session, connection, server) |
| 52 | { |
| 53 | } |
| 54 | } |
| 55 | 55 | |
| 56 | | public delegate void OnCommandHandler(Object o, CommandEventArgs ea); |
| 57 | | public delegate void OnClientConnectedHandler(Object o, SessionEventArgs ea); |
| 58 | | public delegate void OnClientDisconnectedHandler(Object o, SessionEventArgs ea); |
| 56 | public delegate void OnCommandHandler(Object o, CommandEventArgs ea); |
| 57 | public delegate void OnClientConnectedHandler(Object o, SessionEventArgs ea); |
| 58 | public delegate void OnClientDisconnectedHandler(Object o, SessionEventArgs ea); |
| 59 | 59 | |
| 60 | | public abstract class CommandBasedServer : Server |
| 61 | | { |
| 60 | public abstract class CommandBasedServer : Server |
| 61 | { |
| 62 | 62 | |
| 63 | | internal protected Hashtable commands = new Hashtable(); |
| 63 | internal protected Hashtable commands = new Hashtable(); |
| 64 | 64 | |
| 65 | | #region Properties |
| 65 | #region Properties |
| 66 | 66 | |
| 67 | | private String unknowncommand = "500 {0}: Command not understood"; |
| 68 | | public String UnknownCommand { get { return unknowncommand; } set { unknowncommand = value; } } |
| 67 | private String unknowncommand = "500 {0}: Command not understood"; |
| 68 | public String UnknownCommand { get { return unknowncommand; } set { unknowncommand = value; } } |
| 69 | 69 | |
| 70 | | private String greeting = "GREETING"; |
| 71 | | protected internal String Greeting { get {return greeting; } set { greeting = value; } } |
| 70 | private String greeting = "GREETING"; |
| 71 | protected internal String Greeting { get { return greeting; } set { greeting = value; } } |
| 72 | 72 | |
| 73 | | private Type fSessionClass; |
| 74 | | public Type SessionClass |
| 75 | | { |
| 76 | | get { return fSessionClass; } |
| 77 | | set { fSessionClass = value; } |
| 78 | | } |
| 79 | | #endregion |
| 73 | private Type fSessionClass; |
| 74 | public Type SessionClass |
| 75 | { |
| 76 | get { return fSessionClass; } |
| 77 | set { fSessionClass = value; } |
| 78 | } |
| 79 | #endregion |
| 80 | 80 | |
| 81 | | #region Events |
| 81 | #region Events |
| 82 | 82 | |
| 83 | | public event OnClientConnectedHandler OnClientConnected; |
| 84 | | public event OnClientDisconnectedHandler OnClientDisconnected; |
| 83 | public event OnClientConnectedHandler OnClientConnected; |
| 84 | public event OnClientDisconnectedHandler OnClientDisconnected; |
| 85 | 85 | |
| 86 | | internal protected virtual void InvokeOnClientConnected(SessionEventArgs args) |
| 87 | | { |
| 86 | internal protected virtual void InvokeOnClientConnected(SessionEventArgs args) |
| 87 | { |
| 88 | 88 | |
| 89 | | if (OnClientConnected != null) |
| 90 | | { |
| 91 | | OnClientConnected(this, args); |
| 92 | | } |
| 93 | | } |
| 89 | if (OnClientConnected != null) |
| 90 | { |
| 91 | OnClientConnected(this, args); |
| 92 | } |
| 93 | } |
| 94 | 94 | |
| 95 | | internal protected virtual void InvokeOnClientDisconnected(SessionEventArgs args) |
| 96 | | { |
| 95 | internal protected virtual void InvokeOnClientDisconnected(SessionEventArgs args) |
| 96 | { |
| 97 | 97 | |
| 98 | | if (OnClientDisconnected != null) |
| 99 | | { |
| 100 | | OnClientDisconnected(this, args); |
| 101 | | } |
| 102 | | } |
| 103 | | #endregion |
| 98 | if (OnClientDisconnected != null) |
| 99 | { |
| 100 | OnClientDisconnected(this, args); |
| 101 | } |
| 102 | } |
| 103 | #endregion |
| 104 | 104 | |
| 105 | | protected internal virtual CommandBasedSession CreateSession() |
| 106 | | { |
| 105 | protected internal virtual CommandBasedSession CreateSession() |
| 106 | { |
| 107 | 107 | |
| 108 | | if (SessionClass != null) |
| 109 | | { |
| 110 | | return (CommandBasedSession)Activator.CreateInstance(SessionClass); |
| 111 | | } |
| 112 | | else |
| 113 | | { |
| 114 | | return (CommandBasedSession)Activator.CreateInstance(GetDefaultSessionClass()); |
| 115 | | } |
| 116 | | } |
| 108 | if (SessionClass != null) |
| 109 | { |
| 110 | return (CommandBasedSession)Activator.CreateInstance(SessionClass); |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | return (CommandBasedSession)Activator.CreateInstance(GetDefaultSessionClass()); |
| 115 | } |
| 116 | } |
| 117 | 117 | |
| 118 | | protected abstract void InitCommands(); |
| 118 | protected abstract void InitCommands(); |
| 119 | 119 | |
| 120 | | protected CommandBasedServer() |
| 121 | | { |
| 122 | | InitCommands(); |
| 123 | | } |
| 120 | protected CommandBasedServer() |
| 121 | { |
| 122 | InitCommands(); |
| 123 | } |
| 124 | 124 | |
| 125 | | public void AddCustomCommand(String name, OnCommandHandler handler) |
| 126 | | { |
| 127 | | commands.Add(name, handler); |
| 128 | | } |
| 125 | public void AddCustomCommand(String name, OnCommandHandler handler) |
| 126 | { |
| 127 | commands.Add(name, handler); |
| 128 | } |
| 129 | 129 | |
| 130 | | public override Type GetWorkerClass() |
| 131 | | { |
| 132 | | return typeof(CommandBasedWorker); |
| 133 | | } |
| 130 | public override Type GetWorkerClass() |
| 131 | { |
| 132 | return typeof(CommandBasedWorker); |
| 133 | } |
| 134 | 134 | |
| 135 | | protected virtual Type GetDefaultSessionClass() |
| 136 | | { |
| 137 | | return typeof(CommandBasedSession); |
| 138 | | } |
| 135 | protected virtual Type GetDefaultSessionClass() |
| 136 | { |
| 137 | return typeof(CommandBasedSession); |
| 138 | } |
| 139 | 139 | |
| 140 | | protected static string CleanStringForCommandResponse(string aValue) |
| 141 | | { |
| 142 | | return aValue.Replace("\n","").Replace("\r",""); |
| 143 | | } |
| 140 | protected static string CleanStringForCommandResponse(string aValue) |
| 141 | { |
| 142 | return aValue.Replace("\n", "").Replace("\r", ""); |
| 143 | } |
| 144 | 144 | |
| 145 | | protected internal virtual void HandleCommandException(Connection aConnection, Exception aException) |
| 146 | | { |
| 147 | | /* On error, just close the connection, descendand classes may implement |
| 148 | | * additional/different behavior */ |
| 149 | | aConnection.Close(); |
| 150 | | } |
| 151 | | } |
| 145 | protected internal virtual void HandleCommandException(Connection aConnection, Exception aException) |
| 146 | { |
| 147 | /* On error, just close the connection, descendand classes may implement |
| 148 | * additional/different behavior */ |
| 149 | aConnection.Close(); |
| 150 | } |
| 151 | } |
| 152 | 152 | |
| 153 | | |
| 154 | | public class CommandBasedSession |
| 155 | | { |
| 156 | 153 | |
| 157 | | private IPEndPoint fRemoteEndPoint; |
| 158 | | public IPEndPoint RemoteEndPoint |
| 159 | | { |
| 160 | | get { return fRemoteEndPoint; } |
| 161 | | set { fRemoteEndPoint = value; } |
| 162 | | } |
| 154 | public class CommandBasedSession |
| 155 | { |
| 163 | 156 | |
| 164 | | private IPEndPoint fLocalEndPoint; |
| 165 | | public IPEndPoint LocalEndPoint |
| 166 | | { |
| 167 | | get { return fLocalEndPoint; } |
| 168 | | set { fLocalEndPoint = value; } |
| 169 | | } |
| 170 | | } |
| 157 | private IPEndPoint fRemoteEndPoint; |
| 158 | public IPEndPoint RemoteEndPoint |
| 159 | { |
| 160 | get { return fRemoteEndPoint; } |
| 161 | set { fRemoteEndPoint = value; } |
| 162 | } |
| 171 | 163 | |
| 164 | private IPEndPoint fLocalEndPoint; |
| 165 | public IPEndPoint LocalEndPoint |
| 166 | { |
| 167 | get { return fLocalEndPoint; } |
| 168 | set { fLocalEndPoint = value; } |
| 169 | } |
| 170 | } |
| 172 | 171 | |
| 173 | | internal class CommandBasedWorker : Worker |
| 174 | | { |
| 175 | 172 | |
| 176 | | public CommandBasedWorker() |
| 177 | | { |
| 178 | | } |
| 173 | internal class CommandBasedWorker : Worker |
| 174 | { |
| 179 | 175 | |
| 180 | | private char[] SPACE = {' '}; |
| 176 | public CommandBasedWorker() |
| 177 | { |
| 178 | } |
| 181 | 179 | |
| 182 | | protected override void DoWork() |
| 183 | | { |
| 184 | | CommandBasedServer lServer = (CommandBasedServer)Owner; |
| 185 | | CommandBasedSession lSession = lServer.CreateSession(); |
| 186 | | lSession.RemoteEndPoint = ((IPEndPoint)DataConnection.RemoteEndPoint); |
| 187 | | lSession.LocalEndPoint = ((IPEndPoint)DataConnection.RemoteEndPoint); |
| 180 | private char[] SPACE = { ' ' }; |
| 188 | 181 | |
| 189 | | try |
| 190 | | { |
| 191 | | lServer.InvokeOnClientConnected(new SessionEventArgs(lSession, DataConnection, lServer)); |
| 192 | | DataConnection.WriteLine(lServer.Greeting); |
| 193 | | CommandEventArgs lArgs = new CommandEventArgs(lSession, DataConnection, lServer); |
| 194 | | String lCmdLine; |
| 182 | protected override void DoWork() |
| 183 | { |
| 184 | CommandBasedServer lServer = (CommandBasedServer)Owner; |
| 185 | CommandBasedSession lSession = lServer.CreateSession(); |
| 186 | lSession.RemoteEndPoint = ((IPEndPoint)DataConnection.RemoteEndPoint); |
| 187 | lSession.LocalEndPoint = ((IPEndPoint)DataConnection.RemoteEndPoint); |
| 195 | 188 | |
| 196 | | while (DataConnection.Connected) |
| 197 | | { |
| 198 | | lCmdLine = DataConnection.ReadLine().Trim(); |
| 189 | try |
| 190 | { |
| 191 | lServer.InvokeOnClientConnected(new SessionEventArgs(lSession, DataConnection, lServer)); |
| 192 | DataConnection.WriteLine(lServer.Greeting); |
| 193 | CommandEventArgs lArgs = new CommandEventArgs(lSession, DataConnection, lServer); |
| 194 | String lCmdLine; |
| 199 | 195 | |
| 200 | | if (lCmdLine.Length == 0) |
| 201 | | continue; |
| 202 | | int tempidx = lCmdLine.IndexOf(' '); |
| 196 | while (DataConnection.Connected) |
| 197 | { |
| 198 | lCmdLine = DataConnection.ReadLine().Trim(); |
| 203 | 199 | |
| 204 | | if (tempidx == -1) |
| 205 | | { |
| 206 | | lArgs.Command = lCmdLine.ToUpper(); |
| 207 | | lArgs.AllParameters = ""; |
| 208 | | lArgs.Parameters = new String[0]; |
| 209 | | } |
| 210 | | else |
| 211 | | { |
| 212 | | lArgs.Command = lCmdLine.Substring(0, tempidx).ToUpper(); |
| 213 | | lArgs.AllParameters = lCmdLine.Substring(tempidx + 1).Trim(); |
| 214 | | lArgs.Parameters = lArgs.AllParameters.Split(SPACE); |
| 215 | | } |
| 216 | | OnCommandHandler handler = (OnCommandHandler)lServer.commands[lArgs.Command]; |
| 200 | if (lCmdLine.Length == 0) |
| 201 | continue; |
| 202 | int tempidx = lCmdLine.IndexOf(' '); |
| 217 | 203 | |
| 218 | | if (handler == null) |
| 219 | | { |
| 220 | | DataConnection.WriteLine(String.Format(lServer.UnknownCommand, lArgs.Command)); |
| 221 | | } |
| 222 | | else |
| 223 | | { |
| 204 | if (tempidx == -1) |
| 205 | { |
| 206 | lArgs.Command = lCmdLine.ToUpper(); |
| 207 | lArgs.AllParameters = ""; |
| 208 | lArgs.Parameters = new String[0]; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | lArgs.Command = lCmdLine.Substring(0, tempidx).ToUpper(); |
| 213 | lArgs.AllParameters = lCmdLine.Substring(tempidx + 1).Trim(); |
| 214 | lArgs.Parameters = lArgs.AllParameters.Split(SPACE); |
| 215 | } |
| 216 | OnCommandHandler handler = (OnCommandHandler)lServer.commands[lArgs.Command]; |
| 224 | 217 | |
| 225 | | try |
| 226 | | { |
| 227 | | handler(lServer, lArgs); |
| 228 | | } |
| 229 | | catch (Exception e) |
| 230 | | { |
| 231 | | lServer.HandleCommandException(DataConnection, e); |
| 232 | | } |
| 233 | | } |
| 234 | | } |
| 235 | | } |
| 236 | | catch (System.Net.Sockets.SocketException e) |
| 237 | | { |
| 238 | | Debug.Write(e.Message); |
| 239 | | } |
| 240 | | catch (ConnectionClosedException e) |
| 241 | | { |
| 242 | | Debug.Write(e.Message); |
| 243 | | } |
| 218 | if (handler == null) |
| 219 | { |
| 220 | DataConnection.WriteLine(String.Format(lServer.UnknownCommand, lArgs.Command)); |
| 221 | } |
| 222 | else |
| 223 | { |
| 244 | 224 | |
| 245 | | lServer.InvokeOnClientDisconnected(new SessionEventArgs(lSession, DataConnection, lServer)); |
| 246 | | } |
| 247 | | } |
| 225 | try |
| 226 | { |
| 227 | handler(lServer, lArgs); |
| 228 | } |
| 229 | catch (Exception e) |
| 230 | { |
| 231 | lServer.HandleCommandException(DataConnection, e); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | #if DEBUGSERVER |
| 237 | catch (System.Net.Sockets.SocketException e) |
| 238 | { |
| 239 | Debug.Write(e.Message); |
| 240 | } |
| 241 | catch (ConnectionClosedException e) |
| 242 | { |
| 243 | Debug.Write(e.Message); |
| 244 | } |
| 245 | #else |
| 246 | catch |
| 247 | { |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | lServer.InvokeOnClientDisconnected(new SessionEventArgs(lSession, DataConnection, lServer)); |
| 252 | } |
| 253 | } |
| 248 | 254 | } |
| Source/RemObjects.InternetPack.SecureBlackbox/RemObjects.InternetPack.SecureBlackbox.2003.csproj |
| 1 | <VisualStudioProject> |
| 2 | <CSHARP |
| 3 | ProjectType = "Local" |
| 4 | ProductVersion = "7.10.3077" |
| 5 | SchemaVersion = "2.0" |
| 6 | ProjectGuid = "{01F5EA8B-EFD5-439A-9DCF-E2D83ED01F81}" |
| 7 | > |
| 8 | <Build> |
| 9 | <Settings |
| 10 | ApplicationIcon = "" |
| 11 | AssemblyKeyContainerName = "" |
| 12 | AssemblyName = "RemObjects.InternetPack.SecureBlackbox" |
| 13 | AssemblyOriginatorKeyFile = "" |
| 14 | DefaultClientScript = "JScript" |
| 15 | DefaultHTMLPageLayout = "Grid" |
| 16 | DefaultTargetSchema = "IE50" |
| 17 | DelaySign = "false" |
| 18 | OutputType = "Library" |
| 19 | PreBuildEvent = "" |
| 20 | PostBuildEvent = "" |
| 21 | RootNamespace = "RemObjects.InternetPack.SecureBlackbox" |
| 22 | RunPostBuildEvent = "OnBuildSuccess" |
| 23 | StartupObject = "" |
| 24 | > |
| 25 | <Config |
| 26 | Name = "Debug" |
| 27 | AllowUnsafeBlocks = "false" |
| 28 | BaseAddress = "285212672" |
| 29 | CheckForOverflowUnderflow = "false" |
| 30 | ConfigurationOverrideFile = "" |
| 31 | DefineConstants = "DEBUG;TRACE" |
| 32 | DocumentationFile = "" |
| 33 | DebugSymbols = "true" |
| 34 | FileAlignment = "4096" |
| 35 | IncrementalBuild = "false" |
| 36 | NoStdLib = "false" |
| 37 | NoWarn = "" |
| 38 | Optimize = "false" |
| 39 | OutputPath = "bin\Debug\" |
| 40 | RegisterForComInterop = "false" |
| 41 | RemoveIntegerChecks = "false" |
| 42 | TreatWarningsAsErrors = "false" |
| 43 | WarningLevel = "4" |
| 44 | /> |
| 45 | <Config |
| 46 | Name = "Release" |
| 47 | AllowUnsafeBlocks = "false" |
| 48 | BaseAddress = "285212672" |
| 49 | CheckForOverflowUnderflow = "false" |
| 50 | ConfigurationOverrideFile = "" |
| 51 | DefineConstants = "TRACE" |
| 52 | DocumentationFile = "" |
| 53 | DebugSymbols = "false" |
| 54 | FileAlignment = "4096" |
| 55 | IncrementalBuild = "false" |
| 56 | NoStdLib = "false" |
| 57 | NoWarn = "" |
| 58 | Optimize = "true" |
| 59 | OutputPath = "..\..\Bin\" |
| 60 | RegisterForComInterop = "false" |
| 61 | RemoveIntegerChecks = "false" |
| 62 | TreatWarningsAsErrors = "false" |
| 63 | WarningLevel = "4" |
| 64 | /> |
| 65 | </Settings> |
| 66 | <References> |
| 67 | <Reference |
| 68 | Name = "System" |
| 69 | AssemblyName = "System" |
| 70 | HintPath = "D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" |
| 71 | /> |
| 72 | <Reference |
| 73 | Name = "System.Data" |
| 74 | AssemblyName = "System.Data" |
| 75 | HintPath = "D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" |
| 76 | /> |
| 77 | <Reference |
| 78 | Name = "System.XML" |
| 79 | AssemblyName = "System.Xml" |
| 80 | HintPath = "D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" |
| 81 | /> |
| 82 | <Reference |
| 83 | Name = "RemObjects.InternetPack.2003" |
| 84 | Project = "{7C02E26A-2522-4C8F-8CAC-4E65854A09DE}" |
| 85 | Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" |
| 86 | /> |
| 87 | <Reference |
| 88 | Name = "SecureBlackbox.PKI" |
| 89 | AssemblyName = "SecureBlackbox.PKI" |
| 90 | HintPath = "C:\Program Files\EldoS\SecureBlackbox\SecureBlackbox.PKI.dll" |
| 91 | /> |
| 92 | <Reference |
| 93 | Name = "SecureBlackbox.SSLClient" |
| 94 | AssemblyName = "SecureBlackbox.SSLClient" |
| 95 | HintPath = "C:\Program Files\EldoS\SecureBlackbox\SecureBlackbox.SSLClient.dll" |
| 96 | /> |
| 97 | <Reference |
| 98 | Name = "SecureBlackbox.SSLServer" |
| 99 | AssemblyName = "SecureBlackbox.SSLServer" |
| 100 | HintPath = "C:\Program Files\EldoS\SecureBlackbox\SecureBlackbox.SSLServer.dll" |
| 101 | /> |
| 102 | <Reference |
| 103 | Name = "SecureBlackbox" |
| 104 | AssemblyName = "SecureBlackbox" |
| 105 | HintPath = "C:\Program Files\EldoS\SecureBlackbox\SecureBlackbox.dll" |
| 106 | /> |
| 107 | <Reference |
| 108 | Name = "SecureBlackbox.SSLSocket" |
| 109 | AssemblyName = "SecureBlackbox.SSLSocket" |
| 110 | HintPath = "C:\Program Files\EldoS\SecureBlackbox\SecureBlackbox.SSLSocket.dll" |
| 111 | /> |
| 112 | </References> |
| 113 | </Build> |
| 114 | <Files> |
| 115 | <Include> |
| 116 | <File |
| 117 | RelPath = "AssemblyInfo.cs" |
| 118 | SubType = "Code" |
| 119 | BuildAction = "Compile" |
| 120 | /> |
| 121 | <File |
| 122 | RelPath = "SSLConnection.cs" |
| 123 | SubType = "Code" |
| 124 | BuildAction = "Compile" |
| 125 | /> |
| 126 | <File |
| 127 | RelPath = "SSLConnectionFactory.cs" |
| 128 | SubType = "Code" |
| 129 | BuildAction = "Compile" |
| 130 | /> |
| 131 | </Include> |
| 132 | </Files> |
| 133 | </CSHARP> |
| 134 | </VisualStudioProject> |
| 135 | |