upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / ServiceEngine / SE_AutoConfig.c
1 /*
2  * oma-ds-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHak Park <juhaki.park@samsung.com>,
7  *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8  *          SunBong Ha <sunbong.ha@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24
25
26
27 /*
28  * For any sort of issue you concern as to this software,
29  * you may use following point of contact.
30  * All resources contributed on this software
31  * are orinigally written by S-Core Inc., a member of Samsung Group.
32  *
33  * SeongWon Shim <seongwon.shim@samsung.com>
34  */
35
36 /**
37  *   @SE_AutoConfig.c
38  *   @version                                                                   0.1
39  *   @brief                                                                             This file is the source file of implementation of auto configure in Service Engine
40  */
41
42 #include "agent-framework/Utility/fw_log.h"
43 #include "ServiceEngine/SE_AutoConfig.h"
44 #include "ServiceEngine/SE_Common.h"
45 #include "ServiceEngine/SE_Error.h"
46 #include "ServiceEngine/SE_Sync.h"
47 #include "ServiceEngine/SE_Notification.h"
48 #include "Common/Common_Vconf.h"
49 #include "Common/Common_Define.h"
50 #include "ServiceAdapter/SA_Common_Interface.h"
51
52 #define LOG_TAG "OMA_DS_SE"
53
54 bool autoconfigure_from_vconf(char *profile)
55 {
56         FW_LOGV("start");
57
58         SE_ErrorType err = SE_INTERNAL_OK;
59
60         char profilePath[128];
61         char *email = NULL;
62         char *password = NULL;
63         char *serverIP = NULL;
64
65         SyncProgress process = PROGRESS_NONE;
66         SyncError error = ERROR_NONE ;
67
68         if (!profile) {
69                 FW_LOGE("Not Defined profile");
70                 err = SE_INTERNAL_NOT_DEFINED;
71                 goto free;
72         }
73
74         sprintf(profilePath, "%s/%s", DS_SETTINGS_PATH, profile);
75
76         email = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHNAME);
77         if (email == NULL) {
78                 FW_LOGE("email is NULL");
79                 err = SE_INTERNAL_DA_ERROR;
80                 goto error;
81         }
82
83         password = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHPWD);
84         if (password == NULL) {
85                 FW_LOGE("password is NULL");
86                 err = SE_INTERNAL_DA_ERROR;
87                 goto error;
88         }
89
90         serverIP = get_vconf_str(profilePath, DS_SETTING_ADDR);
91         if (serverIP == NULL) {
92                 FW_LOGE("serverIP is NULL");
93                 err = SE_INTERNAL_DA_ERROR;
94                 goto error;
95         }
96
97         GList *configure = NULL;
98         Common_ErrorType common_err = auto_configure_from_vconf(email, password, serverIP, profilePath, &configure);
99
100         if (common_err != COMMON_CANCEL) {
101
102                 convert_common_errorcode(common_err, &process, &error);
103
104                 if (common_err == COMMON_OK) {
105                         err = send_noti_auto_configure(profile, configure);
106                         if (err  != SE_INTERNAL_OK) {
107                                 FW_LOGE("failed in send_noti_auto_configure");
108                                 goto error;
109                         }
110                 } else
111                         err = SE_INTERNAL_SA_ERROR;
112
113                 err = session_process(profile, process, error);
114                 if (err  != SE_INTERNAL_OK) {
115                         FW_LOGE("failed in send_noti_auto_configure");
116                         goto error;
117                 }
118         } else
119                 err = SE_INTERNAL_CANCEL;
120
121         FW_LOGV("end");
122
123         goto free;
124
125 error:
126
127         convert_engine_errorcode(err, &process, &error);
128         session_process(profile, process, error);
129
130 free:
131
132         if (email)
133                 free(email);
134         if (password)
135                 free(password);
136         if (serverIP)
137                 free(serverIP);
138
139         GList *iter = NULL;
140         GList *inIter = NULL;
141         for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
142
143                 inIter = iter->data;
144                 for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter))
145                         free(inIter->data);
146                 g_list_free(inIter);
147         }
148
149         g_list_free(configure);
150
151         if (err != SE_INTERNAL_OK)
152                 return false;
153         else
154                 return true;
155 }
156
157 bool autoconfigure(char *profildDirName, char *addr, char *id, char *password)
158 {
159         FW_LOGV("start");
160
161         SE_ErrorType err = SE_INTERNAL_OK;
162
163         SyncProgress process = PROGRESS_NONE;
164         SyncError error = ERROR_NONE ;
165
166         GList *configure = NULL;
167         GList *iter = NULL;
168         GList *inIter = NULL;
169
170         Common_ErrorType common_err = auto_configure(addr, id, password, &configure);
171
172         if (common_err != COMMON_CANCEL) {
173
174                 convert_common_errorcode(common_err, &process, &error);
175
176                 if (common_err == COMMON_OK) {
177                         err = send_noti_auto_configure(profildDirName, configure);
178                         if (err  != SE_INTERNAL_OK) {
179                                 FW_LOGE("failed in send_noti_auto_configure");
180                                 goto error;
181                         }
182                 } else
183                         err = SE_INTERNAL_SA_ERROR;
184
185                 err = session_process(profildDirName, process, error);
186                 if (err  != SE_INTERNAL_OK) {
187                         FW_LOGE("failed in send_noti_auto_configure");
188                         goto error;
189                 }
190         } else
191                 err = SE_INTERNAL_CANCEL;
192
193         FW_LOGV("end");
194
195         goto free;
196
197 error:
198
199         convert_engine_errorcode(err, &process, &error);
200         session_process(profildDirName, process, error);
201
202 free:
203
204         for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
205
206                 inIter = iter->data;
207                 for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter))
208                         free(inIter->data);
209                 g_list_free(inIter);
210         }
211
212         g_list_free(configure);
213
214         if (err != SE_INTERNAL_OK)
215                 return false;
216         else
217                 return true;
218 }