summaryrefslogtreecommitdiff
path: root/source3/aparser/parser.awk
diff options
context:
space:
mode:
Diffstat (limited to 'source3/aparser/parser.awk')
-rw-r--r--source3/aparser/parser.awk207
1 files changed, 33 insertions, 174 deletions
diff --git a/source3/aparser/parser.awk b/source3/aparser/parser.awk
index a32d4b727b..dde43b91a2 100644
--- a/source3/aparser/parser.awk
+++ b/source3/aparser/parser.awk
@@ -1,9 +1,7 @@
-function add_elem(type, elem)
-{
- types[num_elems] = type;
- elems[num_elems] = elem;
- num_elems++;
-}
+@include basic.awk
+@include struct.awk
+@include union.awk
+@include func.awk
function produce_preamble() {
printf("#define TEST_STRUCT %s\n", struct_name);
@@ -12,189 +10,50 @@ function produce_preamble() {
printf("\n\n");
}
-function produce_header() {
- printf("\n/* %s structure */\n", struct_name);
- printf("typedef struct {\n");
- for (i=0;i<num_elems;i++) {
- if (types[i] == "UNISTR2") {
- printf("\tuint32 %s_ptr;\n", elems[i]);
- } else if (types[i] == "BUFFER5") {
- printf("\tuint32 %s_len;\n", elems[i]);
- printf("\tuint32 %s_ptr;\n", elems[i]);
- } else {
- printf("\t%s\t%s;\n", types[i], elems[i]);
- }
- }
- for (i=0;i<num_elems;i++) {
- if (types[i] == "UNISTR2" ||
- types[i] == "BUFFER5") {
- printf("\t%s\t%s;\n", types[i], elems[i]);
- }
- }
- printf("} %s;\n\n", struct_name);
-}
-
-
-function parse_structs() {
- printf("\n\t/* parse the structures in the packet */\n\n");
- for (i=0;i<num_elems;i++) {
- if (types[i] == "UNISTR2") {
- io_unistr2(elems[i]);
- }
- if (types[i] == "BUFFER5") {
- io_buffer5(elems[i]);
- }
- }
-}
-
-function io_unistr2(elem) {
- printf("\
- if(!smb_io_unistr2(\"%s\", &il->%s, il->%s_ptr, ps, depth))\n\
- return False;\n\
- if(!prs_align(ps))\n\
- return False;\n\
-", elem, elem, elem);
-}
-
-function io_buffer5(elem) {
- printf("\
- if (il->%s_ptr) {\n\
- if(!smb_io_buffer5(\"%s\", &il->%s, ps, depth))\n\
- return False;\n\
- if(!prs_align(ps))\n\
- return False;\n\
- }\n\
-", elem, elem, elem);
-}
-
-function start_struct(name) {
- num_elems=0;
- struct_name=toupper(module"_"name);
- func_name=tolower(module"_io_"name);
-}
-
-function parse_elems() {
- printf("\n\t/* parse the main elements the packet */\n\n");
- for (i=0;i<num_elems;i++) {
- if (types[i] == "uint32") {
- uint32_parser(elems[i]);
- }
- if (types[i] == "UINT64_S") {
- uint64_parser(elems[i]);
- }
- if (types[i] == "UNISTR2") {
- unistr2_parser(elems[i]);
- }
- if (types[i] == "BUFFER5") {
- buffer5_parser(elems[i]);
- }
- if (types[i] == "NTTIME") {
- nttime_parser(elems[i]);
- }
- }
-}
-
-function end_struct() {
- produce_preamble();
- produce_header();
- func_header(func_name, struct_name);
- parse_elems();
- parse_structs();
- func_footer();
-}
-
-
-function func_footer() {
- printf("\n\
-\n\
- return True;\n\
-}\n");
-}
-
-function func_header(func_name, struct_name)
-{
- printf("\
-/*******************************************************************\n\
-parse a %s structure\n\
-********************************************************************/ \n\
-BOOL %s(char *desc, %s **q_u, \n\
- prs_struct *ps, int depth)\n\
-{ \n\
- %s *il;\n\
- \n\
- prs_debug(ps, depth, desc, \"%s\");\n\
- depth++;\n\
- \n\
- /* reading */\n\
- if (UNMARSHALLING(ps)) {\n\
- il=(%s *)malloc(sizeof(%s));\n\
- if(il == NULL)\n\
- return False;\n\
- ZERO_STRUCTP(il);\n\
- *q_u=il;\n\
- }\n\
- else {\n\
- il=*q_u;\n\
- }\n\
- \n\
- if(!prs_align(ps))\n\
- return False;\n\
-\n\
-", struct_name, func_name, struct_name, struct_name, func_name, struct_name, struct_name);
-}
-
-function uint32_parser(elem) {
- printf("\
- if(!prs_uint32(\"%s\", ps, depth, &il->%s))\n\
- return False;\n\
-", elem, elem);
+/^module/ {
+ module=$2;
+ next;
}
-function unistr2_parser(elem) {
- printf("\
- if(!prs_uint32(\"%s_ptr\", ps, depth, &il->%s_ptr))\n\
- return False;\n\
-", elem, elem);
+/^test/ {
+ test=$2;
+ next;
}
-function buffer5_parser(elem) {
- printf("\
- if(!prs_uint32(\"%s_len\", ps, depth, &il->%s_len))\n\
- return False;\n\
- if(!prs_uint32(\"%s_ptr\", ps, depth, &il->%s_ptr))\n\
- return False;\n\
-", elem, elem, elem, elem);
+/^struct/ {
+ start_struct($2);
+ next;
}
-function nttime_parser(elem) {
- printf("\
- if(!smb_io_time(\"%s\", &il->%s, ps, depth))\n\
- return False;\n\
-", elem, elem);
+/^[ \t]*union/ {
+ start_union($2, $3);
+ next;
}
-function uint64_parser(elem) {
- printf("\
- if(!prs_uint64(\"%s\", ps, depth, &il->%s))\n\
- return False;\n\
-", elem, elem);
+/^[ \t]*case/ {
+ split($0,a,"[ \t;]*");
+ parse_case(a[3],a[4],a[5]);
+ next;
}
-/^module/ {
- module=$2;
+/^\};/ {
+ end_struct();
+ next;
}
-/^struct/ {
- start_struct($2);
+/^[ \t]*\}/ {
+ end_union();
+ next;
}
-
-/^\}/ {
- end_struct();
+/^[ \t]*REF/ {
+ split($0,a,"[ \t;]*");
+ add_elem(a[3],a[4], 1);
+ next;
}
-/uint32|UINT64_S|UNISTR2|BUFFER5|NTTIME/ {
- split($0,a,"[ ;]*");
- add_elem(a[2], a[3]);
+/.*;/ {
+ split($0,a,"[ \t;]*");
+ add_elem(a[2], a[3], 0);
}