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);
134 SCJsonBuilder *js = SCJbNewObject();
140 bool array_open =
false;
141 for (
int j = 0; j <
cnt; j++) {
146 if (nm && strcasecmp(
m->key, nm->
key) == 0) {
148 SCJbOpenArray(js,
m->key);
151 SCJbAppendString(js,
m->value);
154 SCJbOpenArray(js,
m->key);
156 SCJbAppendString(js,
m->value);
163 const size_t len = SCJbLen(js);
164 #define MD_STR "\"metadata\":"
165 #define MD_STR_LEN (sizeof(MD_STR) - 1)
174 memcpy(ptr, SCJbPtr(js),
len);
186 char copy[strlen(metadatastr)+1];
187 strlcpy(copy, metadatastr,
sizeof(copy));
188 char *xsaveptr = NULL;
189 char *key = strtok_r(copy,
",", &xsaveptr);
190 while (key != NULL) {
191 while (*key !=
'\0' && isblank(*key)) {
194 char *val = strchr(key,
' ');
197 while (*val !=
'\0' && isblank(*val)) {
206 if (strlen(key) == 0 || strlen(val) == 0) {
210 const char *hkey = DetectMetadataHashAdd(
de_ctx, key);
216 const char *hval = DetectMetadataHashAdd(
de_ctx, val);
234 key = strtok_r(NULL,
",", &xsaveptr);
258 DetectMetadataParse(
de_ctx, s, rawstr);
266 static int DetectMetadataParseTest01(
void)
273 "alert tcp any any -> any any "
274 "(metadata: toto 1; sid:1; rev:1;)");
282 static int DetectMetadataParseTest02(
void)
288 "alert tcp any any -> any any "
289 "(metadata: toto 1; "
290 "metadata: titi 2, jaivu gros_minet;"
305 "\"metadata\":{\"jaivu\":[\"gros_minet\"],\"titi\":[\"2\"],\"toto\":[\"1\"]}") == 0);
313 static void DetectMetadataRegisterTests(
void)
315 UtRegisterTest(
"DetectMetadataParseTest01", DetectMetadataParseTest01);
316 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)
Free a HashTable and all its contents.
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)
#define DETECT_MAX_RULE_SIZE
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)