+Changes in 2.2.2
+================
+* FIX: dbd: Better checking for duplicated or bogus CNIDs from AppleDouble files
+
Changes in 2.2.1
================
-2.2.1
\ No newline at end of file
+2.2.2dev
\ No newline at end of file
contrib/Makefile
contrib/macusers/Makefile
contrib/macusers/macusers
+ contrib/misc/Makefile
contrib/printing/Makefile
contrib/shell_utils/Makefile
contrib/shell_utils/apple_dump
# Makefile.am for contrib/
-SUBDIRS = macusers shell_utils
+SUBDIRS = macusers misc shell_utils
if COMPILE_TIMELORD
SUBDIRS += timelord
--- /dev/null
+# Makefile for contrib/misc/
+
+EXTRA_DIST = cnid.lua
--- /dev/null
+--
+-- Netatalk DBD protocol
+-- wireshark -X lua_script:cnid.lua
+-- don't forget to comment out the line disable_lua = true; do return end;
+-- in /etc/wireshark/init.lua
+
+-- global environment
+local b = _G
+
+-- declare our protocol
+local dbd_proto = Proto("dbd","Netatalk Dbd Wire Protocol")
+
+local cmd = ProtoField.uint32("dbd.cmd", "Request") -- , base.HEX
+local len = ProtoField.uint32("dbd.name.len", "Name Length")
+local filename = ProtoField.string("dbd.name", "Name")
+local error = ProtoField.uint32("dbd.error", "Error code")
+local cnid = ProtoField.uint32("dbd.cnid", "Cnid")
+local did = ProtoField.uint32("dbd.did", "Parent Directory Id")
+local dev = ProtoField.uint64("dbd.dev", "Device number")
+local ino = ProtoField.uint64("dbd.ino", "Inode number")
+local type = ProtoField.uint32("dbd.type", "File type")
+
+dbd_proto.fields = {cmd, error, cnid, did, dev, ino, type, filename, len}
+
+--- Request list
+local Cmd = { [3] = "add",
+ [4] = "get",
+ [5] = "resolve",
+ [6] = "lookup",
+ [7] = "update",
+ [8] = "delete",
+ [11] = "timestamp"
+ }
+
+--- display a filename
+local function fname(buffer, pinfo, tree, len, ofs)
+
+ pinfo.cols.info:append(" Name=" .. buffer(ofs +4, len):string())
+
+ local subtree = tree:add(buffer(ofs, len +4), buffer(ofs +4, len):string())
+ subtree:add(filename, buffer(ofs +4, len))
+
+ return subtree
+end
+
+-- create a function to dissect it
+function dbd_proto.dissector(buffer, pinfo, tree)
+
+
+ pinfo.cols.protocol = "DBD"
+
+ local subtree = tree:add(dbd_proto,buffer(),"Netatalk DBD Wire Protocol")
+
+ if pinfo.dst_port == 4700 then
+ pinfo.cols.info = "Query"
+ local val = buffer(0,4):uint()
+ local item = subtree:add(cmd, buffer(0,4))
+ if Cmd[val] then
+ item:append_text(" (" .. Cmd[val] .. ")")
+ pinfo.cols.info = Cmd[val]
+
+ local val = buffer(4,4):uint()
+ if val ~= 0 then
+ pinfo.cols.info:append(" Cnid=" .. val)
+ end
+ subtree:add(cnid, buffer(4, 4))
+ subtree:add(dev, buffer(8, 8))
+ subtree:add(ino, buffer(16, 8))
+ subtree:add(type, buffer(24, 4))
+
+ local val = buffer(28,4):uint()
+ if val ~= 0 then
+ pinfo.cols.info:append(" Did=" .. val)
+ end
+ subtree:add(did, buffer(28, 4))
+
+ local val = buffer(36,4):uint()
+ if val ~= 0 then
+ item = fname(buffer, pinfo, subtree, val, 36)
+ item:add(len, buffer(36, 4))
+
+ end
+ end
+ else
+ pinfo.cols.info = "Reply"
+
+ local rply = {}
+
+ local val = buffer(0,4):uint()
+ rply.error = val
+ subtree:add(error, buffer(0,4))
+ if val ~= 0 then
+ pinfo.cols.info:append(" Error=" .. val)
+ end
+
+ val = buffer(4,4):uint()
+ rply.cnid = val
+ subtree:add(cnid, buffer(4,4))
+ if val ~= 0 then
+ pinfo.cols.info:append(" Cnid=" .. val)
+ end
+
+ val = buffer(8,4):uint()
+ rply.did = val
+ subtree:add(did, buffer(8,4))
+ if val ~= 0 then
+ pinfo.cols.info:append(" Did=" .. val)
+ end
+
+ val = buffer(16,4):uint()
+ rply.len = val
+
+ if rply.error == 0 and rply.did ~= 0 then
+ subtree = fname(buffer, pinfo, subtree, val, 16)
+ subtree:add(len, buffer(16,4))
+ end
+ end
+end
+
+-- load the tcp.port table
+local tcp_table = DissectorTable.get("tcp.port")
+-- register our protocol
+tcp_table:add(4700, dbd_proto)
+++ /dev/null
-#!/usr/bin/perl
-#
-# usage: make-casetable.pl <infile> <outfile1> <outfile2>
-# make-casetable.pl UnicodeData.txt utf16_casetable.h utf16_case.c
-#
-# (c) 2011 by HAT <hat@fa2.so-net.ne.jp>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-
-# See
-# http://www.unicode.org/reports/tr44/
-# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
-
-# One block has 64 chars.
-#
-# BMP
-# block 0 = dummy
-# block 1 = U+0000 - U+003F
-# block 2 = U+0040 - U+007F
-# .....
-# block 1024 = U+FFC0 - U+FFFF
-# block 1025 = dummy
-#
-# Surrogate Pair
-# block 1024 = dummy
-# block 1025 = U+010000 - U+01003F
-# block 1026 = U+010040 - U+01007F
-# .....
-# block 17408 = U+10FFC0 - U+10FFFF
-# block 17409 = dummy
-#
-# Dummy block is for edge detection.
-# If block include upper/lower chars, block_enable[]=1.
-
-use strict;
-use warnings;
-
-our $code0;
-our $Name1;
-our $General_Category2;
-our $Canonical_Combining_Class3;
-our $Bidi_Class4;
-our $Decomposition_Mapping5;
-our $Numeric_Value6;
-our $Numeric_Value7;
-our $Numeric_Value8;
-our $Bidi_Mirrored9;
-our $Unicode_1_Name10;
-our $ISO_Comment11;
-our $Simple_Uppercase_Mapping12;
-our $Simple_Lowercase_Mapping13;
-our $Simple_Titlecase_Mapping14;
-
-our $hex_code0;
-our $Mapping;
-our $hex_Mapping;
-
-our $char;
-our $sp;
-our $block;
-
-our @table;
-our @table_sp;
-
-our @block_enable;
-our @block_enable_sp;
-
-our $table_no;
-our $block_start;
-our $block_end;
-our $char_start;
-our $char_end;
-
-open(CHEADER, ">$ARGV[1]");
-open(CSOURCE, ">$ARGV[2]");
-
-printf (CHEADER "\/\*\n");
-printf (CHEADER "DO NOT EDIT BY HAND\!\!\!\n");
-printf (CHEADER "\n");
-printf (CHEADER "This file is generated by\n");
-printf (CHEADER " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
-printf (CHEADER "\n");
-printf (CHEADER "%s is got from\n", $ARGV[0]);
-printf (CHEADER "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
-printf (CHEADER "\*\/\n");
-printf (CHEADER "\n");
-
-printf (CSOURCE "\/\*\n");
-printf (CSOURCE "DO NOT EDIT BY HAND\!\!\!\n");
-printf (CSOURCE "\n");
-printf (CSOURCE "This file is generated by\n");
-printf (CSOURCE " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
-printf (CSOURCE "\n");
-printf (CSOURCE "%s is got from\n", $ARGV[0]);
-printf (CSOURCE "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
-printf (CSOURCE "\*\/\n");
-printf (CSOURCE "\n");
-printf (CSOURCE "\#include \<stdint.h\>\n");
-printf (CSOURCE "\#include \<atalk\/unicode.h\>\n");
-printf (CSOURCE "\#include \"%s\"\n", $ARGV[1]);
-printf (CSOURCE "\n");
-
-&make_array("upper");
-&make_array("lower");
-
-printf (CHEADER "\/\* EOF \*\/\n");
-printf (CSOURCE "\/\* EOF \*\/\n");
-
-close(CHEADER);
-close(CSOURCE);
-
-
-###########################################################################
-sub make_array{
-
- # init table -----------------------------------------------------
-
- for ($char = 0 ; $char <= 0xFFFF ; $char++) {
- $table[$char][0] = $char; # mapped char
- $table[$char][1] = $char; # orig char
- $table[$char][2] = ""; # char name
- }
-
- for ($char = 0x10000 ; $char <= 0x10FFFF ; $char++) {
- $sp = ((0xD800 - (0x10000 >> 10) + ($char >> 10)) << 16)
- + (0xDC00 + ($char & 0x3FF));
- $table_sp[$char][0] = $sp; # mapped surrogate pair
- $table_sp[$char][1] = $sp; # orig surrogate pair
- $table_sp[$char][2] = $char; # mapped char
- $table_sp[$char][3] = $char; # orig char
- $table_sp[$char][4] = ""; # char name
- }
-
- for ($block = 0 ; $block <= 1025 ; $block++) {
- $block_enable[$block] = 0;
- }
-
- $block_enable[1] = 1; # ASCII block is forcibly included
- $block_enable[2] = 1; # in the array for Speed-Up.
-
- for ($block = 1024 ; $block <= 17409 ; $block++) {
- $block_enable_sp[$block] = 0;
- }
-
- # write data to table --------------------------------------------
-
- open(UNICODEDATA, "<$ARGV[0]");
-
- while (<UNICODEDATA>) {
- chop;
- (
- $code0,
- $Name1,
- $General_Category2,
- $Canonical_Combining_Class3,
- $Bidi_Class4,
- $Decomposition_Mapping5,
- $Numeric_Value6,
- $Numeric_Value7,
- $Numeric_Value8,
- $Bidi_Mirrored9,
- $Unicode_1_Name10,
- $ISO_Comment11,
- $Simple_Uppercase_Mapping12,
- $Simple_Lowercase_Mapping13,
- $Simple_Titlecase_Mapping14
- ) = split(/\;/);
-
- if ($_[0] eq "upper") {
- $Mapping = $Simple_Uppercase_Mapping12;
- } elsif ($_[0] eq "lower") {
- $Mapping = $Simple_Lowercase_Mapping13;
- } else {
- exit(1);
- }
-
- next if ($Mapping eq "");
-
- $hex_code0 = hex($code0);
- $hex_Mapping = hex($Mapping);
-
- if ($hex_code0 <= 0xFFFF) {
- $table[$hex_code0][0] = $hex_Mapping;
- #table[$hex_code0][1] already set
- $table[$hex_code0][2] = $Name1;
- $block_enable[($hex_code0 / 64) +1] = 1;
- } else {
- $sp = ((0xD800 - (0x10000 >> 10) + ($hex_Mapping >> 10)) << 16)
- + (0xDC00 + ($hex_Mapping & 0x3FF));
- $table_sp[$hex_code0][0] = $sp;
- #table_sp[$hex_code0][1] already set
- $table_sp[$hex_code0][2] = $hex_Mapping;
- #table_sp[$hex_code0][3] already set
- $table_sp[$hex_code0][4] = $Name1;
- $block_enable_sp[($hex_code0 / 64) +1] = 1;
- }
- }
-
- close(UNICODEDATA);
-
- # array for BMP --------------------------------------------------
-
- printf(CSOURCE "\/*******************************************************************\n");
- printf(CSOURCE " Convert a wide character to %s case.\n", $_[0]);
- printf(CSOURCE "*******************************************************************\/\n");
- printf(CSOURCE "ucs2\_t to%s\_w\(ucs2\_t val\)\n", $_[0]);
- printf(CSOURCE "{\n");
-
- $table_no = 1;
-
- for ($block = 1 ; $block <= 1024 ; $block++) {
-
- # rising edge detection
- if ($block_enable[$block - 1] == 0 && $block_enable[$block] == 1) {
- $block_start = $block;
- }
-
- # falling edge detection
- if ($block_enable[$block] == 1 && $block_enable[$block + 1] == 0) {
- $block_end = $block;
-
- $char_start = ($block_start -1)* 64;
- $char_end = ($block_end * 64) -1;
-
- printf(CHEADER "static const uint16\_t %s\_table\_%d\[%d\] \= \{\n",
- $_[0], $table_no, $char_end - $char_start +1);
-
- for ($char = $char_start ; $char <= $char_end ; $char++) {
- printf(CHEADER " 0x%04X, /*U\+%04X*/ /*%s*/\n",
- $table[$char][0],
- $table[$char][1],
- $table[$char][2]
- );
- }
- printf(CHEADER "\}\;\n");
- printf(CHEADER "\n");
-
- if ($char_start == 0x0000) {
- printf(CSOURCE " if \( val \<\= 0x%04X)\n",
- $char_end);
- printf(CSOURCE " return %s\_table\_%d\[val]\;\n",
- $_[0], $table_no);
- } else {
- printf(CSOURCE " if \( val \>\= 0x%04X \&\& val \<\= 0x%04X)\n",
- $char_start, $char_end);
- printf(CSOURCE " return %s\_table\_%d\[val-0x%04X\]\;\n",
- $_[0], $table_no, $char_start);
- }
- printf(CSOURCE "\n");
-
- $table_no++;
- }
- }
-
- printf(CSOURCE "\treturn \(val\)\;\n");
- printf(CSOURCE "\}\n");
- printf(CSOURCE "\n");
-
- # array for Surrogate Pair ---------------------------------------
-
- printf(CSOURCE "\/*******************************************************************\n");
- printf(CSOURCE " Convert a surrogate pair to %s case.\n", $_[0]);
- printf(CSOURCE "*******************************************************************\/\n");
- printf(CSOURCE "uint32\_t to%s\_sp\(uint32\_t val\)\n", $_[0]);
- printf(CSOURCE "{\n");
-
- $table_no = 1;
-
- for ($block = 1025 ; $block <= 17408 ; $block++) {
-
- # rising edge detection
- if ((($block_enable_sp[$block - 1] == 0) || ((($block - 1) & 0xF) == 0))
- && ($block_enable_sp[$block] == 1)) {
- $block_start = $block;
- }
-
- # falling edge detection
- if (($block_enable_sp[$block] == 1) &&
- ((($block - 1) & 0xF == 0xF) || ($block_enable_sp[$block + 1] == 0))) {
- $block_end = $block;
-
- $char_start = ($block_start -1)* 64;
- $char_end = ($block_end * 64) -1;
-
- printf(CHEADER "static const uint32\_t %s\_table\_sp\_%d\[%d\] \= \{\n",
- $_[0], $table_no, $char_end - $char_start +1);
-
- for ($char = $char_start ; $char <= $char_end ; $char++) {
- printf(CHEADER " 0x%08X, /*0x%08X*/ /*U\+%06X*/ /*U\+%06X*/ /*%s*/\n",
- $table_sp[$char][0],
- $table_sp[$char][1],
- $table_sp[$char][2],
- $table_sp[$char][3],
- $table_sp[$char][4]
- );
- }
- printf(CHEADER "\}\;\n");
- printf(CHEADER "\n");
-
- printf(CSOURCE " if \( val \>\= 0x%08X \&\& val \<\= 0x%08X)\n",
- $table_sp[$char_start][1], $table_sp[$char_end][1]);
- printf(CSOURCE " return %s\_table\_sp\_%d\[val-0x%08X\]\;\n",
- $_[0], $table_no, $table_sp[$char_start][1]);
- printf(CSOURCE "\n");
-
- $table_no++;
- }
- }
-
- printf(CSOURCE "\treturn \(val\)\;\n");
- printf(CSOURCE "\}\n");
- printf(CSOURCE "\n");
-}
-
-# EOF
+++ /dev/null
-#!/usr/bin/perl
-#
-# usage: make-precompose.h.pl UnicodeData.txt > precompose.h
-#
-# (c) 2008-2011 by HAT <hat@fa2.so-net.ne.jp>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-
-# See
-# http://www.unicode.org/Public/UNIDATA/UCD.html
-# http://www.unicode.org/reports/tr15/
-# http://www.unicode.org/Public/*/ucd/UnicodeData*.txt
-# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
-
-
-# temp files for binary search (compose.TEMP, compose_sp.TEMP) -------------
-
-open(UNICODEDATA, "<$ARGV[0]");
-
-open(COMPOSE_TEMP, ">compose.TEMP");
-open(COMPOSE_SP_TEMP, ">compose_sp.TEMP");
-
-while (<UNICODEDATA>) {
- chop;
- (
- $code0,
- $Name1,
- $General_Category2,
- $Canonical_Combining_Class3,
- $Bidi_Class4,
- $Decomposition_Mapping5,
- $Numeric_Value6,
- $Numeric_Value7,
- $Numeric_Value8,
- $Bidi_Mirrored9,
- $Unicode_1_Name10,
- $ISO_Comment11,
- $Simple_Uppercase_Mapping12,
- $Simple_Lowercase_Mapping13,
- $Simple_Titlecase_Mapping14
- ) = split(/\;/);
-
- if (($Decomposition_Mapping5 ne "") && ($Decomposition_Mapping5 !~ /\</) && ($Decomposition_Mapping5 =~ / /)) {
- ($base, $comb) = split(/ /,$Decomposition_Mapping5);
-
- $leftbracket = " { ";
- $rightbracket =" }, ";
-
- # AFP 3.x Spec
- if ( ((0x2000 <= hex($code0)) && (hex($code0) <= 0x2FFF))
- || ((0xFE30 <= hex($code0)) && (hex($code0) <= 0xFE4F))
- || ((0x2F800 <= hex($code0)) && (hex($code0) <= 0x2FA1F))) {
- $leftbracket = "\/\*{ ";
- $rightbracket =" },\*\/ ";
- }
-
- if (hex($code0) > 0xFFFF) {
-
- $code0_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($code0) >> 10);
- $code0_sp_lo = 0xDC00 + (hex($code0) & 0x3FF);
-
- $base_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($base) >> 10);
- $base_sp_lo = 0xDC00 + (hex($base) & 0x3FF);
-
- $comb_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($comb) >> 10);
- $comb_sp_lo = 0xDC00 + (hex($comb) & 0x3FF);
-
- printf(COMPOSE_SP_TEMP "%s0x%04X%04X, 0x%04X%04X, 0x%04X%04X%s\/\* %s \*\/\n",
- $leftbracket, $code0_sp_hi ,$code0_sp_lo, $base_sp_hi, $base_sp_lo, $comb_sp_hi, $comb_sp_lo, $rightbracket, $Name1);
-
- $leftbracket = "\/\*{ ";
- $rightbracket =" },\*\/ ";
- }
-
- printf(COMPOSE_TEMP "%s0x%08X, 0x%08X, 0x%08X%s\/\* %s \*\/\n", $leftbracket, hex($code0), hex($base), hex($comb), $rightbracket, $Name1);
-
- }
-}
-
-close(UNICODEDATA);
-
-close(COMPOSE_TEMP);
-close(COMPOSE_SP_TEMP);
-
-# macros for BMP (PRECOMP_COUNT, DECOMP_COUNT, MAXCOMBLEN) ----------------
-
-open(COMPOSE_TEMP, "<compose.TEMP");
-
-@comp_table = ();
-$comp_count = 0;
-
-while (<COMPOSE_TEMP>) {
- if (m/^\/\*/) {
- next;
- }
- $comp_table[$comp_count][0] = substr($_, 4, 10);
- $comp_table[$comp_count][1] = substr($_, 16, 10);
- $comp_count++;
-}
-
-$maxcomblen = 2; # Hangul's maxcomblen is already 2. That is, VT.
-
-for ($i = 0 ; $i < $comp_count ; $i++) {
- $base = $comp_table[$i][1];
- $comblen = 1;
- $j = 0;
- while ($j < $comp_count) {
- if ($base ne $comp_table[$j][0]) {
- $j++;
- next;
- } else {
- $comblen++;
- $base = $comp_table[$j][1];
- $j = 0;
- }
- }
- $maxcomblen = ($maxcomblen > $comblen) ? $maxcomblen : $comblen;
-}
-
-close(COMPOSE_TEMP);
-
-# macros for SP (PRECOMP_SP_COUNT,DECOMP_SP_COUNT, MAXCOMBSPLEN) -----------
-
-open(COMPOSE_SP_TEMP, "<compose_sp.TEMP");
-
-@comp_sp_table = ();
-$comp_sp_count = 0;
-
-while (<COMPOSE_SP_TEMP>) {
- if (m/^\/\*/) {
- next;
- }
- $comp_sp_table[$comp_sp_count][0] = substr($_, 4, 10);
- $comp_sp_table[$comp_sp_count][1] = substr($_, 16, 10);
- $comp_sp_count++;
-}
-
-$maxcombsplen = 2; # one char have 2 codepoints, like a D8xx DCxx.
-
-for ($i = 0 ; $i < $comp_sp_count ; $i++) {
- $base_sp = $comp_sp_table[$i][1];
- $comblen = 2;
- $j = 0;
- while ($j < $comp_sp_count) {
- if ($base_sp ne $comp_sp_table[$j][0]) {
- $j++;
- next;
- } else {
- $comblen += 2;
- $base_sp = $comp_sp_table[$j][1];
- $j = 0;
- }
- }
- $maxcombsplen = ($maxcombsplen > $comblen) ? $maxcombsplen : $comblen;
-}
-
-close(COMPOSE_SP_TEMP);
-
-# macro for buffer length (COMBBUFLEN) -------------------------------------
-
-$combbuflen = ($maxcomblen > $maxcombsplen) ? $maxcomblen : $maxcombsplen;
-
-# sort ---------------------------------------------------------------------
-
-system("sort -k 3 compose.TEMP \> precompose.SORT");
-system("sort -k 2 compose.TEMP \> decompose.SORT");
-
-system("sort -k 3 compose_sp.TEMP \> precompose_sp.SORT");
-system("sort -k 2 compose_sp.TEMP \> decompose_sp.SORT");
-
-# print -------------------------------------------------------------------
-
-print ("\/\* DO NOT EDIT BY HAND\!\!\! \*\/\n");
-print ("\/\* This file is generated by \*\/\n");
-printf ("\/\* contrib/misc/make-precompose.h.pl %s \*\/\n", $ARGV[0]);
-print ("\n");
-printf ("\/\* %s is got from \*\/\n", $ARGV[0]);
-print ("\/\* http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt \*\/\n");
-print ("\n");
-
-print ("\#define SBASE 0xAC00\n");
-print ("\#define LBASE 0x1100\n");
-print ("\#define VBASE 0x1161\n");
-print ("\#define TBASE 0x11A7\n");
-print ("\#define LCOUNT 19\n");
-print ("\#define VCOUNT 21\n");
-print ("\#define TCOUNT 28\n");
-print ("\#define NCOUNT 588 \/\* (VCOUNT \* TCOUNT) \*\/\n");
-print ("\#define SCOUNT 11172 \/\* (LCOUNT \* NCOUNT) \*\/\n");
-print ("\n");
-
-printf ("\#define PRECOMP_COUNT %d\n", $comp_count);
-printf ("\#define DECOMP_COUNT %d\n", $comp_count);
-printf ("\#define MAXCOMBLEN %d\n", $maxcomblen);
-print ("\n");
-printf ("\#define PRECOMP_SP_COUNT %d\n", $comp_sp_count);
-printf ("\#define DECOMP_SP_COUNT %d\n", $comp_sp_count);
-printf ("\#define MAXCOMBSPLEN %d\n", $maxcombsplen);
-print ("\n");
-printf ("\#define COMBBUFLEN %d \/\* max\(MAXCOMBLEN\,MAXCOMBSPLEN\) \*\/\n", $combbuflen);
-print ("\n");
-
-print ("static const struct \{\n");
-print (" unsigned int replacement\;\n");
-print (" unsigned int base\;\n");
-print (" unsigned int comb\;\n");
-print ("\} precompositions\[\] \= \{\n");
-
-system("cat precompose.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-print ("static const struct \{\n");
-print (" unsigned int replacement\;\n");
-print (" unsigned int base\;\n");
-print (" unsigned int comb\;\n");
-print ("\} decompositions\[\] \= \{\n");
-
-system("cat decompose.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-
-
-print ("static const struct \{\n");
-print (" unsigned int replacement_sp\;\n");
-print (" unsigned int base_sp\;\n");
-print (" unsigned int comb_sp\;\n");
-print ("\} precompositions_sp\[\] \= \{\n");
-
-system("cat precompose_sp.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-print ("static const struct \{\n");
-print (" unsigned int replacement_sp\;\n");
-print (" unsigned int base_sp\;\n");
-print (" unsigned int comb_sp\;\n");
-print ("\} decompositions_sp\[\] \= \{\n");
-
-system("cat decompose_sp.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-print ("\/\* EOF \*\/\n");
-
-# EOF
bin_SCRIPTS = $(PERLSCRIPTS) $(GENERATED_FILES)
-EXTRA_DIST = $(TEMPLATE_FILES)
+EXTRA_DIST = $(TEMPLATE_FILES) make-casetable.pl make-precompose.h.pl
--- /dev/null
+#!/usr/bin/perl
+#
+# usage: make-casetable.pl <infile> <outfile1> <outfile2>
+# make-casetable.pl UnicodeData.txt utf16_casetable.h utf16_case.c
+#
+# (c) 2011 by HAT <hat@fa2.so-net.ne.jp>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+# See
+# http://www.unicode.org/reports/tr44/
+# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
+
+# One block has 64 chars.
+#
+# BMP
+# block 0 = dummy
+# block 1 = U+0000 - U+003F
+# block 2 = U+0040 - U+007F
+# .....
+# block 1024 = U+FFC0 - U+FFFF
+# block 1025 = dummy
+#
+# Surrogate Pair
+# block 1024 = dummy
+# block 1025 = U+010000 - U+01003F
+# block 1026 = U+010040 - U+01007F
+# .....
+# block 17408 = U+10FFC0 - U+10FFFF
+# block 17409 = dummy
+#
+# Dummy block is for edge detection.
+# If block include upper/lower chars, block_enable[]=1.
+
+use strict;
+use warnings;
+
+our $code0;
+our $Name1;
+our $General_Category2;
+our $Canonical_Combining_Class3;
+our $Bidi_Class4;
+our $Decomposition_Mapping5;
+our $Numeric_Value6;
+our $Numeric_Value7;
+our $Numeric_Value8;
+our $Bidi_Mirrored9;
+our $Unicode_1_Name10;
+our $ISO_Comment11;
+our $Simple_Uppercase_Mapping12;
+our $Simple_Lowercase_Mapping13;
+our $Simple_Titlecase_Mapping14;
+
+our $hex_code0;
+our $Mapping;
+our $hex_Mapping;
+
+our $char;
+our $sp;
+our $block;
+
+our @table;
+our @table_sp;
+
+our @block_enable;
+our @block_enable_sp;
+
+our $table_no;
+our $block_start;
+our $block_end;
+our $char_start;
+our $char_end;
+
+open(CHEADER, ">$ARGV[1]");
+open(CSOURCE, ">$ARGV[2]");
+
+printf (CHEADER "\/\*\n");
+printf (CHEADER "DO NOT EDIT BY HAND\!\!\!\n");
+printf (CHEADER "\n");
+printf (CHEADER "This file is generated by\n");
+printf (CHEADER " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
+printf (CHEADER "\n");
+printf (CHEADER "%s is got from\n", $ARGV[0]);
+printf (CHEADER "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
+printf (CHEADER "\*\/\n");
+printf (CHEADER "\n");
+
+printf (CSOURCE "\/\*\n");
+printf (CSOURCE "DO NOT EDIT BY HAND\!\!\!\n");
+printf (CSOURCE "\n");
+printf (CSOURCE "This file is generated by\n");
+printf (CSOURCE " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
+printf (CSOURCE "\n");
+printf (CSOURCE "%s is got from\n", $ARGV[0]);
+printf (CSOURCE "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
+printf (CSOURCE "\*\/\n");
+printf (CSOURCE "\n");
+printf (CSOURCE "\#include \<stdint.h\>\n");
+printf (CSOURCE "\#include \<atalk\/unicode.h\>\n");
+printf (CSOURCE "\#include \"%s\"\n", $ARGV[1]);
+printf (CSOURCE "\n");
+
+&make_array("upper");
+&make_array("lower");
+
+printf (CHEADER "\/\* EOF \*\/\n");
+printf (CSOURCE "\/\* EOF \*\/\n");
+
+close(CHEADER);
+close(CSOURCE);
+
+
+###########################################################################
+sub make_array{
+
+ # init table -----------------------------------------------------
+
+ for ($char = 0 ; $char <= 0xFFFF ; $char++) {
+ $table[$char][0] = $char; # mapped char
+ $table[$char][1] = $char; # orig char
+ $table[$char][2] = ""; # char name
+ }
+
+ for ($char = 0x10000 ; $char <= 0x10FFFF ; $char++) {
+ $sp = ((0xD800 - (0x10000 >> 10) + ($char >> 10)) << 16)
+ + (0xDC00 + ($char & 0x3FF));
+ $table_sp[$char][0] = $sp; # mapped surrogate pair
+ $table_sp[$char][1] = $sp; # orig surrogate pair
+ $table_sp[$char][2] = $char; # mapped char
+ $table_sp[$char][3] = $char; # orig char
+ $table_sp[$char][4] = ""; # char name
+ }
+
+ for ($block = 0 ; $block <= 1025 ; $block++) {
+ $block_enable[$block] = 0;
+ }
+
+ $block_enable[1] = 1; # ASCII block is forcibly included
+ $block_enable[2] = 1; # in the array for Speed-Up.
+
+ for ($block = 1024 ; $block <= 17409 ; $block++) {
+ $block_enable_sp[$block] = 0;
+ }
+
+ # write data to table --------------------------------------------
+
+ open(UNICODEDATA, "<$ARGV[0]");
+
+ while (<UNICODEDATA>) {
+ chop;
+ (
+ $code0,
+ $Name1,
+ $General_Category2,
+ $Canonical_Combining_Class3,
+ $Bidi_Class4,
+ $Decomposition_Mapping5,
+ $Numeric_Value6,
+ $Numeric_Value7,
+ $Numeric_Value8,
+ $Bidi_Mirrored9,
+ $Unicode_1_Name10,
+ $ISO_Comment11,
+ $Simple_Uppercase_Mapping12,
+ $Simple_Lowercase_Mapping13,
+ $Simple_Titlecase_Mapping14
+ ) = split(/\;/);
+
+ if ($_[0] eq "upper") {
+ $Mapping = $Simple_Uppercase_Mapping12;
+ } elsif ($_[0] eq "lower") {
+ $Mapping = $Simple_Lowercase_Mapping13;
+ } else {
+ exit(1);
+ }
+
+ next if ($Mapping eq "");
+
+ $hex_code0 = hex($code0);
+ $hex_Mapping = hex($Mapping);
+
+ if ($hex_code0 <= 0xFFFF) {
+ $table[$hex_code0][0] = $hex_Mapping;
+ #table[$hex_code0][1] already set
+ $table[$hex_code0][2] = $Name1;
+ $block_enable[($hex_code0 / 64) +1] = 1;
+ } else {
+ $sp = ((0xD800 - (0x10000 >> 10) + ($hex_Mapping >> 10)) << 16)
+ + (0xDC00 + ($hex_Mapping & 0x3FF));
+ $table_sp[$hex_code0][0] = $sp;
+ #table_sp[$hex_code0][1] already set
+ $table_sp[$hex_code0][2] = $hex_Mapping;
+ #table_sp[$hex_code0][3] already set
+ $table_sp[$hex_code0][4] = $Name1;
+ $block_enable_sp[($hex_code0 / 64) +1] = 1;
+ }
+ }
+
+ close(UNICODEDATA);
+
+ # array for BMP --------------------------------------------------
+
+ printf(CSOURCE "\/*******************************************************************\n");
+ printf(CSOURCE " Convert a wide character to %s case.\n", $_[0]);
+ printf(CSOURCE "*******************************************************************\/\n");
+ printf(CSOURCE "ucs2\_t to%s\_w\(ucs2\_t val\)\n", $_[0]);
+ printf(CSOURCE "{\n");
+
+ $table_no = 1;
+
+ for ($block = 1 ; $block <= 1024 ; $block++) {
+
+ # rising edge detection
+ if ($block_enable[$block - 1] == 0 && $block_enable[$block] == 1) {
+ $block_start = $block;
+ }
+
+ # falling edge detection
+ if ($block_enable[$block] == 1 && $block_enable[$block + 1] == 0) {
+ $block_end = $block;
+
+ $char_start = ($block_start -1)* 64;
+ $char_end = ($block_end * 64) -1;
+
+ printf(CHEADER "static const uint16\_t %s\_table\_%d\[%d\] \= \{\n",
+ $_[0], $table_no, $char_end - $char_start +1);
+
+ for ($char = $char_start ; $char <= $char_end ; $char++) {
+ printf(CHEADER " 0x%04X, /*U\+%04X*/ /*%s*/\n",
+ $table[$char][0],
+ $table[$char][1],
+ $table[$char][2]
+ );
+ }
+ printf(CHEADER "\}\;\n");
+ printf(CHEADER "\n");
+
+ if ($char_start == 0x0000) {
+ printf(CSOURCE " if \( val \<\= 0x%04X)\n",
+ $char_end);
+ printf(CSOURCE " return %s\_table\_%d\[val]\;\n",
+ $_[0], $table_no);
+ } else {
+ printf(CSOURCE " if \( val \>\= 0x%04X \&\& val \<\= 0x%04X)\n",
+ $char_start, $char_end);
+ printf(CSOURCE " return %s\_table\_%d\[val-0x%04X\]\;\n",
+ $_[0], $table_no, $char_start);
+ }
+ printf(CSOURCE "\n");
+
+ $table_no++;
+ }
+ }
+
+ printf(CSOURCE "\treturn \(val\)\;\n");
+ printf(CSOURCE "\}\n");
+ printf(CSOURCE "\n");
+
+ # array for Surrogate Pair ---------------------------------------
+
+ printf(CSOURCE "\/*******************************************************************\n");
+ printf(CSOURCE " Convert a surrogate pair to %s case.\n", $_[0]);
+ printf(CSOURCE "*******************************************************************\/\n");
+ printf(CSOURCE "uint32\_t to%s\_sp\(uint32\_t val\)\n", $_[0]);
+ printf(CSOURCE "{\n");
+
+ $table_no = 1;
+
+ for ($block = 1025 ; $block <= 17408 ; $block++) {
+
+ # rising edge detection
+ if ((($block_enable_sp[$block - 1] == 0) || ((($block - 1) & 0xF) == 0))
+ && ($block_enable_sp[$block] == 1)) {
+ $block_start = $block;
+ }
+
+ # falling edge detection
+ if (($block_enable_sp[$block] == 1) &&
+ ((($block - 1) & 0xF == 0xF) || ($block_enable_sp[$block + 1] == 0))) {
+ $block_end = $block;
+
+ $char_start = ($block_start -1)* 64;
+ $char_end = ($block_end * 64) -1;
+
+ printf(CHEADER "static const uint32\_t %s\_table\_sp\_%d\[%d\] \= \{\n",
+ $_[0], $table_no, $char_end - $char_start +1);
+
+ for ($char = $char_start ; $char <= $char_end ; $char++) {
+ printf(CHEADER " 0x%08X, /*0x%08X*/ /*U\+%06X*/ /*U\+%06X*/ /*%s*/\n",
+ $table_sp[$char][0],
+ $table_sp[$char][1],
+ $table_sp[$char][2],
+ $table_sp[$char][3],
+ $table_sp[$char][4]
+ );
+ }
+ printf(CHEADER "\}\;\n");
+ printf(CHEADER "\n");
+
+ printf(CSOURCE " if \( val \>\= 0x%08X \&\& val \<\= 0x%08X)\n",
+ $table_sp[$char_start][1], $table_sp[$char_end][1]);
+ printf(CSOURCE " return %s\_table\_sp\_%d\[val-0x%08X\]\;\n",
+ $_[0], $table_no, $table_sp[$char_start][1]);
+ printf(CSOURCE "\n");
+
+ $table_no++;
+ }
+ }
+
+ printf(CSOURCE "\treturn \(val\)\;\n");
+ printf(CSOURCE "\}\n");
+ printf(CSOURCE "\n");
+}
+
+# EOF
--- /dev/null
+#!/usr/bin/perl
+#
+# usage: make-precompose.h.pl UnicodeData.txt > precompose.h
+#
+# (c) 2008-2011 by HAT <hat@fa2.so-net.ne.jp>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+# See
+# http://www.unicode.org/Public/UNIDATA/UCD.html
+# http://www.unicode.org/reports/tr15/
+# http://www.unicode.org/Public/*/ucd/UnicodeData*.txt
+# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
+
+
+# temp files for binary search (compose.TEMP, compose_sp.TEMP) -------------
+
+open(UNICODEDATA, "<$ARGV[0]");
+
+open(COMPOSE_TEMP, ">compose.TEMP");
+open(COMPOSE_SP_TEMP, ">compose_sp.TEMP");
+
+while (<UNICODEDATA>) {
+ chop;
+ (
+ $code0,
+ $Name1,
+ $General_Category2,
+ $Canonical_Combining_Class3,
+ $Bidi_Class4,
+ $Decomposition_Mapping5,
+ $Numeric_Value6,
+ $Numeric_Value7,
+ $Numeric_Value8,
+ $Bidi_Mirrored9,
+ $Unicode_1_Name10,
+ $ISO_Comment11,
+ $Simple_Uppercase_Mapping12,
+ $Simple_Lowercase_Mapping13,
+ $Simple_Titlecase_Mapping14
+ ) = split(/\;/);
+
+ if (($Decomposition_Mapping5 ne "") && ($Decomposition_Mapping5 !~ /\</) && ($Decomposition_Mapping5 =~ / /)) {
+ ($base, $comb) = split(/ /,$Decomposition_Mapping5);
+
+ $leftbracket = " { ";
+ $rightbracket =" }, ";
+
+ # AFP 3.x Spec
+ if ( ((0x2000 <= hex($code0)) && (hex($code0) <= 0x2FFF))
+ || ((0xFE30 <= hex($code0)) && (hex($code0) <= 0xFE4F))
+ || ((0x2F800 <= hex($code0)) && (hex($code0) <= 0x2FA1F))) {
+ $leftbracket = "\/\*{ ";
+ $rightbracket =" },\*\/ ";
+ }
+
+ if (hex($code0) > 0xFFFF) {
+
+ $code0_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($code0) >> 10);
+ $code0_sp_lo = 0xDC00 + (hex($code0) & 0x3FF);
+
+ $base_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($base) >> 10);
+ $base_sp_lo = 0xDC00 + (hex($base) & 0x3FF);
+
+ $comb_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($comb) >> 10);
+ $comb_sp_lo = 0xDC00 + (hex($comb) & 0x3FF);
+
+ printf(COMPOSE_SP_TEMP "%s0x%04X%04X, 0x%04X%04X, 0x%04X%04X%s\/\* %s \*\/\n",
+ $leftbracket, $code0_sp_hi ,$code0_sp_lo, $base_sp_hi, $base_sp_lo, $comb_sp_hi, $comb_sp_lo, $rightbracket, $Name1);
+
+ $leftbracket = "\/\*{ ";
+ $rightbracket =" },\*\/ ";
+ }
+
+ printf(COMPOSE_TEMP "%s0x%08X, 0x%08X, 0x%08X%s\/\* %s \*\/\n", $leftbracket, hex($code0), hex($base), hex($comb), $rightbracket, $Name1);
+
+ }
+}
+
+close(UNICODEDATA);
+
+close(COMPOSE_TEMP);
+close(COMPOSE_SP_TEMP);
+
+# macros for BMP (PRECOMP_COUNT, DECOMP_COUNT, MAXCOMBLEN) ----------------
+
+open(COMPOSE_TEMP, "<compose.TEMP");
+
+@comp_table = ();
+$comp_count = 0;
+
+while (<COMPOSE_TEMP>) {
+ if (m/^\/\*/) {
+ next;
+ }
+ $comp_table[$comp_count][0] = substr($_, 4, 10);
+ $comp_table[$comp_count][1] = substr($_, 16, 10);
+ $comp_count++;
+}
+
+$maxcomblen = 2; # Hangul's maxcomblen is already 2. That is, VT.
+
+for ($i = 0 ; $i < $comp_count ; $i++) {
+ $base = $comp_table[$i][1];
+ $comblen = 1;
+ $j = 0;
+ while ($j < $comp_count) {
+ if ($base ne $comp_table[$j][0]) {
+ $j++;
+ next;
+ } else {
+ $comblen++;
+ $base = $comp_table[$j][1];
+ $j = 0;
+ }
+ }
+ $maxcomblen = ($maxcomblen > $comblen) ? $maxcomblen : $comblen;
+}
+
+close(COMPOSE_TEMP);
+
+# macros for SP (PRECOMP_SP_COUNT,DECOMP_SP_COUNT, MAXCOMBSPLEN) -----------
+
+open(COMPOSE_SP_TEMP, "<compose_sp.TEMP");
+
+@comp_sp_table = ();
+$comp_sp_count = 0;
+
+while (<COMPOSE_SP_TEMP>) {
+ if (m/^\/\*/) {
+ next;
+ }
+ $comp_sp_table[$comp_sp_count][0] = substr($_, 4, 10);
+ $comp_sp_table[$comp_sp_count][1] = substr($_, 16, 10);
+ $comp_sp_count++;
+}
+
+$maxcombsplen = 2; # one char have 2 codepoints, like a D8xx DCxx.
+
+for ($i = 0 ; $i < $comp_sp_count ; $i++) {
+ $base_sp = $comp_sp_table[$i][1];
+ $comblen = 2;
+ $j = 0;
+ while ($j < $comp_sp_count) {
+ if ($base_sp ne $comp_sp_table[$j][0]) {
+ $j++;
+ next;
+ } else {
+ $comblen += 2;
+ $base_sp = $comp_sp_table[$j][1];
+ $j = 0;
+ }
+ }
+ $maxcombsplen = ($maxcombsplen > $comblen) ? $maxcombsplen : $comblen;
+}
+
+close(COMPOSE_SP_TEMP);
+
+# macro for buffer length (COMBBUFLEN) -------------------------------------
+
+$combbuflen = ($maxcomblen > $maxcombsplen) ? $maxcomblen : $maxcombsplen;
+
+# sort ---------------------------------------------------------------------
+
+system("sort -k 3 compose.TEMP \> precompose.SORT");
+system("sort -k 2 compose.TEMP \> decompose.SORT");
+
+system("sort -k 3 compose_sp.TEMP \> precompose_sp.SORT");
+system("sort -k 2 compose_sp.TEMP \> decompose_sp.SORT");
+
+# print -------------------------------------------------------------------
+
+print ("\/\* DO NOT EDIT BY HAND\!\!\! \*\/\n");
+print ("\/\* This file is generated by \*\/\n");
+printf ("\/\* contrib/misc/make-precompose.h.pl %s \*\/\n", $ARGV[0]);
+print ("\n");
+printf ("\/\* %s is got from \*\/\n", $ARGV[0]);
+print ("\/\* http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt \*\/\n");
+print ("\n");
+
+print ("\#define SBASE 0xAC00\n");
+print ("\#define LBASE 0x1100\n");
+print ("\#define VBASE 0x1161\n");
+print ("\#define TBASE 0x11A7\n");
+print ("\#define LCOUNT 19\n");
+print ("\#define VCOUNT 21\n");
+print ("\#define TCOUNT 28\n");
+print ("\#define NCOUNT 588 \/\* (VCOUNT \* TCOUNT) \*\/\n");
+print ("\#define SCOUNT 11172 \/\* (LCOUNT \* NCOUNT) \*\/\n");
+print ("\n");
+
+printf ("\#define PRECOMP_COUNT %d\n", $comp_count);
+printf ("\#define DECOMP_COUNT %d\n", $comp_count);
+printf ("\#define MAXCOMBLEN %d\n", $maxcomblen);
+print ("\n");
+printf ("\#define PRECOMP_SP_COUNT %d\n", $comp_sp_count);
+printf ("\#define DECOMP_SP_COUNT %d\n", $comp_sp_count);
+printf ("\#define MAXCOMBSPLEN %d\n", $maxcombsplen);
+print ("\n");
+printf ("\#define COMBBUFLEN %d \/\* max\(MAXCOMBLEN\,MAXCOMBSPLEN\) \*\/\n", $combbuflen);
+print ("\n");
+
+print ("static const struct \{\n");
+print (" unsigned int replacement\;\n");
+print (" unsigned int base\;\n");
+print (" unsigned int comb\;\n");
+print ("\} precompositions\[\] \= \{\n");
+
+system("cat precompose.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+print ("static const struct \{\n");
+print (" unsigned int replacement\;\n");
+print (" unsigned int base\;\n");
+print (" unsigned int comb\;\n");
+print ("\} decompositions\[\] \= \{\n");
+
+system("cat decompose.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+
+
+print ("static const struct \{\n");
+print (" unsigned int replacement_sp\;\n");
+print (" unsigned int base_sp\;\n");
+print (" unsigned int comb_sp\;\n");
+print ("\} precompositions_sp\[\] \= \{\n");
+
+system("cat precompose_sp.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+print ("static const struct \{\n");
+print (" unsigned int replacement_sp\;\n");
+print (" unsigned int base_sp\;\n");
+print (" unsigned int comb_sp\;\n");
+print ("\} decompositions_sp\[\] \= \{\n");
+
+system("cat decompose_sp.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+print ("\/\* EOF \*\/\n");
+
+# EOF
+++ /dev/null
---
--- Netatalk DBD protocol
--- wireshark -X lua_script:cnid.lua
--- don't forget to comment out the line disable_lua = true; do return end;
--- in /etc/wireshark/init.lua
-
--- global environment
-local b = _G
-
--- declare our protocol
-local dbd_proto = Proto("dbd","Netatalk Dbd Wire Protocol")
-
-local cmd = ProtoField.uint32("dbd.cmd", "Request") -- , base.HEX
-local len = ProtoField.uint32("dbd.name.len", "Name Length")
-local filename = ProtoField.string("dbd.name", "Name")
-local error = ProtoField.uint32("dbd.error", "Error code")
-local cnid = ProtoField.uint32("dbd.cnid", "Cnid")
-local did = ProtoField.uint32("dbd.did", "Parent Directory Id")
-local dev = ProtoField.uint64("dbd.dev", "Device number")
-local ino = ProtoField.uint64("dbd.ino", "Inode number")
-local type = ProtoField.uint32("dbd.type", "File type")
-
-dbd_proto.fields = {cmd, error, cnid, did, dev, ino, type, filename, len}
-
---- Request list
-local Cmd = { [3] = "add",
- [4] = "get",
- [5] = "resolve",
- [6] = "lookup",
- [7] = "update",
- [8] = "delete",
- [11] = "timestamp"
- }
-
---- display a filename
-local function fname(buffer, pinfo, tree, len, ofs)
-
- pinfo.cols.info:append(" Name=" .. buffer(ofs +4, len):string())
-
- local subtree = tree:add(buffer(ofs, len +4), buffer(ofs +4, len):string())
- subtree:add(filename, buffer(ofs +4, len))
-
- return subtree
-end
-
--- create a function to dissect it
-function dbd_proto.dissector(buffer, pinfo, tree)
-
-
- pinfo.cols.protocol = "DBD"
-
- local subtree = tree:add(dbd_proto,buffer(),"Netatalk DBD Wire Protocol")
-
- if pinfo.dst_port == 4700 then
- pinfo.cols.info = "Query"
- local val = buffer(0,4):uint()
- local item = subtree:add(cmd, buffer(0,4))
- if Cmd[val] then
- item:append_text(" (" .. Cmd[val] .. ")")
- pinfo.cols.info = Cmd[val]
-
- local val = buffer(4,4):uint()
- if val ~= 0 then
- pinfo.cols.info:append(" Cnid=" .. val)
- end
- subtree:add(cnid, buffer(4, 4))
- subtree:add(dev, buffer(8, 8))
- subtree:add(ino, buffer(16, 8))
- subtree:add(type, buffer(24, 4))
-
- local val = buffer(28,4):uint()
- if val ~= 0 then
- pinfo.cols.info:append(" Did=" .. val)
- end
- subtree:add(did, buffer(28, 4))
-
- local val = buffer(36,4):uint()
- if val ~= 0 then
- item = fname(buffer, pinfo, subtree, val, 36)
- item:add(len, buffer(36, 4))
-
- end
- end
- else
- pinfo.cols.info = "Reply"
-
- local rply = {}
-
- local val = buffer(0,4):uint()
- rply.error = val
- subtree:add(error, buffer(0,4))
- if val ~= 0 then
- pinfo.cols.info:append(" Error=" .. val)
- end
-
- val = buffer(4,4):uint()
- rply.cnid = val
- subtree:add(cnid, buffer(4,4))
- if val ~= 0 then
- pinfo.cols.info:append(" Cnid=" .. val)
- end
-
- val = buffer(8,4):uint()
- rply.did = val
- subtree:add(did, buffer(8,4))
- if val ~= 0 then
- pinfo.cols.info:append(" Did=" .. val)
- end
-
- val = buffer(16,4):uint()
- rply.len = val
-
- if rply.error == 0 and rply.did ~= 0 then
- subtree = fname(buffer, pinfo, subtree, val, 16)
- subtree:add(len, buffer(16,4))
- end
- end
-end
-
--- load the tcp.port table
-local tcp_table = DissectorTable.get("tcp.port")
--- register our protocol
-tcp_table:add(4700, dbd_proto)
/* Everything is fine */
return db_cnid;
} else if (ad_cnid && db_cnid && (ad_cnid != db_cnid)) {
- /* Mismatch ? Delete both from db and re-add data from file */
+ /* Mismatch, overwrite ad file with value from db */
dbd_log( LOGSTD, "CNID mismatch for '%s/%s', db: %u, ad-file: %u", cwdbuf, name, ntohl(db_cnid), ntohl(ad_cnid));
if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
- rqst.cnid = db_cnid;
- ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID);
- if (dbif_txn_close(dbd, ret) != 0)
- return CNID_INVALID;
-
- rqst.cnid = ad_cnid;
- ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID);
- if (dbif_txn_close(dbd, ret) != 0)
- return CNID_INVALID;
-
- ret = dbd_rebuild_add(dbd, &rqst, &rply);
- if (dbif_txn_close(dbd, ret) != 0)
+ dbd_log(LOGSTD, "Updating AppleDouble file for '%s/%s' with CNID: %u from database",
+ cwdbuf, name, ntohl(db_cnid));
+ ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+ if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
+ dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
+ cwdbuf, name, strerror(errno));
return CNID_INVALID;
+ }
+ ad_setid( &ad, st->st_dev, st->st_ino, db_cnid, did, stamp);
+ ad_flush(&ad);
+ ad_close_metadata(&ad);
}
- return ad_cnid;
+ return db_cnid;
} else if (ad_cnid && (db_cnid == 0)) {
/* in ad-file but not in db */
if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
rqst.cnid = ad_cnid;
ret = dbd_resolve(dbd, &rqst, &rply);
- if (ret == CNID_DBD_RES_OK) {
+ if (rply.result == CNID_DBD_RES_OK) {
/* Occupied! Choose another, update ad-file */
ret = dbd_add(dbd, &rqst, &rply, 1);
if (dbif_txn_close(dbd, ret) != 0)
return -1;
}
+ LOG(log_debug, logtype_cnid,
+ "dbd_rebuild_add(CNID: %u, did: %u, name: \"%s\", dev/ino:0x%llx/0x%llx): success",
+ ntohl(rqst->cnid), ntohl(rqst->did), rqst->name,
+ (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
+
key.data = ROOTINFO_KEY;
key.size = ROOTINFO_KEYLEN;
rply->namelen = data.size;
rply->name = (char *)data.data;
- LOG(log_debug, logtype_cnid, "dbd_resolve: Resolving CNID %u to did %u name %s",
- ntohl(rqst->cnid), ntohl(rply->did), rply->name);
+ LOG(log_debug, logtype_cnid, "dbd_resolve(CNID: %u): did: %u, name: \"%s\"",
+ ntohl(rqst->cnid), ntohl(rply->did), rply->name + CNID_NAME_OFS);
rply->result = CNID_DBD_RES_OK;
return 1;