Merge lp:~thomas-voss/trust-store/add-click-based-package-name-query into lp:trust-store
- add-click-based-package-name-query
- Merge into trunk
Proposed by
Thomas Voß
Status: | Work in progress |
---|---|
Proposed branch: | lp:~thomas-voss/trust-store/add-click-based-package-name-query |
Merge into: | lp:trust-store |
Diff against target: |
1616 lines (+1469/-1) 22 files modified
CMakeLists.txt (+3/-1) include/core/trust/click.h (+36/-0) src/CMakeLists.txt (+28/-0) src/core/trust/click.cpp (+58/-0) src/core/trust/click/database.h (+53/-0) src/core/trust/click/deb822.cpp (+50/-0) src/core/trust/click/deb822.h (+35/-0) src/core/trust/click/file_system_database.cpp (+192/-0) src/core/trust/click/file_system_database.h (+61/-0) src/core/trust/click/file_system_resource_resolver.h (+44/-0) src/core/trust/click/framework.h (+53/-0) src/core/trust/click/framework_registry.h (+44/-0) src/core/trust/click/in_memory_framework_registry.cpp (+43/-0) src/core/trust/click/in_memory_framework_registry.h (+53/-0) src/core/trust/click/index.cpp (+86/-0) src/core/trust/click/index.h (+70/-0) src/core/trust/click/json_object.cpp (+191/-0) src/core/trust/click/json_object.h (+114/-0) src/core/trust/click/manifest.h (+65/-0) src/core/trust/click/package.h (+103/-0) src/core/trust/click/paths.cpp (+42/-0) src/core/trust/click/paths.h (+45/-0) |
To merge this branch: | bzr merge lp:~thomas-voss/trust-store/add-click-based-package-name-query |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phablet Team | Pending | ||
Review via email: mp+231694@code.launchpad.net |
Commit message
Add an interface to installed click packages.
Description of the change
Add an interface to installed click packages.
To post a comment you must log in.
- 39. By Thomas Voß
-
More fixes.
Unmerged revisions
- 39. By Thomas Voß
-
More fixes.
- 38. By Thomas Voß
-
Add an interface to installed click packages.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2014-08-13 08:24:18 +0000 |
3 | +++ CMakeLists.txt 2014-08-26 14:23:37 +0000 |
4 | @@ -28,7 +28,7 @@ |
5 | ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE]) |
6 | |
7 | find_package(PkgConfig) |
8 | -find_package(Boost COMPONENTS program_options system REQUIRED) |
9 | +find_package(Boost COMPONENTS filesystem program_options system REQUIRED) |
10 | |
11 | option( |
12 | TRUST_STORE_MIR_AGENT_ENABLED |
13 | @@ -45,6 +45,7 @@ |
14 | |
15 | pkg_check_modules(GFLAGS libgflags REQUIRED) |
16 | pkg_check_modules(GLOG libglog REQUIRED) |
17 | +pkg_check_modules(JSON_C json-c REQUIRED) |
18 | pkg_check_modules(PROCESS_CPP process-cpp REQUIRED) |
19 | |
20 | set(TRUST_STORE_VERSION_MAJOR 1) |
21 | @@ -58,6 +59,7 @@ |
22 | |
23 | ${GFLAGS_INCLUDE_DIRS} |
24 | ${GLOG_INCLUDE_DIRS} |
25 | + ${JSON_C_INCLUDE_DIRS} |
26 | ${PROCESS_CPP_INCLUDE_DIRS} |
27 | ) |
28 | |
29 | |
30 | === added file 'include/core/trust/click.h' |
31 | --- include/core/trust/click.h 1970-01-01 00:00:00 +0000 |
32 | +++ include/core/trust/click.h 2014-08-26 14:23:37 +0000 |
33 | @@ -0,0 +1,36 @@ |
34 | +/* |
35 | + * Copyright © 2014 Canonical Ltd. |
36 | + * |
37 | + * This program is free software: you can redistribute it and/or modify it |
38 | + * under the terms of the GNU Lesser General Public License version 3, |
39 | + * as published by the Free Software Foundation. |
40 | + * |
41 | + * This program is distributed in the hope that it will be useful, |
42 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
43 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
44 | + * GNU Lesser General Public License for more details. |
45 | + * |
46 | + * You should have received a copy of the GNU Lesser General Public License |
47 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
48 | + * |
49 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
50 | + */ |
51 | + |
52 | +#ifndef CORE_TRUST_CLICK_H_ |
53 | +#define CORE_TRUST_CLICK_H_ |
54 | + |
55 | +#include <string> |
56 | + |
57 | +namespace core |
58 | +{ |
59 | +namespace trust |
60 | +{ |
61 | +namespace click |
62 | +{ |
63 | +/** @brief A helper function that resolves an AppArmor confinement profile to an application name. */ |
64 | +std::string localized_app_name_for_confinement_profile(const std::string& profile); |
65 | +} |
66 | +} |
67 | +} |
68 | + |
69 | +#endif // CORE_TRUST_CLICK_H_ |
70 | |
71 | === modified file 'src/CMakeLists.txt' |
72 | --- src/CMakeLists.txt 2014-08-14 13:22:53 +0000 |
73 | +++ src/CMakeLists.txt 2014-08-26 14:23:37 +0000 |
74 | @@ -127,6 +127,33 @@ |
75 | core/trust/dbus/codec.h |
76 | core/trust/dbus/interface.h |
77 | |
78 | + # The publicly exposed click helper |
79 | + core/trust/click.cpp |
80 | + |
81 | + # An internal implementation of the click spec |
82 | + core/trust/click/database.h |
83 | + core/trust/click/framework.h |
84 | + core/trust/click/framework_registry.h |
85 | + core/trust/click/manifest.h |
86 | + core/trust/click/package.h |
87 | + |
88 | + core/trust/click/deb822.h |
89 | + core/trust/click/deb822.cpp |
90 | + |
91 | + core/trust/click/paths.h |
92 | + core/trust/click/paths.cpp |
93 | + |
94 | + core/trust/click/index.h |
95 | + core/trust/click/index.cpp |
96 | + |
97 | + core/trust/click/in_memory_framework_registry.h |
98 | + core/trust/click/in_memory_framework_registry.cpp |
99 | + core/trust/click/file_system_database.h |
100 | + core/trust/click/file_system_database.cpp |
101 | + core/trust/click/file_system_resource_resolver.h |
102 | + |
103 | + core/trust/click/json_object.h |
104 | + core/trust/click/json_object.cpp |
105 | # The default implementation leverages SQLite3 to persist |
106 | # requests. |
107 | core/trust/impl/sqlite3/store.cpp |
108 | @@ -176,6 +203,7 @@ |
109 | ${DBUS_LIBRARIES} |
110 | ${GFLAGS_LDFLAGS} |
111 | ${GLOG_LDFLAGS} |
112 | + ${JSON_C_LDFLAGS} |
113 | ${LIBAPPARMOR_LDFLAGS} |
114 | ${MIR_CLIENT_LDFLAGS} |
115 | ${PROCESS_CPP_LDFLAGS} |
116 | |
117 | === added directory 'src/core/trust/click' |
118 | === added file 'src/core/trust/click.cpp' |
119 | --- src/core/trust/click.cpp 1970-01-01 00:00:00 +0000 |
120 | +++ src/core/trust/click.cpp 2014-08-26 14:23:37 +0000 |
121 | @@ -0,0 +1,58 @@ |
122 | +/* |
123 | + * Copyright © 2014 Canonical Ltd. |
124 | + * |
125 | + * This program is free software: you can redistribute it and/or modify it |
126 | + * under the terms of the GNU Lesser General Public License version 3, |
127 | + * as published by the Free Software Foundation. |
128 | + * |
129 | + * This program is distributed in the hope that it will be useful, |
130 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
131 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
132 | + * GNU Lesser General Public License for more details. |
133 | + * |
134 | + * You should have received a copy of the GNU Lesser General Public License |
135 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
136 | + * |
137 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
138 | + */ |
139 | + |
140 | +#include <core/trust/click.h> |
141 | + |
142 | +#include <core/trust/click/index.h> |
143 | + |
144 | +#include <regex> |
145 | + |
146 | +namespace |
147 | +{ |
148 | +click::Index click_index{click::Index::Configuration{}}; |
149 | +} |
150 | + |
151 | +std::string core::trust::click::localized_app_name_for_confinement_profile(const std::string& profile) |
152 | +{ |
153 | + // Please see https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId. |
154 | + static const std::regex regex{"(.*)_(.*)_(.*)"}; |
155 | + static constexpr std::size_t index_package{1}; |
156 | + static constexpr std::size_t index_app{2}; |
157 | + |
158 | + // We store our matches here. |
159 | + std::smatch match; |
160 | + |
161 | + // See if the profile matches the pattern described in |
162 | + // https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId |
163 | + if (not std::regex_match(profile, match, regex)) throw std::runtime_error |
164 | + { |
165 | + "Profile " + profile + " does not match expected pattern" |
166 | + }; |
167 | + |
168 | + auto current_version = click_index.find_package_for_name(match[index_package])->current_version(); |
169 | + |
170 | + auto& installed_version = current_version->resolve_to_installed_version_or_throw(); |
171 | + |
172 | + auto dot_desktop_file_name = |
173 | + std::string{match[index_package]} + "_" + std::string{match[index_app]} + ".desktop"; |
174 | + auto dot_desktop_file = installed_version.resolve_named_resource(dot_desktop_file_name); |
175 | + |
176 | + std::cout << dot_desktop_file << std::endl; |
177 | + |
178 | + return "lalelu"; |
179 | +} |
180 | |
181 | === added file 'src/core/trust/click/database.cpp' |
182 | === added file 'src/core/trust/click/database.h' |
183 | --- src/core/trust/click/database.h 1970-01-01 00:00:00 +0000 |
184 | +++ src/core/trust/click/database.h 2014-08-26 14:23:37 +0000 |
185 | @@ -0,0 +1,53 @@ |
186 | +/* |
187 | + * Copyright © 2014 Canonical Ltd. |
188 | + * |
189 | + * This program is free software: you can redistribute it and/or modify it |
190 | + * under the terms of the GNU Lesser General Public License version 3, |
191 | + * as published by the Free Software Foundation. |
192 | + * |
193 | + * This program is distributed in the hope that it will be useful, |
194 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
195 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
196 | + * GNU Lesser General Public License for more details. |
197 | + * |
198 | + * You should have received a copy of the GNU Lesser General Public License |
199 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
200 | + * |
201 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
202 | + */ |
203 | + |
204 | +#ifndef CLICK_DATABASE_H_ |
205 | +#define CLICK_DATABASE_H_ |
206 | + |
207 | +#include <core/trust/click/package.h> |
208 | + |
209 | +#include <functional> |
210 | +#include <memory> |
211 | + |
212 | +namespace click |
213 | +{ |
214 | +struct FrameworkRegistry; |
215 | + |
216 | +/** @brief Abstracts an enumerateable and queryable collection of click::Package's */ |
217 | +struct Database |
218 | +{ |
219 | + /** @brief To save some typing. */ |
220 | + typedef std::shared_ptr<Database> Ptr; |
221 | + |
222 | + /** @brief Functor called for every package in a database. */ |
223 | + typedef std::function<void(const Package::Ptr&)> PackageEnumerator; |
224 | + |
225 | + /** @cond */ |
226 | + Database() = default; |
227 | + virtual ~Database() = default; |
228 | + /** @endcond */ |
229 | + |
230 | + /** @brief Enumerates all packages known to a database instance. */ |
231 | + virtual void enumerate_packages(const PackageEnumerator& enumerator) const = 0; |
232 | + |
233 | + /** @brief Tries to lookup a package in the database. */ |
234 | + virtual Package::Ptr find_package_for_name(const std::string& package_name) const = 0; |
235 | +}; |
236 | +} |
237 | + |
238 | +#endif // CLICK_DATABASE_H_ |
239 | |
240 | === added file 'src/core/trust/click/database_of_installed_packages.h' |
241 | === added file 'src/core/trust/click/deb822.cpp' |
242 | --- src/core/trust/click/deb822.cpp 1970-01-01 00:00:00 +0000 |
243 | +++ src/core/trust/click/deb822.cpp 2014-08-26 14:23:37 +0000 |
244 | @@ -0,0 +1,50 @@ |
245 | +/* |
246 | + * Copyright © 2014 Canonical Ltd. |
247 | + * |
248 | + * This program is free software: you can redistribute it and/or modify it |
249 | + * under the terms of the GNU Lesser General Public License version 3, |
250 | + * as published by the Free Software Foundation. |
251 | + * |
252 | + * This program is distributed in the hope that it will be useful, |
253 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
254 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
255 | + * GNU Lesser General Public License for more details. |
256 | + * |
257 | + * You should have received a copy of the GNU Lesser General Public License |
258 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
259 | + * |
260 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
261 | + */ |
262 | + |
263 | +#include <core/trust/click/deb822.h> |
264 | + |
265 | +#include <istream> |
266 | +#include <regex> |
267 | + |
268 | +std::map<std::string, std::string> click::deb822::parse_from_stream(std::istream& in) |
269 | +{ |
270 | + // Matches the entirely blank line |
271 | + static const std::regex blank_re{R"foo(^[[:space:]]*$)foo"}; |
272 | + // Matches key:value lines |
273 | + static const std::regex line_re{R"foo(^([^\s]+)\s*:\s*([^\s]*)\s*)foo"}; |
274 | + static const std::size_t index_key{1}; |
275 | + static const std::size_t index_value{2}; |
276 | + |
277 | + std::map<std::string, std::string> result; |
278 | + |
279 | + std::smatch match; |
280 | + std::string line; |
281 | + |
282 | + while (std::getline(in, line)) |
283 | + { |
284 | + if (std::regex_match(line, blank_re)) |
285 | + continue; |
286 | + |
287 | + if (std::regex_match(line, match, line_re)) |
288 | + { |
289 | + result[match[index_key]] = match[index_value]; |
290 | + } |
291 | + } |
292 | + |
293 | + return result; |
294 | +} |
295 | |
296 | === added file 'src/core/trust/click/deb822.h' |
297 | --- src/core/trust/click/deb822.h 1970-01-01 00:00:00 +0000 |
298 | +++ src/core/trust/click/deb822.h 2014-08-26 14:23:37 +0000 |
299 | @@ -0,0 +1,35 @@ |
300 | +/* |
301 | + * Copyright © 2014 Canonical Ltd. |
302 | + * |
303 | + * This program is free software: you can redistribute it and/or modify it |
304 | + * under the terms of the GNU Lesser General Public License version 3, |
305 | + * as published by the Free Software Foundation. |
306 | + * |
307 | + * This program is distributed in the hope that it will be useful, |
308 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
309 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
310 | + * GNU Lesser General Public License for more details. |
311 | + * |
312 | + * You should have received a copy of the GNU Lesser General Public License |
313 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
314 | + * |
315 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
316 | + */ |
317 | + |
318 | +#ifndef CLICK_DEB822_H_ |
319 | +#define CLICK_DEB822_H_ |
320 | + |
321 | +#include <iosfwd> |
322 | +#include <map> |
323 | +#include <string> |
324 | + |
325 | +namespace click |
326 | +{ |
327 | +namespace deb822 |
328 | +{ |
329 | +// A simple Deb822 parser for single-line, non-folded formats. |
330 | +std::map<std::string, std::string> parse_from_stream(std::istream& in); |
331 | +} |
332 | +} |
333 | + |
334 | +#endif // CLICK_DEB822_H_ |
335 | |
336 | === added file 'src/core/trust/click/file_system_database.cpp' |
337 | --- src/core/trust/click/file_system_database.cpp 1970-01-01 00:00:00 +0000 |
338 | +++ src/core/trust/click/file_system_database.cpp 2014-08-26 14:23:37 +0000 |
339 | @@ -0,0 +1,192 @@ |
340 | +/* |
341 | + * Copyright © 2014 Canonical Ltd. |
342 | + * |
343 | + * This program is free software: you can redistribute it and/or modify it |
344 | + * under the terms of the GNU Lesser General Public License version 3, |
345 | + * as published by the Free Software Foundation. |
346 | + * |
347 | + * This program is distributed in the hope that it will be useful, |
348 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
349 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
350 | + * GNU Lesser General Public License for more details. |
351 | + * |
352 | + * You should have received a copy of the GNU Lesser General Public License |
353 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
354 | + * |
355 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
356 | + */ |
357 | + |
358 | +#include <core/trust/click/file_system_database.h> |
359 | + |
360 | +#include <core/trust/click/framework_registry.h> |
361 | +#include <core/trust/click/manifest.h> |
362 | +#include <core/trust/click/package.h> |
363 | + |
364 | +// Just a helper |
365 | +#include <core/trust/click/json_object.h> |
366 | + |
367 | +#include <fstream> |
368 | + |
369 | +namespace |
370 | +{ |
371 | +struct FilesystemPackage |
372 | + : public click::Package, |
373 | + public std::enable_shared_from_this<FilesystemPackage> |
374 | +{ |
375 | + struct FilesystemVersion : public click::installed::Version |
376 | + { |
377 | + struct Configuration |
378 | + { |
379 | + click::Package::Ptr parent; |
380 | + boost::filesystem::path root; |
381 | + click::FrameworkRegistry::Ptr framework_registry; |
382 | + }; |
383 | + |
384 | + FilesystemVersion(const Configuration& configuration) |
385 | + : configuration(configuration) |
386 | + { |
387 | + if (not boost::filesystem::is_directory(configuration.root)) throw std::logic_error |
388 | + { |
389 | + "Path has to be a directory: " + configuration.root.string() |
390 | + }; |
391 | + |
392 | + std::ifstream in{(configuration.root / ".click" / "info" / (configuration.parent->name() + ".manifest")).string().c_str()}; |
393 | + std::string contents{std::istream_iterator<char>(in), std::istream_iterator<char>()}; |
394 | + |
395 | + auto object = json::Object::parse_from_string(contents); |
396 | + |
397 | + manifest.installed_size = object.get(click::Manifest::Json::installed_size).to_int64(); |
398 | + manifest.required_frameworks.insert( |
399 | + configuration.framework_registry->find_framework_for_base_name( |
400 | + object.get(click::Manifest::Json::framework).to_string())); |
401 | + } |
402 | + |
403 | + click::installed::Version& resolve_to_installed_version_or_throw() override |
404 | + { |
405 | + return *this; |
406 | + } |
407 | + |
408 | + Package& parent() override |
409 | + { |
410 | + return *configuration.parent; |
411 | + } |
412 | + |
413 | + std::string specifier() override |
414 | + { |
415 | + return configuration.root.filename().string(); |
416 | + } |
417 | + |
418 | + boost::filesystem::path resolve_named_resource(const std::string& resource) override |
419 | + { |
420 | + return configuration.root / resource; |
421 | + } |
422 | + |
423 | + std::size_t size() override |
424 | + { |
425 | + return manifest.installed_size; |
426 | + } |
427 | + |
428 | + void enumerate_required_frameworks(click::Package::Version::FrameworkEnumerator enumerator) override |
429 | + { |
430 | + for (const auto& framework : manifest.required_frameworks) |
431 | + enumerator(framework); |
432 | + } |
433 | + |
434 | + Configuration configuration; |
435 | + |
436 | + struct |
437 | + { |
438 | + std::int64_t installed_size; |
439 | + std::set<click::Framework::Ptr> required_frameworks; |
440 | + } manifest; |
441 | + }; |
442 | + |
443 | + struct Configuration |
444 | + { |
445 | + boost::filesystem::path root; |
446 | + click::FrameworkRegistry::Ptr framework_registry; |
447 | + }; |
448 | + |
449 | + FilesystemPackage(const Configuration& configuration) : configuration(configuration) |
450 | + { |
451 | + if (not boost::filesystem::is_directory(configuration.root)) throw std::logic_error |
452 | + { |
453 | + "Path has to be a directory: " + configuration.root.string() |
454 | + }; |
455 | + } |
456 | + |
457 | + std::string name() override |
458 | + { |
459 | + return configuration.root.filename().string(); |
460 | + } |
461 | + |
462 | + void enumerate_versions(click::Package::VersionEnumerator enumerator) override |
463 | + { |
464 | + boost::filesystem::directory_iterator it{configuration.root}, itE; |
465 | + |
466 | + for (; it != itE; ++it) |
467 | + { |
468 | + // We post-process all symlinks and just store them during this iteration. |
469 | + if (boost::filesystem::is_symlink(*it)) |
470 | + continue; |
471 | + |
472 | + enumerator(std::make_shared<FilesystemVersion>( |
473 | + FilesystemVersion::Configuration |
474 | + { |
475 | + shared_from_this(), |
476 | + *it, |
477 | + configuration.framework_registry |
478 | + })); |
479 | + } |
480 | + } |
481 | + |
482 | + Version::Ptr current_version() override |
483 | + { |
484 | + auto path = boost::filesystem::read_symlink(configuration.root / "current"); |
485 | + |
486 | + if (not boost::filesystem::is_directory(path)) throw std::runtime_error |
487 | + { |
488 | + "Could not resolve current version of package" |
489 | + }; |
490 | + |
491 | + return std::make_shared<FilesystemVersion>(FilesystemVersion::Configuration |
492 | + { |
493 | + shared_from_this(), |
494 | + path, |
495 | + configuration.framework_registry |
496 | + }); |
497 | + } |
498 | + |
499 | + Configuration configuration; |
500 | +}; |
501 | +} |
502 | + |
503 | +click::FileSystemDatabase::FileSystemDatabase(const Configuration& config) |
504 | + : root{config.path}, |
505 | + framework_registry{config.framework_registry} |
506 | +{ |
507 | + if (not boost::filesystem::exists(root)) throw std::logic_error |
508 | + { |
509 | + "Cannot operate on non-existant directory: " + config.path |
510 | + }; |
511 | + |
512 | + if (not boost::filesystem::is_directory(root)) throw std::logic_error |
513 | + { |
514 | + "Cannot operator on file: " + config.path |
515 | + }; |
516 | +} |
517 | + |
518 | +void click::FileSystemDatabase::enumerate_packages(const click::Database::PackageEnumerator& enumerator) const |
519 | +{ |
520 | + boost::filesystem::directory_iterator it{root}, itE{}; |
521 | + |
522 | + for (; it != itE; ++it) |
523 | + enumerator(std::make_shared<FilesystemPackage>( |
524 | + FilesystemPackage::Configuration{*it, framework_registry})); |
525 | +} |
526 | + |
527 | +click::Package::Ptr click::FileSystemDatabase::find_package_for_name(const std::string& package_name) const |
528 | +{ |
529 | + return std::make_shared<FilesystemPackage>(FilesystemPackage::Configuration{root / package_name, framework_registry}); |
530 | +} |
531 | + |
532 | |
533 | === added file 'src/core/trust/click/file_system_database.h' |
534 | --- src/core/trust/click/file_system_database.h 1970-01-01 00:00:00 +0000 |
535 | +++ src/core/trust/click/file_system_database.h 2014-08-26 14:23:37 +0000 |
536 | @@ -0,0 +1,61 @@ |
537 | +/* |
538 | + * Copyright © 2014 Canonical Ltd. |
539 | + * |
540 | + * This program is free software: you can redistribute it and/or modify it |
541 | + * under the terms of the GNU Lesser General Public License version 3, |
542 | + * as published by the Free Software Foundation. |
543 | + * |
544 | + * This program is distributed in the hope that it will be useful, |
545 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
546 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
547 | + * GNU Lesser General Public License for more details. |
548 | + * |
549 | + * You should have received a copy of the GNU Lesser General Public License |
550 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
551 | + * |
552 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
553 | + */ |
554 | + |
555 | +#ifndef CLICK_FILE_SYSTEM_DATABASE_H_ |
556 | +#define CLICK_FILE_SYSTEM_DATABASE_H_ |
557 | + |
558 | +#include <core/trust/click/database.h> |
559 | + |
560 | +#include <core/trust/click/file_system_resource_resolver.h> |
561 | + |
562 | +#include <boost/filesystem.hpp> |
563 | + |
564 | +namespace click |
565 | +{ |
566 | +// An implementation of the Database interface using the filesystem as repository |
567 | +// for click packages. |
568 | +class FileSystemDatabase : public Database |
569 | +{ |
570 | +public: |
571 | + // To save some typing. |
572 | + typedef std::shared_ptr<FileSystemDatabase> Ptr; |
573 | + |
574 | + // Creation time options go here. |
575 | + struct Configuration |
576 | + { |
577 | + // Root path of the database. |
578 | + std::string path; |
579 | + // FrameworkRegistry instance for resolving framework base names. |
580 | + std::shared_ptr<FrameworkRegistry> framework_registry; |
581 | + }; |
582 | + |
583 | + // Creates a new instance with the given root path. |
584 | + // Throws if the root path does not exist or does not refer to a directory. |
585 | + FileSystemDatabase(const Configuration& Configuration); |
586 | + |
587 | + // From Database. |
588 | + void enumerate_packages(const Database::PackageEnumerator& enumerator) const override; |
589 | + Package::Ptr find_package_for_name(const std::string& package_name) const override; |
590 | + |
591 | +private: |
592 | + boost::filesystem::path root; |
593 | + std::shared_ptr<FrameworkRegistry> framework_registry; |
594 | +}; |
595 | +} |
596 | + |
597 | +#endif // CLICK_FILE_SYSTEM_DATABASE_H_ |
598 | |
599 | === added file 'src/core/trust/click/file_system_resource_resolver.h' |
600 | --- src/core/trust/click/file_system_resource_resolver.h 1970-01-01 00:00:00 +0000 |
601 | +++ src/core/trust/click/file_system_resource_resolver.h 2014-08-26 14:23:37 +0000 |
602 | @@ -0,0 +1,44 @@ |
603 | +/* |
604 | + * Copyright © 2014 Canonical Ltd. |
605 | + * |
606 | + * This program is free software: you can redistribute it and/or modify it |
607 | + * under the terms of the GNU Lesser General Public License version 3, |
608 | + * as published by the Free Software Foundation. |
609 | + * |
610 | + * This program is distributed in the hope that it will be useful, |
611 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
612 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
613 | + * GNU Lesser General Public License for more details. |
614 | + * |
615 | + * You should have received a copy of the GNU Lesser General Public License |
616 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
617 | + * |
618 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
619 | + */ |
620 | + |
621 | +#ifndef CLICK_FILE_SYSTEM_RESOURCE_RESOLVER_H_ |
622 | +#define CLICK_FILE_SYSTEM_RESOURCE_RESOLVER_H_ |
623 | + |
624 | +#include <core/trust/click/package.h> |
625 | + |
626 | +#include <boost/filesystem.hpp> |
627 | + |
628 | +namespace click |
629 | +{ |
630 | +/** @brief Abstracts lookup of package resources in locally available filesystems. */ |
631 | +struct FileSystemResourceResolver |
632 | +{ |
633 | + /** @brief A descriptor for resources contained in a specific version of a click package. */ |
634 | + typedef boost::filesystem::path ResourceDescriptor; |
635 | + |
636 | + /** @cond */ |
637 | + FileSystemResourceResolver() = default; |
638 | + virtual ~FileSystemResourceResolver() = default; |
639 | + /** @endcond */ |
640 | + |
641 | + /** @brief Resolves a resource in a package version. */ |
642 | + virtual ResourceDescriptor resolve_named_resource_in_package_version(const std::string& resource_name, const Package::Version& version) = 0; |
643 | +}; |
644 | +} |
645 | + |
646 | +#endif // CLICK_FILE_SYSTEM_RESOURCE_RESOLVER_H_ |
647 | |
648 | === added file 'src/core/trust/click/framework.cpp' |
649 | === added file 'src/core/trust/click/framework.h' |
650 | --- src/core/trust/click/framework.h 1970-01-01 00:00:00 +0000 |
651 | +++ src/core/trust/click/framework.h 2014-08-26 14:23:37 +0000 |
652 | @@ -0,0 +1,53 @@ |
653 | +/* |
654 | + * Copyright © 2014 Canonical Ltd. |
655 | + * |
656 | + * This program is free software: you can redistribute it and/or modify it |
657 | + * under the terms of the GNU Lesser General Public License version 3, |
658 | + * as published by the Free Software Foundation. |
659 | + * |
660 | + * This program is distributed in the hope that it will be useful, |
661 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
662 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
663 | + * GNU Lesser General Public License for more details. |
664 | + * |
665 | + * You should have received a copy of the GNU Lesser General Public License |
666 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
667 | + * |
668 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
669 | + */ |
670 | + |
671 | +#ifndef CLICK_FRAMEWORK_H_ |
672 | +#define CLICK_FRAMEWORK_H_ |
673 | + |
674 | +#include <memory> |
675 | +#include <string> |
676 | + |
677 | +namespace click |
678 | +{ |
679 | +/** @brief Click Frameworks are "contracts" between the platform (OS) and apps. */ |
680 | +struct Framework |
681 | +{ |
682 | + /** @brief To save some typing. */ |
683 | + typedef std::shared_ptr<Framework> Ptr; |
684 | + |
685 | + /** |
686 | + * @brief Compile-time constants for the keys in a .framework file. |
687 | + * |
688 | + * The file is in Deb822 format. |
689 | + */ |
690 | + struct Keys |
691 | + { |
692 | + Keys() = delete; |
693 | + |
694 | + static constexpr const char* base_name{"Base-Name"}; |
695 | + static constexpr const char* base_version{"Base-Version"}; |
696 | + }; |
697 | + |
698 | + /** @brief The 'base name' of the framework is here to permit click to support a wider range of underlying software than Ubuntu for phones in future. */ |
699 | + std::string base_name; |
700 | + /** @brief The 'base version' of the framework is determined by the release of Ubuntu that the framework first targeted. */ |
701 | + std::string base_version; |
702 | +}; |
703 | +} |
704 | + |
705 | +#endif // CLICK_FRAMEWORK_H_ |
706 | |
707 | === added file 'src/core/trust/click/framework_registry.h' |
708 | --- src/core/trust/click/framework_registry.h 1970-01-01 00:00:00 +0000 |
709 | +++ src/core/trust/click/framework_registry.h 2014-08-26 14:23:37 +0000 |
710 | @@ -0,0 +1,44 @@ |
711 | +/* |
712 | + * Copyright © 2014 Canonical Ltd. |
713 | + * |
714 | + * This program is free software: you can redistribute it and/or modify it |
715 | + * under the terms of the GNU Lesser General Public License version 3, |
716 | + * as published by the Free Software Foundation. |
717 | + * |
718 | + * This program is distributed in the hope that it will be useful, |
719 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
720 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
721 | + * GNU Lesser General Public License for more details. |
722 | + * |
723 | + * You should have received a copy of the GNU Lesser General Public License |
724 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
725 | + * |
726 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
727 | + */ |
728 | + |
729 | +#ifndef CLICK_FRAMEWORK_REGISTRY_H_ |
730 | +#define CLICK_FRAMEWORK_REGISTRY_H_ |
731 | + |
732 | +#include <memory> |
733 | + |
734 | +namespace click |
735 | +{ |
736 | +struct Framework; |
737 | + |
738 | +/** @brief Keeps track of all installed frameworks. */ |
739 | +struct FrameworkRegistry |
740 | +{ |
741 | + /** @brief To save some typing. */ |
742 | + typedef std::shared_ptr<FrameworkRegistry> Ptr; |
743 | + |
744 | + /** @cond */ |
745 | + FrameworkRegistry() = default; |
746 | + virtual ~FrameworkRegistry() = default; |
747 | + /** @endcond */ |
748 | + |
749 | + /** @brief Returns the framework corresponding to the given base_name or throws. */ |
750 | + virtual std::shared_ptr<Framework> find_framework_for_base_name(const std::string& base_name) const = 0; |
751 | +}; |
752 | +} |
753 | + |
754 | +#endif // CLICK_FRAMEWORK_REGISTRY_H_ |
755 | |
756 | === added file 'src/core/trust/click/in_memory_framework_registry.cpp' |
757 | --- src/core/trust/click/in_memory_framework_registry.cpp 1970-01-01 00:00:00 +0000 |
758 | +++ src/core/trust/click/in_memory_framework_registry.cpp 2014-08-26 14:23:37 +0000 |
759 | @@ -0,0 +1,43 @@ |
760 | +/* |
761 | + * Copyright © 2014 Canonical Ltd. |
762 | + * |
763 | + * This program is free software: you can redistribute it and/or modify it |
764 | + * under the terms of the GNU Lesser General Public License version 3, |
765 | + * as published by the Free Software Foundation. |
766 | + * |
767 | + * This program is distributed in the hope that it will be useful, |
768 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
769 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
770 | + * GNU Lesser General Public License for more details. |
771 | + * |
772 | + * You should have received a copy of the GNU Lesser General Public License |
773 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
774 | + * |
775 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
776 | + */ |
777 | + |
778 | +#include <core/trust/click/in_memory_framework_registry.h> |
779 | + |
780 | +#include <core/trust/click/framework.h> |
781 | + |
782 | +void click::InMemoryFrameworkRegistry::register_framework(const std::shared_ptr<click::Framework>& framework) |
783 | +{ |
784 | + frameworks[framework->base_name] = framework; |
785 | +} |
786 | + |
787 | +void click::InMemoryFrameworkRegistry::unregister_framework(const std::shared_ptr<click::Framework>& framework) |
788 | +{ |
789 | + frameworks.erase(framework->base_name); |
790 | +} |
791 | + |
792 | +std::shared_ptr<click::Framework> click::InMemoryFrameworkRegistry::find_framework_for_base_name(const std::string& base_name) const |
793 | +{ |
794 | + auto it = frameworks.find(base_name); |
795 | + |
796 | + if (it == frameworks.end()) throw std::out_of_range |
797 | + { |
798 | + "No entry for " + base_name |
799 | + }; |
800 | + |
801 | + return it->second; |
802 | +} |
803 | |
804 | === added file 'src/core/trust/click/in_memory_framework_registry.h' |
805 | --- src/core/trust/click/in_memory_framework_registry.h 1970-01-01 00:00:00 +0000 |
806 | +++ src/core/trust/click/in_memory_framework_registry.h 2014-08-26 14:23:37 +0000 |
807 | @@ -0,0 +1,53 @@ |
808 | +/* |
809 | + * Copyright © 2014 Canonical Ltd. |
810 | + * |
811 | + * This program is free software: you can redistribute it and/or modify it |
812 | + * under the terms of the GNU Lesser General Public License version 3, |
813 | + * as published by the Free Software Foundation. |
814 | + * |
815 | + * This program is distributed in the hope that it will be useful, |
816 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
817 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
818 | + * GNU Lesser General Public License for more details. |
819 | + * |
820 | + * You should have received a copy of the GNU Lesser General Public License |
821 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
822 | + * |
823 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
824 | + */ |
825 | + |
826 | +#ifndef CLICK_IN_MEMORY_FRAMEWORK_REGISTRY_H_ |
827 | +#define CLICK_IN_MEMORY_FRAMEWORK_REGISTRY_H_ |
828 | + |
829 | +#include <core/trust/click/framework_registry.h> |
830 | + |
831 | +#include <memory> |
832 | +#include <unordered_map> |
833 | + |
834 | +namespace click |
835 | +{ |
836 | +struct Framework; |
837 | + |
838 | +// Implements FrameworkRegistry using a hash-map. |
839 | +class InMemoryFrameworkRegistry : public FrameworkRegistry |
840 | +{ |
841 | +public: |
842 | + // To save some typing |
843 | + typedef std::shared_ptr<InMemoryFrameworkRegistry> Ptr; |
844 | + |
845 | + InMemoryFrameworkRegistry() = default; |
846 | + |
847 | + // Allow for registering ... |
848 | + void register_framework(const std::shared_ptr<Framework>& framework); |
849 | + // and unregistering frameworks. |
850 | + void unregister_framework(const std::shared_ptr<Framework>& framework); |
851 | + |
852 | + // From FrameworkRegistry. |
853 | + std::shared_ptr<Framework> find_framework_for_base_name(const std::string& base_name) const override; |
854 | + |
855 | +private: |
856 | + std::unordered_map<std::string, std::shared_ptr<Framework>> frameworks; |
857 | +}; |
858 | +} |
859 | + |
860 | +#endif // CLICK_IN_MEMORY_FRAMEWORK_REGISTRY_H_ |
861 | |
862 | === added file 'src/core/trust/click/index.cpp' |
863 | --- src/core/trust/click/index.cpp 1970-01-01 00:00:00 +0000 |
864 | +++ src/core/trust/click/index.cpp 2014-08-26 14:23:37 +0000 |
865 | @@ -0,0 +1,86 @@ |
866 | +/* |
867 | + * Copyright © 2014 Canonical Ltd. |
868 | + * |
869 | + * This program is free software: you can redistribute it and/or modify it |
870 | + * under the terms of the GNU Lesser General Public License version 3, |
871 | + * as published by the Free Software Foundation. |
872 | + * |
873 | + * This program is distributed in the hope that it will be useful, |
874 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
875 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
876 | + * GNU Lesser General Public License for more details. |
877 | + * |
878 | + * You should have received a copy of the GNU Lesser General Public License |
879 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
880 | + * |
881 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
882 | + */ |
883 | + |
884 | +#include <core/trust/click/index.h> |
885 | + |
886 | +#include <core/trust/click/deb822.h> |
887 | + |
888 | +#include <boost/filesystem.hpp> |
889 | +#include <boost/property_tree/ini_parser.hpp> |
890 | +#include <boost/property_tree/ptree.hpp> |
891 | + |
892 | +// Constructs a new instance, querying filesystem path setups |
893 | +click::Index::Index(const click::Index::Configuration& configuration) |
894 | +{ |
895 | + // Iterate over all known frameworks. |
896 | + boost::filesystem::directory_iterator it{configuration.paths->default_frameworks_config_dir()}, itE; |
897 | + for (; it != itE; ++it) |
898 | + { |
899 | + std::ifstream in{it->path().string().c_str()}; |
900 | + auto kv = click::deb822::parse_from_stream(in); |
901 | + |
902 | + if (kv.count(click::Framework::Keys::base_name) == 0 || kv.count(click::Framework::Keys::base_version) == 0) |
903 | + continue; |
904 | + |
905 | + framework_registry->register_framework(Framework::Ptr |
906 | + { |
907 | + new Framework |
908 | + { |
909 | + kv.at(click::Framework::Keys::base_name), |
910 | + kv.at(click::Framework::Keys::base_version) |
911 | + } |
912 | + }); |
913 | + } |
914 | + |
915 | + // Iterate over all configured databases. |
916 | + boost::filesystem::directory_iterator itd{configuration.paths->default_database_config_dir()}, itdE; |
917 | + for (; itd != itdE; ++itd) |
918 | + { |
919 | + boost::property_tree::ptree ptree; |
920 | + boost::property_tree::ini_parser::read_ini(itd->path().string(), ptree); |
921 | + |
922 | + auto root = ptree.get_child("Click Database").get<std::string>("root"); |
923 | + databases.push_back(std::make_shared<click::FileSystemDatabase>( |
924 | + click::FileSystemDatabase::Configuration{root, framework_registry} |
925 | + )); |
926 | + } |
927 | +} |
928 | + |
929 | +// From Database |
930 | +void click::Index::enumerate_packages(const click::Database::PackageEnumerator& enumerator) const |
931 | +{ |
932 | + for(auto database : databases) |
933 | + { |
934 | + database->enumerate_packages(enumerator); |
935 | + } |
936 | +} |
937 | + |
938 | +click::Package::Ptr click::Index::find_package_for_name(const std::string& name) const |
939 | +{ |
940 | + for(auto database : databases) |
941 | + { |
942 | + try |
943 | + { |
944 | + return database->find_package_for_name(name); |
945 | + } catch(...) |
946 | + { |
947 | + } |
948 | + } |
949 | + return click::Package::Ptr{}; |
950 | +} |
951 | + |
952 | |
953 | === added file 'src/core/trust/click/index.h' |
954 | --- src/core/trust/click/index.h 1970-01-01 00:00:00 +0000 |
955 | +++ src/core/trust/click/index.h 2014-08-26 14:23:37 +0000 |
956 | @@ -0,0 +1,70 @@ |
957 | +/* |
958 | + * Copyright © 2014 Canonical Ltd. |
959 | + * |
960 | + * This program is free software: you can redistribute it and/or modify it |
961 | + * under the terms of the GNU Lesser General Public License version 3, |
962 | + * as published by the Free Software Foundation. |
963 | + * |
964 | + * This program is distributed in the hope that it will be useful, |
965 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
966 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
967 | + * GNU Lesser General Public License for more details. |
968 | + * |
969 | + * You should have received a copy of the GNU Lesser General Public License |
970 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
971 | + * |
972 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
973 | + */ |
974 | + |
975 | +#ifndef CLICK_INDEX_H_ |
976 | +#define CLICK_INDEX_H_ |
977 | + |
978 | +#include <core/trust/click/file_system_database.h> |
979 | +#include <core/trust/click/paths.h> |
980 | + |
981 | +#include <core/trust/click/in_memory_framework_registry.h> |
982 | + |
983 | +#include <boost/filesystem.hpp> |
984 | + |
985 | +#include <memory> |
986 | + |
987 | +namespace click |
988 | +{ |
989 | +// Ties together multiple parts of the click world and renders |
990 | +// them readily accessible by implementing click::Database. |
991 | +class Index: public click::Database, |
992 | + public std::enable_shared_from_this<Index> |
993 | +{ |
994 | +public: |
995 | + // Creation time arguments go here. |
996 | + struct Configuration |
997 | + { |
998 | + // Provides the path configuration to the index. |
999 | + Paths::Ptr paths |
1000 | + { |
1001 | + std::make_shared<click::Paths>() |
1002 | + }; |
1003 | + }; |
1004 | + |
1005 | + // Constructs a new instance, querying filesystem path setups |
1006 | + Index(const Configuration& configuration); |
1007 | + |
1008 | + // From Database |
1009 | + void enumerate_packages(const PackageEnumerator& enumerator) const override; |
1010 | + Package::Ptr find_package_for_name(const std::string& package_name) const override; |
1011 | + |
1012 | +private: |
1013 | + // Keeps track of all known frameworks |
1014 | + InMemoryFrameworkRegistry::Ptr framework_registry |
1015 | + { |
1016 | + std::make_shared<InMemoryFrameworkRegistry>() |
1017 | + }; |
1018 | + // Sorted in descending order of priority. |
1019 | + std::vector<FileSystemDatabase::Ptr> databases |
1020 | + { |
1021 | + // Empty by default |
1022 | + }; |
1023 | +}; |
1024 | +} |
1025 | + |
1026 | +#endif // CLICK_INDEX_H_ |
1027 | |
1028 | === added file 'src/core/trust/click/json_object.cpp' |
1029 | --- src/core/trust/click/json_object.cpp 1970-01-01 00:00:00 +0000 |
1030 | +++ src/core/trust/click/json_object.cpp 2014-08-26 14:23:37 +0000 |
1031 | @@ -0,0 +1,191 @@ |
1032 | +/* |
1033 | + * Copyright © 2014 Canonical Ltd. |
1034 | + * |
1035 | + * This program is free software: you can redistribute it and/or modify it |
1036 | + * under the terms of the GNU Lesser General Public License version 3, |
1037 | + * as published by the Free Software Foundation. |
1038 | + * |
1039 | + * This program is distributed in the hope that it will be useful, |
1040 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1041 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1042 | + * GNU Lesser General Public License for more details. |
1043 | + * |
1044 | + * You should have received a copy of the GNU Lesser General Public License |
1045 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1046 | + * |
1047 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1048 | + */ |
1049 | + |
1050 | +#include <core/trust/click/json_object.h> |
1051 | + |
1052 | +#include <json-c/json.h> |
1053 | + |
1054 | +#include <stdexcept> |
1055 | + |
1056 | +namespace json |
1057 | +{ |
1058 | +Object Object::parse_from_string(const std::string& s) |
1059 | +{ |
1060 | + return Object{json_tokener_parse(s.c_str())}; |
1061 | +} |
1062 | + |
1063 | +Object Object::create_array() |
1064 | +{ |
1065 | + return Object{json_object_new_array()}; |
1066 | +} |
1067 | + |
1068 | +Object Object::create_object() |
1069 | +{ |
1070 | + return Object{json_object_new_object()}; |
1071 | +} |
1072 | + |
1073 | +Object::Object(json_object* object) : object(object) |
1074 | +{ |
1075 | +} |
1076 | + |
1077 | +Object::Object(const Object& rhs) : object(json_object_get(rhs.object)) |
1078 | +{ |
1079 | +} |
1080 | + |
1081 | +Object::~Object() |
1082 | +{ |
1083 | + json_object_put(object); |
1084 | +} |
1085 | + |
1086 | +Object& Object::operator=(const Object& rhs) |
1087 | +{ |
1088 | + json_object_put(object); |
1089 | + object = json_object_get(rhs.object); |
1090 | + |
1091 | + return *this; |
1092 | +} |
1093 | + |
1094 | +std::string Object::to_plain_string() |
1095 | +{ |
1096 | + return std::string |
1097 | + { |
1098 | + json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN) |
1099 | + }; |
1100 | +} |
1101 | + |
1102 | +Object Object::get(const std::string& name) const |
1103 | +{ |
1104 | + json_object* result{nullptr}; |
1105 | + |
1106 | + json_object_object_get_ex(object, name.c_str(), &result); |
1107 | + |
1108 | + if (not result) throw std::out_of_range |
1109 | + { |
1110 | + name.c_str() |
1111 | + }; |
1112 | + |
1113 | + return Object{result}; |
1114 | +} |
1115 | + |
1116 | +namespace |
1117 | +{ |
1118 | +template<json_type type> void throw_if_type_mismatch(json_object* object) |
1119 | +{ |
1120 | + if (not json_object_is_type(object, type)) throw std::logic_error |
1121 | + { |
1122 | + "Type mismatch." |
1123 | + }; |
1124 | +} |
1125 | +} |
1126 | +// Attempts to resolve the object to a boolean value. |
1127 | +// Throws std::logic_error in case of type mismatches. |
1128 | +bool Object::to_bool() const |
1129 | +{ |
1130 | + throw_if_type_mismatch<json_type_boolean>(object); |
1131 | + return json_object_get_boolean(object); |
1132 | +} |
1133 | + |
1134 | +std::int32_t Object::to_int32() const |
1135 | +{ |
1136 | + throw_if_type_mismatch<json_type_int>(object); |
1137 | + return json_object_get_int(object); |
1138 | +} |
1139 | + |
1140 | +std::int64_t Object::to_int64() const |
1141 | +{ |
1142 | + throw_if_type_mismatch<json_type_int>(object); |
1143 | + return json_object_get_int64(object); |
1144 | +} |
1145 | + |
1146 | +double Object::to_double() const |
1147 | +{ |
1148 | + throw_if_type_mismatch<json_type_double>(object); |
1149 | + return json_object_get_double(object); |
1150 | +} |
1151 | + |
1152 | +std::string Object::to_string() const |
1153 | +{ |
1154 | + throw_if_type_mismatch<json_type_string>(object); |
1155 | + return std::string{json_object_get_string(object)}; |
1156 | +} |
1157 | + |
1158 | +void Object::put_array(const std::string& name, Object array) |
1159 | +{ |
1160 | + json_object_object_add(object, name.c_str(), json_object_get(array.object)); |
1161 | +} |
1162 | + |
1163 | +void Object::put_object(const std::string& name, Object other) |
1164 | +{ |
1165 | + json_object_object_add(object, name.c_str(), json_object_get(other.object)); |
1166 | +} |
1167 | + |
1168 | +void Object::put_boolean(const std::string& name, bool value) |
1169 | +{ |
1170 | + json_object_object_add(object, name.c_str(), json_object_new_boolean(value)); |
1171 | +} |
1172 | + |
1173 | +void Object::put_int32(const std::string& name, std::int32_t value) |
1174 | +{ |
1175 | + json_object_object_add(object, name.c_str(), json_object_new_int(value)); |
1176 | +} |
1177 | + |
1178 | +void Object::put_int64(const std::string& name, std::int64_t value) |
1179 | +{ |
1180 | + json_object_object_add(object, name.c_str(), json_object_new_int64(value)); |
1181 | +} |
1182 | + |
1183 | +void Object::put_double(const std::string& name, double value) |
1184 | +{ |
1185 | + json_object_object_add(object, name.c_str(), json_object_new_double(value)); |
1186 | +} |
1187 | + |
1188 | +void Object::put_string(const std::string& name, const std::string& value) |
1189 | +{ |
1190 | + json_object_object_add(object, name.c_str(), json_object_new_string_len(value.c_str(), value.size())); |
1191 | +} |
1192 | + |
1193 | +std::size_t Object::array_size() const |
1194 | +{ |
1195 | + throw_if_type_mismatch<json_type_array>(object); |
1196 | + return json_object_array_length(object); |
1197 | +} |
1198 | + |
1199 | +void Object::append(Object other) |
1200 | +{ |
1201 | + throw_if_type_mismatch<json_type_array>(object); |
1202 | + json_object_array_add(object, json_object_get(other.object)); |
1203 | +} |
1204 | + |
1205 | +void Object::put_object_for_index(std::size_t index, Object other) |
1206 | +{ |
1207 | + throw_if_type_mismatch<json_type_array>(object); |
1208 | + json_object_array_put_idx(object, index, json_object_get(other.object)); |
1209 | +} |
1210 | + |
1211 | +// Queries the object at index 'index'. |
1212 | +// Throws std::logic_error if the object does not represent an array. |
1213 | +// Throws std::out_of_range if the index exceeds the bounds of the array. |
1214 | +Object Object::get_object_for_index(std::size_t index) |
1215 | +{ |
1216 | + throw_if_type_mismatch<json_type_array>(object); |
1217 | + return Object |
1218 | + { |
1219 | + json_object_get(json_object_array_get_idx(object, index)) |
1220 | + }; |
1221 | +} |
1222 | +} |
1223 | |
1224 | === added file 'src/core/trust/click/json_object.h' |
1225 | --- src/core/trust/click/json_object.h 1970-01-01 00:00:00 +0000 |
1226 | +++ src/core/trust/click/json_object.h 2014-08-26 14:23:37 +0000 |
1227 | @@ -0,0 +1,114 @@ |
1228 | +/* |
1229 | + * Copyright © 2014 Canonical Ltd. |
1230 | + * |
1231 | + * This program is free software: you can redistribute it and/or modify it |
1232 | + * under the terms of the GNU Lesser General Public License version 3, |
1233 | + * as published by the Free Software Foundation. |
1234 | + * |
1235 | + * This program is distributed in the hope that it will be useful, |
1236 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1237 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1238 | + * GNU Lesser General Public License for more details. |
1239 | + * |
1240 | + * You should have received a copy of the GNU Lesser General Public License |
1241 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1242 | + * |
1243 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1244 | + */ |
1245 | + |
1246 | +#ifndef CLICK_JSON_OBJECT_H_ |
1247 | +#define CLICK_JSON_OBJECT_H_ |
1248 | + |
1249 | +#include <cstdint> |
1250 | + |
1251 | +#include <string> |
1252 | + |
1253 | +// Forward declare the opaque json_object handle from json-c here. |
1254 | +struct json_object; |
1255 | + |
1256 | +// We are wrapping libjson-c and introduce a generic Object type for that purpose. |
1257 | +namespace json |
1258 | +{ |
1259 | +// For internal purposes only |
1260 | +class Object |
1261 | +{ |
1262 | +public: |
1263 | + // Parses a new object from the given string. |
1264 | + // Throws std::runtime_error in case of parsing errors. |
1265 | + static Object parse_from_string(const std::string& s); |
1266 | + // Creates a new object of type array. |
1267 | + static Object create_array(); |
1268 | + // Creates a new object of type object. |
1269 | + static Object create_object(); |
1270 | + |
1271 | + // Shallow copy, only increments reference count. |
1272 | + Object(const Object& rhs); |
1273 | + // Decrements the reference count of the object. |
1274 | + ~Object(); |
1275 | + |
1276 | + // Shallow copy, decrements reference count of this object, |
1277 | + // increments reference count of object contained in rhs. |
1278 | + Object& operator=(const Object& rhs); |
1279 | + |
1280 | + // Encodes this object instance as a valid JSON string without any |
1281 | + // unneccessary whitespace |
1282 | + std::string to_plain_string(); |
1283 | + |
1284 | + // Resolves the object with the given name. |
1285 | + // Throws std::out_of_range if no object with the given name is known. |
1286 | + Object get(const std::string& name) const; |
1287 | + |
1288 | + // Attempts to resolve the object to a boolean value. |
1289 | + // Throws std::logic_error in case of type mismatches. |
1290 | + bool to_bool() const; |
1291 | + // Attempts to resolve the object to an integer value of 32bit width. |
1292 | + // Throws std::logic_error in case of type mismatches. |
1293 | + std::int32_t to_int32() const; |
1294 | + // Attempts to resolve the object to an integer value of 64bit width. |
1295 | + // Throws std::logic_error in case of type mismatches. |
1296 | + std::int64_t to_int64() const; |
1297 | + // Attempts to resolve the object to a floating point value. |
1298 | + // Throws std::logic_error in case of type mismatches. |
1299 | + double to_double() const; |
1300 | + // Attempts to resolve the object to a string value. |
1301 | + // Throws std::logic_error in case of type mismatches. |
1302 | + std::string to_string() const; |
1303 | + |
1304 | + // Adds the given array under the given name to this object instance. |
1305 | + void put_array(const std::string& name, Object array); |
1306 | + // Adds the given object under the given name to this object instance. |
1307 | + void put_object(const std::string& name, Object other); |
1308 | + // Adds the given boolean under the given name to this object instance. |
1309 | + void put_boolean(const std::string& name, bool value); |
1310 | + // Adds the given integer under the given name to this object instance. |
1311 | + void put_int32(const std::string& name, std::int32_t value); |
1312 | + // Adds the given integer under the given name to this object instance. |
1313 | + void put_int64(const std::string& name, std::int64_t value); |
1314 | + // Adds the given floating point value under the given name to this object instance. |
1315 | + void put_double(const std::string& name, double value); |
1316 | + // Adds the given string value under the given name to this object instance. |
1317 | + void put_string(const std::string& name, const std::string& value); |
1318 | + |
1319 | + // Only valid for array objects |
1320 | + // Returns the size of the array, throws std::logic_error if the object |
1321 | + // does not represent an array. |
1322 | + std::size_t array_size() const; |
1323 | + // Appends an object to the end of the array, throws std::logic_error if |
1324 | + // the object does not represent an array. |
1325 | + void append(Object other); |
1326 | + // Replaces the object at index 'index' with the given instance. |
1327 | + // Throws std::logic_error if the object does not represent an array. |
1328 | + // Throws std::out_of_range if the index exceeds the bounds of the array. |
1329 | + void put_object_for_index(std::size_t index, Object other); |
1330 | + // Queries the object at index 'index'. |
1331 | + // Throws std::logic_error if the object does not represent an array. |
1332 | + // Throws std::out_of_range if the index exceeds the bounds of the array. |
1333 | + Object get_object_for_index(std::size_t index); |
1334 | + |
1335 | +private: |
1336 | + Object(json_object* object); |
1337 | + json_object* object; |
1338 | +}; |
1339 | +} |
1340 | + |
1341 | +#endif // CLICK_JSON_OBJECT_H_ |
1342 | |
1343 | === added file 'src/core/trust/click/manifest.h' |
1344 | --- src/core/trust/click/manifest.h 1970-01-01 00:00:00 +0000 |
1345 | +++ src/core/trust/click/manifest.h 2014-08-26 14:23:37 +0000 |
1346 | @@ -0,0 +1,65 @@ |
1347 | +/* |
1348 | + * Copyright © 2014 Canonical Ltd. |
1349 | + * |
1350 | + * This program is free software: you can redistribute it and/or modify it |
1351 | + * under the terms of the GNU Lesser General Public License version 3, |
1352 | + * as published by the Free Software Foundation. |
1353 | + * |
1354 | + * This program is distributed in the hope that it will be useful, |
1355 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1356 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1357 | + * GNU Lesser General Public License for more details. |
1358 | + * |
1359 | + * You should have received a copy of the GNU Lesser General Public License |
1360 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1361 | + * |
1362 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1363 | + */ |
1364 | + |
1365 | +#ifndef CLICK_MANIFEST_H_ |
1366 | +#define CLICK_MANIFEST_H_ |
1367 | + |
1368 | +namespace click |
1369 | +{ |
1370 | +/** |
1371 | + * @brief Describes the click package contents, in JSON format. |
1372 | + * |
1373 | + * Please see http://click.readthedocs.org/en/latest/file-format.html#manifest |
1374 | + * |
1375 | + */ |
1376 | +struct Manifest |
1377 | +{ |
1378 | + /** @brief Enumerates all known JSON keys. */ |
1379 | + struct Json |
1380 | + { |
1381 | + Json() = delete; |
1382 | + |
1383 | + /** @brief Unique name for the application. */ |
1384 | + static constexpr const char* name {"name"}; |
1385 | + /** @brief Version number of the application. */ |
1386 | + static constexpr const char* version {"version"}; |
1387 | + /** @brief The system framework(s) for which the package was built. */ |
1388 | + static constexpr const char* framework {"framework"}; |
1389 | + /** @brief The size of the unpacked package in KiB. */ |
1390 | + static constexpr const char* installed_size {"installed-size"}; |
1391 | + |
1392 | + /** @brief Short (one-line) synopsis of the application. */ |
1393 | + static constexpr const char* title {"title"}; |
1394 | + /** @brief Extended description of the application; may be multi-paragraph. */ |
1395 | + static constexpr const char* description {"description"}; |
1396 | + /** @brief Name and email address of maintainer of the application. */ |
1397 | + static constexpr const char* maintainer {"maintainer"}; |
1398 | + /** |
1399 | + * @brief Icon to display in interfaces listing click packages. |
1400 | + * |
1401 | + * If the name refers to an existing file when resolved relative to the |
1402 | + * base directory of the package, the given file will be used; if not, |
1403 | + * the algorithm described in the Icon Theme Specification will be used |
1404 | + * to locate the icon |
1405 | + */ |
1406 | + static constexpr const char* icon {"icon"}; |
1407 | + }; |
1408 | +}; |
1409 | +} |
1410 | + |
1411 | +#endif // CLICK_MANIFEST_H_ |
1412 | |
1413 | === added file 'src/core/trust/click/package.h' |
1414 | --- src/core/trust/click/package.h 1970-01-01 00:00:00 +0000 |
1415 | +++ src/core/trust/click/package.h 2014-08-26 14:23:37 +0000 |
1416 | @@ -0,0 +1,103 @@ |
1417 | +/* |
1418 | + * Copyright © 2014 Canonical Ltd. |
1419 | + * |
1420 | + * This program is free software: you can redistribute it and/or modify it |
1421 | + * under the terms of the GNU Lesser General Public License version 3, |
1422 | + * as published by the Free Software Foundation. |
1423 | + * |
1424 | + * This program is distributed in the hope that it will be useful, |
1425 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1426 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1427 | + * GNU Lesser General Public License for more details. |
1428 | + * |
1429 | + * You should have received a copy of the GNU Lesser General Public License |
1430 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1431 | + * |
1432 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1433 | + */ |
1434 | + |
1435 | +#ifndef CLICK_PACKAGE_H_ |
1436 | +#define CLICK_PACKAGE_H_ |
1437 | + |
1438 | +#include <core/trust/click/framework.h> |
1439 | + |
1440 | +#include <boost/filesystem.hpp> |
1441 | + |
1442 | +#include <functional> |
1443 | +#include <map> |
1444 | +#include <memory> |
1445 | +#include <set> |
1446 | +#include <string> |
1447 | + |
1448 | +namespace click |
1449 | +{ |
1450 | +namespace installed |
1451 | +{ |
1452 | +struct Version; |
1453 | +} |
1454 | +/** @brief A click package. */ |
1455 | +struct Package |
1456 | +{ |
1457 | + /** @brief To save some typing. */ |
1458 | + typedef std::shared_ptr<Package> Ptr; |
1459 | + |
1460 | + /** @brief A specific version of a package. */ |
1461 | + struct Version |
1462 | + { |
1463 | + /** @brief To save some typing. */ |
1464 | + typedef std::shared_ptr<Version> Ptr; |
1465 | + |
1466 | + /** @brief Functor invoked for every required framework. */ |
1467 | + typedef std::function<void(const Framework::Ptr&)> FrameworkEnumerator; |
1468 | + |
1469 | + /** @cond */ |
1470 | + Version() = default; |
1471 | + virtual ~Version() = default; |
1472 | + /** @endcond */ |
1473 | + |
1474 | + /** @brief Parent package of this specific version. */ |
1475 | + virtual Package& parent() = 0; |
1476 | + |
1477 | + /** @brief Version number of the package. */ |
1478 | + virtual std::string specifier() = 0; |
1479 | + |
1480 | + /** @brief Frameworks required by this specific version of the package. */ |
1481 | + virtual void enumerate_required_frameworks(FrameworkEnumerator) = 0; |
1482 | + |
1483 | + /** @brief Returns the installed details if the package is installed or throws. */ |
1484 | + virtual installed::Version& resolve_to_installed_version_or_throw() = 0; |
1485 | + }; |
1486 | + |
1487 | + /** @brief Functor invoked for every known version of the package. */ |
1488 | + typedef std::function<void(const Version::Ptr&)> VersionEnumerator; |
1489 | + |
1490 | + /** @cond */ |
1491 | + Package() = default; |
1492 | + virtual ~Package() = default; |
1493 | + /** @endcond */ |
1494 | + |
1495 | + /** @brief Unique name of the package. */ |
1496 | + virtual std::string name() = 0; |
1497 | + |
1498 | + /** @brief All known versions of the package. */ |
1499 | + virtual void enumerate_versions(VersionEnumerator) = 0; |
1500 | + |
1501 | + /** @brief Queries the current version of the package. */ |
1502 | + virtual Version::Ptr current_version() = 0; |
1503 | +}; |
1504 | + |
1505 | +namespace installed |
1506 | +{ |
1507 | +/** @brief Marks an installed, locally available version. */ |
1508 | +struct Version : public click::Package::Version |
1509 | +{ |
1510 | + /** @brief Resolves a resource in a package version. */ |
1511 | + virtual boost::filesystem::path resolve_named_resource(const std::string& resource_name) = 0; |
1512 | + |
1513 | + /** @brief Size of the unpackaged package in KiB. */ |
1514 | + virtual std::size_t size() = 0; |
1515 | +}; |
1516 | +} |
1517 | +} |
1518 | + |
1519 | +#endif // CLICK_PACKAGE_H_ |
1520 | |
1521 | === added file 'src/core/trust/click/paths.cpp' |
1522 | --- src/core/trust/click/paths.cpp 1970-01-01 00:00:00 +0000 |
1523 | +++ src/core/trust/click/paths.cpp 2014-08-26 14:23:37 +0000 |
1524 | @@ -0,0 +1,42 @@ |
1525 | +/* |
1526 | + * Copyright © 2014 Canonical Ltd. |
1527 | + * |
1528 | + * This program is free software: you can redistribute it and/or modify it |
1529 | + * under the terms of the GNU Lesser General Public License version 3, |
1530 | + * as published by the Free Software Foundation. |
1531 | + * |
1532 | + * This program is distributed in the hope that it will be useful, |
1533 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1534 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1535 | + * GNU Lesser General Public License for more details. |
1536 | + * |
1537 | + * You should have received a copy of the GNU Lesser General Public License |
1538 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1539 | + * |
1540 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1541 | + */ |
1542 | + |
1543 | +#include <core/trust/click/paths.h> |
1544 | + |
1545 | +namespace |
1546 | +{ |
1547 | +static constexpr const char* the_database_config_dir |
1548 | +{ |
1549 | + "/etc/click/databases" |
1550 | +}; |
1551 | + |
1552 | +static constexpr const char* the_frameworks_config_dir |
1553 | +{ |
1554 | + "/usr/share/click/frameworks" |
1555 | +}; |
1556 | +} |
1557 | + |
1558 | +std::string click::Paths::default_database_config_dir() const |
1559 | +{ |
1560 | + return the_database_config_dir; |
1561 | +} |
1562 | + |
1563 | +std::string click::Paths::default_frameworks_config_dir() const |
1564 | +{ |
1565 | + return the_frameworks_config_dir; |
1566 | +} |
1567 | |
1568 | === added file 'src/core/trust/click/paths.h' |
1569 | --- src/core/trust/click/paths.h 1970-01-01 00:00:00 +0000 |
1570 | +++ src/core/trust/click/paths.h 2014-08-26 14:23:37 +0000 |
1571 | @@ -0,0 +1,45 @@ |
1572 | +/* |
1573 | + * Copyright © 2014 Canonical Ltd. |
1574 | + * |
1575 | + * This program is free software: you can redistribute it and/or modify it |
1576 | + * under the terms of the GNU Lesser General Public License version 3, |
1577 | + * as published by the Free Software Foundation. |
1578 | + * |
1579 | + * This program is distributed in the hope that it will be useful, |
1580 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1581 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1582 | + * GNU Lesser General Public License for more details. |
1583 | + * |
1584 | + * You should have received a copy of the GNU Lesser General Public License |
1585 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1586 | + * |
1587 | + * Authored by: Thomas Voß <thomas.voss@canonical.com> |
1588 | + */ |
1589 | + |
1590 | +#ifndef CLICK_PATHS_H_ |
1591 | +#define CLICK_PATHS_H_ |
1592 | + |
1593 | +#include <memory> |
1594 | +#include <string> |
1595 | + |
1596 | +namespace click |
1597 | +{ |
1598 | +/** @brief Provides default settings for config directories. */ |
1599 | +struct Paths |
1600 | +{ |
1601 | + /** @brief To save some typing. */ |
1602 | + typedef std::shared_ptr<Paths> Ptr; |
1603 | + |
1604 | + /** @cond */ |
1605 | + Paths() = default; |
1606 | + virtual ~Paths() = default; |
1607 | + /** @endcond */ |
1608 | + |
1609 | + /** @brief The default database config directory, i.e., /etc/click/databases */ |
1610 | + virtual std::string default_database_config_dir() const; |
1611 | + /** @brief The default frameworks config directory, i.e., /usr/share/click/frameworks */ |
1612 | + virtual std::string default_frameworks_config_dir() const; |
1613 | +}; |
1614 | +} |
1615 | + |
1616 | +#endif // CLICK_PATHS_H_ |