]> arthur.barton.de Git - netatalk.git/commitdiff
Add checking for kMDQueryItemArray
authorRalph Boehme <sloowfranklin@gmail.com>
Fri, 18 Jan 2013 16:54:38 +0000 (17:54 +0100)
committerRalph Boehme <sloowfranklin@gmail.com>
Fri, 18 Jan 2013 16:54:38 +0000 (17:54 +0100)
etc/afpd/spotlight.c
etc/spotlight/slmod_tracker_0_6.c
include/atalk/spotlight.h

index d9d1d112db1d1ec55a7eddd3900d713f9d6e5809..8ea0a4595474fee561b03947d44bdb8ba00dca80 100644 (file)
@@ -224,6 +224,38 @@ EC_CLEANUP:
     EC_EXIT;
 }
 
+static int cnid_comp_fn(const void *p1, const void *p2)
+{
+    const uint64_t *cnid1 = p1, *cnid2 = p2;
+    if (*cnid1 == *cnid2)
+        return 0;
+    if (*cnid1 < *cnid2)
+        return -1;
+    else
+        return 1;            
+}
+
+static int sl_createCNIDArray(slq_t *slq, const DALLOC_CTX *p)
+{
+    EC_INIT;
+    uint64_t *cnids = NULL;
+
+    EC_NULL( cnids = talloc_array(slq, uint64_t, talloc_array_length(p)) );
+    for (int i = 0; i < talloc_array_length(p); i++)
+        memcpy(&cnids[i], p->dd_talloc_array[i], sizeof(uint64_t));
+    qsort(cnids, talloc_array_length(p), sizeof(uint64_t), cnid_comp_fn);
+
+    slq->slq_cnids = cnids;
+    slq->slq_cnids_num = talloc_array_length(p);
+
+EC_CLEANUP:
+    if (ret != 0) {
+        if (cnids)
+            talloc_free(cnids);
+    }
+    EC_EXIT;
+}
+
 static int sl_rpc_openQuery(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, struct vol *v)
 {
     EC_INIT;
@@ -231,6 +263,7 @@ static int sl_rpc_openQuery(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *re
     uint64_t *uint64;
     DALLOC_CTX *reqinfo;
     sl_array_t *array;
+    sl_cnids_t *cnids;
     slq_t *slq = NULL;
 
     /* Allocate and initialize query object */
@@ -249,12 +282,15 @@ static int sl_rpc_openQuery(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *re
     slq->slq_ctx2 = *uint64;
     EC_NULL_LOG( reqinfo = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, "kMDAttributeArray") );
     slq->slq_reqinfo = talloc_steal(slq, reqinfo);
-
+    if ((cnids = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, "kMDQueryItemArray"))) {
+        EC_ZERO_LOG( sl_createCNIDArray(slq, cnids->ca_cnids) );
+    }
+        
     LOG(log_maxdebug, logtype_sl, "sl_rpc_openQuery: requested attributes:");
     dd_dump(slq->slq_reqinfo, 0);
 
     (void)slq_add(slq);
-
+    
     /* Run the query */
     EC_ZERO( sl_module_export->sl_mod_start_search(slq) );
 
index b80992625ef97e1341866bcf07208161fc834bbb..42d716232371fde5f503285e9b3f46b988aa2d7e 100644 (file)
@@ -118,6 +118,17 @@ EC_CLEANUP:
     EC_EXIT;
 }
 
+static int cnid_cmp_fn(const void *p1, const void *p2)
+{
+    const uint64_t *cnid1 = p1, *cnid2 = p2;
+    if (*cnid1 == *cnid2)
+        return 0;
+    if (*cnid1 < *cnid2)
+        return -1;
+    else
+        return 1;            
+}
+
 static int sl_mod_fetch_result(void *p)
 {
     EC_INIT;
@@ -185,6 +196,11 @@ static int sl_mod_fetch_result(void *p)
             LOG(log_debug, logtype_sl, "Result %d: CNID: %" PRIu32 ", path: \"%s\"", i, ntohl(id), *result);
 
             uint64 = ntohl(id);
+            if (slq->slq_cnids) {
+                if (!bsearch(&uint64, slq->slq_cnids, slq->slq_cnids_num, sizeof(uint64_t), cnid_cmp_fn))
+                    goto loop_continue;
+            }
+
             dalloc_add_copy(cnids->ca_cnids, &uint64, uint64_t);
             add_filemeta(slq->slq_reqinfo, fm_array, id, *result);
 
index 8af8272f80b959e47f612d989ce2cb84e6bce4bf..8049a67663e91773754d8545155e7c3e61332395 100644 (file)
@@ -99,7 +99,8 @@ typedef struct _slq_t {
     uint64_t       slq_ctx2;          /* client context 2                                               */
     sl_array_t     *slq_reqinfo;      /* array with requested metadata                                  */
     const char     *slq_qstring;      /* the Spotlight query string                                     */
-
+    uint64_t       *slq_cnids;        /* Pointer to array with CNIDs to which a query applies           */
+    size_t         slq_cnids_num;    /* Size of slq_cnids array                                        */
 #ifdef HAVE_TRACKER_SPARQL
     void           *slq_tracker_cursor; /* Tracker SPARQL query result cursor                           */
 #endif