Add onRequestUpdateCallback in CA and also fix a status bug

Change-Id: I82ace0ee982b4b1bb5c1c10d316b314d9300348e
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index edd61dc..6b93ee4 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -35,9 +35,19 @@
   : m_face(face)
   , m_keyChain(keyChain)
 {
+  // load the config and create storage
   m_config.load(configPath);
   m_storage = CaStorage::createCaStorage(storageType);
 
+  // set default handler and callback
+  m_probeHandler = [&] (const std::string& probeInfo) {
+    return probeInfo;
+  };
+  m_requestUpdateCallback = [&] (const CertificateRequest& CertRequest) {
+    // do nothing
+  };
+
+  // register prefix
   for (const auto& item : m_config.m_caItems) {
     Name prefix = item.m_caName;
     prefix.append("CA");
@@ -131,6 +141,7 @@
   }
   std::string requestId = std::to_string(random::generateWord64());
   CertificateRequest certRequest(caItem.m_caName, requestId, clientCert);
+  certRequest.setStatus(ChallengeModule::WAIT_SELECTION);
   try {
     m_storage->addRequest(certRequest);
   }
@@ -141,11 +152,12 @@
 
   Data result;
   result.setName(request.getName());
-  result.setContent(dataContentFromJson(genResponseNewJson(requestId,
-                                                           ChallengeModule::WAIT_SELECTION,
+  result.setContent(dataContentFromJson(genResponseNewJson(requestId, certRequest.getStatus(),
                                                            caItem.m_supportedChallenges)));
   m_keyChain.sign(result, signingByCertificate(caItem.m_anchor));
   m_face.put(result);
+
+  m_requestUpdateCallback(certRequest);
 }
 
 void
@@ -193,6 +205,8 @@
   result.setContent(dataContentFromJson(contentJson));
   m_keyChain.sign(result, signingByCertificate(caItem.m_anchor));
   m_face.put(result);
+
+  m_requestUpdateCallback(certRequest);
 }
 
 void
@@ -233,6 +247,8 @@
   m_keyChain.sign(result, signingByCertificate(caItem.m_anchor));
   m_face.put(result);
 
+  m_requestUpdateCallback(certRequest);
+
   if (certRequest.getStatus() == ChallengeModule::SUCCESS) {
     issueCertificate(certRequest, caItem);
   }