r9700: Change DATA_BLOB in ejs back to struct datablob
[sfrench/samba-autobuild/.git] / source4 / scripting / ejs / mprutil.c
index 657078e7c79a125d324863991f67fb05a1a765e9..9634c9bf4236ada7d6da304778548f71efafebd8 100644 (file)
@@ -161,7 +161,7 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *
        const char *multivalued[] = { "objectClass", "memberOf", "privilege", 
                                            "member", NULL };
 
-       var = mprObject(msg->dn);
+       var = mprObject(ldb_dn_linearize(msg, msg->dn));
 
        for (i=0;i<msg->num_elements;i++) {
                struct ldb_message_element *el = &msg->elements[i];
@@ -196,7 +196,7 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *
 
        /* add the dn if it is not already specified */
        if (mprGetProperty(&var, "dn", 0) == 0) {
-               mprSetVar(&var, "dn", mprString(msg->dn));
+               mprSetVar(&var, "dn", mprString(ldb_dn_linearize(msg, msg->dn)));
        }
        
        return var;             
@@ -317,6 +317,31 @@ struct MprVar mprNTSTATUS(NTSTATUS status)
        return res;
 }
 
+/*
+  create a data-blob in a mpr variable
+*/
+struct MprVar mprDataBlob(DATA_BLOB blob)
+{
+       struct MprVar res;
+       struct datablob *pblob = talloc(mprMemCtx(), struct datablob);
+       *pblob = data_blob_talloc(pblob, blob.data, blob.length);
+
+       res = mprObject("DATA_BLOB");
+
+       mprSetVar(&res, "size", mprCreateIntegerVar(blob.length));
+       mprSetPtrChild(&res, "blob", pblob);
+
+       return res;
+}
+
+/*
+  return a data blob from a mpr var created using mprDataBlob
+*/
+struct datablob *mprToDataBlob(struct MprVar *v)
+{
+       return talloc_get_type(mprGetPtr(v, "blob"), struct datablob);
+}
+
 /*
   turn a WERROR into a MprVar object with lots of funky properties
 */
@@ -344,12 +369,14 @@ void mprSetPtr(struct MprVar *v, const char *propname, const void *p)
 }
 
 /*
-  set a pointer in a existing MprVar, making it a child of the property
+  set a pointer in a existing MprVar, freeing it when the property goes away
 */
 void mprSetPtrChild(struct MprVar *v, const char *propname, const void *p)
 {
        mprSetVar(v, propname, mprCreatePtrVar(discard_const(p)));
-       talloc_steal(mprGetProperty(v, propname, NULL), p);
+       v = mprGetProperty(v, propname, NULL);
+       v->allocatedData = 1;
+       talloc_steal(mprMemCtx(), p);
 }
 
 /*