2 Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
27 #include <atalk/errchk.h>
28 #include <atalk/util.h>
29 #include <atalk/logger.h>
30 #include <atalk/talloc.h>
31 #include <atalk/dalloc.h>
32 #include <atalk/byteorder.h>
33 #include <atalk/netatalk_conf.h>
34 #include <atalk/volume.h>
35 #include <atalk/dsi.h>
37 #include "spotlight.h"
39 #define MAX_SLQ_DAT (DSI_DATASIZ - 64)
40 #define MAX_SLQ_TOC 8192
42 /**************************************************************************************************
43 * RPC data marshalling and unmarshalling
44 **************************************************************************************************/
46 /* Spotlight epoch is UNIX epoch minus SPOTLIGHT_TIME_DELTA */
47 #define SPOTLIGHT_TIME_DELTA INT64_C(280878921600U)
49 #define SQ_TYPE_NULL 0x0000
50 #define SQ_TYPE_COMPLEX 0x0200
51 #define SQ_TYPE_INT64 0x8400
52 #define SQ_TYPE_BOOL 0x0100
53 #define SQ_TYPE_FLOAT 0x8500
54 #define SQ_TYPE_DATA 0x0700
55 #define SQ_TYPE_CNIDS 0x8700
56 #define SQ_TYPE_UUID 0x0e00
57 #define SQ_TYPE_DATE 0x8600
58 #define SQ_TYPE_TOC 0x8800
60 #define SQ_CPX_TYPE_ARRAY 0x0a00
61 #define SQ_CPX_TYPE_STRING 0x0c00
62 #define SQ_CPX_TYPE_UTF16_STRING 0x1c00
63 #define SQ_CPX_TYPE_DICT 0x0d00
64 #define SQ_CPX_TYPE_CNIDS 0x1a00
65 #define SQ_CPX_TYPE_FILEMETA 0x1b00
67 #define SUBQ_SAFETY_LIM 20
69 /* Forward declarations */
70 static int sl_pack_loop(DALLOC_CTX *query, char *buf, int offset, char *toc_buf, int *toc_idx);
71 static int sl_unpack_loop(DALLOC_CTX *query, const char *buf, int offset, uint count, const uint toc_offset, const uint encoding);
73 /**************************************************************************************************
74 * Wrapper functions for the *VAL macros with bound checking
75 **************************************************************************************************/
77 static int sivalc(char *buf, off_t off, off_t maxoff, uint32_t val)
79 if (off + sizeof(val) >= maxoff) {
80 LOG(log_error, logtype_sl, "sivalc: off: %zd, maxoff: %zd", off, maxoff);
87 static int slvalc(char *buf, off_t off, off_t maxoff, uint64_t val)
89 if (off + sizeof(val) >= maxoff) {
90 LOG(log_error, logtype_sl, "slvalc: off: %zd, maxoff: %zd", off, maxoff);
98 * Returns the UTF-16 string encoding, by checking the 2-byte byte order mark.
99 * If there is no byte order mark, -1 is returned.
101 static uint spotlight_get_utf16_string_encoding(const char *buf, int offset, int query_length, uint encoding) {
104 /* check for byte order mark */
105 utf16_encoding = SL_ENC_BIG_ENDIAN;
106 if (query_length >= 2) {
107 uint16_t byte_order_mark;
108 if (encoding == SL_ENC_LITTLE_ENDIAN)
109 byte_order_mark = SVAL(buf, offset);
111 byte_order_mark = RSVAL(buf, offset);
113 if (byte_order_mark == 0xFFFE) {
114 utf16_encoding = SL_ENC_BIG_ENDIAN | SL_ENC_UTF_16;
116 else if (byte_order_mark == 0xFEFF) {
117 utf16_encoding = SL_ENC_LITTLE_ENDIAN | SL_ENC_UTF_16;
121 return utf16_encoding;
124 /**************************************************************************************************
125 * marshalling functions
126 **************************************************************************************************/
128 #define SL_OFFSET_DELTA 16
130 static uint64_t sl_pack_tag(uint16_t type, uint16_t size_or_count, uint32_t val)
132 uint64_t tag = ((uint64_t)val << 32) | ((uint64_t)type << 16) | size_or_count;
136 static int sl_pack_float(double d, char *buf, int offset)
145 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_FLOAT, 2, 1)) );
146 EC_ZERO( slvalc(buf, offset + 8, MAX_SLQ_DAT, ieee_fp_union.w) );
151 return offset + 2 * sizeof(uint64_t);
154 static int sl_pack_uint64(uint64_t u, char *buf, int offset)
158 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_INT64, 2, 1)) );
159 EC_ZERO( slvalc(buf, offset + 8, MAX_SLQ_DAT, u) );
164 return offset + 2 * sizeof(uint64_t);
167 static int sl_pack_bool(sl_bool_t bl, char *buf, int offset)
171 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_BOOL, 1, bl ? 1 : 0)) );
176 return offset + sizeof(uint64_t);
179 static int sl_pack_nil(char *buf, int offset)
183 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_NULL, 1, 1)) );
188 return offset + sizeof(uint64_t);
191 static int sl_pack_date(sl_time_t t, char *buf, int offset)
196 data = (t.tv_sec + SPOTLIGHT_TIME_DELTA) << 24;
198 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_DATE, 2, 1)) );
199 EC_ZERO( slvalc(buf, offset + 8, MAX_SLQ_DAT, data) );
204 return offset + 2 * sizeof(uint64_t);
207 static int sl_pack_uuid(sl_uuid_t *uuid, char *buf, int offset)
211 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_UUID, 3, 1)) );
212 if (offset + 8 + 16 >= MAX_SLQ_DAT)
214 memcpy(buf + offset + 8, uuid, 16);
219 return offset + sizeof(uint64_t) + 16;
222 static int sl_pack_CNID(sl_cnids_t *cnids, char *buf, int offset, char *toc_buf, int *toc_idx)
226 int cnid_count = talloc_array_length(cnids->ca_cnids->dd_talloc_array);
229 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_CNIDS, (offset + SL_OFFSET_DELTA) / 8, 0)) );
230 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
234 len = cnid_count + 1;
238 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_CNIDS, len, 8 /* unknown meaning, but always 8 */)) );
241 if (cnid_count > 0) {
242 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(0x0add, cnid_count, cnids->ca_context)) );
245 for (int i = 0; i < cnid_count; i++) {
246 memcpy(&id, cnids->ca_cnids->dd_talloc_array[i], sizeof(uint64_t));
247 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, id) );
258 static int sl_pack_array(sl_array_t *array, char *buf, int offset, char *toc_buf, int *toc_idx)
261 int count = talloc_array_length(array->dd_talloc_array);
262 int octets = (offset + SL_OFFSET_DELTA) / 8;
264 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_ARRAY, octets, count)) );
265 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
269 EC_NEG1( offset = sl_pack_loop(array, buf, offset, toc_buf, toc_idx) );
277 static int sl_pack_dict(sl_array_t *dict, char *buf, int offset, char *toc_buf, int *toc_idx)
281 EC_ZERO( slvalc(toc_buf,
284 sl_pack_tag(SQ_CPX_TYPE_DICT,
285 (offset + SL_OFFSET_DELTA) / 8,
286 talloc_array_length(dict->dd_talloc_array))) );
287 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
291 EC_NEG1( offset = sl_pack_loop(dict, buf, offset, toc_buf, toc_idx) );
299 static int sl_pack_filemeta(sl_filemeta_t *fm, char *buf, int offset, char *toc_buf, int *toc_idx)
302 int fmlen; /* lenght of filemeta */
303 int saveoff = offset;
305 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
308 EC_NEG1( fmlen = sl_pack(fm, buf + offset) );
310 /* Check for empty filemeta array, if it's only 40 bytes, it's only the header but no content */
311 LOG(log_debug, logtype_sl, "fmlen: %d", fmlen);
317 EC_ZERO( slvalc(buf, saveoff + 8, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_DATA, (fmlen / 8) + 1, 8 /* unknown meaning, but always 8 */)) );
319 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_FILEMETA, (saveoff + SL_OFFSET_DELTA) / 8, fmlen / 8)) );
328 static int sl_pack_string(char *s, char *buf, int offset, char *toc_buf, int *toc_idx)
331 int len, octets, used_in_last_octet;
334 octets = (len / 8) + (len & 7 ? 1 : 0);
335 used_in_last_octet = 8 - (octets * 8 - len);
337 EC_ZERO( slvalc(toc_buf, *toc_idx * 8, MAX_SLQ_TOC, sl_pack_tag(SQ_CPX_TYPE_STRING, (offset + SL_OFFSET_DELTA) / 8, used_in_last_octet)) );
338 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_COMPLEX, 1, *toc_idx + 1)) );
342 EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_DATA, octets + 1, used_in_last_octet)) );
345 if (offset + octets * 8 > MAX_SLQ_DAT)
347 memset(buf + offset, 0, octets * 8);
348 strncpy(buf + offset, s, len);
349 offset += octets * 8;
357 static int sl_pack_loop(DALLOC_CTX *query, char *buf, int offset, char *toc_buf, int *toc_idx)
362 for (int n = 0; n < talloc_array_length(query->dd_talloc_array); n++) {
364 type = talloc_get_name(query->dd_talloc_array[n]);
366 if (STRCMP(type, ==, "sl_array_t")) {
367 EC_NEG1( offset = sl_pack_array(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
368 } else if (STRCMP(type, ==, "sl_dict_t")) {
369 EC_NEG1( offset = sl_pack_dict(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
370 } else if (STRCMP(type, ==, "sl_filemeta_t")) {
371 EC_NEG1( offset = sl_pack_filemeta(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
372 } else if (STRCMP(type, ==, "uint64_t")) {
374 memcpy(&i, query->dd_talloc_array[n], sizeof(uint64_t));
375 EC_NEG1( offset = sl_pack_uint64(i, buf, offset) );
376 } else if (STRCMP(type, ==, "char *")) {
377 EC_NEG1( offset = sl_pack_string(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
378 } else if (STRCMP(type, ==, "sl_bool_t")) {
380 memcpy(&bl, query->dd_talloc_array[n], sizeof(sl_bool_t));
381 EC_NEG1( offset = sl_pack_bool(bl, buf, offset) );
382 } else if (STRCMP(type, ==, "double")) {
384 memcpy(&d, query->dd_talloc_array[n], sizeof(double));
385 EC_NEG1( offset = sl_pack_float(d, buf, offset) );
386 } else if (STRCMP(type, ==, "sl_nil_t")) {
387 EC_NEG1( offset = sl_pack_nil(buf, offset) );
388 } else if (STRCMP(type, ==, "sl_time_t")) {
390 memcpy(&t, query->dd_talloc_array[n], sizeof(sl_time_t));
391 EC_NEG1( offset = sl_pack_date(t, buf, offset) );
392 } else if (STRCMP(type, ==, "sl_uuid_t")) {
393 EC_NEG1( offset = sl_pack_uuid(query->dd_talloc_array[n], buf, offset) );
394 } else if (STRCMP(type, ==, "sl_cnids_t")) {
395 EC_NEG1( offset = sl_pack_CNID(query->dd_talloc_array[n], buf, offset, toc_buf, toc_idx) );
405 /**************************************************************************************************
406 * unmarshalling functions
407 **************************************************************************************************/
409 static uint64_t sl_unpack_uint64(const char *buf, int offset, uint encoding)
411 if (encoding == SL_ENC_LITTLE_ENDIAN)
412 return LVAL(buf, offset);
414 return RLVAL(buf, offset);
417 static int sl_unpack_ints(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
420 uint64_t query_data64;
422 query_data64 = sl_unpack_uint64(buf, offset, encoding);
423 count = query_data64 >> 32;
427 while (i++ < count) {
428 query_data64 = sl_unpack_uint64(buf, offset, encoding);
429 dalloc_add_copy(query, &query_data64, uint64_t);
436 static int sl_unpack_date(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
439 uint64_t query_data64;
442 query_data64 = sl_unpack_uint64(buf, offset, encoding);
443 count = query_data64 >> 32;
447 while (i++ < count) {
448 query_data64 = sl_unpack_uint64(buf, offset, encoding) >> 24;
449 t.tv_sec = query_data64 - SPOTLIGHT_TIME_DELTA;
451 dalloc_add_copy(query, &t, sl_time_t);
458 static int sl_unpack_uuid(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
461 uint64_t query_data64;
463 query_data64 = sl_unpack_uint64(buf, offset, encoding);
464 count = query_data64 >> 32;
468 while (i++ < count) {
469 memcpy(uuid.sl_uuid, buf + offset, 16);
470 dalloc_add_copy(query, &uuid, sl_uuid_t);
477 static int sl_unpack_floats(DALLOC_CTX *query, const char *buf, int offset, uint encoding)
480 uint64_t query_data64;
487 query_data64 = sl_unpack_uint64(buf, offset, encoding);
488 count = query_data64 >> 32;
492 while (i++ < count) {
493 if (encoding == SL_ENC_LITTLE_ENDIAN) {
494 #ifdef WORDS_BIGENDIAN
495 ieee_fp_union.w[0] = IVAL(buf, offset + 4);
496 ieee_fp_union.w[1] = IVAL(buf, offset);
498 ieee_fp_union.w[0] = IVAL(buf, offset);
499 ieee_fp_union.w[1] = IVAL(buf, offset + 4);
502 #ifdef WORDS_BIGENDIAN
503 ieee_fp_union.w[0] = RIVAL(buf, offset);
504 ieee_fp_union.w[1] = RIVAL(buf, offset + 4);
506 ieee_fp_union.w[0] = RIVAL(buf, offset + 4);
507 ieee_fp_union.w[1] = RIVAL(buf, offset);
510 dalloc_add_copy(query, &ieee_fp_union.d, double);
517 static int sl_unpack_CNID(DALLOC_CTX *query, const char *buf, int offset, int length, uint encoding)
521 uint64_t query_data64;
524 EC_NULL( cnids = talloc_zero(query, sl_cnids_t) );
525 EC_NULL( cnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX) );
528 /* that's permitted, it's an empty array */
531 query_data64 = sl_unpack_uint64(buf, offset, encoding);
532 count = query_data64 & 0xffff;
534 cnids->ca_unkn1 = (query_data64 & 0xffff0000) >> 16;
535 cnids->ca_context = query_data64 >> 32;
540 query_data64 = sl_unpack_uint64(buf, offset, encoding);
541 dalloc_add_copy(cnids->ca_cnids, &query_data64, uint64_t);
545 dalloc_add(query, cnids, sl_cnids_t);
551 static const char *spotlight_get_qtype_string(uint64_t query_type)
553 switch (query_type) {
556 case SQ_TYPE_COMPLEX:
573 static const char *spotlight_get_cpx_qtype_string(uint64_t cpx_query_type)
575 switch (cpx_query_type) {
576 case SQ_CPX_TYPE_ARRAY:
578 case SQ_CPX_TYPE_STRING:
580 case SQ_CPX_TYPE_UTF16_STRING:
581 return "utf-16 string";
582 case SQ_CPX_TYPE_DICT:
584 case SQ_CPX_TYPE_CNIDS:
586 case SQ_CPX_TYPE_FILEMETA:
593 static int sl_unpack_cpx(DALLOC_CTX *query,
597 uint cpx_query_count,
598 const uint toc_offset,
603 int roffset = offset;
604 uint64_t query_data64;
605 uint unicode_encoding;
608 int qlen, used_in_last_block, slen;
609 sl_array_t *sl_array;
611 sl_filemeta_t *sl_fm;
613 switch (cpx_query_type) {
614 case SQ_CPX_TYPE_ARRAY:
615 sl_array = talloc_zero(query, sl_array_t);
616 EC_NEG1_LOG( roffset = sl_unpack_loop(sl_array, buf, offset, cpx_query_count, toc_offset, encoding) );
617 dalloc_add(query, sl_array, sl_array_t);
620 case SQ_CPX_TYPE_DICT:
621 sl_dict = talloc_zero(query, sl_dict_t);
622 EC_NEG1_LOG( roffset = sl_unpack_loop(sl_dict, buf, offset, cpx_query_count, toc_offset, encoding) );
623 dalloc_add(query, sl_dict, sl_dict_t);
626 case SQ_CPX_TYPE_STRING:
627 case SQ_CPX_TYPE_UTF16_STRING:
628 query_data64 = sl_unpack_uint64(buf, offset, encoding);
629 qlen = (query_data64 & 0xffff) * 8;
630 used_in_last_block = query_data64 >> 32;
631 slen = qlen - 8 + used_in_last_block;
633 if (cpx_query_type == SQ_CPX_TYPE_STRING) {
634 p = dalloc_strndup(query, buf + offset + 8, slen);
636 unicode_encoding = spotlight_get_utf16_string_encoding(buf, offset + 8, slen, encoding);
637 mark_exists = (unicode_encoding & SL_ENC_UTF_16);
638 unicode_encoding &= ~SL_ENC_UTF_16;
639 EC_NEG1( convert_string_allocate(CH_UCS2, CH_UTF8, buf + offset + (mark_exists ? 18 : 16), slen, &p) );
642 dalloc_add(query, p, char *);
646 case SQ_CPX_TYPE_FILEMETA:
647 query_data64 = sl_unpack_uint64(buf, offset, encoding);
648 qlen = (query_data64 & 0xffff) * 8;
650 EC_FAIL_LOG("SQ_CPX_TYPE_FILEMETA: query_length <= 8: %d", qlen);
652 sl_fm = talloc_zero(query, sl_filemeta_t);
653 EC_NEG1_LOG( sl_unpack(sl_fm, buf + offset + 8) );
654 dalloc_add(query, sl_fm, sl_filemeta_t);
659 case SQ_CPX_TYPE_CNIDS:
660 query_data64 = sl_unpack_uint64(buf, offset, encoding);
661 qlen = (query_data64 & 0xffff) * 8;
662 EC_NEG1_LOG( sl_unpack_CNID(query, buf, offset + 8, qlen, encoding) );
676 static int sl_unpack_loop(DALLOC_CTX *query,
680 const uint toc_offset,
684 int i, toc_index, query_length;
686 uint64_t query_data64, query_type;
687 uint cpx_query_type, cpx_query_count;
691 while (count > 0 && (offset < toc_offset)) {
692 query_data64 = sl_unpack_uint64(buf, offset, encoding);
693 query_length = (query_data64 & 0xffff) * 8;
694 query_type = (query_data64 & 0xffff0000) >> 16;
695 if (query_length == 0)
698 switch (query_type) {
699 case SQ_TYPE_COMPLEX:
700 toc_index = (query_data64 >> 32) - 1;
701 query_data64 = sl_unpack_uint64(buf, toc_offset + toc_index * 8, encoding);
702 cpx_query_type = (query_data64 & 0xffff0000) >> 16;
703 cpx_query_count = query_data64 >> 32;
705 EC_NEG1_LOG( offset = sl_unpack_cpx(query, buf, offset + 8, cpx_query_type, cpx_query_count, toc_offset, encoding));
709 subcount = query_data64 >> 32;
713 for (i = 0; i < subcount; i++)
714 dalloc_add_copy(query, &nil, sl_nil_t);
715 offset += query_length;
719 b = query_data64 >> 32;
720 dalloc_add_copy(query, &b, sl_bool_t);
721 offset += query_length;
725 EC_NEG1_LOG( subcount = sl_unpack_ints(query, buf, offset, encoding) );
726 offset += query_length;
730 EC_NEG1_LOG( subcount = sl_unpack_uuid(query, buf, offset, encoding) );
731 offset += query_length;
735 EC_NEG1_LOG( subcount = sl_unpack_floats(query, buf, offset, encoding) );
736 offset += query_length;
740 EC_NEG1_LOG( subcount = sl_unpack_date(query, buf, offset, encoding) );
741 offset += query_length;
756 /**************************************************************************************************
757 * Global functions for packing und unpacking
758 **************************************************************************************************/
760 int sl_pack(DALLOC_CTX *query, char *buf)
763 char toc_buf[MAX_SLQ_TOC];
767 memcpy(buf, "432130dm", 8);
768 EC_NEG1_LOG( len = sl_pack_loop(query, buf + 16, 0, toc_buf + 8, &toc_index) );
769 EC_ZERO( sivalc(buf, 8, MAX_SLQ_DAT, len / 8 + 1 + toc_index + 1) );
770 EC_ZERO( sivalc(buf, 12, MAX_SLQ_DAT, len / 8 + 1) );
772 EC_ZERO( slvalc(toc_buf, 0, MAX_SLQ_TOC, sl_pack_tag(SQ_TYPE_TOC, toc_index + 1, 0)) );
773 if ((16 + len + ((toc_index + 1 ) * 8)) >= MAX_SLQ_DAT)
775 memcpy(buf + 16 + len, toc_buf, (toc_index + 1 ) * 8);
776 len += 16 + (toc_index + 1 ) * 8;
784 int sl_unpack(DALLOC_CTX *query, const char *buf)
787 int encoding, i, toc_entries;
788 uint64_t toc_offset, tquerylen, toc_entry;
790 if (strncmp(buf, "md031234", 8) == 0)
791 encoding = SL_ENC_BIG_ENDIAN;
793 encoding = SL_ENC_LITTLE_ENDIAN;
797 toc_offset = ((sl_unpack_uint64(buf, 0, encoding) >> 32) - 1 ) * 8;
798 if (toc_offset < 0 || (toc_offset > 65000)) {
804 toc_entries = (int)(sl_unpack_uint64(buf, toc_offset, encoding) & 0xffff);
806 EC_NEG1( sl_unpack_loop(query, buf, 0, 1, toc_offset + 8, encoding) );