~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/ssl/context_service.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2008-07-02 10:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080702104621-jzx3pfke9lkcxfxn
Tags: upstream-0.13.1
ImportĀ upstreamĀ versionĀ 0.13.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// context_service.hpp
 
3
// ~~~~~~~~~~~~~~~~~~~
 
4
//
 
5
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
 
6
// Copyright (c) 2005-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 
7
//
 
8
// Distributed under the Boost Software License, Version 1.0. (See accompanying
 
9
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
10
//
 
11
 
 
12
#ifndef ASIO_SSL_CONTEXT_SERVICE_HPP
 
13
#define ASIO_SSL_CONTEXT_SERVICE_HPP
 
14
 
 
15
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
 
16
# pragma once
 
17
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
 
18
 
 
19
#include "asio/detail/push_options.hpp"
 
20
 
 
21
#include "asio/detail/push_options.hpp"
 
22
#include <string>
 
23
#include <boost/noncopyable.hpp>
 
24
#include "asio/detail/pop_options.hpp"
 
25
 
 
26
#include "asio/error.hpp"
 
27
#include "asio/io_service.hpp"
 
28
#include "asio/detail/service_base.hpp"
 
29
#include "asio/ssl/context_base.hpp"
 
30
#include "asio/ssl/detail/openssl_context_service.hpp"
 
31
 
 
32
namespace asio {
 
33
namespace ssl {
 
34
 
 
35
/// Default service implementation for a context.
 
36
class context_service
 
37
#if defined(GENERATING_DOCUMENTATION)
 
38
  : public asio::io_service::service
 
39
#else
 
40
  : public asio::detail::service_base<context_service>
 
41
#endif
 
42
{
 
43
private:
 
44
  // The type of the platform-specific implementation.
 
45
  typedef detail::openssl_context_service service_impl_type;
 
46
 
 
47
public:
 
48
#if defined(GENERATING_DOCUMENTATION)
 
49
  /// The unique service identifier.
 
50
  static asio::io_service::id id;
 
51
#endif
 
52
 
 
53
  /// The type of the context.
 
54
#if defined(GENERATING_DOCUMENTATION)
 
55
  typedef implementation_defined impl_type;
 
56
#else
 
57
  typedef service_impl_type::impl_type impl_type;
 
58
#endif
 
59
 
 
60
  /// Constructor.
 
61
  explicit context_service(asio::io_service& io_service)
 
62
    : asio::detail::service_base<context_service>(io_service),
 
63
      service_impl_(asio::use_service<service_impl_type>(io_service))
 
64
  {
 
65
  }
 
66
 
 
67
  /// Destroy all user-defined handler objects owned by the service.
 
68
  void shutdown_service()
 
69
  {
 
70
  }
 
71
 
 
72
  /// Return a null context implementation.
 
73
  impl_type null() const
 
74
  {
 
75
    return service_impl_.null();
 
76
  }
 
77
 
 
78
  /// Create a new context implementation.
 
79
  void create(impl_type& impl, context_base::method m)
 
80
  {
 
81
    service_impl_.create(impl, m);
 
82
  }
 
83
 
 
84
  /// Destroy a context implementation.
 
85
  void destroy(impl_type& impl)
 
86
  {
 
87
    service_impl_.destroy(impl);
 
88
  }
 
89
 
 
90
  /// Set options on the context.
 
91
  asio::error_code set_options(impl_type& impl,
 
92
      context_base::options o, asio::error_code& ec)
 
93
  {
 
94
    return service_impl_.set_options(impl, o, ec);
 
95
  }
 
96
 
 
97
  /// Set peer verification mode.
 
98
  asio::error_code set_verify_mode(impl_type& impl,
 
99
      context_base::verify_mode v, asio::error_code& ec)
 
100
  {
 
101
    return service_impl_.set_verify_mode(impl, v, ec);
 
102
  }
 
103
 
 
104
  /// Load a certification authority file for performing verification.
 
105
  asio::error_code load_verify_file(impl_type& impl,
 
106
      const std::string& filename, asio::error_code& ec)
 
107
  {
 
108
    return service_impl_.load_verify_file(impl, filename, ec);
 
109
  }
 
110
 
 
111
  /// Add a directory containing certification authority files to be used for
 
112
  /// performing verification.
 
113
  asio::error_code add_verify_path(impl_type& impl,
 
114
      const std::string& path, asio::error_code& ec)
 
115
  {
 
116
    return service_impl_.add_verify_path(impl, path, ec);
 
117
  }
 
118
 
 
119
  /// Use a certificate from a file.
 
120
  asio::error_code use_certificate_file(impl_type& impl,
 
121
      const std::string& filename, context_base::file_format format,
 
122
      asio::error_code& ec)
 
123
  {
 
124
    return service_impl_.use_certificate_file(impl, filename, format, ec);
 
125
  }
 
126
 
 
127
  /// Use a certificate chain from a file.
 
128
  asio::error_code use_certificate_chain_file(impl_type& impl,
 
129
      const std::string& filename, asio::error_code& ec)
 
130
  {
 
131
    return service_impl_.use_certificate_chain_file(impl, filename, ec);
 
132
  }
 
133
 
 
134
  /// Use a private key from a file.
 
135
  asio::error_code use_private_key_file(impl_type& impl,
 
136
      const std::string& filename, context_base::file_format format,
 
137
      asio::error_code& ec)
 
138
  {
 
139
    return service_impl_.use_private_key_file(impl, filename, format, ec);
 
140
  }
 
141
 
 
142
  /// Use an RSA private key from a file.
 
143
  asio::error_code use_rsa_private_key_file(impl_type& impl,
 
144
      const std::string& filename, context_base::file_format format,
 
145
      asio::error_code& ec)
 
146
  {
 
147
    return service_impl_.use_rsa_private_key_file(impl, filename, format, ec);
 
148
  }
 
149
 
 
150
  /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
 
151
  asio::error_code use_tmp_dh_file(impl_type& impl,
 
152
      const std::string& filename, asio::error_code& ec)
 
153
  {
 
154
    return service_impl_.use_tmp_dh_file(impl, filename, ec);
 
155
  }
 
156
 
 
157
  /// Set the password callback.
 
158
  template <typename PasswordCallback>
 
159
  asio::error_code set_password_callback(impl_type& impl,
 
160
      PasswordCallback callback, asio::error_code& ec)
 
161
  {
 
162
    return service_impl_.set_password_callback(impl, callback, ec);
 
163
  }
 
164
 
 
165
private:
 
166
  // The service that provides the platform-specific implementation.
 
167
  service_impl_type& service_impl_;
 
168
};
 
169
 
 
170
} // namespace ssl
 
171
} // namespace asio
 
172
 
 
173
#include "asio/detail/pop_options.hpp"
 
174
 
 
175
#endif // ASIO_SSL_CONTEXT_SERVICE_HPP