diff options
| author | Marcel Holtmann <marcel@holtmann.org> | 2008-03-15 02:23:02 +0000 | 
|---|---|---|
| committer | Marcel Holtmann <marcel@holtmann.org> | 2008-03-15 02:23:02 +0000 | 
| commit | 15884ba98a8ddec4b2ca7fb9fa21a1bc82faa3eb (patch) | |
| tree | 3ce67800acff1ce55f4a1254079eb35937a150b5 | |
| parent | ea7a10e0084b203f1e414cb163a9b5a998d80a83 (diff) | |
Implement basic support for new service record registration
| -rw-r--r-- | hcid/adapter.c | 28 | ||||
| -rw-r--r-- | hcid/dbus-database.c | 86 | ||||
| -rw-r--r-- | hcid/dbus-database.h | 7 | 
3 files changed, 88 insertions, 33 deletions
| diff --git a/hcid/adapter.c b/hcid/adapter.c index 2c4cdc00..b18b054f 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -60,6 +60,7 @@  #include "dbus-helper.h"  #include "dbus-hci.h"  #include "dbus-sdp.h" +#include "dbus-database.h"  #include "dbus-error.h"  #include "error.h"  #include "glib-helper.h" @@ -3767,37 +3768,48 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,  						DBusMessage *msg, void *data)  {  	DBusMessage *reply; -	const char *record; +	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); +	sender = dbus_message_get_sender(msg); + +	err = add_xml_record(conn, sender, record, &handle); +	if (err < 0) +		return error_failed_errno(conn, msg, err); +  	reply = dbus_message_new_method_return(msg);  	if (!reply)  		return DBUS_HANDLER_RESULT_NEED_MEMORY; -	handle = 0; -  	dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle,  							DBUS_TYPE_INVALID);  	return send_message_and_unref(conn, reply);  } -  static DBusHandlerResult update_service_record(DBusConnection *conn,  						DBusMessage *msg, void *data)  {  	DBusMessage *reply;  	dbus_uint32_t handle; -	const char *record; +	const char *sender, *record; +	int err;  	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle,  			DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE)  		return error_invalid_arguments(conn, msg, NULL); +	sender = dbus_message_get_sender(msg); + +	err = update_xml_record(conn, sender, handle, record); +	if (err < 0) +		return error_failed_errno(conn, msg, err); +  	reply = dbus_message_new_method_return(msg);  	if (!reply)  		return DBUS_HANDLER_RESULT_NEED_MEMORY; @@ -3810,11 +3822,17 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn,  {  	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); +	sender = dbus_message_get_sender(msg); + +	if (remove_record(conn, sender, handle) < 0) +		return error_not_available(conn, msg); +  	reply = dbus_message_new_method_return(msg);  	if (!reply)  		return DBUS_HANDLER_RESULT_NEED_MEMORY; diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index c5bcd6ae..aa8a7467 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -166,25 +166,19 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,  	return send_message_and_unref(conn, reply);  } -static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, -						DBusMessage *msg, void *data) +int add_xml_record(DBusConnection *conn, const char *sender, +				const char *record, dbus_uint32_t *handle)  { -	DBusMessage *reply; -	const char *sender, *record;  	struct record_data *user_record;  	sdp_record_t *sdp_record; -	if (dbus_message_get_args(msg, NULL, -			DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); -  	user_record = g_new0(struct record_data, 1);  	sdp_record = sdp_xml_parse_record(record, strlen(record));  	if (!sdp_record) {  		error("Parsing of XML service record failed");  		g_free(user_record); -		return error_failed_errno(conn, msg, EIO); +		return -EIO;  	}  	if (sdp_server_enable) { @@ -192,7 +186,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn,  			error("Failed to register service record");  			g_free(user_record);  			sdp_record_free(sdp_record); -			return error_failed_errno(conn, msg, EIO); +			return -EIO;  		}  		user_record->handle = sdp_record->handle; @@ -201,7 +195,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn,  			error("Failed to register service record");  			g_free(user_record);  			sdp_record_free(sdp_record); -			return error_failed_errno(conn, msg, EIO); +			return -EIO;  		}  		user_record->handle = sdp_record->handle; @@ -209,25 +203,45 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn,  		sdp_record_free(sdp_record);  	} -	sender = dbus_message_get_sender(msg); -  	user_record->sender = g_strdup(sender);  	records = g_slist_append(records, user_record);  	name_listener_add(conn, sender, exit_callback, user_record); +	*handle = user_record->handle; + +	return 0; +} + +static DBusHandlerResult 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); + +	sender = dbus_message_get_sender(msg); +  	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); +	err = add_xml_record(conn, sender, record, &handle); +	if (err < 0) +		return error_failed_errno(conn, msg, err); + +	dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, +							DBUS_TYPE_INVALID);  	return send_message_and_unref(conn, reply);  } -  static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg,  				dbus_uint32_t handle, sdp_record_t *sdp_record)  { @@ -300,6 +314,12 @@ static DBusHandlerResult update_service_record(DBusConnection *conn,  	return update_record(conn, msg, handle, sdp_record);  } +int update_xml_record(DBusConnection *conn, const char *sender, +				dbus_uint32_t handle, const char *record) +{ +	return -EIO; +} +  static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn,  						DBusMessage *msg, void *data)  { @@ -333,23 +353,14 @@ static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn,  	return update_record(conn, msg, handle, sdp_record);  } -static DBusHandlerResult remove_service_record(DBusConnection *conn, -						DBusMessage *msg, void *data) +int remove_record(DBusConnection *conn, const char *sender, +						dbus_uint32_t handle)  { -	DBusMessage *reply; -	dbus_uint32_t handle; -	const char *sender;  	struct record_data *user_record; -	if (dbus_message_get_args(msg, NULL, -			DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) -		return error_invalid_arguments(conn, msg, NULL); - -	sender = dbus_message_get_sender(msg); -  	user_record = find_record(handle, sender);  	if (!user_record) -		return error_not_available(conn, msg); +		return -1;  	name_listener_remove(conn, sender, exit_callback, user_record); @@ -365,6 +376,25 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn,  	g_free(user_record); +	return 0; +} + +static DBusHandlerResult 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); + +	sender = dbus_message_get_sender(msg); + +	if (remove_record(conn, sender, handle) < 0) +		return error_not_available(conn, msg); +  	reply = dbus_message_new_method_return(msg);  	if (!reply)  		return DBUS_HANDLER_RESULT_NEED_MEMORY; diff --git a/hcid/dbus-database.h b/hcid/dbus-database.h index 21b8921b..832c1fb5 100644 --- a/hcid/dbus-database.h +++ b/hcid/dbus-database.h @@ -29,4 +29,11 @@ dbus_bool_t database_init(DBusConnection *conn, const char *path);  DBusHandlerResult database_message(DBusConnection *conn,  						DBusMessage *msg, void *data); +int add_xml_record(DBusConnection *conn, const char *sender, +				const char *record, dbus_uint32_t *handle); +int update_xml_record(DBusConnection *conn, const char *sender, +				dbus_uint32_t handle, const char *record); +int remove_record(DBusConnection *conn, const char *sender, +						dbus_uint32_t handle); +  void set_sdp_server_enable(void); | 
