]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/spotlight.c
Start working on replying queries, add struct for storing query and a queue
[netatalk.git] / etc / afpd / spotlight.c
index 8eb26a7eb7fddea7b0626a6d525ac0e9a8d6ebbe..205a20e18b4c4e5ea9ae1ebb8b52105bfffd90a7 100644 (file)
 #include <atalk/byteorder.h>
 #include <atalk/netatalk_conf.h>
 #include <atalk/volume.h>
+#include <atalk/queue.h>
 
 #include "spotlight.h"
 
+static void *sl_module;
+static struct sl_module_export *sl_module_export;
+static q_t *sl_queries;
 
 /* Helper functions and stuff */
 static const char *neststrings[] = {
@@ -144,6 +148,40 @@ EC_CLEANUP:
 static int sl_rpc_openQuery(const AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, const struct vol *v)
 {
     EC_INIT;
+
+    char **sl_query;
+    EC_NULL_LOG( sl_query = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, "kMDQueryString") );
+
+    LOG(log_debug, logtype_sl, "sl_rpc_openQuery: %s", *sl_query);
+
+    enqueue(sl_queries, query);
+
+EC_CLEANUP:
+    EC_EXIT;
+}
+
+/**************************************************************************************************
+ * Spotlight module functions
+ **************************************************************************************************/
+
+int sl_mod_load(const char *path)
+{
+    EC_INIT;
+
+    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());
+        EC_FAIL;
+    }
+
+    if ((sl_module_export = mod_symbol(sl_module, "sl_mod")) == NULL) {
+        LOG(log_error, logtype_sl, "sl_mod_load(%s): mod_symbol error for symbol %s", path, "sl_mod");
+        EC_FAIL;
+    }
+
+    sl_module_export->sl_mod_init("test");
+   
 EC_CLEANUP:
     EC_EXIT;
 }
@@ -204,16 +242,12 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_
         DALLOC_CTX *reply;
         EC_NULL( reply = talloc_zero(tmp_ctx, DALLOC_CTX) );
 
-        ret = sl_unpack(query, ibuf + 22);
+        EC_NEG1_LOG( sl_unpack(query, ibuf + 22) );
         dd_dump(query, 0);
-        if (ret != 0) {
-            LOG(log_error, logtype_sl, "sl_unpack");
-            EC_FAIL;
-        }
+
         char **cmd;
         EC_NULL_LOG( cmd = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "char *", 0) );
 
-
         if (STRCMP(*cmd, ==, "fetchPropertiesForContext:")) {
             EC_ZERO_LOG( sl_rpc_fetchPropertiesForContext(obj, query, reply, vol) );
         } else if (STRCMP(*cmd, ==, "openQueryWithParams:forContext:")) {
@@ -225,19 +259,15 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_
             }
         }
 
-        /* Spotlight RPC status code ? 0 in all traces, we use 0xffffffff for an error, never seen from Apple */
-        if (ret == 0)
-            memset(rbuf, 0, 4);
-        else
-            memset(rbuf, 0xff, 4);
+        dd_dump(reply, 0);
+
+        memset(rbuf, 0, 4);
         *rbuflen += 4;
 
         int len;
         EC_NEG1_LOG( len = sl_pack(reply, rbuf + 4) );
         *rbuflen += len;
 
-        dd_dump(reply, 0);
-
         break;
     }
     }