[PATCH] parametric options
Stefan (metze) Metzmacher
metze at metzemix.de
Mon Oct 21 13:27:00 GMT 2002
Hi Alexander,
here're the patch for parametric options...
metze
-----------------------------------------------------------------------------
Stefan "metze" Metzmacher <metze at metzemix.de>
-------------- next part --------------
--- loadparm.c.bak Mon Aug 26 06:42:14 2002
+++ loadparm.c Mon Aug 26 13:56:03 2002
@@ -7,6 +7,7 @@
Copyright (C) Simo Sorce 2001
Copyright (C) Alexander Bokovoy 2002
+ Copyright (C) Stefan (metze) Metzmacher 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1775,34 +1776,186 @@ static param_opt_struct *param_opt = NUL
/* Returned value is allocated in 'lp_talloc' context */
char *lp_parm_string(const char *servicename, const char *type, const char *option)
{
- param_opt_struct *data;
- pstring vfskey;
+ param_opt_struct *data;
+ pstring vfskey;
- if (param_opt != NULL) {
- ZERO_STRUCT(vfskey);
- pstr_sprintf(vfskey, "%s:%s:%s", (servicename==NULL) ? "global" : servicename,
- type, option);
- data = param_opt;
- while (data) {
- if (strcmp(data->key, vfskey) == 0) {
- return lp_string(data->value);
- }
- data = data->next;
- }
- /* Try to fetch the same option but from globals */
- pstr_sprintf(vfskey, "global:%s:%s", type, option);
- data = param_opt;
- while (data) {
- if (strcmp(data->key, vfskey) == 0) {
- return lp_string(data->value);
- }
- data = data->next;
- }
-
- }
- return NULL;
+ if (param_opt != NULL) {
+ ZERO_STRUCT(vfskey);
+ pstr_sprintf(vfskey, "%s:%s:%s", (servicename==NULL) ? "global" : servicename,
+ type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_string(data->value);
+ }
+ data = data->next;
+ }
+ /* Try to fetch the same option but from globals */
+ pstr_sprintf(vfskey, "global:%s:%s", type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_string(data->value);
+ }
+ data = data->next;
+ }
+ }
+ return NULL;
}
+/*******************************************************************
+convenience routine to return int parameters.
+********************************************************************/
+static int lp_int(const char *s)
+{
+ int ret = 0;
+
+#if 0
+ DEBUG(10, ("lp_int(%s)\n", s));
+#endif
+
+ if (!s) {
+ DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
+ return (-1);
+ }
+ return atoi(s);
+}
+
+/* Return parametric option from given service. Type is a part of option before ':' */
+/* Parametric option has following syntax: 'Type: option = value' */
+int lp_parm_int(const char *servicename, const char *type, const char *option)
+{
+ param_opt_struct *data;
+ pstring vfskey;
+
+ if (param_opt != NULL) {
+ ZERO_STRUCT(vfskey);
+ pstr_sprintf(vfskey, "%s:%s:%s", (servicename==NULL) ? "global" : servicename,
+ type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_int(data->value);
+ }
+ data = data->next;
+ }
+ /* Try to fetch the same option but from globals */
+ pstr_sprintf(vfskey, "global:%s:%s", type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_int(data->value);
+ }
+ data = data->next;
+ }
+ }
+ return (-1);
+}
+
+/*******************************************************************
+convenience routine to return boolean parameters.
+********************************************************************/
+static BOOL lp_bool(const char *s)
+{
+ BOOL ret = False;
+
+ if (!s) {
+ DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
+ return False;
+ }
+
+ if (!set_boolean(&ret,s)) {
+ DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
+ return False;
+ }
+
+ return ret;
+}
+
+/* Return parametric option from given service. Type is a part of option before ':' */
+/* Parametric option has following syntax: 'Type: option = value' */
+BOOL lp_parm_bool(const char *servicename, const char *type, const char *option)
+{
+ param_opt_struct *data;
+ pstring vfskey;
+
+ if (param_opt != NULL) {
+ ZERO_STRUCT(vfskey);
+ pstr_sprintf(vfskey, "%s:%s:%s", (servicename==NULL) ? "global" : servicename,
+ type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_bool(data->value);
+ }
+ data = data->next;
+ }
+ /* Try to fetch the same option but from globals */
+ pstr_sprintf(vfskey, "global:%s:%s", type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_bool(data->value);
+ }
+ data = data->next;
+ }
+ }
+ return False;
+}
+
+/*******************************************************************
+convenience routine to return enum parameters.
+********************************************************************/
+static int lp_enum(const char *s,const enum_list *enum)
+{
+ int i;
+
+ if (!s || !enum) {
+ DEBUG(0,("lp_enum(%s,enum): is called with NULL!\n",s));
+ return False;
+ }
+
+ for (i=0; enum[i].name; i++ {
+ if (strcasecmp(enum[i].name,s)==0)
+ return enum[i].value;
+ }
+
+ DEBUG(0,("lp_enum(%s,enum): value is not in enum_list!\n",s));
+ return (-1);
+}
+
+/* Return parametric option from given service. Type is a part of option before ':' */
+/* Parametric option has following syntax: 'Type: option = value' */
+int lp_parm_enum(const char *servicename, const char *type, const char *option, const enum_list *enum)
+{
+ param_opt_struct *data;
+ pstring vfskey;
+
+ if (param_opt != NULL) {
+ ZERO_STRUCT(vfskey);
+ pstr_sprintf(vfskey, "%s:%s:%s", (servicename==NULL) ? "global" : servicename,
+ type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_enum(data->value,enum);
+ }
+ data = data->next;
+ }
+ /* Try to fetch the same option but from globals */
+ pstr_sprintf(vfskey, "global:%s:%s", type, option);
+ data = param_opt;
+ while (data) {
+ if (strcmp(data->key, vfskey) == 0) {
+ return lp_enum(data->value,enum);
+ }
+ data = data->next;
+ }
+
+ }
+ return (-1);
+}
+
/* local prototypes */
static int map_parameter(char *pszParmName);
More information about the samba-technical
mailing list