CKMC API: Add option to list aliases with information about password protection
[platform/core/security/key-manager.git] / src / manager / client / client-common.h
index 93a1ce3..032f2f9 100644 (file)
@@ -1,7 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Contact: Bumjin Im <bj.im@samsung.com>
+ *  Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  * @file        client-common.h
  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
  * @version     1.0
- * @brief       This file constains implementation of common types
+ * @brief       This file contains implementation of common types
  *              used in Central Key Manager.
  */
 
 #ifndef _KEY_MANAGER_CLIENT_
 #define _KEY_MANAGER_CLIENT_
 
+#include <unistd.h>
+
 #include <vector>
 #include <functional>
 
+#include <noncopyable.h>
+#include <ckm/ckm-type.h>
+#include <ckmc/ckmc-error.h>
 #include <message-buffer.h>
+#include <protocols.h>
 
-#define KEY_MANAGER_API __attribute__((visibility("default")))
+#define EXCEPTION_GUARD_START_CPPAPI return CKM::try_catch([&]()->int {
+#define EXCEPTION_GUARD_START_CAPI   return CKM::try_catch_enclosure([&]()->int {
+#define EXCEPTION_GUARD_END          });
 
 extern "C" {
-    struct msghdr;
+       struct msghdr;
+
+       struct ckmc_alias_info_s {
+               char* alias;
+               bool is_password_protected;
+       };
+
 }
 
 namespace CKM {
 
-int sendToServer(char const * const interface, const SafeBuffer &send, MessageBuffer &recv);
+class AliasSupport {
+public:
+       AliasSupport(const Alias &alias);
+
+       const ClientId &getOwner() const;
+       const Name &getName() const;
+       bool isOwnerEmpty() const;
+
+       static Alias merge(const ClientId &owner, const Name &alias);
+
+private:
+       Name m_name;
+       ClientId m_owner;
+};
+
+class SockRAII {
+public:
+       SockRAII();
+
+       NONCOPYABLE(SockRAII);
+
+       virtual ~SockRAII();
+
+       int connect(const char *interface);
+       void disconnect();
+       bool isConnected() const;
+       int get() const;
+       int waitForSocket(int event, int timeout);
+
+protected:
+       int connectWrapper(int socket, const char *interface);
+       int m_sock;
+};
+
+class ServiceConnection {
+public:
+       ServiceConnection(const char *service_interface);
+
+       // roundtrip: send and receive
+       int processRequest(const CKM::RawBuffer &send_buf,
+                                          CKM::MessageBuffer &recv_buf);
+
+       // blocking
+       int send(const CKM::RawBuffer &send_buf);
+       int receive(CKM::MessageBuffer &recv_buf);
+
+       virtual ~ServiceConnection();
+
+protected:
+       int prepareConnection();
+
+       SockRAII m_socket;
+       std::string m_serviceInterface;
+};
 
 /*
  * Decorator function that performs frequently repeated exception handling in
  * SS client API functions. Accepts lambda expression as an argument.
  */
-int try_catch(const std::function<int()>& func);
+// for c++ api layer
+int try_catch(const std::function<int()> &func);
+// for c api layer
+int try_catch_enclosure(const std::function<int()> &func);
+
+// for c++ async api layer
+void try_catch_async(const std::function<void()> &func,
+                                        const std::function<void(int)> &error);
 
 } // namespace CKM