1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

r9292: More compiles fixes for autogenerated smb_interfaces ejs wrappers.

Add some code to try and work out whether a smb_interface requires a
TALLOC_CTX in the function signature.  I'm not sure whether this is
going to work as the raw api is a bit inconsistent I think.
(This used to be commit 13a101653e)
This commit is contained in:
Tim Potter 2005-08-13 01:42:14 +00:00 committed by Gerald (Jerry) Carter
parent 76787d5da4
commit a1ca088901

View File

@ -65,6 +65,7 @@ open(FILE, ">libcli/gen_raw/ejs_${basename}.c");
print FILE "/* EJS wrapper functions auto-generated by build_smb_interfaces.pl */\n\n";
print FILE "#include \"includes.h\"\n";
print FILE "#include \"scripting/ejs/smbcalls.h\"\n";
print FILE "#include \"lib/appweb/ejs/ejs.h\"\n";
print FILE "#include \"scripting/ejs/ejsrpc.h\"\n"; # TODO: remove this
print FILE "\n";
@ -98,6 +99,52 @@ sub transfer_struct($$) {
}
}
# Should a structure definition require a memory context to return
# data?
sub struct_need_mem_ctx($) {
my $s = shift;
for my $f (@{$s->{FIELDS}}) {
if ($f->{NAME} eq "out") {
# Look for pointers
for my $e (@{$f->{FIELDS}}) {
if (defined($e->{POINTERS})) {
return 1;
}
}
return 0;
}
}
# No 'out' structure found so we can't return anything
return 0;
}
# Does the top-level structure definition require a memory context to
# return data?
sub need_mem_ctx($) {
my $s = shift;
# Check for presence of an 'out' nested structure that contains a
# pointer.
if ($s->{TYPE} eq "struct") {
return struct_need_mem_ctx($s);
} else {
foreach my $ss (@{$s->{FIELDS}}) {
return 1 if struct_need_mem_ctx($ss);
}
return 0;
}
return 1;
}
# Top level call functions
foreach my $s (@newheader) {
@ -120,15 +167,34 @@ foreach my $s (@newheader) {
print FILE "static int ejs_$s->{TYPE_DEFINED}(int eid, int argc, struct MprVar **argv)\n";
print FILE "{\n";
print FILE "\tstruct MprVar *io;\n";
print FILE "\tstruct ejs_rpc *ejs;\n";
print FILE "\tstruct $s->{TYPE_DEFINED} params;\n";
print FILE "\tstruct smbcli_tree *tree;\n";
print FILE "\tNTSTATUS status;\n\n";
print FILE "\tNTSTATUS status;\n";
print FILE "\tvoid *ptr;\n\n";
print FILE "\tif (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) {\n";
print FILE "\t\tejsSetErrorMsg(eid, \"invalid arguments\");\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";
print FILE "\tio = argv[0];\n\n";
print FILE "\tejs = talloc(mprMemCtx(), struct ejs_rpc);\n";
print FILE "\tif (ejs == NULL) {\n";
print FILE "\t\tstatus = NT_STATUS_NO_MEMORY;\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";
print FILE "\tptr = talloc_zero_size(ejs, sizeof(struct $s->{TYPE_DEFINED}));\n";
print FILE "\tif (ptr == NULL) {\n";
print FILE "\t\tstatus = NT_STATUS_NO_MEMORY;\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";
print FILE "\tejs->eid = eid;\n\n";
print FILE "\tstatus = ejs_pull_$s->{TYPE_DEFINED}(ejs, io, ptr);\n";
print FILE "\tif (!NT_STATUS_IS_OK(status)) {\n";
print FILE "\t\treturn -1;\n";
@ -137,11 +203,15 @@ foreach my $s (@newheader) {
my $fn = $s->{TYPE_DEFINED};
$fn =~ s/^smb_/smb_raw_/;
print FILE "\tresult = $fn(tree, &params);\n\n";
if (need_mem_ctx($s)) {
print FILE "\tstatus = $fn(tree, mprMemCtx(), &params);\n\n";
} else {
print FILE "\tstatus = $fn(tree, &params);\n\n";
}
print FILE "\tstatus = ejs_push_$s->{TYPE_DEFINED}(ejs, io, ptr);\n\n";
print FILE "\tmpr_Return(eid, mprNTSTATUS(result));\n\n";
print FILE "\tmpr_Return(eid, mprNTSTATUS(status));\n\n";
print FILE "\tif (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) {\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";
@ -157,27 +227,46 @@ foreach my $s (@newheader) {
# Push/pull union arm
print FILE "NTSTATUS ejs_pull_$s->{TYPE_DEFINED}_$arm->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, struct $s->{TYPE_DEFINED}_$arm->{NAME} *r)\n";
print FILE "NTSTATUS ejs_pull_$s->{TYPE_DEFINED}_$arm->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, union $s->{TYPE_DEFINED} *r)\n";
print FILE "{\n";
print FILE "\treturn NT_STATUS_OK;\n";
print FILE "}\n\n";
print FILE "NTSTATUS ejs_push_$s->{TYPE_DEFINED}_$arm->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, const struct $s->{TYPE_DEFINED}_$arm->{NAME} *r)\n";
print FILE "NTSTATUS ejs_push_$s->{TYPE_DEFINED}_$arm->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, const union $s->{TYPE_DEFINED} *r)\n";
print FILE "{\n";
print FILE "\treturn NT_STATUS_OK;\n";
print FILE "}\n\n";
print FILE "static int ejs_$s->{TYPE_DEFINED}_$arm->{NAME}(int eid, int argc, struct MprVar **argv)\n";
print FILE "{\n";
print FILE "\tstruct MprVar *io;\n";
print FILE "\tstruct ejs_rpc *ejs;\n";
print FILE "\tunion $s->{TYPE_DEFINED} params;\n";
print FILE "\tstruct smbcli_tree *tree;\n";
print FILE "\tNTSTATUS result;\n\n";
print FILE "\tNTSTATUS status;\n";
print FILE "\tvoid *ptr;\n\n";
print FILE "\tif (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) {\n";
print FILE "\t\tejsSetErrorMsg(eid, \"invalid arguments\");\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";
print FILE "\tio = argv[0];\n\n";
print FILE "\tejs = talloc(mprMemCtx(), struct ejs_rpc);\n";
print FILE "\tif (ejs == NULL) {\n";
print FILE "\t\tstatus = NT_STATUS_NO_MEMORY;\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";
print FILE "\tptr = talloc_zero_size(ejs, sizeof(union $s->{TYPE_DEFINED}));\n";
print FILE "\tif (ptr == NULL) {\n";
print FILE "\t\tstatus = NT_STATUS_NO_MEMORY;\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";
print FILE "\tejs->eid = eid;\n\n";
print FILE "\tstatus = ejs_pull_$s->{TYPE_DEFINED}_$arm->{NAME}(ejs, io, ptr);\n";
print FILE "\tif (!NT_STATUS_IS_OK(status)) {\n";
print FILE "\t\treturn -1;\n";
@ -186,11 +275,15 @@ foreach my $s (@newheader) {
my $fn = $s->{TYPE_DEFINED};
$fn =~ s/^smb_/smb_raw_/;
print FILE "\tresult = $fn(tree, &params);\n\n";
if (need_mem_ctx($s)) {
print FILE "\tstatus = $fn(tree, mprMemCtx(), &params);\n\n";
} else {
print FILE "\tstatus = $fn(tree, &params);\n\n";
}
print FILE "\tstatus = ejs_push_$s->{TYPE_DEFINED}_$arm->{NAME}(ejs, io, ptr);\n\n";
print FILE "\tmpr_Return(eid, mprNTSTATUS(result));\n\n";
print FILE "\tmpr_Return(eid, mprNTSTATUS(status));\n\n";
print FILE "\tif (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) {\n";
print FILE "\t\treturn -1;\n";
print FILE "\t}\n\n";