mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
param: copy parametric option helper to lib/param
Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
66338032c2
commit
9d90969a37
@ -237,6 +237,55 @@ static bool do_section(const char *pszSectionName, void *);
|
|||||||
/* This is a helper function for parametrical options support. */
|
/* This is a helper function for parametrical options support. */
|
||||||
/* It returns a pointer to parametrical option value if it exists or NULL otherwise */
|
/* It returns a pointer to parametrical option value if it exists or NULL otherwise */
|
||||||
/* Actual parametrical functions are quite simple */
|
/* Actual parametrical functions are quite simple */
|
||||||
|
struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
|
||||||
|
const char *type, const char *option,
|
||||||
|
struct parmlist_entry *global_opts)
|
||||||
|
{
|
||||||
|
char* param_key;
|
||||||
|
struct parmlist_entry *data = NULL;
|
||||||
|
TALLOC_CTX *mem_ctx = talloc_stackframe();
|
||||||
|
|
||||||
|
param_key = talloc_asprintf(mem_ctx, "%s:%s", type, option);
|
||||||
|
if (param_key == NULL) {
|
||||||
|
DEBUG(0,("asprintf failed!\n"));
|
||||||
|
TALLOC_FREE(mem_ctx);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to fetch the option from the data.
|
||||||
|
*/
|
||||||
|
if (service != NULL) {
|
||||||
|
data = service->param_opt;
|
||||||
|
while (data != NULL) {
|
||||||
|
if (strwicmp(data->key, param_key) == 0) {
|
||||||
|
TALLOC_FREE(mem_ctx);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
data = data->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fall back to fetching from the globals.
|
||||||
|
*/
|
||||||
|
data = global_opts;
|
||||||
|
while (data != NULL) {
|
||||||
|
if (strwicmp(data->key, param_key) == 0) {
|
||||||
|
TALLOC_FREE(mem_ctx);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
data = data->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TALLOC_FREE(mem_ctx);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
|
const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
|
||||||
struct loadparm_service *service,
|
struct loadparm_service *service,
|
||||||
const char *type, const char *option)
|
const char *type, const char *option)
|
||||||
|
@ -1228,10 +1228,10 @@ static struct parmlist_entry *get_parametrics(int snum, const char *type,
|
|||||||
if (snum >= iNumServices) return NULL;
|
if (snum >= iNumServices) return NULL;
|
||||||
|
|
||||||
if (snum < 0) {
|
if (snum < 0) {
|
||||||
return get_parametrics_by_service(NULL, type, option, Globals.param_opt);
|
return get_parametric_helper(NULL, type, option, Globals.param_opt);
|
||||||
} else {
|
} else {
|
||||||
return get_parametrics_by_service(ServicePtrs[snum],
|
return get_parametric_helper(ServicePtrs[snum],
|
||||||
type, option, Globals.param_opt);
|
type, option, Globals.param_opt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1295,7 +1295,9 @@ const char *lp_parm_const_string_service(struct loadparm_service *service,
|
|||||||
const char *type, const char *option,
|
const char *type, const char *option,
|
||||||
const char *def)
|
const char *def)
|
||||||
{
|
{
|
||||||
struct parmlist_entry *data = get_parametrics_by_service(service, type, option, Globals.param_opt);
|
struct parmlist_entry *data;
|
||||||
|
|
||||||
|
data = get_parametric_helper(service, type, option, Globals.param_opt);
|
||||||
|
|
||||||
if (data == NULL||data->value==NULL)
|
if (data == NULL||data->value==NULL)
|
||||||
return def;
|
return def;
|
||||||
|
Loading…
Reference in New Issue
Block a user