summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-08-17 02:55:31 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:33:26 -0500
commit29e5e9e1e3b8f463bf782f3f42ce4a02cd55fca2 (patch)
treebca023c3d0cb95d2e25f40496223c66c9911c582 /source4/scripting/ejs
parent60beb50044b57b87bbb0143ed0236fdedfb81552 (diff)
downloadsamba-29e5e9e1e3b8f463bf782f3f42ce4a02cd55fca2.tar.gz
samba-29e5e9e1e3b8f463bf782f3f42ce4a02cd55fca2.tar.bz2
samba-29e5e9e1e3b8f463bf782f3f42ce4a02cd55fca2.zip
r9344: started adding calls for manipulation of data blobs in ejs
added: blobToArray() blobFromArray() blobCompare() (This used to be commit cc5a3e9cc3b44f418eb5dfcd4e855a36c5ac8327)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/config.mk1
-rw-r--r--source4/scripting/ejs/smbcalls.c1
-rw-r--r--source4/scripting/ejs/smbcalls_data.c165
-rw-r--r--source4/scripting/ejs/smbcalls_string.c1
4 files changed, 167 insertions, 1 deletions
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk
index 191b139c66..096c2049ab 100644
--- a/source4/scripting/ejs/config.mk
+++ b/source4/scripting/ejs/config.mk
@@ -22,6 +22,7 @@ OBJ_FILES = \
scripting/ejs/smbcalls_options.o \
scripting/ejs/smbcalls_nss.o \
scripting/ejs/smbcalls_string.o \
+ scripting/ejs/smbcalls_data.o \
scripting/ejs/smbcalls_rand.o \
scripting/ejs/smbcalls_sys.o \
scripting/ejs/smbcalls_creds.o \
diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c
index cc4a3d703a..3981e1dd7a 100644
--- a/source4/scripting/ejs/smbcalls.c
+++ b/source4/scripting/ejs/smbcalls.c
@@ -128,6 +128,7 @@ void smb_setup_ejs_functions(void)
smb_setup_ejs_random();
smb_setup_ejs_system();
smb_setup_ejs_credentials();
+ smb_setup_ejs_datablob();
ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE);
diff --git a/source4/scripting/ejs/smbcalls_data.c b/source4/scripting/ejs/smbcalls_data.c
new file mode 100644
index 0000000000..3b431dc8c3
--- /dev/null
+++ b/source4/scripting/ejs/smbcalls_data.c
@@ -0,0 +1,165 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ provide access to data blobs
+
+ Copyright (C) Andrew Tridgell 2005
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "scripting/ejs/smbcalls.h"
+#include "lib/appweb/ejs/ejs.h"
+
+/*
+ create a data blob object from a ejs array of integers
+*/
+static int ejs_blobFromArray(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct MprVar *array, *v;
+ unsigned length, i;
+ DATA_BLOB blob;
+
+ if (argc != 1) {
+ ejsSetErrorMsg(eid, "blobFromArray invalid arguments");
+ return -1;
+ }
+ array = argv[0];
+
+ v = mprGetProperty(array, "length", NULL);
+ if (v == NULL) {
+ goto failed;
+ }
+ length = mprToInt(v);
+
+ blob = data_blob_talloc(mprMemCtx(), NULL, length);
+ if (length != 0 && blob.data == NULL) {
+ goto failed;
+ }
+
+ for (i=0;i<length;i++) {
+ struct MprVar *vs;
+ char idx[16];
+ mprItoa(i, idx, sizeof(idx));
+ vs = mprGetProperty(array, idx, NULL);
+ if (vs == NULL) {
+ goto failed;
+ }
+ blob.data[i] = mprVarToNumber(vs);
+ }
+
+ mpr_Return(eid, mprDataBlob(blob));
+ return 0;
+
+failed:
+ mpr_Return(eid, mprCreateUndefinedVar());
+ return 0;
+}
+
+/*
+ create a ejs array of integers from a data blob
+*/
+static int ejs_blobToArray(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ DATA_BLOB *blob;
+ struct MprVar array;
+ int i;
+
+ if (argc != 1) {
+ ejsSetErrorMsg(eid, "blobToArray invalid arguments");
+ return -1;
+ }
+ blob = mprToDataBlob(argv[0]);
+ if (blob == NULL) {
+ goto failed;
+ }
+
+ array = mprObject("array");
+
+ for (i=0;i<blob->length;i++) {
+ mprAddArray(&array, i, mprCreateNumberVar(blob->data[i]));
+ }
+ mpr_Return(eid, array);
+ return 0;
+
+failed:
+ mpr_Return(eid, mprCreateUndefinedVar());
+ return 0;
+}
+
+
+/*
+ compare two data blobs
+*/
+static int ejs_blobCompare(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ DATA_BLOB *blob1, *blob2;
+ BOOL ret = False;
+
+ if (argc != 2) {
+ ejsSetErrorMsg(eid, "blobCompare invalid arguments");
+ return -1;
+ }
+
+ blob1 = mprToDataBlob(argv[0]);
+ blob2 = mprToDataBlob(argv[1]);
+
+ if (blob1 == blob2) {
+ ret = True;
+ goto done;
+ }
+ if (blob1 == NULL || blob2 == NULL) {
+ ret = False;
+ goto done;
+ }
+
+ if (blob1->length != blob2->length) {
+ ret = False;
+ goto done;
+ }
+
+ if (memcmp(blob1->data, blob2->data, blob1->length) != 0) {
+ ret = False;
+ goto done;
+ }
+ ret = True;
+
+done:
+ mpr_Return(eid, mprCreateBoolVar(ret));
+ return 0;
+}
+
+/*
+ initialise datablob ejs subsystem
+*/
+static int ejs_datablob_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct MprVar *obj = mprInitObject(eid, "datablob", argc, argv);
+
+ mprSetCFunction(obj, "blobFromArray", ejs_blobFromArray);
+ mprSetCFunction(obj, "blobToArray", ejs_blobToArray);
+ mprSetCFunction(obj, "blobCompare", ejs_blobCompare);
+
+ return 0;
+}
+
+/*
+ setup C functions that be called from ejs
+*/
+void smb_setup_ejs_datablob(void)
+{
+ ejsDefineCFunction(-1, "datablob_init", ejs_datablob_init, NULL, MPR_VAR_SCRIPT_HANDLE);
+}
diff --git a/source4/scripting/ejs/smbcalls_string.c b/source4/scripting/ejs/smbcalls_string.c
index b4c85dbd28..1b6b7d09dd 100644
--- a/source4/scripting/ejs/smbcalls_string.c
+++ b/source4/scripting/ejs/smbcalls_string.c
@@ -23,7 +23,6 @@
#include "includes.h"
#include "scripting/ejs/smbcalls.h"
#include "lib/appweb/ejs/ejs.h"
-#include "system/passwd.h"
/*
usage: