detect-parse: add new func to get last sigmatch

Add SigMatchGetLastSM which simply returns the very last SM added
to the signature.

Minor cleanups.
pull/2310/head
Victor Julien 9 years ago
parent 3ab405dc50
commit c4dcb20522

@ -411,7 +411,7 @@ void SigMatchRemoveSMFromList(Signature *s, SigMatch *sm, int sm_list)
*
* \retval match Pointer to the last SigMatch instance of type 'type'.
*/
static inline SigMatch *SigMatchGetLastSM(SigMatch *sm, uint8_t type)
static SigMatch *SigMatchGetLastSMByType(SigMatch *sm, uint8_t type)
{
while (sm != NULL) {
if (sm->type == type) {
@ -424,11 +424,12 @@ static inline SigMatch *SigMatchGetLastSM(SigMatch *sm, uint8_t type)
}
/**
* \brief Returns the sm with the largest index (added latest) from all the lists.
* \brief Returns the sm with the largest index (added latest) from the lists
* passed to us.
*
* \retval Pointer to Last sm.
*/
SigMatch *SigMatchGetLastSMFromLists(Signature *s, int args, ...)
SigMatch *SigMatchGetLastSMFromLists(const Signature *s, int args, ...)
{
if (args == 0 || args % 2 != 0) {
SCLogError(SC_ERR_INVALID_ARGUMENTS, "You need to send an even no of args "
@ -449,11 +450,11 @@ SigMatch *SigMatchGetLastSMFromLists(Signature *s, int args, ...)
for (i = 0; i < args; i += 2) {
int sm_type = va_arg(ap, int);
SigMatch *sm_list = va_arg(ap, SigMatch *);
sm_new = SigMatchGetLastSM(sm_list, sm_type);
sm_new = SigMatchGetLastSMByType(sm_list, sm_type);
if (sm_new == NULL)
continue;
continue;
if (sm_last == NULL || sm_new->idx > sm_last->idx)
sm_last = sm_new;
sm_last = sm_new;
}
va_end(ap);
@ -461,6 +462,28 @@ SigMatch *SigMatchGetLastSMFromLists(Signature *s, int args, ...)
return sm_last;
}
/**
* \brief Returns the sm with the largest index (added latest) from this sig
*
* \retval Pointer to Last sm.
*/
SigMatch *SigMatchGetLastSM(const Signature *s)
{
SigMatch *sm_last = NULL;
SigMatch *sm_new;
int i;
for (i = 0; i < DETECT_SM_LIST_MAX; i ++) {
sm_new = s->sm_lists_tail[i];
if (sm_new == NULL)
continue;
if (sm_last == NULL || sm_new->idx > sm_last->idx)
sm_last = sm_new;
}
return sm_last;
}
void SigMatchTransferSigMatchAcrossLists(SigMatch *sm,
SigMatch **src_sm_list, SigMatch **src_sm_list_tail,
SigMatch **dst_sm_list, SigMatch **dst_sm_list_tail)

@ -45,7 +45,8 @@ Signature *SigAlloc(void);
void SigFree(Signature *s);
Signature *SigInit(DetectEngineCtx *,char *sigstr);
Signature *SigInitReal(DetectEngineCtx *, char *);
SigMatch *SigMatchGetLastSMFromLists(Signature *, int, ...);
SigMatch *SigMatchGetLastSMFromLists(const Signature *, int, ...);
SigMatch *SigMatchGetLastSM(const Signature *);
void SigMatchTransferSigMatchAcrossLists(SigMatch *sm,
SigMatch **, SigMatch **s,
SigMatch **, SigMatch **);

Loading…
Cancel
Save