From cb586635de541f0516f52a522a0c8a045477203d Mon Sep 17 00:00:00 2001 From: Ingo Huerner Date: Tue, 10 Feb 2015 01:42:05 +0100 Subject: Cleanup in data organization: replaced external variables by getFunctions --- src/persistence_client_library.c | 21 ++- src/persistence_client_library_backup_filelist.c | 24 +-- src/persistence_client_library_custom_loader.c | 23 ++- src/persistence_client_library_data_organization.c | 149 ++++++++------- src/persistence_client_library_data_organization.h | 203 ++++++++++----------- src/persistence_client_library_db_access.c | 20 +- src/persistence_client_library_dbus_cmd.c | 10 + src/persistence_client_library_dbus_service.h | 2 +- src/persistence_client_library_file.c | 77 ++++---- src/persistence_client_library_handle.c | 48 ++--- src/persistence_client_library_handle.h | 6 +- src/persistence_client_library_key.c | 30 +-- src/persistence_client_library_prct_access.c | 46 ++--- 13 files changed, 361 insertions(+), 298 deletions(-) (limited to 'src') diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index af20fb7..118953c 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -50,6 +50,9 @@ static int gCancelCounter = 0; static pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER; +/// name of the backup blacklist file (contains all the files which are excluded from backup creation) +const char* gBackupFilename = "BackupFileList.info"; + #if USE_APPCHECK /// global flag static int gAppCheckFlag = -1; @@ -71,11 +74,11 @@ static int private_pclDeinitLibrary(void); /* security check for valid application: if the RCT table exists, the application is proven to be valid (trusted), otherwise return EPERS_NOPRCTABLE */ -void doInitAppcheck(const char* appName) +static void doInitAppcheck(const char* appName) { #if USE_APPCHECK - char rctFilename[DbPathMaxLen] = {0}; - snprintf(rctFilename, DbPathMaxLen, gLocalWtPathKey, appName, plugin_gResTableCfg); + char rctFilename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; + snprintf(rctFilename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), appName, plugin_gResTableCfg); if(access(rctFilename, F_OK) == 0) { @@ -100,8 +103,8 @@ int doAppcheck(void) #if USE_APPCHECK if(gAppCheckFlag != 1) { - char rctFilename[DbPathMaxLen] = {0}; - snprintf(rctFilename, DbPathMaxLen, gLocalWtPathKey, gAppId, plugin_gResTableCfg); + char rctFilename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; + snprintf(rctFilename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), gAppId, plugin_gResTableCfg); if(access(rctFilename, F_OK) == 0) { gAppCheckFlag = 1; // "trusted" application @@ -146,7 +149,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) static int private_pclInitLibrary(const char* appName, int shutdownMode) { int rval = 1; - char blacklistPath[DbPathMaxLen] = {0}; + char blacklistPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; gShutdownMode = shutdownMode; @@ -160,7 +163,7 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received // Assemble backup blacklist path - snprintf(blacklistPath, DbPathMaxLen, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename); + snprintf(blacklistPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename); if(readBlacklistConfigFile(blacklistPath) == -1) { @@ -208,8 +211,8 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) pers_unlock_access(); - strncpy(gAppId, appName, MaxAppNameLen); // assign application name - gAppId[MaxAppNameLen-1] = '\0'; + strncpy(gAppId, appName, PERS_RCT_MAX_LENGTH_RESPONSIBLE); // assign application name + gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE-1] = '\0'; return rval; } diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c index f59e3fa..9629a57 100644 --- a/src/persistence_client_library_backup_filelist.c +++ b/src/persistence_client_library_backup_filelist.c @@ -222,11 +222,11 @@ int pclCreateFile(const char* path, int chached) { const char* delimiters = "/\n"; // search for blank and end of line char* tokenArray[24] = {0}; - char thePath[DbPathMaxLen] = {0}; + char thePath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; int numTokens = 0, i = 0, validPath = 1, handle = -1; - strncpy(thePath, path, DbPathMaxLen); - thePath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination + strncpy(thePath, path, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + thePath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination tokenArray[numTokens++] = strtok(thePath, delimiters); while(tokenArray[numTokens-1] != NULL ) @@ -249,18 +249,18 @@ int pclCreateFile(const char* path, int chached) if(validPath == 1) { - char createPath[DbPathMaxLen] = {0}; - snprintf(createPath, DbPathMaxLen, "/%s",tokenArray[0] ); + char createPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; + snprintf(createPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "/%s",tokenArray[0] ); for(i=1; i/ ( -const char* gLocalCachePath = CACHEPREFIX "%s"; +static const char* gLocalCachePath_ = CACHEPREFIX "%s"; // path prefix for local write through database /Data/mnt_wt// -const char* gLocalWtPath = WTPREFIX "%s"; +static const char* gLocalWtPath_ = WTPREFIX "%s"; // path prefix for shared cached database: /Data/mnt_c/Shared/Group// -const char* gSharedCachePath = CACHEPREFIX "%s/shared_group_%x"; +static const char* gSharedCachePath_ = CACHEPREFIX "%s/shared_group_%x"; // path prefix for shared write through database: /Data/mnt_wt/Shared/Group// -const char* gSharedWtPath = WTPREFIX "%s/shared_group_%x"; +static const char* gSharedWtPath_ = WTPREFIX "%s/shared_group_%x"; // path prefix for shared public cached database: /Data/mnt_c/Shared/Public// -const char* gSharedPublicCachePath = CACHEPREFIX "%s/shared_public"; +static const char* gSharedPublicCachePath_ = CACHEPREFIX "%s/shared_public"; // path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ -const char* gSharedPublicWtPath = WTPREFIX "%s/shared_public"; +static const char* gSharedPublicWtPath_ = WTPREFIX "%s/shared_public"; // path prefix for local cached database: /Data/mnt_c// ( -const char* gLocalCachePathKey = CACHEPREFIX "%s%s"; +static const char* gLocalCachePathKey = CACHEPREFIX "%s%s"; // path prefix for local write through database /Data/mnt_wt// -const char* gLocalWtPathKey = WTPREFIX "%s%s"; +static const char* gLocalWtPathKey = WTPREFIX "%s%s"; // path prefix for shared cached database: /Data/mnt_c/Shared/Group// -const char* gSharedCachePathKey = CACHEPREFIX "%s/shared_group_%x%s"; +static const char* gSharedCachePathKey = CACHEPREFIX "%s/shared_group_%x%s"; // path prefix for shared write through database: /Data/mnt_wt/Shared/Group// -const char* gSharedWtPathKey = WTPREFIX "%s/shared_group_%x%s"; +static const char* gSharedWtPathKey = WTPREFIX "%s/shared_group_%x%s"; // path prefix for shared public cached database: /Data/mnt_c/Shared/Public// -const char* gSharedPublicCachePathKey = CACHEPREFIX "%s/shared_public%s"; +static const char* gSharedPublicCachePathKey = CACHEPREFIX "%s/shared_public%s"; // path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ -const char* gSharedPublicWtPathKey = WTPREFIX "%s/shared_public%s"; +static const char* gSharedPublicWtPathKey = WTPREFIX "%s/shared_public%s"; // path prefix for local cached files: /Data/mnt_c//// const char* gLocalCacheFilePath = CACHEPREFIX "%s"PERS_ORG_USER_FOLDER_NAME_"%d"PERS_ORG_SEAT_FOLDER_NAME_"%d/%s"; -const char* gBackupFilename = "BackupFileList.info"; - -const char* gChangeSignal = "PersistenceResChange"; -const char* gDeleteSignal = "PersistenceResDelete"; -const char* gCreateSignal = "PersistenceResCreate"; - -int gTimeoutMs = 5000; - -int gDbusPendingRvalue = 0; - - -/// application id -char gAppId[MaxAppNameLen] = { [0 ... MaxAppNameLen-1] = 0}; - - -/// max key value data size [default 16kB] -int gMaxKeyValDataSize = defaultMaxKeyValDataSize; - - -unsigned int gPclInitCounter = 0; - - -DltContext gPclDLTContext; - -int(* gChangeNotifyCallback)(pclNotification_s * notifyStruct); - -const char gCharLookup[] = +const char* getLocalCachePath(void) { - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, // from 0x0 (NULL) to 0x1F (unit seperator) - 0,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, // from 020 (space) to 0x2F (?) - 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, // from 040 (@) to 0x5F (_) - 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1 // from 060 (') to 0x7E (~) - -}; - - -const char* gPluginTypeDefault = "default"; -const char* gPluginTypeEarly = "early"; -const char* gPluginTypeSecure = "secure"; -const char* gPluginTypeEmergency = "emergency"; -const char* gPluginTypeHwInfo = "hwinfo"; -const char* gPluginTypeCustom1 = "custom1"; -const char* gPluginTypeCustom2 = "custom2"; -const char* gPluginTypeCustom3 = "custom3"; + return gLocalCachePath_; +} +const char* getLocalWtPath(void) +{ + return gLocalWtPath_; +} +const char* getSharedCachePath(void) +{ + return gSharedCachePath_; +} +const char* getSharedWtPath(void) +{ + return gSharedWtPath_; +} +const char* getSharedPublicCachePath(void) +{ + return gSharedPublicCachePath_; +} +const char* getSharedPublicWtPath(void) +{ + return gSharedPublicWtPath_; +} +const char* getLocalCachePathKey(void) +{ + return gLocalCachePathKey; +} +const char* getLocalWtPathKey(void) +{ + return gLocalWtPathKey; +} +const char* getSharedCachePathKey(void) +{ + return gSharedCachePathKey; +} +const char* getSharedWtPathKey(void) +{ + return gSharedWtPathKey; +} +const char* getSharedPublicCachePathKey(void) +{ + return gSharedPublicCachePathKey; +} +const char* getSharedPublicWtPathKey(void) +{ + return gSharedPublicWtPathKey; +} +const char* getLocalCacheFilePath(void) +{ + return gLocalCacheFilePath; +} diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h index 4000e47..cd87b6f 100644 --- a/src/persistence_client_library_data_organization.h +++ b/src/persistence_client_library_data_organization.h @@ -37,6 +37,13 @@ extern "C" { #include +// define PERS_ORG_ROOT_PATH has been defined in persistence common object + +/// cached path location +#define CACHEPREFIX PERS_ORG_ROOT_PATH "/mnt-c/" +/// write through path location +#define WTPREFIX PERS_ORG_ROOT_PATH "/mnt-wt/" + /// structure used to manage database context typedef struct _PersistenceDbContext_s @@ -138,18 +145,12 @@ enum _PersistenceConstantDef DbusSubMatchSize = 12, /// max character size of the dbus match rule size DbusMatchRuleSize = 300, - /// persistence resource config table max key size - PrctKeySize = PERS_RCT_MAX_LENGTH_RESOURCE_ID, /// persistence resource config table max value size PrctValueSize = sizeof(PersistenceConfigurationKey_s), /// number of persistence resource config tables to store PrctDbTableSize = 1024, /// write buffer size RDRWBufferSize = 1024, - /// database max key size - DbKeySize = PERS_DB_MAX_LENGTH_KEY_NAME, - /// database max value size - DbValueSize = PERS_DB_MAX_SIZE_KEY_DATA, /// database table size DbTableSize = 1024, /// persistence administration service block access @@ -164,16 +165,6 @@ enum _PersistenceConstantDef PasErrorStatus_OK = 0x0002, /// persistence administration service msg return status PasErrorStatus_FAIL = 0x8000, - /// max length of the custom library name and path - CustLibMaxLen = PERS_RCT_MAX_LENGTH_CUSTOM_NAME, - /// max database key length - DbKeyMaxLen = PERS_DB_MAX_LENGTH_KEY_NAME, - /// max database key length - DbResIDMaxLen = PERS_DB_MAX_LENGTH_KEY_NAME, - /// max database path length - DbPathMaxLen = PERS_ORG_MAX_LENGTH_PATH_FILENAME, - /// max application name - MaxAppNameLen = PERS_RCT_MAX_LENGTH_RESPONSIBLE, /// max number of parallel open persistence handles MaxPersHandle = 255, /// length of the config key responsible name @@ -184,104 +175,112 @@ enum _PersistenceConstantDef MaxRctLengthCustom_ID = 64, /// token array size TOKENARRAYSIZE = 255, - /// default limit the key-value data size to 16kB - defaultMaxKeyValDataSize = PERS_DB_MAX_SIZE_KEY_DATA }; +/** + * @brief get the local cache path + * + * @ return the path + */ +const char* getLocalCachePath(void); -// define PERS_ORG_ROOT_PATH comes form persistence common object +/** + * @brief get the local wt path + * + * @ return the path + */ +const char* getLocalWtPath(void); -/// cached path location -#define CACHEPREFIX PERS_ORG_ROOT_PATH "/mnt-c/" -/// write through path location -#define WTPREFIX PERS_ORG_ROOT_PATH "/mnt-wt/" +/** + * @brief get the shared cache path + * + * @ return the path + */ +const char* getSharedCachePath(void); -/// path for the backup location -extern const char* gBackupPrefix; -/// backup filename postfix -extern const char* gBackupPostfix; -/// backup checksum filename postfix -extern const char* gBackupCsPostfix; - -/// size of cached prefix string -extern const int gCPathPrefixSize; -/// size of write through prefix string -extern const int gWTPathPrefixSize; - -/// path prefix for local cached database: /Data/mnt_c/<appId>/<database_name> -extern const char* gLocalCachePath; -/// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name> -extern const char* gLocalWtPath; -/// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name> -extern const char* gSharedCachePath; -/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name> -extern const char* gSharedWtPath; -/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name> -extern const char* gSharedPublicCachePath; -/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name> -extern const char* gSharedPublicWtPath; - -/// path prefix for local cached database: /Data/mnt_c/<appId>/<database_name> -extern const char* gLocalCachePathKey; -/// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name> -extern const char* gLocalWtPathKey; -/// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name> -extern const char* gSharedCachePathKey; -/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name> -extern const char* gSharedWtPathKey; -/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name> -extern const char* gSharedPublicCachePathKey; -/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name> -extern const char* gSharedPublicWtPathKey; - -/// path prefix for local cached files: /Data/mnt_c/<appId>/<user>/>userno>/<seat>/>seatno>/<resource> -extern const char* gLocalCacheFilePath; - -// backup blacklist filename -extern const char* gBackupFilename; +/** + * @brief get the shared wt path + * + * @ return the path + */ +const char* getSharedWtPath(void); -/// application id -extern char gAppId[MaxAppNameLen]; +/** + * @brief get the shared public cache path + * + * @ return the path + */ +const char* getSharedPublicCachePath(void); -/// max key value data size -extern int gMaxKeyValDataSize; +/** + * @brief get shared public wt path + * + * @ return the path + */ +const char* getSharedPublicWtPath(void); -/// the DLT context -extern DltContext gPclDLTContext; +/** + * @brief get the local cache path key + * + * @ return the key + */ +const char* getLocalCachePathKey(void); -/// flag to indicate if client library has been initialized -extern unsigned int gPclInitCounter; +/** + * @brief get local wt path key + * + * @ return the key + */ +const char* getLocalWtPathKey(void); + +/** + * @brief get the shared cache path key + * + * @ return the key + */ +const char* getSharedCachePathKey(void); +/** + * @brief get the shared wt path key + * + * @ return the key + */ +const char* getSharedWtPathKey(void); -/// change signal string -extern const char* gChangeSignal; -/// delete signal string -extern const char* gDeleteSignal; -/// create signal string -extern const char* gCreateSignal; +/** + * @brief get the shared public cache path key + * + * @ return the key + */ +const char* getSharedPublicCachePathKey(void); -// dbus timeout (5 seconds) -extern int gTimeoutMs; +/** + * @brief get the shared public write through path + * + * @ return the key + */ +const char* getSharedPublicWtPathKey(void); + +/** + * @brief get local cache file path + * + * @ return the path + */ +const char* getLocalCacheFilePath(void); + + + +/// application id +extern char gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE] __attribute__ ((visibility ("hidden"))); + +/// the DLT context +extern DltContext gPclDLTContext __attribute__ ((visibility ("hidden"))); + +/// flag to indicate if client library has been initialized +extern unsigned int gPclInitCounter __attribute__ ((visibility ("hidden"))); /// dbus pending return value -extern int gDbusPendingRvalue; - -/// string to identify default plugin -extern const char* gPluginTypeDefault; -/// string to identify early plugin -extern const char* gPluginTypeEarly; -/// string to identify secure plugin -extern const char* gPluginTypeSecure; -/// string to identify emergency plugin -extern const char* gPluginTypeEmergency; -/// string to identify hwinfo plugin -extern const char* gPluginTypeHwInfo; -/// string to identify custom2 plugin -extern const char* gPluginTypeCustom1; -/// string to identify custom2 plugin -extern const char* gPluginTypeCustom2; -/// string to identify custom3 plugin -extern const char* gPluginTypeCustom3; +extern int gDbusPendingRvalue __attribute__ ((visibility ("hidden"))); /** @@ -291,8 +290,8 @@ extern const char* gPluginTypeCustom3; */ extern int(* gChangeNotifyCallback)(pclNotification_s * notifyStruct); -/// character lookup table -extern const char gCharLookup[]; +/// character lookup table used for parsing configuration files +extern const char gCharLookup[] __attribute__ ((visibility ("hidden"))); #ifdef __cplusplus diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index 2dcd7ec..438e7e8 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -44,23 +44,23 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType) { if(gHandlesDBCreated[arrayIdx][dbType] == 0) { - char path[DbPathMaxLen] = {0}; + char path[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; if(PersistencePolicy_wt == dbType) /// write through database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalWt); + snprintf(path, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, plugin_gLocalWt); } else if(PersistencePolicy_wc == dbType) // cached database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalCached); + snprintf(path, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, plugin_gLocalCached); } else if(PersistenceDB_confdefault == dbType) // configurable default database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalConfigurableDefault); + snprintf(path, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, plugin_gLocalConfigurableDefault); } else if(PersistenceDB_default == dbType) // default database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalFactoryDefault); + snprintf(path, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, plugin_gLocalFactoryDefault); } else { @@ -102,7 +102,7 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned { PersDefaultType_e i = PersDefaultType_Configurable; int handleDefaultDB = -1, read_size = EPERS_NOKEY; - char dltMessage[DbPathMaxLen] = {0}; + char dltMessage[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; for(i=(int)PersistenceDB_confdefault; i<(int)PersistenceDB_LastEntry; i++) { @@ -134,11 +134,11 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned { if (PersDefaultType_Configurable == i) { - snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalConfigurableDefault); + snprintf(dltMessage, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, plugin_gLocalConfigurableDefault); } if (PersDefaultType_Factory == i) { - snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalFactoryDefault); + snprintf(dltMessage, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, plugin_gLocalFactoryDefault); } DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("getDefaults - default data will be used for Key"), DLT_STRING(key), DLT_STRING("from"), DLT_STRING(dltMessage)); @@ -627,7 +627,7 @@ int persistence_notify_on_change(const char* key, unsigned int ldbid, unsigned i data.message.params[2] = seat_no; data.message.params[3] = regPolicy; - snprintf(data.message.string, DbKeyMaxLen, "%s", key); + snprintf(data.message.string, PERS_DB_MAX_LENGTH_KEY_NAME, "%s", key); if(regPolicy == Notify_register) { @@ -667,7 +667,7 @@ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* conte data.message.params[2] = context->seat_no; data.message.params[3] = reason; - snprintf(data.message.string, DbKeyMaxLen, "%s", key); + snprintf(data.message.string, PERS_DB_MAX_LENGTH_KEY_NAME, "%s", key); if(-1 == deliverToMainloop(&data) ) { diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c index 06c5a6d..9692e0f 100644 --- a/src/persistence_client_library_dbus_cmd.c +++ b/src/persistence_client_library_dbus_cmd.c @@ -40,6 +40,16 @@ #include #include +/// change signal string +static const char* gChangeSignal = "PersistenceResChange"; +/// delete signal string +static const char* gDeleteSignal = "PersistenceResDelete"; +/// create signal string +static const char* gCreateSignal = "PersistenceResCreate"; + +/// dbus timeout +static int gTimeoutMs = 5000; + // function prototype static void msg_pending_func(DBusPendingCall *call, void *data); diff --git a/src/persistence_client_library_dbus_service.h b/src/persistence_client_library_dbus_service.h index fa42ba3..7b6544b 100644 --- a/src/persistence_client_library_dbus_service.h +++ b/src/persistence_client_library_dbus_service.h @@ -60,7 +60,7 @@ typedef union MainLoopData_u_{ /// unsigned int parameters uint32_t params[4]; /// string parameter - char string[DbKeyMaxLen]; + char string[PERS_DB_MAX_LENGTH_KEY_NAME]; }message; /// the message payload diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index b6312a4..ca8c681 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -36,6 +36,17 @@ #include #include +// path for the backup location +static const char* gBackupPrefix = PERS_ORG_ROOT_PATH "/mnt-backup/"; +// backup filename postfix +static const char* gBackupPostfix = "~"; +// backup checksum filename postfix +static const char* gBackupCsPostfix = "~.crc"; +// size of cached path string +static const int gCPathPrefixSize = sizeof(CACHEPREFIX)-1; +// size of write through string +static const int gWTPathPrefixSize = sizeof(WTPREFIX)-1; + // local function prototype static int pclFileGetDefaultData(int handle, const char* resource_id, int policy); static int pclFileOpenDefaultData(PersistenceInfo_s* dbContext, const char* resource_id); @@ -50,7 +61,7 @@ char* get_raw_string(char* dbKey) char* keyPtr = NULL; int cnt = 0, i = 0; - for(i=0; iconfigKey.policy == PersistencePolicy_wc) { @@ -215,10 +226,10 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch length = gWTPathPrefixSize; } - strncpy(fileSubPath, dbPath+length, DbPathMaxLen); - fileSubPath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination - snprintf(backupPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupPostfix); - snprintf(csumPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupCsPostfix); + strncpy(fileSubPath, dbPath+length, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + fileSubPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination + snprintf(backupPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupPostfix); + snprintf(csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupCsPostfix); // // check valid database context @@ -324,7 +335,7 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch else { // assemble file string for local cached location - snprintf(dbPath, DbPathMaxLen, gLocalCacheFilePath, gAppId, user_no, seat_no, resource_id); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCacheFilePath(), gAppId, user_no, seat_no, resource_id); handle = pclCreateFile(dbPath, 1); set_file_cache_status(handle, 1); @@ -358,20 +369,20 @@ int pclFileOpenDefaultData(PersistenceInfo_s* dbContext, const char* resource_id int flags = pclGetPosixPermission(dbContext->configKey.permission); // check if there is default data available - char pathPrefix[DbPathMaxLen] = { [0 ... DbPathMaxLen-1] = 0}; - char defaultPath[DbPathMaxLen] = { [0 ... DbPathMaxLen-1] = 0}; + char pathPrefix[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; + char defaultPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; if(dbContext->configKey.policy == PersistencePolicy_wc) // create path to default data { - snprintf(pathPrefix, DbPathMaxLen, gLocalCachePath, gAppId); + snprintf(pathPrefix, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCachePath(), gAppId); } else if(dbContext->configKey.policy == PersistencePolicy_wt) { - snprintf(pathPrefix, DbPathMaxLen, gLocalWtPath, gAppId); + snprintf(pathPrefix, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPath(), gAppId); } // first check for c o n f i g u r a b l e default data - snprintf(defaultPath, DbPathMaxLen, "%s%s/%s", pathPrefix, PERS_ORG_CONFIG_DEFAULT_DATA_FOLDER_NAME_, resource_id); + snprintf(defaultPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s/%s", pathPrefix, PERS_ORG_CONFIG_DEFAULT_DATA_FOLDER_NAME_, resource_id); return open(defaultPath, flags); } @@ -387,8 +398,8 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n PersistenceInfo_s dbContext; int shared_DB = 0; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); @@ -461,8 +472,8 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user int shared_DB = 0; PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location dbContext.context.ldbid = ldbid; dbContext.context.seat_no = seat_no; @@ -629,10 +640,10 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int int shared_DB = 0; PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location - char backupPath[DbPathMaxLen] = {0}; // backup file - char csumPath[DbPathMaxLen] = {0}; // checksum file + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + char backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // backup file + char csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // checksum file //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); @@ -653,8 +664,8 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int if( dbContext.configKey.permission != PersistencePermission_ReadOnly && pclBackupNeeded(get_raw_string(dbPath)) == CREATE_BACKUP) { - snprintf(backupPath, DbPathMaxLen-1, "%s%s", dbPath, gBackupPostfix); - snprintf(csumPath, DbPathMaxLen-1, "%s%s", dbPath, gBackupCsPostfix); + snprintf(backupPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s", dbPath, gBackupPostfix); + snprintf(csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s", dbPath, gBackupCsPostfix); if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1) { @@ -736,15 +747,15 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int else { // assemble file string for local cached location - snprintf(dbPath, DbPathMaxLen, gLocalCacheFilePath, gAppId, user_no, seat_no, resource_id); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCacheFilePath(), gAppId, user_no, seat_no, resource_id); handle = get_persistence_handle_idx(); if(handle != -1) { if(handle < MaxPersHandle) { - snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, gBackupPostfix); - snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, gBackupCsPostfix); + snprintf(backupPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, gBackupPostfix); + snprintf(csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, gBackupCsPostfix); __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag @@ -820,25 +831,25 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy) int defaultHandle = -1, rval = 0; // check if there is default data available - char pathPrefix[DbPathMaxLen] = { [0 ... DbPathMaxLen-1] = 0}; - char defaultPath[DbPathMaxLen] = { [0 ... DbPathMaxLen-1] = 0}; + char pathPrefix[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; + char defaultPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; // create path to default data if(policy == PersistencePolicy_wc) { - snprintf(pathPrefix, DbPathMaxLen, gLocalCachePath, gAppId); + snprintf(pathPrefix, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCachePath(), gAppId); } else if(policy == PersistencePolicy_wt) { - snprintf(pathPrefix, DbPathMaxLen, gLocalWtPath, gAppId); + snprintf(pathPrefix, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPath(), gAppId); } // first check for c o n f i g u r a b l e default data - snprintf(defaultPath, DbPathMaxLen, "%s%s/%s", pathPrefix, PERS_ORG_CONFIG_DEFAULT_DATA_FOLDER_NAME_, resource_id); + snprintf(defaultPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s/%s", pathPrefix, PERS_ORG_CONFIG_DEFAULT_DATA_FOLDER_NAME_, resource_id); if(access(defaultPath, F_OK) ) { // if no c o n f i g u r a b l e default data available, check for d e f a u l t data - snprintf(defaultPath, DbPathMaxLen, "%s%s/%s", pathPrefix, PERS_ORG_DEFAULT_DATA_FOLDER_NAME_, resource_id); + snprintf(defaultPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s/%s", pathPrefix, PERS_ORG_DEFAULT_DATA_FOLDER_NAME_, resource_id); } defaultHandle = open(defaultPath, O_RDONLY); diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c index 8fc7a68..47b16ea 100644 --- a/src/persistence_client_library_handle.c +++ b/src/persistence_client_library_handle.c @@ -122,8 +122,8 @@ int set_key_handle_data(int idx, const char* id, unsigned int ldbid, unsigned i item->value.keyHandle.ldbid = ldbid; item->value.keyHandle.user_no = user_no; item->value.keyHandle.seat_no = seat_no; - strncpy(item->value.keyHandle.resource_id, id, DbResIDMaxLen); - item->value.keyHandle.resource_id[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + strncpy(item->value.keyHandle.resource_id, id, PERS_DB_MAX_LENGTH_KEY_NAME); + item->value.keyHandle.resource_id[PERS_DB_MAX_LENGTH_KEY_NAME-1] = '\0'; // Ensures 0-Termination jsw_rbinsert(gKeyHandleTree, item); @@ -158,8 +158,8 @@ int get_key_handle_data(int idx, PersistenceKeyHandle_s* handleStruct) handleStruct->ldbid = foundItem->value.keyHandle.ldbid; handleStruct->user_no = foundItem->value.keyHandle.user_no; handleStruct->seat_no = foundItem->value.keyHandle.seat_no; - strncpy(handleStruct->resource_id, foundItem->value.keyHandle.resource_id, DbResIDMaxLen); - handleStruct->resource_id[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + strncpy(handleStruct->resource_id, foundItem->value.keyHandle.resource_id, PERS_DB_MAX_LENGTH_KEY_NAME); + handleStruct->resource_id[PERS_DB_MAX_LENGTH_KEY_NAME-1] = '\0'; // Ensures 0-Termination rval = 0; } free(item); @@ -237,11 +237,11 @@ int set_file_handle_data(int idx, PersistencePermission_e permission, const char item->value.fileHandle.userId = 0; // default value item->value.fileHandle.filePath = filePath; - strncpy(item->value.fileHandle.backupPath, backup, DbPathMaxLen); - item->value.fileHandle.backupPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + strncpy(item->value.fileHandle.backupPath, backup, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination - strncpy(item->value.fileHandle.csumPath, csumPath, DbPathMaxLen); - item->value.fileHandle.csumPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + strncpy(item->value.fileHandle.csumPath, csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination jsw_rbinsert(gFileHandleTree, item); @@ -433,10 +433,10 @@ void set_file_cache_status(int idx, int status) item->value.fileHandle.userId = 0; // default value item->value.fileHandle.filePath = NULL; - memset(item->value.fileHandle.csumPath , 0, DbResIDMaxLen); - item->value.fileHandle.csumPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination - memset(item->value.fileHandle.backupPath, 0, DbResIDMaxLen); - item->value.fileHandle.backupPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + memset(item->value.fileHandle.csumPath , 0, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination + memset(item->value.fileHandle.backupPath, 0, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination jsw_rbinsert(gFileHandleTree, item); } @@ -509,10 +509,10 @@ void set_file_user_id(int idx, int userID) item->value.fileHandle.cacheStatus = -1; // set to -1 by default item->value.fileHandle.filePath = NULL; - memset(item->value.fileHandle.csumPath , 0, DbResIDMaxLen); - item->value.fileHandle.csumPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination - memset(item->value.fileHandle.backupPath, 0, DbResIDMaxLen); - item->value.fileHandle.backupPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + memset(item->value.fileHandle.csumPath , 0, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination + memset(item->value.fileHandle.backupPath, 0, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination jsw_rbinsert(gFileHandleTree, item); } @@ -592,10 +592,10 @@ int set_ossfile_handle_data(int idx, PersistencePermission_e permission, int bac item->value.fileHandle.userId = 0; // default value item->value.fileHandle.filePath = filePath; - strncpy(item->value.fileHandle.backupPath, backup, DbPathMaxLen); - item->value.fileHandle.backupPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination - strncpy(item->value.fileHandle.csumPath, csumPath, DbPathMaxLen); - item->value.fileHandle.csumPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + strncpy(item->value.fileHandle.backupPath, backup, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination + strncpy(item->value.fileHandle.csumPath, csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination jsw_rbinsert(gOssFileHandleTree, item); @@ -713,11 +713,11 @@ void set_ossfile_file_path(int idx, char* file) item->value.fileHandle.permission = -1; item->value.fileHandle.cacheStatus = -1; // set to -1 by default item->value.fileHandle.userId = 0; // default value - memset(item->value.fileHandle.csumPath , 0, DbResIDMaxLen); - item->value.fileHandle.csumPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + memset(item->value.fileHandle.csumPath , 0, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination - memset(item->value.fileHandle.backupPath, 0, DbResIDMaxLen); - item->value.fileHandle.backupPath[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + memset(item->value.fileHandle.backupPath, 0, PERS_ORG_MAX_LENGTH_PATH_FILENAME); + item->value.fileHandle.backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination jsw_rbinsert(gFileHandleTree, item); } diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h index 1b16ae3..a9085f0 100644 --- a/src/persistence_client_library_handle.h +++ b/src/persistence_client_library_handle.h @@ -32,7 +32,7 @@ typedef struct _PersistenceKeyHandle_s /// Seat No unsigned int seat_no; /// Resource ID - char resource_id[DbResIDMaxLen]; + char resource_id[PERS_DB_MAX_LENGTH_KEY_NAME]; } PersistenceKeyHandle_s; @@ -48,9 +48,9 @@ typedef struct _PersistenceFileHandle_s /// the user id int userId; /// path to the backup file - char backupPath[DbPathMaxLen]; + char backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME]; /// path to the checksum file - char csumPath[DbPathMaxLen]; + char csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME]; /// the file path char* filePath; } PersistenceFileHandle_s; diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 5a30519..8c1a8c0 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -24,6 +24,10 @@ #include "persistence_client_library_db_access.h" +/// max key value data size [default 16kB] +static int gMaxKeyValDataSize = PERS_DB_MAX_SIZE_KEY_DATA; + + // function declaration static int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy); static int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, @@ -48,8 +52,8 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u { PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location dbContext.context.ldbid = ldbid; dbContext.context.seat_no = seat_no; @@ -315,8 +319,8 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ { PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location dbContext.context.ldbid = ldbid; dbContext.context.seat_no = seat_no; @@ -363,8 +367,8 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user { PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location dbContext.context.ldbid = ldbid; dbContext.context.seat_no = seat_no; @@ -413,8 +417,8 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use { PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location dbContext.context.ldbid = ldbid; dbContext.context.seat_no = seat_no; @@ -471,8 +475,8 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us { PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location dbContext.context.ldbid = ldbid; dbContext.context.seat_no = seat_no; @@ -489,7 +493,7 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { if( (dbContext.configKey.storage == PersistenceStorage_shared) - && (0 != strncmp(dbContext.configKey.reponsible, gAppId, MaxAppNameLen) ) ) + && (0 != strncmp(dbContext.configKey.reponsible, gAppId, PERS_RCT_MAX_LENGTH_RESPONSIBLE) ) ) { data_size = EPERS_NOT_RESP_APP; } @@ -571,8 +575,8 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int PersistenceInfo_s dbContext; // unsigned int hash_val_data = 0; - char dbKey[DbKeyMaxLen] = {0}; // database key - char dbPath[DbPathMaxLen] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location dbContext.context.ldbid = ldbid; dbContext.context.seat_no = seat_no; diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index 44c9a8d..60526fb 100644 --- a/src/persistence_client_library_prct_access.c +++ b/src/persistence_client_library_prct_access.c @@ -76,7 +76,7 @@ int get_resource_cfg_table_by_idx(int i) { int idx = -1; - if(i > 0 && i < PrctDbTableSize) + if(i >= 0 && i < PrctDbTableSize) { idx = gResource_table[i]; } @@ -105,18 +105,18 @@ int get_resource_cfg_table(PersistenceRCT_e rct, int group) { if(gResourceOpen[arrayIdx] == 0) // check if database is already open { - char filename[DbPathMaxLen] = { [0 ... DbPathMaxLen-1] = 0}; + char filename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; switch(rct) // create db name { case PersistenceRCT_local: - snprintf(filename, DbPathMaxLen, gLocalWtPathKey, gAppId, plugin_gResTableCfg); + snprintf(filename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), gAppId, plugin_gResTableCfg); break; case PersistenceRCT_shared_public: - snprintf(filename, DbPathMaxLen, gSharedPublicWtPathKey, gAppId, plugin_gResTableCfg); + snprintf(filename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedPublicWtPathKey(), gAppId, plugin_gResTableCfg); break; case PersistenceRCT_shared_group: - snprintf(filename, DbPathMaxLen, gSharedWtPathKey, gAppId, group, plugin_gResTableCfg); + snprintf(filename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedWtPathKey(), gAppId, group, plugin_gResTableCfg); break; default: DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("gRCT - no valid PersistenceRCT_e")); @@ -193,7 +193,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign dbContext->configKey.policy = PersistencePolicy_wc; dbContext->configKey.storage = PersistenceStorage_local; dbContext->configKey.permission = PersistencePermission_ReadWrite; - dbContext->configKey.max_size = defaultMaxKeyValDataSize; + dbContext->configKey.max_size = PERS_DB_MAX_SIZE_KEY_DATA; if(isFile == PersistenceResourceType_file) { dbContext->configKey.type = PersistenceResourceType_file; @@ -234,7 +234,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if((dbContext->context.user_no == 0) && (dbContext->context.seat_no == 0)) { // Node is added in front of the resource ID as the key string. - snprintf(dbKey, DbKeyMaxLen, "%s/%s", plugin_gNode, resource_id); + snprintf(dbKey, PERS_DB_MAX_LENGTH_KEY_NAME, "%s/%s", plugin_gNode, resource_id); } else { @@ -242,12 +242,12 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(dbContext->context.seat_no == 0) { // /User/ is added in front of the resource ID as the key string. - snprintf(dbKey, DbKeyMaxLen, "%s%d/%s", plugin_gUser, dbContext->context.user_no, resource_id); + snprintf(dbKey, PERS_DB_MAX_LENGTH_KEY_NAME, "%s%d/%s", plugin_gUser, dbContext->context.user_no, resource_id); } else { // /User//Seat/ is added in front of the resource ID as the key string. - snprintf(dbKey, DbKeyMaxLen, "%s%d%s%d/%s", plugin_gUser, dbContext->context.user_no, plugin_gSeat, dbContext->context.seat_no, resource_id); + snprintf(dbKey, PERS_DB_MAX_LENGTH_KEY_NAME, "%s%d%s%d/%s", plugin_gUser, dbContext->context.user_no, plugin_gSeat, dbContext->context.seat_no, resource_id); } } storePolicy = PersistenceStorage_local; @@ -262,11 +262,11 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c // /User/ and /Seat/ are add after / if there are different than 0. if(dbContext->context.seat_no != 0) { - snprintf(dbKey, DbKeyMaxLen, "/%x%s%d%s%d/%s", dbContext->context.ldbid, plugin_gUser, dbContext->context.user_no, plugin_gSeat, dbContext->context.seat_no, resource_id); + snprintf(dbKey, PERS_DB_MAX_LENGTH_KEY_NAME, "/%x%s%d%s%d/%s", dbContext->context.ldbid, plugin_gUser, dbContext->context.user_no, plugin_gSeat, dbContext->context.seat_no, resource_id); } else { - snprintf(dbKey, DbKeyMaxLen, "/%x%s%d/%s", dbContext->context.ldbid, plugin_gUser, dbContext->context.user_no, resource_id); + snprintf(dbKey, PERS_DB_MAX_LENGTH_KEY_NAME, "/%x%s%d/%s", dbContext->context.ldbid, plugin_gUser, dbContext->context.user_no, resource_id); } storePolicy = PersistenceStorage_local; } @@ -284,16 +284,16 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(PersistencePolicy_wc == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gSharedCachePath, gAppId, dbContext->context.ldbid, ""); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedCachePath(), gAppId, dbContext->context.ldbid, ""); else - snprintf(dbPath, DbPathMaxLen, gSharedCachePathKey, gAppId, dbContext->context.ldbid, dbKey); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedCachePathKey(), gAppId, dbContext->context.ldbid, dbKey); } else if(PersistencePolicy_wt == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gSharedWtPath, gAppId, dbContext->context.ldbid); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedWtPath(), gAppId, dbContext->context.ldbid); else - snprintf(dbPath, DbPathMaxLen, gSharedWtPathKey, gAppId, dbContext->context.ldbid, dbKey); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedWtPathKey(), gAppId, dbContext->context.ldbid, dbKey); } } else @@ -304,16 +304,16 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(PersistencePolicy_wc == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gSharedPublicCachePath, gAppId, ""); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedPublicCachePath(), gAppId, ""); else - snprintf(dbPath, DbPathMaxLen, gSharedPublicCachePathKey, gAppId, dbKey); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedPublicCachePathKey(), gAppId, dbKey); } else if(PersistencePolicy_wt == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPath, gAppId, ""); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedPublicWtPath(), gAppId, ""); else - snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPathKey, gAppId, dbKey); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getSharedPublicWtPathKey(), gAppId, dbKey); } } storePolicy = PersistenceStorage_shared; // we have a shared database @@ -324,16 +324,16 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(PersistencePolicy_wc == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gLocalCachePath, gAppId, ""); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCachePath(), gAppId, ""); else - snprintf(dbPath, DbPathMaxLen, gLocalCachePathKey, gAppId, dbKey); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCachePathKey(), gAppId, dbKey); } else if(PersistencePolicy_wt == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen-1, gLocalWtPath, gAppId, ""); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, getLocalWtPath(), gAppId, ""); else - snprintf(dbPath, DbPathMaxLen-1, gLocalWtPathKey, gAppId, dbKey); + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, getLocalWtPathKey(), gAppId, dbKey); } storePolicy = PersistenceStorage_local; // we have a local database -- cgit v1.2.1