flowvars: update funcs to accept u16 id

All id's are u16, but flowvar functions would only accept u8.

Minor cleanups.
pull/346/head
Victor Julien 12 years ago
parent ffffe6c10e
commit 4c2e6a8402

@ -47,7 +47,7 @@ void FlowVarUpdateInt(FlowVar *fv, uint32_t value) {
/* get the flowvar with name 'name' from the flow
*
* name is a normal string*/
FlowVar *FlowVarGet(Flow *f, uint8_t idx) {
FlowVar *FlowVarGet(Flow *f, uint16_t idx) {
GenericVar *gv = f->flowvar;
for ( ; gv != NULL; gv = gv->next) {
@ -59,9 +59,7 @@ FlowVar *FlowVarGet(Flow *f, uint8_t idx) {
}
/* add a flowvar to the flow, or update it */
void FlowVarAddStr(Flow *f, uint8_t idx, uint8_t *value, uint16_t size) {
//printf("Adding flow var \"%s\" with value(%" PRId32 ") \"%s\"\n", name, size, value);
void FlowVarAddStr(Flow *f, uint16_t idx, uint8_t *value, uint16_t size) {
FLOWLOCK_WRLOCK(f);
FlowVar *fv = FlowVarGet(f, idx);
@ -87,9 +85,7 @@ out:
}
/* add a flowvar to the flow, or update it */
void FlowVarAddInt(Flow *f, uint8_t idx, uint32_t value) {
//printf("Adding flow var \"%s\" with value(%" PRId32 ") \"%s\"\n", name, size, value);
void FlowVarAddInt(Flow *f, uint16_t idx, uint32_t value) {
FLOWLOCK_WRLOCK(f);
FlowVar *fv = FlowVarGet(f, idx);
@ -118,14 +114,14 @@ void FlowVarFree(FlowVar *fv) {
return;
if (fv->datatype == FLOWVAR_TYPE_STR) {
if (fv->data.fv_str.value != NULL)
SCFree(fv->data.fv_str.value);
if (fv->data.fv_str.value != NULL)
SCFree(fv->data.fv_str.value);
}
SCFree(fv);
}
void FlowVarPrint(GenericVar *gv) {
uint16_t i;
uint16_t u;
if (!SCLogDebugEnabled())
return;
@ -137,16 +133,16 @@ void FlowVarPrint(GenericVar *gv) {
FlowVar *fv = (FlowVar *)gv;
if (fv->datatype == FLOWVAR_TYPE_STR) {
SCLogDebug("Name idx \"%" PRIu32 "\", Value \"", fv->idx);
for (i = 0; i < fv->data.fv_str.value_len; i++) {
if (isprint(fv->data.fv_str.value[i]))
SCLogDebug("%c", fv->data.fv_str.value[i]);
SCLogDebug("Name idx \"%" PRIu16 "\", Value \"", fv->idx);
for (u = 0; u < fv->data.fv_str.value_len; u++) {
if (isprint(fv->data.fv_str.value[u]))
SCLogDebug("%c", fv->data.fv_str.value[u]);
else
SCLogDebug("\\%02X", fv->data.fv_str.value[i]);
SCLogDebug("\\%02X", fv->data.fv_str.value[u]);
}
SCLogDebug("\", Len \"%" PRIu32 "\"\n", fv->data.fv_str.value_len);
SCLogDebug("\", Len \"%" PRIu16 "\"\n", fv->data.fv_str.value_len);
} else if (fv->datatype == FLOWVAR_TYPE_INT) {
SCLogDebug("Name idx \"%" PRIu32 "\", Value \"%" PRIu32 "\"", fv->idx,
SCLogDebug("Name idx \"%" PRIu16 "\", Value \"%" PRIu16 "\"", fv->idx,
fv->data.fv_int.value);
} else {
SCLogDebug("Unknown data type at flowvars\n");

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2010 Open Information Security Foundation
/* Copyright (C) 2007-2013 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -37,20 +37,20 @@
typedef struct FlowVarTypeStr {
uint8_t *value;
uint16_t value_len;
}FlowVarTypeStr;
} FlowVarTypeStr;
/** Struct used to hold the integer data type for flowvars */
typedef struct FlowVarTypeInt_ {
uint32_t value;
}FlowVarTypeInt;
} FlowVarTypeInt;
/** Generic Flowvar Structure */
typedef struct FlowVar_ {
uint8_t type; /* type, DETECT_FLOWVAR in this case */
GenericVar *next; /* right now just implement this as a list,
* in the long run we have think of something
* faster. */
uint16_t idx; /* name idx */
uint8_t type; /* type, DETECT_FLOWVAR in this case */
GenericVar *next; /* right now just implement this as a list,
* in the long run we have think of something
* faster. */
uint16_t idx; /* name idx */
uint8_t datatype;
union {
FlowVarTypeStr fv_str;
@ -59,12 +59,11 @@ typedef struct FlowVar_ {
} FlowVar;
/** Flowvar Interface API */
void FlowVarAddStr(Flow *, uint8_t, uint8_t *, uint16_t);
void FlowVarAddInt(Flow *, uint8_t, uint32_t);
FlowVar *FlowVarGet(Flow *, uint8_t);
void FlowVarAddStr(Flow *, uint16_t, uint8_t *, uint16_t);
void FlowVarAddInt(Flow *, uint16_t, uint32_t);
FlowVar *FlowVarGet(Flow *, uint16_t);
void FlowVarFree(FlowVar *);
void FlowVarPrint(GenericVar *);

Loading…
Cancel
Save