Fixed BACnet basic file object to have dynamic name, mime-type, path. (#835)

This commit is contained in:
Steve Karg
2024-10-29 13:30:03 -05:00
committed by GitHub
parent a38cc531d2
commit 089caf7e4b
2 changed files with 18 additions and 19 deletions
+11 -12
View File
@@ -33,10 +33,10 @@
#define FILE_RECORD_SIZE MAX_OCTET_STRING_BYTES #define FILE_RECORD_SIZE MAX_OCTET_STRING_BYTES
#endif #endif
struct object_data { struct object_data {
const char *Object_Name; char *Object_Name;
char *Pathname; char *Pathname;
BACNET_DATE_TIME Modification_Date;
char *File_Type; char *File_Type;
BACNET_DATE_TIME Modification_Date;
bool File_Access_Stream : 1; bool File_Access_Stream : 1;
bool Read_Only : 1; bool Read_Only : 1;
bool Archive : 1; bool Archive : 1;
@@ -131,9 +131,7 @@ void bacfile_pathname_set(uint32_t object_instance, const char *pathname)
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
if (pObject->Pathname) {
free(pObject->Pathname); free(pObject->Pathname);
}
pObject->Pathname = bacfile_strdup(pathname); pObject->Pathname = bacfile_strdup(pathname);
} }
} }
@@ -154,10 +152,12 @@ uint32_t bacfile_pathname_instance(const char *pathname)
count = Keylist_Count(Object_List); count = Keylist_Count(Object_List);
while (count) { while (count) {
pObject = Keylist_Data_Index(Object_List, index); pObject = Keylist_Data_Index(Object_List, index);
if (pObject->Pathname) {
if (strcmp(pathname, pObject->Pathname) == 0) { if (strcmp(pathname, pObject->Pathname) == 0) {
Keylist_Index_Key(Object_List, index, &key); Keylist_Index_Key(Object_List, index, &key);
break; break;
} }
}
count--; count--;
index++; index++;
} }
@@ -205,7 +205,7 @@ bool bacfile_object_name(
* *
* @return true if object-name was set * @return true if object-name was set
*/ */
bool bacfile_object_name_set(uint32_t object_instance, char *new_name) bool bacfile_object_name_set(uint32_t object_instance, const char *new_name)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
struct object_data *pObject; struct object_data *pObject;
@@ -213,7 +213,8 @@ bool bacfile_object_name_set(uint32_t object_instance, char *new_name)
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
status = true; status = true;
pObject->Object_Name = new_name; free(pObject->Object_Name);
pObject->Object_Name = bacfile_strdup(new_name);
} }
return status; return status;
@@ -438,15 +439,9 @@ void bacfile_file_type_set(uint32_t object_instance, const char *mime_type)
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
if (pObject->File_Type) {
if (strcmp(pObject->File_Type, mime_type) != 0) {
free(pObject->File_Type); free(pObject->File_Type);
pObject->File_Type = bacfile_strdup(mime_type); pObject->File_Type = bacfile_strdup(mime_type);
} }
} else {
pObject->File_Type = bacfile_strdup(mime_type);
}
}
} }
/** /**
@@ -1019,6 +1014,7 @@ uint32_t bacfile_create(uint32_t object_instance)
if (pObject) { if (pObject) {
pObject->Object_Name = NULL; pObject->Object_Name = NULL;
pObject->Pathname = NULL; pObject->Pathname = NULL;
pObject->File_Type = NULL;
/* April Fool's Day */ /* April Fool's Day */
datetime_set_values( datetime_set_values(
&pObject->Modification_Date, 2006, 4, 1, 7, 0, 3, 1); &pObject->Modification_Date, 2006, 4, 1, 7, 0, 3, 1);
@@ -1069,6 +1065,9 @@ void bacfile_cleanup(void)
do { do {
pObject = Keylist_Data_Pop(Object_List); pObject = Keylist_Data_Pop(Object_List);
if (pObject) { if (pObject) {
free(pObject->Pathname);
free(pObject->File_Type);
free(pObject->Object_Name);
free(pObject); free(pObject);
} }
} while (pObject); } while (pObject);
+1 -1
View File
@@ -32,7 +32,7 @@ BACNET_STACK_EXPORT
bool bacfile_object_name( bool bacfile_object_name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name); uint32_t object_instance, BACNET_CHARACTER_STRING *object_name);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
bool bacfile_object_name_set(uint32_t object_instance, char *new_name); bool bacfile_object_name_set(uint32_t object_instance, const char *new_name);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
const char *bacfile_name_ansi(uint32_t object_instance); const char *bacfile_name_ansi(uint32_t object_instance);