Feature #494 ยป 0061-registry_ini.-ch-Replace-NULLs-with-nullptrs.patch
utility/registry_ini.c | ||
---|---|---|
***********************************************************************/
|
||
/**************************************************************************
|
||
the idea with this file is to create something similar to the ms-windows
|
||
The idea with this file is to create something similar to the ms-windows
|
||
.ini files functions.
|
||
however the interface is nice. ie:
|
||
secfile_lookup_str(file, "player%d.unit%d.name", plrno, unitno);
|
||
... | ... | |
char *name; /* Name, not including section prefix. */
|
||
enum entry_type type; /* The type of the entry. */
|
||
int used; /* Number of times entry looked up. */
|
||
char *comment; /* Comment, may be NULL. */
|
||
char *comment; /* Comment, may be nullptr. */
|
||
union {
|
||
/* ENTRY_BOOL */
|
||
... | ... | |
static const char *const allowed = "_.,-[]";
|
||
while ('\0' != *name) {
|
||
if (!fc_isalnum(*name) && NULL == strchr(allowed, *name)) {
|
||
if (!fc_isalnum(*name) && strchr(allowed, *name) == nullptr) {
|
||
return FALSE;
|
||
}
|
||
name++;
|
||
... | ... | |
char buf[256];
|
||
struct entry *hentry;
|
||
if (NULL == secfile->hash.entries) {
|
||
if (secfile->hash.entries == nullptr) {
|
||
/* Consider as success if this secfile doesn't have built the entries
|
||
* hash table. */
|
||
return TRUE;
|
||
... | ... | |
entry_path(pentry, buf, sizeof(buf));
|
||
if (entry_hash_replace_full(secfile->hash.entries, buf, pentry,
|
||
NULL, &hentry)) {
|
||
nullptr, &hentry)) {
|
||
entry_use(hentry);
|
||
if (!secfile->allow_duplicates) {
|
||
SECFILE_LOG(secfile, entry_section(hentry),
|
||
... | ... | |
{
|
||
char buf[256];
|
||
if (NULL == secfile->hash.entries) {
|
||
if (secfile->hash.entries == nullptr) {
|
||
/* Consider as success if this secfile doesn't have built the entries
|
||
* hash table. */
|
||
return TRUE;
|
||
... | ... | |
bool allow_duplicates)
|
||
{
|
||
struct section_file *secfile;
|
||
struct section *psection = NULL;
|
||
struct section *single_section = NULL;
|
||
struct section *psection = nullptr;
|
||
struct section *single_section = nullptr;
|
||
bool table_state = FALSE; /* TRUE when within tabular format. */
|
||
int table_lineno = 0; /* Row number in tabular, 0 top data row. */
|
||
const char *tok;
|
||
... | ... | |
bool error = FALSE;
|
||
if (!inf) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/* Assign the real value later, to speed up the creation of new entries. */
|
||
... | ... | |
if (filename) {
|
||
secfile->name = fc_strdup(filename);
|
||
} else {
|
||
secfile->name = NULL;
|
||
secfile->name = nullptr;
|
||
}
|
||
astring_vector_init(&columns);
|
||
... | ... | |
}
|
||
astring_vector_free(&columns);
|
||
if (section != NULL) {
|
||
if (section != nullptr) {
|
||
if (!found_my_section) {
|
||
secfile_destroy(secfile);
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/* Build the entry hash table with single section information */
|
||
... | ... | |
entry_list_iterate(section_entries(single_section), pentry) {
|
||
if (!secfile_hash_insert(secfile, pentry)) {
|
||
secfile_destroy(secfile);
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} entry_list_iterate_end;
|
||
... | ... | |
}
|
||
if (error) {
|
||
secfile_destroy(secfile);
|
||
return NULL;
|
||
return nullptr;
|
||
} else {
|
||
return secfile;
|
||
}
|
||
... | ... | |
/**********************************************************************//**
|
||
Create a section file from a file, read only one particular section.
|
||
Returns NULL on error.
|
||
Returns nullptr on error.
|
||
**************************************************************************/
|
||
struct section_file *secfile_load_section(const char *filename,
|
||
const char *section,
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Create a section file from a stream. Returns NULL on error.
|
||
Create a section file from a stream. Returns nullptr on error.
|
||
**************************************************************************/
|
||
struct section_file *secfile_from_stream(fz_FILE *stream,
|
||
bool allow_duplicates)
|
||
{
|
||
return secfile_from_input_file(inf_from_stream(stream, datafilename),
|
||
NULL, NULL, allow_duplicates);
|
||
nullptr, nullptr, allow_duplicates);
|
||
}
|
||
/**********************************************************************//**
|
||
... | ... | |
struct entry *pentry, *col_pentry;
|
||
int i;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, FALSE);
|
||
if (NULL == filename) {
|
||
if (filename == nullptr) {
|
||
filename = secfile->name;
|
||
}
|
||
... | ... | |
compression_method, compression_level);
|
||
if (!fs) {
|
||
SECFILE_LOG(secfile, NULL, _("Could not open %s for writing"), real_filename);
|
||
SECFILE_LOG(secfile, nullptr, _("Could not open %s for writing"), real_filename);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
/* Tables: break out of this loop if this is a non-table
|
||
* entry (pentry and ent_iter unchanged) or after table (pentry
|
||
* and ent_iter suitably updated, pentry possibly NULL).
|
||
* and ent_iter suitably updated, pentry possibly nullptr).
|
||
* After each table, loop again in case the next entry
|
||
* is another table.
|
||
*/
|
||
... | ... | |
for (i = 1;; i++) {
|
||
col_iter = entry_list_link_next(ent_iter);
|
||
col_pentry = entry_list_link_data(col_iter);
|
||
if (NULL == col_pentry || col_pentry->type == ENTRY_LONG_COMMENT) {
|
||
if (col_pentry == nullptr || col_pentry->type == ENTRY_LONG_COMMENT) {
|
||
break;
|
||
}
|
||
fc_snprintf(pentry_name, sizeof(pentry_name),
|
||
... | ... | |
} section_list_iterate_end;
|
||
if (0 != fz_ferror(fs)) {
|
||
SECFILE_LOG(secfile, NULL, "Error before closing %s: %s",
|
||
SECFILE_LOG(secfile, nullptr, "Error before closing %s: %s",
|
||
real_filename, fz_strerror(fs));
|
||
fz_fclose(fs);
|
||
return FALSE;
|
||
}
|
||
if (0 != fz_fclose(fs)) {
|
||
SECFILE_LOG(secfile, NULL, "Error closing %s", real_filename);
|
||
SECFILE_LOG(secfile, nullptr, "Error closing %s", real_filename);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
}
|
||
if (are_deprecation_warnings_enabled()) {
|
||
log_deprecation_always("%s: unused entry: %s.%s",
|
||
secfile->name != NULL ? secfile->name : "nameless",
|
||
secfile->name != nullptr ? secfile->name : "nameless",
|
||
section_name(psection), entry_name(pentry));
|
||
} else {
|
||
#ifdef FREECIV_TESTMATIC
|
||
log_testmatic("%s: unused entry: %s.%s",
|
||
secfile->name != NULL ? secfile->name : "nameless",
|
||
secfile->name != nullptr ? secfile->name : "nameless",
|
||
section_name(psection), entry_name(pentry));
|
||
#else /* FREECIV_TESTMATIC */
|
||
log_verbose(" unused entry: %s.%s",
|
||
... | ... | |
**************************************************************************/
|
||
const char *secfile_name(const struct section_file *secfile)
|
||
{
|
||
if (NULL == secfile) {
|
||
return "NULL";
|
||
if (secfile == nullptr) {
|
||
return "nullptr";
|
||
} else if (secfile->name) {
|
||
return secfile->name;
|
||
} else {
|
||
... | ... | |
ent_name = strchr(fullpath, '.');
|
||
if (!ent_name) {
|
||
SECFILE_LOG(secfile, NULL,
|
||
SECFILE_LOG(secfile, nullptr,
|
||
"Section and entry names must be separated by a dot.");
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/* Separates section and entry names. */
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH];
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (allow_replace) {
|
||
pentry = section_entry_by_name(psection, ent_name);
|
||
if (NULL != pentry) {
|
||
if (pentry != nullptr) {
|
||
if (ENTRY_BOOL == entry_type_get(pentry)) {
|
||
if (!entry_bool_set(pentry, value)) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} else {
|
||
entry_destroy(pentry);
|
||
pentry = NULL;
|
||
pentry = nullptr;
|
||
}
|
||
}
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_bool_new(psection, ent_name, value);
|
||
}
|
||
if (NULL != pentry && NULL != comment) {
|
||
if (pentry != nullptr && comment != nullptr) {
|
||
entry_set_comment(pentry, comment);
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Insert 'dim' boolean entries at 'path,0', 'path,1' etc. Returns
|
||
the number of entries inserted or replaced.
|
||
Insert 'dim' boolean entries at 'path,0', 'path,1' etc.
|
||
Returns the number of entries inserted or replaced.
|
||
**************************************************************************/
|
||
size_t secfile_insert_bool_vec_full(struct section_file *secfile,
|
||
const bool *values, size_t dim,
|
||
... | ... | |
size_t i, ret = 0;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, 0);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
* of the file. */
|
||
if (dim > 0
|
||
&& NULL != secfile_insert_bool_full(secfile, values[0], comment,
|
||
allow_replace, "%s", fullpath)) {
|
||
&& secfile_insert_bool_full(secfile, values[0], comment,
|
||
allow_replace, "%s", fullpath) != nullptr) {
|
||
ret++;
|
||
}
|
||
for (i = 1; i < dim; i++) {
|
||
if (NULL != secfile_insert_bool_full(secfile, values[i], comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i)) {
|
||
if (secfile_insert_bool_full(secfile, values[i], comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i) != nullptr) {
|
||
ret++;
|
||
}
|
||
}
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH];
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (allow_replace) {
|
||
pentry = section_entry_by_name(psection, ent_name);
|
||
if (NULL != pentry) {
|
||
if (pentry != nullptr) {
|
||
if (ENTRY_INT == entry_type_get(pentry)) {
|
||
if (!entry_int_set(pentry, value)) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} else {
|
||
entry_destroy(pentry);
|
||
pentry = NULL;
|
||
pentry = nullptr;
|
||
}
|
||
}
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_int_new(psection, ent_name, value);
|
||
}
|
||
if (NULL != pentry && NULL != comment) {
|
||
if (pentry != nullptr && comment != nullptr) {
|
||
entry_set_comment(pentry, comment);
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Insert 'dim' integer entries at 'path,0', 'path,1' etc. Returns
|
||
the number of entries inserted or replaced.
|
||
Insert 'dim' integer entries at 'path,0', 'path,1' etc.
|
||
Returns the number of entries inserted or replaced.
|
||
**************************************************************************/
|
||
size_t secfile_insert_int_vec_full(struct section_file *secfile,
|
||
const int *values, size_t dim,
|
||
... | ... | |
size_t i, ret = 0;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, 0);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
* of the file. */
|
||
if (dim > 0
|
||
&& NULL != secfile_insert_int_full(secfile, values[0], comment,
|
||
allow_replace, "%s", fullpath)) {
|
||
&& secfile_insert_int_full(secfile, values[0], comment,
|
||
allow_replace, "%s", fullpath) != nullptr) {
|
||
ret++;
|
||
}
|
||
for (i = 1; i < dim; i++) {
|
||
if (NULL != secfile_insert_int_full(secfile, values[i], comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i)) {
|
||
if (secfile_insert_int_full(secfile, values[i], comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i) != nullptr) {
|
||
ret++;
|
||
}
|
||
}
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH];
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (allow_replace) {
|
||
pentry = section_entry_by_name(psection, ent_name);
|
||
if (NULL != pentry) {
|
||
if (pentry != nullptr) {
|
||
if (ENTRY_FLOAT == entry_type_get(pentry)) {
|
||
if (!entry_float_set(pentry, value)) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} else {
|
||
entry_destroy(pentry);
|
||
pentry = NULL;
|
||
pentry = nullptr;
|
||
}
|
||
}
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_float_new(psection, ent_name, value);
|
||
}
|
||
if (NULL != pentry && NULL != comment) {
|
||
if (pentry != nullptr && comment != nullptr) {
|
||
entry_set_comment(pentry, comment);
|
||
}
|
||
... | ... | |
fc_snprintf(buffer, sizeof(buffer), "include_%u", secfile->num_includes++);
|
||
fc_assert_ret_val(secfile_section_by_name(secfile, buffer) == NULL, NULL);
|
||
fc_assert_ret_val(secfile_section_by_name(secfile, buffer) == nullptr, nullptr);
|
||
/* Create include section. */
|
||
psection = secfile_section_new(secfile, buffer);
|
||
psection->special = EST_INCLUDE;
|
||
/* Then add string entry "file" to it. */
|
||
secfile_insert_str_full(secfile, filename, NULL, FALSE, FALSE,
|
||
secfile_insert_str_full(secfile, filename, nullptr, FALSE, FALSE,
|
||
EST_INCLUDE, "%s.file", buffer);
|
||
return psection;
|
||
... | ... | |
fc_snprintf(buffer, sizeof(buffer), "long_comment_%u", secfile->num_long_comments++);
|
||
fc_assert_ret_val(secfile_section_by_name(secfile, buffer) == NULL, NULL);
|
||
fc_assert_ret_val(secfile_section_by_name(secfile, buffer) == nullptr, nullptr);
|
||
/* Create long comment section. */
|
||
psection = secfile_section_new(secfile, buffer);
|
||
psection->special = EST_COMMENT;
|
||
/* Then add string entry "comment" to it. */
|
||
secfile_insert_str_full(secfile, comment, NULL, FALSE, TRUE,
|
||
secfile_insert_str_full(secfile, comment, nullptr, FALSE, TRUE,
|
||
EST_COMMENT, "%s.comment", buffer);
|
||
return psection;
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH];
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (psection->special != stype) {
|
||
log_error("Tried to insert wrong type of entry to section");
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (allow_replace) {
|
||
pentry = section_entry_by_name(psection, ent_name);
|
||
if (NULL != pentry) {
|
||
if (pentry != nullptr) {
|
||
if (ENTRY_STR == entry_type_get(pentry)) {
|
||
if (!entry_str_set(pentry, str)) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} else {
|
||
entry_destroy(pentry);
|
||
pentry = NULL;
|
||
pentry = nullptr;
|
||
}
|
||
}
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_str_new(psection, ent_name, str, !no_escape);
|
||
}
|
||
if (NULL != pentry && NULL != comment) {
|
||
if (pentry != nullptr && comment != nullptr) {
|
||
entry_set_comment(pentry, comment);
|
||
}
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH];
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (psection->special != EST_NORMAL) {
|
||
log_error("Tried to insert wrong type of entry to section");
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
pentry = section_entry_comment_new(psection, str);
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Insert 'dim' string entries at 'path,0', 'path,1' etc. Returns
|
||
the number of entries inserted or replaced.
|
||
Insert 'dim' string entries at 'path,0', 'path,1' etc.
|
||
Returns the number of entries inserted or replaced.
|
||
**************************************************************************/
|
||
size_t secfile_insert_str_vec_full(struct section_file *secfile,
|
||
const char *const *strings, size_t dim,
|
||
... | ... | |
size_t i, ret = 0;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, 0);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
* of the file. */
|
||
if (dim > 0
|
||
&& NULL != secfile_insert_str_full(secfile, strings[0], comment,
|
||
allow_replace, no_escape, FALSE,
|
||
"%s", fullpath)) {
|
||
&& secfile_insert_str_full(secfile, strings[0], comment,
|
||
allow_replace, no_escape, FALSE,
|
||
"%s", fullpath) != nullptr) {
|
||
ret++;
|
||
}
|
||
for (i = 1; i < dim; i++) {
|
||
if (NULL != secfile_insert_str_full(secfile, strings[i], comment,
|
||
allow_replace, no_escape, FALSE,
|
||
"%s,%d", fullpath, (int) i)) {
|
||
if (secfile_insert_str_full(secfile, strings[i], comment,
|
||
allow_replace, no_escape, FALSE,
|
||
"%s,%d", fullpath, (int) i) != nullptr) {
|
||
ret++;
|
||
}
|
||
}
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH];
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (psection->special != EST_NORMAL) {
|
||
log_error("Tried to insert normal entry to different kind of section");
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_filereference_new(psection, ent_name, filename);
|
||
}
|
||
... | ... | |
const char *str;
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != name_fn, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, name_fn != nullptr, nullptr);
|
||
str = name_fn(enumerator);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != str, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, str != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (allow_replace) {
|
||
pentry = section_entry_by_name(psection, ent_name);
|
||
if (NULL != pentry) {
|
||
if (pentry != nullptr) {
|
||
if (ENTRY_STR == entry_type_get(pentry)) {
|
||
if (!entry_str_set(pentry, str)) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} else {
|
||
entry_destroy(pentry);
|
||
pentry = NULL;
|
||
pentry = nullptr;
|
||
}
|
||
}
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_str_new(psection, ent_name, str, TRUE);
|
||
}
|
||
if (NULL != pentry && NULL != comment) {
|
||
if (pentry != nullptr && comment != nullptr) {
|
||
entry_set_comment(pentry, comment);
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Insert 'dim' string entries at 'path,0', 'path,1' etc. Returns
|
||
the number of entries inserted or replaced.
|
||
Insert 'dim' string entries at 'path,0', 'path,1' etc.
|
||
Returns the number of entries inserted or replaced.
|
||
**************************************************************************/
|
||
size_t secfile_insert_plain_enum_vec_full(struct section_file *secfile,
|
||
const int *enumurators, size_t dim,
|
||
... | ... | |
size_t i, ret = 0;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != name_fn, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, name_fn != nullptr, 0);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
* of the file. */
|
||
if (dim > 0
|
||
&& NULL != secfile_insert_plain_enum_full(secfile, enumurators[0],
|
||
name_fn, comment,
|
||
allow_replace, "%s",
|
||
fullpath)) {
|
||
&& secfile_insert_plain_enum_full(secfile, enumurators[0],
|
||
name_fn, comment,
|
||
allow_replace, "%s",
|
||
fullpath) != nullptr) {
|
||
ret++;
|
||
}
|
||
for (i = 1; i < dim; i++) {
|
||
if (NULL != secfile_insert_plain_enum_full(secfile, enumurators[i],
|
||
name_fn, comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i)) {
|
||
if (secfile_insert_plain_enum_full(secfile, enumurators[i],
|
||
name_fn, comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i) != nullptr) {
|
||
ret++;
|
||
}
|
||
}
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH], str[MAX_LEN_SECPATH];
|
||
const char *ent_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
int i;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != name_fn, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != begin_fn, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != end_fn, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != next_fn, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, name_fn != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, begin_fn != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, end_fn != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, next_fn != nullptr, nullptr);
|
||
/* Compute a string containing all the values separated by '|'. */
|
||
str[0] = '\0'; /* Insert at least an empty string. */
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (allow_replace) {
|
||
pentry = section_entry_by_name(psection, ent_name);
|
||
if (NULL != pentry) {
|
||
if (pentry != nullptr) {
|
||
if (ENTRY_STR == entry_type_get(pentry)) {
|
||
if (!entry_str_set(pentry, str)) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} else {
|
||
entry_destroy(pentry);
|
||
pentry = NULL;
|
||
pentry = nullptr;
|
||
}
|
||
}
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_str_new(psection, ent_name, str, TRUE);
|
||
}
|
||
if (NULL != pentry && NULL != comment) {
|
||
if (pentry != nullptr && comment != nullptr) {
|
||
entry_set_comment(pentry, comment);
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Insert 'dim' string entries at 'path,0', 'path,1' etc. Returns
|
||
the number of entries inserted or replaced.
|
||
Insert 'dim' string entries at 'path,0', 'path,1' etc.
|
||
Returns the number of entries inserted or replaced.
|
||
**************************************************************************/
|
||
size_t secfile_insert_bitwise_enum_vec_full(struct section_file *secfile,
|
||
const int *bitwise_vals,
|
||
... | ... | |
size_t i, ret = 0;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != name_fn, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != begin_fn, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != end_fn, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != next_fn, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, name_fn != nullptr, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, begin_fn != nullptr, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, end_fn != nullptr, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, next_fn != nullptr, 0);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
* of the file. */
|
||
if (dim > 0
|
||
&& NULL != secfile_insert_bitwise_enum_full(secfile, bitwise_vals[0],
|
||
name_fn, begin_fn, end_fn,
|
||
next_fn, comment,
|
||
allow_replace, "%s",
|
||
fullpath)) {
|
||
&& secfile_insert_bitwise_enum_full(secfile, bitwise_vals[0],
|
||
name_fn, begin_fn, end_fn,
|
||
next_fn, comment,
|
||
allow_replace, "%s",
|
||
fullpath) != nullptr) {
|
||
ret++;
|
||
}
|
||
for (i = 1; i < dim; i++) {
|
||
if (NULL != secfile_insert_bitwise_enum_full(secfile, bitwise_vals[i],
|
||
name_fn, begin_fn, end_fn,
|
||
next_fn, comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i)) {
|
||
if (secfile_insert_bitwise_enum_full(secfile, bitwise_vals[i],
|
||
name_fn, begin_fn, end_fn,
|
||
next_fn, comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i) != nullptr) {
|
||
ret++;
|
||
}
|
||
}
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH], str[MAX_LEN_SECPATH];
|
||
const char *ent_name, *val_name;
|
||
struct section *psection;
|
||
struct entry *pentry = NULL;
|
||
struct entry *pentry = nullptr;
|
||
va_list args;
|
||
int i;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != name_fn, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, name_fn != nullptr, nullptr);
|
||
if (bitwise) {
|
||
/* Compute a string containing all the values separated by '|'. */
|
||
... | ... | |
}
|
||
} else {
|
||
if (!(val_name = name_fn(data, value))) {
|
||
SECFILE_LOG(secfile, NULL, "Value %d not supported.", value);
|
||
return NULL;
|
||
SECFILE_LOG(secfile, nullptr, "Value %d not supported.", value);
|
||
return nullptr;
|
||
}
|
||
sz_strlcpy(str, val_name);
|
||
}
|
||
... | ... | |
psection = secfile_insert_base(secfile, fullpath, &ent_name);
|
||
if (!psection) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (allow_replace) {
|
||
pentry = section_entry_by_name(psection, ent_name);
|
||
if (NULL != pentry) {
|
||
if (pentry != nullptr) {
|
||
if (ENTRY_STR == entry_type_get(pentry)) {
|
||
if (!entry_str_set(pentry, str)) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
} else {
|
||
entry_destroy(pentry);
|
||
pentry = NULL;
|
||
pentry = nullptr;
|
||
}
|
||
}
|
||
}
|
||
if (NULL == pentry) {
|
||
if (pentry == nullptr) {
|
||
pentry = section_entry_str_new(psection, ent_name, str, TRUE);
|
||
}
|
||
if (NULL != pentry && NULL != comment) {
|
||
if (pentry != nullptr && comment != nullptr) {
|
||
entry_set_comment(pentry, comment);
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Insert 'dim' entries at 'path,0', 'path,1' etc. Returns the number of
|
||
Insert 'dim' entries at 'path,0', 'path,1' etc. Returns the number of
|
||
entries inserted or replaced.
|
||
**************************************************************************/
|
||
size_t secfile_insert_enum_vec_data_full(struct section_file *secfile,
|
||
... | ... | |
size_t i, ret = 0;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != name_fn, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, 0);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, name_fn != nullptr, 0);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
/* NB: 'path,0' is actually 'path'. See comment in the head
|
||
* of the file. */
|
||
if (dim > 0
|
||
&& NULL != secfile_insert_enum_data_full(secfile, values[0], bitwise,
|
||
name_fn, data, comment,
|
||
allow_replace, "%s",
|
||
fullpath)) {
|
||
&& secfile_insert_enum_data_full(secfile, values[0], bitwise,
|
||
name_fn, data, comment,
|
||
allow_replace, "%s",
|
||
fullpath) != nullptr) {
|
||
ret++;
|
||
}
|
||
for (i = 1; i < dim; i++) {
|
||
if (NULL != secfile_insert_enum_data_full(secfile, values[i], bitwise,
|
||
name_fn, data, comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i)) {
|
||
if (secfile_insert_enum_data_full(secfile, values[i], bitwise,
|
||
name_fn, data, comment,
|
||
allow_replace, "%s,%d",
|
||
fullpath, (int) i) != nullptr) {
|
||
ret++;
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Returns the entry by the name or NULL if not matched.
|
||
Returns the entry by the name or nullptr if not matched.
|
||
**************************************************************************/
|
||
struct entry *secfile_entry_by_path(const struct section_file *secfile,
|
||
const char *path)
|
||
... | ... | |
size_t len;
|
||
struct section *psection;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
sz_strlcpy(fullpath, path);
|
||
/* treat "sec.foo,0" as "sec.foo": */
|
||
/* Treat "sec.foo,0" as "sec.foo": */
|
||
len = strlen(fullpath);
|
||
if (len > 2 && fullpath[len - 2] == ',' && fullpath[len - 1] == '0') {
|
||
fullpath[len - 2] = '\0';
|
||
}
|
||
if (NULL != secfile->hash.entries) {
|
||
if (secfile->hash.entries != nullptr) {
|
||
struct entry *pentry;
|
||
if (entry_hash_lookup(secfile->hash.entries, fullpath, &pentry)) {
|
||
... | ... | |
return pentry;
|
||
}
|
||
/* I dont like strtok.
|
||
/* I dont like strtok().
|
||
* - Me neither! */
|
||
ent_name = strchr(fullpath, '.');
|
||
if (!ent_name) {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/* Separates section and entry names. */
|
||
... | ... | |
if (psection) {
|
||
return section_entry_by_name(psection, ent_name);
|
||
} else {
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
}
|
||
... | ... | |
va_list args;
|
||
struct entry *pentry;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, FALSE);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
if (!(pentry = secfile_entry_by_path(secfile, fullpath))) {
|
||
SECFILE_LOG(secfile, NULL, "Path %s does not exists.", fullpath);
|
||
SECFILE_LOG(secfile, nullptr, "Path %s does not exists.", fullpath);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Returns the entry at "fullpath" or NULL if not matched.
|
||
Returns the entry at "fullpath" or nullptr if not matched.
|
||
**************************************************************************/
|
||
struct entry *secfile_entry_lookup(const struct section_file *secfile,
|
||
const char *path, ...)
|
||
... | ... | |
char fullpath[MAX_LEN_SECPATH];
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a boolean value in the secfile. Returns TRUE on success.
|
||
Lookup a boolean value in the secfile. Returns TRUE on success.
|
||
**************************************************************************/
|
||
bool secfile_lookup_bool(const struct section_file *secfile, bool *bval,
|
||
const char *path, ...)
|
||
... | ... | |
const struct entry *pentry;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, FALSE);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
if (!(pentry = secfile_entry_by_path(secfile, fullpath))) {
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a boolean value in the secfile. On failure, use the default
|
||
Lookup a boolean value in the secfile. On failure, use the default
|
||
value.
|
||
**************************************************************************/
|
||
bool secfile_lookup_bool_default(const struct section_file *secfile,
|
||
... | ... | |
bool bval;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, def);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, def);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a boolean vector in the secfile. Returns NULL on error. This
|
||
vector is not owned by the registry module, and should be free by the
|
||
user.
|
||
Lookup a boolean vector in the secfile. Returns nullptr on error.
|
||
This vector is not owned by the registry module, and should be
|
||
free by the user.
|
||
**************************************************************************/
|
||
bool *secfile_lookup_bool_vec(const struct section_file *secfile,
|
||
size_t *dim, const char *path, ...)
|
||
... | ... | |
bool *vec;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != dim, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, dim != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* Check size. */
|
||
while (NULL != secfile_entry_lookup(secfile, "%s,%d", fullpath, (int) i)) {
|
||
while (secfile_entry_lookup(secfile, "%s,%d", fullpath, (int) i) != nullptr) {
|
||
i++;
|
||
}
|
||
*dim = i;
|
||
if (0 == i) {
|
||
/* Doesn't exist. */
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
return NULL;
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return nullptr;
|
||
}
|
||
vec = fc_malloc(i * sizeof(bool));
|
||
for (i = 0; i < *dim; i++) {
|
||
if (!secfile_lookup_bool(secfile, vec + i, "%s,%d", fullpath, (int) i)) {
|
||
SECFILE_LOG(secfile, NULL,
|
||
SECFILE_LOG(secfile, nullptr,
|
||
"An error occurred when looking up to \"%s,%d\" entry.",
|
||
fullpath, (int) i);
|
||
free(vec);
|
||
*dim = 0;
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a integer value in the secfile. Returns TRUE on success.
|
||
Lookup a integer value in the secfile. Returns TRUE on success.
|
||
**************************************************************************/
|
||
bool secfile_lookup_int(const struct section_file *secfile, int *ival,
|
||
const char *path, ...)
|
||
... | ... | |
const struct entry *pentry;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, FALSE);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
if (!(pentry = secfile_entry_by_path(secfile, fullpath))) {
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a integer value in the secfile. On failure, use the default
|
||
Lookup a integer value in the secfile. On failure, use the default
|
||
value.
|
||
**************************************************************************/
|
||
int secfile_lookup_int_default(const struct section_file *secfile, int def,
|
||
... | ... | |
int ival;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, def);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, def);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
int value;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, defval);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, defval);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a integer vector in the secfile. Returns NULL on error. This
|
||
vector is not owned by the registry module, and should be free by the
|
||
user.
|
||
Lookup a integer vector in the secfile. Returns nullptr on error.
|
||
This vector is not owned by the registry module, and should be
|
||
freed by the user.
|
||
**************************************************************************/
|
||
int *secfile_lookup_int_vec(const struct section_file *secfile,
|
||
size_t *dim, const char *path, ...)
|
||
... | ... | |
int *vec;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != dim, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, dim != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* Check size. */
|
||
while (NULL != secfile_entry_lookup(secfile, "%s,%d", fullpath, (int) i)) {
|
||
while (secfile_entry_lookup(secfile, "%s,%d", fullpath, (int) i) != nullptr) {
|
||
i++;
|
||
}
|
||
*dim = i;
|
||
if (0 == i) {
|
||
/* Doesn't exist. */
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
return NULL;
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return nullptr;
|
||
}
|
||
vec = fc_malloc(i * sizeof(int));
|
||
for (i = 0; i < *dim; i++) {
|
||
if (!secfile_lookup_int(secfile, vec + i, "%s,%d", fullpath, (int) i)) {
|
||
SECFILE_LOG(secfile, NULL,
|
||
SECFILE_LOG(secfile, nullptr,
|
||
"An error occurred when looking up to \"%s,%d\" entry.",
|
||
fullpath, (int) i);
|
||
free(vec);
|
||
*dim = 0;
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a floating point value in the secfile. Returns TRUE on success.
|
||
Lookup a floating point value in the secfile. Returns TRUE on success.
|
||
**************************************************************************/
|
||
bool secfile_lookup_float(const struct section_file *secfile, float *fval,
|
||
const char *path, ...)
|
||
... | ... | |
const struct entry *pentry;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, FALSE);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
if (!(pentry = secfile_entry_by_path(secfile, fullpath))) {
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
float fval;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, def);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, def);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup a string value in the secfile. Returns NULL on error.
|
||
Lookup a string value in the secfile. Returns nullptr on error.
|
||
**************************************************************************/
|
||
const char *secfile_lookup_str(const struct section_file *secfile,
|
||
const char *path, ...)
|
||
... | ... | |
const char *str;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
if (!(pentry = secfile_entry_by_path(secfile, fullpath))) {
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
return NULL;
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return nullptr;
|
||
}
|
||
if (entry_str_get(pentry, &str)) {
|
||
return str;
|
||
}
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
/**********************************************************************//**
|
||
... | ... | |
const char *str;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, def);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, def);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
return str;
|
||
}
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't have a string.", fullpath);
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't have a string.", fullpath);
|
||
return def;
|
||
}
|
||
/**********************************************************************//**
|
||
Lookup a string vector in the secfile. Returns NULL on error. This
|
||
vector is not owned by the registry module, and should be free by the
|
||
user, but the string pointers stored inside the vector shouldn't be
|
||
free.
|
||
Lookup a string vector in the secfile. Returns nullptr on error.
|
||
This vector is not owned by the registry module, and should be
|
||
freed by the user, but the string pointers stored inside the vector
|
||
shouldn't be freed.
|
||
**************************************************************************/
|
||
const char **secfile_lookup_str_vec(const struct section_file *secfile,
|
||
size_t *dim, const char *path, ...)
|
||
... | ... | |
const char **vec;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != dim, NULL);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, nullptr);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, dim != nullptr, nullptr);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
/* Check size. */
|
||
while (NULL != secfile_entry_lookup(secfile, "%s,%d", fullpath, (int) i)) {
|
||
while (secfile_entry_lookup(secfile, "%s,%d", fullpath, (int) i) != nullptr) {
|
||
i++;
|
||
}
|
||
*dim = i;
|
||
if (0 == i) {
|
||
/* Doesn't exist. */
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
return NULL;
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return nullptr;
|
||
}
|
||
vec = fc_malloc(i * sizeof(const char *));
|
||
for (i = 0; i < *dim; i++) {
|
||
if (!(vec[i] = secfile_lookup_str(secfile, "%s,%d",
|
||
fullpath, (int) i))) {
|
||
SECFILE_LOG(secfile, NULL,
|
||
SECFILE_LOG(secfile, nullptr,
|
||
"An error occurred when looking up to \"%s,%d\" entry.",
|
||
fullpath, (int) i);
|
||
free(vec);
|
||
*dim = 0;
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup an enumerator value in the secfile. Returns FALSE on error.
|
||
Lookup an enumerator value in the secfile. Returns FALSE on error.
|
||
**************************************************************************/
|
||
bool secfile_lookup_plain_enum_full(const struct section_file *secfile,
|
||
int *penumerator,
|
||
... | ... | |
const char *str;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != penumerator, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != is_valid_fn, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != by_name_fn, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, penumerator != nullptr, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, is_valid_fn != nullptr, FALSE);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, by_name_fn != nullptr, FALSE);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
va_end(args);
|
||
if (!(pentry = secfile_entry_by_path(secfile, fullpath))) {
|
||
SECFILE_LOG(secfile, NULL, "\"%s\" entry doesn't exist.", fullpath);
|
||
SECFILE_LOG(secfile, nullptr, "\"%s\" entry doesn't exist.", fullpath);
|
||
return FALSE;
|
||
}
|
||
... | ... | |
}
|
||
/**********************************************************************//**
|
||
Lookup an enumerator value in the secfile. Returns 'defval' on error.
|
||
Lookup an enumerator value in the secfile. Returns 'defval' on error.
|
||
**************************************************************************/
|
||
int secfile_lookup_plain_enum_default_full(const struct section_file
|
||
*secfile, int defval,
|
||
... | ... | |
int val;
|
||
va_list args;
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, defval);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != is_valid_fn, defval);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != by_name_fn, defval);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, secfile != nullptr, defval);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, is_valid_fn != nullptr, defval);
|
||
SECFILE_RETURN_VAL_IF_FAIL(secfile, nullptr, by_name_fn != nullptr, defval);
|
||
va_start(args, path);
|
||
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
|
||
... | ... | |
}
|
||