<commit_before>/** /file utils_xml.c 	
*	/brief Parsing the keys for manufacturer, pgn ,spn and function
*
*	This module takes the adress-claimed message (PGN 60928) and uses
*	the NAME from the CAN Data field to retrieve manufacturer, function
*	and class of the sender from the iso 11783 NAME list.
*
*	/author <NAME>
*/

#include <stdio.h>
#include <stdlib.h>
#include "mxml-2.10/mxml.h"
#include <time.h>
#include <unistd.h>


#include "utils_general.h"
#include "utils_parse.h"




int xml_add_device(mxml_node_t* tree, int device_id, u_int64_t data,int sa) {
	
	printf("Add device to xml\n");
	
	char man_name[50]={0}; //Name max is 50 chars, Database max name length is.
	parse_get_manufacturer(data,man_name);
	
	char func_name[50]={0};
	parse_get_function(data,func_name);
	
	char class_name[50]={0};
	char industry_name[50]={0};

	parse_get_class_industry(data,class_name,industry_name);

	char* uuid = int_to_string(device_id);

	char date_buff[70];
 	time_t now = time(NULL);
 	struct tm *now_local = localtime(&now);

 	if (strftime(date_buff, sizeof date_buff, "%Y-%m-%d-%H:%M",now_local)) {
        fprintf(stdout,"Device seen on %s",date_buff);
    } else {
        fprintf(stderr,"strftime failed");
    }
	
	mxml_node_t* device = mxmlNewElement(tree,"device");

	mxmlElementSetAttr(device, "UUID", uuid);
	mxmlElementSetAttr(device, "manufacturer", man_name);
	mxmlElementSetAttr(device, "function", func_name);
	mxmlElementSetAttr(device, "class",class_name);
	mxmlElementSetAttr(device, "industry",industry_name);
	mxmlElementSetAttr(device, "lastClaim",date_buff);
	mxmlElementSetAttr(device, "lastSA",int_to_string(sa));
	mxmlElementSetAttr(device, "status","online");
	free(uuid);
	return EXIT_SUCCESS;

}

/*
*   \brief Add message to xml-tree
*	Adds a detected message and its signals to the isoident.xml tree.
*/

int xml_add_message(mxml_node_t* device, int message_pgn) {
	printf("Add message PGN: %d to device.\n",message_pgn);<commit_msg>fixed memleak<commit_after>/** /file utils_xml.c 	
*	/brief Parsing the keys for manufacturer, pgn ,spn and function
*
*	This module takes the adress-claimed message (PGN 60928) and uses
*	the NAME from the CAN Data field to retrieve manufacturer, function
*	and class of the sender from the iso 11783 NAME list.
*
*	/author <NAME>
*/

#include <stdio.h>
#include <stdlib.h>
#include "mxml-2.10/mxml.h"
#include <time.h>
#include <unistd.h>


#include "utils_general.h"
#include "utils_parse.h"




int xml_add_device(mxml_node_t* tree, int device_id, u_int64_t data,int sa) {
	
	printf("Add device to xml\n");
	
	char man_name[50]={0}; //Name max is 50 chars, Database max name length is.
	parse_get_manufacturer(data,man_name);
	
	char func_name[50]={0};
	parse_get_function(data,func_name);
	
	char class_name[50]={0};
	char industry_name[50]={0};

	parse_get_class_industry(data,class_name,industry_name);

	char* uuid = int_to_string(device_id);
	char* device_sa = int_to_string(sa);

	char date_buff[70];
 	time_t now = time(NULL);
 	struct tm *now_local = localtime(&now);
 	

 	if (strftime(date_buff, sizeof date_buff, "%Y-%m-%d-%H:%M",now_local)) {
        fprintf(stdout,"Device seen on %s",date_buff);
    } else {
        fprintf(stderr,"strftime failed");
    }
	
	mxml_node_t* device = mxmlNewElement(tree,"device");

	mxmlElementSetAttr(device, "UUID", uuid);
	mxmlElementSetAttr(device, "manufacturer", man_name);
	mxmlElementSetAttr(device, "function", func_name);
	mxmlElementSetAttr(device, "class",class_name);
	mxmlElementSetAttr(device, "industry",industry_name);
	mxmlElementSetAttr(device, "lastClaim",date_buff);
	mxmlElementSetAttr(device, "lastSA",device_sa);
	mxmlElementSetAttr(device, "status","online");
	
	free(device_sa);
	free(uuid);

	return EXIT_SUCCESS;

}

/*
*   \brief Add message to xml-tree
*	Adds a detected message and its signals to the isoident.xml tree.
*/

int xml_add_message(mxml_node_t* device, int message_pgn) {
	printf("Add message PGN: %d to device.\n",message_pgn);
{'fraction_non_alphanumeric': 0.1343358395989975, 'fraction_numerical': 0.015538847117794486, 'mean_word_length': 5.365231259968102, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 40}, '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': '7075105', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1451, 'n_words': 344}