Integration with CryptoService class.
[platform/core/security/key-manager.git] / src / manager / client / client-echo.cpp
1 /* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
2  *
3  *  Licensed under the Apache License, Version 2.0 (the "License");
4  *  you may not use this file except in compliance with the License.
5  *  You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  *  Unless required by applicable law or agreed to in writing, software
10  *  distributed under the License is distributed on an "AS IS" BASIS,
11  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  *  See the License for the specific language governing permissions and
13  *  limitations under the License
14  *
15  *
16  * @file        client-echo.cpp
17  * @author      Zofia Abramowska (z.abramowska@samsung.com)
18  * @version     1.0
19  * @brief       This file contains example of key-manager client implementation
20  */
21
22 #include <dpl/log/log.h>
23 #include <dpl/exception.h>
24
25 #include <message-buffer.h>
26 #include <client-common.h>
27 #include <protocols.h>
28
29 #include <ckm/ckm-error.h>
30
31 KEY_MANAGER_API
32 int key_manager_echo(const char *echo, char** oche) {
33     using namespace CKM;
34
35     if(echo == NULL){
36         LogDebug("Echo message is null");
37         return KEY_MANAGER_API_ERROR_INPUT_PARAM;
38     }
39
40     MessageBuffer send, recv;
41     Serialization::Serialize(send, std::string(echo));
42
43     int retCode = sendToServer(SERVICE_SOCKET_ECHO, send.Pop(), recv);
44
45     if(retCode != KEY_MANAGER_API_SUCCESS)
46         return retCode;
47
48     std::string response;
49     Deserialization::Deserialize(recv, response);
50
51     *oche = strdup(response.c_str());
52
53     return KEY_MANAGER_API_SUCCESS;
54 }