svn commit: samba r9496 - in branches/SAMBA_4_0/source/scripting/ejs: .

Stefan (metze) Metzmacher metze at samba.org
Tue Aug 23 05:09:26 GMT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

tridge at samba.org schrieb:
> Author: tridge
> Date: 2005-08-23 01:59:08 +0000 (Tue, 23 Aug 2005)
> New Revision: 9496
> 
> WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9496
> 
> Log:
> 
> added a regToVar() function that converts a registry blob variable to a ejs variable.
> 
> Modified:
>    branches/SAMBA_4_0/source/scripting/ejs/smbcalls_data.c
> 
> 
> Changeset:
> Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_data.c
> ===================================================================
> --- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_data.c	2005-08-23 00:41:25 UTC (rev 9495)
> +++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_data.c	2005-08-23 01:59:08 UTC (rev 9496)
> @@ -23,6 +23,7 @@
>  #include "includes.h"
>  #include "scripting/ejs/smbcalls.h"
>  #include "lib/appweb/ejs/ejs.h"
> +#include "librpc/gen_ndr/winreg.h"
>  
>  /*
>    create a data blob object from a ejs array of integers
> @@ -142,7 +143,124 @@
>  	return 0;
>  }
>  
> +
>  /*
> +  convert a blob in winreg format to a mpr variable
> +  
> +  usage:
> +     v = data.regToVar(blob, type);
> +*/
> +static int ejs_regToVar(MprVarHandle eid, int argc, struct MprVar **argv)
> +{
> +	DATA_BLOB *blob;
> +	enum winreg_Type type;
> +	struct MprVar v;
> +
> +	if (argc != 2) {
> +		ejsSetErrorMsg(eid, "regToVar invalid arguments");
> +		return -1;		
> +	}
> +	
> +	blob = mprToDataBlob(argv[0]);
> +	type = mprToInt(argv[1]);
> +
> +	if (blob == NULL) {
> +		ejsSetErrorMsg(eid, "regToVar null data");
> +		return -1;
> +	}
> +
> +	switch (type) {
> +	case REG_NONE:
> +		v = mprCreateUndefinedVar();
> +		break;
> +
> +	case REG_SZ:
> +	case REG_EXPAND_SZ: {
> +		char *s;
> +		ssize_t len;
> +		len = convert_string_talloc(mprMemCtx(), CH_UTF16, CH_UNIX, 
> +					    blob->data, blob->length, &s);
> +		if (len == -1) {
> +			ejsSetErrorMsg(eid, "regToVar invalid REG_SZ string");
> +			return -1;
> +		}
> +		v = mprString(s);
> +		talloc_free(s);
> +		break;
> +	}
> +
> +	case REG_DWORD: {
> +		if (blob->length != 4) {
> +			ejsSetErrorMsg(eid, "regToVar invalid REG_DWORD length %d", blob->length);
> +			return -1;
> +		}
> +		v = mprCreateNumberVar(IVAL(blob->data, 0));
> +		break;
> +	}
> +
> +	case REG_DWORD_BIG_ENDIAN: {
> +		if (blob->length != 4) {
> +			ejsSetErrorMsg(eid, "regToVar invalid REG_DWORD_BIG_ENDIAN length %d", blob->length);
> +			return -1;
> +		}
> +		v = mprCreateNumberVar(RIVAL(blob->data, 0));
> +		break;
> +	}
> +
> +	case REG_QWORD: {
> +		if (blob->length != 8) {
> +			ejsSetErrorMsg(eid, "regToVar invalid REG_QWORD length %d", blob->length);
> +			return -1;
> +		}
> +		v = mprCreateNumberVar(BVAL(blob->data, 0));
> +		break;
> +	}
> +
> +	case REG_MULTI_SZ: {
> +		DATA_BLOB b = *blob;
> +		char **list = NULL;
> +		while (b.length > 0) {
> +			char *s;
> +			ssize_t len;
> +			size_t slen = utf16_len_n(b.data, b.length);
> +			if (slen == 2 && b.length == 2 && SVAL(b.data, 0) == 0) {
> +				break;
> +			}
> +			len = convert_string_talloc(mprMemCtx(), CH_UTF16, CH_UNIX, 
> +						    b.data, slen, &s);
> +			if (len == -1) {
> +				ejsSetErrorMsg(eid, "regToVar invalid REG_MULTI_SZ string");
> +				return -1;
> +			}
> +			list = str_list_add(list, s);
> +			talloc_free(s);
> +			talloc_steal(mprMemCtx(), list);
> +			b.data += slen;
> +			b.length -= slen;
> +		}
> +		v = mprList("REG_MULTI_SZ", list);
> +		talloc_free(list);
> +		break;
> +	}
> +		
> +
> +	case REG_FULL_RESOURCE_DESCRIPTOR:
> +	case REG_RESOURCE_LIST:
> +	case REG_BINARY:
> +	case REG_RESOURCE_REQUIREMENTS_LIST:
> +	case REG_LINK:
> +		return ejs_blobToArray(eid, 1, argv);
> +
> +	default:
> +		ejsSetErrorMsg(eid, "regToVar invalid type %d", type);
> +		return -1;		
> +	}
> +	
> +	mpr_Return(eid, v);
> +	return 0;
> +}
> +
> +/*
>    initialise datablob ejs subsystem
>  */
>  static int ejs_datablob_init(MprVarHandle eid, int argc, struct MprVar **argv)
> @@ -152,6 +270,7 @@
>  	mprSetCFunction(obj, "blobFromArray", ejs_blobFromArray);
>  	mprSetCFunction(obj, "blobToArray", ejs_blobToArray);
>  	mprSetCFunction(obj, "blobCompare", ejs_blobCompare);
> +	mprSetCFunction(obj, "regToVar", ejs_regToVar);
Hi Tridge,

I think we should try to do that in the ndr layer, as I have done it in the spoolss code,
then it will be easy to programm in C too.

And then we can share the structs/union between winreg and spoolss


- --
metze

Stefan Metzmacher <metze at samba.org> www.samba.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3-nr1 (Windows XP)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDCq8tm70gjA5TCD8RAgJjAKC/Ky4pqwcPQHDNxMEcZ73Utl73WQCgnFHA
zMhnyr9nqFCLzjMSY2hrrZY=
=Q01I
-----END PGP SIGNATURE-----


More information about the samba-cvs mailing list