2525#include <fluent-bit/flb_mp.h>
2626#include <fluent-bit/flb_conditionals.h>
2727
28- /* Function to get the record variant based on context */
29- static inline struct cfl_variant * get_record_variant (struct flb_mp_chunk_record * record ,
30- enum record_context_type context_type )
28+ static struct cfl_variant * default_get_record_variant (struct flb_condition_rule * rule ,
29+ void * ctx )
3130{
32- if (!record ) {
31+ struct flb_mp_chunk_record * record = (struct flb_mp_chunk_record * ) ctx ;
32+
33+ if (!record || !rule ) {
3334 return NULL ;
3435 }
3536
36- switch (context_type ) {
37+ switch (rule -> context ) {
3738 case RECORD_CONTEXT_METADATA :
3839 if (record -> cobj_metadata ) {
3940 return record -> cobj_metadata -> variant ;
@@ -45,6 +46,9 @@ static inline struct cfl_variant *get_record_variant(struct flb_mp_chunk_record
4546 return record -> cobj_record -> variant ;
4647 }
4748 break ;
49+
50+ default :
51+ break ;
4852 }
4953
5054 return NULL ;
@@ -356,8 +360,9 @@ static int evaluate_rule(struct flb_condition_rule *rule,
356360 return result ;
357361}
358362
359- int flb_condition_evaluate (struct flb_condition * cond ,
360- struct flb_mp_chunk_record * record )
363+ int flb_condition_evaluate_ex (struct flb_condition * cond ,
364+ void * ctx ,
365+ flb_condition_get_variant_fn get_variant )
361366{
362367 struct mk_list * head ;
363368 struct flb_condition_rule * rule ;
@@ -366,11 +371,16 @@ int flb_condition_evaluate(struct flb_condition *cond,
366371 int any_rule_evaluated = FLB_FALSE ;
367372 int any_rule_matched = FLB_FALSE ;
368373
369- if (!cond || ! record ) {
370- flb_trace ("[condition] NULL condition or record , returning TRUE" );
374+ if (!cond ) {
375+ flb_trace ("[condition] NULL condition, returning TRUE" );
371376 return FLB_TRUE ;
372377 }
373378
379+ if (!get_variant ) {
380+ flb_trace ("[condition] missing variant provider, returning FALSE" );
381+ return FLB_FALSE ;
382+ }
383+
374384 flb_trace ("[condition] evaluating condition with %d rules" , mk_list_size (& cond -> rules ));
375385
376386 if (mk_list_size (& cond -> rules ) == 0 ) {
@@ -382,8 +392,7 @@ int flb_condition_evaluate(struct flb_condition *cond,
382392 rule = mk_list_entry (head , struct flb_condition_rule , _head );
383393 flb_trace ("[condition] processing rule with op=%d" , rule -> op );
384394
385- /* Get the variant for this rule's context */
386- record_variant = get_record_variant (record , rule -> context );
395+ record_variant = get_variant (rule , ctx );
387396 any_rule_evaluated = FLB_TRUE ;
388397 if (!record_variant ) {
389398 flb_trace ("[condition] no record variant found for context %d" , rule -> context );
@@ -427,3 +436,13 @@ int flb_condition_evaluate(struct flb_condition *cond,
427436 flb_trace ("[condition] final evaluation result: TRUE" );
428437 return FLB_TRUE ;
429438}
439+
440+ int flb_condition_evaluate (struct flb_condition * cond ,
441+ struct flb_mp_chunk_record * record )
442+ {
443+ if (!cond || !record ) {
444+ return FLB_TRUE ;
445+ }
446+
447+ return flb_condition_evaluate_ex (cond , record , default_get_record_variant );
448+ }
0 commit comments