added zero padding and utf8-validation to entity parser for first test

This commit is contained in:
sirmbcode 2026-05-31 17:15:04 -07:00 committed by Wim Taymans
parent 925cea5822
commit 1a1cd8d743

View file

@ -3,9 +3,11 @@
#include "aecp-aem-descriptors.h" #include "aecp-aem-descriptors.h"
#include "avb.h" #include "avb.h"
#include "entity_model.h" #include "entity-model-milan-v12.h"
#include "internal.h" #include "internal.h"
#include "descriptors.h" #include "descriptors.h"
#include "strings.h"
#include <cstddef>
struct avb_entity_config { struct avb_entity_config {
char entity_name[64]; char entity_name[64];
@ -21,18 +23,37 @@ struct avb_entity_config {
}; };
static inline struct avb_entity_config conf_load_entity (struct pw_properties *props) { static inline struct avb_entity_config conf_load_entity (struct pw_properties *props) {
// Grab entity field and turn into pw_properties struct
struct avb_entity_config entity_conf; struct avb_entity_config entity_conf;
char *str; char *str;
pw_log_info("Acquiring entity properties from avb.properties.entity"); pw_log_info("Acquiring entity properties from entity dict in avb.properties");
str = pw_properties_get(props, "avb.properties.entity"); str = pw_properties_get(props, "entity");
struct pw_properties *entity_props; struct pw_properties *entity_props;
entity_props = pw_properties_new(NULL,NULL); entity_props = pw_properties_new(NULL,NULL);
pw_properties_update_string(entity_props, str, strlen(str)); pw_properties_update_string(entity_props, str, strlen(str));
// Assign properties to aem_entity_config struct
// First handle strings
//TODO: with strings, check utf8 format and set as a filled 64 byte char array
// check zero padding and utf8 format
pw_log_info("Assigning entity properties"); pw_log_info("Assigning entity properties");
char *name = pw_properties_get(entity_props, "entity_name"); char *name = pw_properties_get(entity_props, "entity_name");
char *entity_name = name ? name : DSC_ENTITY_MODEL_ENTITY_NAME; char *entity_name;
strncpy(entity_conf.entity_name, entity_name, sizeof(entity_conf.entity_name));
int use_default = name ? 1 : 0;
size_t len;
if (name){
len = strnlen(name, 64);
if (validate_utf8(name, len)) entity_name = name;
else use_default = 1;
if (use_default){
len = strnlen(name, 64);
entity_name = (char *)DSC_ENTITY_MODEL_ENTITY_NAME;
}
memcpy(entity_conf.entity_name, entity_name, 64);
memset(entity_conf.entity_name + len, 0, 64 - len);
char *serial = pw_properties_get(entity_props, "serial_number"); char *serial = pw_properties_get(entity_props, "serial_number");
char *serial_number = serial ? serial : DSC_ENTITY_MODEL_SERIAL_NUMBER; char *serial_number = serial ? serial : DSC_ENTITY_MODEL_SERIAL_NUMBER;
@ -46,6 +67,7 @@ static inline struct avb_entity_config conf_load_entity (struct pw_properties *p
char *group_name = group ? group: DSC_ENTITY_MODEL_GROUP_NAME; char *group_name = group ? group: DSC_ENTITY_MODEL_GROUP_NAME;
strncpy(entity_conf.group_name, group_name, sizeof(entity_conf.group_name)); strncpy(entity_conf.group_name, group_name, sizeof(entity_conf.group_name));
// Handle integers
uint32_t vendor_name; uint32_t vendor_name;
int vn_found = pw_properties_fetch_uint32(entity_props, "vendor_name", &vendor_name); int vn_found = pw_properties_fetch_uint32(entity_props, "vendor_name", &vendor_name);
entity_conf.vendor_name = !vn_found ? (uint16_t)vendor_name : DSC_ENTITY_MODEL_VENDOR_NAME_STRING; entity_conf.vendor_name = !vn_found ? (uint16_t)vendor_name : DSC_ENTITY_MODEL_VENDOR_NAME_STRING;