2021-10-01 16:52:38 +03:00
package eventcreator
import (
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
)
2021-10-07 20:54:12 +03:00
// CreateEvent wraps the outputEvent with the result of the operators defined on the request
2021-10-01 16:52:38 +03:00
func CreateEvent ( request protocols . Request , outputEvent output . InternalEvent ) * output . InternalWrappedEvent {
return CreateEventWithAdditionalOptions ( request , outputEvent , func ( internalWrappedEvent * output . InternalWrappedEvent ) { } )
}
2021-10-07 20:54:12 +03:00
// CreateEventWithAdditionalOptions wraps the outputEvent with the result of the operators defined on the request and enables extending the resulting event with additional attributes or values.
2021-10-01 16:52:38 +03:00
func CreateEventWithAdditionalOptions ( request protocols . Request , outputEvent output . InternalEvent , addAdditionalOptions func ( internalWrappedEvent * output . InternalWrappedEvent ) ) * output . InternalWrappedEvent {
event := & output . InternalWrappedEvent { InternalEvent : outputEvent }
for _ , compiledOperator := range request . GetCompiledOperators ( ) {
if compiledOperator != nil {
result , ok := compiledOperator . Execute ( outputEvent , request . Match , request . Extract )
if ok && result != nil {
event . OperatorsResult = result
addAdditionalOptions ( event )
2021-10-06 21:53:03 +03:00
event . Results = append ( event . Results , request . MakeResultEvent ( event ) ... )
2021-10-01 16:52:38 +03:00
}
}
}
return event
}