diff options
Diffstat (limited to 'source4/scripting')
-rw-r--r-- | source4/scripting/ejs/ejsrpc.c | 37 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsrpc.h | 7 | ||||
-rw-r--r-- | source4/scripting/ejs/mprutil.c | 25 |
3 files changed, 69 insertions, 0 deletions
diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c index f107c84b73..de25d3a0f0 100644 --- a/source4/scripting/ejs/ejsrpc.c +++ b/source4/scripting/ejs/ejsrpc.c @@ -349,3 +349,40 @@ NTSTATUS ejs_push_BOOL(struct ejs_rpc *ejs, { return mprSetVar(v, name, mprCreateBoolVar(*r)); } + + +/* + pull a uint8 array from a mpr variable to a C element - treating as a data blob +*/ +NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, + uint8_t *r, uint32_t length) +{ + NTSTATUS status; + DATA_BLOB *blob; + + status = mprGetVar(&v, name); + NT_STATUS_NOT_OK_RETURN(status); + + blob = mprToDataBlob(v); + if (blob == NULL) { + return NT_STATUS_OBJECT_NAME_INVALID; + } + if (blob->length != length) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + memcpy(r, blob->data, length); + return NT_STATUS_OK; + +} + +NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, + const uint8_t *r, uint32_t length) +{ + DATA_BLOB blob; + blob.data = discard_const(r); + blob.length = length; + mprSetVar(v, name, mprDataBlob(blob)); + return NT_STATUS_OK; +} diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h index 99da0d35ea..03919c3602 100644 --- a/source4/scripting/ejs/ejsrpc.h +++ b/source4/scripting/ejs/ejsrpc.h @@ -108,6 +108,13 @@ NTSTATUS ejs_pull_BOOL(struct ejs_rpc *ejs, NTSTATUS ejs_push_BOOL(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const BOOL *r); +NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, + uint8_t *r, uint32_t length); +NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, + const uint8_t *r, uint32_t length); + #define EJS_ALLOC_SIZE(ejs, s, size) do { \ (s) = talloc_size(ejs, size); \ if (!(s)) return ejs_panic(ejs, "out of memory"); \ diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c index 657078e7c7..700185f07e 100644 --- a/source4/scripting/ejs/mprutil.c +++ b/source4/scripting/ejs/mprutil.c @@ -318,6 +318,31 @@ struct MprVar mprNTSTATUS(NTSTATUS status) } /* + create a data-blob in a mpr variable +*/ +struct MprVar mprDataBlob(DATA_BLOB blob) +{ + struct MprVar res; + struct data_blob *pblob = talloc(mprMemCtx(), struct data_blob); + *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 data_blob *mprToDataBlob(struct MprVar *v) +{ + return talloc_get_type(mprGetPtr(v, "blob"), struct data_blob); +} + +/* turn a WERROR into a MprVar object with lots of funky properties */ struct MprVar mprWERROR(WERROR status) |