diff options
author | Jeonghoon Park <jh1979.park@samsung.com> | 2018-06-21 16:22:35 +0900 |
---|---|---|
committer | Jeonghoon Park <jh1979.park@samsung.com> | 2018-06-21 17:38:14 +0900 |
commit | 416fcca7e109a55b6c8fde4e21e62abfabc1e900 (patch) | |
tree | 5c973549f80dfef3ac0ff378b5bab68d9479e095 | |
parent | c7696f5ab5b6056cef7d9efb696d4e5e7475c29f (diff) | |
download | tizen-things-daemon-416fcca7e109a55b6c8fde4e21e62abfabc1e900.tar.gz tizen-things-daemon-416fcca7e109a55b6c8fde4e21e62abfabc1e900.tar.bz2 tizen-things-daemon-416fcca7e109a55b6c8fde4e21e62abfabc1e900.zip |
apply data API url based on project name
Change-Id: I4c7a2f8ac9ec0297adbb21b2477009682452837d
-rw-r--r-- | daemon/include/ttd-http.h | 3 | ||||
-rw-r--r-- | daemon/include/ttd-url.h | 1 | ||||
-rw-r--r-- | daemon/src/ttd-app-interface.c | 11 | ||||
-rw-r--r-- | daemon/src/ttd-http.c | 24 | ||||
-rw-r--r-- | daemon/src/ttd-url.c | 26 |
5 files changed, 47 insertions, 18 deletions
diff --git a/daemon/include/ttd-http.h b/daemon/include/ttd-http.h index bf1b98c..5f95b7e 100644 --- a/daemon/include/ttd-http.h +++ b/daemon/include/ttd-http.h @@ -21,6 +21,7 @@ int ttd_http_init(void); int ttd_http_fini(void); int ttd_http_command_get(char **cmd_json, long *res_code); int ttd_http_report_post(const char *result_json, long *res_code); -int ttd_http_appdata_post(const char *url, const char *data, long *res_code); +int ttd_http_appdata_post( + const char *project, const char *data, long *res_code); #endif /* __TT_DAEMON_HTTP_H__ */ diff --git a/daemon/include/ttd-url.h b/daemon/include/ttd-url.h index 07f5d01..1b8b8bd 100644 --- a/daemon/include/ttd-url.h +++ b/daemon/include/ttd-url.h @@ -20,6 +20,7 @@ typedef enum { TTD_URL_CMD = 0, TTD_URL_REPORT, + TTD_URL_DATA, TTD_URL_TYPE_NUM } ttd_url_type_e; diff --git a/daemon/src/ttd-app-interface.c b/daemon/src/ttd-app-interface.c index 39a4a97..9257f07 100644 --- a/daemon/src/ttd-app-interface.c +++ b/daemon/src/ttd-app-interface.c @@ -578,6 +578,7 @@ static gpointer post_thread(gpointer user_data) while (TRUE) { ttd_app_data *app_data = NULL; int ret = 0; + long res_code = 0; app_data = g_async_queue_pop(handle->data_queue); if (!app_data) @@ -587,14 +588,8 @@ static gpointer post_thread(gpointer user_data) _D("receiving queue_quit_marker"); break; } -#if 0 /* Enable it if API url for posting data is created */ - /* TODO : get API url for posting data to replace POST_DATA_URL */ - long res_code = 0; - char *url = NULL; - /* TODO : get url based on project name */ - url = __get_projcet_url(ttd_app_data_get_project_name(app_data)); - ret = ttd_http_appdata_post(url, + ret = ttd_http_appdata_post(ttd_app_data_get_project_name(app_data), ttd_app_data_get_data(app_data), &res_code); if (!ret) { _E("failed to post data, retry it - code[%ld]", res_code); @@ -603,7 +598,7 @@ static gpointer post_thread(gpointer user_data) /* 0.5 sec sleep before retry it */ continue; } -#endif + _D("msg posted : %s", ttd_app_data_get_data(app_data)); ttd_app_data_free(app_data); } diff --git a/daemon/src/ttd-http.c b/daemon/src/ttd-http.c index f81b68f..ea7f298 100644 --- a/daemon/src/ttd-http.c +++ b/daemon/src/ttd-http.c @@ -226,6 +226,8 @@ int ttd_http_report_post(const char *result_json, long *res_code) struct curl_slist *headers = NULL; const char *url = NULL; + retvm_if(!result_json, -1, "result_json is NULL"); + url = __get_url_by_type(TTD_URL_REPORT); retvm_if(!url, -1, "failed to get url for command POST"); @@ -238,13 +240,31 @@ int ttd_http_report_post(const char *result_json, long *res_code) return __ttd_http_post(url, result_json, headers, res_code); } -int ttd_http_appdata_post(const char *url, const char *data, long *res_code) +int ttd_http_appdata_post( + const char *project, const char *data_json, long *res_code) { struct curl_slist *headers = NULL; + const char *url = NULL; + char *p_url = NULL; + int ret = 0; + + retvm_if(!project, -1, "project is NULL"); + retvm_if(!data_json, -1, "data_json is NULL"); + + url = __get_url_by_type(TTD_URL_DATA); + retvm_if(!url, -1, "failed to get url for DATA"); + + p_url = g_strdup_printf("%s%s", url, project); + retvm_if(!p_url, -1, "failed to create url for project"); + + _D("[%s] : %s", project, data_json); headers = curl_slist_append(headers, "Accept: application/json"); headers = curl_slist_append(headers, "Content-Type: application/json"); /* add here http headers to set new one */ - return __ttd_http_post(url, data, headers, res_code); + ret = __ttd_http_post(p_url, data_json, headers, res_code); + g_free(p_url); + + return ret; } diff --git a/daemon/src/ttd-url.c b/daemon/src/ttd-url.c index 7059d77..21a2508 100644 --- a/daemon/src/ttd-url.c +++ b/daemon/src/ttd-url.c @@ -23,6 +23,7 @@ #define CONF_URL_KEY_ADDRESS "server" #define CONF_URL_KEY_CMD "api_cmd" #define CONF_URL_KEY_REPORT "api_report" +#define CONF_URL_KEY_DATA "api_data" #define QUERY_KEY_DEVICE_ID "deviceId=" #define QUERY_KEY_STATE "state=" @@ -49,6 +50,15 @@ static char *__ttd_url_get_device_id(void) return device_id; } +static char *__ttd_url_get_by_key(const char *key) +{ + char *url = NULL; + retv_if(!key, NULL); + + ttd_config_read_string(CONF_URL_GROUP_NAME, key, &url); + return url; +} + static char *_ttd_url_get_cmd(void) { char *cmd_api = NULL; @@ -58,7 +68,7 @@ static char *_ttd_url_get_cmd(void) device_id = __ttd_url_get_device_id(); retv_if(!device_id, NULL); - ttd_config_read_string(CONF_URL_GROUP_NAME, CONF_URL_KEY_CMD, &cmd_api); + cmd_api = __ttd_url_get_by_key(CONF_URL_KEY_CMD); goto_if(!cmd_api, DONE_N_FREE); cmd_url = g_strdup_printf("%s?&%s%s&%s%d", cmd_api, @@ -77,13 +87,12 @@ DONE_N_FREE: static char *_ttd_url_get_report(void) { - char *report_url = NULL; - - ttd_config_read_string(CONF_URL_GROUP_NAME, - CONF_URL_KEY_REPORT, &report_url); - retv_if(!report_url, NULL); + return __ttd_url_get_by_key(CONF_URL_KEY_REPORT); +} - return report_url; +static char *_ttd_url_get_data(void) +{ + return __ttd_url_get_by_key(CONF_URL_KEY_DATA); } char *ttd_url_get_by_type(ttd_url_type_e type) @@ -102,6 +111,9 @@ char *ttd_url_get_by_type(ttd_url_type_e type) case TTD_URL_REPORT: url_postfix = _ttd_url_get_report(); break; + case TTD_URL_DATA: + url_postfix = _ttd_url_get_data(); + break; case TTD_URL_TYPE_NUM: default: _E("not supported type : %d", type); |