Imported Upstream version 2.0.2.1 upstream/2.0.2.1
authorJohn L. Whiteman <john.l.whiteman@intel.com>
Thu, 8 Jan 2015 23:38:58 +0000 (16:38 -0700)
committerJohn L. Whiteman <john.l.whiteman@intel.com>
Thu, 8 Jan 2015 23:38:58 +0000 (16:38 -0700)
50 files changed:
docs/Tizen Web Protection API Specification.pdf
docs/Tizen Web Protection Plugin API Specification.pdf
docs/Tizen Web Protection Service Daemon Test Specification.pdf
docs/Tizen Web Protection Test Specification.pdf
framework/Debug.h
framework/IpcClient.c
framework/IpcClient.h
framework/IpcMacros.h
framework/IpcServer.c
framework/IpcServerHdr.h
framework/IpcStructs.c
framework/IpcStructs.h
framework/IpcThrdPool.c
framework/IpcTypes.h [new file with mode: 0644]
framework/Makefile
framework/Makefile_TPCSSerDaemon [changed mode: 0644->0755]
framework/Makefile_TWPSerDaemon
framework/Makefile_channel_client
framework/Makefile_channel_server
framework/TCSImpl.c
framework/TCSImpl.h
framework/TPCSSerDaemon.c
framework/TPCSSerDaemon.h
framework/TWPImpl.c
framework/TWPImpl.h
framework/TWPSerDaemon.c
plugin/TCSPImpl.h
plugin/TWPPImpl.h
plugin/lib/libwpengine.so
plugin/plugin_i386_release/libengine.so
plugin/plugin_i386_release/libwpengine.so
test/scripts/CSFBuildExec.sh
test/scripts/PrepareForDevice.sh
test/scripts/PrepareForEmul.sh
test/test_cases/Makefile
test/test_cases/TCSTest.c
test/test_cases/TCSTestUtils.c
test/test_cases/TWPTest.c
test/test_cases/TWPTestUtils.c
test/test_cases/WPMakefile
test/test_cases/tpcsserdaemon/Makefile
test/test_cases/tpcsserdaemon/TPCSSerDaemonTest.c
test/test_cases/tpcsserdaemon/TPCSSerDaemonTest.h
test/test_cases/tpcsserdaemon/TPCSSerDaemonTestUtils.c
test/test_cases/tpcsserdaemon/TPCSSerDaemonTestUtils.h
test/test_cases/twpserdaemon/Makefile
test/test_cases/twpserdaemon/TWPSerDaemonTest.c
test/test_cases/twpserdaemon/TWPSerDaemonTest.h
test/test_cases/twpserdaemon/TWPSerDaemonTestUtils.c
test/test_cases/twpserdaemon/TWPSerDaemonTestUtils.h

index 7daa827..11855f9 100644 (file)
Binary files a/docs/Tizen Web Protection API Specification.pdf and b/docs/Tizen Web Protection API Specification.pdf differ
index b2d62ff..abd7b91 100644 (file)
Binary files a/docs/Tizen Web Protection Plugin API Specification.pdf and b/docs/Tizen Web Protection Plugin API Specification.pdf differ
index 802ea6a..c1df92d 100644 (file)
Binary files a/docs/Tizen Web Protection Service Daemon Test Specification.pdf and b/docs/Tizen Web Protection Service Daemon Test Specification.pdf differ
index ae1509f..6b85053 100644 (file)
Binary files a/docs/Tizen Web Protection Test Specification.pdf and b/docs/Tizen Web Protection Test Specification.pdf differ
index 53414a1..b099968 100644 (file)
@@ -45,10 +45,9 @@ extern "C" {
 
 #define LOG_TAG "CS_FRAMEWORK"
 
+#ifdef DEBUG
 #include <dlog/dlog.h>
 
-
-#ifdef DEBUG
 #define DLOG(prio, fmt, arg...) \
     do { SLOG(prio, LOG_TAG, fmt, ##arg); } while(0);
 
index b1aec2a..935b29c 100644 (file)
@@ -36,6 +36,7 @@
  * This file implements the IPC Client API functions used by Security framework.
  */
 
+#include <dbus/dbus.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -43,6 +44,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "Debug.h"
+#include "IpcClient.h"
 #include "IpcStructs.h"
 #include "TSCErrorCodes.h"
 
@@ -50,21 +53,12 @@ static DBusHandlerResult _IpcClientMsgFilter(DBusConnection *dbconn, DBusMessage
 static bool _IpcClientInit(IpcClientInfo *pInfo);
 static void _IpcClientDeInit(IpcClientInfo *pInfo);
 static void _IpcHandleAsyncReply(DBusPendingCall *pPendingCall, void *pThreadData);
-
-#ifdef DEBUG
-#define DEBUG_LOG(_fmt_, _param_...)    \
-    { \
-        fprintf(stderr, "[TSC Client] %s %d " _fmt_, __FILE__, __LINE__, _param_); \
-    }
-#else
-#define DEBUG_LOG(_fmt_, _param_...)
-#endif
-
+static void _free_str_array(char*** arr, int size);
 
 /**
- * Initializes and returns IPC info of client.
+ * Initializes and returns handle to client side IPC.
  */
-IpcClientInfo* IpcClientOpen(void)
+TSC_IPC_HANDLE IpcClientOpen(void)
 {
     IpcClientInfo *pInfo = NULL;
     pInfo = calloc(1, sizeof(IpcClientInfo));
@@ -78,23 +72,24 @@ IpcClientInfo* IpcClientOpen(void)
     if (!_IpcClientInit(pInfo))
         goto err_conn;
 
-    return pInfo;
+    return (TSC_IPC_HANDLE)pInfo;
 
 err_conn:
     if (pInfo)
         free(pInfo);
 
-    return NULL;
+    return INVALID_IPC_HANDLE;
 }
 
 /**
  * Close the client-side IPC and release the resources.
  */
-void IpcClientClose(IpcClientInfo *pInfo)
+void IpcClientClose(TSC_IPC_HANDLE hIpc)
 {
-    if (!pInfo)
+    if (hIpc == INVALID_IPC_HANDLE)
         return;
 
+    IpcClientInfo *pInfo = (IpcClientInfo *)hIpc;
     _IpcClientDeInit(pInfo);
     free(pInfo);
 }
@@ -114,9 +109,10 @@ char *_GetMsgIdPrefix(void)
 /**
  * Requests the Security framework's IPC server and returns back the reply.
  */
-int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *szMethod, int argc,
+int TSCSendMessageN(TSC_IPC_HANDLE hIpc, const char *service_name, const char *szMethod, int argc,
                     char **argv, int *argc_reply, char ***argv_reply, int timeout_milliseconds)
 {
+    IpcClientInfo *pInfo = (IpcClientInfo *)hIpc;
     DBusMessage *dbmsg = NULL;
     DBusMessage *reply_msg = NULL;
     DBusMessageIter dbiter;
@@ -161,7 +157,7 @@ int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *
     char *szIdPrefix = _GetMsgIdPrefix();
     if (!szIdPrefix || !dbus_message_iter_append_basic(&dbiter, DBUS_TYPE_STRING, &szIdPrefix))
     {
-        DEBUG_LOG("client_lib: Failed to append id prefix for %s.\n", szMethod);
+        DDBG("client_lib: Failed to append id prefix for %s.\n", szMethod);
         free(szIdPrefix);
         goto err_send;
     }
@@ -170,12 +166,12 @@ int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *
     {
         if (!dbus_validate_utf8(argv[i], &dberr))
         {
-            DEBUG_LOG("%s", "client_lib: Not valid utf8 string\n");
+            DDBG("%s", "client_lib: Not valid utf8 string\n");
             goto err_send;
         }
         if (!dbus_message_iter_append_basic(&dbiter, DBUS_TYPE_STRING, &argv[i]))
         {
-            DEBUG_LOG("client_lib: %s failed to append arguments\n", pInfo->pid);
+            DDBG("client_lib: %s failed to append arguments\n", pInfo->pid);
             goto err_send;
         }
     }
@@ -187,22 +183,22 @@ int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *
                                                           timeout_milliseconds,
                                                           &dberr);
 
-    if (dbus_error_is_set(&dberr))
+    if (reply_msg == NULL && dbus_error_is_set(&dberr))
     {
-        DEBUG_LOG("client_lib: Failed to end %s\n", dberr.message);
+        DDBG("client_lib: Failed to end %s\n", dberr.message);
         goto err_send;
     }
 
     if (reply_msg == NULL)
     {
-        DEBUG_LOG("%s\n", "client_lib: reply message is NULL");
+        DDBG("%s\n", "client_lib: reply message is NULL");
         goto err_send;
     }
 
     j = 0;
     if (!dbus_message_iter_init(reply_msg, &dbiter))
     {
-        DEBUG_LOG("%s\n", "client_lib: Message has no arguments.");
+        DDBG("%s\n", "client_lib: Message has no arguments.");
         goto zero_args;
     }
 
@@ -210,14 +206,14 @@ int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *
     {
         if (dbus_message_iter_get_arg_type(&dbiter) != DBUS_TYPE_STRING)
         {
-            DEBUG_LOG("client_lib: %s argument is not string\n", pInfo->pid);
+            DDBG("client_lib: %s argument is not string\n", pInfo->pid);
             goto err_send;
         }
 
         dbus_message_iter_get_basic(&dbiter, &pArgItem);
         if (!pArgItem)
         {
-            DEBUG_LOG("client_lib: %s arg is NULL\n", pInfo->pid);
+            DDBG("client_lib: %s arg is NULL\n", pInfo->pid);
             goto err_send;
         }
 
@@ -330,7 +326,7 @@ void *_SendMessageWorker(void *pData)
     {
         if (pThreadData == NULL)
         {
-            DEBUG_LOG("%s\n", "Nothing to send from thread. Deadlock!!");
+            DDBG("%s\n", "Nothing to send from thread. Deadlock!!");
             break;
         }
 
@@ -339,7 +335,7 @@ void *_SendMessageWorker(void *pData)
                                         pThreadData->pPrivate);
         if (pPendingData == NULL)
         {
-            DEBUG_LOG("%s\n", "Duplicating user data in thread failed. Deadlock!!");
+            DDBG("%s\n", "Duplicating user data in thread failed. Deadlock!!");
             break;
         }
 
@@ -348,7 +344,7 @@ void *_SendMessageWorker(void *pData)
                                                  &pPendingCall, pThreadData->timeout_milliseconds);
         if (!result || !pPendingCall)
         {
-            DEBUG_LOG("%s\n", "client_lib: SendAsync failed.");
+            DDBG("%s\n", "client_lib: SendAsync failed.");
             break;
         }
 
@@ -379,11 +375,11 @@ void *_SendMessageWorker(void *pData)
 
     if (iSentFailed && pThreadData)
     {
-        DEBUG_LOG("%s\n", "Error in send messsage worker. Unblocking..");
+        DDBG("%s\n", "Error in send messsage worker. Unblocking..");
         UnblockOnSent(pThreadData->pSharedData);
     }
 
-    DEBUG_LOG("%s\n", "Finished send message worker.");
+    DDBG("%s\n", "Finished send message worker.");
     return NULL;
 }
 
@@ -391,11 +387,12 @@ void *_SendMessageWorker(void *pData)
 /**
  * Requests the Security framework's IPC server asynchronously.
  */
-int TSCSendMessageAsync(IpcClientInfo *pInfo, const char *service_name, const char *szMethod,
-                        int argc, char **argv, TSC_CALL_HANDLE *pCallHandle, TSCCallback pCallback,
+int TSCSendMessageAsync(TSC_IPC_HANDLE hIpc, const char *service_name, const char *szMethod,
+                        int argc, char **argv, TSC_CALL_HANDLE *phCallHandle, TSCCallback pCallback,
                         void *pPrivate, int timeout_milliseconds)
 {
-    DEBUG_LOG("%s %s\n", "sendmessage async ", service_name);
+    DDBG("%s %s\n", "sendmessage async ", service_name);
+    IpcClientInfo *pInfo = (IpcClientInfo *)hIpc;
     DBusMessage *pMsg = NULL;
     DBusMessageIter dbiter;
     DBusError dberr;
@@ -428,21 +425,21 @@ int TSCSendMessageAsync(IpcClientInfo *pInfo, const char *service_name, const ch
     char *szIdPrefix = _GetMsgIdPrefix();
     if (!szIdPrefix || !dbus_message_iter_append_basic(&dbiter, DBUS_TYPE_STRING, &szIdPrefix))
     {
-        DEBUG_LOG("client_lib: Failed to append id prefix for %s.\n", szMethod);
+        DDBG("client_lib: Failed to append id prefix for %s.\n", szMethod);
         free(szIdPrefix);
         goto err_send;
     }
-    free(szIdPrefix);
+
     for (i = 0; i < argc; i++)
     {
         if (!dbus_validate_utf8(argv[i], &dberr))
         {
-            DEBUG_LOG("%s", "client_lib: Not valid utf8 string\n");
+            DDBG("%s", "client_lib: Not valid utf8 string\n");
             goto err_send;
         }
         if (!dbus_message_iter_append_basic(&dbiter, DBUS_TYPE_STRING, &argv[i]))
         {
-            DEBUG_LOG("client_lib: %s failed to append arguments\n", pInfo->pid);
+            DDBG("client_lib: %s failed to append arguments\n", pInfo->pid);
             goto err_send;
         }
     }
@@ -452,6 +449,8 @@ int TSCSendMessageAsync(IpcClientInfo *pInfo, const char *service_name, const ch
         dbus_message_set_no_reply(pMsg, TRUE);
 
     SharedData *pSharedData = _CreateSharedData(szIdPrefix, pMsg);
+    free(szIdPrefix);
+
     if (!pSharedData)
     {
         iErr = TSC_ERROR_INSUFFICIENT_RES;
@@ -473,26 +472,26 @@ int TSCSendMessageAsync(IpcClientInfo *pInfo, const char *service_name, const ch
     // Assert that the message is ready to be used.
     if (pThreadData->pSharedData->iSent)
     {
-        DEBUG_LOG("%s\n", "client_lib: Sent flag already set!!");
+        DDBG("%s\n", "client_lib: Sent flag already set!!");
         goto err_send;
     }
 
-    DEBUG_LOG("Before sending: %d\n", dbus_message_get_serial(pMsg));
+    DDBG("Before sending: %d\n", dbus_message_get_serial(pMsg));
     if (_RunDetachedThread(_SendMessageWorker, pThreadData) == -1)
     {
-        DEBUG_LOG("%s\n", "client_lib: Running thread failed!!");
+        DDBG("%s\n", "client_lib: Running thread failed!!");
         goto err_send;
     }
 
     BlockTillSent(pThreadData->pSharedData);
-    DEBUG_LOG("After sending: %d\n", dbus_message_get_serial(pMsg));
+    DDBG("After sending: %d\n", dbus_message_get_serial(pMsg));
 
-    if (pCallHandle)
+    if (phCallHandle)
     {
-        *pCallHandle = pThreadData->pSharedData->pCallHandle;
+        *phCallHandle = (TSC_CALL_HANDLE)pThreadData->pSharedData->pCallHandle;
         //TODO: should add here
-        DEBUG_LOG("method unique  id :%s\n", (*pCallHandle)->idUnique);
-        strncpy((*pCallHandle)->service_name, service_name, TSC_SERVER_NAME_LEN);
+        DDBG("method unique  id :%s\n", ((ClientCallHandle*) phCallHandle)->idUnique);
+        strncpy(pThreadData->pSharedData->pCallHandle->service_name, service_name, TSC_SERVER_NAME_LEN);
     }
     else
     {
@@ -516,9 +515,9 @@ err_send:
 /**
  * Releases the asynchronous call handle.
  */
-void TSCFreeSentMessageHandle(ClientCallHandle *pCallHandle)
+void TSCFreeSentMessageHandle(TSC_CALL_HANDLE hCallHandle)
 {
-    _FreeClientCallHandle(pCallHandle);
+    _FreeClientCallHandle((ClientCallHandle *)hCallHandle);
 }
 
 /**
@@ -550,14 +549,14 @@ static void _IpcHandleAsyncReply(DBusPendingCall *pPendingCall, void *pThreadDat
     pMsg = dbus_pending_call_steal_reply(pPendingCall);
     if (pMsg == NULL)
     {
-        DEBUG_LOG("%s\n", "client_lib: reply message is NULL");
+        DDBG("%s\n", "client_lib: reply message is NULL");
         goto reply_err;
     }
 
     i = 0;
     if (!dbus_message_iter_init(pMsg, &dbiter))
     {
-        DEBUG_LOG("%s\n", "client_lib: Async reply has no arguments");
+        DDBG("%s\n", "client_lib: Async reply has no arguments");
         goto reply_err;
     }
 
@@ -565,14 +564,14 @@ static void _IpcHandleAsyncReply(DBusPendingCall *pPendingCall, void *pThreadDat
     {
         if (dbus_message_iter_get_arg_type(&dbiter) != DBUS_TYPE_STRING)
         {
-            DEBUG_LOG("%s\n", "client_lib: Reply argument is not string");
+            DDBG("%s\n", "client_lib: Reply argument is not string");
             goto reply_err;
         }
 
         dbus_message_iter_get_basic(&dbiter, &pArgItem);
         if (!pArgItem)
         {
-            DEBUG_LOG("%s\n", "client_lib: Failed getting string arg from reply");
+            DDBG("%s\n", "client_lib: Failed getting string arg from reply");
             goto reply_err;
         }
 
@@ -599,14 +598,7 @@ static void _IpcHandleAsyncReply(DBusPendingCall *pPendingCall, void *pThreadDat
 
 reply_err:
     // Reset values being returned.
-    while (i)
-        free(argv[--i]);
-    if (argv)
-    {
-        free(argv);
-        argv = NULL;
-    }
-    argc = i;
+    _free_str_array(&argv, i);
 
 forward_reply:
     if(pMsg)
@@ -615,57 +607,49 @@ forward_reply:
         dbus_pending_call_unref(pPendingCall);
 
     if (pData && pData->pCallBack)
-        (*(pData->pCallBack))(pData->pPrivate, argc, argv);
+        (*(pData->pCallBack))(pData->pPrivate, argc, (const char**)argv);
 
-    DEBUG_LOG("%s\n", "client_lib: Async Reply Completed.");
+    _free_str_array(&argv, i);
+
+    DDBG("%s\n", "client_lib: Async Reply Completed.");
 }
 
 
 /**
  * Cancels an asynchronous request previously made to the Security framework's IPC server.
  * On success, releases the handle of the previously called asynchronous method.
- *
- * TODO: the ClientCallHandle
- * and TSC_CALL_HANDLE (typedef struct _ClientCallHandle * TSC_CALL_HANDLE;) is confusing
  */
-int TSCCancelMessage(IpcClientInfo *pInfo, ClientCallHandle *pCallHandle)
+int TSCCancelMessage(TSC_IPC_HANDLE hIpc, TSC_CALL_HANDLE hCallHandle)
 {
-    int argc_reply = 0;
-    char **argv_reply = NULL;
+    IpcClientInfo *pInfo = (IpcClientInfo *)hIpc;
+    ClientCallHandle *pCallHandle = (ClientCallHandle *)hCallHandle;
     char *argv_req[1];
     int iResult = -1;
 
     do
     {
-        DEBUG_LOG("%s\n", "client_lib: CANCELing.");
+        DDBG("%s\n", "client_lib: CANCELing.");
         if (!pInfo || !pCallHandle)
             break;
 
-        DEBUG_LOG("%s\n", "prepare cancel");
+        DDBG("%s\n", "prepare cancel");
         // Cancel the message call locally.
         dbus_pending_call_cancel(pCallHandle->pPendingCall);
 
         // Now request the server to abort the running of the method.
         argv_req[0] = pCallHandle->idUnique;
-        DEBUG_LOG("cancel method unique id:%s\n", argv_req[0]);
+        DDBG("cancel method unique id:%s\n", argv_req[0]);
         //TODO: need change here for cancel message
 
         TSC_CALL_HANDLE handle = NULL;
-        iResult = TSCSendMessageAsync(pInfo, pCallHandle->service_name, TSC_FN_CANCELMETHOD, 1,
-                                      argv_req, &handle, NULL, NULL, DEF_TIMEOUT);
-        DEBUG_LOG("%s\n", "client_lib: Sent Cancel to server.");
+        iResult = TSCSendMessageAsync((TSC_IPC_HANDLE)pInfo, pCallHandle->service_name,
+                                      TSC_FN_CANCELMETHOD, 1, argv_req, &handle, NULL, NULL,
+                                      DEF_TIMEOUT);
+        DDBG("%s\n", "client_lib: Sent Cancel to server.");
 
         if (iResult == 0)
         {
             _FreeClientCallHandle(pCallHandle);
-
-            // Ignore the returned values, if any.
-            if (argv_reply)
-            {
-                while (argc_reply)
-                    free(argv_reply[--argc_reply]);
-                free(argv_reply);
-            }
         }
 
     } while (0);
@@ -678,7 +662,7 @@ static DBusHandlerResult _IpcClientMsgFilter(DBusConnection *dbconn, DBusMessage
     IpcClientInfo *info = (IpcClientInfo*) data;
     if (dbus_message_is_signal(dbmsg, DBUS_INTERFACE_LOCAL, "Disconnected"))
     {
-       DEBUG_LOG("client_lib: %s disconnected by signal\n", info->pid);
+       DDBG("client_lib: %s disconnected by signal\n", info->pid);
         info->dbconn = NULL;
         return DBUS_HANDLER_RESULT_HANDLED;
     }
@@ -694,24 +678,29 @@ static bool _IpcClientInit(IpcClientInfo *pInfo)
     DBusError dberr;
     int ret;
 
+    if (!dbus_threads_init_default())
+    {
+        DDBG("failed dbus_threads_init_default %s\n", "");
+        goto err;
+    }
+
     dbus_error_init(&dberr);
 
-    dbus_threads_init_default();
 
     if (pInfo->dbconn != NULL)
         return false;
 
     pInfo->dbconn = dbus_bus_get(DBUS_BUS_SYSTEM, &dberr);
 
-    if (dbus_error_is_set(&dberr))
+    if (pInfo->dbconn == NULL && dbus_error_is_set(&dberr))
     {
-       DEBUG_LOG("client_lib: %s error in get connection %s\n", pInfo->pid, dberr.message);
+       DDBG("client_lib: %s error in get connection %s\n", pInfo->pid, dberr.message);
         goto err_get;
     }
 
     if (!pInfo->dbconn)
     {
-       DEBUG_LOG("client_lib: %s get connection is NULL\n", pInfo->pid);
+       DDBG("client_lib: %s get connection is NULL\n", pInfo->pid);
         goto err_get;
     }
 
@@ -719,21 +708,21 @@ static bool _IpcClientInit(IpcClientInfo *pInfo)
 
     if (!dbus_connection_add_filter(pInfo->dbconn, _IpcClientMsgFilter, pInfo, NULL))
     {
-       DEBUG_LOG("client_lib: %s failed to add filter %s\n", pInfo->pid, dberr.message);
+       DDBG("client_lib: %s failed to add filter %s\n", pInfo->pid, dberr.message);
         goto err_get;
     }
 
     ret = dbus_bus_request_name(pInfo->dbconn, pInfo->req_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &dberr);
 
-    if (dbus_error_is_set(&dberr))
+    if (ret == -1 && dbus_error_is_set(&dberr))
     {
-       DEBUG_LOG("client_lib: %s failed to request name %s\n", pInfo->pid, dberr.message);
+       DDBG("client_lib: %s failed to request name %s\n", pInfo->pid, dberr.message);
         goto err_get;
     }
 
     if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
     {
-       DEBUG_LOG("client_lib: %s failed, it is not primary owner %d\n", pInfo->req_name, ret);
+       DDBG("client_lib: %s failed, it is not primary owner %d\n", pInfo->req_name, ret);
         goto err_get;
     }
 
@@ -748,6 +737,7 @@ err_get:
     }
     dbus_error_free(&dberr);
 
+err:
     return false;
 }
 
@@ -757,14 +747,16 @@ static void _IpcClientDeInit(IpcClientInfo *pInfo)
         return;
 
     DBusError dberr;
+    int ret;
 
     if (!pInfo->dbconn)
         return;
 
     dbus_error_init(&dberr);
-    dbus_bus_release_name(pInfo->dbconn, pInfo->req_name, &dberr);
-    if (dbus_error_is_set(&dberr))
-       DEBUG_LOG("client_lib: %s failed to release name %s\n", pInfo->pid, dberr.message);
+    ret = dbus_bus_release_name(pInfo->dbconn, pInfo->req_name, &dberr);
+
+    if (ret == -1 && dbus_error_is_set(&dberr))
+       DDBG("client_lib: %s failed to release name %s\n", pInfo->pid, dberr.message);
 
     dbus_error_free(&dberr);
 
@@ -772,3 +764,22 @@ static void _IpcClientDeInit(IpcClientInfo *pInfo)
     dbus_connection_unref(pInfo->dbconn);
     pInfo->dbconn = NULL;
 }
+
+/**
+ * Release all the elements of the array and assign it to NULL.
+ */
+static void _free_str_array(char*** arr, int size)
+{
+    if (arr)
+    {
+        char **sArr = *arr;
+        if (sArr && *sArr)
+        {
+            while (size)
+                free(sArr[--size]);
+
+            free(sArr);
+            *arr = NULL;
+        }
+    }
+}
index 514ef34..42681c4 100644 (file)
@@ -43,79 +43,49 @@ extern "C" {
  * This file provides the IPC Client API functions used by Security framework.
  */
 
-#include <dbus/dbus.h>
-
-#include "IpcMacros.h"
-
+#include "IpcTypes.h"
 
 /*==================================================================================================
                                  CONSTANTS & ENUMS
 ==================================================================================================*/
 #define DEF_TIMEOUT -1
 
-/*==================================================================================================
-                                 FORWARD DECLARATIONS
-==================================================================================================*/
-struct _ClientCallHandle;
-
-/*==================================================================================================
-                                 STRUCTURES AND OTHER TYPEDEFS
-==================================================================================================*/
-
-/**
- * Asynchronous call handle.
- */
-typedef struct _ClientCallHandle * TSC_CALL_HANDLE;
-
-/**
- * Data structure to encapsulate client side information of the IPC.
- */
-typedef struct _IpcClientInfo IpcClientInfo;
-
-/**
- * CallBack Function type for Async method supported by the IPC.
- *
- * \param[in] pPrivate API caller's context information, supplied with TSCSendMessageAsync earlier.
- * \param[in] argc Length of the string in argv.
- * \param[in] argv Array of strings representing result value of asynchronous reply.
- */
-typedef void (*TSCCallback)(void *pPrivate, int argc, char **argv);
 
 /*==================================================================================================
                                      FUNCTION PROTOTYPES
 ==================================================================================================*/
 
 /**
- * \brief Initializes and returns IPC info of client.
+ * \brief Initializes client side IPC and returns its handle.
  *
- * Opens and initialises the client side IPC structure using the security 
+ * Opens and initialises the handle to client side IPC using the security 
  * framework defaults.
  *
  * This is a synchronous API.
  *
- * \return Return Type (IpcClientInfo*) \n
- * Pointer to structure containing IPC info - on success. \n
+ * \return Return Type (TSC_IPC_HANDLE) \n
+ * Client IPC handle - on success. \n
  * NULL - on failure. \n
  */
-IpcClientInfo* IpcClientOpen(void);
+TSC_IPC_HANDLE IpcClientOpen(void);
 
 /**
  * \brief Requests the Security framework's IPC server and returns back the reply.
  *
  * This is a synchronous API.
  *
- * \param[in] pInfo Client side IPC info returned by IpcClientOpen().
+ * \param[in] hIpc IPC handle returned by IpcClientOpen().
  *
  * \return Return Type (void) \n
  */
-void IpcClientClose(IpcClientInfo *pInfo);
+void IpcClientClose(TSC_IPC_HANDLE hIpc);
 
 /**
  * \brief Requests the Security framework's IPC server and returns back the reply.
  *
  * This is a synchronous API.
  *
- * \param[in] pInfo Client side IPC info.
+ * \param[in] hIpc Client side IPC handle.
  * \param[in] szMethod Name of the method called.
  * \param[in] argc Number of parameters passed in argv.
  * \param[in] argv Array of strings representing parameters for method called.
@@ -127,7 +97,7 @@ void IpcClientClose(IpcClientInfo *pInfo);
  * 0 - on send success. \n
  * -1 - on send failure. \n
  */
-int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *szMethod, int argc,
+int TSCSendMessageN(TSC_IPC_HANDLE hIpc, const char *service_name, const char *szMethod, int argc,
                     char **argv, int *argc_reply, char ***argv_reply, int timeout_milliseconds);
 
 /**
@@ -135,11 +105,11 @@ int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *
  *
  * This is an asynchronous API.
  *
- * \param[in] pInfo Client side IPC info.
+ * \param[in] hIpc Client side IPC handle.
  * \param[in] szMethod Name of the method called.
  * \param[in] argc Number of parameters passed in argv.
  * \param[in] argv Array of strings representing parameters for method called.
- * \param[out] pCallHandle Pointer to handle of the asynchronous message sent.
+ * \param[out] phCallHandle Pointer to handle of the asynchronous message sent.
  * \param[in] pCallback Callback function for the asynchronous reply.
  * \param[in] pPrivate API caller's context information, to be supplied with callback.
  * \param[in] timeout_milliseconds Timeout in milliseconds. -1 for default or 0 for no timeout.
@@ -148,31 +118,31 @@ int TSCSendMessageN(IpcClientInfo *pInfo, const char *service_name, const char *
  * 0 - on send success. \n
  * Error code - on send failure. \n
  */
-int TSCSendMessageAsync(IpcClientInfo *pInfo, const char *service_name, const char *szMethod, int argc, char **argv,
-                        TSC_CALL_HANDLE *pCallHandle, TSCCallback pCallback, void *pPrivate,
+int TSCSendMessageAsync(TSC_IPC_HANDLE hIpc, const char *service_name, const char *szMethod, int argc, char **argv,
+                        TSC_CALL_HANDLE *phCallHandle, TSCCallback pCallback, void *pPrivate,
                         int timeout_milliseconds);
 
 /**
  * \brief Releases the asynchronous call handle.
  *
- * \param[in] callHandle handle of the asynchronous message sent earlier.
+ * \param[in] hCallHandle Handle of the asynchronous message sent earlier.
  */
-void TSCFreeSentMessageHandle(TSC_CALL_HANDLE callHandle);
+void TSCFreeSentMessageHandle(TSC_CALL_HANDLE hCallHandle);
 
 /**
- * Cancels an asynchronous request previously made to the Security framework's IPC server.
+ * \brief Cancels an asynchronous request previously made to the Security framework's IPC server.
  * On success, releases the handle of the previously called asynchronous method.
  *
  * This is an asynchronous API.
  *
- * \param[in] pInfo Client side IPC info.
- * \param[in] callHandle handle of the asynchronous message sent earlier.
+ * \param[in] hIpc Client side IPC handle.
+ * \param[in] hCallHandle Handle of the asynchronous message sent earlier.
  *
  * \return Return Type (int) \n
  * 0 - on send success. \n
  * Error code - on failure. \n
  */
-int TSCCancelMessage(IpcClientInfo *pInfo, TSC_CALL_HANDLE callHandle);
+int TSCCancelMessage(TSC_IPC_HANDLE hIpc, TSC_CALL_HANDLE hCallHandle);
 
 #ifdef __cplusplus
 }
index 0c18b46..4c91412 100644 (file)
@@ -53,7 +53,7 @@
 #define TSC_FN_PROGRESSMETHOD  "_Progress_"
 #define TSC_FN_SHUTDOWN "IpcShutdown"
 
-#define TSC_MID_PREFIX_FORMAT  "%u_%u_"
+#define TSC_MID_PREFIX_FORMAT  "%u_%lu_"
 #define TSC_MID_FORMAT         TSC_MID_PREFIX_FORMAT"%u"
 #define TSC_MID_SVR_FORMAT     "%s%u"
 
index 7403ab4..3d85e85 100644 (file)
@@ -44,6 +44,7 @@
 #include <pthread.h>
 #include <signal.h>
 
+#include "Debug.h"
 #include "IpcMacros.h"
 #include "IpcServerError.h"
 #include "IpcServerHdr.h"
 
 
 #ifdef DEBUG
-#define DEBUG_LOG(_fmt_, _param_...)    \
-    { \
-        fprintf(stderr, "[TSC Server] %s %d " _fmt_, __FILE__, __LINE__, _param_); \
-    }
 #define DBUS_D_LOG(_dbusErr_, _fmt_, _param_...)    \
     { \
-        DEBUG_LOG("%s:%s; " _fmt_, _dbusErr_.name, _dbusErr_.message, _param_); \
+        DDBG("%s:%s; " _fmt_, _dbusErr_.name, _dbusErr_.message, _param_); \
     }
 #else
-#define DEBUG_LOG(_fmt_, _param_...)
 #define DBUS_D_LOG(_dbusErr_, _fmt_, _param_...)
 #endif
 
@@ -70,11 +66,9 @@ static void IterateList(IpcMethodHandle* pHandle)
     int count = 0;
     for(ph = pHandle; ph != NULL; ph = ph->pNext)
     {
-        DEBUG_LOG(".....handle addr: %u, uniqueid:%s, name:%s\n", ph, ph->unique_id, ph->pMethod->szMethod);
-        DEBUG_LOG("....pnext:%u\n", ph->pNext);
         count++;
     }
-    DEBUG_LOG(".....total count: %d\n", count);
+    DDBG(".....total count: %d\n", count);
 }
 
 inline DBusHandlerResult _IpcSendMessageAndUnref(DBusConnection *pConn, DBusMessage *pMsg)
@@ -159,16 +153,8 @@ void _FreeHandleConn(IpcServerInfo *pInfo)
     pthread_mutex_lock(&(pInfo->Lock));
     if (pInfo->pConn)
     {
-        DBusError dberr;
-        dbus_error_init(&dberr);
-
         dbus_connection_remove_filter(pInfo->pConn, _IpcServerMsgFilter, pInfo);
-        if (dbus_error_is_set(&dberr))
-        {
-            DEBUG_LOG("FreeHandleConn, remove_filter wrong:%s\n", dberr.message);
-        }
            pInfo->pConn = NULL;
-
     }
     pthread_mutex_unlock(&(pInfo->Lock));
 
@@ -203,7 +189,9 @@ int IpcServerAddMethod(TSC_SERVER_HANDLE hServer, IpcServerMethod *pMethod)
        IpcServerMethod* tpMethod = calloc(1, sizeof(IpcServerMethod));
        if (tpMethod == NULL)
        {
-           return -1;
+               free(pList);
+               pList = NULL;
+           return r;
        }
        // Copy method
 
@@ -229,12 +217,11 @@ int IpcServerAddMethod(TSC_SERVER_HANDLE hServer, IpcServerMethod *pMethod)
 int IpcServerRemoveMethod(TSC_SERVER_HANDLE hServer, METHODFUNC method)
 {
     IpcServerInfo *pInfo = NULL;
-    IpcServerMethodList *pList = NULL;
     IpcServerMethodList **pPrev = NULL;
     IpcServerMethodList *pCurr = NULL;
     int r = TSC_ERROR_REMOVE_METHOD_NOT_FOUND;
 
-    DEBUG_LOG("%s\n", "IpcServerRemoveMethod");
+    DDBG("%s\n", "IpcServerRemoveMethod");
     if (INVALID_TSC_SERVER_HANDLE == hServer)
         return r;
 
@@ -244,10 +231,10 @@ int IpcServerRemoveMethod(TSC_SERVER_HANDLE hServer, METHODFUNC method)
     pthread_mutex_lock(&(pInfo->Lock));
        for (pPrev = &pInfo->pMethodList; *pPrev; pPrev = &(*pPrev)->pNext)
        {
-               DEBUG_LOG("REMOVE method list name :%s\n", (*pPrev)->pMethod->szMethod);
+               DDBG("REMOVE method list name :%s\n", (*pPrev)->pMethod->szMethod);
                if ((*pPrev)->pMethod->method == method)
                {
-                       DEBUG_LOG("==== FIND REVMOE MOETHOD %s\n", " ");
+                       DDBG("==== FIND REVMOE MOETHOD %s\n", " ");
                        pCurr = *pPrev;
                        *pPrev = (*pPrev)->pNext;
             r = 0;
@@ -269,16 +256,20 @@ int IpcServerRemoveMethod(TSC_SERVER_HANDLE hServer, METHODFUNC method)
 
 TSC_SERVER_HANDLE IpcServerOpen(char *service_name)
 {
-    DEBUG_LOG("IpcServerOpen: %s\n", service_name);
+    DDBG("IpcServerOpen: %s\n", service_name);
        DBusError dberr;
-       dbus_error_init(&dberr);
 
-       dbus_threads_init_default();
+    if (!dbus_threads_init_default())
+    {
+        DDBG("failed dbus_threads_init_default %s\n", "");
+        goto err_ret;
+    }
 
-    dbus_validate_bus_name(service_name, &dberr);
-    if (dbus_error_is_set(&dberr))
+       dbus_error_init(&dberr);
+
+    if (!dbus_validate_bus_name(service_name, &dberr) && dbus_error_is_set(&dberr))
     {
-        DEBUG_LOG("it is invalid request name %s\n", "");
+        DDBG("it is invalid request name %s\n", "");
         goto err;
     }
 
@@ -296,11 +287,11 @@ TSC_SERVER_HANDLE IpcServerOpen(char *service_name)
 
        if (_IpcServerInit(pInfo, service_name))
        {
-           DEBUG_LOG("IpcServerInit failed: %s\n", service_name);
+           DDBG("IpcServerInit failed: %s\n", service_name);
            goto free_table;
        }
 
-    //DEBUG_LOG("IpcServerOpen  success conn:%s\n", pInfo->name);
+    //DDBG("IpcServerOpen  success conn:%s\n", pInfo->name);
     dbus_error_free(&dberr);
     return (TSC_SERVER_HANDLE) pInfo;
 
@@ -308,11 +299,13 @@ free_table:
     SAFE_FREE(pInfo->pTable);
 
 free_info:
-    DEBUG_LOG("IpcServerOpen free_info, conn:%s\n", pInfo->name);
+    DDBG("IpcServerOpen free_info, conn:%s\n", pInfo->name);
     FREE(pInfo);
 
 err:
     dbus_error_free(&dberr);
+
+err_ret:
     return INVALID_TSC_SERVER_HANDLE;
 }
 
@@ -324,7 +317,7 @@ int IpcServerMainLoop(TSC_SERVER_HANDLE hServer)
         if (pInfo->lDbus_listen_thread)
         {
             pthread_join(pInfo->lDbus_listen_thread, NULL);
-            DEBUG_LOG("finsihed main loop:%s\n", "==========");
+            DDBG("finsihed main loop:%s\n", "==========");
         }
 
     }
@@ -335,7 +328,7 @@ void IpcServerClose(TSC_SERVER_HANDLE *hServer)
        IpcServerInfo *pInfo = (IpcServerInfo *) *hServer;
        if (pInfo != (IpcServerInfo*)INVALID_TSC_SERVER_HANDLE)
        {
-           DEBUG_LOG("IpcServerClose:%s\n", pInfo->name);
+           DDBG("IpcServerClose:%s\n", pInfo->name);
            _WaitForListenThreadClose(pInfo);
 
            // Wait till no detachable thread is running
@@ -373,14 +366,14 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
     dbus_error_init(&dberr);
 
     pInfo->pConn = dbus_bus_get(DBUS_BUS_SYSTEM, &dberr);
-    if (dbus_error_is_set(&dberr))
+    if (pInfo->pConn == NULL && dbus_error_is_set(&dberr))
     {
         DBUS_D_LOG(dberr, "%s\n", "Server failed: connection NULL.");
         goto free_err;
     }
 
     ret = dbus_bus_request_name(pInfo->pConn, szServiceName, DBUS_NAME_FLAG_REPLACE_EXISTING, &dberr);
-    if (dbus_error_is_set(&dberr))
+    if (ret == -1 && dbus_error_is_set(&dberr))
     {
         DBUS_D_LOG(dberr, "%s\n", "server failed: request name.");
         goto free_conn;
@@ -389,14 +382,14 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
     // TODO: Why not allow DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER also?
     if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
     {
-       DEBUG_LOG("server failed: Not primary owner :%d\n", ret);
+       DDBG("server failed: Not primary owner :%d\n", ret);
         goto free_conn;
     }
 
     if (0 > snprintf(pInfo->rule, sizeof(pInfo->rule), "type='method_call', interface='%s'",
                      TSC_DBUS_INTERFACE))
     {
-        DEBUG_LOG("%s\n", "server failed: Unable to write rule");
+        DDBG("%s\n", "server failed: Unable to write rule");
         goto free_conn;
     }
 
@@ -407,9 +400,9 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
         goto free_conn;
     }
 
-    ret = dbus_connection_try_register_object_path(pInfo->pConn, TSC_DBUS_PATH, pInfo->pTable,
-                                                   pInfo, &dberr);
-    if (dbus_error_is_set(&dberr) || !ret)
+    if (!dbus_connection_try_register_object_path(pInfo->pConn, TSC_DBUS_PATH, pInfo->pTable,
+                                                   pInfo, &dberr)
+               && dbus_error_is_set(&dberr))
     {
         DBUS_D_LOG(dberr, "%s\n", "server failed: register object path");
         goto free_match;
@@ -419,34 +412,34 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
 
     if (!dbus_connection_add_filter(pInfo->pConn, _IpcServerMsgFilter, pInfo, NULL))
     {
-       DEBUG_LOG("%s\n", "server failed: add filter.");
+       DDBG("%s\n", "server failed: add filter.");
         goto free_register;
     }
 
     if (!dbus_connection_get_unix_fd(pInfo->pConn, &pInfo->fd) || pInfo->fd < 0)
     {
-       DEBUG_LOG("%s\n", "server failed: get fd.");
+       DDBG("%s\n", "server failed: get fd.");
         goto free_filter;
     }
 
     pInfo->pHandlePool = calloc(1, sizeof(IpcHandlePool));
     if (pInfo->pHandlePool == NULL)
     {
-        DEBUG_LOG("%s\n", "Thread pool alloc failed.");
+        DDBG("%s\n", "Thread pool alloc failed.");
         goto free_filter;
     }
 
     ret = IpcThrPoolInit(pInfo->pHandlePool, TSC_THREAD_POOL_NUMBERS);
     if (ret)
     {
-        DEBUG_LOG("%s\n", "*****Failed in IpcThrPoolInit");
+        DDBG("%s\n", "*****Failed in IpcThrPoolInit");
         goto free_handle;
     }
 
     ret = pthread_mutex_init(&(pInfo->Lock), NULL);
     if (ret)
     {
-        DEBUG_LOG("Failed to init IpcServerInfo lock %d\n", ret);
+        DDBG("Failed to init IpcServerInfo lock %d\n", ret);
         goto free_pool;
     }
 
@@ -454,14 +447,14 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
     pMethodCancel = calloc(1, sizeof(IpcServerMethod));
     if (pMethodCancel == NULL)
     {
-        DEBUG_LOG("%s\n", "Cancel alloc failed.");
+        DDBG("%s\n", "Cancel alloc failed.");
         goto free_mutex;
     }
 
     ret = snprintf(pMethodCancel->szMethod, sizeof(pMethodCancel->szMethod), "%s", TSC_FN_CANCELMETHOD);
     if (ret < 0)
     {
-        DEBUG_LOG("%s\n", "Cancel create failed.");
+        DDBG("%s\n", "Cancel create failed.");
         goto free_method_cancel;
     }
 
@@ -470,23 +463,21 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
     ret = IpcServerAddMethod((TSC_SERVER_HANDLE) pInfo,  pMethodCancel);
     if (ret)
     {
-        DEBUG_LOG("%s\n", "Cancel add failed.");
+        DDBG("%s\n", "Cancel add failed.");
         goto free_method_cancel;
     }
-    FREE(pMethodCancel);
-
 
     IpcServerMethod *pMethodProgress = calloc(1, sizeof(IpcServerMethod));
     if (pMethodProgress == NULL)
     {
-        DEBUG_LOG("%s\n", "Progress alloc failed.");
+        DDBG("%s\n", "Progress alloc failed.");
         goto free_method_cancel;
     }
 
     ret = snprintf(pMethodProgress->szMethod, sizeof(pMethodProgress->szMethod), "%s", TSC_FN_PROGRESSMETHOD);
     if (ret < 0)
     {
-        DEBUG_LOG("%s\n", "Progress create failed.");
+        DDBG("%s\n", "Progress create failed.");
         goto free_method_progress;
     }
 
@@ -496,23 +487,21 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
     ret = IpcServerAddMethod((TSC_SERVER_HANDLE) pInfo, pMethodProgress);
     if (ret)
     {
-        DEBUG_LOG("%s\n", "Progress add failed.");
+        DDBG("%s\n", "Progress add failed.");
         goto free_method_progress;
     }
-    FREE(pMethodProgress);
-
 
     IpcServerMethod *pMethodShutdown = calloc(1, sizeof(IpcServerMethod));
     if (pMethodShutdown == NULL)
     {
-        DEBUG_LOG("%s\n", "shutdown alloc failed.");
+        DDBG("%s\n", "shutdown alloc failed.");
         goto free_method_progress;
     }
 
     ret = snprintf(pMethodShutdown->szMethod, sizeof(pMethodShutdown->szMethod), "%s", TSC_FN_SHUTDOWN);
     if (ret < 0)
     {
-        DEBUG_LOG("%s\n", "Shutdown create failed.");
+        DDBG("%s\n", "Shutdown create failed.");
         goto free_method_shutdown;
     }
 
@@ -522,19 +511,21 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
     ret = IpcServerAddMethod((TSC_SERVER_HANDLE) pInfo, pMethodShutdown);
     if (ret)
     {
-        DEBUG_LOG("%s\n", "Shutdown add failed.");
+        DDBG("%s\n", "Shutdown add failed.");
         goto free_method_shutdown;
     }
-    FREE(pMethodShutdown);
+    SAFE_FREE(pMethodShutdown);
+    SAFE_FREE(pMethodProgress);
+    SAFE_FREE(pMethodCancel);
 
     pthread_mutex_lock(&(pInfo->Lock));
 
     ret = pthread_create(&(pInfo->lDbus_listen_thread), NULL, _IpcPopMessage, (void *)pInfo);
-    DEBUG_LOG("Creating thrd for Server: %s\n", pInfo->name);
+    DDBG("Creating thrd for Server: %s\n", pInfo->name);
 
     if (ret)
     {
-        DEBUG_LOG("%s(%d)\n", "** FAILED to launch thread", ret);
+        DDBG("%s(%d)\n", "** FAILED to launch thread", ret);
         pInfo->start_server_flag = false;
         pthread_mutex_unlock(&(pInfo->Lock));
         goto free_mutex;
@@ -545,11 +536,11 @@ int _IpcServerInit(IpcServerInfo *pInfo, char *szServiceName)
 
     return 0;
 free_method_shutdown:
-    FREE(pMethodShutdown);
+    SAFE_FREE(pMethodShutdown);
 free_method_progress:
-    FREE(pMethodProgress);
+    SAFE_FREE(pMethodProgress);
 free_method_cancel:
-    FREE(pMethodCancel);
+    SAFE_FREE(pMethodCancel);
 free_mutex:
     pthread_mutex_destroy(&(pInfo->Lock));
 free_pool:
@@ -562,20 +553,18 @@ free_register:
     //dbus_connection_unregister_object_path(pInfo->pConn, TSC_DBUS_PATH);
 free_match:
     //dbus_bus_remove_match(pInfo->pConn, pInfo->rule, &dberr);
-free_name:
-    //dbus_bus_release_name(pInfo->pConn, szServiceName, &dberr);
 free_conn:
     //dbus_connection_close(pInfo->pConn); TODO: Why not????
 free_err:
     dbus_error_free(&dberr);
-    DEBUG_LOG("%s", "_IpcServerInit free_err before return -1\n");
+    DDBG("%s", "_IpcServerInit free_err before return -1\n");
 err:
     return -1;
 }
 
 void _IpcServerDeInit(TSC_SERVER_HANDLE hServer)
 {
-    DEBUG_LOG("%s\n", "IpcServerDeInit========");
+    DDBG("%s\n", "IpcServerDeInit========");
        IpcServerInfo *pInfo = (IpcServerInfo *) hServer;
     if (pInfo)
     {
@@ -586,14 +575,14 @@ void _IpcServerDeInit(TSC_SERVER_HANDLE hServer)
         FreeIpcServerHandle((TSC_SERVER_HANDLE) pInfo);
     }
     //dbus_shutdown(); // for valgrind only
-    DEBUG_LOG("%s\n", "*_*_*_*_*_*_* Server is disconnected *_*_*_*_*_*_*_*_*");
+    DDBG("%s\n", "*_*_*_*_*_*_* Server is disconnected *_*_*_*_*_*_*_*_*");
 }
 
 
 DBusHandlerResult _IpcServerReplyMessage(DBusConnection *pConn, DBusMessage *pMsg,
                                                 char **pReply, int size)
 {
-    DEBUG_LOG("%s %d\n", "ReplyMessage size: ", size);
+    DDBG("%s %d\n", "ReplyMessage size: ", size);
     DBusMessage *pReplyMsg = NULL;
     DBusMessageIter    iter;
     int i;
@@ -612,7 +601,7 @@ DBusHandlerResult _IpcServerReplyMessage(DBusConnection *pConn, DBusMessage *pMs
     {
         if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &(pReply[i])))
         {
-            DEBUG_LOG("----- Replied string :%s\n", pReply[i]);
+            DDBG("----- Replied string :%s\n", pReply[i]);
             dbus_message_unref(pReplyMsg);
             return DBUS_HANDLER_RESULT_NEED_MEMORY;
         }
@@ -624,7 +613,7 @@ DBusHandlerResult _IpcServerReplyMessage(DBusConnection *pConn, DBusMessage *pMs
 DBusHandlerResult _IpcServerReplyError(DBusConnection *pConn, DBusMessage *pMsg,
                                               int iErrCode)
 {
-    DEBUG_LOG("%s\n", "IpcServerReplyError");
+    DDBG("%s\n", "IpcServerReplyError");
     DBusMessage *pErrMsg = NULL;
 
     if (!pConn || !pMsg)
@@ -640,16 +629,16 @@ DBusHandlerResult _IpcServerReplyError(DBusConnection *pConn, DBusMessage *pMsg,
 
 DBusHandlerResult _IpcServerMsgFilter(DBusConnection *pConn, DBusMessage *pMsg, void *pData)
 {
-    DEBUG_LOG("%s\n", "IpcServerMsgFilter");
+    DDBG("%s\n", "IpcServerMsgFilter");
     IpcServerInfo *pInfo = (IpcServerInfo*) pData;
     if (!pInfo)
     {
-       DEBUG_LOG("%s\n", "not handled the server info");
+       DDBG("%s\n", "not handled the server info");
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     }
     else if (dbus_message_is_signal(pMsg, DBUS_INTERFACE_LOCAL, "Disconnected"))
     {
-       DEBUG_LOG("%s\n", "server is disconnected by signal");
+       DDBG("%s\n", "server is disconnected by signal");
         IpcServerClose((TSC_SERVER_HANDLE*) pInfo);
         //return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
         return DBUS_HANDLER_RESULT_HANDLED;
@@ -663,42 +652,45 @@ DBusHandlerResult _IpcServerMsgHandler(void *user_data)
 {
     DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     IpcAsyncInfo *pAsync = user_data;
-    DBusConnection *pConn = pAsync->pConn;
-    DBusMessage *pMsg = pAsync->pMsg;
-    IpcServerInfo *pInfo = pAsync->pInfo;
 
-
-    bool handle_flag = false;
-    if (pInfo)
+    if (pAsync)
     {
-        DEBUG_LOG("==IpcServerMsgHandler:%s\n", pInfo->name);
-        IpcServerMethodList **pPrev;
-        pthread_mutex_lock(&(pInfo->Lock));
-        for (pPrev = &pInfo->pMethodList; *pPrev; pPrev = &(*pPrev)->pNext)
+        DBusMessage *pMsg = pAsync->pMsg;
+        IpcServerInfo *pInfo = pAsync->pInfo;
+
+        bool handle_flag = false;
+        if (pInfo)
         {
-            if ((*pPrev) && (*pPrev)->pMethod)
+            DDBG("==IpcServerMsgHandler:%s\n", pInfo->name);
+            IpcServerMethodList **pPrev;
+            pthread_mutex_lock(&(pInfo->Lock));
+            for (pPrev = &pInfo->pMethodList; *pPrev; pPrev = &(*pPrev)->pNext)
             {
-                if (dbus_message_is_method_call(pMsg, TSC_DBUS_INTERFACE, (*pPrev)->pMethod->szMethod)){
-                    DEBUG_LOG("FOUND method: %s\n", (*pPrev)->pMethod->szMethod);
-                    handle_flag = true;
-                    pAsync->pMethod = (*pPrev)->pMethod;
-                    break;
+                if ((*pPrev) && (*pPrev)->pMethod)
+                {
+                    if (dbus_message_is_method_call(pMsg, TSC_DBUS_INTERFACE, (*pPrev)->pMethod->szMethod)){
+                        DDBG("FOUND method: %s\n", (*pPrev)->pMethod->szMethod);
+                        handle_flag = true;
+                        pAsync->pMethod = (*pPrev)->pMethod;
+                        break;
+                    }
                 }
             }
+            pthread_mutex_unlock(&(pInfo->Lock));
+            if (handle_flag)
+            {
+                return _IpcServerProcessMessage(pAsync);
+            }
         }
-        pthread_mutex_unlock(&(pInfo->Lock));
-        if (handle_flag)
+        if (ret == DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
         {
-            return _IpcServerProcessMessage(pAsync);
-        }
-    }
-    if (ret == DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
-    {
-        if (pAsync && pAsync->pInfo && pAsync->pInfo->pHandlePool)
-        {
-            IpcThrPoolPut(pAsync->pInfo->pHandlePool, pAsync->pHandle);
+            if (pAsync->pInfo->pHandlePool)
+            {
+                IpcThrPoolPut(pAsync->pInfo->pHandlePool, pAsync->pHandle);
+            }
+            CleanupAsync(pAsync);
         }
-        CleanupAsync(pAsync);
+
     }
 
     return ret;
@@ -706,7 +698,7 @@ DBusHandlerResult _IpcServerMsgHandler(void *user_data)
 
 int _ParseDBusMessage(DBusMessage *pMsg, int *pargc, char ***argv)
 {
-    DBusBasicValue temp = {0};
+    DBusBasicValue temp = {{0}};
     int argc = 0;
     int iSize = TSC_REPLY_MSG_COUNT_AVERAGE;
     DBusMessageIter iter;
@@ -718,7 +710,7 @@ int _ParseDBusMessage(DBusMessage *pMsg, int *pargc, char ***argv)
         {
             if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
             {
-                DEBUG_LOG("%s\n", "wrong type");
+                DDBG("%s\n", "wrong type");
                 if (argc == 0)
                     iSize = 0;
                 iRet = TSC_ERROR_NOT_IMPLEMENTED;
@@ -727,7 +719,7 @@ int _ParseDBusMessage(DBusMessage *pMsg, int *pargc, char ***argv)
             dbus_message_iter_get_basic(&iter, &temp);
             if (!temp.str)
             {
-                DEBUG_LOG("%s\n", "no string");
+                DDBG("%s\n", "no string");
                 iRet = TSC_ERROR_INTERNAL;
                 goto clean_up;
             }
@@ -739,7 +731,7 @@ int _ParseDBusMessage(DBusMessage *pMsg, int *pargc, char ***argv)
 
                 if (!(*argv))
                 {
-                    DEBUG_LOG("PARSE message, insufficient: 7-1, argc:%d iSize:%d\n",  argc, iSize);
+                    DDBG("PARSE message, insufficient: 7-1, argc:%d iSize:%d\n",  argc, iSize);
                     iRet = TSC_ERROR_INSUFFICIENT_RES;
                     iSize = iSize - TSC_REPLY_MSG_COUNT_AVERAGE;
                     goto clean_up;
@@ -760,7 +752,7 @@ int _ParseDBusMessage(DBusMessage *pMsg, int *pargc, char ***argv)
 
             if (!(*argv)[argc])
             {
-                DEBUG_LOG("not engough memory: %s\n", "4");
+                DDBG("not engough memory: %s\n", "4");
                 iRet = TSC_ERROR_INSUFFICIENT_RES;
                 goto clean_up;
             }
@@ -771,7 +763,7 @@ int _ParseDBusMessage(DBusMessage *pMsg, int *pargc, char ***argv)
     }
     else
     {
-        DEBUG_LOG("%s\n", "Request message has no arguments");
+        DDBG("%s\n", "Request message has no arguments");
         *pargc = argc;
         return iRet;
     }
@@ -780,29 +772,24 @@ clean_up:
 
     if (iRet)
     {
-        DEBUG_LOG("ADDRESS to clean:%u\n", *argv);
         //Error code here
        int i = 0;
-       for (i = 0; i < iSize; i++)
+       if (*argv)
        {
-               if ((*argv)[i])
-                       free((*argv)[i]);
-               (*argv)[i] = NULL;
-       }
-               if (*argv)
+               for (i = 0; i < iSize; i++)
+               {
+                       if ((*argv)[i])
+                               free((*argv)[i]);
+                       (*argv)[i] = NULL;
+               }
                    free(*argv);
-        *argv = NULL;
+                   *argv = NULL;
+       }
     }
     else
     {
         // Everything went well till now...
         *pargc = argc;
-        int i = 0;
-
-
-        for (i = 0; i < argc; i++)
-            DEBUG_LOG("thread:%u, argc:%d, i:%d, Parsemessage :msg:%s\n", pthread_self(),argc, i,
-                      (*argv)[i]);
     }
 
     return iRet;
@@ -811,16 +798,15 @@ clean_up:
 
 DBusHandlerResult _IpcServerProcessMessage(void *user_data)
 {
-    DEBUG_LOG("%s\n", "IpcServerProcessMessage");
+    DDBG("%s\n", "IpcServerProcessMessage");
     IpcAsyncInfo *pAsync = user_data;
     DBusError dberr;
-    DBusMessageIter iter;
-    int iSize = TSC_REPLY_MSG_COUNT_AVERAGE;
     char **reply = NULL;
     int iFreeMtdHandle = 0;
     int len = 0;
 //    int iErr = DBUS_HANDLER_RESULT_HANDLED; // Return the result to caller of this function.
     int iRet = TSC_ERROR_MODULE_GENERIC;   // Return as result of method requested by client.
+    IpcMethodHandle *pMtdHandle = NULL;
 
     dbus_error_init(&dberr);
     if (pAsync->pConn == NULL)
@@ -828,7 +814,7 @@ DBusHandlerResult _IpcServerProcessMessage(void *user_data)
         goto clean_up;
     }
     // Here when calling method, pass the callback function
-    IpcMethodHandle *pMtdHandle = calloc(1, sizeof(IpcMethodHandle));
+    pMtdHandle = calloc(1, sizeof(IpcMethodHandle));
 
     if (pMtdHandle == NULL)
     {
@@ -854,20 +840,14 @@ DBusHandlerResult _IpcServerProcessMessage(void *user_data)
         }
 
         strncpy(pMtdHandle->unique_id, pAsync->async_unique_id, MSGHANDLE_LEN);
-
-        if (pMtdHandle->unique_id == NULL)
-        {
-            DEBUG_LOG("unable to copy unique_id:%u\n", pthread_self());
-            goto clean_up;
-        }
-
+        (pMtdHandle->unique_id)[MSGHANDLE_LEN] = '\0';
 
         pthread_mutex_lock(&pAsync->pInfo->Lock);
         (pAsync->pInfo->count)++;
         pMtdHandle->pNext = pAsync->pInfo->pRunningMethods;
         pAsync->pInfo->pRunningMethods = pMtdHandle;
 /*
-        DEBUG_LOG("============== after adding running method:%s\n", "------");
+        DDBG("============== after adding running method:%s\n", "------");
         IterateList(pMtdHandle);
 */
         pthread_mutex_unlock(&pAsync->pInfo->Lock);
@@ -877,7 +857,7 @@ DBusHandlerResult _IpcServerProcessMessage(void *user_data)
         pMtdHandle->iCancel = TSC_NON_CANCEL;
 
         // Skip the first params which is for unique_id
-        DEBUG_LOG("method to run:%s, argv[0]:%s\n", pAsync->pMethod->szMethod, pAsync->argv[0]);
+        DDBG("method to run:%s, argv[0]:%s\n", pAsync->pMethod->szMethod, pAsync->argv[0]);
 
         iRet = (pAsync->pMethod)->method((pAsync->pMethod)->pData, pAsync->argc - 1,
                                          &(pAsync->argv[1]), &reply, &len,
@@ -907,7 +887,7 @@ clean_up:
         {
             *pmpPrev = (*pmpPrev)->pNext;
             iFreeMtdHandle = 1;
-            DEBUG_LOG("FOUND method, and remove from running one, method:%s, uniquid:%s\n",
+            DDBG("FOUND method, and remove from running one, method:%s, uniquid:%s\n",
                       pAsync->pMethod->szMethod, pAsync->async_unique_id);
             IterateList(pAsync->pInfo->pRunningMethods);
             break;
@@ -919,8 +899,6 @@ clean_up:
     CleanupAsync(pAsync);
     dbus_error_free(&dberr);
 
-    DEBUG_LOG(">>>>> after search, mtdHandleId:%s, iFreeFlag:%d, thread:%u, pMtdHandle:%u\n",
-              pMtdHandle->unique_id, iFreeMtdHandle, pthread_self(), pMtdHandle);
     if (pMtdHandle && iFreeMtdHandle)
     {
         free(pMtdHandle);
@@ -933,7 +911,7 @@ clean_up:
 void *_IpcPopMessage(void *hServer)
 {
     IpcServerInfo *pInfo = (IpcServerInfo *) hServer;
-    DEBUG_LOG("=IpcPopMessage:%s\n", pInfo->name);
+    DDBG("=IpcPopMessage:%s\n", pInfo->name);
     int iRet = 0;
 
     while (pInfo != NULL && pInfo->pConn != NULL && pInfo->start_server_flag) {
@@ -967,13 +945,12 @@ void *_IpcPopMessage(void *hServer)
                 {
                     iRet = snprintf(pAsync->async_unique_id, MSGHANDLE_LEN, TSC_MID_SVR_FORMAT, pAsync->argv[0],
                                                        dbus_message_get_serial(pAsync->pMsg));
-                    //DEBUG_LOG("ASYNC_UNQIEU-DI: %s\n", pAsync->async_unique_id);
+                    //DDBG("ASYNC_UNQIEU-DI: %s\n", pAsync->async_unique_id);
                     if (iRet < 0)
                         break;
 
-                    pthread_t lthread;
                     iRet = _RunDetachedThread(_IpcServerMsgHandler, pAsync);
-                    DEBUG_LOG("====RunDetachedThread ret:%d\n", iRet);
+                    DDBG("====RunDetachedThread ret:%d\n", iRet);
                 }
 
                 if (iRet)
@@ -985,7 +962,7 @@ void *_IpcPopMessage(void *hServer)
                }
         }
     }
-    DEBUG_LOG("popmessage ended :%s\n", "============");
+    DDBG("popmessage ended :%s\n", "============");
 
     return NULL;
 }
@@ -1035,7 +1012,7 @@ int IpcServerCallbackMethod(TSC_METHOD_HANDLE *pMHandle, TSC_METHOD_REASON_CODE
         if (p_MHandle->iCancel == TSC_IS_CANCEL)
         {
             iRet = 0;
-            DEBUG_LOG("%s", "callback check, it is cancel true\n");
+            DDBG("%s", "callback check, it is cancel true\n");
         }
         pthread_mutex_unlock(&(p_MHandle->Lock));
     }
@@ -1060,11 +1037,11 @@ int IpcCancelMethod(void *pData, int argc, char **argv, char ***szReply, int *le
     int ret = 0;
     if (argc > 0)
     {
-        DEBUG_LOG("IpcCancelMethod unique_id %s\n", argv[0]);
+        DDBG("IpcCancelMethod unique_id %s\n", argv[0]);
     }
     else
     {
-        DEBUG_LOG("%s\n", "Error params in cancel method");
+        DDBG("%s\n", "Error params in cancel method");
     }
 
     //TODO :error checking
@@ -1082,13 +1059,13 @@ int IpcCancelMethod(void *pData, int argc, char **argv, char ***szReply, int *le
 
     for (pmpPrev = &(pInfo->pRunningMethods); *pmpPrev; pmpPrev = &((*pmpPrev)->pNext))
     {
-        DEBUG_LOG("Method to cancel: %s, list method:%s\n", argv[0], (*pmpPrev)->unique_id);
+        DDBG("Method to cancel: %s, list method:%s\n", argv[0], (*pmpPrev)->unique_id);
         if (strcmp((*pmpPrev)->unique_id, argv[0]) == 0)
         {
-            DEBUG_LOG("%s\n", "found the running method to cancel");
+            DDBG("%s\n", "found the running method to cancel");
             pthread_mutex_lock(&(pMHandle->Lock));
             (*pmpPrev)->iCancel = TSC_IS_CANCEL;
-            DEBUG_LOG("%s %s\n", "set is cancel to true for this method: ", (*pmpPrev)->unique_id);
+            DDBG("%s %s\n", "set is cancel to true for this method: ", (*pmpPrev)->unique_id);
             //TODO: should we return something?
             *len = 1;
             *szReply = calloc(1, sizeof(char*) *(*len));
@@ -1099,7 +1076,7 @@ int IpcCancelMethod(void *pData, int argc, char **argv, char ***szReply, int *le
     }
     pthread_mutex_unlock(&(pInfo->Lock));
 
-    DEBUG_LOG("%s\n", "END OF cancel method");
+    DDBG("%s\n", "END OF cancel method");
     return ret;
 }
 
@@ -1108,7 +1085,7 @@ int IpcCancelMethod(void *pData, int argc, char **argv, char ***szReply, int *le
 int
 IpcGetProgressMethod(void *pData, int argc, char **argv, char ***szReply, int *len, CALLBACKFUNC callback, TSC_METHOD_HANDLE *handle)
 {
-    DEBUG_LOG("%s\n", "IpcGetProgressMethod");
+    DDBG("%s\n", "IpcGetProgressMethod");
     IpcMethodHandle *pMHandle = (IpcMethodHandle*) handle;
     IpcServerInfo *pInfo = (IpcServerInfo*) pMHandle->pInfo;
 
@@ -1117,15 +1094,15 @@ IpcGetProgressMethod(void *pData, int argc, char **argv, char ***szReply, int *l
     IpcMethodHandle **pmpPrev;
     for (pmpPrev = &(pInfo->pRunningMethods); *pmpPrev; pmpPrev = &((*pmpPrev)->pNext))
     {
-        DEBUG_LOG("running methods unique id :%s,  passing id :%s \n", (*pmpPrev)->unique_id, argv[0]);
+        DDBG("running methods unique id :%s,  passing id :%s \n", (*pmpPrev)->unique_id, argv[0]);
 
         if (!strcmp((*pmpPrev)->unique_id, argv[0]))
         {
-            DEBUG_LOG("=== found running method to get progress\n", argv[0]);
+            DDBG("=== found running method to get progress %s\n", argv[0]);
             // get the running method, update its status
             *len = 1;
             *szReply = calloc(1, sizeof(char*) * 10);
-            DEBUG_LOG("-- status to reply :%s\n",(*pmpPrev)->cStatus);
+            DDBG("-- status to reply :%s\n",(*pmpPrev)->cStatus);
             (*szReply)[0] = strdup((*pmpPrev)->cStatus);
             break;
         }
@@ -1136,85 +1113,91 @@ IpcGetProgressMethod(void *pData, int argc, char **argv, char ***szReply, int *l
 int
 IpcShutdown(void *pData, int argc, char **argv, char ***szReply, int *len, CALLBACKFUNC callback, TSC_METHOD_HANDLE *handle)
 {
-    DEBUG_LOG("==============%s\n", "IpcShutdownMethod");
+    DDBG("==============%s\n", "IpcShutdownMethod");
     IpcMethodHandle *pMHandle = (IpcMethodHandle*) handle;
     IpcServerInfo *pInfo = (IpcServerInfo*) pMHandle->pInfo;
 
     pthread_mutex_lock(&(pInfo->Lock));
     pInfo->start_server_flag = false;
     pthread_mutex_unlock(&(pInfo->Lock));
-    DEBUG_LOG("end of shutdown:%s\n", "===================");
+    DDBG("end of shutdown:%s\n", "===================");
     return 0;
 }
 
 
 void FreeIpcServerHandle(TSC_SERVER_HANDLE hServer)
 {
-    DEBUG_LOG("%s\n", "FreeIpcServerHandle");
+    DDBG("%s\n", "FreeIpcServerHandle");
     IpcServerInfo *pInfo = (IpcServerInfo*) hServer;
 
-    // Free MethodList
-    IpcServerMethodList *pCurr = pInfo->pMethodList;
-    IpcServerMethodList *pPrev;
-
-    while (pCurr)
+    if (pInfo)
     {
-        pPrev = pCurr;
-        pCurr = pCurr->pNext;
-        DEBUG_LOG("*****pPrev method is 0 :%s\n", pPrev->pMethod->szMethod);
+        pthread_mutex_lock(&(pInfo->Lock));
+        // Free MethodList
+        IpcServerMethodList *pCurr = pInfo->pMethodList;
+        IpcServerMethodList *pPrev;
 
-        if (pPrev)
+        while (pCurr)
         {
-            if (pPrev->pMethod)
-            {
-                if (pPrev->pMethod->method == (METHODFUNC) IpcCancelMethod
-                        || pPrev->pMethod->method == (METHODFUNC) IpcGetProgressMethod
-                        || pPrev->pMethod->method == (METHODFUNC) IpcShutdown)
-                    free(pPrev->pMethod);
+            pPrev = pCurr;
+            pCurr = pCurr->pNext;
+            DDBG("*****pPrev method is 0 :%s\n", pPrev->pMethod->szMethod);
 
-                pPrev->pMethod = NULL;
-            }
-            if (pPrev->pNext)
+            if (pPrev)
             {
-                pPrev->pNext = NULL;
+                if (pPrev->pMethod)
+                {
+                    if (pPrev->pMethod->method == (METHODFUNC) IpcCancelMethod
+                            || pPrev->pMethod->method == (METHODFUNC) IpcGetProgressMethod
+                            || pPrev->pMethod->method == (METHODFUNC) IpcShutdown)
+                    {
+                       free(pPrev->pMethod);
+                    }
+                    pPrev->pMethod = NULL;
+                }
+                if (pPrev->pNext)
+                {
+                       pPrev->pNext = NULL;
+                }
+
+                free(pPrev);
+                pPrev = NULL;
             }
-            free(pPrev);
-            pPrev = NULL;
         }
-    }
 
-    pInfo->pMethodList = NULL;
+        pInfo->pMethodList = NULL;
+        pInfo->pRunningMethods = NULL;
 
-    pInfo->pRunningMethods = NULL;
+        if (pInfo->pHandlePool)
+            IpcThrPoolFree(&pInfo->pHandlePool);
 
-    if (pInfo->pHandlePool)
-        IpcThrPoolFree(&pInfo->pHandlePool);
+        pthread_mutex_unlock(&(pInfo->Lock));
 
-    pthread_mutex_destroy(&(pInfo->Lock));
+        pthread_mutex_destroy(&(pInfo->Lock));
 
-    if (pInfo->pTable)
-        free(pInfo->pTable);
-    pInfo->pTable = NULL;
+        if (pInfo->pTable)
+            free(pInfo->pTable);
+        pInfo->pTable = NULL;
 
-    if (pInfo->pConn)
-    {
-        DBusError dberr;
-        dbus_error_init(&dberr);
+        if (pInfo->pConn)
+        {
+            DBusError dberr;
+            dbus_error_init(&dberr);
 
-        dbus_connection_remove_filter(pInfo->pConn, _IpcServerMsgFilter, pInfo);
-        dbus_connection_unregister_object_path(pInfo->pConn, TSC_DBUS_PATH);
-        dbus_bus_remove_match(pInfo->pConn, pInfo->rule, &dberr);
+            dbus_connection_remove_filter(pInfo->pConn, _IpcServerMsgFilter, pInfo);
+            dbus_connection_unregister_object_path(pInfo->pConn, TSC_DBUS_PATH);
+            dbus_bus_remove_match(pInfo->pConn, pInfo->rule, &dberr);
 
-        dbus_bus_release_name(pInfo->pConn, TSC_DBUS_SERVER, &dberr);
+            dbus_bus_release_name(pInfo->pConn, TSC_DBUS_SERVER, &dberr);
 
-        dbus_connection_unref(pInfo->pConn);
-        dbus_error_free(&dberr);
-    }
-    pInfo->pConn = NULL;
+            dbus_connection_unref(pInfo->pConn);
+            dbus_error_free(&dberr);
+        }
+        pInfo->pConn = NULL;
 
-    if (pInfo)
         free(pInfo);
-    pInfo = NULL;
+        pInfo = NULL;
+    }
 }
 
 
index 556a884..d48d4d2 100644 (file)
@@ -46,7 +46,7 @@ extern "C" {
  * Forward Declarations.
  */
 /*struct IpcServerInfo;*/
-
+typedef struct _IpcServerInfo IpcServerInfo;
 
 /**
  * Keep registered methods list
@@ -64,8 +64,8 @@ typedef struct _IpcMethodHandle
 {
     IpcServerMethod *pMethod;
     void *pData;
-    struct IpcServerInfo *pInfo;
-    char unique_id[MSGHANDLE_LEN]; //uniquely identify the running method
+    IpcServerInfo *pInfo;
+    char unique_id[MSGHANDLE_LEN + 1]; //uniquely identify the running method
     int iCancel;  // 1 is cancel, 0 not cancel
     char *cStatus;    // any status
     pthread_mutex_t Lock;
@@ -76,9 +76,9 @@ typedef struct _IpcMethodHandle
 /**
  *  Single context per server connection.
  */
-typedef struct _IpcServerInfo
+struct _IpcServerInfo
 {
-    char name[TSC_SERVER_NAME_LEN];
+    char name[TSC_SERVER_NAME_LEN + 1];
     DBusConnection *pConn;
     IpcServerMethodList *pMethodList;   // available methods list
     char rule[TSC_INFO_RULE_LEN];
@@ -90,7 +90,7 @@ typedef struct _IpcServerInfo
     int count;
     IpcMethodHandle *pRunningMethods;  // current running methods
     pthread_mutex_t Lock;   // mutex to manage methods - iteration, add, remove.
-} IpcServerInfo;
+};
 
 
 /**
@@ -105,7 +105,7 @@ typedef struct _IpcAsyncInfo
     char **argv;
     IpcServerMethod *pMethod;
     IpcHandles *pHandle;
-    char async_unique_id[MSGHANDLE_LEN]; //uniquely identify the running method
+    char async_unique_id[MSGHANDLE_LEN + 1]; //uniquely identify the running method
 } IpcAsyncInfo;
 
 int _IpcServerInit(IpcServerInfo *pServerInfo, char *szServiceName);
index 95ea210..1d73751 100644 (file)
@@ -85,7 +85,7 @@ int _CreateClientCallHandle(ClientCallHandle **ppHandle, const char *szPrefix, d
         if (!pHandle)
             break;
 
-        if (iRet = _AssignToClientCallHandle(pHandle, szPrefix, serial, pPendingCall))
+        if ((iRet = _AssignToClientCallHandle(pHandle, szPrefix, serial, pPendingCall)))
             break;
 
         *ppHandle = pHandle;
@@ -129,7 +129,7 @@ SharedData *_CreateSharedData(const char *szCallHandlePrefix, DBusMessage *pMsg)
         if (!pMsg)
             break;
 
-        if ((pSharedData = (SharedData *)malloc(sizeof(SharedData))) == NULL)
+        if ((pSharedData = (SharedData *)calloc(1, sizeof(SharedData))) == NULL)
             break;
 
         if (0 > snprintf(pSharedData->szCallHandlePrefix, MSGHANDLE_LEN, "%s", szCallHandlePrefix))
index 179c1df..d312a24 100644 (file)
@@ -1,22 +1,22 @@
 /*
     Copyright (c) 2014, McAfee, Inc.
-    
+
     All rights reserved.
-    
+
     Redistribution and use in source and binary forms, with or without modification,
     are permitted provided that the following conditions are met:
-    
+
     Redistributions of source code must retain the above copyright notice, this list
     of conditions and the following disclaimer.
-    
+
     Redistributions in binary form must reproduce the above copyright notice, this
     list of conditions and the following disclaimer in the documentation and/or other
     materials provided with the distribution.
-    
+
     Neither the name of McAfee, Inc. nor the names of its contributors may be used
     to endorse or promote products derived from this software without specific prior
     written permission.
-    
+
     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 #ifndef IPCSTRUCTS_H
 #define IPCSTRUCTS_H
 
-#ifdef __cplusplus 
+#ifdef __cplusplus
 extern "C" {
 #endif
 
 /**
  * \file IpcStructs.h
  * \brief Header File for structures by Ipc.
- *  
+ *
  * This file implements the structures needed by IPC Client, used by Security framework.
  */
 
+#include <dbus/dbus.h>
 #include <pthread.h>
 
-#include "IpcClient.h"
+#include "IpcMacros.h"
+#include "IpcTypes.h"
 
 /*==================================================================================================
                                  STRUCTURES AND OTHER TYPEDEFS
@@ -58,18 +60,18 @@ typedef struct _ClientCallHandle
 {
     char idUnique[MSGHANDLE_LEN];
     DBusPendingCall *pPendingCall;
-    char service_name[TSC_SERVER_NAME_LEN];
+    char service_name[TSC_SERVER_NAME_LEN + 1];
 } ClientCallHandle;
 
 /**
- * DBus connection related info.
+ * IPC client connection info.
  */
-struct _IpcClientInfo
+typedef struct _IpcClientInfo
 {
     DBusConnection *dbconn;
     char req_name[TSC_REQ_STR_LEN];
     char pid[TSC_REQ_STR_LEN];
-};
+} IpcClientInfo;
 
 /**
  * Data shared between the synchronized thread. It wraps the asynchronous call handle.
@@ -131,7 +133,7 @@ void _FreeThreadData(void *pThreadData);
 
 #ifdef __cplusplus
 }
-#endif 
+#endif
 
 #endif  /* IPCSTRUCTS_H */
 
index 77c03d4..253b638 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 #include <pthread.h>
+#include "Debug.h"
 #include "IpcThrdPool.h"
 
-#ifdef DEBUG
-#define DEBUG_LOG(_fmt_, _param_...)    \
-    { \
-        fprintf(stderr, "[TSC Server] %s %d " _fmt_, __FILE__, __LINE__, _param_); \
-    }
-#else
-#define DEBUG_LOG(_fmt_, _param_...)
-#endif
-
 static void IpcThrPoolReset(IpcHandlePool *pHPool)
 {
     IpcHandles *pHandle;
@@ -88,7 +80,7 @@ static int AddHandleToThrPool(IpcHandlePool *pHPool)
     IpcHandles *pHandle = NULL;
     if ((pHandle = (IpcHandles *) calloc(1, sizeof(IpcHandles))) == NULL)
     {
-        DEBUG_LOG("%s\n", "calloc IpcHandles");
+        DDBG("%s\n", "calloc IpcHandles");
         return -1;
     }
 
@@ -111,7 +103,7 @@ int IpcThrPoolInit(IpcHandlePool *pHPool, int iNumHandles)
 
     if (pthread_mutex_init(&pHPool->Lock, NULL))
     {
-        DEBUG_LOG("%s\n", "mutex init");
+        DDBG("%s\n", "mutex init");
         return -1;
     }
 
@@ -119,7 +111,7 @@ int IpcThrPoolInit(IpcHandlePool *pHPool, int iNumHandles)
     if (pthread_cond_init(&pHPool->Cond, NULL))
     {
         pthread_mutex_destroy(&pHPool->Lock);
-        DEBUG_LOG("%s\n", "cond_init");
+        DDBG("%s\n", "cond_init");
         return -1;
     }
 
@@ -130,7 +122,7 @@ int IpcThrPoolInit(IpcHandlePool *pHPool, int iNumHandles)
     {
         if (0 != AddHandleToThrPool(pHPool))
         {
-            DEBUG_LOG("%s\n", "add to thrpool");
+            DDBG("%s\n", "add to thrpool");
             result = -1;
             break;
         }
diff --git a/framework/IpcTypes.h b/framework/IpcTypes.h
new file mode 100644 (file)
index 0000000..296c03b
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+    Copyright (c) 2014, McAfee, Inc.
+
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without modification,
+    are permitted provided that the following conditions are met:
+
+    Redistributions of source code must retain the above copyright notice, this list
+    of conditions and the following disclaimer.
+
+    Redistributions in binary form must reproduce the above copyright notice, this
+    list of conditions and the following disclaimer in the documentation and/or other
+    materials provided with the distribution.
+
+    Neither the name of McAfee, Inc. nor the names of its contributors may be used
+    to endorse or promote products derived from this software without specific prior
+    written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+    IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+    OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+    OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef IPCTYPES_H
+#define IPCTYPES_H
+
+/**
+ * \file IpcTypes.h
+ * \brief Data types and structs for Security framework IPC clients.
+ *
+ * This file provides the data types and structs needed by clients of Security framework IPC.
+ */
+
+/*==================================================================================================
+                                 STRUCTURES AND OTHER TYPEDEFS
+==================================================================================================*/
+
+/**
+ * \brief CallBack Function type for Async method supported by the IPC.
+ *
+ * \param[in] pPrivate API caller's context information, supplied with TSCSendMessageAsync earlier.
+ * \param[in] argc Length of the string in argv.
+ * \param[in] argv Array of strings representing result value of asynchronous reply.
+ */
+typedef void (*TSCCallback)(void *pPrivate, int argc, const char **argv);
+
+/**
+ * Client side IPC handles.
+ */
+#define TSCHANDLE(n) struct n##_struct { int iDummy; }; typedef struct n##_struct *n
+
+/**
+ * IPC client handle.
+ */
+TSCHANDLE(TSC_IPC_HANDLE);
+#define INVALID_IPC_HANDLE ((TSC_IPC_HANDLE) NULL)
+
+/**
+ * Asynchronous call handle.
+ */
+TSCHANDLE(TSC_CALL_HANDLE);
+
+#endif  /* IPCTYPES_H */
+
index a7a50f8..bd3751a 100644 (file)
@@ -62,7 +62,22 @@ else
        CFLAGS := -g -fPIC $(INCLUDE) -DUNIX -DDEBUG $(CFLAGS)
 endif
 
-CFLAGS := $(CFLAGS) $(PKCL_CFLAGS) $(TCS_CFLAGS)
+CFLAGS := $(CFLAGS) $(PKCL_CFLAGS) $(TCS_CFLAGS) -Wall -Werror
+
+# Define a list of pkg-config packages we want to use
+pkg_packages = dlog
+
+PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
+PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
+
+# Combine user supplied, additional, and pkg-config flags
+ifeq ($(TCS_CFG), release)
+       PKGLD_FLAGS = 
+       PKGCFLAGS =
+else
+       PKGLD_FLAGS += $(PKG_LDFLAGS) -L./lib
+       PKGCFLAGS += -Wall -I$(SRCDIR) $(PKCL_CFLAGS) $(PKG_CFLAGS)
+endif
 
 SOURCES = $(SRCDIR)/TCSImpl.c $(SRCDIR)/TWPImpl.c
 
@@ -72,7 +87,7 @@ MKDEP = mkdep -f .depend
 
 
 $(OUTDIR)/%.o: $(SRCDIR)/%.c
-       $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(SRCDIR)/$*.c
+       $(CC) $(CFLAGS) $(PKGCFLAGS) -I. -o $(OUTDIR)/$*.o -c $(SRCDIR)/$*.c
 
 all: $(OUTDIR) .depend $(TARGET)
 
@@ -80,7 +95,7 @@ all: $(OUTDIR) .depend $(TARGET)
        $(MKDEP) $(CFLAGS) $(SOURCES)
 
 $(TARGET): $(OBJECTS)
-       $(LD) -shared -Wl,-zdefs -o $(TARGET) $(OBJECTS) $(LD_FLAGS)
+       $(LD) -shared -Wl,-zdefs -o $(TARGET) $(OBJECTS) $(LD_FLAGS) $(PKGLD_FLAGS)
 
 #      $(AR) -cr $(TARGET) $(OBJECTS)
 
old mode 100644 (file)
new mode 100755 (executable)
index 3c473dd..7eb3ccf
@@ -71,7 +71,7 @@ PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
 LD_FLAGS += $(PKG_LDFLAGS) -lscserver -L./lib -lxml2
 
 GBS_CFLAGS = -I${SYSROOT}/usr/include/dbus-1.0 -I${SYSROOT}/usr/lib/dbus-1.0/include -I${SYSROOT}/usr/include/libxml2
-CFLAGS += -Wall -I$(SRCDIR) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS)
+CFLAGS += -Wall -Werror -I$(SRCDIR) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS)
 
 SOURCES = $(SRCDIR)/TPCSSerDaemon.c \
                $(SRCDIR)/IpcForkDaemon.c
@@ -90,7 +90,7 @@ all: $(OUTDIR) .depend $(TARGET)
        $(MKDEP) $(CFLAGS) $(SOURCES)
 
 $(TARGET): $(OBJECTS)
-       $(LD) -Wl,-zdefs -o $(TARGET) $(OBJECTS) $(LD_FLAGS)
+       $(LD) -Wl,-zdefs -o $(TARGET) $(OBJECTS) $(LD_FLAGS) $(PKG_LDFLAGS)
 
 #      $(AR) -cr $(TARGET) $(OBJECTS)
 
index e659faf..aacfd07 100644 (file)
@@ -62,7 +62,7 @@ else
        CFLAGS := -g -fPIC $(INCLUDE) -DUNIX -DDEBUG $(CFLAGS)
 endif
 
-CFLAGS := $(CFLAGS) $(PKCL_CFLAGS) $(TCS_CFLAGS)
+CFLAGS := $(CFLAGS) $(PKCL_CFLAGS) $(TCS_CFLAGS) -Wall -Werror
 
 SOURCES = $(SRCDIR)/TWPSerDaemon.c \
                $(SRCDIR)/IpcForkDaemon.c 
@@ -73,7 +73,11 @@ OBJECTS = $(OUTDIR)/TWPSerDaemon.o \
 MKDEP = mkdep -f .depend
 
 # Define a list of pkg-config packages we want to use
-pkg_packages = dbus-glib-1 dlog
+ifeq ($(TCS_CFG), release)
+       pkg_packages = dbus-glib-1
+else
+       pkg_packages = dbus-glib-1 dlog
+endif
 
 PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
 PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
@@ -108,4 +112,4 @@ clean:
        @rm -f $(OBJECTS) *~
        @rm -f *.bb *.bbg *.da *.gcov
 
--include .depend
\ No newline at end of file
+-include .depend
index 82b1c86..b16c902 100644 (file)
@@ -62,7 +62,12 @@ else
 endif
 
 # Define a list of pkg-config packages we want to use
-pkg_packages = dbus-glib-1
+
+ifeq ($(TCS_CFG), release)
+       pkg_packages = dbus-glib-1
+else
+       pkg_packages =  dbus-glib-1 dlog
+endif
 
 PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
 PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
@@ -71,7 +76,7 @@ PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
 LD_FLAGS += $(PKG_LDFLAGS)
 
 GBS_CFLAGS = -I${SYSROOT}/usr/include/dbus-1.0 -I${SYSROOT}/usr/lib/dbus-1.0/include
-CFLAGS   += $(PKCL_CFLAGS) $(TCS_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS)
+CFLAGS   += $(PKCL_CFLAGS) $(TCS_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -Wall -Werror
 
 SOURCES = $(SRCDIR)/IpcClient.c        \
                $(SRCDIR)/IpcStructs.c
index d9cc671..286be2d 100644 (file)
@@ -62,7 +62,11 @@ else
 endif
 
 # Define a list of pkg-config packages we want to use
-pkg_packages = dbus-glib-1
+ifeq ($(TCS_CFG), release)
+       pkg_packages = dbus-glib-1
+else
+       pkg_packages = dbus-glib-1 dlog
+endif
 
 PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
 PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
@@ -71,7 +75,7 @@ PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
 LD_FLAGS += $(PKG_LDFLAGS)
 
 GBS_CFLAGS = -I${SYSROOT}/usr/include/dbus-1.0 -I${SYSROOT}/usr/lib/dbus-1.0/include
-CFLAGS   += $(PKCL_CFLAGS) $(TCS_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS)
+CFLAGS   += $(PKCL_CFLAGS) $(TCS_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -Wall -Werror
 
 SOURCES = $(SRCDIR)/IpcServer.c \
                $(SRCDIR)/IpcServerError.c \
index aa3f40d..6894245 100644 (file)
 #include <pthread.h>
 #include <string.h>
 
+#include "Debug.h"
 #include "TCSImpl.h"
 #include "TCSErrorCodes.h"
 
 
 #define TCS_CONSTRUCT_ERRCODE(m, e) (((m) << 24) | (e))
 
-#if defined(DEBUG)
-#define DEBUG_LOG(_fmt_, _param_...) { \
-                                        FILE *fp = fopen("/tmp/csframelog.txt", "a"); \
-                                        if (fp != NULL) \
-                                        { \
-                                            printf("%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fprintf(fp, "%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fclose(fp); \
-                                        } \
-                                       }
-#else
-#define DEBUG_LOG(_fmt_, _param_...)
-#endif
-
-
 #define PLUGIN_PATH "/opt/usr/share/sec_plugin/libengine.so"
 
 
@@ -112,7 +98,7 @@ TCSLIB_HANDLE TCSLibraryOpen(void)
 {
     PluginContext *pCtx = NULL;
 
-    DEBUG_LOG("%s", "tcs lib open\n");
+    DDBG("%s", "tcs lib open\n");
     pCtx = LoadPlugin();
     if (pCtx != NULL)
     {
@@ -121,11 +107,11 @@ TCSLIB_HANDLE TCSLibraryOpen(void)
             free(pCtx);
             return INVALID_TCSLIB_HANDLE;
         }
-        DEBUG_LOG("%s", "call to TCSPLibraryOpen\n");
+        DDBG("%s", "call to TCSPLibraryOpen\n");
         pCtx->hLib = (*pCtx->pfLibraryOpen)();
         if (pCtx->hLib == INVALID_TCSLIB_HANDLE)
         {
-            DEBUG_LOG("%s", "failed to open engine\n");
+            DDBG("%s", "failed to open engine\n");
             if (pCtx->pPlugin != NULL)
                 dlclose(pCtx->pPlugin);
             free(pCtx);
@@ -160,11 +146,13 @@ int TCSGetVersion(TCSLIB_HANDLE hLib, TCSVerInfo *pVerInfo)
     char const *pPluginVer = (*pCtx->pfGetVersion)();
 
     if (pPluginVer != NULL)
-        strncpy(pVerInfo->szPluginVer, pPluginVer, TCS_VER_MAX);
+        strncpy(pVerInfo->szPluginVer, pPluginVer, TCS_VER_MAX - 1);
     else
-        strncpy(pVerInfo->szPluginVer, "NULL", TCS_VER_MAX);
+        strncpy(pVerInfo->szPluginVer, "NULL", TCS_VER_MAX - 1);
 
-    DEBUG_LOG("%s %s %s\n", "Framework|Plugin version = ",
+    pVerInfo->szPluginVer[TCS_VER_MAX - 1] = '\0';
+
+    DDBG("%s %s %s\n", "Framework|Plugin version = ",
               pVerInfo->szFrameworkVer, pVerInfo->szPluginVer);
 
     return 0;
@@ -186,10 +174,12 @@ int TCSGetInfo(TCSLIB_HANDLE hLib, char *pszInfo)
 
     char const *pszInfoPlugin = (*pCtx->pfGetInfo)();
 
-    if (pszInfo != NULL)
-        strncpy(pszInfo, pszInfoPlugin, TCS_META_MAX);
+    if (pszInfoPlugin != NULL)
+        strncpy(pszInfo, pszInfoPlugin, TCS_META_MAX - 1);
     else
-        strncpy(pszInfo, "NULL", TCS_META_MAX);
+        strncpy(pszInfo, "NULL", TCS_META_MAX - 1);
+
+    pszInfo[TCS_META_MAX - 1] = '\0';
 
     return 0;
 }
@@ -321,7 +311,7 @@ void *TCSScanDataAsyncWorker(void *pTData)
     {
         if (pCtx == NULL || pCtx->pfScanFile == NULL)
         {
-            DEBUG_LOG("%s", "failed to open engine\n");
+            DDBG("%s", "failed to open engine\n");
             pTCSScanParam->pfCallBack(pTCSScanParam->pPrivate, TCS_CB_SCANFINISH, NULL);
             break;
         }
@@ -350,7 +340,7 @@ void *TCSScanDataAsyncWorker(void *pTData)
 
 int TCSScanDataAsync(TCSLIB_HANDLE hLib, TCSScanParam *pParam)
 {
-    ThreadScanData *pThreadData = malloc(sizeof(ThreadScanData));
+    ThreadScanData *pThreadData = calloc(1, sizeof(ThreadScanData));
 
     int rc = -1;
 
@@ -399,7 +389,7 @@ void *TCSScanFileAsyncWorker(void *pTData)
     {
         if (pCtx == NULL || pCtx->pfScanFile == NULL)
         {
-            DEBUG_LOG("%s", "failed to open engine\n");
+            DDBG("%s", "failed to open engine\n");
             pThreadData->pfCallBack(pThreadData->pPrivate, TCS_CB_SCANFINISH, NULL);
             break;
         }
@@ -432,7 +422,7 @@ int TCSScanFileAsync(TCSLIB_HANDLE hLib, char const *pszFileName, int iDataType,
         int iAction, int iCompressFlag, void *pPrivate, 
         int (*pfCallBack)(void *pPrivate, int iReason, void *pParam))
 {
-    ThreadScanFileData *pThreadData = malloc(sizeof(ThreadScanFileData));
+    ThreadScanFileData *pThreadData = calloc(1, sizeof(ThreadScanFileData));
 
     int rc = -1;
 
@@ -475,7 +465,7 @@ static PluginContext *LoadPlugin(void)
 {
     PluginContext *pCtx = NULL;
     void *pTmp = dlopen(PLUGIN_PATH, RTLD_LAZY);
-    DEBUG_LOG("%s", "load plugin\n");
+    DDBG("%s", "load plugin\n");
     if (pTmp != NULL)
     {
         FuncLibraryOpen TmpLibraryOpen;
@@ -490,10 +480,10 @@ static PluginContext *LoadPlugin(void)
         do
         {
             TmpLibraryOpen = dlsym(pTmp, "TCSPLibraryOpen");
-            DEBUG_LOG("%s", "load api TCSPLibraryOpen\n");
+            DDBG("%s", "load api TCSPLibraryOpen\n");
             if (TmpLibraryOpen == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPLibraryOpen in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPLibraryOpen in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -501,7 +491,7 @@ static PluginContext *LoadPlugin(void)
             TmpLibraryClose = dlsym(pTmp, "TCSPLibraryClose");
             if (TmpLibraryClose == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPLibraryClose in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPLibraryClose in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -509,7 +499,7 @@ static PluginContext *LoadPlugin(void)
             TmpGetLastError = dlsym(pTmp, "TCSPGetLastError");
             if (TmpGetLastError == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPGetLastError in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPGetLastError in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -517,7 +507,7 @@ static PluginContext *LoadPlugin(void)
             TmpScanData = dlsym(pTmp, "TCSPScanData");
             if (TmpScanData == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPScanData in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPScanData in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -525,7 +515,7 @@ static PluginContext *LoadPlugin(void)
             TmpScanFile = dlsym(pTmp, "TCSPScanFile");
             if (TmpScanFile == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPScanFile in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPScanFile in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -533,7 +523,7 @@ static PluginContext *LoadPlugin(void)
             TmpScanFileEx = dlsym(pTmp, "TCSPScanFileEx");
             if (TmpScanFileEx == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPScanFileEx in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPScanFileEx in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -541,7 +531,7 @@ static PluginContext *LoadPlugin(void)
             TmpGetVersion = dlsym(pTmp, "TCSPGetVersion");
             if(TmpGetVersion == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPGetVersion in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPGetVersion in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -549,7 +539,7 @@ static PluginContext *LoadPlugin(void)
             TmpGetInfo = dlsym(pTmp, "TCSPGetInfo");
             if(TmpGetInfo == NULL)
             {
-                DEBUG_LOG("Failed to load TCSPGetInfo in %s\n", PLUGIN_PATH);
+                DDBG("Failed to load TCSPGetInfo in %s\n", PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -574,7 +564,7 @@ static PluginContext *LoadPlugin(void)
     }
     else
     {
-        DEBUG_LOG("No plugin found. %s\n", dlerror());
+        DDBG("No plugin found. %s\n", dlerror());
     }
 
     return pCtx;
index cf72f67..cee0691 100644 (file)
@@ -393,7 +393,7 @@ int TCSGetVersion(TCSLIB_HANDLE hLib, TCSVerInfo *pVerInfo);
 /**
  * \brief Gets the meta information about the plugin
  * \param[in] hLib instance handle obtained from a call to the TCSLibraryOpen().
- * \param[out] pszInfo string containing meta info
+ * \param[out] pszInfo string containing meta info, pszInfo allocated by caller of size TCS_META_MAX.
  *
  * \return Return Type (int) \n
  * 0 - on success. \n
index b8bb4e5..fcb2687 100644 (file)
@@ -1,27 +1,29 @@
 /**
  * Methods supported in TPCS (Tizen Plugin Control Service)
- *
  */
+
+#include <dirent.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <ftw.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlreader.h>
+#include <libxml/xmlwriter.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <dirent.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
-#include <ftw.h>
-#include <dlfcn.h>
-
+#include "Debug.h"
 #include "IpcServer.h"
-#include <libxml/xmlreader.h>
-#include <libxml/xmlwriter.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-#include "TPCSSerDaemon.h"
 #include "IpcForkDaemon.h"
+#include "TPCSSerDaemon.h"
 
 /**
  * This daemon provides four services to manage plugins.
  * It maintains config.xml that has the plugin info.
  * It will recover the config.xml if it is corrupted.
  *
- * During the services, the update config.xml and set up the symbolic link of the library is an atomic action.
- * Daemon will store the config.xml in the buffer. When running each method, the buffer config.xml is copied to pData and being update inside the method.
+ * During the services, the update config.xml and set up the symbolic link of the library is an
+ * atomic action.
+ * Daemon will store the config.xml in the buffer. When running each method, the buffer config.xml
+ * is copied to pData and being update inside the method.
  * Except the GetInfoPlugin(), all other methods serializing when updating the config.xml.
- *
  */
 
 /**
  *
  */
 
-#if defined(DEBUG)
-#define DEBUG_LOG(_fmt_, _param_...) \
-{ \
-    fprintf(stderr, "%s %d " _fmt_, __FILE__, __LINE__, _param_); \
-}
-#else
-#define DEBUG_LOG(_fmt, _param_...)
-#endif
-
 typedef struct _ConfigBuf
 {
     xmlDoc *pConfigBuffer;
@@ -60,55 +54,54 @@ static void GetNSURI(xmlDoc *pXmlDoc, xmlChar **pns, xmlChar **uri);
 static void GetConfigElements(xmlDoc **pXmlDoc, xmlChar *pXPath, int *size, char ***content);
 static int WriteXmlToFile(xmlDoc *pXmlDoc, const char* filename);
 static int UpdatePluglibList(const char *appPath, xmlDoc **pXmlDoc, const char *appId);
-static int ActivePlugin(const ConfigBuf *pBuf, xmlDoc **pXmlCp, const char *appId);
-static int SetSuccessReturn(int *argc, char ***argv);
-static int SetFailureReturn(int *argc, char ***argv);
+static int ActivePlugin(ConfigBuf *pBuf, xmlDoc **pXmlCp, const xmlChar *appId);
+static void SetSuccessReturn(int *argc, char ***argv);
+static void SetFailureReturn(int *argc, char ***argv);
+static void CleanupArray(char*** pArr, int len);
+static int EndsWith(char const *hay, char const *needle);
+
+/**
+ * Local functions declaration.
+ */
+static int HasTag(const char *pTag, const char *pFileName, const char *xpath);
+int UpdateNode(const xmlChar* content, xmlDoc **pDoc, const xmlChar *xpathNodeParent,
+               const char* appID);
 
-static int SetSuccessReturn(int *res_argc, char ***res_argv)
+static void SetReturn(int *res_argc, char ***res_argv, char *val)
 {
-    *res_argc = 1;
-    *res_argv = calloc(1, sizeof(char*));
-    if (*res_argv == NULL)
+    if (val)
     {
-        *res_argc = 0;
-    }
-    else
-    {
-        (*res_argv)[0] = strndup((const char*) RETURN_SUCCESS, sizeof(RETURN_SUCCESS));
-        if ((*res_argv)[0] == NULL)
+        *res_argv = calloc(1, sizeof(char*));
+        if (*res_argv)
         {
-            *res_argc = 0;
-            free(*res_argv);
+            (*res_argv)[0] = strdup((const char*) val);
+            if ((*res_argv)[0])
+            {
+                *res_argc = 1;
+                return;
+            }
         }
 
+        free(*res_argv);
+        *res_argc = 0;
     }
 }
 
-static int SetFailureReturn(int *res_argc, char ***res_argv)
+static void SetSuccessReturn(int *res_argc, char ***res_argv)
 {
-    *res_argc = 1;
-    *res_argv = calloc(1, sizeof(char*));
-    if (*res_argv == NULL)
-    {
-        *res_argc = 0;
-    }
-    else
-    {
-        (*res_argv)[0] = strndup((const char*) RETURN_FAILURE, sizeof(RETURN_FAILURE));
-        if ((*res_argv)[0] == NULL)
-        {
-            *res_argc = 0;
-            free(*res_argv);
-        }
+    SetReturn(res_argc, res_argv, RETURN_SUCCESS);
+}
 
-    }
+static void SetFailureReturn(int *res_argc, char ***res_argv)
+{
+    SetReturn(res_argc, res_argv, RETURN_FAILURE);
 }
 
-int SearchNodeN(const char *xpath, const xmlDoc *pXmlDoc, xmlXPathObject **pXPathObj)
+int SearchNodeN(const xmlChar *xpath, xmlDoc *pXmlDoc, xmlXPathObject **pXPathObj)
 {
-    DEBUG_LOG("searchNode :%s\n", xpath);
+    DDBG("searchNode :%s\n", xpath);
     int result = -1;
-    xmlXPathContext *pXPathCtx;
+    xmlXPathContextPtr pXPathCtx;
 
     pXPathCtx = xmlXPathNewContext(pXmlDoc);
     if (pXPathCtx == NULL)
@@ -126,17 +119,16 @@ int SearchNodeN(const char *xpath, const xmlDoc *pXmlDoc, xmlXPathObject **pXPat
 
     //Evaluate xpath expression
     *pXPathObj = xmlXPathEvalExpression(xpath, pXPathCtx);
-    DEBUG_LOG("============== XPATHobj address:%p\n", *pXPathObj);
+    DDBG("============== XPATHobj address:%p\n", *pXPathObj);
 
     if (*pXPathObj == NULL)
     {
-        DEBUG_LOG("Cannot find node:%s\n", xpath);
+        DDBG("Cannot find node:%s\n", xpath);
         free(pns);
         free(puri);
         return result;
     }
 
-    //*pNodeSet = pXPathObj->nodesetval;
     result = 0;
 
     free(pns);
@@ -147,13 +139,11 @@ int SearchNodeN(const char *xpath, const xmlDoc *pXmlDoc, xmlXPathObject **pXPat
 
 }
 
-int UpdateNode(const xmlChar* content, xmlDoc **pDoc, const xmlChar *xpathNodeParent,
-               const char* appID);
-// Dynamically load the library, get the product name, vendor name and version number, then update the xml file
-
-int InsertNode(xmlDoc **pDoc, const char *xpathNodeParent, const char *content)
+// Dynamically load the library, get the product name, vendor name and version number, then
+// update the xml file.
+int InsertNode(xmlDoc **pDoc, const xmlChar *xpathNodeParent, const char *content)
 {
-    DEBUG_LOG("insert node :%s\n", "==============");
+    DDBG("insert node :%s\n", "==============");
     int result = -1;
     xmlXPathContext *pXPathCtx;
     xmlXPathObject *pXPathObj;
@@ -168,10 +158,11 @@ int InsertNode(xmlDoc **pDoc, const char *xpathNodeParent, const char *content)
         {
             if (xmlXPathRegisterNs(pXPathCtx, pns, puri) != 0)
             {
-                DEBUG_LOG("Cannot register xpath :%s\n", "");
+                DDBG("Cannot register xpath :%s\n", "");
                 return result;
             }
         }
+
         // Evaluate xpath expression
         pXPathObj = xmlXPathEvalExpression(xpathNodeParent, pXPathCtx);
         if (pXPathObj != NULL)
@@ -179,40 +170,46 @@ int InsertNode(xmlDoc **pDoc, const char *xpathNodeParent, const char *content)
             xmlNodeSet *pNodeSet = pXPathObj->nodesetval;
             int size;
             size = pNodeSet ? pNodeSet->nodeNr : 0;
-            if (size == 1) //Should find only one node
+            if (size == 1) // Should find only one node
             {
-                //Get xmlnode
+                // Get xmlnode
                 xmlDoc *pPlugDoc = xmlReadMemory(content, strlen(content), NULL, NULL, 0);
-                DEBUG_LOG("plugdoc :%s\n", content);
+                DDBG("plugdoc :%s\n", content);
 
                 if (pPlugDoc != NULL)
                 {
-                    xmlNode *newnode = xmlDocCopyNode(xmlDocGetRootElement(pPlugDoc), pNodeSet->nodeTab[0]->doc,1);
-                    DEBUG_LOG("=========== pplugdoc address:%p\n", pPlugDoc);
+                    xmlNode *newnode = xmlDocCopyNode(xmlDocGetRootElement(pPlugDoc),
+                                                      pNodeSet->nodeTab[0]->doc,1);
+                    DDBG("=========== pplugdoc address:%p\n", pPlugDoc);
 
                     xmlFreeDoc(pPlugDoc);
                     //xmlNode *addNode = xmlAddChildList(pNodeSet->nodeTab[0], newnode->children);
                     xmlNode *addNode = xmlAddChildList(pNodeSet->nodeTab[0], newnode->children);
-                    DEBUG_LOG("=========== new node addr:%p\n", newnode);
+                    DDBG("=========== new node addr:%p\n", newnode);
 
                     if (addNode != NULL)
                     {
                         result = 0;
-                        DEBUG_LOG("FREE new node:%p\n", newnode);
+                        DDBG("FREE new node:%p\n", newnode);
                         newnode->children = NULL;
                         xmlFreeNode(newnode);
                     }
                 }
             }
-
         }
+        free(pns);
+        free(puri);
+        pns = NULL;
+        puri = NULL;
+
         xmlXPathFreeObject(pXPathObj);
         xmlXPathFreeContext(pXPathCtx);
     }
 
     return result;
 }
-int RemoveNodeParent(xmlDoc **pDoc, const char *path, const char* value)
+
+int RemoveNodeParent(xmlDoc **pDoc, const xmlChar *path, const char* value)
 {
     int result = -1;
     if (*pDoc != NULL)
@@ -243,103 +240,114 @@ int RemoveNodeParent(xmlDoc **pDoc, const char *path, const char* value)
                 size = pNodeSet ? pNodeSet->nodeNr : 0;
                 int i = 0;
                 xmlNode *cur;
-                xmlChar *content;
                 xmlNode *parent;
                 for (; i < size; i++)
                 {
                     cur = pNodeSet->nodeTab[i]->children;
-                    if (strncmp(cur->content, value, strlen(value)) == 0)
+                    if (strcmp((const char*)cur->content, value) == 0)
                     {
                         parent = cur->parent->parent;
                         xmlUnlinkNode(parent);
                         break;
                     }
                     else
-                        DEBUG_LOG("THEY ARE NOT EQUAL:%s\n", value);
+                        DDBG("THEY ARE NOT EQUAL:%s\n", value);
 
                 }
                 result = 0;
                 xmlXPathFreeObject(pXPathObj);
             }
+            free(pns);
+            free(puri);
+            pns = NULL;
+            puri = NULL;
             xmlXPathFreeContext(pXPathCtx);
         }
     }
     return result;
 }
 
-int PrintXmlDoc(const xmlDoc *pDoc)
+int PrintXmlDoc(xmlDocPtr pDoc)
 {
+#ifdef DEBUG
     int result = 0;
     int xmlSize;
     xmlChar *xmlMem;
-    xmlDocDumpFormatMemory(pDoc, &xmlMem, &xmlSize, NULL);
-    DEBUG_LOG("pdoc content:%s\n", xmlMem);
+    xmlDocDumpFormatMemory(pDoc, &xmlMem, &xmlSize, 0);
+    DDBG("pdoc content:%s\n", xmlMem);
     free(xmlMem);
     return result;
+#else
+    return 0;
+#endif
 }
 
-int UpdateConfigFile(ConfigBuf **pData, const xmlDoc **pXmlCp)
+int UpdateConfigFile(ConfigBuf **pData, xmlDoc **pXmlCp)
 {
-    pthread_mutex_lock(&((*pData)->configLock));
-
     int result = -1;
-    if (*pXmlCp != NULL && (*pData) != NULL)
+
+    if (pData && *pData)
     {
-        result = WriteXmlToFile(*pXmlCp, CONFIG_FILE_NEW_W_PATH);
-        if (result == 0)
+        pthread_mutex_lock(&((*pData)->configLock));
+        if (pXmlCp && *pXmlCp)
         {
-            DEBUG_LOG("==============update config file%s\n", " ");
-            PrintXmlDoc(*pXmlCp);
-            result = WriteXmlToFile(*pXmlCp, CONFIG_FILE_W_PATH);
+            result = WriteXmlToFile(*pXmlCp, CONFIG_FILE_NEW_W_PATH);
             if (result == 0)
             {
-                //delete config new file
-                DEBUG_LOG("REMOVE file:%s\n", CONFIG_FILE_NEW_W_PATH);
-                result = remove(CONFIG_FILE_NEW_W_PATH);
-
+                DDBG("==============update config file%s\n", " ");
+                PrintXmlDoc(*pXmlCp);
+                result = WriteXmlToFile(*pXmlCp, CONFIG_FILE_W_PATH);
+                if (result == 0)
+                {
+                    //delete config new file
+                    DDBG("REMOVE file:%s\n", CONFIG_FILE_NEW_W_PATH);
+                    result = remove(CONFIG_FILE_NEW_W_PATH);
 
-                 if ((*pData)->pConfigBuffer != NULL)
-                     xmlFreeDoc((*pData)->pConfigBuffer);
+                     if ((*pData)->pConfigBuffer != NULL)
+                         xmlFreeDoc((*pData)->pConfigBuffer);
 
-                (*pData)->pConfigBuffer = xmlCopyDoc(*pXmlCp, DO_RECURSIVE_COPY);
+                    (*pData)->pConfigBuffer = xmlCopyDoc(*pXmlCp, DO_RECURSIVE_COPY);
+                }
             }
         }
+        pthread_mutex_unlock(&((*pData)->configLock));
     }
-    pthread_mutex_unlock(&((*pData)->configLock));
     return result;
 }
 
 static int UpdatePlugin(const char *libname, xmlDoc **pXmlDoc, const char* appId)
 {
-    DEBUG_LOG("~~~~~~~~~~~~~`UPDATE plugin: libname:%s, appID:%s\n", libname, appId);
+    DDBG("~~~~~ UPDATE plugin: libname:%s, appID:%s\n", libname, appId);
     int result = -1;
-    void *handle;
+    void *pHandle = NULL;
 
-    char *error;
-
-    handle = dlopen(libname, RTLD_LAZY);
-    if ((error = dlerror()) != NULL)
+    pHandle = dlopen(libname, RTLD_LAZY);
+    if (pHandle == NULL)
     {
-        DEBUG_LOG("failed to open lib: %s, error:%s\n", libname, error);
+        char *error;
+        if ((error = dlerror()) != NULL)
+            DDBG("failed to open lib: %s, error:%s\n", libname, error);
     }
     else
     {
-        char *pInfo;
+        char *pInfo = NULL;
         char* (*getInfo)(void);
 
-        DEBUG_LOG("open library:%s\n",libname);
-        getInfo = dlsym(handle, "TCSGetInfo");
+        DDBG("open library:%s\n", libname);
+        getInfo = dlsym(pHandle, "TCSGetInfo");
 
-        if ((error = dlerror()) != NULL)
+        if (getInfo == NULL)
         {
-            DEBUG_LOG("SOMETHID :%s\n", error);
+            char *error;
+            if ((error = dlerror()) != NULL)
+                DDBG("SOMETHID :%s\n", error);
         }
         else
         {
-            pInfo = strdup((const char*) (*getInfo)());
+            pInfo = strdup(getInfo());
             if (pInfo != NULL)
             {
-                //Update node tree
+                // Update node tree
                 result = UpdateNode((const xmlChar*) pInfo, pXmlDoc, (const xmlChar*) XPATH_PLUGINS,
                                     appId);
                 free(pInfo);
@@ -347,92 +355,113 @@ static int UpdatePlugin(const char *libname, xmlDoc **pXmlDoc, const char* appId
             }
         }
 
-        dlclose(handle);
+        dlclose(pHandle);
     }
     return result;
 }
 
 /**
- * Get plugins node, should only have one node. After that, Check if has the node with appId, if so, remove this node. otherwise, add the new node.
+ * Get plugins node, should only have one node. After that, Check if has the node with appId, if so,
+ * remove this node. otherwise, add the new node.
  */
 int UpdateNode(const xmlChar* content, xmlDoc **pDoc, const xmlChar *xpathNodeParent,
                const char* appId)
 {
-
     int result = -1;
 
-    //Remove the plugin first if its appId same
+    // Remove the plugin first if its appId same
     char appidpath[GENERIC_STRING_SIZE];
     strncpy(appidpath, (const char*) XPATH_PLUGINS_PLUG, sizeof(appidpath));
-    result = RemoveNodeParent(pDoc, appidpath, appId);
+    result = RemoveNodeParent(pDoc, (const xmlChar *)appidpath, appId);
 
-    result = InsertNode(pDoc, xpathNodeParent, content);
-    //PrintXmlDoc(*pDoc);
+    result = InsertNode(pDoc, xpathNodeParent, (const char*)content);
     return result;
 }
 
-void CleanupArray(char*** pArr, int len);
-
-int EndsWith(char const *str, char const *suffix);
-
-static int ActivePlugin(const ConfigBuf *pBuf, xmlDoc **pXmlCp, const char *appId)
+static int ActivePlugin(ConfigBuf *pBuf, xmlDoc **pXmlCp, const xmlChar *appId)
 {
     int result = -1;
 
     xmlXPathObject *pObj = NULL;
-    result = SearchNodeN(XPATH_ACTIVE_PLUGIN, *pXmlCp, &pObj);
-    DEBUG_LOG("========= active plug:%p\n", pObj);
+    result = SearchNodeN((const xmlChar *)XPATH_ACTIVE_PLUGIN, *pXmlCp, &pObj);
+
     PrintXmlDoc(*pXmlCp);
 
     if (result == -1)
         return result;
 
     result = -1;
-    xmlNodeSet *pNodeSet = pObj->nodesetval;
-
-    // Get the plugin path from the appPath, set symbolic link for the plugin, update the xmlDoc
-    int count;
-    char **paths = NULL;
-    GetConfigElements(pXmlCp, (xmlChar *) XPATH_APP_PATHS, &count, &paths);
-    int i = 0;
-    for (; i < count; i++)
+    xmlNodeSet *pNodeSet = NULL;
+    if (pObj)
     {
-        char appPath[FILE_NAME_MAX_SIZE];
-        snprintf(appPath, FILE_NAME_MAX_SIZE, "%s%s%s%s", paths[i], "/", appId,
-                 PLUGIN_DEFAULT_DIR_NAME);
-        if (appPath == NULL)
-            continue;
+       pNodeSet = pObj->nodesetval;
+    }
 
-        //Found the app path
-        struct stat info;
-        if (stat(appPath, &info) != 0)
-            continue;
+    // If appId is empty, disable the active plugin, update activePlugin Node to None
+    if (strcmp((const char*)appId, APP_ID_NULL) == 0)
+    {
         pthread_mutex_lock(&(pBuf->configLock));
-        unlink(SYSLINK_PLUG_PATH);
-        result = symlink(appPath, SYSLINK_PLUG_PATH);
+        result = unlink(SYSLINK_PLUG_PATH);
         pthread_mutex_unlock(&(pBuf->configLock));
 
-        DEBUG_LOG("set symbolic link result:from :%s to %s result:%d\n", appPath, SYSLINK_PLUG_PATH, result);
-        if (result == 0)
+               if (pNodeSet)
+               {
+                       if (pNodeSet->nodeTab[0])
+                       {
+                               xmlNode *cur = pNodeSet->nodeTab[0];
+                               xmlNodeSetContent(cur, (xmlChar*)ACTIVE_NONE);
+                               DDBG("GET node content :%s\n", cur->content);
+                       }
+               }
+               result = 0;
+    }
+    else
+    {
+        // Get the plugin path from the appPath, set symbolic link for the plugin, update the xmlDoc
+        int count;
+        char **paths = NULL;
+        GetConfigElements(pXmlCp, (xmlChar *) XPATH_APP_PATHS, &count, &paths);
+        int i = 0;
+        for (; i < count; i++)
         {
-            //update active Id node
-            xmlNode *cur = pNodeSet->nodeTab[0];
-            xmlNodeSetContent(cur, appId);
-            DEBUG_LOG("GET NOde conten :%s\n", cur->content);
+            char appPath[FILE_NAME_MAX_SIZE];
+            snprintf(appPath, FILE_NAME_MAX_SIZE, "%s%s%s%s", paths[i], "/", appId,
+                     PLUGIN_DEFAULT_DIR_NAME);
+
+            //Found the app path
+            struct stat info;
+            if (stat(appPath, &info) != 0)
+                continue;
 
-            //xmlFreeNode(cur);
-            DEBUG_LOG("RETURn from active plu g  0000:%d\n", result);
-            PrintXmlDoc(*pXmlCp);
+            pthread_mutex_lock(&(pBuf->configLock));
+            unlink(SYSLINK_PLUG_PATH);
+            result = symlink(appPath, SYSLINK_PLUG_PATH);
+            pthread_mutex_unlock(&(pBuf->configLock));
 
+            DDBG("set symbolic link result:from :%s to %s result:%d\n", appPath, SYSLINK_PLUG_PATH, result);
+            if (result == 0 && pNodeSet)
+            {
+                //update active Id node
+                xmlNode *cur = pNodeSet->nodeTab[0];
+                xmlNodeSetContent(cur, appId);
+                DDBG("GET NOde conten :%s\n", cur->content);
+
+                //xmlFreeNode(cur);
+                DDBG("RETURn from active plu g  0000:%d\n", result);
+                PrintXmlDoc(*pXmlCp);
+
+            }
+            DDBG("RETURn from active plu g  0000  000000:%d\n", result);
+            //xmlXPathFreeNodeSet(pNodeSet);
+            break;
         }
-        DEBUG_LOG("RETURn from active plu g  0000  000000:%d\n", result);
-        //xmlXPathFreeNodeSet(pNodeSet);
-        break;
+        DDBG("RETURn from active plu g  0000  0111 :%d\n", result);
+        CleanupArray(&paths, count);
+        xmlXPathFreeObject(pObj);
+
     }
-    DEBUG_LOG("RETURn from active plu g  0000  0111 :%d\n", result);
-    CleanupArray(&paths, count);
-    xmlXPathFreeObject(pObj);
-    DEBUG_LOG("RETURn from active plug :%d\n", result);
+
+    DDBG("RETURn from active plug :%d\n", result);
     return result;
 }
 
@@ -441,7 +470,7 @@ static int ActivePlugin(const ConfigBuf *pBuf, xmlDoc **pXmlCp, const char *appI
  */
 static int UpdatePluglibList(const char *appPath, xmlDoc **pXmlDoc, const char* appId)
 {
-    DEBUG_LOG("=========================update plugin lib path:%s\n", appPath);
+    DDBG("=========================update plugin lib path:%s\n", appPath);
 
     int result = -1;
     char plugPath[FILE_NAME_MAX_SIZE];
@@ -451,17 +480,15 @@ static int UpdatePluglibList(const char *appPath, xmlDoc **pXmlDoc, const char*
     struct dirent *pDirEnt;
 
     pDir = opendir(plugPath);
-    DEBUG_LOG("OPEN DIR:%s\n", plugPath);
+    DDBG("OPEN DIR:%s\n", plugPath);
     if (pDir)
     {
         //open directories
         while ((pDirEnt = readdir(pDir)) != NULL)
         {
-            if (strncmp(pDirEnt->d_name, ".", sizeof(".")) == 0
-                    || strncmp(pDirEnt->d_name, "..", sizeof("..")) == 0)
-            {
+            if (strcmp(pDirEnt->d_name, ".") == 0 || strcmp(pDirEnt->d_name, "..") == 0)
                 continue;
-            }
+
             if (pDirEnt->d_type == DT_REG)
             {
                 // load the library, update xml node
@@ -472,29 +499,22 @@ static int UpdatePluglibList(const char *appPath, xmlDoc **pXmlDoc, const char*
             }
             else
             {
-                DEBUG_LOG("IT IS NO regular file:%s\n", pDirEnt->d_name);
+                DDBG("IT IS NO regular file:%s\n", pDirEnt->d_name);
                 continue;
             }
         }
         closedir(pDir);
 
     }
-    DEBUG_LOG("RESTURN  from update pluglib list :%d\n", result);
+    DDBG("RESTURN  from update pluglib list :%d\n", result);
     return result;
-
 }
 
-/***
- * Local functions declarations
- */
-static int HasTag(const char *pTag, const char *pFileName, const char *xpath);
-
 /**
  *
  */
 int GetInfoPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv, int *res_argc,
-                  CALLBACKFUNC callback,
-                  TSC_METHOD_HANDLE *handle)
+                  CALLBACKFUNC callback, TSC_METHOD_HANDLE *handle)
 {
     // check data pass is valid xml
     xmlDoc *pXml = (xmlDoc*) *((xmlDoc**) pData);
@@ -511,11 +531,11 @@ int GetInfoPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv,
         xmlDocDumpFormatMemory(pXml, &xmlMem, &xmlSize, 0);
         if (xmlMem != NULL)
         {
-            DEBUG_LOG("size is: %d, xmlmem is ** :%s\n", xmlSize, xmlMem);
+            DDBG("size is: %d, xmlmem is ** :%s\n", xmlSize, xmlMem);
             (*res_argv)[1] = strdup((const char*) xmlMem);
             if ((*res_argv)[1] == NULL)
             {
-                DEBUG_LOG("Not enough memory in :%s\n", "set xmlmem in return");
+                DDBG("Not enough memory in :%s\n", "set xmlmem in return");
                 free((*res_argv)[0]);
                 (*res_argv)[0] = NULL;
                 goto invalid_xml;
@@ -528,10 +548,10 @@ int GetInfoPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv,
     }
     else
     {
-        DEBUG_LOG("failed to copy return_successS:%s\n", "");
+        DDBG("failed to copy return_successS:%s\n", "");
         goto no_memory;
     }
-    DEBUG_LOG("successfully finished:%s\n", "GetInfoPlugin");
+    DDBG("successfully finished:%s\n", "GetInfoPlugin");
     return 0;
 
     invalid_xml:
@@ -557,13 +577,11 @@ int GetInfoPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv,
  *
  *     @req_argc: 1
  *     @req_argv: app installation path, i.e. /opt/usr/apps/appID
- *
  */
 int InstallPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv, int *res_argc,
-                  CALLBACKFUNC callback,
-                  TSC_METHOD_HANDLE *handle)
+                  CALLBACKFUNC callback, TSC_METHOD_HANDLE *handle)
 {
-    DEBUG_LOG("InstallPlugin for serverstub:%s\n", req_argv[0]);
+    DDBG("InstallPlugin for serverstub:%s\n", req_argv[0]);
     int result = -1;
     ConfigBuf *pBuf = *((ConfigBuf **) pData);
     pthread_mutex_lock(&(pBuf->configLock));
@@ -584,45 +602,42 @@ int InstallPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv,
             {
                 char appPath[FILE_NAME_MAX_SIZE];
                 sprintf(appPath, "%s%s%s", paths[i], "/", req_argv[0]);
-                if (appPath != NULL)
+
+                PrintXmlDoc(pXmlCp);
+                if (UpdatePluglibList(appPath, &pXmlCp, req_argv[0]) == 0)
                 {
-                    PrintXmlDoc(pXmlCp);
-                    if (UpdatePluglibList(appPath, &pXmlCp, req_argv[0]) == 0)
+                    if (ActivePlugin(*((ConfigBuf**) pData), &pXmlCp, (const xmlChar *)req_argv[0]) == 0)
                     {
-                        if (ActivePlugin(*((ConfigBuf**) pData), &pXmlCp, req_argv[0]) == 0)
-                        {
-                            // Write to new file
-                            DEBUG_LOG("Success cpy xml 2:%s\n", appPath);
+                        // Write to new file
+                        DDBG("Success cpy xml 2:%s\n", appPath);
 
-                            *res_argc = FN_INSTALL_PLUG_RTN_COUNT;
-                            *res_argv = calloc(1, sizeof(char*) * FN_INSTALL_PLUG_RTN_COUNT);
-                            if (*res_argv == NULL)
-                                goto no_memory;
+                        *res_argc = FN_INSTALL_PLUG_RTN_COUNT;
+                        *res_argv = calloc(1, sizeof(char*) * FN_INSTALL_PLUG_RTN_COUNT);
+                        if (*res_argv == NULL)
+                            goto no_memory;
 
-                            (*res_argv)[0] = strdup((const char*) RETURN_SUCCESS);
-                            if ((*res_argv)[0] == NULL)
-                                goto no_memory;
+                        (*res_argv)[0] = strdup((const char*) RETURN_SUCCESS);
+                        if ((*res_argv)[0] == NULL)
+                            goto no_memory;
 
-                            xmlChar *xmlMem;
-                            int xmlSize;
+                        xmlChar *xmlMem = NULL;
+                        int xmlSize;
 
-                            xmlDocDumpFormatMemory(pXmlCp, &xmlMem, &xmlSize, 0);
-                            DEBUG_LOG("XMLmEM address: %p\n", xmlMem);
-                            if (xmlMem != NULL)
-                            {
-                                (*res_argv)[1] = strdup((const char*) xmlMem);
-                                DEBUG_LOG("return from install plug:%s\n", (*res_argv)[1]);
-                                free(xmlMem);
-                                xmlMem = NULL;
+                        xmlDocDumpFormatMemory(pXmlCp, &xmlMem, &xmlSize, 0);
+                        DDBG("XMLmEM address: %p\n", xmlMem);
+                        if (xmlMem != NULL)
+                        {
+                            (*res_argv)[1] = strdup((const char*) xmlMem);
+                            DDBG("return from install plug:%s\n", (*res_argv)[1]);
+                            free(xmlMem);
+                            xmlMem = NULL;
 
-                                if ((*res_argv)[1] != NULL)
-                                {
-                                    result = UpdateConfigFile(pData, &pXmlCp);
-                                    break;
-                                }
+                            if ((*res_argv)[1] != NULL)
+                            {
+                                result = UpdateConfigFile(pData, &pXmlCp);
+                                break;
                             }
                         }
-
                     }
                 }
             }
@@ -630,6 +645,7 @@ int InstallPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv,
         }
     }
     xmlFreeDoc(pXmlCp);
+
     if (result == -1)
         goto failure;
     else
@@ -647,61 +663,81 @@ failure:
     return result;
 }
 
-//If it is active plugin, unlink the syslink, and update active element with AppId to None.
+/**
+ * If it is active plugin, unlink the syslink, and update active element with AppId to None.
+ * If the request plugin is not active one, remove it from the plugin list
+ */
 int UninstallPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv, int *res_argc,
-                    CALLBACKFUNC callback,
-                    TSC_METHOD_HANDLE *handle)
+                    CALLBACKFUNC callback, TSC_METHOD_HANDLE *handle)
 {
     int result = -1;
-    ConfigBuf *pBuf = *((ConfigBuf **) pData);
+    xmlDoc *pXml = NULL;
+    xmlDoc *pXmlCp = NULL;
+    ConfigBuf *pBuf = NULL;
+    xmlXPathObject *pObj = NULL;
+
+    if (req_argc != 1 || req_argv == NULL)
+        goto failure;
+
+    pBuf = *((ConfigBuf **) pData);
+
     pthread_mutex_lock(&(pBuf->configLock));
-    xmlDoc *pXml = pBuf->pConfigBuffer;
-    xmlDoc *pXmlCp = xmlCopyDoc(pXml, DO_RECURSIVE_COPY);
+    pXml = pBuf->pConfigBuffer;
+    pXmlCp = xmlCopyDoc(pXml, DO_RECURSIVE_COPY);
     pthread_mutex_unlock(&(pBuf->configLock));
 
     if (pXmlCp == NULL)
-        return result;
-    if (req_argc != 1 | req_argv == NULL)
-        return result;
+        goto failure;
 
-    xmlXPathObject *pObj = NULL;
-    result = SearchNodeN(XPATH_ACTIVE_PLUGIN, pXmlCp, &pObj);
-    if (result == -1)
-        return result;
+    result = SearchNodeN((const xmlChar *)XPATH_ACTIVE_PLUGIN, pXmlCp, &pObj);
+    if (result != 0)
+        goto failure;
 
     xmlNodeSet *pNodeSet = pObj->nodesetval;
     xmlNode *pNode = pNodeSet->nodeTab[0];
     if (pNode == NULL)
     {
-        DEBUG_LOG("not such node %s\n", XPATH_ACTIVE_PLUGIN);
-        return result;
+        DDBG("not such node %s\n", XPATH_ACTIVE_PLUGIN);
+        goto failure;
     }
+
     if (pNode->type != XML_ELEMENT_NODE)
-        return result;
-    DEBUG_LOG("node name:%s, activenode value: %s\n", pNode->name, pNode->children->content);
-    if (strncmp(pNode->children->content, req_argv[0], strlen(req_argv[0])) == 0)
+        goto failure;
+
+    // Search for plugin. If found, unlink the plugin. Otherwise, the plugin was already
+    // unlinked and updated in the config file.
+    DDBG("node name:%s, activenode value: %s\n", pNode->name, pNode->children->content);
+    if (strcmp((const char *)pNode->children->content, req_argv[0]) == 0)
     {
         pthread_mutex_lock(&(pBuf->configLock));
         result = unlink(SYSLINK_PLUG_PATH);
         pthread_mutex_unlock(&(pBuf->configLock));
 
-        if (result == -1)
-            return result;
+        if (result != 0 && result != ENOENT)
+            goto failure;
 
-        xmlNodeSetContent(pNode, ACTIVE_NONE);
-        UpdateConfigFile((ConfigBuf**) pData, &pXmlCp);
+        xmlNodeSetContent(pNode, (const xmlChar *)ACTIVE_NONE);
+    }
 
+    // Remove the plugin node if it is in the plugin list
+    result = RemoveNodeParent(&pXmlCp, (const xmlChar *)XPATH_PLUGINS_PLUG, req_argv[0]);
+    result = UpdateConfigFile((ConfigBuf**) pData, &pXmlCp);
+    if (result != 0)
+    {
+        DDBG("Unable to update config file with uninstall info\n");
+        goto failure;
     }
-    xmlXPathFreeObject(pObj);
-    xmlFreeDoc(pXmlCp);
-    *res_argc = 1;
-    *res_argv = calloc(1, sizeof(char*));
-    if (*res_argv == NULL)
-        *res_argc = 0;
+    SetSuccessReturn(res_argc, res_argv);
+    goto cleanup;
 
-    (*res_argv)[0] = strndup((const char*) RETURN_SUCCESS, sizeof(RETURN_SUCCESS));
-    if ((*res_argv)[0] == NULL)
-        *res_argc = 0;
+failure:
+    SetFailureReturn(res_argc, res_argv);
+
+cleanup:
+    if (pObj)
+        xmlXPathFreeObject(pObj);
+    if (pXmlCp)
+        xmlFreeDoc(pXmlCp);
 
     return result;
 }
@@ -712,47 +748,41 @@ int UninstallPlugin(void *pData, int req_argc, char **req_argv, char ***res_argv
  * Update xmlDoc, save to the tpcs_config.xml
  */
 int SetActivePlugin(void *pData, int req_argc, char **req_argv, char ***res_argv, int *res_argc,
-                    CALLBACKFUNC callback,
-                    TSC_METHOD_HANDLE *handle)
+                    CALLBACKFUNC callback, TSC_METHOD_HANDLE *handle)
 {
-    DEBUG_LOG("SetActivePlugin :%s\n", req_argv[0]);
+    DDBG("SetActivePlugin :%s\n", req_argv[0]);
+
+    ConfigBuf *pBuf = NULL;
+    xmlDoc *pXml = NULL;
+    xmlDoc *pXmlCp = NULL;
     int result = -1;
 
-    ConfigBuf *pBuf = *((ConfigBuf **) pData);
+    if (req_argc != 1 || req_argv == NULL)
+        return result;
+
+    pBuf = *((ConfigBuf **) pData);
+
     pthread_mutex_lock(&(pBuf->configLock));
-    xmlDoc *pXml = pBuf->pConfigBuffer;
-    xmlDoc *pXmlCp = xmlCopyDoc(pXml, DO_RECURSIVE_COPY);
+    pXml = pBuf->pConfigBuffer;
+    pXmlCp = xmlCopyDoc(pXml, DO_RECURSIVE_COPY);
     pthread_mutex_unlock(&(pBuf->configLock));
-    if (pXmlCp == NULL)
-        return result;
 
-    if (req_argc != 1 || req_argv == NULL)
+    if (pXmlCp == NULL)
         return result;
 
     PrintXmlDoc(pXmlCp);
-    if (ActivePlugin(*((ConfigBuf**) pData), &pXmlCp, req_argv[0]) == 0)
+    if ((ActivePlugin(pBuf, &pXmlCp, (const xmlChar *)req_argv[0]) == 0)
+            && UpdateConfigFile((ConfigBuf**) pData, &pXmlCp) == 0)
     {
-        UpdateConfigFile((ConfigBuf**) pData, &pXmlCp);
         SetSuccessReturn(res_argc, res_argv);
-        DEBUG_LOG("====================== FINd tha ppid %s\n", req_argv[0]);
-/*
-
-        *res_argc = 1;
-        *res_argv = calloc(1, sizeof(char*));
-        if (*res_argv == NULL)
-            *res_argc = 0;
-        (*res_argv)[0] = strndup((const char*) RETURN_SUCCESS, sizeof(RETURN_SUCCESS));
-        if ((*res_argv)[0] == NULL)
-            *res_argc = 0;
-*/
+        DDBG("==== FINd tha ppid %s\n", req_argv[0]);
     }
     else
     {
-        DEBUG_LOG("====================== ******************* FINd tha ppid %s\n", req_argv[0]);
+        DDBG("==== **** FINd tha ppid %s\n", req_argv[0]);
         SetFailureReturn(res_argc, res_argv);
     }
 
-
     xmlFreeDoc(pXmlCp);
     return result;
 }
@@ -760,7 +790,7 @@ int SetActivePlugin(void *pData, int req_argc, char **req_argv, char ***res_argv
 static int WriteXmlToFile(xmlDoc *pXmlDoc, const char* filename)
 {
 
-    DEBUG_LOG("Write xml to file: %s\n", filename);
+    DDBG("Write xml to file: %s\n", filename);
     int result = -1;
     FILE *pfConfig = fopen(filename, "w");
     if (pfConfig != NULL)
@@ -775,7 +805,7 @@ static int WriteXmlToFile(xmlDoc *pXmlDoc, const char* filename)
 static int InitConfigFile(xmlDoc **pXmlDoc)
 {
     int result = -1;
-    DEBUG_LOG("Size of xml doc in memory :%d\n", sizeof(CONFIG_DEFAULT_STRING));
+    DDBG("Size of xml doc in memory :%d\n", sizeof(CONFIG_DEFAULT_STRING));
 
     *pXmlDoc = xmlReadMemory(CONFIG_DEFAULT_STRING, sizeof(CONFIG_DEFAULT_STRING) + 1,
                              CONFIG_FILE_NAME,
@@ -797,42 +827,32 @@ static bool IsValidTPCSConfig(const char *pFileName, xmlDoc **ppXmlDoc)
     xmlDoc *pXmlDoc;
     if (pParserCtxt == NULL)
     {
-        DEBUG_LOG("%s\n", "===========Failled to allocate parser context");
+        DDBG("%s\n", "======Failed to allocate parser context");
         return ret;
     }
     else
     {
         // valid this config file
-        FILE *fpConfig = fopen(pFileName, "r");
-        if (fpConfig)
-        {
-            fclose(fpConfig); // File exists
             // Parse the file, activating the DTD validation option */
-            DEBUG_LOG("------------------ IS VALID config file :%s\n", "---------------------");
-            pXmlDoc = xmlCtxtReadFile(pParserCtxt, pFileName, NULL, XML_PARSE_DTDVALID);
-            DEBUG_LOG("--- 0 pxmldoc address: %p\n", pXmlDoc);
-            xmlFreeDoc(pXmlDoc);
-            pXmlDoc = xmlCtxtReadFile(pParserCtxt, pFileName, NULL, XML_PARSE_DTDVALID);
-            DEBUG_LOG("--- 1 pxmldoc address: %p\n", pXmlDoc);
-            DEBUG_LOG("file to read:%s\n", pFileName);
-            //PrintXmlDoc(pXmlDoc);
-            if (pXmlDoc != NULL)
-            {
-                // Check if validation succeeded
-                if (pParserCtxt->valid)
-                {
-                    *ppXmlDoc = pXmlDoc;
-                    DEBUG_LOG("address of ppxmldoc: %p\n", *ppXmlDoc);
-                    ret = TRUE;
-                }
-            }
-            else
-            {
-                DEBUG_LOG("NOT VALID file: %s\n", pFileName);
-            }
-        }
-        else
-            DEBUG_LOG("cannot open file :%s\n", pFileName);
+               DDBG("------------------ IS VALID config file :%s\n", "---------------------");
+               pXmlDoc = xmlCtxtReadFile(pParserCtxt, pFileName, NULL, XML_PARSE_DTDVALID);
+               DDBG("--- 1 pxmldoc address: %p\n", pXmlDoc);
+               DDBG("file to read:%s\n", pFileName);
+               PrintXmlDoc(pXmlDoc);
+               if (pXmlDoc != NULL)
+               {
+                       // Check if validation succeeded
+                       if (pParserCtxt->valid)
+                       {
+                               *ppXmlDoc = pXmlDoc;
+                               DDBG("address of ppxmldoc: %p\n", *ppXmlDoc);
+                               ret = TRUE;
+                       }
+               }
+               else
+               {
+                       DDBG("NOT VALID file: %s\n", pFileName);
+               }
 
         xmlFreeParserCtxt(pParserCtxt);
         return ret;
@@ -843,11 +863,14 @@ static bool IsValidTPCSConfig(const char *pFileName, xmlDoc **ppXmlDoc)
  * Return directory list that has the specified directory within
  */
 static void GetDirsHasPath(const char *dir, const char *search_path, int *pCount,
-                           char ***name_w_path,
-                           char ***appId)
+                           char ***name_w_path, char ***appId)
 {
-    DIR *pDir;
-    struct dirent *pDirEnt;
+    DIR *pDir = NULL;
+    struct dirent *pDirEnt = NULL;
+
+    if (!dir || !search_path || !pCount || !appId || !name_w_path)
+        return;
+
     pDir = opendir(dir);
     *pCount = 0;
     if (pDir)
@@ -858,8 +881,7 @@ static void GetDirsHasPath(const char *dir, const char *search_path, int *pCount
         struct stat info;
         while ((pDirEnt = readdir(pDir)) != NULL)
         {
-            if (strncmp(pDirEnt->d_name, ".", sizeof(".")) == 0
-                    || strncmp(pDirEnt->d_name, "..", sizeof("..")) == 0)
+            if (strcmp(pDirEnt->d_name, ".") == 0 || strcmp(pDirEnt->d_name, "..") == 0)
             {
                 continue;
             }
@@ -890,7 +912,7 @@ static void GetDirsHasPath(const char *dir, const char *search_path, int *pCount
                         if (*appId)
                         {
                             (*appId)[0] = strdup((const char*) pDirEnt->d_name);
-                            DEBUG_LOG("COUNT 0, name: %s\n", pDirEnt->d_name);
+                            DDBG("COUNT 0, name: %s\n", pDirEnt->d_name);
                             if ((*appId)[0] == NULL)
                                 goto clean_up;
                         }
@@ -928,20 +950,25 @@ static void GetDirsHasPath(const char *dir, const char *search_path, int *pCount
                 }
             }
         }
-        DEBUG_LOG("CLSOE dir: %s\n", " " );
 
-        closedir(pDir);
-        return;
+        goto success;
     }
-    clean_up:
+
+clean_up:
     CleanupArray(name_w_path, *pCount);
+
+success:
+    DDBG("CLOSE dir: %s\n", " " );
+    if (pDir)
+        closedir(pDir);
+
     return;
 }
+
 /**
- * Return File List
+ *
  */
-
-void CleanupArray(char*** pArr, int len)
+static void CleanupArray(char*** pArr, int len)
 {
     if (pArr)
     {
@@ -971,15 +998,15 @@ int FileTreeCallback(const char *pFile, const struct stat *pStat, int flag)
     int result = 0;
     if (pStat->st_mode & S_IFREG)
     {
-        //DEBUG_LOG(">>>>>file tree walk :%s, such substring:%s\n", pFile, MANIFEST_FILE_NAME);
+        //DDBG(">>>>>file tree walk :%s, such substring:%s\n", pFile, MANIFEST_FILE_NAME);
         if (EndsWith(pFile, MANIFEST_FILE_NAME) == 0)
         {
-            DEBUG_LOG("FOUNd the file: %s\n", pFile);
+            DDBG("FOUNd the file: %s\n", pFile);
             // check if it has the plugin tag
             if (HasTag(PLUGIN_ANTI_VIRUS_TAG, pFile, XPATH_PLUGIN_CATEGORY) == 0)
             {
                 // found the library
-                DEBUG_LOG("this app is plugin app:%s\n", pFile);
+                DDBG("this app is plugin app:%s\n", pFile);
                 result = 1;
             }
         }
@@ -987,24 +1014,23 @@ int FileTreeCallback(const char *pFile, const struct stat *pStat, int flag)
     return result;
 }
 
-int EndsWith(char const *str, char const *suffix)
+/**
+ * Checks if str ends with needle. Return zero on success otherwise non-zero.
+ */
+static int EndsWith(const char *hay, const char *needle)
 {
-    int result = 1;
-    int strLen = strlen(str);
-    int sufLen = strlen(suffix);
-    int index = strLen - sufLen;
+    size_t haylen, needlelen;
 
-    if (strLen > sufLen)
-    {
-        char *substring = calloc('0', sizeof(sufLen));
-        strncpy(substring, str + index, sufLen);
-        if (substring != NULL)
-        {
-            result = strncmp(substring, suffix, sizeof(suffix));
-            free(substring);
-        }
-    }
-    return result;
+    if (!hay || !needle)
+        return -1;
+
+    needlelen = strlen(needle);
+    haylen = strlen(hay);
+
+    if (needlelen > haylen)
+        return -1;
+
+    return strncmp(hay + haylen - needlelen, needle, needlelen);
 }
 
 static void GetNSURI(xmlDoc *pXmlDoc, xmlChar **pns, xmlChar **uri)
@@ -1024,7 +1050,7 @@ static void GetNSURI(xmlDoc *pXmlDoc, xmlChar **pns, xmlChar **uri)
             }
             else
             {
-                DEBUG_LOG("root node name:%s\n", root_node->name);
+                DDBG("root node name:%s\n", root_node->name);
                 *pns = (xmlChar*) strdup((const char*) root_node->name);
             }
         }
@@ -1033,7 +1059,7 @@ static void GetNSURI(xmlDoc *pXmlDoc, xmlChar **pns, xmlChar **uri)
         {
             if (pXmlNSDef->href != NULL)
             {
-                DEBUG_LOG("nsdef :%s\n", pXmlNSDef->href);
+                DDBG("nsdef :%s\n", pXmlNSDef->href);
                 *uri = (xmlChar*) strdup((const char*) pXmlNSDef->href);
             }
         }
@@ -1046,7 +1072,7 @@ static void GetNSURI(xmlDoc *pXmlDoc, xmlChar **pns, xmlChar **uri)
  */
 static void GetConfigElements(xmlDoc **pXmlDoc, xmlChar *pXPath, int *size, char ***content)
 {
-    DEBUG_LOG("GetConfigElements in xpath: %s\n", (char*)pXPath);
+    DDBG("GetConfigElements in xpath: %s\n", (char*)pXPath);
     // Scan all the directories that has av category, update its plugin element in config.xml
     xmlXPathContext *pXPathCtx;
     xmlXPathObject *pXPathObj;
@@ -1061,7 +1087,7 @@ static void GetConfigElements(xmlDoc **pXmlDoc, xmlChar *pXPath, int *size, char
         {
             if (xmlXPathRegisterNs(pXPathCtx, pns, puri) != 0)
             {
-                DEBUG_LOG("Cannot register xpath :%s\n", "");
+                DDBG("Cannot register xpath :%s\n", "");
                 return;
             }
         }
@@ -1077,7 +1103,7 @@ static void GetConfigElements(xmlDoc **pXmlDoc, xmlChar *pXPath, int *size, char
             {
                 int i = 0;
                 *content = calloc(1, sizeof(char*) * (*size));
-                DEBUG_LOG("XAPTH OBJCT FOUND:%s, size:%d\n", "", *size);
+                DDBG("XAPTH OBJCT FOUND:%s, size:%d\n", "", *size);
                 if (*content)
                 {
                     for (; i < *size; i++)
@@ -1088,7 +1114,7 @@ static void GetConfigElements(xmlDoc **pXmlDoc, xmlChar *pXPath, int *size, char
 
                             if (*content)
                             {
-                                DEBUG_LOG("content; %s\n", cur->children->content);
+                                DDBG("content; %s\n", cur->children->content);
                                 (*content)[i] = strdup((const char*) cur->children->content);
                             }
                         }
@@ -1096,7 +1122,7 @@ static void GetConfigElements(xmlDoc **pXmlDoc, xmlChar *pXPath, int *size, char
                 }
                 else
                 {
-                    DEBUG_LOG("CANNOT FOUND content:%s\n", "");
+                    DDBG("CANNOT FOUND content:%s\n", "");
                 }
 
             }
@@ -1121,20 +1147,24 @@ static void GetConfigElements(xmlDoc **pXmlDoc, xmlChar *pXPath, int *size, char
 static int HasTag(const char *pTag, const char *pFileName, const char *xpath)
 {
     int result = 1;
-    xmlDoc *pConfigXml;
+    xmlDoc *pConfigXml = NULL;
+
+    if (!pTag)
+        return result;
+
     pConfigXml = xmlReadFile(pFileName, NULL, 0);
     if (pConfigXml != NULL)
     {
         int size;
-        char **pCategory;
+        char **pCategory = NULL;
         GetConfigElements(&pConfigXml, (xmlChar*) xpath, &size, &pCategory);
         if (size > 0)
         {
-            DEBUG_LOG("size is: %d, category:%s\n", size, pCategory[0]);
+            DDBG("size is: %d, category:%s\n", size, pCategory[0]);
             int i = 0;
             for (; i < size; i++)
             {
-                if (strncmp(pCategory[i], pTag, sizeof(pTag)) == 0)
+                if (strcmp(pCategory[i], pTag) == 0)
                 {
                     result = 0;
                     break;
@@ -1156,7 +1186,8 @@ static int HasTag(const char *pTag, const char *pFileName, const char *xpath)
  *    if it is consistent with symbolic link, buffer the config.xml
  *    else based on the symbolic link, update config.xml, then buffer the config.xml
  *   else
- *    recover the config.xml by scan all the applications, checking symbolic link, create the config.xml, buffer it.
+ *    recover the config.xml by scan all the applications, checking symbolic link, create the
+ *    config.xml, buffer it.
  * Pass the data address to the pData
  */
 int main(int argc, char **argv)
@@ -1177,7 +1208,7 @@ int main(int argc, char **argv)
     //TODO: rename TSC_DBUS_SERVER_PLUGIN_CHANNEL to TSC_DBUS_SERVER_PLUGIN_CHANNEL
     if ((hServer = IpcServerOpen(TSC_DBUS_SERVER_PLUGIN_CHANNEL)) != NULL)
     {
-        DEBUG_LOG("%s", "**** successfully opened server ****\n");
+        DDBG("%s", "**** successfully opened server ****\n");
         // Write out the DTD validation file
         FILE *pDTD = fopen(CONFIG_DTD_FILE_W_PATH, "r");
         if (pDTD == NULL)
@@ -1210,20 +1241,18 @@ int main(int argc, char **argv)
             return ret;
         }
 
-        xmlDoc *pXmlDoc = NULL;
-
         if (IsValidTPCSConfig(CONFIG_FILE_NEW_W_PATH, &(pConfigBuf->pConfigBuffer)))
         {
             // switch to config.xml
             if (rename(CONFIG_FILE_NEW_W_PATH, CONFIG_FILE_W_PATH) == 0)
             {
-                DEBUG_LOG("%s has been renamed to :%s\n", CONFIG_FILE_NEW_W_PATH, CONFIG_FILE_W_PATH);
+                DDBG("%s has been renamed to :%s\n", CONFIG_FILE_NEW_W_PATH, CONFIG_FILE_W_PATH);
             }
             //TODO: if failed, it will exist,
         }
         else
         {
-            DEBUG_LOG("=== check config.xml not valid config file: %s\n", CONFIG_FILE_NEW_W_PATH);
+            DDBG("=== check config.xml not valid config file: %s\n", CONFIG_FILE_NEW_W_PATH);
 
 
             // Buffer config.xml
@@ -1231,9 +1260,9 @@ int main(int argc, char **argv)
             {
                 //Recover config.xml from memory
                 InitConfigFile(&(pConfigBuf->pConfigBuffer));
-                DEBUG_LOG("***************** initconfigfile: %p\n", pConfigBuf->pConfigBuffer);
+                DDBG("***************** initconfigfile: %p\n", pConfigBuf->pConfigBuffer);
 
-                DEBUG_LOG("Failed to parse file : %s\n", CONFIG_FILE_W_PATH);
+                DDBG("Failed to parse file : %s\n", CONFIG_FILE_W_PATH);
 
                 // Add plugins by scanning appPath directory
                 int count;
@@ -1242,16 +1271,17 @@ int main(int argc, char **argv)
                                   &paths);
 
                 int i;
-                int dirCount;
+                int dirCount = 0;
                 char **app_path = NULL;
                 char **appId = NULL;
                 for (i = 0; i < count; i++)
                 {
-                    // Get list of directories under the app path, if it has $appPath/lib/plugin/, search its manifest.xml for av tag, then recompose config.xml
+                    // Get list of directories under the app path, if it has $appPath/lib/plugin/,
+                    // search its manifest.xml for av tag, then recompose config.xml
 
                     //TODO: if better way to get list of directory
                     GetDirsHasPath(paths[i], PLUGIN_DEFAULT_DIR_NAME, &dirCount, &app_path, &appId);
-                    DEBUG_LOG("fater get dirshas path:%s\n", PLUGIN_DEFAULT_DIR_NAME);
+                    DDBG("fater get dirshas path:%s\n", PLUGIN_DEFAULT_DIR_NAME);
                     if (dirCount > 0)
                     {
                         // search manifest.xml within the app_path, if found, copy the appid to plugin element
@@ -1262,7 +1292,7 @@ int main(int argc, char **argv)
                             int result = ftw(app_path[j], FileTreeCallback, 12);
                             if (result == 1)
                             {
-                                DEBUG_LOG("00000000000000000000000--it found the plugin app dir:%s, appID:%s\n", app_path[j], appId[j]);
+                                DDBG("it found the plugin app dir:%s, appID:%s\n", app_path[j], appId[j]);
                                 //Update plugin element node
                                 UpdatePluglibList(app_path[j], &(pConfigBuf->pConfigBuffer),
                                                   appId[j]);
@@ -1275,14 +1305,14 @@ int main(int argc, char **argv)
 
                 CleanupArray(&paths, count);
 
-                //Recover config.xml from memory
+                // Recover config.xml from memory
                 WriteXmlToFile(pConfigBuf->pConfigBuffer, CONFIG_FILE_W_PATH);
-                DEBUG_LOG("%%%%%%%%%%%%%%%%%%%%%55 before clean up:%s, dircoutn:%d, pathCount:%d, \n", CONFIG_FILE_W_PATH, dirCount, count);
+                DDBG("before clean up:%s, dircoutn:%d, pathCount:%d, \n", CONFIG_FILE_W_PATH, dirCount, count);
 
             }
             else
             {
-                DEBUG_LOG("Success in paring file: %s\n", CONFIG_FILE_W_PATH);
+                DDBG("Success in paring file: %s\n", CONFIG_FILE_W_PATH);
             }
         }
 
@@ -1295,7 +1325,7 @@ int main(int argc, char **argv)
 
         if (IpcServerAddMethod(hServer, &method_getPlugin) != 0)
         {
-            DEBUG_LOG("%s", "unable to add method GetInfoPlugin\n");
+            DDBG("%s", "unable to add method GetInfoPlugin\n");
             goto close_server;
         }
 
@@ -1304,12 +1334,11 @@ int main(int argc, char **argv)
         snprintf(method_installPlugin.szMethod, sizeof(method_installPlugin.szMethod), "%s",
                  "TPCSInstallPlugin");
         method_installPlugin.method = (METHODFUNC) InstallPlugin;
-        //method_installPlugin.pData = &(pConfigBuf->pConfigBuffer);
         method_installPlugin.pData = &pConfigBuf;
 
         if (IpcServerAddMethod(hServer, &method_installPlugin) != 0)
         {
-            DEBUG_LOG("%s", "unable to add method InstallPlugin\n");
+            DDBG("%s", "unable to add method InstallPlugin\n");
             goto close_server;
         }
 
@@ -1318,12 +1347,11 @@ int main(int argc, char **argv)
         snprintf(method_setActivePlugin.szMethod, sizeof(method_setActivePlugin.szMethod), "%s",
                  "TPCSSetActivePlugin");
         method_setActivePlugin.method = (METHODFUNC) SetActivePlugin;
-        //method_setActivePlugin.pData = &(pConfigBuf->pConfigBuffer);
         method_setActivePlugin.pData = &pConfigBuf;
 
         if (IpcServerAddMethod(hServer, &method_setActivePlugin) != 0)
         {
-            DEBUG_LOG("%s", "unable to add method SetActivePlugin\n");
+            DDBG("%s", "unable to add method SetActivePlugin\n");
             goto close_server;
         }
 
@@ -1336,18 +1364,18 @@ int main(int argc, char **argv)
 
         if (IpcServerAddMethod(hServer, &method_uninstallPlugin) != 0)
         {
-            DEBUG_LOG("%s", "unable to add method UninstallPlugin\n");
+            DDBG("%s", "unable to add method UninstallPlugin\n");
             goto close_server;
         }
 
-        DEBUG_LOG("----------------- START method loop----------%s", "\n");
+        DDBG("----------------- START method loop----------%s", "\n");
 
         // Daemon waits here for request from clients.
         IpcServerMainLoop(hServer);
-        DEBUG_LOG("----------------- END method loop----------%s", "\n");
+        DDBG("----------------- END method loop----------%s", "\n");
         // Clean up
-        DEBUG_LOG("======================= free xmldoc for isvalidConfig %s\n", "==============");
-        DEBUG_LOG("pconfigbuf address:%p\n", pConfigBuf->pConfigBuffer);
+        DDBG("======================= free xmldoc for isvalidConfig %s\n", "==============");
+        DDBG("pconfigbuf address:%p\n", pConfigBuf->pConfigBuffer);
         xmlFreeDoc(pConfigBuf->pConfigBuffer);
         free(pConfigBuf);
 
@@ -1355,7 +1383,7 @@ int main(int argc, char **argv)
     }
     else
     {
-        DEBUG_LOG("%s", "unable to open server connection \n");
+        DDBG("%s", "unable to open server connection \n");
         ret = -1;
         goto done;
     }
@@ -1364,7 +1392,7 @@ int main(int argc, char **argv)
     IpcServerClose(&hServer);
 
     done:
-    DEBUG_LOG("%s", "Unable to start the Daemon \n");
+    DDBG("%s", "Unable to start the Daemon \n");
 
     return ret;
 
index 367fe90..7dd3e2c 100644 (file)
@@ -29,6 +29,7 @@
 #define CONFIG_FILE_NEW_W_PATH "/usr/bin/tpcs_config_new.xml"
 #define SYSLINK_PLUG_PATH "/lib/plugin"
 #define ACTIVE_NONE "None"
+#define APP_ID_NULL ""
 #define CONFIG_DEFAULT_STRING "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
     <!DOCTYPE TPCSConfig SYSTEM \"tpcs_config.dtd\">\n\
     <TPCSConfig>\n\
index 80dffd2..0c35bac 100644 (file)
 #include <malloc.h>
 #include <string.h>
 
+#include "Debug.h"
 #include "TWPImpl.h"
 
 
 #define SITE_PLUGIN_PATH "/opt/usr/share/sec_plugin/libwpengine.so"
 
-#if defined(DEBUG)
-#define DEBUG_LOG(_fmt_, _param_...) { \
-                                        FILE *fp = fopen("/tmp/wpframelog.txt", "a"); \
-                                        if (fp != NULL) \
-                                        { \
-                                            printf("%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fprintf(fp, "%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fclose(fp); \
-                                        } \
-                                      }
-#else
-#define DEBUG_LOG(_fmt_, _param_...)
-#endif
-
-
 typedef TWP_RESULT (*FuncInitLibrary)(TWPAPIInit *pApiInit);
 typedef void (*FuncUninitLibrary)(void);
 typedef TWP_RESULT (*FuncConfigurationCreate)(TWPConfiguration *pConfigure, TWPConfigurationHandle *phConfigure);
@@ -163,11 +149,13 @@ TWP_RESULT TWPGetVersion(TWPLIB_HANDLE hLib, TWPVerInfo *pVerInfo)
     char const *pPluginVer = (*pCtx->pfGetVersion)();
 
     if (pPluginVer != NULL)
-        strncpy(pVerInfo->szPluginVer, pPluginVer, TWP_VER_MAX);
+        strncpy(pVerInfo->szPluginVer, pPluginVer, TWP_VER_MAX - 1);
     else
-        strncpy(pVerInfo->szPluginVer, "NULL", TWP_VER_MAX);
+        strncpy(pVerInfo->szPluginVer, "NULL", TWP_VER_MAX - 1);
 
-    DEBUG_LOG("%s %s %s\n", "Framework|Plugin version = ",
+    pVerInfo->szPluginVer[TWP_VER_MAX - 1] = '\n';
+
+    DDBG("%s %s %s\n", "Framework|Plugin version = ",
               pVerInfo->szFrameworkVer, pVerInfo->szPluginVer);
 
     return TWP_SUCCESS;
@@ -194,10 +182,12 @@ TWP_RESULT TWPGetInfo(TWPLIB_HANDLE hLib, char *pszInfo)
 
     char const *pszInfoPlugin = (*pCtx->pfGetInfo)();
 
-    if (pszInfo != NULL)
-        strncpy(pszInfo, pszInfoPlugin, TWP_META_MAX);
+    if (pszInfoPlugin != NULL)
+        strncpy(pszInfo, pszInfoPlugin, TWP_META_MAX - 1);
     else
-        strncpy(pszInfo, "NULL", TWP_META_MAX);
+        strncpy(pszInfo, "NULL", TWP_META_MAX - 1);
+
+    pszInfo[TWP_META_MAX - 1] = '\n';
 
     return TWP_SUCCESS;
 }
@@ -423,7 +413,7 @@ static SitePluginContext *LoadPlugin(void)
 {
     SitePluginContext *pCtx = NULL;
     void *pTmp = dlopen(SITE_PLUGIN_PATH, RTLD_LAZY);
-    DEBUG_LOG("%s", "load site plugin\n");
+    DDBG("%s", "load site plugin\n");
     if (pTmp != NULL)
     {
         FuncUninitLibrary TmpUninitLibrary;
@@ -453,208 +443,208 @@ static SitePluginContext *LoadPlugin(void)
         do
         {
             TmpInitLibrary = dlsym(pTmp, "TWPPInitLibrary");
-            DEBUG_LOG("%s", "load api TWPPInitLibrary\n");
+            DDBG("%s", "load api TWPPInitLibrary\n");
             if (TmpInitLibrary == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPInitLibrary in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPInitLibrary in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpUninitLibrary = dlsym(pTmp, "TWPPUninitLibrary");
-            DEBUG_LOG("%s", "load api TWPPUninitLibrary\n");
+            DDBG("%s", "load api TWPPUninitLibrary\n");
             if (TmpUninitLibrary == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPUninitLibrary in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPUninitLibrary in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpConfigurationCreate = dlsym(pTmp, "TWPPConfigurationCreate");
-            DEBUG_LOG("%s", "load api TWPPConfigurationCreate\n");
+            DDBG("%s", "load api TWPPConfigurationCreate\n");
             if (TmpConfigurationCreate == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPConfigurationCreate in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPConfigurationCreate in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpConfigurationDestroy = dlsym(pTmp, "TWPPConfigurationDestroy");
-            DEBUG_LOG("%s", "load api TWPPConfigurationDestroy\n");
+            DDBG("%s", "load api TWPPConfigurationDestroy\n");
             if (TmpConfigurationDestroy == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPConfigurationDestroy in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPConfigurationDestroy in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpLookupUrls = dlsym(pTmp, "TWPPLookupUrls");
-            DEBUG_LOG("%s", "load api TWPPLookupUrls\n");
+            DDBG("%s", "load api TWPPLookupUrls\n");
             if (TmpLookupUrls == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPLookupUrls in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPLookupUrls in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpResponseWrite = dlsym(pTmp, "TWPPResponseWrite");
-            DEBUG_LOG("%s", "load api TWPPResponseWrite\n");
+            DDBG("%s", "load api TWPPResponseWrite\n");
             if (TmpResponseWrite == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPResponseWrite in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPResponseWrite in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpResponseGetUrlRatingByIndex = dlsym(pTmp, "TWPPResponseGetUrlRatingByIndex");
-            DEBUG_LOG("%s", "load api TWPPResponseGetUrlRatingByIndex\n");
+            DDBG("%s", "load api TWPPResponseGetUrlRatingByIndex\n");
             if (TmpResponseGetUrlRatingByIndex == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPResponseGetUrlRatingByIndex in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPResponseGetUrlRatingByIndex in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpResponseGetUrlRatingByUrl = dlsym(pTmp, "TWPPResponseGetUrlRatingByUrl");
-            DEBUG_LOG("%s", "load api TWPPResponseGetUrlRatingByUrl\n");
+            DDBG("%s", "load api TWPPResponseGetUrlRatingByUrl\n");
             if (TmpResponseGetUrlRatingByUrl == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPResponseGetUrlRatingByUrl in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPResponseGetUrlRatingByUrl in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpResponseGetRedirUrlFor = dlsym(pTmp, "TWPPResponseGetRedirUrlFor");
-            DEBUG_LOG("%s", "load api TWPPResponseGetRedirUrlFor\n");
+            DDBG("%s", "load api TWPPResponseGetRedirUrlFor\n");
             if (TmpResponseGetRedirUrlFor == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPResponseGetRedirUrlFor in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPResponseGetRedirUrlFor in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpResponseGetUrlRatingsCount = dlsym(pTmp, "TWPPResponseGetUrlRatingsCount");
-            DEBUG_LOG("%s", "load api TWPPResponseGetUrlRatingsCount\n");
+            DDBG("%s", "load api TWPPResponseGetUrlRatingsCount\n");
             if (TmpResponseGetUrlRatingsCount == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPResponseGetUrlRatingsCount in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPResponseGetUrlRatingsCount in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpResponseDestroy = dlsym(pTmp, "TWPPResponseDestroy");
-            DEBUG_LOG("%s", "load api TWPPResponseDestroy\n");
+            DDBG("%s", "load api TWPPResponseDestroy\n");
             if (TmpResponseDestroy == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPResponseDestroy in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPResponseDestroy in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpPolicyCreate = dlsym(pTmp, "TWPPPolicyCreate");
-            DEBUG_LOG("%s", "load api TWPPPolicyCreate\n");
+            DDBG("%s", "load api TWPPPolicyCreate\n");
             if (TmpPolicyCreate == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPPolicyCreate in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPPolicyCreate in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpPolicyValidate = dlsym(pTmp, "TWPPPolicyValidate");
-            DEBUG_LOG("%s", "load api TWPPPolicyValidate\n");
+            DDBG("%s", "load api TWPPPolicyValidate\n");
             if (TmpPolicyValidate == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPPolicyValidate in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPPolicyValidate in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpPolicyGetViolations = dlsym(pTmp, "TWPPPolicyGetViolations");
-            DEBUG_LOG("%s", "load api TWPPPolicyGetViolations\n");
+            DDBG("%s", "load api TWPPPolicyGetViolations\n");
             if (TmpPolicyGetViolations == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPPolicyGetViolations in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPPolicyGetViolations in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpPolicyDestroy = dlsym(pTmp, "TWPPPolicyDestroy");
-            DEBUG_LOG("%s", "load api TWPPPolicyDestroy\n");
+            DDBG("%s", "load api TWPPPolicyDestroy\n");
             if (TmpPolicyDestroy == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPPolicyDestroy in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPPolicyDestroy in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpUrlRatingGetScore = dlsym(pTmp, "TWPPUrlRatingGetScore");
-            DEBUG_LOG("%s", "load api TWPPUrlRatingGetScore\n");
+            DDBG("%s", "load api TWPPUrlRatingGetScore\n");
             if (TmpUrlRatingGetScore == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPUrlRatingGetScore in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPUrlRatingGetScore in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpUrlRatingGetUrl = dlsym(pTmp, "TWPPUrlRatingGetUrl");
-            DEBUG_LOG("%s", "load api TWPPUrlRatingGetUrl\n");
+            DDBG("%s", "load api TWPPUrlRatingGetUrl\n");
             if (TmpUrlRatingGetUrl == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPUrlRatingGetUrl in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPUrlRatingGetUrl in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpUrlRatingGetDLAUrl = dlsym(pTmp, "TWPPUrlRatingGetDLAUrl");
-            DEBUG_LOG("%s", "load api TWPPUrlRatingGetDLAUrl\n");
+            DDBG("%s", "load api TWPPUrlRatingGetDLAUrl\n");
             if (TmpUrlRatingGetDLAUrl == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPUrlRatingGetDLAUrl in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPUrlRatingGetDLAUrl in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpUrlRatingHasCategory = dlsym(pTmp, "TWPPUrlRatingHasCategory");
-            DEBUG_LOG("%s", "load api TWPPUrlRatingHasCategory\n");
+            DDBG("%s", "load api TWPPUrlRatingHasCategory\n");
             if (TmpUrlRatingHasCategory == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPUrlRatingHasCategory in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPUrlRatingHasCategory in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpUrlRatingGetCategories = dlsym(pTmp, "TWPPUrlRatingGetCategories");
-            DEBUG_LOG("%s", "load api TWPPUrlRatingGetCategories\n");
+            DDBG("%s", "load api TWPPUrlRatingGetCategories\n");
             if (TmpUrlRatingGetCategories == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPUrlRatingGetCategories in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPUrlRatingGetCategories in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpCheckURL = dlsym(pTmp, "TWPPCheckURL");
-            DEBUG_LOG("%s", "load api TWPPCheckURL\n");
+            DDBG("%s", "load api TWPPCheckURL\n");
             if (TmpCheckURL == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPCheckURL in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPCheckURL in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpGetVersion = dlsym(pTmp, "TWPPGetVersion");
-            DEBUG_LOG("%s", "load api TWPPGetVersion\n");
+            DDBG("%s", "load api TWPPGetVersion\n");
             if(TmpGetVersion == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPGetVersion in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPGetVersion in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
 
             TmpGetInfo = dlsym(pTmp, "TWPPGetInfo");
-            DEBUG_LOG("%s", "load api TWPPGetInfo\n");
+            DDBG("%s", "load api TWPPGetInfo\n");
             if(TmpGetInfo == NULL)
             {
-                DEBUG_LOG("Failed to load TWPPGetInfo in %s\n", SITE_PLUGIN_PATH);
+                DDBG("Failed to load TWPPGetInfo in %s\n", SITE_PLUGIN_PATH);
                 dlclose(pTmp);
                 break;
             }
@@ -695,7 +685,7 @@ static SitePluginContext *LoadPlugin(void)
     }
     else
     {
-        DEBUG_LOG("No plugin found. %s \n", dlerror());
+        DDBG("No plugin found. %s \n", dlerror());
     }
 
     return pCtx;
index a652ef0..15e19c4 100644 (file)
@@ -328,7 +328,7 @@ TWP_RESULT TWPGetVersion(TWPLIB_HANDLE hLib, TWPVerInfo *pVerInfo);
  * This is a synchronous API.
  *
  * \param[in] hLib instance handle obtained from a call to the TWPInitLibrary().
- * \param[out] pszInfo string containing meta info
+ * \param[out] pszInfo string containing meta info, pszInfo allocated by caller of size TWP_META_MAX.
  *
  * \return TWP_RESULT
  */
index bede4c6..bc01242 100644 (file)
@@ -68,7 +68,7 @@ TWPSerGetVersion(void *pData, int req_argc, char **req_argv, char ***rep_argv, i
     TWP_RESULT iRes;
     char *szRes = NULL;
 
-    if (hLib == TWP_INVALID_HANDLE)
+    if (hLib == INVALID_TWPLIB_HANDLE)
     {
         iRes = TWP_INVALID_HANDLE;
         goto close_library;
@@ -129,9 +129,6 @@ close_library:
     if (szRes == NULL)
     {
         DERR("%s", "malloc returns error\n");
-        free((*rep_argv)[1]);
-        free((*rep_argv)[2]);
-        free((*rep_argv)[3]);
         goto err;
     }
     snprintf(szRes, RETURN_STATUS_STR_LEN, "%d", iRes);
@@ -139,6 +136,8 @@ close_library:
     if (*rep_argc == 1)
     {
         *rep_argv = (char **) malloc (sizeof(char*) * 1);
+        if (*rep_argv == NULL)
+            goto err;
     }
 
     //Assign result code.
@@ -148,8 +147,19 @@ close_library:
     return 0;
 
 err:
+    if (*rep_argv != NULL)
+    {
+        free((*rep_argv)[1]);
+        free((*rep_argv)[2]);
+        free((*rep_argv)[3]);
+    }
     *rep_argc = 0;
     free(*rep_argv);
+    *rep_argv = NULL;
+    rep_argv = NULL;
+    free(szRes);
+    TWPUninitLibrary(hLib);
+
     return -1;
 }
 
@@ -172,7 +182,7 @@ TWPSerGetURLReputation(void *pData, int req_argc, char **req_argv, char ***rep_a
     TWP_RESULT iRes;
     char *szRes = NULL;
 
-    if (hLib == TWP_INVALID_HANDLE)
+    if (hLib == INVALID_TWPLIB_HANDLE)
     {
         iRes = TWP_INVALID_HANDLE;
         goto close_library;
@@ -244,9 +254,6 @@ close_library:
     if (szRes == NULL)
     {
         DERR("%s", "malloc returns error\n");
-        free((*rep_argv)[1]);
-        free((*rep_argv)[2]);
-        free(*rep_argv);
         goto err;
     }
     snprintf(szRes, RETURN_STATUS_STR_LEN, "%d", iRes);
@@ -254,6 +261,8 @@ close_library:
     if (*rep_argc == 1)
     {
         *rep_argv = (char **) malloc (sizeof(char*) * 1);
+        if (*rep_argv == NULL)
+            goto err;
     }
     //Assign Result code
     (*rep_argv)[0] = szRes;
@@ -262,8 +271,17 @@ close_library:
     return 0;
 
 err:
+    if (*rep_argv != NULL)
+    {
+        free((*rep_argv)[1]);
+        free((*rep_argv)[2]);
+    }
     *rep_argc = 0;
     free(*rep_argv);
+    *rep_argv = NULL;  
+    rep_argv = NULL;
+    free(szRes);
+    TWPUninitLibrary(hLib);
     return -1;
 }
 
@@ -283,7 +301,7 @@ main(int argc, char **argv)
         // Register methods for get url reputation
         IpcServerMethod method_1;
         snprintf(method_1.szMethod, sizeof(method_1.szMethod), "%s", "TWPSerGetURLReputation");
-        method_1.method = TWPSerGetURLReputation;
+        method_1.method = (METHODFUNC) TWPSerGetURLReputation;
         method_1.pData = NULL;
 
         if (IpcServerAddMethod(hServer, &method_1) != 0)
@@ -295,7 +313,7 @@ main(int argc, char **argv)
         // Register methods for getversion
         IpcServerMethod method_2;
         snprintf(method_2.szMethod, sizeof(method_2.szMethod), "%s", "TWPSerGetVersion");
-        method_2.method = TWPSerGetVersion;
+        method_2.method = (METHODFUNC) TWPSerGetVersion;
         method_2.pData = NULL;
 
         if (IpcServerAddMethod(hServer, &method_2) != 0)
index bbb3996..2576b73 100644 (file)
@@ -42,6 +42,7 @@ const char *TCSPGetVersion(void);
  *
  * \return Return Type (const char *) \n
  * Meta information of plugin. \n
+ * Size should less than TCS_META_MAX. \n
  */
 const char *TCSPGetInfo(void);
 
index f1a0f0e..b47c6ad 100644 (file)
@@ -87,6 +87,8 @@ TWP_RESULT TWPPCheckURL(const char *pUrl, char **ppBlkUrl, unsigned int *puBlkUr
 
 const char *TWPPGetVersion(void);
 
+const char *TWPPGetInfo(void);
+
 #ifdef __cplusplus
 }
 #endif 
index 1d3b3ae..ed64bf5 100755 (executable)
Binary files a/plugin/lib/libwpengine.so and b/plugin/lib/libwpengine.so differ
index f3aaf9a..2c2b778 100755 (executable)
Binary files a/plugin/plugin_i386_release/libengine.so and b/plugin/plugin_i386_release/libengine.so differ
index e5a7626..4f2ba19 100755 (executable)
Binary files a/plugin/plugin_i386_release/libwpengine.so and b/plugin/plugin_i386_release/libwpengine.so differ
index 93f4d30..65c583a 100755 (executable)
@@ -4,9 +4,9 @@ build()
 {
        if [ $1 = "i386" ]
        then
-       . ./scripts/PrepareForEmul.sh
+           . ./scripts/PrepareForEmul.sh
        else
-       . ./scripts/PrepareForDevice.sh
+           . ./scripts/PrepareForDevice.sh
        fi
        
        cd ../framework
@@ -75,9 +75,9 @@ run()
          
          if [ "$TCS" = "" -o "$TWP" = "" -o "$TPCS" = "" -o "$TWPS" = "" ]
          then
-         echo "FAILED">>finalResult_i386.txt
+             echo "FAILED">>finalResult_i386.txt
          else
-         echo "PASSED">>finalResult_i386.txt
+             echo "PASSED">>finalResult_i386.txt
          fi
        else
          sdb -d root on
@@ -109,29 +109,27 @@ run()
          
          if [ "$TCS" = "" -o "$TWP" = "" ]
          then
-         echo "FAILED">>finalResult_arm.txt
+             echo "FAILED">>finalResult_arm.txt
          else
-         echo "PASSED">>finalResult_arm.txt
+             echo "PASSED">>finalResult_arm.txt
          fi
        fi
 }
 
 type=$2;
 if [ "$type" = "" ]
- then
-  type="i386"
+then
+    type="i386"
 fi
 
 if [ "$1" == "Build" ]
 then
-       build $type
-fi
-
-if [ "$1" == "Run" ]
+    build $type
+elif [ "$1" == "Run" ]
 then
-       build $type
-       run  $type
+    build $type
+    run  $type
 else
-echo "Invalid Parameters"
+    echo "Invalid Parameters"
 fi
 
index 469240c..a5d80cb 100755 (executable)
@@ -1,7 +1,7 @@
 export TCS_CFG=release
 export PORT=arm
 export SDK_HOME=$HOME/tizen-sdk
-SYSROOT="$SDK_HOME/platforms/tizen2.2/rootstraps/tizen-device-2.2.native"
+SYSROOT="$SDK_HOME/tools/smart-build-interface/../../platforms/tizen2.2/rootstraps/tizen-device-2.2.native"
 export CFLAGS="-I$SYSROOT/usr/include"
 export LD_FLAGS="--sysroot $SYSROOT -B $SYSROOT/usr/lib -L$SYSROOT/lib -L$SYSROOT/usr/lib -lc-2.13 -lpthread-2.13 -lc_nonshared"
 export TCS_CC="$SDK_HOME/tools/arm-linux-gnueabi-gcc-4.5/bin/arm-linux-gnueabi-gcc"
index 2d1e903..83c6242 100755 (executable)
@@ -2,7 +2,7 @@ export TCS_CFG="release"
 #export TCS_CFG="DEBUG"
 export PORT=x86
 export SDK_HOME=$HOME/tizen-sdk
-export SYSROOT="$SDK_HOME/platforms/tizen2.2/rootstraps/tizen-emulator-2.2.native"
+export SYSROOT="$SDK_HOME/tools/smart-build-interface/../../platforms/tizen2.2/rootstraps/tizen-emulator-2.2.native"
 export CFLAGS="-I$SYSROOT/usr/include"
 export LD_FLAGS="--sysroot=$SYSROOT -L$SYSROOT/lib -L$SYSROOT/usr/lib -lc-2.13 -lpthread-2.13 -lc_nonshared"
 export TCS_CC="$SDK_HOME/tools/i386-linux-gnueabi-gcc-4.5/bin/i386-linux-gnueabi-gcc"
index 7af8b11..e9a756f 100644 (file)
@@ -45,7 +45,19 @@ endif
 
 TCS_HEADER_FILE_PATH=../../framework
 
-CFLAGS := $(CFLAGS) -fPIC -g -Wall -O3 -I$(SRCDIR)/port -I$(SRCDIR)/tests -I$(TCS_HEADER_FILE_PATH)
+CFLAGS := $(CFLAGS) -fPIC -g -Wall -Werror -O3 -I$(SRCDIR)/port -I$(SRCDIR)/tests -I$(TCS_HEADER_FILE_PATH)
+
+# Define a list of pkg-config packages we want to use
+pkg_packages = dlog
+
+PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
+PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
+
+# Combine user supplied, additional, and pkg-config flags
+PKGLD_FLAGS += $(PKG_LDFLAGS) -L./lib
+
+PKGCFLAGS += -Wall -I$(SRCDIR) $(PKCL_CFLAGS) $(PKG_CFLAGS)
+
 ifeq ($(LD_FLAGS), )
 LDFLAGS= $(LD_FLAGS) -lc -pthread -L../../framework/lib -lsecfw -ldl
 else
@@ -65,7 +77,7 @@ $(OUTDIR)/%.o: $(SRCDIR)/%.c
        $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(SRCDIR)/$*.c
 
 $(TARGET): $(OUTDIR) $(OBJECTS) $(SOURCES)
-       $(LD) -o $(TARGET) $(OBJECTS) $(LDFLAGS)
+       $(LD) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(PKGLD_FLAGS)
 
 all: $(TARGET)
 
index 4aa9258..f0de59c 100644 (file)
@@ -1126,7 +1126,6 @@ static void TCSGetVersion_0001(void)
 
 static void TCSGetVersion_0002(void)
 {
-    TCSLIB_HANDLE hLib = INVALID_TCSLIB_HANDLE;
     TestCase TestCtx;
 
     TESTCASECTOR(&TestCtx, __FUNCTION__, 0, 0, 0, NULL);
@@ -1156,7 +1155,7 @@ static void TCSGetInfo_0001(void)
     TESTCASECTOR(&TestCtx, __FUNCTION__, 0, 0, 0, NULL);
     TEST_ASSERT((hLib = TCSLibraryOpen()) != INVALID_TCSLIB_HANDLE);
     char szMetaInfo[TCS_META_MAX];
-    TEST_ASSERT(TCSGetInfo(hLib, &szMetaInfo) == 0);
+    TEST_ASSERT(TCSGetInfo(hLib, szMetaInfo) == 0);
     TEST_ASSERT(strlen(szMetaInfo) > 0);
     TCSLibraryClose(hLib);
     TESTCASEDTOR(&TestCtx);
@@ -1164,12 +1163,11 @@ static void TCSGetInfo_0001(void)
 
 static void TCSGetInfo_0002(void)
 {
-    TCSLIB_HANDLE hLib = INVALID_TCSLIB_HANDLE;
     TestCase TestCtx;
 
     TESTCASECTOR(&TestCtx, __FUNCTION__, 0, 0, 0, NULL);
     char szMetaInfo[TCS_META_MAX];
-    TEST_ASSERT(TCSGetInfo(INVALID_TCSLIB_HANDLE, &szMetaInfo) == -1);
+    TEST_ASSERT(TCSGetInfo(INVALID_TCSLIB_HANDLE, szMetaInfo) == -1);
     TESTCASEDTOR(&TestCtx);
 }
 
index 4c20b43..f1d262b 100644 (file)
@@ -134,8 +134,6 @@ static int ScanBuffer(TestCase *pCtx);
 static int ScanFile(TestCase *pCtx);
 static char *GetTestRoot(void);
 static void PutTestRoot(char *pszRoot);
-static int BufferCompare(const char *pBuffer1, const char *pBuffer2, int iLen);
-static int FileCompare(const char *pszFile1, const char *pszFile2);
 static int VerifyRepairData(TestCase *pCtx, const char *pRepairedBuffer,
                             int iRepairedLen);
 static int VerifyRepairFile(TestCase *pCtx);
@@ -1104,37 +1102,6 @@ void TestScanFileEx(const char *pszFunc, int iTType, int iPolarity,
 }
 
 
-static int BufferCompare(const char *pBuffer1, const char *pBuffer2, int iLen)
-{
-
-    return memcmp(pBuffer1, pBuffer2, iLen);
-}
-
-
-static int FileCompare(const char *pszFile1, const char *pszFile2)
-{
-    int iLen1 = 0, iLen2 = 0, iRet = -1;
-    char *pBuffer1 = NULL, *pBuffer2 = NULL;
-
-    pBuffer1 = LoadFile(pszFile1, &iLen1);
-    if (pBuffer1 != NULL)
-    {
-        pBuffer2 = LoadFile(pszFile2, &iLen2);
-        if (pBuffer2 != NULL)
-        {
-            if (iLen1 != iLen2)
-                iRet = iLen1 - iLen2;
-
-            iRet = BufferCompare(pBuffer1, pBuffer2, iLen1);
-            PutLoadedFile(pBuffer2);
-        }
-        PutLoadedFile(pBuffer1);
-    }
-
-    return iRet;
-}
-
-
 static int ConInfectedFile(int iType, int iCompressFlag, const char *pszPath)
 {
     int iRet = -1;
@@ -1229,7 +1196,7 @@ static int Infected(TestCase *pCtx, const char *pData, int iDataLen)
     TCSLIB_HANDLE hLib = INVALID_TCSLIB_HANDLE;
     TestCase TestCtx = *pCtx;
 
-    ScanCtx.pData = pData;
+    ScanCtx.pData = (char *) pData;
     ScanCtx.uSize = (unsigned int) iDataLen;
     ScanCtx.pCurrentTestCase = pCtx;
 
@@ -1337,7 +1304,7 @@ static int ConVerifyRepairData(int iTType, int iCompressFlag, const char *pRepai
                                int iRepairedLen)
 {
 
-    return ConInfected(iTType, iCompressFlag, pRepairedBuffer, iRepairedLen);
+    return ConInfected(iTType, iCompressFlag, (char *) pRepairedBuffer, iRepairedLen);
 }
 
 
index ab1c641..3f0b6c9 100644 (file)
@@ -1245,7 +1245,7 @@ static void TWPCheckURL_0005(void)
     int iRiskLevel;
 
     RemoveEngine();
-    TEST_ASSERT(TWPCheckURL(INVALID_TWPLIB_HANDLE, URL_0_0, pBlkUrl, &uBlkUrlLen, &iRiskLevel) != TWP_SUCCESS);
+    TEST_ASSERT(TWPCheckURL(INVALID_TWPLIB_HANDLE, URL_0_0, &pBlkUrl, &uBlkUrlLen, &iRiskLevel) != TWP_SUCCESS);
     RestoreEngine();
     TESTCASEDTOR(&TestCtx);
 }
@@ -1311,7 +1311,7 @@ static void TWPGetInfo_0001(void)
     Init.memfreefunc = free;
     TEST_ASSERT((hLib = TWPInitLibrary(&Init)) != INVALID_TWPLIB_HANDLE);
     char szMetaInfo[TWP_META_MAX];
-    TEST_ASSERT(TWPGetInfo(hLib, &szMetaInfo) == TWP_SUCCESS);
+    TEST_ASSERT(TWPGetInfo(hLib, szMetaInfo) == TWP_SUCCESS);
     TEST_ASSERT(strlen(szMetaInfo) > 0);
     TWPUninitLibrary(hLib);
 
@@ -1324,7 +1324,7 @@ static void TWPGetInfo_0002(void)
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     char szMetaInfo[TWP_META_MAX];
-    TEST_ASSERT(TWPGetInfo(INVALID_TWPLIB_HANDLE, &szMetaInfo) == TWP_INVALID_PARAMETER);
+    TEST_ASSERT(TWPGetInfo(INVALID_TWPLIB_HANDLE, szMetaInfo) == TWP_INVALID_PARAMETER);
 
     TESTCASEDTOR(&TestCtx);
 }
index 542781b..8d7dbdc 100644 (file)
@@ -160,7 +160,7 @@ void RemoveEngine()
     if (pszRoot != NULL)
     {
         char szCommand[1024];
-        sprintf(&szCommand, "rm -f /opt/usr/share/sec_plugin/libwpengine.so");
+        sprintf(szCommand, "rm -f /opt/usr/share/sec_plugin/libwpengine.so");
         CallSys(szCommand);
     }
 }
index 1b5ca50..dc75f36 100644 (file)
@@ -45,7 +45,19 @@ endif
 
 TWP_HEADER_FILE_PATH=../../framework
 
-CFLAGS := $(CFLAGS) -fstack-protector-all -fPIC -g -Wall -O3 -I$(SRCDIR) -I$(TWP_HEADER_FILE_PATH)
+CFLAGS := $(CFLAGS) -fPIC -g -Wall -O3 -I$(SRCDIR) -I$(TWP_HEADER_FILE_PATH)
+
+# Define a list of pkg-config packages we want to use
+pkg_packages = dlog
+
+PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
+PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
+
+# Combine user supplied, additional, and pkg-config flags
+PKGLD_FLAGS += $(PKG_LDFLAGS) -L./lib
+
+PKGCFLAGS += -Wall -I$(SRCDIR) $(PKCL_CFLAGS) $(PKG_CFLAGS)
+
 ifeq ($(LD_FLAGS), )
 LDFLAGS= $(LD_FLAGS) -lc -pthread -L../../framework/lib -lsecfw -ldl
 else
@@ -67,7 +79,7 @@ $(OUTDIR)/%.o: $(SRCDIR)/%.c
        $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(SRCDIR)/$*.c
 
 $(TARGET): $(OUTDIR) $(OBJECTS) $(SOURCES)
-       $(LD) -o $(TARGET) $(OBJECTS) $(LDFLAGS)
+       $(LD) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(PKGLD_FLAGS)
 
 all: $(TARGET)
 
index b339245..12088b4 100644 (file)
@@ -46,7 +46,7 @@ else
 endif
 
 # Define a list of pkg-config packages we want to use
-pkg_packages = dbus-glib-1
+pkg_packages = dbus-glib-1 dlog
 
 PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
 PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
@@ -59,9 +59,9 @@ LD_FLAGS += $(PKG_LDFLAGS) -lscclient -lscserver -L$(TSC_ROOT_PATH)/lib -lxml2
 GBS_CFLAGS = -I${SYSROOT}/usr/include/dbus-1.0 -I${SYSROOT}/usr/lib/dbus-1.0/include -I${SYSROOT}/usr/include/libxml2
 
 ifeq ($(TCS_CFG), release)
-       CFLAGS := $(CFLAGS) -fPIE -g -Wall -O3 -I$(SRCDIR) -I$(TSC_ROOT_PATH) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -I../
+       CFLAGS := $(CFLAGS) -fPIE -g -Wall -Werror -O3 -I$(SRCDIR) -I$(TSC_ROOT_PATH) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -I../
 else
-       CFLAGS := $(CFLAGS) -fPIE -g -Wall -O3 -DDEBUG -I$(SRCDIR) -I$(TSC_ROOT_PATH) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -I../
+       CFLAGS := $(CFLAGS) -fPIE -g -Wall -Werror -O3 -DDEBUG -I$(SRCDIR) -I$(TSC_ROOT_PATH) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -I../
 endif
 
 SOURCES=$(SRCDIR)/TPCSSerDaemonTestUtils.c \
index dd44916..8fa5964 100755 (executable)
@@ -68,7 +68,7 @@ UpdateList(void *pData, int argc, char **argv, char ***szReply, int *len, CALLBA
 /* Test cases. */
 static void TSCStartup(void);
 static void TSCCleanup(void);
-static void TestCases(void);
+//static void TestCases(void);
 
 /**
  *  Plugin Control Service Test Cases BEGIN
@@ -107,7 +107,7 @@ static void TPCS_SetActivePlugin_002(void);
 static void TPCS_SetActivePlugin_003(void);
 static void TPCS_SetActivePluginSync_001(void);
 static void TPCS_SetActivePluginAsync_001(void);
-static void TPCS_ShutDown_IPC_001(void);
+//static void TPCS_ShutDown_IPC_001(void);
 
 static void TPCSTestCases(void);
 
@@ -138,7 +138,6 @@ static void TPCSTestCases(void)
     TPCS_GetPluginInfo_001();
 #endif
 #if 1
-
     TPCS_GetPluginInfo_002();
     TPCS_GetPluginInfo_003();
     TPCS_GetPluginInfo_004();
@@ -146,7 +145,6 @@ static void TPCSTestCases(void)
     TPCS_GetPluginInfo_006();
     TPCS_GetPluginInfoSync_001();
        TPCS_GetPluginInfoAsync_001();
-
 #endif
 #if 1
     TPCS_InstallPlugin_001();
@@ -216,7 +214,7 @@ static void TPCS_GetPluginInfo_001(void)
     WriteToFileFromMemory(CONFIG_TEST_NORMAL, CONFIG_FILE_W_PATH);
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 0;
@@ -227,21 +225,21 @@ static void TPCS_GetPluginInfo_001(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
     pid_t pidStub = 0;
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
 
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(strncmp(rep_argv[1], (const char*)CONFIG_TEST_NORMAL, rep_argc) == 0);
     xmlChar *data;
     int size;
@@ -252,7 +250,7 @@ static void TPCS_GetPluginInfo_001(void)
     TESTCASEDTOR(&TestCtx);
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 /**
@@ -274,7 +272,7 @@ static void TPCS_GetPluginInfo_002(void)
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 0;
@@ -285,19 +283,19 @@ static void TPCS_GetPluginInfo_002(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(strncmp(rep_argv[1], (const char*)CONFIG_FILE_NEW, rep_argc) == 0);
 
 
@@ -313,7 +311,7 @@ static void TPCS_GetPluginInfo_002(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
     return;
 }
@@ -336,7 +334,7 @@ static void TPCS_GetPluginInfo_003(void)
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 0;
@@ -347,19 +345,19 @@ static void TPCS_GetPluginInfo_003(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(strncmp(rep_argv[1], (const char*)CONFIG_DEFAULT_STRING, rep_argc) == 0);
 
 
@@ -375,7 +373,7 @@ static void TPCS_GetPluginInfo_003(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
     return;
 }
@@ -398,7 +396,7 @@ static void TPCS_GetPluginInfo_004(void)
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 0;
@@ -409,20 +407,20 @@ static void TPCS_GetPluginInfo_004(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(strncmp(rep_argv[1], (const char*)CONFIG_DEFAULT_STRING, rep_argc) == 0);
 
     FILE *pfConf = fopen(CONFIG_FILE_NEW_W_PATH, "r");
@@ -437,7 +435,7 @@ static void TPCS_GetPluginInfo_004(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
     return;
 
@@ -467,7 +465,7 @@ static void TPCS_GetPluginInfo_005()
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 0;
@@ -478,20 +476,20 @@ static void TPCS_GetPluginInfo_005()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(strncmp(rep_argv[1], (const char*)CONFIG_DEFAULT_STRING, rep_argc) == 0);
 
 
@@ -507,7 +505,7 @@ static void TPCS_GetPluginInfo_005()
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
     return;
 
@@ -546,7 +544,7 @@ static void TPCS_GetPluginInfo_006(void)
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 0;
@@ -557,19 +555,19 @@ static void TPCS_GetPluginInfo_006(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_GETINFO_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(strncmp(rep_argv[1], (const char*)CONFIG_DEFAULT_STRING, rep_argc) == 0);
 
 
@@ -586,7 +584,7 @@ static void TPCS_GetPluginInfo_006(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
     return;
 
@@ -606,14 +604,14 @@ static void TPCS_GetPluginInfoSync_001()
 
     int i;
 
-    IpcClientInfo *pInfo = NULL;
-    pInfo = IpcClientOpen();
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
+    hIpc = IpcClientOpen();
 
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
     sleep(1);
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -625,7 +623,7 @@ static void TPCS_GetPluginInfoSync_001()
         methods[i].isAsync = 0;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -635,7 +633,7 @@ static void TPCS_GetPluginInfoSync_001()
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
@@ -651,15 +649,15 @@ static void TPCS_GetPluginInfoAsync_001()
 
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -671,7 +669,7 @@ static void TPCS_GetPluginInfoAsync_001()
         methods[i].isAsync = 1;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -681,7 +679,7 @@ static void TPCS_GetPluginInfoAsync_001()
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
@@ -705,7 +703,7 @@ static void TPCS_InstallPlugin_001()
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 1;
@@ -717,26 +715,26 @@ static void TPCS_InstallPlugin_001()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(HasNode(XPATH_PLUGINS_PLUG, APP_ID_SAMPLE_2) == 0);
     TEST_ASSERT(HasNode(XPATH_ACTIVE_PLUGIN, APP_ID_SAMPLE_2) == 0);
 
     TESTCASEDTOR(&TestCtx);
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -760,7 +758,7 @@ static void TPCS_InstallPlugin_002()
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args 1
     int req_argc = 1;
@@ -772,18 +770,18 @@ static void TPCS_InstallPlugin_002()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(HasNode(XPATH_PLUGINS_PLUG, APP_ID_SAMPLE_1) == 0);
     CleanupReply(&rep_argv, &rep_argc);
 
@@ -792,16 +790,14 @@ static void TPCS_InstallPlugin_002()
     int req_argc_1 = 1;
     char *req_argv_1[] = {};
     req_argv_1[0] = strdup((const char*) APP_ID_SAMPLE_2);
-    int iResult_1 = -1;
 
-
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc_1, req_argv_1, &rep_argc,
-                              &rep_argv, DEF_TIMEOUT);
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN,
+                              req_argc_1, req_argv_1, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(HasNode(XPATH_PLUGINS_PLUG, APP_ID_SAMPLE_2) == 0);
     CleanupReply(&rep_argv, &rep_argc);
 
@@ -810,14 +806,14 @@ static void TPCS_InstallPlugin_002()
     char *req_argv_2[] = {};
     req_argv_2[0] = strdup((const char*) "IpcShutdown");
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_2, req_argv_2, &rep_argc,
-                              &rep_argv, DEF_TIMEOUT);
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_2,
+                              req_argv_2, &rep_argc, &rep_argv, DEF_TIMEOUT);
     CleanupReply(&rep_argv, &rep_argc);
 
     TESTCASEDTOR(&TestCtx);
     // Cleanup - On both success and failure.
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -839,7 +835,7 @@ static void TPCS_InstallPlugin_003()
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 1;
@@ -851,41 +847,41 @@ static void TPCS_InstallPlugin_003()
     int req_argc_1 = 1;
     char *req_argv_1[] = {};
     req_argv_1[0] = strdup((const char*) APP_ID_SAMPLE_1);
-    int iResult_1 = -1;
+
     //Response argc
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(HasNode(XPATH_PLUGINS_PLUG, APP_ID_SAMPLE_1) == 0);
 
     system("exec rm -r /opt/usr/apps/u7097a278m/lib/plugin/*");
     system("exec cp  /opt/usr/apps/u7097a278m/lib/u709v4.2.1.so  /opt/usr/apps/u7097a278m/lib/plugin/");
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc_1, req_argv_1, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc_1, req_argv_1, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 2);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
     TEST_ASSERT(HasNode(XPATH_PLUGINS_PLUG, APP_ID_SAMPLE_1) == 0);
 
     TESTCASEDTOR(&TestCtx);
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 
 
@@ -924,7 +920,7 @@ static void TPCS_InstallPlugin_006()
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 1;
@@ -936,26 +932,26 @@ static void TPCS_InstallPlugin_006()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_INSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 1);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_FAILURE, sizeof(RETURN_FAILURE)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_FAILURE) == 0);
 
     TEST_ASSERT(HasNode(XPATH_PLUGINS_PLUG, APP_ID_NO_EXIST) == -1);
 
     TESTCASEDTOR(&TestCtx);
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 
 }
@@ -1030,8 +1026,8 @@ static void TPCS_InstallPluginSync_001()
 
     int i;
 
-    IpcClientInfo *pInfo = NULL;
-    pInfo = IpcClientOpen();
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
+    hIpc = IpcClientOpen();
 
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
@@ -1039,7 +1035,7 @@ static void TPCS_InstallPluginSync_001()
     sleep(1);
 
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -1051,7 +1047,7 @@ static void TPCS_InstallPluginSync_001()
         methods[i].isAsync = 0;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -1061,7 +1057,7 @@ static void TPCS_InstallPluginSync_001()
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
@@ -1077,15 +1073,15 @@ static void TPCS_InstallPluginAsync_001()
 
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -1097,7 +1093,7 @@ static void TPCS_InstallPluginAsync_001()
         methods[i].isAsync = 1;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -1107,7 +1103,7 @@ static void TPCS_InstallPluginAsync_001()
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
@@ -1139,7 +1135,7 @@ static void TPCS_UninstallPlugin_001()
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 1;
@@ -1151,19 +1147,20 @@ static void TPCS_UninstallPlugin_001()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_UNINSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_UNINSTALL_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 1);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
+    TEST_ASSERT(HasNode(XPATH_PLUGINS_PLUG, APP_ID_SAMPLE_1) != 0);
 
     // Cleanup - On both success and failure.
 
@@ -1171,14 +1168,14 @@ static void TPCS_UninstallPlugin_001()
     char *req_argv_1[] = {};
     req_argv_1[0] = strdup((const char*) "IpcShutdown");
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_1, req_argv_1, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_1, req_argv_1, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
 
     sleep(1);
     CleanupReply(&rep_argv, &rep_argc);
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 
 }
@@ -1222,8 +1219,8 @@ static void TPCS_UninstallPluginSync_001(void)
 
     int i;
 
-    IpcClientInfo *pInfo = NULL;
-    pInfo = IpcClientOpen();
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
+    hIpc = IpcClientOpen();
 
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
@@ -1231,7 +1228,7 @@ static void TPCS_UninstallPluginSync_001(void)
     sleep(2);
 
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -1243,7 +1240,7 @@ static void TPCS_UninstallPluginSync_001(void)
         methods[i].isAsync = 0;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -1253,7 +1250,7 @@ static void TPCS_UninstallPluginSync_001(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
@@ -1269,15 +1266,15 @@ static void TPCS_UninstallPluginAsync_001(void)
 
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -1289,7 +1286,7 @@ static void TPCS_UninstallPluginAsync_001(void)
         methods[i].isAsync = 1;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -1299,7 +1296,7 @@ static void TPCS_UninstallPluginAsync_001(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
@@ -1319,8 +1316,8 @@ static void TPCS_SetActivePluginSync_001(void)
 
     int i;
 
-    IpcClientInfo *pInfo = NULL;
-    pInfo = IpcClientOpen();
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
+    hIpc = IpcClientOpen();
 
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
@@ -1328,7 +1325,7 @@ static void TPCS_SetActivePluginSync_001(void)
     sleep(2);
 
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -1340,7 +1337,7 @@ static void TPCS_SetActivePluginSync_001(void)
         methods[i].isAsync = 0;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -1350,12 +1347,13 @@ static void TPCS_SetActivePluginSync_001(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
 
 }
+
 static void TPCS_SetActivePluginAsync_001(void)
 {
 #if defined(TIMES)
@@ -1366,15 +1364,15 @@ static void TPCS_SetActivePluginAsync_001(void)
 
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -1386,7 +1384,7 @@ static void TPCS_SetActivePluginAsync_001(void)
         methods[i].isAsync = 1;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -1396,21 +1394,21 @@ static void TPCS_SetActivePluginAsync_001(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 
 
 }
 
-
+/*
 static void TPCS_ShutDown_IPC_001()
 {
     return;
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 1;
@@ -1422,29 +1420,28 @@ static void TPCS_ShutDown_IPC_001()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 1);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
 
 
     TESTCASEDTOR(&TestCtx);
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
-
-
-
+    IpcClientClose(hIpc);
 }
+*/
+
 /**
  * normal case, appId, update config.xml, verify the symbolic link with the new one
  */
@@ -1458,12 +1455,12 @@ static void TPCS_SetActivePlugin_001()
         int status = remove(CONFIG_FILE_NEW_W_PATH);
         TEST_ASSERT(status == 0);
     }
-    WriteToFileFromMemory(CONFIG_TEST_NORMAL, CONFIG_FILE_W_PATH);
+//    WriteToFileFromMemory(CONFIG_TEST_NORMAL, CONFIG_FILE_W_PATH);
 
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 1;
@@ -1475,31 +1472,31 @@ static void TPCS_SetActivePlugin_001()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_SETACTIVE_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_SETACTIVE_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 1);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_SUCCESS, sizeof(RETURN_SUCCESS)) == 0);
-    //TEST_ASSERT(HasNode(XPATH_ACTIVE_PLUGIN, APP_ID_SAMPLE_1) == 0);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
+    TEST_ASSERT(HasNode(XPATH_ACTIVE_PLUGIN, APP_ID_SAMPLE_1) == 0);
 
 
     int req_argc_1 = 1;
     char *req_argv_1[] = {};
     req_argv_1[0] = strdup((const char*) "IpcShutdown");
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_1, req_argv_1, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_1, req_argv_1, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     CleanupReply(&rep_argv, &rep_argc);
     sleep(1);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TESTCASEDTOR(&TestCtx);
 
@@ -1526,7 +1523,7 @@ static void TPCS_SetActivePlugin_002()
     pid_t pidStub = 0;
 
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     //Request args
     int req_argc = 1;
@@ -1538,31 +1535,31 @@ static void TPCS_SetActivePlugin_002()
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartTPCSServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_SETACTIVE_PLUGIN, req_argc, req_argv, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_SETACTIVE_PLUGIN, req_argc, req_argv, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult == 0);
 
     TEST_ASSERT(rep_argc == 1);
-    TEST_ASSERT(strncmp(rep_argv[0], RETURN_FAILURE, sizeof(RETURN_FAILURE)) == 0);
-    TEST_ASSERT(HasNode(XPATH_ACTIVE_PLUGIN, APP_ID_NO_EXIST) == -1);
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_FAILURE) == 0);
+    TEST_ASSERT(HasNode(XPATH_ACTIVE_PLUGIN, ACTIVE_NONE) == 0);
 
 
     int req_argc_1 = 1;
     char *req_argv_1[] = {};
     req_argv_1[0] = strdup((const char*) "IpcShutdown");
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_1, req_argv_1, &rep_argc,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_1, req_argv_1, &rep_argc,
                               &rep_argv, DEF_TIMEOUT);
     CleanupReply(&rep_argv, &rep_argc);
     sleep(1);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TESTCASEDTOR(&TestCtx);
 
@@ -1571,10 +1568,68 @@ static void TPCS_SetActivePlugin_002()
 }
 
 /**
- * other failure case, similar
+ * if passing is null, should disable the active plugin
  */
 static void TPCS_SetActivePlugin_003()
 {
+    //prepare normal case, config.xml exists, config.xml.new not exist.
+    FILE *fNew = fopen(CONFIG_FILE_NEW_W_PATH, "w");
+    if (fNew)
+    {
+        fclose(fNew);
+        int status = remove(CONFIG_FILE_NEW_W_PATH);
+        TEST_ASSERT(status == 0);
+    }
+    //WriteToFileFromMemory(CONFIG_TEST_NORMAL, CONFIG_FILE_W_PATH);
+
+    pid_t pidStub = 0;
+
+    TestCase TestCtx;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
+
+    //Request args
+    int req_argc = 1;
+    char *req_argv[] = {};
+    req_argv[0] = strdup((const char*) APP_ID_NULL);
+    int iResult = -1;
+
+    //Response argc
+    int rep_argc = 0;
+    char **rep_argv = NULL;
+
+    hIpc = IpcClientOpen();
+
+    TESTCASECTOR(&TestCtx, __FUNCTION__);
+    pidStub = StartTPCSServerStub();
+
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
+
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_METHOD_SETACTIVE_PLUGIN, req_argc, req_argv, &rep_argc,
+                              &rep_argv, DEF_TIMEOUT);
+    TEST_ASSERT(iResult == 0);
+
+    TEST_ASSERT(rep_argc == 1);
+
+    TEST_ASSERT(strcmp(rep_argv[0], RETURN_SUCCESS) == 0);
+    TEST_ASSERT(HasNode(XPATH_ACTIVE_PLUGIN, ACTIVE_NONE) == 0);
+
+
+    int req_argc_1 = 1;
+    char *req_argv_1[] = {};
+    req_argv_1[0] = strdup((const char*) "IpcShutdown");
+
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL, TPCS_SHUTDOWN_IPC, req_argc_1, req_argv_1, &rep_argc,
+                              &rep_argv, DEF_TIMEOUT);
+    CleanupReply(&rep_argv, &rep_argc);
+
+
+    sleep(1);
+    IpcClientClose(hIpc);
+
+    TESTCASEDTOR(&TestCtx);
+
+
+    TerminateProcess(pidStub);
 
 }
 
index ef0569b..452dd40 100755 (executable)
 #define TSCTEST_H
 
 #include <setjmp.h>
+#include "Debug.h"
 #include "IpcClient.h"
 #include "IpcServer.h"
+#include "IpcTypes.h"
 
 #ifdef __cplusplus 
 extern "C" {
@@ -56,20 +58,6 @@ extern "C" {
 
 /* Sleep interval for thread context switch. */
 #define SLEEP_INTERVAL 500
-#if defined(DEBUG)
-#define DEBUG_LOG(_fmt_, _param_...) { \
-                                        FILE *fp = fopen("/tmp/tpcsserdaemontestlog.txt", "a"); \
-                                        if (fp != NULL) \
-                                        { \
-                                            printf("%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fprintf(fp, "%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fclose(fp); \
-                                        } \
-                                       }
-#else
-#define DEBUG_LOG(_fmt_, _param_...)
-#endif
-
 
 /* Output methods. */
 #define LOG_OUT(fmt, x...) printf("Log:"fmt, ##x)
@@ -117,12 +105,6 @@ extern "C" {
 #define TSC_BACKUP_CONTENT_DIR "contents_bak"
 
 /**
- * Asynchronous methods callback signatures.
- */
-typedef void (*Callback)(void *pPrivate, int argc, char **argv);
-
-
-/**
  * Test case information data
  */
 typedef struct TestCase_struct
@@ -138,10 +120,10 @@ typedef struct ConTestContext_struct
 {
     TestCase *pTestCtx;
     const char *szMethod; /* Server method to be called inside thread. */
-    IpcClientInfo *pInfo;
+    TSC_IPC_HANDLE hIpc;
     int timeout;
     int iCid; /* Concurrency test id. */
-    Callback cbReply;
+    TSCCallback cbReply;
 
     /* Report concurrency test status. 1 - success, -1 - failure, 0 - running. */
     int iConTestRet;    /* Return value from Concurrent thread, which makes async call */
@@ -151,9 +133,9 @@ typedef struct ConTestContext_struct
 
 typedef struct MethodCall_struct
 {
-    const char *szMethod;
+    char *szMethod;
     int isAsync;  /* 0 = Synchronous; 1 = Asynchronous ; 2 = Cancel*/
-    Callback pfnCallback;
+    TSCCallback pfnCallback;
 } MethodCall;
 
 
@@ -186,7 +168,7 @@ typedef struct MethodCall_struct
     <Path>/sdcard</Path>\n \
     </AppPaths>\n\
     <Active>\n\
-        <AppId>xxxxx</AppId>\n\
+        <AppId>None</AppId>\n\
     </Active>\n\
     <Plugins>\n\
     </Plugins>\n\
index 8b1886a..3b6a430 100644 (file)
@@ -99,9 +99,9 @@ static void CallSys(const char *pszCmd);
 static pid_t StartProcess(const char *szPath, char *const argv[]);
 static pid_t StartProcess(const char *szPath, char *const argv[]);
 // For test cases needing concurrency.
-static void ConTestCaseCtor(ConTestContext *pConCtx, IpcClientInfo *pInfo, int iCid,
+static void ConTestCaseCtor(ConTestContext *pConCtx, TSC_IPC_HANDLE hIpc, int iCid,
                             TestCase *pCtx, const char *szMethod, int timeout, 
-                            Callback pfnCallback);
+                            TSCCallback pfnCallback);
 static void ConTestCaseDtor(ConTestContext *pConCtx);
 static int ConWaitOnTestCond(ConTestContext conCtxAry[], int len);
 static int ConTestSuccess(ConTestContext conCtxAry[], int len);
@@ -115,13 +115,13 @@ static void *ConUninstallProc(void *pData);
 static void *ConUninstallProcAsync(void *pData);
 static void *ConSetActiveProc(void *pData);
 static void *ConSetActiveProcAsync(void *pData);
-static void *ConSendMessageProc(void *pData);
+/*static void *ConSendMessageProc(void *pData);*/
 static void *ConSendMessageProcAsync(void *pData);
 static void *ConSendMessageProcCancelAsync(void *pData);
-static void Callback_GetInfo(void *pPrivate, int argc, char **argv);
-static void Callback_Install(void *pPrivate, int argc, char **argv);
-static void Callback_Uninstall(void *pPrivate, int argc, char **argv);
-static void Callback_SetActive(void *pPrivate, int argc, char **argv);
+static void Callback_GetInfo(void *pPrivate, int argc, const char **argv);
+static void Callback_Install(void *pPrivate, int argc, const char **argv);
+static void Callback_Uninstall(void *pPrivate, int argc, const char **argv);
+static void Callback_SetActive(void *pPrivate, int argc, const char **argv);
 
 pthread_mutex_t g_Mutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t g_Cond = PTHREAD_COND_INITIALIZER;
@@ -208,7 +208,7 @@ static int ConTestSuccess(ConTestContext *pConCtxAry, int len)
 
     for (i = 0; i < len; i++)
     {
-        DEBUG_LOG("\nSuccess [%d] iConTestRet=%d, iConTestReplyRet=%d\n", i,
+        DDBG("\nSuccess [%d] iConTestRet=%d, iConTestReplyRet=%d\n", i,
                 pConCtxAry[i].iConTestRet, pConCtxAry[i].iConTestReplyRet);
 
         if (pConCtxAry[i].iConTestRet != 1 || pConCtxAry[i].iConTestReplyRet != 1)
@@ -219,13 +219,13 @@ static int ConTestSuccess(ConTestContext *pConCtxAry, int len)
 }
 
 
-static void ConTestCaseCtor(ConTestContext *pConCtx, IpcClientInfo *pInfo, int iCid, TestCase *pCtx,
-                            const char *szMethod, int timeout, Callback pfnCallback)
+static void ConTestCaseCtor(ConTestContext *pConCtx, TSC_IPC_HANDLE hIpc, int iCid, TestCase *pCtx,
+                            const char *szMethod, int timeout, TSCCallback pfnCallback)
 {
     pConCtx->pTestCtx = pCtx;
     pConCtx->szMethod = szMethod;
     pConCtx->timeout = timeout;
-    pConCtx->pInfo = pInfo;
+    pConCtx->hIpc = hIpc;
     pConCtx->iCid = iCid;
     pConCtx->cbReply = pfnCallback;
     pConCtx->iConTestRet = 0; /* running. */
@@ -287,7 +287,7 @@ void Callback_In1_Out1(void *pPrivate, int argc, char **argv)
 
     // Cleanup - On both success and failure.
     CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "In1_Out1 Callback done");
+    DDBG("%s\n", "In1_Out1 Callback done");
 
     CONREPLYTEST_RELEASE(pConCtx)
 }
@@ -306,7 +306,7 @@ void Callback_In1_Out2(void *pPrivate, int argc, char **argv)
 
     // Cleanup - On both success and failure.
     CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "In1_Out2 Callback done");
+    DDBG("%s\n", "In1_Out2 Callback done");
 
     CONREPLYTEST_RELEASE(pConCtx)
 }
@@ -327,7 +327,7 @@ static void *ConGetInfoProcAsync(void *pData)
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
     TSC_CALL_HANDLE handle = NULL;
-    iResult = TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                                   pConCtx->szMethod, req_argc, req_argv,
                                   &handle, Callback_GetInfo, pConCtx, pConCtx->timeout);
 
@@ -356,7 +356,7 @@ static void *ConGetInfoProc(void *pData)
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
-    iResult = TSCSendMessageN(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageN(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                               pConCtx->szMethod, req_argc, req_argv, &rep_argc,
                               &rep_argv, pConCtx->timeout);
 
@@ -389,7 +389,7 @@ static void *ConInstallProcAsync(void *pData)
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
     TSC_CALL_HANDLE handle = NULL;
-    iResult = TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                                   pConCtx->szMethod, req_argc, req_argv,
                                   &handle, Callback_Install, pConCtx, pConCtx->timeout);
 
@@ -419,7 +419,7 @@ static void *ConInstallProc(void *pData)
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
-    iResult = TSCSendMessageN(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageN(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                               pConCtx->szMethod, req_argc, req_argv, &rep_argc,
                               &rep_argv, pConCtx->timeout);
 
@@ -455,7 +455,7 @@ static void *ConUninstallProc(void *pData)
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
-    iResult = TSCSendMessageN(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageN(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                               pConCtx->szMethod, req_argc, req_argv, &rep_argc,
                               &rep_argv, pConCtx->timeout);
 
@@ -487,7 +487,7 @@ static void *ConUninstallProcAsync(void *pData)
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
     TSC_CALL_HANDLE handle = NULL;
-    iResult = TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                                   pConCtx->szMethod, req_argc, req_argv,
                                   &handle, Callback_Uninstall, pConCtx, pConCtx->timeout);
 
@@ -519,7 +519,7 @@ static void *ConSetActiveProc(void *pData)
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
-    iResult = TSCSendMessageN(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageN(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                               pConCtx->szMethod, req_argc, req_argv, &rep_argc,
                               &rep_argv, pConCtx->timeout);
 
@@ -552,7 +552,7 @@ static void *ConSetActiveProcAsync(void *pData)
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
     TSC_CALL_HANDLE handle = NULL;
-    iResult = TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                                   pConCtx->szMethod, req_argc, req_argv,
                                   &handle, Callback_SetActive, pConCtx, pConCtx->timeout);
 
@@ -564,6 +564,7 @@ static void *ConSetActiveProcAsync(void *pData)
 
 }
 
+/*
 static void *ConSendMessageProc(void *pData)
 {
     int iOldType;
@@ -582,7 +583,7 @@ static void *ConSendMessageProc(void *pData)
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
-    iResult = TSCSendMessageN(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageN(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                               pConCtx->szMethod, req_argc, req_argv, &rep_argc,
                               &rep_argv, pConCtx->timeout);
 
@@ -597,6 +598,7 @@ static void *ConSendMessageProc(void *pData)
 
     return NULL;
 }
+*/
 
 
 static void *ConSendMessageProcAsync(void *pData)
@@ -614,7 +616,7 @@ static void *ConSendMessageProcAsync(void *pData)
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
     TSC_CALL_HANDLE handle = NULL;
-    iResult = TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                                   pConCtx->szMethod, req_argc, req_argv,
                                   &handle, pConCtx->cbReply, pConCtx, pConCtx->timeout);
 
@@ -640,15 +642,15 @@ static void *ConSendMessageProcCancelAsync(void *pData)
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
-    DEBUG_LOG("%s\n", "Sending message to be CANCELLED");
+    DDBG("%s\n", "Sending message to be CANCELLED");
     TSC_CALL_HANDLE handle = NULL;
-    iResult = TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
+    iResult = TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_PLUGIN_CHANNEL,
                                   pConCtx->szMethod, req_argc, req_argv,
                                   &handle, pConCtx->cbReply, pConCtx, pConCtx->timeout);
 
     sleep(1);
-    iResult = TSCCancelMessage(pConCtx->pInfo, handle);
-    DEBUG_LOG("Result after cancel:%d\n", iResult);
+    iResult = TSCCancelMessage(pConCtx->hIpc, handle);
+    DDBG("Result after cancel:%d\n", iResult);
 
     CONTEST_ASSERT(iResult == 0);
 
@@ -661,17 +663,17 @@ static void *ConSendMessageProcCancelAsync(void *pData)
 /**
  *
  */
-void ConSendMessage(TestCase *pCtx, IpcClientInfo *pInfo, ConTestContext conCtxs[],
+void ConSendMessage(TestCase *pCtx, TSC_IPC_HANDLE hIpc, ConTestContext conCtxs[],
                     pthread_t threads[], int lenCtxs, MethodCall methods[], int timeout)
 {
     int i, iRet = 0;
 
     /* Basic validation */
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     /* Prepare for concurrency tests. */
     for (i = 0; i < lenCtxs; i++)
-        ConTestCaseCtor(&conCtxs[i], pInfo, i + 1, pCtx, methods[i].szMethod, timeout, 
+        ConTestCaseCtor(&conCtxs[i], hIpc, i + 1, pCtx, methods[i].szMethod, timeout,
                         methods[i].pfnCallback);
 
     /* Concurrency tests. */
@@ -728,11 +730,11 @@ void ConSendMessage(TestCase *pCtx, IpcClientInfo *pInfo, ConTestContext conCtxs
     sleep(5);
     /* Wait for all tests completed. */
     iRet = ConWaitOnTestCond(conCtxs, lenCtxs);
-    DEBUG_LOG("All done. iRet = %d\n", iRet);
+    DDBG("All done. iRet = %d\n", iRet);
 
     if (iRet == ETIMEDOUT)
     {
-        DEBUG_LOG("%s\n", "Timed out.");
+        DDBG("%s\n", "Timed out.");
         usleep(SLEEP_INTERVAL);
         /* Cancel them all, if timeout. */
         for (i = 0; i < lenCtxs; i++)
@@ -757,7 +759,7 @@ void ConSendMessage(TestCase *pCtx, IpcClientInfo *pInfo, ConTestContext conCtxs
 /**
  *
  */
-void InThreadSendMessageAsync(TestCase *pCtx, IpcClientInfo *pInfo, 
+void InThreadSendMessageAsync(TestCase *pCtx, TSC_IPC_HANDLE hIpc,
                               ConTestContext conCtxs[], int lenCtxs, 
                               MethodCall methods[], int timeout)
 {
@@ -765,7 +767,7 @@ void InThreadSendMessageAsync(TestCase *pCtx, IpcClientInfo *pInfo,
     int i = 0;
     for (i = 0; i < lenCtxs; i++)
     {
-        ConTestCaseCtor(&conCtxs[i], pInfo, i + 1, pCtx, methods[i].szMethod, timeout,
+        ConTestCaseCtor(&conCtxs[i], hIpc, i + 1, pCtx, methods[i].szMethod, timeout,
                         methods[i].pfnCallback);
 
         // Wraps creating concurrency & sending of message in current thread.
@@ -774,7 +776,7 @@ void InThreadSendMessageAsync(TestCase *pCtx, IpcClientInfo *pInfo,
 
     /* Wait for all tests to complete. */
     int iRet = ConWaitOnTestCond(conCtxs, lenCtxs);
-    DEBUG_LOG("All done. iRet = %d\n", iRet);
+    DDBG("All done. iRet = %d\n", iRet);
 
     if (iRet == ETIMEDOUT)
     {
@@ -794,7 +796,7 @@ void InThreadSendMessageAsync(TestCase *pCtx, IpcClientInfo *pInfo,
 /**
  *
  */
-void InThreadSendMessageCancelAsync(TestCase *pCtx, IpcClientInfo *pInfo,
+void InThreadSendMessageCancelAsync(TestCase *pCtx, TSC_IPC_HANDLE hIpc,
                                     ConTestContext conCtxs[], int lenCtxs,
                                     MethodCall methods[], int timeout)
 {
@@ -802,7 +804,7 @@ void InThreadSendMessageCancelAsync(TestCase *pCtx, IpcClientInfo *pInfo,
     int i = 0;
     for (i = 0; i < lenCtxs; i++)
     {
-        ConTestCaseCtor(&conCtxs[i], pInfo, i + 1, pCtx, methods[i].szMethod, timeout,
+        ConTestCaseCtor(&conCtxs[i], hIpc, i + 1, pCtx, methods[i].szMethod, timeout,
                         methods[i].pfnCallback);
 
         // Wraps creating concurrency & sending of message in current thread.
@@ -812,7 +814,7 @@ void InThreadSendMessageCancelAsync(TestCase *pCtx, IpcClientInfo *pInfo,
 
     /* Wait for all tests to complete. */
     int iRet = ConWaitOnTestCond(conCtxs, lenCtxs);
-    DEBUG_LOG("All done. iRet = %d\n", iRet);
+    DDBG("All done. iRet = %d\n", iRet);
 
     if (iRet == ETIMEDOUT)
     {
@@ -891,7 +893,7 @@ pid_t StartTPCSServerStub(void)
 
 void CleanupReply(char ***pArr, int *pLen)
 {
-    if (pArr) {
+    if (pArr && *pArr) {
         while (*pLen)
             free ((*pArr)[--(*pLen)]);
 
@@ -962,7 +964,6 @@ int GetXmlFromFile(const char *pFileName, xmlDoc **pXmlDoc)
             *pXmlDoc = xmlCtxtReadFile(pParserCtxt, pFileName, NULL, XML_PARSE_DTDVALID);
             if (pXmlDoc != NULL)
             {
-
                 // Check if validation succeeded
                 if (pParserCtxt->valid)
                     ret = 0;
@@ -975,7 +976,7 @@ int GetXmlFromFile(const char *pFileName, xmlDoc **pXmlDoc)
     return ret;
 }
 
-int SearchNodeN(const char *xpath, const xmlDoc *pXmlDoc, const char* appId)
+int SearchNodeN(const xmlChar *xpath, xmlDocPtr pXmlDoc, const char* appId)
 {
 
     int result = -1;
@@ -1009,18 +1010,30 @@ int SearchNodeN(const char *xpath, const xmlDoc *pXmlDoc, const char* appId)
     }
 
     pNodeSet = pXPathObj->nodesetval;
-    int count = pNodeSet->nodeNr;
-    int i;
-    xmlNode *cur;
-
-    for(; i < count; i++)
+    if (pNodeSet)
     {
-        cur = pNodeSet->nodeTab[i]->children;
-        if (strncmp(cur->content, appId, strlen(appId)) == 0)
+        int count = pNodeSet->nodeNr;
+        int i = 0;
+        xmlNode *cur;
+
+        for(; i < count; i++)
         {
-            result = 0;
-            break;
+               if (pNodeSet->nodeTab[i])
+               {
+                cur = pNodeSet->nodeTab[i]->children;
+                if (cur)
+                {
+                    if (strcmp((const char *)cur->content, appId) == 0)
+                    {
+                        result = 0;
+                        break;
+                    }
+
+                }
+
+               }
         }
+
     }
     xmlXPathFreeObject(pXPathObj);
     xmlXPathFreeContext(pXPathCtx);
@@ -1033,11 +1046,11 @@ int HasNode(const char *xpath, const char *appId)
 
     int ret = -1;
     xmlDoc *pDoc = NULL;
-    //TEST_ASSERT(GetXmlFromMemory(&pDoc, req_argv[1] == 0));
+
     ret = GetXmlFromFile("/usr/bin/tpcs_config.xml", &pDoc);
     if (ret == 0)
     {
-        ret = SearchNodeN(xpath, pDoc, appId);
+        ret = SearchNodeN((const xmlChar *)xpath, pDoc, appId);
         xmlFreeDoc(pDoc);
     }
     return ret;
@@ -1046,7 +1059,7 @@ int HasNode(const char *xpath, const char *appId)
 /**
  *
  */
-static void Callback_GetInfo(void *pPrivate, int argc, char **argv)
+static void Callback_GetInfo(void *pPrivate, int argc, const char **argv)
 {
     CONREPLYTEST_START
 
@@ -1057,14 +1070,12 @@ static void Callback_GetInfo(void *pPrivate, int argc, char **argv)
         CONREPLYTEST_ASSERT(strncmp(argv[0], RETURN_SUCCESS, 1) == 0);
     }
 
-    // Cleanup - On both success and failure.
-    CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "Callback done");
+    DDBG("%s\n", "Callback done");
 
     CONREPLYTEST_RELEASE(pConCtx)
 }
 
-static void Callback_Install(void *pPrivate, int argc, char **argv)
+static void Callback_Install(void *pPrivate, int argc, const char **argv)
 {
     CONREPLYTEST_START
 
@@ -1075,13 +1086,12 @@ static void Callback_Install(void *pPrivate, int argc, char **argv)
         CONREPLYTEST_ASSERT(strncmp(argv[0], RETURN_SUCCESS, 1) == 0);
     }
 
-    // Cleanup - On both success and failure.
-    CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "Callback done");
+    DDBG("%s\n", "Callback done");
 
     CONREPLYTEST_RELEASE(pConCtx)
 }
-static void Callback_Uninstall(void *pPrivate, int argc, char **argv)
+
+static void Callback_Uninstall(void *pPrivate, int argc, const char **argv)
 {
     CONREPLYTEST_START
 
@@ -1092,13 +1102,12 @@ static void Callback_Uninstall(void *pPrivate, int argc, char **argv)
         CONREPLYTEST_ASSERT(strncmp(argv[0], RETURN_SUCCESS, 1) == 0);
     }
 
-    // Cleanup - On both success and failure.
-    CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "Callback done");
+    DDBG("%s\n", "Callback done");
 
     CONREPLYTEST_RELEASE(pConCtx)
 }
-static void Callback_SetActive(void *pPrivate, int argc, char **argv)
+
+static void Callback_SetActive(void *pPrivate, int argc, const char **argv)
 {
     CONREPLYTEST_START
 
@@ -1109,9 +1118,7 @@ static void Callback_SetActive(void *pPrivate, int argc, char **argv)
         CONREPLYTEST_ASSERT(strncmp(argv[0], RETURN_SUCCESS, 1) == 0);
     }
 
-    // Cleanup - On both success and failure.
-    CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "Callback done");
+    DDBG("%s\n", "Callback done");
 
     CONREPLYTEST_RELEASE(pConCtx)
 }
index 157df12..3f47298 100644 (file)
@@ -46,14 +46,15 @@ pid_t AddPlugApp(void);
 
 void CleanupReply(char ***pArr, int *pLen);
 char *GetNextUnsupportedMethodN(char **req_argv);
-void ConSendMessage(TestCase *pCtx, IpcClientInfo *pInfo, ConTestContext conCtxs[],
+void ConSendMessage(TestCase *pCtx, TSC_IPC_HANDLE hIpc, ConTestContext conCtxs[],
                     pthread_t threads[], int lenCtxs, MethodCall methods[], int timeout);
-void InThreadSendMessageAsync(TestCase *pCtx, IpcClientInfo *pInfo,
+void InThreadSendMessageAsync(TestCase *pCtx, TSC_IPC_HANDLE hIpc,
                               ConTestContext conCtxs[], int lenCtxs,
                               MethodCall methods[], int timeout);
-void InThreadSendMessageCancelAsync(TestCase *pCtx, IpcClientInfo *pInfo,
+void InThreadSendMessageCancelAsync(TestCase *pCtx, TSC_IPC_HANDLE hIpc,
                                     ConTestContext conCtxs[], int lenCtxs,
                                     MethodCall methods[], int timeout);
-
+pid_t StartTPCSServerStub(void);
+int HasNode(const char *xpath, const char *appId);
 
 #endif  /* TPCS_SER_DAEMON_TESTUTILS_H */
index 5619c78..e5e5556 100644 (file)
@@ -46,7 +46,11 @@ else
 endif
 
 # Define a list of pkg-config packages we want to use
-pkg_packages = dbus-glib-1
+ifeq ($(TCS_CFG), release)
+       pkg_packages = dbus-glib-1 
+else
+       pkg_packages = dbus-glib-1 dlog
+endif
 
 PKG_CFLAGS  = $(shell pkg-config --cflags $(pkg_packages))
 PKG_LDFLAGS = $(shell pkg-config --libs $(pkg_packages))
@@ -64,7 +68,7 @@ else
 CFLAGS := $(CFLAGS) -fPIE -g -Wall -O3 -DDEBUG -I$(SRCDIR) -I$(TSC_ROOT_PATH) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -I..
 endif
 
-CFLAGS := $(CFLAGS) -fPIE -g -Wall -O3 -I$(SRCDIR) -I$(TSC_ROOT_PATH) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -I..
+CFLAGS := $(CFLAGS) -fPIE -g -Wall -Werror -O3 -I$(SRCDIR) -I$(TSC_ROOT_PATH) $(PKCL_CFLAGS) $(GBS_CFLAGS) $(PKG_CFLAGS) -I..
 
 SOURCES=$(SRCDIR)/TWPSerDaemonTestUtils.c \
                $(SRCDIR)/TWPSerDaemonTest.c
index b1fa459..a07895d 100755 (executable)
@@ -45,6 +45,7 @@
 
 /* Constants */
 #define DEF_TIMEOUT -1
+#define TIMES 10
 
 /* Test cases. */
 static void TWPSerDaemonStartup(void);
@@ -53,8 +54,8 @@ static void TWPSerDaemonGetVerSendMessageN_001(void);
 static void TWPSerDaemonGetVerSendMessageN_002(void);
 static void TWPSerDaemonGetVerSendMessageN_003(void);
 static void TWPSerDaemonGetVerSendMessageN_004(void);
+static void TWPSerDaemonGetVerSendMessageSync_001(void);
 static void TWPSerDaemonGetVerSendMessageAsync_001(void);
-static void TWPSerDaemonGetVerSendMessageAsync_002(void);
 static void TWPSerDaemonGetRepSendMessageN_001(void);
 static void TWPSerDaemonGetRepSendMessageN_002(void);
 static void TWPSerDaemonGetRepSendMessageN_003(void);
@@ -90,8 +91,8 @@ static void TestCases(void)
     TWPSerDaemonGetVerSendMessageN_002();
     TWPSerDaemonGetVerSendMessageN_003();
     TWPSerDaemonGetVerSendMessageN_004();
+    TWPSerDaemonGetVerSendMessageSync_001();
     TWPSerDaemonGetVerSendMessageAsync_001();
-    TWPSerDaemonGetVerSendMessageAsync_002();
     TWPSerDaemonGetRepSendMessageN_001();
     TWPSerDaemonGetRepSendMessageN_002();
     TWPSerDaemonGetRepSendMessageN_003();
@@ -110,7 +111,7 @@ static void TestCases(void)
 static void TWPSerDaemonGetVerSendMessageN_001(void)
 {
     TestCase TestCtx;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 0;
@@ -121,13 +122,13 @@ static void TWPSerDaemonGetVerSendMessageN_001(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
     TESTCASECTOR(&TestCtx, __FUNCTION__);
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     /* Sending message without server should return failure. */
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
     TEST_ASSERT(iResult != 0);
 
@@ -135,7 +136,7 @@ static void TWPSerDaemonGetVerSendMessageN_001(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 }
 
 
@@ -146,7 +147,7 @@ static void TWPSerDaemonGetVerSendMessageN_002(void)
 {
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 0;
@@ -157,14 +158,14 @@ static void TWPSerDaemonGetVerSendMessageN_002(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT((iResult == 0) && (rep_argc == 4));
@@ -177,7 +178,7 @@ static void TWPSerDaemonGetVerSendMessageN_002(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -187,16 +188,10 @@ static void TWPSerDaemonGetVerSendMessageN_002(void)
  */
 static void TWPSerDaemonGetVerSendMessageN_003(void)
 {
-#if defined(TIMES)
-#undef TIMES
-#endif
-
-#define TIMES   100
-
     int i = 0;
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 0;
@@ -207,16 +202,16 @@ static void TWPSerDaemonGetVerSendMessageN_003(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
     LOG_OUT("Verbose: Please wait for test case to complete\n");
     for (i = 0; i < TIMES; ++i)
     {
-        iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
+        iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
                                   req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
         TEST_ASSERT((iResult == 0) && (rep_argc == 4));
@@ -225,14 +220,14 @@ static void TWPSerDaemonGetVerSendMessageN_003(void)
         TEST_ASSERT(strlen(rep_argv[2]) > 0);
         TEST_ASSERT(strncmp(rep_argv[3], TWP_DAEMON_VERSION, strlen(TWP_DAEMON_VERSION)) == 0);
         CleanupReply(&rep_argv, &rep_argc);
-        DEBUG_LOG("Sending Message to get Version (%d/%d)\n", i + 1, TIMES);
+        DDBG("Sending Message to get Version (%d/%d)\n", i + 1, TIMES);
     }
 
     TESTCASEDTOR(&TestCtx);
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -244,7 +239,7 @@ static void TWPSerDaemonGetVerSendMessageN_004(void)
 
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 0;
@@ -255,51 +250,46 @@ static void TWPSerDaemonGetVerSendMessageN_004(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     BackupEngine();
     system("rm -f /opt/usr/share/sec_plugin/libwpengine.so");
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETVERSIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
     RestoreEngine();
 
     TEST_ASSERT((iResult == 0) && (rep_argc == 1));
+    TEST_ASSERT(strncmp(rep_argv[0], "3", 1) == 0);
 
     TESTCASEDTOR(&TestCtx);
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
 /**
  * Multi-Thread Test case: [Sync method] Verify if we are able to do sync TWPGETVERSION in
- * the 2 threads.
+ * the 10 threads.
  */
-static void TWPSerDaemonGetVerSendMessageAsync_001(void)
+static void TWPSerDaemonGetVerSendMessageSync_001(void)
 {
-#if defined(TIMES)
-#undef TIMES
-#endif
-
-#define TIMES   100
-
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -311,7 +301,7 @@ static void TWPSerDaemonGetVerSendMessageAsync_001(void)
         methods[i].isAsync = 0;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
 
     for (i = 0; i < TIMES; i++)
@@ -321,7 +311,7 @@ static void TWPSerDaemonGetVerSendMessageAsync_001(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 
     TerminateProcess(pidStub);
 }
@@ -330,25 +320,19 @@ static void TWPSerDaemonGetVerSendMessageAsync_001(void)
  * Multi-Thread Test case: [Async method] Verify if we are able to do async TWPGETVERSION in
  * the 2 threads.
  */
-static void TWPSerDaemonGetVerSendMessageAsync_002(void)
+static void TWPSerDaemonGetVerSendMessageAsync_001(void)
 {
-#if defined(TIMES)
-#undef TIMES
-#endif
-
-#define TIMES   100
-
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -360,7 +344,7 @@ static void TWPSerDaemonGetVerSendMessageAsync_002(void)
         methods[i].isAsync = 1;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
     for (i = 0; i < TIMES; i++)
     {
@@ -369,7 +353,7 @@ static void TWPSerDaemonGetVerSendMessageAsync_002(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -380,8 +364,7 @@ static void TWPSerDaemonGetVerSendMessageAsync_002(void)
 static void TWPSerDaemonGetRepSendMessageN_001(void)
 {
     TestCase TestCtx;
-    pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 1;
@@ -392,12 +375,12 @@ static void TWPSerDaemonGetRepSendMessageN_001(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
     TESTCASECTOR(&TestCtx, __FUNCTION__);
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT((iResult != 0));
@@ -406,7 +389,7 @@ static void TWPSerDaemonGetRepSendMessageN_001(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
 }
 
 
@@ -418,7 +401,7 @@ static void TWPSerDaemonGetRepSendMessageN_002(void)
 {
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 1;
@@ -429,13 +412,13 @@ static void TWPSerDaemonGetRepSendMessageN_002(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT((iResult == 0) && (rep_argc == 3));
@@ -447,7 +430,7 @@ static void TWPSerDaemonGetRepSendMessageN_002(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -459,7 +442,7 @@ static void TWPSerDaemonGetRepSendMessageN_003(void)
 {
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 1;
@@ -470,13 +453,13 @@ static void TWPSerDaemonGetRepSendMessageN_003(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT((iResult == 0) && (rep_argc == 3));
@@ -488,7 +471,7 @@ static void TWPSerDaemonGetRepSendMessageN_003(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -500,7 +483,7 @@ static void TWPSerDaemonGetRepSendMessageN_004(void)
 {
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 1;
@@ -511,14 +494,14 @@ static void TWPSerDaemonGetRepSendMessageN_004(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT((iResult == 0) && (rep_argc == 2));
@@ -529,7 +512,7 @@ static void TWPSerDaemonGetRepSendMessageN_004(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -541,7 +524,7 @@ static void TWPSerDaemonGetRepSendMessageN_005(void)
 {
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 1;
@@ -552,13 +535,13 @@ static void TWPSerDaemonGetRepSendMessageN_005(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
 
     TEST_ASSERT((iResult == 0) && (rep_argc == 2));
@@ -569,7 +552,7 @@ static void TWPSerDaemonGetRepSendMessageN_005(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -580,7 +563,7 @@ static void TWPSerDaemonGetRepSendMessageN_006(void)
 {
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 1;
@@ -591,25 +574,25 @@ static void TWPSerDaemonGetRepSendMessageN_006(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
     BackupEngine();
     system("rm -f /opt/usr/share/sec_plugin/libwpengine.so");
-    iResult = TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
+    iResult = TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
                               req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT);
     RestoreEngine();
     TEST_ASSERT((iResult == 0) && (rep_argc == 1));
-    TEST_ASSERT(strncmp(rep_argv[0], "500", 1) == 0);
+    TEST_ASSERT(strncmp(rep_argv[0], "3", 1) == 0);
 
     TESTCASEDTOR(&TestCtx);
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -618,15 +601,10 @@ static void TWPSerDaemonGetRepSendMessageN_006(void)
  */
 static void TWPSerDaemonGetRepSendMessageN_007(void)
 {
-#if defined(TIMES)
-#undef TIMES
-#endif
-
-#define TIMES 50
     int i = 0;
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
 
     // Request args.
     int req_argc = 1;
@@ -636,18 +614,18 @@ static void TWPSerDaemonGetRepSendMessageN_007(void)
     int rep_argc = 0;
     char **rep_argv = NULL;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
     LOG_OUT("Verbose: Please wait for test case to complete\n");
 
     for (i = 0; i < TIMES; ++i)
     {
-        DEBUG_LOG("Debug: Sending message to get URL reputation (%d/%d)\n", i + 1, TIMES);
-        if (TSCSendMessageN(pInfo, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
+        DDBG("Debug: Sending message to get URL reputation (%d/%d)\n", i + 1, TIMES);
+        if (TSCSendMessageN(hIpc, TSC_DBUS_SERVER_WP_CHANNEL, TWPGETURLREPUTATIONMETHOD,
                                   req_argc, req_argv, &rep_argc, &rep_argv, DEF_TIMEOUT) == 0)
                {
                    if (rep_argc == 3)
@@ -658,12 +636,12 @@ static void TWPSerDaemonGetRepSendMessageN_007(void)
                    }
                    else
                    {
-                       DEBUG_LOG("Debug: Error while receiving the reputation");
+                       DDBG("Debug: Error while receiving the reputation");
                    }
                }
                else
                {
-              DEBUG_LOG("Debug: Error while Sending message\n");
+              DDBG("Debug: Error while Sending message\n");
                }
 
         CleanupReply(&rep_argv, &rep_argc);
@@ -674,7 +652,7 @@ static void TWPSerDaemonGetRepSendMessageN_007(void)
 
     // Cleanup - On both success and failure.
     CleanupReply(&rep_argv, &rep_argc);
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -685,23 +663,17 @@ static void TWPSerDaemonGetRepSendMessageN_007(void)
  */
 static void TWPSerDaemonGetRepSendMessageAsync_001(void)
 {
-#if defined(TIMES)
-#undef TIMES
-#endif
-
-#define TIMES   50
-
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
 
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -713,7 +685,7 @@ static void TWPSerDaemonGetRepSendMessageAsync_001(void)
         methods[i].isAsync = 0;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
     for (i = 0; i < TIMES; i++)
     {
@@ -722,7 +694,7 @@ static void TWPSerDaemonGetRepSendMessageAsync_001(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
@@ -732,22 +704,16 @@ static void TWPSerDaemonGetRepSendMessageAsync_001(void)
  */
 static void TWPSerDaemonGetRepSendMessageAsync_002(void)
 {
-#if defined(TIMES)
-#undef TIMES
-#endif
-
-#define TIMES   50
-
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -759,32 +725,26 @@ static void TWPSerDaemonGetRepSendMessageAsync_002(void)
         methods[i].isAsync = 1;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
 static void TWPSerDaemonGetRepGetVerSendAsync_001(void)
 {
-#if defined(TIMES)
-#undef TIMES
-#endif
-
-#define TIMES   50
-
     TestCase TestCtx;
     pid_t pidStub = 0;
-    IpcClientInfo *pInfo = NULL;
+    TSC_IPC_HANDLE hIpc = INVALID_IPC_HANDLE;
     int i;
 
-    pInfo = IpcClientOpen();
+    hIpc = IpcClientOpen();
 
     TESTCASECTOR(&TestCtx, __FUNCTION__);
     pidStub = StartServerStub();
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     ConTestContext ConCtxs[TIMES];
     pthread_t Threads[TIMES];
@@ -802,7 +762,7 @@ static void TWPSerDaemonGetRepGetVerSendAsync_001(void)
         methods[i].isAsync = 1;
     }
 
-    ConSendMessage(&TestCtx, pInfo, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
+    ConSendMessage(&TestCtx, hIpc, ConCtxs, Threads, TIMES, methods, DEF_TIMEOUT);
 
     for (i = 0; i < TIMES; i++)
     {
@@ -811,7 +771,7 @@ static void TWPSerDaemonGetRepGetVerSendAsync_001(void)
 
     TESTCASEDTOR(&TestCtx);
 
-    IpcClientClose(pInfo);
+    IpcClientClose(hIpc);
     TerminateProcess(pidStub);
 }
 
index 084c081..cebf9a5 100755 (executable)
@@ -36,6 +36,7 @@
 #define TWPGETURLREPUTATIONMETHOD "TWPSerGetURLReputation"
 
 #include <setjmp.h>
+#include "Debug.h"
 #include "IpcClient.h"
 
 #define Test_TWP_Minimal "0"
@@ -67,20 +68,6 @@ extern "C" {
 /* Output methods. */
 #define LOG_OUT(fmt, x...) printf("Log:"fmt, ##x)
 
-#if defined(DEBUG)
-#define DEBUG_LOG(_fmt_, _param_...) { \
-                                        FILE *fp = fopen("/tmp/twpserdaemontestlog.txt", "a"); \
-                                        if (fp != NULL) \
-                                        { \
-                                            printf("%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fprintf(fp, "%s,%d: " _fmt_, __FILE__, __LINE__, ##_param_); \
-                                            fclose(fp); \
-                                        } \
-                                       }
-#else
-#define DEBUG_LOG(_fmt_, _param_...)
-#endif
-
 #define TRY_TEST { \
     TestCasesCount++; \
     int _ret_ = setjmp(SCJmpBuf); \
@@ -140,7 +127,7 @@ typedef struct ConTestContext_struct
 {
     TestCase *pTestCtx;
     const char *szMethod; /* Server method to be called inside thread. */
-    IpcClientInfo *pInfo;
+    TSC_IPC_HANDLE hIpc;
     int timeout;
     int iCid; /* Concurrency test id. */
 
@@ -152,7 +139,7 @@ typedef struct ConTestContext_struct
 
 typedef struct MethodCall_struct
 {
-    const char *szMethod;
+    char *szMethod;
     int isAsync;  /* 0 = Synchronous; 1 = Asynchronous */
 } MethodCall;
 
index 43d30df..ffc69dc 100644 (file)
@@ -100,7 +100,7 @@ static pid_t StartProcess(const char *szPath, char *const argv[]);
 static pid_t StartProcess(const char *szPath, char *const argv[]);
 
 // For test cases needing concurrency.
-static void ConTestCaseCtor(ConTestContext *pConCtx, IpcClientInfo *pInfo, int iCid,
+static void ConTestCaseCtor(ConTestContext *pConCtx, TSC_IPC_HANDLE hIpc, int iCid,
                             TestCase *pCtx, const char *szMethod, int timeout);
 static void ConTestCaseDtor(ConTestContext *pConCtx);
 static int ConWaitOnTestCond(ConTestContext conCtxAry[], int len);
@@ -207,13 +207,13 @@ static int ConTestSuccess(ConTestContext *pConCtxAry, int len)
 }
 
 
-static void ConTestCaseCtor(ConTestContext *pConCtx, IpcClientInfo *pInfo, int iCid, TestCase *pCtx,
+static void ConTestCaseCtor(ConTestContext *pConCtx, TSC_IPC_HANDLE hIpc, int iCid, TestCase *pCtx,
                             const char *szMethod, int timeout)
 {
     pConCtx->pTestCtx = pCtx;
     pConCtx->szMethod = szMethod;
     pConCtx->timeout = timeout;
-    pConCtx->pInfo = pInfo;
+    pConCtx->hIpc = hIpc;
     pConCtx->iCid = iCid;
     pConCtx->iConTestRet = 0; /* running. */
     pConCtx->iConTestReplyRet = 0; /* running. */
@@ -274,7 +274,7 @@ static int ConWaitOnTestCond(ConTestContext conCtxAry[], int len)
 /**
  *
  */
-static void Callback_GetVer(void *pPrivate, int argc, char **argv)
+static void Callback_GetVer(void *pPrivate, int argc, const char **argv)
 {
     pthread_mutex_lock(&g_Mutex_cb);
     CONREPLYTEST_START
@@ -290,13 +290,10 @@ static void Callback_GetVer(void *pPrivate, int argc, char **argv)
 
     if (argc == 1 || argc == 0)
     {
-        DEBUG_LOG("%s\n", "Debug: Error returned from channel client");
+        DDBG("%s\n", "Debug: Error returned from channel client");
     }
 
-    // Cleanup - On both success and failure.
-    CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "Callback done");
-    sleep(2);
+    DDBG("%s\n", "Callback done");
     CONREPLYTEST_RELEASE(pConCtx)
     pthread_mutex_unlock(&g_Mutex_cb);
 }
@@ -305,7 +302,7 @@ static void Callback_GetVer(void *pPrivate, int argc, char **argv)
 /**
  *
  */
-static void Callback_GetRep(void *pPrivate, int argc, char **argv)
+static void Callback_GetRep(void *pPrivate, int argc, const char **argv)
 {
     pthread_mutex_lock(&g_Mutex_cb);
     CONREPLYTEST_START
@@ -320,12 +317,10 @@ static void Callback_GetRep(void *pPrivate, int argc, char **argv)
 
     if (argc == 0 || argc == 1)
     {
-        DEBUG_LOG("%s\n", "Debug: Error returned from channel client");
+        DDBG("%s\n", "Debug: Error returned from channel client");
     }
 
-    // Cleanup - On both success and failure.
-    CleanupReply(&argv, &argc);
-    DEBUG_LOG("%s\n", "Callback done");
+    DDBG("%s\n", "Callback done");
     sleep(2);
     CONREPLYTEST_RELEASE(pConCtx)
     pthread_mutex_unlock(&g_Mutex_cb);
@@ -348,7 +343,7 @@ static void *ConSendMessageProc(void *pData)
 
     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &iOldType);
 
-    if (TSCSendMessageN(pConCtx->pInfo, TSC_DBUS_SERVER_WP_CHANNEL, pConCtx->szMethod, req_argc, req_argv, &rep_argc,
+    if (TSCSendMessageN(pConCtx->hIpc, TSC_DBUS_SERVER_WP_CHANNEL, pConCtx->szMethod, req_argc, req_argv, &rep_argc,
                               &rep_argv, pConCtx->timeout) == 0)
     {
         if (strcmp(pConCtx->szMethod, TWPGETVERSIONMETHOD) == 0)
@@ -362,7 +357,7 @@ static void *ConSendMessageProc(void *pData)
             }
             else
             {
-                DEBUG_LOG("Debug: call did not succeed with result code %s", rep_argv[0]);
+                DDBG("Debug: call did not succeed with result code %s", rep_argv[0]);
             }
         }
 
@@ -376,14 +371,14 @@ static void *ConSendMessageProc(void *pData)
             }
             else
             {
-                DEBUG_LOG("Debug: call did not succeed with result code %s", rep_argv[0]);
+                DDBG("Debug: call did not succeed with result code %s", rep_argv[0]);
             }
             sleep(3);
         }
     }
     else
     {
-        DEBUG_LOG("Error while sending message");
+        DDBG("Error while sending message");
     }
 
     CONTEST_RELEASE(pConCtx)
@@ -403,7 +398,6 @@ static void *ConSendMessageProcAsync(void *pData)
     // Request args.
     int req_argc = 1;
     char *req_argv[] = {"www.zcrack.com"};
-    int iResult = -1;
 
     CONREPLYTEST_START
 
@@ -413,16 +407,18 @@ static void *ConSendMessageProcAsync(void *pData)
 
     if (strcmp(pConCtx->szMethod, TWPGETVERSIONMETHOD) == 0)
     {
-        if (TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_WP_CHANNEL, pConCtx->szMethod, req_argc, req_argv,
+        if (TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_WP_CHANNEL, pConCtx->szMethod, req_argc, req_argv,
                                       &handle, Callback_GetVer, pConCtx, pConCtx->timeout) != 0)
-            DEBUG_LOG("Debug: Error while sending message TSCSendMessageAsync\n");
+            DDBG("Debug: Error while sending message TSCSendMessageAsync\n");
+        
+        sleep(4);
     }
 
     if (strcmp(pConCtx->szMethod, TWPGETURLREPUTATIONMETHOD) == 0)
     {
-        if (TSCSendMessageAsync(pConCtx->pInfo, TSC_DBUS_SERVER_WP_CHANNEL, pConCtx->szMethod, req_argc, req_argv,
+        if (TSCSendMessageAsync(pConCtx->hIpc, TSC_DBUS_SERVER_WP_CHANNEL, pConCtx->szMethod, req_argc, req_argv,
                                       &handle, Callback_GetRep, pConCtx, pConCtx->timeout) != 0)
-            DEBUG_LOG("Debug: Error while sending message TSCSendMessageAsync\n");
+            DDBG("Debug: Error while sending message TSCSendMessageAsync\n");
 
         sleep(3);
     }
@@ -436,7 +432,7 @@ static void *ConSendMessageProcAsync(void *pData)
 /**
  *
  */
-void ConSendMessage(TestCase *pCtx, IpcClientInfo *pInfo, ConTestContext conCtxs[],
+void ConSendMessage(TestCase *pCtx, TSC_IPC_HANDLE hIpc, ConTestContext conCtxs[],
                     pthread_t threads[], int lenCtxs, MethodCall methods[], int timeout)
 {
     int i, iRet = 0;
@@ -444,11 +440,11 @@ void ConSendMessage(TestCase *pCtx, IpcClientInfo *pInfo, ConTestContext conCtxs
     TestCase TestCtx = *pCtx;
 
     /* Basic validation */
-    TEST_ASSERT(pInfo != NULL);
+    TEST_ASSERT(hIpc != INVALID_IPC_HANDLE);
 
     /* Prepare for concurrency tests. */
     for (i = 0; i < lenCtxs; i++)
-        ConTestCaseCtor(&conCtxs[i], pInfo, i + 1, pCtx, methods[i].szMethod, timeout);
+        ConTestCaseCtor(&conCtxs[i], hIpc, i + 1, pCtx, methods[i].szMethod, timeout);
 
     /* Concurrency tests. */
     for (i = 0; i < lenCtxs; i++)
@@ -551,7 +547,7 @@ pid_t StartServerStub(void)
 
 void CleanupReply(char ***pArr, int *pLen)
 {
-    if (pArr) {
+    if (pArr && *pArr) {
         while (*pLen)
             free ((*pArr)[--(*pLen)]);
 
@@ -631,7 +627,7 @@ void RestoreEngine()
 
     if (pszRoot != NULL)
     {
-        char szCommand[1024];
+        char szCommand[1024] = {0};
 
         sprintf(szCommand, "cp -f %s/backup/libwpengine.so /opt/usr/share/sec_plugin/", pszRoot);
         CallSys(szCommand);
@@ -649,8 +645,7 @@ void RemoveEngine()
     if (pszRoot != NULL)
     {
         LOG_OUT("Remove Engine 1");
-        char szCommand[1024];
-        sprintf(&szCommand, "rm -f /opt/usr/share/sec_plugin/libwpengine.so");
+        char szCommand[1024] = "rm -f /opt/usr/share/sec_plugin/libwpengine.so";
         CallSys(szCommand);
         PutTestRoot(pszRoot);
     }
index b053f96..cc92164 100644 (file)
@@ -37,7 +37,9 @@ void TerminateAllProcess(const char *szName);
 pid_t StartServerStub(void);
 void CleanupReply(char ***pArr, int *pLen);
 char *GetNextUnsupportedMethodN(char **req_argv);
-void ConSendMessage(TestCase *pCtx, IpcClientInfo *pInfo, ConTestContext conCtxs[],
+void ConSendMessage(TestCase *pCtx, TSC_IPC_HANDLE hIpc, ConTestContext conCtxs[],
                     pthread_t threads[], int lenCtxs, MethodCall methods[], int timeout);
 
+void BackupEngine();
+void RestoreEngine();
 #endif  /* TSCTESTUTILS_H */