]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/spotlight.c
Move and rename Spotlight module
[netatalk.git] / etc / afpd / spotlight.c
index 60d3679ae6b554f0251f160d10985da925e1b53f..eb4a125bf76b629db220df69fc84936399683c09 100644 (file)
@@ -36,8 +36,7 @@
 #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;
@@ -276,7 +275,6 @@ static int sl_rpc_fetchQueryResultsForContext(const AFPObj *obj, const DALLOC_CT
     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) );
@@ -286,20 +284,17 @@ static int sl_rpc_fetchQueryResultsForContext(const AFPObj *obj, const DALLOC_CT
 
     /* 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) {
@@ -323,6 +318,8 @@ static int sl_rpc_closeQueryForContext(const AFPObj *obj, const DALLOC_CTX *quer
 
     /* 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);
@@ -351,7 +348,7 @@ int sl_mod_load(const char *path)
     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;
     }
 
@@ -366,9 +363,19 @@ EC_CLEANUP:
     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;
@@ -384,6 +391,9 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_
 
     *rbuflen = 0;
 
+    if (sl_module == NULL)
+        return AFPERR_NOOP;
+
     ibuf += 2;
     ibuflen -= 2;