Fix error message bug on xmlsec callback function 78/82278/3
authorsangwan.kwon <sangwan.kwon@samsung.com>
Tue, 2 Aug 2016 10:11:58 +0000 (19:11 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Wed, 3 Aug 2016 01:59:15 +0000 (10:59 +0900)
[Problem]
* If parameter has NULL value. It doesn't show proper.
* Making error message is dealt on xmlsec1.
[Solution]
* Add null check logic.
* Callback function make error message.

Change-Id: Iaa33d15780840e5f1df32881703c8952148b269c
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
vcore/vcore/XmlsecAdapter.cpp

index 2ac5318..1694f2e 100644 (file)
@@ -45,6 +45,8 @@
 
 #include <vcore/XmlsecAdapter.h>
 
+#define VCORE_ERRORS_BUFFER_SIZE 1024
+
 IMPLEMENT_SINGLETON(ValidationCore::XmlSec)
 
 namespace {
@@ -166,15 +168,34 @@ void LogDebugPrint(const char *file,
                                   int reason,
                                   const char *msg)
 {
-       std::stringstream ss;
-       ss << "[" << file << ":" << line << "][" << func
-          << "] : [" << errorObject << "] : [" << errorSubject
-          << "] : [" << msg << "]" << std::endl;
+       // Get error message from xmlsec.
+       const char *errorMsg = NULL;
+       for (xmlSecSize i = 0; (i < XMLSEC_ERRORS_MAX_NUMBER) &&
+                                                       (xmlSecErrorsGetMsg(i) != NULL); ++i) {
+               if (xmlSecErrorsGetCode(i) == reason) {
+                       errorMsg = xmlSecErrorsGetMsg(i);
+                       break;
+               }
+       }
 
-       if (reason == 256)
-               LogError(ss.str());
+       // Make full error message.
+       char buff[VCORE_ERRORS_BUFFER_SIZE];
+       snprintf(buff,
+                       sizeof(buff),
+                       "[%s:%d] %s(): obj=%s, subj=%s, error=%d:%s:%s\n",
+                       file,
+                       line,
+                       func,
+                       (errorObject != NULL) ? errorObject : "",
+                       (errorSubject != NULL) ? errorSubject : "",
+                       reason,
+                       (errorMsg != NULL) ? errorMsg : "",
+                       (msg != NULL) ? msg : "");
+
+       if (reason == XMLSEC_ERRORS_MAX_NUMBER)
+               LogError(buff);
        else
-               LogDebug(ss.str());
+               LogDebug(buff);
 }
 
 XmlSec::XmlSec()