MemBuffer *buffer;
} JsonFileLogThread;
-/**
- * \internal
- * \brief Write meta data on a single line json record
- */
-static void FileWriteJsonRecord(JsonFileLogThread *aft, const Packet *p, const File *ff)
+json_t *JsonBuildFileInfoRecord(const Packet *p, const File *ff)
{
json_t *js = CreateJSONHeader((Packet *)p, 0, "fileinfo"); //TODO const
json_t *hjs = NULL;
if (unlikely(js == NULL))
- return;
-
- /* reset */
- MemBufferReset(aft->buffer);
+ return NULL;
switch (p->flow->alproto) {
case ALPROTO_HTTP:
json_t *fjs = json_object();
if (unlikely(fjs == NULL)) {
json_decref(js);
- return;
+ return NULL;
}
char *s = BytesToString(ff->name, ff->name_len);
}
json_object_set_new(fjs, "sha1", json_string(str));
}
- if (ff->flags & FILE_SHA256) {
- size_t x;
- int i;
- char str[256];
- for (i = 0, x = 0; x < sizeof(ff->sha256); x++) {
- i += snprintf(&str[i], 255-i, "%02x", ff->sha256[x]);
- }
- json_object_set_new(fjs, "sha256", json_string(str));
- }
#endif
break;
case FILE_STATE_TRUNCATED:
json_object_set_new(fjs, "state", json_string("UNKNOWN"));
break;
}
+
+#ifdef HAVE_NSS
+ if (ff->flags & FILE_SHA256) {
+ size_t x;
+ int i;
+ char str[256];
+ for (i = 0, x = 0; x < sizeof(ff->sha256); x++) {
+ i += snprintf(&str[i], 255-i, "%02x", ff->sha256[x]);
+ }
+ json_object_set_new(fjs, "sha256", json_string(str));
+ }
+#endif
+
json_object_set_new(fjs, "stored",
(ff->flags & FILE_STORED) ? json_true() : json_false());
if (ff->flags & FILE_STORED) {
/* originally just 'file', but due to bug 1127 naming it fileinfo */
json_object_set_new(js, "fileinfo", fjs);
- OutputJSONBuffer(js, aft->filelog_ctx->file_ctx, &aft->buffer);
- json_object_del(js, "fileinfo");
- switch (p->flow->alproto) {
- case ALPROTO_HTTP:
- json_object_del(js, "http");
- break;
- case ALPROTO_SMTP:
- json_object_del(js, "smtp");
- json_object_del(js, "email");
- break;
+ return js;
+}
+
+/**
+ * \internal
+ * \brief Write meta data on a single line json record
+ */
+static void FileWriteJsonRecord(JsonFileLogThread *aft, const Packet *p, const File *ff)
+{
+ json_t *js = JsonBuildFileInfoRecord(p, ff);
+ if (unlikely(js == NULL)) {
+ return;
}
- json_object_clear(js);
+ MemBufferReset(aft->buffer);
+ OutputJSONBuffer(js, aft->filelog_ctx->file_ctx, &aft->buffer);
json_decref(js);
}