@@ -1200,7 +1200,8 @@ static bool _cache_methods(JNIEnv *env)
12001200 "(Lcom/datadog/ddwaf/Waf$Result;"
12011201 "Ljava/lang/String;"
12021202 "Ljava/util/Map;"
1203- "Ljava/util/Map;)V" ,
1203+ "Ljava/util/Map;"
1204+ "ZJ)V" ,
12041205 JMETHOD_CONSTRUCTOR )) {
12051206 goto error ;
12061207 }
@@ -2138,7 +2139,24 @@ static jobject _create_result_checked(JNIEnv *env, DDWAF_RET_CODE code,
21382139 const ddwaf_object * ret )
21392140{
21402141 if (code == DDWAF_OK && !_has_derivative (ret )) {
2141- return _result_with_data_ok_null ;
2142+ // Get keep and duration from the ddwaf_object structure for the OK case
2143+ const ddwaf_object * keep_obj = ddwaf_object_find (ret , "keep" , 4 );
2144+ jboolean keep = JNI_FALSE ;
2145+ if (keep_obj != NULL && keep_obj -> type == DDWAF_OBJ_BOOL ) {
2146+ keep = (jboolean ) ddwaf_object_get_bool (keep_obj );
2147+ }
2148+
2149+ const ddwaf_object * duration_obj =
2150+ ddwaf_object_find (ret , "duration" , 8 );
2151+ jlong duration = 0 ;
2152+ if (duration_obj != NULL && duration_obj -> type == DDWAF_OBJ_UNSIGNED ) {
2153+ duration = (jlong ) ddwaf_object_get_unsigned (duration_obj );
2154+ }
2155+
2156+ // Create a new instance with the new constructor signature
2157+ return java_meth_call (env , & result_with_data_init , NULL , _action_ok ,
2158+ NULL , _result_with_data_empty_map ,
2159+ _result_with_data_empty_map , keep , duration );
21422160 }
21432161
21442162 // Get actions from the new ddwaf_object structure
@@ -2179,20 +2197,33 @@ static jobject _create_result_checked(JNIEnv *env, DDWAF_RET_CODE code,
21792197 // Get attributes (formerly derivatives) from the new ddwaf_object structure
21802198 const ddwaf_object * attributes_obj =
21812199 ddwaf_object_find (ret , "attributes" , 10 );
2182- jobject derivatives = NULL ;
2200+ jobject attributes = NULL ;
21832201 if (attributes_obj != NULL && attributes_obj -> type == DDWAF_OBJ_MAP &&
21842202 ddwaf_object_size (attributes_obj ) > 0 ) {
2185- derivatives = output_convert_derivatives_checked (env , attributes_obj );
2186- if (!derivatives ) {
2187- java_wrap_exc ("%s" , "Failed encoding inferred derivatives " );
2203+ attributes = output_convert_attributes_checked (env , attributes_obj );
2204+ if (!attributes ) {
2205+ java_wrap_exc ("%s" , "Failed encoding inferred attributes " );
21882206 goto err ;
21892207 }
21902208 }
21912209
2210+ // Get keep and duration from the ddwaf_object structure
2211+ const ddwaf_object * keep_obj = ddwaf_object_find (ret , "keep" , 4 );
2212+ jboolean keep = JNI_FALSE ;
2213+ if (keep_obj != NULL && keep_obj -> type == DDWAF_OBJ_BOOL ) {
2214+ keep = (jboolean ) ddwaf_object_get_bool (keep_obj );
2215+ }
2216+
2217+ const ddwaf_object * duration_obj = ddwaf_object_find (ret , "duration" , 8 );
2218+ jlong duration = 0 ;
2219+ if (duration_obj != NULL && duration_obj -> type == DDWAF_OBJ_UNSIGNED ) {
2220+ duration = (jlong ) ddwaf_object_get_unsigned (duration_obj );
2221+ }
2222+
21922223 jobject result =
21932224 java_meth_call (env , & result_with_data_init , NULL ,
21942225 code == DDWAF_OK ? _action_ok : _action_match ,
2195- data_obj , actions_jmap , derivatives );
2226+ data_obj , actions_jmap , attributes , keep , duration );
21962227 if (del_actions_jmap ) {
21972228 JNI (DeleteLocalRef , actions_jmap );
21982229 }
0 commit comments