PageRenderTime 36ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/MSNPSHARP_DEV/MSNPSharp/ProxySocket/ProxyException.cs

http://msnp-sharp.googlecode.com/
C# | 82 lines | 32 code | 2 blank | 48 comment | 0 complexity | 2ecd7e79f0700194e38a2041e9ffe098 MD5 | raw file
  1. /*
  2. Copyright Š 2002, The KPD-Team
  3. All rights reserved.
  4. http://www.mentalis.org/
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. - Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. - Neither the name of the KPD-Team, nor the names of its contributors
  11. may be used to endorse or promote products derived from this
  12. software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  16. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  17. THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  18. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  20. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  22. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  24. OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. using System;
  27. namespace Org.Mentalis.Network.ProxySocket {
  28. /// <summary>
  29. /// The exception that is thrown when a proxy error occurs.
  30. /// </summary>
  31. public class ProxyException : Exception {
  32. /// <summary>
  33. /// Initializes a new instance of the ProxyException class.
  34. /// </summary>
  35. public ProxyException() : this("An error Occurred while talking to the proxy server.") {}
  36. /// <summary>
  37. /// Initializes a new instance of the ProxyException class.
  38. /// </summary>
  39. /// <param name="message">The message that describes the error.</param>
  40. public ProxyException(string message) : base(message) {}
  41. /// <summary>
  42. /// Initializes a new instance of the ProxyException class.
  43. /// </summary>
  44. /// <param name="socks5Error">The error number returned by a SOCKS5 server.</param>
  45. public ProxyException(int socks5Error) : this(ProxyException.Socks5ToString(socks5Error)) {}
  46. /// <summary>
  47. /// Converts a SOCKS5 error number to a human readable string.
  48. /// </summary>
  49. /// <param name="socks5Error">The error number returned by a SOCKS5 server.</param>
  50. /// <returns>A string representation of the specified SOCKS5 error number.</returns>
  51. public static string Socks5ToString(int socks5Error) {
  52. switch(socks5Error) {
  53. case 0:
  54. return "Connection succeeded.";
  55. case 1:
  56. return "General SOCKS server failure.";
  57. case 2:
  58. return "Connection not allowed by ruleset.";
  59. case 3:
  60. return "Network unreachable.";
  61. case 4:
  62. return "Host unreachable.";
  63. case 5:
  64. return "Connection refused.";
  65. case 6:
  66. return "TTL expired.";
  67. case 7:
  68. return "Command not supported.";
  69. case 8:
  70. return "Address type not supported.";
  71. default:
  72. return "Unspecified SOCKS error.";
  73. }
  74. }
  75. }
  76. }