summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2013-03-06 17:27:23 +0100
committerIngo Huerner <ingo.huerner@xse.de>2013-03-06 17:27:23 +0100
commit1e9bbac24b54622b43c3ed04a639506cdb905252 (patch)
tree125ff982ea719ee2e2fcf5fb63b9312aa16ea202
parent76f9691f8d62b09fb82e926fe63c9a9ae6a24767 (diff)
downloadpersistence-client-library-1e9bbac24b54622b43c3ed04a639506cdb905252.tar.gz
Added db entry for prc table for resource type and customID
-rw-r--r--configure.ac2
-rw-r--r--include_protected/persistence_client_library_data_organization.h1
-rw-r--r--include_protected/persistence_client_library_rc_table.h22
-rw-r--r--src/persistence_client_library_file.c18
-rw-r--r--src/persistence_client_library_key.c38
-rw-r--r--src/persistence_client_library_prct_access.c31
-rw-r--r--src/persistence_client_library_prct_access.h5
-rw-r--r--test/data/Data.tar.gzbin91997 -> 98914 bytes
8 files changed, 87 insertions, 30 deletions
diff --git a/configure.ac b/configure.ac
index 62f1547..141e49f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,7 +17,7 @@ AC_GNU_SOURCE()
# create library version information
m4_define([pers_client_library_version_current], [3])
-m4_define([pers_client_library_version_revision], [1])
+m4_define([pers_client_library_version_revision], [2])
m4_define([pers_client_library_version_age], [0])
m4_define([pers_client_library_version], [pers_client_library_version_current():pers_client_library_version_revision():pers_client_library_version_age()])
diff --git a/include_protected/persistence_client_library_data_organization.h b/include_protected/persistence_client_library_data_organization.h
index 87680d3..ca28be8 100644
--- a/include_protected/persistence_client_library_data_organization.h
+++ b/include_protected/persistence_client_library_data_organization.h
@@ -70,6 +70,7 @@ enum _PersistenceConstantDef
MaxConfKeyLengthResp = 32, /// length of the config key responsible name
MaxConfKeyLengthCusName = 32, /// length of the config key custom name
+ MaxRctLengthCustom_ID = 64, /// length of the customer ID
defaultMaxKeyValDataSize = 16384 /// default limit the key-value data size to 16kB
};
diff --git a/include_protected/persistence_client_library_rc_table.h b/include_protected/persistence_client_library_rc_table.h
index 7ea58d3..054d23c 100644
--- a/include_protected/persistence_client_library_rc_table.h
+++ b/include_protected/persistence_client_library_rc_table.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-#define PERSIST_DATA_RC_TABLE_INTERFACE_VERSION (0x01000000U)
+#define PERSIST_DATA_RC_TABLE_INTERFACE_VERSION (0x02000000U)
#include "persistence_client_library_data_organization.h"
@@ -54,6 +54,20 @@ typedef enum _PersistenceStorage_e
} PersistenceStorage_e;
+
+/** specify the type of the resource */
+typedef enum PersistenceResourceType_e_
+{
+ PersistenceResourceType_key = 0, /**< key type resource */
+ PersistenceResourceType_file, /**< file type resource */
+
+ /** insert new entries here ... */
+ PersistenceResourceType_LastEntry /**< last entry */
+
+} PersistenceResourceType_e;
+
+
+
/// structure used to manage database context
typedef struct _PersistenceDbContext_s
{
@@ -66,12 +80,14 @@ typedef struct _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 */
+ PersistencePolicy_e policy; /**< policy */
+ PersistenceStorage_e storage; /**< definition of storage to use */
+ PersistenceResourceType_e type; /**< type of the resource - since 4.0.0.0*/
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 */
+ char customID[MaxRctLengthCustom_ID]; /**< internal ID for the custom type resource */
} PersistenceConfigurationKey_s;
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index a98357b..6c1e3fe 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -103,7 +103,8 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
// get database context: database path and database key
shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath);
- if(shared_DB != -1) // check valid database context
+ if( (shared_DB >= 0) // check valid database context
+ && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches
{
handle = open(dbPath, flags);
if(handle != -1)
@@ -178,10 +179,15 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
}
else
{
- printf("file_open ==> no valid path to create: %s\n", dbPath);
+ printf("pclFileOpen ==> no valid path to create: %s\n", dbPath);
}
}
}
+ else
+ {
+ handle = shared_DB;
+ printf("pclFileOpen ==> no valid database context or resource no file\n");
+ }
return handle;
}
@@ -217,7 +223,8 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user
// get database context: database path and database key
shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath);
- if(shared_DB != -1) // check valid database context
+ if( (shared_DB >= 0) // check valid database context
+ && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches
{
rval = remove(dbPath);
if(rval == -1)
@@ -225,6 +232,11 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user
printf("file_remove ERROR: %s \n", strerror(errno) );
}
}
+ else
+ {
+ rval = shared_DB;
+ printf("pclFileRemove ==> no valid database context or resource not a file\n");
+ }
}
else
{
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index f4f4949..7a3df3f 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -52,9 +52,10 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u
// get database context: database path and database key
handle = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
- if(handle >= 0)
+ if( (handle >= 0)
+ && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches
{
- if(dbContext.configKey.storage < PersistenceStoragePolicy_LastEntry) // check if store policy is valid
+ if(dbContext.configKey.storage < PersistenceStoragePolicy_LastEntry) // check if store policy is valid
{
if(PersistenceStorage_custom == dbContext.configKey.storage)
{
@@ -88,10 +89,14 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u
}
else
{
- printf("key_handle_open: error - handleId out of bounds [%d]\n", handle);
+ printf("pclKeyHandleOpen: error - handleId out of bounds [%d]\n", handle);
}
}
}
+ else
+ {
+ printf("pclKeyHandleOpen: error - no database context or resource is not a key \n");
+ }
return handle;
@@ -244,7 +249,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size
}
else
{
- printf("key_handle_write_data: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize);
+ printf("pclKeyHandleWriteData: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize);
}
}
else
@@ -285,7 +290,8 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_
// get database context: database path and database key
rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
- if(rval >= 0)
+ if( (rval >= 0)
+ && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type is matching
{
if( dbContext.configKey.storage < PersistenceStoragePolicy_LastEntry
&& dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid
@@ -326,7 +332,8 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user
// get database context: database path and database key
data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
- if(data_size >= 0)
+ if( (data_size >= 0)
+ && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches
{
if( dbContext.configKey.storage < PersistenceStoragePolicy_LastEntry
&& dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid
@@ -370,7 +377,8 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use
// get database context: database path and database key
data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
- if(data_size >= 0)
+ if( (data_size >= 0)
+ && (dbContext.configKey.type == PersistenceResourceType_key) )
{
if( dbContext.configKey.storage < PersistenceStoragePolicy_LastEntry
@@ -383,6 +391,10 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use
data_size = EPERS_BADPOL;
}
}
+ else
+ {
+ printf("pclKeyReadData - error - no database context or resource is not a key\n");
+ }
}
else
{
@@ -419,7 +431,8 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
// get database context: database path and database key
data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
- if(data_size >= 0)
+ if( (data_size >= 0)
+ && (dbContext.configKey.type == PersistenceResourceType_key))
{
// get hash value of data to verify storing
hash_val_data = crc32(hash_val_data, buffer, buffer_size);
@@ -435,11 +448,15 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
data_size = EPERS_BADPOL;
}
}
+ else
+ {
+ printf("pclKeyWriteData: error - no database context or resource is not a key\n");
+ }
}
else
{
data_size = EPERS_BUFLIMIT;
- printf("key_write_data: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize);
+ printf("pclKeyWriteData: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize);
}
}
else
@@ -473,7 +490,8 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un
rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
// registration is only on shared key possible
- if(PersistenceStorage_shared == rval)
+ if( (PersistenceStorage_shared == rval)
+ && (dbContext.configKey.type == PersistenceResourceType_key) )
{
rval = persistence_reg_notify_on_change(dbPath, dbKey);
}
diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c
index e044f6f..c2e4d21 100644
--- a/src/persistence_client_library_prct_access.c
+++ b/src/persistence_client_library_prct_access.c
@@ -149,12 +149,13 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
dbContext->configKey.storage = search.data.storage;
dbContext->configKey.permission = search.data.permission;
dbContext->configKey.max_size = search.data.max_size;
+ dbContext->configKey.type = search.data.type;
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);
+ rval = get_db_path_and_key(dbContext, resource_id, dbKey, dbPath);
}
else
{
@@ -178,17 +179,27 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
if(resourceFound == 0)
{
//
- // resource NOT found in resource table ==> default is local cached
+ // resource NOT found in resource table ==> default is local cached key
//
dbContext->configKey.policy = PersistencePolicy_wc;
dbContext->configKey.storage = PersistenceStorage_local;
dbContext->configKey.permission = 0; // TODO define default permission
dbContext->configKey.max_size = defaultMaxKeyValDataSize;
+ if(isFile == PersistenceResourceType_file)
+ {
+ dbContext->configKey.type = PersistenceResourceType_file;
+ }
+ else
+ {
+ dbContext->configKey.type = PersistenceResourceType_key;
+ }
+
+ memcpy(dbContext->configKey.customID, "A_CUSTOM_ID", strlen("A_CUSTOM_ID"));
memcpy(dbContext->configKey.reponsible, "default", strlen("default"));
memcpy(dbContext->configKey.custom_name, "default", strlen("default"));
//printf("get_db_context ==> R E S O U R C E N O T found: %s \n", resource_id);
- rval = get_db_path_and_key(dbContext, resource_id, isFile, dbKey, dbPath);
+ rval = get_db_path_and_key(dbContext, resource_id, dbKey, dbPath);
}
return rval;
@@ -197,7 +208,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
// status: OK
-int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, unsigned int isFile, char dbKey[], char dbPath[])
+int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, char dbKey[], char dbPath[])
{
int storePolicy = PersistenceStoragePolicy_LastEntry;
@@ -267,14 +278,14 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, u
//
if(PersistencePolicy_wc == dbContext->configKey.policy)
{
- if(isFile == ResIsNoFile)
+ if(dbContext->configKey.type == PersistenceResourceType_key)
snprintf(dbPath, DbPathMaxLen, gSharedCachePath, gAppId, dbContext->context.ldbid, gSharedCached);
else
snprintf(dbPath, DbPathMaxLen, gSharedCachePath, gAppId, dbContext->context.ldbid, dbKey);
}
else if(PersistencePolicy_wt == dbContext->configKey.policy)
{
- if(isFile == ResIsNoFile)
+ if(dbContext->configKey.type == PersistenceResourceType_key)
snprintf(dbPath, DbPathMaxLen, gSharedWtPath, gAppId, dbContext->context.ldbid, gSharedWt);
else
snprintf(dbPath, DbPathMaxLen, gSharedWtPath, gAppId, dbContext->context.ldbid, dbKey);
@@ -288,14 +299,14 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, u
//
if(PersistencePolicy_wc == dbContext->configKey.policy)
{
- if(isFile == ResIsNoFile)
+ if(dbContext->configKey.type == PersistenceResourceType_key)
snprintf(dbPath, DbPathMaxLen, gSharedPublicCachePath, gAppId, gSharedCached);
else
snprintf(dbPath, DbPathMaxLen, gSharedPublicCachePath, gAppId, dbKey);
}
else if(PersistencePolicy_wt == dbContext->configKey.policy)
{
- if(isFile == ResIsNoFile)
+ if(dbContext->configKey.type == PersistenceResourceType_key)
snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPath, gAppId, gSharedWt);
else
snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPath, gAppId, dbKey);
@@ -310,14 +321,14 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, u
if(PersistencePolicy_wc == dbContext->configKey.policy)
{
- if(isFile == ResIsNoFile)
+ if(dbContext->configKey.type == PersistenceResourceType_key)
snprintf(dbPath, DbPathMaxLen, gLocalCachePath, gAppId, gLocalCached);
else
snprintf(dbPath, DbPathMaxLen, gLocalCachePath, gAppId, dbKey);
}
else if(PersistencePolicy_wt == dbContext->configKey.policy)
{
- if(isFile == ResIsNoFile)
+ if(dbContext->configKey.type == PersistenceResourceType_key)
snprintf(dbPath, DbPathMaxLen, gLocalWtPath, gAppId, gLocalWt);
else
snprintf(dbPath, DbPathMaxLen, gLocalWtPath, gAppId, dbKey);
diff --git a/src/persistence_client_library_prct_access.h b/src/persistence_client_library_prct_access.h
index 0a05c58..85d4b68 100644
--- a/src/persistence_client_library_prct_access.h
+++ b/src/persistence_client_library_prct_access.h
@@ -32,7 +32,6 @@
* @param resource_id the resource id
* @param user_no user identification
* @param seat_no seat identifier
- * @param isFile identifier if this resource is a file
* @param dbKey the array where the database key will be stored
* @param dbPath the array where the database location path will be stored
* @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0)
@@ -40,7 +39,7 @@
* @return 1 if shared database and 0 if local database or PersistenceStoragePolicy_LastEntry
* when no valid database has been found
*/
-int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, unsigned int isFile, char dbKey[], char dbPath[]);
+int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, char dbKey[], char dbPath[]);
@@ -51,7 +50,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, u
* @param resource_id the resource id
* @param user_no user identification
* @param seat_no seat identifier
- * @param isFile identifier if this resource is a file
+ * @param isFile identifier if this resource is a file (used for file/key creation if resource does not exist)
* @param dbKey the array where the database key will be stored
* @param dbPath the array where the database location path will be stored
* @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0)
diff --git a/test/data/Data.tar.gz b/test/data/Data.tar.gz
index d1bc63c..dab24c2 100644
--- a/test/data/Data.tar.gz
+++ b/test/data/Data.tar.gz
Binary files differ