Initialize Tizen 2.3
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / bootstrap / factory_bootstrap.c
1 /*
2  * oma-dm-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*sync-agent*/
19 #include <sync_agent.h>
20
21 /*dm-agent*/
22 #include "common/dm_common.h"
23 #include "mo-handler/dm_mo_handler.h"
24 #include "mo-handler/dm_mo_common.h"
25 #include "dm-engine/bootstrap/factory_bootstrap.h"
26
27 #ifndef OMADM_AGENT_LOG
28 #undef LOG_TAG
29 #define LOG_TAG "OMA_DM_BOOTSTRAP"
30 #endif
31
32 static DM_ERROR _completed_bootstrap();
33 static DM_ERROR _start_ddf_mo(GSList * seg_list);
34
35 static DM_ERROR _completed_bootstrap()
36 {
37         _INNER_FUNC_ENTER;
38
39         DM_ERROR ret = DM_OK;
40         ENGINE_STATUS status = DM_IDLE;
41
42         ret = Update_Engine_Status_Column(IDLE_ENGINE, VALUE_ENGINE_STATUS, &status);
43         _DEBUG_TRACE("update engine status : %d", ret);
44         if (ret != DM_OK)
45                 goto error;
46
47         _INNER_FUNC_EXIT;
48         return ret;
49  error:
50         _DEBUG_TRACE(" end!! error : %d \n", ret);
51         _INNER_FUNC_EXIT;
52         return ret;
53 }
54
55 static DM_ERROR _start_ddf_mo(GSList * seg_list)
56 {
57         _INNER_FUNC_ENTER;
58
59         DM_ERROR ret = DM_OK;
60
61         GSList *ddf_iter = NULL;
62         sync_agent_dm_mo_error_e err_code;
63         ddf_spec *ddf_content;
64
65         retvm_if((seg_list) == NULL, COMMON_ERR_IS_NULL, "seg_list is NULL!!");
66
67         for (ddf_iter = seg_list; ddf_iter != NULL; ddf_iter = g_slist_next(ddf_iter)) {
68                 ddf_content = (ddf_spec *) (ddf_iter->data);
69
70                 _DEBUG_TRACE(" mo_type : %d schema : %s sevice_ddf : %d server_type : %d\n", ddf_content->mo_type, ddf_content->schema_file, ddf_content->service_ddf, ddf_content->server_type);
71                 err_code = sync_agent_construct_mo_table(ddf_content->mo_type, ddf_content->schema_file, ddf_content->service_ddf, ddf_content->server_type);
72
73                 if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
74                         _DEBUG_TRACE("Success to sync_agent_construct_mo_table()\n");
75                 } else {
76                         _DEBUG_TRACE("Failed to sync_agent_construct_mo_table()\n");
77                         ret = DM_ERR_DDF_PROCCESS;
78                         goto error;
79                 }
80         }
81
82         _INNER_FUNC_EXIT;
83         return ret;
84  error:
85         _DEBUG_TRACE(" end!! error : %d \n", ret);
86         _INNER_FUNC_EXIT;
87         return ret;
88 }
89
90 DM_ERROR factory_bootstrap(SERVICE_SERVER_TYPE server_type)
91 {
92         _INNER_FUNC_EXIT;
93
94         DM_ERROR ret = DM_OK;
95
96         /*dm acc */
97         //pre_define_mo();
98
99         /*change css value for test */
100         int file_ret = 0;
101         char *file_path = NULL;
102         unsigned long required_length = 0;
103         char *required_contents = NULL;
104         int is_exist = 0;
105
106         _DEBUG_INFO("server_type : [%d]", server_type);
107
108         switch (server_type) {
109         case SAMSUNG_FUMO_TYPE:
110                 {
111                         ret = is_exist_dmacc(SAMSUNG_FUMO_TYPE, &is_exist);
112                         if (ret != DM_OK) {
113                                 _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
114                                 goto error;
115                         }
116                         if (is_exist == 1) {
117                                 ret = remove_dm_acc(DM_DMACC_MSCTESTSERVER);
118                                 if (ret != DM_OK) {
119                                         _DEBUG_VERBOSE("remove dm acc error :%d", ret);
120                                         goto error;
121                                 } else {
122                                         _DEBUG_VERBOSE("remove fumo dm acc");
123                                 }
124                         } else {
125                                 _DEBUG_VERBOSE("samsung fumo dm acc");
126                         }
127
128                         file_path = DDF_MSCFUMO_DMACC_FILE;
129                 }
130                 break;
131         case SAMSUNG_FMM_TYPE:
132                 {
133                         ret = is_exist_dmacc(SAMSUNG_FMM_TYPE, &is_exist);
134                         if (ret != DM_OK) {
135                                 _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
136                                 goto error;
137                         }
138                         if (is_exist == 1) {
139                                 ret = remove_dm_acc(DM_DMACC_MSCSERVER);
140                                 if (ret != DM_OK) {
141                                         _DEBUG_VERBOSE("remove dm acc error :%d", ret);
142                                         goto error;
143                                 } else {
144                                         _DEBUG_VERBOSE("remove fumo dm acc");
145                                 }
146                         } else {
147                                 _DEBUG_VERBOSE("samsung fmm dm acc");
148                         }
149
150                         file_path = DDF_MSCLAWMO_DMACC_FILE;
151                 }
152                 break;
153         case GCF_TYPE:
154                 {
155                         ret = is_exist_dmacc(GCF_TYPE, &is_exist);
156                         if (ret != DM_OK) {
157                                 _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
158                                 goto error;
159                         }
160                         if (is_exist == 1) {
161                                 ret = remove_dm_acc(DM_DMACC_MSCSERVER);
162                                 if (ret != DM_OK) {
163                                         _DEBUG_VERBOSE("remove dm acc error :%d", ret);
164                                         goto error;
165                                 } else {
166                                         _DEBUG_VERBOSE("remove fumo dm acc");
167                                 }
168                         } else {
169                                 _DEBUG_VERBOSE("product dm acc");
170                         }
171                         file_path = DDF_GCF_DMACC_FILE;
172                 }
173                 break;
174         default:
175                 {
176                         file_path = DDF_FILES;
177                         _DEBUG_INFO("the first factory bootstrap");
178                 }
179                 break;
180         }
181
182         file_ret = sync_agent_read_whole_file(file_path, &required_contents, &required_length);
183         if (file_ret != 1) {
184                 ret = DM_ERR_DDF_PROCCESS;
185                 goto error;
186         }
187         _DEBUG_INFO(" file read is %d, required_length is %d \n", ret, required_length);
188
189         GSList *seg_list = NULL;
190         char *check_segment = NULL;
191         ddf_spec ddf_contents[DDF_SPEC_COUNT] = { {0}, };
192         int i = 0;
193         if (required_contents != NULL) {
194                 check_segment = strtok(required_contents, "\n");
195                 _DEBUG_INFO(" check_segment : %s\n", check_segment);
196         } else {
197                 ret = DM_ERR_DDF_PROCCESS;
198                 goto error;
199         }
200
201         if (check_segment != NULL) {
202                 sscanf(check_segment, "%d %s %d %d", (int *)(&(ddf_contents[i].mo_type)), (ddf_contents[i].schema_file), &(ddf_contents[i].service_ddf), &(ddf_contents[i].server_type));
203                 seg_list = g_slist_append(seg_list, &(ddf_contents[i]));
204
205                 _DEBUG_INFO(" mo_type: %d\n", ddf_contents[i].mo_type);
206                 _DEBUG_INFO(" schema_file : %s\n", ddf_contents[i].schema_file);
207                 _DEBUG_INFO(" service_ddf : %d\n", ddf_contents[i].service_ddf);
208                 _DEBUG_INFO(" server_type : %d\n", ddf_contents[i].server_type);
209                 ++i;
210
211                 while (check_segment != NULL) {
212                         check_segment = strtok(NULL, "\n");
213                         if (check_segment == NULL)
214                                 break;
215                         _DEBUG_INFO(" check_segment : %s\n", check_segment);
216
217                         sscanf(check_segment, "%d %s %d %d", (int *)(&(ddf_contents[i].mo_type)), (ddf_contents[i].schema_file), &(ddf_contents[i].service_ddf), &(ddf_contents[i].server_type));
218                         seg_list = g_slist_append(seg_list, &(ddf_contents[i]));
219
220                         _DEBUG_INFO(" mo_type: %d\n", ddf_contents[i].mo_type);
221                         _DEBUG_INFO(" schema_file : %s\n", ddf_contents[i].schema_file);
222                         _DEBUG_INFO(" service_ddf : %d\n", ddf_contents[i].service_ddf);
223                         _DEBUG_INFO(" server_type : %d\n", ddf_contents[i].server_type);
224                         ++i;
225                 }
226
227                 ret = _start_ddf_mo(seg_list);
228                 if (ret != DM_OK)
229                         goto error;
230
231                 file_ret = sync_agent_free_file(&required_contents);
232                 required_contents = NULL;
233                 if (file_ret != 1) {
234                         ret = DM_ERR_DDF_PROCCESS;
235                         goto error;
236                 }
237
238                 ret = _completed_bootstrap();
239                 if (ret != DM_OK) {
240                         goto error;
241                 }
242
243         } else {
244                 ret = DM_ERR_DDF_PROCCESS;
245                 goto error;
246         }
247
248         _EXTERN_FUNC_EXIT;
249
250         return ret;
251  error:
252
253         file_ret = sync_agent_free_file(&required_contents);
254         if (file_ret != 1) {
255                 ret = DM_ERR_DDF_PROCCESS;
256         }
257
258         _DEBUG_INFO(" end!! error : %d \n", ret);
259         _EXTERN_FUNC_EXIT;
260         return ret;
261
262 }
263
264 /*
265 void    ddf_parser() {
266
267         sync_agent_dm_mo_type_e mo_type_devdetail = SYNC_AGENT_DM_MO_TYPE_DEVDETAIL;
268         sync_agent_dm_mo_type_e mo_type_devinfo = SYNC_AGENT_DM_MO_TYPE_DEVINFO;
269         sync_agent_dm_mo_type_e mo_type_fumo = SYNC_AGENT_DM_MO_TYPE_FUMO;
270         sync_agent_dm_mo_type_e mo_type_gcf = SYNC_AGENT_DM_MO_TYPE_DMACC;
271         sync_agent_dm_mo_type_e mo_type_mscserver = SYNC_AGENT_DM_MO_TYPE_DMACC;
272         sync_agent_dm_mo_type_e mo_type_msctestserver = SYNC_AGENT_DM_MO_TYPE_DMACC;
273
274         const char *schema_file_devdetail = "/usr/share/oma-dm/ddf/slp/slp_DEVDETAIL_DDF.xml";
275         const char *schema_file_devinfo = "/usr/share/oma-dm/ddf/slp/slp_DEVINF_DDF.xml";
276         const char *schema_file_fumo = "/usr/share/oma-dm/ddf/slp/slp_FUMO_DDF.xml";
277         const char *schema_file_gcf = "/usr/share/oma-dm/ddf/slp/slp_gcf_DMACC_DDF_1.2.xml";
278         const char *schema_file_mscserver = "/usr/share/oma-dm/ddf/slp/slp_MSCserver_DMACC_DDF_1.2.xml";
279         const char *schema_file_msctestserver = "/usr/share/oma-dm/ddf/slp/slp_MSCTestserver_DMACC_DDF_1.2.xml";
280
281         sync_agent_dm_mo_error_e err_code = sync_agent_construct_mo_table(mo_type_devdetail, schema_file_devdetail , "devdetail");
282         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
283                 _DEBUG_INFO("Success to sync_agent_construct_mo_table()\n");
284         } else {
285                 _DEBUG_INFO("Failed to sync_agent_construct_mo_table()\n");
286         }
287
288         err_code = sync_agent_construct_mo_table(mo_type_devinfo, schema_file_devinfo , "devinf");
289         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
290                 _DEBUG_INFO("Success to sync_agent_construct_mo_table()\n");
291         } else {
292                 _DEBUG_INFO("Failed to sync_agent_construct_mo_table()\n");
293         }
294
295         err_code = sync_agent_construct_mo_table(mo_type_fumo, schema_file_fumo , "fumo");
296         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
297                 _DEBUG_INFO("Success to sync_agent_construct_mo_table()\n");
298         } else {
299                 _DEBUG_INFO("Failed to sync_agent_construct_mo_table()\n");
300         }
301                 err_code = sync_agent_construct_mo_table(mo_type_gcf, schema_file_gcf , "dmacc_gcf");
302         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
303                 _DEBUG_INFO("Success to sync_agent_construct_mo_table()\n");
304         } else {
305                 _DEBUG_INFO("Failed to sync_agent_construct_mo_table()\n");
306         }
307         err_code = sync_agent_construct_mo_table(mo_type_mscserver, schema_file_mscserver , "dmacc_MSCserver");
308         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
309                 _DEBUG_INFO("Success to sync_agent_construct_mo_table()\n");
310         } else {
311                 _DEBUG_INFO("Failed to sync_agent_construct_mo_table()\n");
312         }
313         err_code = sync_agent_construct_mo_table(mo_type_msctestserver, schema_file_msctestserver , "dmacc_MSCTestserver");
314         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
315                 _DEBUG_INFO("Success to sync_agent_construct_mo_table()\n");
316         } else {
317                 _DEBUG_INFO("Failed to sync_agent_construct_mo_table()\n");
318         }
319 */