4 * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
36 //******************************************************************************
37 //* Global variables and defines
38 //******************************************************************************
40 //******************************************************************************
42 //******************************************************************************
44 //******************************************************************************
45 //* Private interface definition
46 //******************************************************************************
48 int service_auth_oauth1_start(service_auth_oauth1_h oauth1)
52 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
53 RETV_IF(NULL == oauth1->plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
55 int ret = SERVICE_ADAPTOR_ERROR_NONE;
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);
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);
65 RETV_IF(NULL == oauth1->callback, SERVICE_ADAPTOR_ERROR_NONE);
67 oauth1->callback(SERVICE_ADAPTOR_ERROR_NONE, auth_oauth1, oauth1->user_data);
69 return SERVICE_ADAPTOR_ERROR_NONE;
72 int service_auth_oauth1_stop(service_auth_oauth1_h oauth1)
76 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
78 return SERVICE_ADAPTOR_ERROR_NONE;
81 //******************************************************************************
82 //* Public interface definition
83 //******************************************************************************
85 API int service_auth_oauth1_create(service_plugin_h plugin, service_auth_oauth1_h *oauth1)
89 RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
90 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
92 service_auth_oauth1_h auth_oauth1 = (service_auth_oauth1_h) g_malloc0(sizeof(service_auth_oauth1_s));
93 auth_oauth1->plugin = plugin;
95 *oauth1 = auth_oauth1;
97 return SERVICE_ADAPTOR_ERROR_NONE;
100 API int service_auth_oauth1_oauth1_clone(service_auth_oauth1_h src_oauth1, service_auth_oauth1_h *dst_oauth1)
104 RETV_IF(NULL == src_oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
105 RETV_IF(NULL == dst_oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
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);
113 *dst_oauth1 = auth_oauth1;
115 return SERVICE_ADAPTOR_ERROR_NONE;
118 API int service_auth_oauth1_oauth1_destroy(service_auth_oauth1_h oauth1)
122 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
124 SAL_FREE(oauth1->access_token);
125 SAL_FREE(oauth1->operation);
128 return SERVICE_ADAPTOR_ERROR_NONE;
131 API int service_auth_oauth1_set_callback(service_auth_oauth1_h oauth1, service_auth_oauth1_cb callback, void *user_data)
135 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
136 RETV_IF(NULL == callback, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
138 oauth1->callback = callback;
139 oauth1->user_data = user_data;
141 return SERVICE_ADAPTOR_ERROR_NONE;
144 API int service_auth_oauth1_unset_callback(service_auth_oauth1_h oauth1)
148 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
150 oauth1->callback = NULL;
151 oauth1->user_data = NULL;
153 return SERVICE_ADAPTOR_ERROR_NONE;
156 API int service_auth_oauth1_set_access_token(service_auth_oauth1_h oauth1, const char *access_token)
160 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
161 RETV_IF(NULL == access_token, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
163 oauth1->access_token = strdup(access_token);
165 return SERVICE_ADAPTOR_ERROR_NONE;
168 API int service_auth_oauth1_get_access_token(service_auth_oauth1_h oauth1, char **access_token)
172 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
173 RETV_IF(NULL == access_token, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
175 *access_token = strdup(oauth1->access_token);
177 return SERVICE_ADAPTOR_ERROR_NONE;
180 API int service_auth_oauth1_set_operation(service_auth_oauth1_h oauth1, const char *operation)
184 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
185 RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
187 oauth1->operation = strdup(operation);
189 return SERVICE_ADAPTOR_ERROR_NONE;
192 API int service_auth_oauth1_get_operation(service_auth_oauth1_h oauth1, char **operation)
196 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
197 RETV_IF(NULL == operation, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
199 *operation = strdup(oauth1->operation);
201 return SERVICE_ADAPTOR_ERROR_NONE;
204 API int service_auth_oauth1_create_task(service_auth_oauth1_h oauth1, service_task_h *task)
208 RETV_IF(NULL == oauth1, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
209 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
211 service_task_h service_task = (service_task_h) g_malloc0(sizeof(service_task_s));
212 service_task->oauth1 = oauth1;
214 *task = service_task;
216 return SERVICE_ADAPTOR_ERROR_NONE;
219 API int service_auth_oauth1_destroy_task(service_task_h task)
223 RETV_IF(NULL == task, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
227 return SERVICE_ADAPTOR_ERROR_NONE;