libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_to_mit_main_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2016 by J.M.McGuiness, isimud@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges {
20 
21 template<class Link> inline int
22 fix_to_mit_link<Link>::main(int argc, char const * const *argv) noexcept(true) {
23  return base_t::main<link_t>(
24  argc,
25  argv,
26  MIT::create_program_options<link_t>(create_program_options()),
27  [](boost::program_options::variables_map const &vm) {
28  using conn_pol_t=typename link_t::exchg_link_t::conn_pol_t;
29  using ref_data_t=typename link_t::client_link_t::proc_rules_t::ref_data;
30  using exchange_msg_details_t=typename link_t::exchg_link_t::exchange_msg_details_t;
31 
32  std::string const MIC_code=[]() {
33  std::ostringstream ss;
34  common::mic_codes::to_stream<exchange_msg_details_t::MIC_code>(ss);
35  return ss.str();
36  }();
37  std::ifstream ref_data_src(vm[(MIC_code+"_ref_data").c_str()].as<std::string>().c_str());
38  std::shared_ptr<ref_data_t> ref_data(std::make_shared<ref_data_t>(ref_data_src));
39 
40  const std::string user(vm[(MIC_code+"_username").c_str()].as<std::string>());
41  typename exchange_msg_details_t::UserName_t user_conv{};
42  std::memcpy(user_conv.data(), user.data(), std::min(user_conv.size(), user.size()));
43  const std::string pass(vm[(MIC_code+"_password").c_str()].as<std::string>());
44  typename exchange_msg_details_t::Password_t pass_conv{};
45  std::memcpy(pass_conv.data(), pass.data(), std::min(pass_conv.size(), pass.size()));
46  const std::string new_pass(vm[(MIC_code+"_new_password").c_str()].as<std::string>());
47  typename exchange_msg_details_t::Password_t new_pass_conv{};
48  std::memcpy(new_pass_conv.data(), new_pass.data(), std::min(new_pass_conv.size(), new_pass.size()));
49  const std::string reason(vm[(MIC_code+"_logout_reason").c_str()].as<std::string>());
50  MIT::common::Reason_t reason_conv{};
51  std::memcpy(reason_conv.data(), reason.data(), std::min(reason_conv.size(), reason.size()));
52  return std::make_tuple(
53  typename link_t::client_link_t::ctor_args{
54  boost::asio::ip::address_v4::from_string(vm["client_address"].as<std::string>()),
55  vm["client_port"].as<unsigned short>(),
56  typename link_t::client_link_t::proc_rules_t(*ref_data)
57  },
58  conn_pol_t(
59  typename conn_pol_t::gateways_t(
60  std::make_pair(boost::asio::ip::address_v4::from_string(vm[(MIC_code+"_primary_gateway_address").c_str()].as<std::string>()), vm[(MIC_code+"_primary_gateway_port").c_str()].as<unsigned short>()),
61  std::make_pair(boost::asio::ip::address_v4::from_string(vm[(MIC_code+"_secondary_gateway_address").c_str()].as<std::string>()), vm[(MIC_code+"_secondary_gateway_port").c_str()].as<unsigned short>())
62  ),
63  typename conn_pol_t::logon_args_t{
64  user_conv,
65  pass_conv,
66  new_pass_conv
67  },
68  MIT::common::logoff_args_t{
69  reason_conv
70  }
71  ),
72  typename link_t::exchg_to_client_proc_rules_t(*ref_data),
73  ref_data
74  );
75  }
76  );
77 }
78 
79 } } }