3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <sync_agent.h>
27 #define EXPORT_API __attribute__ ((visibility("default")))
30 #ifndef OMADM_AGENT_LOG
32 #define LOG_TAG "PLUGIN_DEVDETAIL"
37 #define CSC_VCONF_KEY_SYNCMLDM_NBFIELD "db/SyncML/oma-dm-service/DevManagement/NbDevManagement"
38 #define CSC_VCONF_KEY_SYNCMLDM_ACCNAME "db/SyncML/oma-dm-service/DevManagement/%d/AccName"
39 #define CSC_VCONF_KEY_SYNCMLDM_SERVID "db/SyncML/oma-dm-service/DevManagement/%d/ServID"
41 #define ALTER_SYNCMLDM_NBFIELD 3
43 #define ALTER_SYNCMLDM_ACCNAME_1 "MSCTestserver"
44 #define ALTER_SYNCMLDM_ACCNAME_2 "MSCServer"
45 #define ALTER_SYNCMLDM_ACCNAME_3 "gcf"
48 #define MAX_DEPTH "100"
49 #define MAX_SEG_LEN "100"
50 #define MAX_TOTAL_LEN "1000"
52 static sync_agent_get_devinfo_cb pfunc_get_dev_info = 0;
54 //static int _get_index(const char *name);
55 //static char *_get_mo_value_str(const char *vconf_key, int n_index);
57 EXPORT_API char **sync_agent_plugin_get_server_id_list(int *server_id_list_cnt)
61 *server_id_list_cnt = 0;
62 char **temp_id_list = (char **)calloc(SERVER_NUM, sizeof(char *));
63 if (temp_id_list == NULL) {
73 for (i = 0; i < SERVER_NUM; i++) {
77 sever_name = ALTER_SYNCMLDM_ACCNAME_1;
80 sever_name = ALTER_SYNCMLDM_ACCNAME_2;
83 sever_name = ALTER_SYNCMLDM_ACCNAME_3;
90 server_idx = _get_index(sever_name);
91 server_id = _get_mo_value_str(CSC_VCONF_KEY_SYNCMLDM_SERVID, server_idx);
92 if (server_id != NULL) {
93 _DEBUG_INFO("Temp_id_list[%d] = %s\n", i, server_id);
94 temp_id_list[i] = server_id;
95 (*server_id_list_cnt)++;
98 _DEBUG_INFO("server_id_list_cnt = %d\n", *server_id_list_cnt);
103 *server_id_list_cnt = 1;
104 char **temp_id_list = (char **)calloc(SERVER_NUM, sizeof(char *));
105 if (temp_id_list == NULL) {
109 char *server_id = NULL;
110 server_id = strdup("*");
111 *temp_id_list = server_id;
113 _DEBUG_INFO("devdetail server_id = %s\n", server_id);
114 _DEBUG_INFO("devdetail server_id_list_cnt = %d\n", *server_id_list_cnt);
120 EXPORT_API int sync_agent_plugin_get_mo_value(const char *mo_pull_path, const char *mo_name, char **mo_value)
124 retvm_if((mo_pull_path) == NULL, -1, "mo_pull_path is NULL!!");
125 retvm_if((mo_name) == NULL, -1, "mo_name is NULL!!");
127 _DEBUG_INFO("mo_name : %s", mo_name);
130 if (!strcmp(mo_name, "DevTyp")) {
131 if (pfunc_get_dev_info == NULL) {
135 pfunc_get_dev_info(2, "DevTyp", mo_value);
136 } else if (!strcmp(mo_name, "Bearer")) {
137 if (pfunc_get_dev_info == NULL) {
141 pfunc_get_dev_info(2, "Bearer", mo_value);
142 } else if (!strcmp(mo_name, "OEM")) {
143 if (pfunc_get_dev_info == NULL) {
147 pfunc_get_dev_info(2, "OEM", mo_value);
148 } else if (!strcmp(mo_name, "FwV")) {
149 if (pfunc_get_dev_info == NULL) {
153 pfunc_get_dev_info(2, "FwV", mo_value);
154 } else if (!strcmp(mo_name, "SwV")) {
155 if (pfunc_get_dev_info == NULL) {
159 pfunc_get_dev_info(2, "SwV", mo_value);
160 } else if (!strcmp(mo_name, "HwV")) {
161 if (pfunc_get_dev_info == NULL) {
165 pfunc_get_dev_info(2, "HwV", mo_value);
166 } else if (!strcmp(mo_name, "LrgObj")) {
167 *mo_value = strdup("0");
168 } else if (!strcmp(mo_name, "MaxDepth")) {
169 *mo_value = strdup(MAX_DEPTH);
170 } else if (!strcmp(mo_name, "MaxTotLen")) {
171 *mo_value = strdup(MAX_TOTAL_LEN);
172 } else if (!strcmp(mo_name, "MaxSegLen")) {
173 *mo_value = strdup(MAX_SEG_LEN);
176 _DEBUG_INFO("mo_value : %s", *mo_value);
183 EXPORT_API void sync_agent_plugin_set_function_get_devinfo(sync_agent_get_devinfo_cb func)
187 pfunc_get_dev_info = func;
193 static int _get_index(const char *name)
197 retvm_if((name) == NULL, -1, "name is NULL!!");
200 if (vconf_get_int(CSC_VCONF_KEY_SYNCMLDM_NBFIELD, &acc_count)) {
201 _DEBUG_TRACE("vconf_get_int FAIL");
203 acc_count =ALTER_SYNCMLDM_NBFIELD;
206 _DEBUG_TRACE("acc_count : %d", acc_count);
209 for (; i < acc_count; i++) {
210 char *compare_name = _get_mo_value_str(CSC_VCONF_KEY_SYNCMLDM_ACCNAME, i + 1);
211 if (compare_name != NULL) {
212 _DEBUG_TRACE("[%d] compare_name : %s [%d], name : %s [%d]", i, compare_name, strlen(compare_name), name, strlen(name));
213 if (!strcmp(name, compare_name)) {
214 _DEBUG_TRACE("nIndex : %d", i + 1);
225 static char *_get_mo_value_str(const char *vconf_key, int n_index)
229 retvm_if((vconf_key) == NULL, NULL, "vconf_key is NULL!!");
235 char input_vconf_path[200] = { 0, };
238 memset(cRecIdx, 0x0, sizeof(cRecIdx));
239 snprintf(cRecIdx, sizeof(cRecIdx), "%d", n_index);
240 snprintf(input_vconf_path, strlen(vconf_key) + strlen(cRecIdx) + 1, vconf_key, n_index);
242 char *value = vconf_get_str(input_vconf_path);
244 _DEBUG_TRACE("vconf_get_str FAIL");