summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-20 22:55:10 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-20 22:55:10 +0000
commitb9a114ace318dbb6cb4eadf5a06b386ba5efb48f (patch)
tree950c858c99b76cadb30bdd78f2a4dd6a1b1563b5 /hcid
parentce45df47b1a9a80f46cbb0ff1ae00308bf5046fa (diff)
Close SDP session if request fails
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-common.c59
1 files changed, 39 insertions, 20 deletions
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c
index 0ff395ed..ee36055b 100644
--- a/hcid/dbus-common.c
+++ b/hcid/dbus-common.c
@@ -370,47 +370,66 @@ int hcid_dbus_init(void)
return 0;
}
-int register_sdp_binary(uint8_t *data, uint32_t size, uint32_t *handle)
+static inline sdp_session_t *get_sdp_session(void)
{
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_binary(sess, BDADDR_ANY,
+ return sess;
+}
+
+void cleanup_sdp_session(void)
+{
+ if (sess)
+ sdp_close(sess);
+
+ sess = NULL;
+}
+
+int register_sdp_binary(uint8_t *data, uint32_t size, uint32_t *handle)
+{
+ int err;
+
+ if (!get_sdp_session())
+ return -1;
+
+ err = sdp_device_record_register_binary(sess, BDADDR_ANY,
data, size, 0, handle);
+ if (err < 0)
+ cleanup_sdp_session();
+
+ return err;
}
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;
- }
- }
+ int err;
+
+ if (!get_sdp_session())
+ return -1;
- return sdp_device_record_register(sess, BDADDR_ANY, rec, 0);
+ err = sdp_device_record_register(sess, BDADDR_ANY, rec, 0);
+ if (err < 0)
+ cleanup_sdp_session();
+
+ return err;
}
int unregister_sdp_record(uint32_t handle)
{
+ int err;
+
if (!sess)
return -ENOENT;
- return sdp_device_record_unregister_binary(sess, BDADDR_ANY, handle);
-}
+ err = sdp_device_record_unregister_binary(sess, BDADDR_ANY, handle);
+ if (err < 0)
+ cleanup_sdp_session();
-void cleanup_sdp_session(void)
-{
- if (sess)
- sdp_close(sess);
-
- sess = NULL;
+ return err;
}