From 2e0decbe6d2ea1461659922e6cba2f8bf1cc80ec Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Thu, 2 Nov 2023 13:52:02 +0100 Subject: [PATCH] Added date to all MDF file object items --- src/common/sockettcp.c | 4 +- src/vscp/common/canal_xmlconfig.h | 2 + src/vscp/common/mdf.cpp | 66 ++++++++++ src/vscp/common/mdf.h | 195 ++++++++++++++++++++---------- src/vscp/common/vscpunit.h | 2 + 5 files changed, 205 insertions(+), 64 deletions(-) diff --git a/src/common/sockettcp.c b/src/common/sockettcp.c index ad6d2ed79..5d5885e63 100644 --- a/src/common/sockettcp.c +++ b/src/common/sockettcp.c @@ -1468,7 +1468,7 @@ typedef int socklen_t; // strlcpy // -static void strlcpy( register char *dst, register const char *src, size_t n ) +static void _strlcpy( register char *dst, register const char *src, size_t n ) { for (; *src != '\0' && n > 1; n--) { *dst++ = *src++; @@ -1490,7 +1490,7 @@ static char *stcp_strndup( const char *ptr, size_t len ) char *p; if ( ( p = (char *)malloc( len + 1 ) ) != NULL ) { - strlcpy( p, ptr, len + 1 ); + _strlcpy( p, ptr, len + 1 ); } return p; diff --git a/src/vscp/common/canal_xmlconfig.h b/src/vscp/common/canal_xmlconfig.h index 74b967386..b7f815b59 100644 --- a/src/vscp/common/canal_xmlconfig.h +++ b/src/vscp/common/canal_xmlconfig.h @@ -36,6 +36,8 @@ #if !defined(CANALCONFIG_H__INCLUDED_) #define CANALCONFIG_H__INCLUDED_ +#include + #include #include #include diff --git a/src/vscp/common/mdf.cpp b/src/vscp/common/mdf.cpp index c5522b8ca..410b671a6 100644 --- a/src/vscp/common/mdf.cpp +++ b/src/vscp/common/mdf.cpp @@ -1020,6 +1020,7 @@ CMDF_Picture::clearStorage(void) m_strName.clear(); m_strURL.clear(); m_strFormat.clear(); + m_strDate.clear(); m_mapDescription.clear(); m_mapInfoURL.clear(); } @@ -1049,6 +1050,7 @@ CMDF_Video::clearStorage(void) m_strName.clear(); m_strURL.clear(); m_strFormat.clear(); + m_strDate.clear(); m_mapDescription.clear(); m_mapInfoURL.clear(); } @@ -1157,6 +1159,7 @@ CMDF_Manual::clearStorage(void) m_strName.clear(); m_strURL.clear(); m_strFormat.clear(); + m_strDate.clear(); m_mapDescription.clear(); m_mapInfoURL.clear(); } @@ -1186,6 +1189,7 @@ CMDF_Setup::clearStorage(void) m_strName.clear(); m_strURL.clear(); m_strFormat.clear(); + m_strDate.clear(); m_mapDescription.clear(); m_mapInfoURL.clear(); } @@ -1785,6 +1789,11 @@ __startSetupMDFParser(void *data, const char *name, const char **attr) gpPictureStruct->m_strFormat = attribute; } } + else if (0 == strcasecmp(attr[i], "date")) { + // Date for picture + spdlog::trace("Parse-XML: handleMDFParserData: Module picture date: {0}", attribute); + gpPictureStruct->m_strDate = attribute; + } } } // * * * NOTE! * * * @@ -1900,6 +1909,11 @@ __startSetupMDFParser(void *data, const char *name, const char **attr) spdlog::trace("Parse-XML: handleMDFParserData: Module manual format: {0}", attribute); gpManualStruct->m_strFormat = attribute; } + else if (0 == strcasecmp(attr[i], "date")) { + // Date for manula + spdlog::trace("Parse-XML: handleMDFParserData: Module manialö date: {0}", attribute); + gpManualStruct->m_strDate = attribute; + } } } else if (currentToken == "boot") { @@ -1978,6 +1992,11 @@ __startSetupMDFParser(void *data, const char *name, const char **attr) gpPictureStruct->m_strFormat = attribute; } } + else if (0 == strcasecmp(attr[i], "date")) { + // Date for picture + spdlog::trace("Parse-XML: handleMDFParserData: Module picture date: {0}", attribute); + gpPictureStruct->m_strDate = attribute; + } } } // [3] Video (standard format) @@ -2011,6 +2030,11 @@ __startSetupMDFParser(void *data, const char *name, const char **attr) gpVideoStruct->m_strFormat = attribute; } } + else if (0 == strcasecmp(attr[i], "date")) { + // Date for video + spdlog::trace("Parse-XML: handleMDFParserData: Module video date: {0}", attribute); + gpVideoStruct->m_strDate = attribute; + } } } // [3] Firmware (standard format) @@ -2200,6 +2224,11 @@ __startSetupMDFParser(void *data, const char *name, const char **attr) spdlog::trace("Parse-XML: handleMDFParserData: Module manual format: {0}", attribute); gpManualStruct->m_strFormat = attribute; } + else if (0 == strcasecmp(attr[i], "date")) { + // Date for manual + spdlog::trace("Parse-XML: handleMDFParserData: Module manual date: {0}", attribute); + gpManualStruct->m_strDate = attribute; + } } } // [3] Picture (standard format) @@ -2233,6 +2262,11 @@ __startSetupMDFParser(void *data, const char *name, const char **attr) gpSetupStruct->m_strFormat = attribute; } } + else if (0 == strcasecmp(attr[i], "date")) { + // Date for setup + spdlog::trace("Parse-XML: handleMDFParserData: Module setup date: {0}", attribute); + gpSetupStruct->m_strDate = attribute; + } } } // Boot (standard format) @@ -6938,6 +6972,14 @@ CMDF::parseMDF_JSON(const std::string &path) spdlog::warn("Parse-JSON: No picture format."); } + if (jpic.contains("date") && jpic["date"].is_string()) { + ppicture->m_strDate = jpic["date"]; + spdlog::debug("Parse-JSON: Picture date: {0} ", jpic["date"]); + } + else { + spdlog::warn("Parse-JSON: No picture date"); + } + if (getDescriptionList(jpic, ppicture->m_mapDescription) != VSCP_ERROR_SUCCESS) { spdlog::warn("Parse-JSON: Failed to get picture description."); } @@ -6986,6 +7028,14 @@ CMDF::parseMDF_JSON(const std::string &path) spdlog::warn("Parse-JSON: No video format."); } + if (jvideo.contains("date") && jvideo["date"].is_string()) { + pvideo->m_strDate = jvideo["date"]; + spdlog::debug("Parse-JSON: Video date: {0} ", jvideo["date"]); + } + else { + spdlog::warn("Parse-JSON: No video date"); + } + if (getDescriptionList(jvideo, pvideo->m_mapDescription) != VSCP_ERROR_SUCCESS) { spdlog::warn("Parse-JSON: Failed to get video description."); } @@ -7351,6 +7401,14 @@ CMDF::parseMDF_JSON(const std::string &path) spdlog::warn("Parse-JSON: No manual language."); } + if (jmanual.contains("date") && jmanual["date"].is_string()) { + pmanual->m_strDate = jmanual["date"]; + spdlog::debug("Parse-JSON: Manual date: {0} ", jmanual["date"]); + } + else { + spdlog::warn("Parse-JSON: No manual date"); + } + if (getDescriptionList(jmanual, pmanual->m_mapDescription) != VSCP_ERROR_SUCCESS) { spdlog::warn("Parse-JSON: Failed to get event data description."); } @@ -7399,6 +7457,14 @@ CMDF::parseMDF_JSON(const std::string &path) spdlog::warn("Parse-JSON: No setup format."); } + if (jsetup.contains("date") && jsetup["date"].is_string()) { + psetup->m_strDate = jsetup["date"]; + spdlog::debug("Parse-JSON: Setup date: {0} ", jsetup["date"]); + } + else { + spdlog::warn("Parse-JSON: No setup date"); + } + if (getDescriptionList(jsetup, psetup->m_mapDescription) != VSCP_ERROR_SUCCESS) { spdlog::warn("Parse-JSON: Failed to get setup description."); } diff --git a/src/vscp/common/mdf.h b/src/vscp/common/mdf.h index 0501c4e21..b243ac6e8 100644 --- a/src/vscp/common/mdf.h +++ b/src/vscp/common/mdf.h @@ -116,11 +116,11 @@ typedef enum mdf_record_type { mdf_type_decision_matrix, mdf_type_action, mdf_type_action_item, - mdf_type_action_param, + mdf_type_action_param, mdf_type_event, mdf_type_event_item, mdf_type_event_data, - mdf_type_event_data_item, + mdf_type_event_data_item, mdf_type_bootloader, mdf_type_bootloader_item, mdf_type_address, @@ -155,7 +155,7 @@ typedef enum mdf_record_type { mdf_type_setup_item, mdf_type_manual, mdf_type_manual_item, - mdf_type_redirection, + mdf_type_redirection, mdf_type_alarm, mdf_type_generic_string, // Used for direct item editing mdf_type_generic_number, // Used for direct item editing @@ -197,7 +197,7 @@ class CMDF_Object { std::string getObjectTypeString(void); virtual std::map *getMapDescription(void) { return nullptr; }; - virtual std::map *getMapInfoUrl(void) {return nullptr; }; + virtual std::map *getMapInfoUrl(void) { return nullptr; }; private: mdf_record_type m_type; @@ -1658,7 +1658,7 @@ class CMDF_Item : public CMDF_Object { Set item value @param Value to set */ - void setValue(std::string& str) { m_value = str; }; + void setValue(std::string &str) { m_value = str; }; /*! Get the register description @@ -1699,7 +1699,7 @@ class CMDF_Item : public CMDF_Object { std::map *getMapInfoUrl(void) { return &m_mapInfoURL; }; private: - std::string m_value; // Item value + std::string m_value; // Item value std::map m_mapDescription; std::map m_mapInfoURL; // Url that contain extra hel information }; @@ -1810,9 +1810,9 @@ class CMDF_Address : public CMDF_Object { /*! Set street address - @param Street address to set + @param Street address to set */ - void setStreet(const std::string& str) { m_strStreet = str; }; + void setStreet(const std::string &str) { m_strStreet = str; }; /*! Get town address @@ -1822,9 +1822,9 @@ class CMDF_Address : public CMDF_Object { /*! Set town address - @param str Town address to set + @param str Town address to set */ - void setTown(const std::string& str) { m_strTown = str; }; + void setTown(const std::string &str) { m_strTown = str; }; /*! Get city address @@ -1834,9 +1834,9 @@ class CMDF_Address : public CMDF_Object { /*! Set city address - @param str City address to set + @param str City address to set */ - void setCity(const std::string& str) { m_strCity = str; }; + void setCity(const std::string &str) { m_strCity = str; }; /*! Get post code address @@ -1846,9 +1846,9 @@ class CMDF_Address : public CMDF_Object { /*! Set post code address - @param str Post code address to set + @param str Post code address to set */ - void setPostCode(const std::string& str) { m_strPostCode = str; }; + void setPostCode(const std::string &str) { m_strPostCode = str; }; /*! Get state address @@ -1858,9 +1858,9 @@ class CMDF_Address : public CMDF_Object { /*! Set state address - @param str State address to set + @param str State address to set */ - void setState(const std::string& str) { m_strState = str; }; + void setState(const std::string &str) { m_strState = str; }; /*! Get region address @@ -1870,9 +1870,9 @@ class CMDF_Address : public CMDF_Object { /*! Set region address - @param str Region address to set + @param str Region address to set */ - void setRegion(const std::string& str) { m_strRegion = str; }; + void setRegion(const std::string &str) { m_strRegion = str; }; /*! Get country address @@ -1882,9 +1882,9 @@ class CMDF_Address : public CMDF_Object { /*! Set country address - @param str Country address to set + @param str Country address to set */ - void setCountry(const std::string& str) { m_strCountry = str; }; + void setCountry(const std::string &str) { m_strCountry = str; }; private: std::string m_strStreet; @@ -1908,17 +1908,10 @@ class CMDF_Address : public CMDF_Object { class CMDF_Manufacturer : public CMDF_Object { public: - CMDF_Manufacturer(); ~CMDF_Manufacturer(); - enum contact_type { - contact_type_phone, - contact_type_fax, - contact_type_email, - contact_type_web, - contact_type_social - }; + enum contact_type { contact_type_phone, contact_type_fax, contact_type_email, contact_type_web, contact_type_social }; // Friend declarations friend CMDF; @@ -1934,7 +1927,7 @@ class CMDF_Manufacturer : public CMDF_Object { void clearStorage(void); /// Get company name - std::string& getName(void) { return m_strName; }; + std::string &getName(void) { return m_strName; }; /// Set company name void setName(const std::string name) { m_strName = name; }; @@ -2078,6 +2071,18 @@ class CMDF_Picture : public CMDF_Object { */ void setFormat(std::string &strFormat) { m_strFormat = strFormat; }; + /* + Get date for object + @return date on ISO string format + */ + std::string getDate(void) { return m_strDate; }; + + /*! + Set date for object + @param isodate Date for object oin ISO string form. + */ + void setDate(const std::string& isodate) { m_strDate = isodate; }; + /*! Set description for picture */ @@ -2091,16 +2096,7 @@ class CMDF_Picture : public CMDF_Object { @param strLanguage Language for description (default="en") @return Description for picture as string */ - std::string getDescription(std::string strLanguage = "en") - { - return m_mapDescription[strLanguage]; - // if (m_mapDescription.find(strLanguage) != m_mapDescription.end()) { - // return m_mapDescription[strLanguage]; - // } - // else { - // return ""; - // } - }; + std::string getDescription(std::string strLanguage = "en") { return m_mapDescription[strLanguage]; }; /*! Get the value info URL @@ -2143,6 +2139,12 @@ class CMDF_Picture : public CMDF_Object { */ std::string m_strFormat; + /* + Date + */ + std::string m_strDate; + + /*! Description of file */ @@ -2207,6 +2209,18 @@ class CMDF_Video : public CMDF_Object { */ void setFormat(std::string &strFormat) { m_strFormat = strFormat; }; + /* + Get date for object + @return date on ISO string format + */ + std::string getDate(void) { return m_strDate; }; + + /*! + Set date for object + @param isodate Date for object oin ISO string form. + */ + void setDate(const std::string& isodate) { m_strDate = isodate; }; + /*! Set description for video */ @@ -2271,6 +2285,12 @@ class CMDF_Video : public CMDF_Object { */ std::string m_strFormat; + /* + Date + */ + std::string m_strDate; + + /*! Description of file */ @@ -2342,12 +2362,18 @@ class CMDF_Firmware : public CMDF_Object { */ std::string getFormat(void) { return m_strFormat; }; - /*! - Get ISO date string for firmware - @return ISO date string for firmware + /* + Get date for object + @return date on ISO string format */ std::string getDate(void) { return m_strDate; }; + /*! + Set date for object + @param isodate Date for object oin ISO string form. + */ + void setDate(const std::string& isodate) { m_strDate = isodate; }; + /*! Get version major for firmware @return Version major for firmware @@ -2579,12 +2605,18 @@ class CMDF_Driver : public CMDF_Object { */ std::string getMd5(void) { return m_strMd5; }; - /*! - Get ISO date for driver - @return ISO date on string form + /* + Get date for object + @return date on ISO string format */ std::string getDate(void) { return m_strDate; }; + /*! + Set date for object + @param isodate Date for object oin ISO string form. + */ + void setDate(const std::string& isodate) { m_strDate = isodate; }; + /*! Set description for picture */ @@ -2659,6 +2691,11 @@ class CMDF_Driver : public CMDF_Object { */ std::string m_strOSVer; + /*! + Date for object + */ + std::string m_strDate; + /*! Processor architecture */ @@ -2673,9 +2710,6 @@ class CMDF_Driver : public CMDF_Object { /// Subminor version number uint16_t m_version_patch; - /// Date for driver - std::string m_strDate; - /*! MD5 hash on hex string form for firmware file */ @@ -2768,6 +2802,18 @@ class CMDF_Setup : public CMDF_Object { } }; + /* + Get date for object + @return date on ISO string format + */ + std::string getDate(void) { return m_strDate; }; + + /*! + Set date for object + @param isodate Date for object oin ISO string form. + */ + void setDate(const std::string& isodate) { m_strDate = isodate; }; + /*! Get the value info URL @return Value info URL @@ -2809,6 +2855,16 @@ class CMDF_Setup : public CMDF_Object { */ std::string m_strFormat; + /* + Date + */ + std::string m_strDate; + + /* + Version + */ + std::string m_strVersion; + /*! Description of file */ @@ -2867,6 +2923,18 @@ class CMDF_Manual : public CMDF_Object { */ std::string getLanguage(void) { return m_strLanguage; }; + /* + Get date for object + @return date on ISO string format + */ + std::string getDate(void) { return m_strDate; }; + + /*! + Set date for object + @param isodate Date for object oin ISO string form. + */ + void setDate(const std::string& isodate) { m_strDate = isodate; }; + /*! Set description for manual item */ @@ -2936,6 +3004,11 @@ class CMDF_Manual : public CMDF_Object { */ std::string m_strLanguage; + /*! + Object date + */ + std::string m_strDate; + /*! Description of file */ @@ -3064,7 +3137,7 @@ class CMDF : public CMDF_Object { Set module buffer size @param size Module buffer size to set */ - void setModuleBufferSize(uint16_t size ) { m_module_bufferSize = size; }; + void setModuleBufferSize(uint16_t size) { m_module_bufferSize = size; }; /*! Get Module copyright. @@ -3149,8 +3222,6 @@ class CMDF : public CMDF_Object { */ std::map *getHelpUrlMap(void) { return &m_mapInfoURL; }; - - /*! Get manufacturer object @return Pointer to manufacturer object @@ -3224,10 +3295,10 @@ class CMDF : public CMDF_Object { }; /*! - Get pointer to picture object + Get pointer to picture object list @return Picture object */ - std::deque *getPictureObj(void) { return &m_list_picture; }; + std::deque *getPictureObjList(void) { return &m_list_picture; }; /*! Get number of module videos @@ -3246,10 +3317,10 @@ class CMDF : public CMDF_Object { }; /*! - Get pointer to video object + Get pointer to video object list @return Video object */ - std::deque *getVideoObj(void) { return &m_list_video; }; + std::deque *getVideoObjList(void) { return &m_list_video; }; /*! Get number of module firmware files @@ -3271,7 +3342,7 @@ class CMDF : public CMDF_Object { Get pointer to firmware object @return Firmware object */ - std::deque *getFirmwareObj(void) { return &m_list_firmware; }; + std::deque *getFirmwareObjList(void) { return &m_list_firmware; }; /*! Get number of driver files @@ -3293,7 +3364,7 @@ class CMDF : public CMDF_Object { Get pointer to driver object @return Driver object */ - std::deque *getDriverObj(void) { return &m_list_driver; }; + std::deque *getDriverObjList(void) { return &m_list_driver; }; /*! Get number of setup files @@ -3315,7 +3386,7 @@ class CMDF : public CMDF_Object { Get pointer to setup object @return Setup object */ - std::deque *getSetupObj(void) { return &m_list_setup; }; + std::deque *getSetupObjList(void) { return &m_list_setup; }; /*! Get number of module manual files @@ -3334,12 +3405,12 @@ class CMDF : public CMDF_Object { }; /*! - Get pointer to manual object + Get pointer to manual object list @return Manual object */ - std::deque *getManualObj(void) { return &m_list_manual; }; + std::deque *getManualObjList(void) { return &m_list_manual; }; - // --------------------------------------------------------------------------------------------- + // --------------------------------------------------------------------------------------------- /*! Get bootloader object @@ -3359,7 +3430,7 @@ class CMDF : public CMDF_Object { Get the complete register list @return Pointer to register list. */ - std::deque *getRegisterList(void) { return &m_list_register; }; + std::deque *getRegisterObjList(void) { return &m_list_register; }; /*! Get all registers for a specific page diff --git a/src/vscp/common/vscpunit.h b/src/vscp/common/vscpunit.h index af708e955..9d59b9b52 100644 --- a/src/vscp/common/vscpunit.h +++ b/src/vscp/common/vscpunit.h @@ -29,6 +29,8 @@ #if !defined(VSCP_UNIT_H__INCLUDED_) #define VSCP_UNIT_H__INCLUDED_ +#include + #include class CVscpUnit {