lib/param: Make and use lpcfg_dump_a_service() in common
authorAndrew Bartlett <abartlet@samba.org>
Mon, 27 Jan 2014 02:32:39 +0000 (15:32 +1300)
committerJeremy Allison <jra@samba.org>
Wed, 7 May 2014 17:49:17 +0000 (19:49 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/param/loadparm.c
source3/param/loadparm.c

index bf3b09486ced63afc16d3ef0256be79b4cc4df28..cf943261fe1dcc49e759399de9bb10ddeb79f608 100644 (file)
@@ -1949,8 +1949,8 @@ static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
  * Display the contents of a single services record.
  */
 
-static void dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
-                          unsigned int *flags)
+void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_service *sDefault, FILE * f,
+                         unsigned int *flags, bool show_defaults)
 {
        int i;
        struct parmlist_entry *data;
@@ -1967,7 +1967,7 @@ static void dump_a_service(struct loadparm_service * pService, struct loadparm_s
                                if (flags && (flags[i] & FLAG_DEFAULT)) {
                                        continue;
                                }
-                               if (defaults_saved) {
+                               if (!show_defaults) {
                                        if (is_default(sDefault, i)) {
                                                continue;
                                        }
@@ -2711,11 +2711,9 @@ void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
                return;
        }
 
-       defaults_saved = !show_defaults;
-
        dump_globals(lp_ctx, f, show_defaults);
 
-       dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags);
+       lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);
 
        for (iService = 0; iService < maxtoprint; iService++)
                lpcfg_dump_one(f, show_defaults, lp_ctx->services[iService], lp_ctx->sDefault);
@@ -2729,7 +2727,7 @@ void lpcfg_dump_one(FILE *f, bool show_defaults, struct loadparm_service *servic
        if (service != NULL) {
                if (service->szService[0] == '\0')
                        return;
-               dump_a_service(service, sDefault, f, NULL);
+               lpcfg_dump_a_service(service, sDefault, f, NULL, show_defaults);
        }
 }
 
index cbaabcc7db37b2a5e2b30d821ed522731a2f738a..c5d5dcc4cc4760f59b65f9b13293b3ba62c3d352 100644 (file)
@@ -3010,46 +3010,9 @@ static void dump_globals(FILE *f)
  Display the contents of a single services record.
 ***************************************************************************/
 
-static void dump_a_service(struct loadparm_service *pService, FILE * f)
+static void dump_a_service(struct loadparm_service *pService, FILE * f, bool show_defaults)
 {
-       int i;
-       struct parmlist_entry *data;
-
-       if (pService != &sDefault)
-               fprintf(f, "[%s]\n", pService->szService);
-
-       for (i = 0; parm_table[i].label; i++) {
-
-               if (parm_table[i].p_class == P_LOCAL &&
-                   !(parm_table[i].flags & FLAG_META) &&
-                   (*parm_table[i].label != '-') &&
-                   (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) 
-               {
-                       if (pService == &sDefault) {
-                               if (defaults_saved && is_default(i))
-                                       continue;
-                       } else {
-                               if (lpcfg_equal_parameter(parm_table[i].type,
-                                                         lp_parm_ptr(pService, &parm_table[i]),
-                                                         lp_parm_ptr(NULL, &parm_table[i])))
-                                       continue;
-                       }
-
-                       fprintf(f, "\t%s = ", parm_table[i].label);
-                       lpcfg_print_parameter(&parm_table[i],
-                                       lp_parm_ptr(pService, &parm_table[i]),
-                                       f);
-                       fprintf(f, "\n");
-               }
-       }
-
-               if (pService->param_opt != NULL) {
-                       data = pService->param_opt;
-                       while(data) {
-                               fprintf(f, "\t%s = %s\n", data->key, data->value);
-                               data = data->next;
-                       }
-               }
+       return lpcfg_dump_a_service(pService, &sDefault, f, NULL, show_defaults);
 }
 
 /***************************************************************************
@@ -4320,7 +4283,7 @@ void lp_dump(FILE *f, bool show_defaults, int maxtoprint)
 
        dump_globals(f);
 
-       dump_a_service(&sDefault, f);
+       dump_a_service(&sDefault, f, show_defaults);
 
        for (iService = 0; iService < maxtoprint; iService++) {
                fprintf(f,"\n");
@@ -4337,7 +4300,7 @@ void lp_dump_one(FILE * f, bool show_defaults, int snum)
        if (VALID(snum)) {
                if (ServicePtrs[snum]->szService[0] == '\0')
                        return;
-               dump_a_service(ServicePtrs[snum], f);
+               dump_a_service(ServicePtrs[snum], f, show_defaults);
        }
 }