summaryrefslogtreecommitdiff
path: root/source3/aparser
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>2000-05-31 05:39:54 +0000
committerLuke Leighton <lkcl@samba.org>2000-05-31 05:39:54 +0000
commitd500cbb2064e4beb40a760f62b53a3f75f2a87fb (patch)
tree2cf28401f2e473d02a8d5555a4007c65f511051b /source3/aparser
parent23d705672eea5562c585421c2d4c0be694a7f354 (diff)
downloadsamba-d500cbb2064e4beb40a760f62b53a3f75f2a87fb.tar.gz
samba-d500cbb2064e4beb40a760f62b53a3f75f2a87fb.tar.bz2
samba-d500cbb2064e4beb40a760f62b53a3f75f2a87fb.zip
messing about.
(This used to be commit 9c6f2d75d848a280f25f2377130953ecd824b7b1)
Diffstat (limited to 'source3/aparser')
-rw-r--r--source3/aparser/Makefile2
-rwxr-xr-xsource3/aparser/build2
-rw-r--r--source3/aparser/cifs.struct38
-rw-r--r--source3/aparser/header.awk12
-rw-r--r--source3/aparser/main.awk2
-rw-r--r--source3/aparser/parsefn.awk70
-rw-r--r--source3/aparser/parser.c247
-rw-r--r--source3/aparser/parser.h46
-rw-r--r--source3/aparser/parsetree.awk8
-rw-r--r--source3/aparser/templates/fn_end.tpl4
-rw-r--r--source3/aparser/templates/fn_start.tpl10
-rw-r--r--source3/aparser/templates/harness.tpl2
-rw-r--r--source3/aparser/templates/harness_start.tpl5
-rw-r--r--source3/aparser/templates/module_start.tpl3
-rw-r--r--source3/aparser/templates/prs_.align.tpl2
-rw-r--r--source3/aparser/templates/prs_array.tpl2
-rw-r--r--source3/aparser/templates/prs_array_remainder.tpl10
-rw-r--r--source3/aparser/templates/prs_uint16.tpl2
-rw-r--r--source3/aparser/templates/prs_uint32.tpl2
-rw-r--r--source3/aparser/templates/prs_uint8s.tpl2
-rw-r--r--source3/aparser/templates/prs_uint8s_fixed.tpl3
-rw-r--r--source3/aparser/templates/prs_wstring.tpl2
-rw-r--r--source3/aparser/templates/prs_wstring_fixed.tpl2
-rw-r--r--source3/aparser/token.awk12
-rw-r--r--source3/aparser/vluke.c16
25 files changed, 297 insertions, 209 deletions
diff --git a/source3/aparser/Makefile b/source3/aparser/Makefile
index ebf3a9bcde..68e63193c2 100644
--- a/source3/aparser/Makefile
+++ b/source3/aparser/Makefile
@@ -1,7 +1,7 @@
CFLAGS=-Wall -g
CC=gcc
-OBJ = vluke.o parser.o
+OBJ = vluke.o parser.o util.o
AWKPROGS=dump.awk harness.awk header.awk parsefn.awk main.awk parsetree.awk template.awk util.awk
all: test.h vluke
diff --git a/source3/aparser/build b/source3/aparser/build
index 3c212cfe41..574cad9620 100755
--- a/source3/aparser/build
+++ b/source3/aparser/build
@@ -8,6 +8,6 @@ if ! igawk -f main.awk $file; then
fi
echo compiling vluke
-gcc -Wall -o vluke parser.c vluke.c
+gcc -Wall -o vluke parser.c vluke.c util.c
echo done.
diff --git a/source3/aparser/cifs.struct b/source3/aparser/cifs.struct
index c50810b4ac..9bafa1f930 100644
--- a/source3/aparser/cifs.struct
+++ b/source3/aparser/cifs.struct
@@ -29,7 +29,7 @@ typedef struct {
typedef struct {
uint8 tag2;
- string protocol;
+ STRING protocol;
} BUF2;
typedef struct {
@@ -65,7 +65,7 @@ typedef struct {
USHORT Reserved; /* MBZ */
USHORT ByteCount; /* Count of data bytes */
UCHAR Challenge[ChallengeLength]; /* The challenge */
- string PrimaryDomain; /* The server's primary domain */
+ STRING PrimaryDomain; /* The server's primary domain */
} R_NEGPROT_12;
@@ -99,7 +99,7 @@ typedef struct {
/* security package if CAP_EXTENDED_SECURITY is */
/* on in the Capabilities field; else challenge */
/* for CIFS challenge/response authentication. */
- string OemDomainName[+]; /*The name of the domain (in OEM chars); not */
+ STRING OemDomainName[+]; /*The name of the domain (in OEM chars); not */
/* present if CAP_EXTENDED_SECURITY is on in the */
/* Capabilities field */
} R_NEGPROT_17;
@@ -163,9 +163,9 @@ typedef struct {
uint16 bcount;
uint8 password[pwlen];
- string domain;
- string os;
- string server;
+ STRING domain;
+ STRING os;
+ STRING server;
} Q_SESSION_SETUP_ANDX_10;
@@ -183,10 +183,10 @@ typedef struct {
uint16 bcount;
uint8 password[pwlen];
uint8 upassword[upwlen];
- string user;
- string domain;
- string os;
- string server;
+ STRING user;
+ STRING domain;
+ STRING os;
+ STRING server;
} Q_SESSION_SETUP_ANDX_13;
@@ -204,8 +204,8 @@ typedef struct {
uint16 passlen;
uint16 bcount;
uint8 password[passlen];
- string path;
- string device;
+ STRING path;
+ STRING device;
} Q_TCON_ANDX_4;
typedef struct _Q_TCON_ANDX {
@@ -219,7 +219,7 @@ typedef struct {
ANDX_INFO andx;
uint16 vwv2;
uint16 bcount;
- string share;
+ STRING share;
} R_TCON_ANDX_3;
typedef struct _R_TCON_ANDX {
@@ -234,9 +234,9 @@ typedef struct {
uint16 action;
uint16 count;
- string os;
- string server;
- string domain;
+ STRING os;
+ STRING server;
+ STRING domain;
} R_SESSION_SETUP_ANDX_10;
typedef struct _R_SESSION_SETUP_ANDX {
@@ -694,7 +694,7 @@ typedef struct {
typedef struct {
USHORT InformationLevel; /* Level of information requested */
ULONG Reserved; /* Must be zero */
- string FileName; /* File or directory name */
+ STRING FileName; /* File or directory name */
} TRANS2_QUERY_PATH_INFO_STRUCT;
typedef struct {
@@ -703,7 +703,7 @@ typedef struct {
USHORT Flags;
USHORT InformationLevel;
ULONG SearchStorageType;
- string FileName;
+ STRING FileName;
} TRANS2_FIND_FIRST2_STRUCT;
typedef struct _Q_TRANS2_15 {
@@ -857,7 +857,7 @@ typedef struct _Q_TRANS_16 {
UCHAR Reserved3; /* Reserved (pad above to word) */
USHORT Setup[SetupCount]; /* Setup words (# = SetupWordCount) */
USHORT ByteCount; /* Count of data bytes */
- string Name; /* Must be NULL */
+ STRING Name; /* Must be NULL */
.align4 0;
UCHAR Parameters[ParameterCount];/* Parameter bytes (# = ParameterCount) */
.align4 0;
diff --git a/source3/aparser/header.awk b/source3/aparser/header.awk
index 24232bacf0..900985b84b 100644
--- a/source3/aparser/header.awk
+++ b/source3/aparser/header.awk
@@ -3,9 +3,16 @@
function header_elstring(elnum,
LOCAL, elem)
{
+ array_len = elements[elnum, "array_len"];
elem=elements[elnum, "elem"];
if (elements[elnum, "ptr"]=="1") elem="*"elem;
- if (elements[elnum, "array_len"]!="") elem="*"elem;
+ if (array_len!="") {
+ if (match(array_len,"[0-9]") == 1) {
+ elem=elem"["array_len"]";
+ } else {
+ elem="*"elem;
+ }
+ }
return elem;
}
@@ -54,9 +61,12 @@ function produce_headers(f, NIL,
LOCAL, i)
{
xprintf(f,"/* auto-generated headers for %s */\n\n\n", module);
+ xprintf(f,"#ifndef _%s_\n", module);
+ xprintf(f,"#define _%s_\n", module);
for (i=0;i < num_structs;i++) {
header_struct(f, i);
}
xprintf(f,"/* end auto-generated headers */\n\n");
+ xprintf(f,"#endif /* _%s_ */\n", module);
}
diff --git a/source3/aparser/main.awk b/source3/aparser/main.awk
index 46acfe5c59..7163dbc829 100644
--- a/source3/aparser/main.awk
+++ b/source3/aparser/main.awk
@@ -14,7 +14,7 @@ END {
printf("Producing headers...\n");
produce_headers("prs_"module".h");
printf("Producing parsers...\n");
- produce_parsers("prs_"module".c");
+ produce_parsers("prs_"module".c", "mod_"module".c");
printf("Producing harness...\n");
produce_harness("test.h");
printf("Done.\n");
diff --git a/source3/aparser/parsefn.awk b/source3/aparser/parsefn.awk
index f4fb65dd07..2bebd765e6 100644
--- a/source3/aparser/parsefn.awk
+++ b/source3/aparser/parsefn.awk
@@ -47,6 +47,9 @@ function parse_array(f, v, elnum, flags,
function parse_element(f, v, elnum, flags,
LOCAL, type, elem)
{
+ if (elements[elnum,"nowire"] != "") {
+ return;
+ }
type = elements[elnum, "type"];
if (substr(type,1,1) == ".") return;
elem = elements[elnum, "elem"];
@@ -130,6 +133,40 @@ function parse_pointer(f, v, elnum, flags,
print_template(f, "prs_pointer.tpl", v);
}
+function parse_scalar_fn(m, v, elnum,
+ LOCAL, elem, type)
+{
+ elem = elements[elnum, "elem"];
+ type = elements[elnum, "type"]
+ xprintf(m, "%s %s", type, elem_name(v, elem));
+ if (type == "union") {
+ } else if (elements[elnum, "array_len"]!="") {
+ } else {
+ }
+}
+
+function parse_pointer_fn(f, v, elnum, flags,
+ LOCAL, elem)
+{
+ elem = elements[elnum, "elem"];
+ v["ELEM"] = elem_name(v, elem);
+ v["FLAGS"] = flags;
+ xprintf(m, "%s\n", v["ELEM"]);
+}
+
+function parse_scalars_fn(m, v, elnum, flags)
+{
+ if (elements[elnum, "type"] == ".align2") {
+ }
+ else if (elements[elnum, "type"] == ".align4") {
+ }
+ else if (elements[elnum, "ptr"] == "1") {
+ parse_pointer_fn(m, v, elnum, flags);
+ } else {
+ parse_scalar_fn(m, v, elnum, flags);
+ }
+}
+
function parse_scalars(f, v, elnum, flags)
{
if (elements[elnum, "type"] == ".align2") {
@@ -163,15 +200,20 @@ function parse_buffers(f, v, elnum, flags,
}
}
-function struct_parser(f, v, struct_num,
- LOCAL, i, n1)
+function struct_parser(f, m, v, struct_num,
+ LOCAL, i, n1, f1, num_elems)
{
+ f1 = -1;
+ num_elems = structs[struct_num, "num_elems"];
v["STRUCTNAME"] = structs[struct_num, "name"];
v["FUNCNAME"] = "io_" v["STRUCTNAME"];
print_template(f, "fn_start.tpl", v);
- for (n1=0;n1<structs[struct_num, "num_elems"];n1++) {
- if (elements[structs[struct_num, n1], "type"] == ".trailer") break;
+ for (n1=0;n1<num_elems;n1++) {
+ if (elements[structs[struct_num, n1], "type"] == ".trailer") {
+ f1 = n1;
+ break;
+ }
}
# first all the structure pointers, scalars and arrays
@@ -187,7 +229,7 @@ function struct_parser(f, v, struct_num,
}
# and any trailers
- for (i=n1;i<structs[struct_num, "num_elems"];i++) {
+ for (i=n1;i<num_elems;i++) {
parse_scalars(f, v, structs[struct_num, i], "PARSE_SCALARS");
parse_buffers(f, v, structs[struct_num, i], "PARSE_BUFFERS");
}
@@ -198,9 +240,23 @@ function struct_parser(f, v, struct_num,
else {
print_template(f, "fn_end0.tpl", v);
}
+
+ if (f1 == -1)
+ return;
+
+ xprintf(m, "void fn_%s(\n", v["STRUCTNAME"]);
+
+ for (i=f1+1;i<num_elems;i++) {
+ parse_scalars_fn(m, v, structs[struct_num, i]);
+ if (i != num_elems-1)
+ xprintf(m, ", \n");
+
+ }
+
+ xprintf(m, ")\n{\n}\n");
}
-function produce_parsers(f,
+function produce_parsers(f, m,
LOCAL, v, i)
{
v["MODULE"]=module;
@@ -208,7 +264,7 @@ function produce_parsers(f,
print_template(f, "module_start.tpl", v);
for (i=0;i < num_structs;i++) {
- struct_parser(f, v, i);
+ struct_parser(f, m, v, i);
}
print_template(f, "module_end.tpl", v);
diff --git a/source3/aparser/parser.c b/source3/aparser/parser.c
index 000f361f26..f831393973 100644
--- a/source3/aparser/parser.c
+++ b/source3/aparser/parser.c
@@ -1,47 +1,12 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <unistd.h>
-#include "parser.h"
+#include "includes.h"
-char *tab_depth(int depth)
-{
- static pstring spaces;
- memset(spaces, ' ', depth * 4);
- spaces[depth * 4] = 0;
- return spaces;
-}
-
-/****************************************************************************
-expand a pointer to be a particular size
-****************************************************************************/
-void *Realloc(void *p,size_t size)
-{
- void *ret=NULL;
-
- if (size == 0) {
- if (p) free(p);
- DEBUG(5,("Realloc asked for 0 bytes\n"));
- return NULL;
- }
-
- if (!p)
- ret = (void *)malloc(size);
- else
- ret = (void *)realloc(p,size);
-
- if (!ret)
- DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
-
- return(ret);
-}
/*******************************************************************
Attempt, if needed, to grow a data buffer.
Also depends on the data stream mode (io).
********************************************************************/
-BOOL prs_grow(prs_struct *ps, uint32 extra_space)
+BOOL io_grow(io_struct *ps, uint32 extra_space)
{
uint32 new_size;
char *new_data;
@@ -53,11 +18,11 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
/*
* We cannot grow the buffer if we're not reading
- * into the prs_struct, or if we don't own the memory.
+ * into the io_struct, or if we don't own the memory.
*/
if(UNMARSHALLING(ps) || !ps->is_dynamic) {
- DEBUG(0,("prs_grow: Buffer overflow - unable to expand buffer by %u bytes.\n",
+ DEBUG(0,("io_grow: Buffer overflow - unable to expand buffer by %u bytes.\n",
(unsigned int)extra_space));
return False;
}
@@ -76,7 +41,7 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
if((new_data = malloc(new_size)) == NULL) {
- DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
+ DEBUG(0,("io_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
return False;
}
memset(new_data, '\0', new_size );
@@ -88,7 +53,7 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);
if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
- DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
+ DEBUG(0,("io_grow: Realloc failure for size %u.\n",
(unsigned int)new_size));
return False;
}
@@ -104,14 +69,14 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
Ensure we can read/write to a given offset.
********************************************************************/
-char *prs_mem_get(prs_struct *ps, uint32 extra_size)
+char *io_mem_get(io_struct *ps, uint32 extra_size)
{
if(UNMARSHALLING(ps)) {
/*
* If reading, ensure that we can read the requested size item.
*/
if (ps->data_offset + extra_size > ps->buffer_size) {
- DEBUG(0,("prs_mem_get: reading data of size %u would overrun buffer.\n",
+ DEBUG(0,("io_mem_get: reading data of size %u would overrun buffer.\n",
(unsigned int)extra_size ));
return NULL;
}
@@ -119,7 +84,7 @@ char *prs_mem_get(prs_struct *ps, uint32 extra_size)
/*
* Writing - grow the buffer if needed.
*/
- if(!prs_grow(ps, extra_size))
+ if(!io_grow(ps, extra_size))
return False;
}
return &ps->data_p[ps->data_offset];
@@ -129,7 +94,7 @@ char *prs_mem_get(prs_struct *ps, uint32 extra_size)
Initialise a parse structure - malloc the data if requested.
********************************************************************/
-BOOL prs_init(prs_struct *ps, uint32 size, BOOL io)
+BOOL io_init(io_struct *ps, uint32 size, BOOL io)
{
ZERO_STRUCTP(ps);
ps->io = io;
@@ -142,7 +107,7 @@ BOOL prs_init(prs_struct *ps, uint32 size, BOOL io)
if (size != 0) {
ps->buffer_size = size;
if((ps->data_p = (char *)malloc((size_t)size)) == NULL) {
- DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size));
+ DEBUG(0,("io_init: malloc fail for %u bytes.\n", (unsigned int)size));
return False;
}
ps->is_dynamic = True; /* We own this memory. */
@@ -157,7 +122,7 @@ BOOL prs_init(prs_struct *ps, uint32 size, BOOL io)
XXXX side-effect of this function is to increase the debug depth XXXX
********************************************************************/
-void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name)
+void io_debug(io_struct *ps, int depth, char *desc, char *fn_name)
{
DEBUG(5+depth, ("%s%06x %s %s\n", tab_depth(depth), ps->data_offset, fn_name, desc));
}
@@ -167,13 +132,13 @@ void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name)
zeros.
********************************************************************/
-BOOL io_align2(prs_struct *ps, int offset)
+BOOL io_align2(io_struct *ps, int offset)
{
uint32 mod = (ps->data_offset + offset) & (2-1);
if (mod != 0) {
uint32 extra_space = (2 - mod);
- if(!prs_grow(ps, extra_space))
+ if(!io_grow(ps, extra_space))
return False;
memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
ps->data_offset += extra_space;
@@ -182,13 +147,13 @@ BOOL io_align2(prs_struct *ps, int offset)
return True;
}
-BOOL io_align4(prs_struct *ps, int offset)
+BOOL io_align4(io_struct *ps, int offset)
{
uint32 mod = (ps->data_offset + offset) & (4-1);
if (mod != 0) {
uint32 extra_space = (4 - mod);
- if(!prs_grow(ps, extra_space))
+ if(!io_grow(ps, extra_space))
return False;
memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
ps->data_offset += extra_space;
@@ -202,7 +167,7 @@ BOOL io_align4(prs_struct *ps, int offset)
zeros.
********************************************************************/
-BOOL prs_align(prs_struct *ps, int align)
+BOOL io_align(io_struct *ps, int align)
{
uint32 mod = ps->data_offset & (align-1);
@@ -210,7 +175,7 @@ BOOL prs_align(prs_struct *ps, int align)
if (align != 0 && mod != 0) {
uint32 extra_space = (align - mod);
- if(!prs_grow(ps, extra_space))
+ if(!io_grow(ps, extra_space))
return False;
memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
ps->data_offset += extra_space;
@@ -220,21 +185,14 @@ BOOL prs_align(prs_struct *ps, int align)
}
-void print_asc(int level, unsigned char *buf,int len)
-{
- int i;
- for (i=0;i<len;i++)
- DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.'));
-}
-
/*******************************************************************
read from a socket into memory.
********************************************************************/
-BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout)
+BOOL io_read(io_struct *ps, int fd, size_t len, int timeout)
{
BOOL ok;
size_t prev_size = ps->buffer_size;
- if (!prs_grow(ps, len))
+ if (!io_grow(ps, len))
{
return False;
}
@@ -250,52 +208,19 @@ BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout)
return ok;
}
-void dump_data(int level,char *buf1,int len)
-{
- unsigned char *buf = (unsigned char *)buf1;
- int i=0;
- if (len<=0) return;
-
- DEBUG(level,("[%03X] ",i));
- for (i=0;i<len;) {
- DEBUG(level,("%02X ",(int)buf[i]));
- i++;
- if (i%8 == 0) DEBUG(level,(" "));
- if (i%16 == 0) {
- print_asc(level,&buf[i-16],8); DEBUG(level,(" "));
- print_asc(level,&buf[i-8],8); DEBUG(level,("\n"));
- if (i<len) DEBUG(level,("[%03X] ",i));
- }
- }
- if (i%16) {
- int n;
-
- n = 16 - (i%16);
- DEBUG(level,(" "));
- if (n>8) DEBUG(level,(" "));
- while (n--) DEBUG(level,(" "));
-
- n = MIN(8,i%16);
- print_asc(level,&buf[i-(i%16)],n); DEBUG(level,(" "));
- n = (i%16) - n;
- if (n>0) print_asc(level,&buf[i-n],n);
- DEBUG(level,("\n"));
- }
-}
-
/*******************************************************************
do IO on a uint32.
********************************************************************/
-BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned flags)
+BOOL io_uint32(char *name, io_struct *ps, int depth, uint32 *data32, unsigned flags)
{
char *q;
if (!(flags & PARSE_SCALARS)) return True;
- if (!prs_align(ps, 4)) return False;
+ if (!io_align(ps, 4)) return False;
- q = prs_mem_get(ps, sizeof(uint32));
+ q = io_mem_get(ps, sizeof(uint32));
if (q == NULL) return False;
DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data32)
@@ -307,18 +232,18 @@ BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned f
/*******************************************************************
do IO on a uint16.
********************************************************************/
-BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned flags)
+BOOL io_uint16(char *name, io_struct *ps, int depth, uint16 *data16, unsigned flags)
{
char *q;
if (!(flags & PARSE_SCALARS)) return True;
- if (!prs_align(ps, 2)) return False;
+ if (!io_align(ps, 2)) return False;
- q = prs_mem_get(ps, sizeof(uint16));
+ q = io_mem_get(ps, sizeof(uint16));
if (q == NULL) return False;
- DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data16)
+ DBG_RW_SVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data16)
ps->data_offset += sizeof(uint16);
return True;
@@ -327,13 +252,13 @@ BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned f
/*******************************************************************
do IO on a uint8.
********************************************************************/
-BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flags)
+BOOL io_uint8(char *name, io_struct *ps, int depth, uint8 *data8, unsigned flags)
{
char *q;
if (!(flags & PARSE_SCALARS)) return True;
- q = prs_mem_get(ps, sizeof(uint8));
+ q = io_mem_get(ps, sizeof(uint8));
if (q == NULL) return False;
DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data8)
@@ -345,7 +270,7 @@ BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flag
/*******************************************************************
do IO on a pointer
********************************************************************/
-BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags)
+BOOL io_pointer(char *desc, io_struct *ps, int depth, void **p, unsigned flags)
{
uint32 v;
@@ -360,7 +285,7 @@ BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags)
/*******************************************************************
Stream a null-terminated string.
********************************************************************/
-BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags)
+BOOL io_SMBSTR(char *name, io_struct *ps, int depth, char **str, unsigned flags)
{
char *q;
uint8 *start;
@@ -371,7 +296,7 @@ BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags
if (!(flags & PARSE_SCALARS)) return True;
if (UNMARSHALLING(ps)) {
- *str = prs_mem_get(ps, 0);
+ *str = io_mem_get(ps, 0);
if (*str == NULL)
return False;
len = strlen(*str);
@@ -379,25 +304,17 @@ BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags
}
else
{
- len = strlen(*str);
+ len = strlen(*str)+1;
start = (uint8*)q;
for(i = 0; i < len; i++) {
- q = prs_mem_get(ps, 1);
+ q = io_mem_get(ps, 1);
if (q == NULL)
return False;
RW_CVAL(ps->io, q, (*str)[i],0);
- if ((*str)[i] == 0)
- break;
ps->data_offset++;
}
-
- /* The terminating null. */
- (*str)[i] = '\0';
- RW_CVAL(ps->io, q, (*str)[i], 0);
-
- ps->data_offset++;
}
DEBUG(5,("%s%04x %s: %s\n", tab_depth(depth),
@@ -408,16 +325,14 @@ BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags
/******************************************************************
do IO on a byte array
********************************************************************/
-BOOL io_uint8s(char *name, prs_struct *ps, int depth, uint8 **data8s, int len, unsigned flags)
+BOOL io_uint8s(char *name, io_struct *ps, int depth, uint8 **data8s, int len, unsigned flags)
{
char *q;
size_t num_bytes = len * sizeof(uint8);
if (!(flags & PARSE_SCALARS)) return True;
- if (!prs_align(ps, 2)) return False;
-
- q = prs_mem_get(ps, num_bytes);
+ q = io_mem_get(ps, num_bytes);
if (q == NULL) return False;
if (MARSHALLING(ps))
@@ -427,26 +342,92 @@ BOOL io_uint8s(char *name, prs_struct *ps, int depth, uint8 **data8s, int len, u
else
{
*data8s = q;
- dump_data(depth+5, q, num_bytes);
+ dump_data(depth+5, *data8s, num_bytes);
}
ps->data_offset += num_bytes;
return True;
}
+/******************************************************************
+ do IO on a fixed-size byte array
+ ********************************************************************/
+BOOL io_uint8s_fixed(char *name, io_struct *ps, int depth, uint8 *data8s, int len, unsigned flags)
+{
+ char *q;
+ size_t num_bytes = len * sizeof(uint8);
+
+ if (!(flags & PARSE_SCALARS)) return True;
+
+ q = io_mem_get(ps, num_bytes);
+ if (q == NULL) return False;
+
+ DBG_RW_PCVAL(True, name, depth, ps->data_offset, ps->io, q, data8s, len)
+ ps->data_offset += num_bytes;
+
+ return True;
+}
+
+
+/******************************************************************
+ do IO on an io (eh?? :)
+ ********************************************************************/
+BOOL io_io_struct(char *name, io_struct *ps, int depth, io_struct *io, unsigned flags)
+{
+ char *q;
+ uint16 len;
+
+ if (!(flags & PARSE_SCALARS)) return True;
+ q = io_mem_get(ps, sizeof(uint16));
+ if (q == NULL) return False;
+
+ /* length first */
+ if (MARSHALLING(ps))
+ {
+ len = io->data_offset;
+ }
+ if (!io_uint16("len", ps, depth+1, &len, flags))
+ {
+ return False;
+ }
+ if (UNMARSHALLING(ps))
+ {
+ if (!io_init(io, len, UNMARSHALL))
+ {
+ return False;
+ }
+ }
+
+ /* now data */
+ q = io_mem_get(ps, len * sizeof(uint8));
+ if (q == NULL) return False;
+
+ if (MARSHALLING(ps))
+ {
+ DBG_RW_PCVAL(False, name, depth+1, ps->data_offset, ps->io, q, io->data_p, len)
+ }
+ else
+ {
+ io->data_p = q;
+ dump_data(depth+5, q, len);
+ }
+ ps->data_offset += len;
+
+ return True;
+}
/******************************************************************
do IO on a unicode array
********************************************************************/
-BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len, unsigned flags)
+BOOL io_wstring(char *name, io_struct *ps, int depth, uint16 *data16s, int len, unsigned flags)
{
char *q;
if (!(flags & PARSE_SCALARS)) return True;
- if (!prs_align(ps, 2)) return False;
+ if (!io_align(ps, 2)) return False;
- q = prs_mem_get(ps, len * sizeof(uint16));
+ q = io_mem_get(ps, len * sizeof(uint16));
if (q == NULL) return False;
DBG_RW_PSVAL(False, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, data16s, len)
@@ -459,7 +440,19 @@ BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len,
/******************************************************************
allocate some memory for a parse structure
********************************************************************/
-BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size)
+void io_free(io_struct *ps)
+{
+ if (ps->is_dynamic && ps->data_p)
+ {
+ free(ps->data_p);
+ ps->data_p = NULL;
+ }
+}
+
+/******************************************************************
+allocate some memory for a parse structure
+ ********************************************************************/
+BOOL io_alloc(char *name, io_struct *ps, void **ptr, unsigned size)
{
(*ptr) = (void *)malloc(size);
if (*ptr) return True;
@@ -469,7 +462,7 @@ BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size)
/******************************************************************
realloc some memory for a parse structure
********************************************************************/
-BOOL io_realloc(char *name, prs_struct *ps, void **ptr, unsigned size)
+BOOL io_realloc(char *name, io_struct *ps, void **ptr, unsigned size)
{
(*ptr) = (void *)Realloc(*ptr, size);
if (*ptr) return True;
diff --git a/source3/aparser/parser.h b/source3/aparser/parser.h
index a06242debb..e5e5a757cb 100644
--- a/source3/aparser/parser.h
+++ b/source3/aparser/parser.h
@@ -27,7 +27,7 @@ typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned short wchar;
typedef unsigned uint32;
-typedef char *string;
+typedef char *SMBSTR;
#ifndef _PSTRING
@@ -50,7 +50,7 @@ typedef char fstring[FSTRING_LEN];
#define MAX_STRINGLEN 256
#define MAX_BUFFERLEN 512
-typedef struct _prs_struct
+typedef struct _io_struct
{
BOOL io; /* parsing in or out of data stream */
/*
@@ -61,26 +61,32 @@ typedef struct _prs_struct
BOOL is_dynamic; /* Do we own this memory or not ? */
uint32 data_offset; /* Current working offset into data. */
uint32 buffer_size; /* Current size of the buffer. */
- uint32 grow_size; /* size requested via prs_grow() calls */
+ uint32 grow_size; /* size requested via io_grow() calls */
char *data_p; /* The buffer itself. */
-} prs_struct;
+} io_struct;
-char *prs_mem_get(prs_struct *ps, uint32 extra_size);
-BOOL prs_init(prs_struct *ps, uint32 size, BOOL io);
-void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name);
-BOOL prs_align(prs_struct *ps, int align);
-BOOL io_align4(prs_struct *ps, int align);
-BOOL io_align2(prs_struct *ps, int align);
+char *io_mem_get(io_struct *ps, uint32 extra_size);
+BOOL io_init(io_struct *ps, uint32 size, BOOL io);
+void io_debug(io_struct *ps, int depth, char *desc, char *fn_name);
+BOOL io_align(io_struct *ps, int align);
+BOOL io_align4(io_struct *ps, int align);
+BOOL io_align2(io_struct *ps, int align);
+void print_asc(int level, unsigned char *buf,int len);
+BOOL io_read(io_struct *ps, int fd, size_t len, int timeout);
+void dump_data(int level,char *buf1,int len);
+BOOL io_alloc(char *name, io_struct *ps, void **ptr, unsigned size);
+BOOL io_uint32(char *name, io_struct *ps, int depth, uint32 *data32, unsigned flags);
+BOOL io_uint16(char *name, io_struct *ps, int depth, uint16 *data16, unsigned flags);
+BOOL io_uint8(char *name, io_struct *ps, int depth, uint8 *data8, unsigned flags);
+BOOL io_pointer(char *desc, io_struct *ps, int depth, void **p, unsigned flags);
+BOOL io_SMBSTR(char *name, io_struct *ps, int depth, char **str, unsigned flags);
+BOOL io_io_struct(char *name, io_struct *ps, int depth, io_struct *io, unsigned flags);
+BOOL io_wstring(char *name, io_struct *ps, int depth, uint16 *data16s, int len, unsigned flags);
+BOOL io_uint8s_fixed(char *name, io_struct *ps, int depth, uint8 *data8s, int len, unsigned flags);
+BOOL io_uint8s(char *name, io_struct *ps, int depth, uint8 **data8s, int len, unsigned flags);
+
+char *tab_depth(int depth);
+void *Realloc(void *p,size_t size);
void print_asc(int level, unsigned char *buf,int len);
-BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout);
void dump_data(int level,char *buf1,int len);
-BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size);
-BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned flags);
-BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned flags);
-BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flags);
-BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags);
-BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags);
-BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len, unsigned flags);
-BOOL io_uint8s(char *name, prs_struct *ps, int depth, uint8 **data8s, int len, unsigned flags);
-
diff --git a/source3/aparser/parsetree.awk b/source3/aparser/parsetree.awk
index 832cd5f2e8..bb1160b954 100644
--- a/source3/aparser/parsetree.awk
+++ b/source3/aparser/parsetree.awk
@@ -51,6 +51,11 @@ function add_element(type, elem, case,
}
elem_num=num_elements;
+ if (substr(elem, 1, 1) == ".") {
+ elem=substr(elem, 2);
+ elements[elem_num, "nowire"]=1;
+ }
+
if (substr(elem, 1, 1) == "*") {
elem=substr(elem, 2);
elements[elem_num, "ptr"]=1;
@@ -185,7 +190,8 @@ function end_function(LOCAL, i)
i--;
}
}
- add_function_param("[out]", "STATUS", "status");
+ if (return_result!="void")
+ add_function_param("[out]", return_result, "status");
end_struct();
}
diff --git a/source3/aparser/templates/fn_end.tpl b/source3/aparser/templates/fn_end.tpl
index df62f6c0ac..2275ec4e33 100644
--- a/source3/aparser/templates/fn_end.tpl
+++ b/source3/aparser/templates/fn_end.tpl
@@ -4,7 +4,9 @@ end:
return True;
fail:
- ZERO_STRUCTP(il);
+ if (UNMARSHALLING(ps)) {
+ ZERO_STRUCTP(il);
+ }
return False;
} /* @FUNCNAME@ */
diff --git a/source3/aparser/templates/fn_start.tpl b/source3/aparser/templates/fn_start.tpl
index 017f894f78..a5d58767a6 100644
--- a/source3/aparser/templates/fn_start.tpl
+++ b/source3/aparser/templates/fn_start.tpl
@@ -1,13 +1,17 @@
/*******************************************************************
parse a @STRUCTNAME@ structure
********************************************************************/
-BOOL @FUNCNAME@(char *desc, prs_struct *ps, int depth,
+BOOL @FUNCNAME@(char *desc, io_struct *ps, int depth,
@STRUCTNAME@ *il, unsigned flags)
{
- prs_debug(ps, depth, desc, "@FUNCNAME@");
+ io_debug(ps, depth, desc, "@FUNCNAME@");
depth++;
if (!(flags & PARSE_SCALARS)) goto buffers;
- ZERO_STRUCTP(il);
+#if 0
+ if (UNMARSHALLING(ps)) {
+ ZERO_STRUCTP(il);
+ }
+#endif
/* parse the scalars */
diff --git a/source3/aparser/templates/harness.tpl b/source3/aparser/templates/harness.tpl
index bd2355d2a2..0a10ccf49f 100644
--- a/source3/aparser/templates/harness.tpl
+++ b/source3/aparser/templates/harness.tpl
@@ -1,5 +1,5 @@
if (strcmp(test,"@TEST@")==0) {
@TEST@ il;
- ret = io_@TEST@("@TEST@", ps, 0, &il, PARSE_SCALARS|PARSE_BUFFERS);
+ ret = io_@TEST@("@TEST@", ps, 0, &il, flags);
}
diff --git a/source3/aparser/templates/harness_start.tpl b/source3/aparser/templates/harness_start.tpl
index e6cf18a163..beba6fc12d 100644
--- a/source3/aparser/templates/harness_start.tpl
+++ b/source3/aparser/templates/harness_start.tpl
@@ -1,8 +1,7 @@
-#include "prs_@MODULE@.h"
#include "prs_@MODULE@.c"
-static BOOL run_test(char *test, prs_struct *ps)
+static BOOL run_test(char *test, io_struct *ps, int flags)
{
BOOL ret;
- \ No newline at end of file
+
diff --git a/source3/aparser/templates/module_start.tpl b/source3/aparser/templates/module_start.tpl
index fef9d296ff..5bcdbf3275 100644
--- a/source3/aparser/templates/module_start.tpl
+++ b/source3/aparser/templates/module_start.tpl
@@ -1,5 +1,6 @@
/* auto-generated structure parsers for @MODULE@
generated by aparser
*/
-
+#include "includes.h"
+#include "prs_@MODULE@.h"
diff --git a/source3/aparser/templates/prs_.align.tpl b/source3/aparser/templates/prs_.align.tpl
index d5b2ceb082..25816a23b3 100644
--- a/source3/aparser/templates/prs_.align.tpl
+++ b/source3/aparser/templates/prs_.align.tpl
@@ -1 +1 @@
- if(!prs_align(ps)) goto fail;
+ if(!io_align(ps)) goto fail;
diff --git a/source3/aparser/templates/prs_array.tpl b/source3/aparser/templates/prs_array.tpl
index 1bf3fa4b04..4bd6a26c99 100644
--- a/source3/aparser/templates/prs_array.tpl
+++ b/source3/aparser/templates/prs_array.tpl
@@ -1,5 +1,5 @@
if ((@FLAGS@ & PARSE_SCALARS) &&
- !io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*il->@ARRAY_LEN@)) goto fail;
+ !io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(il->@ARRAY_LEN@))) goto fail;
{
int i;
for (i=0;i<il->@ARRAY_LEN@;i++) {
diff --git a/source3/aparser/templates/prs_array_remainder.tpl b/source3/aparser/templates/prs_array_remainder.tpl
index 80c5d8b9af..c8b1e2ab5a 100644
--- a/source3/aparser/templates/prs_array_remainder.tpl
+++ b/source3/aparser/templates/prs_array_remainder.tpl
@@ -1,3 +1,4 @@
+ if (UNMARSHALLING(ps))
{
int i;
for (i=0;ps->data_offset < ps->buffer_size;i++) {
@@ -5,3 +6,12 @@
if (!io_@TYPE@("@ELEM@...", ps, depth+1, &il->@ELEM@[i], @FLAGS@)) goto fail;
}
}
+ else
+ {
+ int i = -1;
+ /* HACK ALERT! */
+ do {
+ i++;
+ if (!io_@TYPE@("@ELEM@...", ps, depth+1, &il->@ELEM@[i], @FLAGS@)) goto fail;
+ } while (il->@ELEM@[i].tag2 != 0);
+ }
diff --git a/source3/aparser/templates/prs_uint16.tpl b/source3/aparser/templates/prs_uint16.tpl
index 36b8298fb2..b40d6d4216 100644
--- a/source3/aparser/templates/prs_uint16.tpl
+++ b/source3/aparser/templates/prs_uint16.tpl
@@ -1 +1 @@
- if (!prs_uint16("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail;
+ if (!io_uint16("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail;
diff --git a/source3/aparser/templates/prs_uint32.tpl b/source3/aparser/templates/prs_uint32.tpl
index 2e2fd638e4..eb76715d28 100644
--- a/source3/aparser/templates/prs_uint32.tpl
+++ b/source3/aparser/templates/prs_uint32.tpl
@@ -1 +1 @@
- if (!prs_uint32("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail;
+ if (!io_uint32("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail;
diff --git a/source3/aparser/templates/prs_uint8s.tpl b/source3/aparser/templates/prs_uint8s.tpl
index e5f82670d0..967162213f 100644
--- a/source3/aparser/templates/prs_uint8s.tpl
+++ b/source3/aparser/templates/prs_uint8s.tpl
@@ -1,2 +1,2 @@
- if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*il->@ARRAY_LEN@)) goto fail;
+ if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(il->@ARRAY_LEN@))) goto fail;
if (!io_uint8s("@ELEM@", ps, depth+1, &il->@ELEM@, il->@ARRAY_LEN@, @FLAGS@)) goto fail;
diff --git a/source3/aparser/templates/prs_uint8s_fixed.tpl b/source3/aparser/templates/prs_uint8s_fixed.tpl
index f752fa6c84..26597f419f 100644
--- a/source3/aparser/templates/prs_uint8s_fixed.tpl
+++ b/source3/aparser/templates/prs_uint8s_fixed.tpl
@@ -1,2 +1 @@
- if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*@ARRAY_LEN@)) goto fail;
- if (!io_uint8s("@ELEM@", ps, depth+1, &il->@ELEM@, @ARRAY_LEN@, @FLAGS@)) goto fail;
+ if (!io_uint8s_fixed("@ELEM@", ps, depth+1, il->@ELEM@, @ARRAY_LEN@, @FLAGS@)) goto fail;
diff --git a/source3/aparser/templates/prs_wstring.tpl b/source3/aparser/templates/prs_wstring.tpl
index 022381c2d2..4de46f093c 100644
--- a/source3/aparser/templates/prs_wstring.tpl
+++ b/source3/aparser/templates/prs_wstring.tpl
@@ -1,2 +1,2 @@
- if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*il->@ARRAY_LEN@)) goto fail;
+ if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(il->@ARRAY_LEN@))) goto fail;
if (!io_wstring("@ELEM@", ps, depth+1, il->@ELEM@, il->@ARRAY_LEN@, @FLAGS@)) goto fail;
diff --git a/source3/aparser/templates/prs_wstring_fixed.tpl b/source3/aparser/templates/prs_wstring_fixed.tpl
index bf2539b216..e33f7c3d5d 100644
--- a/source3/aparser/templates/prs_wstring_fixed.tpl
+++ b/source3/aparser/templates/prs_wstring_fixed.tpl
@@ -1,2 +1,2 @@
- if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*@ARRAY_LEN@)) goto fail;
+ if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(@ARRAY_LEN@))) goto fail;
if (!io_wstring("@ELEM@", ps, depth+1, il->@ELEM@, @ARRAY_LEN@, @FLAGS@)) goto fail;
diff --git a/source3/aparser/token.awk b/source3/aparser/token.awk
index 0c4c7f65b1..9920de562b 100644
--- a/source3/aparser/token.awk
+++ b/source3/aparser/token.awk
@@ -53,10 +53,19 @@ function parse_error(msg) {
next;
}
-/^[ \t]*STATUS.*\(/ {
+/^[ \t]*void.*\(/ {
{if (current_struct!="") parse_error("you cannot have nested structures");}
split($0,a,"[ \t;()]*");
start_function(a[2], a[3]);
+ return_result="void";
+ next;
+}
+
+/^[ \t]*STATUS.*\(|^[ \t]*void.*\(/ {
+ {if (current_struct!="") parse_error("you cannot have nested structures");}
+ split($0,a,"[ \t;()]*");
+ start_function(a[2], a[3]);
+ return_result="STATUS";
next;
}
@@ -118,6 +127,7 @@ function parse_error(msg) {
/^[ \t]*\);/ {
end_function();
+ return_result="";
next;
}
diff --git a/source3/aparser/vluke.c b/source3/aparser/vluke.c
index 15608ae01a..87664267d0 100644
--- a/source3/aparser/vluke.c
+++ b/source3/aparser/vluke.c
@@ -1,11 +1,3 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include "parser.h"
#include "test.h"
int main(int argc, char *argv[])
@@ -14,7 +6,7 @@ int main(int argc, char *argv[])
char *fname, *test;
int fd;
struct stat st;
- prs_struct ps;
+ io_struct ps;
if (argc < 3) {
printf("usage: vluke <structure> <file>\n");
@@ -31,13 +23,13 @@ int main(int argc, char *argv[])
}
fstat(fd, &st);
- prs_init(&ps, 0, MARSHALL);
+ io_init(&ps, 0, MARSHALL);
ps.is_dynamic=True;
- prs_read(&ps, fd, st.st_size, 0);
+ io_read(&ps, fd, st.st_size, 0);
ps.data_offset = 0;
ps.buffer_size = ps.grow_size;
ps.io = UNMARSHALL;
- ret = run_test(test, &ps);
+ ret = run_test(test, &ps, PARSE_SCALARS|PARSE_BUFFERS);
printf("\nret=%s\n", ret?"OK":"Bad");
printf("Trailer is %d bytes\n\n", ps.grow_size - ps.data_offset);
if (ps.grow_size - ps.data_offset > 0) {