Generate security setup for cion cpp code 03/270003/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 24 Jan 2022 05:59:31 +0000 (14:59 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 25 Jan 2022 04:10:58 +0000 (13:10 +0900)
Change-Id: I2ba76e0219418df0440fb2273e0de27e3ad11eab
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
idlc/gen_cion/cpp_cion_gen_base.cc
idlc/gen_cion/cpp_cion_gen_base.h
idlc/gen_cion/cpp_cion_gen_base_cb.h
idlc/gen_cion/cpp_cion_group_body_gen.cc
idlc/gen_cion/cpp_cion_group_body_gen_cb.h
idlc/gen_cion/cpp_cion_proxy_body_gen.cc
idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h
idlc/gen_cion/cpp_cion_stub_body_gen.cc
idlc/gen_cion/cpp_cion_stub_body_gen_cb.h

index a0319cb..1e4346e 100644 (file)
@@ -742,6 +742,24 @@ void CppCionGeneratorBase::GenHeaderCallback(std::ofstream& stream,
       .Out(stream);
 }
 
+std::string CppCionGeneratorBase::GenSecurity(const Interface& iface) {
+  std::string security_path;
+
+  for (const auto& attr : iface.GetAttributes()) {
+    if (attr->GetKey() == "ca_path")
+      security_path += ReplaceAll(CB_INTERFACE_SECURITY_CA, "<ARG>",
+          attr->GetValue());
+    else if (attr->GetKey() == "cert_path")
+      security_path += ReplaceAll(CB_INTERFACE_SECURITY_CERT, "<ARG>",
+          attr->GetValue());
+    else if (attr->GetKey() == "private_key")
+      security_path += ReplaceAll(CB_INTERFACE_SECURITY_PRIVATE_KEY, "<ARG>",
+          attr->GetValue());
+  }
+
+  return security_path;
+}
+
 void CppCionGeneratorBase::GenVersion(std::ofstream& stream) {
   GenTemplate(CB_VERSION, stream,
     [&]()->std::string {
index 38f3c21..b7570fe 100644 (file)
@@ -49,6 +49,7 @@ class CppCionGeneratorBase : public Generator {
                         bool is_proxy);
   void GenHeaderCallbacks(std::ofstream& stream, const Interface& iface,
                           bool is_proxy);
+  std::string GenSecurity(const Interface& iface);
   std::string ConvertTypeToString(const BaseType& type);
   std::string Tab(int cnt);
   std::string NLine(int cnt);
index d6043c9..fa946be 100644 (file)
@@ -290,6 +290,30 @@ $$
 }
 )__cpp_cb";
 
+const char CB_INTERFACE_SECURITY_CA[] =
+R"__cpp_cb(
+  if (cion_security_set_ca_path(security, "<ARG>") != CION_ERROR_NONE) {
+    _E("Failed to set ca path.");
+    throw InvalidIOException();
+  }
+)__cpp_cb";
+
+const char CB_INTERFACE_SECURITY_CERT[] =
+R"__cpp_cb(
+  if (cion_security_set_cert_path(security, "<ARG>") != CION_ERROR_NONE) {
+    _E("Failed to set cert path.");
+    throw InvalidIOException();
+  }
+)__cpp_cb";
+
+const char CB_INTERFACE_SECURITY_PRIVATE_KEY[] =
+R"__cpp_cb(
+  if (cion_security_set_private_key_path(security, "<ARG>") != CION_ERROR_NONE) {
+    _E("Failed to set private key path.");
+    throw InvalidIOException();
+  }
+)__cpp_cb";
+
 const char CB_LOG_TAG[] =
 R"__cpp_cb(
 #ifdef LOG_TAG
index 51ab1ee..8bd51f2 100644 (file)
@@ -90,8 +90,10 @@ void CppCionGroupBodyGen::GenInterface(std::ofstream& stream,
 
 void CppCionGroupBodyGen::GenConstructor(std::ofstream& stream,
     const Interface& iface) {
-  stream << ReplaceAll(CB_GROUP_INTERFACE_CTOR, "<CLS_NAME>", iface.GetID())
-         << NLine(1);
+  ReplaceAll(CB_GROUP_INTERFACE_CTOR)
+      .Change("<CLS_NAME>", iface.GetID())
+      .Change("<SET_SECURITY>", GenSecurity(iface))
+      .Out(stream);
 }
 
 void CppCionGroupBodyGen::GenDestructor(std::ofstream& stream,
index 5450595..adf535b 100644 (file)
@@ -137,10 +137,11 @@ R"__cpp_cb(
     _E("Failed to create security handle. error(%d)", ret);
     throw InvalidIOException();
   }
+
   auto security_auto = std::unique_ptr<
       std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
           security, cion_security_destroy);
-
+<SET_SECURITY>
   cion_group_h group = nullptr;
   ret = cion_group_create(&group, topic_name_.c_str(), security);
   if (ret != CION_ERROR_NONE) {
index 05dd623..1be3e02 100644 (file)
@@ -92,13 +92,10 @@ void CppCionProxyBodyGen::GenInterface(std::ofstream& stream,
 
 void CppCionProxyBodyGen::GenConstructor(std::ofstream& stream,
                                      const Interface& iface) {
-  GenTemplate(CB_PROXY_INTERFACE_CTOR, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    },
-    [&]()->std::string {
-      return iface.GetID();
-    });
+  ReplaceAll(CB_PROXY_INTERFACE_CTOR)
+      .Change("$$", iface.GetID())
+      .Change("<SET_SECURITY>", GenSecurity(iface))
+      .Out(stream);
 }
 
 void CppCionProxyBodyGen::GenDestructor(std::ofstream& stream,
index 54cd1ca..84df8bc 100644 (file)
@@ -355,10 +355,11 @@ $$::$$(IEventListener* listener, const std::string& service_name,
     _E("Failed to create security handle. error(%d)", ret);
     throw InvalidIOException();
   }
+
   auto security_auto = std::unique_ptr<
       std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
           security, cion_security_destroy);
-
+<SET_SECURITY>
   cion_client_h client = nullptr;
   ret = cion_client_create(&client, service_name.c_str(), security);
   if (ret != CION_ERROR_NONE) {
index 925926e..2d10b92 100644 (file)
@@ -102,7 +102,10 @@ void CppCionStubBodyGen::GenServiceBase(std::ofstream& stream,
 
 void CppCionStubBodyGen::GenConstructor(std::ofstream& stream,
                                     const Interface& iface) {
-  stream << ReplaceAll(CB_CTOR_FRONT, "##", iface.GetID());
+  ReplaceAll(CB_CTOR_FRONT)
+      .Change("##", iface.GetID())
+      .Change("<SET_SECURITY>", GenSecurity(iface))
+      .Out(stream);
 }
 
 void CppCionStubBodyGen::GenDefaultMethods(std::ofstream& stream,
index 00b5b94..b6c6712 100644 (file)
@@ -26,10 +26,11 @@ R"__cpp_cb(
     _E("Failed to create security handle. error(%d)", ret);
     throw InvalidIOException();
   }
+
   auto security_auto = std::unique_ptr<
       std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
           security, cion_security_destroy);
-
+<SET_SECURITY>
   cion_server_h server;
   ret = cion_server_create(&server, service_name.c_str(),
       display_name.c_str(), security);