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"
26 #define QUERY_KEY_DEVICE_ID "deviceId="
27 #define QUERY_KEY_STATE "state="
28 #define QUERY_PARAM_STATE "created"
31 #define TEST_DEVICE_ID "test-page-device"
33 static char *__ttd_url_get_address(void)
35 char *url_address = NULL;
37 ttd_config_read_string(CONF_URL_GROUP_NAME,
38 CONF_URL_KEY_ADDRESS, &url_address);
42 static char *__ttd_url_get_device_id(void)
44 char *device_id = NULL;
46 /* TODO : get device id */
47 g_strdup(TEST_DEVICE_ID);
51 static char *_ttd_url_get_cmd(void)
54 char *device_id = NULL;
57 device_id = __ttd_url_get_device_id();
58 retv_if(!device_id, NULL);
60 ttd_config_read_string(CONF_URL_GROUP_NAME, CONF_URL_KEY_CMD, &cmd_api);
61 goto_if(!cmd_api, DONE_N_FREE);
63 cmd_url = g_strdup_printf("%s?&%s%s&%s%s", cmd_api,
64 QUERY_KEY_DEVICE_ID, device_id,
65 QUERY_KEY_STATE, QUERY_PARAM_STATE);
68 _D("cmd url - %s", cmd_url);
70 _E("failed to create cmd_url");
79 static char *_ttd_url_get_report(void)
81 char *report_url = NULL;
83 ttd_config_read_string(CONF_URL_GROUP_NAME,
84 CONF_URL_KEY_REPORT, &report_url);
85 retv_if(!report_url, NULL);
87 _D("report url - %s", report_url);
92 char *ttd_url_get_by_type(ttd_url_type_e type)
94 char *url_addr = NULL;
95 char *url_postfix = NULL;
98 url_addr = __ttd_url_get_address();
99 retv_if(!url_addr, NULL);
103 url_postfix = _ttd_url_get_cmd();
106 url_postfix = _ttd_url_get_report();
111 url = g_strdup_printf("%s%s", url_addr, url_postfix);
112 _D("url[%d] - %s", type, url);