summaryrefslogtreecommitdiffabout
path: root/src/eyekinfig.cc
authorMichael Krelin <hacker@klever.net>2009-03-08 20:09:21 (UTC)
committer Michael Krelin <hacker@klever.net>2009-03-08 20:09:21 (UTC)
commitaadaa8b5d7eda23e72dbded9d6437b40358353f3 (patch) (unidiff)
tree0bff6fdde1e2b9be02b48aaf7d03f095604718e1 /src/eyekinfig.cc
downloadiii-aadaa8b5d7eda23e72dbded9d6437b40358353f3.zip
iii-aadaa8b5d7eda23e72dbded9d6437b40358353f3.tar.gz
iii-aadaa8b5d7eda23e72dbded9d6437b40358353f3.tar.bz2
Inital commit to public repository0.0
Diffstat (limited to 'src/eyekinfig.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyekinfig.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/eyekinfig.cc b/src/eyekinfig.cc
new file mode 100644
index 0000000..27a5a56
--- a/dev/null
+++ b/src/eyekinfig.cc
@@ -0,0 +1,67 @@
1#include <cassert>
2#include <stdexcept>
3#include <autosprintf.h>
4#include "eyekinfig.h"
5
6#include "config.h"
7
8eyekinfig_t::eyekinfig_t(const std::string& ma)
9 : macaddress(ma) {
10 static cfg_opt_t opts[] = {
11 CFG_STR((char*)"targetdir",(char*)"/var/lib/" PACKAGE "/%s",CFGF_NONE),
12 CFG_STR((char*)"uploadkey",(char*)"",CFGF_NONE),
13 CFG_STR((char*)"on-start-session",(char*)"",CFGF_NONE),
14 CFG_STR((char*)"on-upload-photo",(char*)"",CFGF_NONE),
15 CFG_STR((char*)"on-mark-last-photo-in-roll",(char*)"",CFGF_NONE),
16 CFG_INT((char*)"umask",022,CFGF_NONE),
17 CFG_END()
18 };
19 cfg = cfg_init(opts,CFGF_NONE);
20 if(!cfg)
21 throw std::runtime_error("failed to cfg_init()");
22 std::string::size_type ls = macaddress.rfind('/');
23 if(cfg_parse(cfg,gnu::autosprintf(
24 EYEKIN_CONF_DIR "/%s.conf",
25 (ls==std::string::npos)
26 ? macaddress.c_str()
27 : macaddress.substr(ls+1).c_str()
28 )) ==CFG_PARSE_ERROR) {
29 if(cfg) cfg_free(cfg);
30 cfg=0;
31 throw std::runtime_error("failed to cfg_parse()");
32 }
33 }
34
35eyekinfig_t::~eyekinfig_t() {
36 if(cfg) cfg_free(cfg);
37}
38
39std::string eyekinfig_t::get_targetdir() {
40 assert(cfg);
41 return gnu::autosprintf(cfg_getstr(cfg,"targetdir"),macaddress.c_str());
42}
43
44std::string eyekinfig_t::get_upload_key() {
45 assert(cfg);
46 return cfg_getstr(cfg,"uploadkey");
47}
48
49std::string eyekinfig_t::get_on_start_session() {
50 assert(cfg);
51 return cfg_getstr(cfg,"on-start-session");
52}
53std::string eyekinfig_t::get_on_upload_photo() {
54 assert(cfg);
55 return cfg_getstr(cfg,"on-upload-photo");
56}
57
58std::string eyekinfig_t::get_on_mark_last_photo_in_roll() {
59 assert(cfg);
60 return cfg_getstr(cfg,"on-mark-last-photo-in-roll");
61}
62
63
64int eyekinfig_t::get_umask() {
65 assert(cfg);
66 return cfg_getint(cfg,"umask");
67}