(ACR) Add iotcon_request_get_host_address API
authorsung.goo.kim <sung.goo.kim@samsung.com>
Fri, 23 Oct 2015 05:38:24 +0000 (14:38 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 11:08:20 +0000 (20:08 +0900)
Change-Id: Ie62131149c5ee37e28904f72aaf650ded2ee7ce0

daemon/icd-ioty-ocprocess.c
lib/icl-request.c
lib/icl-request.h
lib/icl-resource.c
lib/include/iotcon-struct.h
test/iotcon-test-basic-server.c

index 74f8637..5c41470 100644 (file)
@@ -53,6 +53,7 @@ struct icd_req_context {
        GVariant *payload;
        GVariantBuilder *options;
        GVariantBuilder *query;
+       OCDevAddr *dev_addr;
 };
 
 
@@ -214,6 +215,7 @@ static int _worker_req_handler(void *context)
        GVariant *value;
        struct icd_req_context *ctx = context;
        GVariantBuilder payload_builder;
+       char addr[PATH_MAX] = {0};
 
        RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
 
@@ -221,7 +223,11 @@ static int _worker_req_handler(void *context)
        if (ctx->payload)
                g_variant_builder_add(&payload_builder, "v", ctx->payload);
 
-       value = g_variant_new("(ia(qs)a(ss)iiavxx)",
+       if (ctx->dev_addr->addr && *ctx->dev_addr->addr)
+               snprintf(addr, sizeof(addr), "%s:%d", ctx->dev_addr->addr, ctx->dev_addr->port);
+
+       value = g_variant_new("(sia(qs)a(ss)iiavxx)",
+                       addr,
                        ctx->types,
                        ctx->options,
                        ctx->query,
@@ -239,6 +245,7 @@ static int _worker_req_handler(void *context)
        free(ctx->bus_name);
        g_variant_builder_unref(ctx->options);
        g_variant_builder_unref(ctx->query);
+       free(ctx->dev_addr);
        free(ctx);
 
        return ret;
@@ -255,6 +262,7 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
        char *token, *save_ptr1, *save_ptr2;
        char *bus_name = NULL;
        struct icd_req_context *req_ctx;
+       OCDevAddr *dev_addr;
 
        RETV_IF(NULL == request, OC_EH_ERROR);
 
@@ -279,6 +287,15 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
        req_ctx->signum = signal_number;
        req_ctx->bus_name = bus_name;
 
+       dev_addr = calloc(1, sizeof(OCDevAddr));
+       if (NULL == dev_addr) {
+               ERR("calloc() Fail(%d)", errno);
+               free(req_ctx);
+               return OC_EH_ERROR;
+       }
+       memcpy(dev_addr, &request->devAddr, sizeof(OCDevAddr));
+       req_ctx->dev_addr = dev_addr;
+
        /* request type */
        if (OC_REQUEST_FLAG & flag) {
                switch (request->method) {
@@ -340,6 +357,7 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
                        g_variant_unref(req_ctx->payload);
                g_variant_builder_unref(req_ctx->options);
                g_variant_builder_unref(req_ctx->query);
+               free(req_ctx->dev_addr);
                free(req_ctx);
                return OC_EH_ERROR;
        }
index d43f8fb..9c42130 100644 (file)
 #include "icl.h"
 #include "icl-request.h"
 
+API int iotcon_request_get_host_address(iotcon_request_h request,
+               char **host_address)
+{
+       RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
+
+       *host_address = request->host_address;
+
+       return IOTCON_ERROR_NONE;
+}
+
+
 /* The content of the request should not be freed by user. */
 API int iotcon_request_get_representation(iotcon_request_h request,
                iotcon_representation_h *repr)
index e4727ad..daf25a2 100644 (file)
@@ -26,6 +26,7 @@ struct icl_observe_info {
 };
 
 struct icl_resource_request {
+       char *host_address;
        int types;
        iotcon_options_h header_options;
        iotcon_query_h query;
index aae9c7d..a60f702 100644 (file)
@@ -54,7 +54,8 @@ static void _icl_request_handler(GDBusConnection *connection,
        iotcon_resource_h resource = user_data;
        iotcon_request_handler_cb cb = resource->cb;
 
-       g_variant_get(parameters, "(ia(qs)a(ss)iiavxx)",
+       g_variant_get(parameters, "(sia(qs)a(ss)iiavxx)",
+                       &request.host_address,
                        &request.types,
                        &options,
                        &query,
index 899e306..b61465e 100644 (file)
@@ -1031,6 +1031,29 @@ int iotcon_remote_resource_set_options(iotcon_remote_resource_h resource,
 typedef struct icl_resource_request* iotcon_request_h;
 
 /**
+ * @brief Gets host address of the request
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] request The handle of the request
+ * @param[out] host_address The host address of the request
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE  Successful
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @see iotcon_request_get_representation()
+ * @see iotcon_request_get_types()
+ * @see iotcon_request_get_options()
+ * @see iotcon_request_get_query()
+ * @see iotcon_request_get_observer_action()
+ * @see iotcon_request_get_observer_id()
+ */
+int iotcon_request_get_host_address(iotcon_request_h request,
+               char **host_address);
+
+
+/**
  * @brief Gets an representation of the request
  *
  * @since_tizen 3.0
@@ -1043,6 +1066,7 @@ typedef struct icl_resource_request* iotcon_request_h;
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
+ * @see iotcon_request_get_host_address()
  * @see iotcon_request_get_types()
  * @see iotcon_request_get_options()
  * @see iotcon_request_get_query()
@@ -1064,6 +1088,7 @@ int iotcon_request_get_representation(iotcon_request_h request,
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
+ * @see iotcon_request_get_host_address()
  * @see iotcon_request_get_representation()
  * @see iotcon_request_get_options()
  * @see iotcon_request_get_query()
@@ -1085,6 +1110,7 @@ int iotcon_request_get_types(iotcon_request_h request, int *types);
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
+ * @see iotcon_request_get_host_address()
  * @see iotcon_request_get_representation()
  * @see iotcon_request_get_types()
  * @see iotcon_request_get_query()
@@ -1106,6 +1132,7 @@ int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *optio
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
+ * @see iotcon_request_get_host_address()
  * @see iotcon_request_get_representation()
  * @see iotcon_request_get_types()
  * @see iotcon_request_get_options()
@@ -1127,6 +1154,7 @@ int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query);
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
+ * @see iotcon_request_get_host_address()
  * @see iotcon_request_get_representation()
  * @see iotcon_request_get_types()
  * @see iotcon_request_get_options()
@@ -1147,6 +1175,7 @@ int iotcon_request_get_observer_action(iotcon_request_h request, int *action);
  * @retval #IOTCON_ERROR_NONE  Successful
  * @retval #IOTCON_ERROR_INVALID_PARAMETER  Invalid parameter
  *
+ * @see iotcon_request_get_host_address()
  * @see iotcon_request_get_representation()
  * @see iotcon_request_get_types()
  * @see iotcon_request_get_options()
index f8c5051..a2e95c1 100644 (file)
@@ -429,6 +429,7 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
        iotcon_query_h query;
        iotcon_response_h response = NULL;
        int ret, types, observer_id, observer_action;
+       char *host_address;
 
        RET_IF(NULL == request);
 
@@ -468,6 +469,13 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
 
        iotcon_response_destroy(response);
 
+       ret = iotcon_request_get_host_address(request, &host_address);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_request_get_host_address() Fail(%d)", ret);
+               return;
+       }
+       INFO("host_address : %s", host_address);
+
        if (IOTCON_REQUEST_OBSERVE & types) {
                ret = iotcon_request_get_observer_action(request, &observer_action);
                if (IOTCON_ERROR_NONE != ret) {
@@ -475,6 +483,7 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                        return;
                }
 
+
                if (IOTCON_OBSERVE_REGISTER == observer_action) {
                        ret = iotcon_request_get_observer_id(request, &observer_id);
                        if (IOTCON_ERROR_NONE != ret) {