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 13 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 /* get the flowvar with name 'name' from the flow
* *
* name is a normal string*/ * name is a normal string*/
FlowVar *FlowVarGet(Flow *f, uint8_t idx) { FlowVar *FlowVarGet(Flow *f, uint16_t idx) {
GenericVar *gv = f->flowvar; GenericVar *gv = f->flowvar;
for ( ; gv != NULL; gv = gv->next) { 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 */ /* add a flowvar to the flow, or update it */
void FlowVarAddStr(Flow *f, uint8_t idx, uint8_t *value, uint16_t size) { void FlowVarAddStr(Flow *f, uint16_t idx, uint8_t *value, uint16_t size) {
//printf("Adding flow var \"%s\" with value(%" PRId32 ") \"%s\"\n", name, size, value);
FLOWLOCK_WRLOCK(f); FLOWLOCK_WRLOCK(f);
FlowVar *fv = FlowVarGet(f, idx); FlowVar *fv = FlowVarGet(f, idx);
@ -87,9 +85,7 @@ out:
} }
/* add a flowvar to the flow, or update it */ /* add a flowvar to the flow, or update it */
void FlowVarAddInt(Flow *f, uint8_t idx, uint32_t value) { void FlowVarAddInt(Flow *f, uint16_t idx, uint32_t value) {
//printf("Adding flow var \"%s\" with value(%" PRId32 ") \"%s\"\n", name, size, value);
FLOWLOCK_WRLOCK(f); FLOWLOCK_WRLOCK(f);
FlowVar *fv = FlowVarGet(f, idx); FlowVar *fv = FlowVarGet(f, idx);
@ -118,14 +114,14 @@ void FlowVarFree(FlowVar *fv) {
return; return;
if (fv->datatype == FLOWVAR_TYPE_STR) { if (fv->datatype == FLOWVAR_TYPE_STR) {
if (fv->data.fv_str.value != NULL) if (fv->data.fv_str.value != NULL)
SCFree(fv->data.fv_str.value); SCFree(fv->data.fv_str.value);
} }
SCFree(fv); SCFree(fv);
} }
void FlowVarPrint(GenericVar *gv) { void FlowVarPrint(GenericVar *gv) {
uint16_t i; uint16_t u;
if (!SCLogDebugEnabled()) if (!SCLogDebugEnabled())
return; return;
@ -137,16 +133,16 @@ void FlowVarPrint(GenericVar *gv) {
FlowVar *fv = (FlowVar *)gv; FlowVar *fv = (FlowVar *)gv;
if (fv->datatype == FLOWVAR_TYPE_STR) { if (fv->datatype == FLOWVAR_TYPE_STR) {
SCLogDebug("Name idx \"%" PRIu32 "\", Value \"", fv->idx); SCLogDebug("Name idx \"%" PRIu16 "\", Value \"", fv->idx);
for (i = 0; i < fv->data.fv_str.value_len; i++) { for (u = 0; u < fv->data.fv_str.value_len; u++) {
if (isprint(fv->data.fv_str.value[i])) if (isprint(fv->data.fv_str.value[u]))
SCLogDebug("%c", fv->data.fv_str.value[i]); SCLogDebug("%c", fv->data.fv_str.value[u]);
else 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) { } 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); fv->data.fv_int.value);
} else { } else {
SCLogDebug("Unknown data type at flowvars\n"); 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 * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -37,20 +37,20 @@
typedef struct FlowVarTypeStr { typedef struct FlowVarTypeStr {
uint8_t *value; uint8_t *value;
uint16_t value_len; uint16_t value_len;
}FlowVarTypeStr; } FlowVarTypeStr;
/** Struct used to hold the integer data type for flowvars */ /** Struct used to hold the integer data type for flowvars */
typedef struct FlowVarTypeInt_ { typedef struct FlowVarTypeInt_ {
uint32_t value; uint32_t value;
}FlowVarTypeInt; } FlowVarTypeInt;
/** Generic Flowvar Structure */ /** Generic Flowvar Structure */
typedef struct FlowVar_ { typedef struct FlowVar_ {
uint8_t type; /* type, DETECT_FLOWVAR in this case */ uint8_t type; /* type, DETECT_FLOWVAR in this case */
GenericVar *next; /* right now just implement this as a list, GenericVar *next; /* right now just implement this as a list,
* in the long run we have think of something * in the long run we have think of something
* faster. */ * faster. */
uint16_t idx; /* name idx */ uint16_t idx; /* name idx */
uint8_t datatype; uint8_t datatype;
union { union {
FlowVarTypeStr fv_str; FlowVarTypeStr fv_str;
@ -59,12 +59,11 @@ typedef struct FlowVar_ {
} FlowVar; } FlowVar;
/** Flowvar Interface API */ /** Flowvar Interface API */
void FlowVarAddStr(Flow *, uint8_t, uint8_t *, uint16_t); void FlowVarAddStr(Flow *, uint16_t, uint8_t *, uint16_t);
void FlowVarAddInt(Flow *, uint8_t, uint32_t); void FlowVarAddInt(Flow *, uint16_t, uint32_t);
FlowVar *FlowVarGet(Flow *, uint8_t); FlowVar *FlowVarGet(Flow *, uint16_t);
void FlowVarFree(FlowVar *); void FlowVarFree(FlowVar *);
void FlowVarPrint(GenericVar *); void FlowVarPrint(GenericVar *);

Loading…
Cancel
Save