diff options
Diffstat (limited to 'source4/param')
-rw-r--r-- | source4/param/generic.c | 54 | ||||
-rw-r--r-- | source4/param/loadparm.c | 2 | ||||
-rw-r--r-- | source4/param/param.i | 33 | ||||
-rw-r--r-- | source4/param/param.py | 18 | ||||
-rw-r--r-- | source4/param/param_wrap.c | 290 | ||||
-rw-r--r-- | source4/param/tests/bindings.py | 11 |
6 files changed, 342 insertions, 66 deletions
diff --git a/source4/param/generic.c b/source4/param/generic.c index f706dd6407..2327000fc9 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -49,7 +49,7 @@ struct param_opt *param_section_get(struct param_section *section, return NULL; } -struct param_opt *param_get (struct param_context *ctx, const char *section_name, const char *name) +struct param_opt *param_get (struct param_context *ctx, const char *name, const char *section_name) { struct param_section *section = param_get_section(ctx, section_name); if (section == NULL) @@ -58,8 +58,20 @@ struct param_opt *param_get (struct param_context *ctx, const char *section_name return param_section_get(section, name); } +struct param_section *param_add_section(struct param_context *ctx, const char *section_name) +{ + struct param_section *section; + section = talloc_zero(ctx, struct param_section); + if (section == NULL) + return NULL; + + section->name = talloc_strdup(section, section_name); + DLIST_ADD_END(ctx->sections, section, struct param_section *); + return section; +} + /* Look up parameter. If it is not found, add it */ -static struct param_opt *param_get_add(struct param_context *ctx, const char *section_name, const char *name) +struct param_opt *param_get_add(struct param_context *ctx, const char *name, const char *section_name) { struct param_section *section; struct param_opt *p; @@ -70,12 +82,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se section = param_get_section(ctx, section_name); if (section == NULL) { - section = talloc_zero(ctx, struct param_section); - if (section == NULL) - return NULL; - - section->name = talloc_strdup(section, section_name); - DLIST_ADD_END(ctx->sections, section, struct param_section *); + section = param_add_section(ctx, section_name); } p = param_section_get(section, name); @@ -91,9 +98,9 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se return p; } -const char *param_get_string(struct param_context *ctx, const char *section, const char *param) +const char *param_get_string(struct param_context *ctx, const char *param, const char *section) { - struct param_opt *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, param, section); if (p == NULL) return NULL; @@ -101,9 +108,9 @@ const char *param_get_string(struct param_context *ctx, const char *section, con return p->value; } -int param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value) +int param_set_string(struct param_context *ctx, const char *param, const char *value, const char *section) { - struct param_opt *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, param, section); if (p == NULL) return -1; @@ -113,10 +120,9 @@ int param_set_string(struct param_context *ctx, const char *section, const char return 0; } -const char **param_get_string_list(struct param_context *ctx, const char *section, const char *param, - const char *separator) +const char **param_get_string_list(struct param_context *ctx, const char *param, const char *separator, const char *section) { - struct param_opt *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, param, section); if (p == NULL) return NULL; @@ -127,18 +133,18 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio return str_list_make(ctx, p->value, separator); } -int param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list) +int param_set_string_list(struct param_context *ctx, const char *param, const char **list, const char *section) { - struct param_opt *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, param, section); p->value = str_list_join(p, list, ' '); return 0; } -int param_get_int(struct param_context *ctx, const char *section, const char *param, int default_v) +int param_get_int(struct param_context *ctx, const char *param, int default_v, const char *section) { - const char *value = param_get_string(ctx, section, param); + const char *value = param_get_string(ctx, param, section); if (value) return strtol(value, NULL, 0); @@ -146,7 +152,7 @@ int param_get_int(struct param_context *ctx, const char *section, const char *pa return default_v; } -void param_set_int(struct param_context *ctx, const char *section, const char *param, int value) +void param_set_int(struct param_context *ctx, const char *param, int value, const char *section) { struct param_opt *p = param_get_add(ctx, section, param); @@ -156,9 +162,9 @@ void param_set_int(struct param_context *ctx, const char *section, const char *p p->value = talloc_asprintf(p, "%d", value); } -unsigned long param_get_ulong(struct param_context *ctx, const char *section, const char *param, unsigned long default_v) +unsigned long param_get_ulong(struct param_context *ctx, const char *param, unsigned long default_v, const char *section) { - const char *value = param_get_string(ctx, section, param); + const char *value = param_get_string(ctx, param, section); if (value) return strtoul(value, NULL, 0); @@ -166,9 +172,9 @@ unsigned long param_get_ulong(struct param_context *ctx, const char *section, co return default_v; } -void param_set_ulong(struct param_context *ctx, const char *section, const char *name, unsigned long value) +void param_set_ulong(struct param_context *ctx, const char *name, unsigned long value, const char *section) { - struct param_opt *p = param_get_add(ctx, section, name); + struct param_opt *p = param_get_add(ctx, name, section); if (!p) return; diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c index 6c23a1d520..51d4beb0ae 100644 --- a/source4/param/loadparm.c +++ b/source4/param/loadparm.c @@ -2525,7 +2525,7 @@ struct loadparm_service *lp_service(struct loadparm_context *lp_ctx, { int iService; char *serviceName; - + for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) { if (lp_ctx->services[iService] && lp_ctx->services[iService]->szService) { diff --git a/source4/param/param.i b/source4/param/param.i index d013fa7ae5..3d5deba5ff 100644 --- a/source4/param/param.i +++ b/source4/param/param.i @@ -29,6 +29,7 @@ typedef struct param_context param; typedef struct loadparm_context loadparm_context; typedef struct loadparm_service loadparm_service; typedef struct param_section param_section; +typedef struct param_opt param_opt; %} %import "stdint.i" @@ -55,6 +56,7 @@ typedef struct loadparm_context { const char *configfile() { return lp_configfile($self); } bool is_mydomain(const char *domain) { return lp_is_mydomain($self, domain); } bool is_myname(const char *name) { return lp_is_myname($self, name); } + int use(struct param_context *param) { return param_use($self, param); } } } loadparm_context; @@ -76,10 +78,21 @@ typedef struct param_context { %extend { param(TALLOC_CTX *mem_ctx) { return param_init(mem_ctx); } struct param_section *get_section(const char *name); - struct param_opt *get(const char *section_name, const char *name); - int set_string(const char *section, const char *param, const char *value); + struct param_section *add_section(const char *name); + struct param_opt *get(const char *name, const char *section_name="global"); + const char *get_string(const char *name, const char *section_name="global"); + int set_string(const char *param, const char *value, const char *section="global"); + int set(const char *param, PyObject *ob, const char *section_name="global") + { + struct param_opt *opt = param_get_add($self, param, section_name); + + talloc_free(opt->value); + opt->value = talloc_strdup(opt, PyObject_Str(ob)); + + return 0; + } + int read(const char *fn); - int use(struct param_context *); int write(const char *fn); } %pythoncode { @@ -91,6 +104,16 @@ typedef struct param_context { } } param; +%talloctype(param_opt); + +typedef struct param_opt { + %extend { +#ifdef SWIGPYTHON + const char *__str__() { return $self->value; } +#endif + } +} param_opt; + %talloctype(param); typedef struct param_section { %extend { @@ -98,9 +121,9 @@ typedef struct param_section { } %pythoncode { def __getitem__(self, name): - ret = self.get_section(name) + ret = self.get(name) if ret is None: - raise KeyError("No such section %s" % name) + raise KeyError("No such option %s" % name) return ret } } param_section; diff --git a/source4/param/param.py b/source4/param/param.py index aa01d6e830..bd5965aa17 100644 --- a/source4/param/param.py +++ b/source4/param/param.py @@ -69,6 +69,7 @@ LoadParm.__getitem__ = new_instancemethod(_param.LoadParm___getitem__,None,LoadP LoadParm.configfile = new_instancemethod(_param.LoadParm_configfile,None,LoadParm) LoadParm.is_mydomain = new_instancemethod(_param.LoadParm_is_mydomain,None,LoadParm) LoadParm.is_myname = new_instancemethod(_param.LoadParm_is_myname,None,LoadParm) +LoadParm.use = new_instancemethod(_param.LoadParm_use,None,LoadParm) LoadParm_swigregister = _param.LoadParm_swigregister LoadParm_swigregister(LoadParm) @@ -95,21 +96,32 @@ class ParamFile(object): __swig_destroy__ = _param.delete_ParamFile ParamFile.get_section = new_instancemethod(_param.ParamFile_get_section,None,ParamFile) +ParamFile.add_section = new_instancemethod(_param.ParamFile_add_section,None,ParamFile) ParamFile.get = new_instancemethod(_param.ParamFile_get,None,ParamFile) +ParamFile.get_string = new_instancemethod(_param.ParamFile_get_string,None,ParamFile) ParamFile.set_string = new_instancemethod(_param.ParamFile_set_string,None,ParamFile) +ParamFile.set = new_instancemethod(_param.ParamFile_set,None,ParamFile) ParamFile.read = new_instancemethod(_param.ParamFile_read,None,ParamFile) -ParamFile.use = new_instancemethod(_param.ParamFile_use,None,ParamFile) ParamFile.write = new_instancemethod(_param.ParamFile_write,None,ParamFile) ParamFile_swigregister = _param.ParamFile_swigregister ParamFile_swigregister(ParamFile) +class param_opt(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + def __init__(self): raise AttributeError, "No constructor defined" + __repr__ = _swig_repr + __swig_destroy__ = _param.delete_param_opt +param_opt.__str__ = new_instancemethod(_param.param_opt___str__,None,param_opt) +param_opt_swigregister = _param.param_opt_swigregister +param_opt_swigregister(param_opt) + class param_section(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __getitem__(self, name): - ret = self.get_section(name) + ret = self.get(name) if ret is None: - raise KeyError("No such section %s" % name) + raise KeyError("No such option %s" % name) return ret def __init__(self, *args, **kwargs): diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c index 7f0b8c865b..ab54bca381 100644 --- a/source4/param/param_wrap.c +++ b/source4/param/param_wrap.c @@ -2522,6 +2522,7 @@ typedef struct param_context param; typedef struct loadparm_context loadparm_context; typedef struct loadparm_service loadparm_service; typedef struct param_section param_section; +typedef struct param_opt param_opt; SWIGINTERN loadparm_context *new_loadparm_context(TALLOC_CTX *mem_ctx){ return loadparm_init(mem_ctx); } @@ -2639,12 +2640,23 @@ SWIG_FromCharPtr(const char *cptr) SWIGINTERN bool loadparm_context_is_mydomain(loadparm_context *self,char const *domain){ return lp_is_mydomain(self, domain); } SWIGINTERN bool loadparm_context_is_myname(loadparm_context *self,char const *name){ return lp_is_myname(self, name); } +SWIGINTERN int loadparm_context_use(loadparm_context *self,struct param_context *param){ return param_use(self, param); } SWIGINTERN void delete_loadparm_context(loadparm_context *self){ talloc_free(self); } SWIGINTERN char const *loadparm_service_volume_label(loadparm_service *self){ return volume_label(self); } SWIGINTERN char const *loadparm_service_printername(loadparm_service *self){ return lp_printername(self); } SWIGINTERN int loadparm_service_maxprintjobs(loadparm_service *self){ return lp_maxprintjobs(self); } SWIGINTERN param *new_param(TALLOC_CTX *mem_ctx){ return param_init(mem_ctx); } +SWIGINTERN int param_set(param *self,char const *param,PyObject *ob,char const *section_name){ + struct param_opt *opt = param_get_add(self, param, section_name); + + talloc_free(opt->value); + opt->value = talloc_strdup(opt, PyObject_Str(ob)); + + return 0; + } SWIGINTERN void delete_param(param *self){ talloc_free(self); } +SWIGINTERN char const *param_opt___str__(param_opt *self){ return self->value; } +SWIGINTERN void delete_param_opt(param_opt *self){ talloc_free(self); } #ifdef __cplusplus extern "C" { #endif @@ -2901,6 +2913,47 @@ fail: } +SWIGINTERN PyObject *_wrap_LoadParm_use(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + loadparm_context *arg1 = (loadparm_context *) 0 ; + struct param_context *arg2 = (struct param_context *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "param", NULL + }; + + { + arg1 = loadparm_init(NULL); + } + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:LoadParm_use",kwnames,&obj0,&obj1)) SWIG_fail; + if (obj0) { + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_use" "', argument " "1"" of type '" "loadparm_context *""'"); + } + arg1 = (loadparm_context *)(argp1); + } + if (obj1) { + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_use" "', argument " "2"" of type '" "struct param_context *""'"); + } + arg2 = (struct param_context *)(argp2); + } + result = (int)loadparm_context_use(arg1,arg2); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_delete_LoadParm(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; loadparm_context *arg1 = (loadparm_context *) 0 ; @@ -3072,11 +3125,48 @@ fail: } +SWIGINTERN PyObject *_wrap_ParamFile_add_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + struct param_section *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_add_section",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_add_section" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_add_section" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + result = (struct param_section *)param_add_section(arg1,(char const *)arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, 0 | 0 ); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + SWIGINTERN PyObject *_wrap_ParamFile_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; param *arg1 = (param *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) 0 ; + char *arg3 = (char *) "global" ; struct param_opt *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; @@ -3090,10 +3180,10 @@ SWIGINTERN PyObject *_wrap_ParamFile_get(PyObject *SWIGUNUSEDPARM(self), PyObjec PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "section_name",(char *) "name", NULL + (char *) "self",(char *) "name",(char *) "section_name", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:ParamFile_get",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|O:ParamFile_get",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_get" "', argument " "1"" of type '" "param *""'"); @@ -3104,11 +3194,13 @@ SWIGINTERN PyObject *_wrap_ParamFile_get(PyObject *SWIGUNUSEDPARM(self), PyObjec SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_get" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); - res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get" "', argument " "3"" of type '" "char const *""'"); + if (obj2) { + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); } - arg3 = (char *)(buf3); result = (struct param_opt *)param_get(arg1,(char const *)arg2,(char const *)arg3); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_opt, 0 | 0 ); if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); @@ -3121,12 +3213,63 @@ fail: } +SWIGINTERN PyObject *_wrap_ParamFile_get_string(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + param *arg1 = (param *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) "global" ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name",(char *) "section_name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|O:ParamFile_get_string",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_get_string" "', argument " "1"" of type '" "param *""'"); + } + arg1 = (param *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_get_string" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + if (obj2) { + res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get_string" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = (char *)(buf3); + } + result = (char *)param_get_string(arg1,(char const *)arg2,(char const *)arg3); + resultobj = SWIG_FromCharPtr((const char *)result); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); + return NULL; +} + + SWIGINTERN PyObject *_wrap_ParamFile_set_string(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; param *arg1 = (param *) 0 ; char *arg2 = (char *) 0 ; char *arg3 = (char *) 0 ; - char *arg4 = (char *) 0 ; + char *arg4 = (char *) "global" ; int result; void *argp1 = 0 ; int res1 = 0 ; @@ -3144,10 +3287,10 @@ SWIGINTERN PyObject *_wrap_ParamFile_set_string(PyObject *SWIGUNUSEDPARM(self), PyObject * obj2 = 0 ; PyObject * obj3 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "section",(char *) "param",(char *) "value", NULL + (char *) "self",(char *) "param",(char *) "value",(char *) "section", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOOO:ParamFile_set_string",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:ParamFile_set_string",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_set_string" "', argument " "1"" of type '" "param *""'"); @@ -3163,11 +3306,13 @@ SWIGINTERN PyObject *_wrap_ParamFile_set_string(PyObject *SWIGUNUSEDPARM(self), SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_set_string" "', argument " "3"" of type '" "char const *""'"); } arg3 = (char *)(buf3); - res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); - if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set_string" "', argument " "4"" of type '" "char const *""'"); + if (obj3) { + res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set_string" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); } - arg4 = (char *)(buf4); result = (int)param_set_string(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4); resultobj = SWIG_From_int((int)(result)); if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); @@ -3182,73 +3327,93 @@ fail: } -SWIGINTERN PyObject *_wrap_ParamFile_read(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_ParamFile_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; param *arg1 = (param *) 0 ; char *arg2 = (char *) 0 ; + PyObject *arg3 = (PyObject *) 0 ; + char *arg4 = (char *) "global" ; int result; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "fn", NULL + (char *) "self",(char *) "param",(char *) "ob",(char *) "section_name", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_read",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:ParamFile_set",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_read" "', argument " "1"" of type '" "param *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_set" "', argument " "1"" of type '" "param *""'"); } arg1 = (param *)(argp1); res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_read" "', argument " "2"" of type '" "char const *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_set" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); - result = (int)param_read(arg1,(char const *)arg2); + arg3 = obj2; + if (obj3) { + res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + } + result = (int)param_set(arg1,(char const *)arg2,arg3,(char const *)arg4); resultobj = SWIG_From_int((int)(result)); if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); return NULL; } -SWIGINTERN PyObject *_wrap_ParamFile_use(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_ParamFile_read(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; param *arg1 = (param *) 0 ; - struct param_context *arg2 = (struct param_context *) 0 ; + char *arg2 = (char *) 0 ; int result; void *argp1 = 0 ; int res1 = 0 ; - void *argp2 = 0 ; - int res2 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; char * kwnames[] = { - (char *) "self",(char *)"arg2", NULL + (char *) "self",(char *) "fn", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_use",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_read",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_use" "', argument " "1"" of type '" "param *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_read" "', argument " "1"" of type '" "param *""'"); } arg1 = (param *)(argp1); - res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_param_context, 0 | 0 ); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_use" "', argument " "2"" of type '" "struct param_context *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_read" "', argument " "2"" of type '" "char const *""'"); } - arg2 = (struct param_context *)(argp2); - result = (int)param_use(arg1,arg2); + arg2 = (char *)(buf2); + result = (int)param_read(arg1,(char const *)arg2); resultobj = SWIG_From_int((int)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); return resultobj; fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); return NULL; } @@ -3324,6 +3489,59 @@ SWIGINTERN PyObject *ParamFile_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject return SWIG_Python_InitShadowInstance(args); } +SWIGINTERN PyObject *_wrap_param_opt___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_opt *arg1 = (param_opt *) 0 ; + char *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_opt___str__" "', argument " "1"" of type '" "param_opt *""'"); + } + arg1 = (param_opt *)(argp1); + result = (char *)param_opt___str__(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_delete_param_opt(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + param_opt *arg1 = (param_opt *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_param_opt" "', argument " "1"" of type '" "param_opt *""'"); + } + arg1 = (param_opt *)(argp1); + delete_param_opt(arg1); + + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *param_opt_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *obj; + if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_param_opt, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); +} + SWIGINTERN PyObject *_wrap_param_section_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; param_section *arg1 = (param_section *) 0 ; @@ -3439,6 +3657,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"LoadParm_configfile", (PyCFunction) _wrap_LoadParm_configfile, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"LoadParm_is_mydomain", (PyCFunction) _wrap_LoadParm_is_mydomain, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"LoadParm_is_myname", (PyCFunction) _wrap_LoadParm_is_myname, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_use", (PyCFunction) _wrap_LoadParm_use, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_LoadParm", (PyCFunction) _wrap_delete_LoadParm, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"LoadParm_swigregister", LoadParm_swigregister, METH_VARARGS, NULL}, { (char *)"LoadParm_swiginit", LoadParm_swiginit, METH_VARARGS, NULL}, @@ -3448,14 +3667,19 @@ static PyMethodDef SwigMethods[] = { { (char *)"loadparm_service_swigregister", loadparm_service_swigregister, METH_VARARGS, NULL}, { (char *)"new_ParamFile", (PyCFunction)_wrap_new_ParamFile, METH_NOARGS, NULL}, { (char *)"ParamFile_get_section", (PyCFunction) _wrap_ParamFile_get_section, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_add_section", (PyCFunction) _wrap_ParamFile_add_section, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_get", (PyCFunction) _wrap_ParamFile_get, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_get_string", (PyCFunction) _wrap_ParamFile_get_string, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_set_string", (PyCFunction) _wrap_ParamFile_set_string, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_set", (PyCFunction) _wrap_ParamFile_set, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_read", (PyCFunction) _wrap_ParamFile_read, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ParamFile_use", (PyCFunction) _wrap_ParamFile_use, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_write", (PyCFunction) _wrap_ParamFile_write, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_ParamFile", (PyCFunction)_wrap_delete_ParamFile, METH_O, NULL}, { (char *)"ParamFile_swigregister", ParamFile_swigregister, METH_VARARGS, NULL}, { (char *)"ParamFile_swiginit", ParamFile_swiginit, METH_VARARGS, NULL}, + { (char *)"param_opt___str__", (PyCFunction)_wrap_param_opt___str__, METH_O, NULL}, + { (char *)"delete_param_opt", (PyCFunction)_wrap_delete_param_opt, METH_O, NULL}, + { (char *)"param_opt_swigregister", param_opt_swigregister, METH_VARARGS, NULL}, { (char *)"param_section_get", (PyCFunction) _wrap_param_section_get, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"new_param_section", (PyCFunction)_wrap_new_param_section, METH_NOARGS, NULL}, { (char *)"delete_param_section", (PyCFunction)_wrap_delete_param_section, METH_O, NULL}, @@ -3474,7 +3698,7 @@ static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "stru static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *|param_opt *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; diff --git a/source4/param/tests/bindings.py b/source4/param/tests/bindings.py index 57ad23b21e..11f8a299be 100644 --- a/source4/param/tests/bindings.py +++ b/source4/param/tests/bindings.py @@ -35,6 +35,17 @@ class ParamTestCase(unittest.TestCase): file = param.ParamFile() self.assertTrue(file is not None) + def test_add_section(self): + file = param.ParamFile() + file.add_section("global") + self.assertTrue(file["global"] is not None) + + def test_set_param_string(self): + file = param.ParamFile() + file.add_section("global") + file["global"]["data"] = "bar" + self.assertEquals("bar", file["global"]["data"]) + def test_get_section(self): file = param.ParamFile() self.assertEquals(None, file.get_section("unknown")) |