2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "ttd-config.h"
22 #define CONF_URL_GROUP_NAME "url"
23 #define CONF_URL_KEY_ADDRESS "server"
24 #define CONF_URL_KEY_CMD "api_cmd"
25 #define CONF_URL_KEY_REPORT "api_report"
27 #define QUERY_KEY_DEVICE_ID "deviceId="
28 #define QUERY_KEY_STATE "state="
29 #define QUERY_PARAM_STATE 0
31 /* for test - TO BE Removed */
32 #define TEST_DEVICE_ID "test-page-device"
34 static char *__ttd_url_get_address(void)
36 char *url_address = NULL;
38 ttd_config_read_string(CONF_URL_GROUP_NAME,
39 CONF_URL_KEY_ADDRESS, &url_address);
43 static char *__ttd_url_get_device_id(void)
45 char *device_id = NULL;
47 /* TODO : get device id */
48 device_id = g_strdup(TEST_DEVICE_ID);
52 static char *_ttd_url_get_cmd(void)
55 char *device_id = NULL;
58 device_id = __ttd_url_get_device_id();
59 retv_if(!device_id, NULL);
61 ttd_config_read_string(CONF_URL_GROUP_NAME, CONF_URL_KEY_CMD, &cmd_api);
62 goto_if(!cmd_api, DONE_N_FREE);
64 cmd_url = g_strdup_printf("%s?&%s%s&%s%d", cmd_api,
65 QUERY_KEY_DEVICE_ID, device_id,
66 QUERY_KEY_STATE, QUERY_PARAM_STATE);
69 _E("failed to create cmd_url");
78 static char *_ttd_url_get_report(void)
80 char *report_url = NULL;
82 ttd_config_read_string(CONF_URL_GROUP_NAME,
83 CONF_URL_KEY_REPORT, &report_url);
84 retv_if(!report_url, NULL);
89 char *ttd_url_get_by_type(ttd_url_type_e type)
91 char *url_addr = NULL;
92 char *url_postfix = NULL;
95 url_addr = __ttd_url_get_address();
96 retv_if(!url_addr, NULL);
100 url_postfix = _ttd_url_get_cmd();
103 url_postfix = _ttd_url_get_report();
105 case TTD_URL_TYPE_NUM:
107 _E("not supported type : %d", type);
112 url = g_strdup_printf("%s%s", url_addr, url_postfix);
113 _D("url[%d] - %s", type, url);