From de91921561092689369b56c54950474e0a86e66f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 15 Oct 2018 21:08:04 +0300 Subject: Add implementation --- openssl/protocol.hxx | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 openssl/protocol.hxx (limited to 'openssl/protocol.hxx') diff --git a/openssl/protocol.hxx b/openssl/protocol.hxx new file mode 100644 index 0000000..c676a8b --- /dev/null +++ b/openssl/protocol.hxx @@ -0,0 +1,74 @@ +// file : openssl/protocol.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef OPENSSL_PROTOCOL_HXX +#define OPENSSL_PROTOCOL_HXX + +#include +#include + +namespace openssl +{ + // Simple client/agent communication protocol. + // + + // Return the file descriptor connected to the agent's Unix-domain socket. + // Throw io_error on the underlying OS error. + // + auto_fd + connect (const path& socket); + + class request + { + public: + string cmd; + strings args; // Shouldn't contain NULL characters. + vector input; + + // Create an empty request, normally before reading it from a stream. + // + request () = default; + + request (string c, strings a, vector i) + : cmd (move (c)), args (move (a)), input (move (i)) {} + + explicit + request (string c): cmd (move (c)) {} + request (string c, strings a): cmd (move (c)), args (move (a)) {} + request (string c, vector i): cmd (move (c)), input (move (i)) {} + }; + + class response + { + public: + uint8_t status; + vector output; + string error; + + response (uint8_t s, vector o, string e) + : status (s), output (move (o)), error (move (e)) {} + + // Success. + // + response (): status (0) {} + + explicit + response (vector o): status (0), output (move (o)) {} + + // Error. + // + explicit + response (string e, uint8_t s = 1): status (s), error (move (e)) {} + }; + + // The stream's exception mask should have at least failbit and badbit set + // (that is the default for fdstreams). + // + ostream& operator<< (ostream&, const request&); + istream& operator>> (istream&, request&); + ostream& operator<< (ostream&, const response&); + istream& operator>> (istream&, response&); +} + +#endif // OPENSSL_PROTOCOL_HXX -- cgit v1.1