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);
-int ttd_http_post_data(const char *url, const char *data);
+int ttd_http_get_cloud_cmd(const char *url, char **cmd_json, long *res_code);
+int ttd_http_post_cmd_result(
+ const char *url, const char *result_json, long *res_code);
+int ttd_http_post_data(const char *url, const char *data, long *res_code);
#endif /* __TT_DAEMON_HTTP_H__ */
#ifndef SERVER_URL
/* TODO : remove it after test */
-#define TEST_SERVER_URL "http://apitest.showiot.xyz/api/cmd?&target=test-page-device&owner=test-page&state=created"
+#define TEST_SERVER_URL "http://test.showiot.xyz/api/cmd?&target=test-page-device&owner=test-page&state=created"
#define SERVER_URL TEST_SERVER_URL
#endif
{
int ret = 0;
char *cmd = NULL;
+ long res_code = 0;
- ret = ttd_http_get_cloud_cmd(__ttd_get_cloud_url(), &cmd);
-
- retvm_if(ret, -1, "failed to get cmd");
+ ret = ttd_http_get_cloud_cmd(__ttd_get_cloud_url(), &cmd, &res_code);
+ retvm_if(ret, -1, "failed to get cmd [%ld]", res_code);
if (cmd) {
GList *cmd_list = NULL;
return res_size;
}
-int ttd_http_get_cloud_cmd(const char *url, char **cmd_json)
+int ttd_http_get_cloud_cmd(const char *url, char **cmd_json, long *res_code)
{
int ret = 0;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
+ long r_code = 0;
retvm_if(!http_initialized, -1, "http is not initialized yet");
retvm_if(!url, -1, "url is null");
g_free(*cmd_json);
ret = -1;
}
- _D("received cmd : %s", *cmd_json ? *cmd_json : "NULL");
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r_code);
+ if (res_code)
+ *res_code = r_code;
+
+ _D("received code[%ld], cmd : %s", r_code, *cmd_json ? *cmd_json : "NULL");
curl_easy_cleanup(curl);
}
static int __ttd_http_post(const char *url,
- const char *msg_body, struct curl_slist *headers)
+ const char *msg_body, struct curl_slist *headers, long *res_code)
{
int ret = 0;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
+ long r_code = 0;
retvm_if(!http_initialized, -1, "http is not initialized yet");
retvm_if(!url, -1, "url is null");
_E("curl_easy_perform() failed: %s", curl_easy_strerror(res));
ret = -1;
}
+
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &r_code);
+ if (res_code)
+ *res_code = r_code;
+
if (headers)
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return ret;
}
-int ttd_http_post_cmd_result(const char *url, const char *result_json)
+int ttd_http_post_cmd_result(
+ const char *url, const char *result_json, long *res_code)
{
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
/* add here http headers to set new one */
- return __ttd_http_post(url, result_json, headers);
+ return __ttd_http_post(url, result_json, headers, res_code);
}
-int ttd_http_post_data(const char *url, const char *data)
+int ttd_http_post_data(const char *url, const char *data, long *res_code)
{
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
/* add here http headers to set new one */
- return __ttd_http_post(url, data, headers);
+ return __ttd_http_post(url, data, headers, res_code);
}