]>
Commit | Line | Data |
---|---|---|
a0c715e9 JF |
1 | #ifndef LDID_HPP |
2 | #define LDID_HPP | |
3 | ||
4 | #include <cstdlib> | |
5 | #include <map> | |
42d1472e | 6 | #include <sstream> |
a0c715e9 JF |
7 | #include <streambuf> |
8 | #include <string> | |
42d1472e | 9 | #include <vector> |
a0c715e9 JF |
10 | |
11 | namespace ldid { | |
12 | ||
e6a376fc JF |
13 | // I wish Apple cared about providing quality toolchains :/ |
14 | ||
15 | template <typename Function_> | |
16 | class Functor; | |
17 | ||
18 | template <typename Type_, typename... Args_> | |
19 | class Functor<Type_ (Args_...)> { | |
20 | public: | |
21 | virtual Type_ operator ()(Args_... args) const = 0; | |
22 | }; | |
23 | ||
24 | template <typename Function_> | |
25 | class FunctorImpl; | |
26 | ||
27 | template <typename Value_, typename Type_, typename... Args_> | |
28 | class FunctorImpl<Type_ (Value_::*)(Args_...) const> : | |
29 | public Functor<Type_ (Args_...)> | |
30 | { | |
31 | private: | |
32 | const Value_ *value_; | |
33 | ||
34 | public: | |
35 | FunctorImpl(const Value_ &value) : | |
36 | value_(&value) | |
37 | { | |
38 | } | |
39 | ||
40 | virtual Type_ operator ()(Args_... args) const { | |
41 | return (*value_)(args...); | |
42 | } | |
43 | }; | |
44 | ||
45 | template <typename Function_> | |
46 | FunctorImpl<decltype(&Function_::operator())> fun(const Function_ &value) { | |
47 | return value; | |
48 | } | |
49 | ||
23c11ee8 JF |
50 | class Folder { |
51 | public: | |
fefcecb0 | 52 | virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code) = 0; |
878260fc JF |
53 | virtual bool Look(const std::string &path) = 0; |
54 | virtual void Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code) = 0; | |
51ced023 | 55 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link) = 0; |
23c11ee8 JF |
56 | }; |
57 | ||
58 | class DiskFolder : | |
59 | public Folder | |
60 | { | |
61 | private: | |
62 | const std::string path_; | |
63 | std::map<std::string, std::string> commit_; | |
64 | ||
65 | std::string Path(const std::string &path); | |
66 | ||
51ced023 | 67 | void Find(const std::string &root, const std::string &base, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link); |
54a0f854 | 68 | |
23c11ee8 JF |
69 | public: |
70 | DiskFolder(const std::string &path); | |
71 | ~DiskFolder(); | |
72 | ||
fefcecb0 | 73 | virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code); |
878260fc JF |
74 | virtual bool Look(const std::string &path); |
75 | virtual void Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code); | |
51ced023 | 76 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link); |
23c11ee8 JF |
77 | }; |
78 | ||
79 | class SubFolder : | |
80 | public Folder | |
81 | { | |
82 | private: | |
2443500c | 83 | Folder &parent_; |
23c11ee8 JF |
84 | std::string path_; |
85 | ||
86 | public: | |
2443500c | 87 | SubFolder(Folder &parent, const std::string &path); |
23c11ee8 | 88 | |
fefcecb0 | 89 | virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code); |
878260fc JF |
90 | virtual bool Look(const std::string &path); |
91 | virtual void Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code); | |
51ced023 | 92 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link); |
23c11ee8 JF |
93 | }; |
94 | ||
886cb3f1 JF |
95 | class UnionFolder : |
96 | public Folder | |
97 | { | |
98 | private: | |
4d453c35 JF |
99 | class StringBuffer : |
100 | public std::stringbuf | |
101 | { | |
102 | public: | |
103 | StringBuffer() { | |
104 | } | |
105 | ||
106 | StringBuffer(const StringBuffer &rhs) : | |
107 | std::stringbuf(rhs.str()) | |
108 | { | |
109 | } | |
110 | }; | |
111 | ||
886cb3f1 | 112 | Folder &parent_; |
7c49f771 JF |
113 | std::set<std::string> deletes_; |
114 | ||
115 | std::map<std::string, std::string> remaps_; | |
fefcecb0 | 116 | std::map<std::string, std::pair<StringBuffer, const void *>> resets_; |
7c49f771 JF |
117 | |
118 | std::string Map(const std::string &path); | |
fefcecb0 | 119 | void Map(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const std::string &file, const Functor<void (const Functor<void (std::streambuf &, const void *)> &)> &save); |
886cb3f1 JF |
120 | |
121 | public: | |
122 | UnionFolder(Folder &parent); | |
123 | ||
fefcecb0 | 124 | virtual void Save(const std::string &path, const void *flag, const Functor<void (std::streambuf &)> &code); |
878260fc JF |
125 | virtual bool Look(const std::string &path); |
126 | virtual void Open(const std::string &path, const Functor<void (std::streambuf &, const void *)> &code); | |
51ced023 | 127 | virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code, const Functor<void (const std::string &, const Functor<std::string ()> &)> &link); |
886cb3f1 | 128 | |
7c49f771 JF |
129 | void operator ()(const std::string &from) { |
130 | deletes_.insert(from); | |
131 | } | |
132 | ||
133 | void operator ()(const std::string &from, const std::string &to) { | |
134 | operator ()(from); | |
135 | remaps_[to] = from; | |
136 | } | |
137 | ||
fefcecb0 JF |
138 | std::stringbuf &operator ()(const std::string &from, const void *flag) { |
139 | operator ()(from); | |
140 | auto &reset(resets_[from]); | |
141 | reset.second = flag; | |
142 | return reset.first; | |
886cb3f1 JF |
143 | } |
144 | }; | |
145 | ||
9ec8439b | 146 | std::string Bundle(const std::string &root, Folder &folder, const std::string &key, const std::string &entitlements, const std::string &requirement); |
2dcf3faf | 147 | |
23c11ee8 | 148 | typedef std::map<uint32_t, std::vector<char>> Slots; |
a0c715e9 | 149 | |
9914b1b3 | 150 | void Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &requirement, const std::string &key, const Slots &slots); |
a0c715e9 JF |
151 | |
152 | } | |
153 | ||
154 | #endif//LDID_HPP |