Return-Path: Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: (qmail 99540 invoked from network); 3 Dec 2009 23:56:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Dec 2009 23:56:24 -0000 Received: (qmail 16606 invoked by uid 500); 3 Dec 2009 23:56:24 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 16592 invoked by uid 500); 3 Dec 2009 23:56:24 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 16583 invoked by uid 99); 3 Dec 2009 23:56:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2009 23:56:24 +0000 X-ASF-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2009 23:56:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0D17B23889FD; Thu, 3 Dec 2009 23:55:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r886998 [3/14] - in /qpid/trunk: ./ qpid/dotnet/Qpid.Buffer.Tests/ qpid/dotnet/Qpid.Buffer.Tests/Properties/ qpid/dotnet/Qpid.Buffer/ qpid/dotnet/Qpid.Client.Tests/BrokerDetails/ qpid/dotnet/Qpid.Client.Tests/Channel/ qpid/dotnet/Qpid.Clien... Date: Thu, 03 Dec 2009 23:55:56 -0000 To: commits@qpid.apache.org From: aidan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091203235559.0D17B23889FD@eris.apache.org> Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs Thu Dec 3 23:55:48 2009 @@ -1,129 +1,129 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -using System; -using System.Collections; -using System.Configuration; -using System.Text; -using Apache.Qpid.Sasl; -using Apache.Qpid.Sasl.Mechanisms; - -using Apache.Qpid.Client.Configuration; - -namespace Apache.Qpid.Client.Security -{ - - /// - /// Helper class to map SASL mechanisms to our - /// internal ISaslCallbackHandler implementations. - /// - /// - /// The set of configured callback handlers and their order - /// controls the selection of the SASL mechanism used for authentication. - /// - /// You can either replace the default handler for CRAM-MD5 and PLAIN - /// authentication (the two default options) using the application - /// configuration file. Configuration is done by especifying the SASL - /// mechanism name (e.g PLAIN) and the type implementing the callback handler - /// used to provide any data required by the mechanism like username and password. - /// - /// - /// Callback handler types should implement the IAMQCallbackHandler interface. - /// - /// - /// New callbacks or authentication mechanisms can be configured like this: - /// - /// - /// - /// - ///
- /// - /// - /// - /// - /// - /// - /// - /// - /// ]]> - /// - public sealed class CallbackHandlerRegistry - { - private static CallbackHandlerRegistry _instance = - new CallbackHandlerRegistry(); - private OrderedHashTable _mechanism2HandlerMap; - private string[] _mechanisms; - - public static CallbackHandlerRegistry Instance - { - get { return _instance; } - } - - public string[] Mechanisms - { - get { return _mechanisms; } - } - - private CallbackHandlerRegistry() - { - _mechanism2HandlerMap = (OrderedHashTable) - ConfigurationSettings.GetConfig("qpid.client/authentication"); - - // configure default options if not available - if ( _mechanism2HandlerMap == null ) - _mechanism2HandlerMap = new OrderedHashTable(); - - if ( !_mechanism2HandlerMap.Contains(ExternalSaslClient.Mechanism) ) - _mechanism2HandlerMap.Add(ExternalSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); - if ( !_mechanism2HandlerMap.Contains(CramMD5SaslClient.Mechanism) ) - _mechanism2HandlerMap.Add(CramMD5SaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); - if ( !_mechanism2HandlerMap.Contains(CramMD5HexSaslClient.Mechanism) ) - _mechanism2HandlerMap.Add(CramMD5HexSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); - if ( !_mechanism2HandlerMap.Contains(PlainSaslClient.Mechanism) ) - _mechanism2HandlerMap.Add(PlainSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); - - _mechanisms = new string[_mechanism2HandlerMap.Count]; - _mechanism2HandlerMap.OrderedKeys.CopyTo(_mechanisms, 0); - } - - public bool IsSupportedMechanism(string mechanism) - { - return _mechanism2HandlerMap.Contains(mechanism); - } - - public string ChooseMechanism(string mechanisms) - { - IList mechs = mechanisms.Split(' '); - foreach ( string supportedMech in _mechanisms ) - { - if ( mechs.Contains(supportedMech) ) - return supportedMech; - } - return null; - } - - public Type GetCallbackHandler(string mechanism) - { - return (Type)_mechanism2HandlerMap[mechanism]; - } - } -} +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Configuration; +using System.Text; +using Apache.Qpid.Sasl; +using Apache.Qpid.Sasl.Mechanisms; + +using Apache.Qpid.Client.Configuration; + +namespace Apache.Qpid.Client.Security +{ + + /// + /// Helper class to map SASL mechanisms to our + /// internal ISaslCallbackHandler implementations. + /// + /// + /// The set of configured callback handlers and their order + /// controls the selection of the SASL mechanism used for authentication. + /// + /// You can either replace the default handler for CRAM-MD5 and PLAIN + /// authentication (the two default options) using the application + /// configuration file. Configuration is done by especifying the SASL + /// mechanism name (e.g PLAIN) and the type implementing the callback handler + /// used to provide any data required by the mechanism like username and password. + /// + /// + /// Callback handler types should implement the IAMQCallbackHandler interface. + /// + /// + /// New callbacks or authentication mechanisms can be configured like this: + /// + /// + /// + /// + ///
+ /// + /// + /// + /// + /// + /// + /// + /// + /// ]]> + /// + public sealed class CallbackHandlerRegistry + { + private static CallbackHandlerRegistry _instance = + new CallbackHandlerRegistry(); + private OrderedHashTable _mechanism2HandlerMap; + private string[] _mechanisms; + + public static CallbackHandlerRegistry Instance + { + get { return _instance; } + } + + public string[] Mechanisms + { + get { return _mechanisms; } + } + + private CallbackHandlerRegistry() + { + _mechanism2HandlerMap = (OrderedHashTable) + ConfigurationSettings.GetConfig("qpid.client/authentication"); + + // configure default options if not available + if ( _mechanism2HandlerMap == null ) + _mechanism2HandlerMap = new OrderedHashTable(); + + if ( !_mechanism2HandlerMap.Contains(ExternalSaslClient.Mechanism) ) + _mechanism2HandlerMap.Add(ExternalSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); + if ( !_mechanism2HandlerMap.Contains(CramMD5SaslClient.Mechanism) ) + _mechanism2HandlerMap.Add(CramMD5SaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); + if ( !_mechanism2HandlerMap.Contains(CramMD5HexSaslClient.Mechanism) ) + _mechanism2HandlerMap.Add(CramMD5HexSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); + if ( !_mechanism2HandlerMap.Contains(PlainSaslClient.Mechanism) ) + _mechanism2HandlerMap.Add(PlainSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler)); + + _mechanisms = new string[_mechanism2HandlerMap.Count]; + _mechanism2HandlerMap.OrderedKeys.CopyTo(_mechanisms, 0); + } + + public bool IsSupportedMechanism(string mechanism) + { + return _mechanism2HandlerMap.Contains(mechanism); + } + + public string ChooseMechanism(string mechanisms) + { + IList mechs = mechanisms.Split(' '); + foreach ( string supportedMech in _mechanisms ) + { + if ( mechs.Contains(supportedMech) ) + return supportedMech; + } + return null; + } + + public Type GetCallbackHandler(string mechanism) + { + return (Type)_mechanism2HandlerMap[mechanism]; + } + } +} Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/IAMQCallbackHandler.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/IAMQCallbackHandler.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/IAMQCallbackHandler.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/IAMQCallbackHandler.cs Thu Dec 3 23:55:48 2009 @@ -1,35 +1,35 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System; -using System.Text; -using Apache.Qpid.Client.Protocol; -using Apache.Qpid.Sasl; - -namespace Apache.Qpid.Client.Security -{ - public interface IAMQCallbackHandler : ISaslCallbackHandler - { - void Initialize(AMQProtocolSession session); - } - -} - - +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using System.Text; +using Apache.Qpid.Client.Protocol; +using Apache.Qpid.Sasl; + +namespace Apache.Qpid.Client.Security +{ + public interface IAMQCallbackHandler : ISaslCallbackHandler + { + void Initialize(AMQProtocolSession session); + } + +} + + Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/IAMQCallbackHandler.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/UsernamePasswordCallbackHandler.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/UsernamePasswordCallbackHandler.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/UsernamePasswordCallbackHandler.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/UsernamePasswordCallbackHandler.cs Thu Dec 3 23:55:48 2009 @@ -1,56 +1,56 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -using System; -using System.Collections; -using System.Text; -using Apache.Qpid.Client.Protocol; -using Apache.Qpid.Sasl; - -namespace Apache.Qpid.Client.Security -{ - internal class UsernamePasswordCallbackHandler : IAMQCallbackHandler - { - private AMQProtocolSession _session; - - public void Initialize(AMQProtocolSession session) - { - if ( session == null ) - throw new ArgumentNullException("session"); - - _session = session; - } - - public void Handle(ISaslCallback[] callbacks) - { - foreach ( ISaslCallback cb in callbacks ) - { - if ( cb is NameCallback ) - { - ((NameCallback)cb).Text = _session.Username; - } else if ( cb is PasswordCallback ) - { - ((PasswordCallback)cb).Text = _session.Password; - } - } - } - } -} +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Text; +using Apache.Qpid.Client.Protocol; +using Apache.Qpid.Sasl; + +namespace Apache.Qpid.Client.Security +{ + internal class UsernamePasswordCallbackHandler : IAMQCallbackHandler + { + private AMQProtocolSession _session; + + public void Initialize(AMQProtocolSession session) + { + if ( session == null ) + throw new ArgumentNullException("session"); + + _session = session; + } + + public void Handle(ISaslCallback[] callbacks) + { + foreach ( ISaslCallback cb in callbacks ) + { + if ( cb is NameCallback ) + { + ((NameCallback)cb).Text = _session.Username; + } else if ( cb is PasswordCallback ) + { + ((PasswordCallback)cb).Text = _session.Password; + } + } + } + } +} Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/UsernamePasswordCallbackHandler.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/SslOptions.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/SslOptions.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/SslOptions.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/SslOptions.cs Thu Dec 3 23:55:48 2009 @@ -1,81 +1,81 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System; -using System.Security.Cryptography.X509Certificates; - -namespace Apache.Qpid.Client -{ - /// - /// Configures SSL-related options to connect to an AMQP broker. - /// - /// - /// If the server certificate is not trusted by the client, - /// connection will fail. However, you can set the - /// property to true - /// to ignore any certificate verification errors for debugging purposes. - /// - public class SslOptions - { - private X509Certificate _clientCertificate; - private bool _ignoreValidationErrors; - - /// - /// Certificate to present to the broker to authenticate - /// this client connection - /// - public X509Certificate ClientCertificate - { - get { return _clientCertificate; } - } - - /// - /// If true, the validity of the broker certificate - /// will not be verified on connection - /// - public bool IgnoreValidationErrors - { - get { return _ignoreValidationErrors; } - } - - /// - /// Initialize a new instance with default values - /// (No client certificate, don't ignore validation errors) - /// - public SslOptions() - { - } - - /// - /// Initialize a new instance - /// - /// - /// Certificate to use to authenticate the client to the broker - /// - /// - /// If true, ignore any validation errors when validating the server certificate - /// - public SslOptions(X509Certificate clientCertificate, bool ignoreValidationErrors) - { - _clientCertificate = clientCertificate; - _ignoreValidationErrors = ignoreValidationErrors; - } - } -} +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using System.Security.Cryptography.X509Certificates; + +namespace Apache.Qpid.Client +{ + /// + /// Configures SSL-related options to connect to an AMQP broker. + /// + /// + /// If the server certificate is not trusted by the client, + /// connection will fail. However, you can set the + /// property to true + /// to ignore any certificate verification errors for debugging purposes. + /// + public class SslOptions + { + private X509Certificate _clientCertificate; + private bool _ignoreValidationErrors; + + /// + /// Certificate to present to the broker to authenticate + /// this client connection + /// + public X509Certificate ClientCertificate + { + get { return _clientCertificate; } + } + + /// + /// If true, the validity of the broker certificate + /// will not be verified on connection + /// + public bool IgnoreValidationErrors + { + get { return _ignoreValidationErrors; } + } + + /// + /// Initialize a new instance with default values + /// (No client certificate, don't ignore validation errors) + /// + public SslOptions() + { + } + + /// + /// Initialize a new instance + /// + /// + /// Certificate to use to authenticate the client to the broker + /// + /// + /// If true, ignore any validation errors when validating the server certificate + /// + public SslOptions(X509Certificate clientCertificate, bool ignoreValidationErrors) + { + _clientCertificate = clientCertificate; + _ignoreValidationErrors = ignoreValidationErrors; + } + } +} Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/SslOptions.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IStreamFilter.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IStreamFilter.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IStreamFilter.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IStreamFilter.cs Thu Dec 3 23:55:48 2009 @@ -1,38 +1,38 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System.IO; - -namespace Apache.Qpid.Client.Transport -{ - /// - /// Defines a way to introduce an arbitrary filtering - /// stream into the stream chain managed by - /// - public interface IStreamFilter - { - /// - /// Creates a new filtering stream on top of another - /// - /// Next stream on the stack - /// A new filtering stream - Stream CreateFilterStream(Stream lowerStream); - } -} +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System.IO; + +namespace Apache.Qpid.Client.Transport +{ + /// + /// Defines a way to introduce an arbitrary filtering + /// stream into the stream chain managed by + /// + public interface IStreamFilter + { + /// + /// Creates a new filtering stream on top of another + /// + /// Next stream on the stack + /// A new filtering stream + Stream CreateFilterStream(Stream lowerStream); + } +} Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IStreamFilter.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IoHandler.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IoHandler.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IoHandler.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IoHandler.cs Thu Dec 3 23:55:48 2009 @@ -1,322 +1,322 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System; -using System.IO; -using System.Threading; -using log4net; -using Apache.Qpid.Buffer; -using Apache.Qpid.Client.Protocol; - -namespace Apache.Qpid.Client.Transport -{ - /// - /// Responsible for reading and writing - /// ByteBuffers from/to network streams, and handling - /// the stream filters - /// - public class IoHandler : IByteChannel, IDisposable - { - private static readonly ILog _log = LogManager.GetLogger(typeof(IoHandler)); - private const int DEFAULT_BUFFER_SIZE = 32 * 1024; - - private Stream _topStream; - private IProtocolListener _protocolListener; - private int _readBufferSize; - - public int ReadBufferSize - { - get { return _readBufferSize; } - set { _readBufferSize = value; } - } - - /// - /// Initialize a new instance - /// - /// Underlying network stream - /// Protocol listener to report exceptions to - public IoHandler(Stream stream, IProtocolListener protocolListener) - { - if ( stream == null ) - throw new ArgumentNullException("stream"); - if ( protocolListener == null ) - throw new ArgumentNullException("protocolListener"); - - // initially, the stream at the top of the filter - // chain is the underlying network stream - _topStream = stream; - _protocolListener = protocolListener; - _readBufferSize = DEFAULT_BUFFER_SIZE; - } - - /// - /// Adds a new filter on the top of the chain - /// - /// Stream filter to put on top of the chain - /// - /// This should *only* be called during initialization. We don't - /// support changing the filter change after the first read/write - /// has been done and it's not thread-safe to boot! - /// - public void AddFilter(IStreamFilter filter) - { - _topStream = filter.CreateFilterStream(_topStream); - } - - #region IByteChannel Implementation - // - // IByteChannel Implementation - // - - /// - /// Read a from the underlying - /// network stream and any configured filters - /// - /// A ByteBuffer, if available - public ByteBuffer Read() - { - byte[] bytes = AllocateBuffer(); - - int numOctets = _topStream.Read(bytes, 0, bytes.Length); - - return WrapByteArray(bytes, numOctets); - } - - /// - /// Begin an asynchronous read operation - /// - /// Callback method to call when read operation completes - /// State object - /// An object - public IAsyncResult BeginRead(AsyncCallback callback, object state) - { - byte[] bytes = AllocateBuffer(); - ReadData rd = new ReadData(callback, state, bytes); - - // only put a callback if the caller wants one. - AsyncCallback myCallback = null; - if ( callback != null ) - myCallback = new AsyncCallback(OnAsyncReadDone); - - IAsyncResult result = _topStream.BeginRead( - bytes, 0, bytes.Length, myCallback,rd - ); - return new WrappedAsyncResult(result, bytes); - } - - /// - /// End an asynchronous read operation - /// - /// The object returned from - /// The read - public ByteBuffer EndRead(IAsyncResult result) - { - WrappedAsyncResult theResult = (WrappedAsyncResult)result; - int bytesRead = _topStream.EndRead(theResult.InnerResult); - return WrapByteArray(theResult.Buffer, bytesRead); - } - - /// - /// Write a to the underlying network - /// stream, going through any configured filters - /// - /// - public void Write(ByteBuffer buffer) - { - try - { - _topStream.Write(buffer.Array, buffer.Position, buffer.Limit); // FIXME - } - catch (Exception e) - { - _log.Warn("Write caused exception", e); - _protocolListener.OnException(e); - } - } - - /// - /// Begin an asynchronous write operation - /// - /// Buffer to write - /// A callback to call when the operation completes - /// State object - /// An object - public IAsyncResult BeginWrite(ByteBuffer buffer, AsyncCallback callback, object state) - { - try - { - return _topStream.BeginWrite( - buffer.Array, buffer.Position, buffer.Limit, - callback, state - ); - } catch ( Exception e ) - { - _log.Error("BeginWrite caused exception", e); - // not clear if an exception here should be propagated? we still - // need to propagate it upwards anyway! - _protocolListener.OnException(e); - throw; - } - } - - /// - /// End an asynchronous write operation - /// - /// The object returned by - public void EndWrite(IAsyncResult result) - { - try - { - _topStream.EndWrite(result); - } catch ( Exception e ) - { - _log.Error("EndWrite caused exception", e); - // not clear if an exception here should be propagated? - _protocolListener.OnException(e); - //throw; - } - } - #endregion // IByteChannel Implementation - - #region IDisposable Implementation - // - // IDisposable Implementation - // - - public void Dispose() - { - if ( _topStream != null ) - { - _topStream.Close(); - } - } - - #endregion // IDisposable Implementation - - #region Private and Helper Classes/Methods - // - // Private and Helper Classes/Methods - // - - private byte[] AllocateBuffer() - { - return new byte[ReadBufferSize]; - } - - private static ByteBuffer WrapByteArray(byte[] bytes, int size) - { - ByteBuffer byteBuffer = ByteBuffer.Wrap(bytes); - byteBuffer.Limit = size; - byteBuffer.Flip(); - - return byteBuffer; - } - - - private static void OnAsyncReadDone(IAsyncResult result) - { - ReadData rd = (ReadData) result.AsyncState; - IAsyncResult wrapped = new WrappedAsyncResult(result, rd.Buffer); - rd.Callback(wrapped); - } - - class ReadData - { - private object _state; - private AsyncCallback _callback; - private byte[] _buffer; - - public object State - { - get { return _state; } - } - - public AsyncCallback Callback - { - get { return _callback; } - } - - public byte[] Buffer - { - get { return _buffer; } - } - - public ReadData(AsyncCallback callback, object state, byte[] buffer) - { - _callback = callback; - _state = state; - _buffer = buffer; - } - } - - class WrappedAsyncResult : IAsyncResult - { - private IAsyncResult _innerResult; - private byte[] _buffer; - - #region IAsyncResult Properties - // - // IAsyncResult Properties - // - public bool IsCompleted - { - get { return _innerResult.IsCompleted; } - } - - public WaitHandle AsyncWaitHandle - { - get { return _innerResult.AsyncWaitHandle; } - } - - public object AsyncState - { - get { return _innerResult.AsyncState; } - } - - public bool CompletedSynchronously - { - get { return _innerResult.CompletedSynchronously; } - } - #endregion // IAsyncResult Properties - - public IAsyncResult InnerResult - { - get { return _innerResult; } - } - public byte[] Buffer - { - get { return _buffer; } - } - - public WrappedAsyncResult(IAsyncResult result, byte[] buffer) - { - if ( result == null ) - throw new ArgumentNullException("result"); - if ( buffer == null ) - throw new ArgumentNullException("buffer"); - - _innerResult = result; - _buffer = buffer; - } - } - - #endregion // Private and Helper Classes/Methods - } -} +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using System.IO; +using System.Threading; +using log4net; +using Apache.Qpid.Buffer; +using Apache.Qpid.Client.Protocol; + +namespace Apache.Qpid.Client.Transport +{ + /// + /// Responsible for reading and writing + /// ByteBuffers from/to network streams, and handling + /// the stream filters + /// + public class IoHandler : IByteChannel, IDisposable + { + private static readonly ILog _log = LogManager.GetLogger(typeof(IoHandler)); + private const int DEFAULT_BUFFER_SIZE = 32 * 1024; + + private Stream _topStream; + private IProtocolListener _protocolListener; + private int _readBufferSize; + + public int ReadBufferSize + { + get { return _readBufferSize; } + set { _readBufferSize = value; } + } + + /// + /// Initialize a new instance + /// + /// Underlying network stream + /// Protocol listener to report exceptions to + public IoHandler(Stream stream, IProtocolListener protocolListener) + { + if ( stream == null ) + throw new ArgumentNullException("stream"); + if ( protocolListener == null ) + throw new ArgumentNullException("protocolListener"); + + // initially, the stream at the top of the filter + // chain is the underlying network stream + _topStream = stream; + _protocolListener = protocolListener; + _readBufferSize = DEFAULT_BUFFER_SIZE; + } + + /// + /// Adds a new filter on the top of the chain + /// + /// Stream filter to put on top of the chain + /// + /// This should *only* be called during initialization. We don't + /// support changing the filter change after the first read/write + /// has been done and it's not thread-safe to boot! + /// + public void AddFilter(IStreamFilter filter) + { + _topStream = filter.CreateFilterStream(_topStream); + } + + #region IByteChannel Implementation + // + // IByteChannel Implementation + // + + /// + /// Read a from the underlying + /// network stream and any configured filters + /// + /// A ByteBuffer, if available + public ByteBuffer Read() + { + byte[] bytes = AllocateBuffer(); + + int numOctets = _topStream.Read(bytes, 0, bytes.Length); + + return WrapByteArray(bytes, numOctets); + } + + /// + /// Begin an asynchronous read operation + /// + /// Callback method to call when read operation completes + /// State object + /// An object + public IAsyncResult BeginRead(AsyncCallback callback, object state) + { + byte[] bytes = AllocateBuffer(); + ReadData rd = new ReadData(callback, state, bytes); + + // only put a callback if the caller wants one. + AsyncCallback myCallback = null; + if ( callback != null ) + myCallback = new AsyncCallback(OnAsyncReadDone); + + IAsyncResult result = _topStream.BeginRead( + bytes, 0, bytes.Length, myCallback,rd + ); + return new WrappedAsyncResult(result, bytes); + } + + /// + /// End an asynchronous read operation + /// + /// The object returned from + /// The read + public ByteBuffer EndRead(IAsyncResult result) + { + WrappedAsyncResult theResult = (WrappedAsyncResult)result; + int bytesRead = _topStream.EndRead(theResult.InnerResult); + return WrapByteArray(theResult.Buffer, bytesRead); + } + + /// + /// Write a to the underlying network + /// stream, going through any configured filters + /// + /// + public void Write(ByteBuffer buffer) + { + try + { + _topStream.Write(buffer.Array, buffer.Position, buffer.Limit); // FIXME + } + catch (Exception e) + { + _log.Warn("Write caused exception", e); + _protocolListener.OnException(e); + } + } + + /// + /// Begin an asynchronous write operation + /// + /// Buffer to write + /// A callback to call when the operation completes + /// State object + /// An object + public IAsyncResult BeginWrite(ByteBuffer buffer, AsyncCallback callback, object state) + { + try + { + return _topStream.BeginWrite( + buffer.Array, buffer.Position, buffer.Limit, + callback, state + ); + } catch ( Exception e ) + { + _log.Error("BeginWrite caused exception", e); + // not clear if an exception here should be propagated? we still + // need to propagate it upwards anyway! + _protocolListener.OnException(e); + throw; + } + } + + /// + /// End an asynchronous write operation + /// + /// The object returned by + public void EndWrite(IAsyncResult result) + { + try + { + _topStream.EndWrite(result); + } catch ( Exception e ) + { + _log.Error("EndWrite caused exception", e); + // not clear if an exception here should be propagated? + _protocolListener.OnException(e); + //throw; + } + } + #endregion // IByteChannel Implementation + + #region IDisposable Implementation + // + // IDisposable Implementation + // + + public void Dispose() + { + if ( _topStream != null ) + { + _topStream.Close(); + } + } + + #endregion // IDisposable Implementation + + #region Private and Helper Classes/Methods + // + // Private and Helper Classes/Methods + // + + private byte[] AllocateBuffer() + { + return new byte[ReadBufferSize]; + } + + private static ByteBuffer WrapByteArray(byte[] bytes, int size) + { + ByteBuffer byteBuffer = ByteBuffer.Wrap(bytes); + byteBuffer.Limit = size; + byteBuffer.Flip(); + + return byteBuffer; + } + + + private static void OnAsyncReadDone(IAsyncResult result) + { + ReadData rd = (ReadData) result.AsyncState; + IAsyncResult wrapped = new WrappedAsyncResult(result, rd.Buffer); + rd.Callback(wrapped); + } + + class ReadData + { + private object _state; + private AsyncCallback _callback; + private byte[] _buffer; + + public object State + { + get { return _state; } + } + + public AsyncCallback Callback + { + get { return _callback; } + } + + public byte[] Buffer + { + get { return _buffer; } + } + + public ReadData(AsyncCallback callback, object state, byte[] buffer) + { + _callback = callback; + _state = state; + _buffer = buffer; + } + } + + class WrappedAsyncResult : IAsyncResult + { + private IAsyncResult _innerResult; + private byte[] _buffer; + + #region IAsyncResult Properties + // + // IAsyncResult Properties + // + public bool IsCompleted + { + get { return _innerResult.IsCompleted; } + } + + public WaitHandle AsyncWaitHandle + { + get { return _innerResult.AsyncWaitHandle; } + } + + public object AsyncState + { + get { return _innerResult.AsyncState; } + } + + public bool CompletedSynchronously + { + get { return _innerResult.CompletedSynchronously; } + } + #endregion // IAsyncResult Properties + + public IAsyncResult InnerResult + { + get { return _innerResult; } + } + public byte[] Buffer + { + get { return _buffer; } + } + + public WrappedAsyncResult(IAsyncResult result, byte[] buffer) + { + if ( result == null ) + throw new ArgumentNullException("result"); + if ( buffer == null ) + throw new ArgumentNullException("buffer"); + + _innerResult = result; + _buffer = buffer; + } + } + + #endregion // Private and Helper Classes/Methods + } +} Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/IoHandler.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/ProtocolDecoderOutput.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/ProtocolDecoderOutput.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/ProtocolDecoderOutput.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/ProtocolDecoderOutput.cs Thu Dec 3 23:55:48 2009 @@ -1,60 +1,60 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System; -using System.Threading; -using Apache.Qpid.Client.Protocol; -using Apache.Qpid.Codec; -using Apache.Qpid.Framing; -using log4net; - -namespace Apache.Qpid.Client.Transport -{ - /// - /// implementation that forwards - /// each as it is decoded to the - /// protocol listener - /// - internal class ProtocolDecoderOutput : IProtocolDecoderOutput - { - private IProtocolListener _protocolListener; - static readonly ILog _protocolTraceLog = LogManager.GetLogger("TRACE.Qpid.Client.ProtocolChannel"); - - public ProtocolDecoderOutput(IProtocolListener protocolListener) - { - if ( protocolListener == null ) - throw new ArgumentNullException("protocolListener"); - - _protocolListener = protocolListener; - } - - public void Write(object message) - { - IDataBlock block = message as IDataBlock; - if ( block != null ) - { - _protocolTraceLog.Debug(String.Format("READ {0}", block)); - _protocolListener.OnMessage(block); - } - } - } -} // namespace Apache.Qpid.Client.Transport - - +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using System.Threading; +using Apache.Qpid.Client.Protocol; +using Apache.Qpid.Codec; +using Apache.Qpid.Framing; +using log4net; + +namespace Apache.Qpid.Client.Transport +{ + /// + /// implementation that forwards + /// each as it is decoded to the + /// protocol listener + /// + internal class ProtocolDecoderOutput : IProtocolDecoderOutput + { + private IProtocolListener _protocolListener; + static readonly ILog _protocolTraceLog = LogManager.GetLogger("TRACE.Qpid.Client.ProtocolChannel"); + + public ProtocolDecoderOutput(IProtocolListener protocolListener) + { + if ( protocolListener == null ) + throw new ArgumentNullException("protocolListener"); + + _protocolListener = protocolListener; + } + + public void Write(object message) + { + IDataBlock block = message as IDataBlock; + if ( block != null ) + { + _protocolTraceLog.Debug(String.Format("READ {0}", block)); + _protocolListener.OnMessage(block); + } + } + } +} // namespace Apache.Qpid.Client.Transport + + Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/ProtocolDecoderOutput.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/BlockingSocketTransport.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/BlockingSocketTransport.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/BlockingSocketTransport.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/BlockingSocketTransport.cs Thu Dec 3 23:55:48 2009 @@ -1,150 +1,150 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System; -using System.Collections; -using System.IO; -using System.Threading; -using Apache.Qpid.Client.Qms; -using Apache.Qpid.Client.Protocol; -using Apache.Qpid.Codec; -using Apache.Qpid.Framing; - -namespace Apache.Qpid.Client.Transport.Socket.Blocking -{ - /// - /// TCP Socket transport supporting both - /// SSL and non-SSL connections. - /// - public class BlockingSocketTransport : ITransport - { - // Configuration variables. - IProtocolListener _protocolListener; - - // Runtime variables. - private ISocketConnector _connector; - private IoHandler _ioHandler; - private AmqpChannel _amqpChannel; - private ManualResetEvent _stopEvent; - - public IProtocolWriter ProtocolWriter - { - get { return _amqpChannel; } - } - public string LocalEndpoint - { - get { return _connector.LocalEndpoint; } - } - - - /// - /// Connect to the specified broker - /// - /// The broker to connect to - /// The AMQ connection - public void Connect(IBrokerInfo broker, AMQConnection connection) - { - _stopEvent = new ManualResetEvent(false); - _protocolListener = connection.ProtocolListener; - - _ioHandler = MakeBrokerConnection(broker, connection); - // todo: get default read size from config! - - IProtocolDecoderOutput decoderOutput = - new ProtocolDecoderOutput(_protocolListener); - _amqpChannel = - new AmqpChannel(new ByteChannel(_ioHandler), decoderOutput); - - // post an initial async read - _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), this); - } - - /// - /// Close the broker connection - /// - public void Close() - { - StopReading(); - CloseBrokerConnection(); - } - - private void StopReading() - { - _stopEvent.Set(); - } - - private void CloseBrokerConnection() - { - if ( _ioHandler != null ) - { - _ioHandler.Dispose(); - _ioHandler = null; - } - if ( _connector != null ) - { - _connector.Dispose(); - _connector = null; - } - } - - private IoHandler MakeBrokerConnection(IBrokerInfo broker, AMQConnection connection) - { - if ( broker.UseSSL ) - { - _connector = new SslSocketConnector(); - } else - { - _connector = new SocketConnector(); - } - - Stream stream = _connector.Connect(broker); - return new IoHandler(stream, connection.ProtocolListener); - } - - private void OnAsyncReadDone(IAsyncResult result) - { - try - { - _amqpChannel.EndRead(result); - - bool stopping = _stopEvent.WaitOne(0, false); - if ( !stopping ) - _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), null); - } catch ( Exception e ) - { - // ignore any errors during closing - bool stopping = _stopEvent.WaitOne(0, false); - if ( !stopping ) - _protocolListener.OnException(e); - } - } - - #region IProtocolDecoderOutput Members - - public void Write(object message) - { - _protocolListener.OnMessage((IDataBlock)message); - } - - #endregion - } -} - - +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using System.Collections; +using System.IO; +using System.Threading; +using Apache.Qpid.Client.Qms; +using Apache.Qpid.Client.Protocol; +using Apache.Qpid.Codec; +using Apache.Qpid.Framing; + +namespace Apache.Qpid.Client.Transport.Socket.Blocking +{ + /// + /// TCP Socket transport supporting both + /// SSL and non-SSL connections. + /// + public class BlockingSocketTransport : ITransport + { + // Configuration variables. + IProtocolListener _protocolListener; + + // Runtime variables. + private ISocketConnector _connector; + private IoHandler _ioHandler; + private AmqpChannel _amqpChannel; + private ManualResetEvent _stopEvent; + + public IProtocolWriter ProtocolWriter + { + get { return _amqpChannel; } + } + public string LocalEndpoint + { + get { return _connector.LocalEndpoint; } + } + + + /// + /// Connect to the specified broker + /// + /// The broker to connect to + /// The AMQ connection + public void Connect(IBrokerInfo broker, AMQConnection connection) + { + _stopEvent = new ManualResetEvent(false); + _protocolListener = connection.ProtocolListener; + + _ioHandler = MakeBrokerConnection(broker, connection); + // todo: get default read size from config! + + IProtocolDecoderOutput decoderOutput = + new ProtocolDecoderOutput(_protocolListener); + _amqpChannel = + new AmqpChannel(new ByteChannel(_ioHandler), decoderOutput); + + // post an initial async read + _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), this); + } + + /// + /// Close the broker connection + /// + public void Close() + { + StopReading(); + CloseBrokerConnection(); + } + + private void StopReading() + { + _stopEvent.Set(); + } + + private void CloseBrokerConnection() + { + if ( _ioHandler != null ) + { + _ioHandler.Dispose(); + _ioHandler = null; + } + if ( _connector != null ) + { + _connector.Dispose(); + _connector = null; + } + } + + private IoHandler MakeBrokerConnection(IBrokerInfo broker, AMQConnection connection) + { + if ( broker.UseSSL ) + { + _connector = new SslSocketConnector(); + } else + { + _connector = new SocketConnector(); + } + + Stream stream = _connector.Connect(broker); + return new IoHandler(stream, connection.ProtocolListener); + } + + private void OnAsyncReadDone(IAsyncResult result) + { + try + { + _amqpChannel.EndRead(result); + + bool stopping = _stopEvent.WaitOne(0, false); + if ( !stopping ) + _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), null); + } catch ( Exception e ) + { + // ignore any errors during closing + bool stopping = _stopEvent.WaitOne(0, false); + if ( !stopping ) + _protocolListener.OnException(e); + } + } + + #region IProtocolDecoderOutput Members + + public void Write(object message) + { + _protocolListener.OnMessage((IDataBlock)message); + } + + #endregion + } +} + + Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/BlockingSocketTransport.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ByteChannel.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ByteChannel.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ByteChannel.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ByteChannel.cs Thu Dec 3 23:55:48 2009 @@ -1,92 +1,92 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System; -using log4net; -using Apache.Qpid.Buffer; - -namespace Apache.Qpid.Client.Transport.Socket.Blocking -{ - class ByteChannel : IByteChannel - { - // Warning: don't use this log for regular logging. - private static readonly ILog _ioTraceLog = LogManager.GetLogger("TRACE.Qpid.Client.ByteChannel"); - - private IByteChannel _lowerChannel; - - public ByteChannel(IByteChannel lowerChannel) - { - _lowerChannel = lowerChannel; - } - - public ByteBuffer Read() - { - ByteBuffer result = _lowerChannel.Read(); - - // TODO: Move into decorator. - if (_ioTraceLog.IsDebugEnabled) - { - _ioTraceLog.Debug(String.Format("READ {0}", result)); - } - - return result; - } - - public IAsyncResult BeginRead(AsyncCallback callback, object state) - { - return _lowerChannel.BeginRead(callback, state); - } - - public ByteBuffer EndRead(IAsyncResult result) - { - ByteBuffer buffer = _lowerChannel.EndRead(result); - if ( _ioTraceLog.IsDebugEnabled ) - { - _ioTraceLog.Debug(String.Format("READ {0}", buffer)); - } - return buffer; - } - - public void Write(ByteBuffer buffer) - { - // TODO: Move into decorator. - if (_ioTraceLog.IsDebugEnabled) - { - _ioTraceLog.Debug(String.Format("WRITE {0}", buffer)); - } - - _lowerChannel.Write(buffer); - } - - public IAsyncResult BeginWrite(ByteBuffer buffer, AsyncCallback callback, object state) - { - if ( _ioTraceLog.IsDebugEnabled ) - { - _ioTraceLog.Debug(String.Format("WRITE {0}", buffer)); - } - return _lowerChannel.BeginWrite(buffer, callback, state); - } - - public void EndWrite(IAsyncResult result) - { - _lowerChannel.EndWrite(result); - } - } -} +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using log4net; +using Apache.Qpid.Buffer; + +namespace Apache.Qpid.Client.Transport.Socket.Blocking +{ + class ByteChannel : IByteChannel + { + // Warning: don't use this log for regular logging. + private static readonly ILog _ioTraceLog = LogManager.GetLogger("TRACE.Qpid.Client.ByteChannel"); + + private IByteChannel _lowerChannel; + + public ByteChannel(IByteChannel lowerChannel) + { + _lowerChannel = lowerChannel; + } + + public ByteBuffer Read() + { + ByteBuffer result = _lowerChannel.Read(); + + // TODO: Move into decorator. + if (_ioTraceLog.IsDebugEnabled) + { + _ioTraceLog.Debug(String.Format("READ {0}", result)); + } + + return result; + } + + public IAsyncResult BeginRead(AsyncCallback callback, object state) + { + return _lowerChannel.BeginRead(callback, state); + } + + public ByteBuffer EndRead(IAsyncResult result) + { + ByteBuffer buffer = _lowerChannel.EndRead(result); + if ( _ioTraceLog.IsDebugEnabled ) + { + _ioTraceLog.Debug(String.Format("READ {0}", buffer)); + } + return buffer; + } + + public void Write(ByteBuffer buffer) + { + // TODO: Move into decorator. + if (_ioTraceLog.IsDebugEnabled) + { + _ioTraceLog.Debug(String.Format("WRITE {0}", buffer)); + } + + _lowerChannel.Write(buffer); + } + + public IAsyncResult BeginWrite(ByteBuffer buffer, AsyncCallback callback, object state) + { + if ( _ioTraceLog.IsDebugEnabled ) + { + _ioTraceLog.Debug(String.Format("WRITE {0}", buffer)); + } + return _lowerChannel.BeginWrite(buffer, callback, state); + } + + public void EndWrite(IAsyncResult result) + { + _lowerChannel.EndWrite(result); + } + } +} Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ByteChannel.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ISocketConnector.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ISocketConnector.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ISocketConnector.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ISocketConnector.cs Thu Dec 3 23:55:48 2009 @@ -1,34 +1,34 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System; -using System.IO; -using Apache.Qpid.Client.Qms; - -namespace Apache.Qpid.Client.Transport.Socket.Blocking -{ - interface ISocketConnector : IDisposable - { - string LocalEndpoint { get; } - Stream Connect(IBrokerInfo broker); - } -} - - +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System; +using System.IO; +using Apache.Qpid.Client.Qms; + +namespace Apache.Qpid.Client.Transport.Socket.Blocking +{ + interface ISocketConnector : IDisposable + { + string LocalEndpoint { get; } + Stream Connect(IBrokerInfo broker); + } +} + + Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/ISocketConnector.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SocketConnector.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SocketConnector.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SocketConnector.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SocketConnector.cs Thu Dec 3 23:55:48 2009 @@ -1,71 +1,71 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System.IO; -using System.Net; -using System.Net.Sockets; -using Apache.Qpid.Client.Qms; - -namespace Apache.Qpid.Client.Transport.Socket.Blocking -{ - /// - /// Implements a TCP connection over regular sockets. - /// - class SocketConnector : ISocketConnector - { - private MyTcpClient _tcpClient; - - public string LocalEndpoint - { - get { return _tcpClient.LocalEndpoint.ToString(); } - } - - public Stream Connect(IBrokerInfo broker) - { - _tcpClient = new MyTcpClient(broker.Host, broker.Port); - return _tcpClient.GetStream(); - } - - public void Dispose() - { - if ( _tcpClient != null ) - { - _tcpClient.Close(); - _tcpClient = null; - } - } - - class MyTcpClient : TcpClient - { - public MyTcpClient(string host, int port) - : base(host, port) - { - } - - public EndPoint LocalEndpoint - { - get { return Client.LocalEndPoint; } - } - } - - } -} - - +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System.IO; +using System.Net; +using System.Net.Sockets; +using Apache.Qpid.Client.Qms; + +namespace Apache.Qpid.Client.Transport.Socket.Blocking +{ + /// + /// Implements a TCP connection over regular sockets. + /// + class SocketConnector : ISocketConnector + { + private MyTcpClient _tcpClient; + + public string LocalEndpoint + { + get { return _tcpClient.LocalEndpoint.ToString(); } + } + + public Stream Connect(IBrokerInfo broker) + { + _tcpClient = new MyTcpClient(broker.Host, broker.Port); + return _tcpClient.GetStream(); + } + + public void Dispose() + { + if ( _tcpClient != null ) + { + _tcpClient.Close(); + _tcpClient = null; + } + } + + class MyTcpClient : TcpClient + { + public MyTcpClient(string host, int port) + : base(host, port) + { + } + + public EndPoint LocalEndpoint + { + get { return Client.LocalEndPoint; } + } + } + + } +} + + Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SocketConnector.cs ------------------------------------------------------------------------------ svn:eol-style = native Modified: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SslSocketConnector.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SslSocketConnector.cs?rev=886998&r1=886997&r2=886998&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SslSocketConnector.cs (original) +++ qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SslSocketConnector.cs Thu Dec 3 23:55:48 2009 @@ -1,107 +1,107 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -using System.IO; -using System.Net; -using log4net; -using Apache.Qpid.Client.Qms; -using Org.Mentalis.Security.Ssl; -using MCertificate = Org.Mentalis.Security.Certificates.Certificate; -using MCertificateChain = Org.Mentalis.Security.Certificates.CertificateChain; - -namespace Apache.Qpid.Client.Transport.Socket.Blocking -{ - /// - /// Implements a TLS v1.0 connection using the Mentalis.org library - /// - /// - /// It would've been easier to implement this at the StreamFilter - /// level, but unfortunately the Mentalis library doesn't support - /// a passthrough SSL stream class and is tied directly - /// to socket-like classes. - /// - class SslSocketConnector : ISocketConnector - { - private static ILog _logger = LogManager.GetLogger(typeof(SslSocketConnector)); - private MyTcpClient _tcpClient; - - public string LocalEndpoint - { - get { return _tcpClient.LocalEndpoint.ToString(); } - } - - public Stream Connect(IBrokerInfo broker) - { - MCertificate cert = GetClientCert(broker); - SecurityOptions options = new SecurityOptions( - SecureProtocol.Tls1, cert, ConnectionEnd.Client - ); - if ( broker.SslOptions != null - && broker.SslOptions.IgnoreValidationErrors ) - { - _logger.Warn("Ignoring any certificate validation errors during SSL handshake..."); - options.VerificationType = CredentialVerification.None; - } - - _tcpClient = new MyTcpClient(broker.Host, broker.Port, options); - return _tcpClient.GetStream(); - } - - public void Dispose() - { - if ( _tcpClient != null ) - { - _tcpClient.Close(); - _tcpClient = null; - } - } - - private static MCertificate GetClientCert(IBrokerInfo broker) - { - // if a client certificate is configured, - // use that to enable mutual authentication - MCertificate cert = null; - if ( broker.SslOptions != null - && broker.SslOptions.ClientCertificate != null ) - { - cert = MCertificate.CreateFromX509Certificate( - broker.SslOptions.ClientCertificate - ); - _logger.DebugFormat("Using Client Certificate for SSL '{0}'", cert.ToString(true)); - } - return cert; - } - - class MyTcpClient : SecureTcpClient - { - public MyTcpClient(string host, int port, SecurityOptions options) - : base(host, port, options) - { - } - - public EndPoint LocalEndpoint - { - get { return Client.LocalEndPoint; } - } - - } - - } -} +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using System.IO; +using System.Net; +using log4net; +using Apache.Qpid.Client.Qms; +using Org.Mentalis.Security.Ssl; +using MCertificate = Org.Mentalis.Security.Certificates.Certificate; +using MCertificateChain = Org.Mentalis.Security.Certificates.CertificateChain; + +namespace Apache.Qpid.Client.Transport.Socket.Blocking +{ + /// + /// Implements a TLS v1.0 connection using the Mentalis.org library + /// + /// + /// It would've been easier to implement this at the StreamFilter + /// level, but unfortunately the Mentalis library doesn't support + /// a passthrough SSL stream class and is tied directly + /// to socket-like classes. + /// + class SslSocketConnector : ISocketConnector + { + private static ILog _logger = LogManager.GetLogger(typeof(SslSocketConnector)); + private MyTcpClient _tcpClient; + + public string LocalEndpoint + { + get { return _tcpClient.LocalEndpoint.ToString(); } + } + + public Stream Connect(IBrokerInfo broker) + { + MCertificate cert = GetClientCert(broker); + SecurityOptions options = new SecurityOptions( + SecureProtocol.Tls1, cert, ConnectionEnd.Client + ); + if ( broker.SslOptions != null + && broker.SslOptions.IgnoreValidationErrors ) + { + _logger.Warn("Ignoring any certificate validation errors during SSL handshake..."); + options.VerificationType = CredentialVerification.None; + } + + _tcpClient = new MyTcpClient(broker.Host, broker.Port, options); + return _tcpClient.GetStream(); + } + + public void Dispose() + { + if ( _tcpClient != null ) + { + _tcpClient.Close(); + _tcpClient = null; + } + } + + private static MCertificate GetClientCert(IBrokerInfo broker) + { + // if a client certificate is configured, + // use that to enable mutual authentication + MCertificate cert = null; + if ( broker.SslOptions != null + && broker.SslOptions.ClientCertificate != null ) + { + cert = MCertificate.CreateFromX509Certificate( + broker.SslOptions.ClientCertificate + ); + _logger.DebugFormat("Using Client Certificate for SSL '{0}'", cert.ToString(true)); + } + return cert; + } + + class MyTcpClient : SecureTcpClient + { + public MyTcpClient(string host, int port, SecurityOptions options) + : base(host, port, options) + { + } + + public EndPoint LocalEndpoint + { + get { return Client.LocalEndPoint; } + } + + } + + } +} Propchange: qpid/trunk/qpid/dotnet/Qpid.Client/Client/Transport/Socket/Blocking/SslSocketConnector.cs ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscribe@qpid.apache.org