From e2729966ff89f6ee99b3875f53533030e2622643 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Fri, 28 Sep 2012 23:29:49 +0200 Subject: [PATCH] Use a linked list for the SL queries --- etc/afpd/spotlight.c | 55 ++++++++++++++++++++++++++------------------ etc/afpd/spotlight.h | 3 ++- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/etc/afpd/spotlight.c b/etc/afpd/spotlight.c index a8124897..60d3679a 100644 --- a/etc/afpd/spotlight.c +++ b/etc/afpd/spotlight.c @@ -12,6 +12,8 @@ GNU General Public License for more details. */ +#define USE_LIST + #ifdef HAVE_CONFIG_H #include "config.h" #endif /* HAVE_CONFIG_H */ @@ -25,6 +27,7 @@ #include #include +#include #include #include #include @@ -33,7 +36,6 @@ #include #include #include -#include #include "spotlight.h" @@ -98,30 +100,35 @@ static int dd_dump(DALLOC_CTX *dd, int nestinglevel) * Spotlight queries **************************************************************************************************/ -static q_t *sl_queries; -static slq_t *slq_active; +static ATALK_LIST_HEAD(sl_queries); /*! * Add a query to the list of active queries */ static int slq_add(slq_t *slq) { - EC_INIT; - - if (slq_active) - talloc_free(slq_active); - slq_active = slq; - -EC_CLEANUP: - EC_EXIT; + list_add(&(slq->slq_list), &sl_queries); + return 0; } static int slq_remove(slq_t *slq) { EC_INIT; + struct list_head *p; + slq_t *q = NULL; + + list_for_each(p, &sl_queries) { + q = list_entry(p, slq_t, slq_list); + if ((q->slq_ctx1 == slq->slq_ctx1) && (q->slq_ctx2 == slq->slq_ctx2)) { + list_del(p); + break; + } + q = NULL; + } - if ((slq_active->slq_ctx1 == slq->slq_ctx1) && (slq_active->slq_ctx2 == slq->slq_ctx2)) { - slq_active = NULL; + if (q == NULL) { + /* The SL query 'slq' was not found in the list, this is not supposed to happen! */ + LOG(log_warning, logtype_sl, "slq_remove: slq not in active query list"); } EC_CLEANUP: @@ -131,17 +138,22 @@ EC_CLEANUP: static slq_t *slq_for_ctx(uint64_t ctx1, uint64_t ctx2) { EC_INIT; - slq_t *q; + slq_t *q = NULL; + struct list_head *p; - LOG(log_debug, logtype_sl, "slq_for_ctx(ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64 - "): active: ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64, - ctx1, ctx2, slq_active->slq_ctx1, slq_active->slq_ctx2); + list_for_each(p, &sl_queries) { + q = list_entry(p, slq_t, slq_list); - if ((slq_active->slq_ctx1 == ctx1) && (slq_active->slq_ctx2 == ctx2)) - q = slq_active; - else + LOG(log_debug, logtype_sl, "slq_for_ctx(ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64 + "): active: ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64, + ctx1, ctx2, q->slq_ctx1, q->slq_ctx2); + + if ((q->slq_ctx1 == ctx1) && (q->slq_ctx2 == ctx2)) { + break; + } q = NULL; - + } + EC_CLEANUP: if (ret != 0) q = NULL; @@ -337,7 +349,6 @@ int sl_mod_load(const char *path) EC_INIT; sl_ctx = talloc_new(NULL); - sl_queries = queue_init(); if ((sl_module = mod_open(path)) == NULL) { LOG(log_error, logtype_sl, "sl_mod_load(%s): failed to load: %s", path, mod_error()); diff --git a/etc/afpd/spotlight.h b/etc/afpd/spotlight.h index 0885c96d..49a8fac0 100644 --- a/etc/afpd/spotlight.h +++ b/etc/afpd/spotlight.h @@ -87,7 +87,8 @@ typedef enum { } slq_state_t; /* Internal query data structure */ -typedef struct { +typedef struct _slq_t { + struct list_head slq_list; /* queries are stored in a list */ slq_state_t slq_state; /* State */ AFPObj *slq_obj; /* global AFPObj handle */ const struct vol *slq_vol; /* volume handle */ -- 2.39.2