#include <atalk/byteorder.h>
#include <atalk/netatalk_conf.h>
#include <atalk/volume.h>
-
-#include "spotlight.h"
+#include <atalk/spotlight.h>
static TALLOC_CTX *sl_ctx;
static void *sl_module;
EC_INIT;
slq_t *slq = NULL;
uint64_t *uint64, ctx1, ctx2;
- sl_array_t *array;
/* Context */
EC_NULL_LOG (uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1) );
/* Get query for context */
EC_NULL_LOG( slq = slq_for_ctx(ctx1, ctx2) );
- if (slq->slq_state != SLQ_STATE_RUNNING) {
- EC_FAIL_LOG("Spotlight: attempt to fetch results for query that isn't runnnig");
+ if (slq->slq_state != SLQ_STATE_RUNNING && slq->slq_state != SLQ_STATE_DONE) {
+ EC_FAIL_LOG("Spotlight: attempt to fetch results for query that isn't active");
}
/* Create and pass reply handle */
- array = talloc_zero(reply, sl_array_t);
- uint64_t sl_res = 0;
- dalloc_add_copy(array, &sl_res, uint64_t);
- slq->slq_reply = array;
+ EC_NULL( slq->slq_reply = talloc_zero(reply, sl_array_t) );
/* Fetch Tracker results*/
- EC_ZERO( sl_module_export->sl_mod_fetch_result(slq) );
+ EC_ZERO_LOG( sl_module_export->sl_mod_fetch_result(slq) );
- dalloc_add(reply, array, sl_array_t);
+ dalloc_add(reply, slq->slq_reply, sl_array_t);
EC_CLEANUP:
if (ret != 0) {
/* Get query for context and free it */
EC_NULL_LOG( slq = slq_for_ctx(ctx1, ctx2) );
+ if (slq->slq_state != SLQ_STATE_DONE)
+ LOG(log_warning, logtype_sl, "Closing active query");
sl_module_export->sl_mod_end_search(slq);
slq_remove(slq);
talloc_free(slq);
sl_ctx = talloc_new(NULL);
if ((sl_module = mod_open(path)) == NULL) {
- LOG(log_error, logtype_sl, "sl_mod_load(%s): failed to load: %s", path, mod_error());
+ LOG(log_error, logtype_sl, "Failed to load: %s", path, mod_error());
EC_FAIL;
}
EC_EXIT;
}
+/**
+ * Index a file
+ **/
+void sl_index_file(const char *path)
+{
+ if (sl_module_export && sl_module_export->sl_mod_index_file)
+ sl_module_export->sl_mod_index_file(path);
+}
+
/**************************************************************************************************
* AFP functions
**************************************************************************************************/
+
int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
{
EC_INIT;
*rbuflen = 0;
+ if (sl_module == NULL)
+ return AFPERR_NOOP;
+
ibuf += 2;
ibuflen -= 2;