Go to the documentation of this file.
41 static void DetectMetadataRegisterTests(
void);
93 const char *astring =
SCStrdup(
string);
94 if (astring == NULL) {
106 static int SortHelper(
const void *a,
const void *b)
110 return strcasecmp(ma->
key, mb->
key);
130 JsonBuilder *js = jb_new_object();
136 bool array_open =
false;
137 for (
int j = 0; j < cnt; j++) {
142 if (nm && strcasecmp(
m->key, nm->
key) == 0) {
144 jb_open_array(js,
m->key);
147 jb_append_string(js,
m->value);
150 jb_open_array(js,
m->key);
152 jb_append_string(js,
m->value);
159 const size_t len = jb_len(js);
160 #define MD_STR "\"metadata\":"
161 #define MD_STR_LEN (sizeof(MD_STR) - 1)
170 memcpy(ptr, jb_ptr(js),
len);
182 char copy[strlen(metadatastr)+1];
183 strlcpy(copy, metadatastr,
sizeof(copy));
184 char *xsaveptr = NULL;
185 char *key = strtok_r(copy,
",", &xsaveptr);
186 while (key != NULL) {
187 while (*key !=
'\0' && isblank(*key)) {
190 char *val = strchr(key,
' ');
193 while (*val !=
'\0' && isblank(*val)) {
202 if (strlen(key) == 0 || strlen(val) == 0) {
206 const char *hkey = DetectMedatataHashAdd(
de_ctx, key);
212 const char *hval = DetectMedatataHashAdd(
de_ctx, val);
230 key = strtok_r(NULL,
",", &xsaveptr);
254 DetectMetadataParse(
de_ctx, s, rawstr);
262 static int DetectMetadataParseTest01(
void)
269 "alert tcp any any -> any any "
270 "(metadata: toto 1; sid:1; rev:1;)");
278 static int DetectMetadataParseTest02(
void)
284 "alert tcp any any -> any any "
285 "(metadata: toto 1; "
286 "metadata: titi 2, jaivu gros_minet;"
301 "\"metadata\":{\"jaivu\":[\"gros_minet\"],\"titi\":[\"2\"],\"toto\":[\"1\"]}") == 0);
309 static void DetectMetadataRegisterTests(
void)
311 UtRegisterTest(
"DetectMetadataParseTest01", DetectMetadataParseTest01);
312 UtRegisterTest(
"DetectMetadataParseTest02", DetectMetadataParseTest02);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void(* Free)(DetectEngineCtx *, void *)
int DetectEngineMustParseMetadata(void)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
struct HtpBodyChunk_ * next
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
char StringHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
uint32_t StringHashFunc(HashTable *ht, void *data, uint16_t datalen)
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
void HashTableFree(HashTable *ht)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define PASS
Pass the test.
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
void StringHashFreeFunc(void *data)
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Signature * DetectEngineAppendSig(DetectEngineCtx *de_ctx, const char *sigstr)
Parse and append a Signature into the Detection Engine Context signature list.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
DetectMetadataHead * metadata
void DetectEngineUnsetParseMetadata(void)
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineSetParseMetadata(void)
HashTable * metadata_table
#define DEBUG_VALIDATE_BUG_ON(exp)
void(* RegisterTests)(void)