samsung account activation logic added 53/165653/1 devel/tizen_service_enabler_lib
authorSang-Hun Chung <sanghun.chung@samsung.com>
Wed, 3 Jan 2018 05:49:32 +0000 (14:49 +0900)
committerSang-Hun Chung <sanghun.chung@samsung.com>
Wed, 3 Jan 2018 05:49:32 +0000 (14:49 +0900)
Change-Id: I559a3ef39db4bf0e60bcc6c775aea30f9a7b1e4c

inc/agent_util.h
inc/http_util.h [new file with mode: 0755]
inc/service_agent_lib.h
src/agent_util.c
src/http_util.c
src/service_agent_lib.c

index 548d05a1604f35400cc6b695229bc4df73bc62a6..cd0a157770a8f9babf76ccedd4cd377cb49aca4d 100755 (executable)
@@ -6,6 +6,7 @@
  */
 #include <stdbool.h>
 #include <gio/gio.h>
+#include <app_control.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -14,6 +15,11 @@ 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);
diff --git a/inc/http_util.h b/inc/http_util.h
new file mode 100755 (executable)
index 0000000..7e2bec8
--- /dev/null
@@ -0,0 +1,30 @@
+#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_
+
index eb1718cb97487600bf08cca21d27803aaf68f051..20e8aff788a57283ccd1baac71aed5b6804b6a94 100755 (executable)
@@ -25,6 +25,7 @@ int get_name_by_id(int id, char** name);
 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,
index 1a4a5aa5e8651a4651cc8a0e6f162caac6caa0b5..ab212b475aa8a3dada96849c681ce83e2a133a04 100755 (executable)
@@ -14,7 +14,7 @@
        } 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)
 
 
@@ -47,6 +47,7 @@ _wrapper_cb(app_control_h request, app_control_h reply,
 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
@@ -93,6 +94,44 @@ out:
 }
 
 
+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"
index 86c662bc1f1a4132cbf8d53654a987b26696dc8a..f5214385c85c3c30f2d429d4703c6214a5f0ff2f 100755 (executable)
@@ -1,16 +1,16 @@
-#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,
@@ -114,22 +114,20 @@ void _curl_set_common_option(CURL *curl,
 }
 
 
-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()");
 
@@ -144,11 +142,11 @@ int http_send_request(fmwup_http_req_e type, char *req_url, char **res_header, c
 
        //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;
@@ -162,9 +160,11 @@ int http_send_request(fmwup_http_req_e type, char *req_url, char **res_header, c
 
        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_;
        }
 
index 282a050aadf476683c83efb71c8508dbf7a3f908..8c2a3026ff6c9f5cb515e7003c02abe95b5761c3 100755 (executable)
@@ -123,6 +123,14 @@ int get_name_by_id(int id, char** name)
        return 1;
 }
 
+
+int register_service(char *appid, int server_id)
+{
+
+       return 0;
+}
+
+
 #if 0
 
 #include <gio/gio.h>