summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2012-12-12 12:01:45 +0100
committerIngo Huerner <ingo.huerner@xse.de>2012-12-12 12:01:45 +0100
commit6ce609538cbd1c4e3e67c1d54478b948d988b963 (patch)
tree0c5d0f32805cd3f718bb6975422e69f65b4bbd8c
parent245194a2e74ae6622d24fca4ba2ef9e7049291bb (diff)
downloadpersistence-client-library-6ce609538cbd1c4e3e67c1d54478b948d988b963.tar.gz
Updated prct datastructure, custom_name and responsible are now fixed arrays instead of char ptr; moved definition of prct structure to persistence_client_library hedader
-rw-r--r--include_protected/persistence_client_library.h26
-rw-r--r--src/persistence_client_library_access_helper.c182
-rw-r--r--src/persistence_client_library_access_helper.h23
-rw-r--r--test/data/Data.tar.gzbin92059 -> 91997 bytes
4 files changed, 33 insertions, 198 deletions
diff --git a/include_protected/persistence_client_library.h b/include_protected/persistence_client_library.h
index d34060e..7d00175 100644
--- a/include_protected/persistence_client_library.h
+++ b/include_protected/persistence_client_library.h
@@ -69,6 +69,9 @@ enum _PersistenceConstantDef
MaxAppNameLen = 128, /// max application name
MaxPersHandle = 256, /// max number of parallel open persistence handles
+ MaxConfKeyLengthResp = 32, /// length of the config key responsible name
+ MaxConfKeyLengthCusName = 32, /// length of the config key custom name
+
defaultMaxKeyValDataSize = 16384 /// default limit the key-value data size to 16kB
};
@@ -107,18 +110,28 @@ typedef struct _PersistenceDbContext_s
unsigned char seat_no;
} PersistenceDbContext_s;
+
/// structure used to manage the persistence configuration for a key
typedef struct _PersistenceConfigurationKey_s
{
- PersistencePolicy_e policy; /**< policy */
- PersistenceStorage_e storage; /**< definition of storage to use */
- unsigned int permission; /**< access right, corresponds to UNIX */
- unsigned int max_size; /**< max size expected for the key */
- char * reponsible; /**< name of responsible application */
- char * custom_name; /**< name of the customer plugin */
+ PersistencePolicy_e policy; /**< policy */
+ PersistenceStorage_e storage; /**< definition of storage to use */
+ unsigned int permission; /**< access right, corresponds to UNIX */
+ unsigned int max_size; /**< max size expected for the key */
+ char reponsible[MaxConfKeyLengthResp]; /**< name of responsible application */
+ char custom_name[MaxConfKeyLengthCusName]; /**< name of the customer plugin */
} PersistenceConfigurationKey_s;
+/// structure definition of an persistence resource configuration table entry
+typedef struct _PersistenceRctEntry_s
+{
+ char key[PrctKeySize]; /**< the key */
+ PersistenceConfigurationKey_s data; /**< data for the key */
+}
+PersistenceRctEntry_s;
+
+
/// persistence information
typedef struct _PersistenceInfo_s
{
@@ -128,6 +141,7 @@ typedef struct _PersistenceInfo_s
} PersistenceInfo_s;
+
/// persistence resource config table type definition
typedef enum _PersistenceRCT_e
{
diff --git a/src/persistence_client_library_access_helper.c b/src/persistence_client_library_access_helper.c
index 54fd83c..b5845f2 100644
--- a/src/persistence_client_library_access_helper.c
+++ b/src/persistence_client_library_access_helper.c
@@ -22,24 +22,17 @@
#include <stdlib.h>
+
/// pointer to resource table database
itzam_btree gResource_table[PrctDbTableSize];
/// array to hold the information of database is already open
int gResourceOpen[PrctDbTableSize] = {0};
-/// structure definition of an persistence resource configuration table entry
-typedef struct record_t
-{
- char m_key[PrctKeySize]; // the key
- char m_data[PrctValueSize]; // data for the key
-}
-prct_record;
-
-
PersistenceRCT_e get_table_id(int ldbid, int* groupId)
{
PersistenceRCT_e rctType = PersistenceRCT_LastEntry;
+
if(ldbid < 0x80)
{
// S H A R E D database
@@ -120,162 +113,6 @@ itzam_btree* get_resource_cfg_table(PersistenceRCT_e rct, int group)
}
-
-int serialize_data(PersistenceConfigurationKey_s pc, char* buffer)
-{
- int rval = 0;
- rval = snprintf(buffer, gMaxKeyValDataSize, "%d %d %u %d %s %s",
- pc.policy, pc.storage, pc.permission, pc.max_size,
- pc.reponsible, pc.custom_name);
- return rval;
-}
-
-
-
-int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
-{
- int rval = 1;
- char* token = NULL;
- //printf("\nde_serialize_data: %s \n", buffer);
- if((buffer != NULL) && (pc != NULL))
- {
- token = strtok(buffer, " "); // policy
- if(token != 0)
- {
- pc->policy = strtol(token, 0, 10);
- //printf("pc->policy %d \n", pc->policy);
- }
- else
- {
- printf("de_serialize_data - error: can't get [policy] \n");
- rval = EPERS_DESER_POLICY;
- }
-
- token = strtok (NULL, " "); // storage
- if(token != 0)
- {
- pc->storage = strtol(token, 0, 10);
- //printf("pc->storage %d \n", pc->storage);
- }
- else
- {
- printf("de_serialize_data - error: can't get [storage] \n");
- rval = EPERS_DESER_STORE;
- }
-
- token = strtok (NULL, " "); // permission
- if(token != 0)
- {
- pc->permission = strtol(token, 0, 10);
- //printf("pc->permission %d \n", pc->permission);
- }
- else
- {
- printf("de_serialize_data - error: can't get [permission] \n");
- rval = EPERS_DESER_PERM;
- }
-
- token = strtok (NULL, " "); // max_size
- if(token != 0)
- {
- pc->max_size = strtol(token, 0, 10);
- //printf("pc->max_size %d \n", pc->max_size);
- }
- else
- {
- printf("de_serialize_data - error: can't get [max_size] \n");
- rval = EPERS_DESER_MAXSIZE;
- }
-
- token = strtok (NULL, " "); // reponsible
- if(token != 0)
- {
- int size = strlen(token)+1;
- pc->reponsible = malloc(size);
-
- if(pc->reponsible != NULL)
- {
- strncpy(pc->reponsible, token, size);
- //printf(" pc->reponsible %s | 0x%x \n", pc->reponsible, (int)pc->reponsible);
- }
- else
- {
- rval = EPERS_DESER_ALLOCMEM;
- printf("de_serialize_data - error: can't allocate memory [reponsible] \n");
- }
- }
- else
- {
- printf("de_serialize_data - error: can't get [reponsible] \n");
- rval = EPERS_DESER_RESP;
- }
-
- token = strtok (NULL, " "); // custom_name
- if(token != 0)
- {
- int size = strlen(token)+1;
- pc->custom_name = malloc(size);
- if(pc->custom_name != NULL )
- {
- strncpy(pc->custom_name, token, size);
- }
- else
- {
- rval = EPERS_DESER_ALLOCMEM;
- printf("de_serialize_data - error: can't allocate memory [custom_name] \n");
- }
- //printf(" pc->custom_name %s | 0x%x \n", pc->custom_name, (int)pc->custom_name);
- }
- else
- {
- char* na = "na";
- int size = strlen(na)+1;
- // custom name not available => no custom plugin
- pc->custom_name = malloc(size);
- if(pc->custom_name != NULL )
- {
- strncpy(pc->custom_name, "na", size);
- }
- else
- {
- rval = EPERS_DESER_ALLOCMEM;
- printf("de_serialize_data - error: can't allocate memory [custom_name-default] \n");
- }
- }
- }
- else
- {
- printf("de_serialize_data - error: buffer or PersistenceConfigurationKey_s is NULL\n");
- rval = EPERS_DESER_BUFORKEY;
- }
-
- return rval;
-}
-
-
-
-void free_pers_conf_key(PersistenceConfigurationKey_s* pc)
-{
- if(pc != NULL)
- {
- if(pc->reponsible != NULL)
- {
- free(pc->reponsible);
- pc->reponsible = NULL;
- //printf("free_pers_conf_key => free(pc->reponsible);");
- }
-
- if(pc->custom_name != NULL)
- {
- free(pc->custom_name);
- pc->custom_name = NULL;
- //printf("free_pers_conf_key => free(pc->reponsible);");
- }
- }
-}
-
-
-
// status: OK
int get_db_context(PersistenceInfo_s* dbContext, char* resource_id, unsigned int isFile, char dbKey[], char dbPath[])
{
@@ -290,12 +127,20 @@ int get_db_context(PersistenceInfo_s* dbContext, char* resource_id, unsigned int
if(resource_table != NULL)
{
- prct_record search;
+ PersistenceRctEntry_s search;
// check if resouce id is in write through table
if(itzam_true == itzam_btree_find(resource_table, resource_id, &search))
{
- //printf("get_db_context ==> data: %s\n", search.m_data);
- de_serialize_data(search.m_data, &dbContext->configKey);
+ //printf("get_db_context ==> data: %s\n", search.data);
+ memset(dbContext->configKey.reponsible, 0, MaxConfKeyLengthResp);
+ memset(dbContext->configKey.custom_name, 0, MaxConfKeyLengthCusName);
+ dbContext->configKey.policy = search.data.policy;
+ dbContext->configKey.storage = search.data.storage;
+ dbContext->configKey.permission = search.data.permission;
+ dbContext->configKey.max_size = search.data.max_size;
+ memcpy(dbContext->configKey.reponsible, search.data.reponsible, MaxConfKeyLengthResp);
+ memcpy(dbContext->configKey.custom_name, search.data.custom_name, MaxConfKeyLengthCusName);
+
if(dbContext->configKey.storage != PersistenceStorage_custom )
{
rval = get_db_path_and_key(dbContext, resource_id, isFile, dbKey, dbPath);
@@ -305,7 +150,6 @@ int get_db_context(PersistenceInfo_s* dbContext, char* resource_id, unsigned int
// if customer storage, we use the custom name as path
strncpy(dbPath, dbContext->configKey.custom_name, strlen(dbContext->configKey.custom_name));
}
- free_pers_conf_key(&dbContext->configKey);
resourceFound = 1;
}
else
diff --git a/src/persistence_client_library_access_helper.h b/src/persistence_client_library_access_helper.h
index 3da3459..7a0a236 100644
--- a/src/persistence_client_library_access_helper.h
+++ b/src/persistence_client_library_access_helper.h
@@ -67,28 +67,5 @@ int get_db_context(PersistenceInfo_s* dbContext, char* resource_id, unsigned int
itzam_btree* get_resource_cfg_table_by_idx(int i);
-/**
- * @brief serialize data to store to database
- *
- * @return the number of bytes serialized of a negative value on error and errno is set
- */
-int serialize_data(PersistenceConfigurationKey_s pc, char* buffer);
-
-
-/**
- * @brief deserialize data read from database
- *
- * @return 1 of correct deserialization or on of the following error codes:
- * EPERS_DESER_BUFORKEY, EPERS_DESER_ALLOCMEM, EPERS_DESER_POLICY, EPERS_DESER_STORE,
- * EPERS_DESER_PERM, EPERS_DESER_MAXSIZE or EPERS_DESER_RESP
- */
-int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc);
-
-
-/**
- * @brief free allocated data of a persistence configuration key
- */
-void free_pers_conf_key(PersistenceConfigurationKey_s* pc);
-
#endif /* PERSISTENCE_CLIENT_LIBRARY_ACCESS_HELPER_H */
diff --git a/test/data/Data.tar.gz b/test/data/Data.tar.gz
index 4046ef6..d1bc63c 100644
--- a/test/data/Data.tar.gz
+++ b/test/data/Data.tar.gz
Binary files differ