diff options
-rw-r--r-- | hcid/dbus-common.c | 16 | ||||
-rw-r--r-- | hcid/dbus-common.h | 3 | ||||
-rw-r--r-- | hcid/dbus-database.c | 51 | ||||
-rw-r--r-- | hcid/dbus-database.h | 2 | ||||
-rw-r--r-- | hcid/main.c | 5 |
5 files changed, 61 insertions, 16 deletions
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c index c84b7c37..f70f1c2f 100644 --- a/hcid/dbus-common.c +++ b/hcid/dbus-common.c @@ -368,7 +368,7 @@ int hcid_dbus_init(void) return 0; } -int register_sdp_record(uint8_t *data, uint32_t size, uint32_t *handle) +int register_sdp_binary(uint8_t *data, uint32_t size, uint32_t *handle) { if (!sess) { sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); @@ -383,6 +383,20 @@ int register_sdp_record(uint8_t *data, uint32_t size, uint32_t *handle) data, size, 0, handle); } +int register_sdp_record(sdp_record_t *rec) +{ + if (!sess) { + sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); + if (!sess) { + error("Can't connect to SDP daemon:(%s, %d)", + strerror(errno), errno); + return -1; + } + } + + return sdp_device_record_register(sess, BDADDR_ANY, rec, 0); +} + int unregister_sdp_record(uint32_t handle) { if (!sess) diff --git a/hcid/dbus-common.h b/hcid/dbus-common.h index def64780..4039a9cc 100644 --- a/hcid/dbus-common.h +++ b/hcid/dbus-common.h @@ -54,7 +54,8 @@ DBusHandlerResult handle_method_call(DBusConnection *conn, DBusMessage *msg, voi void hcid_dbus_exit(void); int hcid_dbus_init(void); -int register_sdp_record(uint8_t *data, uint32_t size, uint32_t *handle); +int register_sdp_binary(uint8_t *data, uint32_t size, uint32_t *handle); +int register_sdp_record(sdp_record_t *rec); int unregister_sdp_record(uint32_t handle); void cleanup_sdp_session(void); diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index f526b60e..5da84cfa 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -43,6 +43,8 @@ #include "dbus-error.h" #include "dbus-database.h" +static int sdp_server_enable = 0; + static GSList *records = NULL; struct record_data { @@ -69,7 +71,10 @@ static void exit_callback(const char *name, void *user_data) records = g_slist_remove(records, user_record); - remove_record_from_server(user_record->handle); + if (sdp_server_enable) + remove_record_from_server(user_record->handle); + else + unregister_sdp_record(user_record->handle); free(user_record); } @@ -82,7 +87,6 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, const char *sender; struct record_data *user_record; const uint8_t *record; - uint32_t size = 0; int len = -1; dbus_message_iter_init(msg, &iter); @@ -98,13 +102,17 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, memset(user_record, 0, sizeof(*user_record)); - size = len; + if (sdp_server_enable) { + return error_failed(conn, msg, EIO); + } else { + uint32_t size = len; - if (register_sdp_record((uint8_t *) record, size, + if (register_sdp_binary((uint8_t *) record, size, &user_record->handle) < 0) { - error("Failed to register service record"); - free(user_record); - return error_failed(conn, msg, errno); + error("Failed to register service record"); + free(user_record); + return error_failed(conn, msg, errno); + } } sender = dbus_message_get_sender(msg); @@ -150,11 +158,20 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, return error_failed(conn, msg, EIO); } - if (add_record_to_server(sdp_record) < 0) { - error("Failed to register service record"); - free(user_record); - sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + if (sdp_server_enable) { + if (add_record_to_server(sdp_record) < 0) { + error("Failed to register service record"); + free(user_record); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } + } else { + if (register_sdp_record(sdp_record) < 0) { + error("Failed to register service record"); + free(user_record); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } } sender = dbus_message_get_sender(msg); @@ -196,7 +213,10 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, name_listener_remove(conn, sender, exit_callback, user_record); - remove_record_from_server(handle); + if (sdp_server_enable) + remove_record_from_server(handle); + else + unregister_sdp_record(handle); free(user_record); @@ -226,3 +246,8 @@ DBusHandlerResult handle_database_method(DBusConnection *conn, return error_unknown_method(conn, msg); } + +void set_sdp_server_enable(void) +{ + sdp_server_enable = 1; +} diff --git a/hcid/dbus-database.h b/hcid/dbus-database.h index 3958dd84..235d88fd 100644 --- a/hcid/dbus-database.h +++ b/hcid/dbus-database.h @@ -28,4 +28,6 @@ DBusHandlerResult handle_database_method(DBusConnection *conn, DBusMessage *msg, void *data); +void set_sdp_server_enable(void); + #endif /* __BLUEZ_DBUS_DATABSE_H */ diff --git a/hcid/main.c b/hcid/main.c index 5da2216b..30b1c674 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -49,6 +49,7 @@ #include "sdpd.h" #include "dbus-common.h" #include "dbus-service.h" +#include "dbus-database.h" #include "dbus-hci.h" struct hcid_opts hcid; @@ -755,8 +756,10 @@ int main(int argc, char *argv[]) /* Initialize already connected devices */ init_all_devices(hcid.sock); - if (sdp) + if (sdp) { + set_sdp_server_enable(); start_sdp_server(0, SDP_SERVER_COMPAT); + } notify_init(); |