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) (side-by-side diff)
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 @@
+#include <cassert>
+#include <stdexcept>
+#include <autosprintf.h>
+#include "eyekinfig.h"
+
+#include "config.h"
+
+eyekinfig_t::eyekinfig_t(const std::string& ma)
+ : macaddress(ma) {
+ static cfg_opt_t opts[] = {
+ CFG_STR((char*)"targetdir",(char*)"/var/lib/" PACKAGE "/%s",CFGF_NONE),
+ CFG_STR((char*)"uploadkey",(char*)"",CFGF_NONE),
+ CFG_STR((char*)"on-start-session",(char*)"",CFGF_NONE),
+ CFG_STR((char*)"on-upload-photo",(char*)"",CFGF_NONE),
+ CFG_STR((char*)"on-mark-last-photo-in-roll",(char*)"",CFGF_NONE),
+ CFG_INT((char*)"umask",022,CFGF_NONE),
+ CFG_END()
+ };
+ cfg = cfg_init(opts,CFGF_NONE);
+ if(!cfg)
+ throw std::runtime_error("failed to cfg_init()");
+ std::string::size_type ls = macaddress.rfind('/');
+ if(cfg_parse(cfg,gnu::autosprintf(
+ EYEKIN_CONF_DIR "/%s.conf",
+ (ls==std::string::npos)
+ ? macaddress.c_str()
+ : macaddress.substr(ls+1).c_str()
+ )) ==CFG_PARSE_ERROR) {
+ if(cfg) cfg_free(cfg);
+ cfg=0;
+ throw std::runtime_error("failed to cfg_parse()");
+ }
+ }
+
+eyekinfig_t::~eyekinfig_t() {
+ if(cfg) cfg_free(cfg);
+}
+
+std::string eyekinfig_t::get_targetdir() {
+ assert(cfg);
+ return gnu::autosprintf(cfg_getstr(cfg,"targetdir"),macaddress.c_str());
+}
+
+std::string eyekinfig_t::get_upload_key() {
+ assert(cfg);
+ return cfg_getstr(cfg,"uploadkey");
+}
+
+std::string eyekinfig_t::get_on_start_session() {
+ assert(cfg);
+ return cfg_getstr(cfg,"on-start-session");
+}
+std::string eyekinfig_t::get_on_upload_photo() {
+ assert(cfg);
+ return cfg_getstr(cfg,"on-upload-photo");
+}
+
+std::string eyekinfig_t::get_on_mark_last_photo_in_roll() {
+ assert(cfg);
+ return cfg_getstr(cfg,"on-mark-last-photo-in-roll");
+}
+
+
+int eyekinfig_t::get_umask() {
+ assert(cfg);
+ return cfg_getint(cfg,"umask");
+}