2 Unix SMB/CIFS implementation.
3 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 %module(package="samba.param") param
26 #include "param/param.h"
28 typedef struct param_context param;
29 typedef struct loadparm_context loadparm_context;
30 typedef struct loadparm_service loadparm_service;
31 typedef struct param_section param_section;
32 typedef struct param_opt param_opt;
38 %import "../lib/talloc/talloc.i"
40 %typemap(default) struct loadparm_context * {
41 $1 = loadparm_init(NULL);
44 %rename(LoadParm) loadparm_context;
46 %talloctype(loadparm_context);
48 typedef struct loadparm_context {
50 loadparm_context(TALLOC_CTX *mem_ctx) { return loadparm_init(mem_ctx); }
51 bool load(const char *filename) { return lp_load($self, filename); }
53 int __len__() { return lp_numservices($self); }
54 struct loadparm_service *__getitem__(const char *name) { return lp_service($self, name); }
56 const char *configfile() { return lp_configfile($self); }
57 bool is_mydomain(const char *domain) { return lp_is_mydomain($self, domain); }
58 bool is_myname(const char *name) { return lp_is_myname($self, name); }
59 int use(struct param_context *param) { return param_use($self, param); }
63 %nodefaultctor loadparm_service;
64 %nodefaultdtor loadparm_service;
66 typedef struct loadparm_service {
68 const char *volume_label() { return volume_label($self); }
69 const char *printername() { return lp_printername($self); }
70 int maxprintjobs() { return lp_maxprintjobs($self); }
74 %rename(ParamFile) param_context;
76 %talloctype(param_context);
77 typedef struct param_context {
79 param(TALLOC_CTX *mem_ctx) { return param_init(mem_ctx); }
80 struct param_section *get_section(const char *name);
81 struct param_section *add_section(const char *name);
82 struct param_opt *get(const char *name, const char *section_name="global");
83 const char *get_string(const char *name, const char *section_name="global");
84 int set_string(const char *param, const char *value, const char *section="global");
85 int set(const char *param, PyObject *ob, const char *section_name="global")
87 struct param_opt *opt = param_get_add($self, param, section_name);
89 talloc_free(opt->value);
90 opt->value = talloc_strdup(opt, PyObject_Str(ob));
95 int read(const char *fn);
96 int write(const char *fn);
99 def __getitem__(self, name):
100 ret = self.get_section(name)
102 raise KeyError("No such section %s" % name)
107 %talloctype(param_opt);
109 typedef struct param_opt {
112 const char *__str__() { return $self->value; }
118 typedef struct param_section {
120 struct param_opt *get(const char *name);
123 def __getitem__(self, name):
126 raise KeyError("No such option %s" % name)
131 %rename(default_config) global_loadparm;
132 struct loadparm_context *global_loadparm;