param: setup more variables in for the temporary loadparm context for the special...
[kai/samba-autobuild/.git] / lib / param / loadparm.c
index 5598e259f981762e5123fdaadb12038f9a405a7d..2b8ea237a0624f094ce18b69e1a3ea24ad47bc69 100644 (file)
@@ -91,32 +91,8 @@ static bool defaults_saved = false;
 #define N_(x) x
 #endif
 
-/* prototypes for the special type handlers */
-static bool handle_include(struct loadparm_context *lp_ctx, int unused,
-                          const char *pszParmValue, char **ptr);
-
 #include "lib/param/param_table.c"
 
-/* local variables */
-struct loadparm_context {
-       const char *szConfigFile;
-       struct loadparm_global *globals;
-       struct loadparm_service **services;
-       struct loadparm_service *sDefault;
-       struct smb_iconv_handle *iconv_handle;
-       int iNumServices;
-       struct loadparm_service *currentService;
-       bool bInGlobalSection;
-       struct file_lists *file_lists;
-       unsigned int flags[NUMPARAMETERS];
-       bool loaded;
-       bool refuse_free;
-       bool global; /* Is this the global context, which may set
-                     * global variables such as debug level etc? */
-       const struct loadparm_s3_helpers *s3_fns;
-};
-
-
 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
 {
        if (lp_ctx->s3_fns) {
@@ -292,7 +268,7 @@ const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
                return NULL;
 
        if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->get_parametric(service, type, option);
+               return lp_ctx->s3_fns->get_parametric(service, type, option, NULL);
        }
 
        data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
@@ -331,10 +307,10 @@ const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
 /**
  * convenience routine to return int parameters.
  */
-static int lp_int(const char *s)
+int lp_int(const char *s)
 {
 
-       if (!s) {
+       if (!s || !*s) {
                DEBUG(0,("lp_int(%s): is called with NULL!\n",s));
                return -1;
        }
@@ -345,10 +321,10 @@ static int lp_int(const char *s)
 /**
  * convenience routine to return unsigned long parameters.
  */
-static unsigned long lp_ulong(const char *s)
+unsigned long lp_ulong(const char *s)
 {
 
-       if (!s) {
+       if (!s || !*s) {
                DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
                return -1;
        }
@@ -387,11 +363,11 @@ static double lp_double(const char *s)
 /**
  * convenience routine to return boolean parameters.
  */
-static bool lp_bool(const char *s)
+bool lp_bool(const char *s)
 {
        bool ret = false;
 
-       if (!s) {
+       if (!s || !*s) {
                DEBUG(0,("lp_bool(%s): is called with NULL!\n",s));
                return false;
        }
@@ -404,7 +380,6 @@ static bool lp_bool(const char *s)
        return ret;
 }
 
-
 /**
  * Return parametric option from a given service. Type is a part of option before ':'
  * Parametric option has following syntax: 'Type: option = value'
@@ -546,7 +521,7 @@ bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
  * Set a string value, deallocating any existing space, and allocing the space
  * for the string
  */
-static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
+bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
 {
        talloc_free(*dest);
 
@@ -1067,6 +1042,26 @@ bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
        return false;
 }
 
+/*
+ * set the value for a P_ENUM
+ */
+bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
+                              int *ptr )
+{
+       int i;
+
+       for (i = 0; parm->enum_list[i].name; i++) {
+               if ( strequal(pszParmValue, parm->enum_list[i].name)) {
+                       *ptr = parm->enum_list[i].value;
+                       return true;
+               }
+       }
+       DEBUG(0, ("WARNING: Ignoring invalid value '%s' for parameter '%s'\n",
+                 pszParmValue, parm->label));
+       return false;
+}
+
+
 /***************************************************************************
  Handle the "realm" parameter
 ***************************************************************************/
@@ -1105,10 +1100,16 @@ bool handle_realm(struct loadparm_context *lp_ctx, int unused,
  Handle the include operation.
 ***************************************************************************/
 
-static bool handle_include(struct loadparm_context *lp_ctx, int unused,
+bool handle_include(struct loadparm_context *lp_ctx, int unused,
                           const char *pszParmValue, char **ptr)
 {
-       char *fname = standard_sub_basic(lp_ctx, pszParmValue);
+       char *fname;
+
+       if (lp_ctx->s3_fns) {
+               return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
+       }
+
+       fname = standard_sub_basic(lp_ctx, pszParmValue);
 
        add_to_file_list(lp_ctx, &lp_ctx->file_lists, pszParmValue, fname);
 
@@ -1458,19 +1459,7 @@ static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
                        break;
 
                case P_ENUM:
-                       for (i = 0; parm_table[parmnum].enum_list[i].name; i++) {
-                               if (strequal
-                                   (pszParmValue,
-                                    parm_table[parmnum].enum_list[i].name)) {
-                                       *(int *)parm_ptr =
-                                               parm_table[parmnum].
-                                               enum_list[i].value;
-                                       break;
-                               }
-                       }
-                       if (!parm_table[parmnum].enum_list[i].name) {
-                               DEBUG(0,("Unknown enumerated value '%s' for '%s'\n", 
-                                        pszParmValue, pszParmName));
+                       if (!lp_set_enum_parm(&parm_table[parmnum], pszParmValue, (int*)parm_ptr)) {
                                return false;
                        }
                        break;
@@ -1612,15 +1601,14 @@ bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
        int parmnum;
        int i;
 
+       while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
+
        if (lp_ctx->s3_fns) {
                return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
        }
 
        parmnum = lpcfg_map_parameter(pszParmName);
 
-       while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
-
-
        if (parmnum < 0 && strchr(pszParmName, ':')) {
                /* set a parametric option */
                return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
@@ -2071,6 +2059,7 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
        lp_ctx->bInGlobalSection = true;
        lp_ctx->globals = talloc_zero(lp_ctx, struct loadparm_global);
        lp_ctx->sDefault = talloc_zero(lp_ctx, struct loadparm_service);
+       lp_ctx->flags = talloc_zero_array(lp_ctx, unsigned int, NUMPARAMETERS);
 
        lp_ctx->sDefault->iMaxPrintJobs = 1000;
        lp_ctx->sDefault->bAvailable = true;