]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmbconf: introduce a smbconf_ops layer to allow interchangeable backends.
authorMichael Adam <obnox@samba.org>
Thu, 20 Mar 2008 11:28:41 +0000 (12:28 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 21 Mar 2008 01:25:56 +0000 (02:25 +0100)
Michael

source/lib/smbconf/smbconf.c
source/lib/smbconf/smbconf_private.h

index ba20316b57dd0c405e974a6eab75cdb0188e59fb..a9e895a16854192e05784442d220778047d3bec9 100644 (file)
@@ -413,7 +413,10 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx)
  *
  **********************************************************************/
 
-static WERROR smbconf_reg_initialize(struct smbconf_ctx *ctx)
+/**
+ * initialize the registry smbconf backend
+ */
+static WERROR smbconf_reg_init(struct smbconf_ctx *ctx)
 {
        WERROR werr = WERR_OK;
 
@@ -746,6 +749,20 @@ done:
        return werr;
 }
 
+struct smbconf_ops smbconf_ops_reg = {
+       .init                   = smbconf_reg_init,
+       .get_csn                = smbconf_reg_get_csn,
+       .drop                   = smbconf_reg_drop,
+       .get_share_names        = smbconf_reg_get_share_names,
+       .share_exists           = smbconf_reg_share_exists,
+       .create_share           = smbconf_reg_create_share,
+       .get_share              = smbconf_reg_get_share,
+       .delete_share           = smbconf_reg_delete_share,
+       .set_parameter          = smbconf_reg_set_parameter,
+       .get_parameter          = smbconf_reg_get_parameter,
+       .delete_parameter       = smbconf_reg_delete_parameter
+};
+
 
 /**********************************************************************
  *
@@ -780,7 +797,9 @@ WERROR smbconf_open(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx)
                return WERR_NOMEM;
        }
 
-       werr = smbconf_reg_initialize(ctx);
+       ctx->ops = &smbconf_ops_reg;
+
+       werr = ctx->ops->init(ctx);
        if (!W_ERROR_IS_OK(werr)) {
                goto fail;
        }
@@ -821,7 +840,7 @@ bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn,
 
        old_csn = *csn;
 
-       smbconf_reg_get_csn(ctx, csn, service, param);
+       ctx->ops->get_csn(ctx, csn, service, param);
        return (csn->csn != old_csn.csn);
 }
 
@@ -830,7 +849,7 @@ bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn,
  */
 WERROR smbconf_drop(struct smbconf_ctx *ctx)
 {
-       return smbconf_reg_drop(ctx);
+       return ctx->ops->drop(ctx);
 }
 
 /**
@@ -927,8 +946,8 @@ WERROR smbconf_get_share_names(struct smbconf_ctx *ctx,
                               uint32_t *num_shares,
                               char ***share_names)
 {
-       return smbconf_reg_get_share_names(ctx, mem_ctx, num_shares,
-                                          share_names);
+       return ctx->ops->get_share_names(ctx, mem_ctx, num_shares,
+                                        share_names);
 }
 
 /**
@@ -940,7 +959,7 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx,
        if (servicename == NULL) {
                return false;
        }
-       return smbconf_reg_share_exists(ctx, servicename);
+       return ctx->ops->share_exists(ctx, servicename);
 }
 
 /**
@@ -953,7 +972,7 @@ WERROR smbconf_create_share(struct smbconf_ctx *ctx,
                return WERR_ALREADY_EXISTS;
        }
 
-       return smbconf_reg_create_share(ctx, servicename);
+       return ctx->ops->create_share(ctx, servicename);
 }
 
 /**
@@ -968,8 +987,8 @@ WERROR smbconf_get_share(struct smbconf_ctx *ctx,
                return WERR_NO_SUCH_SERVICE;
        }
 
-       return smbconf_reg_get_share(ctx, mem_ctx, servicename, num_params,
-                                    param_names, param_values);
+       return ctx->ops->get_share(ctx, mem_ctx, servicename, num_params,
+                                  param_names, param_values);
 }
 
 /**
@@ -981,7 +1000,7 @@ WERROR smbconf_delete_share(struct smbconf_ctx *ctx, const char *servicename)
                return WERR_NO_SUCH_SERVICE;
        }
 
-       return smbconf_reg_delete_share(ctx, servicename);
+       return ctx->ops->delete_share(ctx, servicename);
 }
 
 /**
@@ -996,7 +1015,7 @@ WERROR smbconf_set_parameter(struct smbconf_ctx *ctx,
                return WERR_NO_SUCH_SERVICE;
        }
 
-       return smbconf_reg_set_parameter(ctx, service, param, valstr);
+       return ctx->ops->set_parameter(ctx, service, param, valstr);
 }
 
 /**
@@ -1035,7 +1054,7 @@ WERROR smbconf_get_parameter(struct smbconf_ctx *ctx,
                return WERR_NO_SUCH_SERVICE;
        }
 
-       return smbconf_reg_get_parameter(ctx, mem_ctx, service, param, valstr);
+       return ctx->ops->get_parameter(ctx, mem_ctx, service, param, valstr);
 }
 
 /**
@@ -1069,7 +1088,7 @@ WERROR smbconf_delete_parameter(struct smbconf_ctx *ctx,
                return WERR_NO_SUCH_SERVICE;
        }
 
-       return smbconf_reg_delete_parameter(ctx, service, param);
+       return ctx->ops->delete_parameter(ctx, service, param);
 }
 
 /**
index 1827645583018a2516bf6799237440ce16a7505e..d9e0f1396a7c77cc223a5562b158b96f461dbdf5 100644 (file)
 #ifndef __LIBSMBCONF_PRIVATE_H__
 #define __LIBSMBCONF_PRIVATE_H__
 
+struct smbconf_ops {
+       WERROR (*init)(struct smbconf_ctx *ctx);
+       void (*get_csn)(struct smbconf_ctx *ctx, struct smbconf_csn *csn,
+                       const char *service, const char *param);
+       WERROR (*drop)(struct smbconf_ctx *ctx);
+       WERROR (*get_share_names)(struct smbconf_ctx *ctx,
+                                 TALLOC_CTX *mem_ctx,
+                                 uint32_t *num_shares,
+                                 char ***share_names);
+       bool (*share_exists)(struct smbconf_ctx *ctx, const char *service);
+       WERROR (*create_share)(struct smbconf_ctx *ctx, const char *service);
+       WERROR (*get_share)(struct smbconf_ctx *ctx,
+                           TALLOC_CTX *mem_ctx,
+                           const char *servicename, uint32_t *num_params,
+                           char ***param_names, char ***param_values);
+       WERROR (*delete_share)(struct smbconf_ctx *ctx,
+                                   const char *servicename);
+       WERROR (*set_parameter)(struct smbconf_ctx *ctx,
+                               const char *service,
+                               const char *param,
+                               const char *valstr);
+       WERROR (*get_parameter)(struct smbconf_ctx *ctx,
+                               TALLOC_CTX *mem_ctx,
+                               const char *service,
+                               const char *param,
+                               char **valstr);
+       WERROR (*delete_parameter)(struct smbconf_ctx *ctx,
+                                  const char *service, const char *param);
+};
+
 struct smbconf_ctx {
        NT_USER_TOKEN *token;
+       struct smbconf_ops *ops;
 };
 
 #endif