diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-10-15 21:08:04 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-10-17 15:02:42 +0300 |
commit | de91921561092689369b56c54950474e0a86e66f (patch) | |
tree | a9949058021d911db1106b1a2e4d9e0e9281de16 /openssl/protocol.hxx | |
parent | fb65c93daaf369157bd712f2c4c20161c4840b94 (diff) |
Add implementation
Diffstat (limited to 'openssl/protocol.hxx')
-rw-r--r-- | openssl/protocol.hxx | 74 |
1 files changed, 74 insertions, 0 deletions
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 <openssl/types.hxx> +#include <openssl/utility.hxx> + +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<char> input; + + // Create an empty request, normally before reading it from a stream. + // + request () = default; + + request (string c, strings a, vector<char> 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<char> i): cmd (move (c)), input (move (i)) {} + }; + + class response + { + public: + uint8_t status; + vector<char> output; + string error; + + response (uint8_t s, vector<char> o, string e) + : status (s), output (move (o)), error (move (e)) {} + + // Success. + // + response (): status (0) {} + + explicit + response (vector<char> 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 |