Add dnssd_service_get_interface 03/279903/1
authorCheoleun Moon <chleun.moon@samsung.com>
Tue, 1 Jun 2021 07:28:34 +0000 (16:28 +0900)
committerAnjali Nijhara <a.nijhara@samsung.com>
Thu, 18 Aug 2022 05:39:11 +0000 (11:09 +0530)
Change-Id: Idf065fe6e8b58a207cc50f9aaec4ddc2b90506a9
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
include/dns-sd-internal.h
src/dns-sd/dns-sd.c

index e21c8ba6940894a850e9fa8ebe02249ac12693b5..cec434063a27a2f4c22c31856b3662f52f35136b 100644 (file)
@@ -28,8 +28,66 @@ extern "C" {
 #define TIZEN_ERROR_DNSSD -0x01CA0000
 #endif
 
+/**
+ * @brief Gets the interface name of DNSSD local service
+ * @since_tizen 4.0
+ * @privilevel public
+ * @privilege %http://tizen.org/privilege/internet
+ * @param[in] service The DNSSD service handle
+ * @param[in] interface The interface name
+ * @retval #DNSSD_ERROR_NONE Successful
+ * @retval #DNSSD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DNSSD_ERROR_NOT_SUPPORTED Not Supported
+ * @retval #DNSSD_ERROR_OUT_OF_MEMORY Out of Memory
+ * @retval #DNSSD_ERROR_NOT_INITIALIZED Not Initialized
+ */
 int dnssd_service_set_interface(dnssd_service_h local_service, const char *interface);
 
+/**
+ * @brief Gets the interface name of DNSSD local/remote service.
+ * @since_tizen 6.5
+ * @remarks You must release @a interface using g_free().
+ * @privilevel public
+ * @privilege %http://tizen.org/privilege/internet
+ * @param[in] service The DNSSD service handle
+ * @param[out] interface The interface name
+ * @retval #DNSSD_ERROR_NONE Successful
+ * @retval #DNSSD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DNSSD_ERROR_NOT_SUPPORTED Not Supported
+ * @retval #DNSSD_ERROR_OUT_OF_MEMORY Out of Memory
+ * @retval #DNSSD_ERROR_NOT_INITIALIZED Not Initialized
+ */
+int dnssd_service_get_interface(dnssd_service_h dnssd_service, char **interface);
+
+/**
+ * @brief Starts browsing the DNSSD remote service on a specific network interface.
+ * @details found_cb would be called only if there are any services available of
+ *          service_type provided in the argument. Application will keep
+ *          browsing for available/unavailable services until it calls
+ *          dnssd_stop_browsing_service().
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ * @param[in] service_type The DNSSD service type to browse. It is expressed
+ *                         as type followed by protocol, separated by a dot(e.g. "_ftp._tcp").
+ *                         It must begin with an underscore, followed by 1-15 characters
+ *                         which may be letters, digits, or hyphens. The transport protocol
+ *                         must be "_tcp" or "_udp". New service types should be registered
+ *                         at http://www.dns-sd.org/ServiceTypes.html
+ * @param[in] interface The interface name
+ * @param[out] dnssd_service The DNSSD browse service handle
+ * @param[in] found_cb The callback function to be called
+ * @param[in] user_data The user data passed to the callback function
+ * @return @c 0 on success,
+ *         otherwise negative error value
+ * @retval #DNSSD_ERROR_NONE Successful
+ * @retval #DNSSD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DNSSD_ERROR_NOT_SUPPORTED Not Supported
+ * @retval #DNSSD_ERROR_SERVICE_NOT_RUNNING Service Not Running
+ * @retval #DNSSD_ERROR_NOT_INITIALIZED Not Initialized
+ * @retval #DNSSD_ERROR_PERMISSION_DENIED Permission Denied
+ * @pre This API needs dnssd_initialize() before use.
+ */
 int dnssd_start_browsing_service_on_interface(const char *service_type, const char *interface,
                dnssd_browser_h *dnssd_service, dnssd_found_cb found_cb,
                void *user_data);
index ca9e1edfbbe21f5955b7ae2541d4a3542acd65b5..a2394dbcc50297eae6965e4ff7636b6bd32f33f2 100644 (file)
@@ -462,6 +462,22 @@ EXPORT_API int dnssd_create_local_service(const char *service_type,
        return DNSSD_ERROR_NONE;
 }
 
+static int __get_valid_handle(dnssd_service_h dnssd_service, dnssd_handle_s **handle)
+{
+       dnssd_handle_s *local_handle;
+
+       local_handle = __dnssd_get_struct_from_handle(dnssd_service);
+       if (local_handle == NULL) {
+               DNSSD_LOGD("Service Handler not found");
+               __DNSSD_LOG_FUNC_EXIT__;
+               return DNSSD_ERROR_SERVICE_NOT_FOUND;
+       }
+
+       *handle = local_handle;
+
+       return DNSSD_ERROR_NONE;
+}
+
 static int __get_valid_registered_handle(dnssd_service_h dnssd_service, dnssd_handle_s **handle)
 {
        dnssd_handle_s *local_handle;
@@ -625,6 +641,67 @@ EXPORT_API int dnssd_service_set_interface(dnssd_service_h local_service, const
        return DNSSD_ERROR_NONE;
 }
 
+EXPORT_API int dnssd_service_get_interface(dnssd_service_h dnssd_service, char **interface)
+{
+       __DNSSD_LOG_FUNC_ENTER__;
+       dnssd_handle_s *local_handle = NULL;
+       int res = DNSSD_ERROR_NONE;
+       unsigned int if_index = 0;
+
+       CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
+       DNSSD_LOCK;
+
+       CHECK_INITIALIZED();
+
+       res = __get_valid_handle(dnssd_service, &local_handle);
+       if (res != DNSSD_ERROR_NONE) {
+               DNSSD_UNLOCK;
+               return res;
+       }
+
+       if (interface== NULL) {
+               DNSSD_LOGE("Invalid Parameter");
+               DNSSD_UNLOCK;
+               __DNSSD_LOG_FUNC_EXIT__;
+               return DNSSD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (local_handle->op_type == DNSSD_TYPE_FOUND) {
+               dnssd_found_data_s *found = NULL;
+               found = GET_FOUND_DATA_P(local_handle);
+               if_index = found->if_index;
+       } else if (local_handle->op_type == DNSSD_TYPE_REGISTER) {
+               dnssd_register_data_s *reg = NULL;
+               reg = GET_REG_DATA_P(local_handle);
+               if_index = reg->if_index;
+       } else {
+               *interface = NULL;
+               DNSSD_LOGE("Invalid DNS SD service");
+               DNSSD_UNLOCK;
+               __DNSSD_LOG_FUNC_EXIT__;
+               return DNSSD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (if_index > 0) {
+               char iface[IFNAMSIZ + 1];
+               if (if_indextoname(if_index, iface) == NULL) {
+                       DNSSD_LOGE("if_indextoname fails. errno: %d", errno);
+                       res = DNSSD_ERROR_INVALID_OPERATION;
+               }
+               else {
+                       DNSSD_LOGD("Interface Name %s", iface);
+                       *interface = g_strdup(iface);
+               }
+       }
+       else {
+               DNSSD_LOGD("No Interface (all interfaces is used)");
+               *interface = NULL;
+       }
+
+       DNSSD_UNLOCK;
+       __DNSSD_LOG_FUNC_EXIT__;
+       return DNSSD_ERROR_NONE;
+}
 
 EXPORT_API int dnssd_service_add_txt_record(dnssd_service_h local_service,
                const char *key, unsigned short length, const void *value)
@@ -896,22 +973,6 @@ static void __dnssd_register_reply_cb(DNSServiceRef sd_ref, unsigned int flags,
        DNSSD_UNLOCK;
 }
 
-static int __get_valid_handle(dnssd_service_h dnssd_service, dnssd_handle_s **handle)
-{
-       dnssd_handle_s *local_handle;
-
-       local_handle = __dnssd_get_struct_from_handle(dnssd_service);
-       if (local_handle == NULL) {
-               DNSSD_LOGD("Service Handler not found");
-               __DNSSD_LOG_FUNC_EXIT__;
-               return DNSSD_ERROR_SERVICE_NOT_FOUND;
-       }
-
-       *handle = local_handle;
-
-       return DNSSD_ERROR_NONE;
-}
-
 static int __dnssd_service_get_all_txt_record(dnssd_service_h dnssd_service,
                unsigned short *length, void **value)
 {