Go to the documentation of this file.
41 static void DetectMetadataRegisterTests(
void);
94 const char *astring =
SCStrdup(
string);
95 if (astring == NULL) {
108 static int SortHelper(
const void *a,
const void *b)
112 return strcasecmp(ma->
key, mb->
key);
132 JsonBuilder *js = jb_new_object();
138 bool array_open =
false;
139 for (
int j = 0; j <
cnt; j++) {
144 if (nm && strcasecmp(
m->key, nm->
key) == 0) {
146 jb_open_array(js,
m->key);
149 jb_append_string(js,
m->value);
152 jb_open_array(js,
m->key);
154 jb_append_string(js,
m->value);
161 const size_t len = jb_len(js);
162 #define MD_STR "\"metadata\":"
163 #define MD_STR_LEN (sizeof(MD_STR) - 1)
172 memcpy(ptr, jb_ptr(js),
len);
184 char copy[strlen(metadatastr)+1];
185 strlcpy(copy, metadatastr,
sizeof(copy));
186 char *xsaveptr = NULL;
187 char *key = strtok_r(copy,
",", &xsaveptr);
188 while (key != NULL) {
189 while (*key !=
'\0' && isblank(*key)) {
192 char *val = strchr(key,
' ');
195 while (*val !=
'\0' && isblank(*val)) {
204 if (strlen(key) == 0 || strlen(val) == 0) {
208 const char *hkey = DetectMetadataHashAdd(
de_ctx, key);
214 const char *hval = DetectMetadataHashAdd(
de_ctx, val);
232 key = strtok_r(NULL,
",", &xsaveptr);
256 DetectMetadataParse(
de_ctx, s, rawstr);
264 static int DetectMetadataParseTest01(
void)
271 "alert tcp any any -> any any "
272 "(metadata: toto 1; sid:1; rev:1;)");
280 static int DetectMetadataParseTest02(
void)
286 "alert tcp any any -> any any "
287 "(metadata: toto 1; "
288 "metadata: titi 2, jaivu gros_minet;"
303 "\"metadata\":{\"jaivu\":[\"gros_minet\"],\"titi\":[\"2\"],\"toto\":[\"1\"]}") == 0);
311 static void DetectMetadataRegisterTests(
void)
313 UtRegisterTest(
"DetectMetadataParseTest01", DetectMetadataParseTest01);
314 UtRegisterTest(
"DetectMetadataParseTest02", DetectMetadataParseTest02);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
SigTableElmt * sigmatch_table
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::
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
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 *)
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
DetectMetadataHead * metadata
#define SCLogError(...)
Macro used to log ERROR messages.
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)