Cleanup dbus-database.c.

This commit is contained in:
Luiz Augusto von Dentz 2008-07-03 16:50:22 -03:00
parent d3ea4d9816
commit c7b8998896
2 changed files with 0 additions and 162 deletions

View File

@ -100,62 +100,6 @@ static inline DBusMessage *failed(DBusMessage *msg)
return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed", "Failed"); return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed", "Failed");
} }
static DBusMessage *add_service_record(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessageIter iter, array;
const char *sender;
struct record_data *user_record;
sdp_record_t *sdp_record;
const uint8_t *record;
int scanned, len = -1;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_recurse(&iter, &array);
dbus_message_iter_get_fixed_array(&array, &record, &len);
if (len <= 0)
return invalid_arguments(msg);
sdp_record = sdp_extract_pdu_safe(record, len, &scanned);
if (!sdp_record) {
error("Parsing of service record failed");
return failed(msg);
}
if (scanned != len) {
error("Size mismatch of service record");
sdp_record_free(sdp_record);
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 failed(msg);
}
user_record = g_new0(struct record_data, 1);
user_record->handle = sdp_record->handle;
sender = dbus_message_get_sender(msg);
user_record->sender = g_strdup(sender);
records = g_slist_append(records, user_record);
user_record->listener_id = g_dbus_add_disconnect_watch(conn, sender,
exit_callback,
user_record,
NULL);
debug("listener_id %d", user_record->listener_id);
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, int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src,
const char *record, dbus_uint32_t *handle) const char *record, dbus_uint32_t *handle)
{ {
@ -192,27 +136,6 @@ int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src,
return 0; return 0;
} }
static DBusMessage *add_service_record_from_xml(DBusConnection *conn,
DBusMessage *msg, void *data)
{
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 NULL;
sender = dbus_message_get_sender(msg);
err = add_xml_record(conn, sender, BDADDR_ANY, record, &handle);
if (err < 0)
return failed(msg);
return g_dbus_create_reply(msg, DBUS_TYPE_UINT32, &handle,
DBUS_TYPE_INVALID);
}
static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg, static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg,
bdaddr_t *src, dbus_uint32_t handle, sdp_record_t *sdp_record) bdaddr_t *src, dbus_uint32_t handle, sdp_record_t *sdp_record)
{ {
@ -238,44 +161,6 @@ static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg,
return dbus_message_new_method_return(msg); return dbus_message_new_method_return(msg);
} }
static DBusMessage *update_service_record(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct record_data *user_record;
DBusMessageIter iter, array;
sdp_record_t *sdp_record;
dbus_uint32_t handle;
const uint8_t *bin_record;
int scanned, size = -1;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &handle);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &array);
dbus_message_iter_get_fixed_array(&array, &bin_record, &size);
if (size <= 0)
return invalid_arguments(msg);
user_record = find_record(handle, dbus_message_get_sender(msg));
if (!user_record)
return not_available(msg);
sdp_record = sdp_extract_pdu_safe(bin_record, size, &scanned);
if (!sdp_record) {
error("Parsing of service record failed");
return invalid_arguments(msg);
}
if (scanned != size) {
error("Size mismatch of service record");
sdp_record_free(sdp_record);
return invalid_arguments(msg);
}
return update_record(conn, msg, BDADDR_ANY, handle, sdp_record);
}
DBusMessage *update_xml_record(DBusConnection *conn, DBusMessage *update_xml_record(DBusConnection *conn,
DBusMessage *msg, bdaddr_t *src) DBusMessage *msg, bdaddr_t *src)
{ {
@ -313,12 +198,6 @@ DBusMessage *update_xml_record(DBusConnection *conn,
return update_record(conn, msg, src, handle, sdp_record); return update_record(conn, msg, src, handle, sdp_record);
} }
static DBusMessage *update_service_record_from_xml(DBusConnection *conn,
DBusMessage *msg, void *data)
{
return update_xml_record(conn, msg, BDADDR_ANY);
}
int remove_record(DBusConnection *conn, const char *sender, int remove_record(DBusConnection *conn, const char *sender,
dbus_uint32_t handle) dbus_uint32_t handle)
{ {
@ -338,41 +217,3 @@ int remove_record(DBusConnection *conn, const char *sender,
return 0; return 0;
} }
static DBusMessage *remove_service_record(DBusConnection *conn,
DBusMessage *msg, void *data)
{
dbus_uint32_t handle;
const char *sender;
if (dbus_message_get_args(msg, NULL,
DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE)
return NULL;
sender = dbus_message_get_sender(msg);
if (remove_record(conn, sender, handle) < 0)
return not_available(msg);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
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 g_dbus_register_interface(conn, path, DATABASE_INTERFACE,
database_methods, NULL, NULL, NULL, NULL);
}
void database_cleanup(DBusConnection *conn, const char *path)
{
g_dbus_unregister_interface(conn, path, DATABASE_INTERFACE);
}

View File

@ -24,9 +24,6 @@
#define DATABASE_INTERFACE "org.bluez.Database" #define DATABASE_INTERFACE "org.bluez.Database"
dbus_bool_t database_init(DBusConnection *conn, const char *path);
void database_cleanup(DBusConnection *conn, const char *path);
int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src,
const char *record, dbus_uint32_t *handle); const char *record, dbus_uint32_t *handle);
DBusMessage *update_xml_record(DBusConnection *conn, DBusMessage *update_xml_record(DBusConnection *conn,