patch to allow controls in add function for python bindings

Jelmer Vernooij jelmer at samba.org
Fri Sep 25 05:02:00 MDT 2009


Hi Matthieu,

Thanks for the pyldb patch, I've merged it. Andrew, can you perhaps have
a look at the default controls patch?

Cheers,

Jelmer

On Wed, 2009-09-23 at 20:19 +0400, Matthieu Patou wrote:
> Hello,
> Find attached the whole set of patch for this only the patch concerning 
> the python binding has been reworked to comply with jelmer remarks.
> 
> On 09/23/2009 04:41 PM, Jelmer Vernooij wrote:
> > Hi Matthieu,
> >
> > Matthieu Patou wrote:
> >    
> >> Take 2
> >>      
> > Almost there...
> >
> >    
> >> diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
> >> index b4f03dc..8c2285d 100644
> >> --- a/source4/lib/ldb/pyldb.c
> >> +++ b/source4/lib/ldb/pyldb.c
> >> @@ -656,6 +656,66 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args)
> >>   	Py_RETURN_NONE;
> >>   }
> >>
> >> +/* autostarts a transacion if none active */
> >> +static int ldb_autotransaction_request(struct ldb_context *ldb,
> >> +                                       struct ldb_request *req)
> >> +{
> >> +        int ret;
> >> +
> >> +        ret = ldb_transaction_start(ldb);
> >> +        if (ret != LDB_SUCCESS) {
> >> +                return ret;
> >> +        }
> >> +
> >> +        ret = ldb_request(ldb, req);
> >> +        if (ret == LDB_SUCCESS) {
> >> +                ret = ldb_wait(req->handle, LDB_WAIT_ALL);
> >> +        }
> >> +
> >> +        if (ret == LDB_SUCCESS) {
> >> +                return ldb_transaction_commit(ldb);
> >> +        }
> >> +        ldb_transaction_cancel(ldb);
> >> +
> >> +        if (ldb->err_string == NULL) {
> >> +                /* no error string was setup by the backend */
> >> +                ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret);
> >> +        }
> >> +
> >> +        return ret;
> >> +}
> >>
> >>      
> > ^^^ Doesn't LDB do this by itself already? I don't think it's necessary.
> >
> >    
> >> +/*
> >> +  add a record to the database. Will fail if a record with the given class
> >> +  and key already exists.
> >> +  Allow to supply controls
> >> +*/
> >> +static int ldb_add_w_ctrls(struct ldb_context *ldb,
> >> +            const struct ldb_message *message,
> >> +            struct ldb_control **controls)
> >> +{
> >> +        struct ldb_request *req;
> >> +        int ret;
> >> +
> >> +        ret = ldb_msg_sanity_check(ldb, message);
> >> +        if (ret != LDB_SUCCESS) {
> >> +                return ret;
> >> +        }
> >> +
> >> +        ret = ldb_build_add_req(&req, ldb, ldb,
> >> +                                        message,
> >> +                                        controls,
> >> +                                        NULL,
> >> +                                        ldb_op_default_callback,
> >> +                                        NULL);
> >> +
> >> +        if (ret != LDB_SUCCESS) return ret;
> >> +
> >> +        /* do request and autostart a transaction */
> >> +        ret = ldb_autotransaction_request(ldb, req);
> >> +
> >> +        talloc_free(req);
> >> +        return ret;
> >> +}
> >>
> >>      
> > ^^ Please keep an empty line in between functions, per the coding style.
> > This code also seems simple enough to fold into py_ldb_add. That way you
> > can also raise exceptions with clearer messages.
> >
> > Cheers,
> >
> > Jelmer
> >    
> 


-- 
Jelmer Vernooij <jelmer at samba.org> - http://samba.org/~jelmer/
Jabber: jelmer at jabber.fsfe.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20090925/2fdf7aa7/attachment.pgp>


More information about the samba-technical mailing list