Skip to content

Commit

Permalink
Merge pull request #317 from UlfBj/master
Browse files Browse the repository at this point in the history
Consent tagging support added
  • Loading branch information
adobekan authored Dec 12, 2023
2 parents 90c3d95 + 6e0b995 commit c478a80
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
35 changes: 20 additions & 15 deletions binary/c_parser/cparserlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 21 additions & 11 deletions binary/go_parser/datamodel/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

package datamodel

import "fmt"
import (
"fmt"
"strings"
)

type NodeTypes_t uint8

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
7 changes: 4 additions & 3 deletions binary/go_parser/parserlib/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c478a80

Please sign in to comment.