Add stub implementation of libcynara-admin API functions
[platform/core/security/cynara.git] / src / admin / api / admin-api.cpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16 /*
17  * @file        admin-api.cpp
18  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19  * @version     1.0
20  * @brief       Implementation of external libcynara-admin API
21  */
22
23 #include <new>
24
25 #include <common.h>
26 #include <cynara-admin.h>
27
28 #include <api/ApiInterface.h>
29 #include <logic/Logic.h>
30
31 struct cynara_admin {
32     Cynara::ApiInterface *impl;
33
34     cynara_admin(Cynara::ApiInterface *_impl) : impl(_impl) {
35     }
36     ~cynara_admin() {
37         delete impl;
38     }
39 };
40
41 CYNARA_API
42 int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) {
43     if (!pp_cynara_admin)
44         return CYNARA_ADMIN_API_INVALID_PARAM;
45
46     try {
47         *pp_cynara_admin = new cynara_admin(new Cynara::Logic);
48     } catch (const std::bad_alloc &ex) {
49         return CYNARA_ADMIN_API_OUT_OF_MEMORY;
50     }
51
52     return CYNARA_ADMIN_API_SUCCESS;
53 }
54
55 CYNARA_API
56 int cynara_admin_finish(struct cynara_admin *p_cynara_admin) {
57     delete p_cynara_admin;
58
59     return CYNARA_ADMIN_API_SUCCESS;
60 }
61
62 CYNARA_API
63 int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin,
64                               const cynara_admin_policy *const *policies) {
65     if (!p_cynara_admin || !p_cynara_admin->impl)
66         return CYNARA_ADMIN_API_INVALID_PARAM;
67     if (!policies)
68         return CYNARA_ADMIN_API_INVALID_PARAM;
69
70     //todo This is a stub. Parameters should be passed to p_cynara_admin->impl
71     return CYNARA_ADMIN_API_SUCCESS;
72 }
73
74 CYNARA_API
75 int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *bucket,
76                             int operation, const char *extra UNUSED) {
77     if (!p_cynara_admin || !p_cynara_admin->impl)
78         return CYNARA_ADMIN_API_INVALID_PARAM;
79     if (!bucket)
80         return CYNARA_ADMIN_API_INVALID_PARAM;
81     switch (operation) {
82         case CYNARA_ADMIN_DELETE:
83             //todo This is a stub. Parameters should be passed to p_cynara_admin->impl
84             return CYNARA_ADMIN_API_SUCCESS;
85         case CYNARA_ADMIN_DENY:
86         case CYNARA_ADMIN_ALLOW:
87             //todo This is a stub. Parameters should be passed to p_cynara_admin->impl
88             return CYNARA_ADMIN_API_SUCCESS;
89         case CYNARA_ADMIN_BUCKET:
90         default:
91             return CYNARA_ADMIN_API_INVALID_PARAM;
92     }
93 }