Add 3.0 APIs and sync APIs same as 2.4
[platform/core/convergence/service-adaptor.git] / client / sal_service_auth.c
1 /*
2  * Auth Adaptor Client
3  *
4  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this oauth1 except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <glib.h>
23
24 #include <app.h>
25
26 #include "service_adaptor_errors.h"
27 #include "service_adaptor_internal.h"
28 #include "sal_service_adaptor.h"
29 #include "sal_service_adaptor_internal.h"
30 #include "sal_service_task.h"
31 #include "sal_service_task_internal.h"
32 #include "sal_service_auth.h"
33 #include "sal_service_auth_internal.h"
34 #include "sal_ipc_client_auth.h"
35
36 //******************************************************************************
37 //* Global variables and defines
38 //******************************************************************************
39
40 //******************************************************************************
41 //* Private interface
42 //******************************************************************************
43
44 //******************************************************************************
45 //* Private interface definition
46 //******************************************************************************
47
48 int service_auth_oauth1_start(service_auth_oauth1_h oauth1)
49 {
50         SAL_FN_CALL;
51
52         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
53         RETV_IF(NULL == oauth1->plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
54
55         int ret = SERVICE_ADAPTOR_ERROR_NONE;
56         char *uri = NULL;
57
58         ret = service_plugin_get_uri(oauth1->plugin, &uri);
59         RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "service_plugin_get_uri() Failed(%d)", ret);
60
61         service_auth_oauth1_h auth_oauth1 = NULL;
62         ret = ipc_service_auth_oauth1(uri, oauth1, &auth_oauth1);
63         RETVM_IF(SERVICE_ADAPTOR_ERROR_NONE != ret, ret, "ipc_service_auth_oauth1() Failed(%d)", ret);
64
65         RETV_IF(NULL == oauth1->callback, SERVICE_ADAPTOR_ERROR_NONE);
66
67         oauth1->callback(SERVICE_ADAPTOR_ERROR_NONE, auth_oauth1, oauth1->user_data);
68
69         return SERVICE_ADAPTOR_ERROR_NONE;
70 }
71
72 int service_auth_oauth1_stop(service_auth_oauth1_h oauth1)
73 {
74         SAL_FN_CALL;
75
76         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
77
78         return SERVICE_ADAPTOR_ERROR_NONE;
79 }
80
81 //******************************************************************************
82 //* Public interface definition
83 //******************************************************************************
84
85 API int service_auth_oauth1_create(service_plugin_h plugin, service_auth_oauth1_h *oauth1)
86 {
87         SAL_FN_CALL;
88
89         RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
90         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
91
92         service_auth_oauth1_h auth_oauth1 = (service_auth_oauth1_h) g_malloc0(sizeof(service_auth_oauth1_s));
93         auth_oauth1->plugin = plugin;
94
95         *oauth1 = auth_oauth1;
96
97         return SERVICE_ADAPTOR_ERROR_NONE;
98 }
99
100 API int service_auth_oauth1_oauth1_clone(service_auth_oauth1_h src_oauth1, service_auth_oauth1_h *dst_oauth1)
101 {
102         SAL_FN_CALL;
103
104         RETV_IF(NULL == src_oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
105         RETV_IF(NULL == dst_oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
106
107         service_auth_oauth1_h auth_oauth1 = (service_auth_oauth1_h) g_malloc0(sizeof(service_auth_oauth1_s));
108         auth_oauth1->plugin = src_oauth1->plugin;
109         auth_oauth1->callback = src_oauth1->callback;
110         auth_oauth1->access_token = strdup(src_oauth1->access_token);
111         auth_oauth1->operation = strdup(src_oauth1->operation);
112
113         *dst_oauth1 = auth_oauth1;
114
115         return SERVICE_ADAPTOR_ERROR_NONE;
116 }
117
118 API int service_auth_oauth1_oauth1_destroy(service_auth_oauth1_h oauth1)
119 {
120         SAL_FN_CALL;
121
122         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
123
124         SAL_FREE(oauth1->access_token);
125         SAL_FREE(oauth1->operation);
126         SAL_FREE(oauth1);
127
128         return SERVICE_ADAPTOR_ERROR_NONE;
129 }
130
131 API int service_auth_oauth1_set_callback(service_auth_oauth1_h oauth1, service_auth_oauth1_cb callback, void *user_data)
132 {
133         SAL_FN_CALL;
134
135         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
136         RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
137
138         oauth1->callback = callback;
139         oauth1->user_data = user_data;
140
141         return SERVICE_ADAPTOR_ERROR_NONE;
142 }
143
144 API int service_auth_oauth1_unset_callback(service_auth_oauth1_h oauth1)
145 {
146         SAL_FN_CALL;
147
148         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
149
150         oauth1->callback = NULL;
151         oauth1->user_data = NULL;
152
153         return SERVICE_ADAPTOR_ERROR_NONE;
154 }
155
156 API int service_auth_oauth1_set_access_token(service_auth_oauth1_h oauth1, const char *access_token)
157 {
158         SAL_FN_CALL;
159
160         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
161         RETV_IF(NULL == access_token, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
162
163         oauth1->access_token = strdup(access_token);
164
165         return SERVICE_ADAPTOR_ERROR_NONE;
166 }
167
168 API int service_auth_oauth1_get_access_token(service_auth_oauth1_h oauth1, char **access_token)
169 {
170         SAL_FN_CALL;
171
172         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
173         RETV_IF(NULL == access_token, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
174
175         *access_token = strdup(oauth1->access_token);
176
177         return SERVICE_ADAPTOR_ERROR_NONE;
178 }
179
180 API int service_auth_oauth1_set_operation(service_auth_oauth1_h oauth1, const char *operation)
181 {
182         SAL_FN_CALL;
183
184         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
185         RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
186
187         oauth1->operation = strdup(operation);
188
189         return SERVICE_ADAPTOR_ERROR_NONE;
190 }
191
192 API int service_auth_oauth1_get_operation(service_auth_oauth1_h oauth1, char **operation)
193 {
194         SAL_FN_CALL;
195
196         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
197         RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
198
199         *operation = strdup(oauth1->operation);
200
201         return SERVICE_ADAPTOR_ERROR_NONE;
202 }
203
204 API int service_auth_oauth1_create_task(service_auth_oauth1_h oauth1, service_task_h *task)
205 {
206         SAL_FN_CALL;
207
208         RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
209         RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
210
211         service_task_h service_task = (service_task_h) g_malloc0(sizeof(service_task_s));
212         service_task->oauth1 = oauth1;
213
214         *task = service_task;
215
216         return SERVICE_ADAPTOR_ERROR_NONE;
217 }
218
219 API int service_auth_oauth1_destroy_task(service_task_h task)
220 {
221         SAL_FN_CALL;
222
223         RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
224
225         SAL_FREE(task);
226
227         return SERVICE_ADAPTOR_ERROR_NONE;
228 }