1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
/*
* Copyright (C) 2017 Tommi Maekitalo
*
*/
#include <iostream>
#include <cxxtools/http/server.h>
#include <cxxtools/xmlrpc/service.h>
#include <cxxtools/sslcertificate.h>
#include <cxxtools/eventloop.h>
#include <cxxtools/arg.h>
#include <cxxtools/log.h>
bool doAccept(const cxxtools::SslCertificate& cert)
{
std::cout << "cert \"" << cert.getSubject() << "\" accepted" << std::endl;
return true;
}
bool noAccept(const cxxtools::SslCertificate& cert)
{
std::cout << "cert \"" << cert.getSubject() << "\" not accepted" << std::endl;
return false;
}
std::string echo(const std::string& msg)
{
return msg;
}
int add(int a, int b)
{
return a + b;
}
int main(int argc, char* argv[])
{
try
{
log_init();
cxxtools::Arg<std::string> ip(argc, argv, 'i');
cxxtools::Arg<unsigned short> port(argc, argv, 'j', 7002);
cxxtools::Arg<std::string> cert(argc, argv, 'c');
cxxtools::Arg<std::string> ca(argc, argv, 'C', "ca.crt");
cxxtools::Arg<bool> deny(argc, argv, 'd');
cxxtools::Arg<bool> nodeny(argc, argv, 'D');
cxxtools::EventLoop loop;
cxxtools::http::Server server(loop, ip, port, cert, 2, ca);
cxxtools::xmlrpc::Service service;
service.registerFunction("echo", echo);
service.registerFunction("add", add);
server.addService("/xmlrpc", service);
if (deny)
cxxtools::connect(server.acceptSslCertificate(), noAccept);
else if (nodeny)
cxxtools::connect(server.acceptSslCertificate(), doAccept);
loop.run();
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}
|