From: Frank Lahm Date: Tue, 25 Sep 2012 21:43:17 +0000 (+0200) Subject: Fixes X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=b679135397ad722494f3e89839ba8395c8996e23 Fixes --- diff --git a/etc/afpd/spotlight.c b/etc/afpd/spotlight.c index 0945f714..9a50383f 100644 --- a/etc/afpd/spotlight.c +++ b/etc/afpd/spotlight.c @@ -218,7 +218,6 @@ 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); - slq->slq_metacount = dalloc_size(slq->slq_reqinfo); LOG(log_maxdebug, logtype_sl, "sl_rpc_openQuery: requested attributes:"); dd_dump(slq->slq_reqinfo, 0); diff --git a/etc/afpd/spotlight.h b/etc/afpd/spotlight.h index da7aaf65..6dcd9614 100644 --- a/etc/afpd/spotlight.h +++ b/etc/afpd/spotlight.h @@ -95,8 +95,7 @@ typedef struct { uint64_t slq_ctx1; /* client context 1 */ uint64_t slq_ctx2; /* client context 2 */ const char *slq_qstring; /* the Spotlight query string */ - DALLOC_CTX *slq_reqinfo; /* array with requested metadata */ - int slq_metacount; /* number of requested metadata attributes in slq_reqinfo */ + sl_array_t *slq_reqinfo; /* array with requested metadata */ void *slq_tracker_cursor; /* Tracker query result cursor */ } slq_t; diff --git a/etc/afpd/spotlight_marshalling.c b/etc/afpd/spotlight_marshalling.c index 1df56066..f91a83be 100644 --- a/etc/afpd/spotlight_marshalling.c +++ b/etc/afpd/spotlight_marshalling.c @@ -220,7 +220,7 @@ static int sl_pack_dict(sl_array_t *dict, char *buf, int offset, char *toc_buf, static int sl_pack_filemeta(sl_filemeta_t *fm, char *buf, int offset, char *toc_buf, int *toc_idx) { int fmlen; /* lenght of filemeta */ - int saveoff = offset + 8; + int saveoff = offset; SLVAL(buf, offset, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)); offset += 16; @@ -228,9 +228,9 @@ static int sl_pack_filemeta(sl_filemeta_t *fm, char *buf, int offset, char *toc_ fmlen = sl_pack(fm, buf + offset); offset += fmlen; - SLVAL(buf, saveoff, sl_pack_tag(SQ_TYPE_DATA, (fmlen / 8) + 1, 8 /* unknown meaning, but always 8 */)); + SLVAL(buf, saveoff + 8, sl_pack_tag(SQ_TYPE_DATA, (fmlen / 8) + 1, 8 /* unknown meaning, but always 8 */)); - SLVAL(toc_buf, *toc_idx * 8, sl_pack_tag(SQ_CPX_TYPE_FILEMETA, (offset + SL_OFFSET_DELTA) / 8, fmlen / 8)); + SLVAL(toc_buf, *toc_idx * 8, sl_pack_tag(SQ_CPX_TYPE_FILEMETA, (saveoff + SL_OFFSET_DELTA) / 8, fmlen / 8)); *toc_idx += 1; return offset; diff --git a/etc/afpd/spotlight_module.c b/etc/afpd/spotlight_module.c index d9a3280b..a475c8e4 100644 --- a/etc/afpd/spotlight_module.c +++ b/etc/afpd/spotlight_module.c @@ -136,19 +136,30 @@ EC_CLEANUP: EC_EXIT; } -static int add_filemeta(DALLOC_CTX *reqinfo, const int metacount, sl_array_t *fm_array, cnid_t id, const char *path) +static int add_filemeta(sl_array_t *reqinfo, sl_array_t *fm_array, cnid_t id, const char *path) { EC_INIT; sl_array_t *meta; sl_nil_t nil = 0; - int i = metacount; + int i, metacount; + + if ((metacount = talloc_array_length(reqinfo->dd_talloc_array)) == 0) + EC_FAIL; LOG(log_debug, logtype_sl, "add_filemeta: metadata count: %d", metacount); meta = talloc_zero(fm_array, sl_array_t); - while (i--) { - dalloc_add_copy(meta, &nil, sl_nil_t); + for (i = 0; i < metacount; i++) { + if (STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemDisplayName")) { + char *p, *name; + if ((p = strrchr(path, '/'))) { + name = dalloc_strdup(meta, p + 1); + dalloc_add(meta, name, "char *"); + } + } else { + dalloc_add_copy(meta, &nil, sl_nil_t); + } } dalloc_add(fm_array, meta, sl_array_t); @@ -186,6 +197,10 @@ static int sl_mod_fetch_result(void *p) fm_array = talloc_zero(fm, sl_array_t); dalloc_add(fm, fm_array, sl_array_t); + /* For some reason the list of results always starts with a nil entry */ + sl_nil_t nil; + dalloc_add_copy(fm_array, &nil, sl_nil_t); + while (tracker_sparql_cursor_next(slq->slq_tracker_cursor, NULL, &error)) { EC_NULL_LOG( path = tracker_sparql_cursor_get_string(slq->slq_tracker_cursor, 0, NULL) ); path = tracker_to_unix_path(path); @@ -197,7 +212,8 @@ static int sl_mod_fetch_result(void *p) LOG(log_debug, logtype_sl, "Result %d: CNID: %" PRIu32 ", path: \"%s\"", i++, ntohl(id), path); uint64 = ntohl(id); dalloc_add_copy(cnids->ca_cnids, &uint64, uint64_t); - add_filemeta(slq->slq_reqinfo, slq->slq_metacount, fm_array, id, path); + add_filemeta(slq->slq_reqinfo, fm_array, id, path); + //dalloc_add_copy(fm_array, &nil, sl_nil_t); } dalloc_add(slq->slq_reply, cnids, sl_cnids_t); dalloc_add(slq->slq_reply, fm, sl_filemeta_t);