Add new APIs for handling a remove service to make browse() and resolve() operate independently.
- Added APIs:
dnssd_create_remote_service()
dnssd_destroy_remote_service()
- how to test
1. Register service
$ dns-sd -R test _http._tcp local 12345
2. Resolve service using dns-sd-internal-test
$ dns-sd-internal-test
1(_http._tcp, test, wlan0) > 5
Change-Id: I7aa95913d6be359db65d4948a67b49711e3e44e2
*/
int dnssd_cancel_resolve_service(dnssd_service_h service);
+
+/**
+ * @brief Creates a DNSSD remote service handle.
+ * @details @a dnssd_service is used for dnssd_resolve_service() only.
+ * @since_tizen 6.5
+ * @remarks You must release @a dnssd_service using dnssd_destroy_remote_service().
+ * @param[in] service_type The DNSSD service type. 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] service_name The name of DNSSD remote service
+ * @param[in] interface The interface name
+ * @param[out] dnssd_service The DNSSD remote handle
+ * @return @c 0 on success,
+ * otherwise negative error value
+ * @retval #DNSSD_ERROR_NONE Successful
+ * @retval #DNSSD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DNSSD_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #DNSSD_ERROR_NOT_SUPPORTED Not Supported
+ * @retval #DNSSD_ERROR_NOT_INITIALIZED Not Initialized
+ * @see dnssd_destroy_remote_service()
+ * @pre This API needs dnssd_initialize() before use
+ */
+int dnssd_create_remote_service(const char *service_type, const char *service_name, const char *interfac, dnssd_service_h *dnssd_service);
+
+/**
+ * @brief Destroys the DNSSD remote service handle.
+ * @since_tizen 6.5
+ * @remarks You must destroy only remote services created using dnssd_create_remote_service().
+ * @param[in] dnssd_service The DNSSD remote service handle
+ * @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_NOT_INITIALIZED Not Initialized
+ * @see dnssd_create_remote_service()
+ * @pre This API needs dnssd_create_remote_service() before use.
+ */
+int dnssd_destroy_remote_service(dnssd_service_h dnssd_service);
+
#ifdef __cplusplus
}
#endif
Name: capi-network-nsd
Summary: A Network Service Discovery libraries in Native API
-Version: 0.1.5
+Version: 0.1.6
Release: 1
Group: System/Network
License: Apache-2.0
local_handle->flags);
dnssd_handle = __dnssd_get_struct_from_handle(found->browse_handler);
- if (dnssd_handle == NULL) {
- DNSSD_LOGD("Invalid browse handle");
- DNSSD_UNLOCK;
- __DNSSD_LOG_FUNC_EXIT__;
- return;
- }
- DNSSD_LOGD("GetAddrInfo Callback set for [%p]",
- dnssd_handle);
+ if (dnssd_handle)
+ DNSSD_LOGD("GetAddrInfo Callback set for [%p]", dnssd_handle);
__update_found_address(address, found);
return res;
}
+ DNSSD_UNLOCK;
+ __DNSSD_LOG_FUNC_EXIT__;
+
+ return DNSSD_ERROR_NONE;
+}
+
+EXPORT_API int dnssd_create_remote_service(const char *service_type,
+ const char *service_name, const char *interface,
+ dnssd_service_h *dnssd_service)
+{
+ __DNSSD_LOG_FUNC_ENTER__;
+ dnssd_handle_s *remote_handle;
+ dnssd_found_data_s *found = NULL;
+ unsigned int handler;
+
+ CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
+ DNSSD_LOCK;
+
+ CHECK_INITIALIZED();
+
+ if (dnssd_service == NULL || service_type == NULL
+ || service_name == NULL
+ || __dnssd_get_struct_from_handle(*dnssd_service) != NULL) {
+ DNSSD_LOGE("Invalid Parameter");
+ DNSSD_UNLOCK;
+ __DNSSD_LOG_FUNC_EXIT__;
+ return DNSSD_ERROR_INVALID_PARAMETER;
+ }
+
+ remote_handle = (dnssd_handle_s *)g_try_malloc0(FOUND_SIZE);
+ if (remote_handle == NULL) {
+ DNSSD_LOGE("Failed to Allocate Memory"); //LCOV_EXCL_LINE
+ DNSSD_UNLOCK;
+ __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return DNSSD_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+ }
+
+ handler = (uintptr_t)remote_handle & 0xffffffff;
+ *dnssd_service = handler;
+ remote_handle->service_handler = handler;
+ remote_handle->op_type = DNSSD_TYPE_FOUND_NOT_RESOLVED;
+ remote_handle->service_type = g_strdup(service_type);
+ g_strlcpy(remote_handle->domain, "local", sizeof(remote_handle->domain));
+ remote_handle->flags = 0;
+ remote_handle->watch_id = 0;
+
+ found = GET_FOUND_DATA_P(remote_handle);
+ if (interface) {
+ unsigned int if_index;
+ if ((if_index = if_nametoindex(interface)) == 0) {
+ DNSSD_LOGE("Invalid interface name");
+ g_free(remote_handle->service_type);
+ g_free(remote_handle);
+ DNSSD_UNLOCK;
+ __DNSSD_LOG_FUNC_EXIT__;
+ return DNSSD_ERROR_INVALID_PARAMETER;
+ }
+ found->if_index = if_index;
+ } else {
+ found->if_index = kDNSServiceInterfaceIndexAny;
+ }
+ found->service_name = g_strdup(service_name);
+
+ DNSSD_LOGD("New handle created [%p]->[%u] type %s", remote_handle,
+ *dnssd_service, remote_handle->service_type);
+
+ dnssd_handle_list = g_slist_prepend(dnssd_handle_list, remote_handle);
+
+ DNSSD_UNLOCK;
+ __DNSSD_LOG_FUNC_EXIT__;
+ return DNSSD_ERROR_NONE;
+}
+
+EXPORT_API int dnssd_destroy_remote_service(dnssd_service_h dnssd_service)
+{
+ __DNSSD_LOG_FUNC_ENTER__;
+ dnssd_handle_s *remote_handle = NULL;
+
+ CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
+ DNSSD_LOCK;
+
+ CHECK_INITIALIZED();
+
+ remote_handle = __dnssd_get_struct_from_handle(dnssd_service);
+ if (remote_handle == NULL) {
+ DNSSD_LOGD("Service Handler not found");
+ __DNSSD_LOG_FUNC_EXIT__;
+ return DNSSD_ERROR_SERVICE_NOT_FOUND;
+ }
+
+ if (remote_handle->op_type != DNSSD_TYPE_FOUND &&
+ remote_handle->op_type != DNSSD_TYPE_FOUND_NOT_RESOLVED) {
+ DNSSD_LOGE("Invalid handle type");
+ DNSSD_UNLOCK;
+ return DNSSD_ERROR_INVALID_PARAMETER;
+ }
+
+ DNSSD_LOGD("Destroy handle: [%p]->[%u]", remote_handle, dnssd_service);
+
+ dnssd_handle_list = g_slist_remove(dnssd_handle_list, remote_handle);
+ g_free(remote_handle->service_type);
+ dnssd_found_data_s *found = GET_FOUND_DATA_P(remote_handle);
+ if (!found) {
+ DNSSD_LOGE("Cannot find found data.");
+ DNSSD_UNLOCK;
+ return DNSSD_ERROR_INVALID_PARAMETER;
+ }
+
+ if (remote_handle->watch_id > 0)
+ __remove_service_getaddrinfo_socket(remote_handle);
+
+ g_free(found->service_name);
+ g_free(found->host);
+ g_free(remote_handle);
+ remote_handle = NULL;
+
+ DNSSD_LOGD("g_slist length [%d]", g_slist_length(dnssd_handle_list));
DNSSD_UNLOCK;
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
printf("\n");
}
+int test_dnssd_create_remote_service()
+{
+ int rv = -1;
+
+ dnssd_service_h service = 0;
+ char service_type[255];
+ char service_name[255];
+ char interface[255];
+ printf("Create DNS Service\n");
+ test_get_user_string("Enter type:(Example : _http._tcp, "
+ "_printer._tcp etc)", service_type, 255);
+ test_get_user_string("Enter name:", service_name, 255);
+ test_get_user_string("Enter interface name:", interface, 255);
+
+ rv = dnssd_create_remote_service(service_type, service_name, interface, &service);
+ if (rv != DNSSD_ERROR_NONE) {
+ printf("Failed to create DNS SD Service, error [%s]\n",
+ dnssd_error_to_string(rv));
+ return 0;
+ }
+
+ printf("Successfully created DNS SD Service[%u]\n", service);
+
+ return 1;
+}
+
+int test_dnssd_destroy_remote_service()
+{
+ dnssd_service_h service = 0;
+ int rv;
+
+ printf("Destroy Remote Service\n");
+ printf("Enter Remote Service Handler:\n");
+ rv = scanf("%u", &service);
+
+ rv = dnssd_destroy_remote_service(service);
+ if (rv != DNSSD_ERROR_NONE) {
+ printf("Failed to destroy service, error [%s]\n",
+ dnssd_error_to_string(rv));
+ return 0;
+ }
+ printf("Successfully destroy service\n");
+
+
+ return 1;
+}
+
int test_dnssd_browse_service()
{
dnssd_service_h service = 0;
return 1;
}
+int test_dnssd_resolve_service()
+{
+ dnssd_service_h service = 0;
+ int rv;
+
+ printf("Resolve Remote Service\n");
+ printf("Enter Remote Service Handler:\n");
+ rv = scanf("%u", &service);
+
+ rv = dnssd_resolve_service(service, _resolve_cb, NULL);
+ if (rv != DNSSD_ERROR_NONE) {
+ printf("Failed to resolve service, error [%s]\n",
+ dnssd_error_to_string(rv));
+ return 0;
+ }
+ printf("Successfully resolve service\n");
+
+ return 1;
+}
+
static void MenuScreen()
{
printf("_____________________________________\n");
printf("|_____________MENU-SCREEN___________|\n");
printf("| 0 - EXIT |\n");
- printf("| 1 - Browse DNS Service |\n");
- printf("| 2 - Cancel Browse DNS Service |\n");
+ printf("| 1 - Create Remote Service |\n");
+ printf("| 2 - Destroy Remote Service |\n");
+ printf("| 3 - Browse DNS Service |\n");
+ printf("| 4 - Cancel Browse DNS Service |\n");
+ printf("| 5 - Resolve Service |\n");
printf("|___________________________________|\n");
}
switch (a[0]) {
case '1':
- rv = test_dnssd_browse_service();
+ rv = test_dnssd_create_remote_service();
break;
case '2':
+ rv = test_dnssd_destroy_remote_service();
+ break;
+ case '3':
+ rv = test_dnssd_browse_service();
+ break;
+ case '4':
rv = test_dnssd_cancel_browse_service();
break;
+ case '5':
+ rv = test_dnssd_resolve_service();
+ break;
}
if (rv == 1)