]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/spotlight_marshalling.c
Spotlight: use async Tracker SPARQL API
[netatalk.git] / etc / afpd / spotlight_marshalling.c
index 6f0aaca9a0ab506fa2c182ebd38b6b18f424d4fc..9329dde23a20af14f4a16c5277299977e30c666e 100644 (file)
@@ -104,14 +104,12 @@ static uint spotlight_get_utf16_string_encoding(const char *buf, int offset, int
     utf16_encoding = SL_ENC_LITTLE_ENDIAN;
 
     if (query_length >= 2) {
-        uint16_t byte_order_mark;
-        memcpy(&byte_order_mark, buf + offset, sizeof(uint16_t));
-        if (byte_order_mark == 0xFFFE) {
+        uint8_t le_bom[] = {0xff, 0xfe};
+        uint8_t be_bom[] = {0xfe, 0xff};
+        if (memcmp(le_bom, buf + offset, sizeof(uint16_t)) == 0)
             utf16_encoding = SL_ENC_LITTLE_ENDIAN | SL_ENC_UTF_16;
-        }
-        else if (byte_order_mark == 0xFEFF) {
+        else if (memcmp(be_bom, buf + offset, sizeof(uint16_t)) == 0)
             utf16_encoding = SL_ENC_BIG_ENDIAN | SL_ENC_UTF_16;
-        }
     }
 
     return utf16_encoding;
@@ -218,7 +216,7 @@ EC_CLEANUP:
 static int sl_pack_CNID(sl_cnids_t *cnids, char *buf, int offset, char *toc_buf, int *toc_idx)
 {
     EC_INIT;
-    int off = 0, len;
+    int len;
     int cnid_count = talloc_array_length(cnids->ca_cnids->dd_talloc_array);
     uint64_t id;
 
@@ -235,7 +233,7 @@ static int sl_pack_CNID(sl_cnids_t *cnids, char *buf, int offset, char *toc_buf,
     offset += 8;
 
     if (cnid_count > 0) {
-        EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(0x0add, cnid_count, cnids->ca_context)) );
+        EC_ZERO( slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(cnids->ca_unkn1, cnid_count, cnids->ca_context)) );
         offset += 8;
 
         for (int i = 0; i < cnid_count; i++) {
@@ -474,7 +472,6 @@ static int sl_unpack_floats(DALLOC_CTX *query, const char *buf, int offset, uint
 {
     int count, i;
     uint64_t query_data64;
-    double fval;
     union {
         double d;
         uint32_t w[2];
@@ -624,7 +621,7 @@ static int sl_unpack_cpx(DALLOC_CTX *query,
         query_data64 = sl_unpack_uint64(buf, offset, encoding);
         qlen = (query_data64 & 0xffff) * 8;
         used_in_last_block = query_data64 >> 32;
-        slen = qlen - 8 + used_in_last_block;
+        slen = qlen - 16 + used_in_last_block;
 
         if (cpx_query_type == SQ_CPX_TYPE_STRING) {
             p = dalloc_strndup(query, buf + offset + 8, slen);
@@ -633,7 +630,12 @@ static int sl_unpack_cpx(DALLOC_CTX *query,
             mark_exists = (unicode_encoding & SL_ENC_UTF_16);
             if (unicode_encoding & SL_ENC_BIG_ENDIAN)
                 EC_FAIL_LOG("Unsupported big endian UTF16 string");
-            EC_NEG1( convert_string_allocate(CH_UCS2, CH_UTF8, buf + offset + (mark_exists ? 10 : 8), slen, &tmp) );
+            slen -= mark_exists ? 2 : 0;
+            EC_NEG1( convert_string_allocate(CH_UCS2,
+                                             CH_UTF8,
+                                             buf + offset + (mark_exists ? 10 : 8),
+                                             slen,
+                                             &tmp) );
             p = dalloc_strndup(query, tmp, strlen(tmp));
             free(tmp);
         }
@@ -783,8 +785,8 @@ EC_CLEANUP:
 int sl_unpack(DALLOC_CTX *query, const char *buf)
 {
     EC_INIT;
-    int encoding, i, toc_entries;
-    uint64_t toc_offset, tquerylen, toc_entry;
+    int encoding, toc_entries;
+    uint64_t toc_offset;
 
     if (strncmp(buf, "md031234", 8) == 0)
         encoding = SL_ENC_BIG_ENDIAN;