libsmbconf: Document smbconf_drop().
[kai/samba.git] / lib / smbconf / smbconf.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  libsmbconf - Samba configuration library
4  *  Copyright (C) Michael Adam 2008
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef __LIBSMBCONF_H__
21 #define __LIBSMBCONF_H__
22
23 /**
24  * @brief Status codes returned from smbconf functions
25  */
26 enum _sbcErrType {
27         SBC_ERR_OK = 0,          /**< Successful completion **/
28         SBC_ERR_NOT_IMPLEMENTED, /**< Function not implemented **/
29         SBC_ERR_NOT_SUPPORTED,   /**< Function not supported **/
30         SBC_ERR_UNKNOWN_FAILURE, /**< General failure **/
31         SBC_ERR_NOMEM,           /**< Memory allocation error **/
32         SBC_ERR_INVALID_PARAM,   /**< An Invalid parameter was supplied **/
33         SBC_ERR_BADFILE,         /**< A bad file was supplied **/
34         SBC_ERR_NO_SUCH_SERVICE, /**< There is no such service provided **/
35         SBC_ERR_IO_FAILURE,      /**< There was an IO error **/
36         SBC_ERR_CAN_NOT_COMPLETE,/**< Can not complete action **/
37         SBC_ERR_NO_MORE_ITEMS,   /**< No more items left **/
38         SBC_ERR_FILE_EXISTS,     /**< File already exists **/
39         SBC_ERR_ACCESS_DENIED,   /**< Access has been denied **/
40 };
41
42 typedef enum _sbcErrType sbcErr;
43
44 #define SBC_ERROR_IS_OK(x) ((x) == SBC_ERR_OK)
45 #define SBC_ERROR_EQUAL(x,y) ((x) == (y))
46
47 struct smbconf_ctx;
48
49 /* the change sequence number */
50 struct smbconf_csn {
51         uint64_t csn;
52 };
53
54 struct smbconf_service {
55         char *name;
56         uint32_t num_params;
57         char **param_names;
58         char **param_values;
59 };
60
61 /*
62  * The smbconf API functions
63  */
64
65 /**
66  * @brief Translate an error value into a string
67  *
68  * @param error
69  *
70  * @return a pointer to a static string
71  **/
72 const char *sbcErrorString(sbcErr error);
73
74 /**
75  * @brief Check if the backend requires messaging to be set up.
76  *
77  * Tell whether the backend requires messaging to be set up
78  * for the backend to work correctly.
79  *
80  * @param[in] ctx       The smbconf context to check.
81  *
82  * @return              True if needed, false if not.
83  */
84 bool smbconf_backend_requires_messaging(struct smbconf_ctx *ctx);
85
86 /**
87  * @brief Tell whether the source is writeable.
88  *
89  * @param[in] ctx       The smbconf context to check.
90  *
91  * @return              True if it is writeable, false if not.
92  */
93 bool smbconf_is_writeable(struct smbconf_ctx *ctx);
94
95 /**
96  * @brief Close the configuration.
97  *
98  * @param[in] ctx       The smbconf context to close.
99  */
100 void smbconf_shutdown(struct smbconf_ctx *ctx);
101
102 /**
103  * @brief Detect changes in the configuration.
104  *
105  * Get the change sequence number of the given service/parameter. Service and
106  * parameter strings may be NULL.
107  *
108  * The given change sequence number (csn) struct is filled with the current
109  * csn. smbconf_changed() can also be used for initial retrieval of the csn.
110  *
111  * @param[in] ctx       The smbconf context to check for changes.
112  *
113  * @param[inout] csn    The smbconf csn to be filled.
114  *
115  * @param[in] service   The service name to check or NULL.
116  *
117  * @param[in] param     The param to check or NULL.
118  *
119  * @return              True if it has been changed, false if not.
120  */
121 bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn,
122                      const char *service, const char *param);
123
124 /**
125  * @brief Drop the whole configuration (restarting empty).
126  *
127  * @param[in] ctx       The smbconf context to drop the config.
128  *
129  * @return              SBC_ERR_OK on success, a corresponding sbcErr if an
130  *                      error occured.
131  */
132 sbcErr smbconf_drop(struct smbconf_ctx *ctx);
133
134 sbcErr smbconf_get_config(struct smbconf_ctx *ctx,
135                           TALLOC_CTX *mem_ctx,
136                           uint32_t *num_shares,
137                           struct smbconf_service ***services);
138 sbcErr smbconf_get_share_names(struct smbconf_ctx *ctx,
139                                TALLOC_CTX *mem_ctx,
140                                uint32_t *num_shares,
141                                char ***share_names);
142 bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename);
143 sbcErr smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename);
144 sbcErr smbconf_get_share(struct smbconf_ctx *ctx,
145                          TALLOC_CTX *mem_ctx,
146                          const char *servicename,
147                          struct smbconf_service **service);
148 sbcErr smbconf_delete_share(struct smbconf_ctx *ctx,
149                             const char *servicename);
150 sbcErr smbconf_set_parameter(struct smbconf_ctx *ctx,
151                              const char *service,
152                              const char *param,
153                              const char *valstr);
154 sbcErr smbconf_set_global_parameter(struct smbconf_ctx *ctx,
155                                     const char *param, const char *val);
156 sbcErr smbconf_get_parameter(struct smbconf_ctx *ctx,
157                              TALLOC_CTX *mem_ctx,
158                              const char *service,
159                              const char *param,
160                              char **valstr);
161 sbcErr smbconf_get_global_parameter(struct smbconf_ctx *ctx,
162                                     TALLOC_CTX *mem_ctx,
163                                     const char *param,
164                                     char **valstr);
165 sbcErr smbconf_delete_parameter(struct smbconf_ctx *ctx,
166                                 const char *service, const char *param);
167 sbcErr smbconf_delete_global_parameter(struct smbconf_ctx *ctx,
168                                        const char *param);
169 sbcErr smbconf_get_includes(struct smbconf_ctx *ctx,
170                             TALLOC_CTX *mem_ctx,
171                             const char *service,
172                             uint32_t *num_includes, char ***includes);
173 sbcErr smbconf_get_global_includes(struct smbconf_ctx *ctx,
174                                    TALLOC_CTX *mem_ctx,
175                                    uint32_t *num_includes, char ***includes);
176 sbcErr smbconf_set_includes(struct smbconf_ctx *ctx,
177                             const char *service,
178                             uint32_t num_includes, const char **includes);
179 sbcErr smbconf_set_global_includes(struct smbconf_ctx *ctx,
180                                    uint32_t num_includes,
181                                    const char **includes);
182 sbcErr smbconf_delete_includes(struct smbconf_ctx *ctx, const char *service);
183 sbcErr smbconf_delete_global_includes(struct smbconf_ctx *ctx);
184
185 sbcErr smbconf_transaction_start(struct smbconf_ctx *ctx);
186 sbcErr smbconf_transaction_commit(struct smbconf_ctx *ctx);
187 sbcErr smbconf_transaction_cancel(struct smbconf_ctx *ctx);
188
189 #endif /*  _LIBSMBCONF_H_  */