diff options
| -rw-r--r-- | hcid/dbus-manager.c | 261 | 
1 files changed, 0 insertions, 261 deletions
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 480ffd24..b9e1ef55 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -53,8 +53,6 @@  static int default_adapter_id = -1; -static uint32_t next_handle = 0x10000; -  static DBusHandlerResult interface_version(DBusConnection *conn,  						DBusMessage *msg, void *data)  { @@ -284,262 +282,6 @@ static DBusHandlerResult activate_service(DBusConnection *conn,  	return DBUS_HANDLER_RESULT_HANDLED;  } - -static sdp_buf_t *service_record_extract(DBusMessageIter *iter) -{ -	sdp_buf_t *sdp_buf; -	const uint8_t *buff; -	int len = -1; - -	dbus_message_iter_get_fixed_array(iter, &buff, &len); -	if (len < 0) -		return NULL; - -	sdp_buf = malloc(sizeof(sdp_buf_t)); -	if (!sdp_buf) -		return NULL; - -	memset(sdp_buf, 0, sizeof(sdp_buf_t)); -	sdp_buf->data = malloc(len); -	sdp_buf->data_size = len; -	sdp_buf->buf_size = len; -	memcpy(sdp_buf->data, buff, len); - -	return sdp_buf; -} - -static DBusHandlerResult add_service_record(DBusConnection *conn, -						DBusMessage *msg, void *data) -{ -	struct service *service; -	DBusMessageIter iter, array_iter; -	DBusMessage *reply; -	struct binary_record *rec; -	const char *path; -	int err; - -	if (!hcid_dbus_use_experimental()) -		return error_unknown_method(conn, msg); - -	/* Check if it is an array of bytes */ -	if (strcmp(dbus_message_get_signature(msg), "say")) -		return error_invalid_arguments(conn, msg); - -	dbus_message_iter_init(msg, &iter); -	dbus_message_iter_get_basic(&iter, &path); - -	if (!dbus_connection_get_object_path_data(conn, path, -						(void *) &service)) { -		/* If failed the path is invalid! */ -		return error_invalid_arguments(conn, msg); -	} - -	if (!service || strcmp(dbus_message_get_sender(msg), service->bus_name)) -		return error_not_authorized(conn, msg); - -	dbus_message_iter_next(&iter); -	dbus_message_iter_recurse(&iter, &array_iter); - -	reply = dbus_message_new_method_return(msg); -	if (!reply) -		return DBUS_HANDLER_RESULT_NEED_MEMORY; - -	rec = binary_record_new(); -	if (!rec) -		return DBUS_HANDLER_RESULT_NEED_MEMORY; - -	rec->buf = service_record_extract(&array_iter); -	if (!rec->buf) { -		binary_record_free(rec); -		dbus_message_unref(reply); -		return error_invalid_arguments(conn, msg); -	} - -	/* Assign a new handle */ -	rec->ext_handle = next_handle++; - -	if (service->bus_name) { -		uint32_t handle = 0; - -		if (register_sdp_record(rec->buf->data,	rec->buf->data_size, &handle) < 0) { -			err = errno; -			error("Service record registration failed: %s (%d)", -							strerror(err), err); -			goto fail; -		} - -		rec->handle = handle; -	} - -	service->records = g_slist_append(service->records, rec); - -	dbus_message_append_args(reply, -				DBUS_TYPE_UINT32, &rec->ext_handle, -				DBUS_TYPE_INVALID); - -	return send_message_and_unref(conn, reply); - -fail: -	binary_record_free(rec); -	dbus_message_unref(reply); - -	return error_failed(conn, msg, err); -} - -static DBusHandlerResult add_service_record_xml(DBusConnection *conn, -						DBusMessage *msg, void *data) -{ -	struct service *service; -	DBusMessage *reply; -	struct binary_record *rec; -	sdp_record_t *sdp_rec; -	const char *path; -	const char *record; -	int err; - -	if (!hcid_dbus_use_experimental()) -		return error_unknown_method(conn, msg); - -	if (!dbus_message_get_args(msg, NULL, -				DBUS_TYPE_STRING, &path, -				DBUS_TYPE_STRING, &record, -				DBUS_TYPE_INVALID)) -		return error_invalid_arguments(conn, msg); - -	if (!dbus_connection_get_object_path_data(conn, path, -						(void *) &service)) { -		/* If failed the path is invalid! */ -		return error_invalid_arguments(conn, msg); -	} - -	if (!service || strcmp(dbus_message_get_sender(msg), service->bus_name)) -		return error_not_authorized(conn, msg); - -	reply = dbus_message_new_method_return(msg); -	if (!reply) -		return DBUS_HANDLER_RESULT_NEED_MEMORY; - -	sdp_rec = sdp_xml_parse_record(record, strlen(record)); -	if (!sdp_rec) { -		error("Parsing of XML service record failed"); -		dbus_message_unref(reply); -		return error_invalid_arguments(conn, msg); -	} - -        /* TODO: Is this correct? We remove the record handle attribute -	   (if it exists) so SDP server assigns a new one */ -        sdp_attr_remove(sdp_rec, 0x0); - -	rec = binary_record_new(); -	if (!rec) { -		sdp_record_free(sdp_rec); -		dbus_message_unref(reply); -		return DBUS_HANDLER_RESULT_NEED_MEMORY; -	} - -	rec->buf = malloc(sizeof(sdp_buf_t)); - -	if (!rec->buf) { -		sdp_record_free(sdp_rec); -		binary_record_free(rec); -		dbus_message_unref(reply); -		return DBUS_HANDLER_RESULT_NEED_MEMORY; -	} - -	/* Generate binary record */ -	if (sdp_gen_record_pdu(sdp_rec, rec->buf) != 0) { -		sdp_record_free(sdp_rec); -		binary_record_free(rec); -		dbus_message_unref(reply); -		return DBUS_HANDLER_RESULT_NEED_MEMORY; -	} - -	sdp_record_free(sdp_rec); - -	/* Assign a new handle */ -	rec->ext_handle = next_handle++; - -	if (service->bus_name) { -		uint32_t handle = 0; - -		if (register_sdp_record(rec->buf->data,	rec->buf->data_size, &handle) < 0) { -			err = errno; -			error("Service record registration failed: %s (%d)", -							strerror(err), err); -			goto fail; -		} - -		rec->handle = handle; -	} - -	service->records = g_slist_append(service->records, rec); - -	dbus_message_append_args(reply, -				DBUS_TYPE_UINT32, &rec->ext_handle, -				DBUS_TYPE_INVALID); - -	return send_message_and_unref(conn, reply); - -fail: -	binary_record_free(rec); -	dbus_message_unref(reply); - -	return error_failed(conn, msg, err); -} - -static DBusHandlerResult remove_service_record(DBusConnection *conn, -						DBusMessage *msg, void *data) -{ -	struct service *service; -	struct binary_record *rec; -	DBusMessage *reply; -	GSList *l; -	const char *path; -	uint32_t handle; - -	if (!hcid_dbus_use_experimental()) -		return error_unknown_method(conn, msg); - -	if (!dbus_message_get_args(msg, NULL, -				DBUS_TYPE_STRING, &path, -				DBUS_TYPE_UINT32, &handle, -				DBUS_TYPE_INVALID)) -		return error_invalid_arguments(conn, msg); - -	if (!dbus_connection_get_object_path_data(conn, path, -						(void *) &service)) { -		/* If failed the path is invalid! */ -		return error_invalid_arguments(conn, msg); -	} - -	if (!service || strcmp(dbus_message_get_sender(msg), service->bus_name)) -		return error_not_authorized(conn, msg); - - -	l = g_slist_find_custom(service->records, &handle, (GCompareFunc) binary_record_cmp); -	if (!l) -		return error_record_does_not_exist(conn, msg); - -	reply = dbus_message_new_method_return(msg); -	if (!reply) -		return DBUS_HANDLER_RESULT_NEED_MEMORY; - -	rec = l->data; -	service->records = g_slist_remove(service->records, rec); - -	/* If the service is running: remove it from the from sdpd */ -	if (service->bus_name && rec->handle != 0xffffffff) { -		if (unregister_sdp_record(rec->handle) < 0) { -			error("Service record unregistration failed: %s (%d)", -							strerror(errno), errno); -		} -	} - -	binary_record_free(rec); - -	return send_message_and_unref(conn, reply); -} -  static struct service_data methods[] = {  	{ "InterfaceVersion",		interface_version		},  	{ "DefaultAdapter",		default_adapter			}, @@ -548,9 +290,6 @@ static struct service_data methods[] = {  	{ "FindService",		find_service			},  	{ "ListServices",		list_services			},  	{ "ActivateService",		activate_service		}, -	{ "AddServiceRecord",		add_service_record		}, -	{ "AddServiceRecordFromXML", 	add_service_record_xml		}, -	{ "RemoveServiceRecord",	remove_service_record		},  	{ NULL, NULL }  };  | 
