Return a integer result code specifying why we failed, if we fail.
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
cf.set_global(false);
- if (!cf.parse()) {
+ if (cf.parse() != 0) {
derr << "cannot parse buffer" << dendl;
goto done_err;
}
}
if (caps_fn) {
ConfFile *cf = new ConfFile(caps_fn);
- if (!cf->parse()) {
+ if (cf->parse() != 0) {
cerr << "could not parse caps file " << caps_fn << std::endl;
exit(1);
}
return sec;
}
-int ConfFile::_open()
-{
- if (filename)
- return open(filename, O_RDONLY);
-
- if (!pbl)
- return -EINVAL;
-
- buf_pos = 0;
-
- return 0;
-}
-
int ConfFile::_read(int fd, char *buf, size_t size)
{
if (filename)
return 0;
}
-bool ConfFile::_parse(const char *filename, ConfSection **psection)
+int ConfFile::_parse(const char *filename, ConfSection **psection)
{
char *buf;
int len, i, l;
int fd;
int max_line = MAX_LINE;
int eof = 0;
- bool ret = true;
+ bool ret = 0;
- fd = _open();
- if (fd < 0)
- return false;
+ if (filename) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return -errno;
+ }
+ else {
+ if (!pbl)
+ return -EINVAL;
+ buf_pos = 0;
+ }
line = (char *)malloc(max_line);
l = 0;
do {
len = _read(fd, buf, BUF_SIZE);
if (len < 0) {
- ret = false;
+ ret = -EDOM;
goto done;
}
if (cl->get_var()) {
if (strcmp(cl->get_var(), "include") == 0) {
if (!filename) { // don't allow including if we're not using files
- ret = false;
+ ret = -EDOM;
goto done;
}
if (!_parse(cl->get_val(), §ion)) {
} else {
char *norm_var = cl->get_norm_var();
if (!section) {
- ret = false;
+ ret = -EDOM;
goto done;
}
section->conf_map[norm_var] = cl;
return ret;
}
-bool ConfFile::parse()
+int ConfFile::parse()
{
ConfSection *section = NULL;
sections_list.push_back(section);
}
- bool res = _parse(filename, §ion);
+ int res = _parse(filename, §ion);
parse_lock.Unlock();
return res;
}
ConfSection *_add_section(const char *section, ConfLine *cl);
void _dump(int fd);
- bool _parse(const char *filename, ConfSection **psection);
+ int _parse(const char *filename, ConfSection **psection);
void common_init();
int _read(int fd, char *buf, size_t size);
- int _open();
int _close(int fd);
public:
ConfFile(const char *fname);
const SectionList& get_section_list() { return sections_list; }
const char *get_filename() { return filename; }
- bool parse();
+ int parse();
int read(const char *section, const char *var, int *val, int def_val);
int read(const char *section, const char *var, unsigned int *val, unsigned int def_val);
int read(const char *section, const char *var, long long *val, long long def_val);
int opt_len = sizeof(config_optionsp)/sizeof(config_option);
cf->set_post_process_func(conf_post_process_val);
- if (!cf->parse())
+ if (cf->parse() != 0)
return false;
for (int i=0; i<opt_len; i++) {
if (!ls.empty()) {
for (list<string>::iterator p = ls.begin(); p != ls.end(); p++) {
ConfFile c(p->c_str());
- if (c.parse()) {
+ if (c.parse() == 0) {
for (list<ConfSection*>::const_iterator q = c.get_section_list().begin();
q != c.get_section_list().end();
q++) {