diff --git a/binary/c_parser/cparserlib.c b/binary/c_parser/cparserlib.c index dc26e60a..17f9f73a 100644 --- a/binary/c_parser/cparserlib.c +++ b/binary/c_parser/cparserlib.c @@ -50,6 +50,8 @@ typedef struct SearchContext_t { FILE* listFp; } SearchContext_t; +uint8_t validationMatrix[4][4] = {{1,2,11,12}, {2,2,12,12}, {11,12,11,12}, {12,12,12,12}}; + void initReadMetadata() { readTreeMetadata.currentDepth = 0; readTreeMetadata.maxTreeDepth = 0; @@ -107,23 +109,27 @@ char* nodeTypeToString(nodeTypes_t type) { } uint8_t validateToUint8(char* validate) { - if (strcmp(validate, "write-only") == 0) { - return 1; + uint8_t validation = 0; + if (strstr(validate, "write-only") != NULL) { + validation = 1; + } else if (strstr(validate, "read-write") != NULL) { + validation = 2; } - if (strcmp(validate, "read-write") == 0) { - return 2; + if (strstr(validate, "consent") != NULL) { + validation += 10; } - return 0; + return validation; } -char* validateToString(uint8_t validate) { - if (validate == 1) { - return "write-only"; +void validateToString(uint8_t validate, char *validation) { + if (validate%10 == 1) { + strcpy(validation, "write-only"); + } else if (validate%10 == 2) { + strcpy(validation, "read-write"); } - if (validate == 2) { - return "read-write"; + if (validate/10 == 1) { + strcat(validation, "+consent"); } - return ""; } void pushPathSegment(char* name, SearchContext_t* context) { @@ -213,9 +219,7 @@ int saveMatchingNode(long thisNode, SearchContext_t* context, bool* done) { if (strcmp(getPathSegment(0, context), "*") == 0) { context->speculationIndex++; } - if (VSSgetValidation(thisNode) > context->maxValidation) { - context->maxValidation = VSSgetValidation(thisNode); // TODO handle speculative setting - } + context->maxValidation = validationMatrix[VSSgetValidation(thisNode)][context->maxValidation]; if (VSSgetType(thisNode) != BRANCH && VSSgetType(thisNode) != STRUCT || context->leafNodesOnly == false) { if ( isGetLeafNodeList == false && isGetUuidList == false) { strcpy(context->searchData[context->numOfMatches].responsePaths, context->matchPath); @@ -487,7 +491,8 @@ void writeNode(struct node_t* node) { fwrite(node->defaultAllowed, sizeof(char)*node->defaultLen, 1, treeFp); } - char* validate = validateToString(node->validate); + char validate[10+1+7+1]; // access control + consent data + validateToString(node->validate, (char*)&validate); int validateLen = strlen(validate); fwrite(&validateLen, sizeof(uint8_t), 1, treeFp); if (validateLen > 0) { diff --git a/binary/go_parser/datamodel/datamodel.go b/binary/go_parser/datamodel/datamodel.go index 36de24d3..a7e9f006 100644 --- a/binary/go_parser/datamodel/datamodel.go +++ b/binary/go_parser/datamodel/datamodel.go @@ -10,7 +10,10 @@ package datamodel -import "fmt" +import ( + "fmt" + "strings" +) type NodeTypes_t uint8 @@ -65,13 +68,16 @@ func StringToNodetype(nodeType string) uint8 { } func ValidateToInt(validate string) uint8 { - if (validate == "write-only") { - return 1 + validation := (uint8)(0) + if strings.Contains(validate, "write-only") { + validation = 1 + } else if strings.Contains(validate, "read-write") { + validation = 2 } - if (validate == "read-write") { - return 2 + if strings.Contains(validate, "consent") { + validation += 10 } - return 0 + return validation } func NodetypeToString(nodeType NodeTypes_t) string { @@ -99,11 +105,15 @@ func NodetypeToString(nodeType NodeTypes_t) string { func ValidateToString(validate uint8) string { - if (validate == 1) { - return "write-only" + var validation string + if (validate%10 == 1) { + validation = "write-only" } - if (validate == 2) { - return "read-write" + if (validate%10 == 2) { + validation = "read-write" } - return "" + if (validate/10 == 1) { + validation = "+consent" + } + return validation } diff --git a/binary/go_parser/parserlib/parser.go b/binary/go_parser/parserlib/parser.go index f36a1d8d..4a282ea1 100644 --- a/binary/go_parser/parserlib/parser.go +++ b/binary/go_parser/parserlib/parser.go @@ -53,6 +53,9 @@ type SearchContext_t struct { ListFp *os.File } +var validationMatrix [4][4]int = [4][4]int{{1,2,11,12}, {2,2,12,12}, {11,12,11,12}, {12,12,12,12}} + + func initReadMetadata() { readTreeMetadata.CurrentDepth = 0 readTreeMetadata.MaxTreeDepth = 0 @@ -176,9 +179,7 @@ func saveMatchingNode(thisNode *def.Node_t, context *SearchContext_t, done *bool if (getPathSegment(0, context) == "*") { context.SpeculationIndex++ } - if (VSSgetValidation(thisNode) > context.MaxValidation) { - context.MaxValidation = VSSgetValidation(thisNode) // TODO handle speculative setting? - } + context.MaxValidation = validationMatrix[VSSgetValidation(thisNode)][context.MaxValidation] if (VSSgetType(thisNode) != def.BRANCH && VSSgetType(thisNode) != def.STRUCT || context.LeafNodesOnly == false) { if ( isGetLeafNodeList == false && isGetUuidList == false) { context.SearchData[context.NumOfMatches].NodePath = context.MatchPath