IBR-DTNSuite  0.12
EMailSmtpService.h
Go to the documentation of this file.
1 /*
2  * EMailSmtpService.h
3  *
4  * Copyright (C) 2013 IBR, TU Braunschweig
5  *
6  * Written-by: Björn Gernert <mail@bjoern-gernert.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef EMAILSMTPSERVICE_H_
23 #define EMAILSMTPSERVICE_H_
24 
25 #include "Configuration.h"
26 #include "core/Node.h"
27 #include "net/BundleTransfer.h"
28 #include "storage/BundleStorage.h"
29 #include "ibrdtn/data/BundleID.h"
30 
32 #include <ibrcommon/thread/Queue.h>
33 #include <vmime/vmime.hpp>
34 
35 namespace dtn
36 {
37  namespace net
38  {
40  {
41  public:
46  class Task {
47  public:
55  Task(const dtn::core::Node &node,
56  const dtn::net::BundleTransfer &job,
57  std::string recipient);
58 
62  virtual ~Task();
63 
67  const dtn::core::Node getNode();
68 
73 
77  std::string getRecipient();
78 
83  bool checkForReturningMail();
84 
85  private:
86 
90  const dtn::core::Node& _node;
91 
95  const dtn::net::BundleTransfer _job;
96 
100  std::string _recipient;
101 
105  size_t _timesChecked;
106  };
107 
111  static EMailSmtpService& getInstance();
112 
118  void queueTask(Task *t);
119 
125  void submitNow(Task *t);
126 
130  void submitQueue();
131 
135  void run() throw ();
136 
140  void __cancellation() throw ();
141 
142  private:
146  class TimeoutHandler : public vmime::net::timeoutHandler
147  {
148  public:
149  bool isTimeOut();
150  void resetTimeOut();
151  bool handleTimeOut();
152  private:
153  unsigned int getTime()
154  {
155  return vmime::platform::getHandler()->getUnixTime();
156  }
157  unsigned int last;
158  };
159 
163  class TimeoutHandlerFactory : public vmime::net::timeoutHandlerFactory
164  {
165  public:
166  vmime::ref<vmime::net::timeoutHandler> create()
167  {
168  return vmime::create<TimeoutHandler>();
169  }
170  };
171 
176 
180  virtual ~EMailSmtpService();
181 
185  const dtn::daemon::Configuration::EMail& _config;
186 
190  dtn::storage::BundleStorage& _storage;
191 
195  vmime::ref<vmime::security::cert::defaultCertificateVerifier> _certificateVerifier;
196 
200  vmime::ref<vmime::net::transport> _transport;
201 
206 
210  ibrcommon::Mutex _threadMutex;
211 
215  static bool _run;
216 
220  void loadCerificates();
221 
230  vmime::ref<vmime::security::cert::X509Certificate> loadCertificateFromFile(const std::string &path);
231 
237  void submit(Task *t);
238 
243  void connect();
244 
249  void disconnect();
250 
257  bool isConnected();
258 
268  unsigned int getProcFlags(const dtn::data::Block &block);
269 
277  std::string toString(int i);
278 
282  class InvalidCertificate : public ibrcommon::Exception {
283  public:
284  InvalidCertificate() {}
285  InvalidCertificate(std::string msg) : Exception(msg) {}
286  };
287 
288  };
289  }
290 }
291 
292 #endif /* EMAILSMTPSERVICE_H_ */