summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-09-21 16:45:12 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-09-21 16:45:12 +0000
commit0c9b7f361df669ff0e7f681b13f1ba18043be2d4 (patch)
treec3db3f60770b58567f6256c4757a74c1adaffa9e
parenta90757289dbf36ef7f1d8de3dcce9236c1b94cf9 (diff)
Move sdp related data allocation from dbus-rfcomm.c to dbus-sdp.c
-rw-r--r--hcid/dbus-rfcomm.c72
-rw-r--r--hcid/dbus-sdp.c41
-rw-r--r--hcid/dbus.h4
3 files changed, 52 insertions, 65 deletions
diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c
index 558d2c5d..2aa93be8 100644
--- a/hcid/dbus-rfcomm.c
+++ b/hcid/dbus-rfcomm.c
@@ -634,19 +634,16 @@ failed:
rfcomm_continue_data_free(cdata);
}
-static uuid_t *str2uuid(const char *string)
+static int str2uuid(uuid_t *uuid, const char *string)
{
uint16_t svclass, data1, data2, data3, data5;
uint32_t data0, data4;
- uuid_t *uuid;
-
- uuid = malloc(sizeof(uuid_t));
- if (!uuid)
- return NULL;
svclass = sdp_str2svclass(string);
- if (svclass)
- return sdp_uuid16_create(uuid, sdp_str2svclass(string));
+ if (svclass) {
+ sdp_uuid16_create(uuid, sdp_str2svclass(string));
+ return 0;
+ }
if (strlen(string) == 36 &&
string[8] == '-' &&
@@ -671,28 +668,11 @@ static uuid_t *str2uuid(const char *string)
memcpy(&val[10], &data4, 4);
memcpy(&val[14], &data5, 2);
- return sdp_uuid128_create(uuid, val);
+ sdp_uuid128_create(uuid, val);
+ return 0;
}
- free(uuid);
-
- return NULL;
-}
-
-static uint32_t *str2handle(const char *string)
-{
- uint32_t *handle;
-
- handle = malloc(sizeof(*handle));
- if (!handle)
- return NULL;
-
- *handle = strtol(string, NULL, 0);
- if (*handle)
- return handle;
-
- free(handle);
- return NULL;
+ return -1;
}
static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn,
@@ -700,8 +680,8 @@ static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn,
{
struct hci_dbus_data *dbus_data = data;
rfcomm_continue_data_t *cdata;
- uint32_t *handle = NULL;
- uuid_t *uuid = NULL;
+ uint32_t handle;
+ uuid_t uuid;
const char *string;
const char *dst;
int err;
@@ -716,10 +696,10 @@ static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn,
if (!cdata)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- if ((uuid = str2uuid(string)))
+ if (str2uuid(&uuid, string) == 0)
err = get_record_with_uuid(conn, msg, dbus_data->dev_id, dst,
- uuid, rfcomm_conn_req_continue, cdata);
- else if ((handle = str2handle(string)))
+ &uuid, rfcomm_conn_req_continue, cdata);
+ else if ((handle = strtol(string, NULL, 0)))
err = get_record_with_handle(conn, msg, dbus_data->dev_id, dst,
handle, rfcomm_conn_req_continue, cdata);
else {
@@ -730,13 +710,11 @@ static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn,
if (!err)
return DBUS_HANDLER_RESULT_HANDLED;
- if (uuid)
- free(uuid);
- if (handle)
- free(handle);
-
rfcomm_continue_data_free(cdata);
+ if (err == -ENOMEM)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
return error_failed(conn, msg, err);
}
@@ -925,8 +903,8 @@ static DBusHandlerResult rfcomm_bind_req(DBusConnection *conn,
{
struct hci_dbus_data *dbus_data = data;
rfcomm_continue_data_t *cdata;
- uint32_t *handle = NULL;
- uuid_t *uuid = NULL;
+ uint32_t handle;
+ uuid_t uuid;
const char *string;
const char *dst;
int err;
@@ -941,10 +919,10 @@ static DBusHandlerResult rfcomm_bind_req(DBusConnection *conn,
if (!cdata)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- if ((uuid = str2uuid(string)))
+ if (str2uuid(&uuid, string) == 0)
err = get_record_with_uuid(conn, msg, dbus_data->dev_id, dst,
- uuid, rfcomm_bind_req_continue, cdata);
- else if ((handle = str2handle(string)))
+ &uuid, rfcomm_bind_req_continue, cdata);
+ else if ((handle = strtol(string, NULL, 0)))
err = get_record_with_handle(conn, msg, dbus_data->dev_id, dst,
handle, rfcomm_bind_req_continue, cdata);
else {
@@ -955,13 +933,11 @@ static DBusHandlerResult rfcomm_bind_req(DBusConnection *conn,
if (!err)
return DBUS_HANDLER_RESULT_HANDLED;
- if (uuid)
- free(uuid);
- if (handle)
- free(handle);
-
rfcomm_continue_data_free(cdata);
+ if (err == -ENOMEM)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
return error_failed(conn, msg, err);
}
diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c
index bd724dc4..fce4cf90 100644
--- a/hcid/dbus-sdp.c
+++ b/hcid/dbus-sdp.c
@@ -1551,10 +1551,11 @@ failed:
int get_record_with_handle(DBusConnection *conn, DBusMessage *msg,
uint16_t dev_id, const char *dst,
- uint32_t *handle, get_record_cb_t *cb, void *data)
+ uint32_t handle, get_record_cb_t *cb, void *data)
{
struct pending_connect *c;
get_record_data_t *d;
+ uint32_t *rec_handle;
int err;
/* FIXME: search the cache first! */
@@ -1564,10 +1565,18 @@ int get_record_with_handle(DBusConnection *conn, DBusMessage *msg,
return -EINPROGRESS;
}
- d = get_record_data_new(dev_id, dst, handle, cb, data);
- if (!d)
+ rec_handle = malloc(sizeof(uint32_t));
+ if (!rec_handle)
return -ENOMEM;
+ *rec_handle = handle;
+
+ d = get_record_data_new(dev_id, dst, rec_handle, cb, data);
+ if (!d) {
+ free(rec_handle);
+ return -ENOMEM;
+ }
+
if (!(c = connect_request(conn, msg, dev_id, dst,
get_rec_with_handle_conn_cb, &err))) {
error("Search request failed: %s (%d)", strerror(err), err);
@@ -1587,7 +1596,7 @@ static void get_rec_with_uuid_comp_cb(uint8_t type, uint16_t err,
get_record_data_t *d = ctxt->priv;
int csrc, tsrc, cb_err = 0;
sdp_record_t *rec = NULL;
- uint32_t *handle;
+ uint32_t handle;
uint8_t *pdata;
if (err == 0xffff) {
@@ -1619,14 +1628,7 @@ static void get_rec_with_uuid_comp_cb(uint8_t type, uint16_t err,
goto failed;
pdata += sizeof(uint16_t);
- /* FIXME: what should we do with the other handles?? */
- handle = malloc(sizeof(*handle));
- if (!handle) {
- cb_err = ENOMEM;
- goto failed;
- }
-
- *handle = ntohl(bt_get_unaligned((uint32_t*)pdata));
+ handle = ntohl(bt_get_unaligned((uint32_t*)pdata));
get_record_with_handle(ctxt->conn, ctxt->rq, d->dev_id,
d->dst, handle, d->cb, d->data);
get_record_data_free(ctxt->priv);
@@ -1668,11 +1670,12 @@ failed:
int get_record_with_uuid(DBusConnection *conn, DBusMessage *msg,
uint16_t dev_id, const char *dst,
- uuid_t *uuid, get_record_cb_t *cb, void *data)
+ const uuid_t *uuid, get_record_cb_t *cb, void *data)
{
struct pending_connect *c;
get_record_data_t *d;
int err;
+ uuid_t *sdp_uuid;
/* FIXME: search the cache first! */
@@ -1681,9 +1684,17 @@ int get_record_with_uuid(DBusConnection *conn, DBusMessage *msg,
return -EINPROGRESS;
}
- d = get_record_data_new(dev_id, dst, uuid, cb, data);
- if (!d)
+ sdp_uuid = malloc(sizeof(uuid_t));
+ if (!sdp_uuid)
+ return -ENOMEM;
+
+ memcpy(sdp_uuid, uuid, sizeof(uuid_t));
+
+ d = get_record_data_new(dev_id, dst, sdp_uuid, cb, data);
+ if (!d) {
+ free(sdp_uuid);
return -ENOMEM;
+ }
if (!(c = connect_request(conn, msg, dev_id, dst,
get_rec_with_uuid_conn_cb, &err))) {
diff --git a/hcid/dbus.h b/hcid/dbus.h
index f83b5ca8..64f6a002 100644
--- a/hcid/dbus.h
+++ b/hcid/dbus.h
@@ -244,9 +244,9 @@ uint16_t sdp_str2svclass(const char *str);
typedef void get_record_cb_t(sdp_record_t *rec, void *data, int err);
int get_record_with_uuid(DBusConnection *conn, DBusMessage *msg,
uint16_t dev_id, const char *dst,
- uuid_t *uuid, get_record_cb_t *cb, void *data);
+ const uuid_t *uuid, get_record_cb_t *cb, void *data);
int get_record_with_handle(DBusConnection *conn, DBusMessage *msg,
uint16_t dev_id, const char *dst,
- uint32_t *handle, get_record_cb_t *cb, void *data);
+ uint32_t handle, get_record_cb_t *cb, void *data);
#endif /* __H_BLUEZ_DBUS_H__ */