<commit_before>#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include "neat_internal.h"
#include "neat_core.h"
#include "neat_stat.h"


/* Traverse the relevant subsystems of NEAT and gather the stats
   then format the stats as a json string to return */	
void neat_stats_build_json(neat_flow *flow, char **json_stats)
{
	json_t *root = json_object();

	neat_log(NEAT_LOG_DEBUG, "%s", __func__);

	json_object_set_new( root, "remote_host", json_string( flow->name ));
	json_object_set_new( root, "sock_type", json_integer( flow->sockType ));
	json_object_set_new( root, "sock_protocol", json_integer( flow->sockProtocol ));
	json_object_set_new( root, "port", json_integer( flow->port ));
	
	/* TODO: fetch OS-specific stats from the respective stacks used for connecting */

	/* Callers must remember to free the output */
	*json_stats = json_dumps(root, 0);

	json_decref(root);<commit_msg>Moved declaration to beginning of function and assignment to after the debug line in case sth bad happens on json_object()<commit_after>#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include "neat_internal.h"
#include "neat_core.h"
#include "neat_stat.h"


/* Traverse the relevant subsystems of NEAT and gather the stats
   then format the stats as a json string to return */	
void neat_stats_build_json(neat_flow *flow, char **json_stats)
{
	json_t *json_root;

	neat_log(NEAT_LOG_DEBUG, "%s", __func__);

	json_root = json_object();

	json_object_set_new( json_root, "remote_host", json_string( flow->name ));
	json_object_set_new( json_root, "sock_type", json_integer( flow->sockType ));
	json_object_set_new( json_root, "sock_protocol", json_integer( flow->sockProtocol ));
	json_object_set_new( json_root, "port", json_integer( flow->port ));
	
	/* TODO: fetch OS-specific stats from the respective stacks used for connecting */

	/* Callers must remember to free the output */
	*json_stats = json_dumps(json_root, 0);

	json_decref(json_root);
{'fraction_non_alphanumeric': 0.12042905899561189, 'fraction_numerical': 0.0009751340809361287, 'mean_word_length': 5.640776699029126, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1006455', 'n_tokens_mistral': 728, 'n_tokens_neox': 704, 'n_words': 197}