#define SMACK_LABEL_LEN 255
+#define CHECK_INITIALIZED()\
+ do {\
+ if (__dnssd_is_init() == false) {\
+ DNSSD_LOGE("Not initialized");\
+ __DNSSD_LOG_FUNC_EXIT__;\
+ return DNSSD_ERROR_NOT_INITIALIZED;\
+ } \
+ } while (0)
+
+#define CHECK_PERMISSION()\
+ do {\
+ if (__dnssd_check_permission() == false) {\
+ DNSSD_LOGE("Permission denied");\
+ __DNSSD_LOG_FUNC_EXIT__;\
+ return DNSSD_ERROR_PERMISSION_DENIED;\
+ } \
+ } while (0)
+
static __thread GSList *dnssd_handle_list = NULL;
static __thread GSList *resolve_handle_list = NULL;
static __thread bool g_is_init = false;
static __thread GDBusConnection *netconfig_bus = NULL;
+//LCOV_EXCL_START
static const char *dnssd_error_to_string(DNSServiceErrorType dnssd_service_error)
{
switch (dnssd_service_error) {
return "UNSUPPORTED_ERROR";
}
}
+//LCOV_EXCL_STOP
+
static dnssd_handle_s *__dnssd_check_handle_validity(dnssd_handle_s *handle)
{
__DNSSD_LOG_FUNC_ENTER__;
return NULL;
}
-//LCOV_EXCL_START
static bool __dnssd_check_permission()
{
FILE *fd;
return (ret == CYNARA_API_ACCESS_ALLOWED) ? true : false;
}
-//LCOV_EXCL_STOP
static bool __dnssd_is_init(void)
{
return g_is_init;
}
-//LCOV_EXCL_START
-static int __dnssd_launch_mdns_dbus(void)
+static void __dnssd_set_initialized(bool initialized)
+{
+ g_is_init = initialized;
+}
+
+static int __connect_netconfig_gdbus(void)
{
GError *g_error = NULL;
GVariant *params;
DNSSD_LOGD("Successfully launched mdnsresponder");
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
-static int __dnssd_launch_mdns()
+static void __disconnect_netconfig_gdbus(void)
{
- __DNSSD_LOG_FUNC_ENTER__;
- int res = DNSSD_ERROR_NONE;
- res = __dnssd_launch_mdns_dbus();
- if (res != DNSSD_ERROR_NONE)
- DNSSD_LOGE("Fail to send dbus msg");
- __DNSSD_LOG_FUNC_EXIT__;
- return res;
+ g_object_unref(netconfig_bus);
+ netconfig_bus = NULL;
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static gboolean __dnssd_process_result(GIOCondition condition, DNSServiceRef sd_ref)
{
DNSServiceErrorType err;
return FALSE;
}
return TRUE;
+//LCOV_EXCL_START
case G_IO_HUP:
DNSSD_LOGE("G_IO_HUP event received.");
break;
DNSSD_LOGE("Unknown event received.");
break;
}
+//LCOV_EXCL_STOP
return FALSE;
}
return __dnssd_process_result(condition, reply->sd_ref);
}
-//LCOV_EXCL_STOP
static guint __dnssd_io_add_watch(int fd, GIOFunc func, gpointer data)
{
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
if (__dnssd_is_init() == true) {
- DNSSD_LOGE("Already initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
+ DNSSD_LOGE("Already initialized");
+ __DNSSD_LOG_FUNC_EXIT__;
+ return DNSSD_ERROR_INVALID_OPERATION;
}
- res = __dnssd_launch_mdns();
-
+ res = __connect_netconfig_gdbus();
if (res != DNSSD_ERROR_NONE) {
DNSSD_LOGE("Failed to launch mdnsresponder");
__DNSSD_LOG_FUNC_EXIT__;
return res;
}
- g_is_init = true;
+ __dnssd_set_initialized(true);
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_NOT_INITIALIZED;
- }
+ CHECK_INITIALIZED();
- g_is_init = false;
+ __dnssd_set_initialized(false);
- g_object_unref(netconfig_bus);
- netconfig_bus = NULL;
+ __disconnect_netconfig_gdbus();
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ CHECK_INITIALIZED();
if (dnssd_service == NULL || service_type == NULL ||
__dnssd_get_struct_from_handle(*dnssd_service) != NULL) {
return DNSSD_ERROR_NONE;
}
-int dnssd_destroy_local_service(dnssd_service_h dnssd_service)
+static int __get_valid_registered_handle(dnssd_service_h dnssd_service, dnssd_handle_s **handle)
{
- __DNSSD_LOG_FUNC_ENTER__;
- dnssd_handle_s *local_handle = NULL;
-
- CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
+ dnssd_handle_s *local_handle;
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ CHECK_INITIALIZED();
local_handle = __dnssd_get_struct_from_handle(dnssd_service);
if (local_handle == NULL) {
return DNSSD_ERROR_SERVICE_NOT_FOUND;
}
+ *handle = local_handle;
+
+ return DNSSD_ERROR_NONE;
+}
+
+int dnssd_destroy_local_service(dnssd_service_h dnssd_service)
+{
+ __DNSSD_LOG_FUNC_ENTER__;
+ dnssd_handle_s *local_handle = NULL;
+ int res;
+
+ CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
+
+ res = __get_valid_registered_handle(dnssd_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
+
DNSSD_LOGD("Destroy handle: [%p]->[%u]", local_handle, dnssd_service);
dnssd_handle_list = g_slist_remove(dnssd_handle_list, local_handle);
g_free(local_handle);
local_handle = NULL;
+ DNSSD_LOGD("g_slist length [%d]", g_slist_length(dnssd_handle_list));
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
}
__DNSSD_LOG_FUNC_ENTER__;
dnssd_handle_s *local_handle = NULL;
dnssd_register_data_s *reg = NULL;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (service_name == NULL) {
DNSSD_LOGD("Service name is NULL");
return DNSSD_ERROR_INVALID_PARAMETER;
}
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
reg = GET_REG_DATA_P(local_handle);
g_free(reg->service_name);
reg->service_name = g_strdup(service_name);
__DNSSD_LOG_FUNC_ENTER__;
dnssd_handle_s *local_handle = NULL;
dnssd_register_data_s *reg = NULL;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (port < 0 || port > 65535) {
DNSSD_LOGD("Invalid port range");
return DNSSD_ERROR_INVALID_PARAMETER;
}
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_SERVICE_NOT_FOUND; //LCOV_EXCL_LINE
- }
-
reg = GET_REG_DATA_P(local_handle);
reg->port = port;
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_START
int dnssd_service_set_interface(dnssd_service_h local_service, const char *interface)
{
__DNSSD_LOG_FUNC_ENTER__;
dnssd_handle_s *local_handle = NULL;
dnssd_register_data_s *reg = NULL;
unsigned int if_index = 0;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if ((if_index = if_nametoindex(interface)) == 0) {
DNSSD_LOGE("Invalid interface name");
}
DNSSD_LOGD("Interface index: %u", if_index);
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_SERVICE_NOT_FOUND; //LCOV_EXCL_LINE
- }
-
reg = GET_REG_DATA_P(local_handle);
reg->if_index = if_index;
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_STOP
+
int dnssd_service_add_txt_record(dnssd_service_h local_service,
const char *key, unsigned short length, const void *value)
TXTRecordRef *txt_record;
dnssd_handle_s *local_handle = NULL;
dnssd_register_data_s *reg = NULL;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
-
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (key == NULL) {
DNSSD_LOGE("key is NULL");
dnssd_handle_s *local_handle;
dnssd_register_data_s *reg = NULL;
unsigned short txt_len;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (key == NULL) {
DNSSD_LOGE("key is NULL");
return DNSSD_ERROR_INVALID_PARAMETER;
}
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
reg = GET_REG_DATA_P(local_handle);
txt_record = &(reg->txt_ref);
DNSServiceErrorType ret;
dnssd_handle_s *local_handle = NULL;
dnssd_register_data_s *reg;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
-
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
reg = GET_REG_DATA_P(local_handle);
DNSSD_LOGD("Record Type %d Record len %d", type, length);
ret = DNSServiceAddRecord(local_handle->sd_ref, &(reg->record_ref),
local_handle->flags, type, length, data, 0);
} else {
- DNSSD_LOGD("Updating DNS Service Record"); //LCOV_EXCL_LINE
- ret = DNSServiceUpdateRecord(local_handle->sd_ref, reg->record_ref, //LCOV_EXCL_LINE
- local_handle->flags, length, data, 0); //LCOV_EXCL_LINE
+ DNSSD_LOGD("Updating DNS Service Record");
+ ret = DNSServiceUpdateRecord(local_handle->sd_ref, reg->record_ref,
+ local_handle->flags, length, data, 0);
}
if (ret != kDNSServiceErr_NoError) {
DNSServiceErrorType dnssd_err = 0;
uint32_t version = 0;
uint32_t size = sizeof(version);
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
-
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
reg = GET_REG_DATA_P(local_handle);
dnssd_register_data_s *reg = NULL;
void *data;
unsigned short length;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_check_permission() == false) {
- DNSSD_LOGE("Permission denied"); //LCOV_EXCL_LINE
- return DNSSD_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
- }
-
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ CHECK_PERMISSION();
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (register_cb == NULL) {
DNSSD_LOGE("No callback provided");
return DNSSD_ERROR_INVALID_PARAMETER;
}
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_SERVICE_NOT_FOUND; //LCOV_EXCL_LINE
- }
-
reg = GET_REG_DATA_P(local_handle);
if (reg->service_name == NULL) {
int dnssd_deregister_local_service(dnssd_service_h local_service)
{
__DNSSD_LOG_FUNC_ENTER__;
+ DNSServiceErrorType ret;
dnssd_handle_s *local_handle = NULL;
dnssd_register_data_s *reg;
- int ret;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
-
- local_handle = __dnssd_get_struct_from_handle(local_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
-
- if (local_handle->op_type != DNSSD_TYPE_REGISTER) {
- DNSSD_LOGD("DNSSD service is not a local service");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
+ res = __get_valid_registered_handle(local_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (local_handle->sd_ref == NULL) {
DNSSD_LOGE("Invalid DNS SD Client");
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_START
static gboolean __remove_service_getaddrinfo_socket(gpointer user_data)
{
DNSSD_LOGD("Remove DNSServiceGetAddrInfo socket");
local_handle->sd_ref = NULL;
return FALSE;
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static void __dnssd_getaddrinfo_reply_cb(DNSServiceRef sd_ref,
unsigned int flags, unsigned int if_index,
DNSServiceErrorType error_code, const char *host_name,
g_idle_add_full(G_PRIORITY_HIGH, __remove_service_getaddrinfo_socket,
local_handle, NULL);
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static int __dnssd_getaddrinfo(dnssd_handle_s *dnssd_handle, unsigned int flags,
unsigned int if_index, const char *host_name, char *service_name,
const char *fullname, const char *txt_record,
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static gboolean __remove_service_resolve_socket(gpointer user_data)
{
DNSSD_LOGD("Remove DNSServiceResolve socket");
resolve_data->sd_ref = NULL;
return FALSE;
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static void __dnssd_resolve_reply_cb(DNSServiceRef sd_ref, unsigned int flags,
unsigned int if_index, DNSServiceErrorType error_code,
const char *fullname, const char *host_name,
__dnssd_getaddrinfo(resolve_data->dnssd_handle, flags, if_index,
host_name, resolve_data->service_name, fullname,
(const char *) txt_record, txt_len, port);
+
g_idle_add_full(G_PRIORITY_HIGH, __remove_service_resolve_socket,
resolve_data, NULL);
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static int __dnssd_resolve_dns_service(dnssd_handle_s *dnssd_handle,
unsigned int flags, unsigned int if_index,
const char *service_name, const char *type, const char *domain)
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static dnssd_handle_s *__dnssd_get_found_handle(dnssd_service_h browse_service,
const char *service_name)
{
__DNSSD_LOG_FUNC_EXIT__;
return NULL;
}
-//LCOV_EXCL_STOP
-//LCOV_EXCL_START
static void __dnssd_browse_reply_cb(DNSServiceRef sd_ref, unsigned int flags,
unsigned int if_index, DNSServiceErrorType error_code,
const char *service_name, const char *service_type,
}
__DNSSD_LOG_FUNC_EXIT__;
}
-//LCOV_EXCL_STOP
int dnssd_start_browsing_service(const char *service_type,
dnssd_browser_h *dnssd_service, dnssd_found_cb found_cb,
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_check_permission() == false) {
- DNSSD_LOGE("Permission denied"); //LCOV_EXCL_LINE
- return DNSSD_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
- }
+ CHECK_PERMISSION();
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ CHECK_INITIALIZED();
- if (dnssd_service == NULL || service_type == NULL ||
+ if (found_cb == NULL || dnssd_service == NULL || service_type == NULL ||
__dnssd_get_struct_from_handle(*dnssd_service) != NULL) {
DNSSD_LOGE("Invalid Parameter");
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_INVALID_PARAMETER;
}
- if (found_cb == NULL) {
- DNSSD_LOGE("Callback Not Provided");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_INVALID_PARAMETER;
- }
-
local_handle = (dnssd_handle_s *)g_try_malloc0(BROWSE_SIZE);
if (local_handle == NULL) {
DNSSD_LOGE("Failed to Allocate Memory"); //LCOV_EXCL_LINE
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_START
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)
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ CHECK_PERMISSION();
- if (dnssd_service == NULL || service_type == NULL ||
+ CHECK_INITIALIZED();
+
+ if (found_cb == NULL || dnssd_service == NULL || service_type == NULL ||
__dnssd_get_struct_from_handle(*dnssd_service) != NULL) {
DNSSD_LOGE("Invalid Parameter");
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_INVALID_PARAMETER;
}
- if (found_cb == NULL) {
- DNSSD_LOGE("Callback Not Provided");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_INVALID_PARAMETER;
- }
-
local_handle = (dnssd_handle_s *)g_try_malloc0(BROWSE_SIZE);
if (local_handle == NULL) {
DNSSD_LOGE("Failed to Allocate Memory"); //LCOV_EXCL_LINE
if ((if_index = if_nametoindex(interface)) == 0) {
DNSSD_LOGE("Invalid interface name");
- g_free(local_handle); //LCOV_EXCL_LINE
+ g_free(local_handle);
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_INVALID_PARAMETER;
}
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
}
-//LCOV_EXCL_STOP
+
+static int __get_valid_browsing_handle(dnssd_service_h dnssd_service, dnssd_handle_s **handle)
+{
+ dnssd_handle_s *local_handle;
+
+ CHECK_INITIALIZED();
+
+ 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;
+ }
+
+ if (local_handle->op_type != DNSSD_TYPE_BROWSE) {
+ DNSSD_LOGD("DNSSD service is not a local service");
+ __DNSSD_LOG_FUNC_EXIT__;
+ return DNSSD_ERROR_SERVICE_NOT_FOUND;
+ }
+
+ if (local_handle->sd_ref == NULL) {
+ DNSSD_LOGE("Invalid DNS SD Client"); //LCOV_EXCL_LINE
+ __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return DNSSD_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ *handle = local_handle;
+
+ return DNSSD_ERROR_NONE;
+}
static void __dnssd_remove_found_service(gpointer data, gpointer user_data)
{
if (found_handle->op_type != DNSSD_TYPE_FOUND)
return;
- //LCOV_EXCL_START
found_data = GET_FOUND_DATA_P(found_handle);
if (found_data->browse_handler != *handler)
return;
__DNSSD_LOG_FUNC_EXIT__;
return;
- //LCOV_EXCL_STOP
}
-int dnssd_stop_browsing_service(dnssd_browser_h dnssd_service)
+static void __destroy_resolve_data(dnssd_handle_s *browsing_handle,
+ resolve_reply_data *resolve_data)
{
- __DNSSD_LOG_FUNC_ENTER__;
- dnssd_handle_s *local_handle;
- GSList *list;
- resolve_reply_data *resolve_data;
-
- CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
-
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ if (resolve_data->dnssd_handle != browsing_handle)
+ return;
- local_handle = __dnssd_get_struct_from_handle(dnssd_service);
- if (local_handle == NULL) {
- DNSSD_LOGD("Service Handler 0x%x not found", dnssd_service);
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
+ resolve_handle_list = g_slist_remove(resolve_handle_list,
+ resolve_data);
+ if (resolve_data->watch_id > 0)
+ __remove_service_resolve_socket(resolve_data);
- if (local_handle->op_type != DNSSD_TYPE_BROWSE) {
- DNSSD_LOGD("DNS SD service is not browser service");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_INVALID_PARAMETER;
- }
+ g_free(resolve_data->service_name);
+ g_free(resolve_data);
+}
- if (local_handle->sd_ref == NULL) {
- DNSSD_LOGE("Invalid DNS SD Client"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
- }
+static void __remove_related_handles(dnssd_handle_s *browsing_handle)
+{
+ GSList *list;
g_slist_foreach(dnssd_handle_list, (GFunc)__dnssd_remove_found_service,
- &(local_handle->service_handler));
+ &(browsing_handle->service_handler));
list = resolve_handle_list;
while (list) {
- //LCOV_EXCL_START
- resolve_data = list->data;
+ __destroy_resolve_data(browsing_handle, (resolve_reply_data *)list->data);
list = list->next;
-
- if (resolve_data->dnssd_handle == local_handle) {
- resolve_handle_list = g_slist_remove(resolve_handle_list,
- resolve_data);
- if (resolve_data->watch_id > 0)
- __remove_service_resolve_socket(resolve_data);
-
- g_free(resolve_data->service_name);
- g_free(resolve_data);
- }
- //LCOV_EXCL_STOP
}
- if (local_handle->watch_id > 0)
- g_source_remove(local_handle->watch_id);
+ return;
+}
- DNSServiceRefDeallocate(local_handle->sd_ref);
- local_handle->sd_ref = NULL;
+void __destroy_browsing_handle(dnssd_handle_s *browsing_handle)
+{
+ if (browsing_handle->watch_id > 0)
+ g_source_remove(browsing_handle->watch_id);
+ DNSServiceRefDeallocate(browsing_handle->sd_ref);
+ browsing_handle->sd_ref = NULL;
+
+ dnssd_handle_list = g_slist_remove(dnssd_handle_list, browsing_handle);
+ g_free(browsing_handle->service_type);
+ g_free(browsing_handle);
DNSSD_LOGD("g_slist length [%d]", g_slist_length(dnssd_handle_list));
+
+ return;
+}
+
+int dnssd_stop_browsing_service(dnssd_browser_h dnssd_service)
+{
+ __DNSSD_LOG_FUNC_ENTER__;
+ dnssd_handle_s *local_handle;
+ int res;
+
+ CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
+
+ res = __get_valid_browsing_handle(dnssd_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
+
+ __remove_related_handles(local_handle);
+ __destroy_browsing_handle(local_handle);
+
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
}
+static int __get_valid_handle(dnssd_service_h dnssd_service, dnssd_handle_s **handle)
+{
+ dnssd_handle_s *local_handle;
+
+ CHECK_INITIALIZED();
+
+ 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;
+}
+
int dnssd_service_get_type(dnssd_service_h dnssd_service, char **service_type)
{
__DNSSD_LOG_FUNC_ENTER__;
dnssd_handle_s *local_handle = NULL;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ res = __get_valid_handle(dnssd_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (service_type == NULL) {
DNSSD_LOGE("Invalid Parameter");
return DNSSD_ERROR_INVALID_PARAMETER;
}
- 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;
- } else {
- *service_type = g_strdup(local_handle->service_type);
- DNSSD_LOGD("Service Type %s", *service_type);
- }
+ *service_type = g_strdup(local_handle->service_type);
+ DNSSD_LOGD("Service Type %s", *service_type);
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
{
__DNSSD_LOG_FUNC_ENTER__;
dnssd_handle_s *local_handle = NULL;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ res = __get_valid_handle(dnssd_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (service_name == NULL) {
DNSSD_LOGE("Invalid Parameter");
return DNSSD_ERROR_INVALID_PARAMETER;
}
- 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;
- }
-
if (local_handle->op_type == DNSSD_TYPE_FOUND) {
- dnssd_found_data_s *found = NULL; //LCOV_EXCL_LINE
- found = GET_FOUND_DATA_P(local_handle); //LCOV_EXCL_LINE
- *service_name = g_strdup(found->service_name); //LCOV_EXCL_LINE
+ dnssd_found_data_s *found = NULL;
+ found = GET_FOUND_DATA_P(local_handle);
+ *service_name = g_strdup(found->service_name);
} else if (local_handle->op_type == DNSSD_TYPE_REGISTER) {
dnssd_register_data_s *reg = NULL;
reg = GET_REG_DATA_P(local_handle);
dnssd_handle_s *local_handle = NULL;
dnssd_found_data_s *found = NULL;
unsigned char *addr = NULL;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_NOT_INITIALIZED;
- }
-
if (ip_v4_address == NULL && ip_v6_address == NULL) {
DNSSD_LOGE("Invalid Parameter");
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_INVALID_PARAMETER;
}
- 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;
- }
+ res = __get_valid_handle(dnssd_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
-//LCOV_EXCL_START
if (local_handle->op_type != DNSSD_TYPE_FOUND) {
DNSSD_LOGD("Invalid DNS SD Service");
__DNSSD_LOG_FUNC_EXIT__;
__DNSSD_LOG_FUNC_EXIT__;
return DNSSD_ERROR_NONE;
-//LCOV_EXCL_STOP
}
int dnssd_service_get_port(dnssd_service_h dnssd_service, int *port)
{
__DNSSD_LOG_FUNC_ENTER__;
dnssd_handle_s *local_handle = NULL;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
+ res = __get_valid_handle(dnssd_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (port == NULL) {
DNSSD_LOGE("Invalid Parameter");
return DNSSD_ERROR_INVALID_PARAMETER;
}
- 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;
- }
-
if (local_handle->op_type == DNSSD_TYPE_FOUND) {
- dnssd_found_data_s *found = NULL; //LCOV_EXCL_LINE
- found = GET_FOUND_DATA_P(local_handle); //LCOV_EXCL_LINE
- *port = found->port; //LCOV_EXCL_LINE
+ dnssd_found_data_s *found = NULL;
+ found = GET_FOUND_DATA_P(local_handle);
+ *port = found->port;
} else if (local_handle->op_type == DNSSD_TYPE_REGISTER) {
dnssd_register_data_s *reg = NULL;
reg = GET_REG_DATA_P(local_handle);
__DNSSD_LOG_FUNC_ENTER__;
TXTRecordRef *txt_record;
dnssd_handle_s *local_handle;
+ int res;
CHECK_FEATURE_SUPPORTED(NETWORK_SERVICE_DISCOVERY_FEATURE);
- if (__dnssd_is_init() == false) {
- DNSSD_LOGE("Not initialized"); //LCOV_EXCL_LINE
- __DNSSD_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
- return DNSSD_ERROR_NOT_INITIALIZED; //LCOV_EXCL_LINE
- }
-
- local_handle = __dnssd_get_struct_from_handle(dnssd_service);
- if (local_handle == NULL) {
- DNSSD_LOGE("Service Handler not found");
- __DNSSD_LOG_FUNC_EXIT__;
- return DNSSD_ERROR_SERVICE_NOT_FOUND;
- }
+ res = __get_valid_handle(dnssd_service, &local_handle);
+ if (res != DNSSD_ERROR_NONE)
+ return res;
if (value == NULL || length == NULL) {
DNSSD_LOGE("Invalid Parameter");
if (local_handle->op_type == DNSSD_TYPE_FOUND) {
- dnssd_found_data_s *found = NULL; //LCOV_EXCL_LINE
- found = GET_FOUND_DATA_P(local_handle); //LCOV_EXCL_LINE
+ dnssd_found_data_s *found = NULL;
+ found = GET_FOUND_DATA_P(local_handle);
- *value = g_strndup(found->txt_record, found->txt_len); //LCOV_EXCL_LINE
- *length = found->txt_len; //LCOV_EXCL_LINE
+ *value = g_strndup(found->txt_record, found->txt_len);
+ *length = found->txt_len;
} else {
dnssd_register_data_s *reg = NULL;