mirror of
https://github.com/samba-team/samba.git
synced 2025-02-08 05:57:51 +03:00
lib/util: add pm_process_with_flags to allow parsing ini files with empty values
Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
parent
235aa67544
commit
7eeb2edc50
@ -96,7 +96,30 @@ bool pm_process(const char *filename,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = tini_parse(f, sfunc, pfunc, private_data);
|
ret = tini_parse(f, false, sfunc, pfunc, private_data);
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool pm_process_with_flags(const char *filename,
|
||||||
|
bool allow_empty_values,
|
||||||
|
bool (*sfunc)(const char *section, void *private_data),
|
||||||
|
bool (*pfunc)(const char *name, const char *value,
|
||||||
|
void *private_data),
|
||||||
|
void *private_data)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
bool ret;
|
||||||
|
|
||||||
|
f = fopen(filename, "r");
|
||||||
|
if (f == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = tini_parse(f, allow_empty_values, sfunc, pfunc, private_data);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
@ -609,6 +609,12 @@ bool pm_process( const char *fileName,
|
|||||||
bool (*sfunc)(const char *, void *),
|
bool (*sfunc)(const char *, void *),
|
||||||
bool (*pfunc)(const char *, const char *, void *),
|
bool (*pfunc)(const char *, const char *, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
bool pm_process_with_flags(const char *filename,
|
||||||
|
bool allow_empty_values,
|
||||||
|
bool (*sfunc)(const char *section, void *private_data),
|
||||||
|
bool (*pfunc)(const char *name, const char *value,
|
||||||
|
void *private_data),
|
||||||
|
void *private_data);
|
||||||
|
|
||||||
void print_asc(int level, const uint8_t *buf,int len);
|
void print_asc(int level, const uint8_t *buf,int len);
|
||||||
void print_asc_cb(const uint8_t *buf, int len,
|
void print_asc_cb(const uint8_t *buf, int len,
|
||||||
|
@ -227,19 +227,27 @@ static char *trim_one_space(char *buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_param(char *buf,
|
static bool parse_param(char *buf,
|
||||||
|
bool allow_empty_value,
|
||||||
bool (*pfunc)(const char *name, const char *value,
|
bool (*pfunc)(const char *name, const char *value,
|
||||||
void *private_data),
|
void *private_data),
|
||||||
void *private_data)
|
void *private_data)
|
||||||
{
|
{
|
||||||
char *equals;
|
char *equals;
|
||||||
char *name, *value;
|
char *name;
|
||||||
|
const char *value;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
bool no_value = false;
|
||||||
|
|
||||||
equals = strchr(buf, '=');
|
equals = strchr(buf, '=');
|
||||||
if (equals == NULL) {
|
if (equals != NULL) {
|
||||||
return true;
|
*equals = '\0';
|
||||||
|
} else {
|
||||||
|
if (allow_empty_value) {
|
||||||
|
no_value = true;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*equals = '\0';
|
|
||||||
|
|
||||||
name = trim_one_space(buf);
|
name = trim_one_space(buf);
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
@ -247,12 +255,17 @@ static bool parse_param(char *buf,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = trim_one_space(equals+1);
|
if (no_value) {
|
||||||
|
value = "";
|
||||||
|
} else {
|
||||||
|
value = trim_one_space(equals+1);
|
||||||
|
}
|
||||||
|
|
||||||
return pfunc(name, value, private_data);
|
return pfunc(name, value, private_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tini_parse(FILE *f,
|
bool tini_parse(FILE *f,
|
||||||
|
bool allow_empty_value,
|
||||||
bool (*sfunc)(const char *section, void *private_data),
|
bool (*sfunc)(const char *section, void *private_data),
|
||||||
bool (*pfunc)(const char *name, const char *value,
|
bool (*pfunc)(const char *name, const char *value,
|
||||||
void *private_data),
|
void *private_data),
|
||||||
@ -293,7 +306,7 @@ bool tini_parse(FILE *f,
|
|||||||
ok = parse_section(buf, sfunc, private_data);
|
ok = parse_section(buf, sfunc, private_data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ok = parse_param(buf, pfunc, private_data);
|
ok = parse_param(buf, allow_empty_value, pfunc, private_data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
bool tini_parse(FILE *f,
|
bool tini_parse(FILE *f,
|
||||||
|
bool allow_empty_value,
|
||||||
bool (*sfunc)(const char *section, void *private_data),
|
bool (*sfunc)(const char *section, void *private_data),
|
||||||
bool (*pfunc)(const char *name, const char *value,
|
bool (*pfunc)(const char *name, const char *value,
|
||||||
void *private_data),
|
void *private_data),
|
||||||
|
@ -339,6 +339,7 @@ struct tiniparser_dictionary *tiniparser_load(const char *filename)
|
|||||||
d->section_list = NULL;
|
d->section_list = NULL;
|
||||||
|
|
||||||
ret = tini_parse(fp,
|
ret = tini_parse(fp,
|
||||||
|
false,
|
||||||
section_parser,
|
section_parser,
|
||||||
value_parser,
|
value_parser,
|
||||||
d);
|
d);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user