*/
#include <stdbool.h>
#include <gio/gio.h>
+#include <app_control.h>
#ifdef __cplusplus
extern "C" {
int send_request(char *appid, char *operation, char *json,
hello_cb user_cb, void* user_data);
+int send_request_with_app_reply(char *appid, char *operation, char *json,
+ app_control_reply_cb reply_cb, void* user_data);
+
+
+
int proxy_send_command(const char *bus_name, const char *bus_obj, const char *bus_if,
int cmd_type, GVariant *cmd_param, GVariant **cmd_ret);
--- /dev/null
+#ifndef _HTTP_UTIL_H_
+#define _HTTP_UTIL_H_
+
+/**
+ * This header file is included to define _EXPORT_.
+ */
+#include <curl/curl.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ HTTP_GET = 0,
+ HTTP_POST,
+ HTTP_PUT,
+ HTTP_DELETE
+} http_req_e;
+
+typedef struct curl_slist curl_slist;
+
+int http_send_request(http_req_e type, char *req_url, curl_slist *header, char *json,
+ char **res_header, char **res_body);
+int http_download_file(const char *download_url, const char *download_path);
+
+#ifdef __cplusplus
+}
+#endif
+#endif // _HTTP_UTIL_H_
+
typedef enum ERROR_CODE {
SSE_ERROR_NONE = 0,
SSE_ERROR_APP_CONTROL,
+ SSE_ERROR_OTHER_MODULE,
SSE_ERROR_NULL_PTR,
SSE_ERROR_MEM_ALLOC,
SSE_ERROR_NOT_SUPPORTED,
} while (0)
#define ERROR_LOG(fmt, ...) do { \
- dlog_print(DLOG_INFO, LOG_TAG, "%s : %s(%d) > "fmt, rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__,##__VA_ARGS__);\
+ dlog_print(DLOG_ERROR, LOG_TAG, "%s : %s(%d) > "fmt, rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__,##__VA_ARGS__);\
} while (0)
int send_request(char *appid, char *operation, char *json,
hello_cb user_cb, void* user_data)
{
+ DEBUG_LOG("enter");
if (!appid || !operation) {
ERROR_LOG("uri NULL[%p], operation NULL[%p]", appid, operation);
return SSE_ERROR_NULL_PTR; //temp:error_code NULL
}
+int send_request_with_app_reply(char *appid, char *operation, char *json,
+ app_control_reply_cb reply_cb, void* user_data)
+{
+ DEBUG_LOG("enter");
+ if (!appid || !operation) {
+ ERROR_LOG("uri NULL[%p], operation NULL[%p]", appid, operation);
+ return SSE_ERROR_NULL_PTR; //temp:error_code NULL
+ }
+
+ int ret = 0; //temp:error_code sucess
+ app_control_h request = NULL;
+ if ((ret = app_control_create(&request)) != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_create error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ goto out;
+ }
+ if ((ret=app_control_set_app_id(request, appid)) != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_set_app_id error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ goto out;
+ }
+ if ((ret=app_control_set_operation(request, operation)) != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_set_operation error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ goto out;
+ }
+
+ ret = app_control_send_launch_request(request, reply_cb, (void*)user_data);
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_send_launch_request error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ }
+
+out:
+ app_control_destroy(request);
+ return ret;
+}
+
#if 0
#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
-#include <curl/curl.h>
#include <glib.h>
-//#include "staticlibrary.h"
-//#include <fmwup_resource_internal.h>
+#include "http_util.h"
+#include <dlog.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "SSE_HTTP"
-typedef enum {
- FMWUP_HTTP_GET = 0,
- FMWUP_HTTP_POST,
- FMWUP_HTTP_PUT,
- FMWUP_HTTP_DELETE
-} fmwup_http_req_e;
-
+#define ERROR_LOG(fmt, ...) do { \
+ dlog_print(DLOG_ERROR, LOG_TAG, "%s : %s(%d) > "fmt,\
+ rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__,##__VA_ARGS__);\
+ } while (0)
static size_t _gather_data(void *downloaded_data,
size_t size,
}
-static void _curl_set_request_headers(CURL *curl)
+static void _curl_set_request_headers(CURL *curl, curl_slist *header)
{
- struct curl_slist *header = NULL;
-
- char *tmp_header = NULL;
-
- tmp_header = g_strconcat("Content-Type: ", "application/json", NULL);
- //LOG("header=[%s]", tmp_header);
- header = curl_slist_append(header, tmp_header);
- g_free(tmp_header);
-
+ if (!header) {
+ char *tmp_header = NULL;
+ tmp_header = g_strconcat("Content-Type: ", "application/json", NULL);
+ header = curl_slist_append(header, tmp_header);
+ g_free(tmp_header);
+ }
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
}
-int http_send_request(fmwup_http_req_e type, char *req_url, char **res_header, char **res_body)
+int http_send_request(http_req_e type, char *req_url, curl_slist *header, char *json,
+ char **res_header, char **res_body)
{
//LOG("Enter http_send_request()");
//LOG("curl_easy_init()");
- _curl_set_request_headers(curl);
+ _curl_set_request_headers(curl, header);
- if (type == FMWUP_HTTP_GET) {
+ if (type == HTTP_GET) {
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
- } else if (type == FMWUP_HTTP_POST) {
+ } else if (type == HTTP_POST) {
curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
} else {
return -1;
if (error_code == CURLE_ABORTED_BY_CALLBACK) {
ret = -1;
+ ERROR_LOG("curl_easy_perform(curl) error with %s (%d)", curl_easy_strerror(error_code), error_code);
goto _END_OF_FUNC_;
} else if (error_code != CURLE_OK) {
ret = -1;
+ ERROR_LOG("curl_easy_perform(curl) error with %s (%d)", curl_easy_strerror(error_code), error_code);
goto _END_OF_FUNC_;
}
return 1;
}
+
+int register_service(char *appid, int server_id)
+{
+
+ return 0;
+}
+
+
#if 0
#include <gio/gio.h>