From 0391b4b4206b3cd181c3b9f97048fea65fd64a95 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Tue, 25 Sep 2012 11:34:44 +0200 Subject: [PATCH] Work on fixing filemeta handling --- etc/afpd/spotlight.c | 7 ++++--- etc/afpd/spotlight_marshalling.c | 34 ++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/etc/afpd/spotlight.c b/etc/afpd/spotlight.c index d83b7571..a57a15f4 100644 --- a/etc/afpd/spotlight.c +++ b/etc/afpd/spotlight.c @@ -65,6 +65,7 @@ static int dd_dump(DALLOC_CTX *dd, int nestinglevel) if (STRCMP(type, ==, "DALLOC_CTX") || STRCMP(type, ==, "sl_array_t") + || STRCMP(type, ==, "sl_filemeta_t") || STRCMP(type, ==, "sl_dict_t")) { dd_dump(dd->dd_talloc_array[n], nestinglevel + 1); } else if (STRCMP(type, ==, "uint64_t")) { @@ -79,13 +80,15 @@ static int dd_dump(DALLOC_CTX *dd, int nestinglevel) sl_bool_t bl; memcpy(&bl, dd->dd_talloc_array[n], sizeof(sl_bool_t)); LOG(log_debug, logtype_sl, "%sbool: %s", neststrings[nestinglevel + 1], bl ? "true" : "false"); + } else if (STRCMP(type, ==, "sl_nil_t")) { + LOG(log_debug, logtype_sl, "%snil", neststrings[nestinglevel + 1]); } else if (STRCMP(type, ==, "sl_cnids_t")) { sl_cnids_t cnids; memcpy(&cnids, dd->dd_talloc_array[n], sizeof(sl_cnids_t)); LOG(log_debug, logtype_sl, "%sCNIDs: unkn1: 0x%" PRIx16 ", unkn2: 0x%" PRIx32, neststrings[nestinglevel + 1], cnids.ca_unkn1, cnids.ca_context); if (cnids.ca_cnids) - dd_dump(cnids.ca_cnids, nestinglevel + 1); + dd_dump(cnids.ca_cnids, nestinglevel + 2); } } LOG(log_debug, logtype_sl, "%s}", neststrings[nestinglevel]); @@ -461,7 +464,6 @@ int main(int argc, char **argv) EC_NULL_LOG (int2 = dalloc_get(dd, "DALLOC_CTX", 6, "uint64_t", 1) ); LOG(log_debug, logtype_sl, "ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64, *int1, *int2); -#if 0 /* now parse a real spotlight packet */ if (argc > 1) { char ibuf[8192]; @@ -480,7 +482,6 @@ int main(int argc, char **argv) /* Now dump the whole thing */ dd_dump(query, 0); } -#endif #if 0 /* packing */ diff --git a/etc/afpd/spotlight_marshalling.c b/etc/afpd/spotlight_marshalling.c index 4b4a9b96..b74b4f9c 100644 --- a/etc/afpd/spotlight_marshalling.c +++ b/etc/afpd/spotlight_marshalling.c @@ -166,7 +166,7 @@ static int sl_pack_CNID(sl_cnids_t *cnids, char *buf, int offset, char *toc_buf, int cnid_count = talloc_array_length(cnids->ca_cnids); uint64_t id; - SLVAL(toc_buf, *toc_idx * 8, sl_pack_tag(SQ_CPX_TYPE_CNIDS, (offset + SL_OFFSET_DELTA) / 8, cnid_count)); + SLVAL(toc_buf, *toc_idx * 8, sl_pack_tag(SQ_CPX_TYPE_CNIDS, (offset + SL_OFFSET_DELTA) / 8, 0 /* cnid_count */)); SLVAL(buf, offset, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)); *toc_idx += 1; offset += 8; @@ -217,6 +217,25 @@ static int sl_pack_dict(sl_array_t *dict, char *buf, int offset, char *toc_buf, return offset; } +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; + + SLVAL(buf, offset, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)); + offset += 16; + + 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(toc_buf, *toc_idx * 8, sl_pack_tag(SQ_CPX_TYPE_FILEMETA, (offset + SL_OFFSET_DELTA) / 8, fmlen / 8)); + *toc_idx += 1; + + return offset; +} + static int sl_pack_string(char **string, char *buf, int offset, char *toc_buf, int *toc_idx) { int len, octets, used_in_last_octet; @@ -488,14 +507,15 @@ static int sl_unpack_cpx(DALLOC_CTX *query, uint8_t mark_exists; char *p; int qlen, used_in_last_block, slen; - sl_array_t *sl_arrary; + sl_array_t *sl_array; sl_dict_t *sl_dict; + sl_filemeta_t *sl_fm; switch (cpx_query_type) { case SQ_CPX_TYPE_ARRAY: - sl_arrary = talloc_zero(query, sl_array_t); - EC_NEG1_LOG( roffset = sl_unpack_loop(sl_arrary, buf, offset, cpx_query_count, toc_offset, encoding) ); - dalloc_add(query, sl_arrary, sl_array_t); + sl_array = talloc_zero(query, sl_array_t); + EC_NEG1_LOG( roffset = sl_unpack_loop(sl_array, buf, offset, cpx_query_count, toc_offset, encoding) ); + dalloc_add(query, sl_array, sl_array_t); break; case SQ_CPX_TYPE_DICT: @@ -530,7 +550,9 @@ static int sl_unpack_cpx(DALLOC_CTX *query, if (qlen <= 8) { EC_FAIL_LOG("SQ_CPX_TYPE_FILEMETA: query_length <= 8: %d", qlen); } else { - EC_NEG1_LOG( sl_unpack(query, buf + offset + 8) ); + sl_fm = talloc_zero(query, sl_filemeta_t); + EC_NEG1_LOG( sl_unpack(sl_fm, buf + offset + 8) ); + dalloc_add(query, sl_fm, sl_filemeta_t); } roffset += qlen; break; -- 2.39.2