--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TT_DAEMON_HTTP_H__
+#define __TT_DAEMON_HTTP_H__
+
+int ttd_http_init(void);
+int ttd_http_fini(void);
+int ttd_http_get_cloud_cmd(const char *url, char **cmd_json);
+int ttd_http_post_cmd_result(const char *url, const char *result_json);
+
+#endif /* __TT_DAEMON_HTTP_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <curl/curl.h>
+#include <glib.h>
+#include "ttd-log.h"
+
+#define CERT_FILE_PATH "/opt/share/cert-svc/ca-certificate.crt"
+
+int ttd_http_init(void)
+{
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+ return 0;
+}
+
+int ttd_http_fini(void)
+{
+ curl_global_cleanup();
+ return 0;
+}
+
+static size_t _get_cmd_write(void *ptr, size_t size, size_t nmemb, void *data)
+{
+ size_t res_size = 0;
+ char **received = data;
+
+ res_size = size * nmemb;
+
+ if (received && res_size > 0)
+ *received = g_strndup((const char *)ptr, res_size);
+ else
+ _E("fail to get response [res size : %d]", res_size);
+
+ return res_size;
+}
+
+int ttd_http_get_cloud_cmd(const char *url, char **cmd_json)
+{
+ int ret = 0;
+ CURL *curl = NULL;
+ CURLcode res = CURLE_OK;
+
+ retvm_if(!url, -1, "url is null");
+ retvm_if(!cmd_json, -1, "cmd_json is null");
+
+ curl = curl_easy_init();
+
+ retvm_if(!curl, NULL, "failed to curl_easy_init()");
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_CAPATH, CERT_FILE_PATH);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _get_cmd_write);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)cmd_json);
+
+ res = curl_easy_perform(curl);
+ if (res != CURLE_OK) {
+ _E("curl_easy_perform() failed: %s", curl_easy_strerror(res));
+ ret = -1;
+ }
+ _D("received cmd : %s", *cmd_json ? *cmd_json : "NULL");
+
+ curl_easy_cleanup(curl);
+
+ return ret;
+}
+
+int ttd_http_post_cmd_result(const char *url, const char *result_json)
+{
+ int ret = 0;
+ CURL *curl = NULL;
+ CURLcode res = CURLE_OK;
+ struct curl_slist *headers = NULL;
+
+ retvm_if(!url, -1, "url is null");
+ retvm_if(!result_json, -1, "result_json is null");
+
+ curl = curl_easy_init();
+
+ retvm_if(!curl, NULL, "failed to curl_easy_init()");
+
+ headers = curl_slist_append(headers, "Accept: application/json");
+ headers = curl_slist_append(headers, "Content-Type: application/json");
+
+ /* TODO : what should I do before post result */
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_CAPATH, CERT_FILE_PATH);
+ curl_easy_setopt(curl, CURLOPT_POST, 1L);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, result_json);
+
+ res = curl_easy_perform(curl);
+ if (res != CURLE_OK) {
+ _E("curl_easy_perform() failed: %s", curl_easy_strerror(res));
+ ret = -1;
+ }
+
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+
+ return ret;
+}