summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2015-01-23 15:48:34 +0100
committerIngo Huerner <ingo.huerner@xse.de>2015-01-23 15:48:34 +0100
commit16239ca64c53eab04050a8a0672ef2520dad5773 (patch)
tree8068d472efba3d56642f13184a4b59323fa23084
parent84210e9a13cf8b6b7496d0ed1615377a142cfe53 (diff)
downloadpersistence-client-library-16239ca64c53eab04050a8a0672ef2520dad5773.tar.gz
Further code improvements
-rw-r--r--src/persistence_client_library.c5
-rw-r--r--src/persistence_client_library_backup_filelist.c185
-rw-r--r--src/persistence_client_library_backup_filelist.h17
-rw-r--r--src/persistence_client_library_custom_loader.c16
-rw-r--r--src/persistence_client_library_custom_loader.h5
-rw-r--r--src/persistence_client_library_data_organization.h2
-rw-r--r--src/persistence_client_library_db_access.c69
-rw-r--r--src/persistence_client_library_db_access.h14
-rw-r--r--src/persistence_client_library_dbus_cmd.c19
-rw-r--r--src/persistence_client_library_dbus_service.c21
-rw-r--r--src/persistence_client_library_file.c43
-rw-r--r--src/persistence_client_library_handle.c5
-rw-r--r--src/persistence_client_library_key.c8
-rw-r--r--src/persistence_client_library_lc_interface.c6
-rw-r--r--src/persistence_client_library_pas_interface.c6
-rw-r--r--src/persistence_client_library_prct_access.c12
-rw-r--r--src/persistence_client_library_tree_helper.c70
-rw-r--r--src/persistence_client_library_tree_helper.h40
18 files changed, 229 insertions, 314 deletions
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index e6ad3af..edbeeae 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -40,7 +40,7 @@
/// debug log and trace (DLT) setup
-DLT_DECLARE_CONTEXT(gPclDLTContext);
+DLT_DECLARE_CONTEXT(gPclDLTContext)
/// global variable to store lifecycle shutdown mode
@@ -146,11 +146,10 @@ int pclInitLibrary(const char* appName, int shutdownMode)
static int private_pclInitLibrary(const char* appName, int shutdownMode)
{
int rval = 1;
+ char blacklistPath[DbPathMaxLen] = {0};
gShutdownMode = shutdownMode;
- char blacklistPath[DbPathMaxLen] = {0};
-
doInitAppcheck(appName); // check if we have a trusted application
#if USE_FILECACHE
diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c
index a419e42..03f6fec 100644
--- a/src/persistence_client_library_backup_filelist.c
+++ b/src/persistence_client_library_backup_filelist.c
@@ -22,12 +22,10 @@
#include "rbtree.h"
-
#if USE_FILECACHE
#include <persistence_file_cache.h>
#endif
-
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
@@ -35,55 +33,36 @@
#include <sys/sendfile.h>
-/// structure definition for a key value item
-typedef struct _key_value_s
-{
- unsigned int key;
- char* value;
-}key_value_s;
-
-
-static void key_val_rel(void *p);
-
-static void* key_val_dup(void *p);
-
static char* gpTokenArray[TOKENARRAYSIZE] = {0};
-/// the rb tree
-static jsw_rbtree_t *gRb_tree_bl = NULL;
-
// local function prototypes
static int need_backup_key(unsigned int key);
-static int key_val_cmp(const void *p1, const void *p2 );
+int pclRecoverFromBackup(int backupFd, const char* original);
+
static void fillFileBackupCharTokenArray(unsigned int customConfigFileSize, char* fileMap)
{
unsigned int i=0;
- int tokenCounter = 0;
- int blankCount=0;
+ int tokenCounter = 0, blankCount = 0;
char* tmpPointer = fileMap;
- gpTokenArray[blankCount] = tmpPointer; // set the first pointer to the start of the file
+ gpTokenArray[0] = tmpPointer; // set the first pointer to the start of the file
blankCount++;
while(i < customConfigFileSize)
{
- if( ((int)(*tmpPointer) < 127)
- && ((int)*tmpPointer >= 0))
+ if(1 != gCharLookup[(int)*tmpPointer])
{
- if(1 != gCharLookup[(int)*tmpPointer])
- {
- *tmpPointer = 0;
+ *tmpPointer = 0;
- if(blankCount >= TOKENARRAYSIZE) // check if we are at the end of the token array
- {
- break;
- }
- gpTokenArray[blankCount] = tmpPointer+1;
- blankCount++;
- tokenCounter++;
+ if(blankCount >= TOKENARRAYSIZE) // check if we are at the end of the token array
+ {
+ break;
}
+ gpTokenArray[blankCount] = tmpPointer+1;
+ blankCount++;
+ tokenCounter++;
}
tmpPointer++;
i++;
@@ -102,7 +81,7 @@ static void createAndStoreFileNames()
if(gRb_tree_bl != NULL)
{
- while( i < TOKENARRAYSIZE )
+ while( i < (TOKENARRAYSIZE-1) )
{
if(gpTokenArray[i+1] != 0 )
{
@@ -222,83 +201,18 @@ int need_backup_key(unsigned int key)
}
-/// compare function for tree key_value_s item
-int key_val_cmp(const void *p1, const void *p2 )
-{
- int rval = -1;
- key_value_s* first;
- key_value_s* second;
-
- first = (key_value_s*)p1;
- second = (key_value_s*)p2;
-
- if(second->key == first->key)
- {
- rval = 0;
- }
- else if(second->key < first->key)
- {
- rval = -1;
- }
- else
- {
- rval = 1;
- }
-
- return rval;
- }
-
-/// duplicate function for key_value_s item
-void* key_val_dup(void *p)
-{
- int value_size = 0;
- key_value_s* src = NULL;
- key_value_s* dst = NULL;
-
- src = (key_value_s*)p;
- value_size = strlen(src->value)+1;
-
- // allocate memory for node
- dst = malloc(sizeof(key_value_s));
- if(dst != NULL)
- {
- dst->key = src->key; // duplicate hash key
-
- dst->value = malloc(value_size); // duplicate value
- if(dst->value != NULL)
- strncpy(dst->value, src->value, value_size);
- }
-
- return dst;
-}
-
-/// release function for key_value_s item
-void key_val_rel(void *p )
-{
- key_value_s* rel = NULL;
- rel = (key_value_s*)p;
-
- if(rel != NULL)
- {
- if(rel->value != NULL)
- free(rel->value);
-
- free(rel);
- }
-}
-
-
static int pclBackupDoFileCopy(int srcFd, int dstFd)
{
struct stat buf;
- int rval = 0;
+ int rval = -1;
memset(&buf, 0, sizeof(buf));
- (void)fstat(srcFd, &buf);
- rval = (int)sendfile(dstFd, srcFd, 0, buf.st_size);
-
- // Reset file position pointer of destination file 'dstFd'
- lseek(dstFd, 0, SEEK_SET);
+ if(fstat(srcFd, &buf) != -1)
+ {
+ rval = (int)sendfile(dstFd, srcFd, 0, buf.st_size);
+ // Reset file position pointer of destination file 'dstFd'
+ lseek(dstFd, 0, SEEK_SET);
+ }
return rval;
}
@@ -307,13 +221,12 @@ static int pclBackupDoFileCopy(int srcFd, int dstFd)
int pclCreateFile(const char* path, int chached)
{
const char* delimiters = "/\n"; // search for blank and end of line
- char* tokenArray[24];
+ char* tokenArray[24] = {0};
char thePath[DbPathMaxLen] = {0};
- int numTokens = 0, i = 0, validPath = 1;
- int handle = -1;
+ int numTokens = 0, i = 0, validPath = 1, handle = -1;
- thePath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
strncpy(thePath, path, DbPathMaxLen);
+ thePath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
tokenArray[numTokens++] = strtok(thePath, delimiters);
while(tokenArray[numTokens-1] != NULL )
@@ -375,8 +288,7 @@ int pclCreateFile(const char* path, int chached)
int pclVerifyConsistency(const char* origPath, const char* backupPath, const char* csumPath, int openFlags)
{
- int handle = 0, readSize = 0;
- int backupAvail = 0, csumAvail = 0;
+ int handle = 0, readSize = 0, backupAvail = 0, csumAvail = 0;
int fdCsum = 0, fdBackup = 0;
char origCsumBuf[ChecksumBufSize] = {0};
@@ -537,9 +449,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
int pclRecoverFromBackup(int backupFd, const char* original)
{
- int handle = 0;
-
- handle = open(original, O_TRUNC | O_RDWR);
+ int handle = open(original, O_TRUNC | O_RDWR);
if(handle != -1)
{
if(pclBackupDoFileCopy(backupFd, handle) == -1) // copy data from one file to another
@@ -555,15 +465,15 @@ int pclRecoverFromBackup(int backupFd, const char* original)
int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const char* csumBuf)
{
- int dstFd = 0, csfd = 0;
- int readSize = -1;
+ int dstFd = 0, csfd = 0, readSize = -1;
if(access(dstPath, F_OK) != 0)
{
int handle = -1;
char pathToCreate[DbPathMaxLen] = {0};
- pathToCreate[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
+
strncpy(pathToCreate, dstPath, DbPathMaxLen);
+ pathToCreate[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
handle = pclCreateFile(pathToCreate, 0);
close(handle); // don't need the open file
@@ -627,29 +537,34 @@ int pclCalcCrc32Csum(int fd, char crc32sum[])
char* buf;
struct stat statBuf;
- (void)fstat(fd, &statBuf);
- buf = malloc((unsigned int)statBuf.st_size);
-
- if(buf != 0)
+ if(fstat(fd, &statBuf) != -1)
{
- off_t curPos = 0;
- curPos = lseek(fd, 0, SEEK_CUR); // remember the current position
+ buf = malloc((unsigned int)statBuf.st_size);
- if(curPos != 0)
+ if(buf != 0)
{
- lseek(fd, 0, SEEK_SET); // set to beginning of the file
- }
+ off_t curPos = 0;
+ curPos = lseek(fd, 0, SEEK_CUR); // remember the current position
- while((rval = read(fd, buf, statBuf.st_size)) > 0)
- {
- unsigned int crc = 0;
- crc = pclCrc32(crc, (unsigned char*)buf, statBuf.st_size);
- (void)snprintf(crc32sum, ChecksumBufSize-1, "%x", crc);
- }
+ if(curPos != 0)
+ {
+ lseek(fd, 0, SEEK_SET); // set to beginning of the file
+ }
- lseek(fd, curPos, SEEK_SET); // set back to the position
+ while((rval = read(fd, buf, statBuf.st_size)) > 0)
+ {
+ unsigned int crc = 0;
+ crc = pclCrc32(crc, (unsigned char*)buf, statBuf.st_size);
+ (void)snprintf(crc32sum, ChecksumBufSize-1, "%x", crc);
+ }
- free(buf);
+ lseek(fd, curPos, SEEK_SET); // set back to the position
+ free(buf);
+ }
+ else
+ {
+ rval = -1;
+ }
}
else
{
diff --git a/src/persistence_client_library_backup_filelist.h b/src/persistence_client_library_backup_filelist.h
index 5917945..56e1d44 100644
--- a/src/persistence_client_library_backup_filelist.h
+++ b/src/persistence_client_library_backup_filelist.h
@@ -20,6 +20,7 @@
*/
#include "persistence_client_library_handle.h"
+#include "persistence_client_library_tree_helper.h"
/**
@@ -33,7 +34,8 @@ int readBlacklistConfigFile(const char* filename);
/**
- * @brief create the file
+ * @brief Create the file under the given path.
+ * If the path does not exist, the folders will be created
*
* @param path of the file to be created
* @param cached 1 if file should be cached,
@@ -45,7 +47,8 @@ int pclCreateFile(const char* path, int chached);
/**
- * @brief create a backup copy of a file
+ * @brief Create a backup copy of a file under the given path.
+ * If the path does not exist, the folders will be created.
*
* @param srcPath the path of the file
* @param srcfd the file descriptor of the file
@@ -57,16 +60,6 @@ int pclCreateFile(const char* path, int chached);
int pclCreateBackup(const char* srcPath, int srcfd, const char* csumPath, const char* csumBuf);
-/**
- * @brief recover file form backup
- *
- * @param backupFd the file descriptor of the backup file
- * @param original the path of the file to be recovered
- *
- * @return 0 on success -1 on error
- */
-int pclRecoverFromBackup(int backupFd, const char* original);
-
/**
* @brief calculate crc32 checksum
diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c
index a634bd4..c0bb85e 100644
--- a/src/persistence_client_library_custom_loader.c
+++ b/src/persistence_client_library_custom_loader.c
@@ -44,12 +44,11 @@ int(* gPlugin_callback_async_t)(int errcode);
static void fillCustomCharTokenArray(unsigned int customConfigFileSize, char* fileMap)
{
- unsigned int i=0;
- int customTokenCounter = 0;
- int blankCount=0;
+ unsigned int i = 0;
+ int customTokenCounter = 0, blankCount=0;
char* tmpPointer = fileMap;
- gpCustomTokenArray[blankCount] = tmpPointer; // set the first pointer to the start of the file
+ gpCustomTokenArray[0] = tmpPointer; // set the first pointer to the start of the file
blankCount++;
while(i < customConfigFileSize)
@@ -257,7 +256,7 @@ int get_custom_libraries()
fillCustomCharTokenArray(buffer.st_size, customConfFileMap);
- while( i < TOKENARRAYSIZE )
+ while( i < (TOKENARRAYSIZE-3) )
{
if(gpCustomTokenArray[i] != 0 && gpCustomTokenArray[i+1] != 0 && gpCustomTokenArray[i+2] != 0 &&gpCustomTokenArray[i+3] != 0 )
{
@@ -270,13 +269,6 @@ int get_custom_libraries()
gCustomLibArray[libId].loadingType = getLoadingType(gpCustomTokenArray[i+2]);
gCustomLibArray[libId].initFunction = getInitType(gpCustomTokenArray[i+3]);
gCustomLibArray[libId].valid = 1; // marks as valid;
- #if 0
- // debug
- printf(" 1. => %s => %d \n", gpCustomTokenArray[i], libId);
- printf(" 2. => %s => %s \n", gpCustomTokenArray[i+1], gCustomLibArray[libId].libname);
- printf(" 3. => %s => %d \n", gpCustomTokenArray[i+2], (int)gCustomLibArray[libId].initFunction);
- printf(" 4. => %s => %d \n\n", gpCustomTokenArray[i+3], (int)gCustomLibArray[libId].loadingType);
- #endif
}
else
{
diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h
index 49be2b9..8829455 100644
--- a/src/persistence_client_library_custom_loader.h
+++ b/src/persistence_client_library_custom_loader.h
@@ -26,6 +26,7 @@
/// enumerator used to identify the policy to manage the data
typedef enum _PersistenceCustomLibs_e
{
+ /// used for the default library
PersCustomLib_default = 0,
/// predefined custom library for early persistence
PersCustomLib_early = 1,
@@ -50,11 +51,11 @@ typedef enum _PersistenceCustomLibs_e
} PersistenceCustomLibs_e;
-/// enumerator fo custom library defines
+/// enumerator for custom library defines
typedef enum _PersCustomLibDefines_e
{
/// the custom library path size
- PersCustomPathSize = 12
+ PersCustomPathSize = 24
} PersCustomLibDefines_e;
diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h
index c735ef9..e8cc692 100644
--- a/src/persistence_client_library_data_organization.h
+++ b/src/persistence_client_library_data_organization.h
@@ -99,7 +99,7 @@ typedef enum _PersNotifyRegPolicy_e
Notify_unregister = 1,
/// last entry
- Notify_lastEntry,
+ Notify_lastEntry
} PersNotifyRegPolicy_e;
diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c
index adcd4ec..4137282 100644
--- a/src/persistence_client_library_db_access.c
+++ b/src/persistence_client_library_db_access.c
@@ -37,30 +37,9 @@ static int gHandlesDBCreated[DbTableSize][PersistenceDB_LastEntry] = { {0} };
int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, unsigned int reason);
-#if 0
-char* pers_get_raw_key(char *key)
-{
- char *temp = NULL;
- char *rawKey = key;
-
- temp = strrchr(key, (int)'/');
-
- if (NULL != temp)
- {
- rawKey = temp + 1;
- }
-
- return rawKey;
-}
-#endif
-
-
-
-
static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType)
{
- int arrayIdx = 0;
- int handleDB = -1;
+ int arrayIdx = 0, handleDB = -1;
// create array index: index is a combination of resource configuration table type and group
arrayIdx = info->configKey.storage + info->context.ldbid ;
@@ -126,8 +105,7 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType)
int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size, PersGetDefault_e job)
{
PersDefaultType_e i = PersDefaultType_Configurable;
- int handleDefaultDB = -1;
- int read_size = EPERS_NOKEY;
+ int handleDefaultDB = -1, read_size = EPERS_NOKEY;
char dltMessage[DbPathMaxLen] = {0};
for(i=(int)PersistenceDB_confdefault; i<(int)PersistenceDB_LastEntry; i++)
@@ -184,29 +162,6 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned
-#if 0
-void database_close(PersistenceInfo_s* info)
-{
- int arrayIdx = info->configKey.storage + info->context.ldbid;
-
- if(info->configKey.storage <= PersistenceStorage_shared )
- {
- int iErrorCode = plugin_persComDbClose(gHandlesDB[arrayIdx][info->configKey.policy]) ;
- if (iErrorCode < 0)
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close ==> persComDbClose() failed"));
- }
- else
- {
- gHandlesDBCreated[arrayIdx][info->configKey.policy] = 0;
- }
- }
- else
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close ==> invalid storage type"), DLT_INT(info->context.ldbid ));
- }
-}
-#endif
void database_close_all()
{
int i = 0, j = 0;
@@ -235,8 +190,7 @@ void database_close_all()
int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size)
{
- int read_size = -1;
- int ret_defaults = -1;
+ int read_size = -1, ret_defaults = -1;
if( PersistenceStorage_shared == info->configKey.storage
|| PersistenceStorage_local == info->configKey.storage)
@@ -374,7 +328,6 @@ int persistence_set_data(char* dbPath, char* key, const char* resource_id, Persi
}
}
}
-
}
else
{
@@ -384,8 +337,8 @@ int persistence_set_data(char* dbPath, char* key, const char* resource_id, Persi
}
else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library
{
- int available = 0;
- int idx = custom_client_name_to_id(dbPath, 1);
+ int available = 0, idx = custom_client_name_to_id(dbPath, 1);
+
if(idx < PersCustomLib_LastEntry )
{
if(gPersCustomFuncs[idx].custom_plugin_set_data == NULL)
@@ -462,8 +415,7 @@ int persistence_set_data(char* dbPath, char* key, const char* resource_id, Persi
int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info)
{
- int read_size = -1;
- int ret_defaults = -1;
+ int read_size = -1, ret_defaults = -1;
if( PersistenceStorage_shared == info->configKey.storage
|| PersistenceStorage_local == info->configKey.storage)
@@ -481,8 +433,8 @@ int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, P
}
else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library
{
- int available = 0;
- int idx = custom_client_name_to_id(dbPath, 1);
+ int available = 0, idx = custom_client_name_to_id(dbPath, 1);
+
if(idx < PersCustomLib_LastEntry )
{
if(gPersCustomFuncs[idx].custom_plugin_get_size == NULL )
@@ -595,8 +547,8 @@ int persistence_delete_data(char* dbPath, char* key, const char* resource_id, Pe
}
else // custom storage implementation via custom library
{
- int available = 0;
- int idx = custom_client_name_to_id(dbPath, 1);
+ int available = 0, idx = custom_client_name_to_id(dbPath, 1);
+
if(idx < PersCustomLib_LastEntry)
{
if(gPersCustomFuncs[idx].custom_plugin_delete_data == NULL )
@@ -752,7 +704,6 @@ void pers_rct_close_all()
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("prepShtdwn - Err close db => index:"), DLT_INT(i));
}
-
invalidate_resource_cfg_table(i);
}
}
diff --git a/src/persistence_client_library_db_access.h b/src/persistence_client_library_db_access.h
index ba825f2..5a8eb35 100644
--- a/src/persistence_client_library_db_access.h
+++ b/src/persistence_client_library_db_access.h
@@ -28,12 +28,10 @@ extern "C" {
#include "persistence_client_library_data_organization.h"
+#include "../include/persistence_client_library_key.h"
-//#include "persistence_client_library_rc_table.h"
#include <persComRct.h>
-#include "../include/persistence_client_library_key.h"
-
/// default database definitions
@@ -156,15 +154,6 @@ int persistence_delete_data(char* dbPath, char* key, const char* resource_id, Pe
/**
- * @brief close the database for the given storage type
- *
- * @param info persistence information
- */
-//void database_close(PersistenceInfo_s* info);
-
-
-
-/**
* @brief close all databases
*/
void database_close_all();
@@ -205,6 +194,7 @@ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* conte
*/
void pers_rct_close_all();
+
#ifdef __cplusplus
}
#endif
diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c
index c471fea..66c6d2c 100644
--- a/src/persistence_client_library_dbus_cmd.c
+++ b/src/persistence_client_library_dbus_cmd.c
@@ -15,7 +15,7 @@
* @brief Implementation of the persistence client library dbus commands.
* @see
*/
- /* For dlclose() */
+
#include "persistence_client_library_dbus_cmd.h"
#include "persistence_client_library_handle.h"
@@ -128,15 +128,12 @@ void process_send_notification_signal(DBusConnection* conn, unsigned int notifyL
snprintf(seatArray, DbusSubMatchSize, "%u", notifySeatNo);
//printf("process_send_Notification_Signal => key: %s | lbid: %d | gUserNo: %d | gSeatNo: %d | gReason: %d \n", notifyKey, notifyLdbid, notifyUserNo, notifySeatNo, notifyReason);
- message = dbus_message_new_signal(gPersAdminConsumerPath,
- gDbusPersAdminConsInterface,
- notifyReasonString);
+ message = dbus_message_new_signal(gPersAdminConsumerPath, gDbusPersAdminConsInterface, notifyReasonString);
ret = dbus_message_append_args(message, DBUS_TYPE_STRING, &pnotifyKey,
DBUS_TYPE_STRING, &pldbidArra,
DBUS_TYPE_STRING, &puserArray,
- DBUS_TYPE_STRING, &pseatArray,
- DBUS_TYPE_INVALID);
+ DBUS_TYPE_STRING, &pseatArray, DBUS_TYPE_INVALID);
if(ret == TRUE)
{
if(conn != NULL) // Send the signal
@@ -262,8 +259,7 @@ void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int
if(message != NULL)
{
dbus_message_append_args(message, DBUS_TYPE_UINT32, &requestID,
- DBUS_TYPE_INT32, &status,
- DBUS_TYPE_INVALID);
+ DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID);
if(!dbus_connection_send(conn, message, 0))
{
@@ -315,8 +311,7 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati
dbus_message_append_args(message, DBUS_TYPE_STRING, &busName, // bus name
DBUS_TYPE_STRING, &gPersAdminConsumerPath,
DBUS_TYPE_INT32, &notificationFlag,
- DBUS_TYPE_UINT32, &gTimeoutMs,
- DBUS_TYPE_INVALID);
+ DBUS_TYPE_UINT32, &gTimeoutMs, DBUS_TYPE_INVALID);
dbus_connection_send_with_reply(conn, // the connection
message, // the message to write
@@ -420,9 +415,7 @@ void process_send_lifecycle_request(DBusConnection* conn, unsigned int requestId
if(message != NULL)
{
dbus_message_append_args(message, DBUS_TYPE_INT32, &requestId,
- DBUS_TYPE_INT32, &status,
- DBUS_TYPE_INVALID);
-
+ DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID);
if(!dbus_connection_send(conn, message, 0))
{
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index 4232bbd..8081758 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -86,7 +86,7 @@ typedef struct SPollInfo
/// polling information
-static tPollInfo gPollInfo; /// polling information
+static tPollInfo gPollInfo;
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
@@ -151,9 +151,7 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec
DBusError error;
DBusMessage *reply;
dbus_error_init (&error);
- char* ldbid;
- char* user_no;
- char* seat_no;
+ char *ldbid, *user_no, *seat_no;
if (!dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &notifyStruct.resource_id,
DBUS_TYPE_STRING, &ldbid,
@@ -274,7 +272,6 @@ static dbus_bool_t addWatch(DBusWatch *watch, void *data)
++gPollInfo.nfds;
}
-
result = TRUE;
}
@@ -577,8 +574,7 @@ int dispatchInternalCommand(DBusConnection* conn, MainLoopData_u* readData, int*
void* mainLoop(void* userData)
{
- int ret;
- int bContinue = 0; /// indicator if dbus mainloop shall continue
+ int ret, bContinue = 0; /// indicator if dbus mainloop shall continue
DBusConnection* conn = (DBusConnection*)userData;
@@ -598,8 +594,7 @@ void* mainLoop(void* userData)
}
else
{
- int i;
- int bQuit = FALSE;
+ int i, bQuit = FALSE;
for (i=0; gPollInfo.nfds>i && !bQuit; ++i)
{
@@ -627,7 +622,7 @@ void* mainLoop(void* userData)
{
MainLoopData_u readData;
bContinue = TRUE;
- while ((-1==(ret = read(gPollInfo.fds[i].fd, readData.payload, 128)))&&(EINTR == errno));
+ while ((-1==(ret = read(gPollInfo.fds[i].fd, readData.payload, sizeof(struct message_))))&&(EINTR == errno));
if(ret < 0)
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - read() failed"), DLT_STRING(strerror(errno)) );
@@ -696,7 +691,7 @@ int deliverToMainloop(MainLoopData_u* payload)
int rval = 0;
pthread_mutex_lock(&gDeliverpMtx); // make sure deliverToMainloop will be used exclusively
- deliverToMainloop_NM(payload);
+ rval = deliverToMainloop_NM(payload);
pthread_mutex_lock(&gMainCondMtx); // mutex needed for pthread condition used to wait on other thread (mainloop)
@@ -715,9 +710,9 @@ int deliverToMainloop(MainLoopData_u* payload)
int deliverToMainloop_NM(MainLoopData_u* payload)
{
- int rval = 0, length = 128;
+ int rval = 0;
- if(-1 == write(gPipeFd[1], payload->payload, length))
+ if(-1 == write(gPipeFd[1], payload->payload, sizeof(struct message_)))
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("toMainloop => failed write pipe"), DLT_INT(errno));
rval = -1;
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index d84b39d..70a1d7f 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -42,7 +42,6 @@ static int pclFileOpenDefaultData(PersistenceInfo_s* dbContext, const char* reso
static int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id,
char* dbKey, char* dbPath, int shared_DB, unsigned int user_no, unsigned int seat_no);
-
extern int doAppcheck(void);
@@ -149,7 +148,6 @@ int pclFileGetSize(int fd)
}
}
#else
-
size = fstat(fd, &buf);
if(size != -1)
@@ -196,14 +194,9 @@ void* pclFileMapData(void* addr, long size, long offset, int fd)
int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, char* dbKey, char* dbPath, int shared_DB, unsigned int user_no, unsigned int seat_no)
{
- int handle = -1;
- int length = 0;
-
- int wantBackup = 1;
- int cacheStatus = -1;
+ int handle = -1, length = 0, wantBackup = 1, cacheStatus = -1;
char fileSubPath[DbPathMaxLen] = {0};
-
char backupPath[DbPathMaxLen] = {0}; // backup file
char csumPath[DbPathMaxLen] = {0}; // checksum file
@@ -216,8 +209,8 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
length = gWTPathPrefixSize;
}
- fileSubPath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
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);
@@ -295,7 +288,6 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileOpen - no def data avail: "), DLT_STRING(resource_id));
}
}
-
set_file_cache_status(handle, cacheStatus);
}
@@ -389,7 +381,6 @@ 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
@@ -494,7 +485,6 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user
rval = EPERS_LOCKFS;
}
}
-
return rval;
}
@@ -528,7 +518,6 @@ int pclFileSeek(int fd, long int offset, int whence)
rval = EPERS_LOCKFS;
}
}
-
return rval;
}
@@ -551,7 +540,6 @@ int pclFileUnmapData(void* address, long size)
rval = EPERS_LOCKFS;
}
}
-
return rval;
}
@@ -572,8 +560,6 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size)
{
if(permission != PersistencePermission_ReadOnly )
{
-
-
// check if a backup file has to be created
if( (get_file_backup_status(fd) == 0) && get_file_user_id(fd) != PCL_USER_DEFAULTDATA)
{
@@ -771,7 +757,6 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
handle = EPERS_RESOURCE_NO_FILE;
}
}
-
return handle;
}
@@ -796,7 +781,6 @@ int pclFileReleasePath(int pathHandle)
// remove checksum file
remove(get_ossfile_checksum_path(pathHandle)); // we don't care about return value
-
}
free(get_ossfile_file_path(pathHandle));
@@ -821,11 +805,11 @@ int pclFileReleasePath(int pathHandle)
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};
- int defaultHandle = -1;
- int rval = 0;
// create path to default data
if(policy == PersistencePolicy_wc)
@@ -852,17 +836,18 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy)
struct stat buf;
memset(&buf, 0, sizeof(buf));
- (void)fstat(defaultHandle, &buf);
- rval = sendfile(handle, defaultHandle, 0, buf.st_size);
- if(rval != -1)
- {
- rval = lseek(handle, 0, SEEK_SET); // set fd back to beginning of the file
- }
- else
+ if(fstat(defaultHandle, &buf) != -1)
{
- DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileGetDefaultData - Err copy file "), DLT_STRING(strerror(errno)));
+ rval = sendfile(handle, defaultHandle, 0, buf.st_size);
+ if(rval != -1)
+ {
+ rval = lseek(handle, 0, SEEK_SET); // set fd back to beginning of the file
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileGetDefaultData - Err copy file "), DLT_STRING(strerror(errno)));
+ }
}
-
close(defaultHandle);
}
else
diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c
index b88f065..8fc7a68 100644
--- a/src/persistence_client_library_handle.c
+++ b/src/persistence_client_library_handle.c
@@ -334,7 +334,6 @@ char* get_file_checksum_path(int idx)
free(item);
}
}
-
pthread_mutex_unlock(&gFileHandleAccessMtx);
}
return charPtr;
@@ -384,7 +383,6 @@ void set_file_backup_status(int idx, int status)
free(item);
}
}
-
pthread_mutex_unlock(&gFileHandleAccessMtx);
}
}
@@ -409,7 +407,6 @@ int get_file_backup_status(int idx)
free(item);
}
}
-
pthread_mutex_unlock(&gFileHandleAccessMtx);
}
return backup;
@@ -605,7 +602,6 @@ int set_ossfile_handle_data(int idx, PersistencePermission_e permission, int bac
free(item);
rval = 0;
}
-
pthread_mutex_unlock(&gOssFileHandleAccessMtx);
}
@@ -713,7 +709,6 @@ void set_ossfile_file_path(int idx, char* file)
{
item->value.fileHandle.filePath = file;
-
item->value.fileHandle.backupCreated = 0; // set to 0 by default
item->value.fileHandle.permission = -1;
item->value.fileHandle.cacheStatus = -1; // set to -1 by default
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 4a1deb7..bd766f6 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -40,8 +40,7 @@ extern int doAppcheck(void);
int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no)
{
- int rval = 0;
- int handle = EPERS_NOT_INITIALIZED;
+ int rval = 0, handle = EPERS_NOT_INITIALIZED;
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
@@ -273,8 +272,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size
if ('\0' != persHandle.resource_id[0])
{
size = pclKeyWriteData(persHandle.ldbid, persHandle.resource_id,
- persHandle.user_no, persHandle.seat_no,
- buffer, buffer_size);
+ persHandle.user_no, persHandle.seat_no, buffer, buffer_size);
}
else
{
@@ -428,7 +426,7 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use
&& (dbContext.configKey.type == PersistenceResourceType_key) )
{
- if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
+ if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
{
data_size = persistence_get_data(dbPath, dbKey, resource_id, &dbContext, buffer, buffer_size);
}
diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c
index e71d3f5..c81a44d 100644
--- a/src/persistence_client_library_lc_interface.c
+++ b/src/persistence_client_library_lc_interface.c
@@ -60,17 +60,15 @@ int check_lc_request(unsigned int request, unsigned int requestID)
int msg_lifecycleRequest(DBusConnection *connection, DBusMessage *message)
{
- unsigned int request = 0,
- requestID = 0;
int msgReturn = 0;
+ unsigned int request = 0, requestID = 0;
DBusMessage *reply;
DBusError error;
dbus_error_init (&error);
if (!dbus_message_get_args (message, &error, DBUS_TYPE_UINT32, &request,
- DBUS_TYPE_UINT32, &requestID,
- DBUS_TYPE_INVALID))
+ DBUS_TYPE_UINT32, &requestID, DBUS_TYPE_INVALID))
{
reply = dbus_message_new_error(message, error.name, error.message);
diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c
index 625d2cf..284346d 100644
--- a/src/persistence_client_library_pas_interface.c
+++ b/src/persistence_client_library_pas_interface.c
@@ -100,8 +100,7 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage *
dbus_error_init (&error);
if (!dbus_message_get_args(message, &error, DBUS_TYPE_INT32 , &request,
- DBUS_TYPE_INT32 , &requestID,
- DBUS_TYPE_INVALID))
+ DBUS_TYPE_INT32 , &requestID, DBUS_TYPE_INVALID))
{
reply = dbus_message_new_error(message, error.name, error.message);
@@ -148,8 +147,7 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage *
int signal_persModeChange(DBusConnection *connection, DBusMessage *message)
{
- int persistenceMode = 0;
- int errorCode = 0;
+ int persistenceMode = 0, errorCode = 0;
DBusMessage *reply;
DBusError error;
diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c
index 92ba970..ebf2305 100644
--- a/src/persistence_client_library_prct_access.c
+++ b/src/persistence_client_library_prct_access.c
@@ -86,8 +86,11 @@ int get_resource_cfg_table_by_idx(int i)
void invalidate_resource_cfg_table(int i)
{
- gResource_table[i] = -1;
- gResourceOpen[i] = 0;
+ if(i >= 0 && i < PrctDbTableSize)
+ {
+ gResource_table[i] = -1;
+ gResourceOpen[i] = 0;
+ }
}
@@ -142,13 +145,12 @@ int get_resource_cfg_table(PersistenceRCT_e rct, int group)
int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsigned int isFile, char dbKey[], char dbPath[])
{
- int rval = 0, resourceFound = 0, groupId = 0;
-
+ int rval = 0, resourceFound = 0, groupId = 0, handleRCT = 0;
PersistenceRCT_e rct = PersistenceRCT_LastEntry;
rct = get_table_id(dbContext->context.ldbid, &groupId);
- int handleRCT = get_resource_cfg_table(rct, groupId); // get resource configuration table
+ handleRCT = get_resource_cfg_table(rct, groupId); // get resource configuration table
if(handleRCT >= 0)
{
diff --git a/src/persistence_client_library_tree_helper.c b/src/persistence_client_library_tree_helper.c
index 1a88056..b5c6457 100644
--- a/src/persistence_client_library_tree_helper.c
+++ b/src/persistence_client_library_tree_helper.c
@@ -26,6 +26,8 @@ jsw_rbtree_t *gFileHandleTree = NULL;
jsw_rbtree_t *gOssFileHandleTree = NULL;
+jsw_rbtree_t *gRb_tree_bl = NULL;
+
/**
* File handle helper functions
*/
@@ -152,3 +154,71 @@ void kh_key_val_rel(void *p)
free(rel);
}
+
+/// compare function for tree key_value_s item
+int key_val_cmp(const void *p1, const void *p2 )
+{
+ int rval = -1;
+ key_value_s* first;
+ key_value_s* second;
+
+ first = (key_value_s*)p1;
+ second = (key_value_s*)p2;
+
+ if(second->key == first->key)
+ {
+ rval = 0;
+ }
+ else if(second->key < first->key)
+ {
+ rval = -1;
+ }
+ else
+ {
+ rval = 1;
+ }
+
+ return rval;
+ }
+
+/// duplicate function for key_value_s item
+void* key_val_dup(void *p)
+{
+ int value_size = 0;
+ key_value_s* src = NULL;
+ key_value_s* dst = NULL;
+
+ src = (key_value_s*)p;
+ value_size = strlen(src->value)+1;
+
+ // allocate memory for node
+ dst = malloc(sizeof(key_value_s));
+ if(dst != NULL)
+ {
+ dst->key = src->key; // duplicate hash key
+
+ dst->value = malloc(value_size); // duplicate value
+ if(dst->value != NULL)
+ strncpy(dst->value, src->value, value_size);
+ }
+
+ return dst;
+}
+
+/// release function for key_value_s item
+void key_val_rel(void *p )
+{
+ key_value_s* rel = NULL;
+ rel = (key_value_s*)p;
+
+ if(rel != NULL)
+ {
+ if(rel->value != NULL)
+ free(rel->value);
+
+ free(rel);
+ }
+}
+
+
+
diff --git a/src/persistence_client_library_tree_helper.h b/src/persistence_client_library_tree_helper.h
index 60ae99f..290a5ce 100644
--- a/src/persistence_client_library_tree_helper.h
+++ b/src/persistence_client_library_tree_helper.h
@@ -36,6 +36,9 @@ extern jsw_rbtree_t *gFileHandleTree;
/// tree to store OSS file handle information
extern jsw_rbtree_t *gOssFileHandleTree;
+/// the rb tree
+extern jsw_rbtree_t *gRb_tree_bl;
+
/// key handle data union definition
typedef union KeyHandleData_u_
@@ -84,6 +87,14 @@ typedef struct _FileHandleTreeItem_s
} FileHandleTreeItem_s;
+/// structure definition for a key value item
+typedef struct _key_value_s
+{
+ unsigned int key;
+ char* value;
+}key_value_s;
+
+
/**
* @brief Compare function for file handle tree item
@@ -141,5 +152,34 @@ void* kh_key_val_dup(void *p);
void kh_key_val_rel(void *p );
+/**
+ * @brief Compare function for key tree item
+ *
+ * @param p1 pointer to the first item to compare
+ * @param p2 pointer to the second item to compare
+ *
+ * @return 0 if key is equal; -1 if p1 < p2; 1 if p1 > p2
+ */
+int key_val_cmp(const void *p1, const void *p2 );
+
+
+/**
+ * @brief Duplicate function for key tree item
+ *
+ * @param p the pointer of the item to duplicate
+ *
+ * @return pointer to the duplicated item, on failure NULL
+ */
+void* key_val_dup(void *p);
+
+
+/**
+ * @brief Release function for key tree item
+ *
+ * @param p pointer tp the item to release
+ */
+void key_val_rel(void *p);
+
+
#endif /* PERSISTENCE_CLIENT_LIBRARY_TREE_HELPER_H */