Skip to content

Commit

Permalink
Domain match * is with lower priority than conditional match
Browse files Browse the repository at this point in the history
`GroupFile` Vs `UDPGroup`/`TCPGroup`:
"conditional wild card match" > `*`
  • Loading branch information
lifenjoiner committed Oct 6, 2024
1 parent 0ccd4e6 commit 0c0b0c1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions stringchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ BOOL StringChunk_Match_OnlyWildCard_GetOne(StringChunk *dl,
)
{
Array Matches;
Array MatchesAny;
Array *pm;
Array *wl;

EntryForString *FoundEntry;
Expand All @@ -256,6 +258,12 @@ BOOL StringChunk_Match_OnlyWildCard_GetOne(StringChunk *dl,
return FALSE;
}

if( Array_Init(&MatchesAny, sizeof(void *), 4, FALSE, NULL) != 0 )
{
Array_Free(&Matches);
return FALSE;
}

wl = &(dl->List_W_Pos);

for( loop = 0; loop != Array_GetUsed(wl); ++loop )
Expand All @@ -270,18 +278,24 @@ BOOL StringChunk_Match_OnlyWildCard_GetOne(StringChunk *dl,
{
continue;
}
Array_PushBack(&Matches, &(FoundEntry->Data), NULL);
Array_PushBack(strcmp(FoundString, "*") == 0 ? &MatchesAny : &Matches,
&(FoundEntry->Data),
NULL
);
}
}
}

srand(time(NULL));
if( Array_GetUsed(&Matches) > 0 )
pm = Array_GetUsed(&Matches) > 0 ? &Matches : &MatchesAny;

if( Array_GetUsed(pm) > 0 )
{
*Data = *((void **)Array_GetBySubscript(&Matches, rand() % Array_GetUsed(&Matches)));
srand(time(NULL));
*Data = *((void **)Array_GetBySubscript(pm, rand() % Array_GetUsed(pm)));
} else {
*Data = NULL;
}
Array_Free(&MatchesAny);
Array_Free(&Matches);

return *Data != NULL;
Expand Down

0 comments on commit 0c0b0c1

Please sign in to comment.