aboutsummaryrefslogtreecommitdiff
path: root/mod/external-handler.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-08-23 22:29:35 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-08-28 21:46:41 +0300
commit8a094bb0481a9c53646cc15db2e8acecafc3d10c (patch)
tree4fd7012b6a26eb852d42fba8b52bfcf8f1cf2fdd /mod/external-handler.hxx
parent7e0e141273032c7afc1a9129512aa42c672fcf5d (diff)
Add basic support for CI request handling
Diffstat (limited to 'mod/external-handler.hxx')
-rw-r--r--mod/external-handler.hxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/mod/external-handler.hxx b/mod/external-handler.hxx
new file mode 100644
index 0000000..45de711
--- /dev/null
+++ b/mod/external-handler.hxx
@@ -0,0 +1,52 @@
+// file : mod/external-handler.hxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef MOD_EXTERNAL_HANDLER_HXX
+#define MOD_EXTERNAL_HANDLER_HXX
+
+#include <libbutl/manifest-parser.mxx>
+
+#include <libbrep/types.hxx>
+#include <libbrep/utility.hxx>
+
+#include <mod/diagnostics.hxx>
+
+namespace brep
+{
+ // Utility for running external handler programs.
+ //
+ namespace external_handler
+ {
+ // Run an external handler program and, if it exited normally with the
+ // zero exit status, return the result manifest it is expected to write to
+ // stdout, containing at least the HTTP status value. Otherwise, log an
+ // error and return nullopt. Redirect the program stderr to the web server
+ // error log.
+ //
+ // If the timeout (in seconds) is not zero and the handler program does
+ // not exit in the allotted time, then it is killed and its termination is
+ // treated as abnormal.
+ //
+ // Note that warnings can be logged regardless of the program success. If
+ // the trace argument is not NULL, then trace records are also logged.
+ //
+ struct result_manifest
+ {
+ uint16_t status;
+ vector<butl::manifest_name_value> values; // Note: all values, including
+ // status.
+ };
+
+ optional<result_manifest>
+ run (const path& handler,
+ const strings& args,
+ const dir_path& data_dir,
+ size_t timeout,
+ const basic_mark& error,
+ const basic_mark& warn,
+ const basic_mark* trace);
+ }
+}
+
+#endif // MOD_EXTERNAL_HANDLER_HXX