Add 3.0 APIs and sync APIs same as 2.4
[platform/core/convergence/service-adaptor.git] / adaptor / auth-adaptor / oauth2_service.c
1 /*
2  * oAuth 2.0 Service
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 file 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 <glib.h>
22
23 #include <app.h>
24
25 #include "oauth2_service.h"
26 #include "auth_adaptor.h"
27 #include "service_adaptor_errors.h"
28 #include "service_adaptor_internal.h"
29
30 #include "sal_auth_provider.h"
31
32 //******************************************************************************
33 //* Global variables and defines
34 //******************************************************************************
35
36 typedef struct _app_control_user_data_s
37 {
38         void *callback;
39         void *user_data;
40 } app_control_user_data_s;
41 typedef struct _app_control_user_data_s *app_control_user_data_h;
42
43 typedef int (*_get_access_token)(void *plugin, char **access_token, void *user_data);
44 typedef int (*_get_extra_data)(void *plugin, const char *key, char **value, void *user_data);
45
46 //******************************************************************************
47 //* Private interface
48 //******************************************************************************
49
50 //******************************************************************************
51 //* Private interface definition
52 //******************************************************************************
53
54 static int _oauth2_get_access_token(auth_plugin_h plugin, char **access_token, void *user_data)
55 {
56         SAL_FN_CALL;
57
58         RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
59
60         return SERVICE_ADAPTOR_ERROR_NONE;
61 }
62
63 static int _oauth2_get_extra_data(auth_plugin_h plugin, const char *key, char **value, void *user_data)
64 {
65         SAL_FN_CALL;
66
67         RETV_IF(NULL == plugin, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
68
69         return SERVICE_ADAPTOR_ERROR_NONE;
70 }
71
72 //******************************************************************************
73 //* Public interface definition
74 //******************************************************************************
75
76 API int oauth2_register_service(oauth2_service_h oauth2, GHashTable *service)
77 {
78         SAL_FN_CALL;
79
80         RETV_IF(NULL == oauth2, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
81
82         int ret = SERVICE_ADAPTOR_ERROR_NO_DATA;
83         GHashTableIter iter;
84         gpointer iter_key, iter_value;
85
86         g_hash_table_iter_init(&iter, service);
87         while (g_hash_table_iter_next(&iter, &iter_key, &iter_value))
88         {
89                 if (0 == strcmp(iter_key, OAUTH2_0_GET_ACCESS_TOKEN_URI))
90                 {
91                         oauth2->oauth2_get_access_token = (_get_access_token) _oauth2_get_access_token;
92                         ret = SERVICE_ADAPTOR_ERROR_NONE;
93                 }
94                 else if (0 == strcmp(iter_key, OAUTH2_0_GET_EXTRA_DATA_URI))
95                 {
96                         oauth2->oauth2_get_extra_data = (_get_extra_data) _oauth2_get_extra_data;
97                         ret = SERVICE_ADAPTOR_ERROR_NONE;
98                 }
99         }
100
101         return ret;
102 }
103
104 API int oauth2_unregister_service(oauth2_service_h oauth2)
105 {
106         SAL_FN_CALL;
107
108         RETV_IF(NULL == oauth2, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
109
110         oauth2->oauth2_get_access_token = NULL;
111         oauth2->oauth2_get_extra_data = NULL;
112
113         return SERVICE_ADAPTOR_ERROR_NONE;
114 }