git.fiddlerwoaroof.com
Browse code

wiring

Greg Wiley authored on 04/05/2017 18:37:45
Showing 6 changed files
... ...
@@ -2,7 +2,8 @@ CXXFLAGS += -fPIC -fno-stack-protector -std=c++11
2 2
 CFLAGS += -fPIC -fno-stack-protector
3 3
 LDFLAGS = -lpam
4 4
 
5
-INTEGRATION_OBJS = sys_syslog.o sys_fstream.o sys_unistd.o sys_pwd.o sys_pam.o dual_control_integrate.o
5
+INTEGRATION_OBJS = sys_syslog.o sys_fstream.o sys_unistd.o sys_pwd.o sys_pam.o \
6
+                   sys_stdlib.o
6 7
 OBJS = dual_control.o request.o validator.o conversation.o user.o token.o logger.o session.o installer.o
7 8
 TEST_SOURCES := $(wildcard *_test.cc)
8 9
 TESTS := $(patsubst %.cc,%.out,$(TEST_SOURCES))
... ...
@@ -20,12 +21,12 @@ version:
20 21
 	@echo COMPILER VERSION --------------------------------
21 22
 	$(CXX) --version
22 23
 
23
-dual_control.a: $(OBJS) $(INTEGRATION_OBJS)
24
+dual_control.a: dual_control.o $(OBJS) $(INTEGRATION_OBJS)
24 25
 	ar rvs $@ $^
25 26
 	ranlib $@
26 27
 
27
-dual_control: dual_control_tool.cc
28
-	$(CXX) $(CXXFLAGS) $(CPPFLAGS)  -o $@ $^
28
+dual_control: dual_control_tool.o $(OBJS) $(INTEGRATION_OBJS)
29
+	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)  -o $@ $^
29 30
 
30 31
 
31 32
 .PHONY: clean
32 33
Binary files a/dual_control and b/dual_control differ
... ...
@@ -13,10 +13,33 @@
13 13
 #include <iostream>
14 14
 
15 15
 #include "installer.h"
16
+#include "generator.h"
17
+#include "sys_stdlib.h"
18
+#include "user.h"
19
+#include "sys_unistd.h"
20
+#include "sys_pwd.h"
21
+#include "token.h"
22
+#include "sys_fstream.h"
23
+
24
+namespace {
25
+    installer init() {
26
+        fstreams fstreams(fstreams::create());
27
+        tokens tokens(tokens::create(fstreams));
28
+        pwd pwd(pwd::create());
29
+        unistd unistd(unistd::create());
30
+        directory directory(directory::create(unistd, pwd));
31
+        stdlib stdlib(stdlib::get());
32
+        generator generator{make_generator(stdlib)};
33
+        installer installer(installer::create(tokens, unistd,
34
+                            directory, generator));
35
+
36
+        return installer;
37
+    }
38
+}
16 39
 
17 40
 int main (int argc, char *argv[])
18 41
 {
19
-    installer tool;
42
+    installer tool(init());
20 43
     std::string generated_token = tool.install_token();
21 44
     std::cout << generated_token << std::endl;
22 45
     return 0;
... ...
@@ -16,6 +16,7 @@
16 16
 #include "token.h"
17 17
 #include "sys_unistd.h"
18 18
 #include "user.h"
19
+#include "generator.h"
19 20
 
20 21
 namespace
21 22
 {
... ...
@@ -29,7 +30,7 @@ private:
29 30
     generator generator_;
30 31
 public:
31 32
     impl (const tokens &tokens, const unistd &unistd,
32
-          const directory &directory, const installer_ifc::generator &generator) :
33
+          const directory &directory, const generator &generator) :
33 34
         tokens_ (tokens), unistd_ (unistd), directory_ (directory),
34 35
         generator_ (generator) {}
35 36
     std::string install_token() const override
... ...
@@ -58,7 +59,7 @@ public:
58 59
 }
59 60
 
60 61
 installer installer::create (const tokens &tokens, const unistd &unistd,
61
-                             const directory &directory, const installer_ifc::generator &generator)
62
+                             const directory &directory, const generator &generator)
62 63
 {
63 64
     return installer (std::make_shared<impl> (tokens, unistd, directory,
64 65
                       generator));
... ...
@@ -19,11 +19,11 @@
19 19
 #include "token.h"
20 20
 #include "sys_unistd.h"
21 21
 #include "user.h"
22
+#include "generator.h"
22 23
 
23 24
 class installer_ifc
24 25
 {
25 26
 public:
26
-    using generator = std::function<std::string()>;
27 27
     virtual std::string install_token() const
28 28
     {
29 29
         return "123456";
... ...
@@ -44,7 +44,7 @@ public:
44 44
         return delegate_->install_token();
45 45
     }
46 46
     static installer create (const tokens &tokens, const unistd &unistd,
47
-                             const directory &directory, const installer_ifc::generator &generator);
47
+                             const directory &directory, const generator &generator);
48 48
 };
49 49
 
50 50
 #endif
... ...
@@ -81,7 +81,7 @@ int installs_token()
81 81
     tokens tokens{test_tokens};
82 82
     unistd unistd (std::make_shared<fake_unistd> (user_name));
83 83
     directory directory (std::make_shared<fake_directory> (user_name));
84
-    installer_ifc::generator generator = [&] { return token; };
84
+    generator generator = [&] { return token; };
85 85
 
86 86
     installer installer = installer::create (tokens, unistd, directory,
87 87
                           generator);
... ...
@@ -104,7 +104,7 @@ int unistd_does_not_find_user_name()
104 104
     tokens tokens{test_tokens};
105 105
     unistd unistd (std::make_shared<fail_unistd>());
106 106
     directory directory (std::make_shared<fake_directory> (user_name));
107
-    installer_ifc::generator generator = [&] { return token; };
107
+    generator generator = [&] { return token; };
108 108
 
109 109
     installer installer = installer::create (tokens, unistd, directory,
110 110
                           generator);
... ...
@@ -127,7 +127,7 @@ int directory_finds_no_user_info()
127 127
     tokens tokens{test_tokens};
128 128
     unistd unistd (std::make_shared<fake_unistd> (user_name));
129 129
     directory directory (std::make_shared<fake_directory> ("not the user"));
130
-    installer_ifc::generator generator = [&] { return token; };
130
+    generator generator = [&] { return token; };
131 131
 
132 132
     installer installer = installer::create (tokens, unistd, directory,
133 133
                           generator);