diff options
| author | Marcel Holtmann <marcel@holtmann.org> | 2008-06-03 17:47:43 +0000 | 
|---|---|---|
| committer | Marcel Holtmann <marcel@holtmann.org> | 2008-06-03 17:47:43 +0000 | 
| commit | a853f0013160472751d39b68af8c40ce5e5d6336 (patch) | |
| tree | f37e1c45cceb58373a380bda634b4ad8bab230d4 | |
| parent | 83e66f3aef8b1d298ca9033d0f53337c88417c37 (diff) | |
Change database interface to use gdbus API and remove broken methods
| -rw-r--r-- | hcid/dbus-api.txt | 32 | ||||
| -rw-r--r-- | hcid/dbus-common.c | 2 | ||||
| -rw-r--r-- | hcid/dbus-database.c | 242 | ||||
| -rw-r--r-- | hcid/dbus-database.h | 6 | 
4 files changed, 57 insertions, 225 deletions
| diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt index 6c87af84..333ffc9a 100644 --- a/hcid/dbus-api.txt +++ b/hcid/dbus-api.txt @@ -243,19 +243,7 @@ Service		org.bluez  Interface	org.bluez.Database  Object path	/org/bluez -Methods		void RegisterService(string identifier, string name, string description) - -			This method registers a new service specified by -			its unique identifier. This is only needed for -			services that are not started through the -			Bluetooth daemon. - -		void UnregisterService(string identifier) - -			This method unregisters a service specified by -			its unique identifier. - -		uint32 AddServiceRecord(array{byte}) +Methods		uint32 AddServiceRecord(array{byte})  			Adds a new service record and returns the assigned  			record handle. @@ -300,24 +288,6 @@ Methods		void RegisterService(string identifier, string name, string description  					 org.bluez.Error.DoesNotExist  					 org.bluez.Error.Failed -		void RequestAuthorization(string address, string uuid) - -			This method gets called when a service wants to check -			if a remote device is authorized to perform some -			action. The authorization request is forwarded to an -			authorization agent. - -			The address parameter is the Bluetooth address of the -			remote device and the uuid is the identifier of the -			profile requesting the authorization. This parameter -			can also be left blank. - -		void CancelAuthorizationRequest(string address, string uuid) - -			This method cancels an authorization process requested -			by a previous call to RequestAuthorization(). The -			address and uuid parameters must match. -  Adapter hierarchy  ================= diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c index 233bab27..6028bc78 100644 --- a/hcid/dbus-common.c +++ b/hcid/dbus-common.c @@ -282,6 +282,8 @@ void hcid_dbus_exit(void)  	release_default_auth_agent();  	release_services(conn); +	database_cleanup(conn, BASE_PATH); +  	/* Unregister all paths in Adapter path hierarchy */  	if (!dbus_connection_list_registered(conn, BASE_PATH, &children))  		goto done; diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 7dcc6b01..c1ac2b97 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -36,8 +36,6 @@  #include <bluetooth/sdp.h>  #include <bluetooth/sdp_lib.h> -#include <glib.h> -#include <dbus/dbus.h>  #include <gdbus.h>  #include "hcid.h" @@ -88,10 +86,26 @@ static void exit_callback(void *user_data)  	g_free(user_record);  } -static DBusHandlerResult add_service_record(DBusConnection *conn, +static inline DBusMessage *invalid_arguments(DBusMessage *msg) +{ +	return g_dbus_create_error(msg, ERROR_INTERFACE ".InvalidArguments", +					"Invalid arguments in method call"); +} + +static inline DBusMessage *not_available(DBusMessage *msg) +{ +	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable", +							"Not Available"); +} + +static inline DBusMessage *failed(DBusMessage *msg) +{ +	return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed", "Failed"); +} + +static DBusMessage *add_service_record(DBusConnection *conn,  						DBusMessage *msg, void *data)  { -	DBusMessage *reply;  	DBusMessageIter iter, array;  	const char *sender;  	struct record_data *user_record; @@ -104,24 +118,24 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,  	dbus_message_iter_get_fixed_array(&array, &record, &len);  	if (len <= 0) -		return error_invalid_arguments(conn, msg, NULL); +		return invalid_arguments(msg);  	sdp_record = sdp_extract_pdu(record, &scanned);  	if (!sdp_record) {  		error("Parsing of service record failed"); -		return error_failed_errno(conn, msg, EIO); +		return failed(msg);  	}  	if (scanned != len) {  		error("Size mismatch of service record");  		sdp_record_free(sdp_record); -		return error_failed_errno(conn, msg, EIO); +		return failed(msg);  	}  	if (add_record_to_server(BDADDR_ANY, sdp_record) < 0) {  		error("Failed to register service record");  		sdp_record_free(sdp_record); -		return error_failed_errno(conn, msg, EIO); +		return failed(msg);  	}  	user_record = g_new0(struct record_data, 1); @@ -139,14 +153,8 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,  								user_record,  								NULL); -	reply = dbus_message_new_method_return(msg); -	if (!reply) -		return DBUS_HANDLER_RESULT_NEED_MEMORY; - -	dbus_message_append_args(reply, DBUS_TYPE_UINT32, &user_record->handle, -					DBUS_TYPE_INVALID); - -	return send_message_and_unref(conn, reply); +	return g_dbus_create_reply(msg, DBUS_TYPE_UINT32, &user_record->handle, +							DBUS_TYPE_INVALID);  }  int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, @@ -183,32 +191,25 @@ int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src,  	return 0;  } -static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, +static DBusMessage *add_service_record_from_xml(DBusConnection *conn,  						DBusMessage *msg, void *data)  { -	DBusMessage *reply;  	const char *sender, *record;  	dbus_uint32_t handle;  	int err;  	if (dbus_message_get_args(msg, NULL,  			DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); +		return NULL;  	sender = dbus_message_get_sender(msg); -	reply = dbus_message_new_method_return(msg); -	if (!reply) -		return DBUS_HANDLER_RESULT_NEED_MEMORY; -  	err = add_xml_record(conn, sender, BDADDR_ANY, record, &handle);  	if (err < 0) -		return error_failed_errno(conn, msg, err); +		return failed(msg); -	dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, +	return g_dbus_create_reply(msg, DBUS_TYPE_UINT32, &handle,  							DBUS_TYPE_INVALID); - -	return send_message_and_unref(conn, reply);  }  static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg, @@ -236,7 +237,7 @@ static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg,  	return dbus_message_new_method_return(msg);  } -static DBusHandlerResult update_service_record(DBusConnection *conn, +static DBusMessage *update_service_record(DBusConnection *conn,  						DBusMessage *msg, void *data)  {  	struct record_data *user_record; @@ -253,26 +254,25 @@ static DBusHandlerResult update_service_record(DBusConnection *conn,  	dbus_message_iter_get_fixed_array(&array, &bin_record, &size);  	if (size <= 0) -		return error_invalid_arguments(conn, msg, NULL); +		return invalid_arguments(msg);  	user_record = find_record(handle, dbus_message_get_sender(msg));  	if (!user_record) -		return error_not_available(conn, msg); +		return not_available(msg);  	sdp_record = sdp_extract_pdu(bin_record, &scanned);  	if (!sdp_record) {  		error("Parsing of service record failed"); -		return error_invalid_arguments(conn, msg, NULL); +		return invalid_arguments(msg);  	}  	if (scanned != size) {  		error("Size mismatch of service record");  		sdp_record_free(sdp_record); -		return error_invalid_arguments(conn, msg, NULL); +		return invalid_arguments(msg);  	} -	return send_message_and_unref(conn, -			update_record(conn, msg, BDADDR_ANY, handle, sdp_record)); +	return update_record(conn, msg, BDADDR_ANY, handle, sdp_record);  }  DBusMessage *update_xml_record(DBusConnection *conn, @@ -288,15 +288,11 @@ DBusMessage *update_xml_record(DBusConnection *conn,  				DBUS_TYPE_UINT32, &handle,  				DBUS_TYPE_STRING, &record,  				DBUS_TYPE_INVALID) == FALSE) -		return g_dbus_create_error(msg, -				ERROR_INTERFACE ".InvalidArguments", -				"Invalid arguments in method call"); +		return NULL;  	len = (record ? strlen(record) : 0);  	if (len == 0) -		return g_dbus_create_error(msg, -				ERROR_INTERFACE ".InvalidArguments", -				"Invalid arguments in method call"); +		return invalid_arguments(msg);  	user_record = find_record(handle, dbus_message_get_sender(msg));  	if (!user_record) @@ -316,11 +312,10 @@ DBusMessage *update_xml_record(DBusConnection *conn,  	return update_record(conn, msg, src, handle, sdp_record);  } -static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, +static DBusMessage *update_service_record_from_xml(DBusConnection *conn,  						DBusMessage *msg, void *data)  { -	return send_message_and_unref(conn, -			update_xml_record(conn, msg, BDADDR_ANY)); +	return update_xml_record(conn, msg, BDADDR_ANY);  }  int remove_record(DBusConnection *conn, const char *sender, @@ -346,171 +341,40 @@ int remove_record(DBusConnection *conn, const char *sender,  	return 0;  } -static DBusHandlerResult remove_service_record(DBusConnection *conn, +static DBusMessage *remove_service_record(DBusConnection *conn,  						DBusMessage *msg, void *data)  { -	DBusMessage *reply;  	dbus_uint32_t handle;  	const char *sender;  	if (dbus_message_get_args(msg, NULL,  			DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); +		return NULL;  	sender = dbus_message_get_sender(msg);  	if (remove_record(conn, sender, handle) < 0) -		return error_not_available(conn, msg); +		return not_available(msg); -	reply = dbus_message_new_method_return(msg); -	if (!reply) -		return DBUS_HANDLER_RESULT_NEED_MEMORY; - -	return send_message_and_unref(conn, reply); -} - -static DBusHandlerResult register_service_old(DBusConnection *conn, -						DBusMessage *msg, void *data) -{ -	const char *ident, *name, *desc; - -	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, -			DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, -						DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); - -	return error_failed_errno(conn, msg, EIO); +	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);  } -static DBusHandlerResult unregister_service_old(DBusConnection *conn, -						DBusMessage *msg, void *data) -{ -	struct service *service; -	const char *ident; - -	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, -						DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); - -	service = search_service(ident); -	if (!service) -		return error_service_does_not_exist(conn, msg); - -	return error_failed_errno(conn, msg, EIO); -} - -static DBusHandlerResult request_authorization_old(DBusConnection *conn, -						DBusMessage *msg, void *data) -{ -	const char *sender, *address, *uuid; -	struct service *service; -	char path[MAX_PATH_LENGTH]; -	bdaddr_t bdaddr; -	gboolean trusted; -	int adapter_id; - -	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, -			DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); - -	sender = dbus_message_get_sender(msg); - -	service = search_service_by_uuid(uuid); -	if (!service) -		service = search_service(sender); - -	if (!service) { -		debug("Got RequestAuthorization from non-service owner %s", -				sender); -		return error_not_authorized(conn, msg); -	} - -	str2ba(address, &bdaddr); -	adapter_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr); -	if (adapter_id < 0) -		return error_not_connected(conn, msg); - -	hci_devba(adapter_id, &bdaddr); - -	trusted = read_trust(&bdaddr, address, GLOBAL_TRUST); -	if (!trusted) -		trusted = read_trust(BDADDR_ANY, address, service->ident); - -	if (trusted) { -		DBusMessage *reply; - -		reply = dbus_message_new_method_return(msg); -		if (!reply) -			return DBUS_HANDLER_RESULT_NEED_MEMORY; - -		return send_message_and_unref(conn, reply); -	} - -	snprintf(path, sizeof(path), "/org/bluez/hci%d", adapter_id); -	return handle_authorize_request_old(conn, msg, -				service, path, address, uuid); -} - -static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, -						DBusMessage *msg, void *data) -{ -	const char *sender, *address, *uuid; -	struct service *service; - -	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, -			DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); - -	sender = dbus_message_get_sender(msg); - -	service = search_service_by_uuid(uuid); -	if (!service) -		service = search_service(sender); - -	if (!service) -		return error_not_authorized(conn, msg); - -	return cancel_authorize_request_old(conn, msg, service, address, uuid); -} - -static DBusMethodVTable database_methods[] = { -	{ "AddServiceRecord",			add_service_record,		"ay",	"u"	}, -	{ "AddServiceRecordFromXML",		add_service_record_from_xml,	"s",	"u"	}, -	{ "UpdateServiceRecord",		update_service_record,		"uay",	""	}, -	{ "UpdateServiceRecordFromXML",		update_service_record_from_xml,	"us",	""	}, -	{ "RemoveServiceRecord",		remove_service_record,		"u",	""	}, -	{ "RegisterService",			register_service_old,		"sss",	""	}, -	{ "UnregisterService",			unregister_service_old,		"s",	""	}, -	{ "RequestAuthorization",		request_authorization_old,	"ss",	""	}, -	{ "CancelAuthorizationRequest",		cancel_authorization_request,	"ss",	""	}, -	{ NULL, NULL, NULL, NULL } +static GDBusMethodTable database_methods[] = { +	{ "AddServiceRecord",		"ay",  "u",	add_service_record		}, +	{ "AddServiceRecordFromXML",	"s",   "u",	add_service_record_from_xml	}, +	{ "UpdateServiceRecord",	"uay", "",	update_service_record		}, +	{ "UpdateServiceRecordFromXML",	"us",  "",	update_service_record_from_xml	}, +	{ "RemoveServiceRecord",	"u",   "",	remove_service_record		}, +	{ }  };  dbus_bool_t database_init(DBusConnection *conn, const char *path)  { -	return dbus_connection_register_interface(conn, path, -							DATABASE_INTERFACE, -							database_methods, -							NULL, NULL); +	return g_dbus_register_interface(conn, path, DATABASE_INTERFACE, +				database_methods, NULL, NULL, NULL, NULL);  } -DBusHandlerResult database_message(DBusConnection *conn, -						DBusMessage *msg, void *data) +void database_cleanup(DBusConnection *conn, const char *path)  { -	DBusMethodVTable *current; - -	for (current = database_methods; -			current->name && current->message_function; current++) { -		if (!dbus_message_is_method_call(msg, DATABASE_INTERFACE, -								current->name)) -			continue; - -		if (dbus_message_has_signature(msg, current->signature)) { -			debug("%s: %s.%s()", dbus_message_get_path(msg), -					DATABASE_INTERFACE, current->name); -			return current->message_function(conn, msg, data); -		} -	} - -	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +	g_dbus_unregister_interface(conn, path, DATABASE_INTERFACE);  } diff --git a/hcid/dbus-database.h b/hcid/dbus-database.h index f0c4a4a5..c173afaf 100644 --- a/hcid/dbus-database.h +++ b/hcid/dbus-database.h @@ -25,9 +25,7 @@  #define DATABASE_INTERFACE "org.bluez.Database"  dbus_bool_t database_init(DBusConnection *conn, const char *path); - -DBusHandlerResult database_message(DBusConnection *conn, -						DBusMessage *msg, void *data); +void database_cleanup(DBusConnection *conn, const char *path);  int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src,  				const char *record, dbus_uint32_t *handle); @@ -35,5 +33,3 @@ DBusMessage *update_xml_record(DBusConnection *conn,  				DBusMessage *msg, bdaddr_t *src);  int remove_record(DBusConnection *conn, const char *sender,  						dbus_uint32_t handle); - -void set_sdp_server_enable(void); | 
