summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorihuerner <ihuerner@b9707d8c-442e-47db-affb-152dabb2260b>2012-10-30 07:56:21 +0000
committerihuerner <ihuerner@b9707d8c-442e-47db-affb-152dabb2260b>2012-10-30 07:56:21 +0000
commita02ee2a8addc0cfe08706de81660952de5b791d6 (patch)
tree2ee2863596409e0b747c273f928f0307807bdc23
parent1c775a6856caae4946344b919494a7eed1bae9cc (diff)
downloadpersistence-client-library-a02ee2a8addc0cfe08706de81660952de5b791d6.tar.gz
New version 0.2.1 (rev 1748), for chnages see ChangeLog
-rw-r--r--ChangeLog6
-rw-r--r--configure.ac4
-rw-r--r--include/persistence_client_library_error_def.h3
-rw-r--r--include/persistence_client_library_file.h3
-rw-r--r--src/Makefile.am9
-rw-r--r--src/persistence_client_library.c14
-rw-r--r--src/persistence_client_library_access_helper.c2
-rw-r--r--src/persistence_client_library_custom_loader.c1
-rw-r--r--src/persistence_client_library_custom_loader.h46
-rw-r--r--src/persistence_client_library_data_access.c163
-rw-r--r--src/persistence_client_library_data_access.h7
-rw-r--r--src/persistence_client_library_file.c104
-rw-r--r--src/persistence_client_library_handle.h2
-rw-r--r--src/persistence_client_library_key.c214
-rw-r--r--test/Makefile.am3
-rw-r--r--test/data/Data.tar.gzbin50764 -> 50292 bytes
-rw-r--r--test/persistence_client_library_test.c308
17 files changed, 549 insertions, 340 deletions
diff --git a/ChangeLog b/ChangeLog
index 7801d65..cc25cb1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Revision 0.2.1 (rev 1748)
+- Extended tests
+- Fixed some minor bugs
+- Removed dconf
+
+
Revision 0.2.0 (rev 1709)
- Fixed a problem with handle generation
- Updated custom plugin library interface
diff --git a/configure.ac b/configure.ac
index a205fc5..1b5c517 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
-AC_INIT([Persistence Client Library], [0.1.4], [not-valid@xse.de])
+AC_INIT([Persistence Client Library], [0.2.1], [not-valid@xse.de])
AC_CONFIG_SRCDIR([Makefile.am])
AM_INIT_AUTOMAKE([dist-bzip2])
AC_GNU_SOURCE()
@@ -49,8 +49,6 @@ AC_CHECK_FUNCS([fdatasync ftruncate mkdir munmap rmdir strerror utime dlopen])
PKG_CHECK_MODULES(DEPS,
automotive-dlt
dbus-1
- dconf
- dconf-dbus-1
libitzam
glib-2.0)
diff --git a/include/persistence_client_library_error_def.h b/include/persistence_client_library_error_def.h
index 3bfaaa9..a7140d6 100644
--- a/include/persistence_client_library_error_def.h
+++ b/include/persistence_client_library_error_def.h
@@ -83,7 +83,8 @@
#define EPERS_DLOPENERROR -23
/// plugin function not loaded
#define EPERS_NOPLUGINFUNCT -24
-
+/// file remove error
+#define EPERS_FILEREMOVE -25
#endif /* PERSISTENCE_CLIENT_LIBRARY_ERROR_DEF_H */
diff --git a/include/persistence_client_library_file.h b/include/persistence_client_library_file.h
index 26f4ac8..a2a373a 100644
--- a/include/persistence_client_library_file.h
+++ b/include/persistence_client_library_file.h
@@ -66,8 +66,7 @@ int file_close(int fd);
*
* @param fd the POSIX file descriptor
*
- * @return positive value. On error a negative value will be returned with th follwoing error codes:
- * EPERS_LOCKFS
+ * @return positive value. On error the negative value -1 will be returned
*/
int file_get_size(int fd);
diff --git a/src/Makefile.am b/src/Makefile.am
index ee2e002..db5cc1b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,16 +1,15 @@
AUTOMAKE_OPTIONS = foreign
+
if DEBUG
-AM_CFLAGS =$(DEPS_CFLAGS) -g -I../include \
+AM_CFLAGS = $(DEPS_CFLAGS) -g -I../include \
-Iglib-2.0 \
-Idbus-1.0 \
- -Idconf-dbus-1 \
-Iglib-2.0/include
else
-AM_CFLAGS =$(DEPS_CFLAGS) -I../include \
+AM_CFLAGS = $(DEPS_CFLAGS) -I../include \
-Iglib-2.0 \
-Idbus-1.0 \
- -Idconf-dbus-1 \
-Iglib-2.0/include
endif
@@ -22,7 +21,7 @@ include_HEADERS = ../include/persistence_client_library_key.h \
lib_LTLIBRARIES = libpersistence_client_library.la
-libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) -ldconf -ldl -ldconf-dbus-1 -lgvdb
+libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) -ldl -lgvdb
libpersistence_client_library_la_SOURCES = \
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 8bcfc4c..adb21d9 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -87,11 +87,11 @@ const char* gLocalWt = "/wt.itz";
/// directory structure node name defintion
-const char* gNode = "/Node";
+const char* gNode = "/node";
/// directory structure user name defintion
-const char* gUser = "/User/";
+const char* gUser = "/user/";
/// directory structure seat name defintion
-const char* gSeat = "/Seat/";
+const char* gSeat = "/seat/";
/// path prefic for local cached database: /Data/mnt_c/<appId>/<database_name>
@@ -127,10 +127,10 @@ void pers_library_init(void)
{
int status = 0;
int i = 0;
- DLT_REGISTER_APP("Persistence Client Library","persClientLib");
- DLT_REGISTER_CONTEXT(persClientLibCtx,"persClientLib","Context for Logging");
+ //DLT_REGISTER_APP("Persistence Client Library","persClientLib");
+ //DLT_REGISTER_CONTEXT(persClientLibCtx,"persClientLib","Context for Logging");
- DLT_LOG(persClientLibCtx, DLT_LOG_ERROR, DLT_STRING("Initialize Persistence Client Library!!!!"));
+ //DLT_LOG(persClientLibCtx, DLT_LOG_ERROR, DLT_STRING("Initialize Persistence Client Library!!!!"));
/// environment variable for on demand loading of custom libraries
const char *pOnDemandLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND");
@@ -204,7 +204,7 @@ void pers_library_init(void)
//gPersCustomFuncs[PersCustomLib_early].custom_plugin_close(17);
}
- printf("A p p l i c a t i o n n a m e => %s \n", __progname /*program_invocation_short_name*/); // TODO: only temp solution for application name
+ //printf("A p p l i c a t i o n n a m e => %s \n", __progname /*program_invocation_short_name*/); // TODO: only temp solution for application name
strncpy(gAppId, __progname, maxAppNameLen);
}
diff --git a/src/persistence_client_library_access_helper.c b/src/persistence_client_library_access_helper.c
index 034cc7d..cea96b6 100644
--- a/src/persistence_client_library_access_helper.c
+++ b/src/persistence_client_library_access_helper.c
@@ -103,7 +103,7 @@ GvdbTable* get_resource_cfg_table(PersistenceRCT_e rct, int group)
}
gResource_table[rct] = gvdb_table_new(filename, TRUE, &error);
- printf("get_resource_cfg_table - group %d | db filename: %s \n", group, filename);
+ //printf("get_resource_cfg_table - group %d | db filename: %s \n", group, filename);
if(gResource_table[rct] == NULL)
{
diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c
index 9759f4d..c3f6187 100644
--- a/src/persistence_client_library_custom_loader.c
+++ b/src/persistence_client_library_custom_loader.c
@@ -357,7 +357,6 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
return -1;
}
-
// custom_plugin_get_status_notification_clbk
*(void **) (&customFuncts->custom_plugin_get_status_notification_clbk) = dlsym(handle, "plugin_get_status_notification_clbk");
if ((error = dlerror()) != NULL)
diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h
index 6f6dc7c..d4fa7fd 100644
--- a/src/persistence_client_library_custom_loader.h
+++ b/src/persistence_client_library_custom_loader.h
@@ -70,51 +70,51 @@ typedef struct _Pers_custom_functs_s
/// custom library handle
void* handle;
- /// custom library init function
- int (*custom_plugin_init)();
+ /// create backup
+ long (*custom_plugin_create_backup)(const char* backup_id);
/// custom library deinit function
int (*custom_plugin_deinit)();
- /// custom open function
- long (*custom_plugin_handle_open)(char* path, int flag, int mode);
-
- /// custom close function
- int (*custom_plugin_handle_close)(int handle);
+ /// custom delete function
+ int (*custom_plugin_delete_data)(const char* path);
- /// custom get data function
- long (*custom_plugin_handle_get_data)(long handle, char* buffer, long size);
+ /// get backup
+ long (*custom_plugin_get_backup)(const char* backup_id, long size);
- /// custom set data function
- long (*custom_plugin_handle_set_data)(long handle, char* buffer, long size);
+ // get the size
+ int (*custom_plugin_get_size)(const char* path);
/// custom get data function
long (*custom_plugin_get_data)(const char* path, char* buffer, long size);
- /// custom set data function
- long (*custom_plugin_set_data)(const char* path, char* buffer, long size);
+ /// custom close function
+ int (*custom_plugin_handle_close)(int handle);
- /// custom delete function
- int (*custom_plugin_delete_data)(const char* path);
+ /// custom get data function
+ long (*custom_plugin_handle_get_data)(long handle, char* buffer, long size);
- // get the size
- int (*custom_plugin_handle_get_size)(int key_handle);
+ /// custom open function
+ long (*custom_plugin_handle_open)(const char* path, int flag, int mode);
- // get the size
- int (*custom_plugin_get_size)(const char* path);
+ /// custom set data function
+ long (*custom_plugin_handle_set_data)(long handle, char* buffer, long size);
- /// create backup
- long (*custom_plugin_create_backup)(const char* backup_id);
+ /// custom library init function
+ int (*custom_plugin_init)();
/// restore backup
long (*custom_plugin_restore_backup)(const char* backup_id);
- /// get backup
- long (*custom_plugin_get_backup)(const char* backup_id, long size);
+ /// custom set data function
+ long (*custom_plugin_set_data)(const char* path, char* buffer, long size);
/// custom status notification function
int (*custom_plugin_get_status_notification_clbk)(plugin_callback_t pFunct);
+ // get the size
+ int (*custom_plugin_handle_get_size)(int key_handle);
+
}Pers_custom_functs_s;
diff --git a/src/persistence_client_library_data_access.c b/src/persistence_client_library_data_access.c
index b0fa15d..5ddad59 100644
--- a/src/persistence_client_library_data_access.c
+++ b/src/persistence_client_library_data_access.c
@@ -33,12 +33,12 @@
#include "persistence_client_library_data_access.h"
#include "persistence_client_library_custom_loader.h"
+#include "persistence_client_library_itzam_errors.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <itzam.h>
-#include "persistence_client_library_itzam_errors.h"
typedef struct _KeyValuePair_s
@@ -108,12 +108,14 @@ int set_value_to_table_itzam(const char* dbPath, char* key, unsigned char* buffe
dataSize = (int)strlen( (const char*)buffer);
if(dataSize < ValueSize)
{
+ memset(insert.m_key, 0, KeySize);
memcpy(insert.m_key, key, keySize);
if(itzam_true == itzam_btree_find(&btree, key, &insert))
{
// key already available, so delete "old" key
state = itzam_btree_remove(&btree, (const void *)&insert);
}
+ memset(insert.m_data, 0, ValueSize);
memcpy(insert.m_data, buffer, dataSize);
state = itzam_btree_insert(&btree,(const void *)&insert);
if (state != ITZAM_OKAY)
@@ -276,41 +278,94 @@ int get_size_from_table_gvdb(const char* dbPath, char* key)
#else
int get_size_from_table_itzam(const char* dbPath, char* key)
{
- int read_size = 0;
- itzam_btree btree;
- itzam_state state;
- KeyValuePair_s search;
-
- //printf("get_value_from_table_itzam => Path: %s key: \"%s\" \n", dbPath, key);
+ int read_size = 0,
+ keySize = 0;
+ itzam_btree btree;
+ itzam_state state;
+ KeyValuePair_s search;
- state = itzam_btree_open(&btree, dbPath, itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/);
- if(state == ITZAM_OKAY)
- {
- if(itzam_true == itzam_btree_find(&btree, key, &search))
- {
- read_size = strlen(search.m_data);
- }
- else
- {
- read_size = EPERS_NOKEY;
- }
+ //printf("* * * %s ==> dbPath: %s | key: %s \n", __FUNCTION__, dbPath, key);
+ state = itzam_btree_open(&btree, dbPath, itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/);
+ if(state == ITZAM_OKAY)
+ {
+ keySize = (int)strlen((const char*)key);
+ if(keySize < KeySize)
+ {
+ memset(search.m_key,0, KeySize);
+ memcpy(search.m_key, key, keySize);
+ if(itzam_true == itzam_btree_find(&btree, key, &search))
+ {
+ read_size = strlen(search.m_data);
+ }
+ else
+ {
+ read_size = EPERS_NOKEY;
+ }
+ }
- state = itzam_btree_close(&btree);
- if (state != ITZAM_OKAY)
- {
- fprintf(stderr, "\nClose Itzam problem: %s\n", STATE_MESSAGES[state]);
- }
- }
- else
- {
- read_size = EPERS_NOPRCTABLE;
- fprintf(stderr, "\nOpen Itzam problem: %s\n", STATE_MESSAGES[state]);
- }
- return read_size;
+ state = itzam_btree_close(&btree);
+ if (state != ITZAM_OKAY)
+ {
+ fprintf(stderr, "\nClose Itzam problem: %s\n", STATE_MESSAGES[state]);
+ }
+ }
+ else
+ {
+ read_size = EPERS_NOPRCTABLE;
+ fprintf(stderr, "\nOpen Itzam problem: %s\n", STATE_MESSAGES[state]);
+ }
+ return read_size;
}
#endif
+int delete_key_from_table_itzam(char* dbPath, char* key)
+{
+ int rval = 0;
+ itzam_btree btree;
+ itzam_state state;
+ KeyValuePair_s delete;
+
+ //printf("delete_key_from_table_itzam => Path: \"%s\" | key: \"%s\" \n", dbPath, key);
+
+ state = itzam_btree_open(&btree, dbPath, itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/);
+ if(state == ITZAM_OKAY)
+ {
+ int keySize = 0;
+ keySize = (int)strlen((const char*)key);
+ if(keySize < KeySize)
+ {
+ memset(delete.m_key,0, KeySize);
+ memcpy(delete.m_key, key, keySize);
+ state = itzam_btree_remove(&btree, (const void *)&delete);
+ if (state != ITZAM_OKAY)
+ {
+ fprintf(stderr, "\nRemove Itzam problem: %s\n", STATE_MESSAGES[state]);
+ }
+
+ state = itzam_btree_close(&btree);
+ if (state != ITZAM_OKAY)
+ {
+ fprintf(stderr, "\nClose Itzam problem: %s\n", STATE_MESSAGES[state]);
+ }
+ }
+ else
+ {
+ fprintf(stderr, "\nset_value_to_table_itzam => key to long » size: %d | maxSize: %d\n", keySize, KeySize);
+ }
+ }
+ else
+ {
+ rval = EPERS_NOPRCTABLE;
+ fprintf(stderr, "\nOpen Itzam problem: %s\n", STATE_MESSAGES[state]);
+ }
+
+
+ return rval;
+}
+
+
+
int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size)
{
int read_size = -1;
@@ -365,7 +420,6 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
printf(" S H A R E D D A T A => NOW IMPLEMENTING implemented yet\n");
//DConfDBusClient *dcdbc = dconf_dbus_client_new("/com/canonical/indicator/power/", NULL, NULL);
//ok = dconf_dbus_client_write(dcdbc, key, value);
-
}
else if(PersistenceStorage_local == storage) // it is local data (gvdb)
{
@@ -420,7 +474,24 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e stor
+int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e storage)
+{
+ int ret = 0;
+ if(PersistenceStorage_shared == storage) // check if shared data (dconf)
+ {
+ printf("S H A R E D D A T A => not implemented yet\n");
+ }
+ else if(PersistenceStorage_local == storage) // it is local data (gvdb)
+ {
+ ret = delete_key_from_table_itzam(dbPath, dbKey);
+ }
+ else if(PersistenceStorage_custom == storage) // custom storage implementation via custom library
+ {
+ printf(" get C U S T O M D A T A => NOW IMPLEMENTING implemented yet\n");
+ }
+ return ret;
+}
int persistence_reg_notify_on_change(char* dbPath, char* key)
@@ -431,6 +502,36 @@ int persistence_reg_notify_on_change(char* dbPath, char* key)
}
+//-----------------------------------------------------------------------------
+// code to print database content (for debugging)
+//-----------------------------------------------------------------------------
+// walk the database
+/*
+KeyValuePair_s rec;
+itzam_btree_cursor cursor;
+state = itzam_btree_cursor_create(&cursor, &btree);
+if(state == ITZAM_OKAY)
+{
+ printf("==> Database content ==> db size: %d\n", (int)itzam_btree_count(&btree));
+ do
+ {
+ // get the key pointed to by the cursor
+ state = itzam_btree_cursor_read(&cursor,(void *)&rec);
+ if (state == ITZAM_OKAY)
+ {
+ printf(" Key: %s \n ==> data: %s\n", rec.m_key, rec.m_data);
+ }
+ else
+ fprintf(stderr, "\nItzam problem: %s\n", STATE_MESSAGES[state]);
+ }
+ while (itzam_btree_cursor_next(&cursor));
+
+ state = itzam_btree_cursor_free(&cursor);
+}
+*/
+//-----------------------------------------------------------------------------
+
+
diff --git a/src/persistence_client_library_data_access.h b/src/persistence_client_library_data_access.h
index b4764f2..3acb669 100644
--- a/src/persistence_client_library_data_access.h
+++ b/src/persistence_client_library_data_access.h
@@ -35,8 +35,9 @@
*/
#include "persistence_client_library.h"
+#ifdef USE_GVDB
#include "gvdb-builder.h"
-
+#endif
/**
* @brief write data to a key
@@ -92,6 +93,10 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e stor
int persistence_reg_notify_on_change(char* dbPath, char* key);
+/**
+ * @brief delete data
+ */
+int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e storePolicy);
/**
* @brief read data from a key
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 07183ff..9ae5357 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -43,6 +43,8 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
@@ -50,18 +52,12 @@ int file_close(int fd)
{
int rval = -1;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ rval = close(fd);
+ if(fd < maxPersHandle)
{
- rval = close(fd);
- if(fd < maxPersHandle)
- {
- __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag
- }
- }
- else
- {
- rval = EPERS_LOCKFS;
+ __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag
}
+
return rval;
}
@@ -69,22 +65,15 @@ int file_close(int fd)
int file_get_size(int fd)
{
- int rval = 0;
+ int rval = -1;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
- {
- struct stat buf;
- int ret = 0;
- ret = fstat(fd, &buf);
+ struct stat buf;
+ int ret = 0;
+ ret = fstat(fd, &buf);
- if(ret != -1)
- {
- rval = buf.st_size;
- }
- }
- else
+ if(ret != -1)
{
- rval = EPERS_LOCKFS;
+ rval = buf.st_size;
}
return rval;
}
@@ -95,7 +84,7 @@ void* file_map_data(void* addr, long size, long offset, int fd)
{
void* ptr = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
int mapFlag = PROT_WRITE | PROT_READ;
ptr = mmap(addr,size, mapFlag, MAP_SHARED, fd, offset);
@@ -113,46 +102,38 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns
{
int handle = -1;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
- {
- int shared_DB = 0,
- flags = O_RDWR;
+ int shared_DB = 0,
+ flags = O_RDWR;
- char dbKey[dbKeyMaxLen]; // database key
- char dbPath[dbPathMaxLen]; // database location
+ char dbKey[dbKeyMaxLen]; // database key
+ char dbPath[dbPathMaxLen]; // database location
- memset(dbKey, 0, dbKeyMaxLen);
- memset(dbPath, 0, dbPathMaxLen);
+ memset(dbKey, 0, dbKeyMaxLen);
+ memset(dbPath, 0, dbPathMaxLen);
- // get database context: database path and database key
- shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsFile, dbKey, dbPath);
+ // get database context: database path and database key
+ shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsFile, dbKey, dbPath);
- if(shared_DB != -1) // check valid database context
- {
- handle = open(dbPath, flags);
+ if(shared_DB != -1) // check valid database context
+ {
+ handle = open(dbPath, flags);
- if(handle == -1)
+ if(handle == -1)
+ {
+ printf("file_open ERROR: %s \n", strerror(errno) );
+ }
+ else
+ {
+ if(handle < maxPersHandle)
{
- printf("file_open ERROR: %s \n", strerror(errno) );
+ __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
}
else
{
- if(handle < maxPersHandle)
- {
- __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
- }
- else
- {
- handle = EPERS_MAXHANDLE;
- }
+ handle = EPERS_MAXHANDLE;
}
}
}
- else
- {
- handle = EPERS_LOCKFS;
- }
-
return handle;
}
@@ -161,16 +142,7 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns
int file_read_data(int fd, void * buffer, unsigned long buffer_size)
{
- int size = -1;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
- {
- size = read(fd, buffer, buffer_size);
- }
- else
- {
- size = EPERS_LOCKFS;
- }
- return size;
+ return read(fd, buffer, buffer_size);
}
@@ -179,7 +151,7 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u
{
int rval = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
int shared_DB = 0;
@@ -196,7 +168,9 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u
{
rval = remove(dbPath);
if(rval == -1)
+ {
printf("file_remove ERROR: %s \n", strerror(errno) );
+ }
}
}
else
@@ -231,7 +205,7 @@ int file_unmap_data(void* address, long size)
{
int rval = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
rval = munmap(address, size);
}
@@ -249,7 +223,7 @@ int file_write_data(int fd, const void * buffer, unsigned long buffer_size)
{
int size = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
size = write(fd, buffer, buffer_size);
}
diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h
index c832409..da83c0a 100644
--- a/src/persistence_client_library_handle.h
+++ b/src/persistence_client_library_handle.h
@@ -57,7 +57,7 @@ extern int gOpenFdArray[maxPersHandle];
/**
* @brief get persistence handle
*
- * @return a new handle or -1 if an error occured
+ * @return a new handle or 0 if an error occured
*/
int get_persistence_handle_idx();
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 84a87b1..83fe8f3 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -48,67 +48,58 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
{
int handle = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
- {
- int storePolicy = 0;
+ int storePolicy = 0;
- char dbKey[dbKeyMaxLen]; // database key
- char dbPath[dbPathMaxLen]; // database location
+ char dbKey[dbKeyMaxLen]; // database key
+ char dbPath[dbPathMaxLen]; // database location
- memset(dbKey, 0, dbKeyMaxLen);
- memset(dbPath, 0, dbPathMaxLen);
+ memset(dbKey, 0, dbKeyMaxLen);
+ memset(dbPath, 0, dbPathMaxLen);
- // get database context: database path and database key
- storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
+ // get database context: database path and database key
+ storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
- if(storePolicy < PersistenceStoragePolicy_LastEntry) // check if store policy is valid
+ if(storePolicy < PersistenceStoragePolicy_LastEntry) // check if store policy is valid
+ {
+ if(PersistenceStorage_custom == storePolicy)
{
- if(PersistenceStorage_custom == storePolicy)
- {
- int idx = custom_client_name_to_id(dbPath, 1);
- char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
- snprintf(workaroundPath, 128, "%s%s", "/tmp", dbPath );
-
- printf(" open C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", dbPath , idx);
-
- if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_open != NULL) )
- {
- int flag = 0,
- mode = 0;
- handle = gPersCustomFuncs[idx].custom_plugin_handle_open(dbPath, flag, mode);
- }
- else
- {
- handle = EPERS_NOPLUGINFUNCT;
- }
- }
- else
- {
- handle = get_persistence_handle_idx();
- }
+ int idx = custom_client_name_to_id(dbPath, 1);
+ char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
+ snprintf(workaroundPath, 128, "%s%s", "/tmp", dbPath );
- if(handle < maxPersHandle)
+ if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_open != NULL) )
{
- // remember data in handle array
- strncpy(gHandleArray[handle].dbPath, dbPath, dbPathMaxLen);
- strncpy(gHandleArray[handle].dbKey, dbKey, dbKeyMaxLen);
- gHandleArray[handle].shared_DB = storePolicy;
+ int flag = 0, mode = 0;
+ handle = gPersCustomFuncs[idx].custom_plugin_handle_open(dbPath, flag, mode);
}
else
{
- printf("key_handle_open: error - handleId out of bounds [%d]\n", handle);
+ handle = EPERS_NOPLUGINFUNCT;
}
}
else
{
- handle = EPERS_BADPOL;
+ handle = get_persistence_handle_idx();
+ }
+
+ if(handle < maxPersHandle && handle != -1)
+ {
+ // remember data in handle array
+ strncpy(gHandleArray[handle].dbPath, dbPath, dbPathMaxLen);
+ strncpy(gHandleArray[handle].dbKey, dbKey, dbKeyMaxLen);
+ gHandleArray[handle].shared_DB = storePolicy;
+ }
+ else
+ {
+ printf("key_handle_open: error - handleId out of bounds [%d]\n", handle);
}
}
else
{
- handle = EPERS_LOCKFS;
+ handle = EPERS_BADPOL;
}
+
return handle;
}
@@ -118,7 +109,7 @@ int key_handle_close(int key_handle)
{
int rval = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(key_handle < maxPersHandle)
{
if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB )
{
@@ -126,8 +117,6 @@ int key_handle_close(int key_handle)
char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
snprintf(workaroundPath, 128, "%s%s", "/tmp", gHandleArray[key_handle].dbPath );
- printf(" close C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", gHandleArray[key_handle].dbPath , idx);
-
if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_close) )
{
gPersCustomFuncs[idx].custom_plugin_handle_close(key_handle);
@@ -149,7 +138,7 @@ int key_handle_close(int key_handle)
}
else
{
- rval = EPERS_LOCKFS;
+ rval = -1;
}
return rval;
@@ -161,38 +150,28 @@ int key_handle_get_size(int key_handle)
{
int size = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(key_handle < maxPersHandle)
{
- if(key_handle < maxPersHandle)
+ if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB)
{
- if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB)
- {
- int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
- char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
- snprintf(workaroundPath, 128, "%s%s", "/tmp", gHandleArray[key_handle].dbPath );
-
- printf(" get size C U S T O M D A T A => not implemented yet - path: %s | index: %d \n",
- gHandleArray[key_handle].dbPath , idx);
+ int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
+ char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
+ snprintf(workaroundPath, 128, "%s%s", "/tmp", gHandleArray[key_handle].dbPath );
- if(idx < PersCustomLib_LastEntry)
- {
- //gPersCustomFuncs[idx].custom_plugin_get_size()
- }
- else
- {
- size = EPERS_NOPLUGINFUNCT;
- }
+ if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_get_size) != NULL)
+ {
+ gPersCustomFuncs[idx].custom_plugin_get_size(gHandleArray[key_handle].dbPath);
}
else
{
- size = persistence_get_data_size(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey,
- gHandleArray[key_handle].shared_DB);
+ size = EPERS_NOPLUGINFUNCT;
}
}
- }
- else
- {
- size = EPERS_LOCKFS;
+ else
+ {
+ size = persistence_get_data_size(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey,
+ gHandleArray[key_handle].shared_DB);
+ }
}
return size;
@@ -203,38 +182,28 @@ int key_handle_get_size(int key_handle)
int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long buffer_size)
{
int size = 0;
-
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(key_handle < maxPersHandle)
{
- if(key_handle < maxPersHandle)
+ if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB)
{
- if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB)
- {
- int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
- char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
- snprintf(workaroundPath, 128, "%s%s", "/tmp", gHandleArray[key_handle].dbPath );
-
- printf(" read C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", gHandleArray[key_handle].dbPath , idx);
+ int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
+ char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
+ snprintf(workaroundPath, 128, "%s%s", "/tmp", gHandleArray[key_handle].dbPath );
- if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_handle_get_data) != NULL)
- {
- gPersCustomFuncs[idx].custom_plugin_handle_get_data(key_handle, (char*)buffer, buffer_size-1);
- }
- else
- {
- size = EPERS_NOPLUGINFUNCT;
- }
+ if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_handle_get_data) != NULL)
+ {
+ gPersCustomFuncs[idx].custom_plugin_handle_get_data(key_handle, (char*)buffer, buffer_size-1);
}
else
{
- size = persistence_get_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey,
- gHandleArray[key_handle].shared_DB, buffer, buffer_size);
+ size = EPERS_NOPLUGINFUNCT;
}
}
- }
- else
- {
- size = EPERS_LOCKFS;
+ else
+ {
+ size = persistence_get_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey,
+ gHandleArray[key_handle].shared_DB, buffer, buffer_size);
+ }
}
return size;
@@ -255,7 +224,7 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
{
int size = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
if(buffer_size <= gMaxKeyValDataSize) // check data size
{
@@ -267,8 +236,6 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
snprintf(workaroundPath, 128, "%s%s", "/tmp", gHandleArray[key_handle].dbPath );
- printf(" write C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", gHandleArray[key_handle].dbPath , idx);
-
if(idx < PersCustomLib_LastEntry && *gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL)
{
gPersCustomFuncs[idx].custom_plugin_handle_set_data(key_handle, (char*)buffer, buffer_size-1);
@@ -313,9 +280,28 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
{
int rval = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
- // TODO implement key delete
+ int storePolicy = 0;
+
+ char dbKey[dbKeyMaxLen]; // database key
+ char dbPath[dbPathMaxLen]; // database location
+
+ memset(dbKey, 0, dbKeyMaxLen);
+ memset(dbPath, 0, dbPathMaxLen);
+
+ // get database context: database path and database key
+ storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
+
+ if( storePolicy < PersistenceStoragePolicy_LastEntry
+ && storePolicy >= PersistenceStorage_local) // check if store policy is valid
+ {
+ rval = persistence_delete_data(dbPath, dbKey, storePolicy);
+ }
+ else
+ {
+ rval = EPERS_BADPOL;
+ }
}
else
{
@@ -331,33 +317,25 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
int data_size = 0;
+ int storePolicy = 0;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
- {
- int storePolicy = 0;
-
- char dbKey[dbKeyMaxLen]; // database key
- char dbPath[dbPathMaxLen]; // database location
+ char dbKey[dbKeyMaxLen]; // database key
+ char dbPath[dbPathMaxLen]; // database location
- memset(dbKey, 0, dbKeyMaxLen);
- memset(dbPath, 0, dbPathMaxLen);
+ memset(dbKey, 0, dbKeyMaxLen);
+ memset(dbPath, 0, dbPathMaxLen);
- // get database context: database path and database key
- storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
+ // get database context: database path and database key
+ storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
- if( storePolicy < PersistenceStoragePolicy_LastEntry
- && storePolicy >= PersistenceStorage_local) // check if store policy is valid
- {
- data_size = persistence_get_data_size(dbPath, dbKey, storePolicy);
- }
- else
- {
- data_size = EPERS_BADPOL;
- }
+ if( storePolicy < PersistenceStoragePolicy_LastEntry
+ && storePolicy >= PersistenceStorage_local) // check if store policy is valid
+ {
+ data_size = persistence_get_data_size(dbPath, dbKey, storePolicy);
}
else
{
- data_size = EPERS_LOCKFS;
+ data_size = EPERS_BADPOL;
}
return data_size;
diff --git a/test/Makefile.am b/test/Makefile.am
index 743386e..61f22f8 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -3,8 +3,7 @@ AUTOMAKE_OPTIONS = foreign
if DEBUG
AM_CFLAGS =$(DEPS_CFLAGS) $(CHECK_CFLAGS) -g
else
-AM_CFLAGS =$(DEPS_CFLAGS) $(CHECK_CFLAGS)
-#AM_CFLAGS = -fprofile-arcs -ftest-coverage $(DEPS_CFLAGS) $(CHECK_CFLAGS)
+AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS)
endif
diff --git a/test/data/Data.tar.gz b/test/data/Data.tar.gz
index 6466456..c5725f4 100644
--- a/test/data/Data.tar.gz
+++ b/test/data/Data.tar.gz
Binary files differ
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 368822a..6916063 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -37,16 +37,20 @@
#include <unistd.h> /* exit */
#include <check.h>
#include <time.h>
+#include <fcntl.h>
+#include <sys/mman.h>
#include "../include/persistence_client_library_key.h"
#include "../include/persistence_client_library_file.h"
+#include "../include/persistence_client_library_error_def.h"
#define BUF_SIZE 64
#define NUM_OF_FILES 3
#define READ_SIZE 1024
-char* dayOfWeek[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
+
+char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
@@ -57,44 +61,37 @@ START_TEST (test_persGetData)
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0xFF, "/language/country_code", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
- //printf("T E S T Data - country_code: %s | size: %d \n", buffer, ret);
fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0xFF, "/pos/last_position", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
- fail_unless(strncmp((char*)buffer, "+48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read");
- //printf("T E S T Data - last_position: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "+48° 10' 38.95\", +8° 44' 39.06\"", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ fail_unless(ret = strlen("+48° 10' 38.95\", +8° 44' 39.06\""));
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0, "/language/current_language", 3, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Shared/Public/wt.dconf" => "/User/3/language/current_language"
fail_unless(strncmp((char*)buffer, "S H A R E D D A T A => not implemented yet", strlen((char*)buffer)) == 0, "Buffer not correctly read");
- //printf("T E S T Data - current_language: %s \n", buffer);
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0xFF, "/status/open_document", 3, 2, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/User/3/Seat/2/status/open_document"
- printf("T E S T Data - last link: %s \n", buffer);
- fail_unless(strncmp((char*)buffer, "/var/opt/user_manual_climateControl.pdf", ret-1) == 0, "Buffer not correctly read");
- //printf("T E S T Data - open_document: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "/var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0x20, "/address/home_address", 4, 0, buffer, READ_SIZE); // "/Data/mnt-c/Shared/Group/20/cached.dconf" => "/User/4/address/home_address"
fail_unless(strncmp((char*)buffer, "S H A R E D D A T A => not implemented yet", strlen((char*)buffer)) == 0, "Buffer not correctly read");
- //printf("T E S T Data - home_address: %s \n", buffer);
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0xFF, "/pos/last satellites", 0, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-1/wt.gvdb" => "/Node/pos/last satellites"
- fail_unless(strncmp((char*)buffer, "17", ret-1) == 0, "Buffer not correctly read");
- //printf("T E S T Data - last satellites: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0x84, "/links/last link", 2, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-2/wt.gvdb" => "/84/User/2/links/last link"
- fail_unless(strncmp((char*)buffer, "/last_exit/brooklyn", ret-1) == 0, "Buffer not correctly read");
- //printf("T E S T Data - last link: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "/last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
ret = key_read_data(0x84, "/links/last link", 2, 1, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-2/wt.gvdb" => "/84/User/2/links/last link"
- fail_unless(strncmp((char*)buffer, "/last_exit/queens", ret-1) == 0, "Buffer not correctly read");
- //printf("T E S T Data - last link: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "/last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
}
END_TEST
@@ -102,44 +99,69 @@ END_TEST
START_TEST (test_persGetDataHandle)
{
- int ret = 0, handlePos = 0, handleLang = 0, handleStatus = 0, handleHome = 0;
- unsigned char* buffer = NULL;
- char sysTimeBuffer[128];
- buffer = malloc(READ_SIZE);
-
+ int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
+ unsigned char buffer[READ_SIZE];
struct tm *locTime;
time_t t = time(0);
-
+
+ char sysTimeBuffer[128];
+ memset(buffer, 0, READ_SIZE);
+
locTime = localtime(&t);
- snprintf(sysTimeBuffer, 128, "\"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
+ snprintf(sysTimeBuffer, 128, "TimeAndData: \"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
+ // open handle ---------------------------------------------------
+ handle = key_handle_open(0xFF, "/posHandle/last position", 0, 0);
+ fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last position");
- memset(buffer, 0, READ_SIZE);
- handlePos = key_handle_open(0xFF, "/posHandle/last_position", 0, 0);
- ret = key_handle_read_data(handlePos, buffer, READ_SIZE);
- fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
- printf("T E S T handle: %d | Data: %s \n\n", handlePos, buffer);
+ ret = key_handle_read_data(handle, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read");
- memset(buffer, 0, READ_SIZE);
- handleLang = key_handle_open(0, "/languageHandle/current_language", 3, 0);
- ret = key_handle_read_data(handleLang, buffer, READ_SIZE);
- printf("T E S T handle: %d | Data: %s \n\n", handleLang, buffer);
+ size = key_handle_get_size(handle);
+ fail_unless(size = strlen("H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
+
+ // open handle ---------------------------------------------------
+ handle2 = key_handle_open(0xFF, "/statusHandle/open_document", 3, 2);
+ fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
+
+ size = key_handle_write_data(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
+ fail_unless(size = strlen(sysTimeBuffer));
+ // close
+ ret = key_handle_close(handle2);
+
+
+ // open handle ---------------------------------------------------
memset(buffer, 0, READ_SIZE);
- handleStatus = key_handle_open(0xFF, "/statusHandle/open_documen", 3, 2);
- ret = key_handle_read_data(handleStatus, buffer, READ_SIZE);
- printf("T E S T handle: %d | Data: %s \n\n", handleStatus, buffer);
+ handle4 = key_handle_open(0xFF, "/language/country_code", 0, 0);
+ fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
+
+ ret = key_handle_read_data(handle4, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", -1) == 0, "Buffer not correctly read");
+
+ size = key_handle_get_size(handle4);
+ fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
+
+ ret = key_handle_write_data(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
+
+
+ // open handle ---------------------------------------------------
+ handle3 = key_handle_open(0xFF, "/statusHandle/open_document", 3, 2);
+ fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
+
+ ret = key_handle_read_data(handle3, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
+
+ size = key_handle_get_size(handle3);
+ fail_unless(size = strlen(sysTimeBuffer));
// close handle
- key_handle_close(handleLang);
+ ret = key_handle_close(handle);
+ ret = key_handle_close(handle3);
+ ret = key_handle_close(handle4);
- memset(buffer, 0, READ_SIZE);
- handleHome = key_handle_open(0x20, "/address/home_address", 4, 0);
- ret = key_handle_read_data(handleHome, buffer, READ_SIZE);
- printf("T E S T handle: %d | Data: %s \n\n", handleHome, buffer);
- free(buffer);
}
END_TEST
@@ -164,73 +186,193 @@ START_TEST(test_persSetData)
// write data
snprintf(sysTimeBuffer, 128, "\"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
- ret = key_write_data(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, READ_SIZE);
-
- snprintf(write1, 128, "%s %s", "70", sysTimeBuffer);
- ret = key_write_data(0xFF, "70", 1, 2, (unsigned char*)write1, READ_SIZE);
+ ret = key_write_data(0xFF, "/69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
+ fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
- snprintf(write2, 128, "%s %s", "key_70", sysTimeBuffer);
- ret = key_write_data(0xFF, "key_70", 1, 2, (unsigned char*)write2, READ_SIZE);
+ snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
+ ret = key_write_data(0xFF, "/70", 1, 2, (unsigned char*)write1, strlen(write1));
+ fail_unless(ret == strlen(write1), "Wrong write size");
+ snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
+ ret = key_write_data(0xFF, "/key_70", 1, 2, (unsigned char*)write2, strlen(write2));
+ fail_unless(ret == strlen(write2), "Wrong write size");
// read data again and and verify datat has been written correctly
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0xFF, "69", 1, 2, buffer, READ_SIZE);
- //printf("T E S T Data 69: %s | read: \"%s\" \n", sysTimeBuffer, buffer);
+ ret = key_read_data(0xFF, "/69", 1, 2, buffer, READ_SIZE);
fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
+ fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0xFF, "70", 1, 2, buffer, READ_SIZE);
- //printf("T E S T Data 70: %s | read: \"%s\" \n", write1, buffer);
+ ret = key_read_data(0xFF, "/70", 1, 2, buffer, READ_SIZE);
fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
+ fail_unless(ret == strlen(write1), "Wrong read size");
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
- //printf("T E S T Data key_70: %s | read: \"%s\" \n", write2, buffer);
+ ret = key_read_data(0xFF, "/key_70", 1, 2, buffer, READ_SIZE);
fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
+ fail_unless(ret == strlen(write2), "Wrong read size");
+
}
END_TEST
-START_TEST(test_persSetSharedData)
+START_TEST(test_persGetDataSize)
{
- int ret = 0;
- unsigned char* buffer = NULL;
- buffer = malloc(READ_SIZE);
+ int size = 0;
+
+ size = key_get_size(0xFF, "/status/open_document", 3, 2);
+ fail_unless(size == strlen("/var/opt/user_manual_climateControl.pdf"), "Invalid size");
+ size = key_get_size(0x84, "/links/last link", 2, 1);
+ fail_unless(size == strlen("/last_exit/queens"), "Invalid size");
+}
+END_TEST
+
+
+START_TEST(test_persDeleteData)
+{
+ int rval = 0;
+ unsigned char buffer[READ_SIZE];
+
+ // delete key
+ rval = key_delete(0xFF, "/key_70", 1, 2);
+ fail_unless(rval == 0, "Failed to delete key");
+ // reading from key must fail now
+ rval = key_read_data(0xFF, "/key_70", 1, 2, buffer, READ_SIZE);
+ fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
+
+
+ rval = key_delete(0xFF, "/70", 1, 2);
+ fail_unless(rval == 0, "Failed to delete key");
+ rval = key_read_data(0xFF, "/70", 1, 2, buffer, READ_SIZE);
+ fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
+}
+END_TEST
+
+
+
+START_TEST(test_persDataFile)
+{
+ int fd = 0, i = 0, idx = 0;
+ int size = 0, ret = 0;
+ int writeSize = 16*1024;
+ unsigned char buffer[READ_SIZE];
+ const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
+ char* writeBuffer;
+ char* fileMap = NULL;
+ writeBuffer = malloc(writeSize);
+
+
+ // fill buffer a sequence
+ for(i = 0; i<(writeSize/8); i++)
+ {
+ writeBuffer[idx++] = 'A';
+ writeBuffer[idx++] = 'B';
+ writeBuffer[idx++] = 'C';
+ writeBuffer[idx++] = ' ';
+ writeBuffer[idx++] = 'D';
+ writeBuffer[idx++] = 'E';
+ writeBuffer[idx++] = 'F';
+ writeBuffer[idx++] = ' ';
+ }
memset(buffer, 0, READ_SIZE);
- ret = key_write_data(0x20, "/address/home_address", 4, 0, buffer, READ_SIZE);
- fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
- printf("T E S T Data: %s \n\n", buffer);
- free(buffer);
+ // create file
+ fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
+ O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+ close(fd);
+
+ // open ----------------------------------------------------------
+ fd = file_open(0xFF, "/media/mediaDB.db", 1, 1);
+ fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
+
+ size = file_get_size(fd);
+ fail_unless(size == 68, "Wrong file size");
+
+ size = file_read_data(fd, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read");
+ fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
+
+ ret = file_close(fd);
+ fail_unless(ret == 0, "Failed to close file");
+
+
+ // open ----------------------------------------------------------
+ fd = file_open(0xFF, "/media/mediaDBWrite.db", 1, 1);
+ fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
+
+ size = file_write_data(fd, writeBuffer, strlen(writeBuffer));
+ fail_unless(size == strlen(writeBuffer), "Failed to write data");
+
+ ret = file_close(fd);
+ fail_unless(ret == 0, "Failed to close file");
+
+
+ // remove ----------------------------------------------------------
+ ret = file_remove(0xFF, "/media/mediaDBWrite.db", 1, 1);
+ fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
+
+ fd = file_open(0xFF, "/media/mediaDBWrite.db", 1, 1);
+ fail_unless(fd == -1, "File can be opend, but should not ==> /media/mediaDBWrite.db");
+
+
+ // map file ------------------------------------------------------
+ fd = file_open(0xFF, "/media/mediaDB.db", 1, 1);
+
+ size = file_get_size(fd);
+ file_map_data(fileMap, size, 0, fd);
+ fail_unless(fileMap != MAP_FAILED, "Failed to map file");
+
+ ret = file_unmap_data(fileMap, size);
+ fail_unless(ret != -1, "Failed to unmap file");
+
+ // negative test
+ size = file_get_size(1024);
+ fail_unless(ret == 0, "Got size, but should not");
+
+
+ free(writeBuffer);
}
END_TEST
-START_TEST(test_persGetData_file)
+START_TEST(test_persDataHandle)
{
+ int handle1 = 0, handle2 = 0;
int ret = 0;
- unsigned char* buffer = NULL;
- buffer = malloc(READ_SIZE);
+ // test file handles
+ handle1 = file_open(0xFF, "/media/mediaDB.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
- memset(buffer, 0, READ_SIZE);
+ ret = file_close(handle1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
+
+ ret = file_close(1024);
+ fail_unless(ret == -1, "Could close file, but should not!!");
+
+ ret = file_close(17);
+ fail_unless(ret == -1, "Could close file, but should not!!");
+
+
+ // test key handles
+ handle2 = key_handle_open(0xFF, "/statusHandle/open_document", 3, 2);
+ fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
- ret = file_open(0xFF, "/media/mediaDB.db", 1, 1);
- fail_unless(ret != -1, "Could not open file");
- printf("T E S T Data: %s \n\n", buffer);
+ ret = key_handle_close(handle2);
+ fail_unless(ret != -1, "Failed to close handle!!");
- free(buffer);
+ ret = key_handle_close(1024);
+ fail_unless(ret == -1, "Could close, but should not!!");
}
END_TEST
-
static Suite * persistencyClientLib_suite()
{
Suite * s = suite_create("Persistency client library");
@@ -238,24 +380,32 @@ static Suite * persistencyClientLib_suite()
TCase * tc_persGetData = tcase_create("persGetData");
tcase_add_test(tc_persGetData, test_persGetData);
+ TCase * tc_persSetData = tcase_create("persSetData");
+ tcase_add_test(tc_persSetData, test_persSetData);
+
+ TCase * tc_persGetDataSize = tcase_create("persGetDataSize");
+ tcase_add_test(tc_persGetDataSize, test_persGetDataSize);
+
+ TCase * tc_persDeleteData = tcase_create("persDeleteData");
+ tcase_add_test(tc_persDeleteData, test_persDeleteData);
+
TCase * tc_persGetDataHandle = tcase_create("persGetDataHandle");
tcase_add_test(tc_persGetDataHandle, test_persGetDataHandle);
- TCase * tc_persSetData = tcase_create("persSetData");
- tcase_add_test(tc_persSetData, test_persSetData);
+ TCase * tc_persDataHandle = tcase_create("persDataHandle");
+ tcase_add_test(tc_persDataHandle, test_persDataHandle);
- TCase * tc_persSetSharedData = tcase_create("persSetSharedData");
- tcase_add_test(tc_persSetSharedData, test_persSetSharedData);
+ TCase * tc_persDataFile = tcase_create("persDataFile");
+ tcase_add_test(tc_persDataFile, test_persDataFile);
- TCase * tc_persGetData_file = tcase_create("persGetData_file");
- tcase_add_test(tc_persGetData_file, test_persGetData_file);
suite_add_tcase(s, tc_persGetData);
suite_add_tcase(s, tc_persSetData);
-
-// suite_add_tcase(s, tc_persGetDataHandle);
-// suite_add_tcase(s, tc_persSetSharedData);
-// suite_add_tcase(s, tc_persGetData_file);
+ suite_add_tcase(s, tc_persGetDataSize);
+ suite_add_tcase(s, tc_persDeleteData);
+ suite_add_tcase(s, tc_persGetDataHandle);
+ suite_add_tcase(s, tc_persDataHandle);
+ suite_add_tcase(s, tc_persDataFile);
return s;
}