param: use a single copy_service function in lib/param
authorGarming Sam <garming@catalyst.net.nz>
Wed, 19 Feb 2014 00:47:38 +0000 (13:47 +1300)
committerJeremy Allison <jra@samba.org>
Wed, 7 May 2014 17:49:15 +0000 (19:49 +0200)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/param/loadparm.c
lib/param/param.h
source3/param/loadparm.c

index 809793d3ca144305698347d8b88bdfb5cab77e8c..65378864bbe94e6ea96d37953e2486d3d8ca6181 100644 (file)
@@ -285,9 +285,6 @@ FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
 /* local prototypes */
 static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx,
                                        const char *pszServiceName);
-static void copy_service(struct loadparm_service *pserviceDest,
-                        const struct loadparm_service *pserviceSource,
-                        struct bitmap *pcopymapDest);
 static bool lpcfg_service_ok(struct loadparm_service *service);
 static bool do_section(const char *pszSectionName, void *);
 static void init_copymap(struct loadparm_service *pservice);
@@ -561,7 +558,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
  */
-bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
+static bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
 {
        talloc_free(*dest);
 
@@ -581,7 +578,7 @@ bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
  * Set a string value, deallocating any existing space, and allocing the space
  * for the string
  */
-bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
+static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
 {
        talloc_free(*dest);
 
@@ -902,9 +899,9 @@ void set_param_opt(TALLOC_CTX *mem_ctx,
  * If pcopymapDest is NULL then copy all fields
  */
 
-static void copy_service(struct loadparm_service *pserviceDest,
-                        const struct loadparm_service *pserviceSource,
-                        struct bitmap *pcopymapDest)
+void copy_service(struct loadparm_service *pserviceDest,
+                 const struct loadparm_service *pserviceSource,
+                 struct bitmap *pcopymapDest)
 {
        int i;
        bool bcopyall = (pcopymapDest == NULL);
index 428a2a31c29fd7721647401e306eb53ccf77586a..0b65a3c827366ac6ba20df516baaabc3bafabe97 100644 (file)
@@ -46,6 +46,7 @@ struct loadparm_service;
 struct smbcli_options;
 struct smbcli_session_options;
 struct gensec_settings;
+struct bitmap;
 
 #ifdef CONFIG_H_IS_FROM_SAMBA
 #include "lib/param/param_proto.h"
index b2bef1d747bb1373690f7e336235fc074c3fa135..ddf8f45ef62e525755cbbfdecc1baf95fdaaa407 100644 (file)
@@ -1176,9 +1176,6 @@ static int map_parameter_canonical(const char *pszParmName, bool *inverse);
 static const char *get_boolean(bool bool_value);
 static int getservicebyname(const char *pszServiceName,
                            struct loadparm_service *pserviceDest);
-static void copy_service(struct loadparm_service *pserviceDest,
-                        const struct loadparm_service *pserviceSource,
-                        struct bitmap *pcopymapDest);
 static bool do_parameter(const char *pszParmName, const char *pszParmValue,
                         void *userdata);
 static bool do_section(const char *pszSectionName, void *userdata);
@@ -2132,80 +2129,6 @@ struct loadparm_service *lp_default_loadparm_service()
        return &sDefault;
 }
 
-
-/***************************************************************************
- Copy a service structure to another.
- If pcopymapDest is NULL then copy all fields
-***************************************************************************/
-
-static void copy_service(struct loadparm_service *pserviceDest,
-                        const struct loadparm_service *pserviceSource,
-                        struct bitmap *pcopymapDest)
-{
-       int i;
-       bool bcopyall = (pcopymapDest == NULL);
-       struct parmlist_entry *data;
-
-       for (i = 0; parm_table[i].label; i++)
-               if (parm_table[i].p_class == P_LOCAL &&
-                   (bcopyall || bitmap_query(pcopymapDest, i))) {
-                       const void *src_ptr =
-                               ((const char *)pserviceSource) + parm_table[i].offset;
-                       void *dest_ptr =
-                               ((char *)pserviceDest) + parm_table[i].offset;
-
-                       switch (parm_table[i].type) {
-                               case P_BOOL:
-                               case P_BOOLREV:
-                                       *(bool *)dest_ptr = *(const bool *)src_ptr;
-                                       break;
-
-                               case P_INTEGER:
-                               case P_BYTES:
-                               case P_OCTAL:
-                               case P_ENUM:
-                                       *(int *)dest_ptr = *(const int *)src_ptr;
-                                       break;
-
-                               case P_CHAR:
-                                       *(char *)dest_ptr = *(const char *)src_ptr;
-                                       break;
-
-                               case P_STRING:
-                                       lpcfg_string_set(pserviceDest,
-                                                  (char **)dest_ptr,
-                                                  *(const char * const *)src_ptr);
-                                       break;
-
-                               case P_USTRING:
-                                       lpcfg_string_set_upper(pserviceDest,
-                                                        (char **)dest_ptr,
-                                                        *(const char * const *)src_ptr);
-                                       break;
-                               case P_LIST:
-                                       TALLOC_FREE(*((char ***)dest_ptr));
-                                       *(const char * const **)dest_ptr = (const char * const *)str_list_copy(pserviceDest,
-                                                                                 *(const char * * const *)src_ptr);
-                                       break;
-                               default:
-                                       break;
-                       }
-               }
-
-       if (bcopyall) {
-               init_copymap(pserviceDest);
-               if (pserviceSource->copymap)
-                       bitmap_copy(pserviceDest->copymap,
-                                   pserviceSource->copymap);
-       }
-
-       data = pserviceSource->param_opt;
-       while (data) {
-               set_param_opt(pserviceDest, &pserviceDest->param_opt, data->key, data->value, data->priority);
-               data = data->next;
-       }
-}
-
 /***************************************************************************
 Check a service for consistency. Return false if the service is in any way
 incomplete or faulty, else true.