From f711e58f8f635d0afcf3f02da83780bef83c4347 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 13 Jan 2007 12:27:09 +0000 Subject: Rename struct slist to GSList and slist_* to g_slist_* --- common/Makefile.am | 2 +- common/dbus.c | 29 +++--- common/glib-ectomy.c | 256 +++++++++++++++++++++++++++++++++++++++++++++------ common/glib-ectomy.h | 30 ++++++ common/list.c | 234 ---------------------------------------------- common/list.h | 54 ----------- hcid/dbus-adapter.c | 63 +++++++------ hcid/dbus-adapter.h | 15 ++- hcid/dbus-common.c | 1 - hcid/dbus-hci.c | 169 +++++++++++++++++----------------- hcid/dbus-hci.h | 2 +- hcid/dbus-manager.c | 11 +-- hcid/dbus-rfcomm.c | 43 +++++---- hcid/dbus-sdp.c | 9 +- hcid/dbus-security.c | 70 +++++++------- hcid/dbus-security.h | 6 +- hcid/dbus-service.c | 61 ++++++------ hcid/dbus-service.h | 6 +- hcid/dbus-test.c | 31 +++---- hcid/security.c | 23 +++-- 20 files changed, 523 insertions(+), 592 deletions(-) delete mode 100644 common/list.c delete mode 100644 common/list.h diff --git a/common/Makefile.am b/common/Makefile.am index 3774edf9..eb6e62b0 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -15,7 +15,7 @@ endif noinst_LIBRARIES = libhelper.a -libhelper_a_SOURCES = oui.h oui.c list.h list.c \ +libhelper_a_SOURCES = oui.h oui.c \ textfile.h textfile.c helper.h helper.c \ logging.h logging.c dbus.h dbus.c \ sdp-xml.h sdp-xml.c $(sdp_sources) \ diff --git a/common/dbus.c b/common/dbus.c index eb8c77f3..2162feab 100644 --- a/common/dbus.c +++ b/common/dbus.c @@ -37,13 +37,12 @@ #include "glib-ectomy.h" #include "dbus.h" #include "logging.h" -#include "list.h" #define DISPATCH_TIMEOUT 0 static int name_listener_initialized = 0; -static struct slist *name_listeners = NULL; +static GSList *name_listeners = NULL; typedef struct { uint32_t id; @@ -68,12 +67,12 @@ struct name_callback { struct name_data { char *name; - struct slist *callbacks; + GSList *callbacks; }; static struct name_data *name_data_find(const char *name) { - struct slist *current; + GSList *current; for (current = name_listeners; current != NULL; current = current->next) { struct name_data *data = current->data; @@ -84,10 +83,10 @@ static struct name_data *name_data_find(const char *name) return NULL; } -static struct name_callback *name_callback_find(struct slist *callbacks, +static struct name_callback *name_callback_find(GSList *callbacks, name_cb_t func, void *user_data) { - struct slist *current; + GSList *current; for (current = callbacks; current != NULL; current = current->next) { struct name_callback *cb = current->data; @@ -100,12 +99,12 @@ static struct name_callback *name_callback_find(struct slist *callbacks, static void name_data_free(struct name_data *data) { - struct slist *l; + GSList *l; for (l = data->callbacks; l != NULL; l = l->next) free(l->data); - slist_free(data->callbacks); + g_slist_free(data->callbacks); if (data->name) free(data->name); @@ -142,10 +141,10 @@ static int name_data_add(const char *name, name_cb_t func, void *user_data) if (!data->name) goto failed; - name_listeners = slist_append(name_listeners, data); + name_listeners = g_slist_append(name_listeners, data); done: - data->callbacks = slist_append(data->callbacks, cb); + data->callbacks = g_slist_append(data->callbacks, cb); return first; failed: @@ -169,12 +168,12 @@ static void name_data_remove(const char *name, name_cb_t func, void *user_data) cb = name_callback_find(data->callbacks, func, user_data); if (cb) { - data->callbacks = slist_remove(data->callbacks, cb); + data->callbacks = g_slist_remove(data->callbacks, cb); free(cb); } if (!data->callbacks) { - name_listeners = slist_remove(name_listeners, data); + name_listeners = g_slist_remove(name_listeners, data); name_data_free(data); } } @@ -182,7 +181,7 @@ static void name_data_remove(const char *name, name_cb_t func, void *user_data) static DBusHandlerResult name_exit_filter(DBusConnection *connection, DBusMessage *message, void *user_data) { - struct slist *l; + GSList *l; struct name_data *data; char *name, *old, *new; @@ -214,7 +213,7 @@ static DBusHandlerResult name_exit_filter(DBusConnection *connection, cb->func(name, cb->user_data); } - name_listeners = slist_remove(name_listeners, data); + name_listeners = g_slist_remove(name_listeners, data); name_data_free(data); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -283,7 +282,7 @@ int name_listener_remove(DBusConnection *connection, const char *name, return -1; } - data->callbacks = slist_remove(data->callbacks, cb); + data->callbacks = g_slist_remove(data->callbacks, cb); free(cb); /* Don't remove the filter if other callbacks exist */ diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c index 46d92154..b45d26f4 100644 --- a/common/glib-ectomy.c +++ b/common/glib-ectomy.c @@ -13,7 +13,6 @@ #include #include -#include "list.h" #include "glib-ectomy.h" struct timeout { @@ -34,12 +33,12 @@ struct _GMainContext { guint next_id; glong next_timeout; - struct slist *timeouts; - struct slist *proc_timeouts; + GSList *timeouts; + GSList *proc_timeouts; gboolean timeout_lock; - struct slist *watches; - struct slist *proc_watches; + GSList *watches; + GSList *proc_watches; gboolean watch_lock; }; @@ -174,7 +173,7 @@ static GMainContext *g_main_context_default() void g_io_remove_watch(guint id) { GMainContext *context = g_main_context_default(); - struct slist *l; + GSList *l; struct watch *w; if (!context) @@ -186,7 +185,7 @@ void g_io_remove_watch(guint id) if (w->id != id) continue; - context->watches = slist_remove(context->watches, w); + context->watches = g_slist_remove(context->watches, w); watch_free(w); return; @@ -198,7 +197,7 @@ void g_io_remove_watch(guint id) if (w->id != id) continue; - context->proc_watches = slist_remove(context->proc_watches, w); + context->proc_watches = g_slist_remove(context->proc_watches, w); watch_free(w); return; @@ -210,7 +209,7 @@ int watch_prio_cmp(struct watch *w1, struct watch *w2) return w1->priority - w2->priority; } -#define watch_list_add(l, w) slist_insert_sorted((l), (w), (cmp_func_t) watch_prio_cmp) +#define watch_list_add(l, w) g_slist_insert_sorted((l), (w), (GCompareFunc) watch_prio_cmp) guint g_io_add_watch_full(GIOChannel *channel, gint priority, GIOCondition condition, GIOFunc func, @@ -273,7 +272,7 @@ GMainLoop *g_main_loop_new(GMainContext *context, gboolean is_running) static void timeout_handlers_prepare(GMainContext *context) { - struct slist *l; + GSList *l; struct timeval tv; glong msec, timeout = LONG_MAX; @@ -314,8 +313,8 @@ static void timeout_handlers_check(GMainContext *context) gboolean ret; if (timercmp(&tv, &t->expiration, <)) { - context->timeouts = slist_remove(context->timeouts, t); - context->proc_timeouts = slist_append(context->proc_timeouts, t); + context->timeouts = g_slist_remove(context->timeouts, t); + context->proc_timeouts = g_slist_append(context->proc_timeouts, t); continue; } @@ -323,10 +322,10 @@ static void timeout_handlers_check(GMainContext *context) /* Check if the handler was removed/freed by the callback * function */ - if (!slist_find(context->timeouts, t, ptr_cmp)) + if (!g_slist_find_custom(context->timeouts, t, ptr_cmp)) continue; - context->timeouts = slist_remove(context->timeouts, t); + context->timeouts = g_slist_remove(context->timeouts, t); if (!ret) { free(t); @@ -344,7 +343,7 @@ static void timeout_handlers_check(GMainContext *context) t->expiration.tv_sec++; } - context->proc_timeouts = slist_append(context->proc_timeouts, t); + context->proc_timeouts = g_slist_append(context->proc_timeouts, t); } context->timeouts = context->proc_timeouts; @@ -366,7 +365,7 @@ void g_main_loop_run(GMainLoop *loop) while (loop->is_running) { int nfds; - struct slist *l; + GSList *l; struct watch *w; for (nfds = 0, l = context->watches; l != NULL; l = l->next, nfds++) { @@ -391,7 +390,7 @@ void g_main_loop_run(GMainLoop *loop) w = context->watches->data; if (!*w->revents) { - context->watches = slist_remove(context->watches, w); + context->watches = g_slist_remove(context->watches, w); context->proc_watches = watch_list_add(context->proc_watches, w); continue; } @@ -400,10 +399,10 @@ void g_main_loop_run(GMainLoop *loop) /* Check if the watch was removed/freed by the callback * function */ - if (!slist_find(context->watches, w, ptr_cmp)) + if (!g_slist_find_custom(context->watches, w, ptr_cmp)) continue; - context->watches = slist_remove(context->watches, w); + context->watches = g_slist_remove(context->watches, w); if (!ret) { watch_free(w); @@ -434,11 +433,11 @@ void g_main_loop_unref(GMainLoop *loop) if (!loop->context) return; - slist_foreach(loop->context->watches, (slist_func_t)watch_free, NULL); - slist_free(loop->context->watches); + g_slist_foreach(loop->context->watches, (GFunc)watch_free, NULL); + g_slist_free(loop->context->watches); - slist_foreach(loop->context->timeouts, (slist_func_t)free, NULL); - slist_free(loop->context->timeouts); + g_slist_foreach(loop->context->timeouts, (GFunc)free, NULL); + g_slist_free(loop->context->timeouts); free(loop->context); loop->context = NULL; @@ -482,9 +481,9 @@ guint g_timeout_add(guint interval, GSourceFunc function, gpointer data) t->id = context->next_id++; if (context->timeout_lock) - context->proc_timeouts = slist_prepend(context->proc_timeouts, t); + context->proc_timeouts = g_slist_prepend(context->proc_timeouts, t); else - context->timeouts = slist_prepend(context->timeouts, t); + context->timeouts = g_slist_prepend(context->timeouts, t); return t->id; } @@ -492,7 +491,7 @@ guint g_timeout_add(guint interval, GSourceFunc function, gpointer data) gint g_timeout_remove(const guint id) { GMainContext *context = g_main_context_default(); - struct slist *l; + GSList *l; struct timeout *t; if (!context) @@ -507,7 +506,7 @@ gint g_timeout_remove(const guint id) if (t->id != id) continue; - context->timeouts = slist_remove(context->timeouts, t); + context->timeouts = g_slist_remove(context->timeouts, t); free(t); return 0; @@ -522,7 +521,7 @@ gint g_timeout_remove(const guint id) if (t->id != id) continue; - context->proc_timeouts = slist_remove(context->proc_timeouts, t); + context->proc_timeouts = g_slist_remove(context->proc_timeouts, t); free(t); return 0; @@ -616,4 +615,205 @@ failed: return FALSE; } +/* GSList functions */ +GSList *g_slist_append(GSList *list, void *data) +{ + GSList *entry, *tail; + + entry = malloc(sizeof(GSList)); + /* FIXME: this currently just silently fails */ + if (!entry) + return list; + + entry->data = data; + entry->next = NULL; + + if (!list) + return entry; + + /* Find the end of the list */ + for (tail = list; tail->next; tail = tail->next); + + tail->next = entry; + + return list; +} + +GSList *g_slist_prepend(GSList *list, void *data) +{ + GSList *entry; + + entry = malloc(sizeof(GSList)); + /* FIXME: this currently just silently fails */ + if (!entry) + return list; + + entry->data = data; + entry->next = list; + + return entry; +} + +GSList *g_slist_insert_sorted(GSList *list, void *data, GCompareFunc cmp_func) +{ + GSList *tmp, *prev, *entry; + int cmp; + + entry = malloc(sizeof(GSList)); + if (!entry) + return list; + + entry->data = data; + entry->next = NULL; + + if (!list) + return entry; + + prev = NULL; + tmp = list; + + cmp = cmp_func(data, tmp->data); + + while (tmp->next && cmp > 0) { + prev = tmp; + tmp = tmp->next; + + cmp = cmp_func(data, tmp->data); + } + + if (!tmp->next && cmp > 0) { + tmp->next = entry; + return list; + } + + if (prev) { + prev->next = entry; + entry->next = tmp; + return list; + } else { + entry->next = list; + return entry; + } +} + +GSList *g_slist_remove(GSList *list, void *data) +{ + GSList *l, *next, *prev = NULL, *match = NULL; + + if (!list) + return NULL; + + for (l = list; l != NULL; l = l->next) { + if (l->data == data) { + match = l; + break; + } + prev = l; + } + + if (!match) + return list; + + next = match->next; + + free(match); + + /* If the head was removed, return the next element */ + if (!prev) + return next; + + prev->next = next; + + return list; +} + +GSList *g_slist_find_custom(GSList *list, const void *data, + GCompareFunc cmp_func) +{ + GSList *l; + + for (l = list; l != NULL; l = l->next) { + if (!cmp_func(l->data, data)) + return l; + } + + return NULL; +} + +static GSList *g_slist_sort_merge(GSList *l1, GSList *l2, + GCompareFunc cmp_func) +{ + GSList list, *l; + int cmp; + + l = &list; + + while (l1 && l2) { + cmp = cmp_func(l1->data, l2->data); + + if (cmp <= 0) { + l = l->next = l1; + l1 = l1->next; + } else { + l = l->next = l2; + l2 = l2->next; + } + } + + l->next = l1 ? l1 : l2; + + return list.next; +} + +GSList *g_slist_sort(GSList *list, GCompareFunc cmp_func) +{ + GSList *l1, *l2; + + if (!list || !list->next) + return list; + + l1 = list; + l2 = list->next; + + while ((l2 = l2->next) != NULL) { + if ((l2 = l2->next) == NULL) + break; + l1 = l1->next; + } + + l2 = l1->next; + l1->next = NULL; + + return g_slist_sort_merge(g_slist_sort(list, cmp_func), + g_slist_sort(l2, cmp_func), cmp_func); +} + +int g_slist_length(GSList *list) +{ + int len; + + for (len = 0; list != NULL; list = list->next) + len++; + + return len; +} + +void g_slist_foreach(GSList *list, GFunc func, void *user_data) +{ + while (list) { + GSList *next = list->next; + func(list->data, user_data); + list = next; + } +} + +void g_slist_free(GSList *list) +{ + GSList *l, *next; + + for (l = list; l != NULL; l = next) { + next = l->next; + free(l); + } +} diff --git a/common/glib-ectomy.h b/common/glib-ectomy.h index 8502deb5..02fa0230 100644 --- a/common/glib-ectomy.h +++ b/common/glib-ectomy.h @@ -112,6 +112,36 @@ gboolean g_utf8_validate(const gchar *str, gssize max_len, const gchar **end); #define g_main_quit(loop) g_main_loop_quit(loop) #define g_main_unref(loop) g_main_loop_unref(loop) +/* Begin GSList declarations */ + +typedef struct _GSList { + void *data; + struct _GSList *next; +} GSList; + +typedef int (*GCompareFunc)(const void *a, const void *b); +typedef void (*GFunc)(void *data, void *user_data); + +GSList *g_slist_append(GSList *list, void *data); + +GSList *g_slist_prepend(GSList *list, void *data); + +GSList *g_slist_insert_sorted(GSList *list, void *data, GCompareFunc cmp_func); + +GSList *g_slist_remove(GSList *list, void *data); + +GSList *g_slist_find_custom(GSList *list, const void *data, + GCompareFunc cmp_func); + +GSList *g_slist_sort(GSList *list, GCompareFunc cmp_func); + +int g_slist_length(GSList *list); + +void g_slist_foreach(GSList *list, GFunc func, void *user_data); +void g_slist_free(GSList *list); + +/* End GSList declarations */ + #endif #endif /* __GLIB_ECTOMY_H */ diff --git a/common/list.c b/common/list.c deleted file mode 100644 index 827f1789..00000000 --- a/common/list.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2004-2006 Marcel Holtmann - * Copyright (C) 2005-2006 Johan Hedberg - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "list.h" - -struct slist *slist_append(struct slist *list, void *data) -{ - struct slist *entry, *tail; - - entry = malloc(sizeof(struct slist)); - /* FIXME: this currently just silently fails */ - if (!entry) - return list; - - entry->data = data; - entry->next = NULL; - - if (!list) - return entry; - - /* Find the end of the list */ - for (tail = list; tail->next; tail = tail->next); - - tail->next = entry; - - return list; -} - -struct slist *slist_prepend(struct slist *list, void *data) -{ - struct slist *entry; - - entry = malloc(sizeof(struct slist)); - /* FIXME: this currently just silently fails */ - if (!entry) - return list; - - entry->data = data; - entry->next = list; - - return entry; -} - -struct slist *slist_insert_sorted(struct slist *list, void *data, cmp_func_t cmp_func) -{ - struct slist *tmp, *prev, *entry; - int cmp; - - entry = malloc(sizeof(struct slist)); - if (!entry) - return list; - - entry->data = data; - entry->next = NULL; - - if (!list) - return entry; - - prev = NULL; - tmp = list; - - cmp = cmp_func(data, tmp->data); - - while (tmp->next && cmp > 0) { - prev = tmp; - tmp = tmp->next; - - cmp = cmp_func(data, tmp->data); - } - - if (!tmp->next && cmp > 0) { - tmp->next = entry; - return list; - } - - if (prev) { - prev->next = entry; - entry->next = tmp; - return list; - } else { - entry->next = list; - return entry; - } -} - -struct slist *slist_remove(struct slist *list, void *data) -{ - struct slist *l, *next, *prev = NULL, *match = NULL; - - if (!list) - return NULL; - - for (l = list; l != NULL; l = l->next) { - if (l->data == data) { - match = l; - break; - } - prev = l; - } - - if (!match) - return list; - - next = match->next; - - free(match); - - /* If the head was removed, return the next element */ - if (!prev) - return next; - - prev->next = next; - - return list; -} - -struct slist *slist_find(struct slist *list, const void *data, - cmp_func_t cmp_func) -{ - struct slist *l; - - for (l = list; l != NULL; l = l->next) { - if (!cmp_func(l->data, data)) - return l; - } - - return NULL; -} - -static struct slist *slist_sort_merge(struct slist *l1, struct slist *l2, - cmp_func_t cmp_func) -{ - struct slist list, *l; - int cmp; - - l = &list; - - while (l1 && l2) { - cmp = cmp_func(l1->data, l2->data); - - if (cmp <= 0) { - l = l->next = l1; - l1 = l1->next; - } else { - l = l->next = l2; - l2 = l2->next; - } - } - - l->next = l1 ? l1 : l2; - - return list.next; -} - -struct slist *slist_sort(struct slist *list, cmp_func_t cmp_func) -{ - struct slist *l1, *l2; - - if (!list || !list->next) - return list; - - l1 = list; - l2 = list->next; - - while ((l2 = l2->next) != NULL) { - if ((l2 = l2->next) == NULL) - break; - l1 = l1->next; - } - - l2 = l1->next; - l1->next = NULL; - - return slist_sort_merge(slist_sort(list, cmp_func), - slist_sort(l2, cmp_func), cmp_func); -} - -int slist_length(struct slist *list) -{ - int len; - - for (len = 0; list != NULL; list = list->next) - len++; - - return len; -} - -void slist_foreach(struct slist *list, slist_func_t func, void *user_data) -{ - while (list) { - struct slist *next = list->next; - func(list->data, user_data); - list = next; - } -} - -void slist_free(struct slist *list) -{ - struct slist *l, *next; - - for (l = list; l != NULL; l = next) { - next = l->next; - free(l); - } -} diff --git a/common/list.h b/common/list.h deleted file mode 100644 index c11424ca..00000000 --- a/common/list.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - * Copyright (C) 2004-2006 Marcel Holtmann - * Copyright (C) 2005-2006 Johan Hedberg - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __LIST_H -#define __LIST_H - -struct slist { - void *data; - struct slist *next; -}; - -typedef int (*cmp_func_t)(const void *a, const void *b); -typedef void (*slist_func_t)(void *data, void *user_data); - -struct slist *slist_append(struct slist *list, void *data); - -struct slist *slist_prepend(struct slist *list, void *data); - -struct slist *slist_insert_sorted(struct slist *list, void *data, cmp_func_t cmp_func); - -struct slist *slist_remove(struct slist *list, void *data); - -struct slist *slist_find(struct slist *list, const void *data, - cmp_func_t cmp_func); - -struct slist *slist_sort(struct slist *list, cmp_func_t cmp_func); - -int slist_length(struct slist *list); - -void slist_foreach(struct slist *list, slist_func_t func, void *user_data); -void slist_free(struct slist *list); - -#endif /* __LIST_H */ diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index f27e2ccf..59d342b6 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -49,7 +49,6 @@ #include "textfile.h" #include "oui.h" -#include "list.h" #include "dbus-common.h" #include "dbus-hci.h" #include "dbus-sdp.h" @@ -177,7 +176,7 @@ static const char *toy_minor_cls[] = { int pending_remote_name_cancel(struct adapter *adapter) { struct remote_dev_info *dev, match; - struct slist *l; + GSList *l; int dd, err = 0; /* find the pending remote name request */ @@ -185,8 +184,8 @@ int pending_remote_name_cancel(struct adapter *adapter) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = slist_find(adapter->found_devices, &match, - (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(adapter->found_devices, &match, + (GCompareFunc) found_device_cmp); if (!l) /* no pending request */ return 0; @@ -202,8 +201,8 @@ int pending_remote_name_cancel(struct adapter *adapter) } /* free discovered devices list */ - slist_foreach(adapter->found_devices, (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; hci_close_dev(dd); @@ -615,7 +614,7 @@ static DBusHandlerResult adapter_is_connected(DBusConnection *conn, dbus_bool_t connected = FALSE; struct adapter *adapter = data; - struct slist *l = adapter->active_conn; + GSList *l = adapter->active_conn; const char *peer_addr; bdaddr_t peer_bdaddr; @@ -630,7 +629,7 @@ static DBusHandlerResult adapter_is_connected(DBusConnection *conn, str2ba(peer_addr, &peer_bdaddr); - l = slist_find(l, &peer_bdaddr, active_conn_find_by_bdaddr); + l = g_slist_find_custom(l, &peer_bdaddr, active_conn_find_by_bdaddr); if (l) connected = TRUE; @@ -651,7 +650,7 @@ static DBusHandlerResult adapter_list_connections(DBusConnection *conn, DBusMessageIter iter; DBusMessageIter array_iter; struct adapter *adapter = data; - struct slist *l = adapter->active_conn; + GSList *l = adapter->active_conn; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); @@ -1339,7 +1338,7 @@ static DBusHandlerResult adapter_get_remote_service_cls(DBusConnection *conn, { DBusMessage *reply; DBusMessageIter iter, array_iter; - struct slist *service_classes; + GSList *service_classes; uint32_t class; if (get_remote_class(conn, msg, data, &class) < 0) @@ -1355,12 +1354,12 @@ static DBusHandlerResult adapter_get_remote_service_cls(DBusConnection *conn, dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter); - slist_foreach(service_classes, (slist_func_t) append_class_string, + g_slist_foreach(service_classes, (GFunc) append_class_string, &array_iter); dbus_message_iter_close_container(&iter, &array_iter); - slist_free(service_classes); + g_slist_free(service_classes); return send_message_and_unref(conn, reply); } @@ -1731,7 +1730,7 @@ static DBusHandlerResult adapter_dc_remote_device(DBusConnection *conn, DBusMessage *msg, void *data) { struct adapter *adapter = data; - struct slist *l = adapter->active_conn; + GSList *l = adapter->active_conn; const char *peer_addr; bdaddr_t peer_bdaddr; @@ -1750,7 +1749,7 @@ static DBusHandlerResult adapter_dc_remote_device(DBusConnection *conn, str2ba(peer_addr, &peer_bdaddr); - l = slist_find(l, &peer_bdaddr, active_conn_find_by_bdaddr); + l = g_slist_find_custom(l, &peer_bdaddr, active_conn_find_by_bdaddr); if (!l) return error_not_connected(conn, msg); @@ -1963,7 +1962,7 @@ static DBusHandlerResult adapter_create_bonding(DBusConnection *conn, if (adapter->bonding) return error_bonding_in_progress(conn, msg); - if (slist_find(adapter->pin_reqs, &peer_bdaddr, pin_req_cmp)) + if (g_slist_find_custom(adapter->pin_reqs, &peer_bdaddr, pin_req_cmp)) return error_bonding_in_progress(conn, msg); /* check if a link key already exists */ @@ -2005,7 +2004,7 @@ static DBusHandlerResult adapter_cancel_bonding(DBusConnection *conn, DBusMessage *reply; bdaddr_t peer_bdaddr; const char *peer_addr; - struct slist *l; + GSList *l; if (!adapter->up) return error_not_ready(conn, msg); @@ -2029,7 +2028,7 @@ static DBusHandlerResult adapter_cancel_bonding(DBusConnection *conn, adapter->bonding->cancel = 1; - l = slist_find(adapter->pin_reqs, &peer_bdaddr, pin_req_cmp); + l = g_slist_find_custom(adapter->pin_reqs, &peer_bdaddr, pin_req_cmp); if (l) { struct pending_pin_info *pin_req = l->data; @@ -2055,7 +2054,7 @@ static DBusHandlerResult adapter_cancel_bonding(DBusConnection *conn, hci_close_dev(dd); } - adapter->pin_reqs = slist_remove(adapter->pin_reqs, pin_req); + adapter->pin_reqs = g_slist_remove(adapter->pin_reqs, pin_req); free(pin_req); } @@ -2071,7 +2070,7 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn, DBusMessage *msg, void *data) { struct adapter *adapter = data; - struct slist *l; + GSList *l; DBusMessage *reply; DBusMessage *signal; char filename[PATH_MAX + 1]; @@ -2119,7 +2118,7 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn, hci_delete_stored_link_key(dd, &bdaddr, 0, 1000); /* find the connection */ - l = slist_find(adapter->active_conn, &bdaddr, + l = g_slist_find_custom(adapter->active_conn, &bdaddr, active_conn_find_by_bdaddr); if (l) { struct active_conn_info *con = l->data; @@ -2587,7 +2586,7 @@ static DBusHandlerResult adapter_cancel_discovery(DBusConnection *conn, } struct remote_device_list_t { - struct slist *list; + GSList *list; time_t time; }; @@ -2597,7 +2596,7 @@ static void list_remote_devices_do_append(char *key, char *value, void *data) char *address; struct tm date; - if (slist_find(param->list, key, (cmp_func_t) strcasecmp)) + if (g_slist_find_custom(param->list, key, (GCompareFunc) strcasecmp)) return; if (param->time){ @@ -2610,7 +2609,7 @@ static void list_remote_devices_do_append(char *key, char *value, void *data) if (!address) return; - param->list = slist_append(param->list, address); + param->list = g_slist_append(param->list, address); } static void remote_devices_do_append(void *data, void *user_data) @@ -2653,10 +2652,10 @@ static DBusHandlerResult adapter_list_remote_devices(DBusConnection *conn, dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter); - slist_foreach(param.list, remote_devices_do_append, &array_iter); + g_slist_foreach(param.list, remote_devices_do_append, &array_iter); - slist_foreach(param.list, (slist_func_t) free, NULL); - slist_free(param.list); + g_slist_foreach(param.list, (GFunc) free, NULL); + g_slist_free(param.list); dbus_message_iter_close_container(&iter, &array_iter); @@ -2700,10 +2699,10 @@ static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnection *conn dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter); - slist_foreach(param.list, remote_devices_do_append, &array_iter); + g_slist_foreach(param.list, remote_devices_do_append, &array_iter); - slist_foreach(param.list, (slist_func_t) free, NULL); - slist_free(param.list); + g_slist_foreach(param.list, (GFunc) free, NULL); + g_slist_free(param.list); dbus_message_iter_close_container(&iter, &array_iter); @@ -2764,17 +2763,17 @@ const char *minor_class_str(uint32_t class) return ""; } -struct slist *service_classes_str(uint32_t class) +GSList *service_classes_str(uint32_t class) { uint8_t services = class >> 16; - struct slist *l = NULL; + GSList *l = NULL; int i; for (i = 0; i < (sizeof(service_cls) / sizeof(*service_cls)); i++) { if (!(services & (1 << i))) continue; - l = slist_append(l, (void *) service_cls[i]); + l = g_slist_append(l, (void *) service_cls[i]); } return l; diff --git a/hcid/dbus-adapter.h b/hcid/dbus-adapter.h index 288cc338..fa4e7422 100644 --- a/hcid/dbus-adapter.h +++ b/hcid/dbus-adapter.h @@ -25,7 +25,6 @@ #define __ADAPTER_H #include -#include "list.h" #include "glib-ectomy.h" #define ADAPTER_INTERFACE "org.bluez.Adapter" @@ -98,17 +97,17 @@ struct adapter { int pinq_idle; /* tracks the idle time for periodic inquiry */ int discov_type; /* type requested */ int pdiscov_resolve_names; /* Resolve names when doing periodic discovery */ - struct slist *found_devices; - struct slist *oor_devices; /* out of range device list */ + GSList *found_devices; + GSList *oor_devices; /* out of range device list */ char *pdiscov_requestor; /* periodic discovery requestor unique name */ char *discov_requestor; /* discovery requestor unique name */ DBusMessage *discovery_cancel; /* discovery cancel message request */ - struct slist *passkey_agents; - struct slist *auth_agents; /* Authorization agents */ + GSList *passkey_agents; + GSList *auth_agents; /* Authorization agents */ bdaddr_t agents_disabled; /* temporarely disable agents for bda */ - struct slist *active_conn; + GSList *active_conn; struct bonding_request_info *bonding; - struct slist *pin_reqs; + GSList *pin_reqs; struct pending_dc_info *pending_dc; }; @@ -118,7 +117,7 @@ const char *major_class_str(uint32_t class); const char *minor_class_str(uint32_t class); -struct slist *service_classes_str(uint32_t class); +GSList *service_classes_str(uint32_t class); int pending_remote_name_cancel(struct adapter *adapter); diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c index d21327a9..bddef5dc 100644 --- a/hcid/dbus-common.c +++ b/hcid/dbus-common.c @@ -47,7 +47,6 @@ #include #include "hcid.h" -#include "list.h" #include "dbus.h" #include "dbus-error.h" #include "dbus-hci.h" diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index fc316620..c3184041 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -46,7 +46,6 @@ #include "hcid.h" #include "dbus.h" #include "textfile.h" -#include "list.h" #include "dbus-common.h" #include "dbus-error.h" #include "dbus-test.h" @@ -105,18 +104,18 @@ int dev_rssi_cmp(struct remote_dev_info *d1, struct remote_dev_info *d2) return rssi1 - rssi2; } -int found_device_add(struct slist **list, bdaddr_t *bdaddr, int8_t rssi, +int found_device_add(GSList **list, bdaddr_t *bdaddr, int8_t rssi, name_status_t name_status) { struct remote_dev_info *dev, match; - struct slist *l; + GSList *l; memset(&match, 0, sizeof(struct remote_dev_info)); bacpy(&match.bdaddr, bdaddr); match.name_status = NAME_ANY; /* ignore repeated entries */ - l = slist_find(*list, &match, (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(*list, &match, (GCompareFunc) found_device_cmp); if (l) { /* device found, update the attributes */ dev = l->data; @@ -130,7 +129,7 @@ int found_device_add(struct slist **list, bdaddr_t *bdaddr, int8_t rssi, if (name_status != NAME_NOT_REQUIRED) dev->name_status = name_status; - *list = slist_sort(*list, (cmp_func_t) dev_rssi_cmp); + *list = g_slist_sort(*list, (GCompareFunc) dev_rssi_cmp); return -EALREADY; } @@ -144,25 +143,25 @@ int found_device_add(struct slist **list, bdaddr_t *bdaddr, int8_t rssi, dev->rssi = rssi; dev->name_status = name_status; - *list = slist_insert_sorted(*list, dev, (cmp_func_t) dev_rssi_cmp); + *list = g_slist_insert_sorted(*list, dev, (GCompareFunc) dev_rssi_cmp); return 0; } -static int found_device_remove(struct slist **list, bdaddr_t *bdaddr) +static int found_device_remove(GSList **list, bdaddr_t *bdaddr) { struct remote_dev_info *dev, match; - struct slist *l; + GSList *l; memset(&match, 0, sizeof(struct remote_dev_info)); bacpy(&match.bdaddr, bdaddr); - l = slist_find(*list, &match, (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(*list, &match, (GCompareFunc) found_device_cmp); if (!l) return -1; dev = l->data; - *list = slist_remove(*list, dev); + *list = g_slist_remove(*list, dev); free(dev); return 0; @@ -187,7 +186,7 @@ static int active_conn_find_by_handle(const void *data, const void *user_data) return -1; } -static int active_conn_append(struct slist **list, bdaddr_t *bdaddr, +static int active_conn_append(GSList **list, bdaddr_t *bdaddr, uint16_t handle) { struct active_conn_info *dev; @@ -200,7 +199,7 @@ static int active_conn_append(struct slist **list, bdaddr_t *bdaddr, bacpy(&dev->bdaddr, bdaddr); dev->handle = handle; - *list = slist_append(*list, dev); + *list = g_slist_append(*list, dev); return 0; } @@ -447,30 +446,30 @@ int unregister_adapter_path(const char *path) } if (adapter->found_devices) { - slist_foreach(adapter->found_devices, - (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, + (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; } if (adapter->oor_devices) { - slist_foreach(adapter->oor_devices, - (slist_func_t) free, NULL); - slist_free(adapter->oor_devices); + g_slist_foreach(adapter->oor_devices, + (GFunc) free, NULL); + g_slist_free(adapter->oor_devices); adapter->oor_devices = NULL; } if (adapter->pin_reqs) { - slist_foreach(adapter->pin_reqs, - (slist_func_t) free, NULL); - slist_free(adapter->pin_reqs); + g_slist_foreach(adapter->pin_reqs, + (GFunc) free, NULL); + g_slist_free(adapter->pin_reqs); adapter->pin_reqs = NULL; } if (adapter->active_conn) { - slist_foreach(adapter->active_conn, - (slist_func_t) free, NULL); - slist_free(adapter->active_conn); + g_slist_foreach(adapter->active_conn, + (GFunc) free, NULL); + g_slist_free(adapter->active_conn); adapter->active_conn = NULL; } @@ -768,27 +767,27 @@ int hcid_dbus_stop_device(uint16_t id) } if (adapter->found_devices) { - slist_foreach(adapter->found_devices, (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; } if (adapter->oor_devices) { - slist_foreach(adapter->oor_devices, (slist_func_t) free, NULL); - slist_free(adapter->oor_devices); + g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL); + g_slist_free(adapter->oor_devices); adapter->oor_devices = NULL; } if (adapter->pin_reqs) { - slist_foreach(adapter->pin_reqs, (slist_func_t) free, NULL); - slist_free(adapter->pin_reqs); + g_slist_foreach(adapter->pin_reqs, (GFunc) free, NULL); + g_slist_free(adapter->pin_reqs); adapter->pin_reqs = NULL; } if (adapter->active_conn) { - slist_foreach(adapter->active_conn, (slist_func_t) send_dc_signal, path); - slist_foreach(adapter->active_conn, (slist_func_t) free, NULL); - slist_free(adapter->active_conn); + g_slist_foreach(adapter->active_conn, (GFunc) send_dc_signal, path); + g_slist_foreach(adapter->active_conn, (GFunc) free, NULL); + g_slist_free(adapter->active_conn); adapter->active_conn = NULL; } @@ -847,7 +846,7 @@ void hcid_dbus_pending_pin_req_add(bdaddr_t *sba, bdaddr_t *dba) memset(info, 0, sizeof(struct pending_pin_info)); bacpy(&info->bdaddr, dba); - adapter->pin_reqs = slist_append(adapter->pin_reqs, info); + adapter->pin_reqs = g_slist_append(adapter->pin_reqs, info); if (adapter->bonding && !bacmp(dba, &adapter->bonding->bdaddr)) adapter->bonding->auth_active = 1; @@ -895,7 +894,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, struct adapter *adapter; DBusMessage *message; char *local_addr, *peer_addr; - struct slist *l; + GSList *l; bdaddr_t tmp; char path[MAX_PATH_LENGTH]; int id; @@ -922,10 +921,10 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, cancel_passkey_agent_requests(adapter->passkey_agents, path, peer); - l = slist_find(adapter->pin_reqs, peer, pin_req_cmp); + l = g_slist_find_custom(adapter->pin_reqs, peer, pin_req_cmp); if (l) { void *d = l->data; - adapter->pin_reqs = slist_remove(adapter->pin_reqs, l->data); + adapter->pin_reqs = g_slist_remove(adapter->pin_reqs, l->data); free(d); if (!status) { @@ -1016,7 +1015,7 @@ int found_device_req_name(struct adapter *adapter) evt_cmd_status rp; remote_name_req_cp cp; struct remote_dev_info match; - struct slist *l; + GSList *l; int dd, req_sent = 0; /* get the next remote address */ @@ -1027,8 +1026,8 @@ int found_device_req_name(struct adapter *adapter) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUIRED; - l = slist_find(adapter->found_devices, &match, - (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(adapter->found_devices, &match, + (GCompareFunc) found_device_cmp); if (!l) return -ENODATA; @@ -1091,12 +1090,12 @@ int found_device_req_name(struct adapter *adapter) /* if failed, request the next element */ /* remove the element from the list */ - adapter->found_devices = slist_remove(adapter->found_devices, dev); + adapter->found_devices = g_slist_remove(adapter->found_devices, dev); free(dev); /* get the next element */ - l = slist_find(adapter->found_devices, &match, - (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(adapter->found_devices, &match, + (GCompareFunc) found_device_cmp); } while (l); @@ -1108,7 +1107,7 @@ int found_device_req_name(struct adapter *adapter) return 0; } -static void send_out_of_range(const char *path, struct slist *l) +static void send_out_of_range(const char *path, GSList *l) { DBusMessage *message; const char *peer_addr; @@ -1131,7 +1130,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) { DBusMessage *message; struct adapter *adapter; - struct slist *l; + GSList *l; char path[MAX_PATH_LENGTH]; char *local_addr; struct remote_dev_info *dev; @@ -1159,15 +1158,15 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) if (adapter->pdiscov_active && !adapter->discov_active) { send_out_of_range(path, adapter->oor_devices); - slist_foreach(adapter->oor_devices, (slist_func_t) free, NULL); - slist_free(adapter->oor_devices); + g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL); + g_slist_free(adapter->oor_devices); adapter->oor_devices = NULL; l = adapter->found_devices; while (l) { dev = l->data; baswap(&tmp, &dev->bdaddr); - adapter->oor_devices = slist_append(adapter->oor_devices, + adapter->oor_devices = g_slist_append(adapter->oor_devices, batostr(&tmp)); l = l->next; } @@ -1206,8 +1205,8 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) } /* free discovered devices list */ - slist_foreach(adapter->found_devices, (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; if (adapter->discov_requestor) { @@ -1310,13 +1309,13 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status) adapter->discov_type &= ~(PERIODIC_INQUIRY | RESOLVE_NAME); /* free discovered devices list */ - slist_foreach(adapter->found_devices, (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; /* free out of range devices list */ - slist_foreach(adapter->oor_devices, (slist_func_t) free, NULL); - slist_free(adapter->oor_devices); + g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL); + g_slist_free(adapter->oor_devices); adapter->oor_devices = NULL; if (adapter->pdiscov_requestor) { @@ -1372,7 +1371,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, DBusMessage *signal_name; char path[MAX_PATH_LENGTH]; struct adapter *adapter; - struct slist *l; + GSList *l; struct remote_dev_info match; char *local_addr, *peer_addr, *name, *tmp_name; dbus_int16_t tmp_rssi = rssi; @@ -1412,11 +1411,11 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, adapter->pinq_idle = 0; /* Out of range list update */ - l = slist_find(adapter->oor_devices, peer_addr, - (cmp_func_t) strcmp); + l = g_slist_find_custom(adapter->oor_devices, peer_addr, + (GCompareFunc) strcmp); if (l) { char *dev = l->data; - adapter->oor_devices = slist_remove(adapter->oor_devices, + adapter->oor_devices = g_slist_remove(adapter->oor_devices, dev); free(dev); } @@ -1435,8 +1434,8 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, bacpy(&match.bdaddr, peer); match.name_status = NAME_SENT; /* if found: don't send the name again */ - l = slist_find(adapter->found_devices, &match, - (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(adapter->found_devices, &match, + (GCompareFunc) found_device_cmp); if (l) goto done; @@ -1569,8 +1568,8 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, goto done; /* skip if a new request has been sent */ /* free discovered devices list */ - slist_foreach(adapter->found_devices, (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; /* @@ -1637,16 +1636,16 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, } if (status) { - struct slist *l; + GSList *l; cancel_passkey_agent_requests(adapter->passkey_agents, path, peer); release_passkey_agents(adapter, peer); - l = slist_find(adapter->pin_reqs, peer, pin_req_cmp); + l = g_slist_find_custom(adapter->pin_reqs, peer, pin_req_cmp); if (l) { struct pending_pin_req *p = l->data; - adapter->pin_reqs = slist_remove(adapter->pin_reqs, p); + adapter->pin_reqs = g_slist_remove(adapter->pin_reqs, p); free(p); } @@ -1677,7 +1676,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, struct adapter *adapter; struct active_conn_info *dev; DBusMessage *message; - struct slist *l; + GSList *l; char *local_addr, *peer_addr = NULL; bdaddr_t tmp; int id; @@ -1703,7 +1702,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, goto failed; } - l = slist_find(adapter->active_conn, &handle, + l = g_slist_find_custom(adapter->active_conn, &handle, active_conn_find_by_handle); if (!l) @@ -1721,10 +1720,10 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, &dev->bdaddr); release_passkey_agents(adapter, &dev->bdaddr); - l = slist_find(adapter->pin_reqs, &dev->bdaddr, pin_req_cmp); + l = g_slist_find_custom(adapter->pin_reqs, &dev->bdaddr, pin_req_cmp); if (l) { struct pending_pin_req *p = l->data; - adapter->pin_reqs = slist_remove(adapter->pin_reqs, p); + adapter->pin_reqs = g_slist_remove(adapter->pin_reqs, p); free(p); } @@ -1772,7 +1771,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, DBUS_TYPE_INVALID); send_message_and_unref(connection, message); - adapter->active_conn = slist_remove(adapter->active_conn, dev); + adapter->active_conn = g_slist_remove(adapter->active_conn, dev); free(dev); failed: @@ -1970,7 +1969,7 @@ void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr) struct adapter *adapter; char *local_addr; ret_pin_code_req_reply *ret = ptr + EVT_CMD_COMPLETE_SIZE; - struct slist *l; + GSList *l; char path[MAX_PATH_LENGTH]; bdaddr_t tmp; int id; @@ -1990,7 +1989,7 @@ void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr) goto failed; } - l = slist_find(adapter->pin_reqs, &ret->bdaddr, pin_req_cmp); + l = g_slist_find_custom(adapter->pin_reqs, &ret->bdaddr, pin_req_cmp); if (l) { struct pending_pin_info *p = l->data; p->replied = 1; @@ -2003,7 +2002,7 @@ failed: void create_bond_req_exit(const char *name, struct adapter *adapter) { char path[MAX_PATH_LENGTH]; - struct slist *l; + GSList *l; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, adapter->dev_id); @@ -2014,7 +2013,7 @@ void create_bond_req_exit(const char *name, struct adapter *adapter) &adapter->bonding->bdaddr); release_passkey_agents(adapter, &adapter->bonding->bdaddr); - l = slist_find(adapter->pin_reqs, &adapter->bonding->bdaddr, + l = g_slist_find_custom(adapter->pin_reqs, &adapter->bonding->bdaddr, pin_req_cmp); if (l) { struct pending_pin_info *p = l->data; @@ -2031,7 +2030,7 @@ void create_bond_req_exit(const char *name, struct adapter *adapter) } } - adapter->pin_reqs = slist_remove(adapter->pin_reqs, p); + adapter->pin_reqs = g_slist_remove(adapter->pin_reqs, p); free(p); } @@ -2110,7 +2109,7 @@ static int remote_name_cancel(int dd, bdaddr_t *dba, int to) int cancel_discovery(struct adapter *adapter) { struct remote_dev_info *dev, match; - struct slist *l; + GSList *l; int dd, err = 0; if (!adapter->discov_active) @@ -2130,8 +2129,8 @@ int cancel_discovery(struct adapter *adapter) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = slist_find(adapter->found_devices, &match, - (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(adapter->found_devices, &match, + (GCompareFunc) found_device_cmp); if (l) { dev = l->data; if (remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) { @@ -2154,8 +2153,8 @@ cleanup: * Reset discov_requestor and discover_state in the remote name * request event handler or in the inquiry complete handler. */ - slist_foreach(adapter->found_devices, (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; /* Disable name resolution for non D-Bus clients */ @@ -2204,7 +2203,7 @@ static int periodic_inquiry_exit(int dd, int to) int cancel_periodic_discovery(struct adapter *adapter) { struct remote_dev_info *dev, match; - struct slist *l; + GSList *l; int dd, err = 0; if (!adapter->pdiscov_active) @@ -2220,8 +2219,8 @@ int cancel_periodic_discovery(struct adapter *adapter) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = slist_find(adapter->found_devices, &match, - (cmp_func_t) found_device_cmp); + l = g_slist_find_custom(adapter->found_devices, &match, + (GCompareFunc) found_device_cmp); if (l) { dev = l->data; if (remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) { @@ -2246,8 +2245,8 @@ cleanup: * Reset pdiscov_requestor and pdiscov_active is done when the * cmd complete event for exit periodic inquiry mode cmd arrives. */ - slist_foreach(adapter->found_devices, (slist_func_t) free, NULL); - slist_free(adapter->found_devices); + g_slist_foreach(adapter->found_devices, (GFunc) free, NULL); + g_slist_free(adapter->found_devices); adapter->found_devices = NULL; return err; diff --git a/hcid/dbus-hci.h b/hcid/dbus-hci.h index 56572b35..a46051bf 100644 --- a/hcid/dbus-hci.h +++ b/hcid/dbus-hci.h @@ -70,7 +70,7 @@ void bonding_request_free(struct bonding_request_info *dev); int pin_req_cmp(const void *p1, const void *p2); int found_device_cmp(const struct remote_dev_info *d1, const struct remote_dev_info *d2); -int found_device_add(struct slist **list, bdaddr_t *bdaddr, int8_t rssi, +int found_device_add(GSList **list, bdaddr_t *bdaddr, int8_t rssi, name_status_t name_status); int found_device_req_name(struct adapter *dbus_data); diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 8af432a9..07fa035b 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -42,7 +42,6 @@ #include "hcid.h" #include "dbus.h" -#include "list.h" #include "dbus-common.h" #include "dbus-error.h" #include "dbus-security.h" @@ -454,7 +453,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, rec->handle = handle; } - agent->records = slist_append(agent->records, rec); + agent->records = g_slist_append(agent->records, rec); dbus_message_append_args(reply, DBUS_TYPE_UINT32, &rec->ext_handle, @@ -555,7 +554,7 @@ static DBusHandlerResult add_service_record_xml(DBusConnection *conn, rec->handle = handle; } - agent->records = slist_append(agent->records, rec); + agent->records = g_slist_append(agent->records, rec); dbus_message_append_args(reply, DBUS_TYPE_UINT32, &rec->ext_handle, @@ -576,7 +575,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, struct service_agent *agent; struct binary_record *rec; DBusMessage *reply; - struct slist *l; + GSList *l; const char *path; uint32_t handle; @@ -599,7 +598,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, return error_not_authorized(conn, msg); - l = slist_find(agent->records, &handle, (cmp_func_t) binary_record_cmp); + l = g_slist_find_custom(agent->records, &handle, (GCompareFunc) binary_record_cmp); if (!l) return error_record_does_not_exist(conn, msg); @@ -608,7 +607,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, return DBUS_HANDLER_RESULT_NEED_MEMORY; rec = l->data; - agent->records = slist_remove(agent->records, rec); + agent->records = g_slist_remove(agent->records, rec); /* If the service agent is running: remove it from the from sdpd */ if (agent->running && rec->handle != 0xffffffff) { diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c index d238669c..673df910 100644 --- a/hcid/dbus-rfcomm.c +++ b/hcid/dbus-rfcomm.c @@ -45,7 +45,6 @@ #include #include "hcid.h" -#include "list.h" #include "glib-ectomy.h" #include "dbus.h" #include "dbus-common.h" @@ -87,9 +86,9 @@ struct pending_connect { int ntries; }; -static struct slist *pending_connects = NULL; -static struct slist *connected_nodes = NULL; -static struct slist *bound_nodes = NULL; +static GSList *pending_connects = NULL; +static GSList *connected_nodes = NULL; +static GSList *bound_nodes = NULL; static char *rfcomm_node_name_from_id(int16_t id, char *dev, size_t len) { @@ -110,9 +109,9 @@ static void rfcomm_node_free(struct rfcomm_node *node) free(node); } -static struct rfcomm_node *find_node_by_name(struct slist *nodes, const char *name) +static struct rfcomm_node *find_node_by_name(GSList *nodes, const char *name) { - struct slist *l; + GSList *l; for (l = nodes; l != NULL; l = l->next) { struct rfcomm_node *node = l->data; @@ -126,7 +125,7 @@ static struct rfcomm_node *find_node_by_name(struct slist *nodes, const char *na static struct pending_connect *find_pending_connect_by_channel(const char *bda, uint8_t ch) { - struct slist *l; + GSList *l; bdaddr_t dba; str2ba(bda, &dba); @@ -144,7 +143,7 @@ static struct pending_connect *find_pending_connect_by_channel(const char *bda, static struct pending_connect *find_pending_connect_by_service(const char *bda, const char *svc) { - struct slist *l; + GSList *l; bdaddr_t dba; str2ba(bda, &dba); @@ -235,7 +234,7 @@ static void rfcomm_connect_req_exit(const char *name, void *data) debug("Connect requestor %s exited. Releasing %s node", name, node->name); rfcomm_release(node, NULL); - connected_nodes = slist_remove(connected_nodes, node); + connected_nodes = g_slist_remove(connected_nodes, node); rfcomm_node_free(node); } @@ -245,7 +244,7 @@ static gboolean rfcomm_disconnect_cb(GIOChannel *io, GIOCondition cond, debug("RFCOMM node %s was disconnected", node->name); name_listener_remove(node->conn, node->owner, rfcomm_connect_req_exit, node); - connected_nodes = slist_remove(connected_nodes, node); + connected_nodes = g_slist_remove(connected_nodes, node); rfcomm_node_free(node); return FALSE; } @@ -289,7 +288,7 @@ static void rfcomm_connect_cb_devnode_opened(int fd, struct pending_connect *c, send_message_and_unref(c->conn, reply); - connected_nodes = slist_append(connected_nodes, node); + connected_nodes = g_slist_append(connected_nodes, node); node->conn = dbus_connection_ref(c->conn); name_listener_add(node->conn, node->owner, @@ -304,7 +303,7 @@ failed: if (reply) dbus_message_unref(reply); done: - pending_connects = slist_remove(pending_connects, c); + pending_connects = g_slist_remove(pending_connects, c); pending_connect_free(c); } @@ -339,7 +338,7 @@ failed: rfcomm_release(node, NULL); rfcomm_node_free(node); - pending_connects = slist_remove(pending_connects, c); + pending_connects = g_slist_remove(pending_connects, c); pending_connect_free(c); return FALSE; @@ -426,7 +425,7 @@ failed: if (node) rfcomm_node_free(node); - pending_connects = slist_remove(pending_connects, c); + pending_connects = g_slist_remove(pending_connects, c); pending_connect_free(c); return FALSE; @@ -497,7 +496,7 @@ static int rfcomm_connect(DBusConnection *conn, DBusMessage *msg, bdaddr_t *src, debug("Connect in progress"); g_io_add_watch(c->io, G_IO_OUT, (GIOFunc) rfcomm_connect_cb, c); - pending_connects = slist_append(pending_connects, c); + pending_connects = g_slist_append(pending_connects, c); } else { debug("Connect succeeded with first try"); (void) rfcomm_connect_cb(c->io, G_IO_OUT, c); @@ -518,7 +517,7 @@ static void rfcomm_bind_req_exit(const char *name, void *data) struct rfcomm_node *node = data; debug("Bind requestor %s exited. Releasing %s node", name, node->name); rfcomm_release(node, NULL); - bound_nodes = slist_remove(bound_nodes, node); + bound_nodes = g_slist_remove(bound_nodes, node); rfcomm_node_free(node); } @@ -564,7 +563,7 @@ static struct rfcomm_node *rfcomm_bind(bdaddr_t *src, const char *bda, } rfcomm_node_name_from_id(node->id, node->name, sizeof(node->name)); - bound_nodes = slist_append(bound_nodes, node); + bound_nodes = g_slist_append(bound_nodes, node); node->conn = dbus_connection_ref(conn); name_listener_add(node->conn, node->owner, rfcomm_bind_req_exit, node); @@ -812,7 +811,7 @@ static DBusHandlerResult rfcomm_disconnect_req(DBusConnection *conn, name_listener_remove(node->conn, node->owner, rfcomm_connect_req_exit, node); - connected_nodes = slist_remove(connected_nodes, node); + connected_nodes = g_slist_remove(connected_nodes, node); rfcomm_node_free(node); return send_message_and_unref(conn, reply); @@ -875,7 +874,7 @@ failed: if (reply) dbus_message_unref(reply); if (node) { - bound_nodes = slist_remove(bound_nodes, node); + bound_nodes = g_slist_remove(bound_nodes, node); rfcomm_release(node, NULL); rfcomm_node_free(node); } @@ -965,7 +964,7 @@ need_memory: if (reply) dbus_message_unref(reply); if (node) { - bound_nodes = slist_remove(bound_nodes, node); + bound_nodes = g_slist_remove(bound_nodes, node); rfcomm_release(node, NULL); rfcomm_node_free(node); } @@ -1003,7 +1002,7 @@ static DBusHandlerResult rfcomm_release_req(DBusConnection *conn, name_listener_remove(node->conn, node->owner, rfcomm_bind_req_exit, node); - bound_nodes = slist_remove(bound_nodes, node); + bound_nodes = g_slist_remove(bound_nodes, node); rfcomm_node_free(node); return send_message_and_unref(conn, reply); @@ -1016,7 +1015,7 @@ static DBusHandlerResult rfcomm_list_bindings_req(DBusConnection *conn, DBusMessage *reply; DBusMessageIter iter, sub; struct adapter *adapter = data; - struct slist *l; + GSList *l; hci_devba(adapter->dev_id, &bdaddr); diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c index 2e3d563a..781b7e52 100644 --- a/hcid/dbus-sdp.c +++ b/hcid/dbus-sdp.c @@ -46,7 +46,6 @@ #include -#include "list.h" #include "dbus.h" #include "hcid.h" #include "textfile.h" @@ -158,7 +157,7 @@ uint16_t sdp_str2svclass(const char *str) } /* list of remote and local service records */ -static struct slist *pending_connects = NULL; +static GSList *pending_connects = NULL; static struct pending_connect *pending_connect_new(DBusConnection *conn, DBusMessage *msg, const char *dst, connect_cb_t *cb) @@ -207,7 +206,7 @@ static void pending_connect_free(struct pending_connect *c) static struct pending_connect *find_pending_connect(const char *dst) { - struct slist *l; + GSList *l; for (l = pending_connects; l != NULL; l = l->next) { struct pending_connect *pending = l->data; @@ -634,7 +633,7 @@ failed: g_io_channel_unref(chan); done: - pending_connects = slist_remove(pending_connects, c); + pending_connects = g_slist_remove(pending_connects, c); pending_connect_free(c); return FALSE; @@ -671,7 +670,7 @@ static struct pending_connect *connect_request(DBusConnection *conn, chan = g_io_channel_unix_new(sdp_get_socket(c->session)); g_io_add_watch(chan, G_IO_OUT, sdp_client_connect_cb, c); - pending_connects = slist_append(pending_connects, c); + pending_connects = g_slist_append(pending_connects, c); return c; } diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 012114aa..522dda7d 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -57,7 +57,7 @@ static void send_cancel_request(struct pending_agent_request *req); static void passkey_agent_free(struct passkey_agent *agent) { - struct slist *l; + GSList *l; if (!agent) return; @@ -86,14 +86,14 @@ static void passkey_agent_free(struct passkey_agent *agent) if (agent->conn) dbus_connection_unref(agent->conn); - slist_free(agent->pending_requests); + g_slist_free(agent->pending_requests); free(agent); } static void agent_exited(const char *name, struct adapter *adapter) { - struct slist *cur, *next; + GSList *cur, *next; debug("Passkey agent %s exited without calling Unregister", name); @@ -107,7 +107,7 @@ static void agent_exited(const char *name, struct adapter *adapter) agent->exited = 1; - adapter->passkey_agents = slist_remove(adapter->passkey_agents, agent); + adapter->passkey_agents = g_slist_remove(adapter->passkey_agents, agent); passkey_agent_free(agent); } } @@ -119,7 +119,7 @@ static gboolean agent_timeout(struct passkey_agent *agent) debug("Passkey Agent at %s, %s timed out", agent->name, agent->path); if (adapter) - adapter->passkey_agents = slist_remove(adapter->passkey_agents, agent); + adapter->passkey_agents = g_slist_remove(adapter->passkey_agents, agent); agent->timeout = 0; @@ -241,7 +241,7 @@ static DBusHandlerResult register_passkey_agent(DBusConnection *conn, ref.addr = (char *) addr; ref.path = (char *) path; - if (slist_find(adapter->passkey_agents, &ref, (cmp_func_t) agent_cmp)) + if (g_slist_find_custom(adapter->passkey_agents, &ref, (GCompareFunc) agent_cmp)) return error_passkey_agent_already_exists(conn, msg); agent = passkey_agent_new(adapter, conn, ref.name, path, addr); @@ -258,12 +258,12 @@ static DBusHandlerResult register_passkey_agent(DBusConnection *conn, /* Only add a name listener if there isn't one already for this name */ ref.addr = NULL; ref.path = NULL; - if (!slist_find(adapter->passkey_agents, &ref, (cmp_func_t) agent_cmp)) + if (!g_slist_find_custom(adapter->passkey_agents, &ref, (GCompareFunc) agent_cmp)) name_listener_add(conn, ref.name, (name_cb_t) agent_exited, adapter); agent->timeout = g_timeout_add(AGENT_TIMEOUT, (GSourceFunc)agent_timeout, agent); - adapter->passkey_agents = slist_append(adapter->passkey_agents, agent); + adapter->passkey_agents = g_slist_append(adapter->passkey_agents, agent); return send_message_and_unref(conn, reply); } @@ -272,7 +272,7 @@ static DBusHandlerResult unregister_passkey_agent(DBusConnection *conn, DBusMessage *msg, void *data) { struct adapter *adapter; - struct slist *match; + GSList *match; struct passkey_agent ref, *agent; DBusMessage *reply; const char *path, *addr; @@ -296,7 +296,7 @@ static DBusHandlerResult unregister_passkey_agent(DBusConnection *conn, ref.path = (char *) path; ref.addr = (char *) addr; - match = slist_find(adapter->passkey_agents, &ref, (cmp_func_t) agent_cmp); + match = g_slist_find_custom(adapter->passkey_agents, &ref, (GCompareFunc) agent_cmp); if (!match) return error_passkey_agent_does_not_exist(conn, msg); @@ -305,7 +305,7 @@ static DBusHandlerResult unregister_passkey_agent(DBusConnection *conn, name_listener_remove(agent->conn, agent->name, (name_cb_t) agent_exited, adapter); - adapter->passkey_agents = slist_remove(adapter->passkey_agents, agent); + adapter->passkey_agents = g_slist_remove(adapter->passkey_agents, agent); agent->exited = 1; passkey_agent_free(agent); @@ -461,7 +461,7 @@ static void pend_auth_agent_req_cancel(struct pend_auth_agent_req *req) static void auth_agent_cancel_requests(struct authorization_agent *agent) { - struct slist *l; + GSList *l; for (l = agent->pending_requests; l != NULL; l = l->next) { struct pend_auth_agent_req *req = l->data; @@ -498,7 +498,7 @@ static void auth_agent_free(struct authorization_agent *agent) free(agent->name); free(agent->path); dbus_connection_unref(agent->conn); - slist_free(agent->pending_requests); + g_slist_free(agent->pending_requests); free(agent); } @@ -697,7 +697,7 @@ reject: done: dbus_message_unref(reply); - agent->pending_requests = slist_remove(agent->pending_requests, req); + agent->pending_requests = g_slist_remove(agent->pending_requests, req); pend_auth_agent_req_free(req); } @@ -759,7 +759,7 @@ static DBusHandlerResult call_auth_agent(DBusMessage *msg, dbus_pending_call_set_notify(req->call, auth_agent_req_reply, req, NULL); - agent->pending_requests = slist_append(agent->pending_requests, req); + agent->pending_requests = g_slist_append(agent->pending_requests, req); return DBUS_HANDLER_RESULT_HANDLED; } @@ -769,7 +769,7 @@ static DBusHandlerResult authorize_service(DBusConnection *conn, { const char *service_path, *adapter_path, *address, *action; struct service_agent *sagent; - struct slist *l; + GSList *l; if (!hcid_dbus_use_experimental()) return error_unknown_method(conn, msg); @@ -796,7 +796,7 @@ static DBusHandlerResult authorize_service(DBusConnection *conn, return error_rejected(conn, msg); /* Check it is a trusted device */ - l = slist_find(sagent->trusted_devices, address, (cmp_func_t) strcasecmp); + l = g_slist_find_custom(sagent->trusted_devices, address, (GCompareFunc) strcasecmp); if (l) return send_message_and_unref(conn, dbus_message_new_method_return(msg)); @@ -817,7 +817,7 @@ static DBusHandlerResult auth_agent_send_cancel(DBusMessage *msg, { struct pend_auth_agent_req *req = NULL; DBusMessage *message; - struct slist *l; + GSList *l; for (l = agent->pending_requests; l != NULL; l = l->next) { req = l->data; @@ -1021,7 +1021,7 @@ done: if (message) dbus_message_unref(message); - agent->pending_requests = slist_remove(agent->pending_requests, req); + agent->pending_requests = g_slist_remove(agent->pending_requests, req); dbus_pending_call_cancel(req->call); if (req->call) dbus_pending_call_unref(req->call); @@ -1029,7 +1029,7 @@ done: free(req); if (agent != default_agent) { - agent->adapter->passkey_agents = slist_remove(agent->adapter->passkey_agents, + agent->adapter->passkey_agents = g_slist_remove(agent->adapter->passkey_agents, agent); passkey_agent_free(agent); } @@ -1068,7 +1068,7 @@ static int call_passkey_agent(DBusConnection *conn, dbus_pending_call_set_notify(req->call, passkey_agent_reply, req, NULL); - agent->pending_requests = slist_append(agent->pending_requests, req); + agent->pending_requests = g_slist_append(agent->pending_requests, req); return 0; @@ -1088,7 +1088,7 @@ int handle_passkey_request(DBusConnection *conn, int dev, const char *path, { struct passkey_agent *agent = default_agent; struct adapter *adapter = NULL; - struct slist *l; + GSList *l; char addr[18]; void *data; @@ -1106,7 +1106,7 @@ int handle_passkey_request(DBusConnection *conn, int dev, const char *path, for (l = adapter->passkey_agents; l != NULL; l = l->next) { struct passkey_agent *a = l->data; - if (a != default_agent && slist_length(a->pending_requests) >= 1) + if (a != default_agent && g_slist_length(a->pending_requests) >= 1) continue; if (!strcmp(a->addr, addr)) { agent = a; @@ -1203,7 +1203,7 @@ done: if (message) dbus_message_unref(message); - agent->pending_requests = slist_remove(agent->pending_requests, req); + agent->pending_requests = g_slist_remove(agent->pending_requests, req); dbus_pending_call_cancel(req->call); if (req->call) dbus_pending_call_unref(req->call); @@ -1213,7 +1213,7 @@ done: free(req); if (agent != default_agent) { - agent->adapter->passkey_agents = slist_remove(agent->adapter->passkey_agents, + agent->adapter->passkey_agents = g_slist_remove(agent->adapter->passkey_agents, agent); passkey_agent_free(agent); } @@ -1255,7 +1255,7 @@ static int call_confirm_agent(DBusConnection *conn, dbus_pending_call_set_notify(req->call, confirm_agent_reply, req, NULL); - agent->pending_requests = slist_append(agent->pending_requests, req); + agent->pending_requests = g_slist_append(agent->pending_requests, req); return 0; @@ -1277,7 +1277,7 @@ int handle_confirm_request(DBusConnection *conn, int dev, const char *path, { struct passkey_agent *agent = default_agent; struct adapter *adapter = NULL; - struct slist *l; + GSList *l; char addr[18]; void *data; @@ -1295,7 +1295,7 @@ int handle_confirm_request(DBusConnection *conn, int dev, const char *path, for (l = adapter->passkey_agents; l != NULL; l = l->next) { struct passkey_agent *a = l->data; - if (a != default_agent && slist_length(a->pending_requests) >= 1) + if (a != default_agent && g_slist_length(a->pending_requests) >= 1) continue; if (!strcmp(a->addr, addr)) { agent = a; @@ -1366,7 +1366,7 @@ static void release_agent(struct passkey_agent *agent) /* Only remove the name listener if there are no more agents for this name */ memset(&ref, 0, sizeof(ref)); ref.name = agent->name; - if (!slist_find(agent->adapter->passkey_agents, &ref, (cmp_func_t) agent_cmp)) + if (!g_slist_find_custom(agent->adapter->passkey_agents, &ref, (GCompareFunc) agent_cmp)) name_listener_remove(agent->conn, ref.name, (name_cb_t) agent_exited, agent->adapter); } @@ -1395,7 +1395,7 @@ void release_default_auth_agent(void) void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda) { - struct slist *l, *next; + GSList *l, *next; for (l = adapter->passkey_agents; l != NULL; l = next) { struct passkey_agent *agent = l->data; @@ -1408,15 +1408,15 @@ void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda) continue; } - adapter->passkey_agents = slist_remove(adapter->passkey_agents, agent); + adapter->passkey_agents = g_slist_remove(adapter->passkey_agents, agent); passkey_agent_free(agent); } } -void cancel_passkey_agent_requests(struct slist *agents, const char *path, +void cancel_passkey_agent_requests(GSList *agents, const char *path, bdaddr_t *addr) { - struct slist *l, *next; + GSList *l, *next; /* First check the default agent */ for (l = default_agent ? default_agent->pending_requests : NULL; l != NULL; l = next) { @@ -1424,7 +1424,7 @@ void cancel_passkey_agent_requests(struct slist *agents, const char *path, next = l->next; if (!strcmp(path, req->path) && (!addr || !bacmp(addr, &req->bda))) { send_cancel_request(req); - default_agent->pending_requests = slist_remove(default_agent->pending_requests, + default_agent->pending_requests = g_slist_remove(default_agent->pending_requests, req); } } @@ -1438,7 +1438,7 @@ void cancel_passkey_agent_requests(struct slist *agents, const char *path, next = l->next; if (!strcmp(path, req->path) && (!addr || !bacmp(addr, &req->bda))) { send_cancel_request(req); - agent->pending_requests = slist_remove(agent->pending_requests, req); + agent->pending_requests = g_slist_remove(agent->pending_requests, req); } } } diff --git a/hcid/dbus-security.h b/hcid/dbus-security.h index 2096437a..d0f0fe07 100644 --- a/hcid/dbus-security.h +++ b/hcid/dbus-security.h @@ -32,7 +32,7 @@ struct passkey_agent { char *addr; char *name; char *path; - struct slist *pending_requests; + GSList *pending_requests; int exited; guint timeout; }; @@ -52,7 +52,7 @@ struct authorization_agent { DBusConnection *conn; char *name; char *path; - struct slist *pending_requests; + GSList *pending_requests; }; struct pend_auth_agent_req { @@ -79,6 +79,6 @@ void release_default_auth_agent(void); void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda); -void cancel_passkey_agent_requests(struct slist *agents, const char *path, bdaddr_t *dba); +void cancel_passkey_agent_requests(GSList *agents, const char *path, bdaddr_t *dba); #endif /* __BLUEZ_DBUS_SECURITY_H */ diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index 103c8a4b..625a1c32 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -34,14 +34,13 @@ #include "hcid.h" #include "dbus.h" -#include "list.h" #include "dbus-common.h" #include "dbus-error.h" #include "dbus-manager.h" #include "dbus-service.h" #include "dbus-hci.h" -static struct slist *services = NULL; +static GSList *services = NULL; struct binary_record *binary_record_new() { @@ -156,13 +155,13 @@ static void service_agent_free(struct service_agent *agent) free(agent->description); if (agent->trusted_devices) { - slist_foreach(agent->trusted_devices, (slist_func_t) free, NULL); - slist_free(agent->trusted_devices); + g_slist_foreach(agent->trusted_devices, (GFunc) free, NULL); + g_slist_free(agent->trusted_devices); } if (agent->records) { - slist_foreach(agent->records, (slist_func_t) binary_record_free, NULL); - slist_free(agent->records); + g_slist_foreach(agent->records, (GFunc) binary_record_free, NULL); + g_slist_free(agent->records); } free(agent); @@ -205,7 +204,7 @@ mem_fail: return NULL; } -int register_agent_records(struct slist *lrecords) +int register_agent_records(GSList *lrecords) { while (lrecords) { struct binary_record *rec = lrecords->data; @@ -227,7 +226,7 @@ int register_agent_records(struct slist *lrecords) return 0; } -static int unregister_agent_records(struct slist *lrecords) +static int unregister_agent_records(GSList *lrecords) { while (lrecords) { struct binary_record *rec = lrecords->data; @@ -252,7 +251,7 @@ static void service_agent_exit(const char *name, void *data) { DBusConnection *conn = data; DBusMessage *message; - struct slist *l, *lremove = NULL; + GSList *l, *lremove = NULL; struct service_agent *agent; const char *path; @@ -281,12 +280,12 @@ static void service_agent_exit(const char *name, void *data) DBUS_TYPE_INVALID); send_message_and_unref(conn, message); - lremove = slist_append(lremove, l->data); - services = slist_remove(services, l->data); + lremove = g_slist_append(lremove, l->data); + services = g_slist_remove(services, l->data); } - slist_foreach(lremove, (slist_func_t) free, NULL); - slist_free(lremove); + g_slist_foreach(lremove, (GFunc) free, NULL); + g_slist_free(lremove); } static void forward_reply(DBusPendingCall *call, void *udata) @@ -560,7 +559,7 @@ static DBusHandlerResult set_trusted(DBusConnection *conn, DBusMessage *msg, void *data) { struct service_agent *agent = data; - struct slist *l; + GSList *l; DBusMessage *reply; const char *address; @@ -572,7 +571,7 @@ static DBusHandlerResult set_trusted(DBusConnection *conn, if (check_address(address) < 0) return error_invalid_arguments(conn, msg); - l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcasecmp); + l = g_slist_find_custom(agent->trusted_devices, address, (GCompareFunc) strcasecmp); if (l) return error_trusted_device_already_exists(conn, msg); @@ -580,7 +579,7 @@ static DBusHandlerResult set_trusted(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - agent->trusted_devices = slist_append(agent->trusted_devices, strdup(address)); + agent->trusted_devices = g_slist_append(agent->trusted_devices, strdup(address)); return send_message_and_unref(conn, reply); } @@ -589,7 +588,7 @@ static DBusHandlerResult is_trusted(DBusConnection *conn, DBusMessage *msg, void *data) { struct service_agent *agent = data; - struct slist *l; + GSList *l; DBusMessage *reply; const char *address; dbus_bool_t trusted; @@ -599,7 +598,7 @@ static DBusHandlerResult is_trusted(DBusConnection *conn, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcasecmp); + l = g_slist_find_custom(agent->trusted_devices, address, (GCompareFunc) strcasecmp); trusted = (l? TRUE : FALSE); reply = dbus_message_new_method_return(msg); @@ -617,7 +616,7 @@ static DBusHandlerResult remove_trust(DBusConnection *conn, DBusMessage *msg, void *data) { struct service_agent *agent = data; - struct slist *l; + GSList *l; DBusMessage *reply; const char *address; void *paddress; @@ -627,7 +626,7 @@ static DBusHandlerResult remove_trust(DBusConnection *conn, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcasecmp); + l = g_slist_find_custom(agent->trusted_devices, address, (GCompareFunc) strcasecmp); if (!l) return error_trusted_device_does_not_exists(conn, msg); @@ -636,7 +635,7 @@ static DBusHandlerResult remove_trust(DBusConnection *conn, return DBUS_HANDLER_RESULT_NEED_MEMORY; paddress = l->data; - agent->trusted_devices = slist_remove(agent->trusted_devices, l->data); + agent->trusted_devices = g_slist_remove(agent->trusted_devices, l->data); free(paddress); return send_message_and_unref(conn, reply); @@ -718,7 +717,7 @@ int register_service_agent(DBusConnection *conn, const char *sender, const char *path, const char *name, const char *description) { struct service_agent *agent; - struct slist *l; + GSList *l; debug("Registering service object: %s", path); @@ -727,7 +726,7 @@ int register_service_agent(DBusConnection *conn, const char *sender, if (!agent) return -ENOMEM; - l = slist_find(services, path, (cmp_func_t) strcmp); + l = g_slist_find_custom(services, path, (GCompareFunc) strcmp); if (l) return -EADDRNOTAVAIL; @@ -736,7 +735,7 @@ int register_service_agent(DBusConnection *conn, const char *sender, return -ENOMEM; } - services = slist_append(services, strdup(path)); + services = g_slist_append(services, strdup(path)); name_listener_add(conn, sender, (name_cb_t) service_agent_exit, conn); @@ -746,7 +745,7 @@ int register_service_agent(DBusConnection *conn, const char *sender, int unregister_service_agent(DBusConnection *conn, const char *sender, const char *path) { struct service_agent *agent; - struct slist *l; + GSList *l; debug("Unregistering service object: %s", path); @@ -766,10 +765,10 @@ int unregister_service_agent(DBusConnection *conn, const char *sender, const cha name_listener_remove(conn, sender, (name_cb_t) service_agent_exit, conn); - l = slist_find(services, path, (cmp_func_t) strcmp); + l = g_slist_find_custom(services, path, (GCompareFunc) strcmp); if (l) { void *p = l->data; - services = slist_remove(services, l->data); + services = g_slist_remove(services, l->data); free(p); } @@ -791,7 +790,7 @@ void send_release(DBusConnection *conn, const char *id, const char *path) void release_service_agents(DBusConnection *conn) { - struct slist *l = services; + GSList *l = services; struct service_agent *agent; const char *path; @@ -814,14 +813,14 @@ void release_service_agents(DBusConnection *conn) dbus_connection_unregister_object_path(conn, path); } - slist_foreach(services, (slist_func_t) free, NULL); - slist_free(services); + g_slist_foreach(services, (GFunc) free, NULL); + g_slist_free(services); services = NULL; } void append_available_services(DBusMessageIter *array_iter) { - struct slist *l = services; + GSList *l = services; const char *path; while (l) { diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h index f96f2aa7..5fdf6b9a 100644 --- a/hcid/dbus-service.h +++ b/hcid/dbus-service.h @@ -33,8 +33,8 @@ struct service_agent { char *name; char *description; int running; - struct slist *trusted_devices; - struct slist *records; /* list of binary records */ + GSList *trusted_devices; + GSList *records; /* list of binary records */ }; struct service_call { @@ -61,7 +61,7 @@ int unregister_service_agent(DBusConnection *conn, const char *sender, void release_service_agents(DBusConnection *conn); void append_available_services(DBusMessageIter *iter); -int register_agent_records(struct slist *lrecords); +int register_agent_records(GSList *lrecords); struct service_call *service_call_new(DBusConnection *conn, DBusMessage *msg, struct service_agent *agent); diff --git a/hcid/dbus-test.c b/hcid/dbus-test.c index 988fd5f0..407d4f1a 100644 --- a/hcid/dbus-test.c +++ b/hcid/dbus-test.c @@ -34,7 +34,6 @@ #include #include -#include "list.h" #include "hcid.h" #include "dbus.h" #include "dbus-common.h" @@ -77,7 +76,7 @@ struct audit { uint32_t mask; }; -static struct slist *audits = NULL; +static GSList *audits = NULL; static gboolean l2raw_connect_complete(GIOChannel *io, GIOCondition cond, struct audit *audit); @@ -140,7 +139,7 @@ static void send_audit_status(struct audit *audit, const char *name) static void audit_requestor_exited(const char *name, struct audit *audit) { debug("AuditRemoteDevice requestor %s exited", name); - audits = slist_remove(audits, audit); + audits = g_slist_remove(audits, audit); if (audit->io) { struct adapter *adapter = NULL; @@ -169,7 +168,7 @@ int audit_addr_cmp(const void *a, const void *b) static gboolean audit_in_progress(void) { - struct slist *l; + GSList *l; for (l = audits; l != NULL; l = l->next) { struct audit *audit = l->data; @@ -187,7 +186,7 @@ static gboolean l2raw_input_timer(struct audit *audit) send_audit_status(audit, "AuditRemoteDeviceComplete"); g_io_channel_close(audit->io); - audits = slist_remove(audits, audit); + audits = g_slist_remove(audits, audit); name_listener_remove(audit->conn, audit->requestor, (name_cb_t) audit_requestor_exited, audit); audit_free(audit); @@ -332,7 +331,7 @@ failed: g_io_channel_close(io); g_io_channel_unref(io); - audits = slist_remove(audits, audit); + audits = g_slist_remove(audits, audit); name_listener_remove(audit->conn, audit->requestor, (name_cb_t) audit_requestor_exited, audit); @@ -408,7 +407,7 @@ failed: g_io_channel_close(io); g_io_channel_unref(io); - audits = slist_remove(audits, audit); + audits = g_slist_remove(audits, audit); name_listener_remove(audit->conn, audit->requestor, (name_cb_t) audit_requestor_exited, audit); audit_free(audit); @@ -448,7 +447,7 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, if (adapter->bonding) return error_bonding_in_progress(conn, msg); - if (slist_find(adapter->pin_reqs, &peer, pin_req_cmp)) + if (g_slist_find_custom(adapter->pin_reqs, &peer, pin_req_cmp)) return error_bonding_in_progress(conn, msg); if (!read_l2cap_info(&local, &peer, NULL, NULL, NULL, NULL)) @@ -459,7 +458,7 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Just return if an audit for the same device is already queued */ - if (slist_find(audits, &peer, audit_addr_cmp)) + if (g_slist_find_custom(audits, &peer, audit_addr_cmp)) return send_message_and_unref(conn, reply); if (adapter->discov_active || (adapter->pdiscov_active && !adapter->pinq_idle)) @@ -494,7 +493,7 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, name_listener_add(conn, dbus_message_get_sender(msg), (name_cb_t) audit_requestor_exited, audit); - audits = slist_append(audits, audit); + audits = g_slist_append(audits, audit); return send_message_and_unref(conn, reply); } @@ -507,7 +506,7 @@ static DBusHandlerResult cancel_audit_remote_device(DBusConnection *conn, DBusError err; const char *address; bdaddr_t peer, local; - struct slist *l; + GSList *l; struct audit *audit; dbus_error_init(&err); @@ -526,7 +525,7 @@ static DBusHandlerResult cancel_audit_remote_device(DBusConnection *conn, str2ba(address, &peer); str2ba(adapter->address, &local); - l = slist_find(audits, &peer, audit_addr_cmp); + l = g_slist_find_custom(audits, &peer, audit_addr_cmp); if (!l) return error_not_in_progress(conn, msg, "Audit not in progress"); @@ -547,7 +546,7 @@ static DBusHandlerResult cancel_audit_remote_device(DBusConnection *conn, if (audit->timeout) g_timeout_remove(audit->timeout); - audits = slist_remove(audits, audit); + audits = g_slist_remove(audits, audit); name_listener_remove(audit->conn, audit->requestor, (name_cb_t) audit_requestor_exited, audit); audit_free(audit); @@ -669,7 +668,7 @@ DBusHandlerResult handle_test_method(DBusConnection *conn, DBusMessage *msg, voi void process_audits_list(const char *adapter_path) { - struct slist *l, *next; + GSList *l, *next; for (l = audits; l != NULL; l = next) { struct adapter *adapter; @@ -692,7 +691,7 @@ void process_audits_list(const char *adapter_path) (void *) &adapter); if (!adapter) { - audits = slist_remove(audits, audit); + audits = g_slist_remove(audits, audit); name_listener_remove(audit->conn, audit->requestor, (name_cb_t) audit_requestor_exited, audit); audit_free(audit); @@ -706,7 +705,7 @@ void process_audits_list(const char *adapter_path) sk = l2raw_connect(adapter->address, &audit->peer); if (sk < 0) { send_audit_status(audit, "AuditRemoteDeviceFailed"); - audits = slist_remove(audits, audit); + audits = g_slist_remove(audits, audit); name_listener_remove(audit->conn, audit->requestor, (name_cb_t) audit_requestor_exited, audit); audit_free(audit); diff --git a/hcid/security.c b/hcid/security.c index 2bf4ce1d..2e416f09 100644 --- a/hcid/security.c +++ b/hcid/security.c @@ -50,7 +50,6 @@ #include "hcid.h" #include "textfile.h" -#include "list.h" #include "dbus-hci.h" struct g_io_info { @@ -63,7 +62,7 @@ static struct g_io_info io_data[HCI_MAX_DEV]; static int pairing = HCID_PAIRING_MULTI; -static struct slist *hci_req_queue = NULL; +static GSList *hci_req_queue = NULL; struct hci_req_data *hci_req_data_new(int dev_id, const bdaddr_t *dba, uint16_t ogf, uint16_t ocf, int event, const void *cparam, int clen) { @@ -111,7 +110,7 @@ static void hci_req_queue_process(int dev_id) dd = hci_open_dev(dev_id); do { struct hci_req_data *data; - struct slist *l = slist_find(hci_req_queue, &dev_id, hci_req_find_by_devid); + GSList *l = g_slist_find_custom(hci_req_queue, &dev_id, hci_req_find_by_devid); if (!l) break; @@ -121,7 +120,7 @@ static void hci_req_queue_process(int dev_id) ret_val = hci_send_cmd(dd, data->ogf, data->ocf, data->clen, data->cparam); if (ret_val < 0) { - hci_req_queue = slist_remove(hci_req_queue, data); + hci_req_queue = g_slist_remove(hci_req_queue, data); free(data->cparam); free(data); } @@ -133,13 +132,13 @@ static void hci_req_queue_process(int dev_id) void hci_req_queue_append(struct hci_req_data *data) { - struct slist *l; + GSList *l; struct hci_req_data *match; - hci_req_queue = slist_append(hci_req_queue, data); + hci_req_queue = g_slist_append(hci_req_queue, data); - l = slist_find(hci_req_queue, &data->dev_id, hci_req_find_by_devid); + l = g_slist_find_custom(hci_req_queue, &data->dev_id, hci_req_find_by_devid); match = l->data; if (match->status == REQ_SENT) @@ -150,7 +149,7 @@ void hci_req_queue_append(struct hci_req_data *data) void hci_req_queue_remove(int dev_id, bdaddr_t *dba) { - struct slist *cur, *next; + GSList *cur, *next; struct hci_req_data *req; for (cur = hci_req_queue; cur != NULL; cur = next) { @@ -159,7 +158,7 @@ void hci_req_queue_remove(int dev_id, bdaddr_t *dba) if ((req->dev_id != dev_id) || (bacmp(&req->dba, dba))) continue; - hci_req_queue = slist_remove(hci_req_queue, req); + hci_req_queue = g_slist_remove(hci_req_queue, req); free(req->cparam); free(req); } @@ -168,13 +167,13 @@ void hci_req_queue_remove(int dev_id, bdaddr_t *dba) static void check_pending_hci_req(int dev_id, int event) { struct hci_req_data *data; - struct slist *l; + GSList *l; if (!hci_req_queue) return; /* find the first element(pending)*/ - l = slist_find(hci_req_queue, &dev_id, hci_req_find_by_devid); + l = g_slist_find_custom(hci_req_queue, &dev_id, hci_req_find_by_devid); if (!l) return; @@ -187,7 +186,7 @@ static void check_pending_hci_req(int dev_id, int event) return; /* remove the confirmed cmd */ - hci_req_queue = slist_remove(hci_req_queue, data); + hci_req_queue = g_slist_remove(hci_req_queue, data); free(data->cparam); free(data); } -- cgit