author | Michael Krelin <hacker@klever.net> | 2012-01-20 21:49:19 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2012-01-20 21:49:19 (UTC) |
commit | 8e34d78443b8b53e90900fc9e2f7b4d7366596b0 (patch) (unidiff) | |
tree | 21017b3ef5f3be00b96814b841aa605a645b6ef7 | |
parent | 2c469d2d891899dbb51a6125fec3980dac6a7ec0 (diff) | |
download | iii-8e34d78443b8b53e90900fc9e2f7b4d7366596b0.zip iii-8e34d78443b8b53e90900fc9e2f7b4d7366596b0.tar.gz iii-8e34d78443b8b53e90900fc9e2f7b4d7366596b0.tar.bz2 |
initialize config's "cfg" to null
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | src/eyekinfig.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/eyekinfig.cc b/src/eyekinfig.cc index 6dde7b2..79cec80 100644 --- a/src/eyekinfig.cc +++ b/src/eyekinfig.cc | |||
@@ -1,56 +1,56 @@ | |||
1 | #include <cassert> | 1 | #include <cassert> |
2 | #include <stdexcept> | 2 | #include <stdexcept> |
3 | #include <autosprintf.h> | 3 | #include <autosprintf.h> |
4 | #include "eyekinfig.h" | 4 | #include "eyekinfig.h" |
5 | 5 | ||
6 | #include "config.h" | 6 | #include "config.h" |
7 | 7 | ||
8 | eyekinfig_t::eyekinfig_t(const std::string& ma) : macaddress(ma) { | 8 | eyekinfig_t::eyekinfig_t(const std::string& ma) : macaddress(ma), cfg(0) { |
9 | try { | 9 | try { |
10 | static cfg_opt_t opts[] = { | 10 | static cfg_opt_t opts[] = { |
11 | CFG_STR((char*)"targetdir",(char*)"/var/lib/" PACKAGE "/%s",CFGF_NONE), | 11 | CFG_STR((char*)"targetdir",(char*)"/var/lib/" PACKAGE "/%s",CFGF_NONE), |
12 | CFG_STR((char*)"uploadkey",(char*)"",CFGF_NONE), | 12 | CFG_STR((char*)"uploadkey",(char*)"",CFGF_NONE), |
13 | CFG_STR((char*)"on-start-session",(char*)"",CFGF_NONE), | 13 | CFG_STR((char*)"on-start-session",(char*)"",CFGF_NONE), |
14 | CFG_STR((char*)"on-upload-photo",(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), | 15 | CFG_STR((char*)"on-mark-last-photo-in-roll",(char*)"",CFGF_NONE), |
16 | CFG_INT((char*)"umask",022,CFGF_NONE), | 16 | CFG_INT((char*)"umask",022,CFGF_NONE), |
17 | CFG_END() | 17 | CFG_END() |
18 | }; | 18 | }; |
19 | cfg = cfg_init(opts,CFGF_NONE); | 19 | cfg = cfg_init(opts,CFGF_NONE); |
20 | if(!cfg) | 20 | if(!cfg) |
21 | throw std::runtime_error("failed to cfg_init()"); | 21 | throw std::runtime_error("failed to cfg_init()"); |
22 | std::string::size_type ls = macaddress.rfind('/'); | 22 | std::string::size_type ls = macaddress.rfind('/'); |
23 | std::string cf = gnu::autosprintf( EYEKIN_CONF_DIR "/%s.conf", | 23 | std::string cf = gnu::autosprintf( EYEKIN_CONF_DIR "/%s.conf", |
24 | macaddress.c_str()+((ls==std::string::npos)?0:ls+1) ); | 24 | macaddress.c_str()+((ls==std::string::npos)?0:ls+1) ); |
25 | int r = cfg_parse(cfg,cf.c_str()); | 25 | int r = cfg_parse(cfg,cf.c_str()); |
26 | if(r != CFG_SUCCESS) { | 26 | if(r != CFG_SUCCESS) { |
27 | cfg_free(cfg); cfg=0; | 27 | cfg_free(cfg); cfg=0; |
28 | if(CFG_FILE_ERROR) throw std::runtime_error(gnu::autosprintf("failed to open configuration file '%s'",cf.c_str())); | 28 | if(CFG_FILE_ERROR) throw std::runtime_error(gnu::autosprintf("failed to open configuration file '%s'",cf.c_str())); |
29 | throw std::runtime_error(gnu::autosprintf("failed to parse configuration file '%s'",cf.c_str())); | 29 | throw std::runtime_error(gnu::autosprintf("failed to parse configuration file '%s'",cf.c_str())); |
30 | } | 30 | } |
31 | }catch(...) { | 31 | }catch(...) { |
32 | if(cfg) cfg_free(cfg), cfg=0; | 32 | if(cfg) cfg_free(cfg), cfg=0; |
33 | throw; | 33 | throw; |
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | eyekinfig_t::~eyekinfig_t() { | 37 | eyekinfig_t::~eyekinfig_t() { |
38 | if(cfg) cfg_free(cfg); | 38 | if(cfg) cfg_free(cfg); |
39 | } | 39 | } |
40 | 40 | ||
41 | std::string eyekinfig_t::get_targetdir() { | 41 | std::string eyekinfig_t::get_targetdir() { |
42 | assert(cfg); | 42 | assert(cfg); |
43 | return gnu::autosprintf(cfg_getstr(cfg,"targetdir"),macaddress.c_str()); | 43 | return gnu::autosprintf(cfg_getstr(cfg,"targetdir"),macaddress.c_str()); |
44 | } | 44 | } |
45 | 45 | ||
46 | std::string eyekinfig_t::get_upload_key() { | 46 | std::string eyekinfig_t::get_upload_key() { |
47 | assert(cfg); | 47 | assert(cfg); |
48 | return cfg_getstr(cfg,"uploadkey"); | 48 | return cfg_getstr(cfg,"uploadkey"); |
49 | } | 49 | } |
50 | 50 | ||
51 | std::string eyekinfig_t::get_on_start_session() { | 51 | std::string eyekinfig_t::get_on_start_session() { |
52 | assert(cfg); | 52 | assert(cfg); |
53 | return cfg_getstr(cfg,"on-start-session"); | 53 | return cfg_getstr(cfg,"on-start-session"); |
54 | } | 54 | } |
55 | std::string eyekinfig_t::get_on_upload_photo() { | 55 | std::string eyekinfig_t::get_on_upload_photo() { |
56 | assert(cfg); | 56 | assert(cfg); |