.unwrap_or(-1)
}
+/// Get a transaction by its index for the iterator.
+/// # Safety
+/// When calling this method, you have to ensure that connp is either properly initialized or NULL
+#[no_mangle]
+pub unsafe extern "C" fn htp_connp_tx_index(
+ connp: *mut ConnectionParser, index: usize,
+) -> *mut Transaction {
+ if let Some(tx) = connp.as_mut().unwrap().tx_index(index) {
+ if tx.is_started() {
+ return tx as *mut Transaction;
+ }
+ }
+ std::ptr::null_mut()
+}
+
/// Get a transaction.
///
/// Returns the transaction or NULL on error.
tx.as_ref().map(|tx| tx.flags).unwrap_or(0)
}
+/// Get the transaction's index.
+///
+/// tx: Transaction pointer.
+///
+/// # Safety
+/// When calling this method, you have to ensure that tx is either properly initialized or NULL
+#[no_mangle]
+pub unsafe extern "C" fn htp_tx_index(tx: *const Transaction) -> usize {
+ tx.as_ref().map(|tx| tx.index).unwrap_or(0)
+}
+
/// Get the transaction's request progress.
///
/// tx: Transaction pointer.
self.transactions.get(index)
}
+ /// Get a specific transaction by its index
+ pub(crate) fn tx_index(&mut self, index: usize) -> Option<&mut Transaction> {
+ self.transactions.get_index(index)
+ }
+
/// Get a specific transaction
pub(crate) fn tx_mut(&mut self, index: usize) -> Option<&mut Transaction> {
self.transactions.get_mut(index)
return NULL;
}
+static AppLayerGetTxIterTuple HTPGetTxIterator(const uint8_t ipproto, const AppProto alproto,
+ void *alstate, uint64_t min_tx_id, uint64_t max_tx_id, AppLayerGetTxIterState *state)
+{
+ HtpState *http_state = (HtpState *)alstate;
+ uint64_t size = HTPStateGetTxCnt(alstate);
+ AppLayerGetTxIterTuple no_tuple = { NULL, 0, false };
+ if (http_state) {
+ while (state->un.u64 < size) {
+ htp_tx_t *tx = htp_connp_tx_index(http_state->connp, state->un.u64);
+ if (!tx) {
+ return no_tuple;
+ }
+ uint64_t tx_id = htp_tx_index(tx);
+ if (tx_id < min_tx_id) {
+ state->un.u64++;
+ continue;
+ }
+ AppLayerGetTxIterTuple tuple = {
+ .tx_ptr = tx,
+ .tx_id = tx_id,
+ .has_next = state->un.u64 < size,
+ };
+ return tuple;
+ }
+ }
+ return no_tuple;
+}
+
void *HtpGetTxForH2(void *alstate)
{
// gets last transaction
IPPROTO_TCP, ALPROTO_HTTP1, HTPStateGetAlstateProgress);
AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_HTTP1, HTPStateGetTxCnt);
AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_HTTP1, HTPStateGetTx);
-
+ AppLayerParserRegisterGetTxIterator(IPPROTO_TCP, ALPROTO_HTTP1, HTPGetTxIterator);
AppLayerParserRegisterStateProgressCompletionStatus(
ALPROTO_HTTP1, HTP_REQUEST_PROGRESS_COMPLETE, HTP_RESPONSE_PROGRESS_COMPLETE);
AppLayerParserRegisterGetEventInfo(IPPROTO_TCP, ALPROTO_HTTP1, HTPStateGetEventInfo);