diff options
Diffstat (limited to 'tools/persistence_db_viewer.c')
-rw-r--r-- | tools/persistence_db_viewer.c | 93 |
1 files changed, 41 insertions, 52 deletions
diff --git a/tools/persistence_db_viewer.c b/tools/persistence_db_viewer.c index 15f20df..40ab828 100644 --- a/tools/persistence_db_viewer.c +++ b/tools/persistence_db_viewer.c @@ -8,11 +8,10 @@ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ******************************************************************************/ - /** +/** * @file persistence_db_viewer.c * @ingroup Persistence client library tools * @author Ingo Huerner - * * @see */ @@ -60,21 +59,21 @@ typedef enum dbType_ unsigned int gDbMaskArray[] = { - dbTypeNone, - dbTypeCached, - dbTypeWriteThrough, - dbTypeDefault, - dbTypeConfDefault, - dbTypeRCT + dbTypeNone, + dbTypeCached, + dbTypeWriteThrough, + dbTypeDefault, + dbTypeConfDefault, + dbTypeRCT }; const char* gDbNameArray[] = { - "none", - "cached", - "wt", - "default", - "confDefault", - "RCT" + "none", + "cached", + "wt", + "default", + "confDefault", + "RCT" }; @@ -102,15 +101,14 @@ void printDBcontent(const char* appname, dbType type) int handle = 0, listSize = 0, ret = 0; char* resourceList = NULL; - char filename[512] = {0}; + char filename[512] = { 0 }; static const char* nameTemplate = "/Data/mnt-c/%s/%s"; static const char* cache = "cached.itz"; static const char* wt = "wt.itz"; static const char* def = "default-data.itz"; static const char* confDef = "configurable-default-data.itz"; - - memset(filename, 0, 512-1); + static const size_t bufSize = 8192; printf("---------------------------------------------------------------------\n"); if(type == dbTypeCached) @@ -144,40 +142,38 @@ void printDBcontent(const char* appname, dbType type) if(handle >= 0) { listSize = persComDbGetSizeKeysList(handle); - if(listSize > 0 && listSize < 2048) + if(listSize > 0) { - resourceList = (char*)malloc((size_t)listSize+4); - memset(resourceList, 0, (size_t)listSize+4-1); + resourceList = (char*)malloc((size_t)listSize); + memset(resourceList, 0, (size_t)listSize); if(resourceList != NULL) { - int i = 0, idx = 0, numResources = 0; - int resourceStartIdx[256] = {0}; - char buffer[2048] = {0}; - - memset(resourceStartIdx, 0, 256-1); ret = persComDbGetKeysList(handle, resourceList, listSize); - if(ret != 0) { - resourceStartIdx[idx] = 0; // initial start + int i = 0, idx = 0, numResources = 0; + int resourceStartIdx[256] = { 0 }; + char buffer[bufSize]; - for(i=1; i<listSize; i++ ) + for(i = 1; i < listSize; ++i) { - if(resourceList[i] == '\0') - { - numResources++; - resourceStartIdx[idx++] = i+1; - } + if(resourceList[i] == '\0') + { + numResources++; + resourceStartIdx[++idx] = i + 1; + } } printf("NumOf resources: %d \n", numResources); - for(i=0; i<=numResources; i++) + for(i = 0; i < numResources; ++i) { - memset(buffer, 0, 1024); printf("Key[%d]: %s\n", i, &resourceList[resourceStartIdx[i]]); - persComDbReadKey(handle, &resourceList[resourceStartIdx[i]], buffer, 1024); + + memset(buffer, 0, sizeof(buffer)); + persComDbReadKey(handle, &resourceList[resourceStartIdx[i]], buffer, (int)sizeof(buffer)); + printf(" value: %s\n\n", buffer); } } @@ -203,7 +199,6 @@ void printDBcontent(const char* appname, dbType type) - void printRCTcontent(const char* appname, int full) { int handle = -1, listSize = 0, ret = 0; @@ -220,29 +215,25 @@ void printRCTcontent(const char* appname, int full) if(handle >= 0) { listSize = persComRctGetSizeResourcesList(handle); - if(listSize > 0 && listSize < 2048) + if(listSize > 0) { - resourceList = (char*)malloc((size_t)listSize+4); - memset(resourceList, 0, (size_t)listSize+4-1); + resourceList = (char*)malloc((size_t)listSize); + memset(resourceList, 0, (size_t)listSize); if(resourceList != NULL) { - int i = 0, idx = 1, numResources = 0; - int resourceStartIdx[256] = {0}; - - memset(resourceStartIdx, 0, 256-1); ret = persComRctGetResourcesList(handle, resourceList, listSize); - if(ret != 0) { - resourceStartIdx[idx] = 0; // initial start + int i = 0, idx = 0, numResources = 0; + int resourceStartIdx[256] = { 0 }; - for(i=1; i<listSize; i++ ) + for(i = 1; i < listSize; ++i) { if(resourceList[i] == '\0') { numResources++; - resourceStartIdx[idx++] = i+1; + resourceStartIdx[++idx] = i + 1; } } @@ -250,7 +241,7 @@ void printRCTcontent(const char* appname, int full) printf("RCT keys [%d]: %s \n", numResources, filename); printf("---------------------------------------------------------------------\n"); - for(i=0; i<numResources; i++) + for(i = 0; i < numResources; ++i) { PersistenceConfigurationKey_s psConfig_out; printf("RCT[%d] : \"%s\"\n", i, &resourceList[resourceStartIdx[i]]); @@ -398,6 +389,7 @@ void printAvailableApplication(const char* thePath) } + int main(int argc, char *argv[]) { int ret = 0, opt = 0, printAllAppsContent = -1, listAllApps = -1; @@ -460,13 +452,11 @@ int main(int argc, char *argv[]) printAppManual(); } - if(listAllApps == 1) { printAvailableApplication(persPath); } - if(printAllAppsContent == 1) { printAllApplicationDBs(persPath, dbTypeAccum); @@ -476,7 +466,6 @@ int main(int argc, char *argv[]) printSingleApplicationDBs(singleAppName, persPath, dbTypeAccum); } - // unregister debug log and trace DLT_UNREGISTER_APP(); |